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);
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());
});
}