[PATCH] Refrain from automatic selection and trip expansion in the divelist

Lubomir I. Ivanov neolit123 at gmail.com
Thu Sep 20 14:20:27 PDT 2012


From: "Lubomir I. Ivanov" <neolit123 at gmail.com>

Divelist fill:
When we first build the list, leave it to the user to first interact with it
- expand trips, select dives. An example scenario is that when
the topmost trip is automatically opened and the first dive inside selected,
while the trip itself contains a lot of dives, the user may be looking for
a dive inside the bottommost trip, therefore has to scroll down. This is
in the lines of user preference logic and potentially there could be
application settings for it.

Delete:
When deleting a dive, similar to some GUI file managers, leave no dives
selected afterwards. Sill expand the last trip which we can obtain from
the actual callback's GtkTreePath.

Unused methods:
Some methods such as match_dive and get_path_from can remain useful.
Put them inside #if 0 for now.

Signed-off-by: Lubomir I. Ivanov <neolit123 at gmail.com>
---
 divelist.c | 48 ++++++------------------------------------------
 1 file changed, 6 insertions(+), 42 deletions(-)

diff --git a/divelist.c b/divelist.c
index d0332c2..7af4e35 100644
--- a/divelist.c
+++ b/divelist.c
@@ -122,26 +122,8 @@ void dump_selection(void)
 }
 #endif
 
-/* when subsurface starts we want to have the last dive selected. So we simply
-   walk to the first leaf (and skip the summary entries - which have negative
-   DIVE_INDEX) */
-static void first_leaf(GtkTreeModel *model, GtkTreeIter *iter, int *diveidx)
-{
-	GtkTreeIter parent;
-	GtkTreePath *tpath;
-
-	while (*diveidx < 0) {
-		memcpy(&parent, iter, sizeof(parent));
-		tpath = gtk_tree_model_get_path(model, &parent);
-		if (!gtk_tree_model_iter_children(model, iter, &parent))
-			/* we should never have a parent without child */
-			return;
-		if(!gtk_tree_view_row_expanded(GTK_TREE_VIEW(dive_list.tree_view), tpath))
-			gtk_tree_view_expand_row(GTK_TREE_VIEW(dive_list.tree_view), tpath, FALSE);
-		gtk_tree_model_get(model, iter, DIVE_INDEX, diveidx, -1);
-	}
-}
-
+/* defined but not used */
+#if 0
 static GtkTreePath *path_match;
 
 static gboolean match_dive(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data)
@@ -163,6 +145,7 @@ static GtkTreePath *get_path_from(struct dive *dive)
 	gtk_tree_model_foreach(TREEMODEL(dive_list), match_dive, dive);
 	return path_match;
 }
+#endif /* defined but not used */
 
 static struct dive *dive_from_path(GtkTreePath *path)
 {
@@ -1250,15 +1233,6 @@ static void fill_dive_list(void)
 				DIVE_LOCATION, dive_trip->location,
 				-1);
 	update_dive_list_units();
-	if (gtk_tree_model_get_iter_first(MODEL(dive_list), &iter)) {
-		GtkTreeSelection *selection;
-
-		/* select the last dive (and make sure it's an actual dive that is selected) */
-		gtk_tree_model_get(MODEL(dive_list), &iter, DIVE_INDEX, &selected_dive, -1);
-		first_leaf(MODEL(dive_list), &iter, &selected_dive);
-		selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dive_list.tree_view));
-		gtk_tree_selection_select_iter(selection, &iter);
-	}
 }
 
 void dive_list_update_dives(void)
@@ -1850,11 +1824,11 @@ static void delete_dive_cb(GtkWidget *menuitem, GtkTreePath *path)
 	int idx, i;
 	struct dive *dive, *pdive, *ndive;
 	GtkTreeView *tree_view = GTK_TREE_VIEW(dive_list.tree_view);
-	GtkTreeSelection *selection = gtk_tree_view_get_selection(tree_view);
 
 	gtk_tree_model_get_iter(MODEL(dive_list), &iter, path);
 	gtk_tree_model_get(MODEL(dive_list), &iter, DIVE_INDEX, &idx, -1);
 	dive = get_dive(idx);
+
 	if (dive->divetrip) {
 		/* we could be displaying the list model, in which case we can't find out
 		 * if this is part of a trip and the only dive in that trip from the model,
@@ -1877,19 +1851,9 @@ static void delete_dive_cb(GtkWidget *menuitem, GtkTreePath *path)
 		dive_table.dives[i] = dive_table.dives[i+1];
 	dive_table.nr--;
 	free(dive);
+
 	dive_list_update_dives();
-	/* now make sure the same dives stay selected and if necessary their trips are expanded
-	 * also make sure that amount_selected stays consistent */
-	amount_selected = 0;
-	for_each_dive(i, dive) {
-		if (dive->selected) {
-			GtkTreePath *path = get_path_from(dive);
-			if (MODEL(dive_list) == TREEMODEL(dive_list))
-				gtk_tree_view_expand_to_path(tree_view, path);
-			gtk_tree_selection_select_path(selection, path);
-			amount_selected++;
-		}
-	}
+	gtk_tree_view_expand_to_path(tree_view, path);
 	mark_divelist_changed(TRUE);
 }
 
-- 
1.7.11.msysgit.0



More information about the subsurface mailing list