[Commits] [SCM] claws branch, gtk3tree, updated. 3.99.0-82-gba90716e2

thorsten at claws-mail.org thorsten at claws-mail.org
Fri Apr 2 22:37:51 CEST 2021


The branch, gtk3tree has been updated
       via  ba90716e29c2b5d11ab72530096e0203fcb7032a (commit)
      from  b722a827da13d2cd1756951c4d7eab0d8bce59c1 (commit)

Summary of changes:
 src/folderview.c          | 63 ++++++++++++++++++++++++++++++++++++++++++++++-
 src/prefs_folder_column.c | 42 ++++++++++++++++---------------
 2 files changed, 84 insertions(+), 21 deletions(-)


- Log -----------------------------------------------------------------
commit ba90716e29c2b5d11ab72530096e0203fcb7032a
Author: Thorsten Maerz <info at netztorte.de>
Date:   Fri Apr 2 22:37:05 2021 +0200

    Reimplement folderview_set_column_order()

diff --git a/src/folderview.c b/src/folderview.c
index 3053a735a..44d8cd108 100644
--- a/src/folderview.c
+++ b/src/folderview.c
@@ -181,6 +181,8 @@ static void folderview_drag_end_cb	 (GtkWidget	   *widget,
 
 GHashTable *folderview_popups;
 
+GList *treeview_default_columns_ordered;
+
 static void create_action_groups		(gpointer key,
 						 gpointer value,
 						 gpointer data);
@@ -630,6 +632,8 @@ static GtkWidget *treeview_create_unconnected()
 	gtk_tree_view_column_set_title(column, _("Folder"));
 
 	gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
+	treeview_default_columns_ordered = g_list_append
+			(treeview_default_columns_ordered, column);
 
 	/* New */
 	column = gtk_tree_view_column_new();
@@ -651,6 +655,8 @@ static GtkWidget *treeview_create_unconnected()
 	gtk_tree_view_column_set_widget(column, image);
 
 	gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
+	treeview_default_columns_ordered = g_list_append
+			(treeview_default_columns_ordered, column);
 
 	/* Unread */
 	column = gtk_tree_view_column_new();
@@ -670,6 +676,8 @@ static GtkWidget *treeview_create_unconnected()
 	gtk_tree_view_column_set_widget(column, image);
 
 	gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
+	treeview_default_columns_ordered = g_list_append
+			(treeview_default_columns_ordered, column);
 
 	/* Total */
 	column = gtk_tree_view_column_new();
@@ -689,6 +697,8 @@ static GtkWidget *treeview_create_unconnected()
 	gtk_tree_view_column_set_widget(column, image);
 
 	gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
+	treeview_default_columns_ordered = g_list_append
+			(treeview_default_columns_ordered, column);
 
 	return treeview;
 }
@@ -819,6 +829,8 @@ FolderView *folderview_create(MainWindow *mainwin)
 
 	folderview_list = g_list_append(folderview_list, folderview);
 
+	folderview_set_column_order(folderview);
+
 	return folderview;
 }
 /*
@@ -2614,7 +2626,56 @@ void folderview_update_search_icon(FolderItem *item, gboolean matches)
 
 void folderview_set_column_order(FolderView *folderview)
 {
-	debug_print("========STUB======== folderview_set_column_order\n");
+	gint i;
+	GtkTreeViewColumn *default_column;
+	GtkTreeViewColumn *tree_column = NULL;
+	GtkTreeViewColumn *prev = NULL;
+	FolderColumnState *col_state;
+	GList *tree_columns = gtk_tree_view_get_columns
+			(GTK_TREE_VIEW(folderview->treeview));
+
+	/* recreate old order (as saved in treeview_default_columns_ordered) */
+	for (i = F_COL_FOLDER; i <= F_COL_TOTAL; i++) {
+		GList *listentry;
+		default_column = (GtkTreeViewColumn*)g_list_nth_data
+				(treeview_default_columns_ordered,
+				 i - F_COL_FOLDER);
+		listentry = g_list_find(tree_columns, default_column);
+		if (!listentry) {
+			debug_print("Error: default_column not found!\n");
+			g_list_free(tree_columns);
+			return;
+		}
+
+		tree_column = listentry->data;
+		if (prev)
+			gtk_tree_view_move_column_after
+				(GTK_TREE_VIEW(folderview->treeview),
+				 tree_column, prev);
+		prev = tree_column;
+	}
+
+	/* apply new order
+	 * col_state[i].type, when used as an index to the default_columns,
+	 * points to the column, that should be displayed at position "i"
+	 */
+	col_state = prefs_folder_column_get_config();
+	prev = NULL;
+	for (i = F_COL_FOLDER; i <= F_COL_TOTAL; i++) {
+		gint newtype = col_state[i].type;
+		default_column = (GtkTreeViewColumn*)g_list_nth_data
+				(treeview_default_columns_ordered,
+				 newtype - F_COL_FOLDER);
+		gtk_tree_view_column_set_visible(default_column,
+						 col_state[i].visible);
+		if (prev)
+			gtk_tree_view_move_column_after
+				(GTK_TREE_VIEW(folderview->treeview),
+				 default_column, prev);
+		prev = default_column;
+	}
+
+	g_list_free(tree_columns);
 }
 
 void folderview_close_opened(FolderView *folderview, gboolean dirty)
diff --git a/src/prefs_folder_column.c b/src/prefs_folder_column.c
index 6298fac04..f96b32c81 100644
--- a/src/prefs_folder_column.c
+++ b/src/prefs_folder_column.c
@@ -373,7 +373,7 @@ FolderColumnState *prefs_folder_column_get_config(void)
 	for (pos = 0; pos < N_FOLDER_COLS; pos++)
 		state[pos].type = -1;
 
-	for (type = 0; type < N_FOLDER_COLS; type++) {
+	for (type = F_COL_FOLDER; type <= F_COL_TOTAL; type++) {
 		pos = prefs_common.folder_col_pos[type];
 		if (pos < 0 || pos >= N_FOLDER_COLS ||
 		    state[pos].type != -1) {
@@ -394,7 +394,7 @@ static void prefs_folder_column_set_config(FolderColumnState *state)
 	FolderColumnType type;
 	gint pos;
 
-	for (pos = 0; pos < N_FOLDER_COLS; pos++) {
+	for (pos = F_COL_FOLDER; pos <= F_COL_TOTAL; pos++) {
 		type = state[pos].type;
 		prefs_common.folder_col_visible[type] = state[pos].visible;
 		prefs_common.folder_col_pos[type] = pos;
@@ -421,16 +421,18 @@ static void prefs_folder_column_set_dialog(FolderColumnState *state)
 
 	for (pos = 0; pos < N_FOLDER_COLS; pos++) {
 		type = state[pos].type;
-		name = gettext(col_name[type]);
-
-		if (state[pos].visible)
-			prefs_folder_column_insert_column(shown_store,
-							   -1, name,
-							   type);
-		else
-			prefs_folder_column_insert_column(stock_store,
-							    -1, name,
-							    type);
+		if ((type >= F_COL_FOLDER) && (type <= F_COL_TOTAL)) {
+			name = gettext(col_name[type - F_COL_FOLDER]);
+
+			if (state[pos].visible)
+				prefs_folder_column_insert_column(shown_store,
+								   -1, name,
+								   type);
+			else
+				prefs_folder_column_insert_column(stock_store,
+								    -1, name,
+								    type);
+		}
 	}
 }
 
@@ -449,21 +451,21 @@ static void prefs_folder_column_set_view(void)
 			(folder_col.shown_list_view)), NULL);
 
 	cm_return_if_fail
-		(stock_n_rows + shown_n_rows == N_FOLDER_COLS);
+		(stock_n_rows + shown_n_rows < N_FOLDER_COLS);
 
 	for (row = 0; row < stock_n_rows; row++) {
 		type = prefs_folder_column_get_column
 			(folder_col.stock_list_view, row);
-		state[row].type = type;
-		state[row].visible = FALSE;
+		state[F_COL_FOLDER + row].type = type;
+		state[F_COL_FOLDER + row].visible = FALSE;
 	}
 
 	pos = row;
 	for (row = 0; row < shown_n_rows; row++) {
 		type = prefs_folder_column_get_column
 			(folder_col.shown_list_view, row);
-		state[pos + row].type = type;
-		state[pos + row].visible = TRUE;
+		state[F_COL_FOLDER + pos + row].type = type;
+		state[F_COL_FOLDER + pos + row].visible = TRUE;
 	}
 
 	prefs_folder_column_set_config(state);
@@ -505,7 +507,7 @@ static void prefs_folder_column_add(void)
 	gtk_list_store_insert_after(shown_store, &shown_add, 
 				    shown_sel_valid ? &shown_sel : NULL);
 
-	name = gettext(col_name[type]);				    
+	name = gettext(col_name[type - F_COL_FOLDER]);
 				    
 	gtk_list_store_set(shown_store, &shown_add,
 			   SUMCOL_NAME, name,
@@ -554,7 +556,7 @@ static void prefs_folder_column_remove(void)
 	gtk_list_store_insert_after(stock_store, &stock_add, 
 				    stock_sel_valid ? &stock_sel : NULL);
 
-	name = gettext(col_name[type]);				    
+	name = gettext(col_name[type - F_COL_FOLDER ]);
 				    
 	gtk_list_store_set(stock_store, &stock_add,
 			   SUMCOL_NAME, name,
@@ -867,7 +869,7 @@ static void drag_data_received(GtkTreeView *tree_view, GdkDragContext *context,
 						GTK_TREE_VIEW(source)),
 						&sel_model, &isel)) {
 			type = *((gint *) gtk_selection_data_get_data(data));
-			name = gettext(col_name[type]);
+			name = gettext(col_name[type - F_COL_FOLDER]);
 			gtk_list_store_remove(GTK_LIST_STORE(sel_model), &isel);
 
 			/* get insertion position */

-----------------------------------------------------------------------


hooks/post-receive
-- 
Claws Mail


More information about the Commits mailing list