[PATCH] Handle a special case when creating a new trip from the last dive

Dirk Hohndel dirk at hohndel.org
Tue Sep 18 16:13:52 PDT 2012


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

> 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.

I don't understand what you are doing with this patch.
The dive with INDEX 0 is the oldest dive, correct?

Why would we not want to look at other dives in the list that are
selected if we are on that dive (assume that we are in oldest first sort
order, not the default latest first sort order).

Are you trying to stop us from walking off the end of the tree_model,
i.e. when we are at the last dive in the list (as your text above
implies)? That we'll have to do differently. While composing this
response I actually managed to reproduce the bug that I think you are
trying to fix... does this patch work for you?

diff --git a/divelist.c b/divelist.c
index aedcdf0..fb076a8 100644
--- a/divelist.c
+++ b/divelist.c
@@ -166,9 +166,12 @@ static struct dive *dive_from_path(GtkTreePath *path)
        GtkTreeIter iter;
        int idx;
 
-       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);
+       if (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);
+       } else {
+               return NULL;
+       }
 
 }
 
This doesn't depend on the sort order but simply does the logical thing
of checking whether we got a valid iter before using it. Duh.

/D


>
> 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
>
> _______________________________________________
> subsurface mailing list
> subsurface at hohndel.org
> http://lists.hohndel.org/cgi-bin/mailman/listinfo/subsurface

-- 
Dirk Hohndel
Intel Open Source Technology Center


More information about the subsurface mailing list