From 463409acdfe7627979f024dd3a95c10f2b760b60 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Fri, 28 Feb 2014 20:07:59 -0500 Subject: [PATCH] gui: Playlists respond to the delete key This key is used to remove tracks from a playlist. Signed-off-by: Anna Schumaker --- gui/playlist.cpp | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/gui/playlist.cpp b/gui/playlist.cpp index d7e9b06d..9f9d4500 100644 --- a/gui/playlist.cpp +++ b/gui/playlist.cpp @@ -5,6 +5,8 @@ #include +static const std::string current_playlist(); + /** * Playlist tab stuff */ @@ -13,6 +15,7 @@ class PlaylistTab : public Tab { public: PlaylistTab(); ~PlaylistTab(); + bool on_key_press_event(const std::string &); }; @@ -31,6 +34,19 @@ PlaylistTab :: ~PlaylistTab() tab_unmap(); } +bool PlaylistTab :: on_key_press_event(const std::string &key) +{ + std::vector ids; + + if (key != "Delete") + return Tab :: on_key_press_event(key); + + tab_selected_ids(ids); + for (unsigned int i = 0; i < ids.size(); i++) + playlist :: del(current_playlist(), ids[i]); + return true; +} + /** @@ -48,8 +64,7 @@ public: static Glib::RefPtr playlist_ls; static Gtk::TreeView *playlist_tv; - -static void on_playlist_cursor_changed() +static const std::string current_playlist() { Gtk::TreePath path; Gtk::TreeViewColumn *col; @@ -57,7 +72,13 @@ static void on_playlist_cursor_changed() Gtk::TreeModel::Row row = *(playlist_ls->get_iter(path)); std::string res = row[plist_cols.plist_col_name]; - playlist::select(res); + return res; +} + + +static void on_playlist_cursor_changed() +{ + playlist::select(current_playlist()); } static bool on_playlist_clicked(GdkEventButton *button)