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

Method createDocManyLangsAlert

src/tools/ecode/ecode.cpp:2512–2566  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2510}
2511
2512void App::createDocManyLangsAlert( UICodeEditor* editor ) {
2513 UILinearLayout* docAlert = editor->findByClass<UILinearLayout>( "doc_alert_manylangs" );
2514
2515 if ( docAlert )
2516 return;
2517
2518 auto ext = editor->getDocument().getFileInfo().getExtension();
2519 auto langs = SyntaxDefinitionManager::instance()->languagesThatSupportExtension( ext );
2520
2521 if ( langs.size() <= 1 )
2522 return;
2523
2524 const auto msg = R"xml(
2525 <vbox class="doc_alert doc_alert_manylangs" layout_width="wrap_content" layout_height="wrap_content" layout_gravity="top|right" gravity-owner="true">
2526 <TextView id="doc_alert_text" layout_width="wrap_content" layout_height="wrap_content" margin-right="24dp"
2527 text='@string(reload_current_file, "The current document uses an extension that can be interpreted as more than one languages.&#xA;Which language is this document?")'
2528 />
2529 <StackLayout class="languages" layout_width="match_parent" layout_height="wrap_content" margin-right="24dp" margin-top="8dp"></StackLayout>
2530 <TextView font-size="9dp" text='@string(lang_selected_default, The language selected will be set as the default language for this file extension.)' margin-top="8dp" />
2531 </vbox>
2532 )xml";
2533 docAlert = mUISceneNode->loadLayoutFromString( msg, editor )->asType<UILinearLayout>();
2534
2535 UIStackLayout* stack = docAlert->findByClass<UIStackLayout>( "languages" );
2536
2537 if ( !stack ) {
2538 docAlert->close();
2539 return;
2540 }
2541
2542 for ( const auto& lang : langs ) {
2543 UIPushButton* btn = UIPushButton::New();
2544 btn->setParent( stack );
2545 btn->setText( lang->getLanguageName() );
2546 btn->setLayoutMarginRight( PixelDensity::dpToPx( 8 ) );
2547 btn->onClick( [this, editor, lang, docAlert, ext]( auto ) {
2548 editor->setSyntaxDefinition( *lang );
2549 editor->disableReportSizeChangeToChildren();
2550 docAlert->close();
2551 editor->setFocus();
2552 getCurrentLanguageExtensionsPriorities()[ext] = lang->getLSPName();
2553 updateLanguageExtensionsPriorities();
2554 } );
2555 }
2556
2557 editor->enableReportSizeChangeToChildren();
2558
2559 docAlert->runOnMainThread(
2560 [docAlert, editor] {
2561 editor->disableReportSizeChangeToChildren();
2562 docAlert->close();
2563 editor->setFocus();
2564 },
2565 Seconds( 30.f ) );
2566}
2567
2568void App::loadImageFromMedium( const std::string& path, bool isMemory, bool forcePreview,
2569 bool forceTab ) {

Callers

nothing calls this directly

Calls 15

SecondsFunction · 0.85
getExtensionMethod · 0.80
getDocumentMethod · 0.80
loadLayoutFromStringMethod · 0.80
setParentMethod · 0.80
setLayoutMarginRightMethod · 0.80
runOnMainThreadMethod · 0.80
closeMethod · 0.65
NewFunction · 0.50

Tested by

no test coverage detected