From 92d41b2b36067f3b1c1bb7057116615c2174cab2 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Sun, 30 Jul 2000 17:27:45 +0000 Subject: [PATCH] r340: Renaming now uses the action windows. This means that you can now rename something onto another filesystem. --- ROX-Filer/Help/Changes | 5 +++ ROX-Filer/Help/TODO | 2 -- ROX-Filer/src/action.c | 88 +++++++++++++++++++++++++++----------------------- ROX-Filer/src/action.h | 2 +- ROX-Filer/src/dnd.c | 2 +- ROX-Filer/src/menu.c | 17 ++++++---- 6 files changed, 65 insertions(+), 51 deletions(-) diff --git a/ROX-Filer/Help/Changes b/ROX-Filer/Help/Changes index 8a9e5d05..17137016 100644 --- a/ROX-Filer/Help/Changes +++ b/ROX-Filer/Help/Changes @@ -2,6 +2,11 @@ A RISC OS-like filer for X by Thomas Leonard +30-Jul-2000 +~~~~~~~~~~~ +Renaming now uses the action windows. This means that you can now +rename something onto another filesystem. + 28-Jul-2000 ~~~~~~~~~~~ The menu key bindings are now only saved if they actually changed. diff --git a/ROX-Filer/Help/TODO b/ROX-Filer/Help/TODO index 06d9ae02..1506d71d 100644 --- a/ROX-Filer/Help/TODO +++ b/ROX-Filer/Help/TODO @@ -8,8 +8,6 @@ someone sends patches!). BUGS -Rename box - use action window (currently doesn't work across file systems) - Moving a directory (outside of the filer) causes an error when you try to access it (OK), but the error is still reported when you open the directory in its new location until you click refresh. diff --git a/ROX-Filer/src/action.c b/ROX-Filer/src/action.c index b5fe6460..f92d085f 100644 --- a/ROX-Filer/src/action.c +++ b/ROX-Filer/src/action.c @@ -1334,8 +1334,7 @@ static char *make_dest_path(char *object, char *dir) return make_path(dir, leaf)->str; } -/* If action_leaf is not NULL it specifies the new leaf name - */ +/* If action_leaf is not NULL it specifies the new leaf name */ static gboolean do_copy2(char *path, char *dest) { char *dest_path; @@ -1482,50 +1481,18 @@ static gboolean do_copy2(char *path, char *dest) return retval; } -/* Copy path to dest. - * Check that path not copied into itself. - */ -static gboolean do_copy(char *path, char *dest) -{ - if (is_sub_dir(make_dest_path(path, dest), path)) - { - g_string_sprintf(message, - _("!ERROR: Can't copy object into itself\n")); - send(); - return FALSE; - } - return do_copy2(path, dest); -} - -/* Move path to dest. - * Check that path not moved into itself. - */ -static gboolean do_move(char *path, char *dest) +/* If action_leaf is not NULL it specifies the new leaf name */ +static gboolean do_move2(char *path, char *dest) { char *dest_path; - char *leaf; gboolean retval = TRUE; char *argv[] = {"mv", "-f", NULL, NULL, NULL}; struct stat info2; gboolean is_dir; - if (is_sub_dir(dest, path)) - { - g_string_sprintf(message, - _("!ERROR: Can't move object into itself\n")); - send(); - return FALSE; - } - check_flags(); - leaf = strrchr(path, '/'); - if (!leaf) - leaf = path; /* Error? */ - else - leaf++; - - dest_path = make_path(dest, leaf)->str; + dest_path = make_dest_path(path, dest); is_dir = mc_lstat(path, &info2) == 0 && S_ISDIR(info2.st_mode); @@ -1576,12 +1543,20 @@ static gboolean do_move(char *path, char *dest) } argv[2] = path; - argv[3] = dest; + argv[3] = dest_path; if (fork_exec_wait(argv) == 0) { + char *leaf; + + leaf = strrchr(dest_path, '/'); + if (!leaf) + leaf = dest_path; /* Error? */ + else + leaf++; + g_string_sprintf(message, "+%s", path); - g_string_truncate(message, leaf - path); + g_string_truncate(message, leaf - dest_path); send(); if (is_dir) { g_string_sprintf(message, "m%s", path); @@ -1600,6 +1575,36 @@ static gboolean do_move(char *path, char *dest) return retval; } +/* Copy path to dest. + * Check that path not copied into itself. + */ +static gboolean do_copy(char *path, char *dest) +{ + if (is_sub_dir(make_dest_path(path, dest), path)) + { + g_string_sprintf(message, + _("!ERROR: Can't copy object into itself\n")); + send(); + return FALSE; + } + return do_copy2(path, dest); +} + +/* Move path to dest. + * Check that path not moved into itself. + */ +static gboolean do_move(char *path, char *dest) +{ + if (is_sub_dir(make_dest_path(path, dest), path)) + { + g_string_sprintf(message, + _("!ERROR: Can't move/rename object into itself\n")); + send(); + return FALSE; + } + return do_move2(path, dest); +} + static gboolean do_link(char *path, char *dest) { char *dest_path; @@ -2074,6 +2079,7 @@ void action_chmod(FilerWindow *filer_window) gtk_widget_show_all(gui_side->window); } +/* If leaf is NULL then the copy has the same name as the original */ void action_copy(GSList *paths, char *dest, char *leaf) { GUIside *gui_side; @@ -2090,11 +2096,13 @@ void action_copy(GSList *paths, char *dest, char *leaf) gtk_widget_show_all(gui_side->window); } -void action_move(GSList *paths, char *dest) +/* If leaf is NULL then the file is not renamed */ +void action_move(GSList *paths, char *dest, char *leaf) { GUIside *gui_side; action_dest = dest; + action_leaf = leaf; action_do_func = do_move; gui_side = start_action(paths, list_cb, o_auto_move); if (!gui_side) diff --git a/ROX-Filer/src/action.h b/ROX-Filer/src/action.h index c0cfaed2..62e7dcf3 100644 --- a/ROX-Filer/src/action.h +++ b/ROX-Filer/src/action.h @@ -15,7 +15,7 @@ void action_mount(GList *paths); void action_delete(FilerWindow *filer_window); void action_chmod(FilerWindow *filer_window); void action_find(FilerWindow *filer_window); -void action_move(GSList *paths, char *dest); +void action_move(GSList *paths, char *dest, char *leaf); void action_copy(GSList *paths, char *dest, char *leaf); void action_link(GSList *paths, char *dest); void show_condition_help(gpointer data); diff --git a/ROX-Filer/src/dnd.c b/ROX-Filer/src/dnd.c index fafbfa51..d9d763df 100644 --- a/ROX-Filer/src/dnd.c +++ b/ROX-Filer/src/dnd.c @@ -1183,7 +1183,7 @@ static void got_uri_list(GtkWidget *widget, "remote files - sorry."); } else if (context->action == GDK_ACTION_MOVE) - action_move(local_paths, dest_path); + action_move(local_paths, dest_path, NULL); else if (context->action == GDK_ACTION_COPY) action_copy(local_paths, dest_path, NULL); else if (context->action == GDK_ACTION_LINK) diff --git a/ROX-Filer/src/menu.c b/ROX-Filer/src/menu.c index dcf6eaab..147faad2 100644 --- a/ROX-Filer/src/menu.c +++ b/ROX-Filer/src/menu.c @@ -56,6 +56,8 @@ #define MENU_MARGIN 32 +typedef void (*ActionFn)(GSList *paths, char *dest_dir, char *leaf); + GtkAccelGroup *filer_keys; GtkAccelGroup *panel_keys; GtkAccelGroup *pinboard_keys; @@ -85,6 +87,7 @@ static gint save_to_file(GtkSavebox *savebox, guchar *pathname); static GList *list_paths(FilerWindow *filer_window); static void free_paths(GList *paths); static void mark_menus_unmodified(void); +static gboolean action_with_leaf(ActionFn action, guchar *current, guchar *new); /* Note that for most of these callbacks none of the arguments are used. */ static void large(gpointer data, guint action, GtkWidget *widget); @@ -859,6 +862,11 @@ static gint save_to_file(GtkSavebox *savebox, guchar *pathname) static gboolean copy_cb(guchar *current, guchar *new) { + return action_with_leaf(action_copy, current, new); +} + +static gboolean action_with_leaf(ActionFn action, guchar *current, guchar *new) +{ char *new_dir, *leaf; GSList *local_paths; @@ -883,7 +891,7 @@ static gboolean copy_cb(guchar *current, guchar *new) } local_paths = g_slist_append(NULL, current); - action_copy(local_paths, new_dir, leaf); + action(local_paths, new_dir, leaf); g_slist_free(local_paths); g_free(new_dir); @@ -921,12 +929,7 @@ static void copy_item(gpointer data, guint action, GtkWidget *widget) static gboolean rename_cb(guchar *current, guchar *new) { - if (rename(current, new)) - { - report_error("ROX-Filer: rename()", g_strerror(errno)); - return FALSE; - } - return TRUE; + return action_with_leaf(action_move, current, new); } static void rename_item(gpointer data, guint action, GtkWidget *widget) -- 2.11.4.GIT