mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Avoid changing selection status when collapsing/expanding groups
This tries to avoid the problem mentioned in commit972669d6363c ("Rework dive selection logic"), where a selection of dives hidden by collapsing the group gets forgotten about by gtk. It does so by always marking the group selected when it is collapsed with any selected children. We also avoid selecting new children when a group is selected that already has at least *some* children selected already. This way we do minimal damage to existing selections when working with dive group selections. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
972669d636
commit
5322b4aac1
1 changed files with 35 additions and 0 deletions
35
divelist.c
35
divelist.c
|
@ -138,6 +138,37 @@ void row_expanded_cb(GtkTreeView *tree_view, GtkTreeIter *iter, GtkTreePath *pat
|
|||
} while (gtk_tree_model_iter_next(model, &child));
|
||||
}
|
||||
|
||||
static int selected_children(GtkTreeModel *model, GtkTreeIter *iter)
|
||||
{
|
||||
GtkTreeIter child;
|
||||
|
||||
if (!gtk_tree_model_iter_children(model, &child, iter))
|
||||
return FALSE;
|
||||
|
||||
do {
|
||||
int idx;
|
||||
struct dive *dive;
|
||||
|
||||
gtk_tree_model_get(model, &child, DIVE_INDEX, &idx, -1);
|
||||
dive = get_dive(idx);
|
||||
|
||||
if (dive->selected)
|
||||
return TRUE;
|
||||
} while (gtk_tree_model_iter_next(model, &child));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Make sure that if we collapse a summary row with any selected children, the row
|
||||
shows up as selected too */
|
||||
void row_collapsed_cb(GtkTreeView *tree_view, GtkTreeIter *iter, GtkTreePath *path, gpointer data)
|
||||
{
|
||||
GtkTreeModel *model = GTK_TREE_MODEL(dive_list.model);
|
||||
GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dive_list.tree_view));
|
||||
|
||||
if (selected_children(model, iter))
|
||||
gtk_tree_selection_select_iter(selection, iter);
|
||||
}
|
||||
|
||||
static GList *selection_changed = NULL;
|
||||
|
||||
/*
|
||||
|
@ -179,6 +210,9 @@ static void select_dive_group(GtkTreeModel *model, GtkTreeSelection *selection,
|
|||
int first = 1;
|
||||
GtkTreeIter child;
|
||||
|
||||
if (selected == selected_children(model, iter))
|
||||
return;
|
||||
|
||||
if (!gtk_tree_model_iter_children(model, &child, iter))
|
||||
return;
|
||||
|
||||
|
@ -1296,6 +1330,7 @@ GtkWidget *dive_list_create(void)
|
|||
g_signal_connect_after(dive_list.tree_view, "realize", G_CALLBACK(realize_cb), NULL);
|
||||
g_signal_connect(dive_list.tree_view, "row-activated", G_CALLBACK(row_activated_cb), NULL);
|
||||
g_signal_connect(dive_list.tree_view, "row-expanded", G_CALLBACK(row_expanded_cb), NULL);
|
||||
g_signal_connect(dive_list.tree_view, "row-collapsed", G_CALLBACK(row_collapsed_cb), NULL);
|
||||
g_signal_connect(dive_list.tree_view, "button-press-event", G_CALLBACK(button_press_cb), NULL);
|
||||
g_signal_connect(dive_list.tree_view, "popup-menu", G_CALLBACK(popup_menu_cb), NULL);
|
||||
g_signal_connect(selection, "changed", G_CALLBACK(selection_cb), dive_list.model);
|
||||
|
|
Loading…
Add table
Reference in a new issue