diff options
author | Andreas Heinisch <andreas.heinisch@yahoo.de> | 2020-07-14 19:45:51 +0200 |
---|---|---|
committer | Maxim Monastirsky <momonasmon@gmail.com> | 2020-09-21 01:39:22 +0200 |
commit | 327091048c8cbcad0178dfd8e06813153e861e5e (patch) | |
tree | f48cff9b847f81c53526e37faddcbbd347314aeb | |
parent | d3c870fcbfed4bbbcbc5d943c2526b353ad396c6 (diff) |
tdf#134331 - Added possibility to sort macros via context menu
The user now has the possibility to sort the entries in various macro
dialogs either alphabetically or in document order using a context menu.
Change-Id: I064947daa9f9bca05cb28e4b2f65ff1c92689ae9
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/98783
Tested-by: Jenkins
Reviewed-by: Maxim Monastirsky <momonasmon@gmail.com>
-rw-r--r-- | basctl/UIConfig_basicide.mk | 1 | ||||
-rw-r--r-- | basctl/source/basicide/macrodlg.cxx | 33 | ||||
-rw-r--r-- | basctl/source/basicide/macrodlg.hxx | 1 | ||||
-rw-r--r-- | basctl/uiconfig/basicide/ui/sortmenu.ui | 42 | ||||
-rw-r--r-- | cui/source/customize/cfgutil.cxx | 32 | ||||
-rw-r--r-- | cui/source/inc/cfgutil.hxx | 2 |
6 files changed, 109 insertions, 2 deletions
diff --git a/basctl/UIConfig_basicide.mk b/basctl/UIConfig_basicide.mk index 7593e5a83a62..2c23fbfb58af 100644 --- a/basctl/UIConfig_basicide.mk +++ b/basctl/UIConfig_basicide.mk @@ -53,6 +53,7 @@ $(eval $(call gb_UIConfig_add_uifiles,modules/BasicIDE,\ basctl/uiconfig/basicide/ui/modulepage \ basctl/uiconfig/basicide/ui/newlibdialog \ basctl/uiconfig/basicide/ui/organizedialog \ + basctl/uiconfig/basicide/ui/sortmenu \ )) # vim: set noet sw=4 ts=4: diff --git a/basctl/source/basicide/macrodlg.cxx b/basctl/source/basicide/macrodlg.cxx index 0ee787b970bf..24cb210ea7e3 100644 --- a/basctl/source/basicide/macrodlg.cxx +++ b/basctl/source/basicide/macrodlg.cxx @@ -39,6 +39,7 @@ #include <sfx2/request.hxx> #include <sfx2/sfxsids.hrc> #include <tools/debug.hxx> +#include <vcl/commandevent.hxx> #include <vcl/svapp.hxx> #include <vcl/weld.hxx> #include <osl/diagnose.h> @@ -76,8 +77,6 @@ MacroChooser::MacroChooser(weld::Window* pParnt, const Reference< frame::XFrame { m_xBasicBox->set_size_request(m_xBasicBox->get_approximate_digit_width() * 30, m_xBasicBox->get_height_rows(18)); m_xMacroBox->set_size_request(m_xMacroBox->get_approximate_digit_width() * 30, m_xMacroBox->get_height_rows(18)); - // tdf#70813 The macros should be listed alphabetically - m_xMacroBox->make_sorted(); m_aMacrosInTxtBaseStr = m_xMacrosInTxt->get_label(); @@ -102,6 +101,7 @@ MacroChooser::MacroChooser(weld::Window* pParnt, const Reference< frame::XFrame m_xMacroBox->connect_row_activated( LINK( this, MacroChooser, MacroDoubleClickHdl ) ); m_xMacroBox->connect_changed( LINK( this, MacroChooser, MacroSelectHdl ) ); + m_xMacroBox->connect_popup_menu( LINK( this, MacroChooser, ContextMenuHdl ) ); m_xBasicBox->SetMode( BrowseMode::Modules ); @@ -755,6 +755,35 @@ IMPL_LINK(MacroChooser, ButtonHdl, weld::Button&, rButton, void) } } +IMPL_LINK(MacroChooser, ContextMenuHdl, const CommandEvent&, rCEvt, bool) +{ + if (rCEvt.GetCommand() != CommandEventId::ContextMenu || !m_xMacroBox->n_children()) + return false; + + std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(m_xMacroBox.get(), "modules/BasicIDE/ui/sortmenu.ui")); + std::unique_ptr<weld::Menu> xPopup(xBuilder->weld_menu("sortmenu")); + std::unique_ptr<weld::Menu> xDropMenu(xBuilder->weld_menu("sortsubmenu")); + xDropMenu->set_active("alphabetically", m_xMacroBox->get_sort_order()); + xDropMenu->set_active("properorder", !m_xMacroBox->get_sort_order()); + + OString sCommand(xPopup->popup_at_rect(m_xMacroBox.get(), tools::Rectangle(rCEvt.GetMousePosPixel(), Size(1,1)))); + if (sCommand == "alphabetically") + { + m_xMacroBox->make_sorted(); + } + else if (sCommand == "properorder") + { + m_xMacroBox->make_unsorted(); + BasicSelectHdl(m_xBasicBox->get_widget()); + } + else if (!sCommand.isEmpty()) + { + SAL_WARN("basctl.basicide", "Unknown context menu action: " << sCommand ); + } + + return true; +} + void MacroChooser::UpdateFields() { auto nMacroEntry = m_xMacroBox->get_selected_index(); diff --git a/basctl/source/basicide/macrodlg.hxx b/basctl/source/basicide/macrodlg.hxx index 0d239477206a..0e50ee5de02b 100644 --- a/basctl/source/basicide/macrodlg.hxx +++ b/basctl/source/basicide/macrodlg.hxx @@ -58,6 +58,7 @@ private: DECL_LINK(MacroDoubleClickHdl, weld::TreeView&, bool); DECL_LINK(BasicSelectHdl, weld::TreeView&, void); DECL_LINK(EditModifyHdl, weld::Entry&, void); + DECL_LINK(ContextMenuHdl, const CommandEvent&, bool); DECL_LINK(ButtonHdl, weld::Button&, void); void CheckButtons(); diff --git a/basctl/uiconfig/basicide/ui/sortmenu.ui b/basctl/uiconfig/basicide/ui/sortmenu.ui new file mode 100644 index 000000000000..c82c5abb2186 --- /dev/null +++ b/basctl/uiconfig/basicide/ui/sortmenu.ui @@ -0,0 +1,42 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- Generated with glade 3.20.0 --> +<interface domain="basctl"> + <requires lib="gtk+" version="3.18"/> + <object class="GtkMenu" id="sortmenu"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <child> + <object class="GtkMenuItem"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes" context="sortmenu|macrosort">_Sorting</property> + <property name="use_underline">True</property> + <child type="submenu"> + <object class="GtkMenu" id="sortsubmenu"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <child> + <object class="GtkRadioMenuItem" id="alphabetically"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes" context="sortmenu|alphabetically">_Alphabetically</property> + <property name="use_underline">True</property> + <property name="draw_as_radio">True</property> + <property name="group">properorder</property> + </object> + </child> + <child> + <object class="GtkRadioMenuItem" id="properorder"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes" context="sortmenu|properorder">_Proper order</property> + <property name="draw_as_radio">True</property> + <property name="use_underline">True</property> + </object> + </child> + </object> + </child> + </object> + </child> + </object> +</interface>
\ No newline at end of file diff --git a/cui/source/customize/cfgutil.cxx b/cui/source/customize/cfgutil.cxx index 13203e0926a9..f1c5ccef7221 100644 --- a/cui/source/customize/cfgutil.cxx +++ b/cui/source/customize/cfgutil.cxx @@ -49,6 +49,7 @@ #include <osl/diagnose.h> #include <dialmgr.hxx> #include <tools/diagnose_ex.h> +#include <vcl/commandevent.hxx> #include <vcl/commandinfoprovider.hxx> #include <vcl/help.hxx> #include <vcl/svapp.hxx> @@ -1105,6 +1106,7 @@ SvxScriptSelectorDialog::SvxScriptSelectorDialog( LINK( this, SvxScriptSelectorDialog, SelectHdl ) ); m_xCommands->connect_changed( LINK( this, SvxScriptSelectorDialog, SelectHdl ) ); m_xCommands->connect_row_activated( LINK( this, SvxScriptSelectorDialog, FunctionDoubleClickHdl ) ); + m_xCommands->connect_popup_menu( LINK( this, SvxScriptSelectorDialog, ContextMenuHdl ) ); m_xOKButton->connect_clicked( LINK( this, SvxScriptSelectorDialog, ClickHdl ) ); m_xCancelButton->connect_clicked( LINK( this, SvxScriptSelectorDialog, ClickHdl ) ); @@ -1145,6 +1147,36 @@ IMPL_LINK_NOARG(SvxScriptSelectorDialog, FunctionDoubleClickHdl, weld::TreeView& return true; } +IMPL_LINK(SvxScriptSelectorDialog, ContextMenuHdl, const CommandEvent&, rCEvt, bool) +{ + weld::TreeView& xTreeView = m_xCommands->get_widget(); + if (rCEvt.GetCommand() != CommandEventId::ContextMenu || !xTreeView.n_children()) + return false; + + std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(&xTreeView, "modules/BasicIDE/ui/sortmenu.ui")); + std::unique_ptr<weld::Menu> xPopup(xBuilder->weld_menu("sortmenu")); + std::unique_ptr<weld::Menu> xDropMenu(xBuilder->weld_menu("sortsubmenu")); + xDropMenu->set_active("alphabetically", xTreeView.get_sort_order()); + xDropMenu->set_active("properorder", !xTreeView.get_sort_order()); + + OString sCommand(xPopup->popup_at_rect(&xTreeView, tools::Rectangle(rCEvt.GetMousePosPixel(), Size(1,1)))); + if (sCommand == "alphabetically") + { + xTreeView.make_sorted(); + } + else if (sCommand == "properorder") + { + xTreeView.make_unsorted(); + m_xCategories->GroupSelected(); + } + else if (!sCommand.isEmpty()) + { + SAL_WARN("cui.customize", "Unknown context menu action: " << sCommand ); + } + + return true; +} + // Check if command is selected and enable the OK button accordingly // Grab the help text for this id if available and update the description field void diff --git a/cui/source/inc/cfgutil.hxx b/cui/source/inc/cfgutil.hxx index b9ee13450422..c4d50e2aeb12 100644 --- a/cui/source/inc/cfgutil.hxx +++ b/cui/source/inc/cfgutil.hxx @@ -111,6 +111,7 @@ public: CuiConfigFunctionListBox(std::unique_ptr<weld::TreeView> xTreeView); void set_sensitive(bool bSensitive) { m_xTreeView->set_sensitive(bSensitive); } void connect_changed(const Link<weld::TreeView&, void>& rLink) { m_xTreeView->connect_changed(rLink); } + void connect_popup_menu(const Link<const CommandEvent&, bool>& rLink) { m_xTreeView->connect_popup_menu(rLink); } void connect_row_activated(const Link<weld::TreeView&, bool>& rLink) { m_xTreeView->connect_row_activated(rLink); } void freeze() { m_xTreeView->freeze(); } void thaw() { m_xTreeView->thaw(); } @@ -245,6 +246,7 @@ class SvxScriptSelectorDialog : public weld::GenericDialogController DECL_LINK(ClickHdl, weld::Button&, void); DECL_LINK(SelectHdl, weld::TreeView&, void); DECL_LINK(FunctionDoubleClickHdl, weld::TreeView&, bool); + DECL_LINK(ContextMenuHdl, const CommandEvent&, bool); void UpdateUI(); |