gui/playlist: Respond to right-clicking the main treeview

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2016-09-03 12:49:15 -04:00
parent e660e3f0b2
commit 3bf99b12eb
4 changed files with 103 additions and 25 deletions

View File

@ -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)
{

View File

@ -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;

View File

@ -4,6 +4,7 @@
#ifndef OCARINA_GUI_PLAYLIST_H
#define OCARINA_GUI_PLAYLIST_H
#include <core/playlist.h>
#include <gui/builder.h>
#include <gui/playlists/artist.h>
#include <gui/playlists/library.h>
#include <gui/playlists/system.h>
@ -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 */

View File

@ -30,9 +30,44 @@
<property name="can_focus">False</property>
<property name="icon_name">document-new</property>
</object>
<object class="GtkMenu" id="o_menu">
<object class="GtkImage" id="image24">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">audio-x-generic</property>
</object>
<object class="GtkMenu" id="rc_menu">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkImageMenuItem">
<property name="label" translatable="yes">Add to Queued Tracks</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="image">image24</property>
<property name="use_stock">False</property>
<signal name="activate" handler="__gui_playlist_add_queued" swapped="no"/>
</object>
</child>
<child>
<object class="GtkImageMenuItem">
<property name="label" translatable="yes">Add to Favorites</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="image">image20</property>
<property name="use_stock">False</property>
<signal name="activate" handler="__gui_playlist_add_favorites" swapped="no"/>
</object>
</child>
<child>
<object class="GtkImageMenuItem">
<property name="label" translatable="yes">Add to Hidden</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="image">image19</property>
<property name="use_stock">False</property>
<signal name="activate" handler="__gui_playlist_add_hidden" swapped="no"/>
</object>
</child>
<child>
<object class="GtkImageMenuItem">
<property name="label" translatable="yes">Add to New Playlist</property>
@ -40,31 +75,11 @@
<property name="can_focus">False</property>
<property name="image">image23</property>
<property name="use_stock">False</property>
<signal name="activate" handler="__view_rc_add_new" swapped="no"/>
<signal name="activate" handler="__gui_playlist_add_user" swapped="no"/>
</object>
</child>
<child>
<object class="GtkImageMenuItem" id="o_add_to_favorites">
<property name="label" translatable="yes">Add to Favorites</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="image">image20</property>
<property name="use_stock">False</property>
<signal name="activate" handler="__view_rc_add_favorites" swapped="no"/>
</object>
</child>
<child>
<object class="GtkImageMenuItem" id="o_add_to_hidden">
<property name="label" translatable="yes">Add to Hidden</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="image">image19</property>
<property name="use_stock">False</property>
<signal name="activate" handler="__view_rc_add_hidden" swapped="no"/>
</object>
</child>
<child>
<object class="GtkImageMenuItem" id="o_add_to_other">
<object class="GtkImageMenuItem" id="rc_add_to_other">
<property name="label" translatable="yes">Add to Other Playlist</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
@ -886,7 +901,7 @@ audio-volume-medium</property>
<property name="fixed_height_mode">True</property>
<property name="rubber_banding">True</property>
<property name="tooltip_column">9</property>
<signal name="button-press-event" handler="__view_button_press" swapped="no"/>
<signal name="button-press-event" handler="__gui_playlist_button_press" swapped="no"/>
<signal name="key-press-event" handler="__gui_playlist_keypress" swapped="no"/>
<signal name="row-activated" handler="__gui_treeview_row_activated" swapped="no"/>
<child internal-child="selection">