[Libreoffice-commits] core.git: vcl/unx

Caolán McNamara caolanm at redhat.com
Mon Oct 17 13:00:00 UTC 2016


 vcl/unx/gtk/gtksalmenu.cxx |   63 +++++++++++++++++++++++++++------------------
 1 file changed, 39 insertions(+), 24 deletions(-)

New commits:
commit 8bff380fed975dc7f6365b7f2ca7213c3cf4d302
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Mon Oct 17 10:48:45 2016 +0100

    Related: tdf#103166 but still allow removing placeholder submenus
    
    Change-Id: I3ed5feaebcd074562d5412dca9e5cb4086a7df39

diff --git a/vcl/unx/gtk/gtksalmenu.cxx b/vcl/unx/gtk/gtksalmenu.cxx
index fa52fc9..0fbaf88 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;


More information about the Libreoffice-commits mailing list