changeset 396:a01535f52b56

Merge few more functions to view_dir.c.
author zas_
date Thu, 17 Apr 2008 17:19:41 +0000
parents c359fc2c5a1f
children a7be56e84870
files 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 6 files changed, 80 insertions(+), 96 deletions(-) [+]
line wrap: on
line diff
--- a/src/view_dir.c	Thu Apr 17 16:33:31 2008 +0000
+++ b/src/view_dir.c	Thu Apr 17 17:19:41 2008 +0000
@@ -132,6 +132,15 @@
 	return ret;
 }
 
+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;
+	}
+}
+
 gint vd_find_row(ViewDir *vd, FileData *fd, GtkTreeIter *iter)
 {
 	gint ret = FALSE;
@@ -872,3 +881,59 @@
 	popup_menu_position_clamp(menu, x, y, 0);
 }
 
+void vd_activate_cb(GtkTreeView *tview, GtkTreePath *tpath, GtkTreeViewColumn *column, gpointer data)
+{
+	ViewDir *vd = data;
+	GtkTreeModel *store;
+	GtkTreeIter iter;
+	FileData *fd;
+
+	store = gtk_tree_view_get_model(tview);
+	gtk_tree_model_get_iter(store, &iter, tpath);
+	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);
+			fd = (nd) ? nd->fd : NULL;
+			};
+			break;
+		}
+
+	vd_select_row(vd, fd);
+}
+
+static GdkColor *vd_color_shifted(GtkWidget *widget)
+{
+	static GdkColor color;
+	static GtkWidget *done = NULL;
+
+	if (done != widget)
+		{
+		GtkStyle *style;
+
+		style = gtk_widget_get_style(widget);
+		memcpy(&color, &style->base[GTK_STATE_NORMAL], sizeof(color));
+		shift_color(&color, -1, 0);
+		done = widget;
+		}
+
+	return &color;
+}
+
+void vd_color_cb(GtkTreeViewColumn *tree_column, GtkCellRenderer *cell,
+		 GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data)
+{
+	ViewDir *vd = data;
+	gboolean set;
+
+	gtk_tree_model_get(tree_model, iter, DIR_COLUMN_COLOR, &set, -1);
+	g_object_set(G_OBJECT(cell),
+		     "cell-background-gdk", vd_color_shifted(vd->view),
+		     "cell-background-set", set, NULL);
+}
+
--- a/src/view_dir.h	Thu Apr 17 16:33:31 2008 +0000
+++ b/src/view_dir.h	Thu Apr 17 17:19:41 2008 +0000
@@ -47,6 +47,9 @@
 
 void vd_menu_position_cb(GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer data);
 
+void vd_activate_cb(GtkTreeView *tview, GtkTreePath *tpath, GtkTreeViewColumn *column, gpointer data);
+void vd_color_cb(GtkTreeViewColumn *tree_column, GtkCellRenderer *cell, GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data);
+
 
 #endif
 
--- a/src/view_dir_list.c	Thu Apr 17 16:33:31 2008 +0000
+++ b/src/view_dir_list.c	Thu Apr 17 17:19:41 2008 +0000
@@ -121,7 +121,7 @@
  *-----------------------------------------------------------------------------
  */ 
 
-static void vdlist_select_row(ViewDir *vd, FileData *fd)
+void vdlist_select_row(ViewDir *vd, FileData *fd)
 {
 	if (fd && vd->select_func)
 		{
@@ -380,50 +380,6 @@
 	return TRUE;
 }
 
-static void vdlist_select_cb(GtkTreeView *tview, GtkTreePath *tpath, GtkTreeViewColumn *column, gpointer data)
-{
-	ViewDir *vd = data;
-	GtkTreeModel *store;
-	GtkTreeIter iter;
-	FileData *fd;
-
-	store = gtk_tree_view_get_model(tview);
-	gtk_tree_model_get_iter(store, &iter, tpath);
-	gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &fd, -1);
-
-	vdlist_select_row(vd, fd);
-}
-
-static GdkColor *vdlist_color_shifted(GtkWidget *widget)
-{
-	static GdkColor color;
-	static GtkWidget *done = NULL;
-
-	if (done != widget)
-		{
-		GtkStyle *style;
-		
-		style = gtk_widget_get_style(widget);
-		memcpy(&color, &style->base[GTK_STATE_NORMAL], sizeof(color));
-		shift_color(&color, -1, 0);
-		done = widget;
-		}
-
-	return &color;
-}
-
-static void vdlist_color_cb(GtkTreeViewColumn *tree_column, GtkCellRenderer *cell,
-			    GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data)
-{
-	ViewDir *vd = data;
-	gboolean set;
-
-	gtk_tree_model_get(tree_model, iter, DIR_COLUMN_COLOR, &set, -1);
-	g_object_set(G_OBJECT(cell),
-		     "cell-background-gdk", vdlist_color_shifted(vd->view),
-		     "cell-background-set", set, NULL);
-}
-
 static void vdlist_destroy_cb(GtkWidget *widget, gpointer data)
 {
 	ViewDir *vd = data;
@@ -455,7 +411,7 @@
 	gtk_tree_view_set_enable_search(GTK_TREE_VIEW(vd->view), FALSE);
 	g_signal_connect(G_OBJECT(vd->view), "row_activated",
 
-			 G_CALLBACK(vdlist_select_cb), vd);
+			 G_CALLBACK(vd_activate_cb), vd);
 
 	selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vd->view));
 	gtk_tree_selection_set_mode(selection, GTK_SELECTION_NONE);
@@ -466,12 +422,12 @@
 	renderer = gtk_cell_renderer_pixbuf_new();
 	gtk_tree_view_column_pack_start(column, renderer, FALSE);
 	gtk_tree_view_column_add_attribute(column, renderer, "pixbuf", DIR_COLUMN_ICON);
-	gtk_tree_view_column_set_cell_data_func(column, renderer, vdlist_color_cb, vd, NULL);
+	gtk_tree_view_column_set_cell_data_func(column, renderer, vd_color_cb, vd, NULL);
 
 	renderer = gtk_cell_renderer_text_new();
 	gtk_tree_view_column_pack_start(column, renderer, TRUE);
 	gtk_tree_view_column_add_attribute(column, renderer, "text", DIR_COLUMN_NAME);
-	gtk_tree_view_column_set_cell_data_func(column, renderer, vdlist_color_cb, vd, NULL);
+	gtk_tree_view_column_set_cell_data_func(column, renderer, vd_color_cb, vd, NULL);
 
 	gtk_tree_view_append_column(GTK_TREE_VIEW(vd->view), column);
 
--- a/src/view_dir_list.h	Thu Apr 17 16:33:31 2008 +0000
+++ b/src/view_dir_list.h	Thu Apr 17 17:19:41 2008 +0000
@@ -15,6 +15,8 @@
 
 ViewDir *vdlist_new(ViewDir *vd, const gchar *path);
 
+void vdlist_select_row(ViewDir *vd, FileData *fd);
+
 gint vdlist_set_path(ViewDir *vd, const gchar *path);
 void vdlist_refresh(ViewDir *vd);
 
--- a/src/view_dir_tree.c	Thu Apr 17 16:33:31 2008 +0000
+++ b/src/view_dir_tree.c	Thu Apr 17 17:19:41 2008 +0000
@@ -658,7 +658,7 @@
 	return selection_is_ok;
 }
 
-static void vdtree_select_row(ViewDir *vd, FileData *fd)
+void vdtree_select_row(ViewDir *vd, FileData *fd)
 {
 	GtkTreeSelection *selection;
 	GtkTreeIter iter;
@@ -940,50 +940,6 @@
 	vdtree_populate_path(vd, path, FALSE, FALSE);
 }
 
-static void vdtree_activate_cb(GtkTreeView *tview, GtkTreePath *tpath, GtkTreeViewColumn *column, gpointer data)
-{
-	ViewDir *vd = data;
-	GtkTreeModel *store;
-	GtkTreeIter iter;
-	NodeData *nd;
-
-	store = gtk_tree_view_get_model(tview);
-	gtk_tree_model_get_iter(store, &iter, tpath);
-	gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &nd, -1);
-
-	vdtree_select_row(vd, nd->fd);
-}
-
-static GdkColor *vdtree_color_shifted(GtkWidget *widget)
-{
-	static GdkColor color;
-	static GtkWidget *done = NULL;
-
-	if (done != widget)
-		{
-		GtkStyle *style;
-
-		style = gtk_widget_get_style(widget);
-		memcpy(&color, &style->base[GTK_STATE_NORMAL], sizeof(color));
-		shift_color(&color, -1, 0);
-		done = widget;
-		}
-
-	return &color;
-}
-
-static void vdtree_color_cb(GtkTreeViewColumn *tree_column, GtkCellRenderer *cell,
-			    GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data)
-{
-	ViewDir *vd = data;
-	gboolean set;
-
-	gtk_tree_model_get(tree_model, iter, DIR_COLUMN_COLOR, &set, -1);
-	g_object_set(G_OBJECT(cell),
-		     "cell-background-gdk", vdtree_color_shifted(vd->view),
-		     "cell-background-set", set, NULL);
-}
-
 static gboolean vdtree_destroy_node_cb(GtkTreeModel *store, GtkTreePath *tpath, GtkTreeIter *iter, gpointer data)
 {
 	NodeData *nd;
@@ -1033,7 +989,7 @@
 					     GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, GTK_SORT_ASCENDING);
 
 	g_signal_connect(G_OBJECT(vd->view), "row_activated",
-			 G_CALLBACK(vdtree_activate_cb), vd);
+			 G_CALLBACK(vd_activate_cb), vd);
 	g_signal_connect(G_OBJECT(vd->view), "row_expanded",
 			 G_CALLBACK(vdtree_row_expanded), vd);
 	g_signal_connect(G_OBJECT(vd->view), "row_collapsed",
@@ -1053,12 +1009,12 @@
 	renderer = gtk_cell_renderer_pixbuf_new();
 	gtk_tree_view_column_pack_start(column, renderer, FALSE);
 	gtk_tree_view_column_add_attribute(column, renderer, "pixbuf", DIR_COLUMN_ICON);
-	gtk_tree_view_column_set_cell_data_func(column, renderer, vdtree_color_cb, vd, NULL);
+	gtk_tree_view_column_set_cell_data_func(column, renderer, vd_color_cb, vd, NULL);
 
 	renderer = gtk_cell_renderer_text_new();
 	gtk_tree_view_column_pack_start(column, renderer, TRUE);
 	gtk_tree_view_column_add_attribute(column, renderer, "text", DIR_COLUMN_NAME);
-	gtk_tree_view_column_set_cell_data_func(column, renderer, vdtree_color_cb, vd, NULL);
+	gtk_tree_view_column_set_cell_data_func(column, renderer, vd_color_cb, vd, NULL);
 
 	gtk_tree_view_append_column(GTK_TREE_VIEW(vd->view), column);
 
--- a/src/view_dir_tree.h	Thu Apr 17 16:33:31 2008 +0000
+++ b/src/view_dir_tree.h	Thu Apr 17 17:19:41 2008 +0000
@@ -22,6 +22,8 @@
 
 ViewDir *vdtree_new(ViewDir *vd, const gchar *path);
 
+void vdtree_select_row(ViewDir *vd, FileData *fd);
+
 gint vdtree_set_path(ViewDir *vd, const gchar *path);
 void vdtree_refresh(ViewDir *vd);