aboutsummaryrefslogtreecommitdiff
path: root/src/MenuCreator.cc
diff options
context:
space:
mode:
authorPavel Labath <pavelo@centrum.sk>2011-07-02 08:19:48 (GMT)
committerPavel Labath <pavelo@centrum.sk>2011-07-02 08:19:48 (GMT)
commitc56da3e3ddce80f4e33a55a122611db8debcc8a5 (patch)
tree9c294c079a4469709e08b4f9aebe5835189464e8 /src/MenuCreator.cc
parentf61f4d830eefff411889d9b3c1dfaa2ef95ee05d (diff)
downloadfluxbox_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.cc43
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
237void 237void
238createMenu_(FbMenu &inject_into, lua::state &l, int screen_number, FbTk::StringConvertor &conv, 238createMenu_(FbTk::Menu &inject_into, lua::state &l, FbTk::StringConvertor &conv,
239 FbTk::AutoReloadHelper *reloader); 239 FbTk::AutoReloadHelper *reloader);
240 240
241void 241void
242insertMenuItem(lua::state &l, FbMenu &menu, FbTk::StringConvertor &parent_conv, 242insertMenuItem(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
332void 332void
333createMenu_(FbMenu &inject_into, lua::state &l, int screen_number, FbTk::StringConvertor &conv, 333createMenu_(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
355void 355void
356MenuCreator::createMenu(FbMenu &inject_into, lua::state &l, int screen_number, FbTk::AutoReloadHelper *reloader) { 356MenuCreator::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
390bool MenuCreator::createFromFile(const string &filename, 390void 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
419FbMenu *MenuCreator::createMenuType(const string &type, int screen_num) { 404FbMenu *MenuCreator::createMenuType(const string &type, int screen_num) {