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);
|
||||
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());
|
||||
});
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user