diff options
author | Mathias Gumz <akira at fluxbox dot org> | 2008-01-25 07:21:55 (GMT) |
---|---|---|
committer | Mathias Gumz <akira at fluxbox dot org> | 2008-01-25 07:21:55 (GMT) |
commit | 6717a1c805529ea6e1b1c19a591f876c9c8803db (patch) | |
tree | 97bb3193601d67f6137723410753b497e429fdf5 /src/MenuCreator.cc | |
parent | 65df54d635e8ad2029efea1c3c00eccfffe8532d (diff) | |
download | fluxbox_paul-6717a1c805529ea6e1b1c19a591f876c9c8803db.zip fluxbox_paul-6717a1c805529ea6e1b1c19a591f876c9c8803db.tar.bz2 |
cosmetics
Diffstat (limited to 'src/MenuCreator.cc')
-rw-r--r-- | src/MenuCreator.cc | 61 |
1 files changed, 32 insertions, 29 deletions
diff --git a/src/MenuCreator.cc b/src/MenuCreator.cc index 12b0f1c..32a046f 100644 --- a/src/MenuCreator.cc +++ b/src/MenuCreator.cc | |||
@@ -65,7 +65,9 @@ list<size_t> MenuCreator::stacksize_stack; | |||
65 | 65 | ||
66 | FbTk::StringConvertor MenuCreator::m_stringconvertor(FbTk::StringConvertor::ToFbString); | 66 | FbTk::StringConvertor MenuCreator::m_stringconvertor(FbTk::StringConvertor::ToFbString); |
67 | 67 | ||
68 | static void createStyleMenu(FbTk::Menu &parent, const string &label, | 68 | namespace { |
69 | |||
70 | void createStyleMenu(FbTk::Menu &parent, const string &label, | ||
69 | const string &directory) { | 71 | const string &directory) { |
70 | // perform shell style ~ home directory expansion | 72 | // perform shell style ~ home directory expansion |
71 | string stylesdir(FbTk::StringUtil::expandFilename(directory)); | 73 | string stylesdir(FbTk::StringUtil::expandFilename(directory)); |
@@ -101,7 +103,7 @@ static void createStyleMenu(FbTk::Menu &parent, const string &label, | |||
101 | 103 | ||
102 | } | 104 | } |
103 | 105 | ||
104 | static void createRootCmdMenu(FbTk::Menu &parent, const string &label, | 106 | void createRootCmdMenu(FbTk::Menu &parent, const string &label, |
105 | const string &directory, const string &cmd) { | 107 | const string &directory, const string &cmd) { |
106 | // perform shell style ~ home directory expansion | 108 | // perform shell style ~ home directory expansion |
107 | string rootcmddir(FbTk::StringUtil::expandFilename(directory)); | 109 | string rootcmddir(FbTk::StringUtil::expandFilename(directory)); |
@@ -141,15 +143,15 @@ class ParseItem { | |||
141 | public: | 143 | public: |
142 | explicit ParseItem(FbTk::Menu *menu):m_menu(menu) {} | 144 | explicit ParseItem(FbTk::Menu *menu):m_menu(menu) {} |
143 | 145 | ||
144 | inline void load(FbTk::Parser &p, FbTk::StringConvertor &m_labelconvertor) { | 146 | void load(FbTk::Parser &p, FbTk::StringConvertor &m_labelconvertor) { |
145 | p>>m_key>>m_label>>m_cmd>>m_icon; | 147 | p>>m_key>>m_label>>m_cmd>>m_icon; |
146 | m_label.second = m_labelconvertor.recode(m_label.second); | 148 | m_label.second = m_labelconvertor.recode(m_label.second); |
147 | } | 149 | } |
148 | inline const string &icon() const { return m_icon.second; } | 150 | const string &icon() const { return m_icon.second; } |
149 | inline const string &command() const { return m_cmd.second; } | 151 | const string &command() const { return m_cmd.second; } |
150 | inline const string &label() const { return m_label.second; } | 152 | const string &label() const { return m_label.second; } |
151 | inline const string &key() const { return m_key.second; } | 153 | const string &key() const { return m_key.second; } |
152 | inline FbTk::Menu *menu() { return m_menu; } | 154 | FbTk::Menu *menu() { return m_menu; } |
153 | private: | 155 | private: |
154 | FbTk::Parser::Item m_key, m_label, m_cmd, m_icon; | 156 | FbTk::Parser::Item m_key, m_label, m_cmd, m_icon; |
155 | FbTk::Menu *m_menu; | 157 | FbTk::Menu *m_menu; |
@@ -170,10 +172,10 @@ public: | |||
170 | 172 | ||
171 | }; | 173 | }; |
172 | 174 | ||
173 | static void translateMenuItem(FbTk::Parser &parse, ParseItem &item, FbTk::StringConvertor &labelconvertor); | 175 | void translateMenuItem(FbTk::Parser &parse, ParseItem &item, FbTk::StringConvertor &labelconvertor); |
174 | 176 | ||
175 | 177 | ||
176 | static void parseMenu(FbTk::Parser &pars, FbTk::Menu &menu, FbTk::StringConvertor &label_convertor) { | 178 | void parseMenu(FbTk::Parser &pars, FbTk::Menu &menu, FbTk::StringConvertor &label_convertor) { |
177 | ParseItem pitem(&menu); | 179 | ParseItem pitem(&menu); |
178 | while (!pars.eof()) { | 180 | while (!pars.eof()) { |
179 | pitem.load(pars, label_convertor); | 181 | pitem.load(pars, label_convertor); |
@@ -183,7 +185,7 @@ static void parseMenu(FbTk::Parser &pars, FbTk::Menu &menu, FbTk::StringConverto | |||
183 | } | 185 | } |
184 | } | 186 | } |
185 | 187 | ||
186 | static void translateMenuItem(FbTk::Parser &parse, ParseItem &pitem, FbTk::StringConvertor &labelconvertor) { | 188 | void translateMenuItem(FbTk::Parser &parse, ParseItem &pitem, FbTk::StringConvertor &labelconvertor) { |
187 | if (pitem.menu() == 0) | 189 | if (pitem.menu() == 0) |
188 | throw string("translateMenuItem: We must have a menu in ParseItem!"); | 190 | throw string("translateMenuItem: We must have a menu in ParseItem!"); |
189 | 191 | ||
@@ -216,12 +218,10 @@ static void translateMenuItem(FbTk::Parser &parse, ParseItem &pitem, FbTk::Strin | |||
216 | menu.insert(str_label, exit_cmd); | 218 | menu.insert(str_label, exit_cmd); |
217 | } else if (str_key == "exec") { | 219 | } else if (str_key == "exec") { |
218 | // execute and hide menu | 220 | // execute and hide menu |
219 | using namespace FbTk; | 221 | FbTk::RefCount<FbTk::Command<void> > exec_cmd(FbTk::CommandParser<void>::instance().parse("exec " + str_cmd)); |
220 | RefCount<Command<void> > exec_cmd(FbTk::CommandParser<void>::instance().parse("exec " + str_cmd)); | ||
221 | menu.insert(str_label, exec_cmd); | 222 | menu.insert(str_label, exec_cmd); |
222 | } else if (str_key == "macrocmd") { | 223 | } else if (str_key == "macrocmd") { |
223 | using namespace FbTk; | 224 | FbTk::RefCount<FbTk::Command<void> > macro_cmd(FbTk::CommandParser<void>::instance().parse("macrocmd " + str_cmd)); |
224 | RefCount<Command<void> > macro_cmd(FbTk::CommandParser<void>::instance().parse("macrocmd " + str_cmd)); | ||
225 | menu.insert(str_label, macro_cmd); | 225 | menu.insert(str_label, macro_cmd); |
226 | } else if (str_key == "style") { // style | 226 | } else if (str_key == "style") { // style |
227 | menu.insert(new StyleMenuItem(str_label, str_cmd)); | 227 | menu.insert(new StyleMenuItem(str_label, str_cmd)); |
@@ -339,7 +339,7 @@ static void translateMenuItem(FbTk::Parser &parse, ParseItem &pitem, FbTk::Strin | |||
339 | } | 339 | } |
340 | 340 | ||
341 | 341 | ||
342 | static void parseWindowMenu(FbTk::Parser &parse, FbTk::Menu &menu, FbTk::StringConvertor &labelconvertor) { | 342 | void parseWindowMenu(FbTk::Parser &parse, FbTk::Menu &menu, FbTk::StringConvertor &labelconvertor) { |
343 | 343 | ||
344 | ParseItem pitem(&menu); | 344 | ParseItem pitem(&menu); |
345 | while (!parse.eof()) { | 345 | while (!parse.eof()) { |
@@ -361,19 +361,6 @@ static void parseWindowMenu(FbTk::Parser &parse, FbTk::Menu &menu, FbTk::StringC | |||
361 | } | 361 | } |
362 | } | 362 | } |
363 | 363 | ||
364 | FbTk::Menu *MenuCreator::createMenu(const string &label, int screen_number) { | ||
365 | BScreen *screen = Fluxbox::instance()->findScreen(screen_number); | ||
366 | if (screen == 0) | ||
367 | return 0; | ||
368 | |||
369 | FbTk::Menu *menu = new FbMenu(screen->menuTheme(), | ||
370 | screen->imageControl(), | ||
371 | *screen->layerManager().getLayer(Layer::MENU)); | ||
372 | if (!label.empty()) | ||
373 | menu->setLabel(label); | ||
374 | |||
375 | return menu; | ||
376 | } | ||
377 | 364 | ||
378 | bool getStart(FbMenuParser &parser, string &label, FbTk::StringConvertor &labelconvertor) { | 365 | bool getStart(FbMenuParser &parser, string &label, FbTk::StringConvertor &labelconvertor) { |
379 | ParseItem pitem(0); | 366 | ParseItem pitem(0); |
@@ -391,6 +378,22 @@ bool getStart(FbMenuParser &parser, string &label, FbTk::StringConvertor &labelc | |||
391 | return true; | 378 | return true; |
392 | } | 379 | } |
393 | 380 | ||
381 | }; // end of anonymous namespace | ||
382 | |||
383 | FbTk::Menu *MenuCreator::createMenu(const string &label, int screen_number) { | ||
384 | BScreen *screen = Fluxbox::instance()->findScreen(screen_number); | ||
385 | if (screen == 0) | ||
386 | return 0; | ||
387 | |||
388 | FbTk::Menu *menu = new FbMenu(screen->menuTheme(), | ||
389 | screen->imageControl(), | ||
390 | *screen->layerManager().getLayer(Layer::MENU)); | ||
391 | if (!label.empty()) | ||
392 | menu->setLabel(label); | ||
393 | |||
394 | return menu; | ||
395 | } | ||
396 | |||
394 | FbTk::Menu *MenuCreator::createFromFile(const string &filename, int screen_number, bool require_begin) { | 397 | FbTk::Menu *MenuCreator::createFromFile(const string &filename, int screen_number, bool require_begin) { |
395 | string real_filename = FbTk::StringUtil::expandFilename(filename); | 398 | string real_filename = FbTk::StringUtil::expandFilename(filename); |
396 | Fluxbox::instance()->saveMenuFilename(real_filename.c_str()); | 399 | Fluxbox::instance()->saveMenuFilename(real_filename.c_str()); |