summaryrefslogtreecommitdiff
path: root/svx
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2023-03-23 10:47:32 +0000
committerAdolfo Jayme Barrientos <fitojb@ubuntu.com>2023-03-26 01:30:50 +0000
commit830c69ac5ed9018d11d25bfb70a534d1a4b55c3d (patch)
tree627fb140e711778c5758109fa26ddf6cf4abe19d /svx
parentea705802b93e90d6cd251fda56dc9896b2caa52b (diff)
Resolves: tdf#154322 if entries are disabled while menu is active, update it
Change-Id: Id5cad5f2f4ac21db8675de16f1bc0ceeff39fe6c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149427 Tested-by: Jenkins Reviewed-by: Adolfo Jayme Barrientos <fitojb@ubuntu.com>
Diffstat (limited to 'svx')
-rw-r--r--svx/source/form/datanavi.cxx61
-rw-r--r--svx/source/inc/datanavi.hxx8
2 files changed, 43 insertions, 26 deletions
diff --git a/svx/source/form/datanavi.cxx b/svx/source/form/datanavi.cxx
index 992195e05778..5d3242e84683 100644
--- a/svx/source/form/datanavi.cxx
+++ b/svx/source/form/datanavi.cxx
@@ -147,32 +147,36 @@ namespace svxform
}
std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(m_xItemList.get(), "svx/ui/formdatamenu.ui"));
- std::unique_ptr<weld::Menu> xMenu(xBuilder->weld_menu("menu"));
+ m_xMenu = xBuilder->weld_menu("menu");
+ m_aRemovedMenuEntries.clear();
if (DGTInstance == m_eGroup)
- xMenu->remove("additem");
+ m_aRemovedMenuEntries.insert("additem");
else
{
- xMenu->remove("addelement");
- xMenu->remove("addattribute");
+ m_aRemovedMenuEntries.insert("addelement");
+ m_aRemovedMenuEntries.insert("addattribute");
if (DGTSubmission == m_eGroup)
{
- xMenu->set_label("additem", SvxResId(RID_STR_DATANAV_ADD_SUBMISSION));
- xMenu->set_label("edit", SvxResId(RID_STR_DATANAV_EDIT_SUBMISSION));
- xMenu->set_label("delete", SvxResId(RID_STR_DATANAV_REMOVE_SUBMISSION));
+ m_xMenu->set_label("additem", SvxResId(RID_STR_DATANAV_ADD_SUBMISSION));
+ m_xMenu->set_label("edit", SvxResId(RID_STR_DATANAV_EDIT_SUBMISSION));
+ m_xMenu->set_label("delete", SvxResId(RID_STR_DATANAV_REMOVE_SUBMISSION));
}
else
{
- xMenu->set_label("additem", SvxResId(RID_STR_DATANAV_ADD_BINDING));
- xMenu->set_label("edit", SvxResId(RID_STR_DATANAV_EDIT_BINDING));
- xMenu->set_label("delete", SvxResId(RID_STR_DATANAV_REMOVE_BINDING));
+ m_xMenu->set_label("additem", SvxResId(RID_STR_DATANAV_ADD_BINDING));
+ m_xMenu->set_label("edit", SvxResId(RID_STR_DATANAV_EDIT_BINDING));
+ m_xMenu->set_label("delete", SvxResId(RID_STR_DATANAV_REMOVE_BINDING));
}
}
- EnableMenuItems(xMenu.get());
- OString sCommand = xMenu->popup_at_rect(m_xItemList.get(), tools::Rectangle(aPos, Size(1,1)));
+ for (const auto& rRemove : m_aRemovedMenuEntries)
+ m_xMenu->remove(rRemove);
+ EnableMenuItems();
+ OString sCommand = m_xMenu->popup_at_rect(m_xItemList.get(), tools::Rectangle(aPos, Size(1,1)));
if (!sCommand.isEmpty())
DoMenuAction(sCommand);
+ m_xMenu.reset();
return true;
}
@@ -242,7 +246,7 @@ namespace svxform
IMPL_LINK_NOARG(XFormsPage, ItemSelectHdl, weld::TreeView&, void)
{
- EnableMenuItems(nullptr);
+ EnableMenuItems();
PrepDnD();
}
@@ -674,7 +678,7 @@ namespace svxform
}
m_pNaviWin->DisableNotify( false );
- EnableMenuItems( nullptr );
+ EnableMenuItems();
if ( bIsDocModified )
svxform::DataNavigatorWindow::SetDocModified();
return bHandled;
@@ -1103,7 +1107,7 @@ namespace svxform
break;
}
- EnableMenuItems( nullptr );
+ EnableMenuItems();
return sRet;
}
@@ -1161,7 +1165,14 @@ namespace svxform
return DoToolBoxAction(rMenuID);
}
- void XFormsPage::EnableMenuItems(weld::Menu* pMenu)
+ void XFormsPage::SetMenuEntrySensitive(const OString& rIdent, bool bSensitive)
+ {
+ if (m_aRemovedMenuEntries.find(rIdent) != m_aRemovedMenuEntries.end())
+ return;
+ m_xMenu->set_sensitive(rIdent, bSensitive);
+ }
+
+ void XFormsPage::EnableMenuItems()
{
bool bEnableAdd = false;
bool bEnableEdit = false;
@@ -1212,13 +1223,13 @@ namespace svxform
m_xToolBox->set_item_sensitive("edit", bEnableEdit);
m_xToolBox->set_item_sensitive("delete", bEnableRemove);
- if (pMenu)
+ if (m_xMenu)
{
- pMenu->set_sensitive("additem", bEnableAdd);
- pMenu->set_sensitive("addelement", bEnableAdd);
- pMenu->set_sensitive("addattribute", bEnableAdd);
- pMenu->set_sensitive("edit", bEnableEdit);
- pMenu->set_sensitive("delete", bEnableRemove);
+ SetMenuEntrySensitive("additem", bEnableAdd);
+ SetMenuEntrySensitive("addelement", bEnableAdd);
+ SetMenuEntrySensitive("addattribute", bEnableAdd);
+ SetMenuEntrySensitive("edit", bEnableEdit);
+ SetMenuEntrySensitive("delete", bEnableRemove);
}
if ( DGTInstance != m_eGroup )
return;
@@ -1247,10 +1258,10 @@ namespace svxform
}
m_xToolBox->set_item_label("edit", SvxResId(pResId1));
m_xToolBox->set_item_label("delete", SvxResId(pResId2));
- if (pMenu)
+ if (m_xMenu)
{
- pMenu->set_label("edit", SvxResId( pResId1 ) );
- pMenu->set_label("delete", SvxResId( pResId2 ) );
+ m_xMenu->set_label("edit", SvxResId( pResId1 ) );
+ m_xMenu->set_label("delete", SvxResId( pResId2 ) );
}
}
diff --git a/svx/source/inc/datanavi.hxx b/svx/source/inc/datanavi.hxx
index f1564fd20e8a..b165b9a94531 100644
--- a/svx/source/inc/datanavi.hxx
+++ b/svx/source/inc/datanavi.hxx
@@ -20,6 +20,7 @@
#define INCLUDED_SVX_SOURCE_INC_DATANAVI_HXX
#include <config_options.h>
+#include <o3tl/sorted_vector.hxx>
#include <vcl/builderpage.hxx>
#include <vcl/idle.hxx>
#include <vcl/transfer.hxx>
@@ -184,9 +185,12 @@ namespace svxform
weld::Container* m_pParent;
std::unique_ptr<weld::Toolbar> m_xToolBox;
+ std::unique_ptr<weld::Menu> m_xMenu;
std::unique_ptr<weld::TreeView> m_xItemList;
std::unique_ptr<weld::TreeIter> m_xScratchIter;
+ o3tl::sorted_vector<OString> m_aRemovedMenuEntries;
+
DataTreeDropTarget m_aDropHelper;
css::uno::Reference< css::xforms::XFormsUIHelper1 >
@@ -220,6 +224,8 @@ namespace svxform
void DeleteAndClearTree();
+ void SetMenuEntrySensitive(const OString& rIdent, bool bSensitive);
+
public:
XFormsPage(weld::Container* pParent, DataNavigatorWindow* _pNaviWin, DataGroupType _eGroup);
virtual ~XFormsPage() override;
@@ -230,7 +236,7 @@ namespace svxform
OUString LoadInstance(const css::uno::Sequence< css::beans::PropertyValue >& _xPropSeq);
bool DoMenuAction(std::string_view rMenuID);
- void EnableMenuItems(weld::Menu* pMenu);
+ void EnableMenuItems();
const OUString& GetInstanceName() const { return m_sInstanceName; }
const OUString& GetInstanceURL() const { return m_sInstanceURL; }