From 72d5cc7d017462ec7b9a5b844c63b38ed520bc86 Mon Sep 17 00:00:00 2001 From: hjk Date: Tue, 12 Dec 2023 18:56:38 +0100 Subject: [PATCH] ClangFormat: Use ActionBuilder Change-Id: Ia276db9928193781ab90d34db01447498f40f4d1 Reviewed-by: Reviewed-by: Eike Ziller --- src/plugins/clangformat/clangformatplugin.cpp | 30 ++++++++----------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/src/plugins/clangformat/clangformatplugin.cpp b/src/plugins/clangformat/clangformatplugin.cpp index b64ca2ac94e..90178a0d264 100644 --- a/src/plugins/clangformat/clangformatplugin.cpp +++ b/src/plugins/clangformat/clangformatplugin.cpp @@ -71,36 +71,30 @@ void ClangFormatPlugin::initialize() ActionContainer *contextMenu = ActionManager::actionContainer(CppEditor::Constants::M_CONTEXT); if (contextMenu) { - auto openClangFormatConfigAction - = new QAction(Tr::tr("Open Used .clang-format Configuration File"), this); - Command *command = ActionManager::registerAction(openClangFormatConfigAction, - Constants::OPEN_CURRENT_CONFIG_ID); contextMenu->addSeparator(); - contextMenu->addAction(command); - if (EditorManager::currentEditor()) { - if (const IDocument *doc = EditorManager::currentEditor()->document()) - openClangFormatConfigAction->setData(doc->filePath().toVariant()); - } - - connect(openClangFormatConfigAction, - &QAction::triggered, - this, - [openClangFormatConfigAction] { - const FilePath fileName = FilePath::fromVariant(openClangFormatConfigAction->data()); + ActionBuilder openConfig(this, Constants::OPEN_CURRENT_CONFIG_ID); + openConfig.setText(Tr::tr("Open Used .clang-format Configuration File")); + openConfig.setContainer(CppEditor::Constants::M_CONTEXT); + openConfig.setOnTriggered([action=openConfig.contextAction()] { + const FilePath fileName = FilePath::fromVariant(action->data()); if (!fileName.isEmpty()) EditorManager::openEditor(configForFile(fileName)); }); + if (EditorManager::currentEditor()) { + if (const IDocument *doc = EditorManager::currentEditor()->document()) + openConfig.contextAction()->setData(doc->filePath().toVariant()); + } + connect(EditorManager::instance(), &EditorManager::currentEditorChanged, this, - [openClangFormatConfigAction](IEditor *editor) { + [action=openConfig.contextAction()](IEditor *editor) { if (!editor) return; - if (const IDocument *doc = editor->document()) - openClangFormatConfigAction->setData(doc->filePath().toVariant()); + action->setData(doc->filePath().toVariant()); }); }