diff --git a/src/plugins/debugger/debuggerplugin.cpp b/src/plugins/debugger/debuggerplugin.cpp index 6156d40b34a..2390096a3fb 100644 --- a/src/plugins/debugger/debuggerplugin.cpp +++ b/src/plugins/debugger/debuggerplugin.cpp @@ -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) { diff --git a/src/plugins/perfprofiler/perfprofilertool.cpp b/src/plugins/perfprofiler/perfprofilertool.cpp index 60bbcc3ae31..d4a06a249e3 100644 --- a/src/plugins/perfprofiler/perfprofilertool.cpp +++ b/src/plugins/perfprofiler/perfprofilertool.cpp @@ -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); } diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp index b68121ca02e..26c6ed8827d 100644 --- a/src/plugins/projectexplorer/projectexplorer.cpp +++ b/src/plugins/projectexplorer/projectexplorer.cpp @@ -3032,85 +3032,63 @@ void ProjectExplorerPluginPrivate::updateDeployActions() doUpdateRunActions(); } -bool ProjectExplorerPlugin::canRunStartupProject(Id runMode, QString *whyNot) +expected_str 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 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(); } diff --git a/src/plugins/projectexplorer/projectexplorer.h b/src/plugins/projectexplorer/projectexplorer.h index 0b87f53310b..c472094a987 100644 --- a/src/plugins/projectexplorer/projectexplorer.h +++ b/src/plugins/projectexplorer/projectexplorer.h @@ -7,6 +7,7 @@ #include +#include #include #include @@ -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 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, diff --git a/src/plugins/qmlprofiler/qmlprofilertool.cpp b/src/plugins/qmlprofiler/qmlprofilertool.cpp index c87562e3f9b..59a740e3b5d 100644 --- a/src/plugins/qmlprofiler/qmlprofilertool.cpp +++ b/src/plugins/qmlprofiler/qmlprofilertool.cpp @@ -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); } } diff --git a/src/plugins/valgrind/callgrindtool.cpp b/src/plugins/valgrind/callgrindtool.cpp index ab5b0e55602..d2dfc469e03 100644 --- a/src/plugins/valgrind/callgrindtool.cpp +++ b/src/plugins/valgrind/callgrindtool.cpp @@ -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); } } diff --git a/src/plugins/valgrind/memchecktool.cpp b/src/plugins/valgrind/memchecktool.cpp index 5224b3c78c8..e179e8c4f55 100644 --- a/src/plugins/valgrind/memchecktool.cpp +++ b/src/plugins/valgrind/memchecktool.cpp @@ -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); } }