mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-10-27 00:28:34 +03:00
Added UIFilePickerDialog support for ecode (SpartanJ/ecode#903) and improved the dialog.
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include "customwidgets.hpp"
|
||||
#include "datetimecontroller.hpp"
|
||||
#include "featureshealth.hpp"
|
||||
#include "fontpickercontroller.hpp"
|
||||
#include "keybindingshelper.hpp"
|
||||
#include "pathhelper.hpp"
|
||||
#include "settingsactions.hpp"
|
||||
@@ -442,89 +443,8 @@ void App::openFolderDialog() {
|
||||
|
||||
void App::openFontDialog( std::string& fontPath, bool loadingMonoFont, bool terminalFont,
|
||||
std::function<void()> onFinish ) {
|
||||
std::string absoluteFontPath( fontPath );
|
||||
if ( FileSystem::isRelativePath( absoluteFontPath ) )
|
||||
absoluteFontPath = mResPath + fontPath;
|
||||
UIFileDialog* dialog = UIFileDialog::New(
|
||||
UIFileDialog::DefaultFlags |
|
||||
( mConfig.ui.nativeFileDialogs ? UIFileDialog::UseNativeFileDialog : 0 ),
|
||||
"*.ttf; *.otf; *.woff; *.woff2; *.otb; *.bdf; *.ttc",
|
||||
FileSystem::fileRemoveFileName( absoluteFontPath ) );
|
||||
if ( dialog->getMultiView() ) {
|
||||
ModelIndex index = dialog->getMultiView()->getListView()->findRowWithText(
|
||||
FileSystem::fileNameFromPath( fontPath ), true,
|
||||
UIAbstractView::FindRowWithTextMatchKind::Equals );
|
||||
if ( index.isValid() )
|
||||
dialog->runOnMainThread(
|
||||
[dialog, index]() { dialog->getMultiView()->setSelection( index ); } );
|
||||
}
|
||||
dialog->setWindowFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL );
|
||||
dialog->setTitle( i18n( "select_font_file", "Select Font File" ) );
|
||||
dialog->setCloseShortcut( KEY_ESCAPE );
|
||||
dialog->setSingleClickNavigation( mConfig.editor.singleClickNavigation );
|
||||
dialog->on( Event::OnWindowClose, [this]( const Event* ) {
|
||||
if ( App::instance() && mSplitter && mSplitter->getCurWidget() &&
|
||||
!SceneManager::instance()->isShuttingDown() ) {
|
||||
mSplitter->getCurWidget()->setFocus();
|
||||
}
|
||||
} );
|
||||
dialog->on( Event::OpenFile, [this, &fontPath, loadingMonoFont, terminalFont,
|
||||
onFinish]( const Event* event ) {
|
||||
auto newPath = event->getNode()->asType<UIFileDialog>()->getFullPath();
|
||||
if ( String::startsWith( newPath, mResPath ) )
|
||||
newPath = newPath.substr( mResPath.size() );
|
||||
if ( fontPath != newPath ) {
|
||||
if ( !loadingMonoFont ) {
|
||||
fontPath = newPath;
|
||||
if ( onFinish )
|
||||
onFinish();
|
||||
return;
|
||||
}
|
||||
auto fontName =
|
||||
FileSystem::fileRemoveExtension( FileSystem::fileNameFromPath( newPath ) );
|
||||
FontTrueType* fontMono = loadFont( fontName, newPath );
|
||||
if ( fontMono ) {
|
||||
auto loadMonoFont = [this, &fontPath, newPath,
|
||||
terminalFont]( FontTrueType* fontMono ) {
|
||||
fontPath = newPath;
|
||||
if ( terminalFont )
|
||||
mTerminalFont = fontMono;
|
||||
else
|
||||
mFontMono = fontMono;
|
||||
fontMono->setEnableDynamicMonospace( true );
|
||||
fontMono->setBoldAdvanceSameAsRegular( true );
|
||||
FontFamily::loadFromRegular( fontMono );
|
||||
if ( mSplitter ) {
|
||||
if ( terminalFont ) {
|
||||
mSplitter->forEachWidgetType(
|
||||
UI_TYPE_TERMINAL, [fontMono]( UIWidget* term ) {
|
||||
term->asType<UITerminal>()->setFont( fontMono );
|
||||
} );
|
||||
} else {
|
||||
mSplitter->forEachEditor( [fontMono]( UICodeEditor* editor ) {
|
||||
editor->setFont( fontMono );
|
||||
} );
|
||||
|
||||
if ( auto buildOutputEditor =
|
||||
mUISceneNode->find<UICodeEditor>( "build_output_output" ) )
|
||||
buildOutputEditor->setFont( fontMono );
|
||||
|
||||
if ( auto appOutputEditor =
|
||||
mUISceneNode->find<UICodeEditor>( "app_output_output" ) )
|
||||
appOutputEditor->setFont( fontMono );
|
||||
|
||||
if ( mConfig.ui.editorFontInInputFields )
|
||||
updateInputFonts();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
loadMonoFont( fontMono );
|
||||
}
|
||||
}
|
||||
} );
|
||||
dialog->center();
|
||||
dialog->show();
|
||||
mFontPickerController->openFontDialog( fontPath, loadingMonoFont, terminalFont,
|
||||
std::move( onFinish ) );
|
||||
}
|
||||
|
||||
void App::updateInputFonts() {
|
||||
@@ -1109,6 +1029,7 @@ App::App( const size_t& jobs, const std::vector<std::string>& args ) :
|
||||
mThreadPool(
|
||||
ThreadPool::createShared( jobs > 0 ? jobs : eemax<int>( 4, Sys::getCPUCount() ) ) ),
|
||||
mDateTimeController( std::make_unique<DateTimeController>( this ) ),
|
||||
mFontPickerController( std::make_unique<FontPickerController>( this ) ),
|
||||
mSettingsActions( std::make_unique<SettingsActions>( this ) ) {}
|
||||
|
||||
static void fsRemoveAll( const std::string& fpath ) {
|
||||
|
||||
Reference in New Issue
Block a user