playlist editor: make playlist deletion work

This commit is contained in:
Andrzej Rybczak
2014-10-04 17:17:23 +02:00
parent 9418451a31
commit af3a666915
2 changed files with 36 additions and 33 deletions

View File

@@ -724,12 +724,13 @@ void DeleteBrowserItems::run()
bool DeleteStoredPlaylist::canBeRun() const bool DeleteStoredPlaylist::canBeRun() const
{ {
return myScreen->isActiveWindow(myPlaylistEditor->Playlists) return myScreen->isActiveWindow(myPlaylistEditor->Playlists);
&& myPlaylistEditor->Playlists.empty();
} }
void DeleteStoredPlaylist::run() void DeleteStoredPlaylist::run()
{ {
if (myPlaylistEditor->Playlists.empty())
return;
boost::format question; boost::format question;
if (hasSelected(myPlaylistEditor->Playlists.begin(), myPlaylistEditor->Playlists.end())) if (hasSelected(myPlaylistEditor->Playlists.begin(), myPlaylistEditor->Playlists.end()))
question = boost::format("Delete selected playlists?"); question = boost::format("Delete selected playlists?");
@@ -740,10 +741,8 @@ void DeleteStoredPlaylist::run()
if (yes) if (yes)
{ {
auto list = getSelectedOrCurrent(myPlaylistEditor->Playlists.begin(), myPlaylistEditor->Playlists.end(), myPlaylistEditor->Playlists.currentI()); auto list = getSelectedOrCurrent(myPlaylistEditor->Playlists.begin(), myPlaylistEditor->Playlists.end(), myPlaylistEditor->Playlists.currentI());
Mpd.StartCommandsList();
for (auto it = list.begin(); it != list.end(); ++it) for (auto it = list.begin(); it != list.end(); ++it)
Mpd.DeletePlaylist((*it)->value()); Mpd.DeletePlaylist((*it)->value());
Mpd.CommitCommandsList();
Statusbar::printf("%1% deleted", list.size() == 1 ? "Playlist" : "Playlists"); Statusbar::printf("%1% deleted", list.size() == 1 ? "Playlist" : "Playlists");
} }
else else

View File

@@ -156,41 +156,45 @@ void PlaylistEditor::update()
Playlists.refresh(); Playlists.refresh();
} }
if (!Playlists.empty() if ((Content.reallyEmpty() && Global::Timer - m_timer > m_fetching_delay)
&& ((Content.reallyEmpty() && Global::Timer - m_timer > m_fetching_delay) || m_content_update_requested) || m_content_update_requested)
)
{ {
m_content_update_requested = false; m_content_update_requested = false;
Content.clearSearchResults(); if (Playlists.empty())
withUnfilteredMenuReapplyFilter(Content, [this]() { Content.clear();
size_t idx = 0; else
Mpd.GetPlaylistContent(Playlists.current().value(), [this, &idx](MPD::Song s) { {
Content.clearSearchResults();
withUnfilteredMenuReapplyFilter(Content, [this]() {
size_t idx = 0;
Mpd.GetPlaylistContent(Playlists.current().value(), [this, &idx](MPD::Song s) {
if (idx < Content.size())
{
Content[idx].value() = s;
Content[idx].setBold(myPlaylist->checkForSong(s));
}
else
Content.addItem(s, myPlaylist->checkForSong(s));
++idx;
});
if (idx < Content.size()) if (idx < Content.size())
Content.resizeList(idx);
std::string title;
if (Config.titles_visibility)
{ {
Content[idx].value() = s; title = "Playlist content";
Content[idx].setBold(myPlaylist->checkForSong(s)); title += " (";
title += boost::lexical_cast<std::string>(Content.size());
title += " item";
if (Content.size() == 1)
title += ")";
else
title += "s)";
title.resize(Content.getWidth());
} }
else Content.setTitle(title);
Content.addItem(s, myPlaylist->checkForSong(s));
++idx;
}); });
if (idx < Content.size()) }
Content.resizeList(idx);
std::string title;
if (Config.titles_visibility)
{
title = "Playlist content";
title += " (";
title += boost::lexical_cast<std::string>(Content.size());
title += " item";
if (Content.size() == 1)
title += ")";
else
title += "s)";
title.resize(Content.getWidth());
}
Content.setTitle(title);
});
Content.display(); Content.display();
} }