diff --git a/src/menu.h b/src/menu.h index 5c088542..58fd265b 100644 --- a/src/menu.h +++ b/src/menu.h @@ -229,11 +229,6 @@ public: /// @param pos given position of item to be deleted 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 /// @param y Y position of menu window to be highlighted /// @return true if the position is reachable, false otherwise @@ -588,11 +583,6 @@ template void Menu::deleteItem(size_t pos) m_options.erase(m_options.begin()+pos); } -template void Menu::Swap(size_t one, size_t two) -{ - std::swap(m_options.at(one), m_options.at(two)); -} - template bool Menu::Goto(size_t y) { if (!isHighlightable(m_beginning+y)) diff --git a/src/sort_playlist.cpp b/src/sort_playlist.cpp index 60369517..0afd0962 100644 --- a/src/sort_playlist.cpp +++ b/src/sort_playlist.cpp @@ -76,7 +76,6 @@ SortPlaylistDialog::SortPlaylistDialog() w.addItem(Entry(std::make_pair("Filename", &MPD::Song::getURI), std::bind(&Self::moveSortOrderHint, this) )); - m_sort_options = w.size(); w.addSeparator(); w.addItem(Entry(std::make_pair("Sort", static_cast(0)), std::bind(&Self::sort, this) @@ -129,20 +128,20 @@ void SortPlaylistDialog::mouseButtonPressed(MEVENT me) void SortPlaylistDialog::moveSortOrderDown() { - size_t pos = w.choice(); - if (pos < m_sort_options-1) + auto cur = w.currentVI(); + if ((cur+1)->item().second) { - w.Swap(pos, pos+1); + std::iter_swap(cur, cur+1); w.scroll(NC::wDown); } } void SortPlaylistDialog::moveSortOrderUp() { - size_t pos = w.choice(); - if (pos > 0 && pos < m_sort_options) + auto cur = w.currentVI(); + if (cur > w.beginV() && cur->item().second) { - w.Swap(pos, pos-1); + std::iter_swap(cur, cur-1); w.scroll(NC::wUp); } } @@ -175,10 +174,10 @@ void SortPlaylistDialog::sort() const LocaleStringComparison cmp(std::locale(), Config.ignore_leading_the); std::function iter_swap, quick_sort; 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), - b.getTags(w[i].value().item().second, Config.tags_separator)); + int res = cmp(a.getTags(it->item().second, Config.tags_separator), + b.getTags(it->item().second, Config.tags_separator)); if (res != 0) return res < 0; } diff --git a/src/sort_playlist.h b/src/sort_playlist.h index 12221c70..e4296d64 100644 --- a/src/sort_playlist.h +++ b/src/sort_playlist.h @@ -59,7 +59,6 @@ private: void setDimensions(); - size_t m_sort_options; size_t m_height; size_t m_width; };