diff options
author | Muhammet Kara <muhammet.kara@pardus.org.tr> | 2017-08-20 20:43:56 +0300 |
---|---|---|
committer | Katarina Behrens <Katarina.Behrens@cib.de> | 2017-09-04 22:39:47 +0200 |
commit | 46d993c352c2f34af532ffd9034ebf7bd3ab9691 (patch) | |
tree | b4e474200ed10a6a0dcc3d1e74b9cadb00585893 /cui | |
parent | 7e0ecdecb1131bffd263d0e51583a25991b9a878 (diff) |
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@libreoffice.org>
Reviewed-by: Katarina Behrens <Katarina.Behrens@cib.de>
Diffstat (limited to 'cui')
-rw-r--r-- | cui/inc/strings.hrc | 1 | ||||
-rw-r--r-- | cui/source/customize/SvxMenuConfigPage.cxx | 31 | ||||
-rw-r--r-- | cui/source/customize/SvxToolbarConfigPage.cxx | 23 | ||||
-rw-r--r-- | cui/source/customize/cfg.cxx | 22 | ||||
-rw-r--r-- | cui/source/inc/SvxMenuConfigPage.hxx | 1 | ||||
-rw-r--r-- | cui/source/inc/SvxToolbarConfigPage.hxx | 1 | ||||
-rw-r--r-- | cui/source/inc/cfg.hxx | 4 | ||||
-rw-r--r-- | cui/uiconfig/ui/menuassignpage.ui | 2 |
8 files changed, 82 insertions, 3 deletions
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 4b3a69f6e2db..ced1a5f0ec92 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 848c68980607..b71e05e66a3b 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 8e0989810b1d..e3272a4c9dd5 100644 --- a/cui/source/customize/cfg.cxx +++ b/cui/source/customize/cfg.cxx @@ -924,8 +924,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(); @@ -1145,6 +1161,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"); @@ -1180,6 +1197,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 555dba9ee30b..bd9704d25420 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> |