[PATCH] Fix keyboard navigation of dive list.

Dirk Hohndel dirk at hohndel.org
Thu Jan 31 16:56:51 PST 2013


Sergey Starosek <sergey.starosek at gmail.com> writes:

> 2013/1/31 Dirk Hohndel <dirk at hohndel.org>:
>>>
>>> Is it possible to fix Menu button to behave like right mouse click as well?
>>
>> So the right mouse click is a context menu relative to the current moust
>> position. When you hit that key, which mouse position should it use?
>> I find that use case a bit counter intuitive, to be honest...
>
> It should use selected dive(s).

Ok, It's got to be something like this patch... I admit it's a bit
hackish but I didn't want to rewrite all the existing code... so I get
an iter for the selected dive, get the path from that iter and then say
"awesome, that's what the other code started with" and continue... and
ignore the fact that the first thing the existing code does is to get an
iter from the path...

This all works beautifully, the menu gets built and then... it doesn't
appear to get rendered. And I don't understand why :-(

Hey Carl, have you subscribed to the Subsurface mailing list, yet?

/D


diff --git a/divelist.c b/divelist.c
index 1463ef9..7dfefbd 100644
--- a/divelist.c
+++ b/divelist.c
@@ -2341,6 +2341,8 @@ static void add_dive_merge_label(int idx, GtkMenuShell *menu)
        gtk_menu_shell_append(menu, menuitem);
 }
 
+static GtkTreeIter *get_iter_from_idx(int idx);
+
 static void popup_divelist_menu(GtkTreeView *tree_view, GtkTreeModel *model, int button, GdkEventButton *event)
 {
        GtkWidget *menu, *menuitem, *image;
@@ -2351,12 +2353,22 @@ static void popup_divelist_menu(GtkTreeView *tree_view, GtkTreeModel *model, int
        char deletesinglelabel[] = N_("Delete dive");
        char *deletelabel;
        GtkTreePath *path, *prevpath, *nextpath;
-       GtkTreeIter iter, previter, nextiter;
+       GtkTreeIter iter, previter, nextiter, *selected_iter;
        int idx, previdx, nextidx;
        struct dive *dive;
 
-       if (!event || !gtk_tree_view_get_path_at_pos(tree_view, event->x, event->y, &path, NULL, NULL, NULL))
+       if (!event) {
+               /* we get here if the user has a key that triggers the menu popup
+                * I'm sure this could be done easier, but for now I just get the iter
+                * for the selected dive, turn it into a path and then go back to the
+                * code that starts with the path (and gets an iter for it.. duh) */
+               selected_iter = get_iter_from_idx(selected_dive);
+               if (!selected_iter)
+                       return;
+               path = gtk_tree_model_get_path(MODEL(dive_list), selected_iter);
+       } else if (!gtk_tree_view_get_path_at_pos(tree_view, event->x, event->y, &path, NULL, NULL, NULL)) {
                return;
+       }
        gtk_tree_model_get_iter(MODEL(dive_list), &iter, path);
        gtk_tree_model_get(MODEL(dive_list), &iter, DIVE_INDEX, &idx, -1);
 


More information about the subsurface mailing list