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.
This commit is contained in:
Christian Persch 2009-11-11 18:59:12 +01:00
parent e571273d81
commit 65485cbc7c
3 changed files with 22 additions and 4 deletions

View 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 >

View 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);
}

View 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">