diff options
author | Pavel Labath <pavelo@centrum.sk> | 2011-07-02 08:19:48 (GMT) |
---|---|---|
committer | Pavel Labath <pavelo@centrum.sk> | 2011-11-01 09:57:20 (GMT) |
commit | adf9f90af810c827fa4c849235515898733da8b6 (patch) | |
tree | 9249a2bbc26b5c9b07b78a2da53cfff81eda7904 | |
parent | d5bef134ea20a2670d383492977b4d152e24464a (diff) | |
download | fluxbox_paul-adf9f90af810c827fa4c849235515898733da8b6.zip fluxbox_paul-adf9f90af810c827fa4c849235515898733da8b6.tar.bz2 |
CustomMenu command now shows lua menus
-rw-r--r-- | src/FbCommands.cc | 16 | ||||
-rw-r--r-- | src/MenuCreator.cc | 43 | ||||
-rw-r--r-- | src/MenuCreator.hh | 8 | ||||
-rw-r--r-- | src/Screen.cc | 4 |
4 files changed, 33 insertions, 38 deletions
diff --git a/src/FbCommands.cc b/src/FbCommands.cc index 63aa79d..e91484c 100644 --- a/src/FbCommands.cc +++ b/src/FbCommands.cc | |||
@@ -30,6 +30,7 @@ | |||
30 | #include "Keys.hh" | 30 | #include "Keys.hh" |
31 | #include "MenuCreator.hh" | 31 | #include "MenuCreator.hh" |
32 | 32 | ||
33 | #include "FbTk/I18n.hh" | ||
33 | #include "FbTk/Theme.hh" | 34 | #include "FbTk/Theme.hh" |
34 | #include "FbTk/Menu.hh" | 35 | #include "FbTk/Menu.hh" |
35 | #include "FbTk/CommandParser.hh" | 36 | #include "FbTk/CommandParser.hh" |
@@ -338,9 +339,20 @@ void ShowCustomMenuCmd::execute() { | |||
338 | } | 339 | } |
339 | 340 | ||
340 | void ShowCustomMenuCmd::reload() { | 341 | void ShowCustomMenuCmd::reload() { |
342 | _FB_USES_NLS; | ||
343 | |||
341 | m_menu->removeAll(); | 344 | m_menu->removeAll(); |
342 | m_menu->setLabel(FbTk::BiDiString("")); | 345 | try { |
343 | MenuCreator::createFromFile(custom_menu_file, *m_menu.get(), m_menu->reloadHelper()); | 346 | MenuCreator::createFromFile(custom_menu_file, *m_menu, m_menu->reloadHelper()); |
347 | } | ||
348 | catch(std::runtime_error &e) { | ||
349 | fprintf(stderr, _FB_CONSOLETEXT(FbCommands, CantLoadMenu, | ||
350 | "Failed to load menu file '%s': %s", | ||
351 | "Error message when loading of custom menu fails. " | ||
352 | "One %s for filename, one for exception text.").c_str(), | ||
353 | custom_menu_file.c_str(), e.what()); | ||
354 | fputs("\n", stderr); | ||
355 | } | ||
344 | } | 356 | } |
345 | 357 | ||
346 | REGISTER_COMMAND(rootmenu, FbCommands::ShowRootMenuCmd, void); | 358 | REGISTER_COMMAND(rootmenu, FbCommands::ShowRootMenuCmd, void); |
diff --git a/src/MenuCreator.cc b/src/MenuCreator.cc index 14035c0..b357dce 100644 --- a/src/MenuCreator.cc +++ b/src/MenuCreator.cc | |||
@@ -302,11 +302,11 @@ string getField(lua::state &l, int pos, const char *field, FbTk::StringConvertor | |||
302 | } | 302 | } |
303 | 303 | ||
304 | void | 304 | void |
305 | createMenu_(FbMenu &inject_into, lua::state &l, int screen_number, FbTk::StringConvertor &conv, | 305 | createMenu_(FbTk::Menu &inject_into, lua::state &l, FbTk::StringConvertor &conv, |
306 | FbTk::AutoReloadHelper *reloader); | 306 | FbTk::AutoReloadHelper *reloader); |
307 | 307 | ||
308 | void | 308 | void |
309 | insertMenuItem(lua::state &l, FbMenu &menu, FbTk::StringConvertor &parent_conv, | 309 | insertMenuItem(lua::state &l, FbTk::Menu &menu, FbTk::StringConvertor &parent_conv, |
310 | FbTk::AutoReloadHelper *reloader) { | 310 | FbTk::AutoReloadHelper *reloader) { |
311 | lua::stack_sentry s(l, -1); | 311 | lua::stack_sentry s(l, -1); |
312 | l.checkstack(1); | 312 | l.checkstack(1); |
@@ -357,7 +357,7 @@ insertMenuItem(lua::state &l, FbMenu &menu, FbTk::StringConvertor &parent_conv, | |||
357 | } else if(str_key == "menu") { | 357 | } else if(str_key == "menu") { |
358 | std::auto_ptr<FbMenu> t(MenuCreator::createMenu("", screen_number)); | 358 | std::auto_ptr<FbMenu> t(MenuCreator::createMenu("", screen_number)); |
359 | l.pushvalue(-1); | 359 | l.pushvalue(-1); |
360 | createMenu_(*t, l, screen_number, *conv, reloader); | 360 | createMenu_(*t, l, *conv, reloader); |
361 | menu.insert(str_label, t.release()); | 361 | menu.insert(str_label, t.release()); |
362 | } else { | 362 | } else { |
363 | // items that have a parameter | 363 | // items that have a parameter |
@@ -397,7 +397,7 @@ insertMenuItem(lua::state &l, FbMenu &menu, FbTk::StringConvertor &parent_conv, | |||
397 | } | 397 | } |
398 | 398 | ||
399 | void | 399 | void |
400 | createMenu_(FbMenu &inject_into, lua::state &l, int screen_number, FbTk::StringConvertor &conv, | 400 | createMenu_(FbTk::Menu &inject_into, lua::state &l, FbTk::StringConvertor &conv, |
401 | FbTk::AutoReloadHelper *reloader) { | 401 | FbTk::AutoReloadHelper *reloader) { |
402 | 402 | ||
403 | lua::stack_sentry s(l, -1); | 403 | lua::stack_sentry s(l, -1); |
@@ -420,7 +420,7 @@ createMenu_(FbMenu &inject_into, lua::state &l, int screen_number, FbTk::StringC | |||
420 | } // end of anonymous namespace | 420 | } // end of anonymous namespace |
421 | 421 | ||
422 | void | 422 | void |
423 | MenuCreator::createMenu(FbMenu &inject_into, lua::state &l, int screen_number, FbTk::AutoReloadHelper *reloader) { | 423 | MenuCreator::createMenu(FbTk::Menu &inject_into, lua::state &l, FbTk::AutoReloadHelper *reloader) { |
424 | lua::stack_sentry s(l, -1); | 424 | lua::stack_sentry s(l, -1); |
425 | 425 | ||
426 | if(l.type(-1) != lua::TTABLE) { | 426 | if(l.type(-1) != lua::TTABLE) { |
@@ -436,7 +436,7 @@ MenuCreator::createMenu(FbMenu &inject_into, lua::state &l, int screen_number, F | |||
436 | if(!enc.empty()) | 436 | if(!enc.empty()) |
437 | conv->setSource(enc); | 437 | conv->setSource(enc); |
438 | 438 | ||
439 | createMenu_(inject_into, l, screen_number, *conv, reloader); | 439 | createMenu_(inject_into, l, *conv, reloader); |
440 | } | 440 | } |
441 | 441 | ||
442 | 442 | ||
@@ -454,33 +454,18 @@ FbMenu *MenuCreator::createMenu(const string &label, int screen_number) { | |||
454 | return menu; | 454 | return menu; |
455 | } | 455 | } |
456 | 456 | ||
457 | bool MenuCreator::createFromFile(const string &filename, | 457 | void MenuCreator::createFromFile(const string &filename, |
458 | FbTk::Menu &inject_into, | 458 | FbTk::Menu &inject_into, |
459 | AutoReloadHelper *reloader, bool begin) { | 459 | AutoReloadHelper *reloader) { |
460 | string real_filename = FbTk::StringUtil::expandFilename(filename); | 460 | string real_filename = FbTk::StringUtil::expandFilename(filename); |
461 | 461 | ||
462 | FbMenuParser parser(real_filename); | 462 | lua::state &l = Fluxbox::instance()->lua(); |
463 | if (!parser.isLoaded()) | 463 | l.checkstack(1); |
464 | return false; | 464 | lua::stack_sentry s(l); |
465 | |||
466 | startFile(); | ||
467 | if (begin) { | ||
468 | string label; | ||
469 | if (!getStart(parser, label, s_stringconvertor)) { | ||
470 | endFile(); | ||
471 | return false; | ||
472 | } | ||
473 | inject_into.setLabel(label); | ||
474 | } | ||
475 | |||
476 | // save menu filename, so we can check if it changes | ||
477 | if (reloader) | ||
478 | reloader->addFile(real_filename); | ||
479 | |||
480 | parseMenu(parser, inject_into, s_stringconvertor, reloader); | ||
481 | endFile(); | ||
482 | 465 | ||
483 | return true; | 466 | l.loadfile(real_filename.c_str()); |
467 | l.call(0, 1); | ||
468 | createMenu(inject_into, l, reloader); | ||
484 | } | 469 | } |
485 | 470 | ||
486 | FbMenu *MenuCreator::createMenuType(const string &type, int screen_num) { | 471 | FbMenu *MenuCreator::createMenuType(const string &type, int screen_num) { |
diff --git a/src/MenuCreator.hh b/src/MenuCreator.hh index 0d13529..60f931d 100644 --- a/src/MenuCreator.hh +++ b/src/MenuCreator.hh | |||
@@ -42,14 +42,12 @@ class FluxboxWindow; | |||
42 | 42 | ||
43 | namespace MenuCreator { | 43 | namespace MenuCreator { |
44 | void | 44 | void |
45 | createMenu(FbMenu &inject_into, lua::state &l, int screen_number, | 45 | createMenu(FbTk::Menu &inject_into, lua::state &l, FbTk::AutoReloadHelper *reloader = NULL); |
46 | FbTk::AutoReloadHelper *reloader = NULL); | ||
47 | FbMenu *createMenu(const std::string &label, int screen_num); | 46 | FbMenu *createMenu(const std::string &label, int screen_num); |
48 | FbMenu *createMenuType(const std::string &label, int screen_num); | 47 | FbMenu *createMenuType(const std::string &label, int screen_num); |
49 | bool createFromFile(const std::string &filename, | 48 | void createFromFile(const std::string &filename, |
50 | FbTk::Menu &inject_into, | 49 | FbTk::Menu &inject_into, |
51 | FbTk::AutoReloadHelper *reloader = NULL, | 50 | FbTk::AutoReloadHelper *reloader = NULL); |
52 | bool begin = true); | ||
53 | bool createWindowMenuItem(const std::string &type, const std::string &label, | 51 | bool createWindowMenuItem(const std::string &type, const std::string &label, |
54 | FbTk::Menu &inject_into); | 52 | FbTk::Menu &inject_into); |
55 | } | 53 | } |
diff --git a/src/Screen.cc b/src/Screen.cc index b953c92..2f83047 100644 --- a/src/Screen.cc +++ b/src/Screen.cc | |||
@@ -1402,7 +1402,7 @@ void BScreen::rereadMenu() { | |||
1402 | m_rootmenu->removeAll(); | 1402 | m_rootmenu->removeAll(); |
1403 | l.loadfile(FbTk::StringUtil::expandFilename(fb->getMenuFilename()).c_str()); | 1403 | l.loadfile(FbTk::StringUtil::expandFilename(fb->getMenuFilename()).c_str()); |
1404 | l.call(0, 1); | 1404 | l.call(0, 1); |
1405 | MenuCreator::createMenu(*m_rootmenu, l, screenNumber(), m_rootmenu->reloadHelper()); | 1405 | MenuCreator::createMenu(*m_rootmenu, l, m_rootmenu->reloadHelper()); |
1406 | 1406 | ||
1407 | if (m_rootmenu->numberOfItems() == 0) { | 1407 | if (m_rootmenu->numberOfItems() == 0) { |
1408 | _FB_USES_NLS; | 1408 | _FB_USES_NLS; |
@@ -1438,7 +1438,7 @@ void BScreen::rereadWindowMenu() { | |||
1438 | m_windowmenu->removeAll(); | 1438 | m_windowmenu->removeAll(); |
1439 | l.loadfile(FbTk::StringUtil::expandFilename(windowMenuFilename()).c_str()); | 1439 | l.loadfile(FbTk::StringUtil::expandFilename(windowMenuFilename()).c_str()); |
1440 | l.call(0, 1); | 1440 | l.call(0, 1); |
1441 | MenuCreator::createMenu(*m_windowmenu, l, screenNumber(), m_windowmenu->reloadHelper()); | 1441 | MenuCreator::createMenu(*m_windowmenu, l, m_windowmenu->reloadHelper()); |
1442 | } | 1442 | } |
1443 | 1443 | ||
1444 | void BScreen::addConfigMenu(const FbTk::FbString &label, FbTk::Menu &menu) { | 1444 | void BScreen::addConfigMenu(const FbTk::FbString &label, FbTk::Menu &menu) { |