diff options
author | Mathias Gumz <akira@fluxbox.org> | 2015-01-28 15:02:59 (GMT) |
---|---|---|
committer | Mathias Gumz <akira@fluxbox.org> | 2015-01-28 15:02:59 (GMT) |
commit | 03ce82a4737b834767c03341db9362ada24c775a (patch) | |
tree | 2444031bbd47d97b1e0af64aa2f1d2a037a08a2e /src/FbTk/Menu.hh | |
parent | fc245408d6975d0813cd4440e7089d987b54d42e (diff) | |
download | fluxbox-03ce82a4737b834767c03341db9362ada24c775a.zip fluxbox-03ce82a4737b834767c03341db9362ada24c775a.tar.bz2 |
Feature: typeahead in menu matches text anywhere
This commit implements a tweak to the typeahead feature already existent in
fluxbox: If the user opens up a menu and starts typing, fluxbox tries to
detect matching menu items and makes them available for quick selection.
The typed pattern is now search also in the middle of the text.
I opted to strip down the code quite a bit and remove complexity by throwing
out FbTk::TypeAhead and FbTk::SearchResult because I do not see the need for a
general solution when the only use case for such a feature is in fluxbox'
menus. FbTk::ITypeAheadable shrunk down to 2 functions; the whole file might
be combined with the code that implements FbTk::Menu::TypeSearch.
FbTk::Menu::setIndex() and related code is also gone: the position of each
menu item is defined by it's position in the items container. This reduces the
mount of book keeping fluxbox has to do. Fewer moving parts is a good thing.
It's possible that users start to complaint because they expect their
typed pattern to match only at the beginning of the text OR that some
demand other tweaks. We will see.
This commit also fixes a regression introduced by 8387742c. The bug made
the menu vanish.
Diffstat (limited to 'src/FbTk/Menu.hh')
-rw-r--r-- | src/FbTk/Menu.hh | 49 |
1 files changed, 22 insertions, 27 deletions
diff --git a/src/FbTk/Menu.hh b/src/FbTk/Menu.hh index 9716a89..39440a8 100644 --- a/src/FbTk/Menu.hh +++ b/src/FbTk/Menu.hh | |||
@@ -33,7 +33,6 @@ | |||
33 | #include "EventHandler.hh" | 33 | #include "EventHandler.hh" |
34 | #include "MenuTheme.hh" | 34 | #include "MenuTheme.hh" |
35 | #include "Timer.hh" | 35 | #include "Timer.hh" |
36 | #include "TypeAhead.hh" | ||
37 | 36 | ||
38 | namespace FbTk { | 37 | namespace FbTk { |
39 | 38 | ||
@@ -53,6 +52,7 @@ public: | |||
53 | 52 | ||
54 | enum Alignment{ ALIGNDONTCARE = 1, ALIGNTOP, ALIGNBOTTOM }; | 53 | enum Alignment{ ALIGNDONTCARE = 1, ALIGNTOP, ALIGNBOTTOM }; |
55 | enum { RIGHT = 1, LEFT }; | 54 | enum { RIGHT = 1, LEFT }; |
55 | enum { UP = 1, DOWN = 0 }; | ||
56 | 56 | ||
57 | /** | 57 | /** |
58 | Bullet type | 58 | Bullet type |
@@ -71,6 +71,7 @@ public: | |||
71 | int insertSubmenu(const FbString &label, Menu *submenu, int pos= -1); | 71 | int insertSubmenu(const FbString &label, Menu *submenu, int pos= -1); |
72 | int insertItem(MenuItem *item, int pos=-1); | 72 | int insertItem(MenuItem *item, int pos=-1); |
73 | int remove(unsigned int item); | 73 | int remove(unsigned int item); |
74 | int removeItem(MenuItem* item); | ||
74 | void removeAll(); | 75 | void removeAll(); |
75 | void setInternalMenu(bool val = true) { m_internal_menu = val; } | 76 | void setInternalMenu(bool val = true) { m_internal_menu = val; } |
76 | void setAlignment(Alignment a) { m_alignment = a; } | 77 | void setAlignment(Alignment a) { m_alignment = a; } |
@@ -180,24 +181,16 @@ private: | |||
180 | void startHide(); | 181 | void startHide(); |
181 | void stopHide(); | 182 | void stopHide(); |
182 | 183 | ||
183 | FbTk::ThemeProxy<MenuTheme> &m_theme; | ||
184 | Menu *m_parent; | ||
185 | ImageControl &m_image_ctrl; | ||
186 | |||
187 | typedef std::vector<MenuItem *> Menuitems; | ||
188 | Menuitems m_items; | ||
189 | TypeAhead<Menuitems, MenuItem *> m_type_ahead; | ||
190 | Menuitems m_matches; | ||
191 | |||
192 | void resetTypeAhead(); | 184 | void resetTypeAhead(); |
193 | void drawTypeAheadItems(); | 185 | void drawTypeAheadItems(); |
194 | void drawLine(int index, int size); | ||
195 | void fixMenuItemIndices(); | ||
196 | 186 | ||
197 | struct Rect { | 187 | |
198 | int x, y; | 188 | Menu *m_parent; |
199 | unsigned int width, height; | 189 | |
200 | } m_screen; | 190 | class TypeSearch; |
191 | |||
192 | std::vector<MenuItem *> m_items; | ||
193 | std::auto_ptr<TypeSearch> m_search; | ||
201 | 194 | ||
202 | struct State { | 195 | struct State { |
203 | bool moving; | 196 | bool moving; |
@@ -206,14 +199,20 @@ private: | |||
206 | bool torn; // torn from parent | 199 | bool torn; // torn from parent |
207 | } m_state; | 200 | } m_state; |
208 | 201 | ||
202 | bool m_need_update; | ||
209 | bool m_internal_menu; ///< whether we should destroy this menu or if it's managed somewhere else | 203 | bool m_internal_menu; ///< whether we should destroy this menu or if it's managed somewhere else |
204 | int m_active_index; ///< current highlighted index | ||
210 | int m_which_sub; | 205 | int m_which_sub; |
206 | int m_x_move; | ||
207 | int m_y_move; | ||
211 | 208 | ||
212 | Alignment m_alignment; | 209 | struct Rect { |
210 | int x, y; | ||
211 | unsigned int width, height; | ||
212 | } m_screen; | ||
213 | 213 | ||
214 | // the menu window | 214 | // the menu window |
215 | FbTk::FbWindow m_window; | 215 | FbTk::FbWindow m_window; |
216 | Pixmap m_hilite_pixmap; | ||
217 | 216 | ||
218 | // the title | 217 | // the title |
219 | struct Title { | 218 | struct Title { |
@@ -231,24 +230,20 @@ private: | |||
231 | } m_frame; | 230 | } m_frame; |
232 | 231 | ||
233 | 232 | ||
234 | int m_x_move; | ||
235 | int m_y_move; | ||
236 | |||
237 | // the menuitems are rendered in a grid with | 233 | // the menuitems are rendered in a grid with |
238 | // 'm_columns' (a minimum of 'm_min_columns') and | 234 | // 'm_columns' (a minimum of 'm_min_columns') and |
239 | // a max of 'm_rows_per_column' | 235 | // a max of 'm_rows_per_column' |
240 | int m_columns; | 236 | int m_columns; |
241 | int m_rows_per_column; | 237 | int m_rows_per_column; |
242 | int m_min_columns; | 238 | int m_min_columns; |
243 | |||
244 | unsigned int m_item_w; | 239 | unsigned int m_item_w; |
245 | 240 | ||
246 | int m_active_index; ///< current highlighted index | 241 | FbTk::ThemeProxy<MenuTheme>& m_theme; |
247 | 242 | ImageControl& m_image_ctrl; | |
248 | // the corners | 243 | std::auto_ptr<FbTk::Shape> m_shape; // the corners |
249 | std::auto_ptr<FbTk::Shape> m_shape; | 244 | Pixmap m_hilite_pixmap; |
245 | Alignment m_alignment; | ||
250 | 246 | ||
251 | bool m_need_update; | ||
252 | Timer m_submenu_timer; | 247 | Timer m_submenu_timer; |
253 | Timer m_hide_timer; | 248 | Timer m_hide_timer; |
254 | 249 | ||