Skip to content

Commit

Permalink
added notification handler to view_dir
Browse files Browse the repository at this point in the history
  • Loading branch information
nadvornik committed Jul 21, 2008
1 parent c8f289f commit 8973689
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 29 deletions.
1 change: 1 addition & 0 deletions src/utilops.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
94 changes: 72 additions & 22 deletions src/view_dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand All @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
13 changes: 6 additions & 7 deletions src/view_dir_tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ struct _PathData



static gint vdtree_populate_path_by_iter(ViewDir *vd, GtkTreeIter *iter, gint force, FileData *target_fd);


/*
*----------------------------------------------------------------------------
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/view_dir_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ struct _NodeData
FileData *fd;
gint expanded;
time_t last_update;
gint version;
};

ViewDir *vdtree_new(ViewDir *vd, FileData *dir_fd);
Expand All @@ -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);
Expand Down

0 comments on commit 8973689

Please sign in to comment.