changeset 384:392dd6541d51

Merge parts of view_dir_list/tree constructors/destructors to view_dir.
author zas_
date Wed, 16 Apr 2008 16:54:38 +0000
parents 499d7ba62261
children 2c06e06f4236
files 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 7 files changed, 66 insertions(+), 83 deletions(-) [+]
line wrap: on
line diff
--- a/src/typedefs.h	Wed Apr 16 16:05:12 2008 +0000
+++ b/src/typedefs.h	Wed Apr 16 16:54:38 2008 +0000
@@ -529,6 +529,9 @@
 struct _ViewDir
 {
 	DirViewType type;
+	gpointer info;
+	void (*widget_destroy_cb)(GtkWidget *widget, gpointer data);
+
 	GtkWidget *widget;
 	GtkWidget *view;
 
@@ -549,8 +552,6 @@
 	GtkWidget *popup;
 
 	PixmapFolders *pf;
-
-	gpointer info;
 };
 
 struct _ViewDirInfoList
--- a/src/view_dir.c	Wed Apr 16 16:05:12 2008 +0000
+++ b/src/view_dir.c	Wed Apr 16 16:54:38 2008 +0000
@@ -13,6 +13,7 @@
 #include "view_dir.h"
 
 #include "filelist.h"
+#include "layout_util.h"
 #include "ui_menu.h"
 #include "utilops.h"
 #include "view_dir_list.h"
@@ -23,16 +24,59 @@
   { "FolderTree",	NULL,		N_("Tr_ee"),		"<control>T",	NULL, DIRVIEW_TREE },
 };
 
+void vd_destroy_cb(GtkWidget *widget, gpointer data)
+{
+	ViewDir *vd = data;
+
+	if (vd->popup)
+		{
+		g_signal_handlers_disconnect_matched(G_OBJECT(vd->popup), G_SIGNAL_MATCH_DATA,
+						     0, 0, 0, NULL, vd);
+		gtk_widget_destroy(vd->popup);
+		}
+
+	if (vd->widget_destroy_cb) vd->widget_destroy_cb(widget, data);
+
+	if (vd->pf) folder_icons_free(vd->pf);
+	if (vd->drop_list) filelist_free(vd->drop_list);
+
+	if (vd->path) g_free(vd->path);
+	if (vd->info) g_free(vd->info);
+
+	g_free(vd);
+}
+
 ViewDir *vd_new(DirViewType type, const gchar *path)
 {
-	ViewDir *vd = NULL;
+	ViewDir *vd = g_new0(ViewDir, 1);
+
+	vd->path = NULL;
+	vd->click_fd = NULL;
+
+	vd->drop_fd = NULL;
+	vd->drop_list = NULL;
+	vd->drop_scroll_id = -1;
+	vd->drop_list = NULL;
+
+	vd->popup = NULL;
+	vd->pf = NULL;
+
+	vd->widget = gtk_scrolled_window_new(NULL, NULL);
+	gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(vd->widget), GTK_SHADOW_IN);
+	gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(vd->widget),
+				       GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
 
 	switch(type)
 	{
-	case DIRVIEW_LIST: vd = vdlist_new(path); break;
-	case DIRVIEW_TREE: vd = vdtree_new(path); break;
+	case DIRVIEW_LIST: vd = vdlist_new(vd, path); break;
+	case DIRVIEW_TREE: vd = vdtree_new(vd, path); break;
 	}
 
+	g_signal_connect(G_OBJECT(vd->widget), "destroy",
+			 G_CALLBACK(vd_destroy_cb), vd);
+
+	vd->pf = folder_icons_new();
+
 	return vd;
 }
 	
--- a/src/view_dir.h	Wed Apr 16 16:05:12 2008 +0000
+++ b/src/view_dir.h	Wed Apr 16 16:54:38 2008 +0000
@@ -22,6 +22,8 @@
 
 extern GtkRadioActionEntry menu_view_dir_radio_entries[2];
 
+void vd_destroy(ViewDir *vd);
+
 ViewDir *vd_new(DirViewType type, const gchar *path);
 
 void vd_set_select_func(ViewDir *vdl, void (*func)(ViewDir *vdl, const gchar *path, gpointer data), gpointer data);
--- a/src/view_dir_list.c	Wed Apr 16 16:05:12 2008 +0000
+++ b/src/view_dir_list.c	Wed Apr 16 16:54:38 2008 +0000
@@ -974,7 +974,7 @@
 	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);
@@ -1000,55 +1000,24 @@
 {
 	ViewDir *vd = data;
 
-	if (vd->popup)
-		{
-		g_signal_handlers_disconnect_matched(G_OBJECT(vd->popup), G_SIGNAL_MATCH_DATA,
-						     0, 0, 0, NULL, vd);
-		gtk_widget_destroy(vd->popup);
-		}
-
 	vdlist_dnd_drop_scroll_cancel(vd);
 	widget_auto_scroll_stop(vd->view);
 
-	filelist_free(vd->drop_list);
-
-	folder_icons_free(vd->pf);
-
-	g_free(vd->path);
 	filelist_free(VDLIST_INFO(vd, list));
-	g_free(vd->info);
-	g_free(vd);
 }
 
-ViewDir *vdlist_new(const gchar *path)
+ViewDir *vdlist_new(ViewDir *vd, const gchar *path)
 {
-	ViewDir *vd;
 	GtkListStore *store;
 	GtkTreeSelection *selection;
 	GtkTreeViewColumn *column;
 	GtkCellRenderer *renderer;
 
-	vd = g_new0(ViewDir, 1);
 	vd->info = g_new0(ViewDirInfoList, 1);
 	vd->type = DIRVIEW_LIST;
-
-	vd->path = NULL;
-	VDLIST_INFO(vd, list) = NULL;
-	vd->click_fd = NULL;
-
-	vd->drop_fd = NULL;
-	vd->drop_list = NULL;
+	vd->widget_destroy_cb = vdlist_destroy_cb;
 
-	vd->drop_scroll_id = -1;
-
-	vd->popup = NULL;
-
-	vd->widget = gtk_scrolled_window_new(NULL, NULL);
-	gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(vd->widget), GTK_SHADOW_IN);
-	gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(vd->widget),
-				       GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
-	g_signal_connect(G_OBJECT(vd->widget), "destroy",
-			 G_CALLBACK(vdlist_destroy_cb), vd);
+	VDLIST_INFO(vd, list) = NULL;
 
 	store = gtk_list_store_new(4, G_TYPE_POINTER, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_BOOLEAN);
 	vd->view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
@@ -1083,8 +1052,6 @@
 	gtk_container_add(GTK_CONTAINER(vd->widget), vd->view);
 	gtk_widget_show(vd->view);
 
-	vd->pf = folder_icons_new();
-
 	vdlist_dnd_init(vd);
 
 	g_signal_connect(G_OBJECT(vd->view), "button_press_event",
--- a/src/view_dir_list.h	Wed Apr 16 16:05:12 2008 +0000
+++ b/src/view_dir_list.h	Wed Apr 16 16:54:38 2008 +0000
@@ -13,12 +13,12 @@
 #define VIEW_DIR_LIST_H
 
 
-ViewDir *vdlist_new(const gchar *path);
+ViewDir *vdlist_new(ViewDir *vd, const gchar *path);
 
-gint vdlist_set_path(ViewDir *vdl, const gchar *path);
-void vdlist_refresh(ViewDir *vdl);
+gint vdlist_set_path(ViewDir *vd, const gchar *path);
+void vdlist_refresh(ViewDir *vd);
 
-const gchar *vdlist_row_get_path(ViewDir *vdl, gint row);
+const gchar *vdlist_row_get_path(ViewDir *vd, gint row);
 gint vdlist_find_row(ViewDir *vd, FileData *fd, GtkTreeIter *iter);
 
 
--- a/src/view_dir_tree.c	Wed Apr 16 16:05:12 2008 +0000
+++ b/src/view_dir_tree.c	Wed Apr 16 16:54:38 2008 +0000
@@ -1544,60 +1544,29 @@
 	ViewDir *vd = data;
 	GtkTreeModel *store;
 
-	if (vd->popup)
-		{
-		g_signal_handlers_disconnect_matched(G_OBJECT(vd->popup), G_SIGNAL_MATCH_DATA,
-						     0, 0, 0, NULL, vd);
-		gtk_widget_destroy(vd->popup);
-		}
-
 	vdtree_dnd_drop_expand_cancel(vd);
 	vdtree_dnd_drop_scroll_cancel(vd);
 	widget_auto_scroll_stop(vd->view);
 
 	store = gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view));
 	gtk_tree_model_foreach(store, vdtree_destroy_node_cb, vd);
-
-	filelist_free(vd->drop_list);
-
-	folder_icons_free(vd->pf);
-
-	g_free(vd->path);
-	g_free(vd->info);
-	g_free(vd);
 }
 
-ViewDir *vdtree_new(const gchar *path)
+ViewDir *vdtree_new(ViewDir *vd, const gchar *path)
 {
-	ViewDir *vd;
 	GtkTreeStore *store;
 	GtkTreeSelection *selection;
 	GtkTreeViewColumn *column;
 	GtkCellRenderer *renderer;
 
-	vd = g_new0(ViewDir, 1);
 	vd->info = g_new0(ViewDirInfoTree, 1);
 	vd->type = DIRVIEW_TREE;
-
-	vd->path = NULL;
-	vd->click_fd = NULL;
+	vd->widget_destroy_cb = vdtree_destroy_cb;
 
-	vd->drop_fd = NULL;
-	vd->drop_list = NULL;
-	vd->drop_scroll_id = -1;
 	VDTREE_INFO(vd, drop_expand_id) = -1;
 
-	vd->popup = NULL;
-
 	VDTREE_INFO(vd, busy_ref) = 0;
 
-	vd->widget = gtk_scrolled_window_new(NULL, NULL);
-	gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(vd->widget), GTK_SHADOW_IN);
-	gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(vd->widget),
-				       GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
-	g_signal_connect(G_OBJECT(vd->widget), "destroy",
-			 G_CALLBACK(vdtree_destroy_cb), vd);
-
 	store = gtk_tree_store_new(4, G_TYPE_POINTER, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_INT);
 	vd->view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
 	g_object_unref(store);
--- a/src/view_dir_tree.h	Wed Apr 16 16:05:12 2008 +0000
+++ b/src/view_dir_tree.h	Wed Apr 16 16:54:38 2008 +0000
@@ -12,12 +12,12 @@
 #ifndef VIEW_DIR_TREE_H
 #define VIEW_DIR_TREE_H
 
-ViewDir *vdtree_new(const gchar *path);
+ViewDir *vdtree_new(ViewDir *vd, const gchar *path);
 
-gint vdtree_set_path(ViewDir *vdt, const gchar *path);
-void vdtree_refresh(ViewDir *vdt);
+gint vdtree_set_path(ViewDir *vd, const gchar *path);
+void vdtree_refresh(ViewDir *vd);
 
-const gchar *vdtree_row_get_path(ViewDir *vdt, gint row);
+const gchar *vdtree_row_get_path(ViewDir *vd, gint row);
 gint vdtree_find_row(ViewDir *vd, FileData *fd, GtkTreeIter *iter, GtkTreeIter *parent);