[gnome-utils] [gsearchtool] Sync open with menu with nautilus



commit df564b04f5e103331dd8343537f22563b99a6f31
Author: Dennis Cranston <Dennis_Cranston yahoo com>
Date:   Tue Apr 28 21:54:23 2009 -0700

    [gsearchtool] Sync open with menu with nautilus
    
    gsearchtool-callbacks.c (build_popup_menu_for_file): Sync
    the open with menu to recent nautilus changes.  Show
    app icon for default application, see bug 546916.
---
 gsearchtool/ChangeLog               |    5 ++
 gsearchtool/gsearchtool-callbacks.c |  119 +++++++++++++++++++++--------------
 2 files changed, 77 insertions(+), 47 deletions(-)

diff --git a/gsearchtool/ChangeLog b/gsearchtool/ChangeLog
index 0918cdd..c4dcf2a 100644
--- a/gsearchtool/ChangeLog
+++ b/gsearchtool/ChangeLog
@@ -1,3 +1,8 @@
+2009-04-28  Dennis Cranston  <dennis_cranston yahoo com>
+
+	* gsearchtool-callbacks.c (build_popup_menu_for_file):  
+	See bug 546916 -- Sync open menu with recent nautilus changes.
+	
 2009-04-27  Dennis Cranston  <dennis_cranston yahoo com>
 
 	* gsearchtool-support.c (compare_regex):  Minor logic fix.
diff --git a/gsearchtool/gsearchtool-callbacks.c b/gsearchtool/gsearchtool-callbacks.c
index 1e5481f..9dc0119 100644
--- a/gsearchtool/gsearchtool-callbacks.c
+++ b/gsearchtool/gsearchtool-callbacks.c
@@ -1023,6 +1023,7 @@ build_popup_menu_for_file (GSearchWindow * gsearch,
 	else {
 		GFile * g_file;
 		GFileInfo * file_info;
+		GIcon * file_icon;
 		GList * list;
 		gchar * str;
 		gint list_length;
@@ -1043,70 +1044,94 @@ build_popup_menu_for_file (GSearchWindow * gsearch,
 			g_list_free (tmp);
 		}
 		
-		/* Popup menu item: Open with (default) */
-		str = g_strdup_printf ("_Open with \"%s\"",  g_app_info_get_name (list->data));
-		new1 = gtk_image_menu_item_new_with_mnemonic (str);
-		gtk_widget_show (new1);
+		if (list_length > 0) {
+		
+			/* Popup menu item: Open with (default) */
+			str = g_strdup_printf ("_Open with \"%s\"",  g_app_info_get_name (list->data));
+			new1 = gtk_image_menu_item_new_with_mnemonic (str);
+			gtk_widget_show (new1);
 
-		g_object_set_data_full (G_OBJECT (new1), "app", (GAppInfo *)list->data,
-		                        (GDestroyNotify) g_object_unref);
+			g_object_set_data_full (G_OBJECT (new1), "app", (GAppInfo *)list->data,
+			                        (GDestroyNotify) g_object_unref);
 
-		gtk_container_add (GTK_CONTAINER (gsearch->search_results_popup_menu), new1);
+			gtk_container_add (GTK_CONTAINER (gsearch->search_results_popup_menu), new1);
+			g_signal_connect ((gpointer) new1, "activate", G_CALLBACK (open_file_cb),
+					  (gpointer) gsearch);
 
-		g_signal_connect ((gpointer) new1, "activate", G_CALLBACK (open_file_cb),
-				  (gpointer) gsearch);
+			file_icon = g_object_ref (g_app_info_get_icon ((GAppInfo *)list->data));
 
-		image1 = gtk_image_new_from_stock ("gtk-open", GTK_ICON_SIZE_MENU);
-		gtk_widget_show (image1);
-		gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (new1), image1);
+			if (file_icon == NULL) {
+				file_icon = g_themed_icon_new (GTK_STOCK_OPEN);
+			}
+
+			image1 = gtk_image_new_from_gicon (file_icon, GTK_ICON_SIZE_MENU);
+			g_object_unref (file_icon);
+			gtk_widget_show (image1);
+			gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (new1), image1);
 		
-		separatormenuitem1 = gtk_separator_menu_item_new ();
-		gtk_widget_show (separatormenuitem1);
-		gtk_container_add (GTK_CONTAINER (gsearch->search_results_popup_menu), separatormenuitem1);
-		gtk_widget_set_sensitive (separatormenuitem1, FALSE);			
+			separatormenuitem1 = gtk_separator_menu_item_new ();
+			gtk_widget_show (separatormenuitem1);
+			gtk_container_add (GTK_CONTAINER (gsearch->search_results_popup_menu), separatormenuitem1);
+			gtk_widget_set_sensitive (separatormenuitem1, FALSE);			
 
-		for (list = g_list_next (list), i = 0; list != NULL; list = g_list_next (list), i++) {
+			for (list = g_list_next (list), i = 0; list != NULL; list = g_list_next (list), i++) {
 
-			/* Popup menu item: Open with (others) */
-			str = g_strdup_printf ("Open with \"%s\"",  g_app_info_get_name (list->data));
-			new1 = gtk_menu_item_new_with_mnemonic (str);
-			gtk_widget_show (new1);
+				/* Popup menu item: Open with (others) */
+				str = g_strdup_printf ("Open with \"%s\"",  g_app_info_get_name (list->data));
+				new1 = gtk_menu_item_new_with_mnemonic (str);
+				gtk_widget_show (new1);
 
-			g_object_set_data_full (G_OBJECT (new1), "app", (GAppInfo *)list->data,
-		                                (GDestroyNotify) g_object_unref);
+				g_object_set_data_full (G_OBJECT (new1), "app", (GAppInfo *)list->data,
+			                                (GDestroyNotify) g_object_unref);
 
-			if (list_length >= 4) {
+				if (list_length >= 4) {
 
-				if (i == 0) {
-					gsearch->search_results_popup_submenu = gtk_menu_new ();
+					if (i == 0) {
+						gsearch->search_results_popup_submenu = gtk_menu_new ();
 
-					/* Popup menu item: Open With */
-				  	new2 = gtk_menu_item_new_with_mnemonic  (_("Open Wit_h"));
-				  	gtk_widget_show (new2);
-				 	gtk_container_add (GTK_CONTAINER (gsearch->search_results_popup_menu), new2);
+						/* Popup menu item: Open With */
+					  	new2 = gtk_menu_item_new_with_mnemonic  (_("Open Wit_h"));
+				  		gtk_widget_show (new2);
+					 	gtk_container_add (GTK_CONTAINER (gsearch->search_results_popup_menu), new2);
 
-	  			  	gtk_menu_item_set_submenu (GTK_MENU_ITEM (new2), gsearch->search_results_popup_submenu);
-	                       	}
-				gtk_container_add (GTK_CONTAINER (gsearch->search_results_popup_submenu), new1);
+		  			  	gtk_menu_item_set_submenu (GTK_MENU_ITEM (new2), gsearch->search_results_popup_submenu);
+		                       	}
+					gtk_container_add (GTK_CONTAINER (gsearch->search_results_popup_submenu), new1);
 
-				/* For submenu items, the "activate" signal is only emitted if the user first clicks 
-				   on the parent menu item.  Since submenus in gtk+ are automatically displayed when
-				   the user hovers over them, most will never click on the parent menu item.  
-				   The work-around is to connect to "button-press-event". */
-				g_signal_connect (G_OBJECT(new1), "button-press-event", G_CALLBACK (open_file_event_cb),
-				                  (gpointer) gsearch);
+					/* For submenu items, the "activate" signal is only emitted if the user first clicks 
+					   on the parent menu item.  Since submenus in gtk+ are automatically displayed when
+					   the user hovers over them, most will never click on the parent menu item.  
+					   The work-around is to connect to "button-press-event". */
+					g_signal_connect (G_OBJECT(new1), "button-press-event", G_CALLBACK (open_file_event_cb),
+					                  (gpointer) gsearch);
+				}
+				else {
+					gtk_container_add (GTK_CONTAINER (gsearch->search_results_popup_menu), new1);
+					g_signal_connect ((gpointer) new1, "activate", G_CALLBACK (open_file_cb),
+					                  (gpointer) gsearch);
+				}
 			}
-			else {
-				gtk_container_add (GTK_CONTAINER (gsearch->search_results_popup_menu), new1);
-				g_signal_connect ((gpointer) new1, "activate", G_CALLBACK (open_file_cb),
-				                  (gpointer) gsearch);
+		
+			if (list_length >= 2) {
+				separatormenuitem1 = gtk_separator_menu_item_new ();
+				gtk_container_add (GTK_CONTAINER (gsearch->search_results_popup_menu), separatormenuitem1);
+				gtk_widget_show (separatormenuitem1);
 			}
 		}
+		else {
+			/* Popup menu item: Open */
+			new1 = gtk_image_menu_item_new_with_mnemonic  (_("_Open"));
+			gtk_container_add (GTK_CONTAINER (gsearch->search_results_popup_menu), new1);
+			gtk_widget_show (new1);
 
-		if (list_length >= 2) {
-			separatormenuitem1 = gtk_separator_menu_item_new ();
-			gtk_container_add (GTK_CONTAINER (gsearch->search_results_popup_menu), separatormenuitem1);
-			gtk_widget_show (separatormenuitem1);
+			image1 = gtk_image_new_from_stock ("gtk-open", GTK_ICON_SIZE_MENU);
+			gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (new1), image1);
+			gtk_widget_show (image1);
+
+			g_signal_connect (G_OBJECT (new1),
+			                  "activate",
+			                  G_CALLBACK (open_file_cb),
+		        	          (gpointer) gsearch);
 		}
 	}
 



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