From e660e3f0b290df292b73ee3f09bdf43d89d43eaa Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Sat, 3 Sep 2016 12:16:24 -0400 Subject: [PATCH] gui/treeview: Add a "select path at pos" function This function isn't easy to test without knowledge of screen coordinates, so I didn't include a unit test this time. Signed-off-by: Anna Schumaker --- gui/treeview.c | 14 ++++++++++++++ gui/view.c | 9 +-------- include/gui/treeview.h | 3 +++ 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/gui/treeview.c b/gui/treeview.c index 795783f2..531c9427 100644 --- a/gui/treeview.c +++ b/gui/treeview.c @@ -218,6 +218,20 @@ void gui_treeview_scroll() gtk_tree_path_free(path); } +void gui_treeview_select_path_at_pos(unsigned int x, unsigned int y) +{ + GtkTreeSelection *selection; + GtkTreePath *path; + + selection = gtk_tree_view_get_selection(gui_treeview()); + if (gtk_tree_view_get_path_at_pos(gui_treeview(), x, y, + &path, NULL, NULL, NULL)) + { + gtk_tree_selection_select_path(selection, path); + gtk_tree_path_free(path); + } +} + GList *gui_treeview_list_selected_tracks(void) { GList *rows, *cur, *list = NULL; diff --git a/gui/view.c b/gui/view.c index e422405d..460edd8e 100644 --- a/gui/view.c +++ b/gui/view.c @@ -171,22 +171,15 @@ static GtkWidget *__view_rc_build_submenu(void) bool __view_button_press(GtkTreeView *treeview, GdkEventButton *event, gpointer data) { - GtkTreeSelection *selection = gtk_tree_view_get_selection(treeview); GtkMenu *menu = GTK_MENU(gui_builder_widget("o_menu")); GtkWidget *submenu = NULL; GtkMenuItem *other; - GtkTreePath *path; if (event->button != GDK_BUTTON_SECONDARY) return false; /* Select path if it isn't already selected */ - if (gtk_tree_view_get_path_at_pos(treeview, event->x, event->y, - &path, NULL, NULL, NULL)) - { - gtk_tree_selection_select_path(selection, path); - gtk_tree_path_free(path); - } + gui_treeview_select_path_at_pos(event->x, event->y); /* Set the "Other Playlists" submenu. */ other = GTK_MENU_ITEM(gui_builder_widget("o_add_to_other")); diff --git a/include/gui/treeview.h b/include/gui/treeview.h index e8b5d54c..f65b99cf 100644 --- a/include/gui/treeview.h +++ b/include/gui/treeview.h @@ -17,6 +17,9 @@ void gui_treeview_set_playlist(struct playlist *); /* Called to scroll the treeview to the current track. */ void gui_treeview_scroll(); +/* Called to select a path from (x, y) screen coodinates. */ +void gui_treeview_select_path_at_pos(unsigned int x, unsigned int y); + /* * Called to get a list of selected tracks. * NOTE: The caller is responsible for freeing the list with g_list_free().