forked from qt-creator/qt-creator
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:
@@ -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());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user