added notification handler to view_dir
authorVladimir Nadvornik <nadvornik@suse.cz>
Mon, 21 Jul 2008 20:40:29 +0000 (20:40 +0000)
committerVladimir Nadvornik <nadvornik@suse.cz>
Mon, 21 Jul 2008 20:40:29 +0000 (20:40 +0000)
src/utilops.c
src/view_dir.c
src/view_dir_tree.c
src/view_dir_tree.h

index d5d9b85..7641156 100644 (file)
@@ -707,6 +707,7 @@ static void file_util_perform_ci_dir(UtilityData *ud, gboolean internal, gboolea
                        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
index d9058fe..b52e03a 100644 (file)
@@ -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 @@ static void vd_destroy_cb(GtkWidget *widget, gpointer data)
 {
        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 @@ ViewDir *vd_new(DirViewType type, FileData *dir_fd)
 
        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 @@ static gint vd_rename_cb(TreeEditData *td, const gchar *old, const gchar *new, g
        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_toggle_show_hidden_files_cb(GtkWidget *widget, gpointer data)
 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 @@ static void vd_pop_menu_new_cb(GtkWidget *widget, gpointer data)
                        }
                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 @@ gint vd_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
 
        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
index 376cca3..096abe7 100644 (file)
@@ -41,8 +41,6 @@ struct _PathData
 
 
 
-static gint vdtree_populate_path_by_iter(ViewDir *vd, GtkTreeIter *iter, gint force, FileData *target_fd);
-
 
 /*
  *----------------------------------------------------------------------------
@@ -381,6 +379,7 @@ static void vdtree_add_by_data(ViewDir *vd, FileData *fd, GtkTreeIter *parent)
 
        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 void vdtree_add_by_data(ViewDir *vd, FileData *fd, GtkTreeIter *parent)
                }
 }
 
-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 @@ static gint vdtree_populate_path_by_iter(ViewDir *vd, GtkTreeIter *iter, gint fo
                        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 @@ static gint vdtree_populate_path_by_iter(ViewDir *vd, GtkTreeIter *iter, gint fo
                        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);
index fc2342f..8ebac4a 100644 (file)
@@ -19,6 +19,7 @@ struct _NodeData
        FileData *fd;
        gint expanded;
        time_t last_update;
+       gint version;
 };
 
 ViewDir *vdtree_new(ViewDir *vd, FileData *dir_fd);
@@ -30,6 +31,7 @@ void vdtree_refresh(ViewDir *vd);
 
 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);