[Libreoffice-commits] core.git: cui/source

baltasarq (via logerrit) logerrit at kemper.freedesktop.org
Tue May 18 07:03:38 UTC 2021


 cui/source/customize/SvxMenuConfigPage.cxx |   13 ++++
 cui/source/customize/cfg.cxx               |   78 ++++++++++++++++++++---------
 cui/source/inc/cfg.hxx                     |    5 +
 3 files changed, 71 insertions(+), 25 deletions(-)

New commits:
commit 43b985b35be324b3398d48585d943f6fb64ae066
Author:     baltasarq <baltasarq at gmail.com>
AuthorDate: Mon May 3 15:48:18 2021 +0200
Commit:     Heiko Tietze <heiko.tietze at documentfoundation.org>
CommitDate: Tue May 18 09:03:04 2021 +0200

    tdf#112369 allow to disable the add command button in menu customize
    
    Instead of showing an alert dialog reporting that a command is already present
    in a given menu, enable or disable the add command button when needed.
    
    Change-Id: I52b9477896d4775ae2033c057fa1b5bfccb6a749
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115057
    Tested-by: Jenkins
    Reviewed-by: Heiko Tietze <heiko.tietze at documentfoundation.org>

diff --git a/cui/source/customize/SvxMenuConfigPage.cxx b/cui/source/customize/SvxMenuConfigPage.cxx
index 3181a78bbb07..34cee1368d7a 100644
--- a/cui/source/customize/SvxMenuConfigPage.cxx
+++ b/cui/source/customize/SvxMenuConfigPage.cxx
@@ -172,8 +172,17 @@ void SvxMenuConfigPage::UpdateButtonStates()
 
     m_xInsertBtn->set_sensitive(pMenuData != nullptr);
 
-    m_xAddCommandButton->set_sensitive(pMenuData != nullptr);
-    m_xRemoveCommandButton->set_sensitive(pMenuData != nullptr);
+    SvxConfigEntry* selectedCmd = CreateCommandFromSelection(GetScriptURL());
+
+    m_xAddCommandButton->set_sensitive(
+        pMenuData != nullptr && !IsCommandInMenuList(selectedCmd, pMenuData->GetEntries()));
+
+    delete selectedCmd;
+
+    if (bIsValidSelection)
+    {
+        m_xRemoveCommandButton->set_sensitive(pMenuData != nullptr);
+    }
 
     //Handle the gear button
     if (pMenuData && m_bIsMenuBar)
diff --git a/cui/source/customize/cfg.cxx b/cui/source/customize/cfg.cxx
index 3ab8e4288703..de32e1063336 100644
--- a/cui/source/customize/cfg.cxx
+++ b/cui/source/customize/cfg.cxx
@@ -1395,18 +1395,14 @@ SvxEntries* SvxConfigPage::FindParentForChild(
     return nullptr;
 }
 
-int SvxConfigPage::AddFunction(int nTarget, bool bAllowDuplicates)
+SvxConfigEntry *SvxConfigPage::CreateCommandFromSelection(const OUString &aURL)
 {
-    OUString aURL = GetScriptURL();
-    SvxConfigEntry* pParent = GetTopLevelSelection();
+    OUString aDisplayName;
 
-    if ( aURL.isEmpty() || pParent == nullptr )
-    {
-        return -1;
+    if ( aURL.isEmpty() ) {
+        return nullptr;
     }
 
-    OUString aDisplayName;
-
     auto aProperties = vcl::CommandInfoProvider::GetCommandProperties(aURL, m_aModuleId);
 
     if ( typeid(*pCurrentSaveInData) == typeid(ContextMenuSaveInData) )
@@ -1416,30 +1412,64 @@ int SvxConfigPage::AddFunction(int nTarget, bool bAllowDuplicates)
     else
         aDisplayName = vcl::CommandInfoProvider::GetLabelForCommand(aProperties);
 
-    SvxConfigEntry* pNewEntryData =
+    SvxConfigEntry* toret =
         new SvxConfigEntry( aDisplayName, aURL, false, /*bParentData*/false );
-    pNewEntryData->SetUserDefined();
+
+    toret->SetUserDefined();
 
     if ( aDisplayName.isEmpty() )
-        pNewEntryData->SetName( GetSelectedDisplayName() );
+        toret->SetName( GetSelectedDisplayName() );
 
-    // check that this function is not already in the menu
-    if ( !bAllowDuplicates )
+    return toret;
+}
+
+bool SvxConfigPage::IsCommandInMenuList(const SvxConfigEntry *pEntryData,
+                                        const SvxEntries *pEntries)
+{
+    bool toret = false;
+
+    if ( pEntries != nullptr
+      && pEntryData != nullptr )
     {
-        for (auto const& entry : *pParent->GetEntries())
+        for (auto const& entry : *pEntries)
         {
-            if ( entry->GetCommand() == pNewEntryData->GetCommand() )
-            {
-                std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(GetFrameWeld(),
-                                                          VclMessageType::Info, VclButtonsType::Ok, CuiResId(RID_SVXSTR_MNUCFG_ALREADY_INCLUDED)));
-                xBox->run();
-                delete pNewEntryData;
-                return -1;
-            }
+                if ( entry->GetCommand() == pEntryData->GetCommand() )
+                {
+                    toret = true;
+                    break;
+                }
         }
     }
 
-    return AppendEntry(pNewEntryData, nTarget);
+    return toret;
+}
+
+int SvxConfigPage::AddFunction(int nTarget, bool bAllowDuplicates)
+{
+    int toret = -1;
+    OUString aURL = GetScriptURL();
+    SvxConfigEntry* pParent = GetTopLevelSelection();
+
+    if ( aURL.isEmpty() || pParent == nullptr )
+    {
+        return -1;
+    }
+
+
+    SvxConfigEntry * pNewEntryData = CreateCommandFromSelection( aURL );
+
+    // check that this function is not already in the menu
+    if ( !bAllowDuplicates
+      && IsCommandInMenuList( pNewEntryData, pParent->GetEntries() )
+    )
+    {
+        delete pNewEntryData;
+    } else {
+        toret = AppendEntry( pNewEntryData, nTarget );
+    }
+
+    UpdateButtonStates();
+    return toret;
 }
 
 int SvxConfigPage::AppendEntry(
@@ -1599,6 +1629,8 @@ IMPL_LINK_NOARG(SvxConfigPage, SelectFunctionHdl, weld::TreeView&, void)
 
         m_xDescriptionField->set_text("");
     }
+
+    UpdateButtonStates();
 }
 
 IMPL_LINK_NOARG(SvxConfigPage, ImplUpdateDataHdl, Timer*, void)
diff --git a/cui/source/inc/cfg.hxx b/cui/source/inc/cfg.hxx
index c5b7c4848933..c1b492cb4b90 100644
--- a/cui/source/inc/cfg.hxx
+++ b/cui/source/inc/cfg.hxx
@@ -466,6 +466,11 @@ protected:
 
     void            ReloadTopLevelListBox( SvxConfigEntry const * pSelection = nullptr );
 
+    static bool     IsCommandInMenuList(const SvxConfigEntry *pEntryData,
+                                        const SvxEntries *pEntries);
+
+    SvxConfigEntry *CreateCommandFromSelection(const OUString &aURL);
+
 public:
 
     virtual ~SvxConfigPage() override;


More information about the Libreoffice-commits mailing list