diff options
author | Andrzej Rybczak <electricityispower@gmail.com> | 2012-09-18 21:17:04 +0200 |
---|---|---|
committer | Andrzej Rybczak <electricityispower@gmail.com> | 2012-09-18 21:17:04 +0200 |
commit | e108604641775e620506e97137d49c46ae0c1087 (patch) | |
tree | ce593ab9e687bf1bc7b7480ba056bdc75287f83b /src/playlist.cpp | |
parent | 059592e28e527edaf66a3db9daf6df745812ef9e (diff) |
playlist: make reverse operate on iterator range
Diffstat (limited to 'src/playlist.cpp')
-rw-r--r-- | src/playlist.cpp | 23 |
1 files changed, 4 insertions, 19 deletions
diff --git a/src/playlist.cpp b/src/playlist.cpp index 6ad07437..086959fb 100644 --- a/src/playlist.cpp +++ b/src/playlist.cpp @@ -223,27 +223,12 @@ bool Playlist::isFiltered() void Playlist::Reverse() { - if (isFiltered()) - return; Statusbar::msg("Reversing playlist order..."); - size_t beginning = -1, end = -1; - for (size_t i = 0; i < w.size(); ++i) - { - if (w.at(i).isSelected()) - { - if (beginning == size_t(-1)) - beginning = i; - end = i; - } - } - if (beginning == size_t(-1)) // no selected items - { - beginning = 0; - end = w.size(); - } + auto begin = w.begin(), end = w.end(); + std::tie(begin, end) = getSelectedRange(begin, end); Mpd.StartCommandsList(); - for (size_t i = beginning, j = end-1; i < (beginning+end)/2; ++i, --j) - Mpd.Swap(i, j); + for (--end; begin < end; ++begin, --end) + Mpd.Swap(begin->value().getPosition(), end->value().getPosition()); if (Mpd.CommitCommandsList()) Statusbar::msg("Playlist reversed"); } |