browser: add support for deleting group of selected items
This commit is contained in:
@@ -520,6 +520,27 @@ void Browser::ChangeBrowseMode()
|
|||||||
GetDirectory(itsBrowsedDir);
|
GetDirectory(itsBrowsedDir);
|
||||||
RedrawHeader = 1;
|
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
|
#endif // !WIN32
|
||||||
|
|
||||||
void Browser::UpdateItemList()
|
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 GetLocalDirectory(MPD::ItemList &, const std::string & = "", bool = 0) const;
|
||||||
void ClearDirectory(const std::string &) const;
|
void ClearDirectory(const std::string &) const;
|
||||||
void ChangeBrowseMode();
|
void ChangeBrowseMode();
|
||||||
|
bool DeleteItem(const MPD::Item &);
|
||||||
# endif // !WIN32
|
# endif // !WIN32
|
||||||
void UpdateItemList();
|
void UpdateItemList();
|
||||||
|
|
||||||
|
|||||||
@@ -711,6 +711,9 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
std::string name = item.type == itSong ? item.song->GetName() : item.name;
|
std::string name = item.type == itSong ? item.song->GetName() : item.name;
|
||||||
LockStatusbar();
|
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 << "] ";
|
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();
|
wFooter->Refresh();
|
||||||
int answer = 0;
|
int answer = 0;
|
||||||
@@ -723,27 +726,34 @@ int main(int argc, char *argv[])
|
|||||||
UnlockStatusbar();
|
UnlockStatusbar();
|
||||||
if (answer == 'y')
|
if (answer == 'y')
|
||||||
{
|
{
|
||||||
std::string path;
|
std::vector<size_t> list;
|
||||||
if (!myBrowser->isLocal())
|
myBrowser->Main()->GetSelected(list);
|
||||||
path = Config.mpd_music_dir;
|
if (list.empty())
|
||||||
path += item.type == itSong ? item.song->GetFile() : item.name;
|
list.push_back(myBrowser->Main()->Choice());
|
||||||
|
bool success = 1;
|
||||||
if (item.type == itDirectory)
|
for (size_t i = 0; i < list.size(); ++i)
|
||||||
myBrowser->ClearDirectory(path);
|
{
|
||||||
|
const MPD::Item &it = (*myBrowser->Main())[list[i]];
|
||||||
if (remove(path.c_str()) == 0)
|
name = it.type == itSong ? it.song->GetName() : it.name;
|
||||||
|
if (myBrowser->DeleteItem(it))
|
||||||
{
|
{
|
||||||
static const char msg[] = "\"%s\" deleted!";
|
static const char msg[] = "\"%s\" deleted!";
|
||||||
ShowMessage(msg, Shorten(TO_WSTRING(name), COLS-static_strlen(msg)).c_str());
|
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
|
else
|
||||||
{
|
{
|
||||||
static const char msg[] = "Couldn't remove \"%s\": %s";
|
static const char msg[] = "Couldn't remove \"%s\": %s";
|
||||||
ShowMessage(msg, Shorten(TO_WSTRING(name), COLS-static_strlen(msg)-25).c_str(), strerror(errno));
|
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
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user