diff options
author | Andy Hertzfeld <andy@src.gnome.org> | 2001-02-07 02:09:20 +0000 |
---|---|---|
committer | Andy Hertzfeld <andy@src.gnome.org> | 2001-02-07 02:09:20 +0000 |
commit | 2ac3f18b34bc1388ca5c4ce21f4303d3a2171bb8 (patch) | |
tree | 3f9890d402793b020028913db4146ee39369f70a | |
parent | 43326b1f520c21faaeb52feeebfa3203d1663022 (diff) | |
download | nautilus-2ac3f18b34bc1388ca5c4ce21f4303d3a2171bb8.tar.gz |
fixed bug 6280, custom icon selection should use gnome-icon-sel instead of
* src/file-manager/fm-properties-window.c:
(widget_destroy_callback), (icon_selected_callback),
(icon_cancel_pressed), (list_icon_selected_callback),
(entry_activated), (select_image_button_callback):
fixed bug 6280, custom icon selection should use gnome-icon-sel
instead of the generic file browser, so now it does.
-rw-r--r-- | ChangeLog | 11 | ||||
-rw-r--r-- | src/file-manager/fm-properties-window.c | 204 |
2 files changed, 152 insertions, 63 deletions
@@ -1,3 +1,12 @@ +2001-02-06 Andy Hertzfeld <andy@eazel.com> + + * src/file-manager/fm-properties-window.c: + (widget_destroy_callback), (icon_selected_callback), + (icon_cancel_pressed), (list_icon_selected_callback), + (entry_activated), (select_image_button_callback): + fixed bug 6280, custom icon selection should use gnome-icon-sel + instead of the generic file browser, so now it does. + 2001-02-06 Ramiro Estrugo <ramiro@eazel.com> reviewed by: Michael Engber <engber@eazel.com> @@ -36,8 +45,6 @@ 2001-02-06 John Sullivan <sullivan@eazel.com> - reviewed by: <delete if not using a buddy> - Fixed bug 5157 (Nautilus won't display directories for which it thinks it doesn't have permissions) diff --git a/src/file-manager/fm-properties-window.c b/src/file-manager/fm-properties-window.c index c5e22c0b0..8ed990232 100644 --- a/src/file-manager/fm-properties-window.c +++ b/src/file-manager/fm-properties-window.c @@ -41,6 +41,11 @@ #include <gtk/gtkvbox.h> #include <libgnome/gnome-defs.h> #include <libgnome/gnome-i18n.h> +#include <libgnomeui/gnome-dialog.h> +#include <libgnomeui/gnome-file-entry.h> +#include <libgnomeui/gnome-icon-list.h> +#include <libgnomeui/gnome-icon-sel.h> +#include <libgnomeui/gnome-stock.h> #include <libgnomeui/gnome-uidefs.h> #include <libgnomevfs/gnome-vfs.h> #include <libnautilus-extensions/nautilus-customization-data.h> @@ -70,6 +75,9 @@ struct FMPropertiesWindowDetails { NautilusFile *file; GtkNotebook *notebook; GtkWidget *remove_image_button; + GtkWidget *icon_selection; + GtkWidget *file_entry; + guint file_changed_handler_id; GtkTable *basic_table; @@ -2323,89 +2331,163 @@ real_finalize (GtkObject *object) /* callbacks to handle adding and removing custom icons */ -/* utility routine to check if the passed-in uri is an image file */ static gboolean -ensure_uri_is_image(const char *uri) -{ - gboolean is_image; - GnomeVFSResult result; - GnomeVFSFileInfo *file_info; - - file_info = gnome_vfs_file_info_new (); - result = gnome_vfs_get_file_info - (uri, file_info, - GNOME_VFS_FILE_INFO_GET_MIME_TYPE - | GNOME_VFS_FILE_INFO_FOLLOW_LINKS); - is_image = nautilus_istr_has_prefix (file_info->mime_type, "image/") && (nautilus_strcmp (file_info->mime_type, "image/svg") != 0); - gnome_vfs_file_info_unref (file_info); - return is_image; +widget_destroy_callback (gpointer callback_data) +{ + gtk_widget_destroy (GTK_WIDGET (callback_data)); + return FALSE; } /* set the image of the file object to the selected file */ static void -set_custom_image (GtkWidget *widget, NautilusFile *file) +icon_selected_callback (GtkWidget *button, FMPropertiesWindow *properties_window) { - char *path_name, *path_uri; - GtkWidget *button; - GtkFileSelection *file_dialog; - gboolean is_image; + const gchar *icon_path; + NautilusFile *file; + GtkWidget *entry; - file_dialog = GTK_FILE_SELECTION (gtk_widget_get_toplevel (widget)); - path_name = g_strdup(gtk_file_selection_get_filename (GTK_FILE_SELECTION (file_dialog))); + g_return_if_fail (properties_window != NULL); + g_return_if_fail (FM_IS_PROPERTIES_WINDOW (properties_window)); - /* ensure that the path name is an image */ - path_uri = gnome_vfs_get_uri_from_local_path (path_name); - is_image = ensure_uri_is_image(path_uri); - g_free(path_uri); - - if (!is_image) { - char *message = g_strdup_printf (_("Sorry, but '%s' is not a usable image file!"), path_name); - nautilus_show_error_dialog (message, _("Not an Image"), NULL); - g_free (message); - g_free (path_name); - return; + gnome_icon_selection_stop_loading ( GNOME_ICON_SELECTION (properties_window->details->icon_selection)); + + entry = gnome_file_entry_gtk_entry (GNOME_FILE_ENTRY (properties_window->details->file_entry)); + icon_path = gtk_entry_get_text (GTK_ENTRY (entry)); + + if (icon_path != NULL) { + file = properties_window->details->file; + nautilus_file_set_metadata (file, NAUTILUS_METADATA_KEY_CUSTOM_ICON, NULL, icon_path); + nautilus_file_set_metadata (file, NAUTILUS_METADATA_KEY_ICON_SCALE, NULL, NULL); + + /* re-enable the property window's clear image button */ + gtk_widget_set_sensitive (properties_window->details->remove_image_button, TRUE); } + + /* we have to get rid of the icon selection dialog, but we can't do it now, since the + * file entry might still need it. Do it when the next idle rolls around + */ + g_idle_add (widget_destroy_callback, gtk_widget_get_toplevel (button)); +} - nautilus_file_set_metadata (file, NAUTILUS_METADATA_KEY_CUSTOM_ICON, NULL, path_name); - nautilus_file_set_metadata (file, NAUTILUS_METADATA_KEY_ICON_SCALE, NULL, NULL); +/* handle the cancel button being pressed */ +static void +icon_cancel_pressed (GtkWidget *button, FMPropertiesWindow *properties_window) +{ + g_return_if_fail (properties_window != NULL); + g_return_if_fail (FM_IS_PROPERTIES_WINDOW (properties_window)); + + gnome_icon_selection_stop_loading(GNOME_ICON_SELECTION (properties_window->details->icon_selection)); - g_free (path_name); + gtk_widget_destroy (gtk_widget_get_toplevel (button)); +} - /* re- enable the property window's clear image button */ - button = GTK_WIDGET (gtk_object_get_user_data (GTK_OBJECT (file_dialog))); - gtk_widget_set_sensitive (button, TRUE); +/* handle an icon being selected by updating the file entry */ +static void +list_icon_selected_callback (GnomeIconList *gil, gint num, GdkEvent *event, FMPropertiesWindow *properties_window) +{ + const gchar *icon; + GtkWidget *entry; - /* we're done with the file dialog */ - gtk_widget_destroy (GTK_WIDGET (file_dialog)); + icon = gnome_icon_selection_get_icon (GNOME_ICON_SELECTION (properties_window->details->icon_selection), TRUE); + + if (icon != NULL) { + entry = gnome_file_entry_gtk_entry (GNOME_FILE_ENTRY (properties_window->details->file_entry)); + gtk_entry_set_text(GTK_ENTRY (entry), icon); + } + + /* handle double-clicks as if the user pressed OK */ + if(event && event->type == GDK_2BUTTON_PRESS && ((GdkEventButton *)event)->button == 1) { + icon_selected_callback (properties_window->details->file_entry, properties_window); + } } -/* handle the "select" button */ +/* handle the file entry changing */ +static void +entry_activated (GtkWidget *widget, FMPropertiesWindow *properties_window) +{ + struct stat buf; + GtkWidget *icon_selection; + gchar *filename; + + g_return_if_fail (properties_window != NULL); + g_return_if_fail (FM_IS_PROPERTIES_WINDOW (properties_window)); + + filename = gtk_entry_get_text (GTK_ENTRY (widget)); + if (!filename) { + return; + } + + stat (filename, &buf); + if (S_ISDIR (buf.st_mode)) { + icon_selection = properties_window->details->icon_selection; + gnome_icon_selection_clear (GNOME_ICON_SELECTION (icon_selection), TRUE); + gnome_icon_selection_add_directory (GNOME_ICON_SELECTION (icon_selection), filename); + gnome_icon_selection_show_icons(GNOME_ICON_SELECTION (icon_selection)); + } else { + /* We pretend like ok has been called */ + icon_selected_callback (properties_window->details->file_entry, properties_window); + } +} + +/* handle the "select icon" button */ static void select_image_button_callback (GtkWidget *widget, NautilusFile *file) { - GtkFileSelection *file_dialog; - FMPropertiesWindow *window; + GtkWidget *dialog, *entry; + FMPropertiesWindow *properties_window; - window = FM_PROPERTIES_WINDOW (gtk_widget_get_toplevel (widget)); + properties_window = FM_PROPERTIES_WINDOW (gtk_widget_get_toplevel (widget)); - file_dialog = GTK_FILE_SELECTION (gtk_file_selection_new - (_("Select an image to represent the file:"))); + dialog = gnome_dialog_new(_("Select an icon:"), + GNOME_STOCK_BUTTON_OK, + GNOME_STOCK_BUTTON_CANCEL, + NULL); + + gnome_dialog_close_hides(GNOME_DIALOG(dialog), TRUE); + gnome_dialog_set_close (GNOME_DIALOG(dialog), TRUE); + + gtk_window_set_policy(GTK_WINDOW(dialog), TRUE, TRUE, TRUE); + + properties_window->details->icon_selection = gnome_icon_selection_new(); + + properties_window->details->file_entry = gnome_file_entry_new (NULL,NULL); + gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(dialog)->vbox), + properties_window->details->file_entry, FALSE, FALSE, 0); + + gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(dialog)->vbox), + properties_window->details->icon_selection, TRUE, TRUE, 0); + + gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE); + gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (properties_window)); + gtk_window_set_wmclass (GTK_WINDOW (dialog), "file_selector", "Nautilus"); + gtk_widget_show_all (dialog); + + + entry = gnome_file_entry_gtk_entry (GNOME_FILE_ENTRY (properties_window->details->file_entry)); + gtk_entry_set_text(GTK_ENTRY (entry), DATADIR "/pixmaps"); + + gnome_icon_selection_add_directory(GNOME_ICON_SELECTION (properties_window->details->icon_selection), + DATADIR "/pixmaps"); + gnome_icon_selection_show_icons( GNOME_ICON_SELECTION (properties_window->details->icon_selection)); + + gnome_dialog_button_connect(GNOME_DIALOG(dialog), + 0, /* OK button */ + GTK_SIGNAL_FUNC(icon_selected_callback), + properties_window); - gtk_object_set_user_data (GTK_OBJECT (file_dialog), window->details->remove_image_button); + gnome_dialog_button_connect(GNOME_DIALOG(dialog), + 1, /* Cancel button */ + GTK_SIGNAL_FUNC(icon_cancel_pressed), + properties_window); - gtk_signal_connect (GTK_OBJECT (file_dialog->ok_button), - "clicked", - set_custom_image, - file); - gtk_signal_connect_object (GTK_OBJECT (file_dialog->cancel_button), - "clicked", - gtk_widget_destroy, - GTK_OBJECT (file_dialog)); - - gtk_window_set_position (GTK_WINDOW (file_dialog), GTK_WIN_POS_MOUSE); - gtk_window_set_transient_for (GTK_WINDOW (file_dialog), GTK_WINDOW (window)); - gtk_window_set_wmclass (GTK_WINDOW (file_dialog), "file_selector", "Nautilus"); - gtk_widget_show (GTK_WIDGET (file_dialog)); + gtk_signal_connect_after(GTK_OBJECT (GNOME_ICON_SELECTION (properties_window->details->icon_selection)->gil), + "select_icon", + GTK_SIGNAL_FUNC(list_icon_selected_callback), + properties_window); + + gtk_signal_connect_while_alive( GTK_OBJECT (entry), "activate", + GTK_SIGNAL_FUNC(entry_activated), + properties_window, GTK_OBJECT (properties_window->details->file_entry)); } static void |