From e575d2582c893edffdd4f5559f7c1fe3516d2635 Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Sat, 6 Sep 2014 14:16:31 +0200 Subject: [PATCH] actions: attempt to crop playlists only if their length is > 1 --- src/actions.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/actions.cpp b/src/actions.cpp index 1dc2454..b657108 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -1728,17 +1728,19 @@ void AddSelectedItems::run() void CropMainPlaylist::run() { + auto &w = myPlaylist->main(); + // cropping doesn't make sense in this case + if (w.size() <= 1) + return; bool yes = true; if (Config.ask_before_clearing_playlists) yes = askYesNoQuestion("Do you really want to crop main playlist?", Status::trace); if (yes) { Statusbar::print("Cropping playlist..."); - auto &w = myPlaylist->main(); - // if no item is selected, select the current one - if (!w.empty() && !hasSelected(w.begin(), w.end())) - w.current().setSelected(true); + selectCurrentIfNoneSelected(w); cropPlaylist(w, boost::bind(&MPD::Connection::Delete, _1, _2)); + Statusbar::print("Playlist cropped"); } } @@ -1749,6 +1751,10 @@ bool CropPlaylist::canBeRun() const void CropPlaylist::run() { + auto &w = myPlaylistEditor->Content; + // cropping doesn't make sense in this case + if (w.size() <= 1) + return; assert(!myPlaylistEditor->Playlists.empty()); std::string playlist = myPlaylistEditor->Playlists.current().value(); bool yes = true; @@ -1759,9 +1765,9 @@ void CropPlaylist::run() ); if (yes) { - auto delete_fun = boost::bind(&MPD::Connection::PlaylistDelete, _1, playlist, _2); + selectCurrentIfNoneSelected(w); Statusbar::printf("Cropping playlist \"%1%\"...", playlist); - cropPlaylist(myPlaylistEditor->Content, delete_fun); + cropPlaylist(w, boost::bind(&MPD::Connection::PlaylistDelete, _1, playlist, _2)); Statusbar::printf("Playlist \"%1%\" cropped", playlist); } } -- 2.11.4.GIT