diff options
author | Caolán McNamara <caolanm@redhat.com> | 2022-12-09 10:47:05 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2022-12-09 12:37:37 +0000 |
commit | 83eb2796d1f4a6778d40a5e2e94c4b536163fecb (patch) | |
tree | 87f115954123ec7237b9db28f0d656fc4651f8d6 /cui | |
parent | 4702910165dff6d5cef0d1bc707ff66b0b0d95bd (diff) |
Related: tdf#152266 give feedback which events are assigned
where assigned is means an event is assigned to a non-empty url, now the
delete button is only enabled when there is something to delete,
bringing the customizie event page into line with the sheet event page
and the writer frame event assignment page
Change-Id: I7e016bf578dff24b7d47312fd5f7cc63883d1e4d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143848
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'cui')
-rw-r--r-- | cui/source/customize/macropg.cxx | 45 | ||||
-rw-r--r-- | cui/source/inc/macropg.hxx | 6 |
2 files changed, 30 insertions, 21 deletions
diff --git a/cui/source/customize/macropg.cxx b/cui/source/customize/macropg.cxx index a1fe3dab39dc..34eb44849d84 100644 --- a/cui/source/customize/macropg.cxx +++ b/cui/source/customize/macropg.cxx @@ -64,7 +64,9 @@ void SvxMacroTabPage_::EnableButtons() int nEvent = mpImpl->xEventLB->get_selected_index(); if (nEvent != -1) { - mpImpl->xDeletePB->set_sensitive( !mpImpl->bReadOnly ); + const EventPair* pEventPair = LookupEvent(mpImpl->xEventLB->get_id(nEvent)); + const bool 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 ); @@ -384,6 +386,24 @@ IMPL_LINK_NOARG( SvxMacroTabPage_, DoubleClickHdl_Impl, weld::TreeView&, bool) return true; } +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) { @@ -401,23 +421,10 @@ void SvxMacroTabPage_::GenericHandler_Impl(const weld::Button* pBtn) OUString sEventURL; OUString sEventType; - if (bAppEvents) + if (const EventPair* pEventPair = LookupEvent(sEventName)) { - EventsHash::iterator h_it = m_appEventsHash.find(sEventName); - if (h_it != m_appEventsHash.end() ) - { - sEventType = h_it->second.first; - sEventURL = h_it->second.second; - } - } - else - { - EventsHash::iterator h_it = m_docEventsHash.find(sEventName); - if (h_it != m_docEventsHash.end() ) - { - sEventType = h_it->second.first; - sEventURL = h_it->second.second; - } + sEventType = pEventPair->first; + sEventURL = pEventPair->second; } bool bDoubleClick = (pBtn == nullptr); @@ -548,7 +555,7 @@ void SvxMacroTabPage_::InitAndSetHandler( const Reference< container::XNameRepla // returns the two props EventType & Script for a given event name Any SvxMacroTabPage_::GetPropsByName( const OUString& eventName, EventsHash& eventsHash ) { - const std::pair< OUString, OUString >& rAssignedEvent( eventsHash[ eventName ] ); + const EventPair& rAssignedEvent(eventsHash[eventName]); Any aReturn; ::comphelper::NamedValueCollection aProps; @@ -564,7 +571,7 @@ Any SvxMacroTabPage_::GetPropsByName( const OUString& eventName, EventsHash& eve // converts the Any returned by GetByName into a pair which can be stored in // the EventHash -std::pair< OUString, OUString > SvxMacroTabPage_::GetPairFromAny( const Any& aAny ) +EventPair SvxMacroTabPage_::GetPairFromAny( const Any& aAny ) { Sequence< beans::PropertyValue > props; OUString type, url; diff --git a/cui/source/inc/macropg.hxx b/cui/source/inc/macropg.hxx index ef9e16c51bba..7c934e33799d 100644 --- a/cui/source/inc/macropg.hxx +++ b/cui/source/inc/macropg.hxx @@ -30,7 +30,8 @@ #include <unordered_map> #include <vector> -typedef std::unordered_map< OUString, std::pair< OUString, OUString > > EventsHash; +typedef std::pair<OUString, OUString> EventPair; +typedef std::unordered_map<OUString, EventPair> EventsHash; struct EventDisplayName { @@ -56,6 +57,7 @@ class SvxMacroTabPage_ : public SfxTabPage DECL_LINK( DoubleClickHdl_Impl, weld::TreeView&, bool ); void GenericHandler_Impl(const weld::Button* pBtn); + const EventPair* LookupEvent(const OUString& rEventName); css::uno::Reference< css::container::XNameReplace > m_xAppEvents; protected: @@ -71,7 +73,7 @@ protected: void EnableButtons(); static css::uno::Any GetPropsByName( const OUString& eventName, EventsHash& eventsHash ); - static std::pair< OUString, OUString > GetPairFromAny( const css::uno::Any& aAny ); + static EventPair GetPairFromAny(const css::uno::Any& aAny); public: |