diff options
author | Caolán McNamara <caolanm@redhat.com> | 2016-10-17 10:48:45 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2016-10-17 13:59:37 +0100 |
commit | 8bff380fed975dc7f6365b7f2ca7213c3cf4d302 (patch) | |
tree | f90807c268d09247adef1896e44a7d2bfcd6c398 /vcl | |
parent | 26c99e42db233e375a007c49e1e903359caa1ce3 (diff) |
Related: tdf#103166 but still allow removing placeholder submenus
Change-Id: I3ed5feaebcd074562d5412dca9e5cb4086a7df39
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/unx/gtk/gtksalmenu.cxx | 63 |
1 files changed, 39 insertions, 24 deletions
diff --git a/vcl/unx/gtk/gtksalmenu.cxx b/vcl/unx/gtk/gtksalmenu.cxx index fa52fc9a8097..0fbaf88b7c78 100644 --- a/vcl/unx/gtk/gtksalmenu.cxx +++ b/vcl/unx/gtk/gtksalmenu.cxx @@ -74,6 +74,28 @@ void RemoveSpareItemsFromNativeMenu( GLOMenu* pMenu, GList** pOldCommandList, un } } +typedef std::pair<GtkSalMenu*, sal_uInt16> MenuAndId; + +namespace +{ + MenuAndId decode_command(const gchar *action_name) + { + OString sCommand(action_name); + + sal_Int32 nIndex = 0; + OString sWindow = sCommand.getToken(0, '-', nIndex); + OString sGtkSalMenu = sCommand.getToken(0, '-', nIndex); + OString sItemId = sCommand.getToken(0, '-', nIndex); + + GtkSalMenu* pSalSubMenu = reinterpret_cast<GtkSalMenu*>(sGtkSalMenu.toInt64()); + + assert(sWindow == "window" && pSalSubMenu); + (void) sWindow; + + return MenuAndId(pSalSubMenu, sItemId.toInt32()); + } +} + void RemoveDisabledItemsFromNativeMenu(GLOMenu* pMenu, GList** pOldCommandList, sal_Int32 nSection, GActionGroup* pActionGroup) { @@ -92,8 +114,23 @@ void RemoveDisabledItemsFromNativeMenu(GLOMenu* pMenu, GList** pOldCommandList, if (pSubMenuModel) { gint nSubMenuSections = g_menu_model_get_n_items(G_MENU_MODEL(pSubMenuModel)); - bRemove = (nSubMenuSections == 0 || - (nSubMenuSections == 1 && g_lo_menu_get_n_items_from_section(pSubMenuModel, 0) == 0)); + if (nSubMenuSections == 0) + bRemove = true; + else if (nSubMenuSections == 1) + { + gint nItems = g_lo_menu_get_n_items_from_section(pSubMenuModel, 0); + if (nItems == 0) + bRemove = true; + else if (nItems == 1) + { + //If the only entry is the "No Selection Possible" entry, then we are allowed + //to removed it + gchar* pSubCommand = g_lo_menu_get_command_from_item_in_section(pSubMenuModel, 0, 0); + MenuAndId aMenuAndId(decode_command(pSubCommand)); + bRemove = aMenuAndId.second == 0xFFFF; + g_free(pSubCommand); + } + } } } @@ -1040,28 +1077,6 @@ GtkSalMenu* GtkSalMenu::GetTopLevel() return pMenu; } -typedef std::pair<GtkSalMenu*, sal_uInt16> MenuAndId; - -namespace -{ - MenuAndId decode_command(const gchar *action_name) - { - OString sCommand(action_name); - - sal_Int32 nIndex = 0; - OString sWindow = sCommand.getToken(0, '-', nIndex); - OString sGtkSalMenu = sCommand.getToken(0, '-', nIndex); - OString sItemId = sCommand.getToken(0, '-', nIndex); - - GtkSalMenu* pSalSubMenu = reinterpret_cast<GtkSalMenu*>(sGtkSalMenu.toInt64()); - - assert(sWindow == "window" && pSalSubMenu); - (void) sWindow; - - return MenuAndId(pSalSubMenu, sItemId.toInt32()); - } -} - void GtkSalMenu::DispatchCommand(const gchar *pCommand) { SolarMutexGuard aGuard; |