diff options
author | Mathias Gumz <akira@fluxbox.org> | 2015-01-15 13:24:46 (GMT) |
---|---|---|
committer | Mathias Gumz <akira@fluxbox.org> | 2015-01-15 13:25:05 (GMT) |
commit | 8387742c8860694777f7c2c62da0a90c9e836988 (patch) | |
tree | e5bd5a50c3e033ea73a9339474750287d06aeb3f /src/IconbarTool.cc | |
parent | b4cd45549013e8b45f95bf3e123cd14684948e91 (diff) | |
download | fluxbox-8387742c8860694777f7c2c62da0a90c9e836988.zip fluxbox-8387742c8860694777f7c2c62da0a90c9e836988.tar.bz2 |
Refactor menu code: be more explicit and compact
This commit is a preparation step for some menu cleanup ahead. To make it
easier to understand which types of MenuItems are added where and when, I
converted the overloaded FbTk::Menu::insert() functions into explicit ones
(Menu::insertSubmenu(), Menu::insertItem(), etc. ). This makes it possible
to just grep for 'insertSubmenu()'.
Side effect this commit: it trims down the very verbose creation of menu items
in regards to how the labels are created.
Minor: FbTk::Menu::shown and FbTk::Menu::s_focused are moved out of the class.
Diffstat (limited to 'src/IconbarTool.cc')
-rw-r--r-- | src/IconbarTool.cc | 115 |
1 files changed, 49 insertions, 66 deletions
diff --git a/src/IconbarTool.cc b/src/IconbarTool.cc index 45e3a45..294d17a 100644 --- a/src/IconbarTool.cc +++ b/src/IconbarTool.cc | |||
@@ -54,11 +54,7 @@ | |||
54 | 54 | ||
55 | #include <typeinfo> | 55 | #include <typeinfo> |
56 | #include <iterator> | 56 | #include <iterator> |
57 | #ifdef HAVE_CSTRING | 57 | #include <cstring> |
58 | #include <cstring> | ||
59 | #else | ||
60 | #include <string.h> | ||
61 | #endif | ||
62 | 58 | ||
63 | using std::string; | 59 | using std::string; |
64 | using std::list; | 60 | using std::list; |
@@ -134,73 +130,60 @@ private: | |||
134 | FbTk::Container::Alignment m_mode; | 130 | FbTk::Container::Alignment m_mode; |
135 | }; | 131 | }; |
136 | 132 | ||
133 | |||
134 | enum { | ||
135 | L_TITLE = 0, | ||
136 | L_MODE_NONE, | ||
137 | L_MODE_ICONS, | ||
138 | L_MODE_NO_ICONS, | ||
139 | L_MODE_ICONS_WORKSPACE, | ||
140 | L_MODE_NOICONS_WORKSPACE, | ||
141 | L_MODE_WORKSPACE, | ||
142 | L_MODE_ALL, | ||
143 | |||
144 | L_LEFT, | ||
145 | L_RELATIVE, | ||
146 | L_RIGHT, | ||
147 | }; | ||
148 | |||
137 | void setupModeMenu(FbTk::Menu &menu, IconbarTool &handler) { | 149 | void setupModeMenu(FbTk::Menu &menu, IconbarTool &handler) { |
150 | |||
138 | using namespace FbTk; | 151 | using namespace FbTk; |
139 | _FB_USES_NLS; | 152 | _FB_USES_NLS; |
140 | 153 | ||
141 | menu.setLabel(_FB_XTEXT(Toolbar, IconbarMode, "Iconbar Mode", "Menu title - chooses which set of icons are shown in the iconbar")); | 154 | static const FbString _labels[] = { |
155 | _FB_XTEXT(Toolbar, IconbarMode, "Iconbar Mode", "Menu title - chooses which set of icons are shown in the iconbar"), | ||
156 | _FB_XTEXT(Toolbar, IconbarModeNone, "None", "No icons are shown in the iconbar"), | ||
157 | _FB_XTEXT(Toolbar, IconbarModeIcons, "Icons", "Iconified windows from all workspaces are shown"), | ||
158 | _FB_XTEXT(Toolbar, IconbarModeNoIcons, "NoIcons", "No iconified windows from all workspaces are shown"), | ||
159 | _FB_XTEXT(Toolbar, IconbarModeWorkspaceIcons, "WorkspaceIcons", "Iconified windows from this workspace are shown"), | ||
160 | _FB_XTEXT(Toolbar, IconbarModeWorkspaceNoIcons, "WorkspaceNoIcons", "No iconified windows from this workspace are shown"), | ||
161 | _FB_XTEXT(Toolbar, IconbarModeWorkspace, "Workspace", "Normal and iconified windows from this workspace are shown"), | ||
162 | _FB_XTEXT(Toolbar, IconbarModeAllWindows, "All Windows", "All windows are shown"), | ||
163 | |||
164 | _FB_XTEXT(Align, Left, "Left", "Align to the left"), | ||
165 | _FB_XTEXT(Align, Relative, "Relative", "Align relative to the width"), | ||
166 | _FB_XTEXT(Align, Right, "Right", "Align to the right"), | ||
167 | }; | ||
142 | 168 | ||
143 | RefCount<Command<void> > saverc_cmd(new FbCommands::SaveResources()); | 169 | RefCount<Command<void> > saverc_cmd(new FbCommands::SaveResources()); |
144 | 170 | ||
171 | menu.setLabel(_labels[L_TITLE]); | ||
172 | menu.insertItem(new ToolbarModeMenuItem(_labels[L_MODE_NONE], handler, "none", saverc_cmd)); | ||
173 | menu.insertItem(new ToolbarModeMenuItem(_labels[L_MODE_ICONS], handler, "{static groups} (minimized=yes)", saverc_cmd)); | ||
174 | menu.insertItem(new ToolbarModeMenuItem(_labels[L_MODE_NO_ICONS], handler, "{static groups} (minimized=no)", saverc_cmd)); | ||
175 | menu.insertItem(new ToolbarModeMenuItem(_labels[L_MODE_ICONS_WORKSPACE], handler, "{static groups} (minimized=yes) (workspace)", saverc_cmd)); | ||
176 | menu.insertItem(new ToolbarModeMenuItem(_labels[L_MODE_NOICONS_WORKSPACE], handler, "{static groups} (minimized=no) (workspace)", saverc_cmd)); | ||
177 | menu.insertItem(new ToolbarModeMenuItem(_labels[L_MODE_WORKSPACE], handler, "{static groups} (workspace)", saverc_cmd)); | ||
178 | menu.insertItem(new ToolbarModeMenuItem(_labels[L_MODE_ALL], handler, "{static groups}", saverc_cmd)); | ||
179 | |||
180 | menu.insertItem(new FbTk::MenuSeparator()); | ||
181 | |||
182 | menu.insertItem(new ToolbarAlignMenuItem(_labels[L_LEFT], handler, FbTk::Container::LEFT, saverc_cmd)); | ||
183 | menu.insertItem(new ToolbarAlignMenuItem(_labels[L_RELATIVE], handler, FbTk::Container::RELATIVE, saverc_cmd)); | ||
184 | menu.insertItem(new ToolbarAlignMenuItem(_labels[L_RIGHT], handler, FbTk::Container::RIGHT, saverc_cmd)); | ||
145 | 185 | ||
146 | menu.insert(new ToolbarModeMenuItem(_FB_XTEXT(Toolbar, IconbarModeNone, | 186 | menu.insertItem(new FbTk::MenuSeparator()); |
147 | "None", "No icons are shown in the iconbar"), | ||
148 | handler, | ||
149 | "none", saverc_cmd)); | ||
150 | |||
151 | menu.insert(new ToolbarModeMenuItem( | ||
152 | _FB_XTEXT(Toolbar, IconbarModeIcons, | ||
153 | "Icons", "Iconified windows from all workspaces are shown"), | ||
154 | handler, | ||
155 | "{static groups} (minimized=yes)", saverc_cmd)); | ||
156 | |||
157 | menu.insert(new ToolbarModeMenuItem( | ||
158 | _FB_XTEXT(Toolbar, IconbarModeNoIcons, | ||
159 | "NoIcons", "No iconified windows from all workspaces are shown"), | ||
160 | handler, | ||
161 | "{static groups} (minimized=no)", saverc_cmd)); | ||
162 | |||
163 | menu.insert(new ToolbarModeMenuItem( | ||
164 | _FB_XTEXT(Toolbar, IconbarModeWorkspaceIcons, | ||
165 | "WorkspaceIcons", "Iconified windows from this workspace are shown"), | ||
166 | handler, | ||
167 | "{static groups} (minimized=yes) (workspace)", saverc_cmd)); | ||
168 | |||
169 | menu.insert(new ToolbarModeMenuItem( | ||
170 | _FB_XTEXT(Toolbar, IconbarModeWorkspaceNoIcons, | ||
171 | "WorkspaceNoIcons", "No iconified windows from this workspace are shown"), | ||
172 | handler, | ||
173 | "{static groups} (minimized=no) (workspace)", saverc_cmd)); | ||
174 | |||
175 | menu.insert(new ToolbarModeMenuItem( | ||
176 | _FB_XTEXT(Toolbar, IconbarModeWorkspace, | ||
177 | "Workspace", "Normal and iconified windows from this workspace are shown"), | ||
178 | handler, | ||
179 | "{static groups} (workspace)", saverc_cmd)); | ||
180 | |||
181 | menu.insert(new ToolbarModeMenuItem( | ||
182 | _FB_XTEXT(Toolbar, IconbarModeAllWindows, "All Windows", "All windows are shown"), | ||
183 | handler, | ||
184 | "{static groups}", saverc_cmd)); | ||
185 | |||
186 | menu.insert(new FbTk::MenuSeparator()); | ||
187 | |||
188 | menu.insert(new ToolbarAlignMenuItem( | ||
189 | _FB_XTEXT(Align, Left, "Left", "Align to the left"), | ||
190 | handler, | ||
191 | FbTk::Container::LEFT, saverc_cmd)); | ||
192 | |||
193 | menu.insert(new ToolbarAlignMenuItem( | ||
194 | _FB_XTEXT(Align, Relative, "Relative", "Align relative to the width"), | ||
195 | handler, | ||
196 | FbTk::Container::RELATIVE, saverc_cmd)); | ||
197 | |||
198 | menu.insert(new ToolbarAlignMenuItem( | ||
199 | _FB_XTEXT(Align, Right, "Right", "Align to the right"), | ||
200 | handler, | ||
201 | FbTk::Container::RIGHT, saverc_cmd)); | ||
202 | |||
203 | menu.insert(new FbTk::MenuSeparator()); | ||
204 | 187 | ||
205 | menu.updateMenu(); | 188 | menu.updateMenu(); |
206 | } | 189 | } |
@@ -280,7 +263,7 @@ IconbarTool::IconbarTool(const FbTk::FbWindow &parent, IconbarTheme &theme, | |||
280 | save_and_reconfig->add(reconfig); | 263 | save_and_reconfig->add(reconfig); |
281 | save_and_reconfig->add(save); | 264 | save_and_reconfig->add(save); |
282 | RefCount<Command<void> > s_and_reconfig(save_and_reconfig); | 265 | RefCount<Command<void> > s_and_reconfig(save_and_reconfig); |
283 | m_menu.insert(new FbTk::BoolMenuItem(_FB_XTEXT(Toolbar, ShowIcons, | 266 | m_menu.insertItem(new FbTk::BoolMenuItem(_FB_XTEXT(Toolbar, ShowIcons, |
284 | "Show Pictures", "chooses if little icons are shown next to title in the iconbar"), | 267 | "Show Pictures", "chooses if little icons are shown next to title in the iconbar"), |
285 | m_rc_use_pixmap, s_and_reconfig)); | 268 | m_rc_use_pixmap, s_and_reconfig)); |
286 | m_menu.updateMenu(); | 269 | m_menu.updateMenu(); |
@@ -288,7 +271,7 @@ IconbarTool::IconbarTool(const FbTk::FbWindow &parent, IconbarTheme &theme, | |||
288 | m_menu.setInternalMenu(); | 271 | m_menu.setInternalMenu(); |
289 | 272 | ||
290 | // add iconbar menu to toolbar menu | 273 | // add iconbar menu to toolbar menu |
291 | menu.insert(m_menu.label().logical(), &m_menu); | 274 | menu.insertSubmenu(m_menu.label().logical(), &m_menu); |
292 | 275 | ||
293 | // setup signals | 276 | // setup signals |
294 | m_tracker.join(theme.reconfigSig(), FbTk::MemFun(*this, &IconbarTool::themeReconfigured)); | 277 | m_tracker.join(theme.reconfigSig(), FbTk::MemFun(*this, &IconbarTool::themeReconfigured)); |