aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/MenuItem.hh
diff options
context:
space:
mode:
authorMathias Gumz <akira@fluxbox.org>2015-01-28 15:02:59 (GMT)
committerMathias Gumz <akira@fluxbox.org>2015-01-28 15:02:59 (GMT)
commit03ce82a4737b834767c03341db9362ada24c775a (patch)
tree2444031bbd47d97b1e0af64aa2f1d2a037a08a2e /src/FbTk/MenuItem.hh
parentfc245408d6975d0813cd4440e7089d987b54d42e (diff)
downloadfluxbox-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/MenuItem.hh')
-rw-r--r--src/FbTk/MenuItem.hh25
1 files changed, 8 insertions, 17 deletions
diff --git a/src/FbTk/MenuItem.hh b/src/FbTk/MenuItem.hh
index 320d065..4bbfcf3 100644
--- a/src/FbTk/MenuItem.hh
+++ b/src/FbTk/MenuItem.hh
@@ -47,8 +47,7 @@ public:
47 m_enabled(true), 47 m_enabled(true),
48 m_selected(false), 48 m_selected(false),
49 m_close_on_click(true), 49 m_close_on_click(true),
50 m_toggle_item(false), 50 m_toggle_item(false)
51 m_index(0)
52 { } 51 { }
53 52
54 explicit MenuItem(const BiDiString &label) 53 explicit MenuItem(const BiDiString &label)
@@ -58,8 +57,7 @@ public:
58 m_enabled(true), 57 m_enabled(true),
59 m_selected(false), 58 m_selected(false),
60 m_close_on_click(true), 59 m_close_on_click(true),
61 m_toggle_item(false), 60 m_toggle_item(false)
62 m_index(0)
63 { } 61 { }
64 62
65 MenuItem(const BiDiString &label, Menu &host_menu) 63 MenuItem(const BiDiString &label, Menu &host_menu)
@@ -69,8 +67,7 @@ public:
69 m_enabled(true), 67 m_enabled(true),
70 m_selected(false), 68 m_selected(false),
71 m_close_on_click(true), 69 m_close_on_click(true),
72 m_toggle_item(false), 70 m_toggle_item(false)
73 m_index(0)
74 { } 71 { }
75 /// create a menu item with a specific command to be executed on click 72 /// create a menu item with a specific command to be executed on click
76 MenuItem(const BiDiString &label, RefCount<Command<void> > &cmd, Menu *menu = 0) 73 MenuItem(const BiDiString &label, RefCount<Command<void> > &cmd, Menu *menu = 0)
@@ -81,8 +78,7 @@ public:
81 m_enabled(true), 78 m_enabled(true),
82 m_selected(false), 79 m_selected(false),
83 m_close_on_click(true), 80 m_close_on_click(true),
84 m_toggle_item(false), 81 m_toggle_item(false)
85 m_index(0)
86 { } 82 { }
87 83
88 MenuItem(const BiDiString &label, Menu *submenu, Menu *host_menu = 0) 84 MenuItem(const BiDiString &label, Menu *submenu, Menu *host_menu = 0)
@@ -92,10 +88,9 @@ public:
92 m_enabled(true), 88 m_enabled(true),
93 m_selected(false), 89 m_selected(false),
94 m_close_on_click(true), 90 m_close_on_click(true),
95 m_toggle_item(false), 91 m_toggle_item(false)
96 m_index(0)
97 { } 92 { }
98 virtual ~MenuItem() { } 93 virtual ~MenuItem();
99 94
100 void setCommand(RefCount<Command<void> > &cmd) { m_command = cmd; } 95 void setCommand(RefCount<Command<void> > &cmd) { m_command = cmd; }
101 virtual void setSelected(bool selected) { m_selected = selected; } 96 virtual void setSelected(bool selected) { m_selected = selected; }
@@ -119,14 +114,12 @@ public:
119 virtual bool isToggleItem() const { return m_toggle_item; } 114 virtual bool isToggleItem() const { return m_toggle_item; }
120 115
121 // iType functions 116 // iType functions
122 virtual void setIndex(int index) { m_index = index; }
123 virtual int getIndex() { return m_index; }
124 const FbString &iTypeString() const { return m_label.visual(); } 117 const FbString &iTypeString() const { return m_label.visual(); }
125 virtual void drawLine(FbDrawable &draw, 118 virtual void drawLine(FbDrawable &draw,
126 const FbTk::ThemeProxy<MenuTheme> &theme, 119 const FbTk::ThemeProxy<MenuTheme> &theme,
127 size_t size, 120 size_t n_chars,
128 int text_x, int text_y, 121 int text_x, int text_y,
129 unsigned int width) const; 122 unsigned int width, size_t skip_chars = 0) const;
130 123
131 virtual unsigned int width(const FbTk::ThemeProxy<MenuTheme> &theme) const; 124 virtual unsigned int width(const FbTk::ThemeProxy<MenuTheme> &theme) const;
132 virtual unsigned int height(const FbTk::ThemeProxy<MenuTheme> &theme) const; 125 virtual unsigned int height(const FbTk::ThemeProxy<MenuTheme> &theme) const;
@@ -160,14 +153,12 @@ private:
160 RefCount<Command<void> > m_command; ///< command to be executed 153 RefCount<Command<void> > m_command; ///< command to be executed
161 bool m_enabled, m_selected; 154 bool m_enabled, m_selected;
162 bool m_close_on_click, m_toggle_item; 155 bool m_close_on_click, m_toggle_item;
163 int m_index;
164 156
165 struct Icon { 157 struct Icon {
166 std::auto_ptr<PixmapWithMask> pixmap; 158 std::auto_ptr<PixmapWithMask> pixmap;
167 std::string filename; 159 std::string filename;
168 }; 160 };
169 std::auto_ptr<Icon> m_icon; 161 std::auto_ptr<Icon> m_icon;
170
171}; 162};
172 163
173} // end namespace FbTk 164} // end namespace FbTk