From e1f7469afb32efa51d665c9211767b214cd93573 Mon Sep 17 00:00:00 2001 From: Artem Sokolovskii Date: Wed, 3 Jan 2024 14:56:54 +0100 Subject: ClangFormat: Replace checks widget with editor The existing approach utilizing the widget poses maintenance challenges, primarily due to the dynamic nature of clang-format settings across versions. The widget necessitates regeneration for each new version, and compatibility issues arise when users have different clang-format versions on their devices. The updated solution adopts an Editor integrated with a yaml language server, offering the ability to highlight and provide code completion for the .clang-format file. This resolves the widget regeneration issue and ensures compatibility with various clang-format versions. - Replaced the checks widget with an editor - Introduced a line for yaml language server schema in .clang-format files to enable autocompletion. ToDo: Enhance schema accessibility without relying on this line. - Added Ctrl+Space shortcut for autocompletion - Added Ctrl+S shortcut for saving - Eliminated outdated logic related to the checks widget - Fixed copying and removal of clang-format settings Change-Id: I2e3fbf19abe2f4df031f6ba5faffd47e07274346 Reviewed-by: hjk Reviewed-by: Christian Kandeler Reviewed-by: David Schulz Reviewed-by: --- src/plugins/texteditor/codestyleselectorwidget.cpp | 1 + src/plugins/texteditor/icodestylepreferences.cpp | 2 ++ src/plugins/texteditor/icodestylepreferences.h | 3 +++ src/plugins/texteditor/textdocument.cpp | 2 ++ 4 files changed, 8 insertions(+) (limited to 'src/plugins/texteditor') diff --git a/src/plugins/texteditor/codestyleselectorwidget.cpp b/src/plugins/texteditor/codestyleselectorwidget.cpp index a219be271a..ddeea0a74e 100644 --- a/src/plugins/texteditor/codestyleselectorwidget.cpp +++ b/src/plugins/texteditor/codestyleselectorwidget.cpp @@ -165,6 +165,7 @@ void CodeStyleSelectorWidget::slotCopyClicked() ICodeStylePreferences *copy = codeStylePool->cloneCodeStyle(currentPreferences); if (copy) { copy->setDisplayName(newName); + emit m_codeStyle->aboutToBeCopied(currentPreferences, copy); m_codeStyle->setCurrentDelegate(copy); } } diff --git a/src/plugins/texteditor/icodestylepreferences.cpp b/src/plugins/texteditor/icodestylepreferences.cpp index d7547d430e..82a478e697 100644 --- a/src/plugins/texteditor/icodestylepreferences.cpp +++ b/src/plugins/texteditor/icodestylepreferences.cpp @@ -241,6 +241,8 @@ void ICodeStylePreferences::fromMap(const Store &map) void ICodeStylePreferences::codeStyleRemoved(ICodeStylePreferences *preferences) { if (currentDelegate() == preferences) { + emit aboutToBeRemoved(preferences); + CodeStylePool *pool = delegatingPool(); QList codeStyles = pool->codeStyles(); const int idx = codeStyles.indexOf(preferences); diff --git a/src/plugins/texteditor/icodestylepreferences.h b/src/plugins/texteditor/icodestylepreferences.h index 7239411b5c..451ac669cc 100644 --- a/src/plugins/texteditor/icodestylepreferences.h +++ b/src/plugins/texteditor/icodestylepreferences.h @@ -80,6 +80,9 @@ signals: void currentDelegateChanged(TextEditor::ICodeStylePreferences *currentDelegate); void currentPreferencesChanged(TextEditor::ICodeStylePreferences *currentPreferences); void displayNameChanged(const QString &newName); + void aboutToBeRemoved(TextEditor::ICodeStylePreferences *preferences); + void aboutToBeCopied(TextEditor::ICodeStylePreferences *current, + TextEditor::ICodeStylePreferences *target); private: void codeStyleRemoved(ICodeStylePreferences *preferences); diff --git a/src/plugins/texteditor/textdocument.cpp b/src/plugins/texteditor/textdocument.cpp index 025720a9d3..5ea17e1097 100644 --- a/src/plugins/texteditor/textdocument.cpp +++ b/src/plugins/texteditor/textdocument.cpp @@ -292,6 +292,8 @@ TextDocument *TextDocument::currentTextDocument() TextDocument *TextDocument::textDocumentForFilePath(const Utils::FilePath &filePath) { + if (filePath.isEmpty()) + return nullptr; return qobject_cast(DocumentModel::documentForFilePath(filePath)); } -- cgit v1.2.3