From 195d8b4e34ba495266e55a53d0755fc37c09db2b Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Mon, 24 Aug 2009 00:36:37 +0200 Subject: [PATCH] ask if one really wants to clear main playlist (disabled by default) --- doc/config | 2 ++ doc/ncmpcpp.1 | 3 +++ src/ncmpcpp.cpp | 57 +++++++++++++++++++++++++++--------------------- src/settings.cpp | 5 +++++ src/settings.h | 1 + 5 files changed, 43 insertions(+), 25 deletions(-) diff --git a/doc/config b/doc/config index cfbace71..458b3716 100644 --- a/doc/config +++ b/doc/config @@ -197,6 +197,8 @@ # #display_screens_numbers_on_start = "yes" # +#ask_before_clearing_main_playlist = "no" +# #clock_display_seconds = "no" # #regular_expressions = "basic" (basic/extended) diff --git a/doc/ncmpcpp.1 b/doc/ncmpcpp.1 index 9db900cb..ac9a7111 100644 --- a/doc/ncmpcpp.1 +++ b/doc/ncmpcpp.1 @@ -186,6 +186,9 @@ If set to "playlist", Search engine will perform searching in current MPD playli .B display_screens_numbers_on_start = yes/no If enabled, screens' names and their keybindings will be shown in header window until key is pressed, otherwise they won't be displayed at all. .TP +.B ask_before_clearing_main_playlist = yes/no +If enabled, user will be asked if he really wants to clear the main playlist after pressing key responsible for that. +.TP .B clock_display_seconds = yes/no If enabled, clock will display time in format hh:mm:ss, otherwise hh:mm. .TP diff --git a/src/ncmpcpp.cpp b/src/ncmpcpp.cpp index 836d38f6..0417e812 100644 --- a/src/ncmpcpp.cpp +++ b/src/ncmpcpp.cpp @@ -1694,6 +1694,35 @@ int main(int argc, char *argv[]) } else if (Keypressed(input, Key.Clear)) { + if (myScreen == myPlaylistEditor && myPlaylistEditor->Playlists->Empty()) + continue; + + if (myScreen->ActiveWindow() == myPlaylistEditor->Content + || Config.ask_before_clearing_main_playlist) + { + int in = 0; + LockStatusbar(); + Statusbar() << "Do you really want to clear playlist"; + if (myScreen->ActiveWindow() == myPlaylistEditor->Content) + *wFooter << " \"" << myPlaylistEditor->Playlists->Current() << "\""; + *wFooter << " ? [y/n] "; + curs_set(1); + do + { + TraceMpdStatus(); + wFooter->ReadKey(in); + } + while (in != 'y' && in != 'n'); + curs_set(0); + UnlockStatusbar(); + + if (in != 'y') + { + ShowMessage("Aborted!"); + continue; + } + } + if (myPlaylist->Main()->isFiltered()) { ShowMessage("Deleting filtered items..."); @@ -1705,38 +1734,16 @@ int main(int argc, char *argv[]) } else { - if (myScreen == myPlaylistEditor && myPlaylistEditor->Playlists->Empty()) - continue; - int in = 0; - if (myScreen == myPlaylistEditor) + if (myScreen->ActiveWindow() == myPlaylistEditor->Content) { - LockStatusbar(); - Statusbar() << "Do you really want to clear playlist \"" << myPlaylistEditor->Playlists->Current() << "\" ? [y/n] "; - curs_set(1); - do - { - TraceMpdStatus(); - wFooter->ReadKey(in); - } - while (in != 'y' && in != 'n'); - curs_set(0); - UnlockStatusbar(); - - if (in == 'y') - { - Mpd.ClearPlaylist(locale_to_utf_cpy(myPlaylistEditor->Playlists->Current())); - myPlaylistEditor->Content->Clear(0); - } - else - ShowMessage("Aborted!"); + Mpd.ClearPlaylist(locale_to_utf_cpy(myPlaylistEditor->Playlists->Current())); + myPlaylistEditor->Content->Clear(0); } else { ShowMessage("Clearing playlist..."); Mpd.ClearPlaylist(); } - if (myScreen != myPlaylistEditor || in == 'y') - ShowMessage("Playlist cleared!"); } // if playlist is cleared, items list have to be updated, but this // can be blocked if new song was added to playlist less than one diff --git a/src/settings.cpp b/src/settings.cpp index f229433a..eaa99c3e 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -295,6 +295,7 @@ void DefaultConfiguration(ncmpcpp_config &conf) conf.use_cyclic_scrolling = false; conf.allow_physical_files_deletion = false; conf.allow_physical_directories_deletion = false; + conf.ask_before_clearing_main_playlist = false; conf.mouse_support = true; conf.new_design = false; conf.set_window_title = true; @@ -742,6 +743,10 @@ void ReadConfiguration(ncmpcpp_config &conf) { conf.allow_physical_directories_deletion = v == "yes"; } + else if (cl.find("ask_before_clearing_main_playlist") != std::string::npos) + { + conf.ask_before_clearing_main_playlist = v == "yes"; + } else if (cl.find("mouse_support") != std::string::npos) { conf.mouse_support = v == "yes"; diff --git a/src/settings.h b/src/settings.h index 4c1e5c53..f4813d34 100644 --- a/src/settings.h +++ b/src/settings.h @@ -190,6 +190,7 @@ struct ncmpcpp_config bool use_cyclic_scrolling; bool allow_physical_files_deletion; bool allow_physical_directories_deletion; + bool ask_before_clearing_main_playlist; bool mouse_support; bool new_design;