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