diff --git a/include/eepp/window/keycodes.hpp b/include/eepp/window/keycodes.hpp index aef7d6606..b06cb87a5 100644 --- a/include/eepp/window/keycodes.hpp +++ b/include/eepp/window/keycodes.hpp @@ -693,7 +693,7 @@ enum KeyModTable { #if EE_PLATFORM == EE_PLATFORM_MACOS #define KEYMOD_DEFAULT_MODIFIER KEYMOD_META #elif EE_PLATFORM == EE_PLATFORM_HAIKU -#define KEYMOD_DEFAULT_MODIFIER KEYMOD_ALT +#define KEYMOD_DEFAULT_MODIFIER KEYMOD_LALT #else #define KEYMOD_DEFAULT_MODIFIER KEYMOD_CTRL #endif diff --git a/src/eepp/ui/uispinbox.cpp b/src/eepp/ui/uispinbox.cpp index 2665daea8..31c1cf1e3 100644 --- a/src/eepp/ui/uispinbox.cpp +++ b/src/eepp/ui/uispinbox.cpp @@ -22,6 +22,7 @@ UISpinBox::UISpinBox() : mInput->setVisible( true ); mInput->setEnabled( true ); mInput->setParent( this ); + mInput->setFlags( UI_SCROLLABLE ); auto cb = [this]( const Event* ) { adjustChildren(); }; diff --git a/src/tools/ecode/fontpickercontroller.cpp b/src/tools/ecode/fontpickercontroller.cpp index 124342b82..3e760537c 100644 --- a/src/tools/ecode/fontpickercontroller.cpp +++ b/src/tools/ecode/fontpickercontroller.cpp @@ -160,26 +160,25 @@ void FontPickerController::openFontDialog( std::string& fontPath, bool loadingMo if ( fontPath != newPath ) { if ( !loadingMonoFont ) { fontPath = newPath; - if ( onFinish ) - onFinish(); - return; - } - - FontTrueTypePtr previewFont = preview && newPath != preview->originalPath - ? loadPreviewFont( selection.font ) - : FontTrueTypePtr{}; - FontTrueType* fontMono = previewFont ? previewFont.get() : preview->originalFont; - if ( fontMono ) { - fontPath = newPath; - if ( preview ) - preview->confirmed = true; - publishPreviewFont( newPath, previewFont ); - applyMonospaceFont( fontMono, previewFont != nullptr ); + } else { + FontTrueTypePtr previewFont = preview && newPath != preview->originalPath + ? loadPreviewFont( selection.font ) + : FontTrueTypePtr{}; + FontTrueType* fontMono = previewFont ? previewFont.get() : preview->originalFont; + if ( fontMono ) { + fontPath = newPath; + if ( preview ) + preview->confirmed = true; + publishPreviewFont( newPath, previewFont ); + applyMonospaceFont( fontMono, previewFont != nullptr ); + } } } else if ( preview ) { preview->confirmed = true; applyMonospaceFont( preview->originalFont, false ); } + if ( onFinish ) + onFinish(); } ); if ( pickFontSize ) { UIFontSelection selection = dialog->getSelection(); diff --git a/src/tools/ecode/settingspage.cpp b/src/tools/ecode/settingspage.cpp index b396b5547..1e8848522 100644 --- a/src/tools/ecode/settingspage.cpp +++ b/src/tools/ecode/settingspage.cpp @@ -185,7 +185,7 @@ bool SettingsPage::addJsonObject( std::string id, std::string jsonPointer, Strin document->setValue( jsonPointer, std::move( parsed ) ); return true; }, - true } } ); + false } } ); } bool SettingsPage::addStringList( std::string id, std::string jsonPointer, String name, diff --git a/src/tools/ecode/settingspanel.cpp b/src/tools/ecode/settingspanel.cpp index 1546d8963..7401c7ccc 100644 --- a/src/tools/ecode/settingspanel.cpp +++ b/src/tools/ecode/settingspanel.cpp @@ -629,6 +629,20 @@ void SettingsPanel::addAction( PanelState& panel, SettingDescriptor binding, { std::move( binding ), ActionSetting{ buttonText, std::move( action ) } } ); } +void SettingsPanel::refreshTextSetting( PanelState& panel, const std::string& id ) { + const auto& settings = panel.model.settings(); + for ( size_t i = 0; i < settings.size(); ++i ) { + if ( settings[i].descriptor.id != id || i >= panel.settingViews.size() || + !panel.settingViews[i].row ) + continue; + auto* value = std::get_if( &settings[i].value ); + auto* input = panel.settingViews[i].row->find( "setting_control_widget" ); + if ( value && input ) + input->setText( String::fromUtf8( value->get() ) ); + return; + } +} + static void setNodeTreeEnabled( Node* node, bool enabled ); void SettingsPanel::materializeCategory( PanelState& panel, const std::string& category ) { @@ -724,7 +738,7 @@ void SettingsPanel::materializeCategory( PanelState& panel, const std::string& c if ( value->password ) input->setMode( UITextInput::TextInputMode::Password ); input->setText( String::fromUtf8( value->get() ) ); - auto commit = [input, value]( const Event* ) { + auto commit = [input, value] { if ( !value->set( input->getText().toUtf8() ) ) { input->addClass( "error" ); return; @@ -732,10 +746,21 @@ void SettingsPanel::materializeCategory( PanelState& panel, const std::string& c input->removeClass( "error" ); }; if ( value->commitOnFocusLoss ) { - panel.connections += input->connect( Event::OnPressEnter, commit ); - panel.connections += input->connect( Event::OnFocusLoss, std::move( commit ) ); + const auto debounceTag = reinterpret_cast( input ); + panel.connections += input->connect( + Event::OnTextChanged, [input, commit, debounceTag]( const Event* ) { + input->debounce( commit, Milliseconds( 500 ), debounceTag ); + } ); + auto flush = [input, commit, debounceTag]( const Event* ) { + input->removeActionsByTag( debounceTag ); + commit(); + }; + panel.connections += input->connect( Event::OnPressEnter, flush ); + panel.connections += input->connect( Event::OnFocusLoss, std::move( flush ) ); } else { - panel.connections += input->connect( Event::OnTextChanged, std::move( commit ) ); + panel.connections += + input->connect( Event::OnTextChanged, + [commit = std::move( commit )]( const Event* ) { commit(); } ); } } else if ( auto* value = std::get_if( &setting.value ) ) { auto* row = createRow( panel, setting, view, SETTINGS_INTEGER_ROW_LAYOUT.root() ); @@ -1429,22 +1454,30 @@ void SettingsPanel::addUserSettings( PanelState& panel ) { { "uiFont", "appearance.fonts", mApp->i18n( "ui_font_and_size_ellipsis", "UI Font & Size..." ), mApp->i18n( "ui_font_desc", "Choose the proportional font used by the interface." ) }, - mApp->i18n( "choose_font", "Choose Font..." ), - [this] { mApp->runCommand( "sans-serif-font" ); } ); + mApp->i18n( "choose_font", "Choose Font..." ), [this, &panel] { + mApp->openFontDialog( mApp->getConfig().ui.sansSerifFont, false, false, + [this, &panel] { refreshTextSetting( panel, "uiFontSize" ); } ); + } ); addAction( panel, { "editorFont", "appearance.fonts", mApp->i18n( "editor_font_and_size_ellipsis", "Editor Font & Size..." ), mApp->i18n( "editor_font_desc", "Choose the monospace font used by code editors." ) }, - mApp->i18n( "choose_font", "Choose Font..." ), - [this] { mApp->runCommand( "editor-font" ); } ); + mApp->i18n( "choose_font", "Choose Font..." ), [this, &panel] { + mApp->openFontDialog( mApp->getConfig().ui.monospaceFont, true, false, [this, &panel] { + refreshTextSetting( panel, "editorFontSize" ); + } ); + } ); addAction( panel, { "terminalFont", "appearance.fonts", mApp->i18n( "terminal_font_and_size_ellipsis", "Terminal Font & Size..." ), mApp->i18n( "terminal_font_desc", "Choose the monospace font used by terminals." ) }, - mApp->i18n( "choose_font", "Choose Font..." ), - [this] { mApp->runCommand( "terminal-font" ); } ); + mApp->i18n( "choose_font", "Choose Font..." ), [this, &panel] { + mApp->openFontDialog( mApp->getConfig().ui.terminalFont, true, true, [this, &panel] { + refreshTextSetting( panel, "terminalFontSize" ); + } ); + } ); addAction( panel, { "fallbackFont", "appearance.fonts", mApp->i18n( "fallback_font_ellipsis", "Fallback Font..." ), diff --git a/src/tools/ecode/settingspanel.hpp b/src/tools/ecode/settingspanel.hpp index ab415e364..390dba40d 100644 --- a/src/tools/ecode/settingspanel.hpp +++ b/src/tools/ecode/settingspanel.hpp @@ -108,6 +108,7 @@ class SettingsPanel { void addAction( PanelState& state, SettingDescriptor binding, const String& buttonText, std::function action ); + void refreshTextSetting( PanelState& state, const std::string& id ); UIWidget* createRow( PanelState& state, SettingDefinition& setting, SettingView& view, pugi::xml_node layout );