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>
diff --git a/cui/inc/strings.hrc b/cui/inc/strings.hrc
index 74b0bcb..266f93b 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 4b3a69f..ced1a5f 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 848c689..b71e05e 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 8e098981..e3272a4 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 a0ba3ab..56365d7 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 2f7e0e4..471d9bc 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 555dba9e..bd9704d 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 1a03939..6093fb2 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>