From 9494303bdf654e2b5370b984d0de8e730badd756 Mon Sep 17 00:00:00 2001 From: hjk Date: Thu, 18 Jun 2015 09:35:41 +0200 Subject: [PATCH] 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: Ulf Hermann --- src/plugins/analyzerbase/analyzermanager.cpp | 3 +- src/plugins/analyzerbase/ianalyzertool.cpp | 40 ++++++--------- src/plugins/analyzerbase/ianalyzertool.h | 8 ++- src/plugins/valgrind/callgrindtool.cpp | 18 ------- src/plugins/valgrind/callgrindtool.h | 3 -- src/plugins/valgrind/memchecktool.cpp | 30 ----------- src/plugins/valgrind/memchecktool.h | 4 -- src/plugins/valgrind/valgrindplugin.cpp | 52 ++++++++++++++------ 8 files changed, 58 insertions(+), 100 deletions(-) diff --git a/src/plugins/analyzerbase/analyzermanager.cpp b/src/plugins/analyzerbase/analyzermanager.cpp index 81e81d15c07..6255e183ee4 100644 --- a/src/plugins/analyzerbase/analyzermanager.cpp +++ b/src/plugins/analyzerbase/analyzermanager.cpp @@ -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) diff --git a/src/plugins/analyzerbase/ianalyzertool.cpp b/src/plugins/analyzerbase/ianalyzertool.cpp index 468455a30df..eda784f5250 100644 --- a/src/plugins/analyzerbase/ianalyzertool.cpp +++ b/src/plugins/analyzerbase/ianalyzertool.cpp @@ -33,7 +33,6 @@ #include "analyzermanager.h" #include "analyzerruncontrol.h" -#include "startremotedialog.h" #include #include @@ -44,6 +43,7 @@ #include #include #include +#include #include #include @@ -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 diff --git a/src/plugins/analyzerbase/ianalyzertool.h b/src/plugins/analyzerbase/ianalyzertool.h index 5a6e3631dc0..d998e782b41 100644 --- a/src/plugins/analyzerbase/ianalyzertool.h +++ b/src/plugins/analyzerbase/ianalyzertool.h @@ -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 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; diff --git a/src/plugins/valgrind/callgrindtool.cpp b/src/plugins/valgrind/callgrindtool.cpp index dcd2a1396b2..0aefec59b87 100644 --- a/src/plugins/valgrind/callgrindtool.cpp +++ b/src/plugins/valgrind/callgrindtool.cpp @@ -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(); diff --git a/src/plugins/valgrind/callgrindtool.h b/src/plugins/valgrind/callgrindtool.h index 0a72cd363ad..930eff7e324 100644 --- a/src/plugins/valgrind/callgrindtool.h +++ b/src/plugins/valgrind/callgrindtool.h @@ -54,9 +54,6 @@ public: ProjectExplorer::RunConfiguration *runConfiguration = 0); QWidget *createWidgets(); - void startLocalTool(); - void startRemoteTool(); - public slots: void handleShowCostsOfFunction(); diff --git a/src/plugins/valgrind/memchecktool.cpp b/src/plugins/valgrind/memchecktool.cpp index b5ec4840334..b409a0d170b 100644 --- a/src/plugins/valgrind/memchecktool.cpp +++ b/src/plugins/valgrind/memchecktool.cpp @@ -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) { diff --git a/src/plugins/valgrind/memchecktool.h b/src/plugins/valgrind/memchecktool.h index ceaaf0c2d94..40e4ecea09a 100644 --- a/src/plugins/valgrind/memchecktool.h +++ b/src/plugins/valgrind/memchecktool.h @@ -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; diff --git a/src/plugins/valgrind/valgrindplugin.cpp b/src/plugins/valgrind/valgrindplugin.cpp index e21a5dc17a7..2ec6623f186 100644 --- a/src/plugins/valgrind/valgrindplugin.cpp +++ b/src/plugins/valgrind/valgrindplugin.cpp @@ -38,6 +38,9 @@ #include "valgrindconfigwidget.h" #include +#include +#include +#include #include #include @@ -49,6 +52,9 @@ #include +#include +#include + #include #include @@ -56,6 +62,7 @@ #include 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 -