forked from qt-creator/qt-creator
Refactor: Get rid of BaseTextEditorWidget from Indenter
Provide directly TabSettings instead. This will be used for indenting a text for which there is no editor instance. Change-Id: Ia5f11a481f42464cf4820efdf2c7c4c32166f55e Reviewed-on: http://codereview.qt.nokia.com/2622 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Leandro T. C. Melo <leandro.melo@nokia.com>
This commit is contained in:
@@ -31,9 +31,11 @@
|
||||
**************************************************************************/
|
||||
|
||||
#include "indenter.h"
|
||||
#include "basetexteditor.h"
|
||||
#include "tabsettings.h"
|
||||
|
||||
#include <QtGui/QTextDocument>
|
||||
#include <QtGui/QTextCursor>
|
||||
|
||||
using namespace TextEditor;
|
||||
|
||||
Indenter::Indenter()
|
||||
@@ -50,60 +52,58 @@ bool Indenter::isElectricCharacter(const QChar &) const
|
||||
void Indenter::indentBlock(QTextDocument *doc,
|
||||
const QTextBlock &block,
|
||||
const QChar &typedChar,
|
||||
BaseTextEditorWidget *editor)
|
||||
const TextEditor::TabSettings &tabSettings)
|
||||
{
|
||||
Q_UNUSED(doc);
|
||||
Q_UNUSED(block);
|
||||
Q_UNUSED(typedChar);
|
||||
Q_UNUSED(editor);
|
||||
Q_UNUSED(tabSettings);
|
||||
}
|
||||
|
||||
void Indenter::indent(QTextDocument *doc,
|
||||
const QTextCursor &cursor,
|
||||
const QChar &typedChar,
|
||||
BaseTextEditorWidget *editor)
|
||||
const TextEditor::TabSettings &tabSettings)
|
||||
{
|
||||
if (cursor.hasSelection()) {
|
||||
QTextBlock block = doc->findBlock(cursor.selectionStart());
|
||||
const QTextBlock end = doc->findBlock(cursor.selectionEnd()).next();
|
||||
do {
|
||||
indentBlock(doc, block, typedChar, editor);
|
||||
indentBlock(doc, block, typedChar, tabSettings);
|
||||
block = block.next();
|
||||
} while (block.isValid() && block != end);
|
||||
} else {
|
||||
indentBlock(doc, cursor.block(), typedChar, editor);
|
||||
indentBlock(doc, cursor.block(), typedChar, tabSettings);
|
||||
}
|
||||
}
|
||||
|
||||
void Indenter::reindent(QTextDocument *doc, const QTextCursor &cursor, BaseTextEditorWidget *editor)
|
||||
void Indenter::reindent(QTextDocument *doc, const QTextCursor &cursor, const TextEditor::TabSettings &tabSettings)
|
||||
{
|
||||
if (cursor.hasSelection()) {
|
||||
QTextBlock block = doc->findBlock(cursor.selectionStart());
|
||||
const QTextBlock end = doc->findBlock(cursor.selectionEnd()).next();
|
||||
|
||||
const TabSettings &ts = editor->tabSettings();
|
||||
|
||||
// skip empty blocks
|
||||
while (block.isValid() && block != end) {
|
||||
QString bt = block.text();
|
||||
if (ts.firstNonSpace(bt) < bt.size())
|
||||
if (tabSettings.firstNonSpace(bt) < bt.size())
|
||||
break;
|
||||
indentBlock(doc, block, QChar::Null, editor);
|
||||
indentBlock(doc, block, QChar::Null, tabSettings);
|
||||
block = block.next();
|
||||
}
|
||||
|
||||
int previousIndentation = ts.indentationColumn(block.text());
|
||||
indentBlock(doc, block, QChar::Null, editor);
|
||||
int currentIndentation = ts.indentationColumn(block.text());
|
||||
int previousIndentation = tabSettings.indentationColumn(block.text());
|
||||
indentBlock(doc, block, QChar::Null, tabSettings);
|
||||
int currentIndentation = tabSettings.indentationColumn(block.text());
|
||||
int delta = currentIndentation - previousIndentation;
|
||||
|
||||
block = block.next();
|
||||
while (block.isValid() && block != end) {
|
||||
ts.reindentLine(block, delta);
|
||||
tabSettings.reindentLine(block, delta);
|
||||
block = block.next();
|
||||
}
|
||||
} else {
|
||||
indentBlock(doc, cursor.block(), QChar::Null, editor);
|
||||
indentBlock(doc, cursor.block(), QChar::Null, tabSettings);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user