]> Pileus Git - ~andy/gtk/commitdiff
Add UI manager attribute to always show image in menu items
authorChristian Persch <chpe@gnome.org>
Wed, 11 Nov 2009 17:59:12 +0000 (18:59 +0100)
committerChristian Persch <chpe@gnome.org>
Fri, 27 Nov 2009 18:14:43 +0000 (19:14 +0100)
Add always-show-image="true|false" attribute to <menuitem> element in UI
manager markup. If present, it overrides the always-show-image property
on image menu items. Bug #589842.

docs/reference/gtk/tmpl/gtkuimanager.sgml
gtk/gtkuimanager.c
tests/merge-2.ui

index b25eaf91c74d7e3e0dd3a1467b72d908384f4c2b..22f5d8b8485487be6d906763e6d412eafe0e6072 100644 (file)
@@ -49,7 +49,8 @@ Definitions</link>.
                        position     (top|bot)    &num;IMPLIED >
 <!ATTLIST menuitem     name                      &num;IMPLIED
                        action                    &num;REQUIRED
-                       position     (top|bot)    &num;IMPLIED >
+                       position     (top|bot)    &num;IMPLIED
+                       always-show-image (true|false) &num;IMPLIED >
 <!ATTLIST toolitem     name                      &num;IMPLIED
                        action                    &num;REQUIRED
                        position     (top|bot)    &num;IMPLIED >
index 24267a6bfa301ec0a748d50f24880da59d35de27..771252d53c5d653fb377ae3d4045a0f3c8e62fe3 100644 (file)
@@ -33,6 +33,7 @@
 #include <string.h>
 #include "gtkactivatable.h"
 #include "gtkbuildable.h"
+#include "gtkimagemenuitem.h"
 #include "gtkintl.h"
 #include "gtkmarshalers.h"
 #include "gtkmenu.h"
@@ -82,6 +83,8 @@ struct _Node {
   guint dirty : 1;
   guint expand : 1;  /* used for separators */
   guint popup_accels : 1;
+  guint always_show_image_set : 1; /* used for menu items */
+  guint always_show_image     : 1; /* used for menu items */
 };
 
 #define GTK_UI_MANAGER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_UI_MANAGER, GtkUIManagerPrivate))
@@ -1211,6 +1214,7 @@ start_element_handler (GMarkupParseContext *context,
   gboolean top;
   gboolean expand = FALSE;
   gboolean accelerators = FALSE;
+  gboolean always_show_image_set = FALSE, always_show_image = FALSE;
 
   gboolean raise_error = TRUE;
 
@@ -1242,6 +1246,11 @@ start_element_handler (GMarkupParseContext *context,
         {
           accelerators = !strcmp (attribute_values[i], "true");
         }
+      else if (!strcmp (attribute_names[i], "always-show-image"))
+        {
+          always_show_image_set = TRUE;
+          always_show_image = !strcmp (attribute_values[i], "true");
+        }
       /*  else silently skip unknown attributes to be compatible with
        *  future additional attributes.
        */
@@ -1340,7 +1349,10 @@ start_element_handler (GMarkupParseContext *context,
                                 TRUE, top);
          if (NODE_INFO (node)->action_name == 0)
            NODE_INFO (node)->action_name = action_quark;
-         
+
+         NODE_INFO (node)->always_show_image_set = always_show_image_set;
+         NODE_INFO (node)->always_show_image = always_show_image;
+
          node_prepend_ui_reference (node, ctx->merge_id, action_quark);
          
          raise_error = FALSE;
@@ -2577,7 +2589,12 @@ update_node (GtkUIManager *self,
              info->proxy = gtk_action_create_menu_item (action);
              g_object_ref_sink (info->proxy);
              gtk_widget_set_name (info->proxy, info->name);
-         
+
+              if (info->always_show_image_set &&
+                  GTK_IS_IMAGE_MENU_ITEM (info->proxy))
+                gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (info->proxy),
+                                                           info->always_show_image);
+
              gtk_menu_shell_insert (GTK_MENU_SHELL (menushell),
                                     info->proxy, pos);
            }
index 05a641fe96f70d76e2999807b08685d344102df6..599a3cb2210637e62ebfa02a427c101cb55b8423 100644 (file)
@@ -5,7 +5,7 @@
       <menuitem name="New" action="NewAction" position="top" />
       <separator name="Sep1" />
       <separator name="Sep2" />
-      <menuitem name="Quit" action="QuitAction" />
+      <menuitem name="Quit" action="QuitAction" always-show-image="true" />
       <separator name="Sep3" />
     </menu>
     <menu name="EditMenu" action="EditMenuAction">