diff options
-rw-r--r-- | doc/bindings | 5 | ||||
-rw-r--r-- | src/actions.cpp | 171 | ||||
-rw-r--r-- | src/actions.h | 25 | ||||
-rw-r--r-- | src/bindings.cpp | 10 | ||||
-rw-r--r-- | src/browser.cpp | 8 | ||||
-rw-r--r-- | src/help.cpp | 6 |
6 files changed, 137 insertions, 88 deletions
diff --git a/doc/bindings b/doc/bindings index d6c231cf..5c79c4f3 100644 --- a/doc/bindings +++ b/doc/bindings @@ -144,7 +144,10 @@ # press_enter # #def_key "delete" -# delete +# delete_playlist_items +# +#def_key "delete" +# delete_stored_playlist # #def_key "right" # next_column diff --git a/src/actions.cpp b/src/actions.cpp index e62dca58..2871814b 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -781,101 +781,116 @@ void VolumeDown::Run() Mpd.SetVolume(Mpd.GetVolume()-1); } -void Delete::Run() +bool DeletePlaylistItems::canBeRun() const { - if (myScreen == myPlaylist && !myPlaylist->main().empty()) + return (myScreen == myPlaylist && !myPlaylist->main().empty()) + || (myScreen->isActiveWindow(myPlaylistEditor->Content) && !myPlaylistEditor->Content.empty()); +} + +void DeletePlaylistItems::Run() +{ + if (myScreen == myPlaylist) { Statusbar::msg("Deleting items..."); auto delete_fun = std::bind(&MPD::Connection::Delete, _1, _2); if (deleteSelectedSongs(myPlaylist->main(), delete_fun)) Statusbar::msg("Item(s) deleted"); } -# ifndef WIN32 - else if (myScreen == myBrowser && !myBrowser->main().empty()) + else if (myScreen->isActiveWindow(myPlaylistEditor->Content)) { - if (!myBrowser->isLocal() && !isMPDMusicDirSet()) - return; - - std::string question; - if (hasSelected(myBrowser->main().begin(), myBrowser->main().end())) - question = "Delete selected items?"; - else - { - MPD::Item &item = myBrowser->main().current().value(); - std::string name = item.type == MPD::itSong ? item.song->getName() : item.name; - question = "Delete "; - question += itemTypeToString(item.type); - question += " \""; - question += ToString(wideShorten(ToWString(name), COLS-question.size()-10)); - question += "\"?"; - } - bool yes = AskYesNoQuestion(question, Status::trace); - if (yes) - { - bool success = true; - auto list = getSelectedOrCurrent(myBrowser->main().begin(), myBrowser->main().end(), myBrowser->main().currentI()); - for (auto it = list.begin(); it != list.end(); ++it) - { - const MPD::Item &i = (*it)->value(); - std::string name = i.type == MPD::itSong ? i.song->getName() : i.name; - if (myBrowser->deleteItem(i)) - { - const char msg[] = "\"%ls\" deleted"; - Statusbar::msg(msg, wideShorten(ToWString(name), COLS-const_strlen(msg)).c_str()); - } - else - { - const char msg[] = "Couldn't delete \"%ls\": %s"; - Statusbar::msg(msg, wideShorten(ToWString(name), COLS-const_strlen(msg)-25).c_str(), strerror(errno)); - success = false; - break; - } - } - if (success) - { - if (!myBrowser->isLocal()) - Mpd.UpdateDirectory(myBrowser->CurrentDir()); - } - } - else - Statusbar::msg("Aborted"); + std::string playlist = myPlaylistEditor->Playlists.current().value(); + auto delete_fun = std::bind(&MPD::Connection::PlaylistDelete, _1, playlist, _2); + Statusbar::msg("Deleting items..."); + if (deleteSelectedSongs(myPlaylistEditor->Content, delete_fun)) + Statusbar::msg("Item(s) deleted"); } -# endif // !WIN32 - else if (myScreen == myPlaylistEditor && !myPlaylistEditor->Content.empty()) +} + +bool DeleteBrowserItems::canBeRun() const +{ + return myScreen == myBrowser + && !myBrowser->main().empty() + && isMPDMusicDirSet(); +} + +void DeleteBrowserItems::Run() +{ + std::string question; + if (hasSelected(myBrowser->main().begin(), myBrowser->main().end())) + question = "Delete selected items?"; + else { - if (myScreen->isActiveWindow(myPlaylistEditor->Playlists)) + MPD::Item &item = myBrowser->main().current().value(); + std::string name = item.type == MPD::itSong ? item.song->getName() : item.name; + question = "Delete "; + question += itemTypeToString(item.type); + question += " \""; + question += ToString(wideShorten(ToWString(name), COLS-question.size()-10)); + question += "\"?"; + } + bool yes = AskYesNoQuestion(question, Status::trace); + if (yes) + { + bool success = true; + auto list = getSelectedOrCurrent(myBrowser->main().begin(), myBrowser->main().end(), myBrowser->main().currentI()); + for (auto it = list.begin(); it != list.end(); ++it) { - std::string question; - if (hasSelected(myPlaylistEditor->Playlists.begin(), myPlaylistEditor->Playlists.end())) - question = "Delete selected playlists?"; - else + const MPD::Item &i = (*it)->value(); + std::string name = i.type == MPD::itSong ? i.song->getName() : i.name; + if (myBrowser->deleteItem(i)) { - question = "Delete playlist \""; - question += ToString(wideShorten(ToWString(myPlaylistEditor->Playlists.current().value()), COLS-question.size()-10)); - question += "\"?"; + const char msg[] = "\"%ls\" deleted"; + Statusbar::msg(msg, wideShorten(ToWString(name), COLS-const_strlen(msg)).c_str()); } - bool yes = AskYesNoQuestion(question, Status::trace); - if (yes) + else { - auto list = getSelectedOrCurrent(myPlaylistEditor->Playlists.begin(), myPlaylistEditor->Playlists.end(), myPlaylistEditor->Playlists.currentI()); - Mpd.StartCommandsList(); - for (auto it = list.begin(); it != list.end(); ++it) - Mpd.DeletePlaylist((*it)->value()); - if (Mpd.CommitCommandsList()) - Statusbar::msg("Playlist%s deleted", list.size() == 1 ? "" : "s"); + const char msg[] = "Couldn't delete \"%ls\": %s"; + Statusbar::msg(msg, wideShorten(ToWString(name), COLS-const_strlen(msg)-25).c_str(), strerror(errno)); + success = false; + break; } - else - Statusbar::msg("Aborted"); } - else if (myScreen->isActiveWindow(myPlaylistEditor->Content)) + if (success) { - std::string playlist = myPlaylistEditor->Playlists.current().value(); - auto delete_fun = std::bind(&MPD::Connection::PlaylistDelete, _1, playlist, _2); - Statusbar::msg("Deleting items..."); - if (deleteSelectedSongs(myPlaylistEditor->Content, delete_fun)) - Statusbar::msg("Item(s) deleted"); + if (myBrowser->isLocal()) + myBrowser->GetDirectory(myBrowser->CurrentDir()); + else + Mpd.UpdateDirectory(myBrowser->CurrentDir()); } } + else + Statusbar::msg("Aborted"); +} + +bool DeleteStoredPlaylist::canBeRun() const +{ + return myScreen->isActiveWindow(myPlaylistEditor->Playlists) + && myPlaylistEditor->Playlists.empty(); +} + +void DeleteStoredPlaylist::Run() +{ + std::string question; + if (hasSelected(myPlaylistEditor->Playlists.begin(), myPlaylistEditor->Playlists.end())) + question = "Delete selected playlists?"; + else + { + question = "Delete playlist \""; + question += ToString(wideShorten(ToWString(myPlaylistEditor->Playlists.current().value()), COLS-question.size()-10)); + question += "\"?"; + } + bool yes = AskYesNoQuestion(question, Status::trace); + if (yes) + { + auto list = getSelectedOrCurrent(myPlaylistEditor->Playlists.begin(), myPlaylistEditor->Playlists.end(), myPlaylistEditor->Playlists.currentI()); + Mpd.StartCommandsList(); + for (auto it = list.begin(); it != list.end(); ++it) + Mpd.DeletePlaylist((*it)->value()); + if (Mpd.CommitCommandsList()) + Statusbar::msg("Playlist%s deleted", list.size() == 1 ? "" : "s"); + } + else + Statusbar::msg("Aborted"); } void ReplaySong::Run() @@ -2552,7 +2567,9 @@ void populateActions() insertAction(new SlaveScreen()); insertAction(new VolumeUp()); insertAction(new VolumeDown()); - insertAction(new Delete()); + insertAction(new DeletePlaylistItems()); + insertAction(new DeleteStoredPlaylist()); + insertAction(new DeleteBrowserItems()); insertAction(new ReplaySong()); insertAction(new PreviousSong()); insertAction(new NextSong()); diff --git a/src/actions.h b/src/actions.h index a97f3e60..6f3ce64f 100644 --- a/src/actions.h +++ b/src/actions.h @@ -31,7 +31,7 @@ enum ActionType aDummy, aMouseEvent, aScrollUp, aScrollDown, aScrollUpArtist, aScrollUpAlbum, aScrollDownArtist, aScrollDownAlbum, aPageUp, aPageDown, aMoveHome, aMoveEnd, aToggleInterface, aJumpToParentDirectory, aPressEnter, aPressSpace, aPreviousColumn, aNextColumn, aMasterScreen, aSlaveScreen, aVolumeUp, - aVolumeDown, aDelete, aReplaySong, aPrevious, aNext, aPause, aStop, aSavePlaylist, + aVolumeDown, aDeletePlaylistItems, aDeleteStoredPlaylist, aDeleteBrowserItems, aReplaySong, aPrevious, aNext, aPause, aStop, aSavePlaylist, aMoveSortOrderUp, aMoveSortOrderDown, aMoveSelectedItemsUp, aMoveSelectedItemsDown, aMoveSelectedItemsTo, aAdd, aSeekForward, aSeekBackward, aToggleDisplayMode, aToggleSeparatorsBetweenAlbums, aToggleLyricsFetcher, aToggleFetchingLyricsInBackground, aTogglePlayingSongCentering, aUpdateDatabase, @@ -294,11 +294,30 @@ protected: virtual void Run(); }; -struct Delete : public Action +struct DeletePlaylistItems : public Action { - Delete() : Action(aDelete, "delete") { } + DeletePlaylistItems() : Action(aDeletePlaylistItems, "delete_playlist_items") { } protected: + virtual bool canBeRun() const; + virtual void Run(); +}; + +struct DeleteStoredPlaylist : public Action +{ + DeleteStoredPlaylist() : Action(aDeleteStoredPlaylist, "delete_stored_playlist") { } + +protected: + virtual bool canBeRun() const; + virtual void Run(); +}; + +struct DeleteBrowserItems : public Action +{ + DeleteBrowserItems() : Action(aDeleteBrowserItems, "delete_browser_items") { } + +protected: + virtual bool canBeRun() const; virtual void Run(); }; diff --git a/src/bindings.cpp b/src/bindings.cpp index f6e6c592..78ad69cb 100644 --- a/src/bindings.cpp +++ b/src/bindings.cpp @@ -256,6 +256,11 @@ bool BindingsConfiguration::read(const std::string &file) break; } } + else + { + error() << "invalid line: '" << line << "'\n"; + break; + } } if (key_def_in_progress) bind_key_def(); @@ -293,7 +298,10 @@ void BindingsConfiguration::generateDefaults() if (notBound(k = stringToKey("enter"))) bind(k, aPressEnter); if (notBound(k = stringToKey("delete"))) - bind(k, aDelete); + { + bind(k, aDeletePlaylistItems); + bind(k, aDeleteStoredPlaylist); + } if (notBound(k = stringToKey("right"))) { bind(k, aNextColumn); diff --git a/src/browser.cpp b/src/browser.cpp index 95b97fe0..015372e5 100644 --- a/src/browser.cpp +++ b/src/browser.cpp @@ -27,6 +27,7 @@ #include "browser.h" #include "charset.h" #include "display.h" +#include "error.h" #include "global.h" #include "helpers.h" #include "playlist.h" @@ -555,9 +556,8 @@ void Browser::ChangeBrowseMode() bool Browser::deleteItem(const MPD::Item &item) { - // parent dir - if (item.type == itDirectory && item.name == "..") - return false; + if (isParentDirectory((item))) + FatalError("Parent directory passed to Browser::deleteItem"); // playlist created by mpd if (!isLocal() && item.type == itPlaylist && CurrentDir() == "/") @@ -571,7 +571,7 @@ bool Browser::deleteItem(const MPD::Item &item) if (item.type == itDirectory) ClearDirectory(path); - return remove(path.c_str()) == 0; + return std::remove(path.c_str()) == 0; } #endif // !WIN32 diff --git a/src/help.cpp b/src/help.cpp index 2b31b1e4..fe68ad4d 100644 --- a/src/help.cpp +++ b/src/help.cpp @@ -268,7 +268,7 @@ void Help::GetKeybindings() KeysSection("Playlist"); KeyDesc(aPressEnter, "Play selected item"); - KeyDesc(aDelete, "Delete selected item(s) from playlist"); + KeyDesc(aDeletePlaylistItems, "Delete selected item(s) from playlist"); KeyDesc(aClearMainPlaylist, "Clear playlist"); KeyDesc(aCropMainPlaylist, "Clear playlist except selected item(s)"); KeyDesc(aSetSelectedItemsPriority, "Set priority of selected items"); @@ -298,7 +298,7 @@ void Help::GetKeybindings() KeyDesc(aToggleBrowserSortMode, "Toggle sort mode"); KeyDesc(aJumpToPlayingSong, "Locate playing song"); KeyDesc(aJumpToParentDirectory, "Jump to parent directory"); - KeyDesc(aDelete, "Delete item"); + KeyDesc(aDeleteBrowserItems, "Delete selected items from disk"); KeyDesc(aJumpToPlaylistEditor, "Jump to playlist editor (playlists only)"); KeysSection("Search engine"); @@ -333,6 +333,8 @@ void Help::GetKeybindings() KeyDesc(aEditPlaylistName, "Edit playlist name"); KeyDesc(aMoveSelectedItemsUp, "Move selected item(s) up"); KeyDesc(aMoveSelectedItemsDown, "Move selected item(s) down"); + KeyDesc(aDeleteStoredPlaylist, "Delete selected playlists (left column)"); + KeyDesc(aDeletePlaylistItems, "Delete selected item(s) from playlist (right column)"); KeyDesc(aClearPlaylist, "Clear playlist"); KeyDesc(aCropPlaylist, "Clear playlist except selected items"); |