diff options
author | Pavel Labath <pavelo@centrum.sk> | 2011-07-01 21:30:54 (GMT) |
---|---|---|
committer | Pavel Labath <pavelo@centrum.sk> | 2013-02-17 00:09:34 (GMT) |
commit | 3e47dab917a73653686ed3e6bef0d58d917cc65b (patch) | |
tree | 39b7298fdcdb9b4b56d3cb778eb16a2bef15b0c4 | |
parent | 65c0c2c2bdbce292d4d2e09b74cedd64305479f1 (diff) | |
download | fluxbox_pavel-3e47dab917a73653686ed3e6bef0d58d917cc65b.zip fluxbox_pavel-3e47dab917a73653686ed3e6bef0d58d917cc65b.tar.bz2 |
Convert windowmenu to lua
also, i've restored the autoreloading capability of menus.
-rw-r--r-- | src/MenuCreator.cc | 34 | ||||
-rw-r--r-- | src/MenuCreator.hh | 6 | ||||
-rw-r--r-- | src/Screen.cc | 37 |
3 files changed, 39 insertions, 38 deletions
diff --git a/src/MenuCreator.cc b/src/MenuCreator.cc index cc891cc..14035c0 100644 --- a/src/MenuCreator.cc +++ b/src/MenuCreator.cc | |||
@@ -301,8 +301,8 @@ string getField(lua::state &l, int pos, const char *field, FbTk::StringConvertor | |||
301 | return conv ? conv->recode(val) : val; | 301 | return conv ? conv->recode(val) : val; |
302 | } | 302 | } |
303 | 303 | ||
304 | std::auto_ptr<FbMenu> | 304 | void |
305 | createMenu_(lua::state &l, int screen_number, FbTk::StringConvertor &conv, | 305 | createMenu_(FbMenu &inject_into, lua::state &l, int screen_number, FbTk::StringConvertor &conv, |
306 | FbTk::AutoReloadHelper *reloader); | 306 | FbTk::AutoReloadHelper *reloader); |
307 | 307 | ||
308 | void | 308 | void |
@@ -355,8 +355,10 @@ insertMenuItem(lua::state &l, FbMenu &menu, FbTk::StringConvertor &parent_conv, | |||
355 | } else if (str_key == "config") { | 355 | } else if (str_key == "config") { |
356 | menu.insert(str_label, &screen->configMenu()); | 356 | menu.insert(str_label, &screen->configMenu()); |
357 | } else if(str_key == "menu") { | 357 | } else if(str_key == "menu") { |
358 | std::auto_ptr<FbMenu> t(MenuCreator::createMenu("", screen_number)); | ||
358 | l.pushvalue(-1); | 359 | l.pushvalue(-1); |
359 | menu.insert(str_label, createMenu_(l, screen_number, *conv, reloader).release()); | 360 | createMenu_(*t, l, screen_number, *conv, reloader); |
361 | menu.insert(str_label, t.release()); | ||
360 | } else { | 362 | } else { |
361 | // items that have a parameter | 363 | // items that have a parameter |
362 | const string &str_cmd = getField(l, -1, "param"); | 364 | const string &str_cmd = getField(l, -1, "param"); |
@@ -394,19 +396,18 @@ insertMenuItem(lua::state &l, FbMenu &menu, FbTk::StringConvertor &parent_conv, | |||
394 | } | 396 | } |
395 | } | 397 | } |
396 | 398 | ||
397 | std::auto_ptr<FbMenu> | 399 | void |
398 | createMenu_(lua::state &l, int screen_number, FbTk::StringConvertor &conv, | 400 | createMenu_(FbMenu &inject_into, lua::state &l, int screen_number, FbTk::StringConvertor &conv, |
399 | FbTk::AutoReloadHelper *reloader) { | 401 | FbTk::AutoReloadHelper *reloader) { |
400 | 402 | ||
401 | lua::stack_sentry s(l, -1); | 403 | lua::stack_sentry s(l, -1); |
402 | l.checkstack(1); | 404 | l.checkstack(1); |
403 | 405 | ||
404 | std::auto_ptr<FbMenu> menu( MenuCreator::createMenu(getField(l, -1, "label", &conv), | 406 | inject_into.setLabel(getField(l, -1, "label", &conv)); |
405 | screen_number) ); | ||
406 | 407 | ||
407 | for(int i = 1; l.rawgeti(-1, i), !l.isnil(-1); ++i) { | 408 | for(int i = 1; l.rawgeti(-1, i), !l.isnil(-1); ++i) { |
408 | try { | 409 | try { |
409 | insertMenuItem(l, *menu, conv, reloader); | 410 | insertMenuItem(l, inject_into, conv, reloader); |
410 | } | 411 | } |
411 | catch(std::runtime_error &e) { | 412 | catch(std::runtime_error &e) { |
412 | cerr << e.what() << endl; | 413 | cerr << e.what() << endl; |
@@ -414,31 +415,28 @@ createMenu_(lua::state &l, int screen_number, FbTk::StringConvertor &conv, | |||
414 | } l.pop(); | 415 | } l.pop(); |
415 | 416 | ||
416 | l.pop(); | 417 | l.pop(); |
417 | return menu; | ||
418 | } | 418 | } |
419 | 419 | ||
420 | } // end of anonymous namespace | 420 | } // end of anonymous namespace |
421 | 421 | ||
422 | std::auto_ptr<FbMenu> | 422 | void |
423 | MenuCreator::createMenu(lua::state &l, int screen_number, FbTk::AutoReloadHelper *reloader) { | 423 | MenuCreator::createMenu(FbMenu &inject_into, lua::state &l, int screen_number, FbTk::AutoReloadHelper *reloader) { |
424 | lua::stack_sentry s(l, -1); | 424 | lua::stack_sentry s(l, -1); |
425 | l.checkstack(1); | ||
426 | 425 | ||
427 | if(l.type(-1) != lua::TTABLE) { | 426 | if(l.type(-1) != lua::TTABLE) { |
428 | cerr << _FB_CONSOLETEXT(Menu, MenuNotTable, "Warning: Menu is not a lua table", | 427 | cerr << _FB_CONSOLETEXT(Menu, MenuNotTable, "Warning: Menu is not a lua table", |
429 | "Menu is not a lua table") << endl; | 428 | "Menu is not a lua table") << endl; |
430 | return std::auto_ptr<FbMenu>(); | 429 | return; |
431 | } | 430 | } |
432 | 431 | ||
433 | std::auto_ptr<FbTk::StringConvertor> conv(new FbTk::StringConvertor(FbTk::StringConvertor::ToFbString)); | 432 | std::auto_ptr<FbTk::StringConvertor> conv(new FbTk::StringConvertor(FbTk::StringConvertor::ToFbString)); |
434 | 433 | ||
435 | // if menu specifies an encoding, create a convertor for it | 434 | // if menu specifies an encoding, create a convertor for it |
436 | l.rawgetfield(-1, "encoding"); { | 435 | const std::string &enc = getField(l, -1, "encoding"); |
437 | if(l.isstring(-1)) | 436 | if(!enc.empty()) |
438 | conv->setSource(l.tostring(-1)); | 437 | conv->setSource(enc); |
439 | } l.pop(); | ||
440 | 438 | ||
441 | return createMenu_(l, screen_number, *conv, reloader); | 439 | createMenu_(inject_into, l, screen_number, *conv, reloader); |
442 | } | 440 | } |
443 | 441 | ||
444 | 442 | ||
diff --git a/src/MenuCreator.hh b/src/MenuCreator.hh index 4329639..0d13529 100644 --- a/src/MenuCreator.hh +++ b/src/MenuCreator.hh | |||
@@ -41,9 +41,9 @@ class FbMenu; | |||
41 | class FluxboxWindow; | 41 | class FluxboxWindow; |
42 | 42 | ||
43 | namespace MenuCreator { | 43 | namespace MenuCreator { |
44 | 44 | void | |
45 | std::auto_ptr<FbMenu> | 45 | createMenu(FbMenu &inject_into, lua::state &l, int screen_number, |
46 | createMenu(lua::state &l, int screen_number, FbTk::AutoReloadHelper *reloader = NULL); | 46 | FbTk::AutoReloadHelper *reloader = NULL); |
47 | FbMenu *createMenu(const std::string &label, int screen_num); | 47 | FbMenu *createMenu(const std::string &label, int screen_num); |
48 | FbMenu *createMenuType(const std::string &label, int screen_num); | 48 | FbMenu *createMenuType(const std::string &label, int screen_num); |
49 | bool createFromFile(const std::string &filename, | 49 | bool createFromFile(const std::string &filename, |
diff --git a/src/Screen.cc b/src/Screen.cc index 51fb165..8a3ad2a 100644 --- a/src/Screen.cc +++ b/src/Screen.cc | |||
@@ -277,7 +277,7 @@ BScreen::ScreenResource::ScreenResource(FbTk::ResourceManager_base &rm, | |||
277 | click_raises(rm, true, scrname+".clickRaises"), | 277 | click_raises(rm, true, scrname+".clickRaises"), |
278 | default_deco(rm, "NORMAL", scrname+".defaultDeco"), | 278 | default_deco(rm, "NORMAL", scrname+".defaultDeco"), |
279 | tab_placement(rm, FbWinFrame::TOPLEFT, scrname+".tab.placement"), | 279 | tab_placement(rm, FbWinFrame::TOPLEFT, scrname+".tab.placement"), |
280 | windowmenufile(rm, Fluxbox::instance()->getDefaultDataFilename("windowmenu"), scrname+".windowMenu"), | 280 | windowmenufile(rm, Fluxbox::instance()->getDefaultDataFilename("windowmenu2"), scrname+".windowMenu"), |
281 | typing_delay(rm, 0, scrname+".noFocusWhileTypingDelay"), | 281 | typing_delay(rm, 0, scrname+".noFocusWhileTypingDelay"), |
282 | workspaces(rm, 4, scrname+".workspaces"), | 282 | workspaces(rm, 4, scrname+".workspaces"), |
283 | edge_snap_threshold(rm, 10, scrname+".edgeSnapThreshold"), | 283 | edge_snap_threshold(rm, 10, scrname+".edgeSnapThreshold"), |
@@ -1403,26 +1403,25 @@ void BScreen::reassociateWindow(FluxboxWindow *w, unsigned int wkspc_id, | |||
1403 | } | 1403 | } |
1404 | 1404 | ||
1405 | void BScreen::initMenus() { | 1405 | void BScreen::initMenus() { |
1406 | lua::state &l = Fluxbox::instance()->lua(); | ||
1407 | m_workspacemenu.reset(MenuCreator::createMenuType("workspacemenu", screenNumber())); | 1406 | m_workspacemenu.reset(MenuCreator::createMenuType("workspacemenu", screenNumber())); |
1408 | l.loadfile(FbTk::StringUtil::expandFilename(Fluxbox::instance()->getMenuFilename()).c_str()); | 1407 | |
1409 | l.call(0, 0); | 1408 | m_rootmenu->reloadHelper()->setMainFile(Fluxbox::instance()->getMenuFilename()); |
1410 | l.getglobal("menu"); | ||
1411 | m_rootmenu = MenuCreator::createMenu(l, 0); | ||
1412 | // m_rootmenu->reloadHelper()->setMainFile(Fluxbox::instance()->getMenuFilename()); | ||
1413 | m_windowmenu->reloadHelper()->setMainFile(windowMenuFilename()); | 1409 | m_windowmenu->reloadHelper()->setMainFile(windowMenuFilename()); |
1414 | } | 1410 | } |
1415 | 1411 | ||
1416 | 1412 | ||
1417 | void BScreen::rereadMenu() { | 1413 | void BScreen::rereadMenu() { |
1418 | 1414 | ||
1419 | m_rootmenu->removeAll(); | ||
1420 | m_rootmenu->setLabel(FbTk::BiDiString("")); | ||
1421 | |||
1422 | Fluxbox * const fb = Fluxbox::instance(); | 1415 | Fluxbox * const fb = Fluxbox::instance(); |
1423 | if (!fb->getMenuFilename().empty()) | 1416 | lua::state &l = fb->lua(); |
1424 | MenuCreator::createFromFile(fb->getMenuFilename(), *m_rootmenu, | 1417 | l.checkstack(1); |
1425 | m_rootmenu->reloadHelper()); | 1418 | lua::stack_sentry s(l); |
1419 | |||
1420 | // XXX try/catch | ||
1421 | m_rootmenu->removeAll(); | ||
1422 | l.loadfile(FbTk::StringUtil::expandFilename(fb->getMenuFilename()).c_str()); | ||
1423 | l.call(0, 1); | ||
1424 | MenuCreator::createMenu(*m_rootmenu, l, screenNumber(), m_rootmenu->reloadHelper()); | ||
1426 | 1425 | ||
1427 | if (m_rootmenu->numberOfItems() == 0) { | 1426 | if (m_rootmenu->numberOfItems() == 0) { |
1428 | _FB_USES_NLS; | 1427 | _FB_USES_NLS; |
@@ -1449,12 +1448,16 @@ const std::string BScreen::windowMenuFilename() const { | |||
1449 | } | 1448 | } |
1450 | 1449 | ||
1451 | void BScreen::rereadWindowMenu() { | 1450 | void BScreen::rereadWindowMenu() { |
1451 | lua::state &l = Fluxbox::instance()->lua(); | ||
1452 | l.checkstack(1); | ||
1453 | lua::stack_sentry s(l); | ||
1452 | 1454 | ||
1453 | m_windowmenu->removeAll(); | ||
1454 | if (!windowMenuFilename().empty()) | ||
1455 | MenuCreator::createFromFile(windowMenuFilename(), *m_windowmenu, | ||
1456 | m_windowmenu->reloadHelper()); | ||
1457 | 1455 | ||
1456 | // XXX try/catch | ||
1457 | m_windowmenu->removeAll(); | ||
1458 | l.loadfile(FbTk::StringUtil::expandFilename(windowMenuFilename()).c_str()); | ||
1459 | l.call(0, 1); | ||
1460 | MenuCreator::createMenu(*m_windowmenu, l, screenNumber(), m_windowmenu->reloadHelper()); | ||
1458 | } | 1461 | } |
1459 | 1462 | ||
1460 | void BScreen::addConfigMenu(const FbTk::FbString &label, FbTk::Menu &menu) { | 1463 | void BScreen::addConfigMenu(const FbTk::FbString &label, FbTk::Menu &menu) { |