Mercurial > geeqie
changeset 143:0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
author | nadvornik |
---|---|
date | Mon, 08 Oct 2007 19:41:49 +0000 |
parents | b5aa95241859 |
children | 2310066cc55a |
files | src/filelist.c src/filelist.h src/typedefs.h src/utilops.c src/view_file_list.c |
diffstat | 5 files changed, 85 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
--- a/src/filelist.c Tue Oct 02 21:49:02 2007 +0000 +++ b/src/filelist.c Mon Oct 08 19:41:49 2007 +0000 @@ -756,22 +756,27 @@ } -FileDataChangeInfo *file_data_change_info_new(const gchar *src, const gchar *dest, FileData *fd) +gboolean file_data_add_change_info(FileData *fd, FileDataChangeType type, const gchar *src, const gchar *dest) { - FileDataChangeInfo *fdci = g_new0(FileDataChangeInfo, 1); + + FileDataChangeInfo *fdci; + + if (fd->change) return FALSE; + + fdci = g_new0(FileDataChangeInfo, 1); + + fdci->type = type; if (src) fdci->source = g_strdup(src); + else + fdci->source = g_strdup(fd->path); + if (dest) fdci->dest = g_strdup(dest); - if (fd) - { - if (fd->change) - file_data_change_info_free(fd->change, NULL); - fd->change = fdci; - } - return fdci; + fd->change = fdci; + return TRUE; } void file_data_change_info_free(FileDataChangeInfo *fdci, FileData *fd)
--- a/src/filelist.h Tue Oct 02 21:49:02 2007 +0000 +++ b/src/filelist.h Mon Oct 08 19:41:49 2007 +0000 @@ -60,7 +60,7 @@ void file_data_unref(FileData *fd); FileData *file_data_do_change(FileData *fd); -FileDataChangeInfo *file_data_change_info_new(const gchar *src, const gchar *dest, FileData *fd); +gboolean file_data_add_change_info(FileData *fd, FileDataChangeType type, const gchar *src, const gchar *dest); void file_data_change_info_free(FileDataChangeInfo *fdci, FileData *fd); gchar *sidecar_file_data_list_to_string(FileData *fd);
--- a/src/typedefs.h Tue Oct 02 21:49:02 2007 +0000 +++ b/src/typedefs.h Mon Oct 08 19:41:49 2007 +0000 @@ -68,6 +68,14 @@ SPLIT_QUAD, } ImageSplitMode; +typedef enum { + FILEDATA_CHANGE_DELETE, + FILEDATA_CHANGE_MOVE, + FILEDATA_CHANGE_RENAME, + FILEDATA_CHANGE_COPY +} FileDataChangeType; + + #define MAX_SPLIT_IMAGES 4 typedef struct _ImageLoader ImageLoader; @@ -329,6 +337,7 @@ #define FILEDATA_MARKS_SIZE 10 struct _FileDataChangeInfo { + FileDataChangeType type; gchar *source; gchar *dest; };
--- a/src/utilops.c Tue Oct 02 21:49:02 2007 +0000 +++ b/src/utilops.c Mon Oct 08 19:41:49 2007 +0000 @@ -777,17 +777,18 @@ } if (try) { - file_data_change_info_new(fdm->source_fd->path, fdm->dest, fdm->source_fd); if (fdm->copy) { - if (copy_file_ext(fdm->source_fd)) + if (file_data_add_change_info(fdm->source_fd, FILEDATA_CHANGE_COPY, fdm->source_fd->path, fdm->dest) && + copy_file_ext(fdm->source_fd)) { success = TRUE; } } else { - if (move_file_ext(fdm->source_fd)) + if (file_data_add_change_info(fdm->source_fd, FILEDATA_CHANGE_MOVE, fdm->source_fd->path, fdm->dest) && + move_file_ext(fdm->source_fd)) { success = TRUE; } @@ -1018,17 +1019,18 @@ else { gint success = FALSE; - file_data_change_info_new(fds->source_fd->path, fds->dest, fds->source_fd); if (fds->copy) { - if (copy_file_ext(fds->source_fd)) + if (file_data_add_change_info(fds->source_fd, FILEDATA_CHANGE_COPY, fds->source_fd->path, fds->dest) && + copy_file_ext(fds->source_fd)) { success = TRUE; } } else { - if (move_file_ext(fds->source_fd)) + if (file_data_add_change_info(fds->source_fd, FILEDATA_CHANGE_MOVE, fds->source_fd->path, fds->dest) && + move_file_ext(fds->source_fd)) { success = TRUE; } @@ -1516,13 +1518,17 @@ g_string_free(msg, TRUE); } - if (!(flags & EDITOR_ERROR_MASK)) + { - /* files were successfully deleted, call the maint functions */ while (list) { FileData *fd = list->data; - file_maint_removed(fd, list); + if (flags & EDITOR_ERROR_MASK) + /* an error occured -> no change -> delete change info */ + file_data_change_info_free(NULL, fd); + else + /* files were successfully deleted, call the maint functions and keep the change info forever */ + file_maint_removed(fd, list); list = list->next; } } @@ -1532,16 +1538,42 @@ static void file_util_delete_multiple_ok_cb(GenericDialog *gd, gpointer data) { GList *source_list = data; + GList *work = source_list; + gboolean ok = TRUE; + + while (work) + { + FileData *fd = work->data; + if (fd->change) ok = FALSE; /* another operation in progress */ + work = work->next; + } + + if (!ok) + { + file_util_warning_dialog(_("File deletion failed"), _("Another operation in progress.\n"), GTK_STOCK_DIALOG_ERROR, NULL); + filelist_free(source_list); + return; + } + if (editor_command[CMD_DELETE]) { gint flags; + work = source_list; + while (work) + { + FileData *fd = work->data; + file_data_add_change_info(fd, FILEDATA_CHANGE_DELETE, NULL, NULL); + work = work->next; + } + if ((flags = start_editor_from_filelist_full(CMD_DELETE, source_list, file_util_delete_ext_cb, NULL))) { gchar *text = g_strdup_printf(_("%s\nUnable to delete files by external command.\n"), editor_get_error_str(flags)); file_util_warning_dialog(_("File deletion failed"), text, GTK_STOCK_DIALOG_ERROR, NULL); g_free(text); } + filelist_free(source_list); return; } @@ -1747,6 +1779,14 @@ { FileData *fd = data; + if (!file_data_add_change_info(fd, FILEDATA_CHANGE_DELETE, NULL, NULL)) + { + file_util_warning_dialog(_("File deletion failed"), _("Another operation in progress.\n"), GTK_STOCK_DIALOG_ERROR, NULL); + file_data_unref(fd); + return; + } + + if (editor_command[CMD_DELETE]) { gint flags; @@ -1755,6 +1795,7 @@ gchar *text = g_strdup_printf(_("%s\nUnable to delete file by external command:\n%s"), editor_get_error_str(flags), fd->path); file_util_warning_dialog(_("File deletion failed"), text, GTK_STOCK_DIALOG_ERROR, NULL); g_free(text); + file_data_change_info_free(NULL, fd); } } else if (!file_util_unlink(fd)) @@ -1762,6 +1803,7 @@ gchar *text = g_strdup_printf(_("Unable to delete file:\n%s"), fd->path); file_util_warning_dialog(_("File deletion failed"), text, GTK_STOCK_DIALOG_ERROR, NULL); g_free(text); + file_data_change_info_free(NULL, fd); } else { @@ -1968,8 +2010,8 @@ } else { - file_data_change_info_new(fdlg->source_fd->path, fdlg->dest_path, fdlg->source_fd); - if (!rename_file_ext(fdlg->source_fd)) + if (!file_data_add_change_info(fdlg->source_fd, FILEDATA_CHANGE_RENAME, fdlg->source_fd->path, fdlg->dest_path) || + !rename_file_ext(fdlg->source_fd)) { gchar *text = g_strdup_printf(_("Unable to rename file:\n%s\n to:\n%s"), fdlg->source_fd->name, @@ -2188,8 +2230,8 @@ dest = g_strdup_printf("%s/%s%0*d%s", base, front, padding, n, end); } - file_data_change_info_new(fd->path, dest, fd); - if (!rename_file_ext(fd)) + if (!file_data_add_change_info(fd, FILEDATA_CHANGE_RENAME, fd->path, dest) || + !rename_file_ext(fd)) { success = FALSE; } @@ -2690,8 +2732,8 @@ file_util_do_move_list(list, FALSE, TRUE); filelist_free(list); */ - file_data_change_info_new(fds->source_fd->path, fds->dest, fds->source_fd); - if (!rename_file_ext(fds->source_fd)) + if (!file_data_add_change_info(fds->source_fd, FILEDATA_CHANGE_RENAME, fds->source_fd->path, fds->dest) || + !rename_file_ext(fds->source_fd)) { gchar *text = g_strdup_printf(_("Unable to rename file:\n%s\nto:\n%s"), fds->source_fd->name, filename_from_path(fds->dest)); file_util_warning_dialog(_("Error renaming file"), text, GTK_STOCK_DIALOG_ERROR, NULL); @@ -2902,8 +2944,8 @@ return FALSE; } - file_data_change_info_new(old_fd->path, new_path, old_fd); - if (!rename_file_ext(old_fd)) + if (!file_data_add_change_info(old_fd, FILEDATA_CHANGE_RENAME, old_fd->path, new_path) || + !rename_file_ext(old_fd)) { gchar *text = g_strdup_printf(_("Failed to rename %s to %s."), old_name, new_name); file_util_warning_dialog(_("Rename failed"), text, GTK_STOCK_DIALOG_ERROR, parent);
--- a/src/view_file_list.c Tue Oct 02 21:49:02 2007 +0000 +++ b/src/view_file_list.c Mon Oct 08 19:41:49 2007 +0000 @@ -465,8 +465,8 @@ { GList *work = g_list_nth(vfl->list, row); FileData *fd = work->data; - file_data_change_info_new(old_path, new_path, fd); - if (!rename_file_ext(fd)) + + if (!file_data_add_change_info(fd, FILEDATA_CHANGE_RENAME, old_path, new_path) || !rename_file_ext(fd)) { gchar *text = g_strdup_printf(_("Unable to rename file:\n%s\nto:\n%s"), old, new); file_util_warning_dialog(_("Error renaming file"), text, GTK_STOCK_DIALOG_ERROR, vfl->listview);