MCPcopy Create free account
hub / github.com/SpartanJ/eepp / createLanguagesMenu

Method createLanguagesMenu

src/tools/ecode/settingsmenu.cpp:2319–2369  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2317}
2318
2319UIMenu* SettingsMenu::createLanguagesMenu() {
2320 UIPopUpMenu* menu = UIPopUpMenu::New();
2321
2322 std::string curLang = mApp->getConfig().ui.language;
2323 if ( curLang.empty() )
2324 curLang = "en";
2325
2326 mApp->getThreadPool()->run( [this, menu, curLang] {
2327 auto files =
2328 FileSystem::filesInfoGetInPath( mApp->geti18nPath(), false, true, false, true );
2329
2330 std::map<std::string, std::string> languages;
2331 for ( const auto& file : files ) {
2332 if ( file.getExtension() != "xml" )
2333 continue;
2334 auto name( FileSystem::fileRemoveExtension( file.getFileName() ) );
2335 std::string data;
2336 FileSystem::fileGet( file.getFilepath(), data );
2337 std::string lptrn( "title=\"(.-)\"" );
2338 LuaPattern pattern( lptrn );
2339 PatternMatcher::Range matches[2];
2340 if ( pattern.matches( data, matches ) ) {
2341 std::string title(
2342 data.substr( matches[1].start, matches[1].end - matches[1].start ) );
2343 languages[title] = name;
2344 } else {
2345 languages[name] = name;
2346 }
2347 }
2348 if ( languages.empty() )
2349 return;
2350
2351 menu->runOnMainThread( [this, menu, curLang, languages] {
2352 for ( const auto& lang : languages )
2353 menu->addRadioButton( lang.first, curLang == lang.second )->setId( lang.second );
2354
2355 menu->on( Event::OnItemClicked, [this]( const Event* event ) {
2356 auto id = event->getNode()->getId();
2357 mApp->getConfig().ui.language = id;
2358 UIMessageBox* msg = UIMessageBox::New(
2359 UIMessageBox::OK,
2360 i18n( "new_ui_language", "New language assigned.\nPlease restart the "
2361 "application to see the complete changes." ) );
2362 msg->showWhenReady();
2363 mApp->setFocusEditorOnClose( msg );
2364 } );
2365 } );
2366 } );
2367
2368 return menu;
2369}
2370
2371void SettingsMenu::toggleSettingsMenu() {
2372 if ( mApp->getConfig().ui.showMenuBar ) {

Callers

nothing calls this directly

Calls 15

getConfigMethod · 0.80
getExtensionMethod · 0.80
substrMethod · 0.80
runOnMainThreadMethod · 0.80
addRadioButtonMethod · 0.80
getNodeMethod · 0.80
showWhenReadyMethod · 0.80
setFocusEditorOnCloseMethod · 0.80
getIdMethod · 0.65
NewFunction · 0.50
emptyMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected