From 993506dfb7b2470e10e65f92d68404df10198699 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Sat, 13 Sep 2025 19:26:03 -0300 Subject: [PATCH] Added "Open Project in New Window" (SpartanJ/ecode#654). Can be enabled from `Settings -> Window -> Open Project in New Window`. Close UIFileDialog with escape key down and not key up. --- include/eepp/ui/uifiledialog.hpp | 2 -- src/eepp/ui/uifiledialog.cpp | 16 +++++----------- src/tools/ecode/appconfig.cpp | 2 ++ src/tools/ecode/appconfig.hpp | 1 + src/tools/ecode/ecode.cpp | 23 ++++++++++++++++++----- src/tools/ecode/ecode.hpp | 2 +- src/tools/ecode/settingsmenu.cpp | 17 +++++++++++++++++ 7 files changed, 44 insertions(+), 19 deletions(-) diff --git a/include/eepp/ui/uifiledialog.hpp b/include/eepp/ui/uifiledialog.hpp index 3b747ede4..3b100d069 100644 --- a/include/eepp/ui/uifiledialog.hpp +++ b/include/eepp/ui/uifiledialog.hpp @@ -154,8 +154,6 @@ class EE_API UIFileDialog : public UIWindow { virtual void onWindowReady(); - virtual Uint32 onKeyUp( const KeyEvent& event ); - virtual Uint32 onKeyDown( const KeyEvent& event ); void onPressEnter( const Event* Event ); diff --git a/src/eepp/ui/uifiledialog.cpp b/src/eepp/ui/uifiledialog.cpp index 74087af31..5efbdf6cb 100644 --- a/src/eepp/ui/uifiledialog.cpp +++ b/src/eepp/ui/uifiledialog.cpp @@ -779,21 +779,15 @@ UIDropDownList* UIFileDialog::getFileTypeList() const { return mFiletype; } -Uint32 UIFileDialog::onKeyUp( const KeyEvent& event ) { - if ( mCloseShortcut && event.getKeyCode() == mCloseShortcut.key && - ( mCloseShortcut.mod == 0 || ( event.getMod() & mCloseShortcut.mod ) ) ) { - disableButtons(); - - closeWindow(); - } - - return UIWindow::onKeyUp( event ); -} - Uint32 UIFileDialog::onKeyDown( const KeyEvent& event ) { if ( mOpenShortut && event.getKeyCode() == mOpenShortut.key && ( mOpenShortut.mod == 0 || ( event.getMod() & mOpenShortut.mod ) ) ) { open(); + } else if ( mCloseShortcut && event.getKeyCode() == mCloseShortcut.key && + ( mCloseShortcut.mod == 0 || ( event.getMod() & mCloseShortcut.mod ) ) ) { + disableButtons(); + + closeWindow(); } return UIWindow::onKeyDown( event ); diff --git a/src/tools/ecode/appconfig.cpp b/src/tools/ecode/appconfig.cpp index cfeb1c183..c7f77c4dd 100644 --- a/src/tools/ecode/appconfig.cpp +++ b/src/tools/ecode/appconfig.cpp @@ -123,6 +123,7 @@ void AppConfig::load( const std::string& confPath, std::string& keybindingsPath, ui.showMenuBar = ini.getValueB( "ui", "show_menu_bar", false ); ui.welcomeScreen = ini.getValueB( "ui", "welcome_screen", true ); ui.openFilesInNewWindow = ini.getValueB( "ui", "open_files_in_new_window", false ); + ui.openProjectInNewWindow = ini.getValueB( "ui", "open_project_in_new_window", false ); ui.panelPosition = panelPositionFromString( ini.getValue( "ui", "panel_position", "left" ) ); ui.serifFont = ini.getValue( "ui", "serif_font", "fonts/NotoSans-Regular.ttf" ); ui.monospaceFont = ini.getValue( "ui", "monospace_font", "fonts/DejaVuSansMono.ttf" ); @@ -305,6 +306,7 @@ void AppConfig::save( const std::vector& recentFiles, ini.setValueB( "ui", "show_menu_bar", ui.showMenuBar ); ini.setValueB( "ui", "welcome_screen", ui.welcomeScreen ); ini.setValueB( "ui", "open_files_in_new_window", ui.openFilesInNewWindow ); + ini.setValueB( "ui", "open_project_in_new_window", ui.openProjectInNewWindow ); ini.setValue( "ui", "panel_position", panelPositionToString( ui.panelPosition ) ); ini.setValue( "ui", "serif_font", ui.serifFont ); ini.setValue( "ui", "monospace_font", ui.monospaceFont ); diff --git a/src/tools/ecode/appconfig.hpp b/src/tools/ecode/appconfig.hpp index d74684753..24283810b 100644 --- a/src/tools/ecode/appconfig.hpp +++ b/src/tools/ecode/appconfig.hpp @@ -33,6 +33,7 @@ struct UIConfig { bool showMenuBar{ false }; bool welcomeScreen{ true }; bool openFilesInNewWindow{ false }; + bool openProjectInNewWindow{ false }; PanelPosition panelPosition{ PanelPosition::Left }; std::string serifFont; std::string monospaceFont; diff --git a/src/tools/ecode/ecode.cpp b/src/tools/ecode/ecode.cpp index c97028eeb..f5ec40924 100644 --- a/src/tools/ecode/ecode.cpp +++ b/src/tools/ecode/ecode.cpp @@ -1078,8 +1078,10 @@ void App::updateRecentFolders() { mConfig.workspace.restoreLastSession = event->getNode()->asType()->isActive(); } else { - const String& txt = event->getNode()->asType()->getText(); - loadFolder( txt ); + UIMenuItem* item = event->getNode()->asType(); + const String& txt = item->getText(); + loadFolder( txt, + item->getUISceneNode()->getWindow()->getInput()->isShiftPressed() ); } } ); } @@ -3088,8 +3090,9 @@ void App::createAndShowRecentFolderPopUpMenu( Node* recentFolderBut ) { menu->on( Event::OnItemClicked, [this]( const Event* event ) { if ( !event->getNode()->isType( UI_TYPE_MENUITEM ) ) return; - const String& txt = event->getNode()->asType()->getText(); - loadFolder( txt ); + UIMenuItem* item = event->getNode()->asType(); + const String& txt = item->getText(); + loadFolder( txt, item->getUISceneNode()->getWindow()->getInput()->isShiftPressed() ); } ); auto pos = recentFolderBut->getScreenPos(); pos.y += recentFolderBut->getPixelsSize().getHeight(); @@ -3408,7 +3411,7 @@ void App::saveSidePanelTabsOrder() { mConfig.windowState.sidePanelTabsOrder.emplace_back( mSidePanel->getTab( i )->getId() ); } -void App::loadFolder( std::string path ) { +void App::loadFolder( std::string path, bool forceNewWindow ) { if ( !FileSystem::fileExists( path ) || !FileSystem::isDirectory( path ) ) { auto msgBox = UIMessageBox::New( UIMessageBox::OK, i18n( "directory_does_not_exist", @@ -3433,6 +3436,16 @@ void App::loadFolder( std::string path ) { return; } + if ( ( mConfig.ui.openProjectInNewWindow || forceNewWindow ) && + ( !mCurrentProject.empty() && mCurrentProject != getPlaygroundPath() ) ) { + std::string processPath = Sys::getProcessFilePath(); + if ( !processPath.empty() ) { + std::string cmd( processPath + " " + path ); + Sys::execute( cmd ); + } + return; + } + bool projectWasLoaded = !mCurrentProject.empty(); if ( projectWasLoaded ) { saveSidePanelTabsOrder(); diff --git a/src/tools/ecode/ecode.hpp b/src/tools/ecode/ecode.hpp index 32a4c0af0..a53a649f7 100644 --- a/src/tools/ecode/ecode.hpp +++ b/src/tools/ecode/ecode.hpp @@ -718,7 +718,7 @@ class App : public UICodeEditorSplitter::Client, public PluginContextProvider { void saveDoc(); - void loadFolder( std::string path ); + void loadFolder( std::string path, bool forceNewWindow = false ); void loadKeybindings(); diff --git a/src/tools/ecode/settingsmenu.cpp b/src/tools/ecode/settingsmenu.cpp index 741a18a3b..63c6be174 100644 --- a/src/tools/ecode/settingsmenu.cpp +++ b/src/tools/ecode/settingsmenu.cpp @@ -1252,19 +1252,23 @@ UIMenu* SettingsMenu::createWindowMenu() { mWindowMenu->addSubMenu( i18n( "split", "Split" ), findIcon( "split-horizontal" ), splitMenu ); mWindowMenu->addSeparator(); + mWindowMenu ->add( i18n( "zoom_in", "Zoom In" ), findIcon( "zoom-in" ), getKeybind( "font-size-grow" ) ) ->setId( "zoom-in" ); + mWindowMenu ->add( i18n( "zoom_out", "Zoom Out" ), findIcon( "zoom-out" ), getKeybind( "font-size-shrink" ) ) ->setId( "zoom-out" ); + mWindowMenu ->add( i18n( "zoom_reset", "Zoom Reset" ), findIcon( "zoom-reset" ), getKeybind( "font-size-reset" ) ) ->setId( "zoom-reset" ); mWindowMenu->addSeparator(); + mWindowMenu ->addCheckBox( i18n( "open_files_in_new_window_enable", "Open Files in New Window" ), mApp->getConfig().ui.openFilesInNewWindow ) @@ -1272,6 +1276,15 @@ UIMenu* SettingsMenu::createWindowMenu() { "When files are opened from a file explorer or from the command " "line, this\ncontrols whether a new window is created or not." ) ) ->setId( "open-files-in-new-window-enable" ); + + mWindowMenu + ->addCheckBox( i18n( "open_project_in_new_window", "Open Project in New Window" ), + mApp->getConfig().ui.openProjectInNewWindow ) + ->setTooltipText( i18n( "open_project_in_new_window_tooltip", + "Opened Project / Folders will be opened in a new window instead " + "of the current window unless no project is currently loaded." ) ) + ->setId( "open-project-in-new-window" ); + mWindowMenu ->addCheckBox( i18n( "welcome_screen_enable", "Enable Welcome Screen" ), mApp->getConfig().ui.welcomeScreen ) @@ -1294,6 +1307,10 @@ UIMenu* SettingsMenu::createWindowMenu() { bool active = item->asType()->isActive(); mApp->getConfig().ui.openFilesInNewWindow = active; mApp->saveConfig(); + } else if ( "open-project-in-new-window" == item->getId() ) { + bool active = item->asType()->isActive(); + mApp->getConfig().ui.openProjectInNewWindow = active; + mApp->saveConfig(); } else { String text = String( event->getNode()->asType()->getId() ).toLower(); String::replaceAll( text, " ", "-" );