ocarina: Bugfix the j and k keys a bit

Don't try to navigate when there are no visible tree views...

Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
Bryan Schumaker 2012-09-03 10:33:27 -04:00
parent 04b4967275
commit 0290ea8710
2 changed files with 12 additions and 4 deletions

View File

@ -133,15 +133,21 @@ static void track_selected(GtkWidget *treeview, GtkTreePath *path,
track->load(true);
}
static void goto_next_row(GtkTreeView *treeview, bool next)
static void move_cursor(GtkTreeView *treeview, string &key)
{
GtkTreePath *path;
gtk_widget_grab_focus(GTK_WIDGET(treeview));
gtk_tree_view_get_cursor(treeview, &path, NULL);
if (next)
if (path == NULL)
return;
if (key == "j")
gtk_tree_path_next(path);
else
gtk_tree_path_prev(path);
gtk_tree_view_set_cursor(treeview, path, NULL, FALSE);
if (path)
gtk_tree_view_set_cursor(treeview, path, NULL, FALSE);
gtk_tree_path_free(path);
}
@ -202,7 +208,7 @@ static gboolean key_pressed(GtkTreeView *treeview, GdkEvent *event, gpointer dat
key = key.substr(3);
if (key == "j" || key == "k")
goto_next_row(treeview, key == "j");
move_cursor(treeview, key);
if (key == "s" || key == "q")
new_playlist(key, treeview, false);
else if (key == "S" || key == "Q")

View File

@ -119,6 +119,8 @@ void playlist_focus_treeview()
gtk_widget_grab_focus(GTK_WIDGET(treeview));
gtk_tree_view_get_cursor(treeview, &path, NULL);
if (path == NULL)
return;
gtk_tree_view_set_cursor(treeview, path, NULL, FALSE);
gtk_tree_path_free(path);
}