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:
@@ -64,7 +64,7 @@ TextEditor::CodeStyleEditorWidget *QmlJSCodeStylePreferencesFactory::createEdito
|
||||
|
||||
TextEditor::Indenter *QmlJSCodeStylePreferencesFactory::createIndenter(QTextDocument *doc) const
|
||||
{
|
||||
return new QmlJSEditor::Internal::Indenter(doc);
|
||||
return QmlJSEditor::createQmlJsIndenter(doc);
|
||||
}
|
||||
|
||||
QString QmlJSCodeStylePreferencesFactory::snippetProviderGroupId() const
|
||||
|
||||
@@ -6,30 +6,47 @@
|
||||
#include <qmljstools/qmljsqtstylecodeformatter.h>
|
||||
#include <texteditor/tabsettings.h>
|
||||
|
||||
#include <QChar>
|
||||
#include <QTextDocument>
|
||||
#include <QTextBlock>
|
||||
|
||||
using namespace QmlJSEditor;
|
||||
using namespace Internal;
|
||||
using namespace TextEditor;
|
||||
|
||||
Indenter::Indenter(QTextDocument *doc)
|
||||
: TextEditor::TextIndenter(doc)
|
||||
{}
|
||||
namespace QmlJSEditor {
|
||||
namespace Internal {
|
||||
|
||||
Indenter::~Indenter() = default;
|
||||
|
||||
bool Indenter::isElectricCharacter(const QChar &ch) const
|
||||
class QmlJsIndenter final : public TextEditor::TextIndenter
|
||||
{
|
||||
if (ch == QLatin1Char('{')
|
||||
|| ch == QLatin1Char('}')
|
||||
|| ch == QLatin1Char(']')
|
||||
|| ch == QLatin1Char(':'))
|
||||
return true;
|
||||
return false;
|
||||
public:
|
||||
explicit QmlJsIndenter(QTextDocument *doc)
|
||||
: TextEditor::TextIndenter(doc)
|
||||
{}
|
||||
|
||||
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 TextEditor::TabSettings &tabSettings,
|
||||
int /*cursorPositionInEditor*/)
|
||||
@@ -52,13 +69,13 @@ void Indenter::indentBlock(const QTextBlock &block,
|
||||
tabSettings.indentLine(block, depth);
|
||||
}
|
||||
|
||||
void Indenter::invalidateCache()
|
||||
void QmlJsIndenter::invalidateCache()
|
||||
{
|
||||
QmlJSTools::CreatorCodeFormatter codeFormatter;
|
||||
codeFormatter.invalidateCache(m_doc);
|
||||
}
|
||||
|
||||
int Indenter::indentFor(const QTextBlock &block,
|
||||
int QmlJsIndenter::indentFor(const QTextBlock &block,
|
||||
const TextEditor::TabSettings &tabSettings,
|
||||
int /*cursorPositionInEditor*/)
|
||||
{
|
||||
@@ -67,12 +84,12 @@ int Indenter::indentFor(const QTextBlock &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);
|
||||
}
|
||||
|
||||
TextEditor::IndentationForBlock Indenter::indentationForBlocks(
|
||||
TextEditor::IndentationForBlock QmlJsIndenter::indentationForBlocks(
|
||||
const QVector<QTextBlock> &blocks,
|
||||
const TextEditor::TabSettings &tabSettings,
|
||||
int /*cursorPositionInEditor*/)
|
||||
@@ -86,3 +103,31 @@ TextEditor::IndentationForBlock Indenter::indentationForBlocks(
|
||||
ret.insert(block.blockNumber(), codeFormatter.indentFor(block));
|
||||
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>
|
||||
|
||||
namespace QmlJSEditor {
|
||||
namespace Internal {
|
||||
|
||||
class QMLJSTOOLS_EXPORT Indenter : public TextEditor::TextIndenter
|
||||
{
|
||||
public:
|
||||
explicit Indenter(QTextDocument *doc);
|
||||
~Indenter() override;
|
||||
QMLJSTOOLS_EXPORT TextEditor::TextIndenter *createQmlJsIndenter(QTextDocument *doc);
|
||||
|
||||
bool isElectricCharacter(const QChar &ch) const override;
|
||||
void indentBlock(const QTextBlock &block,
|
||||
const QChar &typedChar,
|
||||
const TextEditor::TabSettings &tabSettings,
|
||||
int cursorPositionInEditor = -1) override;
|
||||
void invalidateCache() override;
|
||||
QMLJSTOOLS_EXPORT void indentQmlJs(QTextDocument *doc, int startLine, int endLine,
|
||||
const TextEditor::TabSettings &tabSettings);
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user