[PATCH] Select all dives in a trip when said trip is expanded and clicked

Lubomir I. Ivanov neolit123 at gmail.com
Mon Feb 18 07:20:50 PST 2013


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

This patch selects visually all dives within a trip when a
trip is expanded (using gtk_tree_selection_select_iter()).
If the trip is not expanded it only selects the dives
as data (using select_dive()).

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

diff --git a/divelist.c b/divelist.c
index b5fe48e..c4a3879 100644
--- a/divelist.c
+++ b/divelist.c
@@ -72,6 +72,7 @@ enum {
 
 static void turn_dive_into_trip(GtkTreePath *path);
 static void merge_dive_into_trip_above_cb(GtkWidget *menuitem, GtkTreePath *path);
+static GtkTreeIter *get_iter_from_idx(int idx);
 
 #ifdef DEBUG_MODEL
 static gboolean dump_model_entry(GtkTreeModel *model, GtkTreePath *path,
@@ -2734,6 +2735,7 @@ static void entry_selected(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *
 {
 	int idx;
 	timestamp_t when;
+	GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dive_list.tree_view));
 
 	gtk_tree_model_get(model, iter, DIVE_INDEX, &idx, DIVE_DATE, &when, -1);
 	if (idx < 0) {
@@ -2744,13 +2746,14 @@ static void entry_selected(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *
 		if (!trip)
 			return;
 		trip->selected = 1;
-		/* If this is expanded, let the gtk selection happen for each dive under it */
-		if (gtk_tree_view_row_expanded(GTK_TREE_VIEW(dive_list.tree_view), path))
-			return;
-		/* Otherwise, consider each dive under it selected */
+		/* Select dives inside the trip */
 		for_each_dive(i, dive) {
-			if (dive->divetrip == trip)
+			if (dive->divetrip == trip) {
 				select_dive(i);
+				/* Select the actual tree row */
+				if (gtk_tree_view_row_expanded(GTK_TREE_VIEW(dive_list.tree_view), path))
+					gtk_tree_selection_select_iter(selection, get_iter_from_idx(i));				
+			}
 		}
 	} else {
 		select_dive(idx);
-- 
1.7.11.msysgit.0



More information about the subsurface mailing list