[gtk+] Add UI manager attribute to always show image in menu items



commit 65485cbc7c8d48513aa7e14477a2eacf82276f9b
Author: Christian Persch <chpe gnome org>
Date:   Wed Nov 11 18:59:12 2009 +0100

    Add UI manager attribute to always show image in menu items
    
    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 |    3 ++-
 gtk/gtkuimanager.c                        |   21 +++++++++++++++++++--
 tests/merge-2.ui                          |    2 +-
 3 files changed, 22 insertions(+), 4 deletions(-)
---
diff --git a/docs/reference/gtk/tmpl/gtkuimanager.sgml b/docs/reference/gtk/tmpl/gtkuimanager.sgml
index b25eaf9..22f5d8b 100644
--- a/docs/reference/gtk/tmpl/gtkuimanager.sgml
+++ b/docs/reference/gtk/tmpl/gtkuimanager.sgml
@@ -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 >
diff --git a/gtk/gtkuimanager.c b/gtk/gtkuimanager.c
index 24267a6..771252d 100644
--- a/gtk/gtkuimanager.c
+++ b/gtk/gtkuimanager.c
@@ -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);
            }
diff --git a/tests/merge-2.ui b/tests/merge-2.ui
index 05a641f..599a3cb 100644
--- a/tests/merge-2.ui
+++ b/tests/merge-2.ui
@@ -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">



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]