diff options
author | Pavel Labath <pavelo@centrum.sk> | 2011-07-01 21:30:54 (GMT) |
---|---|---|
committer | Pavel Labath <pavelo@centrum.sk> | 2011-07-01 21:30:54 (GMT) |
commit | f61f4d830eefff411889d9b3c1dfaa2ef95ee05d (patch) | |
tree | bae3bc00a1ac8c5b1b4f634fa4d86a2d65296db4 | |
parent | cf91b0e81ba4b14bfc095f7bbfe17dfe8da87bb7 (diff) | |
download | fluxbox_pavel-f61f4d830eefff411889d9b3c1dfaa2ef95ee05d.zip fluxbox_pavel-f61f4d830eefff411889d9b3c1dfaa2ef95ee05d.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 | 5 | ||||
-rw-r--r-- | src/Screen.cc | 37 |
3 files changed, 39 insertions, 37 deletions
diff --git a/src/MenuCreator.cc b/src/MenuCreator.cc index 2c99d61..edbe313 100644 --- a/src/MenuCreator.cc +++ b/src/MenuCreator.cc | |||
@@ -234,8 +234,8 @@ string getField(lua::state &l, int pos, const char *field, FbTk::StringConvertor | |||
234 | return conv ? conv->recode(val) : val; | 234 | return conv ? conv->recode(val) : val; |
235 | } | 235 | } |
236 | 236 | ||
237 | std::auto_ptr<FbMenu> | 237 | void |
238 | createMenu_(lua::state &l, int screen_number, FbTk::StringConvertor &conv, | 238 | createMenu_(FbMenu &inject_into, lua::state &l, int screen_number, FbTk::StringConvertor &conv, |
239 | FbTk::AutoReloadHelper *reloader); | 239 | FbTk::AutoReloadHelper *reloader); |
240 | 240 | ||
241 | void | 241 | void |
@@ -288,8 +288,10 @@ insertMenuItem(lua::state &l, FbMenu &menu, FbTk::StringConvertor &parent_conv, | |||
288 | } else if (str_key == "config") { | 288 | } else if (str_key == "config") { |
289 | menu.insert(str_label, &screen->configMenu()); | 289 | menu.insert(str_label, &screen->configMenu()); |
290 | } else if(str_key == "menu") { | 290 | } else if(str_key == "menu") { |
291 | std::auto_ptr<FbMenu> t(MenuCreator::createMenu("", screen_number)); | ||
291 | l.pushvalue(-1); | 292 | l.pushvalue(-1); |
292 | menu.insert(str_label, createMenu_(l, screen_number, *conv, reloader).release()); | 293 | createMenu_(*t, l, screen_number, *conv, reloader); |
294 | menu.insert(str_label, t.release()); | ||
293 | } else { | 295 | } else { |
294 | // items that have a parameter | 296 | // items that have a parameter |
295 | const string &str_cmd = getField(l, -1, "param"); | 297 | const string &str_cmd = getField(l, -1, "param"); |
@@ -327,19 +329,18 @@ insertMenuItem(lua::state &l, FbMenu &menu, FbTk::StringConvertor &parent_conv, | |||
327 | } | 329 | } |
328 | } | 330 | } |
329 | 331 | ||
330 | std::auto_ptr<FbMenu> | 332 | void |
331 | createMenu_(lua::state &l, int screen_number, FbTk::StringConvertor &conv, | 333 | createMenu_(FbMenu &inject_into, lua::state &l, int screen_number, FbTk::StringConvertor &conv, |
332 | FbTk::AutoReloadHelper *reloader) { | 334 | FbTk::AutoReloadHelper *reloader) { |
333 | 335 | ||
334 | lua::stack_sentry s(l, -1); | 336 | lua::stack_sentry s(l, -1); |
335 | l.checkstack(1); | 337 | l.checkstack(1); |
336 | 338 | ||
337 | std::auto_ptr<FbMenu> menu( MenuCreator::createMenu(getField(l, -1, "label", &conv), | 339 | inject_into.setLabel(getField(l, -1, "label", &conv)); |
338 | screen_number) ); | ||
339 | 340 | ||
340 | for(int i = 1; l.rawgeti(-1, i), !l.isnil(-1); ++i) { | 341 | for(int i = 1; l.rawgeti(-1, i), !l.isnil(-1); ++i) { |
341 | try { | 342 | try { |
342 | insertMenuItem(l, *menu, conv, reloader); | 343 | insertMenuItem(l, inject_into, conv, reloader); |
343 | } | 344 | } |
344 | catch(std::runtime_error &e) { | 345 | catch(std::runtime_error &e) { |
345 | cerr << e.what() << endl; | 346 | cerr << e.what() << endl; |
@@ -347,31 +348,28 @@ createMenu_(lua::state &l, int screen_number, FbTk::StringConvertor &conv, | |||
347 | } l.pop(); | 348 | } l.pop(); |
348 | 349 | ||
349 | l.pop(); | 350 | l.pop(); |
350 | return menu; | ||
351 | } | 351 | } |
352 | 352 | ||
353 | } // end of anonymous namespace | 353 | } // end of anonymous namespace |
354 | 354 | ||
355 | std::auto_ptr<FbMenu> | 355 | void |
356 | MenuCreator::createMenu(lua::state &l, int screen_number, FbTk::AutoReloadHelper *reloader) { | 356 | MenuCreator::createMenu(FbMenu &inject_into, lua::state &l, int screen_number, FbTk::AutoReloadHelper *reloader) { |
357 | lua::stack_sentry s(l, -1); | 357 | lua::stack_sentry s(l, -1); |
358 | l.checkstack(1); | ||
359 | 358 | ||
360 | if(l.type(-1) != lua::TTABLE) { | 359 | if(l.type(-1) != lua::TTABLE) { |
361 | cerr << _FB_CONSOLETEXT(Menu, MenuNotTable, "Warning: Menu is not a lua table", | 360 | cerr << _FB_CONSOLETEXT(Menu, MenuNotTable, "Warning: Menu is not a lua table", |
362 | "Menu is not a lua table") << endl; | 361 | "Menu is not a lua table") << endl; |
363 | return std::auto_ptr<FbMenu>(); | 362 | return; |
364 | } | 363 | } |
365 | 364 | ||
366 | std::auto_ptr<FbTk::StringConvertor> conv(new FbTk::StringConvertor(FbTk::StringConvertor::ToFbString)); | 365 | std::auto_ptr<FbTk::StringConvertor> conv(new FbTk::StringConvertor(FbTk::StringConvertor::ToFbString)); |
367 | 366 | ||
368 | // if menu specifies an encoding, create a convertor for it | 367 | // if menu specifies an encoding, create a convertor for it |
369 | l.rawgetfield(-1, "encoding"); { | 368 | const std::string &enc = getField(l, -1, "encoding"); |
370 | if(l.isstring(-1)) | 369 | if(!enc.empty()) |
371 | conv->setSource(l.tostring(-1)); | 370 | conv->setSource(enc); |
372 | } l.pop(); | ||
373 | 371 | ||
374 | return createMenu_(l, screen_number, *conv, reloader); | 372 | createMenu_(inject_into, l, screen_number, *conv, reloader); |
375 | } | 373 | } |
376 | 374 | ||
377 | 375 | ||
diff --git a/src/MenuCreator.hh b/src/MenuCreator.hh index 6c537de..2c90f3d 100644 --- a/src/MenuCreator.hh +++ b/src/MenuCreator.hh | |||
@@ -42,8 +42,9 @@ class FluxboxWindow; | |||
42 | 42 | ||
43 | class MenuCreator { | 43 | class MenuCreator { |
44 | public: | 44 | public: |
45 | static std::auto_ptr<FbMenu> | 45 | static void |
46 | createMenu(lua::state &l, int screen_number, FbTk::AutoReloadHelper *reloader = NULL); | 46 | createMenu(FbMenu &inject_into, lua::state &l, int screen_number, |
47 | FbTk::AutoReloadHelper *reloader = NULL); | ||
47 | static FbMenu *createMenu(const std::string &label, int screen_num); | 48 | static FbMenu *createMenu(const std::string &label, int screen_num); |
48 | static FbMenu *createMenuType(const std::string &label, int screen_num); | 49 | static FbMenu *createMenuType(const std::string &label, int screen_num); |
49 | static bool createFromFile(const std::string &filename, | 50 | static bool createFromFile(const std::string &filename, |
diff --git a/src/Screen.cc b/src/Screen.cc index f384476..7b81469 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"), |
@@ -1392,26 +1392,25 @@ void BScreen::reassociateWindow(FluxboxWindow *w, unsigned int wkspc_id, | |||
1392 | } | 1392 | } |
1393 | 1393 | ||
1394 | void BScreen::initMenus() { | 1394 | void BScreen::initMenus() { |
1395 | lua::state &l = Fluxbox::instance()->lua(); | ||
1396 | m_workspacemenu.reset(MenuCreator::createMenuType("workspacemenu", screenNumber())); | 1395 | m_workspacemenu.reset(MenuCreator::createMenuType("workspacemenu", screenNumber())); |
1397 | l.loadfile(FbTk::StringUtil::expandFilename(Fluxbox::instance()->getMenuFilename()).c_str()); | 1396 | |
1398 | l.call(0, 0); | 1397 | m_rootmenu->reloadHelper()->setMainFile(Fluxbox::instance()->getMenuFilename()); |
1399 | l.getglobal("menu"); | ||
1400 | m_rootmenu = MenuCreator::createMenu(l, 0); | ||
1401 | // m_rootmenu->reloadHelper()->setMainFile(Fluxbox::instance()->getMenuFilename()); | ||
1402 | m_windowmenu->reloadHelper()->setMainFile(windowMenuFilename()); | 1398 | m_windowmenu->reloadHelper()->setMainFile(windowMenuFilename()); |
1403 | } | 1399 | } |
1404 | 1400 | ||
1405 | 1401 | ||
1406 | void BScreen::rereadMenu() { | 1402 | void BScreen::rereadMenu() { |
1407 | 1403 | ||
1408 | m_rootmenu->removeAll(); | ||
1409 | m_rootmenu->setLabel(FbTk::BiDiString("")); | ||
1410 | |||
1411 | Fluxbox * const fb = Fluxbox::instance(); | 1404 | Fluxbox * const fb = Fluxbox::instance(); |
1412 | if (!fb->getMenuFilename().empty()) | 1405 | lua::state &l = fb->lua(); |
1413 | MenuCreator::createFromFile(fb->getMenuFilename(), *m_rootmenu, | 1406 | l.checkstack(1); |
1414 | m_rootmenu->reloadHelper()); | 1407 | lua::stack_sentry s(l); |
1408 | |||
1409 | // XXX try/catch | ||
1410 | m_rootmenu->removeAll(); | ||
1411 | l.loadfile(FbTk::StringUtil::expandFilename(fb->getMenuFilename()).c_str()); | ||
1412 | l.call(0, 1); | ||
1413 | MenuCreator::createMenu(*m_rootmenu, l, screenNumber(), m_rootmenu->reloadHelper()); | ||
1415 | 1414 | ||
1416 | if (m_rootmenu->numberOfItems() == 0) { | 1415 | if (m_rootmenu->numberOfItems() == 0) { |
1417 | _FB_USES_NLS; | 1416 | _FB_USES_NLS; |
@@ -1438,12 +1437,16 @@ const std::string BScreen::windowMenuFilename() const { | |||
1438 | } | 1437 | } |
1439 | 1438 | ||
1440 | void BScreen::rereadWindowMenu() { | 1439 | void BScreen::rereadWindowMenu() { |
1440 | lua::state &l = Fluxbox::instance()->lua(); | ||
1441 | l.checkstack(1); | ||
1442 | lua::stack_sentry s(l); | ||
1441 | 1443 | ||
1442 | m_windowmenu->removeAll(); | ||
1443 | if (!windowMenuFilename().empty()) | ||
1444 | MenuCreator::createFromFile(windowMenuFilename(), *m_windowmenu, | ||
1445 | m_windowmenu->reloadHelper()); | ||
1446 | 1444 | ||
1445 | // XXX try/catch | ||
1446 | m_windowmenu->removeAll(); | ||
1447 | l.loadfile(FbTk::StringUtil::expandFilename(windowMenuFilename()).c_str()); | ||
1448 | l.call(0, 1); | ||
1449 | MenuCreator::createMenu(*m_windowmenu, l, screenNumber(), m_windowmenu->reloadHelper()); | ||
1447 | } | 1450 | } |
1448 | 1451 | ||
1449 | void BScreen::addConfigMenu(const FbTk::FbString &label, FbTk::Menu &menu) { | 1452 | void BScreen::addConfigMenu(const FbTk::FbString &label, FbTk::Menu &menu) { |