Commit 9fd2fe5a authored by hjk's avatar hjk

TextEditor: Make completion assist provider a data member

In case of the CppEditor a direct member is not possible due
to setup restrictions inside the CppEditor machinery. I'd expect
that to be fixable when the editor base system is in good shape.

Change-Id: I184e219ca2dff6f67c9b58c182212eb12972cc84
Reviewed-by: default avatarChristian Stenger <christian.stenger@digia.com>
parent 80fb7728
......@@ -56,6 +56,7 @@ JavaEditor::JavaEditor(JavaEditorWidget *editor)
TextEditor::Constants::C_TEXTEDITOR));
setDuplicateSupported(true);
setCommentStyle(Utils::CommentDefinition::CppStyle);
setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<JavaCompletionAssistProvider>());
}
Core::IEditor *JavaEditor::duplicate()
......@@ -66,11 +67,6 @@ Core::IEditor *JavaEditor::duplicate()
return ret->editor();
}
TextEditor::CompletionAssistProvider *JavaEditor::completionAssistProvider()
{
return ExtensionSystem::PluginManager::getObject<JavaCompletionAssistProvider>();
}
//
// JavaEditorWidget
//
......
......@@ -63,6 +63,7 @@ CMakeEditor::CMakeEditor(CMakeEditorWidget *editor)
TextEditor::Constants::C_TEXTEDITOR));
setDuplicateSupported(true);
setCommentStyle(Utils::CommentDefinition::HashStyle);
setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<CMakeFileCompletionAssistProvider>());
connect(document(), SIGNAL(changed()), this, SLOT(markAsChanged()));
}
......@@ -74,11 +75,6 @@ Core::IEditor *CMakeEditor::duplicate()
return ret->editor();
}
TextEditor::CompletionAssistProvider *CMakeEditor::completionAssistProvider()
{
return ExtensionSystem::PluginManager::getObject<CMakeFileCompletionAssistProvider>();
}
void CMakeEditor::markAsChanged()
{
if (!document()->isModified())
......
......@@ -53,7 +53,6 @@ public:
CMakeEditor(CMakeEditorWidget *);
Core::IEditor *duplicate();
TextEditor::CompletionAssistProvider *completionAssistProvider();
QString contextHelpId() const;
......
......@@ -114,6 +114,9 @@ CPPEditor::CPPEditor(CppEditorWidget *editor)
m_context.add(TextEditor::Constants::C_TEXTEDITOR);
setDuplicateSupported(true);
setCommentStyle(Utils::CommentDefinition::CppStyle);
setCompletionAssistProvider([this] () -> TextEditor::CompletionAssistProvider * {
return CppModelManagerInterface::instance()->cppEditorSupport(this)->completionAssistProvider();
});
}
Q_GLOBAL_STATIC(CppTools::SymbolFinder, symbolFinder)
......@@ -797,11 +800,6 @@ bool CPPEditor::open(QString *errorString, const QString &fileName, const QStrin
return true;
}
TextEditor::CompletionAssistProvider *CPPEditor::completionAssistProvider()
{
return CppModelManagerInterface::instance()->cppEditorSupport(this)->completionAssistProvider();
}
void CppEditorWidget::applyFontSettings()
{
const TextEditor::FontSettings &fs = baseTextDocument()->fontSettings();
......
......@@ -66,8 +66,6 @@ public:
bool open(QString *errorString,
const QString &fileName,
const QString &realFileName) QTC_OVERRIDE;
TextEditor::CompletionAssistProvider *completionAssistProvider() QTC_OVERRIDE;
};
class CppEditorWidget : public TextEditor::BaseTextEditorWidget
......
......@@ -214,11 +214,6 @@ bool GlslEditor::open(QString *errorString, const QString &fileName, const QStri
return b;
}
TextEditor::CompletionAssistProvider *GlslEditor::completionAssistProvider()
{
return ExtensionSystem::PluginManager::getObject<GLSLCompletionAssistProvider>();
}
QString GlslEditorWidget::wordUnderCursor() const
{
QTextCursor tc = textCursor();
......
......@@ -28,17 +28,14 @@
****************************************************************************/
#include "glsleditoreditable.h"
#include "glsleditor.h"
#include "glsleditorconstants.h"
#include "glslcompletionassist.h"
#include <texteditor/texteditorconstants.h>
#include <qmldesigner/qmldesignerconstants.h>
#include <coreplugin/mimedatabase.h>
#include <coreplugin/icore.h>
#include <coreplugin/designmode.h>
#include <coreplugin/modemanager.h>
#include <coreplugin/coreconstants.h>
#include <extensionsystem/pluginmanager.h>
namespace GLSLEditor {
namespace Internal {
......@@ -50,6 +47,7 @@ GlslEditor::GlslEditor(GlslEditorWidget *editor)
TextEditor::Constants::C_TEXTEDITOR));
setDuplicateSupported(true);
setCommentStyle(Utils::CommentDefinition::CppStyle);
setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<GLSLCompletionAssistProvider>());
}
} // namespace Internal
......
......@@ -46,7 +46,6 @@ public:
Core::IEditor *duplicate();
bool open(QString *errorString, const QString &fileName, const QString &realFileName);
TextEditor::CompletionAssistProvider *completionAssistProvider();
};
} // namespace Internal
......
......@@ -59,6 +59,7 @@ ProFileEditor::ProFileEditor(ProFileEditorWidget *editor)
TextEditor::Constants::C_TEXTEDITOR));
setDuplicateSupported(true);
setCommentStyle(Utils::CommentDefinition::HashStyle);
setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<ProFileCompletionAssistProvider>());
}
Core::IEditor *ProFileEditor::duplicate()
......@@ -69,11 +70,6 @@ Core::IEditor *ProFileEditor::duplicate()
return ret->editor();
}
TextEditor::CompletionAssistProvider *ProFileEditor::completionAssistProvider()
{
return ExtensionSystem::PluginManager::getObject<ProFileCompletionAssistProvider>();
}
//
// ProFileEditorWidget
//
......
......@@ -48,7 +48,6 @@ public:
ProFileEditor(ProFileEditorWidget *);
Core::IEditor *duplicate();
TextEditor::CompletionAssistProvider *completionAssistProvider();
};
class ProFileEditorWidget : public TextEditor::BaseTextEditorWidget
......
......@@ -55,6 +55,7 @@ QmlJSEditor::QmlJSEditor(QmlJSTextEditorWidget *editor)
m_context.add(ProjectExplorer::Constants::LANG_QMLJS);
setDuplicateSupported(true);
setCommentStyle(Utils::CommentDefinition::CppStyle);
setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<Internal::QmlJSCompletionAssistProvider>());
}
bool QmlJSEditor::isDesignModePreferred() const
......@@ -66,10 +67,5 @@ bool QmlJSEditor::isDesignModePreferred() const
return false;
}
TextEditor::CompletionAssistProvider *QmlJSEditor::completionAssistProvider()
{
return ExtensionSystem::PluginManager::getObject<Internal::QmlJSCompletionAssistProvider>();
}
} // namespace Internal
} // namespace QmlJSEditor
......@@ -49,8 +49,6 @@ public:
Core::IEditor *duplicate();
bool open(QString *errorString, const QString &fileName, const QString &realFileName);
bool isDesignModePreferred() const;
TextEditor::CompletionAssistProvider *completionAssistProvider();
};
} // namespace Internal
......
......@@ -198,6 +198,7 @@ public:
QAction *m_fileEncodingLabelAction;
Utils::LineColumnLabel *m_fileEncodingLabel;
CommentDefinition m_commentDefinition;
std::function<CompletionAssistProvider *()> m_completionAssistProvider;
};
class BaseTextEditorWidgetPrivate
......@@ -6447,6 +6448,8 @@ BaseTextEditor::BaseTextEditor(BaseTextEditorWidget *editor)
d->m_cursorPositionLabelAction = d->m_toolBar->addWidget(d->m_cursorPositionLabel);
d->m_fileEncodingLabelAction = d->m_toolBar->addWidget(d->m_fileEncodingLabel);
d->m_completionAssistProvider = [] () -> CompletionAssistProvider * { return 0; };
setFileEncodingLabelVisible(editor->displaySettings().m_displayFileEncoding);
connect(editor, SIGNAL(cursorPositionChanged()), this, SLOT(updateCursorPosition()));
connect(d->m_cursorPositionLabel, SIGNAL(clicked()), this, SLOT(openGotoLocator()));
......@@ -6587,7 +6590,17 @@ void BaseTextEditor::setCommentStyle(CommentDefinition::Style style)
CompletionAssistProvider *BaseTextEditor::completionAssistProvider()
{
return 0;
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;
}
QObject *BaseTextEditor::fileEncodingLabel() const
......
......@@ -42,6 +42,7 @@
#include <utils/uncommentselection.h>
#include <QPlainTextEdit>
#include <functional>
QT_BEGIN_NAMESPACE
class QToolBar;
......@@ -185,7 +186,12 @@ public:
/*! Convenience style setter. */
void setCommentStyle(Utils::CommentDefinition::Style style);
virtual CompletionAssistProvider *completionAssistProvider();
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);
QObject *fileEncodingLabel() const; // FIXME: Remove
......
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