[Libreoffice-commits] core.git: Branch 'feature/gsoc17-revamp-customize-dialog' - cui/inc cui/source cui/uiconfig

Muhammet Kara muhammet.kara at pardus.org.tr
Thu Aug 24 08:47:04 UTC 2017


 cui/inc/strings.hrc                           |    1 
 cui/source/customize/SvxMenuConfigPage.cxx    |   31 ++++++++++++++++++++++++++
 cui/source/customize/SvxToolbarConfigPage.cxx |   23 +++++++++++++++++++
 cui/source/customize/cfg.cxx                  |   22 ++++++++++++++++--
 cui/source/inc/SvxMenuConfigPage.hxx          |    1 
 cui/source/inc/SvxToolbarConfigPage.hxx       |    1 
 cui/source/inc/cfg.hxx                        |    4 +++
 cui/uiconfig/ui/menuassignpage.ui             |    2 -
 8 files changed, 82 insertions(+), 3 deletions(-)

New commits:
commit e0d03d929929dec937d3fbf97ebf7d9eef1806a0
Author: Muhammet Kara <muhammet.kara at pardus.org.tr>
Date:   Sun Aug 20 20:43:56 2017 +0300

    Implement "Reset" button in the Customize dialog
    
    For now, it works for the Toolbar and the Context Menu tabs.
    Normal top-level menus cannot be reset individually at the moment
    because they are sharing a single xml file, and the removeSettings()
    mathod doesn't provide per-item removal from within a single file.
    
    Change-Id: I42d62dc26130e4c03cf75a1ce6dc9ff367a58d47
    Reviewed-on: https://gerrit.libreoffice.org/41367
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Katarina Behrens <Katarina.Behrens at cib.de>

diff --git a/cui/inc/strings.hrc b/cui/inc/strings.hrc
index 74b0bcb4f80e..266f93bdd5de 100644
--- a/cui/inc/strings.hrc
+++ b/cui/inc/strings.hrc
@@ -69,6 +69,7 @@
 #define RID_SVXSTR_CONFIRM_MENU_RESET               NC_("RID_SVXSTR_CONFIRM_MENU_RESET", "The menu configuration for %SAVE IN SELECTION% will be reset to the default settings. Do you want to continue?")
 #define RID_SVXSTR_CONFIRM_TOOLBAR_RESET            NC_("RID_SVXSTR_CONFIRM_TOOLBAR_RESET", "The toolbar configuration for %SAVE IN SELECTION% will be reset to the default settings. Do you want to continue?")
 #define RID_SVXSTR_CONFIRM_RESTORE_DEFAULT          NC_("RID_SVXSTR_CONFIRM_RESTORE_DEFAULT", "This will delete all changes previously made to this toolbar. Do you really want to reset the toolbar?")
+#define RID_SVXSTR_CONFIRM_RESTORE_DEFAULT_MENU     NC_("RID_SVXSTR_CONFIRM_RESTORE_DEFAULT_MENU", "This will delete all changes previously made to this context menu. Do you really want to reset?")
 #define RID_SVXSTR_MNUCFG_ALREADY_INCLUDED          NC_("RID_SVXSTR_MNUCFG_ALREADY_INCLUDED", "Function is already included in this popup.")
 #define RID_SVXSTR_LABEL_NEW_NAME                   NC_("RID_SVXSTR_LABEL_NEW_NAME", "~New name")
 #define RID_SVXSTR_RENAME_MENU                      NC_("RID_SVXSTR_RENAME_MENU", "Rename Menu")
diff --git a/cui/source/customize/SvxMenuConfigPage.cxx b/cui/source/customize/SvxMenuConfigPage.cxx
index 32eb77e83a6c..decf6a9d251b 100644
--- a/cui/source/customize/SvxMenuConfigPage.cxx
+++ b/cui/source/customize/SvxMenuConfigPage.cxx
@@ -130,6 +130,9 @@ SvxMenuConfigPage::SvxMenuConfigPage(vcl::Window *pParent, const SfxItemSet& rSe
 
     m_pInsertBtn->SetSelectHdl(
         LINK( this, SvxMenuConfigPage, InsertHdl ) );
+    m_pResetBtn->SetClickHdl(
+        LINK( this, SvxMenuConfigPage, ResetMenuHdl ) );
+
 }
 
 SvxMenuConfigPage::~SvxMenuConfigPage()
@@ -360,6 +363,34 @@ IMPL_LINK( SvxMenuConfigPage, InsertHdl, MenuButton *, pButton, void )
     }
 }
 
+IMPL_LINK_NOARG( SvxMenuConfigPage, ResetMenuHdl, Button *, void )
+{
+    SvxConfigEntry* pMenuData = GetTopLevelSelection();
+
+    ScopedVclPtrInstance<MessageDialog> qbox(this,
+        CuiResId(RID_SVXSTR_CONFIRM_RESTORE_DEFAULT_MENU), VclMessageType::Question, VclButtonsType::YesNo);
+
+    // Resetting individual top-level menus is not possible at the moment.
+    // So we are resetting only if it is a context menu
+    if (!m_bIsMenuBar && qbox->Execute() == RET_YES)
+    {
+        sal_Int32 nPos = m_pTopLevelListBox->GetSelectEntryPos();
+        ContextMenuSaveInData* pSaveInData = static_cast< ContextMenuSaveInData* >(GetSaveInData());
+
+        pSaveInData->ResetContextMenu(pMenuData);
+
+        // ensure that the UI is cleared before populating it
+        m_pTopLevelListBox->Clear();
+        m_pContentsListBox->Clear();
+
+        ReloadTopLevelListBox();
+
+        // Reselect the resetted menu
+        m_pTopLevelListBox->SelectEntryPos(nPos);
+        m_pTopLevelListBox->GetSelectHdl().Call(*m_pTopLevelListBox);
+    }
+}
+
 SaveInData* SvxMenuConfigPage::CreateSaveInData(
     const css::uno::Reference< css::ui::XUIConfigurationManager >& xCfgMgr,
     const css::uno::Reference< css::ui::XUIConfigurationManager >& xParentCfgMgr,
diff --git a/cui/source/customize/SvxToolbarConfigPage.cxx b/cui/source/customize/SvxToolbarConfigPage.cxx
index c9a87a4b0e23..fdf1837952d7 100644
--- a/cui/source/customize/SvxToolbarConfigPage.cxx
+++ b/cui/source/customize/SvxToolbarConfigPage.cxx
@@ -140,6 +140,9 @@ SvxToolbarConfigPage::SvxToolbarConfigPage(vcl::Window *pParent, const SfxItemSe
 
     m_pInsertBtn->SetSelectHdl(
         LINK( this, SvxToolbarConfigPage, InsertHdl ) );
+    m_pResetBtn->SetClickHdl(
+        LINK( this, SvxToolbarConfigPage, ResetToolbarHdl ) );
+
     // "Insert Submenu" is irrelevant to the toolbars
     PopupMenu* pPopup = m_pInsertBtn->GetPopupMenu();
     pPopup->EnableItem(OString( "insertsubmenu"), false );
@@ -373,6 +376,26 @@ IMPL_LINK( SvxToolbarConfigPage, InsertHdl, MenuButton *, pButton, void )
     }
 }
 
+IMPL_LINK_NOARG( SvxToolbarConfigPage, ResetToolbarHdl, Button *, void )
+{
+    sal_Int32 nSelectionPos = m_pTopLevelListBox->GetSelectEntryPos();
+
+    SvxConfigEntry* pToolbar =
+        static_cast<SvxConfigEntry*>(m_pTopLevelListBox->GetEntryData( nSelectionPos ));
+
+    ScopedVclPtrInstance<MessageDialog> qbox(this,
+        CuiResId(RID_SVXSTR_CONFIRM_RESTORE_DEFAULT), VclMessageType::Question, VclButtonsType::YesNo);
+
+    if ( qbox->Execute() == RET_YES )
+    {
+        ToolbarSaveInData* pSaveInData =
+            static_cast<ToolbarSaveInData*>(GetSaveInData());
+
+        pSaveInData->RestoreToolbar( pToolbar );
+
+        m_pTopLevelListBox->GetSelectHdl().Call( *m_pTopLevelListBox );
+    }
+}
 
 void SvxToolbarConfigPage::UpdateButtonStates()
 {
diff --git a/cui/source/customize/cfg.cxx b/cui/source/customize/cfg.cxx
index 3b30221b8450..8965d4094fe2 100644
--- a/cui/source/customize/cfg.cxx
+++ b/cui/source/customize/cfg.cxx
@@ -923,8 +923,24 @@ void ContextMenuSaveInData::Reset()
         {
             GetConfigManager()->removeSettings( pEntry->GetCommand() );
         }
-        catch ( const css::uno::Exception& )
-        {}
+        catch ( const css::uno::Exception& e )
+        {
+            SAL_WARN("cui.customize", "Exception caught while resetting context menus: " << e.Message);
+        }
+    }
+    PersistChanges( GetConfigManager() );
+    m_pRootEntry.reset();
+}
+
+void ContextMenuSaveInData::ResetContextMenu( SvxConfigEntry* pEntry )
+{
+    try
+    {
+        GetConfigManager()->removeSettings( pEntry->GetCommand() );
+    }
+    catch ( const css::uno::Exception& e )
+    {
+        SAL_WARN("cui.customize", "Exception caught while resetting context menu: " << e.Message);
     }
     PersistChanges( GetConfigManager() );
     m_pRootEntry.reset();
@@ -1144,6 +1160,7 @@ SvxConfigPage::SvxConfigPage(vcl::Window *pParent, const SfxItemSet& rSet)
     get(m_pMoveDownButton, "down");
     get(m_pSaveInListBox, "savein");
     get(m_pInsertBtn, "insert");
+    get(m_pResetBtn, "resetbtn");
     get(m_pDescriptionField, "desc");
     m_pDescriptionField->set_height_request(m_pDescriptionField->GetTextHeight()*4);
     get(m_pEntries, "entries");
@@ -1179,6 +1196,7 @@ void SvxConfigPage::dispose()
     m_pMoveDownButton.clear();
     m_pSaveInListBox.clear();
     m_pInsertBtn.clear();
+    m_pResetBtn.clear();
     m_pDescriptionField.clear();
 
     m_pContentsListBox.disposeAndClear();
diff --git a/cui/source/inc/SvxMenuConfigPage.hxx b/cui/source/inc/SvxMenuConfigPage.hxx
index a0ba3abd1cbe..56365d79aa93 100644
--- a/cui/source/inc/SvxMenuConfigPage.hxx
+++ b/cui/source/inc/SvxMenuConfigPage.hxx
@@ -60,6 +60,7 @@ private:
     DECL_LINK( RemoveCommandHdl, Button *, void );
 
     DECL_LINK( InsertHdl, MenuButton *, void );
+    DECL_LINK( ResetMenuHdl, Button *, void );
 
     void            Init() override;
     void            UpdateButtonStates() override;
diff --git a/cui/source/inc/SvxToolbarConfigPage.hxx b/cui/source/inc/SvxToolbarConfigPage.hxx
index 2f7e0e48331e..471d9bc0d6d3 100644
--- a/cui/source/inc/SvxToolbarConfigPage.hxx
+++ b/cui/source/inc/SvxToolbarConfigPage.hxx
@@ -61,6 +61,7 @@ private:
     DECL_LINK( RemoveCommandHdl, Button *, void );
 
     DECL_LINK( InsertHdl, MenuButton *, void );
+    DECL_LINK( ResetToolbarHdl, Button *, void );
 
     void            UpdateButtonStates() override;
     short           QueryReset() override;
diff --git a/cui/source/inc/cfg.hxx b/cui/source/inc/cfg.hxx
index 9bd115bd64b3..50558a537eab 100644
--- a/cui/source/inc/cfg.hxx
+++ b/cui/source/inc/cfg.hxx
@@ -241,6 +241,8 @@ public:
     bool HasURL( const OUString& rURL ) override;
     void Reset() override;
     bool Apply() override;
+
+    void ResetContextMenu( SvxConfigEntry* pEntry );
 };
 
 class SvxConfigEntry
@@ -404,6 +406,8 @@ protected:
     VclPtr<ListBox>                            m_pSaveInListBox;
 
     VclPtr<MenuButton>                         m_pInsertBtn;
+    // Used to reset the selected toolbar/menu/context menu
+    VclPtr<PushButton>                         m_pResetBtn;
 
     // Middle buttons
     VclPtr<PushButton>                         m_pAddCommandButton;
diff --git a/cui/uiconfig/ui/menuassignpage.ui b/cui/uiconfig/ui/menuassignpage.ui
index 1a0393941fb6..6093fb2ab644 100644
--- a/cui/uiconfig/ui/menuassignpage.ui
+++ b/cui/uiconfig/ui/menuassignpage.ui
@@ -183,7 +183,7 @@
                           </packing>
                         </child>
                         <child>
-                          <object class="GtkButton">
+                          <object class="GtkButton" id="resetbtn">
                             <property name="label" translatable="yes">Reset</property>
                             <property name="visible">True</property>
                             <property name="can_focus">True</property>


More information about the Libreoffice-commits mailing list