/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
// assign button ("Add Command") is enabled only if it is not read only // delete button ("Remove Command") is enabled if a current binding exists // and it is not read only void SvxMacroTabPage_::EnableButtons()
{
mpImpl->xDeleteAllPB->set_sensitive(m_nAssignedEvents != 0); int nEvent = mpImpl->xEventLB->get_selected_index(); const EventPair* pEventPair = nEvent == -1 ? nullptr : LookupEvent(mpImpl->xEventLB->get_id(nEvent)); constbool bAssigned = pEventPair && !pEventPair->second.isEmpty();
mpImpl->xDeletePB->set_sensitive(!mpImpl->bReadOnly && bAssigned);
mpImpl->xAssignPB->set_sensitive(!mpImpl->bReadOnly); if (mpImpl->xAssignComponentPB)
mpImpl->xAssignComponentPB->set_sensitive( !mpImpl->bReadOnly );
}
// the following method is called when the user clicks OK // We use the contents of the hashes to replace the settings bool SvxMacroTabPage_::FillItemSet( SfxItemSet* /*rSet*/ )
{ try
{
OUString eventName; if( m_xAppEvents.is() )
{ for (autoconst& appEvent : m_appEventsHash)
{
eventName = appEvent.first; try
{
m_xAppEvents->replaceByName( eventName, GetPropsByName( eventName, m_appEventsHash ) );
} catch (const Exception&)
{
DBG_UNHANDLED_EXCEPTION("cui.customize");
}
}
} if( m_xDocEvents.is() && bDocModified )
{ for (autoconst& docEvent : m_docEventsHash)
{
eventName = docEvent.first; try
{
m_xDocEvents->replaceByName( eventName, GetPropsByName( eventName, m_docEventsHash ) );
} catch (const Exception&)
{
DBG_UNHANDLED_EXCEPTION("cui.customize");
}
} // if we have a valid XModifiable (in the case of doc events) // call setModified(true) // in principle this should not be necessary (see issue ??) if(m_xModifiable.is())
{
m_xModifiable->setModified( true );
}
}
} catch (const Exception&)
{
} // what is the return value about?? returnfalse;
}
// the following method clears the bindings in the hashes for both doc & app void SvxMacroTabPage_::Reset( const SfxItemSet* )
{ // called once in creation - don't reset the data this time if(!bInitialized)
{
bInitialized = true; return;
}
try
{ if( m_xAppEvents.is() )
{ for (auto & appEvent : m_appEventsHash)
{
appEvent.second.second.clear();
}
} if( m_xDocEvents.is() && bDocModified )
{ for (auto & docEvent : m_docEventsHash)
{
docEvent.second.second.clear();
} // if we have a valid XModifiable (in the case of doc events) // call setModified(true) if(m_xModifiable.is())
{
m_xModifiable->setModified( true );
}
}
} catch (const Exception&)
{
}
DisplayAppEvents(bAppEvents, 0);
}
// displays the app events if appEvents=true, otherwise displays the doc events void SvxMacroTabPage_::DisplayAppEvents(bool appEvents, int nSelectIndex)
{
bAppEvents = appEvents;
mpImpl->xEventLB->freeze();
mpImpl->xEventLB->clear();
m_nAssignedEvents = 0;
EventsHash* eventsHash;
Reference< container::XNameReplace> nameReplace; if(bAppEvents)
{
eventsHash = &m_appEventsHash;
nameReplace = m_xAppEvents;
} else
{
eventsHash = &m_docEventsHash;
nameReplace = m_xDocEvents;
} // have to use the original XNameReplace since the hash iterators do // not guarantee the order in which the elements are returned if(!nameReplace.is())
{
mpImpl->xEventLB->thaw(); return;
}
for (autoconst& displayableEvent : gDisplayNames)
{ const OUString & sEventName( displayableEvent.aAsciiEventName ); if ( !nameReplace->hasByName( sEventName ) ) continue;
const EventPair* SvxMacroTabPage_::LookupEvent(const OUString& rEventName)
{ const EventPair* pRet = nullptr; if (bAppEvents)
{
EventsHash::iterator h_it = m_appEventsHash.find(rEventName); if (h_it != m_appEventsHash.end() )
pRet = &h_it->second;
} else
{
EventsHash::iterator h_it = m_docEventsHash.find(rEventName); if (h_it != m_docEventsHash.end() )
pRet = &h_it->second;
} return pRet;
}
// handler for double click on the listbox, and for the assign/delete buttons void SvxMacroTabPage_::GenericHandler_Impl(const weld::Button* pBtn)
{
weld::TreeView& rListBox = *mpImpl->xEventLB; int nEntry = rListBox.get_selected_index(); if (nEntry == -1)
{
DBG_ASSERT(false, "Where does the empty entry come from?"); return;
}
// returns the two props EventType & Script for a given event name
Any SvxMacroTabPage_::GetPropsByName( const OUString& eventName, EventsHash& eventsHash )
{ const EventPair& rAssignedEvent(eventsHash[eventName]);
// converts the Any returned by GetByName into a pair which can be stored in // the EventHash
EventPair SvxMacroTabPage_::GetPairFromAny( const Any& aAny )
{
Sequence< beans::PropertyValue > props;
OUString type, url; if( aAny >>= props )
{
::comphelper::NamedValueCollection aProps( props );
type = aProps.getOrDefault( u"EventType"_ustr, type );
url = aProps.getOrDefault( u"Script"_ustr, url );
} return std::make_pair( type, url );
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.