diff --git a/src/tools/ecode/ecode.cpp b/src/tools/ecode/ecode.cpp index 3277aa0a8..b5a2754b7 100644 --- a/src/tools/ecode/ecode.cpp +++ b/src/tools/ecode/ecode.cpp @@ -2786,40 +2786,6 @@ void App::toggleSettingsMenu() { mSettings->toggleSettingsMenu(); } -void App::createNewTerminal() { - if ( mSplitter->hasSplit() ) { - if ( mSplitter->getTabWidgets().size() == 2 ) { - UIOrientation orientation = mSplitter->getMainSplitOrientation(); - if ( mConfig.term.newTerminalOrientation == NewTerminalOrientation::Vertical && - orientation == UIOrientation::Horizontal ) { - mTerminalManager->createNewTerminal( "", mSplitter->getTabWidgets()[1] ); - return; - } - if ( mConfig.term.newTerminalOrientation == NewTerminalOrientation::Horizontal && - orientation == UIOrientation::Vertical ) { - mTerminalManager->createNewTerminal( "", mSplitter->getTabWidgets()[1] ); - return; - } - } - mTerminalManager->createNewTerminal(); - } else { - switch ( mConfig.term.newTerminalOrientation ) { - case NewTerminalOrientation::Vertical: { - runCommand( "terminal-split-right" ); - break; - } - case NewTerminalOrientation::Horizontal: { - runCommand( "terminal-split-bottom" ); - break; - } - case NewTerminalOrientation::Same: { - mTerminalManager->createNewTerminal(); - break; - } - } - } -} - void App::showFolderTreeViewTab() { UITab* tab = mSidePanel->find( "treeview_tab" ); if ( tab ) diff --git a/src/tools/ecode/ecode.hpp b/src/tools/ecode/ecode.hpp index 8c0d713cf..b4efd114d 100644 --- a/src/tools/ecode/ecode.hpp +++ b/src/tools/ecode/ecode.hpp @@ -180,8 +180,6 @@ class App : public UICodeEditorSplitter::Client { void toggleSettingsMenu(); - void createNewTerminal(); - UIStatusBar* getStatusBar() const { return mStatusBar; } void showFolderTreeViewTab(); @@ -201,7 +199,8 @@ class App : public UICodeEditorSplitter::Client { t.setCommand( "download-file-web", [this] { downloadFileWebDialog(); } ); t.setCommand( "move-panel-left", [this] { panelPosition( PanelPosition::Left ); } ); t.setCommand( "move-panel-right", [this] { panelPosition( PanelPosition::Right ); } ); - t.setCommand( "create-new-terminal", [this] { createNewTerminal(); } ); + t.setCommand( "create-new-terminal", + [this] { mTerminalManager->createTerminalInSplitter(); } ); t.setCommand( "terminal-split-right", [this] { auto cwd = getCurrentWorkingDir(); mSplitter->split( UICodeEditorSplitter::SplitDirection::Right, diff --git a/src/tools/ecode/projectbuild.cpp b/src/tools/ecode/projectbuild.cpp index 8ab494fb8..f4f459efb 100644 --- a/src/tools/ecode/projectbuild.cpp +++ b/src/tools/ecode/projectbuild.cpp @@ -35,6 +35,18 @@ static void replaceVar( ProjectBuildStep& s, const std::string& var, const std:: FileSystem::dirAddSlashAtEnd( s.workingDir ); } +ProjectBuildStep ProjectBuild::replaceVars( const ProjectBuildStep& step ) const { + ProjectBuildStep s( step ); + replaceVar( s, VAR_PROJECT_ROOT, mProjectRoot ); + for ( auto& var : mVars ) { + std::string varKey( "${" + var.first + "}" ); + std::string varVal( var.second ); + String::replaceAll( varVal, VAR_PROJECT_ROOT, mProjectRoot ); + replaceVar( s, varKey, varVal ); + } + return s; +} + ProjectBuildSteps ProjectBuild::replaceVars( const ProjectBuildSteps& steps ) const { ProjectBuildSteps newSteps( steps ); for ( auto& s : newSteps ) { @@ -723,25 +735,26 @@ void ProjectBuildManager::cleanCurrentConfig( StatusBuildOutputController* sboc } } -void ProjectBuildManager::runCurrentConfig( StatusBuildOutputController* sboc ) { - if ( sboc && !isBuilding() && !getBuilds().empty() ) { +void ProjectBuildManager::runCurrentConfig( StatusBuildOutputController* /* not used yet */ ) { + if ( !isBuilding() && !getBuilds().empty() ) { const ProjectBuild* build = nullptr; for ( const auto& buildIt : getBuilds() ) if ( buildIt.second.getName() == mConfig.buildName ) build = &buildIt.second; if ( build && build->hasRun() ) { - auto cmd = build->mRun.cmd + " " + build->mRun.args; - if ( build->mRun.runInTerminal ) { - UITerminal* term = mApp->getTerminalManager()->createNewTerminal( - "", nullptr, build->mRun.workingDir ); + auto finalBuild( build->replaceVars( build->mRun ) ); + auto cmd = finalBuild.cmd + " " + finalBuild.args; + if ( finalBuild.runInTerminal ) { + UITerminal* term = + mApp->getTerminalManager()->createTerminalInSplitter( finalBuild.workingDir ); if ( term == nullptr || term->getTerm() == nullptr ) { mApp->getTerminalManager()->openInExternalTerminal( cmd ); } else { term->executeFile( cmd ); } } else { - Sys::execute( cmd, build->mRun.workingDir ); + Sys::execute( cmd, finalBuild.workingDir ); } } } diff --git a/src/tools/ecode/projectbuild.hpp b/src/tools/ecode/projectbuild.hpp index 70cb2e3ca..a17132626 100644 --- a/src/tools/ecode/projectbuild.hpp +++ b/src/tools/ecode/projectbuild.hpp @@ -186,6 +186,8 @@ class ProjectBuild { return !mRun.cmd.empty() || !mRun.args.empty() || !mRun.workingDir.empty(); } + ProjectBuildStep replaceVars( const ProjectBuildStep& step ) const; + ProjectBuildSteps replaceVars( const ProjectBuildSteps& steps ) const; static json serialize( const ProjectBuild::Map& builds ); diff --git a/src/tools/ecode/terminalmanager.cpp b/src/tools/ecode/terminalmanager.cpp index 29ffd221d..33b9528c8 100644 --- a/src/tools/ecode/terminalmanager.cpp +++ b/src/tools/ecode/terminalmanager.cpp @@ -6,6 +6,50 @@ namespace ecode { TerminalManager::TerminalManager( App* app ) : mApp( app ) {} +UITerminal* TerminalManager::createTerminalInSplitter( const std::string& workingDir ) { + UITerminal* term = nullptr; + auto splitter = mApp->getSplitter(); + auto& config = mApp->getConfig(); + if ( splitter && splitter->hasSplit() ) { + if ( splitter->getTabWidgets().size() == 2 ) { + UIOrientation orientation = splitter->getMainSplitOrientation(); + if ( config.term.newTerminalOrientation == NewTerminalOrientation::Vertical && + orientation == UIOrientation::Horizontal ) { + term = createNewTerminal( "", splitter->getTabWidgets()[1], workingDir ); + } else if ( config.term.newTerminalOrientation == NewTerminalOrientation::Horizontal && + orientation == UIOrientation::Vertical ) { + term = createNewTerminal( "", splitter->getTabWidgets()[1], workingDir ); + } else { + term = createNewTerminal( "", nullptr, workingDir ); + } + } else { + term = createNewTerminal(); + } + } else { + switch ( config.term.newTerminalOrientation ) { + case NewTerminalOrientation::Vertical: { + auto cwd = workingDir.empty() ? mApp->getCurrentWorkingDir() : workingDir; + splitter->split( UICodeEditorSplitter::SplitDirection::Right, + splitter->getCurWidget(), false ); + term = createNewTerminal( "", nullptr, cwd ); + break; + } + case NewTerminalOrientation::Horizontal: { + auto cwd = workingDir.empty() ? mApp->getCurrentWorkingDir() : workingDir; + splitter->split( UICodeEditorSplitter::SplitDirection::Bottom, + splitter->getCurWidget(), false ); + term = createNewTerminal( "", nullptr, cwd ); + break; + } + case NewTerminalOrientation::Same: { + term = createNewTerminal(); + break; + } + } + } + return term; +} + void TerminalManager::applyTerminalColorScheme( const TerminalColorScheme& colorScheme ) { mApp->getSplitter()->forEachWidget( [colorScheme]( UIWidget* widget ) { if ( widget->isType( UI_TYPE_TERMINAL ) ) @@ -417,7 +461,8 @@ void TerminalManager::setKeybindings( UITerminal* term ) { { "open-file", "download-file-web", "open-folder", "debug-draw-highlight-toggle", "debug-draw-boxes-toggle", "debug-draw-debug-data", "debug-widget-tree-view", "open-locatebar", "open-command-palette", "open-global-search", "menu-toggle", - "console-toggle", "go-to-line", "editor-go-back", "editor-go-forward" } ); + "console-toggle", "go-to-line", "editor-go-back", "editor-go-forward", + "project-run-executable" } ); } } // namespace ecode diff --git a/src/tools/ecode/terminalmanager.hpp b/src/tools/ecode/terminalmanager.hpp index 40db51c1a..95e0bdde6 100644 --- a/src/tools/ecode/terminalmanager.hpp +++ b/src/tools/ecode/terminalmanager.hpp @@ -15,6 +15,8 @@ class TerminalManager { public: TerminalManager( App* app ); + UITerminal* createTerminalInSplitter( const std::string& workingDir = "" ); + UITerminal* createNewTerminal( const std::string& title = "", UITabWidget* inTabWidget = nullptr, const std::string& workingDir = "", std::string program = "",