Commit 1f65111e authored by hjk's avatar hjk

TextEditor: Move CompletionAssistProvider construction

... to the editor factories and pass it to the document, not the widget.
Saves some code, puts fewer objects into the object pool.

Change-Id: Iaaf250af74dc4e0c62700873accbb40ba88b7d9e
Reviewed-by: default avatarChristian Stenger <christian.stenger@digia.com>
Reviewed-by: default avatarDavid Schulz <david.schulz@digia.com>
parent 5bb8134e
......@@ -79,7 +79,6 @@ bool AndroidPlugin::initialize(const QStringList &arguments, QString *errorMessa
addAutoReleasedObject(new Internal::AndroidDeviceFactory);
addAutoReleasedObject(new Internal::AndroidPotentialKit);
addAutoReleasedObject(new Internal::JavaEditorFactory);
addAutoReleasedObject(new Internal::JavaCompletionAssistProvider);
ProjectExplorer::KitManager::registerKitInformation(new Internal::AndroidGdbServerKitInformation);
// AndroidManifest.xml editor
......
......@@ -40,6 +40,7 @@ namespace Internal {
class JavaCompletionAssistProvider : public TextEditor::CompletionAssistProvider
{
Q_OBJECT
public:
JavaCompletionAssistProvider();
~JavaCompletionAssistProvider();
......@@ -53,8 +54,7 @@ private:
mutable QStringList m_keywords;
};
}
}
} // namespace Internal
} // namespace Android
#endif // JAVACOMPLETIONASSISTPROVIDER_H
......@@ -48,20 +48,6 @@
namespace Android {
namespace Internal {
//
// JavaEditorWidget
//
class JavaEditorWidget : public TextEditor::TextEditorWidget
{
public:
JavaEditorWidget()
{
setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<JavaCompletionAssistProvider>());
}
};
//
// JavaDocument
//
......@@ -106,12 +92,11 @@ JavaEditorFactory::JavaEditorFactory()
addMimeType(Constants::JAVA_MIMETYPE);
setDocumentCreator([]() { return new JavaDocument; });
setEditorWidgetCreator([]() { return new JavaEditorWidget; });
setAutoCompleterCreator([]() { return new JavaAutoCompleter; });
setGenericSyntaxHighlighter(QLatin1String(Constants::JAVA_MIMETYPE));
setCommentStyle(Utils::CommentDefinition::CppStyle);
setEditorActionHandlers(TextEditor::TextEditorActionHandler::UnCommentSelection);
setCompletionAssistProvider(new JavaCompletionAssistProvider);
}
} // namespace Internal
......
......@@ -154,7 +154,6 @@ private:
CMakeEditorWidget::CMakeEditorWidget()
{
setCodeFoldingSupported(true);
setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<CMakeFileCompletionAssistProvider>());
}
void CMakeEditorWidget::contextMenuEvent(QContextMenuEvent *e)
......@@ -271,7 +270,7 @@ QString CMakeDocument::suggestedFileName() const
// CMakeEditorFactory
//
CMakeEditorFactory::CMakeEditorFactory()
CMakeEditorFactory::CMakeEditorFactory(CMakeSettingsPage *settingsPage)
{
setId(Constants::CMAKE_EDITOR_ID);
setDisplayName(tr(Constants::CMAKE_EDITOR_DISPLAY_NAME));
......@@ -284,6 +283,8 @@ CMakeEditorFactory::CMakeEditorFactory()
setGenericSyntaxHighlighter(QLatin1String(Constants::CMAKEMIMETYPE));
setCommentStyle(Utils::CommentDefinition::HashStyle);
setCompletionAssistProvider(new CMakeFileCompletionAssistProvider(settingsPage));
setEditorActionHandlers(TextEditorActionHandler::UnCommentSelection
| TextEditorActionHandler::JumpToFileUnderCursor);
......
......@@ -37,6 +37,7 @@ namespace CMakeProjectManager {
namespace Internal {
class CMakeEditorWidget;
class CMakeSettingsPage;
class CMakeEditor : public TextEditor::BaseTextEditor
{
......@@ -56,7 +57,7 @@ class CMakeEditorFactory : public TextEditor::TextEditorFactory
Q_OBJECT
public:
CMakeEditorFactory();
CMakeEditorFactory(CMakeSettingsPage *settingsPage);
};
} // namespace Internal
......
......@@ -60,14 +60,14 @@ bool CMakeProjectPlugin::initialize(const QStringList & /*arguments*/, QString *
{
if (!Core::MimeDatabase::addMimeTypes(QLatin1String(":cmakeproject/CMakeProjectManager.mimetypes.xml"), errorMessage))
return false;
CMakeSettingsPage *cmp = new CMakeSettingsPage();
addAutoReleasedObject(cmp);
addAutoReleasedObject(new CMakeManager(cmp));
addAutoReleasedObject(new MakeStepFactory);
addAutoReleasedObject(new CMakeRunConfigurationFactory);
addAutoReleasedObject(new CMakeBuildConfigurationFactory);
addAutoReleasedObject(new CMakeEditorFactory);
addAutoReleasedObject(new CMakeEditorFactory(cmp));
addAutoReleasedObject(new CMakeLocatorFilter);
addAutoReleasedObject(new CMakeFileCompletionAssistProvider(cmp));
......
......@@ -598,7 +598,8 @@ void CppEditorWidget::updateSemanticInfo(const SemanticInfo &semanticInfo,
AssistInterface *CppEditorWidget::createAssistInterface(AssistKind kind, AssistReason reason) const
{
if (kind == Completion) {
if (CppCompletionAssistProvider *cap = cppEditorDocument()->completionAssistProvider()) {
if (CppCompletionAssistProvider *cap =
qobject_cast<CppCompletionAssistProvider *>(cppEditorDocument()->completionAssistProvider())) {
return cap->createAssistInterface(
textDocument()->filePath(),
document(),
......@@ -711,13 +712,6 @@ FollowSymbolUnderCursor *CppEditorWidget::followSymbolUnderCursorDelegate()
return d->m_followSymbolUnderCursor.data();
}
CompletionAssistProvider *CppEditorWidget::completionAssistProvider() const
{
auto document = qobject_cast<CppEditorDocument *>(textDocument());
QTC_ASSERT(document, return 0);
return document->completionAssistProvider();
}
void CppEditorWidget::abortDeclDefLink()
{
if (!d->m_declDefLink)
......
......@@ -83,7 +83,6 @@ public:
TextEditor::AssistReason reason) const Q_DECL_OVERRIDE;
FollowSymbolUnderCursor *followSymbolUnderCursorDelegate(); // exposed for tests
TextEditor::CompletionAssistProvider *completionAssistProvider() const Q_DECL_OVERRIDE;
public slots:
void paste() Q_DECL_OVERRIDE;
......
......@@ -123,7 +123,7 @@ bool CppEditorDocument::isObjCEnabled() const
return m_isObjCEnabled;
}
CppTools::CppCompletionAssistProvider *CppEditorDocument::completionAssistProvider() const
TextEditor::CompletionAssistProvider *CppEditorDocument::completionAssistProvider() const
{
return m_completionAssistProvider;
}
......
......@@ -55,7 +55,7 @@ public:
~CppEditorDocument();
bool isObjCEnabled() const;
CppTools::CppCompletionAssistProvider *completionAssistProvider() const;
TextEditor::CompletionAssistProvider *completionAssistProvider() const;
void semanticRehighlight();
CppTools::SemanticInfo recalculateSemanticInfo(); // TODO: Remove me
......
......@@ -134,7 +134,6 @@ private:
GlslEditorWidget::GlslEditorWidget()
{
setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<GlslCompletionAssistProvider>());
setAutoCompleter(new GlslCompleter);
m_outlineCombo = 0;
setParenthesesMatchingEnabled(true);
......@@ -343,6 +342,7 @@ GlslEditorFactory::GlslEditorFactory()
setIndenterCreator([]() { return new GlslIndenter; });
setSyntaxHighlighterCreator([]() { return new GlslHighlighter; });
setCommentStyle(Utils::CommentDefinition::CppStyle);
setCompletionAssistProvider(new GlslCompletionAssistProvider);
setEditorActionHandlers(TextEditorActionHandler::Format
| TextEditorActionHandler::UnCommentSelection
......
......@@ -32,7 +32,6 @@
#include <texteditor/codeassist/completionassistprovider.h>
#include <QStringList>
namespace QmakeProjectManager {
......@@ -41,6 +40,7 @@ namespace Internal {
class ProFileCompletionAssistProvider : public TextEditor::CompletionAssistProvider
{
Q_OBJECT
public:
ProFileCompletionAssistProvider();
void init();
......@@ -50,6 +50,7 @@ public:
TextEditor::IAssistProcessor *createProcessor() const Q_DECL_OVERRIDE;
QStringList variables() const;
QStringList functions() const;
private:
QStringList m_variables;
QStringList m_functions;
......
......@@ -57,7 +57,6 @@ class ProFileEditorWidget : public TextEditorWidget
public:
ProFileEditorWidget()
{
setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<ProFileCompletionAssistProvider>());
}
protected:
......@@ -179,7 +178,6 @@ ProFileDocument::ProFileDocument()
{
setId(Constants::PROFILE_EDITOR_ID);
setMimeType(QLatin1String(Constants::PROFILE_MIMETYPE));
setSyntaxHighlighter(new ProFileHighlighter);
}
QString ProFileDocument::defaultPath() const
......@@ -212,11 +210,16 @@ ProFileEditorFactory::ProFileEditorFactory()
setDocumentCreator([]() { return new ProFileDocument; });
setEditorWidgetCreator([]() { return new ProFileEditorWidget; });
ProFileCompletionAssistProvider *pcap = new ProFileCompletionAssistProvider;
setCompletionAssistProvider(pcap);
setCommentStyle(Utils::CommentDefinition::HashStyle);
setEditorActionHandlers(TextEditorActionHandler::UnCommentSelection
| TextEditorActionHandler::JumpToFileUnderCursor);
addHoverHandler(new ProFileHoverHandler);
Keywords keywords(pcap->variables(), pcap->functions(), QMap<QString, QStringList>());
addHoverHandler(new ProFileHoverHandler(keywords));
setSyntaxHighlighterCreator([keywords]() { return new ProFileHighlighter(keywords); });
Core::FileIconProvider::registerIconOverlayForSuffix(QtSupport::Constants::ICON_QT_PROJECT, "pro");
Core::FileIconProvider::registerIconOverlayForSuffix(QtSupport::Constants::ICON_QT_PROJECT, "pri");
......
......@@ -34,23 +34,17 @@
#include <QTextDocument>
using namespace QmakeProjectManager::Internal;
using namespace TextEditor;
namespace QmakeProjectManager {
namespace Internal {
ProFileHighlighter::ProFileHighlighter(QTextDocument *document) :
TextEditor::SyntaxHighlighter(document)
ProFileHighlighter::ProFileHighlighter(const Keywords &keywords)
: m_keywords(keywords)
{
ProFileCompletionAssistProvider *pcap
= ExtensionSystem::PluginManager::getObject<ProFileCompletionAssistProvider>();
m_keywords = TextEditor::Keywords(pcap->variables(), pcap->functions(), QMap<QString, QStringList>());
static QVector<TextEditor::TextStyle> categories;
if (categories.isEmpty()) {
categories << TextEditor::C_TYPE
<< TextEditor::C_KEYWORD
<< TextEditor::C_COMMENT
<< TextEditor::C_VISUAL_WHITESPACE;
}
static QVector<TextStyle> categories;
if (categories.isEmpty())
categories << C_TYPE << C_KEYWORD << C_COMMENT << C_VISUAL_WHITESPACE;
setTextFormatCategories(categories);
}
......@@ -97,3 +91,6 @@ void ProFileHighlighter::highlightBlock(const QString &text)
applyFormatToSpaces(text, formatForCategory(ProfileVisualWhitespaceFormat));
}
} // namespace Internal
} // namespace QmakeProjectManager
......@@ -38,7 +38,6 @@ namespace Internal {
class ProFileHighlighter : public TextEditor::SyntaxHighlighter
{
Q_OBJECT
public:
enum ProfileFormats {
ProfileVariableFormat,
......@@ -48,11 +47,11 @@ public:
NumProfileFormats
};
ProFileHighlighter(QTextDocument *document = 0);
explicit ProFileHighlighter(const TextEditor::Keywords &keywords);
void highlightBlock(const QString &text);
private:
TextEditor::Keywords m_keywords;
const TextEditor::Keywords m_keywords;
};
} // namespace Internal
......
......@@ -32,8 +32,6 @@
#include "qmakeprojectmanagerconstants.h"
#include <coreplugin/helpmanager.h>
#include <coreplugin/editormanager/ieditor.h>
#include <extensionsystem/pluginmanager.h>
#include <texteditor/texteditor.h>
#include <utils/htmldocextractor.h>
......@@ -45,12 +43,9 @@ using namespace Core;
namespace QmakeProjectManager {
namespace Internal {
ProFileHoverHandler::ProFileHoverHandler()
: m_manualKind(UnknownManual)
ProFileHoverHandler::ProFileHoverHandler(const TextEditor::Keywords &keywords)
: m_manualKind(UnknownManual), m_keywords(keywords)
{
ProFileCompletionAssistProvider *pcap
= ExtensionSystem::PluginManager::getObject<ProFileCompletionAssistProvider>();
m_keywords = TextEditor::Keywords(pcap->variables(), pcap->functions(), QMap<QString, QStringList>());
}
void ProFileHoverHandler::identifyMatch(TextEditor::TextEditorWidget *editorWidget, int pos)
......
......@@ -31,6 +31,7 @@
#define PROFILEHOVERHANDLER_H
#include <texteditor/basehoverhandler.h>
#include <texteditor/codeassist/keywordscompletionassist.h>
QT_BEGIN_NAMESPACE
class QUrl;
......@@ -44,7 +45,7 @@ class ProFileHoverHandler : public TextEditor::BaseHoverHandler
Q_OBJECT
public:
ProFileHoverHandler();
explicit ProFileHoverHandler(const TextEditor::Keywords &keywords);
signals:
void creatorHelpRequested(const QUrl &url);
......@@ -65,7 +66,7 @@ private:
QString m_docFragment;
ManualKind m_manualKind;
TextEditor::Keywords m_keywords;
const TextEditor::Keywords m_keywords;
};
} // namespace Internal
......
......@@ -47,7 +47,6 @@
#include "qmakeprojectmanagerconstants.h"
#include "qmakeproject.h"
#include "externaleditors.h"
#include "profilecompletionassist.h"
#include "qmakekitinformation.h"
#include "profilehighlighter.h"
......@@ -133,7 +132,6 @@ bool QmakeProjectManagerPlugin::initialize(const QStringList &arguments, QString
addAutoReleasedObject(new DesignerExternalEditor);
addAutoReleasedObject(new LinguistExternalEditor);
addAutoReleasedObject(new ProFileCompletionAssistProvider);
addAutoReleasedObject(new ProFileEditorFactory);
//menus
......
......@@ -115,7 +115,6 @@ QmlJSEditorWidget::QmlJSEditorWidget()
setMarksVisible(true);
setCodeFoldingSupported(true);
setLanguageSettingsId(QmlJSTools::Constants::QML_JS_SETTINGS_ID);
setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<Internal::QmlJSCompletionAssistProvider>());
}
void QmlJSEditorWidget::finalizeInitialization()
......@@ -903,6 +902,7 @@ QmlJSEditorFactory::QmlJSEditorFactory()
setCommentStyle(Utils::CommentDefinition::CppStyle);
addHoverHandler(new QmlJSHoverHandler);
setCompletionAssistProvider(new QmlJSCompletionAssistProvider);
setEditorActionHandlers(TextEditorActionHandler::Format
| TextEditorActionHandler::UnCommentSelection
......
......@@ -40,7 +40,6 @@
#include "qmltaskmanager.h"
#include "quicktoolbar.h"
#include "quicktoolbarsettingspage.h"
#include "qmljscompletionassist.h"
#include "qmljsquickfixassist.h"
#include <qmljs/qmljsicons.h>
......@@ -209,7 +208,6 @@ bool QmlJSEditorPlugin::initialize(const QStringList & /*arguments*/, QString *e
m_quickFixAssistProvider = new QmlJSQuickFixAssistProvider;
addAutoReleasedObject(m_quickFixAssistProvider);
addAutoReleasedObject(new QmlJSCompletionAssistProvider);
errorMessage->clear();
......
......@@ -219,7 +219,7 @@ void CodeAssistantPrivate::requestProposal(AssistReason reason,
if (!provider) {
if (kind == Completion)
provider = m_editorWidget->completionAssistProvider();
provider = m_editorWidget->textDocument()->completionAssistProvider();
else if (!m_quickFixProviders.isEmpty())
provider = m_quickFixProviders.at(0);
......@@ -380,7 +380,7 @@ void CodeAssistantPrivate::invalidateCurrentRequestData()
CompletionAssistProvider *CodeAssistantPrivate::identifyActivationSequence()
{
CompletionAssistProvider *completionProvider = m_editorWidget->completionAssistProvider();
CompletionAssistProvider *completionProvider = m_editorWidget->textDocument()->completionAssistProvider();
if (!completionProvider)
return 0;
......
......@@ -76,6 +76,7 @@ public:
TextDocumentPrivate() :
m_fontSettingsNeedsApply(false),
m_highlighter(0),
m_completionAssistProvider(0),
m_indenter(new Indenter),
m_fileIsReadOnly(false),
m_autoSaveRevision(-1)
......@@ -97,6 +98,7 @@ public:
bool m_fontSettingsNeedsApply; // for applying font settings delayed till an editor becomes visible
QTextDocument m_document;
SyntaxHighlighter *m_highlighter;
CompletionAssistProvider *m_completionAssistProvider;
QScopedPointer<Indenter> m_indenter;
bool m_fileIsReadOnly;
......@@ -314,6 +316,16 @@ void TextDocument::triggerPendingUpdates()
applyFontSettings();
}
void TextDocument::setCompletionAssistProvider(CompletionAssistProvider *provider)
{
d->m_completionAssistProvider = provider;
}
CompletionAssistProvider *TextDocument::completionAssistProvider() const
{
return d->m_completionAssistProvider;
}
void TextDocument::applyFontSettings()
{
d->m_fontSettingsNeedsApply = false;
......
......@@ -48,6 +48,7 @@ QT_END_NAMESPACE
namespace TextEditor {
class CompletionAssistProvider;
class ExtraEncodingSettings;
class FontSettings;
class Indenter;
......@@ -130,6 +131,9 @@ public:
virtual void triggerPendingUpdates();
void setCompletionAssistProvider(CompletionAssistProvider *provider);
virtual CompletionAssistProvider *completionAssistProvider() const;
public slots:
void setTabSettings(const TextEditor::TabSettings &tabSettings);
void setFontSettings(const TextEditor::FontSettings &fontSettings);
......
......@@ -50,8 +50,9 @@
#include "texteditorsettings.h"
#include "typingsettings.h"
#include <texteditor/codeassist/codeassistant.h>
#include <texteditor/codeassist/assistinterface.h>
#include <texteditor/codeassist/codeassistant.h>
#include <texteditor/codeassist/completionassistprovider.h>
#include <texteditor/generichighlighter/context.h>
#include <texteditor/generichighlighter/highlightdefinition.h>
#include <texteditor/generichighlighter/highlighter.h>
......@@ -437,7 +438,6 @@ public:
QScopedPointer<AutoCompleter> m_autoCompleter;
CommentDefinition m_commentDefinition;
CompletionAssistProvider *m_completionAssistProvider;
};
TextEditorWidgetPrivate::TextEditorWidgetPrivate(TextEditorWidget *parent)
......@@ -489,8 +489,7 @@ TextEditorWidgetPrivate::TextEditorWidgetPrivate(TextEditorWidget *parent)
m_markDragging(false),
m_clipboardAssistProvider(new Internal::ClipboardAssistProvider),
m_isMissingSyntaxDefinition(false),
m_autoCompleter(new AutoCompleter),
m_completionAssistProvider(0)
m_autoCompleter(new AutoCompleter)
{
Aggregation::Aggregate *aggregate = new Aggregation::Aggregate;
BaseTextFind *baseTextFind = new BaseTextFind(q);
......@@ -6731,11 +6730,6 @@ void BaseTextEditor::select(int toPos)
editorWidget()->setTextCursor(tc);
}
CompletionAssistProvider *TextEditorWidget::completionAssistProvider() const
{
return d->m_completionAssistProvider;
}
void TextEditorWidgetPrivate::updateCursorPosition()
{
const QTextCursor cursor = q->textCursor();
......@@ -7048,11 +7042,6 @@ void TextEditorWidget::inSnippetMode(bool *active)
*active = d->m_snippetOverlay->isVisible();
}
void TextEditorWidget::setCompletionAssistProvider(CompletionAssistProvider *provider)
{
d->m_completionAssistProvider = provider;
}
void TextEditorWidget::invokeAssist(AssistKind kind, IAssistProvider *provider)
{
bool previousMode = overwriteMode();
......@@ -7232,11 +7221,13 @@ TextEditorFactory::TextEditorFactory(QObject *parent)
m_widgetCreator = []() { return new TextEditorWidget; };
m_commentStyle = CommentDefinition::NoStyle;
m_duplicatedSupported = true;
m_completionAssistProvider = 0;
}
TextEditorFactory::~TextEditorFactory()
{
qDeleteAll(m_hoverHandlers);
delete m_completionAssistProvider;
}
void TextEditorFactory::setDocumentCreator(const DocumentCreator &creator)
......@@ -7293,6 +7284,11 @@ void TextEditorFactory::addHoverHandler(BaseHoverHandler *handler)
m_hoverHandlers.append(handler);
}
void TextEditorFactory::setCompletionAssistProvider(CompletionAssistProvider *provider)
{
m_completionAssistProvider = provider;
}
void TextEditorFactory::setCommentStyle(CommentDefinition::Style style)
{
m_commentStyle = style;
......@@ -7317,11 +7313,10 @@ IEditor *TextEditorFactory::createEditor()
if (m_indenterCreator)
doc->setIndenter(m_indenterCreator());
if (m_syntaxHighlighterCreator) {
SyntaxHighlighter *highlighter = m_syntaxHighlighterCreator();
highlighter->setParent(doc.data());
doc->setSyntaxHighlighter(highlighter);
}
if (m_syntaxHighlighterCreator)
doc->setSyntaxHighlighter(m_syntaxHighlighterCreator());
doc->setCompletionAssistProvider(m_completionAssistProvider);
return createEditorHelper(doc);
}
......
......@@ -467,11 +467,8 @@ public:
Q_INVOKABLE void inSnippetMode(bool *active); // Used by FakeVim.
void setCompletionAssistProvider(CompletionAssistProvider *provider);
virtual CompletionAssistProvider *completionAssistProvider() const;
signals:
void assistFinished();
void assistFinished(); // Used in tests.
void readOnlyChanged();
void requestFontZoom(int zoom);
......@@ -647,6 +644,7 @@ public:
void setEditorActionHandlers(uint optionalActions);
void addHoverHandler(BaseHoverHandler *handler);
void setCompletionAssistProvider(CompletionAssistProvider *provider);
void setCommentStyle(Utils::CommentDefinition::Style style);
void setDuplicatedSupported(bool on);
......@@ -668,6 +666,7 @@ private:
SyntaxHighLighterCreator m_syntaxHighlighterCreator;
Utils::CommentDefinition::Style m_commentStyle;
QList<BaseHoverHandler *> m_hoverHandlers; // owned
CompletionAssistProvider * m_completionAssistProvider; // owned
bool m_duplicatedSupported;
};
......
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