diff src/view_dir.c @ 907:ca8022a156ec

added notification handler to view_dir
author nadvornik
date Mon, 21 Jul 2008 20:40:29 +0000
parents 1698baa37871
children fac2a1ed31a6
line wrap: on
line diff
--- 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