summaryrefslogtreecommitdiff
path: root/gtk/gtkuimanager.c
diff options
context:
space:
mode:
authorEmmanuele Bassi <ebassi@gnome.org>2007-03-15 19:33:57 +0000
committerEmmanuele Bassi <ebassi@src.gnome.org>2007-03-15 19:33:57 +0000
commitccf49466a64602051ddffca43488b77576abeab2 (patch)
tree2695b60d9ff5e30516ee4950860bd3ac0a778254 /gtk/gtkuimanager.c
parent0b1c9b7cc26d293477a6823a40d3e1feebbd6df7 (diff)
downloadgtk+-ccf49466a64602051ddffca43488b77576abeab2.tar.gz
Add GtkActionClass::get_submenu() vfunc: actions providing a menu item or
2007-03-15 Emmanuele Bassi <ebassi@gnome.org> * gtk/gtkaction.[ch]: Add GtkActionClass::get_submenu() vfunc: actions providing a menu item or a menu tool button with already a submenu should return the GtkMenu widget. * gtk/gtkuimanager.c (update_node): If an action provides its own submenu, use it instead of adding an empty one * gtk/gtkrecentaction.[ch]: Add GtkRecentAction, an action implementing the GtkRecentChooser interface for displaying the list of recently used files into menus and toolbars generated using GtkUIManager. (#338843) * gtk/Makefile.am: * gtk/gtk.h: * gtk/gtk.symbols: Add GtkRecentAction API to the build. * tests/testactions.c: Exercise the GtkRecentAction API. svn path=/trunk/; revision=17524
Diffstat (limited to 'gtk/gtkuimanager.c')
-rw-r--r--gtk/gtkuimanager.c47
1 files changed, 31 insertions, 16 deletions
diff --git a/gtk/gtkuimanager.c b/gtk/gtkuimanager.c
index bcf06b1c63..76e7c284b5 100644
--- a/gtk/gtkuimanager.c
+++ b/gtk/gtkuimanager.c
@@ -2204,8 +2204,9 @@ update_node (GtkUIManager *self,
case NODE_TYPE_MENU:
{
GtkWidget *prev_submenu = NULL;
- GtkWidget *menu;
+ GtkWidget *menu = NULL;
GList *siblings;
+
/* remove the proxy if it is of the wrong type ... */
if (info->proxy &&
G_OBJECT_TYPE (info->proxy) != GTK_ACTION_GET_CLASS (action)->menu_item_type)
@@ -2226,26 +2227,39 @@ update_node (GtkUIManager *self,
g_object_unref (info->proxy);
info->proxy = NULL;
}
+
/* create proxy if needed ... */
if (info->proxy == NULL)
{
- GtkWidget *tearoff;
- GtkWidget *filler;
+ /* ... if the action already provides a menu, then use
+ * that menu instead of creating an empty one
+ */
+ if (NODE_INFO (node->parent)->type == NODE_TYPE_TOOLITEM &&
+ GTK_ACTION_GET_CLASS (action)->get_submenu)
+ {
+ menu = gtk_action_get_submenu (action);
+ }
+
+ if (!menu)
+ {
+ GtkWidget *tearoff;
+ GtkWidget *filler;
- menu = gtk_menu_new ();
- gtk_widget_set_name (menu, info->name);
- tearoff = gtk_tearoff_menu_item_new ();
- gtk_widget_set_no_show_all (tearoff, TRUE);
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), tearoff);
- filler = gtk_menu_item_new_with_label (_("Empty"));
- g_object_set_data (G_OBJECT (filler),
- I_("gtk-empty-menu-item"),
- GINT_TO_POINTER (TRUE));
- gtk_widget_set_sensitive (filler, FALSE);
- gtk_widget_set_no_show_all (filler, TRUE);
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), filler);
+ menu = gtk_menu_new ();
+ gtk_widget_set_name (menu, info->name);
+ tearoff = gtk_tearoff_menu_item_new ();
+ gtk_widget_set_no_show_all (tearoff, TRUE);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), tearoff);
+ filler = gtk_menu_item_new_with_label (_("Empty"));
+ g_object_set_data (G_OBJECT (filler),
+ I_("gtk-empty-menu-item"),
+ GINT_TO_POINTER (TRUE));
+ gtk_widget_set_sensitive (filler, FALSE);
+ gtk_widget_set_no_show_all (filler, TRUE);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), filler);
+ }
- if (NODE_INFO (node->parent)->type == NODE_TYPE_TOOLITEM)
+ if (NODE_INFO (node->parent)->type == NODE_TYPE_TOOLITEM)
{
info->proxy = menu;
g_object_ref_sink (info->proxy);
@@ -2284,6 +2298,7 @@ update_node (GtkUIManager *self,
menu = info->proxy;
else
menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (info->proxy));
+
siblings = gtk_container_get_children (GTK_CONTAINER (menu));
if (siblings != NULL && GTK_IS_TEAROFF_MENU_ITEM (siblings->data))
{