diff --git a/cui/source/customize/SvxMenuConfigPage.cxx b/cui/source/customize/SvxMenuConfigPage.cxx index d8d1d86387d2..72a3d350125e 100644 --- a/cui/source/customize/SvxMenuConfigPage.cxx +++ b/cui/source/customize/SvxMenuConfigPage.cxx @@ -45,7 +45,8 @@ SvxMenuConfigPage::SvxMenuConfigPage(weld::Container* pPage, weld::DialogControl m_xContentsListBox.reset( new SvxMenuEntriesListBox(m_xBuilder->weld_tree_view(u"menucontents"_ustr), this)); weld::TreeView& rTreeView = m_xContentsListBox->get_widget(); - m_xDropTargetHelper.reset(new SvxConfigPageFunctionDropTarget(*this, rTreeView)); + m_xDropTargetHelper.reset(new SvxConfigPageFunctionDropTarget( + *this, rTreeView, m_xFunctions->get_widget(), LINK(this, SvxMenuConfigPage, DropHdl))); rTreeView.connect_size_allocate(LINK(this, SvxMenuConfigPage, MenuEntriesSizeAllocHdl)); Size aSize(m_xFunctions->get_size_request()); rTreeView.set_size_request(aSize.Width(), aSize.Height()); @@ -106,6 +107,8 @@ void SvxMenuConfigPage::ListModified() UpdateButtonStates(); } +IMPL_LINK(SvxMenuConfigPage, DropHdl, int, nTarget, void) { AddCommand(nTarget, false); } + IMPL_LINK(SvxMenuConfigPage, MenuEntriesSizeAllocHdl, const Size&, rSize, void) { weld::TreeView& rTreeView = m_xContentsListBox->get_widget(); @@ -351,9 +354,9 @@ IMPL_LINK_NOARG(SvxMenuConfigPage, SelectCategory, weld::ComboBox&, void) SelectFunctionHdl(m_xFunctions->get_widget()); } -IMPL_LINK_NOARG(SvxMenuConfigPage, AddCommandHdl, weld::Button&, void) +void SvxMenuConfigPage::AddCommand(int nTarget, bool bAfter) { - int nPos = AddFunction(-1, /*bAllowDuplicates*/ false); + int nPos = AddFunction(nTarget, /*bAllowDuplicates*/ false, bAfter); if (nPos == -1) return; weld::TreeView& rTreeView = m_xContentsListBox->get_widget(); @@ -361,6 +364,8 @@ IMPL_LINK_NOARG(SvxMenuConfigPage, AddCommandHdl, weld::Button&, void) InsertEntryIntoUI(pEntry, rTreeView, nPos, true); } +IMPL_LINK_NOARG(SvxMenuConfigPage, AddCommandHdl, weld::Button&, void) { AddCommand(-1, true); } + IMPL_LINK_NOARG(SvxMenuConfigPage, RemoveCommandHdl, weld::Button&, void) { DeleteSelectedContent(); @@ -377,7 +382,7 @@ IMPL_LINK(SvxMenuConfigPage, InsertHdl, const OUString&, rIdent, void) { SvxConfigEntry* pNewEntryData = new SvxConfigEntry; pNewEntryData->SetUserDefined(); - int nPos = AppendEntry(pNewEntryData, -1); + int nPos = AppendEntry(pNewEntryData, -1, true); InsertEntryIntoUI(pNewEntryData, rTreeView, nPos, true); } else if (rIdent == "insertsubmenu") @@ -398,7 +403,7 @@ IMPL_LINK(SvxMenuConfigPage, InsertHdl, const OUString&, rIdent, void) pNewEntryData->SetName(aNewName); pNewEntryData->SetUserDefined(); - int nPos = AppendEntry(pNewEntryData, -1); + int nPos = AppendEntry(pNewEntryData, -1, true); InsertEntryIntoUI(pNewEntryData, rTreeView, nPos, true); ReloadTopLevelListBox(); diff --git a/cui/source/customize/SvxNotebookbarConfigPage.cxx b/cui/source/customize/SvxNotebookbarConfigPage.cxx index 7bde0055bcfc..081b49babfbf 100644 --- a/cui/source/customize/SvxNotebookbarConfigPage.cxx +++ b/cui/source/customize/SvxNotebookbarConfigPage.cxx @@ -117,8 +117,8 @@ SvxNotebookbarConfigPage::SvxNotebookbarConfigPage(weld::Container* pPage, m_xContentsListBox.reset( new SvxNotebookbarEntriesListBox(m_xBuilder->weld_tree_view(u"toolcontents"_ustr), this)); - m_xDropTargetHelper.reset( - new SvxConfigPageFunctionDropTarget(*this, m_xContentsListBox->get_widget())); + m_xDropTargetHelper.reset(new SvxConfigPageFunctionDropTarget( + *this, m_xContentsListBox->get_widget(), rCommandCategoryBox, Link())); weld::TreeView& rTreeView = m_xContentsListBox->get_widget(); Size aSize(m_xFunctions->get_size_request()); rTreeView.set_size_request(aSize.Width(), aSize.Height()); diff --git a/cui/source/customize/SvxToolbarConfigPage.cxx b/cui/source/customize/SvxToolbarConfigPage.cxx index bf506d4dbb43..e8323d18f9b1 100644 --- a/cui/source/customize/SvxToolbarConfigPage.cxx +++ b/cui/source/customize/SvxToolbarConfigPage.cxx @@ -55,8 +55,9 @@ SvxToolbarConfigPage::SvxToolbarConfigPage(weld::Container* pPage, m_xContentsListBox.reset( new SvxToolbarEntriesListBox(m_xBuilder->weld_tree_view(u"toolcontents"_ustr), this)); - m_xDropTargetHelper.reset( - new SvxConfigPageFunctionDropTarget(*this, m_xContentsListBox->get_widget())); + m_xDropTargetHelper.reset(new SvxConfigPageFunctionDropTarget( + *this, m_xContentsListBox->get_widget(), m_xFunctions->get_widget(), + LINK(this, SvxToolbarConfigPage, DropHdl))); weld::TreeView& rTreeView = m_xContentsListBox->get_widget(); Size aSize(m_xFunctions->get_size_request()); @@ -429,7 +430,9 @@ IMPL_LINK_NOARG(SvxToolbarConfigPage, SelectCategory, weld::ComboBox&, void) SelectFunctionHdl(m_xFunctions->get_widget()); } -IMPL_LINK_NOARG(SvxToolbarConfigPage, AddCommandHdl, weld::Button&, void) { AddFunction(); } +IMPL_LINK(SvxToolbarConfigPage, DropHdl, int, nTarget, void) { AddFunction(nTarget, false); } + +IMPL_LINK_NOARG(SvxToolbarConfigPage, AddCommandHdl, weld::Button&, void) { AddFunction(-1, true); } IMPL_LINK_NOARG(SvxToolbarConfigPage, RemoveCommandHdl, weld::Button&, void) { @@ -446,7 +449,7 @@ IMPL_LINK(SvxToolbarConfigPage, InsertHdl, const OUString&, rIdent, void) SvxConfigEntry* pNewEntryData = new SvxConfigEntry; pNewEntryData->SetUserDefined(); - int nPos = AppendEntry(pNewEntryData, -1); + int nPos = AppendEntry(pNewEntryData, -1, true); InsertEntryIntoUI(pNewEntryData, m_xContentsListBox->get_widget(), nPos); static_cast(GetSaveInData())->ApplyToolbar(pToolbar); @@ -770,7 +773,7 @@ void SvxToolbarConfigPage::SelectElement() UpdateButtonStates(); } -void SvxToolbarConfigPage::AddFunction(int nTarget) +void SvxToolbarConfigPage::AddFunction(int nTarget, bool bAfter) { SvxConfigEntry* pToolbar = GetTopLevelSelection(); @@ -778,7 +781,7 @@ void SvxToolbarConfigPage::AddFunction(int nTarget) return; // Add the command to the contents listbox of the selected toolbar - int nNewLBEntry = SvxConfigPage::AddFunction(nTarget, true /*bAllowDuplicates*/); + int nNewLBEntry = SvxConfigPage::AddFunction(nTarget, true /*bAllowDuplicates*/, bAfter); if (nNewLBEntry == -1) return; diff --git a/cui/source/customize/cfg.cxx b/cui/source/customize/cfg.cxx index 5c58eabdbfb0..013b7dba467d 100644 --- a/cui/source/customize/cfg.cxx +++ b/cui/source/customize/cfg.cxx @@ -1495,7 +1495,7 @@ bool SvxConfigPage::IsCommandInMenuList(const SvxConfigEntry *pEntryData, return toret; } -int SvxConfigPage::AddFunction(int nTarget, bool bAllowDuplicates) +int SvxConfigPage::AddFunction(int nTarget, bool bAllowDuplicates, bool bAfter) { int toret = -1; OUString aURL = GetScriptURL(); @@ -1516,7 +1516,7 @@ int SvxConfigPage::AddFunction(int nTarget, bool bAllowDuplicates) { delete pNewEntryData; } else { - toret = AppendEntry( pNewEntryData, nTarget ); + toret = AppendEntry( pNewEntryData, nTarget, bAfter ); } UpdateButtonStates(); @@ -1525,7 +1525,7 @@ int SvxConfigPage::AddFunction(int nTarget, bool bAllowDuplicates) int SvxConfigPage::AppendEntry( SvxConfigEntry* pNewEntryData, - int nTarget) + int nTarget, bool bAfter) { SvxConfigEntry* pTopLevelSelection = GetTopLevelSelection(); @@ -1562,9 +1562,12 @@ int SvxConfigPage::AppendEntry( ++nPos; } - // Now step past it to the entry after the currently selected one - ++iter; - ++nPos; + if (bAfter) + { + // Now step past it to the entry after the currently selected one + ++iter; + ++nPos; + } // Now add the new entry to the UI and to the parent's list if ( iter != end ) @@ -3198,15 +3201,36 @@ SvxIconChangeDialog::SvxIconChangeDialog(weld::Window *pWindow, const OUString& m_xLineEditDescription->set_text(rMessage); } -SvxConfigPageFunctionDropTarget::SvxConfigPageFunctionDropTarget(SvxConfigPage&rPage, weld::TreeView& rTreeView) +SvxConfigPageFunctionDropTarget::SvxConfigPageFunctionDropTarget(SvxConfigPage&rPage, + weld::TreeView& rTreeView, weld::TreeView& rFunctions, + const Link& rDropHdl) : weld::ReorderingDropTarget(rTreeView) , m_rPage(rPage) + , m_rFunctions(rFunctions) + , m_aDropHdl(rDropHdl) { } sal_Int8 SvxConfigPageFunctionDropTarget::ExecuteDrop(const ExecuteDropEvent& rEvt) { - sal_Int8 nRet = weld::ReorderingDropTarget::ExecuteDrop(rEvt); + sal_Int8 nRet; + weld::TreeView* pSource = m_rTreeView.get_drag_source(); + if (pSource && pSource == &m_rFunctions) + { + if (!m_aDropHdl.IsSet()) + return DND_ACTION_NONE; + std::unique_ptr xSource(m_rFunctions.make_iterator()); + if (!m_rFunctions.get_selected(xSource.get())) + return DND_ACTION_NONE; + std::unique_ptr xTarget(m_rTreeView.make_iterator()); + int nTargetPos = -1; + if (m_rTreeView.get_dest_row_at_pos(rEvt.maPosPixel, xTarget.get(), true)) + nTargetPos = m_rTreeView.get_iter_index_in_parent(*xTarget); + m_aDropHdl.Call(nTargetPos); + nRet = DND_ACTION_NONE; + } + else + nRet = weld::ReorderingDropTarget::ExecuteDrop(rEvt); m_rPage.ListModified(); return nRet;; } diff --git a/cui/source/inc/SvxMenuConfigPage.hxx b/cui/source/inc/SvxMenuConfigPage.hxx index 975c6de21eb6..08cebfde091d 100644 --- a/cui/source/inc/SvxMenuConfigPage.hxx +++ b/cui/source/inc/SvxMenuConfigPage.hxx @@ -43,8 +43,11 @@ private: DECL_LINK(ModifyItemHdl, const OUString&, void); DECL_LINK(ResetMenuHdl, weld::Button&, void); + DECL_LINK(DropHdl, int, void); DECL_LINK(MenuEntriesSizeAllocHdl, const Size&, void); + void AddCommand(int nTarget, bool bAfter); + virtual void ListModified() override; void Init() override; diff --git a/cui/source/inc/SvxToolbarConfigPage.hxx b/cui/source/inc/SvxToolbarConfigPage.hxx index 1637d7c0619a..ebf5c5403ea5 100644 --- a/cui/source/inc/SvxToolbarConfigPage.hxx +++ b/cui/source/inc/SvxToolbarConfigPage.hxx @@ -44,6 +44,7 @@ private: DECL_LINK(InsertHdl, const OUString&, void); DECL_LINK(ModifyItemHdl, const OUString&, void); DECL_LINK(ResetToolbarHdl, weld::Button&, void); + DECL_LINK(DropHdl, int, void); virtual void ListModified() override; @@ -59,7 +60,7 @@ public: const SfxItemSet& rItemSet); virtual ~SvxToolbarConfigPage() override; - void AddFunction(int nTarget = -1); + void AddFunction(int nTarget, bool bAfter); void MoveEntry(bool bMoveUp) override; diff --git a/cui/source/inc/cfg.hxx b/cui/source/inc/cfg.hxx index 1ae5b23a2999..43a355b5beb6 100644 --- a/cui/source/inc/cfg.hxx +++ b/cui/source/inc/cfg.hxx @@ -360,11 +360,16 @@ class SvxConfigPageFunctionDropTarget : public weld::ReorderingDropTarget { private: SvxConfigPage& m_rPage; + weld::TreeView& m_rFunctions; + Link m_aDropHdl; virtual sal_Int8 ExecuteDrop( const ExecuteDropEvent& rEvt ) override; public: - SvxConfigPageFunctionDropTarget(SvxConfigPage&rPage, weld::TreeView& rTreeView); + SvxConfigPageFunctionDropTarget(SvxConfigPage&rPage, + weld::TreeView& rTreeView, + weld::TreeView& rFunctions, + const Link& rDropHdl); }; class SvxConfigPage : public SfxTabPage @@ -449,7 +454,7 @@ protected: virtual void SelectElement() = 0; int AppendEntry(SvxConfigEntry* pNewEntryData, - int nTarget); + int nTarget, bool bAfter); void AddSubMenusToUI( std::u16string_view rBaseTitle, SvxConfigEntry const * pParentData ); @@ -486,7 +491,8 @@ public: const OUString& GetFileName() const { return m_sFileName; } int AddFunction(int nTarget, - bool bAllowDuplicates); + bool bAllowDuplicates, + bool bAfter); virtual void MoveEntry( bool bMoveUp ); diff --git a/cui/uiconfig/ui/menuassignpage.ui b/cui/uiconfig/ui/menuassignpage.ui index b545c193a352..b26a70f25497 100644 --- a/cui/uiconfig/ui/menuassignpage.ui +++ b/cui/uiconfig/ui/menuassignpage.ui @@ -328,6 +328,7 @@ True liststore1 False + True 1 True diff --git a/include/vcl/weldutils.hxx b/include/vcl/weldutils.hxx index 8a3291c42345..3ba0bac4c0a0 100644 --- a/include/vcl/weldutils.hxx +++ b/include/vcl/weldutils.hxx @@ -435,9 +435,9 @@ public: */ class VCL_DLLPUBLIC ReorderingDropTarget : public DropTargetHelper { +protected: weld::TreeView& m_rTreeView; -protected: virtual sal_Int8 AcceptDrop(const AcceptDropEvent& rEvt) override; virtual sal_Int8 ExecuteDrop(const ExecuteDropEvent& rEvt) override;