diff --git a/src/browser.cpp b/src/browser.cpp index c409dba5..57c850b6 100644 --- a/src/browser.cpp +++ b/src/browser.cpp @@ -520,6 +520,27 @@ void Browser::ChangeBrowseMode() GetDirectory(itsBrowsedDir); RedrawHeader = 1; } + +bool Browser::DeleteItem(const MPD::Item &item) +{ + // parent dir + if (item.type == itDirectory && item.song) + return false; + + // playlist creatd by mpd + if (!isLocal() && item.type == itPlaylist && CurrentDir() == "/") + return Mpd.DeletePlaylist(locale_to_utf_cpy(item.name)); + + std::string path; + if (!isLocal()) + path = Config.mpd_music_dir; + path += item.type == itSong ? item.song->GetFile() : item.name; + + if (item.type == itDirectory) + ClearDirectory(path); + + return remove(path.c_str()) == 0; +} #endif // !WIN32 void Browser::UpdateItemList() diff --git a/src/browser.h b/src/browser.h index b1e02b77..099329b2 100644 --- a/src/browser.h +++ b/src/browser.h @@ -58,6 +58,7 @@ class Browser : public Screen< Menu > void GetLocalDirectory(MPD::ItemList &, const std::string & = "", bool = 0) const; void ClearDirectory(const std::string &) const; void ChangeBrowseMode(); + bool DeleteItem(const MPD::Item &); # endif // !WIN32 void UpdateItemList(); diff --git a/src/ncmpcpp.cpp b/src/ncmpcpp.cpp index 764285c9..2960c5e0 100644 --- a/src/ncmpcpp.cpp +++ b/src/ncmpcpp.cpp @@ -711,7 +711,10 @@ int main(int argc, char *argv[]) std::string name = item.type == itSong ? item.song->GetName() : item.name; LockStatusbar(); - Statusbar() << "Delete " << (item.type == itSong ? "file" : item.type == itDirectory ? "directory" : "playlist") << " \"" << Shorten(TO_WSTRING(name), COLS-30) << "\" ? [" << fmtBold << 'y' << fmtBoldEnd << '/' << fmtBold << 'n' << fmtBoldEnd << "] "; + if (myBrowser->Main()->hasSelected()) + Statusbar() << "Delete selected items ? [" << fmtBold << 'y' << fmtBoldEnd << '/' << fmtBold << 'n' << fmtBoldEnd << "] "; + else + Statusbar() << "Delete " << (item.type == itSong ? "file" : item.type == itDirectory ? "directory" : "playlist") << " \"" << Shorten(TO_WSTRING(name), COLS-30) << "\" ? [" << fmtBold << 'y' << fmtBoldEnd << '/' << fmtBold << 'n' << fmtBoldEnd << "] "; wFooter->Refresh(); int answer = 0; do @@ -723,28 +726,35 @@ int main(int argc, char *argv[]) UnlockStatusbar(); if (answer == 'y') { - std::string path; - if (!myBrowser->isLocal()) - path = Config.mpd_music_dir; - path += item.type == itSong ? item.song->GetFile() : item.name; - - if (item.type == itDirectory) - myBrowser->ClearDirectory(path); - - if (remove(path.c_str()) == 0) + std::vector list; + myBrowser->Main()->GetSelected(list); + if (list.empty()) + list.push_back(myBrowser->Main()->Choice()); + bool success = 1; + for (size_t i = 0; i < list.size(); ++i) + { + const MPD::Item &it = (*myBrowser->Main())[list[i]]; + name = it.type == itSong ? it.song->GetName() : it.name; + if (myBrowser->DeleteItem(it)) + { + static const char msg[] = "\"%s\" deleted!"; + ShowMessage(msg, Shorten(TO_WSTRING(name), COLS-static_strlen(msg)).c_str()); + } + else + { + static const char msg[] = "Couldn't remove \"%s\": %s"; + ShowMessage(msg, Shorten(TO_WSTRING(name), COLS-static_strlen(msg)-25).c_str(), strerror(errno)); + success = 0; + break; + } + } + if (success) { - static const char msg[] = "\"%s\" deleted!"; - ShowMessage(msg, Shorten(TO_WSTRING(name), COLS-static_strlen(msg)).c_str()); if (!myBrowser->isLocal()) Mpd.UpdateDirectory(myBrowser->CurrentDir()); else myBrowser->GetDirectory(myBrowser->CurrentDir()); } - else - { - static const char msg[] = "Couldn't remove \"%s\": %s"; - ShowMessage(msg, Shorten(TO_WSTRING(name), COLS-static_strlen(msg)-25).c_str(), strerror(errno)); - } } else ShowMessage("Aborted!");