changeset 389:b78077f65eff

Merge few more vdlist/vdtree functions.
author zas_
date Wed, 16 Apr 2008 21:58:05 +0000
parents 5186f8e38cb8
children 39369521e263
files src/view_dir.c src/view_dir.h src/view_dir_list.c src/view_dir_tree.c src/view_dir_tree.h
diffstat 5 files changed, 112 insertions(+), 145 deletions(-) [+]
line wrap: on
line diff
--- a/src/view_dir.c	Wed Apr 16 20:36:10 2008 +0000
+++ b/src/view_dir.c	Wed Apr 16 21:58:05 2008 +0000
@@ -17,6 +17,7 @@
 #include "layout_image.h"
 #include "layout_util.h"
 #include "ui_fileops.h"
+#include "ui_tree_edit.h"
 #include "ui_menu.h"
 #include "utilops.h"
 #include "view_dir_list.h"
@@ -130,26 +131,106 @@
 	return ret;
 }
 
+gint vd_find_row(ViewDir *vd, FileData *fd, GtkTreeIter *iter)
+{
+	gint ret = FALSE;
+
+	switch(vd->type)
+	{
+	case DIRVIEW_LIST: ret = vdlist_find_row(vd, fd, iter); break;
+	case DIRVIEW_TREE: ret = vdtree_find_row(vd, fd, iter, NULL); break;
+	}
+
+	return ret;
+}
+
+static gint vd_rename_cb(TreeEditData *td, const gchar *old, const gchar *new, gpointer data)
+{
+	ViewDir *vd = data;
+	GtkTreeModel *store;
+	GtkTreeIter iter;
+	FileData *fd;
+	gchar *old_path;
+	gchar *new_path;
+	gchar *base;
+
+	store = gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view));
+	if (!gtk_tree_model_get_iter(store, &iter, td->path)) return FALSE;
+
+	switch(vd->type)
+	{
+	case DIRVIEW_LIST:
+		gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &fd, -1);
+		break;
+	case DIRVIEW_TREE:
+		{
+		NodeData *nd;
+		gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &nd, -1);
+		if (!nd) return FALSE;
+		fd = nd->fd;
+		};
+		break;
+	}
+
+	if (!fd) return FALSE;
+
+	old_path = g_strdup(fd->path);
+
+	base = remove_level_from_path(old_path);
+	new_path = concat_dir_and_file(base, new);
+	g_free(base);
+
+	if (file_util_rename_dir(fd, new_path, vd->view))
+		{
+
+		if (vd->type == DIRVIEW_TREE) vdtree_populate_path(vd, new_path, TRUE, TRUE);
+		if (vd->layout && strcmp(vd->path, old_path) == 0)
+			{
+			layout_set_path(vd->layout, new_path);
+			}
+		else
+			{
+			if (vd->type == DIRVIEW_LIST) vd_refresh(vd);
+			}
+		}
+
+	g_free(old_path);
+	g_free(new_path);
+
+	return FALSE;
+}
+
+static void vd_rename_by_data(ViewDir *vd, FileData *fd)
+{
+	GtkTreeModel *store;
+	GtkTreePath *tpath;
+	GtkTreeIter iter;
+
+	if (!fd || vd_find_row(vd, fd, &iter) < 0) return;
+	store = gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view));
+	tpath = gtk_tree_model_get_path(store, &iter);
+
+	tree_edit_by_path(GTK_TREE_VIEW(vd->view), tpath, 0, fd->name,
+			  vd_rename_cb, vd);
+	gtk_tree_path_free(tpath);
+}
+
+
 void vd_color_set(ViewDir *vd, FileData *fd, gint color_set)
 {
 	GtkTreeModel *store;
 	GtkTreeIter iter;
 
+	if (vd_find_row(vd, fd, &iter) < 0) return;
+	store = gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view));
+
 	switch(vd->type)
 	{
 	case DIRVIEW_LIST:
-		{
-		if (vdlist_find_row(vd, fd, &iter) < 0) return;
-		store = gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view));
 		gtk_list_store_set(GTK_LIST_STORE(store), &iter, DIR_COLUMN_COLOR, color_set, -1);
-		}
 		break;
 	case DIRVIEW_TREE:
-		{
-		if (vdtree_find_row(vd, fd, &iter, NULL) < 0) return;
-		store = gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view));
 		gtk_tree_store_set(GTK_TREE_STORE(store), &iter, DIR_COLUMN_COLOR, color_set, -1);
-		}
 		break;
 	}
 }
@@ -390,27 +471,21 @@
 		}
 	else
 		{
+		FileData *fd = NULL;
+
 		switch(vd->type)
 			{
 			case DIRVIEW_LIST:
 				{
-				FileData *fd;
-	
 				vd_refresh(vd);
 				fd = vdlist_row_by_path(vd, new_path, NULL);
-	
-				vdlist_rename_by_row(vd, fd);
 				};
 				break;
 			case DIRVIEW_TREE:
-				{
-				FileData *fd;
-
 				fd = vdtree_populate_path(vd, new_path, TRUE, TRUE);
-				vdtree_rename_by_data(vd, fd);
-				};
 				break;
 			}
+		vd_rename_by_data(vd, fd);
 		}
 
 	g_free(new_path);
@@ -420,11 +495,7 @@
 {
 	ViewDir *vd = data;
 	
-	switch(vd->type)
-	{
-	case DIRVIEW_LIST: vdlist_rename_by_row(vd, vd->click_fd); break;
-	case DIRVIEW_TREE: vdtree_rename_by_data(vd, vd->click_fd); break;
-	}
+	vd_rename_by_data(vd, vd->click_fd);
 }
 
 GtkWidget *vd_pop_menu(ViewDir *vd, FileData *fd)
--- a/src/view_dir.h	Wed Apr 16 20:36:10 2008 +0000
+++ b/src/view_dir.h	Wed Apr 16 21:58:05 2008 +0000
@@ -32,6 +32,7 @@
 
 gint vd_set_path(ViewDir *vdl, const gchar *path);
 void vd_refresh(ViewDir *vdl);
+gint vd_find_row(ViewDir *vd, FileData *fd, GtkTreeIter *iter);
 
 const gchar *vd_row_get_path(ViewDir *vdl, gint row);
 
--- a/src/view_dir_list.c	Wed Apr 16 20:36:10 2008 +0000
+++ b/src/view_dir_list.c	Wed Apr 16 21:58:05 2008 +0000
@@ -62,58 +62,6 @@
 	return -1;
 }
 
-static gint vdlist_rename_row_cb(TreeEditData *td, const gchar *old, const gchar *new, gpointer data)
-{
-	ViewDir *vd = data;
-	GtkTreeModel *store;
-	GtkTreeIter iter;
-	FileData *fd;
-	gchar *old_path;
-	gchar *new_path;
-	gchar *base;
-
-	store = gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view));
-	if (!gtk_tree_model_get_iter(store, &iter, td->path)) return FALSE;
-	gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &fd, -1);
-	if (!fd) return FALSE;
-	
-	old_path = g_strdup(fd->path);
-
-	base = remove_level_from_path(old_path);
-	new_path = concat_dir_and_file(base, new);
-	g_free(base);
-
-	if (file_util_rename_dir(fd, new_path, vd->view))
-		{
-		if (vd->layout && strcmp(vd->path, old_path) == 0)
-			{
-			layout_set_path(vd->layout, new_path);
-			}
-		else
-			{
-			vdlist_refresh(vd);
-			}
-		}
-
-	g_free(old_path);
-	g_free(new_path);
-	return FALSE;
-}
-
-void vdlist_rename_by_row(ViewDir *vd, FileData *fd)
-{
-	GtkTreeModel *store;
-	GtkTreePath *tpath;
-	GtkTreeIter iter;
-
-	if (vdlist_find_row(vd, fd, &iter) < 0) return;
-	store = gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view));
-	tpath = gtk_tree_model_get_path(store, &iter);
-
-	tree_edit_by_path(GTK_TREE_VIEW(vd->view), tpath, 0, fd->name,
-			  vdlist_rename_row_cb, vd);
-	gtk_tree_path_free(tpath);
-}
 
 FileData *vdlist_row_by_path(ViewDir *vd, const gchar *path, gint *row)
 {
@@ -274,7 +222,7 @@
 	GdkRectangle vrect;
 	GdkRectangle crect;
 
-	if (!fd || vdlist_find_row(vd, fd, &iter) < 0) return 0;
+	if (!fd || vd_find_row(vd, fd, &iter) < 0) return 0;
 
 	column = gtk_tree_view_get_column(GTK_TREE_VIEW(vd->view), 0);
 	store = gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view));
@@ -296,7 +244,7 @@
 	GtkTreeIter iter;
 
 	if (GTK_WIDGET_REALIZED(vd->view) &&
-	    vdlist_find_row(vd, fd, &iter) >= 0)
+	    vd_find_row(vd, fd, &iter) >= 0)
 		{
 		GtkTreeModel *store;
 		GtkTreePath *tpath;
@@ -613,7 +561,7 @@
 	GtkTreePath *tpath;
 	gint cw, ch;
 
-	if (vdlist_find_row(vd, vd->click_fd, &iter) < 0) return;
+	if (vd_find_row(vd, vd->click_fd, &iter) < 0) return;
 	store = gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view));
 	tpath = gtk_tree_model_get_path(store, &iter);
 	tree_view_get_cell_clamped(GTK_TREE_VIEW(vd->view), tpath, 0, TRUE, x, y, &cw, &ch);
--- a/src/view_dir_tree.c	Wed Apr 16 20:36:10 2008 +0000
+++ b/src/view_dir_tree.c	Wed Apr 16 21:58:05 2008 +0000
@@ -42,13 +42,6 @@
 	FileData *node;
 };
 
-typedef struct _NodeData NodeData;
-struct _NodeData
-{
-	FileData *fd;
-	gint expanded;
-	time_t last_update;
-};
 
 
 static gint vdtree_populate_path_by_iter(ViewDir *vd, GtkTreeIter *iter, gint force, const gchar *target_path);
@@ -154,66 +147,12 @@
 {
 	GtkTreeIter iter;
 
-	if (vdtree_find_row(vd, fd, &iter, NULL))
+	if (vd_find_row(vd, fd, &iter))
 		{
 		vdtree_expand_by_iter(vd, &iter, expand);
 		}
 }
 
-static gint vdtree_rename_row_cb(TreeEditData *td, const gchar *old, const gchar *new, gpointer data)
-{
-	ViewDir *vd = data;
-	GtkTreeModel *store;
-	GtkTreeIter iter;
-	NodeData *nd;
-	gchar *old_path;
-	gchar *new_path;
-	gchar *base;
-
-	store = gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view));
-	if (!gtk_tree_model_get_iter(store, &iter, td->path)) return FALSE;
-	gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &nd, -1);
-	if (!nd) return FALSE;
-
-	old_path = g_strdup(nd->fd->path);
-
-	base = remove_level_from_path(old_path);
-	new_path = concat_dir_and_file(base, new);
-	g_free(base);
-
-	if (file_util_rename_dir(nd->fd, new_path, vd->view))
-		{
-		vdtree_populate_path(vd, new_path, TRUE, TRUE);
-
-		if (vd->layout && strcmp(vd->path, old_path) == 0)
-			{
-			layout_set_path(vd->layout, new_path);
-			}
-		}
-
-	g_free(old_path);
-	g_free(new_path);
-
-	return FALSE;
-}
-
-void vdtree_rename_by_data(ViewDir *vd, FileData *fd)
-{
-	GtkTreeModel *store;
-	GtkTreePath *tpath;
-	GtkTreeIter iter;
-
-	if (!fd ||
-	    !vdtree_find_row(vd, fd, &iter, NULL)) return;
-
-	store = gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view));
-	tpath = gtk_tree_model_get_path(store, &iter);
-
-	tree_edit_by_path(GTK_TREE_VIEW(vd->view), tpath, 0, fd->name,
-			  vdtree_rename_row_cb, vd);
-	gtk_tree_path_free(tpath);
-}
-
 static void vdtree_node_free(NodeData *nd)
 {
 	if (!nd) return;
@@ -347,7 +286,7 @@
 	GtkTreeIter iter;
 
 	if (vd->drop_fd &&
-	    vdtree_find_row(vd, vd->drop_fd, &iter, NULL))
+	    vd_find_row(vd, vd->drop_fd, &iter))
 		{
 		vdtree_populate_path_by_iter(vd, &iter, FALSE, vd->path);
 		vdtree_expand_by_data(vd, vd->drop_fd, TRUE);
@@ -900,7 +839,7 @@
 
 			parent_pd = work->prev->data;
 
-			if (!vdtree_find_row(vd, parent_pd->node, &parent_iter, NULL) ||
+			if (!vd_find_row(vd, parent_pd->node, &parent_iter) ||
 			    !vdtree_populate_path_by_iter(vd, &parent_iter, force, path) ||
 			    (nd = vdtree_find_iter_by_name(vd, &parent_iter, pd->name, &iter)) == NULL)
 				{
@@ -926,7 +865,7 @@
 			{
 			GtkTreeIter iter;
 
-			if (vdtree_find_row(vd, pd->node, &iter, NULL))
+			if (vd_find_row(vd, pd->node, &iter))
 				{
 				if (expand) vdtree_expand_by_iter(vd, &iter, TRUE);
 				vdtree_populate_path_by_iter(vd, &iter, force, path);
@@ -968,7 +907,7 @@
 	GtkTreeSelection *selection;
 	GtkTreeIter iter;
                                                                                                                                
-	if (!vdtree_find_row(vd, fd, &iter, NULL)) return;
+	if (!vd_find_row(vd, fd, &iter)) return;
 	selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vd->view));
 
 	/* hack, such that selection is only allowed to be changed from here */
@@ -1001,7 +940,7 @@
 
 	if (!fd) return FALSE;
 
-	if (vdtree_find_row(vd, fd, &iter, NULL))
+	if (vd_find_row(vd, fd, &iter))
 		{
 		GtkTreeModel *store;
 		GtkTreePath *tpath;
@@ -1051,7 +990,7 @@
 	GtkTreePath *tpath;
 	gint cw, ch;
 
-	if (vdtree_find_row(vd, vd->click_fd, &iter, NULL) < 0) return;
+	if (vd_find_row(vd, vd->click_fd, &iter) < 0) return;
 	store = gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view));
 	tpath = gtk_tree_model_get_path(store, &iter);
 	tree_view_get_cell_clamped(GTK_TREE_VIEW(vd->view), tpath, 0, TRUE, x, y, &cw, &ch);
--- a/src/view_dir_tree.h	Wed Apr 16 20:36:10 2008 +0000
+++ b/src/view_dir_tree.h	Wed Apr 16 21:58:05 2008 +0000
@@ -12,6 +12,14 @@
 #ifndef VIEW_DIR_TREE_H
 #define VIEW_DIR_TREE_H
 
+typedef struct _NodeData NodeData;
+struct _NodeData
+{
+	FileData *fd;
+	gint expanded;
+	time_t last_update;
+};
+
 ViewDir *vdtree_new(ViewDir *vd, const gchar *path);
 
 gint vdtree_set_path(ViewDir *vd, const gchar *path);