diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/clangstaticanalyzer/clangstaticanalyzertool.cpp | 29 | ||||
-rw-r--r-- | src/plugins/clangstaticanalyzer/clangstaticanalyzertool.h | 1 | ||||
-rw-r--r-- | src/plugins/debugger/analyzer/analyzerconstants.h | 1 | ||||
-rw-r--r-- | src/plugins/debugger/analyzer/analyzermanager.h | 72 | ||||
-rw-r--r-- | src/plugins/debugger/debuggerplugin.cpp | 123 | ||||
-rw-r--r-- | src/plugins/qmlprofiler/qmlprofilerconstants.h | 2 | ||||
-rw-r--r-- | src/plugins/qmlprofiler/qmlprofilertool.cpp | 52 | ||||
-rw-r--r-- | src/plugins/qmlprofiler/qmlprofilertool.h | 2 | ||||
-rw-r--r-- | src/plugins/valgrind/callgrindtool.cpp | 51 | ||||
-rw-r--r-- | src/plugins/valgrind/memchecktool.cpp | 77 |
10 files changed, 194 insertions, 216 deletions
diff --git a/src/plugins/clangstaticanalyzer/clangstaticanalyzertool.cpp b/src/plugins/clangstaticanalyzer/clangstaticanalyzertool.cpp index ece15ae32b..b013ec97b0 100644 --- a/src/plugins/clangstaticanalyzer/clangstaticanalyzertool.cpp +++ b/src/plugins/clangstaticanalyzer/clangstaticanalyzertool.cpp @@ -31,10 +31,15 @@ #include "clangstaticanalyzerdiagnosticview.h" #include "clangstaticanalyzerruncontrol.h" -#include <debugger/analyzer/analyzermanager.h> +#include <coreplugin/actionmanager/actioncontainer.h> +#include <coreplugin/actionmanager/actionmanager.h> #include <coreplugin/coreconstants.h> #include <coreplugin/icore.h> + #include <cpptools/cppmodelmanager.h> + +#include <debugger/analyzer/analyzermanager.h> + #include <projectexplorer/buildconfiguration.h> #include <projectexplorer/projectexplorer.h> #include <projectexplorer/session.h> @@ -52,6 +57,7 @@ #include <QSortFilterProxyModel> #include <QToolButton> +using namespace Core; using namespace Debugger; using namespace ProjectExplorer; using namespace Utils; @@ -134,6 +140,7 @@ ClangStaticAnalyzerTool::ClangStaticAnalyzerTool(QObject *parent) connect(action, &QAction::triggered, m_diagnosticView, &DetailedErrorView::goNext); m_goNext = action; + ActionContainer *menu = ActionManager::actionContainer(Debugger::Constants::M_DEBUG_ANALYZER); const QString toolTip = tr("Clang Static Analyzer uses the analyzer from the Clang project " "to find bugs."); @@ -142,17 +149,16 @@ ClangStaticAnalyzerTool::ClangStaticAnalyzerTool(QObject *parent) {{ClangStaticAnalyzerDockId, m_diagnosticView, {}, Perspective::SplitVertical}} )); - ActionDescription desc; - desc.setText(tr("Clang Static Analyzer")); - desc.setToolTip(toolTip); - desc.setRunMode(Constants::CLANGSTATICANALYZER_RUN_MODE); - desc.setPerspectiveId(ClangStaticAnalyzerPerspectiveId); - desc.setCustomToolStarter([this](RunConfiguration *runConfiguration) { - Q_UNUSED(runConfiguration); - startTool(); + Debugger::registerAction(Constants::CLANGSTATICANALYZER_RUN_MODE, {}); + action = new QAction(tr("Clang Static Analyzer"), this); + action->setToolTip(toolTip); + menu->addAction(ActionManager::registerAction(action, "ClangStaticAnalyzer.Action"), + Debugger::Constants::G_ANALYZER_TOOLS); + QObject::connect(action, &QAction::triggered, this, &ClangStaticAnalyzerTool::startTool); + QObject::connect(m_startAction, &QAction::triggered, action, &QAction::triggered); + QObject::connect(m_startAction, &QAction::changed, action, [action, this] { + action->setEnabled(m_startAction->isEnabled()); }); - desc.setMenuGroup(Debugger::Constants::G_ANALYZER_TOOLS); - Debugger::registerAction(ClangStaticAnalyzerActionId, desc, m_startAction); ToolbarDescription toolbar; toolbar.addAction(m_startAction); @@ -240,6 +246,7 @@ void ClangStaticAnalyzerTool::startTool() if (dontStartAfterHintForDebugMode(project)) return; + Debugger::selectPerspective(ClangStaticAnalyzerPerspectiveId); m_diagnosticModel->clear(); setBusyCursor(true); m_diagnosticFilterModel->setProject(project); diff --git a/src/plugins/clangstaticanalyzer/clangstaticanalyzertool.h b/src/plugins/clangstaticanalyzer/clangstaticanalyzertool.h index f3cb2f4bd1..2d92bac2cc 100644 --- a/src/plugins/clangstaticanalyzer/clangstaticanalyzertool.h +++ b/src/plugins/clangstaticanalyzer/clangstaticanalyzertool.h @@ -40,7 +40,6 @@ class Diagnostic; class DummyRunConfiguration; const char ClangStaticAnalyzerPerspectiveId[] = "ClangStaticAnalyzer.Perspective"; -const char ClangStaticAnalyzerActionId[] = "ClangStaticAnalyzer.Action"; const char ClangStaticAnalyzerDockId[] = "ClangStaticAnalyzer.Dock"; class ClangStaticAnalyzerTool : public QObject diff --git a/src/plugins/debugger/analyzer/analyzerconstants.h b/src/plugins/debugger/analyzer/analyzerconstants.h index 4260d718c8..b88d2c164b 100644 --- a/src/plugins/debugger/analyzer/analyzerconstants.h +++ b/src/plugins/debugger/analyzer/analyzerconstants.h @@ -33,7 +33,6 @@ namespace Constants { // Menu. const char M_DEBUG_ANALYZER[] = "Analyzer.Menu.StartAnalyzer"; -const char M_DEBUG_ANALYZER_QML_OPTIONS[] = "Analyzer.Menu.QMLOptions"; const char G_ANALYZER_CONTROL[] = "Menu.Group.Analyzer.Control"; const char G_ANALYZER_TOOLS[] = "Menu.Group.Analyzer.Tools"; diff --git a/src/plugins/debugger/analyzer/analyzermanager.h b/src/plugins/debugger/analyzer/analyzermanager.h index 92d1911af9..3558a79646 100644 --- a/src/plugins/debugger/analyzer/analyzermanager.h +++ b/src/plugins/debugger/analyzer/analyzermanager.h @@ -32,6 +32,7 @@ #include <coreplugin/id.h> +#include <projectexplorer/buildconfiguration.h> #include <projectexplorer/projectexplorerconstants.h> #include <projectexplorer/runconfiguration.h> @@ -39,11 +40,6 @@ #include <functional> -QT_BEGIN_NAMESPACE -class QDockWidget; -class QAction; -QT_END_NAMESPACE - namespace Debugger { /** @@ -60,71 +56,19 @@ enum ToolMode { ReleaseMode = 0x4, SymbolsMode = DebugMode | ProfileMode, OptimizedMode = ProfileMode | ReleaseMode, - AnyMode = DebugMode | ProfileMode | ReleaseMode + //AnyMode = DebugMode | ProfileMode | ReleaseMode }; -Q_DECLARE_FLAGS(ToolModes, ToolMode) -/** - * This class represents an analyzation action, i.e. a tool that runs in a specific mode. - * -*/ - -class DEBUGGER_EXPORT ActionDescription -{ - Q_DECLARE_TR_FUNCTIONS(Debugger::AnalyzerAction) - -public: - ActionDescription() {} - - Core::Id menuGroup() const { return m_menuGroup; } - void setMenuGroup(Core::Id menuGroup) { m_menuGroup = menuGroup; } - - QByteArray perspectiveId() const { return m_perspectiveId; } - void setPerspectiveId(const QByteArray &id) { m_perspectiveId = id; } - void setToolMode(QFlags<ToolMode> mode) { m_toolMode = mode; } - - Core::Id runMode() const { return m_runMode; } - void setRunMode(Core::Id mode) { m_runMode = mode; } - - /// Returns a new engine for the given start parameters. - /// Called each time the tool is launched. - typedef std::function<ProjectExplorer::RunControl *(ProjectExplorer::RunConfiguration *runConfiguration, - Core::Id runMode)> RunControlCreator; - RunControlCreator runControlCreator() const { return m_runControlCreator; } - void setRunControlCreator(const RunControlCreator &creator) { m_runControlCreator = creator; } - - typedef std::function<bool()> ToolPreparer; - ToolPreparer toolPreparer() const { return m_toolPreparer; } - void setToolPreparer(const ToolPreparer &toolPreparer) { m_toolPreparer = toolPreparer; } - - void startTool() const; - - /// This is only used for setups not using the startup project. - typedef std::function<void(ProjectExplorer::RunConfiguration *runConfiguration)> ToolStarter; - void setCustomToolStarter(const ToolStarter &toolStarter) { m_customToolStarter = toolStarter; } - - QString toolTip() const { return m_toolTip; } - void setToolTip(const QString &toolTip) { m_toolTip = toolTip; } - - QString text() const { return m_text; } - void setText(const QString &text) { m_text = text; } - -private: - QString m_text; - QString m_toolTip; - Core::Id m_menuGroup; - QByteArray m_perspectiveId; - QFlags<ToolMode> m_toolMode = AnyMode; - Core::Id m_runMode; - RunControlCreator m_runControlCreator; - ToolStarter m_customToolStarter; - ToolPreparer m_toolPreparer; -}; +using RunControlCreator = std::function<ProjectExplorer::RunControl * + (ProjectExplorer::RunConfiguration *runConfiguration, Core::Id runMode)>; // FIXME: Merge with something sensible. +DEBUGGER_EXPORT bool wantRunTool(ToolMode toolMode, const QString &toolName); +DEBUGGER_EXPORT void showCannotStartDialog(const QString &toolName); +DEBUGGER_EXPORT ProjectExplorer::RunConfiguration *startupRunConfiguration(); // Register a tool for a given start mode. -DEBUGGER_EXPORT void registerAction(Core::Id actionId, const ActionDescription &desc, QAction *startAction = 0); +DEBUGGER_EXPORT void registerAction(Core::Id runMode, const RunControlCreator &runControlCreator); DEBUGGER_EXPORT void registerPerspective(const QByteArray &perspectiveId, const Utils::Perspective *perspective); DEBUGGER_EXPORT void registerToolbar(const QByteArray &perspectiveId, const Utils::ToolbarDescription &desc); diff --git a/src/plugins/debugger/debuggerplugin.cpp b/src/plugins/debugger/debuggerplugin.cpp index 599ba02bf5..776835e05d 100644 --- a/src/plugins/debugger/debuggerplugin.cpp +++ b/src/plugins/debugger/debuggerplugin.cpp @@ -973,7 +973,7 @@ public: QPointer<QWidget> m_modeWindow; QPointer<DebugMode> m_mode; - QHash<Id, ActionDescription> m_descriptions; + QHash<Id, RunControlCreator> m_runControlCreators; ActionContainer *m_menu = 0; // DockWidgetEventFilter m_resizeEventFilter; @@ -3430,85 +3430,80 @@ static bool buildTypeAccepted(QFlags<ToolMode> toolMode, BuildConfiguration::Bui return false; } -void ActionDescription::startTool() const +RunConfiguration *startupRunConfiguration() { - TaskHub::clearTasks(Constants::ANALYZERTASK_ID); - Debugger::selectPerspective(m_perspectiveId); - - if (m_toolPreparer && !m_toolPreparer()) - return; + if (Project *pro = SessionManager::startupProject()) { + if (const Target *target = pro->activeTarget()) + return target->activeRunConfiguration(); + } + return nullptr; +} - // ### not sure if we're supposed to check if the RunConFiguration isEnabled - Project *pro = SessionManager::startupProject(); - RunConfiguration *rc = 0; +static BuildConfiguration::BuildType startupBuildType() +{ BuildConfiguration::BuildType buildType = BuildConfiguration::Unknown; - if (pro) { - if (const Target *target = pro->activeTarget()) { - // Build configuration is 0 for QML projects. - if (const BuildConfiguration *buildConfig = target->activeBuildConfiguration()) - buildType = buildConfig->buildType(); - rc = target->activeRunConfiguration(); - } + if (RunConfiguration *runConfig = startupRunConfiguration()) { + if (const BuildConfiguration *buildConfig = runConfig->target()->activeBuildConfiguration()) + buildType = buildConfig->buildType(); } + return buildType; +} - // Custom start. - if (m_customToolStarter) { - if (rc) { - m_customToolStarter(rc); - } else { - QMessageBox *errorDialog = new QMessageBox(ICore::mainWindow()); - errorDialog->setIcon(QMessageBox::Warning); - errorDialog->setWindowTitle(m_text); - errorDialog->setText(tr("Cannot start %1 without a project. Please open the project " - "and try again.").arg(m_text)); - errorDialog->setStandardButtons(QMessageBox::Ok); - errorDialog->setDefaultButton(QMessageBox::Ok); - errorDialog->show(); - } - return; - } +void showCannotStartDialog(const QString &text) +{ + QMessageBox *errorDialog = new QMessageBox(ICore::mainWindow()); + errorDialog->setIcon(QMessageBox::Warning); + errorDialog->setWindowTitle(text); + errorDialog->setText(DebuggerPlugin::tr("Cannot start %1 without a project. Please open the project " + "and try again.").arg(text)); + errorDialog->setStandardButtons(QMessageBox::Ok); + errorDialog->setDefaultButton(QMessageBox::Ok); + errorDialog->show(); +} +bool wantRunTool(ToolMode toolMode, const QString &toolName) +{ // 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(m_toolMode, buildType)) { + BuildConfiguration::BuildType buildType = startupBuildType(); + if (!buildTypeAccepted(toolMode, buildType)) { QString currentMode; switch (buildType) { case BuildConfiguration::Debug: - currentMode = tr("Debug"); + currentMode = DebuggerPlugin::tr("Debug"); break; case BuildConfiguration::Profile: - currentMode = tr("Profile"); + currentMode = DebuggerPlugin::tr("Profile"); break; case BuildConfiguration::Release: - currentMode = tr("Release"); + currentMode = DebuggerPlugin::tr("Release"); break; default: QTC_CHECK(false); } QString toolModeString; - switch (m_toolMode) { + switch (toolMode) { case DebugMode: - toolModeString = tr("in Debug mode"); + toolModeString = DebuggerPlugin::tr("in Debug mode"); break; case ProfileMode: - toolModeString = tr("in Profile mode"); + toolModeString = DebuggerPlugin::tr("in Profile mode"); break; case ReleaseMode: - toolModeString = tr("in Release mode"); + toolModeString = DebuggerPlugin::tr("in Release mode"); break; case SymbolsMode: - toolModeString = tr("with debug symbols (Debug or Profile mode)"); + toolModeString = DebuggerPlugin::tr("with debug symbols (Debug or Profile mode)"); break; case OptimizedMode: - toolModeString = tr("on optimized code (Profile or Release mode)"); + toolModeString = DebuggerPlugin::tr("on optimized code (Profile or Release mode)"); break; default: QTC_CHECK(false); } - const QString toolName = m_text; // The action text is always the name of the tool - const QString title = tr("Run %1 in %2 Mode?").arg(toolName).arg(currentMode); - const QString message = tr("<html><head/><body><p>You are trying " + const QString title = DebuggerPlugin::tr("Run %1 in %2 Mode?").arg(toolName).arg(currentMode); + const QString message = DebuggerPlugin::tr("<html><head/><body><p>You are trying " "to run the tool \"%1\" on an application in %2 mode. " "The tool is designed to be used %3.</p><p>" "Run-time characteristics differ significantly between " @@ -3523,34 +3518,15 @@ void ActionDescription::startTool() const if (Utils::CheckableMessageBox::doNotAskAgainQuestion(ICore::mainWindow(), title, message, ICore::settings(), QLatin1String("AnalyzerCorrectModeWarning")) != QDialogButtonBox::Yes) - return; + return false; } - ProjectExplorerPlugin::runStartupProject(m_runMode); + return true; } -void registerAction(Id actionId, const ActionDescription &desc, QAction *startAction) +void registerAction(Id runMode, const RunControlCreator &runControlCreator) { - auto action = new QAction(dd); - action->setText(desc.text()); - action->setToolTip(desc.toolTip()); - dd->m_descriptions.insert(actionId, desc); - - Id menuGroup = desc.menuGroup(); - if (menuGroup.isValid()) { - Command *command = ActionManager::registerAction(action, actionId); - dd->m_menu->addAction(command, menuGroup); - } - - QObject::connect(action, &QAction::triggered, dd, [desc] { desc.startTool(); }); - - if (startAction) { - QObject::connect(startAction, &QAction::triggered, action, &QAction::triggered); - - QObject::connect(startAction, &QAction::changed, action, [action, startAction] { - action->setEnabled(startAction->isEnabled()); - }); - } + dd->m_runControlCreators.insert(runMode, runControlCreator); } void registerToolbar(const QByteArray &perspectiveId, const ToolbarDescription &desc) @@ -3628,11 +3604,10 @@ void showPermanentStatusMessage(const QString &message) RunControl *createAnalyzerRunControl(RunConfiguration *runConfiguration, Id runMode) { - foreach (const ActionDescription &action, dd->m_descriptions) { - if (action.runMode() == runMode) - return action.runControlCreator()(runConfiguration, runMode); - } - return 0; + RunControlCreator rcc = dd->m_runControlCreators.value(runMode); + if (rcc) + return rcc(runConfiguration, runMode); + return nullptr; } namespace Internal { diff --git a/src/plugins/qmlprofiler/qmlprofilerconstants.h b/src/plugins/qmlprofiler/qmlprofilerconstants.h index 196395645d..183e8e779b 100644 --- a/src/plugins/qmlprofiler/qmlprofilerconstants.h +++ b/src/plugins/qmlprofiler/qmlprofilerconstants.h @@ -44,8 +44,6 @@ const char QtdFileExtension[] = ".qtd"; const char QztFileExtension[] = ".qzt"; const char QmlProfilerPerspectiveId[] = "QmlProfiler.Perspective"; -const char QmlProfilerLocalActionId[] = "QmlProfiler.Local"; -const char QmlProfilerRemoteActionId[] = "QmlProfiler.Remote"; const char QmlProfilerLoadActionId[] = "Analyzer.Menu.StartAnalyzer.QMLProfilerOptions.LoadQMLTrace"; diff --git a/src/plugins/qmlprofiler/qmlprofilertool.cpp b/src/plugins/qmlprofiler/qmlprofilertool.cpp index cc5a102e42..dc7b580a62 100644 --- a/src/plugins/qmlprofiler/qmlprofilertool.cpp +++ b/src/plugins/qmlprofiler/qmlprofilertool.cpp @@ -53,6 +53,7 @@ #include <projectexplorer/session.h> #include <projectexplorer/kitinformation.h> #include <projectexplorer/runnables.h> +#include <projectexplorer/taskhub.h> #include <texteditor/texteditor.h> #include <coreplugin/coreconstants.h> @@ -162,7 +163,7 @@ QmlProfilerTool::QmlProfilerTool(QObject *parent) Command *command = 0; ActionContainer *menu = ActionManager::actionContainer(M_DEBUG_ANALYZER); - ActionContainer *options = ActionManager::createMenu(M_DEBUG_ANALYZER_QML_OPTIONS); + ActionContainer *options = ActionManager::createMenu("Analyzer.Menu.QMLOptions"); options->menu()->setTitle(tr("QML Profiler Options")); menu->addMenu(options, G_ANALYZER_OPTIONS); options->menu()->setEnabled(true); @@ -253,25 +254,28 @@ QmlProfilerTool::QmlProfilerTool(QObject *parent) d->m_startAction = Debugger::createStartAction(); d->m_stopAction = Debugger::createStopAction(); - ActionDescription desc; - desc.setText(tr("QML Profiler")); - desc.setToolTip(description); - desc.setPerspectiveId(Constants::QmlProfilerPerspectiveId); - desc.setRunControlCreator(runControlCreator); - desc.setToolPreparer([this] { return prepareTool(); }); - desc.setRunMode(ProjectExplorer::Constants::QML_PROFILER_RUN_MODE); - desc.setMenuGroup(Debugger::Constants::G_ANALYZER_TOOLS); - Debugger::registerAction(Constants::QmlProfilerLocalActionId, desc, d->m_startAction); - - desc.setText(tr("QML Profiler (External)")); - desc.setToolTip(description); - desc.setPerspectiveId(Constants::QmlProfilerPerspectiveId); - desc.setRunControlCreator(runControlCreator); - desc.setCustomToolStarter([this](RunConfiguration *rc) { startRemoteTool(rc); }); - desc.setToolPreparer([this] { return prepareTool(); }); - desc.setRunMode(ProjectExplorer::Constants::QML_PROFILER_RUN_MODE); - desc.setMenuGroup(Debugger::Constants::G_ANALYZER_REMOTE_TOOLS); - Debugger::registerAction(Constants::QmlProfilerRemoteActionId, desc); + Debugger::registerAction(ProjectExplorer::Constants::QML_PROFILER_RUN_MODE, runControlCreator); + act = new QAction(tr("QML Profiler"), this); + act->setToolTip(description); + menu->addAction(ActionManager::registerAction(act, "QmlProfiler.Local"), + Debugger::Constants::G_ANALYZER_TOOLS); + QObject::connect(act, &QAction::triggered, this, [this] { + if (!prepareTool()) + return; + Debugger::selectPerspective(Constants::QmlProfilerPerspectiveId); + ProjectExplorerPlugin::runStartupProject(ProjectExplorer::Constants::QML_PROFILER_RUN_MODE); + }); + QObject::connect(d->m_startAction, &QAction::triggered, act, &QAction::triggered); + QObject::connect(d->m_startAction, &QAction::changed, act, [act, this] { + act->setEnabled(d->m_startAction->isEnabled()); + }); + + Debugger::registerAction(ProjectExplorer::Constants::QML_PROFILER_RUN_MODE, runControlCreator); + act = new QAction(tr("QML Profiler (External)"), this); + act->setToolTip(description); + menu->addAction(ActionManager::registerAction(act, "QmlProfiler.Remote"), + Debugger::Constants::G_ANALYZER_REMOTE_TOOLS); + QObject::connect(act, &QAction::triggered, this, &QmlProfilerTool::startRemoteTool); Utils::ToolbarDescription toolbar; toolbar.addAction(d->m_startAction); @@ -556,8 +560,11 @@ bool QmlProfilerTool::prepareTool() return true; } -void QmlProfilerTool::startRemoteTool(ProjectExplorer::RunConfiguration *rc) +void QmlProfilerTool::startRemoteTool() { + if (!prepareTool()) + return; + Id kitId; quint16 port; Kit *kit = 0; @@ -594,6 +601,9 @@ void QmlProfilerTool::startRemoteTool(ProjectExplorer::RunConfiguration *rc) } connection.analyzerPort = Utils::Port(port); + Debugger::selectPerspective(Constants::QmlProfilerPerspectiveId); + + RunConfiguration *rc = Debugger::startupRunConfiguration(); auto runControl = qobject_cast<QmlProfilerRunControl *>(createRunControl(rc)); runControl->setConnection(connection); diff --git a/src/plugins/qmlprofiler/qmlprofilertool.h b/src/plugins/qmlprofiler/qmlprofilertool.h index e0d7cbabfd..85715f8120 100644 --- a/src/plugins/qmlprofiler/qmlprofilertool.h +++ b/src/plugins/qmlprofiler/qmlprofilertool.h @@ -53,7 +53,7 @@ public: void finalizeRunControl(QmlProfilerRunControl *runControl); bool prepareTool(); - void startRemoteTool(ProjectExplorer::RunConfiguration *rc); + void startRemoteTool(); QString summary(const QVector<int> &typeIds) const; QStringList details(int typeId) const; diff --git a/src/plugins/valgrind/callgrindtool.cpp b/src/plugins/valgrind/callgrindtool.cpp index 90c0b80486..30581c201f 100644 --- a/src/plugins/valgrind/callgrindtool.cpp +++ b/src/plugins/valgrind/callgrindtool.cpp @@ -251,28 +251,47 @@ CallgrindTool::CallgrindTool(QObject *parent) m_startAction = Debugger::createStartAction(); m_stopAction = Debugger::createStopAction(); - ActionDescription desc; - desc.setToolTip(tr("Valgrind Function Profiler uses the " - "Callgrind tool to record function calls when a program runs.")); + ActionContainer *menu = ActionManager::actionContainer(Debugger::Constants::M_DEBUG_ANALYZER); + QString toolTip = tr("Valgrind Function Profiler uses the " + "Callgrind tool to record function calls when a program runs."); + + auto rcc = [this](RunConfiguration *runConfiguration, Id mode) { + return createRunControl(runConfiguration, mode); + }; if (!Utils::HostOsInfo::isWindowsHost()) { - desc.setText(tr("Valgrind Function Profiler")); - desc.setPerspectiveId(CallgrindPerspectiveId); - desc.setRunControlCreator([this](RunConfiguration *runConfiguration, Id) { - return createRunControl(runConfiguration, CALLGRIND_RUN_MODE); + Debugger::registerAction(CALLGRIND_RUN_MODE, rcc); + auto action = new QAction(tr("Valgrind Function Profiler"), this); + action->setToolTip(toolTip); + menu->addAction(ActionManager::registerAction(action, CallgrindLocalActionId), + Debugger::Constants::G_ANALYZER_TOOLS); + QObject::connect(action, &QAction::triggered, this, [action] { + if (!Debugger::wantRunTool(OptimizedMode, action->text())) + return; + Debugger::selectPerspective(CallgrindPerspectiveId); + ProjectExplorerPlugin::runStartupProject(CALLGRIND_RUN_MODE); + }); + QObject::connect(m_startAction, &QAction::triggered, action, &QAction::triggered); + QObject::connect(m_startAction, &QAction::changed, action, [action, this] { + action->setEnabled(m_startAction->isEnabled()); }); - desc.setToolMode(OptimizedMode); - desc.setRunMode(CALLGRIND_RUN_MODE); - desc.setMenuGroup(Debugger::Constants::G_ANALYZER_TOOLS); - Debugger::registerAction(CallgrindLocalActionId, desc, m_startAction); } - desc.setText(tr("Valgrind Function Profiler (External Application)")); - desc.setPerspectiveId(CallgrindPerspectiveId); - desc.setCustomToolStarter([this](RunConfiguration *runConfig) { + Debugger::registerAction(CALLGRIND_RUN_MODE, rcc); + auto action = new QAction(tr("Valgrind Function Profiler (External Application)"), this); + action->setToolTip(toolTip); + menu->addAction(ActionManager::registerAction(action, CallgrindRemoteActionId), + Debugger::Constants::G_ANALYZER_REMOTE_TOOLS); + QObject::connect(action, &QAction::triggered, this, [this, action] { + RunConfiguration *runConfig = startupRunConfiguration(); + if (!runConfig) { + showCannotStartDialog(action->text()); + return; + } StartRemoteDialog dlg; if (dlg.exec() != QDialog::Accepted) return; + Debugger::selectPerspective(CallgrindPerspectiveId); ValgrindRunControl *rc = createRunControl(runConfig, CALLGRIND_RUN_MODE); QTC_ASSERT(rc, return); const auto runnable = dlg.runnable(); @@ -283,8 +302,6 @@ CallgrindTool::CallgrindTool(QObject *parent) rc->setDisplayName(runnable.executable); ProjectExplorerPlugin::startRunControl(rc); }); - desc.setMenuGroup(Debugger::Constants::G_ANALYZER_REMOTE_TOOLS); - Debugger::registerAction(CallgrindRemoteActionId, desc); // If there is a CppEditor context menu add our own context menu actions. if (ActionContainer *editorContextMenu = @@ -360,7 +377,7 @@ CallgrindTool::CallgrindTool(QObject *parent) // // load external log file - auto action = m_loadExternalLogFile = new QAction(this); + action = m_loadExternalLogFile = new QAction(this); action->setIcon(Utils::Icons::OPENFILE.icon()); action->setToolTip(tr("Load External Log File")); connect(action, &QAction::triggered, this, &CallgrindTool::loadExternalLogFile); diff --git a/src/plugins/valgrind/memchecktool.cpp b/src/plugins/valgrind/memchecktool.cpp index 6b40384dac..aab1a8c24e 100644 --- a/src/plugins/valgrind/memchecktool.cpp +++ b/src/plugins/valgrind/memchecktool.cpp @@ -58,6 +58,7 @@ #include <projectexplorer/buildconfiguration.h> #include <coreplugin/actionmanager/actioncontainer.h> +#include <coreplugin/actionmanager/actioncontainer.h> #include <coreplugin/actionmanager/actionmanager.h> #include <coreplugin/actionmanager/command.h> #include <coreplugin/editormanager/editormanager.h> @@ -87,6 +88,7 @@ #include <QString> #include <QToolButton> +using namespace Core; using namespace Debugger; using namespace ProjectExplorer; using namespace Utils; @@ -390,37 +392,66 @@ MemcheckTool::MemcheckTool(QObject *parent) connect(m_filterMenu, &QMenu::triggered, this, &MemcheckTool::updateErrorFilter); filterButton->setMenu(m_filterMenu); - ActionDescription desc; - desc.setToolTip(tr("Valgrind Analyze Memory uses the " - "Memcheck tool to find memory leaks.")); + ActionContainer *menu = ActionManager::actionContainer(Debugger::Constants::M_DEBUG_ANALYZER); + QString toolTip = tr("Valgrind Analyze Memory uses the Memcheck tool to find memory leaks."); if (!Utils::HostOsInfo::isWindowsHost()) { - desc.setText(tr("Valgrind Memory Analyzer")); - desc.setPerspectiveId(MemcheckPerspectiveId); - desc.setRunControlCreator(std::bind(&MemcheckTool::createRunControl, this, _1, _2)); - desc.setToolMode(DebugMode); - desc.setRunMode(MEMCHECK_RUN_MODE); - desc.setMenuGroup(Debugger::Constants::G_ANALYZER_TOOLS); - Debugger::registerAction("Memcheck.Local", desc, m_startAction); - - desc.setText(tr("Valgrind Memory Analyzer with GDB")); - desc.setToolTip(tr("Valgrind Analyze Memory with GDB uses the " + Debugger::registerAction(MEMCHECK_RUN_MODE, std::bind(&MemcheckTool::createRunControl, this, _1, _2)); + action = new QAction(this); + action->setText(tr("Valgrind Memory Analyzer")); + action->setToolTip(toolTip); + menu->addAction(ActionManager::registerAction(action, "Memcheck.Local"), + Debugger::Constants::G_ANALYZER_TOOLS); + QObject::connect(action, &QAction::triggered, this, [action] { + if (!Debugger::wantRunTool(DebugMode, action->text())) + return; + TaskHub::clearTasks(Debugger::Constants::ANALYZERTASK_ID); + Debugger::selectPerspective(MemcheckPerspectiveId); + ProjectExplorerPlugin::runStartupProject(MEMCHECK_RUN_MODE); + }); + QObject::connect(m_startAction, &QAction::triggered, action, &QAction::triggered); + QObject::connect(m_startAction, &QAction::changed, action, [action, this] { + action->setEnabled(m_startAction->isEnabled()); + }); + + Debugger::registerAction(MEMCHECK_WITH_GDB_RUN_MODE, std::bind(&MemcheckTool::createRunControl, this, _1, _2)); + action = new QAction(this); + action->setText(tr("Valgrind Memory Analyzer with GDB")); + action->setToolTip(tr("Valgrind Analyze Memory with GDB uses the " "Memcheck tool to find memory leaks.\nWhen a problem is detected, " "the application is interrupted and can be debugged.")); - desc.setPerspectiveId(MemcheckPerspectiveId); - desc.setRunControlCreator(std::bind(&MemcheckTool::createRunControl, this, _1, _2)); - desc.setToolMode(DebugMode); - desc.setRunMode(MEMCHECK_WITH_GDB_RUN_MODE); - desc.setMenuGroup(Debugger::Constants::G_ANALYZER_TOOLS); - Debugger::registerAction("MemcheckWithGdb.Local", desc, m_startWithGdbAction); + menu->addAction(ActionManager::registerAction(action, "MemcheckWithGdb.Local"), + Debugger::Constants::G_ANALYZER_TOOLS); + QObject::connect(action, &QAction::triggered, this, [action] { + if (!Debugger::wantRunTool(DebugMode, action->text())) + return; + TaskHub::clearTasks(Debugger::Constants::ANALYZERTASK_ID); + Debugger::selectPerspective(MemcheckPerspectiveId); + ProjectExplorerPlugin::runStartupProject(MEMCHECK_WITH_GDB_RUN_MODE); + }); + QObject::connect(m_startWithGdbAction, &QAction::triggered, action, &QAction::triggered); + QObject::connect(m_startWithGdbAction, &QAction::changed, action, [action, this] { + action->setEnabled(m_startWithGdbAction->isEnabled()); + }); } - desc.setText(tr("Valgrind Memory Analyzer (External Application)")); - desc.setPerspectiveId(MemcheckPerspectiveId); - desc.setCustomToolStarter([this](ProjectExplorer::RunConfiguration *runConfig) { + Debugger::registerAction(MEMCHECK_RUN_MODE, std::bind(&MemcheckTool::createRunControl, this, _1, _2)); + action = new QAction(this); + action->setText(tr("Valgrind Memory Analyzer (External Application)")); + action->setToolTip(toolTip); + menu->addAction(ActionManager::registerAction(action, "Memcheck.Remote"), + Debugger::Constants::G_ANALYZER_REMOTE_TOOLS); + QObject::connect(action, &QAction::triggered, this, [this, action] { + RunConfiguration *runConfig = startupRunConfiguration(); + if (!runConfig) { + showCannotStartDialog(action->text()); + return; + } StartRemoteDialog dlg; if (dlg.exec() != QDialog::Accepted) return; + TaskHub::clearTasks(Debugger::Constants::ANALYZERTASK_ID); + Debugger::selectPerspective(MemcheckPerspectiveId); RunControl *rc = createRunControl(runConfig, MEMCHECK_RUN_MODE); QTC_ASSERT(rc, return); const auto runnable = dlg.runnable(); @@ -431,8 +462,6 @@ MemcheckTool::MemcheckTool(QObject *parent) rc->setDisplayName(runnable.executable); ProjectExplorerPlugin::startRunControl(rc); }); - desc.setMenuGroup(Debugger::Constants::G_ANALYZER_REMOTE_TOOLS); - Debugger::registerAction("Memcheck.Remote", desc); ToolbarDescription toolbar; toolbar.addAction(m_startAction); |