Analyzer: Add prepare step to tool starting.

The toolPreparer can do a last minute check and stop the execution of
the actual tool. The QML profiler uses this to check for unsaved notes.

Change-Id: I5185430f50ffb01e9854cafa442f0eaaad27fa5d
Reviewed-by: hjk <hjk@theqtcompany.com>
This commit is contained in:
Ulf Hermann
2015-06-18 16:26:58 +02:00
committed by hjk
parent 23880f77de
commit bb6e697006
5 changed files with 19 additions and 18 deletions

View File

@@ -97,6 +97,9 @@ void AnalyzerAction::startTool()
TaskHub::clearTasks(Constants::ANALYZERTASK_ID); TaskHub::clearTasks(Constants::ANALYZERTASK_ID);
if (m_toolPreparer && !m_toolPreparer())
return;
// Custom start. // Custom start.
if (m_toolStarter) { if (m_toolStarter) {
m_toolStarter(); m_toolStarter();

View File

@@ -110,6 +110,10 @@ public:
void startTool(); void startTool();
void setToolStarter(const ToolStarter &toolStarter) { m_toolStarter = toolStarter; } void setToolStarter(const ToolStarter &toolStarter) { m_toolStarter = toolStarter; }
typedef std::function<bool()> ToolPreparer;
ToolPreparer toolPreparer() const { return m_toolPreparer; }
void setToolPreparer(const ToolPreparer &toolPreparer) { m_toolPreparer = toolPreparer; }
protected: protected:
bool m_useStartupProject; bool m_useStartupProject;
Core::Id m_menuGroup; Core::Id m_menuGroup;
@@ -120,6 +124,7 @@ protected:
WidgetCreator m_widgetCreator; WidgetCreator m_widgetCreator;
RunControlCreator m_runControlCreator; RunControlCreator m_runControlCreator;
ToolStarter m_toolStarter; ToolStarter m_toolStarter;
ToolPreparer m_toolPreparer;
}; };
} // namespace Analyzer } // namespace Analyzer

View File

@@ -70,7 +70,7 @@ 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->startLocalTool(); }); action->setToolPreparer([tool] { return tool->prepareTool(); });
action->setRunMode(ProjectExplorer::QmlProfilerRunMode); action->setRunMode(ProjectExplorer::QmlProfilerRunMode);
action->setText(tr("QML Profiler")); action->setText(tr("QML Profiler"));
action->setToolTip(description); action->setToolTip(description);
@@ -83,6 +83,7 @@ bool QmlProfilerPlugin::initialize(const QStringList &arguments, QString *errorS
action->setWidgetCreator(widgetCreator); action->setWidgetCreator(widgetCreator);
action->setRunControlCreator(runControlCreator); action->setRunControlCreator(runControlCreator);
action->setToolStarter([tool] { tool->startRemoteTool(); }); action->setToolStarter([tool] { tool->startRemoteTool(); });
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);

View File

@@ -433,29 +433,21 @@ void QmlProfilerTool::clearDisplay()
updateTimeDisplay(); updateTimeDisplay();
} }
void QmlProfilerTool::startLocalTool() bool QmlProfilerTool::prepareTool()
{ {
if (d->m_recordButton->isChecked()) { if (d->m_recordButton->isChecked()) {
if (!checkForUnsavedNotes()) if (checkForUnsavedNotes()) {
return;
clearData(); // clear right away to suppress second warning on server recording change clearData(); // clear right away to suppress second warning on server recording change
return true;
} else {
return false;
} }
}
// Make sure mode is shown. return true;
AnalyzerManager::showMode();
// ### not sure if we're supposed to check if the RunConFiguration isEnabled
ProjectExplorerPlugin::runStartupProject(QmlProfilerRunMode);
} }
void QmlProfilerTool::startRemoteTool() void QmlProfilerTool::startRemoteTool()
{ {
if (d->m_recordButton->isChecked()) {
if (!checkForUnsavedNotes())
return;
clearData(); // clear right away to suppress second warning on server recording change
}
AnalyzerManager::showMode(); AnalyzerManager::showMode();
Id kitId; Id kitId;

View File

@@ -58,7 +58,7 @@ public:
ProjectExplorer::RunConfiguration *runConfiguration = 0); ProjectExplorer::RunConfiguration *runConfiguration = 0);
QWidget *createWidgets(); QWidget *createWidgets();
void startLocalTool(); bool prepareTool();
void startRemoteTool(); void startRemoteTool();
QList <QAction *> profilerContextMenuActions() const; QList <QAction *> profilerContextMenuActions() const;