browser: add support for deleting group of selected items
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -58,6 +58,7 @@ class Browser : public Screen< Menu<MPD::Item> >
|
||||
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();
|
||||
|
||||
|
||||
@@ -711,6 +711,9 @@ int main(int argc, char *argv[])
|
||||
|
||||
std::string name = item.type == itSong ? item.song->GetName() : item.name;
|
||||
LockStatusbar();
|
||||
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;
|
||||
@@ -723,27 +726,34 @@ 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<size_t> 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());
|
||||
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));
|
||||
success = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (success)
|
||||
{
|
||||
if (!myBrowser->isLocal())
|
||||
Mpd.UpdateDirectory(myBrowser->CurrentDir());
|
||||
else
|
||||
myBrowser->GetDirectory(myBrowser->CurrentDir());
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user