Add a close button to temporary playlists
I put it on the tab page this time, instead of in the tab label. I don't want wide tab labels, so I should eventually come up with a way of closing playlists without having to change tabs. Maybe a right-click menu? I also noticed that the libsaria delete_playlist() code didn't work, so I simplified it a bit. Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
parent
e57b2891e6
commit
3bb8053ea2
|
@ -10,6 +10,11 @@
|
|||
#include <string>
|
||||
using namespace std;
|
||||
|
||||
enum ExtraWidgets {
|
||||
NO_EXTRA_WIDGETS = 0,
|
||||
CLOSE_BUTTON = (1 << 0),
|
||||
};
|
||||
|
||||
struct PlaylistWidgets {
|
||||
libsaria::Playlist *playlist;
|
||||
GtkListStore *liststore;
|
||||
|
@ -39,7 +44,7 @@ string run_chooser(const string &);
|
|||
/* playlist.cpp */
|
||||
void update_playlist(notify_t, libsaria::PlaylistNotification *);
|
||||
void setup_widgets(struct PlaylistWidgets *, libsaria::Playlist *);
|
||||
void setup_playlist_page(struct PlaylistWidgets *);
|
||||
void setup_playlist_page(struct PlaylistWidgets *, int);
|
||||
|
||||
/* status.cpp */
|
||||
bool update_idle_bar(int);
|
||||
|
|
|
@ -136,13 +136,9 @@ namespace libsaria
|
|||
|
||||
void deck::delete_playlist(Playlist *plist)
|
||||
{
|
||||
list<libsaria::Playlist *>::iterator it;
|
||||
for (it = playlist_deck.begin(); (*it) != plist; it++);
|
||||
|
||||
plist->prepare_for_removal();
|
||||
delete plist;
|
||||
|
||||
playlist_deck.erase(it);
|
||||
notify(PLAYLIST_DELETE, plist);
|
||||
playlist_deck.remove(plist);
|
||||
garbage_collect();
|
||||
}
|
||||
|
||||
|
|
|
@ -243,6 +243,12 @@ static gboolean entry_keypress(GtkEntry *entry, GdkEvent *event, gpointer data)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
static void playlist_close(GtkWidget *button, gpointer data)
|
||||
{
|
||||
struct libsaria::Playlist *playlist = (libsaria::Playlist *)data;
|
||||
libsaria::deck::delete_playlist(playlist);
|
||||
}
|
||||
|
||||
void setup_widgets(struct PlaylistWidgets *widgets, libsaria::Playlist *playlist)
|
||||
{
|
||||
unsigned int num_columns = sizeof(types) / sizeof(GType);
|
||||
|
@ -275,6 +281,27 @@ void setup_widgets(struct PlaylistWidgets *widgets, libsaria::Playlist *playlist
|
|||
g_signal_connect(widgets->entry, "key-press-event", G_CALLBACK(entry_keypress), widgets);
|
||||
}
|
||||
|
||||
static GtkWidget *setup_close_button(struct PlaylistWidgets *widgets)
|
||||
{
|
||||
GtkWidget *close = gtk_button_new();
|
||||
GtkWidget *image = gtk_image_new_from_stock(GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU);
|
||||
|
||||
gtk_button_set_image(GTK_BUTTON(close), image);
|
||||
gtk_button_set_relief(GTK_BUTTON(close), GTK_RELIEF_NONE);
|
||||
|
||||
gtk_rc_parse_string(
|
||||
"style \"close-button-style\"\n"
|
||||
"{\n"
|
||||
" GtkButton::inner-border = {0,0,0,0}\n"
|
||||
"}\n"
|
||||
"widget \"*.ocarina-close-button\" style \"close-button-style\"");
|
||||
gtk_widget_set_name(close, "ocarina-close-button");
|
||||
|
||||
g_signal_connect(close, "clicked", G_CALLBACK(playlist_close), widgets->playlist);
|
||||
|
||||
return close;
|
||||
}
|
||||
|
||||
static void add_column(GtkTreeView *treeview, const string &title, int index,
|
||||
GtkTreeViewColumnSizing sizing, unsigned int fixed_width)
|
||||
{
|
||||
|
@ -289,15 +316,20 @@ static void add_column(GtkTreeView *treeview, const string &title, int index,
|
|||
gtk_tree_view_append_column(treeview, column);
|
||||
}
|
||||
|
||||
void setup_playlist_page(struct PlaylistWidgets *widgets)
|
||||
void setup_playlist_page(struct PlaylistWidgets *widgets, int flags)
|
||||
{
|
||||
GtkWidget *top_box = gtk_hbox_new(FALSE, 0);
|
||||
GtkWidget *window = gtk_scrolled_window_new(NULL, NULL);
|
||||
|
||||
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(window),
|
||||
GTK_POLICY_AUTOMATIC,
|
||||
GTK_POLICY_AUTOMATIC);
|
||||
|
||||
gtk_box_pack_start(widgets->page_box, GTK_WIDGET(widgets->entry), FALSE, FALSE, 0);
|
||||
if (flags & CLOSE_BUTTON)
|
||||
gtk_box_pack_start(GTK_BOX(top_box), setup_close_button(widgets), FALSE, FALSE, 0);
|
||||
gtk_box_pack_start(GTK_BOX(top_box), GTK_WIDGET(widgets->entry), TRUE, TRUE, 0);
|
||||
|
||||
gtk_box_pack_start(widgets->page_box, top_box, FALSE, FALSE, 0);
|
||||
gtk_box_pack_start(widgets->page_box, window, TRUE, TRUE, 0);
|
||||
|
||||
gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(widgets->treeview));
|
||||
|
|
|
@ -187,16 +187,17 @@ static GtkWidget *make_tab_label(const string &name, struct PlaylistWidgets *wid
|
|||
return tab;
|
||||
}
|
||||
|
||||
static void init_widgets(struct PlaylistWidgets *widgets, libsaria::Playlist *playlist)
|
||||
static void init_widgets(struct PlaylistWidgets *widgets, libsaria::Playlist *playlist,
|
||||
int flags)
|
||||
{
|
||||
setup_widgets(widgets, playlist);
|
||||
setup_playlist_page(widgets);
|
||||
setup_playlist_page(widgets, flags);
|
||||
}
|
||||
|
||||
static void add_static_page(const string &name, struct PlaylistWidgets *widgets,
|
||||
libsaria::Playlist *playlist)
|
||||
{
|
||||
init_widgets(widgets, playlist);
|
||||
init_widgets(widgets, playlist, NO_EXTRA_WIDGETS);
|
||||
add_page(GTK_WIDGET(widgets->page_box), make_tab_label(name, widgets), -1);
|
||||
}
|
||||
|
||||
|
@ -218,7 +219,7 @@ static void new_playlist(libsaria::Playlist *playlist)
|
|||
struct PlaylistWidgets *widgets = new struct PlaylistWidgets;
|
||||
dynamic_widgets.push_back(widgets);
|
||||
|
||||
init_widgets(widgets, playlist);
|
||||
init_widgets(widgets, playlist, CLOSE_BUTTON);
|
||||
add_page(GTK_WIDGET(widgets->page_box),
|
||||
make_tab_label(playlist->get_name(), widgets),
|
||||
libsaria::deck::get_playlist_index(playlist));
|
||||
|
|
Loading…
Reference in New Issue