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

Method openFontDialog

src/tools/ecode/ecode.cpp:442–527  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

440}
441
442void App::openFontDialog( std::string& fontPath, bool loadingMonoFont, bool terminalFont,
443 std::function<void()> onFinish ) {
444 std::string absoluteFontPath( fontPath );
445 if ( FileSystem::isRelativePath( absoluteFontPath ) )
446 absoluteFontPath = mResPath + fontPath;
447 UIFileDialog* dialog = UIFileDialog::New(
448 UIFileDialog::DefaultFlags |
449 ( mConfig.ui.nativeFileDialogs ? UIFileDialog::UseNativeFileDialog : 0 ),
450 "*.ttf; *.otf; *.woff; *.woff2; *.otb; *.bdf; *.ttc",
451 FileSystem::fileRemoveFileName( absoluteFontPath ) );
452 if ( dialog->getMultiView() ) {
453 ModelIndex index = dialog->getMultiView()->getListView()->findRowWithText(
454 FileSystem::fileNameFromPath( fontPath ), true,
455 UIAbstractView::FindRowWithTextMatchKind::Equals );
456 if ( index.isValid() )
457 dialog->runOnMainThread(
458 [dialog, index]() { dialog->getMultiView()->setSelection( index ); } );
459 }
460 dialog->setWindowFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL );
461 dialog->setTitle( i18n( "select_font_file", "Select Font File" ) );
462 dialog->setCloseShortcut( KEY_ESCAPE );
463 dialog->setSingleClickNavigation( mConfig.editor.singleClickNavigation );
464 dialog->on( Event::OnWindowClose, [this]( const Event* ) {
465 if ( App::instance() && mSplitter && mSplitter->getCurWidget() &&
466 !SceneManager::instance()->isShuttingDown() ) {
467 mSplitter->getCurWidget()->setFocus();
468 }
469 } );
470 dialog->on( Event::OpenFile, [this, &fontPath, loadingMonoFont, terminalFont,
471 onFinish]( const Event* event ) {
472 auto newPath = event->getNode()->asType<UIFileDialog>()->getFullPath();
473 if ( String::startsWith( newPath, mResPath ) )
474 newPath = newPath.substr( mResPath.size() );
475 if ( fontPath != newPath ) {
476 if ( !loadingMonoFont ) {
477 fontPath = newPath;
478 if ( onFinish )
479 onFinish();
480 return;
481 }
482 auto fontName =
483 FileSystem::fileRemoveExtension( FileSystem::fileNameFromPath( newPath ) );
484 FontTrueType* fontMono = loadFont( fontName, newPath );
485 if ( fontMono ) {
486 auto loadMonoFont = [this, &fontPath, newPath,
487 terminalFont]( FontTrueType* fontMono ) {
488 fontPath = newPath;
489 if ( terminalFont )
490 mTerminalFont = fontMono;
491 else
492 mFontMono = fontMono;
493 fontMono->setEnableDynamicMonospace( true );
494 fontMono->setBoldAdvanceSameAsRegular( true );
495 FontFamily::loadFromRegular( fontMono );
496 if ( mSplitter ) {
497 if ( terminalFont ) {
498 mSplitter->forEachWidgetType(
499 UI_TYPE_TERMINAL, [fontMono]( UIWidget* term ) {

Callers

nothing calls this directly

Calls 15

getMultiViewMethod · 0.80
getListViewMethod · 0.80
runOnMainThreadMethod · 0.80
setWindowFlagsMethod · 0.80
getCurWidgetMethod · 0.80
getFullPathMethod · 0.80
getNodeMethod · 0.80
substrMethod · 0.80
forEachWidgetTypeMethod · 0.80
forEachEditorMethod · 0.80

Tested by

no test coverage detected