Commit 50e951dc authored by hjk's avatar hjk

ProjectExplorer: Streamline the canRun(Project) functions

There's no real need to go through the chain of decisions
a second time to retrieve a message.

Change-Id: Id32ee486a7555f8eaf38668f23ec8fb2e179db89
Reviewed-by: default avatarDaniel Teske <daniel.teske@digia.com>
parent 3df7f949
......@@ -419,8 +419,7 @@ bool AnalyzerManagerPrivate::isActionRunnable(AnalyzerAction *action) const
if (action->startMode() == StartRemote)
return true;
ProjectExplorerPlugin *pe = ProjectExplorerPlugin::instance();
return pe->canRun(SessionManager::startupProject(), action->tool()->runMode());
return ProjectExplorerPlugin::canRun(SessionManager::startupProject(), action->tool()->runMode(), 0);
}
void AnalyzerManagerPrivate::startTool()
......@@ -572,16 +571,14 @@ void AnalyzerManagerPrivate::saveToolSettings(AnalyzerAction *action)
void AnalyzerManagerPrivate::updateRunActions()
{
ProjectExplorerPlugin *pe = ProjectExplorerPlugin::instance();
Project *project = SessionManager::startupProject();
QString disabledReason;
if (m_isRunning)
disabledReason = tr("An analysis is still in progress.");
else if (!m_currentAction)
disabledReason = tr("No analyzer tool selected.");
else
disabledReason = pe->cannotRunReason(project, m_currentAction->tool()->runMode());
ProjectExplorerPlugin::canRun(SessionManager::startupProject(),
m_currentAction->tool()->runMode(), &disabledReason);
m_startAction->setEnabled(isActionRunnable(m_currentAction));
m_startAction->setToolTip(disabledReason);
......
......@@ -1526,10 +1526,10 @@ void DebuggerPluginPrivate::onCurrentProjectChanged(Project *project)
m_interruptAction->setEnabled(false);
m_continueAction->setEnabled(false);
m_exitAction->setEnabled(false);
ProjectExplorerPlugin *pe = ProjectExplorerPlugin::instance();
const bool canRun = pe->canRun(project, DebugRunMode);
QString whyNot;
const bool canRun = ProjectExplorerPlugin::canRun(project, DebugRunMode, &whyNot);
m_startAction->setEnabled(canRun);
m_startAction->setToolTip(canRun ? QString() : pe->cannotRunReason(project, DebugRunMode));
m_startAction->setToolTip(whyNot);
m_debugWithoutDeployAction->setEnabled(canRun);
setProxyAction(m_visibleStartAction, Core::Id(Constants::DEBUG));
}
......@@ -2278,9 +2278,8 @@ void DebuggerPluginPrivate::updateState(DebuggerEngine *engine)
m_hiddenStopAction->setAction(m_interruptAction);
m_localsAndExpressionsWindow->setShowLocals(false);
} else if (state == DebuggerFinished) {
ProjectExplorerPlugin *pe = ProjectExplorerPlugin::instance();
Project *project = SessionManager::startupProject();
const bool canRun = pe->canRun(project, DebugRunMode);
const bool canRun = ProjectExplorerPlugin::canRun(project, DebugRunMode);
// We don't want to do anything anymore.
m_interruptAction->setEnabled(false);
m_continueAction->setEnabled(false);
......@@ -2380,28 +2379,24 @@ void DebuggerPluginPrivate::updateDebugActions()
if (m_currentEngine->state() != DebuggerNotReady)
return;
ProjectExplorerPlugin *pe = ProjectExplorerPlugin::instance();
Project *project = SessionManager::startupProject();
const bool canRun = pe->canRun(project, DebugRunMode);
QString whyNot;
const bool canRun = ProjectExplorerPlugin::canRun(project, DebugRunMode, &whyNot);
m_startAction->setEnabled(canRun);
m_startAction->setToolTip(canRun ? QString() : pe->cannotRunReason(project, DebugRunMode));
m_startAction->setToolTip(whyNot);
m_debugWithoutDeployAction->setEnabled(canRun);
// Step into/next: Start and break at 'main' unless a debugger is running.
if (m_snapshotHandler->currentIndex() < 0) {
const bool canRunAndBreakMain = pe->canRun(project, DebugRunModeWithBreakOnMain);
QString toolTip;
const bool canRunAndBreakMain
= ProjectExplorerPlugin::canRun(project, DebugRunModeWithBreakOnMain, &toolTip);
m_stepAction->setEnabled(canRunAndBreakMain);
m_nextAction->setEnabled(canRunAndBreakMain);
QString toolTip;
if (canRunAndBreakMain) {
QTC_ASSERT(project, return ; );
toolTip = tr("Start \"%1\" and break at function \"main()\"")
.arg(project->displayName());
} else {
// Do not display long tooltip saying run mode is not supported
// for project for projects to which 'break at main' is not applicable.
if (!canRun)
toolTip = pe->cannotRunReason(project, DebugRunModeWithBreakOnMain);
}
m_stepAction->setToolTip(toolTip);
m_nextAction->setToolTip(toolTip);
......
......@@ -2641,70 +2641,75 @@ void ProjectExplorerPlugin::updateDeployActions()
emit updateRunActions();
}
bool ProjectExplorerPlugin::canRun(Project *project, RunMode runMode)
bool ProjectExplorerPlugin::canRun(Project *project, RunMode runMode, QString *whyNot)
{
if (!project ||
!project->activeTarget() ||
!project->activeTarget()->activeRunConfiguration()) {
if (!project) {
if (whyNot)
*whyNot = tr("No active project.");
return false;
}
if (d->m_projectExplorerSettings.buildBeforeDeploy
&& d->m_projectExplorerSettings.deployBeforeRun
&& hasBuildSettings(project)
&& !buildSettingsEnabled(project).first)
if (project->needsConfiguration()) {
if (whyNot)
*whyNot = tr("The project \"%1\" is not configured.").arg(project->displayName());
return false;
}
Target *target = project->activeTarget();
if (!target) {
if (whyNot)
*whyNot = tr("The project \"%1\" has no active kit.").arg(project->displayName());
return false;
}
RunConfiguration *activeRC = project->activeTarget()->activeRunConfiguration();
bool canRun = findRunControlFactory(activeRC, runMode)
&& activeRC->isEnabled();
return canRun && !BuildManager::isBuilding();
}
QString ProjectExplorerPlugin::cannotRunReason(Project *project, RunMode runMode)
{
if (!project)
return tr("No active project.");
if (project->needsConfiguration())
return tr("The project %1 is not configured.").arg(project->displayName());
if (!project->activeTarget())
return tr("The project \"%1\" has no active kit.").arg(project->displayName());
RunConfiguration *activeRC = target->activeRunConfiguration();
if (!activeRC) {
if (whyNot)
*whyNot = tr("The kit \"%1\" for the project \"%2\" has no active run configuration.")
.arg(target->displayName(), project->displayName());
return false;
}
if (!project->activeTarget()->activeRunConfiguration())
return tr("The kit \"%1\" for the project \"%2\" has no active run configuration.")
.arg(project->activeTarget()->displayName(), project->displayName());
if (!activeRC->isEnabled()) {
if (whyNot)
*whyNot = activeRC->disabledReason();
return false;
}
if (d->m_projectExplorerSettings.buildBeforeDeploy
&& d->m_projectExplorerSettings.deployBeforeRun
&& hasBuildSettings(project)) {
QPair<bool, QString> buildState = buildSettingsEnabled(project);
if (!buildState.first)
return buildState.second;
if (m_instance->d->m_projectExplorerSettings.buildBeforeDeploy
&& m_instance->d->m_projectExplorerSettings.deployBeforeRun
&& m_instance->hasBuildSettings(project)) {
QPair<bool, QString> buildState = m_instance->buildSettingsEnabled(project);
if (!buildState.first) {
if (whyNot)
*whyNot = buildState.second;
return false;
}
}
RunConfiguration *activeRC = project->activeTarget()->activeRunConfiguration();
if (!activeRC->isEnabled())
return activeRC->disabledReason();
// shouldn't actually be shown to the user...
if (!findRunControlFactory(activeRC, runMode))
return tr("Cannot run \"%1\".").arg(activeRC->displayName());
if (!m_instance->findRunControlFactory(activeRC, runMode)) {
if (whyNot)
*whyNot = tr("Cannot run \"%1\".").arg(activeRC->displayName());
return false;
}
if (BuildManager::isBuilding())
return tr("A build is still in progress.");
return QString();
if (BuildManager::isBuilding()) {
if (whyNot)
*whyNot = tr("A build is still in progress.");
return false;
}
return true;
}
void ProjectExplorerPlugin::slotUpdateRunActions()
{
Project *project = SessionManager::startupProject();
const bool state = canRun(project, NormalRunMode);
QString whyNot;
const bool state = canRun(project, NormalRunMode, &whyNot);
d->m_runAction->setEnabled(state);
d->m_runAction->setToolTip(cannotRunReason(project, NormalRunMode));
d->m_runWithoutDeployAction->setEnabled(state);
......
......@@ -106,8 +106,7 @@ public:
bool coreAboutToClose();
QList<QPair<QString, QString> > recentProjects();
bool canRun(Project *pro, RunMode runMode);
QString cannotRunReason(Project *project, RunMode runMode);
static bool canRun(Project *pro, RunMode runMode, QString *whyNot = 0);
void runProject(Project *pro, RunMode, const bool forceSkipDeploy = false);
void runRunConfiguration(ProjectExplorer::RunConfiguration *rc, RunMode runMode,
const bool forceSkipDeploy = false);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment