menu: remove Menu::Swap

This commit is contained in:
Andrzej Rybczak
2012-09-18 20:53:34 +02:00
parent 419965924f
commit 3aa21f8ef7
3 changed files with 9 additions and 21 deletions

View File

@@ -229,11 +229,6 @@ public:
/// @param pos given position of item to be deleted /// @param pos given position of item to be deleted
void deleteItem(size_t pos); void deleteItem(size_t pos);
/// Swaps the content of two items
/// @param one position of first item
/// @param two position of second item
void Swap(size_t one, size_t two);
/// 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
@@ -588,11 +583,6 @@ template <typename T> void Menu<T>::deleteItem(size_t pos)
m_options.erase(m_options.begin()+pos); m_options.erase(m_options.begin()+pos);
} }
template <typename T> void Menu<T>::Swap(size_t one, size_t two)
{
std::swap(m_options.at(one), m_options.at(two));
}
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))

View File

@@ -76,7 +76,6 @@ SortPlaylistDialog::SortPlaylistDialog()
w.addItem(Entry(std::make_pair("Filename", &MPD::Song::getURI), w.addItem(Entry(std::make_pair("Filename", &MPD::Song::getURI),
std::bind(&Self::moveSortOrderHint, this) std::bind(&Self::moveSortOrderHint, this)
)); ));
m_sort_options = w.size();
w.addSeparator(); w.addSeparator();
w.addItem(Entry(std::make_pair("Sort", static_cast<MPD::Song::GetFunction>(0)), w.addItem(Entry(std::make_pair("Sort", static_cast<MPD::Song::GetFunction>(0)),
std::bind(&Self::sort, this) std::bind(&Self::sort, this)
@@ -129,20 +128,20 @@ void SortPlaylistDialog::mouseButtonPressed(MEVENT me)
void SortPlaylistDialog::moveSortOrderDown() void SortPlaylistDialog::moveSortOrderDown()
{ {
size_t pos = w.choice(); auto cur = w.currentVI();
if (pos < m_sort_options-1) if ((cur+1)->item().second)
{ {
w.Swap(pos, pos+1); std::iter_swap(cur, cur+1);
w.scroll(NC::wDown); w.scroll(NC::wDown);
} }
} }
void SortPlaylistDialog::moveSortOrderUp() void SortPlaylistDialog::moveSortOrderUp()
{ {
size_t pos = w.choice(); auto cur = w.currentVI();
if (pos > 0 && pos < m_sort_options) if (cur > w.beginV() && cur->item().second)
{ {
w.Swap(pos, pos-1); std::iter_swap(cur, cur-1);
w.scroll(NC::wUp); w.scroll(NC::wUp);
} }
} }
@@ -175,10 +174,10 @@ void SortPlaylistDialog::sort() const
LocaleStringComparison cmp(std::locale(), Config.ignore_leading_the); LocaleStringComparison cmp(std::locale(), Config.ignore_leading_the);
std::function<void(Iterator, Iterator)> iter_swap, quick_sort; std::function<void(Iterator, Iterator)> iter_swap, quick_sort;
auto song_cmp = [this, &cmp](const MPD::Song &a, const MPD::Song &b) -> bool { auto song_cmp = [this, &cmp](const MPD::Song &a, const MPD::Song &b) -> bool {
for (size_t i = 0; i < m_sort_options; ++i) for (auto it = w.beginV(); it->item().second; ++it)
{ {
int res = cmp(a.getTags(w[i].value().item().second, Config.tags_separator), int res = cmp(a.getTags(it->item().second, Config.tags_separator),
b.getTags(w[i].value().item().second, Config.tags_separator)); b.getTags(it->item().second, Config.tags_separator));
if (res != 0) if (res != 0)
return res < 0; return res < 0;
} }

View File

@@ -59,7 +59,6 @@ private:
void setDimensions(); void setDimensions();
size_t m_sort_options;
size_t m_height; size_t m_height;
size_t m_width; size_t m_width;
}; };