browser: make sorting optional

This adds a new option, "noop", to browser_sort_mode. If this mode
is selected, no sorting is done in the browser view, and the elements
are shown in the same order as received from the MPD server.
master
Trygve Aaberge 12 years ago committed by Andrzej Rybczak
parent 49f53c07bb
commit 9e8dc741e5
  1. 3
      doc/config
  2. 2
      doc/ncmpcpp.1
  3. 17
      src/actions.cpp
  4. 11
      src/browser.cpp
  5. 5
      src/enums.cpp
  6. 2
      src/enums.h
  7. 2
      src/utility/comparators.cpp

@ -183,7 +183,8 @@
## 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" and "format".
## Available values for browser_sort_mode are "name", "mtime", "format"
## and "noop".
##
#
#browser_sort_mode = name

@ -109,7 +109,7 @@ Format for albums' list in Tag editor.
Song format for window title.
.TP
.B browser_sort_mode
Determines sort mode for browser. Possible values are "name", "mtime" and "format".
Determines sort mode for browser. Possible values are "name", "mtime", "format" and "noop".
.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".

@ -2060,19 +2060,24 @@ void ToggleBrowserSortMode::run()
{
case SortMode::Name:
Config.browser_sort_mode = SortMode::ModificationTime;
Statusbar::print("Sort songs by: Modification time");
Statusbar::print("Sort songs by: modification time");
break;
case SortMode::ModificationTime:
Config.browser_sort_mode = SortMode::CustomFormat;
Statusbar::print("Sort songs by: Custom format");
Statusbar::print("Sort songs by: custom format");
break;
case SortMode::CustomFormat:
Config.browser_sort_mode = SortMode::Name;
Statusbar::print("Sort songs by: Name");
Config.browser_sort_mode = SortMode::NoOp;
Statusbar::print("Do not sort songs");
break;
case SortMode::NoOp:
Config.browser_sort_mode = SortMode::Name;
Statusbar::print("Sort songs by: name");
}
std::sort(myBrowser->main().begin()+(myBrowser->CurrentDir() != "/"), myBrowser->main().end(),
LocaleBasedItemSorting(std::locale(), Config.ignore_leading_the, Config.browser_sort_mode));
if (Config.browser_sort_mode != SortMode::NoOp)
std::sort(myBrowser->main().begin()+(myBrowser->CurrentDir() != "/"), myBrowser->main().end(),
LocaleBasedItemSorting(std::locale(), Config.ignore_leading_the, Config.browser_sort_mode)
);
}
bool ToggleLibraryTagType::canBeRun() const

@ -437,9 +437,10 @@ void Browser::GetDirectory(std::string dir, std::string subdir)
# else
list = Mpd.GetDirectory(dir);
# endif // !WIN32
if (!isLocal()) // local directory is already sorted
if (Config.browser_sort_mode != SortMode::NoOp && !isLocal()) // local directory is already sorted
std::sort(list.begin(), list.end(),
LocaleBasedItemSorting(std::locale(), Config.ignore_leading_the, Config.browser_sort_mode));
LocaleBasedItemSorting(std::locale(), Config.ignore_leading_the, Config.browser_sort_mode)
);
for (MPD::ItemList::iterator it = list.begin(); it != list.end(); ++it)
{
@ -517,8 +518,10 @@ void Browser::GetLocalDirectory(MPD::ItemList &v, const std::string &directory,
}
});
std::sort(v.begin()+start_size, v.end(), LocaleBasedItemSorting(std::locale(),
Config.ignore_leading_the, Config.browser_sort_mode));
if (Config.browser_sort_mode != SortMode::NoOp)
std::sort(v.begin()+start_size, v.end(),
LocaleBasedItemSorting(std::locale(), Config.ignore_leading_the, Config.browser_sort_mode)
);
}
void Browser::ClearDirectory(const std::string &path) const

@ -60,6 +60,9 @@ std::ostream &operator<<(std::ostream &os, SortMode sm)
case SortMode::CustomFormat:
os << "format";
break;
case SortMode::NoOp:
os << "noop";
break;
}
return os;
}
@ -74,6 +77,8 @@ std::istream &operator>>(std::istream &is, SortMode &sm)
sm = SortMode::ModificationTime;
else if (ssm == "format")
sm = SortMode::CustomFormat;
else if (ssm == "noop")
sm = SortMode::NoOp;
else
is.setstate(std::ios::failbit);
return is;

@ -27,7 +27,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 };
enum class SortMode { Name, ModificationTime, CustomFormat, NoOp };
std::ostream &operator<<(std::ostream &os, SortMode sm);
std::istream &operator>>(std::istream &is, SortMode &sm);

@ -78,6 +78,8 @@ bool LocaleBasedItemSorting::operator()(const MPD::Item &a, const MPD::Item &b)
result = m_cmp(a.song->toString(Config.browser_sort_format, Config.tags_separator),
b.song->toString(Config.browser_sort_format, Config.tags_separator));
break;
case SortMode::NoOp:
throw std::logic_error("can't sort with NoOp sorting mode");
}
break;
}

Loading…
Cancel
Save