diff options
author | Mathias Gumz <akira@fluxbox.org> | 2015-02-05 20:30:44 (GMT) |
---|---|---|
committer | Mathias Gumz <akira@fluxbox.org> | 2015-02-05 20:30:44 (GMT) |
commit | 0da4be2a0114d4419ceb70a4c6b6342f8fd79852 (patch) | |
tree | 371575758618de52415c823f756346cb3e1a5bb4 /src/FbTk/MenuSearch.hh | |
parent | e79228cc08ee1d0d20d7ef27103a5d167fb8f133 (diff) | |
download | fluxbox-0da4be2a0114d4419ceb70a4c6b6342f8fd79852.zip fluxbox-0da4be2a0114d4419ceb70a4c6b6342f8fd79852.tar.bz2 |
Feature: different MenuSearch modes
Fluxbox now supports three MenuSearch modes:
* NoWhere - essentially "disabling" the menu search.
* Somewhere - the search string matches somewhere.
* ItemStart - the search string matches at the start of a menu item.
The default value is "ItemStart", just in the good old times. As long as
this feature is not configurable via the menu it would irritate users
with distinct muscle memory who type without thinking OR checking the
visual feedback: they would trigger items they did not intent to trigger
after years of the old behavior.
Once this feature get's an entry in the config menu the default value
might change.
Diffstat (limited to 'src/FbTk/MenuSearch.hh')
-rw-r--r-- | src/FbTk/MenuSearch.hh | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/FbTk/MenuSearch.hh b/src/FbTk/MenuSearch.hh new file mode 100644 index 0000000..d642929 --- /dev/null +++ b/src/FbTk/MenuSearch.hh | |||
@@ -0,0 +1,60 @@ | |||
1 | #ifndef _MENU_SEARCH_HH_ | ||
2 | #define _MENU_SEARCH_HH_ | ||
3 | |||
4 | #include <vector> | ||
5 | #include <string> | ||
6 | #include <cstddef> | ||
7 | |||
8 | namespace FbTk { | ||
9 | |||
10 | class MenuItem; | ||
11 | |||
12 | |||
13 | // a small helper which applies search operations on a list of MenuItems*. | ||
14 | // the former incarnation of this class was FbTk::TypeAhead in combination with | ||
15 | // the now non-existent FbTk::SearchResults, but the complexity of these | ||
16 | // are not needed for our use case. as a bonus we have less lose parts | ||
17 | // flying around. | ||
18 | |||
19 | class MenuSearch { | ||
20 | public: | ||
21 | |||
22 | enum Mode { | ||
23 | NOWHERE, | ||
24 | ITEMSTART, | ||
25 | SOMEWHERE, | ||
26 | |||
27 | DEFAULT = ITEMSTART | ||
28 | }; | ||
29 | |||
30 | static void setMode(Mode m); | ||
31 | |||
32 | |||
33 | MenuSearch(const std::vector<FbTk::MenuItem*>& items); | ||
34 | |||
35 | size_t size() const; | ||
36 | void clear(); | ||
37 | void add(char c); | ||
38 | void backspace(); | ||
39 | |||
40 | // is 'pattern' matching something? | ||
41 | bool has_match(); | ||
42 | |||
43 | // would 'the_pattern' match something? | ||
44 | bool would_match(const std::string& the_pattern); | ||
45 | |||
46 | size_t num_matches(); | ||
47 | |||
48 | // returns true if m_text matches against m_items[i] and stores | ||
49 | // the position where it matches in the string | ||
50 | bool get_match(size_t i, size_t& idx); | ||
51 | |||
52 | std::string pattern; | ||
53 | private: | ||
54 | const std::vector<FbTk::MenuItem*>& m_items; | ||
55 | }; | ||
56 | |||
57 | } | ||
58 | |||
59 | |||
60 | #endif | ||