changeset 383:499d7ba62261

Move some dnd common code from view_dir_list.c and view_dir_tree.c to view_dir.c.
author zas_
date Wed, 16 Apr 2008 16:05:12 +0000
parents eceeced4cbb9
children 392dd6541d51
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, 128 insertions(+), 170 deletions(-) [+]
line wrap: on
line diff
--- a/src/view_dir.c	Wed Apr 16 14:56:31 2008 +0000
+++ b/src/view_dir.c	Wed Apr 16 16:05:12 2008 +0000
@@ -12,6 +12,9 @@
 #include "main.h"
 #include "view_dir.h"
 
+#include "filelist.h"
+#include "ui_menu.h"
+#include "utilops.h"
 #include "view_dir_list.h"
 #include "view_dir_tree.h"
 
@@ -80,3 +83,96 @@
 	return ret;
 }
 
+void vd_color_set(ViewDir *vd, FileData *fd, gint color_set)
+{
+	GtkTreeModel *store;
+	GtkTreeIter iter;
+
+	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;
+	}
+}
+
+void vd_popup_destroy_cb(GtkWidget *widget, gpointer data)
+{
+	ViewDir *vd = data;
+
+	vd_color_set(vd, vd->click_fd, FALSE);
+	vd->click_fd = NULL;
+	vd->popup = NULL;
+
+	vd_color_set(vd, vd->drop_fd, FALSE);
+	filelist_free(vd->drop_list);
+	vd->drop_list = NULL;
+	vd->drop_fd = NULL;
+}
+
+/*
+ *-----------------------------------------------------------------------------
+ * drop menu (from dnd)
+ *-----------------------------------------------------------------------------
+ */
+
+static void vd_drop_menu_copy_cb(GtkWidget *widget, gpointer data)
+{
+	ViewDir *vd = data;
+	const gchar *path;
+	GList *list;
+
+	if (!vd->drop_fd) return;
+
+	path = vd->drop_fd->path;
+	list = vd->drop_list;
+	vd->drop_list = NULL;
+
+	file_util_copy_simple(list, path);
+}
+
+static void vd_drop_menu_move_cb(GtkWidget *widget, gpointer data)
+{
+	ViewDir *vd = data;
+	const gchar *path;
+	GList *list;
+
+	if (!vd->drop_fd) return;
+
+	path = vd->drop_fd->path;
+	list = vd->drop_list;
+
+	vd->drop_list = NULL;
+
+	file_util_move_simple(list, path);
+}
+
+GtkWidget *vd_drop_menu(ViewDir *vd, gint active)
+{
+	GtkWidget *menu;
+
+	menu = popup_menu_short_lived();
+	g_signal_connect(G_OBJECT(menu), "destroy",
+			 G_CALLBACK(vd_popup_destroy_cb), vd);
+
+	menu_item_add_stock_sensitive(menu, _("_Copy"), GTK_STOCK_COPY, active,
+				      G_CALLBACK(vd_drop_menu_copy_cb), vd);
+	menu_item_add_sensitive(menu, _("_Move"), active, G_CALLBACK(vd_drop_menu_move_cb), vd);
+
+	menu_item_add_divider(menu);
+	menu_item_add_stock(menu, _("Cancel"), GTK_STOCK_CANCEL, NULL, vd);
+
+	return menu;
+}
+
--- a/src/view_dir.h	Wed Apr 16 14:56:31 2008 +0000
+++ b/src/view_dir.h	Wed Apr 16 16:05:12 2008 +0000
@@ -33,6 +33,11 @@
 
 const gchar *vd_row_get_path(ViewDir *vdl, gint row);
 
+void vd_color_set(ViewDir *vd, FileData *fd, gint color_set);
+void vd_popup_destroy_cb(GtkWidget *widget, gpointer data);
+
+GtkWidget *vd_drop_menu(ViewDir *vd, gint active);
+
 
 #endif
 
--- a/src/view_dir_list.c	Wed Apr 16 14:56:31 2008 +0000
+++ b/src/view_dir_list.c	Wed Apr 16 16:05:12 2008 +0000
@@ -42,7 +42,7 @@
  *-----------------------------------------------------------------------------
  */
 
-static gint vdlist_find_row(ViewDir *vd, FileData *fd, GtkTreeIter *iter)
+gint vdlist_find_row(ViewDir *vd, FileData *fd, GtkTreeIter *iter)
 {
 	GtkTreeModel *store;
 	gint valid;
@@ -145,71 +145,6 @@
 	return NULL;
 }
 
-static void vdlist_color_set(ViewDir *vd, FileData *fd, gint color_set)
-{
-	GtkTreeModel *store;
-	GtkTreeIter iter;
-
-	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);
-}
-
-/*
- *-----------------------------------------------------------------------------
- * drop menu (from dnd)
- *-----------------------------------------------------------------------------
- */
-
-static void vdlist_drop_menu_copy_cb(GtkWidget *widget, gpointer data)
-{
-	ViewDir *vd = data;
-	const gchar *path;
-	GList *list;
-
-	if (!vd->drop_fd) return;
-
-	path = vd->drop_fd->path;
-	list = vd->drop_list;
-	vd->drop_list = NULL;
-
-	file_util_copy_simple(list, path);
-}
-
-static void vdlist_drop_menu_move_cb(GtkWidget *widget, gpointer data)
-{
-	ViewDir *vd = data;
-	const gchar *path;
-	GList *list;
-
-	if (!vd->drop_fd) return;
-
-	path = vd->drop_fd->path;
-	list = vd->drop_list;
-
-	vd->drop_list = NULL;
-
-	file_util_move_simple(list, path);
-}
-
-static GtkWidget *vdlist_drop_menu(ViewDir *vd, gint active)
-{
-	GtkWidget *menu;
-
-	menu = popup_menu_short_lived();
-	g_signal_connect(G_OBJECT(menu), "destroy",
-			 G_CALLBACK(vdlist_popup_destroy_cb), vd);
-
-	menu_item_add_stock_sensitive(menu, _("_Copy"), GTK_STOCK_COPY, active,
-				      G_CALLBACK(vdlist_drop_menu_copy_cb), vd);
-	menu_item_add_sensitive(menu, _("_Move"), active, G_CALLBACK(vdlist_drop_menu_move_cb), vd);
-
-	menu_item_add_divider(menu);
-	menu_item_add_stock(menu, _("Cancel"), GTK_STOCK_CANCEL, NULL, vd);
-
-	return menu;
-}
-
 /*
  *-----------------------------------------------------------------------------
  * pop-up menu
@@ -433,11 +368,11 @@
 {
 	ViewDir *vd = data;
 
-	vdlist_color_set(vd, vd->click_fd, FALSE);
+	vd_color_set(vd, vd->click_fd, FALSE);
 	vd->click_fd = NULL;
 	vd->popup = NULL;
 
-	vdlist_color_set(vd, vd->drop_fd, FALSE);
+	vd_color_set(vd, vd->drop_fd, FALSE);
 	filelist_free(vd->drop_list);
 	vd->drop_list = NULL;
 	vd->drop_fd = NULL;
@@ -501,7 +436,7 @@
 {
 	ViewDir *vd = data;
 
-	vdlist_color_set(vd, vd->click_fd, TRUE);
+	vd_color_set(vd, vd->click_fd, TRUE);
 	vdlist_dest_set(vd, FALSE);
 }
 
@@ -509,7 +444,7 @@
 {
 	ViewDir *vd = data;
 
-	vdlist_color_set(vd, vd->click_fd, FALSE);
+	vd_color_set(vd, vd->click_fd, FALSE);
 
 	if (context->action == GDK_ACTION_MOVE)
 		{
@@ -553,8 +488,8 @@
 
 		active = access_file(fd->path, W_OK | X_OK);
 
-		vdlist_color_set(vd, fd, TRUE);
-		vd->popup = vdlist_drop_menu(vd, active);
+		vd_color_set(vd, fd, TRUE);
+		vd->popup = vd_drop_menu(vd, active);
 		gtk_menu_popup(GTK_MENU(vd->popup), NULL, NULL, NULL, NULL, 0, time);
 
 		vd->drop_fd = fd;
@@ -629,8 +564,8 @@
 
 	if (fd != vd->drop_fd)
 		{
-		vdlist_color_set(vd, vd->drop_fd, FALSE);
-		vdlist_color_set(vd, fd, TRUE);
+		vd_color_set(vd, vd->drop_fd, FALSE);
+		vd_color_set(vd, fd, TRUE);
 		}
 
 	vd->drop_fd = fd;
@@ -709,7 +644,7 @@
 {
 	ViewDir *vd = data;
 
-	if (vd->drop_fd != vd->click_fd) vdlist_color_set(vd, vd->drop_fd, FALSE);
+	if (vd->drop_fd != vd->click_fd) vd_color_set(vd, vd->drop_fd, FALSE);
 
 	vd->drop_fd = NULL;
 }
@@ -945,7 +880,7 @@
 		vd->click_fd = NULL;
 		}
 
-	vdlist_color_set(vd, vd->click_fd, TRUE);
+	vd_color_set(vd, vd->click_fd, TRUE);
 
 	vd->popup = vdlist_pop_menu(vd, vd->click_fd);
 
@@ -974,7 +909,7 @@
 		}
 
 	vd->click_fd = fd;
-	vdlist_color_set(vd, vd->click_fd, TRUE);
+	vd_color_set(vd, vd->click_fd, TRUE);
 
 	if (bevent->button == 3)
 		{
@@ -993,7 +928,7 @@
 	GtkTreeIter iter;
 	FileData *fd = NULL;
 
-	vdlist_color_set(vd, vd->click_fd, FALSE);
+	vd_color_set(vd, vd->click_fd, FALSE);
 
 	if (bevent->button != 1) return TRUE;
 
--- a/src/view_dir_list.h	Wed Apr 16 14:56:31 2008 +0000
+++ b/src/view_dir_list.h	Wed Apr 16 16:05:12 2008 +0000
@@ -19,6 +19,7 @@
 void vdlist_refresh(ViewDir *vdl);
 
 const gchar *vdlist_row_get_path(ViewDir *vdl, gint row);
+gint vdlist_find_row(ViewDir *vd, FileData *fd, GtkTreeIter *iter);
 
 
 #endif
--- a/src/view_dir_tree.c	Wed Apr 16 14:56:31 2008 +0000
+++ b/src/view_dir_tree.c	Wed Apr 16 16:05:12 2008 +0000
@@ -85,7 +85,7 @@
 	if (VDTREE_INFO(vd, busy_ref) > 0) VDTREE_INFO(vd, busy_ref)--;
 }
 
-static gint vdtree_find_row(ViewDir *vd, FileData *fd, GtkTreeIter *iter, GtkTreeIter *parent)
+gint vdtree_find_row(ViewDir *vd, FileData *fd, GtkTreeIter *iter, GtkTreeIter *parent)
 {
 	GtkTreeModel *store;
 	gint valid;
@@ -161,16 +161,6 @@
 		}
 }
 
-static void vdtree_color_set(ViewDir *vd, FileData *fd, gint color_set)
-{
-	GtkTreeModel *store;
-	GtkTreeIter iter;
-
-	if (!vdtree_find_row(vd, fd, &iter, NULL)) 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);
-}
-
 static gint vdtree_rename_row_cb(TreeEditData *td, const gchar *old, const gchar *new, gpointer data)
 {
 	ViewDir *vd = data;
@@ -233,76 +223,6 @@
 	g_free(nd);
 }
 
-static void vdtree_popup_destroy_cb(GtkWidget *widget, gpointer data)
-{
-	ViewDir *vd = data;
-
-	vdtree_color_set(vd, vd->click_fd, FALSE);
-	vd->click_fd = NULL;
-	vd->popup = NULL;
-
-	vdtree_color_set(vd, vd->drop_fd, FALSE);
-	filelist_free(vd->drop_list);
-	vd->drop_list = NULL;
-	vd->drop_fd = NULL;
-}
-
-/*
- *-----------------------------------------------------------------------------
- * drop menu (from dnd)
- *-----------------------------------------------------------------------------
- */
-
-static void vdtree_drop_menu_copy_cb(GtkWidget *widget, gpointer data)
-{
-	ViewDir *vd = data;
-	const gchar *path;
-	GList *list;
-
-	if (!vd->drop_fd) return;
-
-	path = vd->drop_fd->path;
-	list = vd->drop_list;
-
-	vd->drop_list = NULL;
-
-	file_util_copy_simple(list, path);
-}
-
-static void vdtree_drop_menu_move_cb(GtkWidget *widget, gpointer data)
-{
-	ViewDir *vd = data;
-	const gchar *path;
-	GList *list;
-
-	if (!vd->drop_fd) return;
-
-	path = vd->drop_fd->path;
-	list = vd->drop_list;
-
-	vd->drop_list = NULL;
-
-	file_util_move_simple(list, path);
-}
-
-static GtkWidget *vdtree_drop_menu(ViewDir *vd, gint active)
-{
-	GtkWidget *menu;
-
-	menu = popup_menu_short_lived();
-	g_signal_connect(G_OBJECT(menu), "destroy",
-			 G_CALLBACK(vdtree_popup_destroy_cb), vd);
-
-	menu_item_add_stock_sensitive(menu, _("_Copy"), GTK_STOCK_COPY, active,
-				      G_CALLBACK(vdtree_drop_menu_copy_cb), vd);
-	menu_item_add_sensitive(menu, _("_Move"), active, G_CALLBACK(vdtree_drop_menu_move_cb), vd);
-
-	menu_item_add_divider(menu);
-	menu_item_add_stock(menu, _("Cancel"), GTK_STOCK_CANCEL, NULL, vd);
-
-	return menu;
-}
-
 /*
  *-----------------------------------------------------------------------------
  * pop-up menu
@@ -483,7 +403,7 @@
 
 	menu = popup_menu_short_lived();
 	g_signal_connect(G_OBJECT(menu), "destroy",
-			 G_CALLBACK(vdtree_popup_destroy_cb), vd);
+			 G_CALLBACK(vd_popup_destroy_cb), vd);
 
 	menu_item_add_stock_sensitive(menu, _("_Up to parent"), GTK_STOCK_GO_UP,
 		       		      (vd->path && strcmp(vd->path, "/") != 0),
@@ -585,7 +505,7 @@
 {
 	ViewDir *vd = data;
 
-	vdtree_color_set(vd, vd->click_fd, TRUE);
+	vd_color_set(vd, vd->click_fd, TRUE);
 	vdtree_dest_set(vd, FALSE);
 }
 
@@ -593,7 +513,7 @@
 {
 	ViewDir *vd = data;
 
-	vdtree_color_set(vd, vd->click_fd, FALSE);
+	vd_color_set(vd, vd->click_fd, FALSE);
 	vdtree_dest_set(vd, TRUE);
 }
 
@@ -635,8 +555,8 @@
 
 		active = access_file(fd->path, W_OK | X_OK);
 
-		vdtree_color_set(vd, fd, TRUE);
-		vd->popup = vdtree_drop_menu(vd, active);
+		vd_color_set(vd, fd, TRUE);
+		vd->popup = vd_drop_menu(vd, active);
 		gtk_menu_popup(GTK_MENU(vd->popup), NULL, NULL, NULL, NULL, 0, time);
 
 		vd->drop_fd = fd;
@@ -694,8 +614,8 @@
 
 	if (fd != vd->drop_fd)
 		{
-		vdtree_color_set(vd, vd->drop_fd, FALSE);
-		vdtree_color_set(vd, fd, TRUE);
+		vd_color_set(vd, vd->drop_fd, FALSE);
+		vd_color_set(vd, fd, TRUE);
 		if (fd) vdtree_dnd_drop_expand(vd);
 		}
 
@@ -774,7 +694,7 @@
 {
 	ViewDir *vd = data;
 
-	if (vd->drop_fd != vd->click_fd) vdtree_color_set(vd, vd->drop_fd, FALSE);
+	if (vd->drop_fd != vd->click_fd) vd_color_set(vd, vd->drop_fd, FALSE);
 
 	vd->drop_fd = NULL;
 
@@ -1389,7 +1309,7 @@
 		{
 		case GDK_Menu:
 			vd->click_fd = fd;
-			vdtree_color_set(vd, vd->click_fd, TRUE);
+			vd_color_set(vd, vd->click_fd, TRUE);
 
 			vd->popup = vdtree_pop_menu(vd, vd->click_fd);
 			gtk_menu_popup(GTK_MENU(vd->popup), NULL, NULL, vdtree_menu_position_cb, vd, 0, GDK_CURRENT_TIME);
@@ -1476,7 +1396,7 @@
 		}
 
 	vd->click_fd = (nd) ? nd->fd : NULL;
-	vdtree_color_set(vd, vd->click_fd, TRUE);
+	vd_color_set(vd, vd->click_fd, TRUE);
 
 	if (bevent->button == 3)
 		{
@@ -1496,7 +1416,7 @@
 	NodeData *nd = NULL;
 
 	if (!vd->click_fd) return FALSE;
-	vdtree_color_set(vd, vd->click_fd, FALSE);
+	vd_color_set(vd, vd->click_fd, FALSE);
 
 	if (bevent->button != 1) return TRUE;
 
--- a/src/view_dir_tree.h	Wed Apr 16 14:56:31 2008 +0000
+++ b/src/view_dir_tree.h	Wed Apr 16 16:05:12 2008 +0000
@@ -18,6 +18,7 @@
 void vdtree_refresh(ViewDir *vdt);
 
 const gchar *vdtree_row_get_path(ViewDir *vdt, gint row);
+gint vdtree_find_row(ViewDir *vd, FileData *fd, GtkTreeIter *iter, GtkTreeIter *parent);
 
 
 #endif