From 6e7b83bb4acb461508d9a71ffad3c5a6e418b92b Mon Sep 17 00:00:00 2001 From: hjk Date: Tue, 30 Jan 2024 18:16:10 +0100 Subject: [PATCH] CppCheck: Use ActionBuilder Change-Id: I385427232891826641760f463da26de3777387b6 Reviewed-by: Reviewed-by: Eike Ziller --- src/plugins/cppcheck/cppcheckplugin.cpp | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/plugins/cppcheck/cppcheckplugin.cpp b/src/plugins/cppcheck/cppcheckplugin.cpp index 496d9af6cd7..30ee2c2d67c 100644 --- a/src/plugins/cppcheck/cppcheckplugin.cpp +++ b/src/plugins/cppcheck/cppcheckplugin.cpp @@ -30,6 +30,8 @@ #include #include +using namespace Core; +using namespace ProjectExplorer; using namespace Utils; namespace Cppcheck::Internal { @@ -46,7 +48,7 @@ public: CppcheckTool manualRunTool{manualRunModel, Constants::MANUAL_CHECK_PROGRESS_ID}; Utils::Perspective perspective{Constants::PERSPECTIVE_ID, ::Cppcheck::Tr::tr("Cppcheck")}; - QAction *manualRunAction; + Action *manualRunAction = nullptr; void startManualRun(); void updateManualRunAction(); @@ -130,7 +132,6 @@ void CppcheckPluginPrivate::startManualRun() void CppcheckPluginPrivate::updateManualRunAction() { - using namespace ProjectExplorer; const Project *project = ProjectManager::startupProject(); const Target *target = ProjectManager::startupTarget(); const Utils::Id cxx = ProjectExplorer::Constants::CXX_LANGUAGE_ID; @@ -148,19 +149,13 @@ class CppcheckPlugin final : public ExtensionSystem::IPlugin { d.reset(new CppcheckPluginPrivate); - using namespace Core; - ActionContainer *menu = ActionManager::actionContainer(Debugger::Constants::M_DEBUG_ANALYZER); + ActionBuilder(this, Constants::MANUAL_RUN_ACTION) + .setText(Tr::tr("Cppcheck...")) + .bindContextAction(&d->manualRunAction) + .addToContainer(Debugger::Constants::M_DEBUG_ANALYZER, + Debugger::Constants::G_ANALYZER_TOOLS) + .addOnTriggered(d.get(), &CppcheckPluginPrivate::startManualRun); - { - auto action = new QAction(Tr::tr("Cppcheck..."), this); - menu->addAction(ActionManager::registerAction(action, Constants::MANUAL_RUN_ACTION), - Debugger::Constants::G_ANALYZER_TOOLS); - connect(action, &QAction::triggered, - d.get(), &CppcheckPluginPrivate::startManualRun); - d->manualRunAction = action; - } - - using ProjectExplorer::ProjectExplorerPlugin; connect(ProjectExplorerPlugin::instance(), &ProjectExplorerPlugin::runActionsUpdated, d.get(), &CppcheckPluginPrivate::updateManualRunAction); d->updateManualRunAction();