Commit 9494303b authored by hjk's avatar hjk Committed by Ulf Hermann

Analyzer: Move tool startup code closer to the action setup

The code sharing in the base was along a somewhat unfortunate
boundary. Moving it into the only user also removes some of
the wrong local/remote separation.

Change-Id: I0be9636ea448d123f9f5105a52d56f47ff7871c3
Reviewed-by: default avatarUlf Hermann <ulf.hermann@theqtcompany.com>
parent 3ea51763
......@@ -422,8 +422,7 @@ bool AnalyzerManagerPrivate::showPromptDialog(const QString &title, const QStrin
void AnalyzerManagerPrivate::startTool()
{
QTC_ASSERT(m_currentAction, return);
TaskHub::clearTasks(Constants::ANALYZERTASK_ID);
m_currentAction->toolStarter()();
m_currentAction->startTool();
}
void AnalyzerManagerPrivate::modeChanged(IMode *mode)
......
......@@ -33,7 +33,6 @@
#include "analyzermanager.h"
#include "analyzerruncontrol.h"
#include "startremotedialog.h"
#include <coreplugin/icore.h>
#include <coreplugin/imode.h>
......@@ -44,6 +43,7 @@
#include <projectexplorer/buildconfiguration.h>
#include <projectexplorer/session.h>
#include <projectexplorer/target.h>
#include <projectexplorer/taskhub.h>
#include <utils/qtcassert.h>
#include <utils/checkablemessagebox.h>
......@@ -59,12 +59,12 @@ using namespace ProjectExplorer;
namespace Analyzer {
AnalyzerAction::AnalyzerAction(QObject *parent)
: QAction(parent), m_useStartupProject(true)
: QAction(parent), m_useStartupProject(true), m_toolMode(AnyMode)
{}
bool AnalyzerAction::isRunnable(QString *reason) const
{
if (!m_useStartupProject)
if (m_toolStarter) // Something special. Pretend we can always run it.
return true;
return ProjectExplorerPlugin::canRun(SessionManager::startupProject(), m_runMode, reason);
......@@ -90,11 +90,19 @@ static bool buildTypeAccepted(ToolMode toolMode, BuildConfiguration::BuildType b
return false;
}
bool checkForLocalStart(ToolMode toolMode)
void AnalyzerAction::startTool()
{
// Make sure mode is shown.
AnalyzerManager::showMode();
TaskHub::clearTasks(Constants::ANALYZERTASK_ID);
// Custom start.
if (m_toolStarter) {
m_toolStarter();
return;
}
// ### not sure if we're supposed to check if the RunConFiguration isEnabled
Project *pro = SessionManager::startupProject();
BuildConfiguration::BuildType buildType = BuildConfiguration::Unknown;
......@@ -108,13 +116,13 @@ bool checkForLocalStart(ToolMode toolMode)
// Check the project for whether the build config is in the correct mode
// if not, notify the user and urge him to use the correct mode.
if (!buildTypeAccepted(toolMode, buildType)) {
if (!buildTypeAccepted(m_toolMode, buildType)) {
const QString currentMode = buildType == BuildConfiguration::Debug
? AnalyzerManager::tr("Debug")
: AnalyzerManager::tr("Release");
QString toolModeString;
switch (toolMode) {
switch (m_toolMode) {
case DebugMode:
toolModeString = AnalyzerManager::tr("Debug");
break;
......@@ -138,26 +146,10 @@ bool checkForLocalStart(ToolMode toolMode)
if (Utils::CheckableMessageBox::doNotAskAgainQuestion(ICore::mainWindow(),
title, message, ICore::settings(), QLatin1String("AnalyzerCorrectModeWarning"))
!= QDialogButtonBox::Yes)
return false;
return;
}
return true;
}
bool checkForRemoteStart(AnalyzerStartParameters *sp)
{
StartRemoteDialog dlg;
if (dlg.exec() != QDialog::Accepted)
return false;
sp->useStartupProject = false;
sp->connParams = dlg.sshParams();
sp->debuggee = dlg.executable();
sp->debuggeeArgs = dlg.arguments();
sp->displayName = dlg.executable();
sp->workingDirectory = dlg.workingDirectory();
return true;
ProjectExplorerPlugin::runStartupProject(m_runMode);
}
} // namespace Analyzer
......@@ -63,10 +63,6 @@ enum ToolMode {
AnyMode
};
ANALYZER_EXPORT bool checkForLocalStart(ToolMode toolMode);
ANALYZER_EXPORT bool checkForRemoteStart(AnalyzerStartParameters *sp);
/**
* This class represents an analyzation action, i.e. a tool that runs in a specific mode.
*
......@@ -90,6 +86,7 @@ public:
Core::Id toolId() const { return m_toolId; }
void setToolId(Core::Id id) { m_toolId = id; }
void setToolMode(ToolMode mode) { m_toolMode = mode; }
void setRunMode(ProjectExplorer::RunMode mode) { m_runMode = mode; }
bool isRunnable(QString *reason = 0) const;
......@@ -110,7 +107,7 @@ public:
void setRunControlCreator(const RunControlCreator &creator) { m_runControlCreator = creator; }
typedef std::function<void()> ToolStarter;
ToolStarter toolStarter() const { return m_toolStarter; }
void startTool();
void setToolStarter(const ToolStarter &toolStarter) { m_toolStarter = toolStarter; }
protected:
......@@ -118,6 +115,7 @@ protected:
Core::Id m_menuGroup;
Core::Id m_actionId;
Core::Id m_toolId;
ToolMode m_toolMode;
ProjectExplorer::RunMode m_runMode;
WidgetCreator m_widgetCreator;
RunControlCreator m_runControlCreator;
......
......@@ -558,24 +558,6 @@ AnalyzerRunControl *CallgrindToolPrivate::createRunControl(const AnalyzerStartPa
return rc;
}
void CallgrindTool::startLocalTool()
{
if (checkForLocalStart(ReleaseMode)) {
ProjectExplorerPlugin::runStartupProject(CallgrindRunMode);
d->setBusyCursor(true);
}
}
void CallgrindTool::startRemoteTool()
{
AnalyzerStartParameters sp;
if (checkForRemoteStart(&sp)) {
AnalyzerRunControl *rc = createRunControl(sp, 0);
ProjectExplorerPlugin::startRunControl(rc, CallgrindRunMode);
d->setBusyCursor(true);
}
}
void CallgrindTool::handleShowCostsOfFunction()
{
d->handleShowCostsOfFunction();
......
......@@ -54,9 +54,6 @@ public:
ProjectExplorer::RunConfiguration *runConfiguration = 0);
QWidget *createWidgets();
void startLocalTool();
void startRemoteTool();
public slots:
void handleShowCostsOfFunction();
......
......@@ -594,42 +594,12 @@ void MemcheckTool::setBusyCursor(bool busy)
m_errorView->setCursor(cursor);
}
void MemcheckTool::startLocalTool()
{
if (checkForLocalStart(DebugMode))
ProjectExplorerPlugin::runStartupProject(MemcheckRunMode);
}
void MemcheckTool::startRemoteTool()
{
AnalyzerStartParameters sp;
if (checkForRemoteStart(&sp)) {
AnalyzerRunControl *rc = createRunControl(sp, 0);
ProjectExplorerPlugin::startRunControl(rc, MemcheckRunMode);
}
}
MemcheckWithGdbTool::MemcheckWithGdbTool(QObject *parent) :
MemcheckTool(parent)
{
setObjectName(QLatin1String("MemcheckWithGdbTool"));
}
void MemcheckWithGdbTool::startLocalTool()
{
if (checkForLocalStart(DebugMode))
ProjectExplorerPlugin::runStartupProject(MemcheckWithGdbRunMode);
}
void MemcheckWithGdbTool::startRemoteTool()
{
AnalyzerStartParameters sp;
if (checkForRemoteStart(&sp)) {
AnalyzerRunControl *rc = createRunControl(sp, 0);
ProjectExplorerPlugin::startRunControl(rc, MemcheckWithGdbRunMode);
}
}
MemcheckRunControl *MemcheckWithGdbTool::createMemcheckRunControl(const AnalyzerStartParameters &sp,
RunConfiguration *runConfiguration)
{
......
......@@ -83,8 +83,6 @@ class MemcheckTool : public QObject
public:
MemcheckTool(QObject *parent);
void startLocalTool();
void startRemoteTool();
QWidget *createWidgets();
Analyzer::AnalyzerRunControl *createRunControl(const Analyzer::AnalyzerStartParameters &sp,
......@@ -140,8 +138,6 @@ class MemcheckWithGdbTool : public MemcheckTool
public:
MemcheckWithGdbTool(QObject *parent);
void startLocalTool();
void startRemoteTool();
MemcheckRunControl *createMemcheckRunControl(
const Analyzer::AnalyzerStartParameters &sp,
ProjectExplorer::RunConfiguration *runConfiguration) override;
......
......@@ -38,6 +38,9 @@
#include "valgrindconfigwidget.h"
#include <analyzerbase/analyzermanager.h>
#include <analyzerbase/analyzerruncontrol.h>
#include <analyzerbase/analyzerstartparameters.h>
#include <analyzerbase/startremotedialog.h>
#include <coreplugin/dialogs/ioptionspage.h>
#include <coreplugin/actionmanager/actioncontainer.h>
......@@ -49,6 +52,9 @@
#include <cppeditor/cppeditorconstants.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <utils/hostosinfo.h>
#include <QtPlugin>
......@@ -56,6 +62,7 @@
#include <QPointer>
using namespace Analyzer;
using namespace ProjectExplorer;
namespace Valgrind {
namespace Internal {
......@@ -101,6 +108,24 @@ ValgrindPlugin::~ValgrindPlugin()
theGlobalSettings = 0;
}
static void customStart(ProjectExplorer::RunMode runMode)
{
StartRemoteDialog dlg;
if (dlg.exec() != QDialog::Accepted)
return;
AnalyzerStartParameters sp;
sp.useStartupProject = false;
sp.connParams = dlg.sshParams();
sp.debuggee = dlg.executable();
sp.debuggeeArgs = dlg.arguments();
sp.displayName = dlg.executable();
sp.workingDirectory = dlg.workingDirectory();
AnalyzerRunControl *rc = AnalyzerManager::createRunControl(sp, 0);
ProjectExplorerPlugin::startRunControl(rc, runMode);
}
bool ValgrindPlugin::initialize(const QStringList &, QString *)
{
theGlobalSettings = new ValgrindGlobalSettings();
......@@ -151,11 +176,11 @@ bool ValgrindPlugin::initialize(const QStringList &, QString *)
action->setToolId("Memcheck");
action->setWidgetCreator(mcWidgetCreator);
action->setRunControlCreator(mcRunControlCreator);
action->setToolStarter([mcTool] { mcTool->startLocalTool(); });
action->setToolMode(DebugMode);
action->setRunMode(ProjectExplorer::MemcheckRunMode);
action->setText(tr("Valgrind Memory Analyzer"));
action->setToolTip(memcheckToolTip);
action->setMenuGroup(Constants::G_ANALYZER_TOOLS);
action->setMenuGroup(Analyzer::Constants::G_ANALYZER_TOOLS);
action->setEnabled(false);
AnalyzerManager::addAction(action);
......@@ -164,11 +189,11 @@ bool ValgrindPlugin::initialize(const QStringList &, QString *)
action->setToolId("MemcheckWithGdb");
action->setWidgetCreator(mcgWidgetCreator);
action->setRunControlCreator(mcgRunControlCreator);
action->setToolStarter([mcgTool] { mcgTool->startLocalTool(); });
action->setToolMode(DebugMode);
action->setRunMode(ProjectExplorer::MemcheckWithGdbRunMode);
action->setText(tr("Valgrind Memory Analyzer with GDB"));
action->setToolTip(memcheckWithGdbToolTip);
action->setMenuGroup(Constants::G_ANALYZER_TOOLS);
action->setMenuGroup(Analyzer::Constants::G_ANALYZER_TOOLS);
action->setEnabled(false);
AnalyzerManager::addAction(action);
......@@ -177,11 +202,11 @@ bool ValgrindPlugin::initialize(const QStringList &, QString *)
action->setToolId(CallgrindToolId);
action->setWidgetCreator(cgWidgetCreator);
action->setRunControlCreator(cgRunControlCreator);
action->setToolStarter([cgTool] { cgTool->startLocalTool(); });
action->setRunMode(ProjectExplorer::CallgrindRunMode);
action->setToolMode(ReleaseMode);
action->setRunMode(CallgrindRunMode);
action->setText(tr("Valgrind Function Profiler"));
action->setToolTip(callgrindToolTip);
action->setMenuGroup(Constants::G_ANALYZER_TOOLS);
action->setMenuGroup(Analyzer::Constants::G_ANALYZER_TOOLS);
action->setEnabled(false);
AnalyzerManager::addAction(action);
}
......@@ -191,11 +216,11 @@ bool ValgrindPlugin::initialize(const QStringList &, QString *)
action->setToolId("Memcheck");
action->setWidgetCreator(mcWidgetCreator);
action->setRunControlCreator(mcRunControlCreator);
action->setToolStarter([mcTool] { mcTool->startRemoteTool(); });
action->setRunMode(ProjectExplorer::MemcheckRunMode);
action->setToolStarter([] { customStart(MemcheckRunMode); });
action->setRunMode(MemcheckRunMode);
action->setText(tr("Valgrind Memory Analyzer (External Remote Application)"));
action->setToolTip(memcheckToolTip);
action->setMenuGroup(Constants::G_ANALYZER_REMOTE_TOOLS);
action->setMenuGroup(Analyzer::Constants::G_ANALYZER_REMOTE_TOOLS);
action->setUseSpecialStart();
AnalyzerManager::addAction(action);
......@@ -204,11 +229,11 @@ bool ValgrindPlugin::initialize(const QStringList &, QString *)
action->setToolId(CallgrindToolId);
action->setWidgetCreator(cgWidgetCreator);
action->setRunControlCreator(cgRunControlCreator);
action->setToolStarter([cgTool] { cgTool->startRemoteTool(); });
action->setRunMode(ProjectExplorer::CallgrindRunMode);
action->setToolStarter([] { customStart(CallgrindRunMode); });
action->setRunMode(CallgrindRunMode);
action->setText(tr("Valgrind Function Profiler (External Remote Application)"));
action->setToolTip(callgrindToolTip);
action->setMenuGroup(Constants::G_ANALYZER_REMOTE_TOOLS);
action->setMenuGroup(Analyzer::Constants::G_ANALYZER_REMOTE_TOOLS);
action->setUseSpecialStart();
AnalyzerManager::addAction(action);
......@@ -246,4 +271,3 @@ void ValgrindPlugin::extensionsInitialized()
} // namespace Internal
} // namespace Valgrind
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