Commit 74c572b5 authored by hjk's avatar hjk
Browse files

QmlJSEditor: Use a BaseTextEditorFactory for creation



Change-Id: I37e81cf3eda57780c893f4e8d7f2c5c6adf75b55
Reviewed-by: default avatarChristian Stenger <christian.stenger@digia.com>
parent 173879eb
......@@ -106,12 +106,8 @@ namespace Internal {
// QmlJSEditorWidget
//
QmlJSEditorWidget::QmlJSEditorWidget(BaseTextDocumentPtr doc)
QmlJSEditorWidget::QmlJSEditorWidget()
{
setTextDocument(doc);
setAutoCompleter(new AutoCompleter);
m_qmlJsEditorDocument = static_cast<QmlJSEditorDocument *>(doc.data());
m_outlineCombo = 0;
m_contextPane = 0;
m_findReferences = new FindReferences(this);
......@@ -120,6 +116,11 @@ QmlJSEditorWidget::QmlJSEditorWidget(BaseTextDocumentPtr doc)
setMarksVisible(true);
setCodeFoldingSupported(true);
setLanguageSettingsId(QmlJSTools::Constants::QML_JS_SETTINGS_ID);
}
void QmlJSEditorWidget::finalizeInitialization()
{
m_qmlJsEditorDocument = static_cast<QmlJSEditorDocument *>(textDocument());
m_updateUsesTimer = new QTimer(this);
m_updateUsesTimer->setInterval(UPDATE_USES_DEFAULT_INTERVAL);
......@@ -160,10 +161,6 @@ QmlJSEditorWidget::QmlJSEditorWidget(BaseTextDocumentPtr doc)
createToolBar();
}
QmlJSEditorWidget::~QmlJSEditorWidget()
{
}
QModelIndex QmlJSEditorWidget::outlineModelIndex()
{
if (!m_outlineModelIndex.isValid()) {
......@@ -173,15 +170,6 @@ QModelIndex QmlJSEditorWidget::outlineModelIndex()
return m_outlineModelIndex;
}
IEditor *QmlJSEditor::duplicate()
{
auto editor = new QmlJSEditor;
auto widget = new QmlJSEditorWidget(editorWidget()->textDocumentPtr());
editor->setEditorWidget(widget);
editor->configureCodeAssistant();
return editor;
}
bool QmlJSEditor::open(QString *errorString, const QString &fileName, const QString &realFileName)
{
bool b = BaseTextEditor::open(errorString, fileName, realFileName);
......@@ -898,6 +886,11 @@ QmlJSEditor::QmlJSEditor()
setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<Internal::QmlJSCompletionAssistProvider>());
}
void QmlJSEditor::finalizeInitialization()
{
configureCodeAssistant();
}
bool QmlJSEditor::isDesignModePreferred() const
{
// stay in design mode if we are there
......@@ -921,7 +914,13 @@ QmlJSEditorFactory::QmlJSEditorFactory()
addMimeType(QmlJSTools::Constants::QMLTYPES_MIMETYPE);
addMimeType(QmlJSTools::Constants::JS_MIMETYPE);
addMimeType(QmlJSTools::Constants::JSON_MIMETYPE);
new TextEditorActionHandler(this, Constants::C_QMLJSEDITOR_ID,
setDocumentCreator([]() { return new QmlJSEditorDocument; });
setEditorWidgetCreator([]() { return new QmlJSEditorWidget; });
setEditorCreator([]() { return new QmlJSEditor; });
setAutoCompleterCreator([]() { return new AutoCompleter; });
setEditorActionHandlers(Constants::C_QMLJSEDITOR_ID,
TextEditorActionHandler::Format
| TextEditorActionHandler::UnCommentSelection
| TextEditorActionHandler::UnCollapseAll
......@@ -929,13 +928,5 @@ QmlJSEditorFactory::QmlJSEditorFactory()
}
IEditor *QmlJSEditorFactory::createEditor()
{
auto editor = new QmlJSEditor;
editor->setEditorWidget(new QmlJSEditorWidget(BaseTextDocumentPtr(new QmlJSEditorDocument)));
editor->configureCodeAssistant();
return editor;
}
} // namespace Internal
} // namespace QmlJSEditor
......@@ -34,7 +34,6 @@
#include <qmljs/qmljsscanner.h>
#include <qmljstools/qmljssemanticinfo.h>
#include <coreplugin/editormanager/ieditorfactory.h>
#include <texteditor/basetexteditor.h>
#include <texteditor/quickfix.h>
#include <texteditor/texteditorconstants.h>
......@@ -65,8 +64,9 @@ class QmlJSEditorWidget : public TextEditor::BaseTextEditorWidget
Q_OBJECT
public:
QmlJSEditorWidget(TextEditor::BaseTextDocumentPtr doc);
~QmlJSEditorWidget();
QmlJSEditorWidget();
void finalizeInitialization();
QmlJSEditorDocument *qmlJsEditorDocument() const;
......@@ -146,19 +146,17 @@ class QmlJSEditor : public TextEditor::BaseTextEditor
public:
QmlJSEditor();
Core::IEditor *duplicate();
bool open(QString *errorString, const QString &fileName, const QString &realFileName);
bool isDesignModePreferred() const;
void finalizeInitialization();
};
class QmlJSEditorFactory : public Core::IEditorFactory
class QmlJSEditorFactory : public TextEditor::BaseTextEditorFactory
{
Q_OBJECT
public:
QmlJSEditorFactory();
Core::IEditor *createEditor();
};
} // namespace Internal
......
......@@ -29,6 +29,7 @@
#include "qmljshoverhandler.h"
#include "qmljseditor.h"
#include "qmljseditorconstants.h"
#include "qmljseditordocument.h"
#include "qmlexpressionundercursor.h"
......@@ -97,10 +98,7 @@ HoverHandler::HoverHandler(QObject *parent) : BaseHoverHandler(parent), m_modelM
bool HoverHandler::acceptEditor(IEditor *editor)
{
QmlJSEditor *qmlEditor = qobject_cast<QmlJSEditor *>(editor);
if (qmlEditor)
return true;
return false;
return editor->context().contains(Constants::C_QMLJSEDITOR_ID);
}
static inline QString getModuleName(const ScopeChain &scopeChain, const Document::Ptr &qmlDocument,
......
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