ClangFormat: Use ActionBuilder

Change-Id: Ia276db9928193781ab90d34db01447498f40f4d1
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
hjk
2023-12-12 18:56:38 +01:00
parent 6e41548230
commit 72d5cc7d01

View File

@@ -71,36 +71,30 @@ void ClangFormatPlugin::initialize()
ActionContainer *contextMenu = ActionManager::actionContainer(CppEditor::Constants::M_CONTEXT); ActionContainer *contextMenu = ActionManager::actionContainer(CppEditor::Constants::M_CONTEXT);
if (contextMenu) { 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->addSeparator();
contextMenu->addAction(command);
if (EditorManager::currentEditor()) { ActionBuilder openConfig(this, Constants::OPEN_CURRENT_CONFIG_ID);
if (const IDocument *doc = EditorManager::currentEditor()->document()) openConfig.setText(Tr::tr("Open Used .clang-format Configuration File"));
openClangFormatConfigAction->setData(doc->filePath().toVariant()); openConfig.setContainer(CppEditor::Constants::M_CONTEXT);
} openConfig.setOnTriggered([action=openConfig.contextAction()] {
const FilePath fileName = FilePath::fromVariant(action->data());
connect(openClangFormatConfigAction,
&QAction::triggered,
this,
[openClangFormatConfigAction] {
const FilePath fileName = FilePath::fromVariant(openClangFormatConfigAction->data());
if (!fileName.isEmpty()) if (!fileName.isEmpty())
EditorManager::openEditor(configForFile(fileName)); EditorManager::openEditor(configForFile(fileName));
}); });
if (EditorManager::currentEditor()) {
if (const IDocument *doc = EditorManager::currentEditor()->document())
openConfig.contextAction()->setData(doc->filePath().toVariant());
}
connect(EditorManager::instance(), connect(EditorManager::instance(),
&EditorManager::currentEditorChanged, &EditorManager::currentEditorChanged,
this, this,
[openClangFormatConfigAction](IEditor *editor) { [action=openConfig.contextAction()](IEditor *editor) {
if (!editor) if (!editor)
return; return;
if (const IDocument *doc = editor->document()) if (const IDocument *doc = editor->document())
openClangFormatConfigAction->setData(doc->filePath().toVariant()); action->setData(doc->filePath().toVariant());
}); });
} }