Commit e3bc7d19 authored by hjk's avatar hjk

TextEditor: Move CompletionAssistProvider to *Widget

All the others live there, too.

Change-Id: I0a418bf235343d40a53fbee089234765386ee05d
Reviewed-by: default avatarChristian Stenger <christian.stenger@digia.com>
parent 877bf3b3
...@@ -58,6 +58,19 @@ public: ...@@ -58,6 +58,19 @@ public:
JavaEditor() JavaEditor()
{ {
setDuplicateSupported(true); setDuplicateSupported(true);
}
};
//
// JavaEditorWidget
//
class JavaEditorWidget : public TextEditor::BaseTextEditorWidget
{
public:
JavaEditorWidget()
{
setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<JavaCompletionAssistProvider>()); setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<JavaCompletionAssistProvider>());
} }
}; };
...@@ -106,8 +119,9 @@ JavaEditorFactory::JavaEditorFactory() ...@@ -106,8 +119,9 @@ JavaEditorFactory::JavaEditorFactory()
setDisplayName(tr("Java Editor")); setDisplayName(tr("Java Editor"));
addMimeType(Constants::JAVA_MIMETYPE); addMimeType(Constants::JAVA_MIMETYPE);
setEditorCreator([]() { return new JavaEditor; });
setDocumentCreator([]() { return new JavaDocument; }); setDocumentCreator([]() { return new JavaDocument; });
setEditorWidgetCreator([]() { return new JavaEditorWidget; });
setEditorCreator([]() { return new JavaEditor; });
setAutoCompleterCreator([]() { return new JavaAutoCompleter; }); setAutoCompleterCreator([]() { return new JavaAutoCompleter; });
setGenericSyntaxHighlighter(QLatin1String(Constants::JAVA_MIMETYPE)); setGenericSyntaxHighlighter(QLatin1String(Constants::JAVA_MIMETYPE));
setCommentStyle(Utils::CommentDefinition::CppStyle); setCommentStyle(Utils::CommentDefinition::CppStyle);
......
...@@ -66,7 +66,6 @@ namespace Internal { ...@@ -66,7 +66,6 @@ namespace Internal {
CMakeEditor::CMakeEditor() CMakeEditor::CMakeEditor()
{ {
setDuplicateSupported(true); setDuplicateSupported(true);
setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<CMakeFileCompletionAssistProvider>());
} }
void CMakeEditor::finalizeInitialization() void CMakeEditor::finalizeInitialization()
...@@ -159,6 +158,7 @@ private: ...@@ -159,6 +158,7 @@ private:
CMakeEditorWidget::CMakeEditorWidget() CMakeEditorWidget::CMakeEditorWidget()
{ {
setCodeFoldingSupported(true); setCodeFoldingSupported(true);
setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<CMakeFileCompletionAssistProvider>());
} }
void CMakeEditorWidget::contextMenuEvent(QContextMenuEvent *e) void CMakeEditorWidget::contextMenuEvent(QContextMenuEvent *e)
......
...@@ -85,7 +85,7 @@ enum { UPDATE_FUNCTION_DECL_DEF_LINK_INTERVAL = 200 }; ...@@ -85,7 +85,7 @@ enum { UPDATE_FUNCTION_DECL_DEF_LINK_INTERVAL = 200 };
using namespace CPlusPlus; using namespace CPlusPlus;
using namespace CppTools; using namespace CppTools;
using namespace CppEditor::Internal; using namespace TextEditor;
namespace CppEditor { namespace CppEditor {
namespace Internal { namespace Internal {
...@@ -95,11 +95,6 @@ CppEditor::CppEditor() ...@@ -95,11 +95,6 @@ CppEditor::CppEditor()
m_context.add(ProjectExplorer::Constants::LANG_CXX); m_context.add(ProjectExplorer::Constants::LANG_CXX);
m_context.add(TextEditor::Constants::C_TEXTEDITOR); m_context.add(TextEditor::Constants::C_TEXTEDITOR);
setDuplicateSupported(true); setDuplicateSupported(true);
setCompletionAssistProvider([this] () -> TextEditor::CompletionAssistProvider * {
if (CppEditorDocument *document = qobject_cast<CppEditorDocument *>(textDocument()))
return document->completionAssistProvider();
return 0;
});
} }
Q_GLOBAL_STATIC(CppTools::SymbolFinder, symbolFinder) Q_GLOBAL_STATIC(CppTools::SymbolFinder, symbolFinder)
...@@ -764,6 +759,13 @@ FollowSymbolUnderCursor *CppEditorWidget::followSymbolUnderCursorDelegate() ...@@ -764,6 +759,13 @@ FollowSymbolUnderCursor *CppEditorWidget::followSymbolUnderCursorDelegate()
return d->m_followSymbolUnderCursor.data(); 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() void CppEditorWidget::abortDeclDefLink()
{ {
if (!d->m_declDefLink) if (!d->m_declDefLink)
......
...@@ -88,6 +88,7 @@ public: ...@@ -88,6 +88,7 @@ public:
TextEditor::AssistReason reason) const QTC_OVERRIDE; TextEditor::AssistReason reason) const QTC_OVERRIDE;
FollowSymbolUnderCursor *followSymbolUnderCursorDelegate(); // exposed for tests FollowSymbolUnderCursor *followSymbolUnderCursorDelegate(); // exposed for tests
TextEditor::CompletionAssistProvider *completionAssistProvider() const QTC_OVERRIDE;
public slots: public slots:
void paste() QTC_OVERRIDE; void paste() QTC_OVERRIDE;
......
...@@ -136,6 +136,7 @@ private: ...@@ -136,6 +136,7 @@ private:
GlslEditorWidget::GlslEditorWidget() GlslEditorWidget::GlslEditorWidget()
{ {
setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<GlslCompletionAssistProvider>());
setAutoCompleter(new GlslCompleter); setAutoCompleter(new GlslCompleter);
m_outlineCombo = 0; m_outlineCombo = 0;
setParenthesesMatchingEnabled(true); setParenthesesMatchingEnabled(true);
...@@ -335,7 +336,6 @@ public: ...@@ -335,7 +336,6 @@ public:
GlslEditor() GlslEditor()
{ {
setDuplicateSupported(true); setDuplicateSupported(true);
setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<GlslCompletionAssistProvider>());
} }
bool open(QString *errorString, const QString &fileName, const QString &realFileName) bool open(QString *errorString, const QString &fileName, const QString &realFileName)
......
...@@ -61,7 +61,6 @@ public: ...@@ -61,7 +61,6 @@ public:
ProFileEditor() ProFileEditor()
{ {
setDuplicateSupported(true); setDuplicateSupported(true);
setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<ProFileCompletionAssistProvider>());
} }
}; };
...@@ -72,7 +71,10 @@ public: ...@@ -72,7 +71,10 @@ public:
class ProFileEditorWidget : public BaseTextEditorWidget class ProFileEditorWidget : public BaseTextEditorWidget
{ {
public: public:
ProFileEditorWidget() {} ProFileEditorWidget()
{
setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<ProFileCompletionAssistProvider>());
}
protected: protected:
virtual Link findLinkAt(const QTextCursor &, bool resolveTarget = true, virtual Link findLinkAt(const QTextCursor &, bool resolveTarget = true,
......
...@@ -116,6 +116,7 @@ QmlJSEditorWidget::QmlJSEditorWidget() ...@@ -116,6 +116,7 @@ QmlJSEditorWidget::QmlJSEditorWidget()
setMarksVisible(true); setMarksVisible(true);
setCodeFoldingSupported(true); setCodeFoldingSupported(true);
setLanguageSettingsId(QmlJSTools::Constants::QML_JS_SETTINGS_ID); setLanguageSettingsId(QmlJSTools::Constants::QML_JS_SETTINGS_ID);
setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<Internal::QmlJSCompletionAssistProvider>());
} }
void QmlJSEditorWidget::finalizeInitialization() void QmlJSEditorWidget::finalizeInitialization()
...@@ -879,7 +880,6 @@ QmlJSEditor::QmlJSEditor() ...@@ -879,7 +880,6 @@ QmlJSEditor::QmlJSEditor()
{ {
addContext(ProjectExplorer::Constants::LANG_QMLJS); addContext(ProjectExplorer::Constants::LANG_QMLJS);
setDuplicateSupported(true); setDuplicateSupported(true);
setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<Internal::QmlJSCompletionAssistProvider>());
} }
bool QmlJSEditor::isDesignModePreferred() const bool QmlJSEditor::isDesignModePreferred() const
......
...@@ -230,8 +230,6 @@ class BaseTextEditorPrivate ...@@ -230,8 +230,6 @@ class BaseTextEditorPrivate
public: public:
BaseTextEditorPrivate() {} BaseTextEditorPrivate() {}
std::function<CompletionAssistProvider *()> m_completionAssistProvider;
QPointer<BaseTextEditorFactory> m_origin; QPointer<BaseTextEditorFactory> m_origin;
}; };
...@@ -435,6 +433,7 @@ public: ...@@ -435,6 +433,7 @@ public:
QScopedPointer<AutoCompleter> m_autoCompleter; QScopedPointer<AutoCompleter> m_autoCompleter;
CommentDefinition m_commentDefinition; CommentDefinition m_commentDefinition;
CompletionAssistProvider *m_completionAssistProvider;
}; };
BaseTextEditorWidgetPrivate::BaseTextEditorWidgetPrivate(BaseTextEditorWidget *parent) BaseTextEditorWidgetPrivate::BaseTextEditorWidgetPrivate(BaseTextEditorWidget *parent)
...@@ -486,7 +485,8 @@ BaseTextEditorWidgetPrivate::BaseTextEditorWidgetPrivate(BaseTextEditorWidget *p ...@@ -486,7 +485,8 @@ BaseTextEditorWidgetPrivate::BaseTextEditorWidgetPrivate(BaseTextEditorWidget *p
m_markDragging(false), m_markDragging(false),
m_clipboardAssistProvider(new Internal::ClipboardAssistProvider), m_clipboardAssistProvider(new Internal::ClipboardAssistProvider),
m_isMissingSyntaxDefinition(false), m_isMissingSyntaxDefinition(false),
m_autoCompleter(new AutoCompleter) m_autoCompleter(new AutoCompleter),
m_completionAssistProvider(0)
{ {
Aggregation::Aggregate *aggregate = new Aggregation::Aggregate; Aggregation::Aggregate *aggregate = new Aggregation::Aggregate;
BaseTextFind *baseTextFind = new BaseTextFind(q); BaseTextFind *baseTextFind = new BaseTextFind(q);
...@@ -6552,7 +6552,6 @@ void BaseTextEditorWidget::appendStandardContextMenuActions(QMenu *menu) ...@@ -6552,7 +6552,6 @@ void BaseTextEditorWidget::appendStandardContextMenuActions(QMenu *menu)
BaseTextEditor::BaseTextEditor() BaseTextEditor::BaseTextEditor()
: d(new BaseTextEditorPrivate) : d(new BaseTextEditorPrivate)
{ {
d->m_completionAssistProvider = [] () -> CompletionAssistProvider * { return 0; };
addContext(TextEditor::Constants::C_TEXTEDITOR); addContext(TextEditor::Constants::C_TEXTEDITOR);
setDuplicateSupported(true); setDuplicateSupported(true);
} }
...@@ -6696,19 +6695,9 @@ void BaseTextEditor::select(int toPos) ...@@ -6696,19 +6695,9 @@ void BaseTextEditor::select(int toPos)
editorWidget()->setTextCursor(tc); editorWidget()->setTextCursor(tc);
} }
CompletionAssistProvider *BaseTextEditor::completionAssistProvider() CompletionAssistProvider *BaseTextEditorWidget::completionAssistProvider() const
{
return d->m_completionAssistProvider();
}
void BaseTextEditor::setCompletionAssistProvider(CompletionAssistProvider *provider)
{
d->m_completionAssistProvider = [provider] () -> CompletionAssistProvider * { return provider; };
}
void BaseTextEditor::setCompletionAssistProvider(const std::function<CompletionAssistProvider *()> &provider)
{ {
d->m_completionAssistProvider = provider; return d->m_completionAssistProvider;
} }
void BaseTextEditorWidgetPrivate::updateCursorPosition() void BaseTextEditorWidgetPrivate::updateCursorPosition()
...@@ -7008,6 +6997,11 @@ void BaseTextEditorWidget::inSnippetMode(bool *active) ...@@ -7008,6 +6997,11 @@ void BaseTextEditorWidget::inSnippetMode(bool *active)
*active = d->m_snippetOverlay->isVisible(); *active = d->m_snippetOverlay->isVisible();
} }
void BaseTextEditorWidget::setCompletionAssistProvider(CompletionAssistProvider *provider)
{
d->m_completionAssistProvider = provider;
}
void BaseTextEditorWidget::invokeAssist(AssistKind kind, IAssistProvider *provider) void BaseTextEditorWidget::invokeAssist(AssistKind kind, IAssistProvider *provider)
{ {
bool previousMode = overwriteMode(); bool previousMode = overwriteMode();
......
...@@ -193,13 +193,6 @@ public: ...@@ -193,13 +193,6 @@ public:
/*! Selects text between current cursor position and \a toPos. */ /*! Selects text between current cursor position and \a toPos. */
virtual void select(int toPos); virtual void select(int toPos);
CompletionAssistProvider *completionAssistProvider();
void setCompletionAssistProvider(CompletionAssistProvider *provider); // Not owned.
// FIXME: Only used to delay initialization from CppEditor.
// There should be something simpler.
void setCompletionAssistProvider(const std::function<CompletionAssistProvider *()> &provider);
signals: signals:
void markRequested(TextEditor::BaseTextEditor *editor, int line, TextEditor::BaseTextEditor::MarkRequestKind kind); void markRequested(TextEditor::BaseTextEditor *editor, int line, TextEditor::BaseTextEditor::MarkRequestKind kind);
void markContextMenuRequested(TextEditor::BaseTextEditor *editor, int line, QMenu *menu); void markContextMenuRequested(TextEditor::BaseTextEditor *editor, int line, QMenu *menu);
...@@ -482,6 +475,9 @@ public: ...@@ -482,6 +475,9 @@ public:
Q_INVOKABLE void inSnippetMode(bool *active); // Used by FakeVim. Q_INVOKABLE void inSnippetMode(bool *active); // Used by FakeVim.
void setCompletionAssistProvider(CompletionAssistProvider *provider);
virtual CompletionAssistProvider *completionAssistProvider() const;
signals: signals:
void assistFinished(); void assistFinished();
void readOnlyChanged(); void readOnlyChanged();
......
...@@ -179,7 +179,7 @@ void CodeAssistantPrivate::configure(BaseTextEditor *textEditor) ...@@ -179,7 +179,7 @@ void CodeAssistantPrivate::configure(BaseTextEditor *textEditor)
// completion and quick-fix provider (getting rid of the list). // completion and quick-fix provider (getting rid of the list).
m_textEditor = textEditor; m_textEditor = textEditor;
m_completionProvider = textEditor->completionAssistProvider(); m_completionProvider = textEditor->editorWidget()->completionAssistProvider();
m_quickFixProviders = m_quickFixProviders =
ExtensionSystem::PluginManager::getObjects<QuickFixAssistProvider>(); ExtensionSystem::PluginManager::getObjects<QuickFixAssistProvider>();
filterEditorSpecificProviders(&m_quickFixProviders, m_textEditor->document()->id()); filterEditorSpecificProviders(&m_quickFixProviders, m_textEditor->document()->id());
...@@ -192,7 +192,7 @@ void CodeAssistantPrivate::configure(BaseTextEditor *textEditor) ...@@ -192,7 +192,7 @@ void CodeAssistantPrivate::configure(BaseTextEditor *textEditor)
void CodeAssistantPrivate::reconfigure() void CodeAssistantPrivate::reconfigure()
{ {
if (isConfigured()) if (isConfigured())
m_completionProvider = m_textEditor->completionAssistProvider(); m_completionProvider = m_textEditor->editorWidget()->completionAssistProvider();
} }
bool CodeAssistantPrivate::isConfigured() const bool CodeAssistantPrivate::isConfigured() const
......
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