[PATCH] Handle a special case when creating a new trip from the last dive
Lubomir I. Ivanov
neolit123 at gmail.com
Tue Sep 18 13:44:58 PDT 2012
From: "Lubomir I. Ivanov" <neolit123 at gmail.com>
When creating a new trip from the last dive in the list, next
dives should not matter even if the dive is selected.
Added a new method dive_from_path_with_index() in divelist.c
which perhaps isn't the best solution.
Signed-off-by: Lubomir I. Ivanov <neolit123 at gmail.com>
---
divelist.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/divelist.c b/divelist.c
index aedcdf0..7784bc7 100644
--- a/divelist.c
+++ b/divelist.c
@@ -169,7 +169,15 @@ static struct dive *dive_from_path(GtkTreePath *path)
gtk_tree_model_get_iter(MODEL(dive_list), &iter, path);
gtk_tree_model_get(MODEL(dive_list), &iter, DIVE_INDEX, &idx, -1);
return get_dive(idx);
+}
+static struct dive *dive_from_path_with_index(GtkTreePath *path, int *idx)
+{
+ GtkTreeIter iter;
+
+ gtk_tree_model_get_iter(MODEL(dive_list), &iter, path);
+ gtk_tree_model_get(MODEL(dive_list), &iter, DIVE_INDEX, idx, -1);
+ return get_dive(*idx);
}
/* make sure that if we expand a summary row that is selected, the children show
@@ -1514,6 +1522,8 @@ static void insert_trip_before(GtkTreePath *path)
static void insert_trip_before_cb(GtkWidget *menuitem, GtkTreePath *path)
{
+ int idx;
+
/* is this splitting a trip or turning a dive into a trip? */
if (gtk_tree_path_get_depth(path) == 2) {
insert_trip_before(path);
@@ -1521,11 +1531,12 @@ static void insert_trip_before_cb(GtkWidget *menuitem, GtkTreePath *path)
struct dive *dive, *next_dive;
GtkTreePath *next_path;
- dive = dive_from_path(path);
+ dive = dive_from_path_with_index(path, &idx);
turn_dive_into_trip(path);
+
/* if the dive was selected and the next dive was selected, too,
* then all of them should be part of the new trip */
- if (dive->selected) {
+ if (dive->selected && idx > 0) {
next_path = gtk_tree_path_copy(path);
gtk_tree_path_next(next_path);
next_dive = dive_from_path(next_path);
--
1.7.11.msysgit.0
More information about the subsurface
mailing list