mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 13:10:19 +00:00
Improvements to select_prev_dive() and select_next_dive()
There were some minor problems when moving the selection cursor around: 1) If the selection was larger than 1, it was possible for the selection to get "stuck" in the middle of the list. This patch approaches this by always calling gtk_tree_selection_unselect_all() before gtk_tree_selection_select_iter(), or simply always making sure we have one selected iterator when navigating with the keys. 2) When there was a single top level dive before the first trip it wasn't possible to navigate trough the child dives of said trip in both directions. The patch attempts to fix this by having the hunks/checks: if (idx < 0) { (idx is of a trip) performed regardless of other conditions. *** Note: testing was done by importing all test*.xml dives with auto-group on. [Dirk Hohndel: adjusted the patch to also fix on_key_press to only grab the key if no modifier key is pressed; otherwise this breaks shift-cursor-keys for selecting multiple dives.] Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
e5e2fb2038
commit
fc882f574f
2 changed files with 33 additions and 29 deletions
60
divelist.c
60
divelist.c
|
@ -2663,7 +2663,7 @@ static GtkTreeIter *get_iter_from_idx(int idx)
|
||||||
|
|
||||||
void select_next_dive(void)
|
void select_next_dive(void)
|
||||||
{
|
{
|
||||||
GtkTreeIter *nextiter;
|
GtkTreeIter *nextiter, *parent;
|
||||||
GtkTreeIter *iter = get_iter_from_idx(selected_dive);
|
GtkTreeIter *iter = get_iter_from_idx(selected_dive);
|
||||||
GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dive_list.tree_view));
|
GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dive_list.tree_view));
|
||||||
GtkTreePath *treepath;
|
GtkTreePath *treepath;
|
||||||
|
@ -2673,31 +2673,33 @@ void select_next_dive(void)
|
||||||
return;
|
return;
|
||||||
nextiter = gtk_tree_iter_copy(iter);
|
nextiter = gtk_tree_iter_copy(iter);
|
||||||
if (!gtk_tree_model_iter_next(MODEL(dive_list), nextiter)) {
|
if (!gtk_tree_model_iter_next(MODEL(dive_list), nextiter)) {
|
||||||
if (!gtk_tree_model_iter_parent(MODEL(dive_list), nextiter, iter))
|
if (!gtk_tree_model_iter_parent(MODEL(dive_list), nextiter, iter)) {
|
||||||
/* we're at the last top level node */
|
/* we're at the last top level node */
|
||||||
return;
|
return;
|
||||||
if (!gtk_tree_model_iter_next(MODEL(dive_list), nextiter))
|
}
|
||||||
|
if (!gtk_tree_model_iter_next(MODEL(dive_list), nextiter)) {
|
||||||
/* last trip */
|
/* last trip */
|
||||||
return;
|
return;
|
||||||
gtk_tree_model_get(MODEL(dive_list), nextiter, DIVE_INDEX, &idx, -1);
|
|
||||||
if (idx < 0) {
|
|
||||||
/* need the first child */
|
|
||||||
GtkTreeIter *parent = gtk_tree_iter_copy(nextiter);
|
|
||||||
if (! gtk_tree_model_iter_children(MODEL(dive_list), nextiter, parent))
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
gtk_tree_model_get(MODEL(dive_list), nextiter, DIVE_INDEX, &idx, -1);
|
||||||
|
if (idx < 0) {
|
||||||
|
/* need the first child */
|
||||||
|
parent = gtk_tree_iter_copy(nextiter);
|
||||||
|
if (! gtk_tree_model_iter_children(MODEL(dive_list), nextiter, parent))
|
||||||
|
return;
|
||||||
|
}
|
||||||
treepath = gtk_tree_model_get_path(MODEL(dive_list), nextiter);
|
treepath = gtk_tree_model_get_path(MODEL(dive_list), nextiter);
|
||||||
gtk_tree_view_expand_to_path(GTK_TREE_VIEW(dive_list.tree_view), treepath);
|
gtk_tree_view_expand_to_path(GTK_TREE_VIEW(dive_list.tree_view), treepath);
|
||||||
gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(dive_list.tree_view), treepath, NULL, FALSE, 0, 0);
|
gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(dive_list.tree_view), treepath, NULL, FALSE, 0, 0);
|
||||||
|
gtk_tree_selection_unselect_all(selection);
|
||||||
gtk_tree_selection_select_iter(selection, nextiter);
|
gtk_tree_selection_select_iter(selection, nextiter);
|
||||||
gtk_tree_selection_unselect_iter(selection, iter);
|
|
||||||
gtk_tree_path_free(treepath);
|
gtk_tree_path_free(treepath);
|
||||||
}
|
}
|
||||||
|
|
||||||
void select_prev_dive(void)
|
void select_prev_dive(void)
|
||||||
{
|
{
|
||||||
GtkTreeIter previter;
|
GtkTreeIter previter, *parent;
|
||||||
GtkTreeIter *iter = get_iter_from_idx(selected_dive);
|
GtkTreeIter *iter = get_iter_from_idx(selected_dive);
|
||||||
GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dive_list.tree_view));
|
GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dive_list.tree_view));
|
||||||
GtkTreePath *treepath;
|
GtkTreePath *treepath;
|
||||||
|
@ -2709,29 +2711,31 @@ void select_prev_dive(void)
|
||||||
if (!gtk_tree_path_prev(treepath)) {
|
if (!gtk_tree_path_prev(treepath)) {
|
||||||
if (!gtk_tree_model_iter_parent(MODEL(dive_list), &previter, iter))
|
if (!gtk_tree_model_iter_parent(MODEL(dive_list), &previter, iter))
|
||||||
/* we're at the last top level node */
|
/* we're at the last top level node */
|
||||||
return;
|
goto free_path;
|
||||||
|
gtk_tree_path_free(treepath);
|
||||||
treepath = gtk_tree_model_get_path(MODEL(dive_list), &previter);
|
treepath = gtk_tree_model_get_path(MODEL(dive_list), &previter);
|
||||||
if (!gtk_tree_path_prev(treepath))
|
if (!gtk_tree_path_prev(treepath))
|
||||||
/* first trip */
|
/* first trip */
|
||||||
return;
|
goto free_path;
|
||||||
if (!gtk_tree_model_get_iter(MODEL(dive_list), &previter, treepath))
|
if (!gtk_tree_model_get_iter(MODEL(dive_list), &previter, treepath))
|
||||||
return;
|
goto free_path;
|
||||||
gtk_tree_model_get(MODEL(dive_list), &previter, DIVE_INDEX, &idx, -1);
|
|
||||||
if (idx < 0) {
|
|
||||||
/* need the last child */
|
|
||||||
GtkTreeIter *parent = gtk_tree_iter_copy(&previter);
|
|
||||||
if (! gtk_tree_model_iter_nth_child(MODEL(dive_list), &previter, parent,
|
|
||||||
gtk_tree_model_iter_n_children(MODEL(dive_list), parent) - 1))
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
treepath = gtk_tree_model_get_path(MODEL(dive_list), &previter);
|
|
||||||
} else {
|
|
||||||
if (!gtk_tree_model_get_iter(MODEL(dive_list), &previter, treepath))
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
if (!gtk_tree_model_get_iter(MODEL(dive_list), &previter, treepath))
|
||||||
|
goto free_path;
|
||||||
|
gtk_tree_model_get(MODEL(dive_list), &previter, DIVE_INDEX, &idx, -1);
|
||||||
|
if (idx < 0) {
|
||||||
|
/* need the last child */
|
||||||
|
parent = gtk_tree_iter_copy(&previter);
|
||||||
|
if (! gtk_tree_model_iter_nth_child(MODEL(dive_list), &previter, parent,
|
||||||
|
gtk_tree_model_iter_n_children(MODEL(dive_list), parent) - 1))
|
||||||
|
goto free_path;
|
||||||
|
}
|
||||||
|
gtk_tree_path_free(treepath);
|
||||||
|
treepath = gtk_tree_model_get_path(MODEL(dive_list), &previter);
|
||||||
gtk_tree_view_expand_to_path(GTK_TREE_VIEW(dive_list.tree_view), treepath);
|
gtk_tree_view_expand_to_path(GTK_TREE_VIEW(dive_list.tree_view), treepath);
|
||||||
gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(dive_list.tree_view), treepath, NULL, FALSE, 0, 0);
|
gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(dive_list.tree_view), treepath, NULL, FALSE, 0, 0);
|
||||||
|
gtk_tree_selection_unselect_all(selection);
|
||||||
gtk_tree_selection_select_iter(selection, &previter);
|
gtk_tree_selection_select_iter(selection, &previter);
|
||||||
gtk_tree_selection_unselect_iter(selection, iter);
|
free_path:
|
||||||
gtk_tree_path_free(treepath);
|
gtk_tree_path_free(treepath);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1147,7 +1147,7 @@ static void switch_page(GtkNotebook *notebook, gint arg1, gpointer user_data)
|
||||||
|
|
||||||
static gboolean on_key_press(GtkWidget *w, GdkEventKey *event, GtkWidget *divelist)
|
static gboolean on_key_press(GtkWidget *w, GdkEventKey *event, GtkWidget *divelist)
|
||||||
{
|
{
|
||||||
if (event->type != GDK_KEY_PRESS)
|
if (event->type != GDK_KEY_PRESS || event->state != 0)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
switch (event->keyval) {
|
switch (event->keyval) {
|
||||||
case GDK_Up:
|
case GDK_Up:
|
||||||
|
|
Loading…
Reference in a new issue