menu: make current() return an iterator

This commit is contained in:
Andrzej Rybczak
2014-11-04 22:33:16 +01:00
parent 12772c47f9
commit efdac2058e
13 changed files with 103 additions and 109 deletions

View File

@@ -657,7 +657,7 @@ void DeletePlaylistItems::run()
} }
else if (myScreen->isActiveWindow(myPlaylistEditor->Content)) else if (myScreen->isActiveWindow(myPlaylistEditor->Content))
{ {
std::string playlist = myPlaylistEditor->Playlists.current().value().path(); std::string playlist = myPlaylistEditor->Playlists.current()->value().path();
auto delete_fun = boost::bind(&MPD::Connection::PlaylistDelete, _1, playlist, _2); auto delete_fun = boost::bind(&MPD::Connection::PlaylistDelete, _1, playlist, _2);
Statusbar::print("Deleting items..."); Statusbar::print("Deleting items...");
deleteSelectedSongs(myPlaylistEditor->Content, delete_fun); deleteSelectedSongs(myPlaylistEditor->Content, delete_fun);
@@ -706,7 +706,7 @@ void DeleteBrowserItems::run()
question = boost::format("Delete selected items?"); question = boost::format("Delete selected items?");
else else
{ {
const auto &item = myBrowser->main().current().value(); const auto &item = myBrowser->main().current()->value();
// parent directories are not accepted (and they // parent directories are not accepted (and they
// can't be selected, so in other cases it's fine). // can't be selected, so in other cases it's fine).
if (myBrowser->isParentDirectory(item)) if (myBrowser->isParentDirectory(item))
@@ -721,7 +721,7 @@ void DeleteBrowserItems::run()
auto items = getSelectedOrCurrent( auto items = getSelectedOrCurrent(
myBrowser->main().begin(), myBrowser->main().begin(),
myBrowser->main().end(), myBrowser->main().end(),
myBrowser->main().currentI() myBrowser->main().current()
); );
for (const auto &item : items) for (const auto &item : items)
{ {
@@ -753,12 +753,12 @@ void DeleteStoredPlaylist::run()
question = boost::format("Delete selected playlists?"); question = boost::format("Delete selected playlists?");
else else
question = boost::format("Delete playlist \"%1%\"?") question = boost::format("Delete playlist \"%1%\"?")
% wideShorten(myPlaylistEditor->Playlists.current().value().path(), COLS-question.size()-10); % wideShorten(myPlaylistEditor->Playlists.current()->value().path(), COLS-question.size()-10);
confirmAction(question); confirmAction(question);
auto list = getSelectedOrCurrent( auto list = getSelectedOrCurrent(
myPlaylistEditor->Playlists.begin(), myPlaylistEditor->Playlists.begin(),
myPlaylistEditor->Playlists.end(), myPlaylistEditor->Playlists.end(),
myPlaylistEditor->Playlists.currentI() myPlaylistEditor->Playlists.current()
); );
for (const auto &item : list) for (const auto &item : list)
Mpd.DeletePlaylist(item->value().path()); Mpd.DeletePlaylist(item->value().path());
@@ -903,7 +903,7 @@ 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().path(); std::string playlist = myPlaylistEditor->Playlists.current()->value().path();
auto move_fun = boost::bind(&MPD::Connection::PlaylistMove, _1, playlist, _2, _3); auto move_fun = boost::bind(&MPD::Connection::PlaylistMove, _1, playlist, _2, _3);
moveSelectedItemsUp(myPlaylistEditor->Content, move_fun); moveSelectedItemsUp(myPlaylistEditor->Content, move_fun);
} }
@@ -928,7 +928,7 @@ 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().path(); std::string playlist = myPlaylistEditor->Playlists.current()->value().path();
auto move_fun = boost::bind(&MPD::Connection::PlaylistMove, _1, playlist, _2, _3); auto move_fun = boost::bind(&MPD::Connection::PlaylistMove, _1, playlist, _2, _3);
moveSelectedItemsDown(myPlaylistEditor->Content, move_fun); moveSelectedItemsDown(myPlaylistEditor->Content, move_fun);
} }
@@ -950,7 +950,7 @@ void MoveSelectedItemsTo::run()
else else
{ {
assert(!myPlaylistEditor->Playlists.empty()); assert(!myPlaylistEditor->Playlists.empty());
std::string playlist = myPlaylistEditor->Playlists.current().value().path(); std::string playlist = myPlaylistEditor->Playlists.current()->value().path();
auto move_fun = boost::bind(&MPD::Connection::PlaylistMove, _1, playlist, _2, _3); auto move_fun = boost::bind(&MPD::Connection::PlaylistMove, _1, playlist, _2, _3);
moveSelectedItemsTo(myPlaylistEditor->Content, move_fun); moveSelectedItemsTo(myPlaylistEditor->Content, move_fun);
} }
@@ -976,7 +976,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(), path); Mpd.AddToPlaylist(myPlaylistEditor->Playlists.current()->value().path(), path);
else else
{ {
const char lastfm_url[] = "lastfm://"; const char lastfm_url[] = "lastfm://";
@@ -1336,13 +1336,13 @@ void EditLibraryTag::run()
{ {
Statusbar::ScopedLock slock; Statusbar::ScopedLock slock;
Statusbar::put() << NC::Format::Bold << tagTypeToString(Config.media_lib_primary_tag) << NC::Format::NoBold << ": "; Statusbar::put() << NC::Format::Bold << tagTypeToString(Config.media_lib_primary_tag) << NC::Format::NoBold << ": ";
new_tag = wFooter->prompt(myLibrary->Tags.current().value().tag()); new_tag = wFooter->prompt(myLibrary->Tags.current()->value().tag());
} }
if (!new_tag.empty() && new_tag != myLibrary->Tags.current().value().tag()) if (!new_tag.empty() && new_tag != myLibrary->Tags.current()->value().tag())
{ {
Statusbar::print("Updating tags..."); Statusbar::print("Updating tags...");
Mpd.StartSearch(true); Mpd.StartSearch(true);
Mpd.AddSearch(Config.media_lib_primary_tag, myLibrary->Tags.current().value().tag()); Mpd.AddSearch(Config.media_lib_primary_tag, myLibrary->Tags.current()->value().tag());
MPD::MutableSong::SetFunction set = tagTypeToSetFunction(Config.media_lib_primary_tag); MPD::MutableSong::SetFunction set = tagTypeToSetFunction(Config.media_lib_primary_tag);
assert(set); assert(set);
bool success = true; bool success = true;
@@ -1395,9 +1395,9 @@ void EditLibraryAlbum::run()
{ {
Statusbar::ScopedLock slock; Statusbar::ScopedLock slock;
Statusbar::put() << NC::Format::Bold << "Album: " << NC::Format::NoBold; Statusbar::put() << NC::Format::Bold << "Album: " << NC::Format::NoBold;
new_album = wFooter->prompt(myLibrary->Albums.current().value().entry().album()); new_album = wFooter->prompt(myLibrary->Albums.current()->value().entry().album());
} }
if (!new_album.empty() && new_album != myLibrary->Albums.current().value().entry().album()) if (!new_album.empty() && new_album != myLibrary->Albums.current()->value().entry().album())
{ {
bool success = 1; bool success = 1;
Statusbar::print("Updating tags..."); Statusbar::print("Updating tags...");
@@ -1435,7 +1435,7 @@ bool EditDirectoryName::canBeRun() const
{ {
return ((myScreen == myBrowser return ((myScreen == myBrowser
&& !myBrowser->main().empty() && !myBrowser->main().empty()
&& myBrowser->main().current().value().type() == MPD::Item::Type::Directory) && myBrowser->main().current()->value().type() == MPD::Item::Type::Directory)
# ifdef HAVE_TAGLIB_H # ifdef HAVE_TAGLIB_H
|| (myScreen->activeWindow() == myTagEditor->Dirs || (myScreen->activeWindow() == myTagEditor->Dirs
&& !myTagEditor->Dirs->empty() && !myTagEditor->Dirs->empty()
@@ -1450,7 +1450,7 @@ void EditDirectoryName::run()
// FIXME: use boost::filesystem and better error reporting // FIXME: use boost::filesystem and better error reporting
if (myScreen == myBrowser) if (myScreen == myBrowser)
{ {
std::string old_dir = myBrowser->main().current().value().directory().path(), new_dir; std::string old_dir = myBrowser->main().current()->value().directory().path(), new_dir;
{ {
Statusbar::ScopedLock slock; Statusbar::ScopedLock slock;
Statusbar::put() << NC::Format::Bold << "Directory: " << NC::Format::NoBold; Statusbar::put() << NC::Format::Bold << "Directory: " << NC::Format::NoBold;
@@ -1485,7 +1485,7 @@ void EditDirectoryName::run()
# ifdef HAVE_TAGLIB_H # ifdef HAVE_TAGLIB_H
else if (myScreen->activeWindow() == myTagEditor->Dirs) else if (myScreen->activeWindow() == myTagEditor->Dirs)
{ {
std::string old_dir = myTagEditor->Dirs->current().value().first, new_dir; std::string old_dir = myTagEditor->Dirs->current()->value().first, new_dir;
{ {
Statusbar::ScopedLock slock; Statusbar::ScopedLock slock;
Statusbar::put() << NC::Format::Bold << "Directory: " << NC::Format::NoBold; Statusbar::put() << NC::Format::Bold << "Directory: " << NC::Format::NoBold;
@@ -1517,7 +1517,7 @@ bool EditPlaylistName::canBeRun() const
&& !myPlaylistEditor->Playlists.empty()) && !myPlaylistEditor->Playlists.empty())
|| (myScreen == myBrowser || (myScreen == myBrowser
&& !myBrowser->main().empty() && !myBrowser->main().empty()
&& myBrowser->main().current().value().type() == MPD::Item::Type::Playlist); && myBrowser->main().current()->value().type() == MPD::Item::Type::Playlist);
} }
void EditPlaylistName::run() void EditPlaylistName::run()
@@ -1525,9 +1525,9 @@ void EditPlaylistName::run()
using Global::wFooter; using Global::wFooter;
std::string old_name, new_name; std::string old_name, new_name;
if (myScreen->isActiveWindow(myPlaylistEditor->Playlists)) if (myScreen->isActiveWindow(myPlaylistEditor->Playlists))
old_name = myPlaylistEditor->Playlists.current().value().path(); old_name = myPlaylistEditor->Playlists.current()->value().path();
else else
old_name = myBrowser->main().current().value().playlist().path(); old_name = myBrowser->main().current()->value().playlist().path();
{ {
Statusbar::ScopedLock slock; Statusbar::ScopedLock slock;
Statusbar::put() << NC::Format::Bold << "Playlist: " << NC::Format::NoBold; Statusbar::put() << NC::Format::Bold << "Playlist: " << NC::Format::NoBold;
@@ -1576,12 +1576,12 @@ void JumpToMediaLibrary::run()
bool JumpToPlaylistEditor::canBeRun() const bool JumpToPlaylistEditor::canBeRun() const
{ {
return myScreen == myBrowser return myScreen == myBrowser
&& myBrowser->main().current().value().type() == MPD::Item::Type::Playlist; && myBrowser->main().current()->value().type() == MPD::Item::Type::Playlist;
} }
void JumpToPlaylistEditor::run() void JumpToPlaylistEditor::run()
{ {
myPlaylistEditor->Locate(myBrowser->main().current().value().playlist()); myPlaylistEditor->Locate(myBrowser->main().current()->value().playlist());
} }
void ToggleScreenLock::run() void ToggleScreenLock::run()
@@ -1778,7 +1778,7 @@ void CropPlaylist::run()
if (w.size() <= 1) if (w.size() <= 1)
return; return;
assert(!myPlaylistEditor->Playlists.empty()); assert(!myPlaylistEditor->Playlists.empty());
std::string playlist = myPlaylistEditor->Playlists.current().value().path(); std::string playlist = myPlaylistEditor->Playlists.current()->value().path();
if (Config.ask_before_clearing_playlists) if (Config.ask_before_clearing_playlists)
confirmAction(boost::format("Do you really want to crop playlist \"%1%\"?") % playlist); confirmAction(boost::format("Do you really want to crop playlist \"%1%\"?") % playlist);
selectCurrentIfNoneSelected(w); selectCurrentIfNoneSelected(w);
@@ -1808,7 +1808,7 @@ void ClearPlaylist::run()
{ {
if (myPlaylistEditor->Playlists.empty()) if (myPlaylistEditor->Playlists.empty())
return; return;
std::string playlist = myPlaylistEditor->Playlists.current().value().path(); std::string playlist = myPlaylistEditor->Playlists.current()->value().path();
if (Config.ask_before_clearing_playlists) if (Config.ask_before_clearing_playlists)
confirmAction(boost::format("Do you really want to clear playlist \"%1%\"?") % playlist); confirmAction(boost::format("Do you really want to clear playlist \"%1%\"?") % playlist);
auto delete_fun = boost::bind(&MPD::Connection::PlaylistDelete, _1, playlist, _2); auto delete_fun = boost::bind(&MPD::Connection::PlaylistDelete, _1, playlist, _2);
@@ -2312,7 +2312,7 @@ void ShowArtistInfo::run()
{ {
assert(!myLibrary->Tags.empty()); assert(!myLibrary->Tags.empty());
assert(Config.media_lib_primary_tag == MPD_TAG_ARTIST); assert(Config.media_lib_primary_tag == MPD_TAG_ARTIST);
artist = myLibrary->Tags.current().value().tag(); artist = myLibrary->Tags.current()->value().tag();
} }
else else
{ {

View File

@@ -127,7 +127,7 @@ void Browser::enterPressed()
if (w.empty()) if (w.empty())
return; return;
const MPD::Item &item = w.current().value(); const MPD::Item &item = w.current()->value();
switch (item.type()) switch (item.type())
{ {
case MPD::Item::Type::Directory: case MPD::Item::Type::Directory:
@@ -170,7 +170,7 @@ void Browser::spacePressed()
return; return;
} }
const MPD::Item &item = w.current().value(); const MPD::Item &item = w.current()->value();
// ignore parent directory // ignore parent directory
if (isParentDirectory(item)) if (isParentDirectory(item))
return; return;
@@ -212,12 +212,12 @@ void Browser::mouseButtonPressed(MEVENT me)
if (me.bstate & (BUTTON1_PRESSED | BUTTON3_PRESSED)) if (me.bstate & (BUTTON1_PRESSED | BUTTON3_PRESSED))
{ {
w.Goto(me.y); w.Goto(me.y);
switch (w.current().value().type()) switch (w.current()->value().type())
{ {
case MPD::Item::Type::Directory: case MPD::Item::Type::Directory:
if (me.bstate & BUTTON1_PRESSED) if (me.bstate & BUTTON1_PRESSED)
{ {
getDirectory(w.current().value().directory().path()); getDirectory(w.current()->value().directory().path());
drawHeader(); drawHeader();
} }
else else
@@ -369,7 +369,7 @@ std::vector<MPD::Song> Browser::getSelectedSongs()
item_handler(item.value()); item_handler(item.value());
// if no item is selected, add current one // if no item is selected, add current one
if (songs.empty() && !w.empty()) if (songs.empty() && !w.empty())
item_handler(w.current().value()); item_handler(w.current()->value());
return songs; return songs;
} }

View File

@@ -49,7 +49,7 @@ void searchForward(NC::Menu<ItemT> &m, const PredicateT &pred, bool wrap)
{ {
if (!pred.defined()) if (!pred.defined())
return; return;
auto it = wrappedSearch(m.begin(), m.currentI(), m.end(), pred, wrap); auto it = wrappedSearch(m.begin(), m.current(), m.end(), pred, wrap);
if (it != m.end()) if (it != m.end())
m.highlight(it-m.begin()); m.highlight(it-m.begin());
} }
@@ -59,7 +59,7 @@ void searchBackward(NC::Menu<ItemT> &m, const PredicateT &pred, bool wrap)
{ {
if (!pred.defined()) if (!pred.defined())
return; return;
auto it = wrappedSearch(m.rbegin(), m.currentRI(), m.rend(), pred, wrap); auto it = wrappedSearch(m.rbegin(), m.rcurrent(), m.rend(), pred, wrap);
if (it != m.rend()) if (it != m.rend())
m.highlight(m.size()-1-(it-m.rbegin())); m.highlight(m.size()-1-(it-m.rbegin()));
} }
@@ -130,7 +130,7 @@ template <typename T>
void selectCurrentIfNoneSelected(NC::Menu<T> &m) void selectCurrentIfNoneSelected(NC::Menu<T> &m)
{ {
if (!hasSelected(m.begin(), m.end())) if (!hasSelected(m.begin(), m.end()))
m.current().setSelected(true); m.current()->setSelected(true);
} }
template <typename Iterator> template <typename Iterator>
@@ -264,7 +264,7 @@ void moveSelectedItemsDown(NC::Menu<MPD::Song> &m, F swap_fun)
template <typename F> template <typename F>
void moveSelectedItemsTo(NC::Menu<MPD::Song> &m, F move_fun) void moveSelectedItemsTo(NC::Menu<MPD::Song> &m, F move_fun)
{ {
auto cur_ptr = &m.current().value(); auto cur_ptr = &m.current()->value();
withUnfilteredMenu(m, [&]() { withUnfilteredMenu(m, [&]() {
// this is kinda shitty, but there is no other way to know // this is kinda shitty, but there is no other way to know
// what position current item has in unfiltered menu. // what position current item has in unfiltered menu.

View File

@@ -344,7 +344,7 @@ void MediaLibrary::update()
) )
{ {
m_albums_update_request = false; m_albums_update_request = false;
auto &primary_tag = Tags.current().value().tag(); auto &primary_tag = Tags.current()->value().tag();
Mpd.StartSearch(true); Mpd.StartSearch(true);
Mpd.AddSearch(Config.media_lib_primary_tag, primary_tag); Mpd.AddSearch(Config.media_lib_primary_tag, primary_tag);
std::map<std::tuple<std::string, std::string>, time_t> albums; std::map<std::tuple<std::string, std::string>, time_t> albums;
@@ -392,7 +392,7 @@ void MediaLibrary::update()
) )
{ {
m_songs_update_request = false; m_songs_update_request = false;
auto &album = Albums.current().value(); auto &album = Albums.current()->value();
Mpd.StartSearch(true); Mpd.StartSearch(true);
Mpd.AddSearch(Config.media_lib_primary_tag, album.entry().tag()); Mpd.AddSearch(Config.media_lib_primary_tag, album.entry().tag());
if (!album.isAllTracksEntry()) if (!album.isAllTracksEntry())
@@ -448,7 +448,7 @@ void MediaLibrary::spacePressed()
} }
else if (isActiveWindow(Albums)) else if (isActiveWindow(Albums))
{ {
if (!Albums.current().value().isAllTracksEntry()) if (!Albums.current()->value().isAllTracksEntry())
{ {
size_t idx = Albums.choice(); size_t idx = Albums.choice();
Albums[idx].setSelected(!Albums[idx].isSelected()); Albums[idx].setSelected(!Albums[idx].isSelected());
@@ -750,7 +750,7 @@ std::vector<MPD::Song> MediaLibrary::getSelectedSongs()
} }
// if no item is selected, add current one // if no item is selected, add current one
if (!any_selected && !Tags.empty()) if (!any_selected && !Tags.empty())
tag_handler(Tags.current().value().tag()); tag_handler(Tags.current()->value().tag());
} }
else if (isActiveWindow(Albums)) else if (isActiveWindow(Albums))
{ {
@@ -766,7 +766,7 @@ std::vector<MPD::Song> MediaLibrary::getSelectedSongs()
Mpd.AddSearch(Config.media_lib_primary_tag, sc.entry().tag()); Mpd.AddSearch(Config.media_lib_primary_tag, sc.entry().tag());
else else
Mpd.AddSearch(Config.media_lib_primary_tag, Mpd.AddSearch(Config.media_lib_primary_tag,
Tags.current().value().tag()); Tags.current()->value().tag());
Mpd.AddSearch(MPD_TAG_ALBUM, sc.entry().album()); Mpd.AddSearch(MPD_TAG_ALBUM, sc.entry().album());
Mpd.AddSearch(MPD_TAG_DATE, sc.entry().date()); Mpd.AddSearch(MPD_TAG_DATE, sc.entry().date());
size_t begin = result.size(); size_t begin = result.size();
@@ -793,7 +793,7 @@ std::vector<MPD::Song> MediaLibrary::getSelectedSongs()
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() && !Songs.empty()) if (result.empty() && !Songs.empty())
result.push_back(Songs.current().value()); result.push_back(Songs.current()->value());
} }
return result; return result;
} }
@@ -979,7 +979,7 @@ void MediaLibrary::LocateSong(const MPD::Song &s)
Tags.showAll(); Tags.showAll();
if (Tags.empty()) if (Tags.empty())
update(); update();
if (primary_tag != Tags.current().value().tag()) if (primary_tag != Tags.current()->value().tag())
{ {
for (size_t i = 0; i < Tags.size(); ++i) for (size_t i = 0; i < Tags.size(); ++i)
{ {
@@ -1000,9 +1000,9 @@ void MediaLibrary::LocateSong(const MPD::Song &s)
std::string album = s.getAlbum(); std::string album = s.getAlbum();
std::string date = s.getDate(); std::string date = s.getDate();
if ((hasTwoColumns && Albums.current().value().entry().tag() != primary_tag) if ((hasTwoColumns && Albums.current()->value().entry().tag() != primary_tag)
|| album != Albums.current().value().entry().album() || album != Albums.current()->value().entry().album()
|| date != Albums.current().value().entry().date()) || date != Albums.current()->value().entry().date())
{ {
for (size_t i = 0; i < Albums.size(); ++i) for (size_t i = 0; i < Albums.size(); ++i)
{ {
@@ -1021,7 +1021,7 @@ void MediaLibrary::LocateSong(const MPD::Song &s)
if (Songs.empty()) if (Songs.empty())
update(); update();
if (s != Songs.current().value()) if (s != Songs.current()->value())
{ {
for (size_t i = 0; i < Songs.size(); ++i) for (size_t i = 0; i < Songs.size(); ++i)
{ {
@@ -1043,14 +1043,14 @@ void MediaLibrary::LocateSong(const MPD::Song &s)
void MediaLibrary::AddToPlaylist(bool add_n_play) void MediaLibrary::AddToPlaylist(bool add_n_play)
{ {
if (isActiveWindow(Songs) && !Songs.empty()) if (isActiveWindow(Songs) && !Songs.empty())
addSongToPlaylist(Songs.current().value(), add_n_play); addSongToPlaylist(Songs.current()->value(), add_n_play);
else else
{ {
if ((!Tags.empty() && isActiveWindow(Tags)) if ((!Tags.empty() && isActiveWindow(Tags))
|| (isActiveWindow(Albums) && Albums.current().value().isAllTracksEntry())) || (isActiveWindow(Albums) && Albums.current()->value().isAllTracksEntry()))
{ {
Mpd.StartSearch(true); Mpd.StartSearch(true);
Mpd.AddSearch(Config.media_lib_primary_tag, Tags.current().value().tag()); Mpd.AddSearch(Config.media_lib_primary_tag, Tags.current()->value().tag());
std::vector<MPD::Song> list( std::vector<MPD::Song> list(
std::make_move_iterator(Mpd.CommitSearchSongs()), std::make_move_iterator(Mpd.CommitSearchSongs()),
std::make_move_iterator(MPD::SongIterator()) std::make_move_iterator(MPD::SongIterator())
@@ -1059,7 +1059,7 @@ void MediaLibrary::AddToPlaylist(bool add_n_play)
std::string tag_type = boost::locale::to_lower( std::string tag_type = boost::locale::to_lower(
tagTypeToString(Config.media_lib_primary_tag)); tagTypeToString(Config.media_lib_primary_tag));
Statusbar::printf("Songs with %1% \"%2%\" added%3%", Statusbar::printf("Songs with %1% \"%2%\" added%3%",
tag_type, Tags.current().value().tag(), withErrors(success) tag_type, Tags.current()->value().tag(), withErrors(success)
); );
} }
else if (isActiveWindow(Albums)) else if (isActiveWindow(Albums))
@@ -1069,7 +1069,7 @@ void MediaLibrary::AddToPlaylist(bool add_n_play)
success = addSongsToPlaylist(Songs.beginV(), Songs.endV(), add_n_play, -1); success = addSongsToPlaylist(Songs.beginV(), Songs.endV(), add_n_play, -1);
}); });
Statusbar::printf("Songs from album \"%1%\" added%2%", Statusbar::printf("Songs from album \"%1%\" added%2%",
Albums.current().value().entry().album(), withErrors(success) Albums.current()->value().entry().album(), withErrors(success)
); );
} }
} }

View File

@@ -265,12 +265,6 @@ public:
/// @throw List::InvalidItem if requested item is separator /// @throw List::InvalidItem if requested item is separator
const Menu<ItemT>::Item &back() const { return *m_options_ptr->back(); } const Menu<ItemT>::Item &back() const { return *m_options_ptr->back(); }
/// @return reference to curently highlighted object
Menu<ItemT>::Item &current() { return *(*m_options_ptr)[m_highlight]; }
/// @return const reference to curently highlighted object
const Menu<ItemT>::Item &current() const { return *(*m_options_ptr)[m_highlight]; }
/// @param pos requested position /// @param pos requested position
/// @return reference to item at given position /// @return reference to item at given position
/// @throw std::out_of_range if given position is out of range /// @throw std::out_of_range if given position is out of range
@@ -289,15 +283,15 @@ public:
/// @return const reference to item at given position /// @return const reference to item at given position
Menu<ItemT>::Item &operator[](size_t pos) { return *(*m_options_ptr)[pos]; } Menu<ItemT>::Item &operator[](size_t pos) { return *(*m_options_ptr)[pos]; }
Iterator currentI() { return Iterator(m_options_ptr->begin() + m_highlight); } Iterator current() { return Iterator(m_options_ptr->begin() + m_highlight); }
ConstIterator currentI() const { return ConstIterator(m_options_ptr->begin() + m_highlight); } ConstIterator current() const { return ConstIterator(m_options_ptr->begin() + m_highlight); }
ReverseIterator currentRI() { return ReverseIterator(++currentI()); } ReverseIterator rcurrent() { return ReverseIterator(++current()); }
ConstReverseIterator currentRI() const { return ReverseIterator(++currentI()); } ConstReverseIterator rcurrent() const { return ReverseIterator(++current()); }
ValueIterator currentVI() { return ValueIterator(m_options_ptr->begin() + m_highlight); } ValueIterator currentV() { return ValueIterator(m_options_ptr->begin() + m_highlight); }
ConstValueIterator currentVI() const { return ConstValueIterator(m_options_ptr->begin() + m_highlight); } ConstValueIterator currentV() const { return ConstValueIterator(m_options_ptr->begin() + m_highlight); }
ReverseValueIterator currentRVI() { return ReverseValueIterator(++currentVI()); } ReverseValueIterator rcurrentV() { return ReverseValueIterator(++currentV()); }
ConstReverseValueIterator currentRVI() const { return ConstReverseValueIterator(++currentVI()); } ConstReverseValueIterator rcurrentV() const { return ConstReverseValueIterator(++currentV()); }
Iterator begin() { return Iterator(m_options_ptr->begin()); } Iterator begin() { return Iterator(m_options_ptr->begin()); }
ConstIterator begin() const { return ConstIterator(m_options_ptr->begin()); } ConstIterator begin() const { return ConstIterator(m_options_ptr->begin()); }

View File

@@ -70,15 +70,15 @@ std::wstring Outputs::title()
void Outputs::enterPressed() void Outputs::enterPressed()
{ {
if (w.current().value().enabled()) if (w.current()->value().enabled())
{ {
Mpd.DisableOutput(w.choice()); Mpd.DisableOutput(w.choice());
Statusbar::printf("Output \"%s\" disabled", w.current().value().name()); Statusbar::printf("Output \"%s\" disabled", w.current()->value().name());
} }
else else
{ {
Mpd.EnableOutput(w.choice()); Mpd.EnableOutput(w.choice());
Statusbar::printf("Output \"%s\" enabled", w.current().value().name()); Statusbar::printf("Output \"%s\" enabled", w.current()->value().name());
} }
} }

View File

@@ -119,14 +119,14 @@ void Playlist::update()
void Playlist::enterPressed() void Playlist::enterPressed()
{ {
if (!w.empty()) if (!w.empty())
Mpd.PlayID(w.current().value().getID()); Mpd.PlayID(w.current()->value().getID());
} }
void Playlist::spacePressed() void Playlist::spacePressed()
{ {
if (!w.empty()) if (!w.empty())
{ {
w.current().setSelected(!w.current().isSelected()); w.current()->setSelected(!w.current()->isSelected());
w.scroll(NC::Scroll::Down); w.scroll(NC::Scroll::Down);
} }
} }
@@ -235,7 +235,7 @@ std::vector<MPD::Song> Playlist::getSelectedSongs()
if (it->isSelected()) if (it->isSelected())
result.push_back(it->value()); result.push_back(it->value());
if (result.empty() && !w.empty()) if (result.empty() && !w.empty())
result.push_back(w.current().value()); result.push_back(w.current()->value());
return result; return result;
} }
@@ -327,7 +327,7 @@ std::string Playlist::getTotalLength()
void Playlist::SetSelectedItemsPriority(int prio) void Playlist::SetSelectedItemsPriority(int prio)
{ {
auto list = getSelectedOrCurrent(w.begin(), w.end(), w.currentI()); auto list = getSelectedOrCurrent(w.begin(), w.end(), w.current());
Mpd.StartCommandsList(); Mpd.StartCommandsList();
for (auto it = list.begin(); it != list.end(); ++it) for (auto it = list.begin(); it != list.end(); ++it)
Mpd.SetPriority((*it)->value(), prio); Mpd.SetPriority((*it)->value(), prio);

View File

@@ -164,7 +164,7 @@ void PlaylistEditor::update()
{ {
withUnfilteredMenuReapplyFilter(Content, [this]() { withUnfilteredMenuReapplyFilter(Content, [this]() {
size_t idx = 0; size_t idx = 0;
MPD::SongIterator s = Mpd.GetPlaylistContent(Playlists.current().value().path()), end; MPD::SongIterator s = Mpd.GetPlaylistContent(Playlists.current()->value().path()), end;
for (; s != end; ++s, ++idx) for (; s != end; ++s, ++idx)
{ {
bool is_bold = myPlaylist->checkForSong(*s); bool is_bold = myPlaylist->checkForSong(*s);
@@ -247,11 +247,11 @@ void PlaylistEditor::AddToPlaylist(bool add_n_play)
success = addSongsToPlaylist(Content.beginV(), Content.endV(), add_n_play, -1); success = addSongsToPlaylist(Content.beginV(), Content.endV(), add_n_play, -1);
}); });
Statusbar::printf("Playlist \"%1%\" loaded%2%", Statusbar::printf("Playlist \"%1%\" loaded%2%",
Playlists.current().value().path(), withErrors(success) Playlists.current()->value().path(), withErrors(success)
); );
} }
else if (isActiveWindow(Content) && !Content.empty()) else if (isActiveWindow(Content) && !Content.empty())
addSongToPlaylist(Content.current().value(), add_n_play); addSongToPlaylist(Content.current()->value(), add_n_play);
if (!add_n_play) if (!add_n_play)
w->scroll(NC::Scroll::Down); w->scroll(NC::Scroll::Down);
@@ -270,7 +270,7 @@ void PlaylistEditor::spacePressed()
{ {
if (!Playlists.empty()) if (!Playlists.empty())
{ {
Playlists.current().setSelected(!Playlists.current().isSelected()); Playlists.current()->setSelected(!Playlists.current()->isSelected());
Playlists.scroll(NC::Scroll::Down); Playlists.scroll(NC::Scroll::Down);
} }
} }
@@ -278,7 +278,7 @@ void PlaylistEditor::spacePressed()
{ {
if (!Content.empty()) if (!Content.empty())
{ {
Content.current().setSelected(!Content.current().isSelected()); Content.current()->setSelected(!Content.current()->isSelected());
Content.scroll(NC::Scroll::Down); Content.scroll(NC::Scroll::Down);
} }
} }
@@ -502,7 +502,7 @@ std::vector<MPD::Song> PlaylistEditor::getSelectedSongs()
result.push_back(e.value()); result.push_back(e.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;
} }

View File

@@ -150,7 +150,7 @@ void SearchEngine::enterPressed()
{ {
size_t option = w.choice(); size_t option = w.choice();
if (option > ConstraintsNumber && option < SearchButton) if (option > ConstraintsNumber && option < SearchButton)
w.current().value().buffer().clear(); w.current()->value().buffer().clear();
if (option < ConstraintsNumber) if (option < ConstraintsNumber)
{ {
@@ -158,21 +158,21 @@ void SearchEngine::enterPressed()
std::string constraint = ConstraintsNames[option]; std::string constraint = ConstraintsNames[option];
Statusbar::put() << NC::Format::Bold << constraint << NC::Format::NoBold << ": "; Statusbar::put() << NC::Format::Bold << constraint << NC::Format::NoBold << ": ";
itsConstraints[option] = Global::wFooter->prompt(itsConstraints[option]); itsConstraints[option] = Global::wFooter->prompt(itsConstraints[option]);
w.current().value().buffer().clear(); w.current()->value().buffer().clear();
constraint.resize(13, ' '); constraint.resize(13, ' ');
w.current().value().buffer() << NC::Format::Bold << constraint << NC::Format::NoBold << ": "; w.current()->value().buffer() << NC::Format::Bold << constraint << NC::Format::NoBold << ": ";
ShowTag(w.current().value().buffer(), itsConstraints[option]); ShowTag(w.current()->value().buffer(), itsConstraints[option]);
} }
else if (option == ConstraintsNumber+1) else if (option == ConstraintsNumber+1)
{ {
Config.search_in_db = !Config.search_in_db; Config.search_in_db = !Config.search_in_db;
w.current().value().buffer() << NC::Format::Bold << "Search in:" << NC::Format::NoBold << ' ' << (Config.search_in_db ? "Database" : "Current playlist"); w.current()->value().buffer() << NC::Format::Bold << "Search in:" << NC::Format::NoBold << ' ' << (Config.search_in_db ? "Database" : "Current playlist");
} }
else if (option == ConstraintsNumber+2) else if (option == ConstraintsNumber+2)
{ {
if (!*++SearchMode) if (!*++SearchMode)
SearchMode = &SearchModes[0]; SearchMode = &SearchModes[0];
w.current().value().buffer() << NC::Format::Bold << "Search mode:" << NC::Format::NoBold << ' ' << *SearchMode; w.current()->value().buffer() << NC::Format::Bold << "Search mode:" << NC::Format::NoBold << ' ' << *SearchMode;
} }
else if (option == SearchButton) else if (option == SearchButton)
{ {
@@ -207,22 +207,22 @@ void SearchEngine::enterPressed()
reset(); reset();
} }
else else
addSongToPlaylist(w.current().value().song(), true); addSongToPlaylist(w.current()->value().song(), true);
} }
void SearchEngine::spacePressed() void SearchEngine::spacePressed()
{ {
if (!w.current().value().isSong()) if (!w.current()->value().isSong())
return; return;
if (Config.space_selects) if (Config.space_selects)
{ {
w.current().setSelected(!w.current().isSelected()); w.current()->setSelected(!w.current()->isSelected());
w.scroll(NC::Scroll::Down); w.scroll(NC::Scroll::Down);
return; return;
} }
addSongToPlaylist(w.current().value().song(), false); addSongToPlaylist(w.current()->value().song(), false);
w.scroll(NC::Scroll::Down); w.scroll(NC::Scroll::Down);
} }
@@ -333,7 +333,7 @@ ProxySongList SearchEngine::proxySongList()
bool SearchEngine::allowsSelection() bool SearchEngine::allowsSelection()
{ {
return w.current().value().isSong(); return w.current()->value().isSong();
} }
void SearchEngine::reverseSelection() void SearchEngine::reverseSelection()
@@ -355,8 +355,8 @@ std::vector<MPD::Song> SearchEngine::getSelectedSongs()
// if no item is selected, add current one // if no item is selected, add current one
if (result.empty() && !w.empty()) if (result.empty() && !w.empty())
{ {
assert(w.current().value().isSong()); assert(w.current()->value().isSong());
result.push_back(w.current().value().song()); result.push_back(w.current()->value().song());
} }
return result; return result;
} }

View File

@@ -163,7 +163,7 @@ std::wstring SelectedItemsAdder::title()
void SelectedItemsAdder::enterPressed() void SelectedItemsAdder::enterPressed()
{ {
w->current().value().run(); w->current()->value().run();
} }
void SelectedItemsAdder::mouseButtonPressed(MEVENT me) void SelectedItemsAdder::mouseButtonPressed(MEVENT me)
@@ -282,7 +282,7 @@ void SelectedItemsAdder::addAfterCurrentAlbum() const
void SelectedItemsAdder::addAfterHighlightedSong() const void SelectedItemsAdder::addAfterHighlightedSong() const
{ {
size_t pos = myPlaylist->main().current().value().getPosition(); size_t pos = myPlaylist->main().current()->value().getPosition();
++pos; ++pos;
bool success = addSongsToPlaylist(m_selected_items.begin(), m_selected_items.end(), false, pos); bool success = addSongsToPlaylist(m_selected_items.begin(), m_selected_items.end(), false, pos);
exitSuccessfully(success); exitSuccessfully(success);

View File

@@ -110,7 +110,7 @@ std::wstring SortPlaylistDialog::title()
void SortPlaylistDialog::enterPressed() void SortPlaylistDialog::enterPressed()
{ {
w.current().value().run(); w.current()->value().run();
} }
void SortPlaylistDialog::mouseButtonPressed(MEVENT me) void SortPlaylistDialog::mouseButtonPressed(MEVENT me)
@@ -130,7 +130,7 @@ void SortPlaylistDialog::mouseButtonPressed(MEVENT me)
void SortPlaylistDialog::moveSortOrderDown() void SortPlaylistDialog::moveSortOrderDown()
{ {
auto cur = w.currentVI(); auto cur = w.currentV();
if ((cur+1)->item().second) if ((cur+1)->item().second)
{ {
std::iter_swap(cur, cur+1); std::iter_swap(cur, cur+1);
@@ -140,7 +140,7 @@ void SortPlaylistDialog::moveSortOrderDown()
void SortPlaylistDialog::moveSortOrderUp() void SortPlaylistDialog::moveSortOrderUp()
{ {
auto cur = w.currentVI(); auto cur = w.currentV();
if (cur > w.beginV() && cur->item().second) if (cur > w.beginV() && cur->item().second)
{ {
std::iter_swap(cur, cur-1); std::iter_swap(cur, cur-1);

View File

@@ -254,7 +254,7 @@ void TagEditor::update()
if (Tags->reallyEmpty()) if (Tags->reallyEmpty())
{ {
Tags->reset(); Tags->reset();
MPD::SongIterator s = Mpd.GetSongs(Dirs->current().value().second), end; MPD::SongIterator s = Mpd.GetSongs(Dirs->current()->value().second), end;
for (; s != end; ++s) for (; s != end; ++s)
Tags->addItem(std::move(*s)); Tags->addItem(std::move(*s));
std::sort(Tags->beginV(), Tags->endV(), std::sort(Tags->beginV(), Tags->endV(),
@@ -279,13 +279,13 @@ void TagEditor::enterPressed()
if (w == Dirs) if (w == Dirs)
{ {
MPD::DirectoryIterator directory = Mpd.GetDirectories(Dirs->current().value().second), end; MPD::DirectoryIterator directory = Mpd.GetDirectories(Dirs->current()->value().second), end;
bool has_subdirs = directory != end; bool has_subdirs = directory != end;
directory.finish(); directory.finish();
if (has_subdirs) if (has_subdirs)
{ {
itsHighlightedDir = itsBrowsedDir; itsHighlightedDir = itsBrowsedDir;
itsBrowsedDir = Dirs->current().value().second; itsBrowsedDir = Dirs->current()->value().second;
Dirs->clear(); Dirs->clear();
Dirs->reset(); Dirs->reset();
} }
@@ -435,7 +435,7 @@ void TagEditor::enterPressed()
} }
else // list of patterns else // list of patterns
{ {
Config.pattern = FParser->current().value(); Config.pattern = FParser->current()->value();
FParser->at(0).value() = "Pattern: " + Config.pattern; FParser->at(0).value() = "Pattern: " + Config.pattern;
} }
@@ -489,18 +489,18 @@ void TagEditor::enterPressed()
if (id > 0 && w == TagTypes) if (id > 0 && w == TagTypes)
{ {
Statusbar::ScopedLock slock; Statusbar::ScopedLock slock;
Statusbar::put() << NC::Format::Bold << TagTypes->current().value() << NC::Format::NoBold << ": "; Statusbar::put() << NC::Format::Bold << TagTypes->current()->value() << NC::Format::NoBold << ": ";
std::string new_tag = wFooter->prompt(Tags->current().value().getTags(get, Config.tags_separator)); std::string new_tag = wFooter->prompt(Tags->current()->value().getTags(get, Config.tags_separator));
for (auto it = EditedSongs.begin(); it != EditedSongs.end(); ++it) for (auto it = EditedSongs.begin(); it != EditedSongs.end(); ++it)
(*it)->setTags(set, new_tag, Config.tags_separator); (*it)->setTags(set, new_tag, Config.tags_separator);
} }
else if (w == Tags) else if (w == Tags)
{ {
Statusbar::ScopedLock slock; Statusbar::ScopedLock slock;
Statusbar::put() << NC::Format::Bold << TagTypes->current().value() << NC::Format::NoBold << ": "; Statusbar::put() << NC::Format::Bold << TagTypes->current()->value() << NC::Format::NoBold << ": ";
std::string new_tag = wFooter->prompt(Tags->current().value().getTags(get, Config.tags_separator)); std::string new_tag = wFooter->prompt(Tags->current()->value().getTags(get, Config.tags_separator));
if (new_tag != Tags->current().value().getTags(get, Config.tags_separator)) if (new_tag != Tags->current()->value().getTags(get, Config.tags_separator))
Tags->current().value().setTags(set, new_tag, Config.tags_separator); Tags->current()->value().setTags(set, new_tag, Config.tags_separator);
Tags->scroll(NC::Scroll::Down); Tags->scroll(NC::Scroll::Down);
} }
} }
@@ -516,7 +516,7 @@ void TagEditor::enterPressed()
else if (w == Tags) else if (w == Tags)
{ {
Statusbar::ScopedLock slock; Statusbar::ScopedLock slock;
MPD::MutableSong &s = Tags->current().value(); MPD::MutableSong &s = Tags->current()->value();
std::string old_name = s.getNewName().empty() ? s.getName() : s.getNewName(); std::string old_name = s.getNewName().empty() ? s.getName() : s.getNewName();
size_t last_dot = old_name.rfind("."); size_t last_dot = old_name.rfind(".");
std::string extension = old_name.substr(last_dot); std::string extension = old_name.substr(last_dot);
@@ -583,7 +583,7 @@ void TagEditor::spacePressed()
{ {
if (w == Tags && !Tags->empty()) if (w == Tags && !Tags->empty())
{ {
Tags->current().setSelected(!Tags->current().isSelected()); Tags->current()->setSelected(!Tags->current()->isSelected());
w->scroll(NC::Scroll::Down); w->scroll(NC::Scroll::Down);
} }
} }
@@ -854,7 +854,7 @@ std::vector<MPD::Song> TagEditor::getSelectedSongs()
result.push_back(it->value()); result.push_back(it->value());
// if no song was selected, add current one // if no song was selected, add current one
if (result.empty() && !Tags->empty()) if (result.empty() && !Tags->empty())
result.push_back(Tags->current().value()); result.push_back(Tags->current()->value());
} }
return result; return result;
} }

View File

@@ -140,7 +140,7 @@ void TinyTagEditor::enterPressed()
else else
{ {
if (m_previous_screen == myPlaylist) if (m_previous_screen == myPlaylist)
myPlaylist->main().current().value() = itsEdited; myPlaylist->main().current()->value() = itsEdited;
else if (m_previous_screen == myBrowser) else if (m_previous_screen == myBrowser)
myBrowser->getDirectory(myBrowser->currentDirectory()); myBrowser->getDirectory(myBrowser->currentDirectory());
} }