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

View File

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

View File

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

View File

@@ -7,6 +7,7 @@
#include <extensionsystem/iplugin.h> #include <extensionsystem/iplugin.h>
#include <utils/expected.h>
#include <utils/filepath.h> #include <utils/filepath.h>
#include <utils/id.h> #include <utils/id.h>
@@ -138,7 +139,7 @@ public:
static void renameFilesForSymbol(const QString &oldSymbolName, const QString &newSymbolName, static void renameFilesForSymbol(const QString &oldSymbolName, const QString &newSymbolName,
const Utils::FilePaths &files, bool preferLowerCaseFileNames); 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 runProject(Project *pro, Utils::Id, const bool forceSkipDeploy = false);
static void runStartupProject(Utils::Id runMode, bool forceSkipDeploy = false); static void runStartupProject(Utils::Id runMode, bool forceSkipDeploy = false);
static void runRunConfiguration(RunConfiguration *rc, Utils::Id runMode, 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_startAction->setToolTip(Tr::tr("A QML Profiler analysis is still in progress."));
d->m_stopAction->setEnabled(true); d->m_stopAction->setEnabled(true);
} else { } else {
QString tooltip = Tr::tr("Start QML Profiler analysis."); const auto canRun = ProjectExplorerPlugin::canRunStartupProject(
bool canRun = ProjectExplorerPlugin::canRunStartupProject ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);
(ProjectExplorer::Constants::QML_PROFILER_RUN_MODE, &tooltip); d->m_startAction->setToolTip(canRun ? Tr::tr("Start QML Profiler analysis.")
d->m_startAction->setToolTip(tooltip); : canRun.error());
d->m_startAction->setEnabled(canRun); d->m_startAction->setEnabled(bool(canRun));
d->m_stopAction->setEnabled(false); 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_startAction->setToolTip(Tr::tr("A Valgrind Callgrind analysis is still in progress."));
m_stopAction->setEnabled(true); m_stopAction->setEnabled(true);
} else { } else {
QString whyNot = Tr::tr("Start a Valgrind Callgrind analysis."); const auto canRun = ProjectExplorerPlugin::canRunStartupProject(CALLGRIND_RUN_MODE);
bool canRun = ProjectExplorerPlugin::canRunStartupProject(CALLGRIND_RUN_MODE, &whyNot); m_startAction->setToolTip(canRun ? Tr::tr("Start a Valgrind Callgrind analysis.")
m_startAction->setToolTip(whyNot); : canRun.error());
m_startAction->setEnabled(canRun); m_startAction->setEnabled(bool(canRun));
m_stopAction->setEnabled(false); 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_startWithGdbAction->setToolTip(Tr::tr("A Valgrind Memcheck analysis is still in progress."));
m_stopAction->setEnabled(true); m_stopAction->setEnabled(true);
} else { } else {
QString whyNot = Tr::tr("Start a Valgrind Memcheck analysis."); const auto canRun = ProjectExplorerPlugin::canRunStartupProject(MEMCHECK_RUN_MODE);
bool canRun = ProjectExplorerPlugin::canRunStartupProject(MEMCHECK_RUN_MODE, &whyNot); m_startAction->setToolTip(canRun ? Tr::tr("Start a Valgrind Memcheck analysis.")
m_startAction->setToolTip(whyNot); : canRun.error());
m_startAction->setEnabled(canRun); m_startAction->setEnabled(bool(canRun));
whyNot = Tr::tr("Start a Valgrind Memcheck with GDB analysis."); const auto canRunGdb = ProjectExplorerPlugin::canRunStartupProject(
canRun = ProjectExplorerPlugin::canRunStartupProject(MEMCHECK_WITH_GDB_RUN_MODE, &whyNot); MEMCHECK_WITH_GDB_RUN_MODE);
m_startWithGdbAction->setToolTip(whyNot); m_startWithGdbAction->setToolTip(
m_startWithGdbAction->setEnabled(canRun); canRunGdb ? Tr::tr("Start a Valgrind Memcheck with GDB analysis.") : canRunGdb.error());
m_startWithGdbAction->setEnabled(bool(canRunGdb));
m_stopAction->setEnabled(false); m_stopAction->setEnabled(false);
} }
} }