[PATCH] Use GtkIconChooser for properties window



The attached patch is on bugzilla [1] for some weeks now, and
unfortunetely didn't get any feedback - so I'm posting it here. It makes
Nautilus use an icon chooser for image selection in the file properties
window and consolidates the "custom image" buttons into the image
button. I've found no appealing way of using a GtkImage as preview
widget, it always looks kind of squeezed on the right edge. This makes
the icon selection consistent with the "gnome-about-me" preferences
dialog.

[1] http://bugzilla.gnome.org/show_bug.cgi?id=95115

-- 
Christian Neumair <chris gnome-de org>
Index: src/file-manager/fm-properties-window.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-properties-window.c,v
retrieving revision 1.218
diff -u -p -r1.218 fm-properties-window.c
--- src/file-manager/fm-properties-window.c	12 Aug 2005 22:05:23 -0000	1.218
+++ src/file-manager/fm-properties-window.c	27 Aug 2005 08:33:40 -0000
@@ -87,13 +87,13 @@ struct FMPropertiesWindowDetails {	
 	GList *target_files;
 	
 	GtkNotebook *notebook;
-	GtkWidget *remove_image_button;
-	GtkWidget *icon_selector_window;
 	
 	GtkTable *basic_table;
 	GtkTable *permissions_table;
 
+	GtkWidget *icon_button;
 	GtkWidget *icon_image;
+	GtkWidget *icon_chooser;
 
 	GtkWidget *name_label;
 	GtkWidget *name_field;
@@ -195,9 +195,7 @@ static void parent_widget_destroyed_call
 						   gpointer            callback_data);
 static void select_image_button_callback          (GtkWidget          *widget,
 						   FMPropertiesWindow *properties_window);
-static void set_icon_callback                     (const char         *icon_path,
-						   FMPropertiesWindow *properties_window);
-static void remove_image_button_callback          (GtkWidget          *widget,
+static void set_icon                              (const char         *icon_path,
 						   FMPropertiesWindow *properties_window);
 static void remove_pending                        (StartupData        *data,
 						   gboolean            cancel_call_when_ready,
@@ -478,8 +476,6 @@ reset_icon (FMPropertiesWindow *properti
 					    NAUTILUS_METADATA_KEY_CUSTOM_ICON,
 					    NULL, NULL);
 	}
-	
-	gtk_widget_set_sensitive (properties_window->details->remove_image_button, FALSE);
 }
 
 
@@ -490,6 +486,7 @@ fm_properties_window_drag_data_received 
 					 guint info, guint time)
 {
 	char **uris;
+	char *path;
 	gboolean exactly_one;
 	GtkImage *image;
  	GtkWindow *window; 
@@ -515,8 +512,9 @@ fm_properties_window_drag_data_received 
 			 window);
 	} else {		
 		if (uri_is_local_image (uris[0])) {			
-			set_icon_callback (gnome_vfs_get_local_path_from_uri (uris[0]), 
-					   FM_PROPERTIES_WINDOW (window));
+			path = gnome_vfs_get_local_path_from_uri (uris[0]);
+			set_icon (path,  FM_PROPERTIES_WINDOW (window));
+			g_free (path);
 		} else {	
 			if (eel_is_remote_uri (uris[0])) {
 				eel_show_error_dialog
@@ -539,17 +537,23 @@ fm_properties_window_drag_data_received 
 
 static GtkWidget *
 create_image_widget (FMPropertiesWindow *window,
-		     gboolean is_drag_dest)
+		     gboolean is_customizable)
 {
- 	GtkWidget *image;
+ 	GtkWidget *button;
+	GtkWidget *image;
 	GdkPixbuf *pixbuf;
 	
 	pixbuf = get_pixbuf_for_properties_window (window);
 	
+
 	image = gtk_image_new ();
-	window->details->icon_image = image;
+	gtk_widget_show (image);
+
+	button = NULL;
+	if (is_customizable) {
+		button = gtk_button_new ();
+		gtk_container_add (GTK_CONTAINER (button), image);
 
-	if (is_drag_dest) {
 		/* prepare the image to receive dropped objects to assign custom images */
 		gtk_drag_dest_set (GTK_WIDGET (image),
 				   GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_HIGHLIGHT | GTK_DEST_DEFAULT_DROP, 
@@ -558,6 +562,8 @@ create_image_widget (FMPropertiesWindow 
 
 		g_signal_connect (image, "drag_data_received",
 				  G_CALLBACK (fm_properties_window_drag_data_received), NULL);
+		g_signal_connect (button, "clicked",
+				  G_CALLBACK (select_image_button_callback), window);
 	}
 
 	gtk_image_set_from_pixbuf (GTK_IMAGE (image), pixbuf);
@@ -572,7 +578,10 @@ create_image_widget (FMPropertiesWindow 
 				 G_CALLBACK (update_properties_window_icon),
 				 image, G_CONNECT_SWAPPED);
 
-	return image;
+	window->details->icon_image = image;
+	window->details->icon_button = button;
+
+	return button != NULL ? button : image;
 }
 
 static void
@@ -2346,13 +2355,15 @@ create_basic_page (FMPropertiesWindow *w
 	icon_pixmap_widget = create_image_widget (
 		window, should_show_custom_icon_buttons (window));
 	gtk_widget_show (icon_pixmap_widget);
-	
+
 	icon_aligner = gtk_alignment_new (1, 0.5, 0, 0);
 	gtk_widget_show (icon_aligner);
 	
 	gtk_container_add (GTK_CONTAINER (icon_aligner), icon_pixmap_widget);
 	gtk_box_pack_start (GTK_BOX (hbox), icon_aligner, TRUE, TRUE, 0);
 
+	window->details->icon_chooser = NULL;
+
 	/* Name label */
 	name_label = gtk_label_new_with_mnemonic (ngettext ("_Name:", "_Names:",
 							    get_not_gone_original_file_count (window)));
@@ -2434,47 +2445,6 @@ create_basic_page (FMPropertiesWindow *w
 					 _("--"),
 					 FALSE);
 	}
-
-	if (should_show_custom_icon_buttons (window)) {
-		GtkWidget *button_box;
-		GtkWidget *temp_button;
-		GList *l;
-		
-		/* add command buttons for setting and clearing custom icons */
-		button_box = gtk_hbox_new (FALSE, 0);
-		gtk_widget_show (button_box);
-		gtk_box_pack_end (GTK_BOX(container), button_box, FALSE, FALSE, 4);  
-		
-	 	temp_button = gtk_button_new_with_mnemonic (_("_Select Custom Icon..."));
-		gtk_widget_show (temp_button);
-		gtk_box_pack_start (GTK_BOX (button_box), temp_button, FALSE, FALSE, 4);  
-
-		g_signal_connect_object (temp_button, "clicked", G_CALLBACK (select_image_button_callback), window, 0);
-	 	
-	 	temp_button = gtk_button_new_with_mnemonic (_("_Remove Custom Icon"));
-		gtk_widget_show (temp_button);
-		gtk_box_pack_start (GTK_BOX(button_box), temp_button, FALSE, FALSE, 4);  
-
-	 	g_signal_connect_object (temp_button, "clicked", G_CALLBACK (remove_image_button_callback), window, 0);
-
-		window->details->remove_image_button = temp_button;
-		
-		/* de-sensitize the remove button if there isn't a custom image */
-		
-		gtk_widget_set_sensitive (temp_button, FALSE);
-		for (l = window->details->original_files; l != NULL; l = l->next) {
-			char *image_uri = nautilus_file_get_metadata 
-				(NAUTILUS_FILE (l->data), 
-				 NAUTILUS_METADATA_KEY_CUSTOM_ICON, NULL);
-			if (image_uri) {
-				gtk_widget_set_sensitive (temp_button, TRUE);
-			}
-			
-			g_free (image_uri);
-		}
-
-		window->details->icon_selector_window = NULL;
-	}
 }
 
 static GHashTable *
@@ -3802,7 +3772,7 @@ real_finalize (GObject *object)
 
 /* icon selection callback to set the image of the file object to the selected file */
 static void
-set_icon_callback (const char* icon_path, FMPropertiesWindow *properties_window)
+set_icon (const char* icon_path, FMPropertiesWindow *properties_window)
 {
 	NautilusFile *file;
 	char *icon_uri;
@@ -3844,45 +3814,72 @@ set_icon_callback (const char* icon_path
 
 		}
 		g_free (icon_uri);	
-		
-		/* re-enable the property window's clear image button */ 
-		gtk_widget_set_sensitive (properties_window->details->remove_image_button, TRUE);
 	}
 }
 
-/* handle the "select icon" button */
 static void
-select_image_button_callback (GtkWidget *widget, FMPropertiesWindow *properties_window)
+select_image_button_callback (GtkWidget *widget,
+			      FMPropertiesWindow *window)
 {
 	GtkWidget *dialog;
+	GtkFileFilter *filter;
+	GList *l;
+	NautilusFile *file;
+	char *image_path;
+	gboolean revert_is_sensitive;
 
-	g_assert (FM_IS_PROPERTIES_WINDOW (properties_window));
+	g_assert (FM_IS_PROPERTIES_WINDOW (window));
 
-	dialog = properties_window->details->icon_selector_window;
+	dialog = window->details->icon_chooser;
 
-	if (dialog) {
-		gtk_window_present (GTK_WINDOW (dialog));
-	} else {
-		dialog = eel_gnome_icon_selector_new (_("Select an icon"),
-						      NULL,
-					 	      GTK_WINDOW (properties_window),
-						      (EelIconSelectionFunction) set_icon_callback,
-						      properties_window);
-		
+	if (dialog == NULL) {
+		dialog = gtk_file_chooser_dialog_new (_("Select Custom Icon"), GTK_WINDOW (window),
+						      GTK_FILE_CHOOSER_ACTION_OPEN,
+						      _("_Revert"), GTK_RESPONSE_NO,
+						      GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+						      GTK_STOCK_OPEN, GTK_RESPONSE_OK,
+						      NULL);
+		gtk_file_chooser_add_shortcut_folder (GTK_FILE_CHOOSER (dialog), "/usr/share/pixmaps", NULL);
 		gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
 
-		properties_window->details->icon_selector_window = dialog;
+		filter = gtk_file_filter_new ();
+		gtk_file_filter_add_pixbuf_formats (filter);
+		gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog), filter);
 
-		eel_add_weak_pointer (&properties_window->details->icon_selector_window);
+		window->details->icon_chooser = dialog;
+
+		eel_add_weak_pointer (&window->details->icon_chooser);
 	}
-}
 
-static void
-remove_image_button_callback (GtkWidget *widget, FMPropertiesWindow *properties_window)
-{
-	g_return_if_fail (FM_IS_PROPERTIES_WINDOW (properties_window));
+	revert_is_sensitive = FALSE;
+	for (l = window->details->original_files; l != NULL; l = l->next) {
+		file = NAUTILUS_FILE (l->data);
+		image_path = nautilus_file_get_metadata (file, NAUTILUS_METADATA_KEY_CUSTOM_ICON, NULL);
+		revert_is_sensitive = (image_path != NULL);
+		g_free (image_path);
+
+		if (revert_is_sensitive) {
+			break;
+		}
+	}
+	gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_NO, revert_is_sensitive);
+
+	switch (gtk_dialog_run (GTK_DIALOG (dialog))) {
+	case GTK_RESPONSE_NO:
+		reset_icon (window);
+		break;
+
+	case GTK_RESPONSE_OK:
+		image_path = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
+		set_icon (image_path, window);
+		g_free (image_path);
+		break;
+
+	default:
+		break;
+	}
 
-	reset_icon (properties_window);
+	gtk_widget_hide (dialog);
 }
 
 static void

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]