From a98d957baaf1b1206c5ae62e754145e157ead9ae Mon Sep 17 00:00:00 2001 From: Miguel de Icaza Date: Fri, 6 Aug 1999 20:10:34 +0000 Subject: [PATCH] 1999-08-06 Federico Mena Quintero * gdesktop.c (try_rename): New function to rename a desktop icon's file by using a file operation context. (text_changed): Use try_rename() instead of fiddling with the VFS directly. BUGFIX: GNOME bug tracker #707. Also, destroy the old icon before updating the desktop. --- gnome/ChangeLog | 8 ++++++ gnome/gdesktop.c | 63 +++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 62 insertions(+), 9 deletions(-) diff --git a/gnome/ChangeLog b/gnome/ChangeLog index 90ffbe93e..7a2f8e987 100644 --- a/gnome/ChangeLog +++ b/gnome/ChangeLog @@ -1,3 +1,11 @@ +1999-08-06 Federico Mena Quintero + + * gdesktop.c (try_rename): New function to rename a desktop icon's + file by using a file operation context. + (text_changed): Use try_rename() instead of fiddling with the VFS + directly. BUGFIX: GNOME bug tracker #707. Also, destroy the old + icon before updating the desktop. + 1999-08-06 Norbert Warmuth * gconf.h (PORT_STATIC_IN_STRING_FILE_XTIME): new port specific diff --git a/gnome/gdesktop.c b/gnome/gdesktop.c index be2363a12..d536cdf53 100644 --- a/gnome/gdesktop.c +++ b/gnome/gdesktop.c @@ -804,8 +804,41 @@ set_icon_wmclass (DesktopIconInfo *dii) XFree (h); } -/* - * Callback used when an icon's text changes. We must validate the +/* Renames a file using a file operation context */ +static int +try_rename (char *source, char *dest) +{ + FileOpContext *ctx; + struct stat s; + long count; + double bytes; + int retval; + + if (mc_lstat (source, &s) != 0) + return FILE_ABORT; + + ctx = file_op_context_new (); + file_op_context_create_ui (ctx, OP_MOVE, FALSE); + + count = 1; + bytes = s.st_size; + + retval = move_file_file (ctx, source, dest, &count, &bytes); + file_op_context_destroy (ctx); + + return retval; +} + +/* Removes the Gtk and Gdk grabs that are present when editing a desktop icon */ +static void +remove_editing_grab (DesktopIconInfo *dii) +{ + gtk_grab_remove (dii->dicon); + gdk_pointer_ungrab (GDK_CURRENT_TIME); + gdk_keyboard_ungrab (GDK_CURRENT_TIME); +} + +/* Callback used when an icon's text changes. We must validate the * rename and return the appropriate value. The desktop icon info * structure is passed in the user data. */ @@ -821,6 +854,7 @@ text_changed (GnomeIconTextItem *iti, gpointer data) int retval; dii = data; + remove_editing_grab (dii); source = g_concat_dir_and_file (desktop_directory, dii->filename); new_name = gnome_icon_text_item_get_text (iti); @@ -830,9 +864,23 @@ text_changed (GnomeIconTextItem *iti, gpointer data) dest = g_concat_dir_and_file (desktop_directory, new_name); - if (mc_rename (source, dest) == 0) { - gnome_metadata_delete (dest); - gnome_metadata_rename (source, dest); + if (try_rename (source, dest) == FILE_CONT) { + GList *icons; + GList *l; + + /* See if there was an icon for the new name. If so, + * destroy it first; desktop_reload_icons() will not be + * happy if two icons have the same filename. + */ + + icons = get_all_icons (); + l = icon_exists_in_list (icons, new_name); + if (l) + desktop_icon_info_destroy (l->data); + + g_list_free (icons); + + /* Set the new name */ g_free (dii->filename); dii->filename = g_strdup (new_name); @@ -928,10 +976,7 @@ editing_stopped (GnomeIconTextItem *iti, gpointer data) DesktopIconInfo *dii; dii = data; - - gtk_grab_remove (dii->dicon); - gdk_pointer_ungrab (GDK_CURRENT_TIME); - gdk_keyboard_ungrab (GDK_CURRENT_TIME); + remove_editing_grab (dii); /* Re-enable drags from this icon */