gui/view: Create a menu item for adding tracks to user playlists
This has to be created programmatically due to the dynamic nature of user playlists. The easiest way to do that is to list user playlists in a submenu and switch them out as needed. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
ecebd20a0b
commit
ddb564ed82
52
gui/view.c
52
gui/view.c
|
@ -177,7 +177,7 @@ void __view_column_clicked(GtkTreeViewColumn *col, gpointer data)
|
|||
|
||||
struct view_add_data {
|
||||
enum playlist_type_t vad_type;
|
||||
gchar *vad_name;
|
||||
const gchar *vad_name;
|
||||
};
|
||||
|
||||
static void __view_add_to_playlist(GtkTreeModel *model, GtkTreePath *path,
|
||||
|
@ -310,14 +310,51 @@ void __view_rc_add_new(GtkMenuItem *item, gpointer data)
|
|||
__view_process_selection(view_treeview, GDK_KEY_p);
|
||||
}
|
||||
|
||||
static void __view_rc_add_other(GtkWidget *item, gpointer data)
|
||||
{
|
||||
GtkTreeView *treeview = GTK_TREE_VIEW(gui_builder_widget("o_treeview"));
|
||||
GtkTreeSelection *selection = gtk_tree_view_get_selection(treeview);
|
||||
struct playlist *playlist = (struct playlist *)data;
|
||||
struct view_add_data vad_data = {
|
||||
.vad_type = PL_USER,
|
||||
.vad_name = playlist->pl_name,
|
||||
};
|
||||
|
||||
gtk_tree_selection_selected_foreach(selection,
|
||||
__view_add_to_playlist,
|
||||
&vad_data);
|
||||
}
|
||||
|
||||
static GtkWidget *__view_rc_build_submenu(void)
|
||||
{
|
||||
struct db_entry *dbe, *next;
|
||||
struct playlist *playlist;
|
||||
GtkWidget *submenu, *item;
|
||||
|
||||
if (pl_user_db_get()->db_size == 0)
|
||||
return NULL;
|
||||
|
||||
submenu = gtk_menu_new();
|
||||
db_for_each(dbe, next, pl_user_db_get()) {
|
||||
playlist = &USER_PLAYLIST(dbe)->pl_playlist;
|
||||
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(__view_rc_add_other), playlist);
|
||||
}
|
||||
|
||||
return submenu;
|
||||
}
|
||||
|
||||
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 != 3)
|
||||
if (event->button != GDK_BUTTON_SECONDARY)
|
||||
return false;
|
||||
|
||||
/* Select path if it isn't already selected */
|
||||
|
@ -328,7 +365,16 @@ bool __view_button_press(GtkTreeView *treeview, GdkEventButton *event,
|
|||
gtk_tree_path_free(path);
|
||||
}
|
||||
|
||||
/* Determine which menu items can be shown */
|
||||
/* Set the "Other Playlists" submenu. */
|
||||
other = GTK_MENU_ITEM(gui_builder_widget("o_add_to_other"));
|
||||
submenu = __view_rc_build_submenu();
|
||||
gtk_menu_item_set_submenu(other, submenu);
|
||||
|
||||
if (!submenu)
|
||||
gtk_widget_hide(GTK_WIDGET(other));
|
||||
else
|
||||
gtk_widget_show_all(GTK_WIDGET(other));
|
||||
|
||||
gtk_menu_popup(menu, NULL, NULL, NULL, NULL, event->button, event->time);
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -2,6 +2,11 @@
|
|||
<!-- Generated with glade 3.20.0 -->
|
||||
<interface>
|
||||
<requires lib="gtk+" version="3.16"/>
|
||||
<object class="GtkImage" id="image">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="icon_name">text-x-generic</property>
|
||||
</object>
|
||||
<object class="GtkImage" id="image10">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
|
@ -94,9 +99,12 @@
|
|||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkSeparatorMenuItem">
|
||||
<object class="GtkImageMenuItem" id="o_add_to_other">
|
||||
<property name="label" translatable="yes">Add to Other Playlist</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="image">image</property>
|
||||
<property name="use_stock">False</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
|
|
Loading…
Reference in New Issue