diff options
author | Andrzej Rybczak <electricityispower@gmail.com> | 2014-11-04 20:53:03 +0100 |
---|---|---|
committer | Andrzej Rybczak <electricityispower@gmail.com> | 2014-11-04 21:31:07 +0100 |
commit | 12772c47f98f233816d4f788410ace364a2b8504 (patch) | |
tree | b3b92f06c39e44d6257a5c5bbc17e2101b0925b5 /src/helpers.h | |
parent | c01e734e6e16fc345311819b61dde2bf6f682208 (diff) |
menu: remove search related methods
Diffstat (limited to 'src/helpers.h')
-rw-r--r-- | src/helpers.h | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/helpers.h b/src/helpers.h index 51a35308..7dc3b500 100644 --- a/src/helpers.h +++ b/src/helpers.h @@ -29,6 +29,41 @@ #include "utility/string.h" #include "utility/wide_string.h" +template <typename Iterator, typename PredicateT> +Iterator wrappedSearch(Iterator begin, Iterator current, Iterator end, + const PredicateT &pred, bool wrap) +{ + ++current; + auto it = std::find_if(current, end, pred); + if (it == end && wrap) + { + it = std::find_if(begin, current, pred); + if (it == current) + it = end; + } + return it; +} + +template <typename ItemT, typename PredicateT> +void searchForward(NC::Menu<ItemT> &m, const PredicateT &pred, bool wrap) +{ +if (!pred.defined()) + return; + auto it = wrappedSearch(m.begin(), m.currentI(), m.end(), pred, wrap); + if (it != m.end()) + m.highlight(it-m.begin()); +} + +template <typename ItemT, typename PredicateT> +void searchBackward(NC::Menu<ItemT> &m, const PredicateT &pred, bool wrap) +{ + if (!pred.defined()) + return; + auto it = wrappedSearch(m.rbegin(), m.currentRI(), m.rend(), pred, wrap); + if (it != m.rend()) + m.highlight(m.size()-1-(it-m.rbegin())); +} + inline HasColumns *hasColumns(BaseScreen *screen) { return dynamic_cast<HasColumns *>(screen); |