Mercurial > geeqie
changeset 907:ca8022a156ec
added notification handler to view_dir
author | nadvornik |
---|---|
date | Mon, 21 Jul 2008 20:40:29 +0000 |
parents | f81a212e7642 |
children | 5a737cc935cc |
files | src/utilops.c src/view_dir.c src/view_dir_tree.c src/view_dir_tree.h |
diffstat | 4 files changed, 81 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
--- a/src/utilops.c Mon Jul 21 08:31:43 2008 +0000 +++ b/src/utilops.c Mon Jul 21 20:40:29 2008 +0000 @@ -707,6 +707,7 @@ if ((internal && mkdir_utf8(ud->dir_fd->path, 0755)) || (!internal && ext_result)) { + file_data_increment_version(ud->dir_fd); file_data_send_notification(ud->dir_fd, NOTIFY_TYPE_REREAD); } else
--- a/src/view_dir.c Mon Jul 21 08:31:43 2008 +0000 +++ b/src/view_dir.c Mon Jul 21 20:40:29 2008 +0000 @@ -26,6 +26,8 @@ #include "view_dir_list.h" #include "view_dir_tree.h" +static void vd_notify_cb(FileData *fd, NotifyType type, gpointer data); + GtkRadioActionEntry menu_view_dir_radio_entries[] = { { "FolderList", NULL, N_("_List"), "<meta>L", NULL, DIRVIEW_LIST }, { "FolderTree", NULL, N_("_Tree"), "<control>T", NULL, DIRVIEW_TREE }, @@ -35,6 +37,8 @@ { ViewDir *vd = data; + file_data_unregister_notify_func(vd_notify_cb, vd); + if (vd->popup) { g_signal_handlers_disconnect_matched(G_OBJECT(vd->popup), G_SIGNAL_MATCH_DATA, @@ -106,6 +110,8 @@ if (dir_fd) vd_set_fd(vd, dir_fd); + file_data_register_notify_func(vd_notify_cb, vd, NOTIFY_PRIORITY_HIGH); + gtk_widget_show(vd->view); return vd; @@ -219,18 +225,11 @@ new_path = g_build_filename(base, new, NULL); g_free(base); - if (file_util_rename_dir(fd, new_path, vd->view)) + file_util_rename_dir(fd, new_path, vd->view); + + if (vd->layout && vd->dir_fd != fd) { - - if (vd->type == DIRVIEW_TREE) vdtree_populate_path(vd, fd, TRUE, TRUE); - if (vd->layout && vd->dir_fd != fd) /* FIXME */ - { - layout_set_path(vd->layout, new_path); - } - else - { - if (vd->type == DIRVIEW_LIST) vd_refresh(vd); - } + layout_set_path(vd->layout, new_path); } g_free(new_path); @@ -506,31 +505,28 @@ static void vd_pop_menu_new_cb(GtkWidget *widget, gpointer data) { ViewDir *vd = data; - const gchar *path = NULL; - gchar *new_path; - gchar *buf; + FileData *dir_fd = NULL; switch(vd->type) { case DIRVIEW_LIST: { if (!vd->dir_fd) return; - path = vd->dir_fd->path; + dir_fd = vd->dir_fd; }; break; case DIRVIEW_TREE: { if (!vd->click_fd) return; - path = vd->click_fd->path; + dir_fd = vd->click_fd; }; break; } - buf = g_build_filename(path, _("new_folder"), NULL); - new_path = unique_filename(buf, NULL, NULL, FALSE); - g_free(buf); - if (!new_path) return; + file_util_create_dir(dir_fd, widget); +/* FIXME:*/ +#if 0 if (!mkdir_utf8(new_path, 0755)) { gchar *text; @@ -561,8 +557,7 @@ } vd_rename_by_data(vd, fd); } - - g_free(new_path); +#endif } static void vd_pop_menu_rename_cb(GtkWidget *widget, gpointer data) @@ -1039,3 +1034,58 @@ return ret; } + +static void vd_notify_cb(FileData *fd, NotifyType type, gpointer data) +{ + ViewDir *vd = data; + gboolean refresh; + gchar *base; + + if (!isdir(fd->path) && isname(fd->path)) return; + + base = remove_level_from_path(fd->path); + + if (vd->type == DIRVIEW_LIST) + { + refresh = (fd == vd->dir_fd); + + if (!refresh) + { + refresh = (strcmp(base, vd->dir_fd->path) == 0); + } + + if (type == NOTIFY_TYPE_CHANGE && fd->change) + { + if (!refresh && fd->change->dest) + { + gchar *dest_base = remove_level_from_path(fd->change->dest); + refresh = (strcmp(dest_base, vd->dir_fd->path) == 0); + g_free(dest_base); + } + + if (!refresh && fd->change->source) + { + gchar *source_base = remove_level_from_path(fd->change->source); + refresh = (strcmp(source_base, vd->dir_fd->path) == 0); + g_free(source_base); + } + } + + if (refresh) vd_refresh(vd); + } + + if (vd->type == DIRVIEW_TREE) + { + GtkTreeIter iter; + FileData *base_fd = file_data_new_simple(base); + + if (vd_find_row(vd, base_fd, &iter)) + { + vdtree_populate_path_by_iter(vd, &iter, FALSE, vd->dir_fd); + } + + file_data_unref(base_fd); + } + + g_free(base); +} \ No newline at end of file
--- a/src/view_dir_tree.c Mon Jul 21 08:31:43 2008 +0000 +++ b/src/view_dir_tree.c Mon Jul 21 20:40:29 2008 +0000 @@ -41,8 +41,6 @@ -static gint vdtree_populate_path_by_iter(ViewDir *vd, GtkTreeIter *iter, gint force, FileData *target_fd); - /* *---------------------------------------------------------------------------- @@ -381,6 +379,7 @@ nd = g_new0(NodeData, 1); nd->fd = fd; + nd->version = fd->version; nd->expanded = FALSE; nd->last_update = time(NULL); @@ -418,7 +417,7 @@ } } -static gint vdtree_populate_path_by_iter(ViewDir *vd, GtkTreeIter *iter, gint force, FileData *target_fd) +gint vdtree_populate_path_by_iter(ViewDir *vd, GtkTreeIter *iter, gint force, FileData *target_fd) { GtkTreeModel *store; GList *list; @@ -446,7 +445,7 @@ vdtree_node_free(nd); return FALSE; } - if (!force && filetime(nd->fd->path) == nd->fd->date) return TRUE; + if (!force && nd->fd->version == nd->version) return TRUE; } vdtree_busy_push(vd); @@ -513,11 +512,11 @@ if (cnd) { old = g_list_remove(old, cnd); - if (cnd->expanded && cnd->fd->date != fd->date && + if (cnd->expanded && cnd->version != fd->version && vdtree_populate_path_by_iter(vd, &child, FALSE, target_fd)) { - cnd->fd->size = fd->size; - cnd->fd->date = fd->date; + gtk_tree_store_set(store, &child, DIR_COLUMN_NAME, fd->name, -1); + cnd->version = fd->version; } file_data_unref(fd);
--- a/src/view_dir_tree.h Mon Jul 21 08:31:43 2008 +0000 +++ b/src/view_dir_tree.h Mon Jul 21 20:40:29 2008 +0000 @@ -19,6 +19,7 @@ FileData *fd; gint expanded; time_t last_update; + gint version; }; ViewDir *vdtree_new(ViewDir *vd, FileData *dir_fd); @@ -30,6 +31,7 @@ const gchar *vdtree_row_get_path(ViewDir *vd, gint row); gint vdtree_find_row(ViewDir *vd, FileData *fd, GtkTreeIter *iter, GtkTreeIter *parent); +gint vdtree_populate_path_by_iter(ViewDir *vd, GtkTreeIter *iter, gint force, FileData *target_fd); FileData *vdtree_populate_path(ViewDir *vd, FileData *target_fd, gint expand, gint force); void vdtree_rename_by_data(ViewDir *vd, FileData *fd);