diff options
author | Pavel Labath <pavelo@centrum.sk> | 2011-07-02 08:19:48 (GMT) |
---|---|---|
committer | Pavel Labath <pavelo@centrum.sk> | 2011-07-02 08:19:48 (GMT) |
commit | c56da3e3ddce80f4e33a55a122611db8debcc8a5 (patch) | |
tree | 9c294c079a4469709e08b4f9aebe5835189464e8 /src/MenuCreator.cc | |
parent | f61f4d830eefff411889d9b3c1dfaa2ef95ee05d (diff) | |
download | fluxbox_pavel-c56da3e3ddce80f4e33a55a122611db8debcc8a5.zip fluxbox_pavel-c56da3e3ddce80f4e33a55a122611db8debcc8a5.tar.bz2 |
CustomMenu command now shows lua menus
Diffstat (limited to 'src/MenuCreator.cc')
-rw-r--r-- | src/MenuCreator.cc | 43 |
1 files changed, 14 insertions, 29 deletions
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) { |