[PATCH 2/2] tree_selected_foreach: ingore trips in the selection

Lubomir I. Ivanov neolit123 at gmail.com
Thu Sep 27 15:45:42 PDT 2012


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

Ignore trips (DIVE_INDEX == -1) when iterating trought the selection,
so that we only call delete_single_dive() for dives.

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

diff --git a/divelist.c b/divelist.c
index 7fa6bac..d1d4038 100644
--- a/divelist.c
+++ b/divelist.c
@@ -1899,11 +1899,15 @@ struct tree_selected_st {
 static void tree_selected_foreach(GtkTreeModel *model, GtkTreePath *path,
                                   GtkTreeIter *iter, gpointer userdata)
 {
+	int idx;
 	struct tree_selected_st *st = (struct tree_selected_st *)userdata;
 
-	st->total++;
-	st->list = (GtkTreeIter *)realloc(st->list, sizeof(GtkTreeIter) * st->total);
-	memcpy(&st->list[st->total - 1], iter, sizeof(GtkTreeIter));
+	gtk_tree_model_get(MODEL(dive_list), iter, DIVE_INDEX, &idx, -1);
+	if (idx >= 0) {
+		st->total++;
+		st->list = (GtkTreeIter *)realloc(st->list, sizeof(GtkTreeIter) * st->total);
+		memcpy(&st->list[st->total - 1], iter, sizeof(GtkTreeIter));
+	}
 }
 
 /* called when multiple dives are selected and one of these is right-clicked for delete */
-- 
1.7.11.msysgit.0



More information about the subsurface mailing list