forked from qt-creator/qt-creator
QmlJsEditor: Don't export Internal classes
Export two functions doing the actual work instead. Centralize some repeated code. Change-Id: I7de674ef7ae5537663d1227d36cc556c4ee3ed74 Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
@@ -169,7 +169,7 @@ void BindingEditorFactory::decorateEditor(TextEditor::TextEditorWidget *editor)
|
|||||||
{
|
{
|
||||||
editor->textDocument()->resetSyntaxHighlighter(
|
editor->textDocument()->resetSyntaxHighlighter(
|
||||||
[] { return new QmlJSEditor::QmlJSHighlighter(); });
|
[] { return new QmlJSEditor::QmlJSHighlighter(); });
|
||||||
editor->textDocument()->setIndenter(new QmlJSEditor::Internal::Indenter(
|
editor->textDocument()->setIndenter(QmlJSEditor::createQmlJsIndenter(
|
||||||
editor->textDocument()->document()));
|
editor->textDocument()->document()));
|
||||||
editor->setAutoCompleter(new QmlJSEditor::AutoCompleter);
|
editor->setAutoCompleter(new QmlJSEditor::AutoCompleter);
|
||||||
}
|
}
|
||||||
|
@@ -33,20 +33,8 @@ void BaseTextEditModifier::indentLines(int startLine, int endLine)
|
|||||||
if (!m_textEdit)
|
if (!m_textEdit)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
TextEditor::TextDocument *baseTextEditorDocument = m_textEdit->textDocument();
|
QmlJSEditor::indentQmlJs(textDocument(), startLine, endLine,
|
||||||
TextEditor::TabSettings tabSettings = baseTextEditorDocument->tabSettings();
|
m_textEdit->textDocument()->tabSettings());
|
||||||
QTextCursor tc(textDocument());
|
|
||||||
|
|
||||||
tc.beginEditBlock();
|
|
||||||
for (int i = startLine; i <= endLine; i++) {
|
|
||||||
QTextBlock start = textDocument()->findBlockByNumber(i);
|
|
||||||
|
|
||||||
if (start.isValid()) {
|
|
||||||
QmlJSEditor::Internal::Indenter indenter(textDocument());
|
|
||||||
indenter.indentBlock(start, QChar::Null, tabSettings);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
tc.endEditBlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseTextEditModifier::indent(int offset, int length)
|
void BaseTextEditModifier::indent(int offset, int length)
|
||||||
|
@@ -186,20 +186,6 @@ void IndentingTextEditModifier::indent(int offset, int length)
|
|||||||
|
|
||||||
void IndentingTextEditModifier::indentLines(int startLine, int endLine)
|
void IndentingTextEditModifier::indentLines(int startLine, int endLine)
|
||||||
{
|
{
|
||||||
if (startLine < 0)
|
QmlJSEditor::indentQmlJs(textDocument(), startLine, endLine, m_tabSettings);
|
||||||
return;
|
|
||||||
|
|
||||||
QTextCursor tc(textDocument());
|
|
||||||
|
|
||||||
tc.beginEditBlock();
|
|
||||||
for (int i = startLine; i <= endLine; i++) {
|
|
||||||
QTextBlock start = textDocument()->findBlockByNumber(i);
|
|
||||||
|
|
||||||
if (start.isValid()) {
|
|
||||||
QmlJSEditor::Internal::Indenter indenter(textDocument());
|
|
||||||
indenter.indentBlock(start, QChar::Null, m_tabSettings);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
tc.endEditBlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1184,7 +1184,7 @@ QmlJSEditorFactory::QmlJSEditorFactory(Utils::Id _id)
|
|||||||
void QmlJSEditorFactory::decorateEditor(TextEditorWidget *editor)
|
void QmlJSEditorFactory::decorateEditor(TextEditorWidget *editor)
|
||||||
{
|
{
|
||||||
editor->textDocument()->resetSyntaxHighlighter([] { return new QmlJSHighlighter(); });
|
editor->textDocument()->resetSyntaxHighlighter([] { return new QmlJSHighlighter(); });
|
||||||
editor->textDocument()->setIndenter(new Internal::Indenter(editor->textDocument()->document()));
|
editor->textDocument()->setIndenter(createQmlJsIndenter(editor->textDocument()->document()));
|
||||||
editor->setAutoCompleter(new AutoCompleter);
|
editor->setAutoCompleter(new AutoCompleter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -822,7 +822,7 @@ QmlJSEditorDocument::QmlJSEditorDocument(Utils::Id id)
|
|||||||
d, &Internal::QmlJSEditorDocumentPrivate::settingsChanged);
|
d, &Internal::QmlJSEditorDocumentPrivate::settingsChanged);
|
||||||
resetSyntaxHighlighter([] { return new QmlJSHighlighter(); });
|
resetSyntaxHighlighter([] { return new QmlJSHighlighter(); });
|
||||||
setCodec(QTextCodec::codecForName("UTF-8")); // qml files are defined to be utf-8
|
setCodec(QTextCodec::codecForName("UTF-8")); // qml files are defined to be utf-8
|
||||||
setIndenter(new Internal::Indenter(document()));
|
setIndenter(createQmlJsIndenter(document()));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QmlJSEditorDocument::supportsCodec(const QTextCodec *codec) const
|
bool QmlJSEditorDocument::supportsCodec(const QTextCodec *codec) const
|
||||||
|
@@ -396,17 +396,8 @@ void QuickToolBar::onEnabledChanged(bool b)
|
|||||||
|
|
||||||
void QuickToolBar::indentLines(int startLine, int endLine)
|
void QuickToolBar::indentLines(int startLine, int endLine)
|
||||||
{
|
{
|
||||||
if (startLine > 0) {
|
QmlJSEditor::indentQmlJs(m_editorWidget->document(), startLine, endLine,
|
||||||
TextEditor::TabSettings tabSettings = m_editorWidget->textDocument()->tabSettings();
|
m_editorWidget->textDocument()->tabSettings());
|
||||||
for (int i = startLine; i <= endLine; i++) {
|
|
||||||
QTextBlock start = m_editorWidget->document()->findBlockByNumber(i);
|
|
||||||
|
|
||||||
if (start.isValid()) {
|
|
||||||
QmlJSEditor::Internal::Indenter indenterMy(m_editorWidget->document());
|
|
||||||
indenterMy.indentBlock(start, QChar::Null, tabSettings);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ContextPaneWidget *QuickToolBar::contextWidget()
|
ContextPaneWidget *QuickToolBar::contextWidget()
|
||||||
|
@@ -64,7 +64,7 @@ TextEditor::CodeStyleEditorWidget *QmlJSCodeStylePreferencesFactory::createEdito
|
|||||||
|
|
||||||
TextEditor::Indenter *QmlJSCodeStylePreferencesFactory::createIndenter(QTextDocument *doc) const
|
TextEditor::Indenter *QmlJSCodeStylePreferencesFactory::createIndenter(QTextDocument *doc) const
|
||||||
{
|
{
|
||||||
return new QmlJSEditor::Internal::Indenter(doc);
|
return QmlJSEditor::createQmlJsIndenter(doc);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QmlJSCodeStylePreferencesFactory::snippetProviderGroupId() const
|
QString QmlJSCodeStylePreferencesFactory::snippetProviderGroupId() const
|
||||||
|
@@ -6,30 +6,47 @@
|
|||||||
#include <qmljstools/qmljsqtstylecodeformatter.h>
|
#include <qmljstools/qmljsqtstylecodeformatter.h>
|
||||||
#include <texteditor/tabsettings.h>
|
#include <texteditor/tabsettings.h>
|
||||||
|
|
||||||
#include <QChar>
|
|
||||||
#include <QTextDocument>
|
#include <QTextDocument>
|
||||||
#include <QTextBlock>
|
#include <QTextBlock>
|
||||||
|
|
||||||
using namespace QmlJSEditor;
|
using namespace TextEditor;
|
||||||
using namespace Internal;
|
|
||||||
|
|
||||||
Indenter::Indenter(QTextDocument *doc)
|
namespace QmlJSEditor {
|
||||||
: TextEditor::TextIndenter(doc)
|
namespace Internal {
|
||||||
{}
|
|
||||||
|
|
||||||
Indenter::~Indenter() = default;
|
class QmlJsIndenter final : public TextEditor::TextIndenter
|
||||||
|
|
||||||
bool Indenter::isElectricCharacter(const QChar &ch) const
|
|
||||||
{
|
{
|
||||||
if (ch == QLatin1Char('{')
|
public:
|
||||||
|| ch == QLatin1Char('}')
|
explicit QmlJsIndenter(QTextDocument *doc)
|
||||||
|| ch == QLatin1Char(']')
|
: TextEditor::TextIndenter(doc)
|
||||||
|| ch == QLatin1Char(':'))
|
{}
|
||||||
return true;
|
|
||||||
return false;
|
bool isElectricCharacter(const QChar &ch) const final;
|
||||||
|
void indentBlock(const QTextBlock &block,
|
||||||
|
const QChar &typedChar,
|
||||||
|
const TextEditor::TabSettings &tabSettings,
|
||||||
|
int cursorPositionInEditor = -1) final;
|
||||||
|
void invalidateCache() final;
|
||||||
|
|
||||||
|
int indentFor(const QTextBlock &block,
|
||||||
|
const TextEditor::TabSettings &tabSettings,
|
||||||
|
int cursorPositionInEditor = -1) final;
|
||||||
|
int visualIndentFor(const QTextBlock &block,
|
||||||
|
const TextEditor::TabSettings &tabSettings) final;
|
||||||
|
TextEditor::IndentationForBlock indentationForBlocks(const QVector<QTextBlock> &blocks,
|
||||||
|
const TextEditor::TabSettings &tabSettings,
|
||||||
|
int cursorPositionInEditor = -1) final;
|
||||||
|
};
|
||||||
|
|
||||||
|
bool QmlJsIndenter::isElectricCharacter(const QChar &ch) const
|
||||||
|
{
|
||||||
|
return ch == QLatin1Char('{')
|
||||||
|
|| ch == QLatin1Char('}')
|
||||||
|
|| ch == QLatin1Char(']')
|
||||||
|
|| ch == QLatin1Char(':');
|
||||||
}
|
}
|
||||||
|
|
||||||
void Indenter::indentBlock(const QTextBlock &block,
|
void QmlJsIndenter::indentBlock(const QTextBlock &block,
|
||||||
const QChar &typedChar,
|
const QChar &typedChar,
|
||||||
const TextEditor::TabSettings &tabSettings,
|
const TextEditor::TabSettings &tabSettings,
|
||||||
int /*cursorPositionInEditor*/)
|
int /*cursorPositionInEditor*/)
|
||||||
@@ -52,13 +69,13 @@ void Indenter::indentBlock(const QTextBlock &block,
|
|||||||
tabSettings.indentLine(block, depth);
|
tabSettings.indentLine(block, depth);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Indenter::invalidateCache()
|
void QmlJsIndenter::invalidateCache()
|
||||||
{
|
{
|
||||||
QmlJSTools::CreatorCodeFormatter codeFormatter;
|
QmlJSTools::CreatorCodeFormatter codeFormatter;
|
||||||
codeFormatter.invalidateCache(m_doc);
|
codeFormatter.invalidateCache(m_doc);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Indenter::indentFor(const QTextBlock &block,
|
int QmlJsIndenter::indentFor(const QTextBlock &block,
|
||||||
const TextEditor::TabSettings &tabSettings,
|
const TextEditor::TabSettings &tabSettings,
|
||||||
int /*cursorPositionInEditor*/)
|
int /*cursorPositionInEditor*/)
|
||||||
{
|
{
|
||||||
@@ -67,12 +84,12 @@ int Indenter::indentFor(const QTextBlock &block,
|
|||||||
return codeFormatter.indentFor(block);
|
return codeFormatter.indentFor(block);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Indenter::visualIndentFor(const QTextBlock &block, const TextEditor::TabSettings &tabSettings)
|
int QmlJsIndenter::visualIndentFor(const QTextBlock &block, const TextEditor::TabSettings &tabSettings)
|
||||||
{
|
{
|
||||||
return indentFor(block, tabSettings);
|
return indentFor(block, tabSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
TextEditor::IndentationForBlock Indenter::indentationForBlocks(
|
TextEditor::IndentationForBlock QmlJsIndenter::indentationForBlocks(
|
||||||
const QVector<QTextBlock> &blocks,
|
const QVector<QTextBlock> &blocks,
|
||||||
const TextEditor::TabSettings &tabSettings,
|
const TextEditor::TabSettings &tabSettings,
|
||||||
int /*cursorPositionInEditor*/)
|
int /*cursorPositionInEditor*/)
|
||||||
@@ -86,3 +103,31 @@ TextEditor::IndentationForBlock Indenter::indentationForBlocks(
|
|||||||
ret.insert(block.blockNumber(), codeFormatter.indentFor(block));
|
ret.insert(block.blockNumber(), codeFormatter.indentFor(block));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // Internal
|
||||||
|
|
||||||
|
TextEditor::TextIndenter *createQmlJsIndenter(QTextDocument *doc)
|
||||||
|
{
|
||||||
|
return new Internal::QmlJsIndenter(doc);
|
||||||
|
}
|
||||||
|
|
||||||
|
void indentQmlJs(QTextDocument *doc, int startLine, int endLine, const TextEditor::TabSettings &tabSettings)
|
||||||
|
{
|
||||||
|
if (startLine <= 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
QTextCursor tc(doc);
|
||||||
|
|
||||||
|
tc.beginEditBlock();
|
||||||
|
for (int i = startLine; i <= endLine; i++) {
|
||||||
|
// FIXME: block.next() should be faster.
|
||||||
|
QTextBlock block = doc->findBlockByNumber(i);
|
||||||
|
if (block.isValid()) {
|
||||||
|
Internal::QmlJsIndenter indenter(doc);
|
||||||
|
indenter.indentBlock(block, QChar::Null, tabSettings);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tc.endEditBlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // QmlJsEditor
|
||||||
|
@@ -8,30 +8,10 @@
|
|||||||
#include <texteditor/textindenter.h>
|
#include <texteditor/textindenter.h>
|
||||||
|
|
||||||
namespace QmlJSEditor {
|
namespace QmlJSEditor {
|
||||||
namespace Internal {
|
|
||||||
|
|
||||||
class QMLJSTOOLS_EXPORT Indenter : public TextEditor::TextIndenter
|
QMLJSTOOLS_EXPORT TextEditor::TextIndenter *createQmlJsIndenter(QTextDocument *doc);
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit Indenter(QTextDocument *doc);
|
|
||||||
~Indenter() override;
|
|
||||||
|
|
||||||
bool isElectricCharacter(const QChar &ch) const override;
|
QMLJSTOOLS_EXPORT void indentQmlJs(QTextDocument *doc, int startLine, int endLine,
|
||||||
void indentBlock(const QTextBlock &block,
|
const TextEditor::TabSettings &tabSettings);
|
||||||
const QChar &typedChar,
|
|
||||||
const TextEditor::TabSettings &tabSettings,
|
|
||||||
int cursorPositionInEditor = -1) override;
|
|
||||||
void invalidateCache() override;
|
|
||||||
|
|
||||||
int indentFor(const QTextBlock &block,
|
|
||||||
const TextEditor::TabSettings &tabSettings,
|
|
||||||
int cursorPositionInEditor = -1) override;
|
|
||||||
int visualIndentFor(const QTextBlock &block,
|
|
||||||
const TextEditor::TabSettings &tabSettings) override;
|
|
||||||
TextEditor::IndentationForBlock indentationForBlocks(const QVector<QTextBlock> &blocks,
|
|
||||||
const TextEditor::TabSettings &tabSettings,
|
|
||||||
int cursorPositionInEditor = -1) override;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // Internal
|
|
||||||
} // QmlJSEditor
|
} // QmlJSEditor
|
||||||
|
Reference in New Issue
Block a user