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 /src/MenuCreator.cc | |
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.
Diffstat (limited to 'src/MenuCreator.cc')
-rw-r--r-- | src/MenuCreator.cc | 34 |
1 files changed, 16 insertions, 18 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 | ||