forked from qt-creator/qt-creator
CppTools: Use indenter from TextDocument or create one
So if you use the ClangFormat Plugin, the ClangFormatIndenter is used and not the CppQtStyleIndenter. Change-Id: I7e71867cd4b48525ddc2f9b2dce8f13a65c3ad88 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -34,6 +34,11 @@
|
||||
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <cpptools/cpptoolsconstants.h>
|
||||
#include <texteditor/icodestylepreferencesfactory.h>
|
||||
#include <texteditor/textdocument.h>
|
||||
#include <texteditor/texteditorsettings.h>
|
||||
|
||||
#include <QTextDocument>
|
||||
|
||||
using namespace CPlusPlus;
|
||||
@@ -42,6 +47,13 @@ namespace CppTools {
|
||||
|
||||
class CppRefactoringChangesData : public TextEditor::RefactoringChangesData
|
||||
{
|
||||
static std::unique_ptr<TextEditor::Indenter> createIndenter(QTextDocument *textDocument)
|
||||
{
|
||||
TextEditor::ICodeStylePreferencesFactory *factory
|
||||
= TextEditor::TextEditorSettings::codeStyleFactory(CppTools::Constants::CPP_SETTINGS_ID);
|
||||
return std::unique_ptr<TextEditor::Indenter>(factory->createIndenter(textDocument));
|
||||
}
|
||||
|
||||
public:
|
||||
explicit CppRefactoringChangesData(const Snapshot &snapshot)
|
||||
: m_snapshot(snapshot)
|
||||
@@ -53,23 +65,26 @@ public:
|
||||
const QString &fileName,
|
||||
const TextEditor::TextDocument *textDocument) const override
|
||||
{
|
||||
const TextEditor::TabSettings &tabSettings =
|
||||
ProjectExplorer::actualTabSettings(fileName, textDocument);
|
||||
|
||||
CppQtStyleIndenter indenter(selection.document());
|
||||
indenter.indent(selection, QChar::Null, tabSettings);
|
||||
if (textDocument) { // use the indenter from the textDocument if there is one, can be ClangFormat
|
||||
textDocument->indenter()->indent(selection, QChar::Null, textDocument->tabSettings());
|
||||
} else {
|
||||
const auto &tabSettings = ProjectExplorer::actualTabSettings(fileName, textDocument);
|
||||
auto indenter = createIndenter(selection.document());
|
||||
indenter->indent(selection, QChar::Null, tabSettings);
|
||||
}
|
||||
}
|
||||
|
||||
void reindentSelection(const QTextCursor &selection,
|
||||
const QString &fileName,
|
||||
const TextEditor::TextDocument *textDocument) const override
|
||||
{
|
||||
const TextEditor::TabSettings &tabSettings =
|
||||
ProjectExplorer::actualTabSettings(fileName, textDocument);
|
||||
|
||||
CppQtStyleIndenter indenter(selection.document());
|
||||
indenter.reindent(selection,
|
||||
tabSettings);
|
||||
if (textDocument) { // use the indenter from the textDocument if there is one, can be ClangFormat
|
||||
textDocument->indenter()->reindent(selection, textDocument->tabSettings());
|
||||
} else {
|
||||
const auto &tabSettings = ProjectExplorer::actualTabSettings(fileName, textDocument);
|
||||
auto indenter = createIndenter(selection.document());
|
||||
indenter->reindent(selection, tabSettings);
|
||||
}
|
||||
}
|
||||
|
||||
void fileChanged(const QString &fileName) override
|
||||
|
||||
Reference in New Issue
Block a user