From 9e9ba73b3d21c2184c16f3ba5cf3a71f7c662a55 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Fri, 17 Aug 2012 15:03:57 -0700 Subject: [PATCH] Another selection fix The corner cases are getting more and more artificial. Without this patch, the following can happen: Select one or more dives in an (expanded) dive trip. Now collapse that trip with the little triangle. Select a different trip. The previously selected dive(s) are still part of the selection (as you can see, for example, in the statistics tab). With this patch the scenario above works as intended (all the dives in the new trip are selected), but we have another corner case: Just as before, select one or more dives in an expanded dive trip. Collapse that trip and ctrl-click on another trip. Now you lose the originally selected dives. Frankly, if you ctrl-click to add more dives to your selection - just don't collapse the trips the dives are in? As this new corner case seems even more artificial than the previous one, I consider this patch an improvement. But fundamentally I am just battling all the ways in which gtk's selection handling is messed up. When I get the selection call back I cannot tell if this is a new selection or an incremental selection (i.e., a shift-click or ctrl-click). Signed-off-by: Dirk Hohndel --- divelist.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/divelist.c b/divelist.c index b1b74d4..0f5c900 100644 --- a/divelist.c +++ b/divelist.c @@ -152,6 +152,11 @@ void track_unselect(int idx) #endif } +void clear_tracker(void) +{ + amount_selected = 0; +} + /* 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) */ @@ -229,12 +234,21 @@ gboolean modify_selection_cb(GtkTreeSelection *selection, GtkTreeModel *model, GtkTreeIter iter; int dive_idx; + /* if gtk thinks nothing is selected we should clear out our + tracker as well - otherwise hidden selected rows can stay + "stuck". The down side is that we now have a different bug: + If you select a dive, collapse the dive trip and ctrl-click + another dive trip, the initial dive is no longer selected. + Just don't do that, ok? */ + if (gtk_tree_selection_count_selected_rows(selection) == 0) + clear_tracker(); + if (gtk_tree_model_get_iter(model, &iter, path)) { gtk_tree_model_get(model, &iter, DIVE_INDEX, &dive_idx, -1); /* turns out we need to move the selectiontracker here */ #if DEBUG_SELECTION_TRACKING - printf("modify_selection_cb with idx %d (according to gtk was %sselected) - ", + printf("modify_selection_cb with idx %d (according to gtk was %sselected)\n", dive_idx, was_selected ? "" : "un"); #endif if (dive_idx >= 0) { -- 2.43.0