From b788cf8ee51a63157ace5d03e7b9036f7ee04908 Mon Sep 17 00:00:00 2001 From: Justyna Hudziak Date: Fri, 27 Sep 2024 14:54:24 +0200 Subject: [PATCH] Lua: Add function to stop running configurations Change-Id: I85cb9113efeb0c7b1bdd6e12eb7cabe369458dee Reviewed-by: Marcus Tillmanns --- src/plugins/lua/bindings/project.cpp | 20 ++++++++++++++++++++ src/plugins/lua/meta/project.lua | 6 ++++++ 2 files changed, 26 insertions(+) diff --git a/src/plugins/lua/bindings/project.cpp b/src/plugins/lua/bindings/project.cpp index 22cc904ea50..e140ca92790 100644 --- a/src/plugins/lua/bindings/project.cpp +++ b/src/plugins/lua/bindings/project.cpp @@ -113,6 +113,26 @@ void setupProjectModule() } }; + result["stopRunConfigurationsByName"] = + [](const QString &displayName, const std::optional &force) -> int { + const auto runControls = ProjectExplorerPlugin::instance()->allRunControls(); + + int stoppedCount = 0; + for (const auto rc : runControls) { + if (rc && rc->displayName() == displayName) { + stoppedCount++; + + if (force.has_value() && force.value()) { + rc->forceStop(); + } else { + rc->initiateStop(); + } + } + } + + return stoppedCount; + }; + result["RunMode"] = lua.create_table_with( "Normal", Constants::NORMAL_RUN_MODE, "Debug", Constants::DEBUG_RUN_MODE); diff --git a/src/plugins/lua/meta/project.lua b/src/plugins/lua/meta/project.lua index 7a90c67c154..37f5881c447 100644 --- a/src/plugins/lua/meta/project.lua +++ b/src/plugins/lua/meta/project.lua @@ -50,4 +50,10 @@ function project.canRunStartupProject(runMode) end ---@param displayName? string Override the run configuration display name with the provided name. function project.runStartupProject(runnable, displayName) end +---Stops any configuration with display names equal to the provided name. +---@param displayName string The name for projects to stop. +---@param force? boolean Whether to close project forcefully (false assumeed if not provided). +---@return int Number of stopped configurations. +function project.stopRunConfigurationsByName(displayName, force) end + return project