[PATCH] popup menu for "remove" and "rename" in place sidebar



Here is a patch to be consistant with gtkfilechooser.

The patch isn't finished yet but I've a problem that I don't
understand : why my function
nautilus_places_sidebar_popup_menu_detach_callback () is never called ?
it should be when GtkMenu is destroyed... I'm not an exert so if someone
can help me it would be nice :-)
Index: src/nautilus-places-sidebar.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-places-sidebar.c,v
retrieving revision 1.5
diff -u -p -r1.5 nautilus-places-sidebar.c
--- src/nautilus-places-sidebar.c	11 Jul 2005 10:12:46 -0000	1.5
+++ src/nautilus-places-sidebar.c	15 Aug 2005 20:27:14 -0000
@@ -38,6 +38,7 @@
 #include <gtk/gtkstock.h>
 #include <gtk/gtktreemodel.h>
 #include <gtk/gtktreeselection.h>
+#include <gtk/gtk.h>
 #include <libgnome/gnome-macros.h>
 #include <libgnome/gnome-i18n.h>
 #include <libnautilus-private/nautilus-bookmark.h>
@@ -62,6 +63,10 @@ typedef struct {
 	GtkListStore       *store;
 	NautilusWindowInfo *window;
 	NautilusBookmarkList *bookmarks;
+
+	GtkWidget *popup_menu;
+	GtkWidget *popup_menu_remove_item;
+	GtkWidget *popup_menu_rename_item;
 } NautilusPlacesSidebar;
 
 typedef struct {
@@ -294,6 +299,101 @@ row_activated_callback (GtkTreeView *tre
 }
 
 static void
+nautilus_places_sidebar_popup_menu_remove_callback (GtkMenuItem *item,
+												NautilusPlacesSidebar *sidebar)
+{
+	g_print ("remove\n");
+}
+
+static void
+nautilus_places_sidebar_popup_menu_rename_callback (GtkMenuItem *item,
+												NautilusPlacesSidebar *sidebar)
+{
+	g_print ("rename\n");
+}
+
+static void
+nautilus_places_sidebar_popup_menu_detach_callback (GtkWidget *attach_widget,
+													GtkMenu   *menu)
+{
+	NautilusPlacesSidebar *sidebar;
+	
+	sidebar = g_object_get_data (G_OBJECT (attach_widget), "sidebar");
+	g_assert (NAUTILUS_IS_PLACES_SIDEBAR (sidebar));
+	sidebar->popup_menu = NULL;
+	sidebar->popup_menu_remove_item = NULL;
+	sidebar->popup_menu_rename_item = NULL;
+}
+
+static void
+nautilus_places_sidebar_do_popup_menu (NautilusPlacesSidebar	*sidebar,
+									   GdkEventButton			*event)
+{
+	GtkWidget *item;
+
+	if (sidebar->popup_menu)
+		return;
+
+	sidebar->popup_menu = gtk_menu_new ();
+	g_object_set_data (G_OBJECT (sidebar->tree_view), "sidebar", sidebar);
+	gtk_menu_attach_to_widget (GTK_MENU (sidebar->popup_menu),
+		GTK_WIDGET (sidebar->tree_view),
+		nautilus_places_sidebar_popup_menu_detach_callback);
+
+	item = gtk_image_menu_item_new_with_label (_("Remove"));
+	sidebar->popup_menu_remove_item = item;
+	gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item),
+		gtk_image_new_from_stock (GTK_STOCK_REMOVE, GTK_ICON_SIZE_MENU));
+	g_signal_connect (item, "activate",
+		G_CALLBACK (nautilus_places_sidebar_popup_menu_remove_callback), sidebar);
+	gtk_widget_show (item);
+	gtk_menu_shell_append (GTK_MENU_SHELL (sidebar->popup_menu), item);
+
+	item = gtk_menu_item_new_with_label (_("Rename..."));
+	sidebar->popup_menu_rename_item = item;
+	g_signal_connect (item, "activate",
+		G_CALLBACK (nautilus_places_sidebar_popup_menu_rename_callback), sidebar);
+	gtk_widget_show (item);
+	gtk_menu_shell_append (GTK_MENU_SHELL (sidebar->popup_menu), item);
+
+	if (event)
+		gtk_menu_popup (GTK_MENU (sidebar->popup_menu),
+			NULL, NULL, NULL, NULL,
+			event->button, event->time);
+	else {
+		gtk_menu_popup (GTK_MENU (sidebar->popup_menu),
+			NULL, NULL, NULL, NULL,
+			0, GDK_CURRENT_TIME);
+		gtk_menu_shell_select_first (GTK_MENU_SHELL (sidebar->popup_menu),
+			FALSE);
+	}
+}
+
+static gboolean
+nautilus_places_sidebar_popup_menu_callback (GtkWidget				*widget,
+											 NautilusPlacesSidebar	*sidebar)
+{
+	nautilus_places_sidebar_do_popup_menu (sidebar, NULL);
+	return TRUE;
+}
+
+static gboolean
+nautilus_places_sidebar_button_press_event_callback (GtkWidget		*widget,
+											GdkEventButton			*event,
+											NautilusPlacesSidebar	*sidebar)
+{
+  if (event->button != 3)
+    return FALSE;
+
+  nautilus_places_sidebar_do_popup_menu (sidebar, event);
+  return TRUE;
+}
+
+static void
 update_click_policy (NautilusPlacesSidebar *sidebar)
 {
 	int policy;
@@ -422,6 +522,12 @@ nautilus_places_sidebar_init (NautilusPl
 	g_signal_connect_object
 		(tree_view, "row_activated", 
 		 G_CALLBACK (row_activated_callback), sidebar, 0);
+	g_signal_connect (tree_view, "popup-menu",
+		 G_CALLBACK (nautilus_places_sidebar_popup_menu_callback),
+		 sidebar);
+	g_signal_connect (tree_view, "button-press-event",
+		G_CALLBACK (nautilus_places_sidebar_button_press_event_callback),
+		sidebar);
 
 	eel_preferences_add_callback (NAUTILUS_PREFERENCES_CLICK_POLICY,
 				      click_policy_changed_callback,

Attachment: signature.asc
Description: This is a digitally signed message part



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