menu: simplify ItemDisplayer further
This commit is contained in:
@@ -1161,13 +1161,13 @@ void ToggleDisplayMode::Run()
|
||||
|
||||
if (Config.columns_in_playlist)
|
||||
{
|
||||
myPlaylist->Items->setItemDisplayer(std::bind(Display::SongsInColumns, _1, _2, *myPlaylist));
|
||||
myPlaylist->Items->setItemDisplayer(std::bind(Display::SongsInColumns, _1, *myPlaylist));
|
||||
myPlaylist->Items->SetTitle(Config.titles_visibility ? Display::Columns(myPlaylist->Items->GetWidth()) : "");
|
||||
myPlaylist->Items->SetItemStringifier(Playlist::SongInColumnsToString);
|
||||
}
|
||||
else
|
||||
{
|
||||
myPlaylist->Items->setItemDisplayer(std::bind(Display::Songs, _1, _2, *myPlaylist, Config.song_list_format));
|
||||
myPlaylist->Items->setItemDisplayer(std::bind(Display::Songs, _1, *myPlaylist, Config.song_list_format));
|
||||
myPlaylist->Items->SetTitle("");
|
||||
myPlaylist->Items->SetItemStringifier(Playlist::SongToString);
|
||||
}
|
||||
@@ -1191,12 +1191,12 @@ void ToggleDisplayMode::Run()
|
||||
ShowMessage("Playlist editor display mode: %s", Config.columns_in_playlist_editor ? "Columns" : "Classic");
|
||||
if (Config.columns_in_playlist_editor)
|
||||
{
|
||||
myPlaylistEditor->Content->setItemDisplayer(std::bind(Display::SongsInColumns, _1, _2, *myPlaylistEditor));
|
||||
myPlaylistEditor->Content->setItemDisplayer(std::bind(Display::SongsInColumns, _1, *myPlaylistEditor));
|
||||
myPlaylistEditor->Content->SetItemStringifier(Playlist::SongInColumnsToString);
|
||||
}
|
||||
else
|
||||
{
|
||||
myPlaylistEditor->Content->setItemDisplayer(std::bind(Display::Songs, _1, _2, *myPlaylistEditor, Config.song_list_format));
|
||||
myPlaylistEditor->Content->setItemDisplayer(std::bind(Display::Songs, _1, *myPlaylistEditor, Config.song_list_format));
|
||||
myPlaylistEditor->Content->SetItemStringifier(Playlist::SongToString);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ void Browser::Init()
|
||||
w->CenteredCursor(Config.centered_cursor);
|
||||
w->SetSelectPrefix(Config.selected_item_prefix);
|
||||
w->SetSelectSuffix(Config.selected_item_suffix);
|
||||
w->setItemDisplayer(std::bind(Display::Items, _1, _2));
|
||||
w->setItemDisplayer(Display::Items);
|
||||
w->SetItemStringifier(ItemToString);
|
||||
|
||||
if (SupportedExtensions.empty())
|
||||
|
||||
@@ -77,18 +77,18 @@ void setProperties(Menu<T> &menu, const MPD::Song &s, BasicScreen &screen, bool
|
||||
bool &is_now_playing, bool &is_selected, bool &discard_colors)
|
||||
{
|
||||
separate_albums = false;
|
||||
if (Config.playlist_separate_albums && menu.CurrentlyDrawedPosition()+1 < menu.Size())
|
||||
if (Config.playlist_separate_albums)
|
||||
{
|
||||
MPD::Song *next = screen.GetSong(menu.CurrentlyDrawedPosition()+1);
|
||||
MPD::Song *next = screen.GetSong(menu.DrawnPosition()+1);
|
||||
if (next && next->getAlbum() != s.getAlbum())
|
||||
separate_albums = true;
|
||||
}
|
||||
if (separate_albums)
|
||||
menu << fmtUnderline;
|
||||
|
||||
int song_pos = menu.isFiltered() ? s.getPosition() : menu.CurrentlyDrawedPosition();
|
||||
int song_pos = menu.isFiltered() ? s.getPosition() : menu.DrawnPosition();
|
||||
is_now_playing = song_pos == myPlaylist->NowPlaying && s.getID() > 0; // playlist
|
||||
is_selected = menu[menu.CurrentlyDrawedPosition()].isSelected();
|
||||
is_selected = menu.Drawn().isSelected();
|
||||
discard_colors = Config.discard_colors_if_item_is_selected && is_selected;
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ void showSongs(Menu<T> &menu, const MPD::Song &s, BasicScreen &screen, const std
|
||||
setProperties(menu, s, screen, separate_albums, is_now_playing, is_selected, discard_colors);
|
||||
|
||||
std::string line = s.toString(format, "$");
|
||||
for (std::string::const_iterator it = line.begin(); it != line.end(); ++it)
|
||||
for (auto it = line.begin(); it != line.end(); ++it)
|
||||
{
|
||||
if (*it == '$')
|
||||
{
|
||||
@@ -122,7 +122,7 @@ void showSongs(Menu<T> &menu, const MPD::Song &s, BasicScreen &screen, const std
|
||||
buf.RemoveFormatting();
|
||||
if (is_now_playing)
|
||||
buf << Config.now_playing_suffix;
|
||||
menu << XY(menu.GetWidth()-buf.Str().length()-(menu[menu.CurrentlyDrawedPosition()].isSelected() ? Config.selected_item_suffix_length : 0), menu.Y()) << buf;
|
||||
menu << XY(menu.GetWidth()-buf.Str().length()-(is_selected ? Config.selected_item_suffix_length : 0), menu.Y()) << buf;
|
||||
if (separate_albums)
|
||||
menu << fmtUnderlineEnd;
|
||||
return;
|
||||
@@ -332,18 +332,19 @@ std::string Display::Columns(size_t list_width)
|
||||
return result;
|
||||
}
|
||||
|
||||
void Display::SongsInColumns(Menu<MPD::Song> &menu, const MPD::Song &s, BasicScreen &screen)
|
||||
void Display::SongsInColumns(Menu<MPD::Song> &menu, BasicScreen &screen)
|
||||
{
|
||||
showSongsInColumns(menu, s, screen);
|
||||
showSongsInColumns(menu, menu.Drawn().value(), screen);
|
||||
}
|
||||
|
||||
void Display::Songs(Menu<MPD::Song> &menu, const MPD::Song &s, BasicScreen &screen, const std::string &format)
|
||||
void Display::Songs(Menu<MPD::Song> &menu, BasicScreen &screen, const std::string &format)
|
||||
{
|
||||
showSongs(menu, s, screen, format);
|
||||
showSongs(menu, menu.Drawn().value(), screen, format);
|
||||
}
|
||||
|
||||
void Display::Tags(Menu<MPD::MutableSong> &menu, const MPD::MutableSong &s)
|
||||
void Display::Tags(Menu<MPD::MutableSong> &menu)
|
||||
{
|
||||
const MPD::MutableSong &s = menu.Drawn().value();
|
||||
size_t i = myTagEditor->TagTypes->Choice();
|
||||
if (i < 11)
|
||||
{
|
||||
@@ -358,13 +359,14 @@ void Display::Tags(Menu<MPD::MutableSong> &menu, const MPD::MutableSong &s)
|
||||
}
|
||||
}
|
||||
|
||||
void Display::Outputs(Menu< MPD::Output > &menu, const MPD::Output &o)
|
||||
void Display::Outputs(Menu< MPD::Output > &menu)
|
||||
{
|
||||
menu << o.name();
|
||||
menu << menu.Drawn().value().name();
|
||||
}
|
||||
|
||||
void Display::Items(Menu<MPD::Item> &menu, const MPD::Item &item)
|
||||
void Display::Items(Menu<MPD::Item> &menu)
|
||||
{
|
||||
const MPD::Item &item = menu.Drawn().value();
|
||||
switch (item.type)
|
||||
{
|
||||
case MPD::itDirectory:
|
||||
@@ -382,15 +384,16 @@ void Display::Items(Menu<MPD::Item> &menu, const MPD::Item &item)
|
||||
}
|
||||
}
|
||||
|
||||
void Display::SearchEngine(Menu<SEItem> &menu, const SEItem &ei)
|
||||
void Display::SearchEngine(Menu<SEItem> &menu)
|
||||
{
|
||||
if (ei.isSong())
|
||||
const SEItem &si = menu.Drawn().value();
|
||||
if (si.isSong())
|
||||
{
|
||||
if (!Config.columns_in_search_engine)
|
||||
showSongs(menu, ei.song(), *mySearcher, Config.song_list_format);
|
||||
showSongs(menu, si.song(), *mySearcher, Config.song_list_format);
|
||||
else
|
||||
showSongsInColumns(menu, ei.song(), *mySearcher);
|
||||
showSongsInColumns(menu, si.song(), *mySearcher);
|
||||
}
|
||||
else
|
||||
menu << ei.buffer();
|
||||
menu << si.buffer();
|
||||
}
|
||||
|
||||
@@ -32,27 +32,27 @@ namespace Display
|
||||
{
|
||||
std::string Columns(size_t);
|
||||
|
||||
template <typename T> void Default(Menu<T> &menu, const T &t)
|
||||
template <typename T> void Default(Menu<T> &menu)
|
||||
{
|
||||
menu << t;
|
||||
menu << menu.Drawn().value();
|
||||
}
|
||||
|
||||
template <typename A, typename B> void Pair(Menu< std::pair<A, B> > &menu, const std::pair<A, B> &pair)
|
||||
template <typename A, typename B> void Pair(Menu< std::pair<A, B> > &menu)
|
||||
{
|
||||
menu << pair.first;
|
||||
menu << menu.Drawn().value().first;
|
||||
}
|
||||
|
||||
void SongsInColumns(Menu<MPD::Song> &menu, const MPD::Song &s, BasicScreen &screen);
|
||||
void SongsInColumns(Menu<MPD::Song> &menu, BasicScreen &screen);
|
||||
|
||||
void Songs(Menu<MPD::Song> &menu, const MPD::Song &s, BasicScreen &screen, const std::string &format);
|
||||
void Songs(Menu<MPD::Song> &menu, BasicScreen &screen, const std::string &format);
|
||||
|
||||
void Tags(Menu<MPD::MutableSong> &menu, const MPD::MutableSong &s);
|
||||
void Tags(Menu<MPD::MutableSong> &menu);
|
||||
|
||||
void Outputs(Menu<MPD::Output> &menu, const MPD::Output &o);
|
||||
void Outputs(Menu<MPD::Output> &menu);
|
||||
|
||||
void SearchEngine(Menu<SEItem> &menu, const SEItem &si);
|
||||
void SearchEngine(Menu<SEItem> &menu);
|
||||
|
||||
void Items(Menu<MPD::Item> &menu, const MPD::Item &item);
|
||||
void Items(Menu<MPD::Item> &menu);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -84,7 +84,7 @@ void MediaLibrary::Init()
|
||||
Songs->CenteredCursor(Config.centered_cursor);
|
||||
Songs->SetSelectPrefix(Config.selected_item_prefix);
|
||||
Songs->SetSelectSuffix(Config.selected_item_suffix);
|
||||
Songs->setItemDisplayer(std::bind(Display::Songs, _1, _2, *this, Config.song_library_format));
|
||||
Songs->setItemDisplayer(std::bind(Display::Songs, _1, *this, Config.song_library_format));
|
||||
Songs->SetItemStringifier(SongToString);
|
||||
|
||||
w = Artists;
|
||||
@@ -768,13 +768,14 @@ std::string MediaLibrary::AlbumToString(const SearchConstraints &sc)
|
||||
return result;
|
||||
}
|
||||
|
||||
void MediaLibrary::DisplayAlbums(Menu<SearchConstraints> &menu, const SearchConstraints &sc)
|
||||
void MediaLibrary::DisplayAlbums(Menu<SearchConstraints> &menu)
|
||||
{
|
||||
menu << AlbumToString(sc);
|
||||
menu << AlbumToString(menu.Drawn().value());
|
||||
}
|
||||
|
||||
void MediaLibrary::DisplayPrimaryTags(Menu<std::string> &menu, const std::string &tag)
|
||||
void MediaLibrary::DisplayPrimaryTags(Menu<std::string> &menu)
|
||||
{
|
||||
const std::string &tag = menu.Drawn().value();
|
||||
if (tag.empty())
|
||||
menu << Config.empty_tag;
|
||||
else
|
||||
|
||||
@@ -90,8 +90,8 @@ class MediaLibrary : public Screen<Window>
|
||||
|
||||
static std::string SongToString(const MPD::Song &s);
|
||||
static std::string AlbumToString(const SearchConstraints &);
|
||||
static void DisplayAlbums(Menu<SearchConstraints> &menu, const SearchConstraints &sc);
|
||||
static void DisplayPrimaryTags(Menu<std::string> &menu, const std::string &tag);
|
||||
static void DisplayAlbums(Menu<SearchConstraints> &menu);
|
||||
static void DisplayPrimaryTags(Menu<std::string> &menu);
|
||||
|
||||
static bool SortSongsByTrack(const MPD::Song &, const MPD::Song &);
|
||||
static bool SortAllTracks(const MPD::Song &, const MPD::Song &);
|
||||
|
||||
18
src/menu.h
18
src/menu.h
@@ -100,7 +100,7 @@ template <typename T> struct Menu : public Window, public List
|
||||
/// If not set by setItemDisplayer(), menu won't display anything.
|
||||
/// @see setItemDisplayer()
|
||||
///
|
||||
typedef std::function<void(Menu<T> &, const T &)> ItemDisplayer;
|
||||
typedef std::function<void(Menu<T> &)> ItemDisplayer;
|
||||
|
||||
/// Function helper prototype used for converting items to strings.
|
||||
/// If not set by SetItemStringifier(), searching and filtering
|
||||
@@ -466,11 +466,17 @@ template <typename T> struct Menu : public Window, public List
|
||||
///
|
||||
virtual size_t Size() const;
|
||||
|
||||
/// @return position of currently drawed item. The result is
|
||||
/// defined only within drawing function that is called by Refresh()
|
||||
/// @return currently drawn item. The result is defined only within
|
||||
/// drawing function that is called by Refresh()
|
||||
/// @see Refresh()
|
||||
///
|
||||
size_t CurrentlyDrawedPosition() const { return m_drawn_position; }
|
||||
const Item &Drawn() const { return *(*m_options_ptr)[m_drawn_position]; }
|
||||
|
||||
/// @return position of currently drawn item. The result is defined
|
||||
/// only within drawing function that is called by Refresh()
|
||||
/// @see Refresh()
|
||||
///
|
||||
size_t DrawnPosition() const { return m_drawn_position; }
|
||||
|
||||
/// @return reference to last item on the list
|
||||
/// @throw List::InvalidItem if requested item is separator
|
||||
@@ -537,7 +543,7 @@ template <typename T> struct Menu : public Window, public List
|
||||
ConstReverseIterator RbeginV() const { return ConstReverseValueIterator(End()); }
|
||||
ReverseValueIterator RendV() { return ReverseValueIterator(Begin()); }
|
||||
ConstReverseValueIterator RendV() const { return ConstReverseValueIterator(Begin()); }
|
||||
|
||||
|
||||
private:
|
||||
/// Clears filter, filtered data etc.
|
||||
///
|
||||
@@ -719,7 +725,7 @@ template <typename T> void Menu<T>::Refresh()
|
||||
if ((*m_options_ptr)[i]->isSelected())
|
||||
*this << m_selected_prefix;
|
||||
if (m_item_displayer)
|
||||
m_item_displayer(*this, (*m_options_ptr)[i]->value());
|
||||
m_item_displayer(*this);
|
||||
if ((*m_options_ptr)[i]->isSelected())
|
||||
*this << m_selected_suffix;
|
||||
if (m_highlight_enabled && i == m_highlight)
|
||||
|
||||
@@ -53,12 +53,12 @@ void Playlist::Init()
|
||||
Items->SetSelectSuffix(Config.selected_item_suffix);
|
||||
if (Config.columns_in_playlist)
|
||||
{
|
||||
Items->setItemDisplayer(std::bind(Display::SongsInColumns, _1, _2, *this));
|
||||
Items->setItemDisplayer(std::bind(Display::SongsInColumns, _1, *this));
|
||||
Items->SetItemStringifier(SongInColumnsToString);
|
||||
}
|
||||
else
|
||||
{
|
||||
Items->setItemDisplayer(std::bind(Display::Songs, _1, _2, *this, Config.song_list_format));
|
||||
Items->setItemDisplayer(std::bind(Display::Songs, _1, *this, Config.song_list_format));
|
||||
Items->SetItemStringifier(SongToString);
|
||||
}
|
||||
|
||||
|
||||
@@ -62,12 +62,12 @@ void PlaylistEditor::Init()
|
||||
Content->SetSelectSuffix(Config.selected_item_suffix);
|
||||
if (Config.columns_in_playlist_editor)
|
||||
{
|
||||
Content->setItemDisplayer(std::bind(Display::SongsInColumns, _1, _2, *this));
|
||||
Content->setItemDisplayer(std::bind(Display::SongsInColumns, _1, *this));
|
||||
Content->SetItemStringifier(Playlist::SongInColumnsToString);
|
||||
}
|
||||
else
|
||||
{
|
||||
Content->setItemDisplayer(std::bind(Display::Songs, _1, _2, *this, Config.song_list_format));
|
||||
Content->setItemDisplayer(std::bind(Display::Songs, _1, *this, Config.song_list_format));
|
||||
Content->SetItemStringifier(Playlist::SongToString);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user