changeset 149:f0c79a514c06

marks: fixes and cleanup
author nadvornik
date Sat, 24 Nov 2007 21:06:30 +0000
parents a8b4b99c9359
children 976fba0add7c
files src/typedefs.h src/view_file_list.c
diffstat 2 files changed, 69 insertions(+), 57 deletions(-) [+]
line wrap: on
line diff
--- a/src/typedefs.h	Thu Nov 22 21:15:35 2007 +0000
+++ b/src/typedefs.h	Sat Nov 24 21:06:30 2007 +0000
@@ -334,7 +334,7 @@
 	gint delay_flip;
 };
 
-#define FILEDATA_MARKS_SIZE 10
+#define FILEDATA_MARKS_SIZE 6
 
 struct _FileDataChangeInfo {
 	FileDataChangeType type;
--- a/src/view_file_list.c	Thu Nov 22 21:15:35 2007 +0000
+++ b/src/view_file_list.c	Sat Nov 24 21:06:30 2007 +0000
@@ -533,19 +533,20 @@
 	GtkTreePath *tpath;
 	GtkTreeIter iter;
 	FileData *fd = NULL;
-    GtkTreeViewColumn *column;
-    gint colnum;
+	GtkTreeViewColumn *column;
+	gint col_idx;
     
 	if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), bevent->x, bevent->y,
 					  &tpath, &column, NULL, NULL))
 		{
 		GtkTreeModel *store;
-        colnum = GPOINTER_TO_INT(g_object_get_data (G_OBJECT(column), "column"));
+		col_idx = GPOINTER_TO_INT(g_object_get_data (G_OBJECT(column), "column_store_idx"));
         
-        if (colnum <= FILE_COLUMN_MARKS - 2 + FILEDATA_MARKS_SIZE && colnum >= FILE_COLUMN_MARKS - 2)
-            return FALSE;
+		if (bevent->button == 1 &&
+		    col_idx >= FILE_COLUMN_MARKS && col_idx <= FILE_COLUMN_MARKS_LAST)
+			return FALSE;
         
-        store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget));
+		store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget));
 
 		gtk_tree_model_get_iter(store, &iter, tpath);
 		gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &fd, -1);
@@ -1380,7 +1381,7 @@
 	column = gtk_tree_view_get_column(GTK_TREE_VIEW(listview), FILE_COLUMN_THUMB - 1);
 	if (!column) return;
 
-	gtk_tree_view_column_set_fixed_width(column, ((thumb) ? thumb_max_width : 4) + 50);
+	gtk_tree_view_column_set_fixed_width(column, ((thumb) ? thumb_max_width : 4) + 10);
 
 	list = gtk_tree_view_column_get_cell_renderers(column);
 	if (!list) return;
@@ -1598,7 +1599,7 @@
 
 	if (!image)
 		{
-		gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
+		gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_GROW_ONLY);
 		renderer = gtk_cell_renderer_text_new();
 		if (right_justify)
 			{
@@ -1606,9 +1607,9 @@
 			}
 		gtk_tree_view_column_pack_start(column, renderer, TRUE);
 		gtk_tree_view_column_add_attribute(column, renderer, "text", n);
-	        if (expand)
+		if (expand)
 			gtk_tree_view_column_set_expand(column, TRUE);
-        }
+		}
 	else
 		{
 		gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
@@ -1619,54 +1620,58 @@
 		}
 
 	gtk_tree_view_column_set_cell_data_func(column, renderer, vflist_listview_color_cb, vfl, NULL);
+	g_object_set_data (G_OBJECT (column), "column_store_idx", GUINT_TO_POINTER(n));
+	g_object_set_data (G_OBJECT (renderer), "column_store_idx", GUINT_TO_POINTER(n));
 
 	gtk_tree_view_append_column(GTK_TREE_VIEW(vfl->listview), column);
 }
 
 static void vflist_listview_mark_toggled(GtkCellRendererToggle *cell, gchar *path_str, GtkTreeStore *store)
 {
-    GtkTreePath *path = gtk_tree_path_new_from_string(path_str);
-    guint *marks;
-    GtkTreeIter iter;
-    FileData *fd;
-    gboolean mark;
-    guint column;
+	GtkTreePath *path = gtk_tree_path_new_from_string(path_str);
+	guint *marks;
+	GtkTreeIter iter;
+	FileData *fd;
+	gboolean mark;
+	guint col_idx;
  
-    if (!path || !gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, path))
-        return;
+	if (!path || !gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, path))
+    		return;
 
-    column = GPOINTER_TO_INT(g_object_get_data (G_OBJECT(cell), "column"));
+	col_idx = GPOINTER_TO_INT(g_object_get_data (G_OBJECT(cell), "column_store_idx"));
+    
+	g_assert(col_idx >= FILE_COLUMN_MARKS && col_idx <= FILE_COLUMN_MARKS_LAST);
     
-    gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, FILE_COLUMN_POINTER, &fd, column, &mark, -1);
-    mark ^= 1;
-    fd->marks[column] = mark;
+	gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, FILE_COLUMN_POINTER, &fd, col_idx, &mark, -1);
+	mark ^= 1;
+	fd->marks[col_idx - FILE_COLUMN_MARKS] = mark;
         
-    gtk_tree_store_set(store, &iter, column, mark, -1);
-    gtk_tree_path_free(path);
+	gtk_tree_store_set(store, &iter, col_idx, mark, -1);
+	gtk_tree_path_free(path);
 }
 
 static void vflist_listview_add_column_toggle(ViewFileList *vfl, gint n, const gchar *title)
 {
-    GtkTreeViewColumn *column;
-    GtkCellRenderer *renderer;
-    GtkTreeStore *store;
-    gint index;
+	GtkTreeViewColumn *column;
+	GtkCellRenderer *renderer;
+	GtkTreeStore *store;
+	gint index;
     
 	store = GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(vfl->listview)));
 
-    renderer = gtk_cell_renderer_toggle_new();
-    column = gtk_tree_view_column_new_with_attributes(title, renderer, "active", n, NULL);
+	renderer = gtk_cell_renderer_toggle_new();
+	column = gtk_tree_view_column_new_with_attributes(title, renderer, "active", n, NULL);
 
-    gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
-    g_object_set_data (G_OBJECT (column), "column", GUINT_TO_POINTER(n));
-    g_object_set_data (G_OBJECT (renderer), "column", GUINT_TO_POINTER(n));
+	gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
+	g_object_set_data (G_OBJECT (column), "column_store_idx", GUINT_TO_POINTER(n));
+	g_object_set_data (G_OBJECT (renderer), "column_store_idx", GUINT_TO_POINTER(n));
  
-    index = gtk_tree_view_append_column(GTK_TREE_VIEW(vfl->listview), column);
-    gtk_tree_view_column_set_fixed_width(column, 16);
-    gtk_tree_view_column_set_visible(column, vfl->marks_enabled);
+	index = gtk_tree_view_append_column(GTK_TREE_VIEW(vfl->listview), column);
+	gtk_tree_view_column_set_fixed_width(column, 16);
+	gtk_tree_view_column_set_visible(column, vfl->marks_enabled);
 
         
-    g_signal_connect(G_OBJECT(renderer), "toggled", G_CALLBACK(vflist_listview_mark_toggled), store);
+	g_signal_connect(G_OBJECT(renderer), "toggled", G_CALLBACK(vflist_listview_mark_toggled), store);
 }
 
 /*
@@ -1720,8 +1725,8 @@
 	GtkTreeStore *store;
 	GtkTreeSelection *selection;
 
-    GType *flist_types;
-    int i;
+	GType flist_types[FILE_COLUMN_COUNT];
+	int i;
     
 	vfl = g_new0(ViewFileList, 1);
 
@@ -1749,7 +1754,6 @@
 	g_signal_connect(G_OBJECT(vfl->widget), "destroy",
 			 G_CALLBACK(vflist_destroy_cb), vfl);
 
-	flist_types = g_new(GType, FILE_COLUMN_COUNT);
 	flist_types[FILE_COLUMN_POINTER] = G_TYPE_POINTER;
 	flist_types[FILE_COLUMN_THUMB] = GDK_TYPE_PIXBUF;
 	flist_types[FILE_COLUMN_NAME] = G_TYPE_STRING;
@@ -1761,7 +1765,6 @@
 		flist_types[i] = G_TYPE_BOOLEAN;
 
 	store = gtk_tree_store_newv(FILE_COLUMN_COUNT, flist_types);
-	g_free(flist_types);
                                
 	vfl->listview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
 	g_object_unref(store);
@@ -1770,18 +1773,20 @@
 	gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_MULTIPLE);
 	gtk_tree_selection_set_select_function(selection, vflist_select_cb, vfl, NULL);
 
-//	gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(vfl->listview), FALSE);
+	gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(vfl->listview), FALSE);
 	gtk_tree_view_set_enable_search(GTK_TREE_VIEW(vfl->listview), FALSE);
 
 	vflist_listview_add_column(vfl, FILE_COLUMN_THUMB, "", TRUE, FALSE, FALSE);
-	vflist_listview_add_column(vfl, FILE_COLUMN_NAME, _("Name"), FALSE, FALSE, FALSE);
-	vflist_listview_add_column(vfl, FILE_COLUMN_SIDECARS, _("Sidecars"), FALSE, FALSE, FALSE);
-	vflist_listview_add_column(vfl, FILE_COLUMN_SIZE, _("Size"), FALSE, TRUE, FALSE);
-	vflist_listview_add_column(vfl, FILE_COLUMN_DATE, _("Date"), FALSE, TRUE, TRUE);
 
 	for(i = 0; i < FILEDATA_MARKS_SIZE;i++)
     		vflist_listview_add_column_toggle(vfl, i + FILE_COLUMN_MARKS, "");
 
+	vflist_listview_add_column(vfl, FILE_COLUMN_NAME, _("Name"), FALSE, FALSE, FALSE);
+	vflist_listview_add_column(vfl, FILE_COLUMN_SIDECARS, _("SC"), FALSE, FALSE, FALSE);
+
+	vflist_listview_add_column(vfl, FILE_COLUMN_SIZE, _("Size"), FALSE, TRUE, FALSE);
+	vflist_listview_add_column(vfl, FILE_COLUMN_DATE, _("Date"), FALSE, TRUE, FALSE);
+
             
 	g_signal_connect(G_OBJECT(vfl->listview), "key_press_event",
 			 G_CALLBACK(vflist_press_key_cb), vfl);
@@ -1827,22 +1832,29 @@
 
 void vflist_marks_set(ViewFileList *vfl, gint enable)
 {
-    GtkTreeStore *store;
-    GtkTreeViewColumn *column;
-    int i;
+	GtkTreeStore *store;
+	GtkTreeViewColumn *column;
+	GList *columns, *work;
     
 	if (vfl->marks_enabled == enable) return;
 
 	vfl->marks_enabled = enable;
     
-    for (i = 0; i < FILEDATA_MARKS_SIZE; i++) {
-        /* index - 2 because column's store != tree view */
-        column = gtk_tree_view_get_column(GTK_TREE_VIEW(vfl->listview), i + FILE_COLUMN_MARKS - 2);
-        
-        gtk_tree_view_column_set_visible(column, enable);
-    }
+	columns = gtk_tree_view_get_columns(GTK_TREE_VIEW(vfl->listview));
+	
+	work = columns;
+	while (work)
+		{
+		GtkTreeViewColumn *column = work->data;
+		gint col_idx = GPOINTER_TO_INT(g_object_get_data (G_OBJECT(column), "column_store_idx"));
+		work = work->next;
+		
+		if (col_idx <= FILE_COLUMN_MARKS_LAST && col_idx >= FILE_COLUMN_MARKS)                                                                                             
+			gtk_tree_view_column_set_visible(column, enable);
+		}
     
-    //vflist_refresh(vfl);
+	g_list_free(columns);
+	//vflist_refresh(vfl);
 }
 
 void vflist_set_layout(ViewFileList *vfl, LayoutWindow *layout)