From 1b6f5b79ff9f2768a1d5e546fedd591d4802b430 Mon Sep 17 00:00:00 2001 From: Paolo Borelli Date: Thu, 22 Jan 2009 13:12:22 +0000 Subject: [PATCH] add utility function to get a GtkMenuToolButton's button 2009-01-22 Paolo Borelli * eel/eel-gtk-extensions.[ch]: add utility function to get a GtkMenuToolButton's button * src/nautilus-window-menus.c: * src/nautilus-navigation-action.c: Use the above util function that doesn't leak the children list. svn path=/trunk/; revision=14877 --- ChangeLog | 10 ++++++++++ eel/eel-gtk-extensions.c | 20 ++++++++++++++++++++ eel/eel-gtk-extensions.h | 3 +++ src/nautilus-navigation-action.c | 11 +++-------- src/nautilus-window-menus.c | 9 ++------- 5 files changed, 38 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index ccf328181..827bd6f55 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2009-01-22 Paolo Borelli + + * eel/eel-gtk-extensions.[ch]: add utility function + to get a GtkMenuToolButton's button + + * src/nautilus-window-menus.c: + * src/nautilus-navigation-action.c: + Use the above util function that doesn't leak the children + list. + 2009-01-20 A. Walton * src/nautilus-main.c (main): diff --git a/eel/eel-gtk-extensions.c b/eel/eel-gtk-extensions.c index 81b8014a8..8b85ec067 100644 --- a/eel/eel-gtk-extensions.c +++ b/eel/eel-gtk-extensions.c @@ -436,6 +436,26 @@ eel_gtk_menu_set_item_visibility (GtkMenu *menu, int index, gboolean visible) g_list_free (children); } +GtkWidget * +eel_gtk_menu_tool_button_get_button (GtkMenuToolButton *tool_button) +{ + GtkContainer *container; + GList *children; + GtkWidget *button; + + g_return_val_if_fail (GTK_IS_MENU_TOOL_BUTTON (tool_button), NULL); + + /* The menu tool button's button is the first child + * of the child hbox. */ + container = GTK_CONTAINER (gtk_bin_get_child (GTK_BIN (tool_button))); + children = gtk_container_get_children (container); + button = GTK_WIDGET (children->data); + + g_list_free (children); + + return button; +} + gboolean eel_point_in_allocation (const GtkAllocation *allocation, int x, int y) diff --git a/eel/eel-gtk-extensions.h b/eel/eel-gtk-extensions.h index 7bf16024e..f9a662ffe 100644 --- a/eel/eel-gtk-extensions.h +++ b/eel/eel-gtk-extensions.h @@ -111,6 +111,9 @@ void eel_gtk_menu_set_item_visibility (GtkMenu int index, gboolean visible); +/* GtkMenuToolButton */ +GtkWidget * eel_gtk_menu_tool_button_get_button (GtkMenuToolButton *tool_button); + /* GtkLabel */ void eel_gtk_label_make_bold (GtkLabel *label); void eel_gtk_label_set_scale (GtkLabel *label, diff --git a/src/nautilus-navigation-action.c b/src/nautilus-navigation-action.c index e9d46dfcb..731811c08 100644 --- a/src/nautilus-navigation-action.c +++ b/src/nautilus-navigation-action.c @@ -33,8 +33,8 @@ #include "nautilus-navigation-window.h" #include "nautilus-window-private.h" #include "nautilus-navigation-window-slot.h" - #include +#include static void nautilus_navigation_action_init (NautilusNavigationAction *action); static void nautilus_navigation_action_class_init (NautilusNavigationActionClass *class); @@ -159,7 +159,6 @@ fill_menu (NautilusNavigationWindow *window, } } - static void show_menu_callback (GtkMenuToolButton *button, NautilusNavigationAction *action) @@ -225,7 +224,6 @@ connect_proxy (GtkAction *action, GtkWidget *proxy) NautilusNavigationAction *naction = NAUTILUS_NAVIGATION_ACTION (action); GtkMenuToolButton *button = GTK_MENU_TOOL_BUTTON (proxy); GtkWidget *menu; - GtkContainer *container; GtkWidget *child; /* set an empty menu, so the arrow button becomes sensitive */ @@ -240,8 +238,7 @@ connect_proxy (GtkAction *action, GtkWidget *proxy) /* Make sure that middle click works. Note that there is some code duplication * between here and nautilus-window-menus.c */ - container = GTK_CONTAINER (gtk_bin_get_child (GTK_BIN (proxy))); - child = GTK_WIDGET (gtk_container_get_children (container)->data); + child = eel_gtk_menu_tool_button_get_button (button); g_signal_connect (child, "button-press-event", G_CALLBACK (proxy_button_press_event_cb), NULL); g_signal_connect (child, "button-release-event", G_CALLBACK (proxy_button_release_event_cb), NULL); } @@ -253,13 +250,11 @@ static void disconnect_proxy (GtkAction *action, GtkWidget *proxy) { if (GTK_IS_MENU_TOOL_BUTTON (proxy)) { - GtkContainer *container; GtkWidget *child; g_signal_handlers_disconnect_by_func (proxy, G_CALLBACK (show_menu_callback), action); - container = GTK_CONTAINER (gtk_bin_get_child (GTK_BIN (proxy))); - child = GTK_WIDGET (gtk_container_get_children (container)->data); + child = eel_gtk_menu_tool_button_get_button (GTK_MENU_TOOL_BUTTON (proxy)); g_signal_handlers_disconnect_by_func (child, G_CALLBACK (proxy_button_press_event_cb), NULL); g_signal_handlers_disconnect_by_func (child, G_CALLBACK (proxy_button_release_event_cb), NULL); } diff --git a/src/nautilus-window-menus.c b/src/nautilus-window-menus.c index 4c0d8abc9..6a1c370e8 100644 --- a/src/nautilus-window-menus.c +++ b/src/nautilus-window-menus.c @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include @@ -622,13 +623,7 @@ get_event_widget (GtkWidget *proxy) /* Menu items already forward middle clicks */ widget = NULL; } else if (GTK_IS_MENU_TOOL_BUTTON (proxy)) { - /** - * The menu tool button's button is the first child - * of the child hbox. - */ - GtkContainer *container = - GTK_CONTAINER (gtk_bin_get_child (GTK_BIN (proxy))); - widget = GTK_WIDGET (gtk_container_get_children (container)->data); + widget = eel_gtk_menu_tool_button_get_button (GTK_MENU_TOOL_BUTTON (proxy)); } else if (GTK_IS_TOOL_BUTTON (proxy)) { /* The tool button's button is the direct child */ widget = gtk_bin_get_child (GTK_BIN (proxy));