Commit 98fd59fd authored by hjk's avatar hjk

TextEditor: Start moving data from *EditorWidget to *Editor

Goal is to consolidate "controller" related data in the *Editor hierarchy.
This patch introduces temporary "cross-Private" accessors dd() to
keep the patches small.

First item moved is the AutoCompleter, a glimps at long term benefits
is the simplification in the JavaEditorWidget which is now essentially
a BaseTextEditorWidget, only containing the still-wrong createEditor().
But that can only be move if the *Editors are self-contained, i.e.
keep data themselves, not indirectly through the *EditorWidgets.

Change-Id: Ia0ab90f0322bb17ac20458e6581069eed30acbaf
Reviewed-by: default avatarChristian Stenger <christian.stenger@digia.com>
Reviewed-by: default avatarhjk <hjk121@nokiamail.com>
parent 9fd2fe5a
......@@ -57,6 +57,7 @@ JavaEditor::JavaEditor(JavaEditorWidget *editor)
setDuplicateSupported(true);
setCommentStyle(Utils::CommentDefinition::CppStyle);
setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<JavaCompletionAssistProvider>());
setAutoCompleter(new JavaAutoCompleter);
}
Core::IEditor *JavaEditor::duplicate()
......@@ -74,18 +75,11 @@ Core::IEditor *JavaEditor::duplicate()
JavaEditorWidget::JavaEditorWidget(QWidget *parent)
: BaseTextEditorWidget(new JavaDocument(), parent)
{
ctor();
}
JavaEditorWidget::JavaEditorWidget(JavaEditorWidget *other)
: BaseTextEditorWidget(other)
{
ctor();
}
void JavaEditorWidget::ctor()
{
setAutoCompleter(new JavaAutoCompleter);
}
TextEditor::BaseTextEditor *JavaEditorWidget::createEditor()
......
......@@ -64,7 +64,6 @@ protected:
private:
JavaEditorWidget(BaseTextEditorWidget *); // avoid stupidity
void ctor();
};
class JavaDocument : public TextEditor::BaseTextDocument
......
......@@ -253,7 +253,7 @@ bool CppDocumentationCommentHelper::handleKeyPressEvent(QKeyEvent *e) const
if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) {
QTextCursor cursor = m_editorWidget->textCursor();
if (!m_editorWidget->autoCompleter()->isInComment(cursor))
if (!m_editorWidget->editor()->autoCompleter()->isInComment(cursor))
return false;
// We are interested on two particular cases:
......
......@@ -117,6 +117,7 @@ CPPEditor::CPPEditor(CppEditorWidget *editor)
setCompletionAssistProvider([this] () -> TextEditor::CompletionAssistProvider * {
return CppModelManagerInterface::instance()->cppEditorSupport(this)->completionAssistProvider();
});
setAutoCompleter(new CppAutoCompleter);
}
Q_GLOBAL_STATIC(CppTools::SymbolFinder, symbolFinder)
......@@ -197,7 +198,6 @@ void CppEditorWidget::ctor()
setParenthesesMatchingEnabled(true);
setMarksVisible(true);
setCodeFoldingSupported(true);
setAutoCompleter(new CppAutoCompleter);
if (d->m_modelManager) {
CppEditorSupport *editorSupport = d->m_modelManager->cppEditorSupport(editor());
......
......@@ -64,5 +64,5 @@ void CppSnippetProvider::decorateEditor(TextEditor::SnippetEditorWidget *editor)
{
editor->setSyntaxHighlighter(new CppHighlighter);
editor->baseTextDocument()->setIndenter(new CppTools::CppQtStyleIndenter);
editor->setAutoCompleter(new CppAutoCompleter);
editor->editor()->setAutoCompleter(new CppAutoCompleter);
}
......@@ -33,7 +33,6 @@
#include "glsleditorplugin.h"
#include "glslhighlighter.h"
#include "glslautocompleter.h"
#include "glslindenter.h"
#include "glslcompletionassist.h"
#include <glsl/glsllexer.h>
......@@ -160,7 +159,6 @@ void GlslEditorWidget::ctor()
setParenthesesMatchingEnabled(true);
setMarksVisible(true);
setCodeFoldingSupported(true);
setAutoCompleter(new GLSLCompleter());
m_updateDocumentTimer = new QTimer(this);
m_updateDocumentTimer->setInterval(UPDATE_DOCUMENT_DEFAULT_INTERVAL);
......
......@@ -30,6 +30,7 @@
#include "glsleditoreditable.h"
#include "glsleditorconstants.h"
#include "glslcompletionassist.h"
#include "glslautocompleter.h"
#include <texteditor/texteditorconstants.h>
......@@ -48,6 +49,7 @@ GlslEditor::GlslEditor(GlslEditorWidget *editor)
setDuplicateSupported(true);
setCommentStyle(Utils::CommentDefinition::CppStyle);
setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<GLSLCompletionAssistProvider>());
setAutoCompleter(new GLSLCompleter);
}
} // namespace Internal
......
......@@ -35,7 +35,6 @@
#include "qmljseditorplugin.h"
#include "qmloutlinemodel.h"
#include "qmljsfindreferences.h"
#include "qmljsautocompleter.h"
#include "qmljscompletionassist.h"
#include "qmljsquickfixassist.h"
......@@ -120,7 +119,6 @@ void QmlJSTextEditorWidget::ctor()
setParenthesesMatchingEnabled(true);
setMarksVisible(true);
setCodeFoldingSupported(true);
setAutoCompleter(new AutoCompleter);
setLanguageSettingsId(QmlJSTools::Constants::QML_JS_SETTINGS_ID);
m_updateUsesTimer = new QTimer(this);
......
......@@ -31,6 +31,7 @@
#include "qmljseditor.h"
#include "qmljseditorconstants.h"
#include "qmljscompletionassist.h"
#include "qmljsautocompleter.h"
#include <qmljstools/qmljstoolsconstants.h>
#include <texteditor/texteditorconstants.h>
......@@ -56,6 +57,7 @@ QmlJSEditor::QmlJSEditor(QmlJSTextEditorWidget *editor)
setDuplicateSupported(true);
setCommentStyle(Utils::CommentDefinition::CppStyle);
setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<Internal::QmlJSCompletionAssistProvider>());
setAutoCompleter(new AutoCompleter);
}
bool QmlJSEditor::isDesignModePreferred() const
......
......@@ -66,5 +66,5 @@ void QmlJSSnippetProvider::decorateEditor(TextEditor::SnippetEditorWidget *edito
{
editor->setSyntaxHighlighter(new Highlighter);
editor->baseTextDocument()->setIndenter(new Indenter);
editor->setAutoCompleter(new AutoCompleter);
editor->editor()->setAutoCompleter(new AutoCompleter);
}
......@@ -188,6 +188,9 @@ private:
class BaseTextEditorPrivate
{
public:
BaseTextEditorPrivate()
{}
// Note: This is always a copy of IContext::m_widget.
BaseTextEditorWidget *m_editorWidget;
......@@ -199,6 +202,7 @@ public:
Utils::LineColumnLabel *m_fileEncodingLabel;
CommentDefinition m_commentDefinition;
std::function<CompletionAssistProvider *()> m_completionAssistProvider;
QScopedPointer<AutoCompleter> m_autoCompleter;
};
class BaseTextEditorWidgetPrivate
......@@ -209,6 +213,9 @@ class BaseTextEditorWidgetPrivate
public:
BaseTextEditorWidgetPrivate(BaseTextEditorWidget *parent);
// FIXME: Remove after relevant members have been moved to BaseTextEditorPrivate
BaseTextEditorPrivate *dd() { return q->editor()->d; }
void setupDocumentSignals();
void updateLineSelectionColor();
......@@ -364,8 +371,6 @@ public:
QPoint m_markDragStart;
bool m_markDragging;
QScopedPointer<AutoCompleter> m_autoCompleter;
QScopedPointer<Internal::ClipboardAssistProvider> m_clipboardAssistProvider;
bool m_isMissingSyntaxDefinition;
......@@ -1892,7 +1897,7 @@ void BaseTextEditorWidget::keyPressEvent(QKeyEvent *e)
cursor.beginEditBlock();
int extraBlocks =
d->m_autoCompleter->paragraphSeparatorAboutToBeInserted(cursor,
dd()->m_autoCompleter->paragraphSeparatorAboutToBeInserted(cursor,
d->m_document->tabSettings());
QString previousIndentationString;
......@@ -2092,16 +2097,17 @@ void BaseTextEditorWidget::keyPressEvent(QKeyEvent *e)
case Qt::Key_Insert:
if (ro) break;
if (e->modifiers() == Qt::NoModifier) {
AutoCompleter *ac = dd()->m_autoCompleter.data();
if (inOverwriteMode) {
d->m_autoCompleter->setAutoParenthesesEnabled(d->autoParenthesisOverwriteBackup);
d->m_autoCompleter->setSurroundWithEnabled(d->surroundWithEnabledOverwriteBackup);
ac->setAutoParenthesesEnabled(d->autoParenthesisOverwriteBackup);
ac->setSurroundWithEnabled(d->surroundWithEnabledOverwriteBackup);
setOverwriteMode(false);
viewport()->update();
} else {
d->autoParenthesisOverwriteBackup = d->m_autoCompleter->isAutoParenthesesEnabled();
d->surroundWithEnabledOverwriteBackup = d->m_autoCompleter->isSurroundWithEnabled();
d->m_autoCompleter->setAutoParenthesesEnabled(false);
d->m_autoCompleter->setSurroundWithEnabled(false);
d->autoParenthesisOverwriteBackup = ac->isAutoParenthesesEnabled();
d->surroundWithEnabledOverwriteBackup = ac->isSurroundWithEnabled();
ac->setAutoParenthesesEnabled(false);
ac->setSurroundWithEnabled(false);
setOverwriteMode(true);
}
e->accept();
......@@ -2150,7 +2156,7 @@ void BaseTextEditorWidget::keyPressEvent(QKeyEvent *e)
// only go here if control is not pressed, except if also alt is pressed
// because AltGr maps to Alt + Ctrl
QTextCursor cursor = textCursor();
const QString &autoText = d->m_autoCompleter->autoComplete(cursor, eventText);
const QString &autoText = dd()->m_autoCompleter->autoComplete(cursor, eventText);
QChar electricChar;
if (d->m_document->typingSettings().m_autoIndent) {
......@@ -2190,7 +2196,7 @@ void BaseTextEditorWidget::keyPressEvent(QKeyEvent *e)
//Select the inserted text, to be able to re-indent the inserted text
cursor.setPosition(pos, QTextCursor::KeepAnchor);
}
if (!electricChar.isNull() && d->m_autoCompleter->contextAllowsElectricCharacters(cursor))
if (!electricChar.isNull() && dd()->m_autoCompleter->contextAllowsElectricCharacters(cursor))
d->m_document->autoIndent(cursor, electricChar);
if (!autoText.isEmpty())
cursor.setPosition(autoText.length() == 1 ? cursor.position() : cursor.anchor());
......@@ -2666,12 +2672,12 @@ int BaseTextEditorWidget::visibleWrapColumn() const
return d->m_visibleWrapColumn;
}
void BaseTextEditorWidget::setAutoCompleter(AutoCompleter *autoCompleter)
void BaseTextEditor::setAutoCompleter(AutoCompleter *autoCompleter)
{
d->m_autoCompleter.reset(autoCompleter);
}
AutoCompleter *BaseTextEditorWidget::autoCompleter() const
AutoCompleter *BaseTextEditor::autoCompleter() const
{
return d->m_autoCompleter.data();
}
......@@ -2721,7 +2727,6 @@ BaseTextEditorWidgetPrivate::BaseTextEditorWidgetPrivate(BaseTextEditorWidget *p
m_cursorBlockNumber(-1),
m_blockCount(0),
m_markDragging(false),
m_autoCompleter(new AutoCompleter),
m_clipboardAssistProvider(new Internal::ClipboardAssistProvider),
m_isMissingSyntaxDefinition(false)
{
......@@ -5060,7 +5065,7 @@ void BaseTextEditorWidgetPrivate::handleBackspaceKey()
const TextEditor::TabSettings &tabSettings = m_document->tabSettings();
const TextEditor::TypingSettings &typingSettings = m_document->typingSettings();
if (typingSettings.m_autoIndent && m_autoCompleter->autoBackspace(cursor))
if (typingSettings.m_autoIndent && dd()->m_autoCompleter->autoBackspace(cursor))
return;
bool handled = false;
......@@ -6003,8 +6008,8 @@ void BaseTextEditorWidget::setStorageSettings(const StorageSettings &storageSett
void BaseTextEditorWidget::setCompletionSettings(const TextEditor::CompletionSettings &completionSettings)
{
d->m_autoCompleter->setAutoParenthesesEnabled(completionSettings.m_autoInsertBrackets);
d->m_autoCompleter->setSurroundWithEnabled(completionSettings.m_autoInsertBrackets
dd()->m_autoCompleter->setAutoParenthesesEnabled(completionSettings.m_autoInsertBrackets);
dd()->m_autoCompleter->setSurroundWithEnabled(completionSettings.m_autoInsertBrackets
&& completionSettings.m_surroundingAutoBrackets);
}
......@@ -6678,6 +6683,11 @@ void BaseTextEditorWidget::doFoo() {
#endif
}
BaseTextEditorPrivate *BaseTextEditorWidget::dd() const
{
return editor()->d;
}
BaseTextBlockSelection::BaseTextBlockSelection(const BaseTextBlockSelection &other)
{
positionBlock = other.positionBlock;
......
......@@ -130,7 +130,6 @@ public:
static BaseTextEditor *currentTextEditor();
friend class BaseTextEditorWidget;
BaseTextEditorWidget *editorWidget() const;
BaseTextDocument *baseTextDocument();
......@@ -195,6 +194,9 @@ public:
QObject *fileEncodingLabel() const; // FIXME: Remove
void setAutoCompleter(AutoCompleter *autoCompleter);
AutoCompleter *autoCompleter() const;
signals:
void markRequested(TextEditor::BaseTextEditor *editor, int line, TextEditor::BaseTextEditor::MarkRequestKind kind);
void markContextMenuRequested(TextEditor::BaseTextEditor *editor, int line, QMenu *menu);
......@@ -210,6 +212,8 @@ private slots:
void setFileEncodingLabelText(const QString &text);
private:
friend class Internal::BaseTextEditorWidgetPrivate;
friend class BaseTextEditorWidget;
Internal::BaseTextEditorPrivate *d;
};
......@@ -315,9 +319,6 @@ public:
QRegion translatedLineRegion(int lineStart, int lineEnd) const;
void setAutoCompleter(AutoCompleter *autoCompleter);
AutoCompleter *autoCompleter() const;
QPoint toolTipPosition(const QTextCursor &c) const;
void invokeAssist(AssistKind assistKind, IAssistProvider *provider = 0);
......@@ -619,6 +620,7 @@ private slots:
private:
Internal::BaseTextEditorWidgetPrivate *d;
Internal::BaseTextEditorPrivate *dd() const;
friend class Internal::BaseTextEditorWidgetPrivate;
friend class Internal::TextEditorOverlay;
friend class RefactorOverlay;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment