changeset 1628:66bf394d162a

simplified the code around vd_select_row
author nadvornik
date Fri, 05 Jun 2009 21:52:37 +0000
parents 1a134b4dc88c
children 0a72cb859b49
files src/layout.c src/typedefs.h src/view_dir.c src/view_dir.h src/view_dir_list.c src/view_dir_list.h src/view_dir_tree.c src/view_dir_tree.h
diffstat 8 files changed, 25 insertions(+), 54 deletions(-) [+]
line wrap: on
line diff
--- a/src/layout.c	Thu Jun 04 21:07:03 2009 +0000
+++ b/src/layout.c	Fri Jun 05 21:52:37 2009 +0000
@@ -242,11 +242,11 @@
 	g_free(buf);
 }
 
-static void layout_vd_select_cb(ViewDir *vd, const gchar *path, gpointer data)
+static void layout_vd_select_cb(ViewDir *vd, FileData *fd, gpointer data)
 {
 	LayoutWindow *lw = data;
 
-	layout_set_path(lw, path);
+	layout_set_fd(lw, fd);
 }
 
 static void layout_path_entry_tab_append_cb(const gchar *path, gpointer data, gint n)
--- a/src/typedefs.h	Thu Jun 04 21:07:03 2009 +0000
+++ b/src/typedefs.h	Fri Jun 05 21:52:37 2009 +0000
@@ -687,7 +687,7 @@
 	guint drop_scroll_id; /* event source id */
 
 	/* func list */
-	void (*select_func)(ViewDir *vd, const gchar *path, gpointer data);
+	void (*select_func)(ViewDir *vd, FileData *fd, gpointer data);
 	gpointer select_data;
 
 	void (*dnd_drop_update_func)(ViewDir *vd);
--- a/src/view_dir.c	Thu Jun 04 21:07:03 2009 +0000
+++ b/src/view_dir.c	Fri Jun 05 21:52:37 2009 +0000
@@ -143,7 +143,7 @@
 }
 
 void vd_set_select_func(ViewDir *vd,
-			void (*func)(ViewDir *vd, const gchar *path, gpointer data), gpointer data)
+			void (*func)(ViewDir *vd, FileData *fd, gpointer data), gpointer data)
 {
 	vd->select_func = func;
 	vd->select_data = data;
@@ -193,13 +193,15 @@
 	return ret;
 }
 
+/* the calling stack is this:
+   vd_select_row -> select_func -> layout_set_fd -> vd_set_fd
+*/
 void vd_select_row(ViewDir *vd, FileData *fd)
 {
-	switch (vd->type)
-	{
-	case DIRVIEW_LIST: vdlist_select_row(vd, fd); break;
-	case DIRVIEW_TREE: vdtree_select_row(vd, fd); break;
-	}
+	if (fd && vd->select_func)
+		{
+		vd->select_func(vd, fd, vd->select_data);
+		}
 }
 
 gboolean vd_find_row(ViewDir *vd, FileData *fd, GtkTreeIter *iter)
@@ -422,7 +424,9 @@
 
 	if (vd->select_func)
 		{
-		vd->select_func(vd, path, vd->select_data);
+		FileData *fd = file_data_new_simple(path);
+		vd->select_func(vd, fd, vd->select_data);
+		file_data_unref(fd);
 		}
 
 	g_free(path);
@@ -1023,7 +1027,7 @@
 
 	if (fd && vd->click_fd == fd)
 		{
-		vdlist_select_row(vd, vd->click_fd);
+		vd_select_row(vd, vd->click_fd);
 		}
 
 	return FALSE;
--- a/src/view_dir.h	Thu Jun 04 21:07:03 2009 +0000
+++ b/src/view_dir.h	Fri Jun 05 21:52:37 2009 +0000
@@ -26,7 +26,7 @@
 
 ViewDir *vd_new(DirViewType type, FileData *dir_fd);
 
-void vd_set_select_func(ViewDir *vdl, void (*func)(ViewDir *vdl, const gchar *path, gpointer data), gpointer data);
+void vd_set_select_func(ViewDir *vdl, void (*func)(ViewDir *vdl, FileData *fd, gpointer data), gpointer data);
 
 void vd_set_layout(ViewDir *vdl, LayoutWindow *layout);
 
--- a/src/view_dir_list.c	Thu Jun 04 21:07:03 2009 +0000
+++ b/src/view_dir_list.c	Fri Jun 05 21:52:37 2009 +0000
@@ -117,18 +117,6 @@
  *-----------------------------------------------------------------------------
  */
 
-void vdlist_select_row(ViewDir *vd, FileData *fd)
-{
-	if (fd && vd->select_func)
-		{
-		gchar *path;
-
-		path = g_strdup(fd->path);
-		vd->select_func(vd, path, vd->select_data);
-		g_free(path);
-		}
-}
-
 const gchar *vdlist_row_get_path(ViewDir *vd, gint row)
 {
 	FileData *fd;
--- a/src/view_dir_list.h	Thu Jun 04 21:07:03 2009 +0000
+++ b/src/view_dir_list.h	Fri Jun 05 21:52:37 2009 +0000
@@ -16,8 +16,6 @@
 
 ViewDir *vdlist_new(ViewDir *vd, FileData *dir_fd);
 
-void vdlist_select_row(ViewDir *vd, FileData *fd);
-
 gboolean vdlist_set_fd(ViewDir *vd, FileData *dir_fd);
 void vdlist_refresh(ViewDir *vd);
 
--- a/src/view_dir_tree.c	Thu Jun 04 21:07:03 2009 +0000
+++ b/src/view_dir_tree.c	Fri Jun 05 21:52:37 2009 +0000
@@ -676,29 +676,6 @@
 	return selection_is_ok;
 }
 
-void vdtree_select_row(ViewDir *vd, FileData *fd)
-{
-	GtkTreeSelection *selection;
-	GtkTreeIter iter;
-
-	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 */
-	selection_is_ok = TRUE;
-	gtk_tree_selection_select_iter(selection, &iter);
-	selection_is_ok = FALSE;
-
-	if (!vdtree_populate_path_by_iter(vd, &iter, FALSE, vd->dir_fd)) return;
-
-	vdtree_expand_by_iter(vd, &iter, TRUE);
-
-	if (fd && vd->select_func)
-		{
-		vd->select_func(vd, fd->path, vd->select_data);
-		}
-}
-
 gboolean vdtree_set_fd(ViewDir *vd, FileData *dir_fd)
 {
 	FileData *fd;
@@ -718,15 +695,21 @@
 		{
 		GtkTreeModel *store;
 		GtkTreePath *tpath;
-
-		tree_view_row_make_visible(GTK_TREE_VIEW(vd->view), &iter, TRUE);
+		GtkTreeSelection *selection;
 
 		store = gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view));
 		tpath = gtk_tree_model_get_path(store, &iter);
 		gtk_tree_view_set_cursor(GTK_TREE_VIEW(vd->view), tpath, NULL, FALSE);
 		gtk_tree_path_free(tpath);
 
-		vdtree_select_row(vd, fd);
+		selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vd->view));
+
+		/* hack, such that selection is only allowed to be changed from here */
+		selection_is_ok = TRUE;
+		gtk_tree_selection_select_iter(selection, &iter);
+		selection_is_ok = FALSE;
+
+		tree_view_row_make_visible(GTK_TREE_VIEW(vd->view), &iter, TRUE);
 		}
 
 	return TRUE;
--- a/src/view_dir_tree.h	Thu Jun 04 21:07:03 2009 +0000
+++ b/src/view_dir_tree.h	Fri Jun 05 21:52:37 2009 +0000
@@ -24,8 +24,6 @@
 
 ViewDir *vdtree_new(ViewDir *vd, FileData *dir_fd);
 
-void vdtree_select_row(ViewDir *vd, FileData *fd);
-
 gboolean vdtree_set_fd(ViewDir *vd, FileData *dir_fd);
 void vdtree_refresh(ViewDir *vd);