[PATCH] Select all dives in a trip when said trip is expanded and clicked
Dirk Hohndel
dirk at hohndel.org
Mon Feb 18 10:28:57 PST 2013
Linus,
as this is doing open heart surgery on the code you recently wrote, can
I get an ACK from you on it, please?
/D
"Lubomir I. Ivanov" <neolit123 at gmail.com> writes:
> 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()).
>
> When calling get_iter_from_idx(), make sure we free memory at
> the returned address.
>
> Signed-off-by: Lubomir I. Ivanov <neolit123 at gmail.com>
> ---
>
> This is an update to the previous patch with the same name, also clearing
> memory allocated by get_iter_from_idx().
>
> ---
> divelist.c | 17 ++++++++++++-----
> 1 file changed, 12 insertions(+), 5 deletions(-)
>
> diff --git a/divelist.c b/divelist.c
> index b5fe48e..a2b17bb 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,
> @@ -2733,7 +2734,9 @@ static gboolean modify_selection_cb(GtkTreeSelection *selection, GtkTreeModel *m
> static void entry_selected(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data)
> {
> int idx;
> + GtkTreeIter *child;
> 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 +2747,17 @@ 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)) {
> + child = get_iter_from_idx(i);
> + gtk_tree_selection_select_iter(selection, child);
> + gtk_tree_iter_free(child);
> + }
> + }
> }
> } else {
> select_dive(idx);
> --
> 1.7.11.msysgit.0
>
> _______________________________________________
> subsurface mailing list
> subsurface at hohndel.org
> http://lists.hohndel.org/cgi-bin/mailman/listinfo/subsurface
More information about the subsurface
mailing list