playlist editor: change columns to be non-pointers

This commit is contained in:
Andrzej Rybczak
2012-09-14 18:38:28 +02:00
parent 8b42a41720
commit 49a21370a6
3 changed files with 172 additions and 173 deletions

View File

@@ -398,9 +398,9 @@ void Action::ListsChangeFinisher()
{ {
myLibrary->Songs.clear(); myLibrary->Songs.clear();
} }
else if (myScreen->activeWindow() == myPlaylistEditor->Playlists) else if (myScreen->isActiveWindow(myPlaylistEditor->Playlists))
{ {
myPlaylistEditor->Content->clear(); myPlaylistEditor->Content.clear();
} }
# ifdef HAVE_TAGLIB_H # ifdef HAVE_TAGLIB_H
else if (myScreen->activeWindow() == myTagEditor->Dirs) else if (myScreen->activeWindow() == myTagEditor->Dirs)
@@ -841,23 +841,23 @@ void Delete::Run()
Statusbar::msg("Aborted"); Statusbar::msg("Aborted");
} }
# endif // !WIN32 # endif // !WIN32
else if (myScreen == myPlaylistEditor && !myPlaylistEditor->Content->empty()) else if (myScreen == myPlaylistEditor && !myPlaylistEditor->Content.empty())
{ {
if (myScreen->activeWindow() == myPlaylistEditor->Playlists) if (myScreen->isActiveWindow(myPlaylistEditor->Playlists))
{ {
std::string question; std::string question;
if (myPlaylistEditor->Playlists->hasSelected()) if (myPlaylistEditor->Playlists.hasSelected())
question = "Delete selected playlists?"; question = "Delete selected playlists?";
else else
{ {
question = "Delete playlist \""; question = "Delete playlist \"";
question += ToString(wideShorten(ToWString(myPlaylistEditor->Playlists->current().value()), COLS-question.size()-10)); question += ToString(wideShorten(ToWString(myPlaylistEditor->Playlists.current().value()), COLS-question.size()-10));
question += "\"?"; question += "\"?";
} }
bool yes = AskYesNoQuestion(question, Status::trace); bool yes = AskYesNoQuestion(question, Status::trace);
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(); 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());
@@ -867,12 +867,12 @@ void Delete::Run()
else else
Statusbar::msg("Aborted"); Statusbar::msg("Aborted");
} }
else if (myScreen->activeWindow() == myPlaylistEditor->Content) else if (myScreen->isActiveWindow(myPlaylistEditor->Content))
{ {
std::string playlist = myPlaylistEditor->Playlists->current().value(); std::string playlist = myPlaylistEditor->Playlists.current().value();
auto delete_fun = std::bind(&MPD::Connection::PlaylistDelete, _1, playlist, _2); auto delete_fun = std::bind(&MPD::Connection::PlaylistDelete, _1, playlist, _2);
Statusbar::msg("Deleting items..."); Statusbar::msg("Deleting items...");
if (deleteSelectedSongs(*myPlaylistEditor->Content, delete_fun)) if (deleteSelectedSongs(myPlaylistEditor->Content, delete_fun))
Statusbar::msg("Item(s) deleted"); Statusbar::msg("Item(s) deleted");
} }
} }
@@ -982,8 +982,8 @@ bool MoveSelectedItemsUp::canBeRun() const
return ((myScreen == myPlaylist return ((myScreen == myPlaylist
&& !myPlaylist->main().empty() && !myPlaylist->main().empty()
&& !myPlaylist->isFiltered()) && !myPlaylist->isFiltered())
|| (myScreen->activeWindow() == myPlaylistEditor->Content || (myScreen->isActiveWindow(myPlaylistEditor->Content)
&& !myPlaylistEditor->Content->empty() && !myPlaylistEditor->Content.empty()
&& !myPlaylistEditor->isContentFiltered())); && !myPlaylistEditor->isContentFiltered()));
} }
@@ -995,10 +995,10 @@ void MoveSelectedItemsUp::Run()
} }
else if (myScreen == myPlaylistEditor) else if (myScreen == myPlaylistEditor)
{ {
assert(!myPlaylistEditor->Playlists->empty()); assert(!myPlaylistEditor->Playlists.empty());
std::string playlist = myPlaylistEditor->Playlists->current().value(); std::string playlist = myPlaylistEditor->Playlists.current().value();
auto move_fun = std::bind(&MPD::Connection::PlaylistMove, _1, playlist, _2, _3); auto move_fun = std::bind(&MPD::Connection::PlaylistMove, _1, playlist, _2, _3);
moveSelectedItemsUp(*myPlaylistEditor->Content, move_fun); moveSelectedItemsUp(myPlaylistEditor->Content, move_fun);
} }
} }
@@ -1007,8 +1007,8 @@ bool MoveSelectedItemsDown::canBeRun() const
return ((myScreen == myPlaylist return ((myScreen == myPlaylist
&& !myPlaylist->main().empty() && !myPlaylist->main().empty()
&& !myPlaylist->isFiltered()) && !myPlaylist->isFiltered())
|| (myScreen->activeWindow() == myPlaylistEditor->Content || (myScreen->isActiveWindow(myPlaylistEditor->Content)
&& !myPlaylistEditor->Content->empty() && !myPlaylistEditor->Content.empty()
&& !myPlaylistEditor->isContentFiltered())); && !myPlaylistEditor->isContentFiltered()));
} }
@@ -1020,17 +1020,17 @@ void MoveSelectedItemsDown::Run()
} }
else if (myScreen == myPlaylistEditor) else if (myScreen == myPlaylistEditor)
{ {
assert(!myPlaylistEditor->Playlists->empty()); assert(!myPlaylistEditor->Playlists.empty());
std::string playlist = myPlaylistEditor->Playlists->current().value(); std::string playlist = myPlaylistEditor->Playlists.current().value();
auto move_fun = std::bind(&MPD::Connection::PlaylistMove, _1, playlist, _2, _3); auto move_fun = std::bind(&MPD::Connection::PlaylistMove, _1, playlist, _2, _3);
moveSelectedItemsDown(*myPlaylistEditor->Content, move_fun); moveSelectedItemsDown(myPlaylistEditor->Content, move_fun);
} }
} }
bool MoveSelectedItemsTo::canBeRun() const bool MoveSelectedItemsTo::canBeRun() const
{ {
return myScreen == myPlaylist return myScreen == myPlaylist
|| myScreen->activeWindow() == myPlaylistEditor->Content; || myScreen->isActiveWindow(myPlaylistEditor->Content);
} }
void MoveSelectedItemsTo::Run() void MoveSelectedItemsTo::Run()
@@ -1039,17 +1039,17 @@ void MoveSelectedItemsTo::Run()
moveSelectedItemsTo(myPlaylist->main(), std::bind(&MPD::Connection::Move, _1, _2, _3)); moveSelectedItemsTo(myPlaylist->main(), std::bind(&MPD::Connection::Move, _1, _2, _3));
else else
{ {
assert(!myPlaylistEditor->Playlists->empty()); assert(!myPlaylistEditor->Playlists.empty());
std::string playlist = myPlaylistEditor->Playlists->current().value(); std::string playlist = myPlaylistEditor->Playlists.current().value();
auto move_fun = std::bind(&MPD::Connection::PlaylistMove, _1, playlist, _2, _3); auto move_fun = std::bind(&MPD::Connection::PlaylistMove, _1, playlist, _2, _3);
moveSelectedItemsTo(*myPlaylistEditor->Content, move_fun); moveSelectedItemsTo(myPlaylistEditor->Content, move_fun);
} }
} }
bool Add::canBeRun() const bool Add::canBeRun() const
{ {
return myScreen != myPlaylistEditor return myScreen != myPlaylistEditor
|| !myPlaylistEditor->Playlists->empty(); || !myPlaylistEditor->Playlists.empty();
} }
void Add::Run() void Add::Run()
@@ -1065,7 +1065,7 @@ void Add::Run()
Statusbar::put() << "Adding..."; Statusbar::put() << "Adding...";
wFooter->refresh(); wFooter->refresh();
if (myScreen == myPlaylistEditor) if (myScreen == myPlaylistEditor)
Mpd.AddToPlaylist(myPlaylistEditor->Playlists->current().value(), path); Mpd.AddToPlaylist(myPlaylistEditor->Playlists.current().value(), path);
else else
{ {
const char lastfm_url[] = "lastfm://"; const char lastfm_url[] = "lastfm://";
@@ -1107,7 +1107,7 @@ bool ToggleDisplayMode::canBeRun() const
return myScreen == myPlaylist return myScreen == myPlaylist
|| myScreen == myBrowser || myScreen == myBrowser
|| myScreen == mySearcher || myScreen == mySearcher
|| myScreen->activeWindow() == myPlaylistEditor->Content; || myScreen->isActiveWindow(myPlaylistEditor->Content);
} }
void ToggleDisplayMode::Run() void ToggleDisplayMode::Run()
@@ -1144,14 +1144,14 @@ void ToggleDisplayMode::Run()
if (mySearcher->main().size() > SearchEngine::StaticOptions) if (mySearcher->main().size() > SearchEngine::StaticOptions)
mySearcher->main().setTitle(Config.columns_in_search_engine && Config.titles_visibility ? Display::Columns(mySearcher->main().getWidth()) : ""); mySearcher->main().setTitle(Config.columns_in_search_engine && Config.titles_visibility ? Display::Columns(mySearcher->main().getWidth()) : "");
} }
else if (myScreen->activeWindow() == myPlaylistEditor->Content) else if (myScreen->isActiveWindow(myPlaylistEditor->Content))
{ {
Config.columns_in_playlist_editor = !Config.columns_in_playlist_editor; Config.columns_in_playlist_editor = !Config.columns_in_playlist_editor;
Statusbar::msg("Playlist editor display mode: %s", Config.columns_in_playlist_editor ? "Columns" : "Classic"); Statusbar::msg("Playlist editor display mode: %s", Config.columns_in_playlist_editor ? "Columns" : "Classic");
if (Config.columns_in_playlist_editor) if (Config.columns_in_playlist_editor)
myPlaylistEditor->Content->setItemDisplayer(std::bind(Display::SongsInColumns, _1, myPlaylistEditor)); myPlaylistEditor->Content.setItemDisplayer(std::bind(Display::SongsInColumns, _1, myPlaylistEditor));
else else
myPlaylistEditor->Content->setItemDisplayer(std::bind(Display::Songs, _1, myPlaylistEditor, Config.song_list_format)); myPlaylistEditor->Content.setItemDisplayer(std::bind(Display::Songs, _1, myPlaylistEditor, Config.song_list_format));
} }
} }
@@ -1529,8 +1529,8 @@ void EditDirectoryName::Run()
bool EditPlaylistName::canBeRun() const bool EditPlaylistName::canBeRun() const
{ {
return (myScreen->activeWindow() == myPlaylistEditor->Playlists return (myScreen->isActiveWindow(myPlaylistEditor->Playlists)
&& !myPlaylistEditor->Playlists->empty()) && !myPlaylistEditor->Playlists.empty())
|| (myScreen == myBrowser || (myScreen == myBrowser
&& !myBrowser->main().empty() && !myBrowser->main().empty()
&& myBrowser->main().current().value().type == MPD::itPlaylist); && myBrowser->main().current().value().type == MPD::itPlaylist);
@@ -1541,8 +1541,8 @@ void EditPlaylistName::Run()
using Global::wFooter; using Global::wFooter;
std::string old_name; std::string old_name;
if (myScreen->activeWindow() == myPlaylistEditor->Playlists) if (myScreen->isActiveWindow(myPlaylistEditor->Playlists))
old_name = myPlaylistEditor->Playlists->current().value(); old_name = myPlaylistEditor->Playlists.current().value();
else else
old_name = myBrowser->main().current().value().name; old_name = myBrowser->main().current().value().name;
Statusbar::lock(); Statusbar::lock();
@@ -1794,8 +1794,8 @@ bool CropPlaylist::canBeRun() const
void CropPlaylist::Run() void CropPlaylist::Run()
{ {
assert(!myPlaylistEditor->Playlists->empty()); assert(!myPlaylistEditor->Playlists.empty());
std::string playlist = myPlaylistEditor->Playlists->current().value(); std::string playlist = myPlaylistEditor->Playlists.current().value();
bool yes = true; bool yes = true;
if (Config.ask_before_clearing_main_playlist) if (Config.ask_before_clearing_main_playlist)
yes = AskYesNoQuestion("Do you really want to crop playlist \"" + playlist + "\"?", Status::trace); yes = AskYesNoQuestion("Do you really want to crop playlist \"" + playlist + "\"?", Status::trace);
@@ -1803,7 +1803,7 @@ void CropPlaylist::Run()
{ {
auto delete_fun = std::bind(&MPD::Connection::PlaylistDelete, _1, playlist, _2); auto delete_fun = std::bind(&MPD::Connection::PlaylistDelete, _1, playlist, _2);
Statusbar::msg("Cropping playlist \"%s\"...", playlist.c_str()); Statusbar::msg("Cropping playlist \"%s\"...", playlist.c_str());
if (cropPlaylist(*myPlaylistEditor->Content, delete_fun)) if (cropPlaylist(myPlaylistEditor->Content, delete_fun))
Statusbar::msg("Playlist \"%s\" cropped", playlist.c_str()); Statusbar::msg("Playlist \"%s\" cropped", playlist.c_str());
} }
} }
@@ -1830,8 +1830,8 @@ bool ClearPlaylist::canBeRun() const
void ClearPlaylist::Run() void ClearPlaylist::Run()
{ {
assert(!myPlaylistEditor->Playlists->empty()); assert(!myPlaylistEditor->Playlists.empty());
std::string playlist = myPlaylistEditor->Playlists->current().value(); std::string playlist = myPlaylistEditor->Playlists.current().value();
bool yes = true; bool yes = true;
if (Config.ask_before_clearing_main_playlist) if (Config.ask_before_clearing_main_playlist)
yes = AskYesNoQuestion("Do you really want to clear playlist \"" + playlist + "\"?", Status::trace); yes = AskYesNoQuestion("Do you really want to clear playlist \"" + playlist + "\"?", Status::trace);
@@ -1840,7 +1840,7 @@ void ClearPlaylist::Run()
auto delete_fun = std::bind(&MPD::Connection::PlaylistDelete, _1, playlist, _2); auto delete_fun = std::bind(&MPD::Connection::PlaylistDelete, _1, playlist, _2);
auto clear_fun = std::bind(&MPD::Connection::ClearPlaylist, _1, playlist); auto clear_fun = std::bind(&MPD::Connection::ClearPlaylist, _1, playlist);
Statusbar::msg("Deleting items from \"%s\"...", playlist.c_str()); Statusbar::msg("Deleting items from \"%s\"...", playlist.c_str());
if (clearPlaylist(*myPlaylistEditor->Content, delete_fun, clear_fun)) if (clearPlaylist(myPlaylistEditor->Content, delete_fun, clear_fun))
Statusbar::msg("Items deleted from \"%s\"", playlist.c_str()); Statusbar::msg("Items deleted from \"%s\"", playlist.c_str());
} }
} }

View File

@@ -61,26 +61,26 @@ PlaylistEditor::PlaylistEditor()
RightColumnStartX = LeftColumnWidth+1; RightColumnStartX = LeftColumnWidth+1;
RightColumnWidth = COLS-LeftColumnWidth-1; RightColumnWidth = COLS-LeftColumnWidth-1;
Playlists = new NC::Menu<std::string>(0, MainStartY, LeftColumnWidth, MainHeight, Config.titles_visibility ? "Playlists" : "", Config.main_color, NC::brNone); Playlists = NC::Menu<std::string>(0, MainStartY, LeftColumnWidth, MainHeight, Config.titles_visibility ? "Playlists" : "", Config.main_color, NC::brNone);
Playlists->setHighlightColor(Config.active_column_color); Playlists.setHighlightColor(Config.active_column_color);
Playlists->cyclicScrolling(Config.use_cyclic_scrolling); Playlists.cyclicScrolling(Config.use_cyclic_scrolling);
Playlists->centeredCursor(Config.centered_cursor); Playlists.centeredCursor(Config.centered_cursor);
Playlists->setSelectedPrefix(Config.selected_item_prefix); Playlists.setSelectedPrefix(Config.selected_item_prefix);
Playlists->setSelectedSuffix(Config.selected_item_suffix); Playlists.setSelectedSuffix(Config.selected_item_suffix);
Playlists->setItemDisplayer(Display::Default<std::string>); Playlists.setItemDisplayer(Display::Default<std::string>);
Content = new NC::Menu<MPD::Song>(RightColumnStartX, MainStartY, RightColumnWidth, MainHeight, Config.titles_visibility ? "Playlist content" : "", Config.main_color, NC::brNone); Content = NC::Menu<MPD::Song>(RightColumnStartX, MainStartY, RightColumnWidth, MainHeight, Config.titles_visibility ? "Playlist content" : "", Config.main_color, NC::brNone);
Content->setHighlightColor(Config.main_highlight_color); Content.setHighlightColor(Config.main_highlight_color);
Content->cyclicScrolling(Config.use_cyclic_scrolling); Content.cyclicScrolling(Config.use_cyclic_scrolling);
Content->centeredCursor(Config.centered_cursor); Content.centeredCursor(Config.centered_cursor);
Content->setSelectedPrefix(Config.selected_item_prefix); Content.setSelectedPrefix(Config.selected_item_prefix);
Content->setSelectedSuffix(Config.selected_item_suffix); Content.setSelectedSuffix(Config.selected_item_suffix);
if (Config.columns_in_playlist_editor) if (Config.columns_in_playlist_editor)
Content->setItemDisplayer(std::bind(Display::SongsInColumns, _1, this)); Content.setItemDisplayer(std::bind(Display::SongsInColumns, _1, this));
else else
Content->setItemDisplayer(std::bind(Display::Songs, _1, this, Config.song_list_format)); Content.setItemDisplayer(std::bind(Display::Songs, _1, this, Config.song_list_format));
w = Playlists; w = &Playlists;
} }
void PlaylistEditor::resize() void PlaylistEditor::resize()
@@ -93,11 +93,11 @@ void PlaylistEditor::resize()
RightColumnStartX = LeftColumnStartX+LeftColumnWidth+1; RightColumnStartX = LeftColumnStartX+LeftColumnWidth+1;
RightColumnWidth = width-LeftColumnWidth-1; RightColumnWidth = width-LeftColumnWidth-1;
Playlists->resize(LeftColumnWidth, MainHeight); Playlists.resize(LeftColumnWidth, MainHeight);
Content->resize(RightColumnWidth, MainHeight); Content.resize(RightColumnWidth, MainHeight);
Playlists->moveTo(LeftColumnStartX, MainStartY); Playlists.moveTo(LeftColumnStartX, MainStartY);
Content->moveTo(RightColumnStartX, MainStartY); Content.moveTo(RightColumnStartX, MainStartY);
hasToBeResized = 0; hasToBeResized = 0;
} }
@@ -109,9 +109,9 @@ std::wstring PlaylistEditor::title()
void PlaylistEditor::refresh() void PlaylistEditor::refresh()
{ {
Playlists->display(); Playlists.display();
mvvline(MainStartY, RightColumnStartX-1, 0, MainHeight); mvvline(MainStartY, RightColumnStartX-1, 0, MainHeight);
Content->display(); Content.display();
} }
void PlaylistEditor::switchTo() void PlaylistEditor::switchTo()
@@ -138,41 +138,41 @@ void PlaylistEditor::switchTo()
void PlaylistEditor::update() void PlaylistEditor::update()
{ {
if (Playlists->reallyEmpty() || playlistsUpdateRequested) if (Playlists.reallyEmpty() || playlistsUpdateRequested)
{ {
playlistsUpdateRequested = false; playlistsUpdateRequested = false;
Playlists->clearSearchResults(); Playlists.clearSearchResults();
withUnfilteredMenuReapplyFilter(*Playlists, [this]() { withUnfilteredMenuReapplyFilter(Playlists, [this]() {
auto list = Mpd.GetPlaylists(); auto list = Mpd.GetPlaylists();
std::sort(list.begin(), list.end(), std::sort(list.begin(), list.end(),
LocaleBasedSorting(std::locale(), Config.ignore_leading_the)); LocaleBasedSorting(std::locale(), Config.ignore_leading_the));
auto playlist = list.begin(); auto playlist = list.begin();
if (Playlists->size() > list.size()) if (Playlists.size() > list.size())
Playlists->resizeList(list.size()); Playlists.resizeList(list.size());
for (auto it = Playlists->begin(); it != Playlists->end(); ++it, ++playlist) for (auto it = Playlists.begin(); it != Playlists.end(); ++it, ++playlist)
it->value() = *playlist; it->value() = *playlist;
for (; playlist != list.end(); ++playlist) for (; playlist != list.end(); ++playlist)
Playlists->addItem(*playlist); Playlists.addItem(*playlist);
}); });
Playlists->refresh(); Playlists.refresh();
} }
if (!Playlists->empty() && (Content->reallyEmpty() || contentUpdateRequested)) if (!Playlists.empty() && (Content.reallyEmpty() || contentUpdateRequested))
{ {
contentUpdateRequested = false; contentUpdateRequested = false;
Content->clearSearchResults(); Content.clearSearchResults();
withUnfilteredMenuReapplyFilter(*Content, [this]() { withUnfilteredMenuReapplyFilter(Content, [this]() {
auto list = Mpd.GetPlaylistContent(Playlists->current().value()); auto list = Mpd.GetPlaylistContent(Playlists.current().value());
auto song = list.begin(); auto song = list.begin();
if (Content->size() > list.size()) if (Content.size() > list.size())
Content->resizeList(list.size()); Content.resizeList(list.size());
for (auto it = Content->begin(); it != Content->end(); ++it, ++song) for (auto it = Content.begin(); it != Content.end(); ++it, ++song)
{ {
it->value() = *song; it->value() = *song;
it->setBold(myPlaylist->checkForSong(*song)); it->setBold(myPlaylist->checkForSong(*song));
} }
for (; song != list.end(); ++song) for (; song != list.end(); ++song)
Content->addItem(*song, myPlaylist->checkForSong(*song)); Content.addItem(*song, myPlaylist->checkForSong(*song));
std::string title; std::string title;
if (Config.titles_visibility) if (Config.titles_visibility)
{ {
@@ -184,30 +184,30 @@ void PlaylistEditor::update()
title += ")"; title += ")";
else else
title += "s)"; title += "s)";
title.resize(Content->getWidth()); title.resize(Content.getWidth());
} }
Content->setTitle(title); Content.setTitle(title);
}); });
Content->display(); Content.display();
} }
if (w == Content && Content->reallyEmpty()) if (isActiveWindow(Content) && Content.reallyEmpty())
{ {
Content->setHighlightColor(Config.main_highlight_color); Content.setHighlightColor(Config.main_highlight_color);
Playlists->setHighlightColor(Config.active_column_color); Playlists.setHighlightColor(Config.active_column_color);
w = Playlists; w = &Playlists;
} }
if (Playlists->empty() && Content->reallyEmpty()) if (Playlists.empty() && Content.reallyEmpty())
{ {
Content->Window::clear(); Content.Window::clear();
Content->Window::display(); Content.Window::display();
} }
} }
bool PlaylistEditor::isContentFiltered() bool PlaylistEditor::isContentFiltered()
{ {
if (Content->isFiltered()) if (Content.isFiltered())
{ {
Statusbar::msg("Function currently unavailable due to filtered playlist content"); Statusbar::msg("Function currently unavailable due to filtered playlist content");
return true; return true;
@@ -217,7 +217,7 @@ bool PlaylistEditor::isContentFiltered()
std::shared_ptr<ProxySongList> PlaylistEditor::contentProxyList() std::shared_ptr<ProxySongList> PlaylistEditor::contentProxyList()
{ {
return mkProxySongList(*Content, [](NC::Menu<MPD::Song>::Item &item) { return mkProxySongList(Content, [](NC::Menu<MPD::Song>::Item &item) {
return &item.value(); return &item.value();
}); });
} }
@@ -226,17 +226,17 @@ void PlaylistEditor::AddToPlaylist(bool add_n_play)
{ {
MPD::SongList list; MPD::SongList list;
if (w == Playlists && !Playlists->empty()) if (isActiveWindow(Playlists) && !Playlists.empty())
{ {
if (Mpd.LoadPlaylist(Playlists->current().value())) if (Mpd.LoadPlaylist(Playlists.current().value()))
{ {
Statusbar::msg("Playlist \"%s\" loaded", Playlists->current().value().c_str()); Statusbar::msg("Playlist \"%s\" loaded", Playlists.current().value().c_str());
if (add_n_play) if (add_n_play)
myPlaylist->PlayNewlyAddedSongs(); myPlaylist->PlayNewlyAddedSongs();
} }
} }
else if (w == Content && !Content->empty()) else if (isActiveWindow(Content) && !Content.empty())
myPlaylist->Add(Content->current().value(), add_n_play); myPlaylist->Add(Content.current().value(), add_n_play);
if (!add_n_play) if (!add_n_play)
w->scroll(NC::wDown); w->scroll(NC::wDown);
@@ -251,20 +251,20 @@ void PlaylistEditor::spacePressed()
{ {
if (Config.space_selects) if (Config.space_selects)
{ {
if (w == Playlists) if (isActiveWindow(Playlists))
{ {
if (!Playlists->empty()) if (!Playlists.empty())
{ {
Playlists->current().setSelected(!Playlists->current().isSelected()); Playlists.current().setSelected(!Playlists.current().isSelected());
Playlists->scroll(NC::wDown); Playlists.scroll(NC::wDown);
} }
} }
else if (w == Content) else if (isActiveWindow(Content))
{ {
if (!Content->empty()) if (!Content.empty())
{ {
Content->current().setSelected(!Content->current().isSelected()); Content.current().setSelected(!Content.current().isSelected());
Content->scroll(NC::wDown); Content.scroll(NC::wDown);
} }
} }
} }
@@ -274,48 +274,48 @@ void PlaylistEditor::spacePressed()
void PlaylistEditor::mouseButtonPressed(MEVENT me) void PlaylistEditor::mouseButtonPressed(MEVENT me)
{ {
if (!Playlists->empty() && Playlists->hasCoords(me.x, me.y)) if (!Playlists.empty() && Playlists.hasCoords(me.x, me.y))
{ {
if (w != Playlists) if (!isActiveWindow(Playlists))
{ {
if (previousColumnAvailable()) if (previousColumnAvailable())
previousColumn(); previousColumn();
else else
return; return;
} }
if (size_t(me.y) < Playlists->size() && (me.bstate & (BUTTON1_PRESSED | BUTTON3_PRESSED))) if (size_t(me.y) < Playlists.size() && (me.bstate & (BUTTON1_PRESSED | BUTTON3_PRESSED)))
{ {
Playlists->Goto(me.y); Playlists.Goto(me.y);
if (me.bstate & BUTTON3_PRESSED) if (me.bstate & BUTTON3_PRESSED)
{ {
size_t pos = Playlists->choice(); size_t pos = Playlists.choice();
spacePressed(); spacePressed();
if (pos < Playlists->size()-1) if (pos < Playlists.size()-1)
Playlists->scroll(NC::wUp); Playlists.scroll(NC::wUp);
} }
} }
else else
Screen<WindowType>::mouseButtonPressed(me); Screen<WindowType>::mouseButtonPressed(me);
Content->clear(); Content.clear();
} }
else if (!Content->empty() && Content->hasCoords(me.x, me.y)) else if (!Content.empty() && Content.hasCoords(me.x, me.y))
{ {
if (w != Content) if (!isActiveWindow(Content))
{ {
if (nextColumnAvailable()) if (nextColumnAvailable())
nextColumn(); nextColumn();
else else
return; return;
} }
if (size_t(me.y) < Content->size() && (me.bstate & (BUTTON1_PRESSED | BUTTON3_PRESSED))) if (size_t(me.y) < Content.size() && (me.bstate & (BUTTON1_PRESSED | BUTTON3_PRESSED)))
{ {
Content->Goto(me.y); Content.Goto(me.y);
if (me.bstate & BUTTON1_PRESSED) if (me.bstate & BUTTON1_PRESSED)
{ {
size_t pos = Content->choice(); size_t pos = Content.choice();
spacePressed(); spacePressed();
if (pos < Content->size()-1) if (pos < Content.size()-1)
Content->scroll(NC::wUp); Content.scroll(NC::wUp);
} }
else else
enterPressed(); enterPressed();
@@ -335,26 +335,26 @@ bool PlaylistEditor::allowsFiltering()
std::string PlaylistEditor::currentFilter() std::string PlaylistEditor::currentFilter()
{ {
std::string filter; std::string filter;
if (w == Playlists) if (isActiveWindow(Playlists))
filter = RegexFilter<std::string>::currentFilter(*Playlists); filter = RegexFilter<std::string>::currentFilter(Playlists);
else if (w == Content) else if (isActiveWindow(Content))
filter = RegexFilter<MPD::Song>::currentFilter(*Content); filter = RegexFilter<MPD::Song>::currentFilter(Content);
return filter; return filter;
} }
void PlaylistEditor::applyFilter(const std::string &filter) void PlaylistEditor::applyFilter(const std::string &filter)
{ {
if (w == Playlists) if (isActiveWindow(Playlists))
{ {
Playlists->showAll(); Playlists.showAll();
auto rx = RegexFilter<std::string>(filter, Config.regex_type, PlaylistEntryMatcher); auto rx = RegexFilter<std::string>(filter, Config.regex_type, PlaylistEntryMatcher);
Playlists->filter(Playlists->begin(), Playlists->end(), rx); Playlists.filter(Playlists.begin(), Playlists.end(), rx);
} }
else if (w == Content) else if (isActiveWindow(Content))
{ {
Content->showAll(); Content.showAll();
auto rx = RegexFilter<MPD::Song>(filter, Config.regex_type, SongEntryMatcher); auto rx = RegexFilter<MPD::Song>(filter, Config.regex_type, SongEntryMatcher);
Content->filter(Content->begin(), Content->end(), rx); Content.filter(Content.begin(), Content.end(), rx);
} }
} }
@@ -368,33 +368,33 @@ bool PlaylistEditor::allowsSearching()
bool PlaylistEditor::search(const std::string &constraint) bool PlaylistEditor::search(const std::string &constraint)
{ {
bool result = false; bool result = false;
if (w == Playlists) if (isActiveWindow(Playlists))
{ {
auto rx = RegexFilter<std::string>(constraint, Config.regex_type, PlaylistEntryMatcher); auto rx = RegexFilter<std::string>(constraint, Config.regex_type, PlaylistEntryMatcher);
result = Playlists->search(Playlists->begin(), Playlists->end(), rx); result = Playlists.search(Playlists.begin(), Playlists.end(), rx);
} }
else if (w == Content) else if (isActiveWindow(Content))
{ {
auto rx = RegexFilter<MPD::Song>(constraint, Config.regex_type, SongEntryMatcher); auto rx = RegexFilter<MPD::Song>(constraint, Config.regex_type, SongEntryMatcher);
result = Content->search(Content->begin(), Content->end(), rx); result = Content.search(Content.begin(), Content.end(), rx);
} }
return result; return result;
} }
void PlaylistEditor::nextFound(bool wrap) void PlaylistEditor::nextFound(bool wrap)
{ {
if (w == Playlists) if (isActiveWindow(Playlists))
Playlists->nextFound(wrap); Playlists.nextFound(wrap);
else if (w == Content) else if (isActiveWindow(Content))
Content->nextFound(wrap); Content.nextFound(wrap);
} }
void PlaylistEditor::prevFound(bool wrap) void PlaylistEditor::prevFound(bool wrap)
{ {
if (w == Playlists) if (isActiveWindow(Playlists))
Playlists->prevFound(wrap); Playlists.prevFound(wrap);
else if (w == Content) else if (isActiveWindow(Content))
Content->prevFound(wrap); Content.prevFound(wrap);
} }
/***********************************************************************/ /***********************************************************************/
@@ -402,7 +402,7 @@ void PlaylistEditor::prevFound(bool wrap)
std::shared_ptr<ProxySongList> PlaylistEditor::getProxySongList() std::shared_ptr<ProxySongList> PlaylistEditor::getProxySongList()
{ {
auto ptr = nullProxySongList(); auto ptr = nullProxySongList();
if (w == Content) if (isActiveWindow(Content))
ptr = contentProxyList(); ptr = contentProxyList();
return ptr; return ptr;
} }
@@ -414,19 +414,19 @@ bool PlaylistEditor::allowsSelection()
void PlaylistEditor::reverseSelection() void PlaylistEditor::reverseSelection()
{ {
if (w == Playlists) if (isActiveWindow(Playlists))
reverseSelectionHelper(Playlists->begin(), Playlists->end()); reverseSelectionHelper(Playlists.begin(), Playlists.end());
else if (w == Content) else if (isActiveWindow(Content))
reverseSelectionHelper(Content->begin(), Content->end()); reverseSelectionHelper(Content.begin(), Content.end());
} }
MPD::SongList PlaylistEditor::getSelectedSongs() MPD::SongList PlaylistEditor::getSelectedSongs()
{ {
MPD::SongList result; MPD::SongList result;
if (w == Playlists) if (isActiveWindow(Playlists))
{ {
bool any_selected = false; bool any_selected = false;
for (auto it = Playlists->begin(); it != Playlists->end(); ++it) for (auto it = Playlists.begin(); it != Playlists.end(); ++it)
{ {
if (it->isSelected()) if (it->isSelected())
{ {
@@ -437,21 +437,21 @@ MPD::SongList PlaylistEditor::getSelectedSongs()
} }
// we don't check for empty result here as it's possible that // we don't check for empty result here as it's possible that
// all selected playlists are empty. // all selected playlists are empty.
if (!any_selected && !Content->empty()) if (!any_selected && !Content.empty())
{ {
withUnfilteredMenu(*Content, [this, &result]() { withUnfilteredMenu(Content, [this, &result]() {
result.insert(result.end(), Content->beginV(), Content->endV()); result.insert(result.end(), Content.beginV(), Content.endV());
}); });
} }
} }
else if (w == Content) else if (isActiveWindow(Content))
{ {
for (auto it = Content->begin(); it != Content->end(); ++it) for (auto it = Content.begin(); it != Content.end(); ++it)
if (it->isSelected()) if (it->isSelected())
result.push_back(it->value()); result.push_back(it->value());
// if no item is selected, add current one // if no item is selected, add current one
if (result.empty() && !Content->empty()) if (result.empty() && !Content.empty())
result.push_back(Content->current().value()); result.push_back(Content.current().value());
} }
return result; return result;
} }
@@ -460,9 +460,9 @@ MPD::SongList PlaylistEditor::getSelectedSongs()
bool PlaylistEditor::previousColumnAvailable() bool PlaylistEditor::previousColumnAvailable()
{ {
if (w == Content) if (isActiveWindow(Content))
{ {
if (!Playlists->reallyEmpty()) if (!Playlists.reallyEmpty())
return true; return true;
} }
return false; return false;
@@ -470,20 +470,20 @@ bool PlaylistEditor::previousColumnAvailable()
void PlaylistEditor::previousColumn() void PlaylistEditor::previousColumn()
{ {
if (w == Content) if (isActiveWindow(Content))
{ {
Content->setHighlightColor(Config.main_highlight_color); Content.setHighlightColor(Config.main_highlight_color);
w->refresh(); w->refresh();
w = Playlists; w = &Playlists;
Playlists->setHighlightColor(Config.active_column_color); Playlists.setHighlightColor(Config.active_column_color);
} }
} }
bool PlaylistEditor::nextColumnAvailable() bool PlaylistEditor::nextColumnAvailable()
{ {
if (w == Playlists) if (isActiveWindow(Playlists))
{ {
if (!Content->reallyEmpty()) if (!Content.reallyEmpty())
return true; return true;
} }
return false; return false;
@@ -491,27 +491,26 @@ bool PlaylistEditor::nextColumnAvailable()
void PlaylistEditor::nextColumn() void PlaylistEditor::nextColumn()
{ {
if (w == Playlists) if (isActiveWindow(Playlists))
{ {
Playlists->setHighlightColor(Config.main_highlight_color); Playlists.setHighlightColor(Config.main_highlight_color);
w->refresh(); w->refresh();
w = Content; w = &Content;
Content->setHighlightColor(Config.active_column_color); Content.setHighlightColor(Config.active_column_color);
} }
} }
/***********************************************************************/ /***********************************************************************/
void PlaylistEditor::Locate(const std::string &name) void PlaylistEditor::Locate(const std::string &name)
{ {
update(); update();
for (size_t i = 0; i < Playlists->size(); ++i) for (size_t i = 0; i < Playlists.size(); ++i)
{ {
if (name == (*Playlists)[i].value()) if (name == Playlists[i].value())
{ {
Playlists->highlight(i); Playlists.highlight(i);
Content->clear(); Content.clear();
break; break;
} }
} }

View File

@@ -76,8 +76,8 @@ struct PlaylistEditor : public Screen<NC::Window *>, public Filterable, public H
bool isContentFiltered(); bool isContentFiltered();
std::shared_ptr<ProxySongList> contentProxyList(); std::shared_ptr<ProxySongList> contentProxyList();
NC::Menu<std::string> *Playlists; NC::Menu<std::string> Playlists;
NC::Menu<MPD::Song> *Content; NC::Menu<MPD::Song> Content;
protected: protected:
virtual bool isLockable() OVERRIDE { return true; } virtual bool isLockable() OVERRIDE { return true; }