add utility function to get a GtkMenuToolButton's button

2009-01-22  Paolo Borelli  <pborelli@katamail.com>

	* 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
This commit is contained in:
Paolo Borelli 2009-01-22 13:12:22 +00:00 committed by Paolo Borelli
parent 657283d20a
commit 1b6f5b79ff
5 changed files with 38 additions and 15 deletions

View file

@ -1,3 +1,13 @@
2009-01-22 Paolo Borelli <pborelli@katamail.com>
* 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 <awalton@gnome.org>
* src/nautilus-main.c (main):

View file

@ -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)

View file

@ -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,

View file

@ -33,8 +33,8 @@
#include "nautilus-navigation-window.h"
#include "nautilus-window-private.h"
#include "nautilus-navigation-window-slot.h"
#include <gtk/gtk.h>
#include <eel/eel-gtk-extensions.h>
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);
}

View file

@ -42,6 +42,7 @@
#include <gtk/gtk.h>
#include <gio/gio.h>
#include <glib/gi18n.h>
#include <eel/eel-gtk-extensions.h>
#include <eel/eel-preferences.h>
#include <libnautilus-extension/nautilus-menu-provider.h>
#include <libnautilus-private/nautilus-file-utilities.h>
@ -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));