diff options
Diffstat (limited to 'src')
-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 be52e47..f5907c9 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" |
@@ -326,9 +327,20 @@ void ShowCustomMenuCmd::execute() { | |||
326 | } | 327 | } |
327 | 328 | ||
328 | void ShowCustomMenuCmd::reload() { | 329 | void ShowCustomMenuCmd::reload() { |
330 | _FB_USES_NLS; | ||
331 | |||
329 | m_menu->removeAll(); | 332 | m_menu->removeAll(); |
330 | m_menu->setLabel(FbTk::BiDiString("")); | 333 | try { |
331 | MenuCreator::createFromFile(custom_menu_file, *m_menu.get(), m_menu->reloadHelper()); | 334 | MenuCreator::createFromFile(custom_menu_file, *m_menu, m_menu->reloadHelper()); |
335 | } | ||
336 | catch(std::runtime_error &e) { | ||
337 | fprintf(stderr, _FB_CONSOLETEXT(FbCommands, CantLoadMenu, | ||
338 | "Failed to load menu file '%s': %s", | ||
339 | "Error message when loading of custom menu fails. " | ||
340 | "One %s for filename, one for exception text.").c_str(), | ||
341 | custom_menu_file.c_str(), e.what()); | ||
342 | fputs("\n", stderr); | ||
343 | } | ||
332 | } | 344 | } |
333 | 345 | ||
334 | REGISTER_COMMAND(rootmenu, FbCommands::ShowRootMenuCmd, void); | 346 | REGISTER_COMMAND(rootmenu, FbCommands::ShowRootMenuCmd, void); |
diff --git a/src/MenuCreator.cc b/src/MenuCreator.cc index edbe313..70075d1 100644 --- a/src/MenuCreator.cc +++ b/src/MenuCreator.cc | |||
@@ -235,11 +235,11 @@ string getField(lua::state &l, int pos, const char *field, FbTk::StringConvertor | |||
235 | } | 235 | } |
236 | 236 | ||
237 | void | 237 | void |
238 | createMenu_(FbMenu &inject_into, lua::state &l, int screen_number, FbTk::StringConvertor &conv, | 238 | createMenu_(FbTk::Menu &inject_into, lua::state &l, FbTk::StringConvertor &conv, |
239 | FbTk::AutoReloadHelper *reloader); | 239 | FbTk::AutoReloadHelper *reloader); |
240 | 240 | ||
241 | void | 241 | void |
242 | insertMenuItem(lua::state &l, FbMenu &menu, FbTk::StringConvertor &parent_conv, | 242 | insertMenuItem(lua::state &l, FbTk::Menu &menu, FbTk::StringConvertor &parent_conv, |
243 | FbTk::AutoReloadHelper *reloader) { | 243 | FbTk::AutoReloadHelper *reloader) { |
244 | lua::stack_sentry s(l, -1); | 244 | lua::stack_sentry s(l, -1); |
245 | l.checkstack(1); | 245 | l.checkstack(1); |
@@ -290,7 +290,7 @@ insertMenuItem(lua::state &l, FbMenu &menu, FbTk::StringConvertor &parent_conv, | |||
290 | } else if(str_key == "menu") { | 290 | } else if(str_key == "menu") { |
291 | std::auto_ptr<FbMenu> t(MenuCreator::createMenu("", screen_number)); | 291 | std::auto_ptr<FbMenu> t(MenuCreator::createMenu("", screen_number)); |
292 | l.pushvalue(-1); | 292 | l.pushvalue(-1); |
293 | createMenu_(*t, l, screen_number, *conv, reloader); | 293 | createMenu_(*t, l, *conv, reloader); |
294 | menu.insert(str_label, t.release()); | 294 | menu.insert(str_label, t.release()); |
295 | } else { | 295 | } else { |
296 | // items that have a parameter | 296 | // items that have a parameter |
@@ -330,7 +330,7 @@ insertMenuItem(lua::state &l, FbMenu &menu, FbTk::StringConvertor &parent_conv, | |||
330 | } | 330 | } |
331 | 331 | ||
332 | void | 332 | void |
333 | createMenu_(FbMenu &inject_into, lua::state &l, int screen_number, FbTk::StringConvertor &conv, | 333 | createMenu_(FbTk::Menu &inject_into, lua::state &l, FbTk::StringConvertor &conv, |
334 | FbTk::AutoReloadHelper *reloader) { | 334 | FbTk::AutoReloadHelper *reloader) { |
335 | 335 | ||
336 | lua::stack_sentry s(l, -1); | 336 | lua::stack_sentry s(l, -1); |
@@ -353,7 +353,7 @@ createMenu_(FbMenu &inject_into, lua::state &l, int screen_number, FbTk::StringC | |||
353 | } // end of anonymous namespace | 353 | } // end of anonymous namespace |
354 | 354 | ||
355 | void | 355 | void |
356 | MenuCreator::createMenu(FbMenu &inject_into, lua::state &l, int screen_number, FbTk::AutoReloadHelper *reloader) { | 356 | MenuCreator::createMenu(FbTk::Menu &inject_into, lua::state &l, FbTk::AutoReloadHelper *reloader) { |
357 | lua::stack_sentry s(l, -1); | 357 | lua::stack_sentry s(l, -1); |
358 | 358 | ||
359 | if(l.type(-1) != lua::TTABLE) { | 359 | if(l.type(-1) != lua::TTABLE) { |
@@ -369,7 +369,7 @@ MenuCreator::createMenu(FbMenu &inject_into, lua::state &l, int screen_number, F | |||
369 | if(!enc.empty()) | 369 | if(!enc.empty()) |
370 | conv->setSource(enc); | 370 | conv->setSource(enc); |
371 | 371 | ||
372 | createMenu_(inject_into, l, screen_number, *conv, reloader); | 372 | createMenu_(inject_into, l, *conv, reloader); |
373 | } | 373 | } |
374 | 374 | ||
375 | 375 | ||
@@ -387,33 +387,18 @@ FbMenu *MenuCreator::createMenu(const string &label, int screen_number) { | |||
387 | return menu; | 387 | return menu; |
388 | } | 388 | } |
389 | 389 | ||
390 | bool MenuCreator::createFromFile(const string &filename, | 390 | void MenuCreator::createFromFile(const string &filename, |
391 | FbTk::Menu &inject_into, | 391 | FbTk::Menu &inject_into, |
392 | AutoReloadHelper *reloader, bool begin) { | 392 | AutoReloadHelper *reloader) { |
393 | string real_filename = FbTk::StringUtil::expandFilename(filename); | 393 | string real_filename = FbTk::StringUtil::expandFilename(filename); |
394 | 394 | ||
395 | FbMenuParser parser(real_filename); | 395 | lua::state &l = Fluxbox::instance()->lua(); |
396 | if (!parser.isLoaded()) | 396 | l.checkstack(1); |
397 | return false; | 397 | lua::stack_sentry s(l); |
398 | |||
399 | startFile(); | ||
400 | if (begin) { | ||
401 | string label; | ||
402 | if (!getStart(parser, label, m_stringconvertor)) { | ||
403 | endFile(); | ||
404 | return false; | ||
405 | } | ||
406 | inject_into.setLabel(label); | ||
407 | } | ||
408 | |||
409 | // save menu filename, so we can check if it changes | ||
410 | if (reloader) | ||
411 | reloader->addFile(real_filename); | ||
412 | |||
413 | parseMenu(parser, inject_into, m_stringconvertor, reloader); | ||
414 | endFile(); | ||
415 | 398 | ||
416 | return true; | 399 | l.loadfile(real_filename.c_str()); |
400 | l.call(0, 1); | ||
401 | createMenu(inject_into, l, reloader); | ||
417 | } | 402 | } |
418 | 403 | ||
419 | FbMenu *MenuCreator::createMenuType(const string &type, int screen_num) { | 404 | FbMenu *MenuCreator::createMenuType(const string &type, int screen_num) { |
diff --git a/src/MenuCreator.hh b/src/MenuCreator.hh index 2c90f3d..8e5cad1 100644 --- a/src/MenuCreator.hh +++ b/src/MenuCreator.hh | |||
@@ -43,14 +43,12 @@ class FluxboxWindow; | |||
43 | class MenuCreator { | 43 | class MenuCreator { |
44 | public: | 44 | public: |
45 | static void | 45 | static void |
46 | createMenu(FbMenu &inject_into, lua::state &l, int screen_number, | 46 | createMenu(FbTk::Menu &inject_into, lua::state &l, FbTk::AutoReloadHelper *reloader = NULL); |
47 | FbTk::AutoReloadHelper *reloader = NULL); | ||
48 | static FbMenu *createMenu(const std::string &label, int screen_num); | 47 | static FbMenu *createMenu(const std::string &label, int screen_num); |
49 | static FbMenu *createMenuType(const std::string &label, int screen_num); | 48 | static FbMenu *createMenuType(const std::string &label, int screen_num); |
50 | static bool createFromFile(const std::string &filename, | 49 | static void createFromFile(const std::string &filename, |
51 | FbTk::Menu &inject_into, | 50 | FbTk::Menu &inject_into, |
52 | FbTk::AutoReloadHelper *reloader = NULL, | 51 | FbTk::AutoReloadHelper *reloader = NULL); |
53 | bool begin = true); | ||
54 | static bool createWindowMenuItem(const std::string &type, const std::string &label, | 52 | static bool createWindowMenuItem(const std::string &type, const std::string &label, |
55 | FbTk::Menu &inject_into); | 53 | FbTk::Menu &inject_into); |
56 | 54 | ||
diff --git a/src/Screen.cc b/src/Screen.cc index 7b81469..ca12cb3 100644 --- a/src/Screen.cc +++ b/src/Screen.cc | |||
@@ -1410,7 +1410,7 @@ void BScreen::rereadMenu() { | |||
1410 | m_rootmenu->removeAll(); | 1410 | m_rootmenu->removeAll(); |
1411 | l.loadfile(FbTk::StringUtil::expandFilename(fb->getMenuFilename()).c_str()); | 1411 | l.loadfile(FbTk::StringUtil::expandFilename(fb->getMenuFilename()).c_str()); |
1412 | l.call(0, 1); | 1412 | l.call(0, 1); |
1413 | MenuCreator::createMenu(*m_rootmenu, l, screenNumber(), m_rootmenu->reloadHelper()); | 1413 | MenuCreator::createMenu(*m_rootmenu, l, m_rootmenu->reloadHelper()); |
1414 | 1414 | ||
1415 | if (m_rootmenu->numberOfItems() == 0) { | 1415 | if (m_rootmenu->numberOfItems() == 0) { |
1416 | _FB_USES_NLS; | 1416 | _FB_USES_NLS; |
@@ -1446,7 +1446,7 @@ void BScreen::rereadWindowMenu() { | |||
1446 | m_windowmenu->removeAll(); | 1446 | m_windowmenu->removeAll(); |
1447 | l.loadfile(FbTk::StringUtil::expandFilename(windowMenuFilename()).c_str()); | 1447 | l.loadfile(FbTk::StringUtil::expandFilename(windowMenuFilename()).c_str()); |
1448 | l.call(0, 1); | 1448 | l.call(0, 1); |
1449 | MenuCreator::createMenu(*m_windowmenu, l, screenNumber(), m_windowmenu->reloadHelper()); | 1449 | MenuCreator::createMenu(*m_windowmenu, l, m_windowmenu->reloadHelper()); |
1450 | } | 1450 | } |
1451 | 1451 | ||
1452 | void BScreen::addConfigMenu(const FbTk::FbString &label, FbTk::Menu &menu) { | 1452 | void BScreen::addConfigMenu(const FbTk::FbString &label, FbTk::Menu &menu) { |