menu: a few semantic changes
This commit is contained in:
@@ -56,8 +56,8 @@ void Browser::Init()
|
|||||||
w->HighlightColor(Config.main_highlight_color);
|
w->HighlightColor(Config.main_highlight_color);
|
||||||
w->CyclicScrolling(Config.use_cyclic_scrolling);
|
w->CyclicScrolling(Config.use_cyclic_scrolling);
|
||||||
w->CenteredCursor(Config.centered_cursor);
|
w->CenteredCursor(Config.centered_cursor);
|
||||||
w->SetSelectPrefix(&Config.selected_item_prefix);
|
w->SetSelectPrefix(Config.selected_item_prefix);
|
||||||
w->SetSelectSuffix(&Config.selected_item_suffix);
|
w->SetSelectSuffix(Config.selected_item_suffix);
|
||||||
w->setItemDisplayer(std::bind(Display::Items, _1, _2));
|
w->setItemDisplayer(std::bind(Display::Items, _1, _2));
|
||||||
w->SetItemStringifier(ItemToString);
|
w->SetItemStringifier(ItemToString);
|
||||||
|
|
||||||
|
|||||||
@@ -65,16 +65,16 @@ void MediaLibrary::Init()
|
|||||||
Artists->HighlightColor(Config.active_column_color);
|
Artists->HighlightColor(Config.active_column_color);
|
||||||
Artists->CyclicScrolling(Config.use_cyclic_scrolling);
|
Artists->CyclicScrolling(Config.use_cyclic_scrolling);
|
||||||
Artists->CenteredCursor(Config.centered_cursor);
|
Artists->CenteredCursor(Config.centered_cursor);
|
||||||
Artists->SetSelectPrefix(&Config.selected_item_prefix);
|
Artists->SetSelectPrefix(Config.selected_item_prefix);
|
||||||
Artists->SetSelectSuffix(&Config.selected_item_suffix);
|
Artists->SetSelectSuffix(Config.selected_item_suffix);
|
||||||
Artists->setItemDisplayer(DisplayPrimaryTags);
|
Artists->setItemDisplayer(DisplayPrimaryTags);
|
||||||
|
|
||||||
Albums = new Menu<SearchConstraints>(itsMiddleColStartX, MainStartY, itsMiddleColWidth, MainHeight, Config.titles_visibility ? "Albums" : "", Config.main_color, brNone);
|
Albums = new Menu<SearchConstraints>(itsMiddleColStartX, MainStartY, itsMiddleColWidth, MainHeight, Config.titles_visibility ? "Albums" : "", Config.main_color, brNone);
|
||||||
Albums->HighlightColor(Config.main_highlight_color);
|
Albums->HighlightColor(Config.main_highlight_color);
|
||||||
Albums->CyclicScrolling(Config.use_cyclic_scrolling);
|
Albums->CyclicScrolling(Config.use_cyclic_scrolling);
|
||||||
Albums->CenteredCursor(Config.centered_cursor);
|
Albums->CenteredCursor(Config.centered_cursor);
|
||||||
Albums->SetSelectPrefix(&Config.selected_item_prefix);
|
Albums->SetSelectPrefix(Config.selected_item_prefix);
|
||||||
Albums->SetSelectSuffix(&Config.selected_item_suffix);
|
Albums->SetSelectSuffix(Config.selected_item_suffix);
|
||||||
Albums->setItemDisplayer(DisplayAlbums);
|
Albums->setItemDisplayer(DisplayAlbums);
|
||||||
Albums->SetItemStringifier(AlbumToString);
|
Albums->SetItemStringifier(AlbumToString);
|
||||||
|
|
||||||
@@ -82,8 +82,8 @@ void MediaLibrary::Init()
|
|||||||
Songs->HighlightColor(Config.main_highlight_color);
|
Songs->HighlightColor(Config.main_highlight_color);
|
||||||
Songs->CyclicScrolling(Config.use_cyclic_scrolling);
|
Songs->CyclicScrolling(Config.use_cyclic_scrolling);
|
||||||
Songs->CenteredCursor(Config.centered_cursor);
|
Songs->CenteredCursor(Config.centered_cursor);
|
||||||
Songs->SetSelectPrefix(&Config.selected_item_prefix);
|
Songs->SetSelectPrefix(Config.selected_item_prefix);
|
||||||
Songs->SetSelectSuffix(&Config.selected_item_suffix);
|
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, _2, *this, Config.song_library_format));
|
||||||
Songs->SetItemStringifier(SongToString);
|
Songs->SetItemStringifier(SongToString);
|
||||||
|
|
||||||
|
|||||||
129
src/menu.h
129
src/menu.h
@@ -246,11 +246,6 @@ template <typename T> struct Menu : public Window, public List
|
|||||||
Menu(size_t startx, size_t starty, size_t width, size_t height,
|
Menu(size_t startx, size_t starty, size_t width, size_t height,
|
||||||
const std::string &title, Color color, Border border);
|
const std::string &title, Color color, Border border);
|
||||||
|
|
||||||
/// Copies the menu
|
|
||||||
/// @param m copied menu
|
|
||||||
///
|
|
||||||
Menu(const Menu &m);
|
|
||||||
|
|
||||||
/// Destroys the object and frees memory
|
/// Destroys the object and frees memory
|
||||||
///
|
///
|
||||||
virtual ~Menu();
|
virtual ~Menu();
|
||||||
@@ -310,12 +305,6 @@ template <typename T> struct Menu : public Window, public List
|
|||||||
///
|
///
|
||||||
void Swap(size_t one, size_t two);
|
void Swap(size_t one, size_t two);
|
||||||
|
|
||||||
/// Moves requested item from one position to another
|
|
||||||
/// @param from the position of item that has to be moved
|
|
||||||
/// @param to the position that indicates where the object has to be moved
|
|
||||||
///
|
|
||||||
void Move(size_t from, size_t to);
|
|
||||||
|
|
||||||
/// Moves the highlighted position to the given line of window
|
/// Moves the highlighted position to the given line of window
|
||||||
/// @param y Y position of menu window to be highlighted
|
/// @param y Y position of menu window to be highlighted
|
||||||
/// @return true if the position is reachable, false otherwise
|
/// @return true if the position is reachable, false otherwise
|
||||||
@@ -428,13 +417,13 @@ template <typename T> struct Menu : public Window, public List
|
|||||||
/// Note that the passed variable is not deleted along with menu object.
|
/// Note that the passed variable is not deleted along with menu object.
|
||||||
/// @param b pointer to buffer that contains the prefix
|
/// @param b pointer to buffer that contains the prefix
|
||||||
///
|
///
|
||||||
void SetSelectPrefix(Buffer *b) { m_selected_prefix = b; }
|
void SetSelectPrefix(const Buffer &b) { m_selected_prefix = b; }
|
||||||
|
|
||||||
/// Sets suffix, that is put after each selected item to indicate its selection
|
/// Sets suffix, that is put after each selected item to indicate its selection
|
||||||
/// Note that the passed variable is not deleted along with menu object.
|
/// Note that the passed variable is not deleted along with menu object.
|
||||||
/// @param b pointer to buffer that contains the suffix
|
/// @param b pointer to buffer that contains the suffix
|
||||||
///
|
///
|
||||||
void SetSelectSuffix(Buffer *b) { m_selected_suffix = b; }
|
void SetSelectSuffix(const Buffer &b) { m_selected_suffix = b; }
|
||||||
|
|
||||||
/// Sets custom color of highlighted position
|
/// Sets custom color of highlighted position
|
||||||
/// @param col custom color
|
/// @param col custom color
|
||||||
@@ -582,8 +571,8 @@ private:
|
|||||||
|
|
||||||
size_t m_drawn_position;
|
size_t m_drawn_position;
|
||||||
|
|
||||||
Buffer *m_selected_prefix;
|
Buffer m_selected_prefix;
|
||||||
Buffer *m_selected_suffix;
|
Buffer m_selected_suffix;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Specialization of Menu<T>::GetItem for T = std::string, it's obvious
|
/// Specialization of Menu<T>::GetItem for T = std::string, it's obvious
|
||||||
@@ -592,45 +581,25 @@ private:
|
|||||||
template <> std::string Menu<std::string>::GetItem(size_t pos);
|
template <> std::string Menu<std::string>::GetItem(size_t pos);
|
||||||
|
|
||||||
template <typename T> Menu<T>::Menu(size_t startx,
|
template <typename T> Menu<T>::Menu(size_t startx,
|
||||||
size_t starty,
|
size_t starty,
|
||||||
size_t width,
|
size_t width,
|
||||||
size_t height,
|
size_t height,
|
||||||
const std::string &title,
|
const std::string &title,
|
||||||
Color color,
|
Color color,
|
||||||
Border border)
|
Border border)
|
||||||
: Window(startx, starty, width, height, title, color, border),
|
: Window(startx, starty, width, height, title, color, border),
|
||||||
m_item_displayer(0),
|
m_item_displayer(0),
|
||||||
m_get_string_helper(0),
|
m_get_string_helper(0),
|
||||||
m_options_ptr(&m_options),
|
m_options_ptr(&m_options),
|
||||||
m_beginning(0),
|
m_beginning(0),
|
||||||
m_highlight(0),
|
m_highlight(0),
|
||||||
m_highlight_color(itsBaseColor),
|
m_highlight_color(itsBaseColor),
|
||||||
m_highlight_enabled(1),
|
m_highlight_enabled(true),
|
||||||
m_cyclic_scroll_enabled(0),
|
m_cyclic_scroll_enabled(false),
|
||||||
m_autocenter_cursor(0),
|
m_autocenter_cursor(false)
|
||||||
m_selected_prefix(0),
|
|
||||||
m_selected_suffix(0)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> Menu<T>::Menu(const Menu &m) : Window(m),
|
|
||||||
m_item_displayer(m.m_item_displayer),
|
|
||||||
m_get_string_helper(m.m_get_string_helper),
|
|
||||||
m_options_ptr(m.m_options_ptr),
|
|
||||||
m_beginning(m.m_beginning),
|
|
||||||
m_highlight(m.m_highlight),
|
|
||||||
m_highlight_color(m.m_highlight_color),
|
|
||||||
m_highlight_enabled(m.m_highlight_enabled),
|
|
||||||
m_cyclic_scroll_enabled(m.m_cyclic_scroll_enabled),
|
|
||||||
m_autocenter_cursor(m.m_autocenter_cursor),
|
|
||||||
m_selected_prefix(m.m_selected_prefix),
|
|
||||||
m_selected_suffix(m.m_selected_suffix)
|
|
||||||
{
|
|
||||||
m_options.reserve(m.m_options.size());
|
|
||||||
for (auto it = m.m_options.begin(); it != m.m_options.end(); ++it)
|
|
||||||
m_options.push_back(new Item(**it));
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T> Menu<T>::~Menu()
|
template <typename T> Menu<T>::~Menu()
|
||||||
{
|
{
|
||||||
for (auto it = m_options.begin(); it != m_options.end(); ++it)
|
for (auto it = m_options.begin(); it != m_options.end(); ++it)
|
||||||
@@ -659,9 +628,9 @@ template <typename T> void Menu<T>::ResizeList(size_t size)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> void Menu<T>::AddItem(const T &item, bool is_bold, bool is_static)
|
template <typename T> void Menu<T>::AddItem(const T &item, bool is_bold, bool is_inactive)
|
||||||
{
|
{
|
||||||
m_options.push_back(new Item(item, is_bold, is_static));
|
m_options.push_back(new Item(item, is_bold, is_inactive));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> void Menu<T>::AddSeparator()
|
template <typename T> void Menu<T>::AddSeparator()
|
||||||
@@ -669,9 +638,9 @@ template <typename T> void Menu<T>::AddSeparator()
|
|||||||
m_options.push_back(Item::mkSeparator());
|
m_options.push_back(Item::mkSeparator());
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> void Menu<T>::InsertItem(size_t pos, const T &item, bool is_bold, bool is_static)
|
template <typename T> void Menu<T>::InsertItem(size_t pos, const T &item, bool is_bold, bool is_inactive)
|
||||||
{
|
{
|
||||||
m_options.insert(m_options.begin()+pos, new Item(item, is_bold, is_static));
|
m_options.insert(m_options.begin()+pos, new Item(item, is_bold, is_inactive));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> void Menu<T>::InsertSeparator(size_t pos)
|
template <typename T> void Menu<T>::InsertSeparator(size_t pos)
|
||||||
@@ -681,24 +650,10 @@ template <typename T> void Menu<T>::InsertSeparator(size_t pos)
|
|||||||
|
|
||||||
template <typename T> void Menu<T>::DeleteItem(size_t pos)
|
template <typename T> void Menu<T>::DeleteItem(size_t pos)
|
||||||
{
|
{
|
||||||
assert(pos < m_options_ptr->size());
|
assert(m_options_ptr != &m_filtered_options);
|
||||||
if (m_options_ptr == &m_filtered_options)
|
assert(pos < m_options.size());
|
||||||
{
|
delete m_options[pos];
|
||||||
delete m_options.at(m_filtered_positions[pos]);
|
m_options.erase(m_options.begin()+pos);
|
||||||
m_options.erase(m_options.begin()+m_filtered_positions[pos]);
|
|
||||||
m_filtered_options.erase(m_filtered_options.begin()+pos);
|
|
||||||
m_filtered_positions.erase(m_filtered_positions.begin()+pos);
|
|
||||||
for (size_t i = pos; i < m_filtered_positions.size(); ++i)
|
|
||||||
m_filtered_positions[i]--;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
delete m_options.at(pos);
|
|
||||||
m_options.erase(m_options.begin()+pos);
|
|
||||||
}
|
|
||||||
m_found_positions.clear();
|
|
||||||
if (m_options_ptr->empty())
|
|
||||||
Window::Clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> void Menu<T>::Swap(size_t one, size_t two)
|
template <typename T> void Menu<T>::Swap(size_t one, size_t two)
|
||||||
@@ -706,21 +661,6 @@ template <typename T> void Menu<T>::Swap(size_t one, size_t two)
|
|||||||
std::swap(m_options.at(one), m_options.at(two));
|
std::swap(m_options.at(one), m_options.at(two));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> void Menu<T>::Move(size_t from, size_t to)
|
|
||||||
{
|
|
||||||
int diff = from-to;
|
|
||||||
if (diff > 0)
|
|
||||||
{
|
|
||||||
for (size_t i = from; i > to; --i)
|
|
||||||
std::swap(m_options.at(i), m_options.at(i-1));
|
|
||||||
}
|
|
||||||
else if (diff < 0)
|
|
||||||
{
|
|
||||||
for (size_t i = from; i < to; ++i)
|
|
||||||
std::swap(m_options.at(i), m_options.at(i+1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T> bool Menu<T>::Goto(size_t y)
|
template <typename T> bool Menu<T>::Goto(size_t y)
|
||||||
{
|
{
|
||||||
if (!isHighlightable(m_beginning+y))
|
if (!isHighlightable(m_beginning+y))
|
||||||
@@ -733,7 +673,7 @@ template <typename T> void Menu<T>::Refresh()
|
|||||||
{
|
{
|
||||||
if (m_options_ptr->empty())
|
if (m_options_ptr->empty())
|
||||||
{
|
{
|
||||||
Window::Refresh();
|
Window::Clear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -776,12 +716,12 @@ template <typename T> void Menu<T>::Refresh()
|
|||||||
*this << m_highlight_color;
|
*this << m_highlight_color;
|
||||||
}
|
}
|
||||||
mvwhline(itsWindow, line, 0, KEY_SPACE, itsWidth);
|
mvwhline(itsWindow, line, 0, KEY_SPACE, itsWidth);
|
||||||
if ((*m_options_ptr)[i]->isSelected() && m_selected_prefix)
|
if ((*m_options_ptr)[i]->isSelected())
|
||||||
*this << *m_selected_prefix;
|
*this << m_selected_prefix;
|
||||||
if (m_item_displayer)
|
if (m_item_displayer)
|
||||||
m_item_displayer(*this, (*m_options_ptr)[i]->value());
|
m_item_displayer(*this, (*m_options_ptr)[i]->value());
|
||||||
if ((*m_options_ptr)[i]->isSelected() && m_selected_suffix)
|
if ((*m_options_ptr)[i]->isSelected())
|
||||||
*this << *m_selected_suffix;
|
*this << m_selected_suffix;
|
||||||
if (m_highlight_enabled && i == m_highlight)
|
if (m_highlight_enabled && i == m_highlight)
|
||||||
{
|
{
|
||||||
*this << clEnd;
|
*this << clEnd;
|
||||||
@@ -905,7 +845,6 @@ template <typename T> void Menu<T>::Clear()
|
|||||||
m_filter.clear();
|
m_filter.clear();
|
||||||
ClearFiltered();
|
ClearFiltered();
|
||||||
m_options_ptr = &m_options;
|
m_options_ptr = &m_options;
|
||||||
Window::Clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> bool Menu<T>::hasSelected() const
|
template <typename T> bool Menu<T>::hasSelected() const
|
||||||
@@ -1018,8 +957,6 @@ template <typename T> void Menu<T>::ApplyFilter(const std::string &filter, size_
|
|||||||
}
|
}
|
||||||
regfree(&rx);
|
regfree(&rx);
|
||||||
m_options_ptr = &m_filtered_options;
|
m_options_ptr = &m_filtered_options;
|
||||||
if (m_options_ptr->empty()) // oops, we didn't find anything
|
|
||||||
Window::Clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> const std::string &Menu<T>::GetFilter()
|
template <typename T> const std::string &Menu<T>::GetFilter()
|
||||||
|
|||||||
@@ -49,8 +49,8 @@ void Playlist::Init()
|
|||||||
Items->CyclicScrolling(Config.use_cyclic_scrolling);
|
Items->CyclicScrolling(Config.use_cyclic_scrolling);
|
||||||
Items->CenteredCursor(Config.centered_cursor);
|
Items->CenteredCursor(Config.centered_cursor);
|
||||||
Items->HighlightColor(Config.main_highlight_color);
|
Items->HighlightColor(Config.main_highlight_color);
|
||||||
Items->SetSelectPrefix(&Config.selected_item_prefix);
|
Items->SetSelectPrefix(Config.selected_item_prefix);
|
||||||
Items->SetSelectSuffix(&Config.selected_item_suffix);
|
Items->SetSelectSuffix(Config.selected_item_suffix);
|
||||||
if (Config.columns_in_playlist)
|
if (Config.columns_in_playlist)
|
||||||
{
|
{
|
||||||
Items->setItemDisplayer(std::bind(Display::SongsInColumns, _1, _2, *this));
|
Items->setItemDisplayer(std::bind(Display::SongsInColumns, _1, _2, *this));
|
||||||
|
|||||||
@@ -58,8 +58,8 @@ void PlaylistEditor::Init()
|
|||||||
Content->HighlightColor(Config.main_highlight_color);
|
Content->HighlightColor(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->SetSelectPrefix(&Config.selected_item_prefix);
|
Content->SetSelectPrefix(Config.selected_item_prefix);
|
||||||
Content->SetSelectSuffix(&Config.selected_item_suffix);
|
Content->SetSelectSuffix(Config.selected_item_suffix);
|
||||||
if (Config.columns_in_playlist_editor)
|
if (Config.columns_in_playlist_editor)
|
||||||
{
|
{
|
||||||
Content->setItemDisplayer(std::bind(Display::SongsInColumns, _1, _2, *this));
|
Content->setItemDisplayer(std::bind(Display::SongsInColumns, _1, _2, *this));
|
||||||
|
|||||||
@@ -68,8 +68,8 @@ void SearchEngine::Init()
|
|||||||
w->CyclicScrolling(Config.use_cyclic_scrolling);
|
w->CyclicScrolling(Config.use_cyclic_scrolling);
|
||||||
w->CenteredCursor(Config.centered_cursor);
|
w->CenteredCursor(Config.centered_cursor);
|
||||||
w->setItemDisplayer(Display::SearchEngine);
|
w->setItemDisplayer(Display::SearchEngine);
|
||||||
w->SetSelectPrefix(&Config.selected_item_prefix);
|
w->SetSelectPrefix(Config.selected_item_prefix);
|
||||||
w->SetSelectSuffix(&Config.selected_item_suffix);
|
w->SetSelectSuffix(Config.selected_item_suffix);
|
||||||
w->SetItemStringifier(SearchEngineOptionToString);
|
w->SetItemStringifier(SearchEngineOptionToString);
|
||||||
SearchMode = &SearchModes[Config.search_engine_default_search_mode];
|
SearchMode = &SearchModes[Config.search_engine_default_search_mode];
|
||||||
isInitialized = 1;
|
isInitialized = 1;
|
||||||
|
|||||||
@@ -108,8 +108,8 @@ void TagEditor::Init()
|
|||||||
Tags->HighlightColor(Config.main_highlight_color);
|
Tags->HighlightColor(Config.main_highlight_color);
|
||||||
Tags->CyclicScrolling(Config.use_cyclic_scrolling);
|
Tags->CyclicScrolling(Config.use_cyclic_scrolling);
|
||||||
Tags->CenteredCursor(Config.centered_cursor);
|
Tags->CenteredCursor(Config.centered_cursor);
|
||||||
Tags->SetSelectPrefix(&Config.selected_item_prefix);
|
Tags->SetSelectPrefix(Config.selected_item_prefix);
|
||||||
Tags->SetSelectSuffix(&Config.selected_item_suffix);
|
Tags->SetSelectSuffix(Config.selected_item_suffix);
|
||||||
Tags->setItemDisplayer(Display::Tags);
|
Tags->setItemDisplayer(Display::Tags);
|
||||||
Tags->SetItemStringifier(TagToString);
|
Tags->SetItemStringifier(TagToString);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user