diff --git a/CHANGELOG.md b/CHANGELOG.md index 74584edc..d8731a0d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ * Do not loop after sending a database update command to Mopidy. * Deprecate `visualizer_sync_interval` configuration option. * Deprecate `noop` value of `browser_sort_mode` in favor of `none`. +* Add `type` value of `browser_sort_mode` (set by default). # ncmpcpp-0.8.2 (2018-04-11) * Help screen: fixed display of EoF keycode diff --git a/doc/config b/doc/config index e9402817..4fc4cae0 100644 --- a/doc/config +++ b/doc/config @@ -268,10 +268,10 @@ ## Note: Below variables are used for sorting songs in browser. The sort mode ## determines how songs are sorted, and can be used in combination with a sort ## format to specify a custom sorting format. Available values for -## browser_sort_mode are "name", "mtime", "format" and "none". +## browser_sort_mode are "type", "name", "mtime", "format" and "none". ## # -#browser_sort_mode = name +#browser_sort_mode = type # #browser_sort_format = {%a - }{%t}|{%f} {(%l)} # diff --git a/doc/ncmpcpp.1 b/doc/ncmpcpp.1 index 0866e58e..83bcd3c9 100644 --- a/doc/ncmpcpp.1 +++ b/doc/ncmpcpp.1 @@ -173,7 +173,7 @@ Suffix for selected items. Prefix for modified item (tag editor). .TP .B browser_sort_mode -Determines sort mode for browser. Possible values are "name", "mtime", "format" and "none". +Determines sort mode for browser. Possible values are "type", "name", "mtime", "format" and "none". .TP .B browser_sort_format Format to use for sorting songs in browser. For this option to be effective, browser_sort_mode must be set to "format". diff --git a/src/actions.cpp b/src/actions.cpp index ae900b61..1a55b512 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -2261,6 +2261,9 @@ void ToggleBrowserSortMode::run() { switch (Config.browser_sort_mode) { + case SortMode::Type: + Config.browser_sort_mode = SortMode::Name; + Statusbar::print("Sort songs by: name"); case SortMode::Name: Config.browser_sort_mode = SortMode::ModificationTime; Statusbar::print("Sort songs by: modification time"); @@ -2274,15 +2277,16 @@ void ToggleBrowserSortMode::run() Statusbar::print("Do not sort songs"); break; case SortMode::None: - Config.browser_sort_mode = SortMode::Name; - Statusbar::print("Sort songs by: name"); + Config.browser_sort_mode = SortMode::Type; + Statusbar::print("Sort songs by: type"); } if (Config.browser_sort_mode != SortMode::None) { size_t sort_offset = myBrowser->inRootDirectory() ? 0 : 1; - std::sort(myBrowser->main().begin()+sort_offset, myBrowser->main().end(), - LocaleBasedItemSorting(std::locale(), Config.ignore_leading_the, Config.browser_sort_mode) - ); + std::stable_sort( + myBrowser->main().begin()+sort_offset, myBrowser->main().end(), + LocaleBasedItemSorting(std::locale(), Config.ignore_leading_the, + Config.browser_sort_mode)); } } diff --git a/src/enums.cpp b/src/enums.cpp index 34860c03..ad9a052c 100644 --- a/src/enums.cpp +++ b/src/enums.cpp @@ -78,6 +78,9 @@ std::ostream &operator<<(std::ostream &os, SortMode sm) { switch (sm) { + case SortMode::Type: + os << "type"; + break; case SortMode::Name: os << "name"; break; @@ -98,7 +101,9 @@ std::istream &operator>>(std::istream &is, SortMode &sm) { std::string ssm; is >> ssm; - if (ssm == "name") + if (ssm == "type") + sm = SortMode::Type; + else if (ssm == "name") sm = SortMode::Name; else if (ssm == "mtime") sm = SortMode::ModificationTime; diff --git a/src/enums.h b/src/enums.h index 61bd00ab..d3055c0b 100644 --- a/src/enums.h +++ b/src/enums.h @@ -32,7 +32,7 @@ enum class SpaceAddMode { AddRemove, AlwaysAdd }; std::ostream &operator<<(std::ostream &os, SpaceAddMode sam); std::istream &operator>>(std::istream &is, SpaceAddMode &sam); -enum class SortMode { Name, ModificationTime, CustomFormat, None }; +enum class SortMode { Type, Name, ModificationTime, CustomFormat, None }; std::ostream &operator<<(std::ostream &os, SortMode sm); std::istream &operator>>(std::istream &is, SortMode &sm); diff --git a/src/screens/browser.cpp b/src/screens/browser.cpp index 17d61012..7303f41c 100644 --- a/src/screens/browser.cpp +++ b/src/screens/browser.cpp @@ -500,8 +500,10 @@ void Browser::getDirectory(std::string directory) if (Config.browser_sort_mode != SortMode::None) { - std::sort(w.begin() + (is_root ? 0 : 1), w.end(), - LocaleBasedItemSorting(std::locale(), Config.ignore_leading_the, Config.browser_sort_mode)); + std::stable_sort( + w.begin() + (is_root ? 0 : 1), w.end(), + LocaleBasedItemSorting(std::locale(), Config.ignore_leading_the, + Config.browser_sort_mode)); } } @@ -681,8 +683,8 @@ void getLocalDirectoryRecursively(std::vector &songs, const std::stri if (Config.browser_sort_mode != SortMode::None) { - std::sort(songs.begin()+sort_offset, songs.end(), - LocaleBasedSorting(std::locale(), Config.ignore_leading_the) + std::stable_sort(songs.begin()+sort_offset, songs.end(), + LocaleBasedSorting(std::locale(), Config.ignore_leading_the) ); } } diff --git a/src/settings.cpp b/src/settings.cpp index 31e04858..b493a8dc 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -387,7 +387,7 @@ bool Configuration::read(const std::vector &config_paths, bool igno "{%a - }{%t}|{%f}", [](std::string v) { return Format::parse(v, Format::Flags::Tag); }); - p.add("browser_sort_mode", &browser_sort_mode, "name", [](std::string v) { + p.add("browser_sort_mode", &browser_sort_mode, "type", [](std::string v) { if (v == "noop") { deprecated("browser_sort_mode = 'noop'", diff --git a/src/utility/comparators.cpp b/src/utility/comparators.cpp index 8dbc7d58..66ea16e6 100644 --- a/src/utility/comparators.cpp +++ b/src/utility/comparators.cpp @@ -58,6 +58,9 @@ bool LocaleBasedItemSorting::operator()(const MPD::Item &a, const MPD::Item &b) { switch (m_sort_mode) { + case SortMode::Type: + result = a.type() > b.type(); + break; case SortMode::Name: switch (a.type()) {