mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Merge branch 'fixes' of git://git.hohndel.org/subsurface
Pull dive selection fixes from Dirk Hohndel. This hopefully fixes the common cases. Dirk is cursing gtk. We may need some gtk selection guru to explain things. * 'fixes' of git://git.hohndel.org/subsurface: Another selection fix More fiddling with the selection
This commit is contained in:
commit
d2d4364afc
1 changed files with 45 additions and 21 deletions
66
divelist.c
66
divelist.c
|
@ -152,6 +152,11 @@ void track_unselect(int idx)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void clear_tracker(void)
|
||||||
|
{
|
||||||
|
amount_selected = 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* when subsurface starts we want to have the last dive selected. So we simply
|
/* when subsurface starts we want to have the last dive selected. So we simply
|
||||||
walk to the first leaf (and skip the summary entries - which have negative
|
walk to the first leaf (and skip the summary entries - which have negative
|
||||||
DIVE_INDEX) */
|
DIVE_INDEX) */
|
||||||
|
@ -169,7 +174,6 @@ static void first_leaf(GtkTreeModel *model, GtkTreeIter *iter, int *diveidx)
|
||||||
if(!gtk_tree_view_row_expanded(GTK_TREE_VIEW(dive_list.tree_view), tpath))
|
if(!gtk_tree_view_row_expanded(GTK_TREE_VIEW(dive_list.tree_view), tpath))
|
||||||
gtk_tree_view_expand_row(GTK_TREE_VIEW(dive_list.tree_view), tpath, FALSE);
|
gtk_tree_view_expand_row(GTK_TREE_VIEW(dive_list.tree_view), tpath, FALSE);
|
||||||
gtk_tree_model_get(GTK_TREE_MODEL(model), iter, DIVE_INDEX, diveidx, -1);
|
gtk_tree_model_get(GTK_TREE_MODEL(model), iter, DIVE_INDEX, diveidx, -1);
|
||||||
track_select(*diveidx);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,31 +183,36 @@ static void select_children(GtkTreeModel *model, GtkTreeSelection * selection,
|
||||||
GtkTreeIter *iter, gboolean was_selected)
|
GtkTreeIter *iter, gboolean was_selected)
|
||||||
{
|
{
|
||||||
int i, nr_children;
|
int i, nr_children;
|
||||||
gboolean unexpand = FALSE;
|
gboolean expanded = FALSE;
|
||||||
GtkTreeIter parent;
|
GtkTreeIter parent;
|
||||||
GtkTreePath *tpath;
|
GtkTreePath *tpath;
|
||||||
|
|
||||||
memcpy(&parent, iter, sizeof(parent));
|
memcpy(&parent, iter, sizeof(parent));
|
||||||
|
|
||||||
tpath = gtk_tree_model_get_path(model, &parent);
|
tpath = gtk_tree_model_get_path(model, &parent);
|
||||||
|
expanded = gtk_tree_view_row_expanded(GTK_TREE_VIEW(dive_list.tree_view), tpath);
|
||||||
/* stupid gtk doesn't allow us to select rows that are invisible; so if the
|
|
||||||
user clicks on a row that isn't expanded, we briefly expand it, select the
|
|
||||||
children, and then unexpand it again */
|
|
||||||
if(!gtk_tree_view_row_expanded(GTK_TREE_VIEW(dive_list.tree_view), tpath)) {
|
|
||||||
unexpand = TRUE;
|
|
||||||
gtk_tree_view_expand_row(GTK_TREE_VIEW(dive_list.tree_view), tpath, FALSE);
|
|
||||||
}
|
|
||||||
nr_children = gtk_tree_model_iter_n_children(model, &parent);
|
nr_children = gtk_tree_model_iter_n_children(model, &parent);
|
||||||
for (i = 0; i < nr_children; i++) {
|
for (i = 0; i < nr_children; i++) {
|
||||||
gtk_tree_model_iter_nth_child(model, iter, &parent, i);
|
gtk_tree_model_iter_nth_child(model, iter, &parent, i);
|
||||||
if (was_selected)
|
|
||||||
gtk_tree_selection_unselect_iter(selection, iter);
|
/* if the parent is expanded, just (un)select the children and we'll
|
||||||
else
|
track their selection status in the callback
|
||||||
gtk_tree_selection_select_iter(selection, iter);
|
otherwise just change the selection status directly without
|
||||||
|
bothering gtk */
|
||||||
|
if (expanded) {
|
||||||
|
if (was_selected)
|
||||||
|
gtk_tree_selection_unselect_iter(selection, iter);
|
||||||
|
else
|
||||||
|
gtk_tree_selection_select_iter(selection, iter);
|
||||||
|
} else {
|
||||||
|
int idx;
|
||||||
|
gtk_tree_model_get(model, iter, DIVE_INDEX, &idx, -1);
|
||||||
|
if (was_selected)
|
||||||
|
track_unselect(idx);
|
||||||
|
else
|
||||||
|
track_select(idx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (unexpand)
|
|
||||||
gtk_tree_view_collapse_row(GTK_TREE_VIEW(dive_list.tree_view), tpath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* make sure that if we expand a summary row that is selected, the children show
|
/* make sure that if we expand a summary row that is selected, the children show
|
||||||
|
@ -225,14 +234,29 @@ gboolean modify_selection_cb(GtkTreeSelection *selection, GtkTreeModel *model,
|
||||||
GtkTreeIter iter;
|
GtkTreeIter iter;
|
||||||
int dive_idx;
|
int dive_idx;
|
||||||
|
|
||||||
|
/* if gtk thinks nothing is selected we should clear out our
|
||||||
|
tracker as well - otherwise hidden selected rows can stay
|
||||||
|
"stuck". The down side is that we now have a different bug:
|
||||||
|
If you select a dive, collapse the dive trip and ctrl-click
|
||||||
|
another dive trip, the initial dive is no longer selected.
|
||||||
|
Just don't do that, ok? */
|
||||||
|
if (gtk_tree_selection_count_selected_rows(selection) == 0)
|
||||||
|
clear_tracker();
|
||||||
|
|
||||||
if (gtk_tree_model_get_iter(model, &iter, path)) {
|
if (gtk_tree_model_get_iter(model, &iter, path)) {
|
||||||
gtk_tree_model_get(model, &iter, DIVE_INDEX, &dive_idx, -1);
|
gtk_tree_model_get(model, &iter, DIVE_INDEX, &dive_idx, -1);
|
||||||
/* turns out we need to move the selectiontracker here */
|
/* turns out we need to move the selectiontracker here */
|
||||||
if (was_selected)
|
|
||||||
track_unselect(dive_idx);
|
#if DEBUG_SELECTION_TRACKING
|
||||||
else
|
printf("modify_selection_cb with idx %d (according to gtk was %sselected)\n",
|
||||||
track_select(dive_idx);
|
dive_idx, was_selected ? "" : "un");
|
||||||
if (dive_idx < 0) {
|
#endif
|
||||||
|
if (dive_idx >= 0) {
|
||||||
|
if (was_selected)
|
||||||
|
track_unselect(dive_idx);
|
||||||
|
else
|
||||||
|
track_select(dive_idx);
|
||||||
|
} else {
|
||||||
select_children(model, selection, &iter, was_selected);
|
select_children(model, selection, &iter, was_selected);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue