forked from qt-creator/qt-creator
ClangFormat: Simplify menu action handling
Change-Id: Ic4a5a6023c2f8f43b30010c14e245d0879da9ab1 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -76,26 +76,13 @@ void ClangFormatPlugin::initialize()
|
|||||||
ActionBuilder openConfig(this, Constants::OPEN_CURRENT_CONFIG_ID);
|
ActionBuilder openConfig(this, Constants::OPEN_CURRENT_CONFIG_ID);
|
||||||
openConfig.setText(Tr::tr("Open Used .clang-format Configuration File"));
|
openConfig.setText(Tr::tr("Open Used .clang-format Configuration File"));
|
||||||
openConfig.addToContainer(CppEditor::Constants::M_CONTEXT);
|
openConfig.addToContainer(CppEditor::Constants::M_CONTEXT);
|
||||||
openConfig.addOnTriggered([action=openConfig.contextAction()] {
|
openConfig.addOnTriggered(this, [] {
|
||||||
const FilePath fileName = FilePath::fromVariant(action->data());
|
if (const IDocument *doc = EditorManager::currentDocument()) {
|
||||||
if (!fileName.isEmpty())
|
const FilePath filePath = doc->filePath();
|
||||||
EditorManager::openEditor(configForFile(fileName));
|
if (!filePath.isEmpty())
|
||||||
});
|
EditorManager::openEditor(configForFile(filePath));
|
||||||
|
}
|
||||||
if (EditorManager::currentEditor()) {
|
});
|
||||||
if (const IDocument *doc = EditorManager::currentEditor()->document())
|
|
||||||
openConfig.contextAction()->setData(doc->filePath().toVariant());
|
|
||||||
}
|
|
||||||
|
|
||||||
connect(EditorManager::instance(),
|
|
||||||
&EditorManager::currentEditorChanged,
|
|
||||||
this,
|
|
||||||
[action=openConfig.contextAction()](IEditor *editor) {
|
|
||||||
if (!editor)
|
|
||||||
return;
|
|
||||||
if (const IDocument *doc = editor->document())
|
|
||||||
action->setData(doc->filePath().toVariant());
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WITH_TESTS
|
#ifdef WITH_TESTS
|
||||||
|
Reference in New Issue
Block a user