Analyzer: Merge AnalyzerAction::useStartupProject and ::toolStarter

Also rename ToolStarter to CustomToolStarter to make clearer
that this is not the normal startupProject based setup.

Change-Id: I6c538eed9280e0c02912954541423f030e88585f
Reviewed-by: Ulf Hermann <ulf.hermann@theqtcompany.com>
This commit is contained in:
hjk
2015-06-18 16:50:42 +02:00
parent e778604803
commit 2c5b4b9be3
4 changed files with 21 additions and 19 deletions

View File

@@ -59,12 +59,12 @@ using namespace ProjectExplorer;
namespace Analyzer { namespace Analyzer {
AnalyzerAction::AnalyzerAction(QObject *parent) AnalyzerAction::AnalyzerAction(QObject *parent)
: QAction(parent), m_useStartupProject(true), m_toolMode(AnyMode) : QAction(parent), m_toolMode(AnyMode)
{} {}
bool AnalyzerAction::isRunnable(QString *reason) const bool AnalyzerAction::isRunnable(QString *reason) const
{ {
if (m_toolStarter) // Something special. Pretend we can always run it. if (m_customToolStarter) // Something special. Pretend we can always run it.
return true; return true;
return ProjectExplorerPlugin::canRun(SessionManager::startupProject(), m_runMode, reason); return ProjectExplorerPlugin::canRun(SessionManager::startupProject(), m_runMode, reason);
@@ -72,7 +72,8 @@ bool AnalyzerAction::isRunnable(QString *reason) const
AnalyzerRunControl *AnalyzerAction::tryCreateRunControl(const AnalyzerStartParameters &sp, RunConfiguration *runConfiguration) const AnalyzerRunControl *AnalyzerAction::tryCreateRunControl(const AnalyzerStartParameters &sp, RunConfiguration *runConfiguration) const
{ {
if (m_runMode == sp.runMode && m_useStartupProject == sp.useStartupProject) const bool useStartupProject = !m_customToolStarter;
if (m_runMode == sp.runMode && useStartupProject == sp.useStartupProject)
return m_runControlCreator(sp, runConfiguration); return m_runControlCreator(sp, runConfiguration);
return 0; return 0;
} }
@@ -101,8 +102,8 @@ void AnalyzerAction::startTool()
return; return;
// Custom start. // Custom start.
if (m_toolStarter) { if (m_customToolStarter) {
m_toolStarter(); m_customToolStarter();
return; return;
} }
@@ -155,4 +156,9 @@ void AnalyzerAction::startTool()
ProjectExplorerPlugin::runStartupProject(m_runMode); ProjectExplorerPlugin::runStartupProject(m_runMode);
} }
void AnalyzerAction::setCustomToolStarter(const AnalyzerAction::ToolStarter &toolStarter)
{
m_customToolStarter = toolStarter;
}
} // namespace Analyzer } // namespace Analyzer

View File

@@ -76,8 +76,6 @@ public:
explicit AnalyzerAction(QObject *parent = 0); explicit AnalyzerAction(QObject *parent = 0);
public: public:
void setUseSpecialStart() { m_useStartupProject = false; }
Core::Id menuGroup() const { return m_menuGroup; } Core::Id menuGroup() const { return m_menuGroup; }
void setMenuGroup(Core::Id menuGroup) { m_menuGroup = menuGroup; } void setMenuGroup(Core::Id menuGroup) { m_menuGroup = menuGroup; }
@@ -106,16 +104,17 @@ public:
ProjectExplorer::RunConfiguration *runConfiguration) const; ProjectExplorer::RunConfiguration *runConfiguration) const;
void setRunControlCreator(const RunControlCreator &creator) { m_runControlCreator = creator; } void setRunControlCreator(const RunControlCreator &creator) { m_runControlCreator = creator; }
typedef std::function<void()> ToolStarter;
void startTool();
void setToolStarter(const ToolStarter &toolStarter) { m_toolStarter = toolStarter; }
typedef std::function<bool()> ToolPreparer; typedef std::function<bool()> ToolPreparer;
ToolPreparer toolPreparer() const { return m_toolPreparer; } ToolPreparer toolPreparer() const { return m_toolPreparer; }
void setToolPreparer(const ToolPreparer &toolPreparer) { m_toolPreparer = toolPreparer; } void setToolPreparer(const ToolPreparer &toolPreparer) { m_toolPreparer = toolPreparer; }
void startTool();
/// This is only used for setups not using the startup project.
typedef std::function<void()> ToolStarter;
void setCustomToolStarter(const ToolStarter &toolStarter);
protected: protected:
bool m_useStartupProject;
Core::Id m_menuGroup; Core::Id m_menuGroup;
Core::Id m_actionId; Core::Id m_actionId;
Core::Id m_toolId; Core::Id m_toolId;
@@ -123,7 +122,7 @@ protected:
ProjectExplorer::RunMode m_runMode; ProjectExplorer::RunMode m_runMode;
WidgetCreator m_widgetCreator; WidgetCreator m_widgetCreator;
RunControlCreator m_runControlCreator; RunControlCreator m_runControlCreator;
ToolStarter m_toolStarter; ToolStarter m_customToolStarter;
ToolPreparer m_toolPreparer; ToolPreparer m_toolPreparer;
}; };

View File

@@ -82,12 +82,11 @@ bool QmlProfilerPlugin::initialize(const QStringList &arguments, QString *errorS
action->setToolId(QmlProfilerToolId); action->setToolId(QmlProfilerToolId);
action->setWidgetCreator(widgetCreator); action->setWidgetCreator(widgetCreator);
action->setRunControlCreator(runControlCreator); action->setRunControlCreator(runControlCreator);
action->setToolStarter([tool] { tool->startRemoteTool(); }); action->setCustomToolStarter([tool] { tool->startRemoteTool(); });
action->setToolPreparer([tool] { return tool->prepareTool(); }); action->setToolPreparer([tool] { return tool->prepareTool(); });
action->setRunMode(ProjectExplorer::QmlProfilerRunMode); action->setRunMode(ProjectExplorer::QmlProfilerRunMode);
action->setText(tr("QML Profiler (External)")); action->setText(tr("QML Profiler (External)"));
action->setToolTip(description); action->setToolTip(description);
action->setUseSpecialStart();
action->setMenuGroup(Constants::G_ANALYZER_REMOTE_TOOLS); action->setMenuGroup(Constants::G_ANALYZER_REMOTE_TOOLS);
AnalyzerManager::addAction(action); AnalyzerManager::addAction(action);

View File

@@ -213,12 +213,11 @@ void ValgrindPlugin::extensionsInitialized()
action->setToolId("Memcheck"); action->setToolId("Memcheck");
action->setWidgetCreator(mcWidgetCreator); action->setWidgetCreator(mcWidgetCreator);
action->setRunControlCreator(mcRunControlCreator); action->setRunControlCreator(mcRunControlCreator);
action->setToolStarter([] { customStart(MemcheckRunMode); }); action->setCustomToolStarter([] { customStart(MemcheckRunMode); });
action->setRunMode(MemcheckRunMode); action->setRunMode(MemcheckRunMode);
action->setText(tr("Valgrind Memory Analyzer (External Remote Application)")); action->setText(tr("Valgrind Memory Analyzer (External Remote Application)"));
action->setToolTip(memcheckToolTip); action->setToolTip(memcheckToolTip);
action->setMenuGroup(Analyzer::Constants::G_ANALYZER_REMOTE_TOOLS); action->setMenuGroup(Analyzer::Constants::G_ANALYZER_REMOTE_TOOLS);
action->setUseSpecialStart();
AnalyzerManager::addAction(action); AnalyzerManager::addAction(action);
action = new AnalyzerAction(this); action = new AnalyzerAction(this);
@@ -226,12 +225,11 @@ void ValgrindPlugin::extensionsInitialized()
action->setToolId(CallgrindToolId); action->setToolId(CallgrindToolId);
action->setWidgetCreator(cgWidgetCreator); action->setWidgetCreator(cgWidgetCreator);
action->setRunControlCreator(cgRunControlCreator); action->setRunControlCreator(cgRunControlCreator);
action->setToolStarter([] { customStart(CallgrindRunMode); }); action->setCustomToolStarter([] { customStart(CallgrindRunMode); });
action->setRunMode(CallgrindRunMode); action->setRunMode(CallgrindRunMode);
action->setText(tr("Valgrind Function Profiler (External Remote Application)")); action->setText(tr("Valgrind Function Profiler (External Remote Application)"));
action->setToolTip(callgrindToolTip); action->setToolTip(callgrindToolTip);
action->setMenuGroup(Analyzer::Constants::G_ANALYZER_REMOTE_TOOLS); action->setMenuGroup(Analyzer::Constants::G_ANALYZER_REMOTE_TOOLS);
action->setUseSpecialStart();
AnalyzerManager::addAction(action); AnalyzerManager::addAction(action);
// If there is a CppEditor context menu add our own context menu actions. // If there is a CppEditor context menu add our own context menu actions.