ProjectExplorerPlugin: Use expected_str for canRunStartupProject()

Change-Id: Iddc9abcb1b9ef02c6a8188d2eb82cc30a0ba4c22
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Jarek Kobus
2023-07-06 18:16:59 +02:00
parent 714b5963f7
commit 9f1b56e91a
7 changed files with 58 additions and 80 deletions

View File

@@ -1393,9 +1393,8 @@ void DebuggerPluginPrivate::updatePresetState()
RunConfiguration *startupRunConfig = ProjectManager::startupRunConfiguration();
DebuggerEngine *currentEngine = EngineManager::currentEngine();
QString whyNot;
const bool canRun =
ProjectExplorerPlugin::canRunStartupProject(ProjectExplorer::Constants::DEBUG_RUN_MODE, &whyNot);
const auto canRun = ProjectExplorerPlugin::canRunStartupProject(
ProjectExplorer::Constants::DEBUG_RUN_MODE);
QString startupRunConfigName;
if (startupRunConfig)
@@ -1404,8 +1403,8 @@ void DebuggerPluginPrivate::updatePresetState()
startupRunConfigName = startupProject->displayName();
// Restrict width, otherwise Creator gets too wide, see QTCREATORBUG-21885
const QString startToolTip =
canRun ? Tr::tr("Start debugging of startup project") : whyNot;
const QString startToolTip = canRun ? Tr::tr("Start debugging of startup project")
: canRun.error();
m_startAction.setToolTip(startToolTip);
m_startAction.setText(Tr::tr("Start Debugging of Startup Project"));
@@ -1413,11 +1412,11 @@ void DebuggerPluginPrivate::updatePresetState()
if (!currentEngine) {
// No engine running -- or -- we have a running engine but it does not
// correspond to the current start up project.
m_startAction.setEnabled(canRun);
m_startAction.setEnabled(bool(canRun));
m_startAction.setIcon(startIcon(true));
m_startAction.setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
m_startAction.setVisible(true);
m_debugWithoutDeployAction.setEnabled(canRun);
m_debugWithoutDeployAction.setEnabled(bool(canRun));
m_visibleStartAction.setAction(&m_startAction);
m_hiddenStopAction.setAction(&m_undisturbableAction);
return;
@@ -1431,7 +1430,7 @@ void DebuggerPluginPrivate::updatePresetState()
m_startAction.setEnabled(false);
m_startAction.setVisible(false);
m_debugWithoutDeployAction.setEnabled(canRun);
m_debugWithoutDeployAction.setEnabled(bool(canRun));
const DebuggerState state = currentEngine->state();
@@ -1449,8 +1448,8 @@ void DebuggerPluginPrivate::updatePresetState()
m_hiddenStopAction.setAction(ActionManager::command(Constants::INTERRUPT)->action());
} else if (state == DebuggerFinished) {
// We don't want to do anything anymore.
m_startAction.setEnabled(canRun);
m_debugWithoutDeployAction.setEnabled(canRun);
m_startAction.setEnabled(bool(canRun));
m_debugWithoutDeployAction.setEnabled(bool(canRun));
m_visibleStartAction.setAction(ActionManager::command(DEBUGGER_START)->action());
m_hiddenStopAction.setAction(&m_undisturbableAction);
} else if (state == InferiorUnrunnable) {

View File

@@ -449,11 +449,10 @@ void PerfProfilerTool::updateRunActions()
m_loadPerfData->setEnabled(false);
m_loadTrace->setEnabled(false);
} else {
QString whyNot = Tr::tr("Start a performance analysis.");
bool canRun = ProjectExplorerPlugin::canRunStartupProject(
ProjectExplorer::Constants::PERFPROFILER_RUN_MODE, &whyNot);
m_startAction->setToolTip(whyNot);
m_startAction->setEnabled(canRun);
const auto canRun = ProjectExplorerPlugin::canRunStartupProject(
ProjectExplorer::Constants::PERFPROFILER_RUN_MODE);
m_startAction->setToolTip(canRun ? Tr::tr("Start a performance analysis.") : canRun.error());
m_startAction->setEnabled(bool(canRun));
m_loadPerfData->setEnabled(true);
m_loadTrace->setEnabled(true);
}

View File

@@ -3032,85 +3032,63 @@ void ProjectExplorerPluginPrivate::updateDeployActions()
doUpdateRunActions();
}
bool ProjectExplorerPlugin::canRunStartupProject(Id runMode, QString *whyNot)
expected_str<void> ProjectExplorerPlugin::canRunStartupProject(Utils::Id runMode)
{
Project *project = ProjectManager::startupProject();
if (!project) {
if (whyNot)
*whyNot = Tr::tr("No active project.");
return false;
}
if (!project)
return make_unexpected(Tr::tr("No active project."));
if (project->needsConfiguration()) {
if (whyNot)
*whyNot = Tr::tr("The project \"%1\" is not configured.").arg(project->displayName());
return false;
return make_unexpected(Tr::tr("The project \"%1\" is not configured.")
.arg(project->displayName()));
}
Target *target = project->activeTarget();
if (!target) {
if (whyNot)
*whyNot = Tr::tr("The project \"%1\" has no active kit.").arg(project->displayName());
return false;
return make_unexpected(Tr::tr("The project \"%1\" has no active kit.")
.arg(project->displayName()));
}
RunConfiguration *activeRC = target->activeRunConfiguration();
if (!activeRC) {
if (whyNot)
*whyNot = Tr::tr("The kit \"%1\" for the project \"%2\" has no active run configuration.")
.arg(target->displayName(), project->displayName());
return false;
return make_unexpected(
Tr::tr("The kit \"%1\" for the project \"%2\" has no active run configuration.")
.arg(target->displayName(), project->displayName()));
}
if (!activeRC->isEnabled()) {
if (whyNot)
*whyNot = activeRC->disabledReason();
return false;
}
if (!activeRC->isEnabled())
return make_unexpected(activeRC->disabledReason());
if (dd->m_projectExplorerSettings.buildBeforeDeploy != BuildBeforeRunMode::Off
&& dd->m_projectExplorerSettings.deployBeforeRun
&& !BuildManager::isBuilding(project)
&& hasBuildSettings(project)) {
QPair<bool, QString> buildState = dd->buildSettingsEnabled(project);
if (!buildState.first) {
if (whyNot)
*whyNot = buildState.second;
return false;
}
if (!buildState.first)
return make_unexpected(buildState.second);
if (BuildManager::isBuilding()) {
if (whyNot)
*whyNot = Tr::tr("A build is still in progress.");
return false;
}
if (BuildManager::isBuilding())
return make_unexpected(Tr::tr("A build is still in progress."));
}
// shouldn't actually be shown to the user...
if (!RunControl::canRun(runMode,
DeviceTypeKitAspect::deviceTypeId(target->kit()),
if (!RunControl::canRun(runMode, DeviceTypeKitAspect::deviceTypeId(target->kit()),
activeRC->id())) {
if (whyNot)
*whyNot = Tr::tr("Cannot run \"%1\".").arg(activeRC->displayName());
return false;
return make_unexpected(Tr::tr("Cannot run \"%1\".").arg(activeRC->displayName()));
}
if (dd->m_delayedRunConfiguration && dd->m_delayedRunConfiguration->project() == project) {
if (whyNot)
*whyNot = Tr::tr("A run action is already scheduled for the active project.");
return false;
}
if (dd->m_delayedRunConfiguration && dd->m_delayedRunConfiguration->project() == project)
return make_unexpected(Tr::tr("A run action is already scheduled for the active project."));
return true;
return {};
}
void ProjectExplorerPluginPrivate::doUpdateRunActions()
{
QString whyNot;
const bool state = ProjectExplorerPlugin::canRunStartupProject(Constants::NORMAL_RUN_MODE, &whyNot);
m_runAction->setEnabled(state);
m_runAction->setToolTip(whyNot);
m_runWithoutDeployAction->setEnabled(state);
const auto canRun = ProjectExplorerPlugin::canRunStartupProject(Constants::NORMAL_RUN_MODE);
m_runAction->setEnabled(bool(canRun));
m_runAction->setToolTip(canRun ? QString() : canRun.error());
m_runWithoutDeployAction->setEnabled(bool(canRun));
emit m_instance->runActionsUpdated();
}

View File

@@ -7,6 +7,7 @@
#include <extensionsystem/iplugin.h>
#include <utils/expected.h>
#include <utils/filepath.h>
#include <utils/id.h>
@@ -138,7 +139,7 @@ public:
static void renameFilesForSymbol(const QString &oldSymbolName, const QString &newSymbolName,
const Utils::FilePaths &files, bool preferLowerCaseFileNames);
static bool canRunStartupProject(Utils::Id runMode, QString *whyNot = nullptr);
static Utils::expected_str<void> canRunStartupProject(Utils::Id runMode);
static void runProject(Project *pro, Utils::Id, const bool forceSkipDeploy = false);
static void runStartupProject(Utils::Id runMode, bool forceSkipDeploy = false);
static void runRunConfiguration(RunConfiguration *rc, Utils::Id runMode,

View File

@@ -276,11 +276,11 @@ void QmlProfilerTool::updateRunActions()
d->m_startAction->setToolTip(Tr::tr("A QML Profiler analysis is still in progress."));
d->m_stopAction->setEnabled(true);
} else {
QString tooltip = Tr::tr("Start QML Profiler analysis.");
bool canRun = ProjectExplorerPlugin::canRunStartupProject
(ProjectExplorer::Constants::QML_PROFILER_RUN_MODE, &tooltip);
d->m_startAction->setToolTip(tooltip);
d->m_startAction->setEnabled(canRun);
const auto canRun = ProjectExplorerPlugin::canRunStartupProject(
ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);
d->m_startAction->setToolTip(canRun ? Tr::tr("Start QML Profiler analysis.")
: canRun.error());
d->m_startAction->setEnabled(bool(canRun));
d->m_stopAction->setEnabled(false);
}
}

View File

@@ -770,10 +770,10 @@ void CallgrindToolPrivate::updateRunActions()
m_startAction->setToolTip(Tr::tr("A Valgrind Callgrind analysis is still in progress."));
m_stopAction->setEnabled(true);
} else {
QString whyNot = Tr::tr("Start a Valgrind Callgrind analysis.");
bool canRun = ProjectExplorerPlugin::canRunStartupProject(CALLGRIND_RUN_MODE, &whyNot);
m_startAction->setToolTip(whyNot);
m_startAction->setEnabled(canRun);
const auto canRun = ProjectExplorerPlugin::canRunStartupProject(CALLGRIND_RUN_MODE);
m_startAction->setToolTip(canRun ? Tr::tr("Start a Valgrind Callgrind analysis.")
: canRun.error());
m_startAction->setEnabled(bool(canRun));
m_stopAction->setEnabled(false);
}
}

View File

@@ -888,14 +888,15 @@ void MemcheckToolPrivate::updateRunActions()
m_startWithGdbAction->setToolTip(Tr::tr("A Valgrind Memcheck analysis is still in progress."));
m_stopAction->setEnabled(true);
} else {
QString whyNot = Tr::tr("Start a Valgrind Memcheck analysis.");
bool canRun = ProjectExplorerPlugin::canRunStartupProject(MEMCHECK_RUN_MODE, &whyNot);
m_startAction->setToolTip(whyNot);
m_startAction->setEnabled(canRun);
whyNot = Tr::tr("Start a Valgrind Memcheck with GDB analysis.");
canRun = ProjectExplorerPlugin::canRunStartupProject(MEMCHECK_WITH_GDB_RUN_MODE, &whyNot);
m_startWithGdbAction->setToolTip(whyNot);
m_startWithGdbAction->setEnabled(canRun);
const auto canRun = ProjectExplorerPlugin::canRunStartupProject(MEMCHECK_RUN_MODE);
m_startAction->setToolTip(canRun ? Tr::tr("Start a Valgrind Memcheck analysis.")
: canRun.error());
m_startAction->setEnabled(bool(canRun));
const auto canRunGdb = ProjectExplorerPlugin::canRunStartupProject(
MEMCHECK_WITH_GDB_RUN_MODE);
m_startWithGdbAction->setToolTip(
canRunGdb ? Tr::tr("Start a Valgrind Memcheck with GDB analysis.") : canRunGdb.error());
m_startWithGdbAction->setEnabled(bool(canRunGdb));
m_stopAction->setEnabled(false);
}
}