Reorder playlists
The user can drag-and-drop tabs to change their order in the libsaria playlist deck. Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
parent
b125fa2595
commit
9365881cb4
|
@ -30,6 +30,7 @@ namespace libsaria
|
|||
unsigned int move_playlist(Playlist *, unsigned int);
|
||||
|
||||
Playlist *get_playlist(unsigned int);
|
||||
int get_playlist_index(Playlist *);
|
||||
Playlist *get_recent_plist();
|
||||
|
||||
void list_recent(Track *);
|
||||
|
|
|
@ -23,7 +23,7 @@ static void renumber_playlists()
|
|||
int n = 0;
|
||||
|
||||
for (it = playlist_deck.begin(); it != playlist_deck.end(); it++)
|
||||
(*it)->renumber(n++);
|
||||
(*it)->renumber(n++);
|
||||
}
|
||||
|
||||
static libsaria::Playlist *get_active_playlist()
|
||||
|
@ -197,6 +197,18 @@ namespace libsaria
|
|||
return *it;
|
||||
}
|
||||
|
||||
int deck::get_playlist_index(Playlist *plist)
|
||||
{
|
||||
list<libsaria::Playlist *>::iterator it;
|
||||
int n = 0;
|
||||
for (it = playlist_deck.begin(); it != playlist_deck.end(); it++) {
|
||||
if ((*it) == plist)
|
||||
return n;
|
||||
n++;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void deck::track_removed(Track *track)
|
||||
{
|
||||
list<Playlist *>::iterator it;
|
||||
|
|
|
@ -1,61 +0,0 @@
|
|||
// Copyright (c) 2012 Bryan Schumaker
|
||||
#include <ocarina/ocarina.h>
|
||||
|
||||
#include <libsaria/libsaria.h>
|
||||
#include <libsaria/deck.h>
|
||||
|
||||
#include <map>
|
||||
using namespace std;
|
||||
|
||||
//static GtkWidget *tabs;
|
||||
static map<GtkWidget *, libsaria::Playlist *> tab_mapping;
|
||||
|
||||
/*static void on_page_reordered(GtkWidget *t, GtkWidget *page, guint num, gpointer d)
|
||||
{
|
||||
libsaria::Playlist *plist = tab_mapping[page];
|
||||
unsigned int n = libsaria::deck::move_playlist(plist, num);
|
||||
if (n != num)
|
||||
gtk_notebook_reorder_child(GTK_NOTEBOOK(tabs), page, n);
|
||||
}*/
|
||||
|
||||
namespace ocarina
|
||||
{
|
||||
|
||||
/*GtkWidget *body::playlist_init()
|
||||
{
|
||||
tabs = gtk_notebook_new();
|
||||
|
||||
gtk_notebook_set_scrollable(GTK_NOTEBOOK(tabs), true);
|
||||
gtk_notebook_set_tab_pos(GTK_NOTEBOOK(tabs), GTK_POS_LEFT);
|
||||
g_signal_connect(tabs, "page-reordered", G_CALLBACK(on_page_reordered), NULL);
|
||||
g_object_set(tabs, "tab-border", 0, NULL);
|
||||
|
||||
gtk_widget_show(tabs);
|
||||
|
||||
return tabs;
|
||||
};
|
||||
|
||||
void body::add_page(int pg, GtkWidget *page, GtkWidget *label, libsaria::Playlist *p)
|
||||
{
|
||||
if (pg == -1)
|
||||
pg = 0;
|
||||
gtk_notebook_insert_page(GTK_NOTEBOOK(tabs), page, label, pg);
|
||||
gtk_notebook_set_tab_reorderable(GTK_NOTEBOOK(tabs), page, !p->is_static());
|
||||
tab_mapping[page] = p;
|
||||
}
|
||||
|
||||
void body::remove_page(GtkWidget *page)
|
||||
{
|
||||
int pg = gtk_notebook_page_num(GTK_NOTEBOOK(tabs), page);
|
||||
gtk_notebook_remove_page(GTK_NOTEBOOK(tabs), pg);
|
||||
tab_mapping.erase(page);
|
||||
}
|
||||
|
||||
void body::switch_to_page(GtkWidget *page)
|
||||
{
|
||||
int pg = gtk_notebook_page_num(GTK_NOTEBOOK(tabs), page);
|
||||
println("Switching to page: %d", pg);
|
||||
gtk_notebook_set_current_page(GTK_NOTEBOOK(tabs), pg);
|
||||
}*/
|
||||
|
||||
}; /* Namespace: ocarina */
|
|
@ -16,6 +16,16 @@ static PlaylistWidgets recent_widgets;
|
|||
static PlaylistWidgets banned_widgets;
|
||||
static list<struct PlaylistWidgets *> dynamic_widgets;
|
||||
|
||||
struct PlaylistWidgets *find_page_widgets(GtkWidget *page)
|
||||
{
|
||||
list<struct PlaylistWidgets *>::iterator it;
|
||||
for (it = dynamic_widgets.begin(); it != dynamic_widgets.end(); it++) {
|
||||
if (GTK_WIDGET((*it)->page_box) == page)
|
||||
return *it;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct PlaylistWidgets *find_playlist_widgets(libsaria::Playlist *plist)
|
||||
{
|
||||
list<struct PlaylistWidgets *>::iterator it;
|
||||
|
@ -104,6 +114,14 @@ static void on_switch_page(GtkNotebook *tabs, gpointer page,
|
|||
update_length_label();
|
||||
}
|
||||
|
||||
static void on_page_reordered(GtkWidget *notebook, GtkWidget *page, guint num, gpointer d)
|
||||
{
|
||||
struct PlaylistWidgets *widgets = find_page_widgets(page);
|
||||
unsigned int n = libsaria::deck::move_playlist(widgets->playlist, num);
|
||||
if (n != num)
|
||||
gtk_notebook_reorder_child(tabs, page, n);
|
||||
}
|
||||
|
||||
static void on_click_open(GtkWidget *b, gpointer d)
|
||||
{
|
||||
string file = run_chooser("FileChooser");
|
||||
|
@ -175,6 +193,7 @@ void init_tabs()
|
|||
add_static_page("Banned", &banned_widgets, libsaria::ban::get_banned_plist());
|
||||
|
||||
connect_signal("PlaylistTabs", "switch-page", G_CALLBACK(on_switch_page), NULL);
|
||||
connect_signal("PlaylistTabs", "page-reordered", G_CALLBACK(on_page_reordered), NULL);
|
||||
}
|
||||
|
||||
static void new_playlist(libsaria::Playlist *playlist)
|
||||
|
@ -183,7 +202,10 @@ static void new_playlist(libsaria::Playlist *playlist)
|
|||
dynamic_widgets.push_back(widgets);
|
||||
|
||||
init_widgets(widgets, playlist);
|
||||
add_page(GTK_WIDGET(widgets->page_box), make_tab_label(playlist->get_name(), widgets), 0);
|
||||
add_page(GTK_WIDGET(widgets->page_box),
|
||||
make_tab_label(playlist->get_name(), widgets),
|
||||
libsaria::deck::get_playlist_index(playlist));
|
||||
gtk_notebook_set_tab_reorderable(tabs, GTK_WIDGET(widgets->page_box), true);
|
||||
}
|
||||
|
||||
static void delete_playlist(libsaria::Playlist *playlist)
|
||||
|
|
Loading…
Reference in New Issue