From 3bf99b12ebaec1f5a458f265b5f2487566282839 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Sat, 3 Sep 2016 12:49:15 -0400 Subject: [PATCH] gui/playlist: Respond to right-clicking the main treeview Signed-off-by: Anna Schumaker --- gui/playlist.c | 49 +++++++++++++++++++++++++++++++ gui/view.c | 2 +- include/gui/playlist.h | 14 +++++++++ share/ocarina/ocarina.ui | 63 +++++++++++++++++++++++++--------------- 4 files changed, 103 insertions(+), 25 deletions(-) diff --git a/gui/playlist.c b/gui/playlist.c index bf829cad..65d6e8c8 100644 --- a/gui/playlist.c +++ b/gui/playlist.c @@ -134,6 +134,11 @@ void __gui_playlist_add_user(GtkMenuItem *item, gpointer data) __gui_playlist_add_selected_to(gui_pl_user_add_dialog()); } +void __gui_playlist_add_other(GtkMenuItem *item, gpointer data) +{ + __gui_playlist_add_selected_to(data); +} + void __gui_playlist_add_queued(GtkMenuItem *item, gpointer data) { __gui_playlist_add_selected_to(playlist_get(PL_SYSTEM, "Queued Tracks")); @@ -181,6 +186,50 @@ void __gui_playlist_keypress(GtkTreeView *treeview, GdkEventKey *event, } } +static GtkWidget *__gui_playlist_build_submenu(void) +{ + struct playlist *playlist; + GList *list = gui_pl_user_list(); + GList *cur = g_list_first(list); + GtkWidget *submenu, *item; + + if (!list) + return NULL; + + submenu = gtk_menu_new(); + while (cur) { + playlist = (struct playlist *)cur->data; + item = gtk_menu_item_new_with_label(playlist->pl_name); + gtk_menu_shell_append(GTK_MENU_SHELL(submenu), item); + g_signal_connect(item, "activate", + G_CALLBACK(__gui_playlist_add_other), + playlist); + cur = g_list_next(cur); + } + + gtk_widget_show_all(submenu); + g_list_free(list); + return submenu; +} + +bool __gui_playlist_button_press(GtkTreeView *treeview, GdkEventButton *event, + gpointer data) +{ + GtkWidget *submenu; + + if (event->button != GDK_BUTTON_SECONDARY) + return false; + + submenu = __gui_playlist_build_submenu(); + gtk_menu_item_set_submenu(gui_rc_add_to_other(), submenu); + gtk_widget_set_visible(GTK_WIDGET(gui_rc_add_to_other()), + submenu != NULL); + + gui_treeview_select_path_at_pos(event->x, event->y); + gtk_menu_popup_at_pointer(gui_rc_menu(), (GdkEvent *)event); + return true; +} + void __gui_playlist_row_activated(GtkTreeView *treeview, GtkTreePath *path, GtkTreeViewColumn *col, gpointer data) { diff --git a/gui/view.c b/gui/view.c index 460edd8e..784b3020 100644 --- a/gui/view.c +++ b/gui/view.c @@ -171,7 +171,7 @@ static GtkWidget *__view_rc_build_submenu(void) bool __view_button_press(GtkTreeView *treeview, GdkEventButton *event, gpointer data) { - GtkMenu *menu = GTK_MENU(gui_builder_widget("o_menu")); + GtkMenu *menu = GTK_MENU(gui_builder_widget("rc_menu")); GtkWidget *submenu = NULL; GtkMenuItem *other; diff --git a/include/gui/playlist.h b/include/gui/playlist.h index f835f4bc..6cf1c4aa 100644 --- a/include/gui/playlist.h +++ b/include/gui/playlist.h @@ -4,6 +4,7 @@ #ifndef OCARINA_GUI_PLAYLIST_H #define OCARINA_GUI_PLAYLIST_H #include +#include #include #include #include @@ -12,7 +13,20 @@ /* Called to initialize the GUI playlist code. */ void gui_playlist_init(); +/* Called to access the right-click menu. */ +static inline GtkMenu *gui_rc_menu() +{ + return GTK_MENU(gui_builder_widget("rc_menu")); +} + +/* Called to acces the "Add to Other Playlist" menu item. */ +static inline GtkMenuItem *gui_rc_add_to_other() +{ + return GTK_MENU_ITEM(gui_builder_widget("rc_add_to_other")); +} + /* Playlist operations passed to core_init() */ extern struct queue_ops playlist_ops; + #endif /* OCARINA_GUI_PLAYLIST_H */ diff --git a/share/ocarina/ocarina.ui b/share/ocarina/ocarina.ui index f984cd67..7e88b91d 100644 --- a/share/ocarina/ocarina.ui +++ b/share/ocarina/ocarina.ui @@ -30,9 +30,44 @@ False document-new - + True False + audio-x-generic + + + True + False + + + Add to Queued Tracks + True + False + image24 + False + + + + + + Add to Favorites + True + False + image20 + False + + + + + + Add to Hidden + True + False + image19 + False + + + Add to New Playlist @@ -40,31 +75,11 @@ False image23 False - + - - Add to Favorites - True - False - image20 - False - - - - - - Add to Hidden - True - False - image19 - False - - - - - + Add to Other Playlist True False @@ -886,7 +901,7 @@ audio-volume-medium True True 9 - +