diff options
author | Pavel Labath <pavelo@centrum.sk> | 2011-07-01 21:30:54 (GMT) |
---|---|---|
committer | Paul Tagliamonte <paultag@fluxbox.org> | 2012-04-07 02:11:29 (GMT) |
commit | dee1ec29d0db48b8a721e8152a980f1379e332af (patch) | |
tree | 0a4d73877d82b71220cae88e283a993e95193d28 | |
parent | fb69fe4ffba1eaceab61ea68052f41589b479784 (diff) | |
download | fluxbox_paul-dee1ec29d0db48b8a721e8152a980f1379e332af.zip fluxbox_paul-dee1ec29d0db48b8a721e8152a980f1379e332af.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 64512eb..43fdafe 100644 --- a/src/Screen.cc +++ b/src/Screen.cc | |||
@@ -259,7 +259,7 @@ BScreen::ScreenResource::ScreenResource(FbTk::ResourceManager_base &rm, | |||
259 | click_raises(rm, true, scrname+".clickRaises"), | 259 | click_raises(rm, true, scrname+".clickRaises"), |
260 | default_deco(rm, "NORMAL", scrname+".defaultDeco"), | 260 | default_deco(rm, "NORMAL", scrname+".defaultDeco"), |
261 | tab_placement(rm, FbWinFrame::TOPLEFT, scrname+".tab.placement"), | 261 | tab_placement(rm, FbWinFrame::TOPLEFT, scrname+".tab.placement"), |
262 | windowmenufile(rm, Fluxbox::instance()->getDefaultDataFilename("windowmenu"), scrname+".windowMenu"), | 262 | windowmenufile(rm, Fluxbox::instance()->getDefaultDataFilename("windowmenu2"), scrname+".windowMenu"), |
263 | typing_delay(rm, 0, scrname+".noFocusWhileTypingDelay"), | 263 | typing_delay(rm, 0, scrname+".noFocusWhileTypingDelay"), |
264 | workspaces(rm, 4, scrname+".workspaces"), | 264 | workspaces(rm, 4, scrname+".workspaces"), |
265 | edge_snap_threshold(rm, 10, scrname+".edgeSnapThreshold"), | 265 | edge_snap_threshold(rm, 10, scrname+".edgeSnapThreshold"), |
@@ -1384,26 +1384,25 @@ void BScreen::reassociateWindow(FluxboxWindow *w, unsigned int wkspc_id, | |||
1384 | } | 1384 | } |
1385 | 1385 | ||
1386 | void BScreen::initMenus() { | 1386 | void BScreen::initMenus() { |
1387 | lua::state &l = Fluxbox::instance()->lua(); | ||
1388 | m_workspacemenu.reset(MenuCreator::createMenuType("workspacemenu", screenNumber())); | 1387 | m_workspacemenu.reset(MenuCreator::createMenuType("workspacemenu", screenNumber())); |
1389 | l.loadfile(FbTk::StringUtil::expandFilename(Fluxbox::instance()->getMenuFilename()).c_str()); | 1388 | |
1390 | l.call(0, 0); | 1389 | m_rootmenu->reloadHelper()->setMainFile(Fluxbox::instance()->getMenuFilename()); |
1391 | l.getglobal("menu"); | ||
1392 | m_rootmenu = MenuCreator::createMenu(l, 0); | ||
1393 | // m_rootmenu->reloadHelper()->setMainFile(Fluxbox::instance()->getMenuFilename()); | ||
1394 | m_windowmenu->reloadHelper()->setMainFile(windowMenuFilename()); | 1390 | m_windowmenu->reloadHelper()->setMainFile(windowMenuFilename()); |
1395 | } | 1391 | } |
1396 | 1392 | ||
1397 | 1393 | ||
1398 | void BScreen::rereadMenu() { | 1394 | void BScreen::rereadMenu() { |
1399 | 1395 | ||
1400 | m_rootmenu->removeAll(); | ||
1401 | m_rootmenu->setLabel(FbTk::BiDiString("")); | ||
1402 | |||
1403 | Fluxbox * const fb = Fluxbox::instance(); | 1396 | Fluxbox * const fb = Fluxbox::instance(); |
1404 | if (!fb->getMenuFilename().empty()) | 1397 | lua::state &l = fb->lua(); |
1405 | MenuCreator::createFromFile(fb->getMenuFilename(), *m_rootmenu, | 1398 | l.checkstack(1); |
1406 | m_rootmenu->reloadHelper()); | 1399 | lua::stack_sentry s(l); |
1400 | |||
1401 | // XXX try/catch | ||
1402 | m_rootmenu->removeAll(); | ||
1403 | l.loadfile(FbTk::StringUtil::expandFilename(fb->getMenuFilename()).c_str()); | ||
1404 | l.call(0, 1); | ||
1405 | MenuCreator::createMenu(*m_rootmenu, l, screenNumber(), m_rootmenu->reloadHelper()); | ||
1407 | 1406 | ||
1408 | if (m_rootmenu->numberOfItems() == 0) { | 1407 | if (m_rootmenu->numberOfItems() == 0) { |
1409 | _FB_USES_NLS; | 1408 | _FB_USES_NLS; |
@@ -1430,12 +1429,16 @@ const std::string BScreen::windowMenuFilename() const { | |||
1430 | } | 1429 | } |
1431 | 1430 | ||
1432 | void BScreen::rereadWindowMenu() { | 1431 | void BScreen::rereadWindowMenu() { |
1432 | lua::state &l = Fluxbox::instance()->lua(); | ||
1433 | l.checkstack(1); | ||
1434 | lua::stack_sentry s(l); | ||
1433 | 1435 | ||
1434 | m_windowmenu->removeAll(); | ||
1435 | if (!windowMenuFilename().empty()) | ||
1436 | MenuCreator::createFromFile(windowMenuFilename(), *m_windowmenu, | ||
1437 | m_windowmenu->reloadHelper()); | ||
1438 | 1436 | ||
1437 | // XXX try/catch | ||
1438 | m_windowmenu->removeAll(); | ||
1439 | l.loadfile(FbTk::StringUtil::expandFilename(windowMenuFilename()).c_str()); | ||
1440 | l.call(0, 1); | ||
1441 | MenuCreator::createMenu(*m_windowmenu, l, screenNumber(), m_windowmenu->reloadHelper()); | ||
1439 | } | 1442 | } |
1440 | 1443 | ||
1441 | void BScreen::addConfigMenu(const FbTk::FbString &label, FbTk::Menu &menu) { | 1444 | void BScreen::addConfigMenu(const FbTk::FbString &label, FbTk::Menu &menu) { |