summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/plugins/analyzerbase/analyzerutils.cpp14
-rw-r--r--src/plugins/beautifier/beautifierplugin.cpp14
-rw-r--r--src/plugins/beautifier/clangformat/clangformat.cpp5
-rw-r--r--src/plugins/clangcodemodel/clangcompletion.cpp9
-rw-r--r--src/plugins/cmakeprojectmanager/cmakeeditor.cpp13
-rw-r--r--src/plugins/cpptools/cppcompletionassist.cpp35
-rw-r--r--src/plugins/cpptools/cpppointerdeclarationformatter_test.cpp9
-rw-r--r--src/plugins/debugger/debuggerplugin.cpp9
-rw-r--r--src/plugins/debugger/sourceagent.cpp6
-rw-r--r--src/plugins/designer/qtcreatorintegration.cpp17
-rw-r--r--src/plugins/qmakeprojectmanager/qmakeprojectmanager.cpp2
-rw-r--r--src/plugins/qmljseditor/qmljscompletionassist.cpp2
-rw-r--r--src/plugins/qmljseditor/quicktoolbar.cpp15
-rw-r--r--src/plugins/texteditor/basetextdocument.cpp9
-rw-r--r--src/plugins/texteditor/basetexteditor.cpp29
-rw-r--r--src/plugins/texteditor/basetexteditor.h11
-rw-r--r--src/plugins/texteditor/circularclipboardassist.cpp3
-rw-r--r--src/plugins/texteditor/codeassist/basicproposalitem.cpp5
-rw-r--r--src/plugins/texteditor/codeassist/keywordscompletionassist.cpp8
19 files changed, 111 insertions, 104 deletions
diff --git a/src/plugins/analyzerbase/analyzerutils.cpp b/src/plugins/analyzerbase/analyzerutils.cpp
index 2aa63e184b..c26d4fa8ec 100644
--- a/src/plugins/analyzerbase/analyzerutils.cpp
+++ b/src/plugins/analyzerbase/analyzerutils.cpp
@@ -62,23 +62,15 @@ static void moveCursorToEndOfName(QTextCursor *tc)
// We cannot depend on this since CppEditor plugin code is internal and requires building the implementation files ourselves
CPlusPlus::Symbol *AnalyzerUtils::findSymbolUnderCursor()
{
- IEditor *editor = EditorManager::currentEditor();
+ TextEditor::BaseTextEditor *editor = TextEditor::BaseTextEditor::currentTextEditor();
if (!editor)
return 0;
- TextEditor::BaseTextEditor *textEditor = qobject_cast<TextEditor::BaseTextEditor *>(editor);
- if (!textEditor)
- return 0;
-
- TextEditor::BaseTextEditorWidget *editorWidget = textEditor->editorWidget();
- if (!editorWidget)
- return 0;
- QTextCursor tc;
- tc = editorWidget->textCursor();
+ QTextCursor tc = editor->textCursor();
int line = 0;
int column = 0;
const int pos = tc.position();
- editorWidget->convertPosition(pos, &line, &column);
+ editor->convertPosition(pos, &line, &column);
const CPlusPlus::Snapshot &snapshot = CppTools::CppModelManagerInterface::instance()->snapshot();
CPlusPlus::Document::Ptr doc = snapshot.document(editor->document()->filePath());
diff --git a/src/plugins/beautifier/beautifierplugin.cpp b/src/plugins/beautifier/beautifierplugin.cpp
index ba2b0c3a14..661dd63c42 100644
--- a/src/plugins/beautifier/beautifierplugin.cpp
+++ b/src/plugins/beautifier/beautifierplugin.cpp
@@ -63,6 +63,8 @@
#include <QTimer>
#include <QtPlugin>
+using namespace TextEditor;
+
namespace Beautifier {
namespace Internal {
@@ -219,9 +221,8 @@ void BeautifierPlugin::formatCurrentFile(const Command &command)
{
QPlainTextEdit *textEditor = 0;
QString filePath;
- if (TextEditor::BaseTextEditor *editor
- = qobject_cast<TextEditor::BaseTextEditor *>(Core::EditorManager::currentEditor())) {
- textEditor = qobject_cast<QPlainTextEdit *>(editor->editorWidget());
+ if (BaseTextEditor *editor = BaseTextEditor::currentTextEditor()) {
+ textEditor = editor->editorWidget();
filePath = editor->document()->filePath();
}
if (!textEditor)
@@ -284,11 +285,10 @@ void BeautifierPlugin::formatCurrentFileContinue(QObject *watcher)
QList<int> foldedBlocks;
QTextBlock block = textEditor->document()->firstBlock();
while (block.isValid()) {
- if (const TextEditor::TextBlockUserData *userdata
- = static_cast<TextEditor::TextBlockUserData *>(block.userData())) {
+ if (const TextBlockUserData *userdata = static_cast<TextBlockUserData *>(block.userData())) {
if (userdata->folded()) {
foldedBlocks << block.blockNumber();
- TextEditor::BaseTextDocumentLayout::doFoldOrUnfold(block, true);
+ BaseTextDocumentLayout::doFoldOrUnfold(block, true);
}
}
block = block.next();
@@ -386,7 +386,7 @@ void BeautifierPlugin::formatCurrentFileContinue(QObject *watcher)
for (int i = 0; i < total; ++i) {
QTextBlock block = doc->findBlockByNumber(qMax(0, foldedBlocks.at(i)));
if (block.isValid())
- TextEditor::BaseTextDocumentLayout::doFoldOrUnfold(block, false);
+ BaseTextDocumentLayout::doFoldOrUnfold(block, false);
}
textEditor->document()->setModified(true);
diff --git a/src/plugins/beautifier/clangformat/clangformat.cpp b/src/plugins/beautifier/clangformat/clangformat.cpp
index c1a90d2fe1..ac46abd6cd 100644
--- a/src/plugins/beautifier/clangformat/clangformat.cpp
+++ b/src/plugins/beautifier/clangformat/clangformat.cpp
@@ -113,12 +113,11 @@ void ClangFormat::formatFile()
void ClangFormat::formatSelectedText()
{
- TextEditor::BaseTextEditor *editor
- = qobject_cast<TextEditor::BaseTextEditor *>(Core::EditorManager::currentEditor());
+ TextEditor::BaseTextEditor *editor = TextEditor::BaseTextEditor::currentTextEditor();
if (!editor)
return;
- QTextCursor tc = editor->editorWidget()->textCursor();
+ QTextCursor tc = editor->textCursor();
if (tc.hasSelection()) {
const int offset = tc.selectionStart();
const int length = tc.selectionEnd() - offset;
diff --git a/src/plugins/clangcodemodel/clangcompletion.cpp b/src/plugins/clangcodemodel/clangcompletion.cpp
index 9fbd1d0f29..412b7f2ee8 100644
--- a/src/plugins/clangcodemodel/clangcompletion.cpp
+++ b/src/plugins/clangcodemodel/clangcompletion.cpp
@@ -456,7 +456,7 @@ void ClangAssistProposalItem::applyContextualContent(TextEditor::BaseTextEditor
// If the function doesn't return anything, automatically place the semicolon,
// unless we're doing a scope completion (then it might be function definition).
- const QChar characterAtCursor = editor->textDocument()->characterAt(editor->position());
+ const QChar characterAtCursor = editor->characterAt(editor->position());
bool endWithSemicolon = m_typedChar == QLatin1Char(';')/*
|| (function->returnType()->isVoidType() && m_completionOperator != T_COLON_COLON)*/; //###
const QChar semicolon = m_typedChar.isNull() ? QLatin1Char(';') : m_typedChar;
@@ -474,7 +474,7 @@ void ClangAssistProposalItem::applyContextualContent(TextEditor::BaseTextEditor
m_typedChar = QChar();
}
} else if (autoParenthesesEnabled) {
- const QChar lookAhead = editor->textDocument()->characterAt(editor->position() + 1);
+ const QChar lookAhead = editor->characterAt(editor->position() + 1);
if (MatchingText::shouldInsertMatchingText(lookAhead)) {
extraChars += QLatin1Char(')');
--cursorOffset;
@@ -510,8 +510,7 @@ void ClangAssistProposalItem::applyContextualContent(TextEditor::BaseTextEditor
// Avoid inserting characters that are already there
const int endsPosition = editor->position(TextEditor::BaseTextEditor::EndOfLine);
- const QString existingText = editor->textDocument()->textAt(editor->position(),
- endsPosition - editor->position());
+ const QString existingText = editor->textAt(editor->position(), endsPosition - editor->position());
int existLength = 0;
if (!existingText.isEmpty()) {
// Calculate the exist length in front of the extra chars
@@ -523,7 +522,7 @@ void ClangAssistProposalItem::applyContextualContent(TextEditor::BaseTextEditor
}
for (int i = 0; i < extraChars.length(); ++i) {
const QChar a = extraChars.at(i);
- const QChar b = editor->textDocument()->characterAt(editor->position() + i + existLength);
+ const QChar b = editor->characterAt(editor->position() + i + existLength);
if (a == b)
++extraLength;
else
diff --git a/src/plugins/cmakeprojectmanager/cmakeeditor.cpp b/src/plugins/cmakeprojectmanager/cmakeeditor.cpp
index 1257d936ef..c13e9a5435 100644
--- a/src/plugins/cmakeprojectmanager/cmakeeditor.cpp
+++ b/src/plugins/cmakeprojectmanager/cmakeeditor.cpp
@@ -105,42 +105,41 @@ void CMakeEditor::build()
QString CMakeEditor::contextHelpId() const
{
int pos = position();
- BaseTextDocument *doc = const_cast<CMakeEditor*>(this)->textDocument();
QChar chr;
do {
--pos;
if (pos < 0)
break;
- chr = doc->characterAt(pos);
+ chr = characterAt(pos);
if (chr == QLatin1Char('('))
return QString();
} while (chr.unicode() != QChar::ParagraphSeparator);
++pos;
- chr = doc->characterAt(pos);
+ chr = characterAt(pos);
while (chr.isSpace()) {
++pos;
- chr = doc->characterAt(pos);
+ chr = characterAt(pos);
}
int begin = pos;
do {
++pos;
- chr = doc->characterAt(pos);
+ chr = characterAt(pos);
} while (chr.isLetterOrNumber() || chr == QLatin1Char('_'));
int end = pos;
while (chr.isSpace()) {
++pos;
- chr = doc->characterAt(pos);
+ chr = characterAt(pos);
}
// Not a command
if (chr != QLatin1Char('('))
return QString();
- QString command = doc->textAt(begin, end - begin).toLower();
+ QString command = textAt(begin, end - begin).toLower();
return QLatin1String("command/") + command;
}
diff --git a/src/plugins/cpptools/cppcompletionassist.cpp b/src/plugins/cpptools/cppcompletionassist.cpp
index a4866da361..6f1001e191 100644
--- a/src/plugins/cpptools/cppcompletionassist.cpp
+++ b/src/plugins/cpptools/cppcompletionassist.cpp
@@ -84,15 +84,14 @@ struct CompleteFunctionDeclaration
// ---------------------
// CppAssistProposalItem
// ---------------------
-class CppAssistProposalItem : public TextEditor::BasicProposalItem
+class CppAssistProposalItem : public BasicProposalItem
{
public:
CppAssistProposalItem() :
m_isOverloaded(false) {}
bool prematurelyApplies(const QChar &c) const QTC_OVERRIDE;
- void applyContextualContent(TextEditor::BaseTextEditor *editor,
- int basePosition) const QTC_OVERRIDE;
+ void applyContextualContent(BaseTextEditor *editor, int basePosition) const QTC_OVERRIDE;
bool isOverloaded() const { return m_isOverloaded; }
void markAsOverloaded() { m_isOverloaded = true; }
@@ -164,9 +163,9 @@ bool CppAssistProposalItem::prematurelyApplies(const QChar &typedChar) const
return false;
}
-static bool isDereferenced(TextEditor::BaseTextEditor *editor, int basePosition)
+static bool isDereferenced(BaseTextEditor *editor, int basePosition)
{
- QTextCursor cursor = editor->editorWidget()->textCursor();
+ QTextCursor cursor = editor->textCursor();
cursor.setPosition(basePosition);
BackwardsScanner scanner(cursor);
@@ -184,8 +183,7 @@ static bool isDereferenced(TextEditor::BaseTextEditor *editor, int basePosition)
return false;
}
-void CppAssistProposalItem::applyContextualContent(TextEditor::BaseTextEditor *editor,
- int basePosition) const
+void CppAssistProposalItem::applyContextualContent(BaseTextEditor *editor, int basePosition) const
{
Symbol *symbol = 0;
@@ -249,7 +247,7 @@ void CppAssistProposalItem::applyContextualContent(TextEditor::BaseTextEditor *e
// If the function doesn't return anything, automatically place the semicolon,
// unless we're doing a scope completion (then it might be function definition).
- const QChar characterAtCursor = editor->textDocument()->characterAt(editor->position());
+ const QChar characterAtCursor = editor->characterAt(editor->position());
bool endWithSemicolon = m_typedChar == QLatin1Char(';')
|| (function->returnType()->isVoidType() && m_completionOperator != T_COLON_COLON);
const QChar semicolon = m_typedChar.isNull() ? QLatin1Char(';') : m_typedChar;
@@ -267,7 +265,7 @@ void CppAssistProposalItem::applyContextualContent(TextEditor::BaseTextEditor *e
m_typedChar = QChar();
}
} else if (autoParenthesesEnabled) {
- const QChar lookAhead = editor->textDocument()->characterAt(editor->position() + 1);
+ const QChar lookAhead = editor->characterAt(editor->position() + 1);
if (MatchingText::shouldInsertMatchingText(lookAhead)) {
extraChars += QLatin1Char(')');
--cursorOffset;
@@ -305,9 +303,8 @@ void CppAssistProposalItem::applyContextualContent(TextEditor::BaseTextEditor *e
// Determine the length of characters that should just be kept on the editor, but do
// not consider content that ends as an identifier (which could be undesired).
- const int lineEnd = editor->position(TextEditor::BaseTextEditor::EndOfLine);
- const QString inEditor = editor->textDocument()->textAt(editor->position(),
- lineEnd - editor->position());
+ const int lineEnd = editor->position(BaseTextEditor::EndOfLine);
+ const QString inEditor = editor->textAt(editor->position(), lineEnd - editor->position());
int preserveLength = 0;
if (!inEditor.isEmpty()) {
preserveLength = toInsert.length() - (editor->position() - basePosition);
@@ -324,7 +321,7 @@ void CppAssistProposalItem::applyContextualContent(TextEditor::BaseTextEditor *e
for (int i = 0; i < extraChars.length(); ++i) {
const QChar a = extraChars.at(i);
- const QChar b = editor->textDocument()->characterAt(editor->position() + i + preserveLength);
+ const QChar b = editor->characterAt(editor->position() + i + preserveLength);
if (a == b)
++extraLength;
else
@@ -344,7 +341,7 @@ void CppAssistProposalItem::applyContextualContent(TextEditor::BaseTextEditor *e
// --------------------
// CppFunctionHintModel
// --------------------
-class CppFunctionHintModel : public TextEditor::IFunctionHintProposalModel
+class CppFunctionHintModel : public IFunctionHintProposalModel
{
public:
CppFunctionHintModel(QList<Function *> functionSymbols,
@@ -420,9 +417,9 @@ IAssistProcessor *InternalCompletionAssistProvider::createProcessor() const
return new CppCompletionAssistProcessor;
}
-TextEditor::IAssistInterface *InternalCompletionAssistProvider::createAssistInterface(
+IAssistInterface *InternalCompletionAssistProvider::createAssistInterface(
ProjectExplorer::Project *project, const QString &filePath, QTextDocument *document,
- bool isObjCEnabled, int position, TextEditor::AssistReason reason) const
+ bool isObjCEnabled, int position, AssistReason reason) const
{
Q_UNUSED(project);
QTC_ASSERT(document, return 0);
@@ -436,11 +433,11 @@ TextEditor::IAssistInterface *InternalCompletionAssistProvider::createAssistInte
// -----------------
// CppAssistProposal
// -----------------
-class CppAssistProposal : public TextEditor::GenericProposal
+class CppAssistProposal : public GenericProposal
{
public:
- CppAssistProposal(int cursorPos, TextEditor::IGenericProposalModel *model)
- : TextEditor::GenericProposal(cursorPos, model)
+ CppAssistProposal(int cursorPos, IGenericProposalModel *model)
+ : GenericProposal(cursorPos, model)
, m_replaceDotForArrow(static_cast<CppAssistProposalModel *>(model)->m_replaceDotForArrow)
{}
diff --git a/src/plugins/cpptools/cpppointerdeclarationformatter_test.cpp b/src/plugins/cpptools/cpppointerdeclarationformatter_test.cpp
index 767192982b..b922727983 100644
--- a/src/plugins/cpptools/cpppointerdeclarationformatter_test.cpp
+++ b/src/plugins/cpptools/cpppointerdeclarationformatter_test.cpp
@@ -104,19 +104,18 @@ public:
// Open file
TextEditor::BaseTextEditor *editor = TextEditor::PlainTextEditorFactory::createPlainTextEditor();
- TextEditor::BaseTextEditorWidget *editorWidget = editor->editorWidget();
QString error;
editor->open(&error, document->fileName(), document->fileName());
QVERIFY(error.isEmpty());
// Set cursor position
- QTextCursor cursor = editorWidget->textCursor();
+ QTextCursor cursor = editor->textCursor();
cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::MoveAnchor, cursorPosition);
- editorWidget->setTextCursor(cursor);
+ editor->setTextCursor(cursor);
- QTextDocument *qtextDocument = editorWidget->document();
+ QTextDocument *qtextDocument = editor->qdocument();
CppRefactoringFilePtr cppRefactoringFile
- = CppRefactoringChanges::file(editorWidget, document);
+ = CppRefactoringChanges::file(editor->editorWidget(), document);
// Prepare for formatting
Overview overview;
diff --git a/src/plugins/debugger/debuggerplugin.cpp b/src/plugins/debugger/debuggerplugin.cpp
index 17c538996b..36600aff11 100644
--- a/src/plugins/debugger/debuggerplugin.cpp
+++ b/src/plugins/debugger/debuggerplugin.cpp
@@ -1030,9 +1030,7 @@ public slots:
{
BaseTextEditor *textEditor = BaseTextEditor::currentTextEditor();
QTC_ASSERT(textEditor, return);
- QPlainTextEdit *ed = textEditor->editorWidget();
- QTC_ASSERT(ed, return);
- QTextCursor cursor = ed->textCursor();
+ QTextCursor cursor = textEditor->textCursor();
QString functionName = cursor.selectedText();
if (functionName.isEmpty()) {
const QTextBlock block = cursor.block();
@@ -1098,11 +1096,10 @@ public slots:
void handleAddToWatchWindow()
{
// Requires a selection, but that's the only case we want anyway.
- IEditor *editor = EditorManager::currentEditor();
- BaseTextEditor *textEditor = qobject_cast<BaseTextEditor*>(editor);
+ BaseTextEditor *textEditor = BaseTextEditor::currentTextEditor();
if (!textEditor)
return;
- QTextCursor tc = textEditor->editorWidget()->textCursor();
+ QTextCursor tc = textEditor->textCursor();
QString exp;
if (tc.hasSelection()) {
exp = tc.selectedText();
diff --git a/src/plugins/debugger/sourceagent.cpp b/src/plugins/debugger/sourceagent.cpp
index 9d3a86bb77..7d2b6b2ead 100644
--- a/src/plugins/debugger/sourceagent.cpp
+++ b/src/plugins/debugger/sourceagent.cpp
@@ -146,12 +146,10 @@ void SourceAgent::updateLocationMarker()
d->locationMark->setIcon(debuggerCore()->locationMarkIcon());
d->locationMark->setPriority(TextEditor::TextMark::HighPriority);
d->editor->textDocument()->addMark(d->locationMark);
- QPlainTextEdit *plainTextEdit = d->editor->editorWidget();
- QTC_ASSERT(plainTextEdit, return);
- QTextCursor tc = plainTextEdit->textCursor();
+ QTextCursor tc = d->editor->textCursor();
QTextBlock block = tc.document()->findBlockByNumber(lineNumber - 1);
tc.setPosition(block.position());
- plainTextEdit->setTextCursor(tc);
+ d->editor->setTextCursor(tc);
EditorManager::activateEditor(d->editor);
}
}
diff --git a/src/plugins/designer/qtcreatorintegration.cpp b/src/plugins/designer/qtcreatorintegration.cpp
index c0fc2b8348..d00064ba3a 100644
--- a/src/plugins/designer/qtcreatorintegration.cpp
+++ b/src/plugins/designer/qtcreatorintegration.cpp
@@ -289,16 +289,13 @@ static void addDeclaration(const Snapshot &snapshot,
//
if (BaseTextEditor *editor = editorAt(fileName, loc.line(), loc.column() - 1)) {
- BaseTextEditorWidget *widget = editor->editorWidget();
- if (widget) {
- QTextCursor tc = widget->textCursor();
- int pos = tc.position();
- tc.beginEditBlock();
- tc.insertText(loc.prefix() + declaration + loc.suffix());
- tc.setPosition(pos, QTextCursor::KeepAnchor);
- widget->textDocument()->autoIndent(tc);
- tc.endEditBlock();
- }
+ QTextCursor tc = editor->textCursor();
+ int pos = tc.position();
+ tc.beginEditBlock();
+ tc.insertText(loc.prefix() + declaration + loc.suffix());
+ tc.setPosition(pos, QTextCursor::KeepAnchor);
+ editor->textDocument()->autoIndent(tc);
+ tc.endEditBlock();
}
}
diff --git a/src/plugins/qmakeprojectmanager/qmakeprojectmanager.cpp b/src/plugins/qmakeprojectmanager/qmakeprojectmanager.cpp
index 7ae586bd1c..7e8d973c51 100644
--- a/src/plugins/qmakeprojectmanager/qmakeprojectmanager.cpp
+++ b/src/plugins/qmakeprojectmanager/qmakeprojectmanager.cpp
@@ -162,7 +162,7 @@ void QmakeManager::addLibrary(const QString &fileName, BaseTextEditor *editor)
// add extra \n in case the last line is not empty
int line, column;
editor->convertPosition(endOfDoc, &line, &column);
- if (!editor->textDocument()->textAt(endOfDoc - column, column).simplified().isEmpty())
+ if (!editor->textAt(endOfDoc - column, column).simplified().isEmpty())
snippet = QLatin1Char('\n') + snippet;
editor->insert(snippet);
diff --git a/src/plugins/qmljseditor/qmljscompletionassist.cpp b/src/plugins/qmljseditor/qmljscompletionassist.cpp
index a3eebd02de..b0e01b8c01 100644
--- a/src/plugins/qmljseditor/qmljscompletionassist.cpp
+++ b/src/plugins/qmljseditor/qmljscompletionassist.cpp
@@ -377,7 +377,7 @@ void QmlJSAssistProposalItem::applyContextualContent(TextEditor::BaseTextEditor
int replacedLength = 0;
for (int i = 0; i < replaceable.length(); ++i) {
const QChar a = replaceable.at(i);
- const QChar b = editor->textDocument()->characterAt(editor->position() + i);
+ const QChar b = editor->characterAt(editor->position() + i);
if (a == b)
++replacedLength;
else
diff --git a/src/plugins/qmljseditor/quicktoolbar.cpp b/src/plugins/qmljseditor/quicktoolbar.cpp
index 416a47a9a2..f4a39733c0 100644
--- a/src/plugins/qmljseditor/quicktoolbar.cpp
+++ b/src/plugins/qmljseditor/quicktoolbar.cpp
@@ -208,15 +208,16 @@ void QuickToolBar::apply(TextEditor::BaseTextEditor *editor, Document::Ptr docum
if (contextWidget()->acceptsType(m_prototypes)) {
m_node = 0;
PropertyReader propertyReader(document, initializer);
- QTextCursor tc(editor->editorWidget()->document());
+ QTextCursor tc = editor->textCursor();
+ QPlainTextEdit *editorWidget = editor->editorWidget();
tc.setPosition(offset);
- QPoint p1 = editor->editorWidget()->mapToParent(editor->editorWidget()->viewport()->mapToParent(editor->editorWidget()->cursorRect(tc).topLeft()) - QPoint(0, contextWidget()->height() + 10));
+ QPoint p1 = editorWidget->mapToParent(editorWidget->viewport()->mapToParent(editorWidget->cursorRect(tc).topLeft()) - QPoint(0, contextWidget()->height() + 10));
tc.setPosition(end);
- QPoint p2 = editor->editorWidget()->mapToParent(editor->editorWidget()->viewport()->mapToParent(editor->editorWidget()->cursorRect(tc).bottomLeft()) + QPoint(0, 10));
+ QPoint p2 = editorWidget->mapToParent(editorWidget->viewport()->mapToParent(editorWidget->cursorRect(tc).bottomLeft()) + QPoint(0, 10));
QPoint offset = QPoint(10, 0);
if (reg.boundingRect().width() < 400)
offset = QPoint(400 - reg.boundingRect().width() + 10 ,0);
- QPoint p3 = editor->editorWidget()->mapToParent(editor->editorWidget()->viewport()->mapToParent(reg.boundingRect().topRight()) + offset);
+ QPoint p3 = editorWidget->mapToParent(editorWidget->viewport()->mapToParent(reg.boundingRect().topRight()) + offset);
p2.setX(p1.x());
contextWidget()->setIsPropertyChanges(isPropertyChanges);
if (!update)
@@ -387,7 +388,7 @@ void QuickToolBar::onPropertyRemovedAndChange(const QString &remove, const QStri
if (!m_doc)
return;
- QTextCursor tc(m_editor->editorWidget()->document());
+ QTextCursor tc = m_editor->textCursor();
tc.beginEditBlock();
if (removeFirst) {
@@ -425,11 +426,11 @@ void QuickToolBar::indentLines(int startLine, int endLine)
if (startLine > 0) {
TextEditor::TabSettings tabSettings = m_editor->textDocument()->tabSettings();
for (int i = startLine; i <= endLine; i++) {
- QTextBlock start = m_editor->editorWidget()->document()->findBlockByNumber(i);
+ QTextBlock start = m_editor->qdocument()->findBlockByNumber(i);
if (start.isValid()) {
QmlJSEditor::Internal::Indenter indenterMy;
- indenterMy.indentBlock(m_editor->editorWidget()->document(), start, QChar::Null, tabSettings);
+ indenterMy.indentBlock(m_editor->qdocument(), start, QChar::Null, tabSettings);
}
}
}
diff --git a/src/plugins/texteditor/basetextdocument.cpp b/src/plugins/texteditor/basetextdocument.cpp
index 7dff24a47c..34b7619068 100644
--- a/src/plugins/texteditor/basetextdocument.cpp
+++ b/src/plugins/texteditor/basetextdocument.cpp
@@ -442,11 +442,10 @@ bool BaseTextDocument::save(QString *errorString, const QString &saveFileName, b
// When saving the current editor, make sure to maintain the cursor and scroll bar
// positions for undo
- IEditor *currentEditor = EditorManager::currentEditor();
- if (BaseTextEditor *editable = qobject_cast<BaseTextEditor*>(currentEditor)) {
- if (editable->document() == this) {
- editorWidget = editable->editorWidget();
- QTextCursor cur = editorWidget->textCursor();
+ if (BaseTextEditor *editor = BaseTextEditor::currentTextEditor()) {
+ if (editor->document() == this) {
+ editorWidget = editor->editorWidget();
+ QTextCursor cur = editor->textCursor();
savedPosition = cur.position();
savedAnchor = cur.anchor();
savedVScrollBarValue = editorWidget->verticalScrollBar()->value();
diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp
index c7bcbe5371..c43d8ea430 100644
--- a/src/plugins/texteditor/basetexteditor.cpp
+++ b/src/plugins/texteditor/basetexteditor.cpp
@@ -6590,7 +6590,7 @@ BaseTextEditor::~BaseTextEditor()
delete d;
}
-BaseTextDocument *BaseTextEditor::textDocument()
+BaseTextDocument *BaseTextEditor::textDocument() const
{
ensureDocument();
return editorWidget()->textDocument();
@@ -7081,6 +7081,31 @@ BaseTextEditorWidget *BaseTextEditor::editorWidget() const
return static_cast<BaseTextEditorWidget *>(m_widget.data());
}
+QTextDocument *BaseTextEditor::qdocument() const
+{
+ return textDocument()->document();
+}
+
+void BaseTextEditor::setTextCursor(const QTextCursor &cursor)
+{
+ editorWidget()->setTextCursor(cursor);
+}
+
+QTextCursor BaseTextEditor::textCursor() const
+{
+ return editorWidget()->textCursor();
+}
+
+QChar BaseTextEditor::characterAt(int pos) const
+{
+ return textDocument()->characterAt(pos);
+}
+
+QString BaseTextEditor::textAt(int from, int to) const
+{
+ return textDocument()->textAt(from, to);
+}
+
void BaseTextEditorWidget::configureMimeType(const QString &mimeType)
{
configureMimeType(MimeDatabase::findByType(mimeType));
@@ -7186,7 +7211,7 @@ BaseTextEditorWidget *BaseTextEditor::ensureWidget() const
return editorWidget();
}
-BaseTextDocumentPtr BaseTextEditor::ensureDocument()
+BaseTextDocumentPtr BaseTextEditor::ensureDocument() const
{
BaseTextEditorWidget *widget = ensureWidget();
if (widget->d->m_document.isNull()) {
diff --git a/src/plugins/texteditor/basetexteditor.h b/src/plugins/texteditor/basetexteditor.h
index ed002ad325..e8e42da422 100644
--- a/src/plugins/texteditor/basetexteditor.h
+++ b/src/plugins/texteditor/basetexteditor.h
@@ -140,10 +140,17 @@ public:
static BaseTextEditor *currentTextEditor();
BaseTextEditorWidget *ensureWidget() const;
- BaseTextDocumentPtr ensureDocument();
+ BaseTextDocumentPtr ensureDocument() const;
BaseTextEditorWidget *editorWidget() const;
- BaseTextDocument *textDocument();
+ BaseTextDocument *textDocument() const;
+
+ // Some convenience text access
+ QTextDocument *qdocument() const;
+ void setTextCursor(const QTextCursor &cursor);
+ QTextCursor textCursor() const;
+ QChar characterAt(int pos) const;
+ QString textAt(int from, int to) const;
void addContext(Core::Id id);
diff --git a/src/plugins/texteditor/circularclipboardassist.cpp b/src/plugins/texteditor/circularclipboardassist.cpp
index e188f527ab..07e65efa21 100644
--- a/src/plugins/texteditor/circularclipboardassist.cpp
+++ b/src/plugins/texteditor/circularclipboardassist.cpp
@@ -66,7 +66,6 @@ public:
void apply(BaseTextEditor *editor, int /*basePosition*/) const QTC_OVERRIDE
{
- BaseTextEditorWidget *editwidget = editor->editorWidget();
//Move to last in circular clipboard
if (CircularClipboard * clipboard = CircularClipboard::instance()) {
@@ -79,7 +78,7 @@ public:
BaseTextEditorWidget::duplicateMimeData(m_mimeData.data()));
//Paste
- editwidget->paste();
+ editor->editorWidget()->paste();
}
private:
diff --git a/src/plugins/texteditor/codeassist/basicproposalitem.cpp b/src/plugins/texteditor/codeassist/basicproposalitem.cpp
index 85010d1069..b92957bfa1 100644
--- a/src/plugins/texteditor/codeassist/basicproposalitem.cpp
+++ b/src/plugins/texteditor/codeassist/basicproposalitem.cpp
@@ -123,10 +123,9 @@ void BasicProposalItem::applyContextualContent(BaseTextEditor *editor, int baseP
void BasicProposalItem::applySnippet(BaseTextEditor *editor, int basePosition) const
{
- BaseTextEditorWidget *editorWidget = editor->editorWidget();
- QTextCursor tc = editorWidget->textCursor();
+ QTextCursor tc = editor->textCursor();
tc.setPosition(basePosition, QTextCursor::KeepAnchor);
- editorWidget->insertCodeSnippet(tc, data().toString());
+ editor->editorWidget()->insertCodeSnippet(tc, data().toString());
}
void BasicProposalItem::applyQuickFix(BaseTextEditor *editor, int basePosition) const
diff --git a/src/plugins/texteditor/codeassist/keywordscompletionassist.cpp b/src/plugins/texteditor/codeassist/keywordscompletionassist.cpp
index 67b5a0bae5..961fd51031 100644
--- a/src/plugins/texteditor/codeassist/keywordscompletionassist.cpp
+++ b/src/plugins/texteditor/codeassist/keywordscompletionassist.cpp
@@ -109,10 +109,10 @@ void KeywordsAssistProposalItem::applyContextualContent(TextEditor::BaseTextEdit
int cursorOffset = 0;
if (m_keywords.isFunction(toInsert) && settings.m_autoInsertBrackets) {
if (settings.m_spaceAfterFunctionName) {
- if (editor->textDocument()->textAt(editor->position(), 2) == QLatin1String(" (")) {
+ if (editor->textAt(editor->position(), 2) == QLatin1String(" (")) {
cursorOffset = 2;
- } else if (editor->textDocument()->characterAt(editor->position()) == QLatin1Char('(')
- || editor->textDocument()->characterAt(editor->position()) == QLatin1Char(' ')) {
+ } else if (editor->characterAt(editor->position()) == QLatin1Char('(')
+ || editor->characterAt(editor->position()) == QLatin1Char(' ')) {
replaceLength += 1;
toInsert += QLatin1String(" (");
} else {
@@ -120,7 +120,7 @@ void KeywordsAssistProposalItem::applyContextualContent(TextEditor::BaseTextEdit
cursorOffset = -1;
}
} else {
- if (editor->textDocument()->characterAt(editor->position()) == QLatin1Char('(')) {
+ if (editor->characterAt(editor->position()) == QLatin1Char('(')) {
cursorOffset = 1;
} else {
toInsert += QLatin1String("()");