diff options
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 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 | ||