QmlJSEditor: Use a BaseTextEditorFactory for creation

Change-Id: I37e81cf3eda57780c893f4e8d7f2c5c6adf75b55
Reviewed-by: Christian Stenger <christian.stenger@digia.com>
This commit is contained in:
hjk
2014-08-23 00:19:48 +02:00
parent 173879eb1f
commit 74c572b532
3 changed files with 25 additions and 38 deletions

View File

@@ -106,12 +106,8 @@ namespace Internal {
// QmlJSEditorWidget // QmlJSEditorWidget
// //
QmlJSEditorWidget::QmlJSEditorWidget(BaseTextDocumentPtr doc) QmlJSEditorWidget::QmlJSEditorWidget()
{ {
setTextDocument(doc);
setAutoCompleter(new AutoCompleter);
m_qmlJsEditorDocument = static_cast<QmlJSEditorDocument *>(doc.data());
m_outlineCombo = 0; m_outlineCombo = 0;
m_contextPane = 0; m_contextPane = 0;
m_findReferences = new FindReferences(this); m_findReferences = new FindReferences(this);
@@ -120,6 +116,11 @@ QmlJSEditorWidget::QmlJSEditorWidget(BaseTextDocumentPtr doc)
setMarksVisible(true); setMarksVisible(true);
setCodeFoldingSupported(true); setCodeFoldingSupported(true);
setLanguageSettingsId(QmlJSTools::Constants::QML_JS_SETTINGS_ID); setLanguageSettingsId(QmlJSTools::Constants::QML_JS_SETTINGS_ID);
}
void QmlJSEditorWidget::finalizeInitialization()
{
m_qmlJsEditorDocument = static_cast<QmlJSEditorDocument *>(textDocument());
m_updateUsesTimer = new QTimer(this); m_updateUsesTimer = new QTimer(this);
m_updateUsesTimer->setInterval(UPDATE_USES_DEFAULT_INTERVAL); m_updateUsesTimer->setInterval(UPDATE_USES_DEFAULT_INTERVAL);
@@ -160,10 +161,6 @@ QmlJSEditorWidget::QmlJSEditorWidget(BaseTextDocumentPtr doc)
createToolBar(); createToolBar();
} }
QmlJSEditorWidget::~QmlJSEditorWidget()
{
}
QModelIndex QmlJSEditorWidget::outlineModelIndex() QModelIndex QmlJSEditorWidget::outlineModelIndex()
{ {
if (!m_outlineModelIndex.isValid()) { if (!m_outlineModelIndex.isValid()) {
@@ -173,15 +170,6 @@ QModelIndex QmlJSEditorWidget::outlineModelIndex()
return m_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 QmlJSEditor::open(QString *errorString, const QString &fileName, const QString &realFileName)
{ {
bool b = BaseTextEditor::open(errorString, fileName, realFileName); bool b = BaseTextEditor::open(errorString, fileName, realFileName);
@@ -898,6 +886,11 @@ QmlJSEditor::QmlJSEditor()
setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<Internal::QmlJSCompletionAssistProvider>()); setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<Internal::QmlJSCompletionAssistProvider>());
} }
void QmlJSEditor::finalizeInitialization()
{
configureCodeAssistant();
}
bool QmlJSEditor::isDesignModePreferred() const bool QmlJSEditor::isDesignModePreferred() const
{ {
// stay in design mode if we are there // stay in design mode if we are there
@@ -921,7 +914,13 @@ QmlJSEditorFactory::QmlJSEditorFactory()
addMimeType(QmlJSTools::Constants::QMLTYPES_MIMETYPE); addMimeType(QmlJSTools::Constants::QMLTYPES_MIMETYPE);
addMimeType(QmlJSTools::Constants::JS_MIMETYPE); addMimeType(QmlJSTools::Constants::JS_MIMETYPE);
addMimeType(QmlJSTools::Constants::JSON_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::Format
| TextEditorActionHandler::UnCommentSelection | TextEditorActionHandler::UnCommentSelection
| TextEditorActionHandler::UnCollapseAll | 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 Internal
} // namespace QmlJSEditor } // namespace QmlJSEditor

View File

@@ -34,7 +34,6 @@
#include <qmljs/qmljsscanner.h> #include <qmljs/qmljsscanner.h>
#include <qmljstools/qmljssemanticinfo.h> #include <qmljstools/qmljssemanticinfo.h>
#include <coreplugin/editormanager/ieditorfactory.h>
#include <texteditor/basetexteditor.h> #include <texteditor/basetexteditor.h>
#include <texteditor/quickfix.h> #include <texteditor/quickfix.h>
#include <texteditor/texteditorconstants.h> #include <texteditor/texteditorconstants.h>
@@ -65,8 +64,9 @@ class QmlJSEditorWidget : public TextEditor::BaseTextEditorWidget
Q_OBJECT Q_OBJECT
public: public:
QmlJSEditorWidget(TextEditor::BaseTextDocumentPtr doc); QmlJSEditorWidget();
~QmlJSEditorWidget();
void finalizeInitialization();
QmlJSEditorDocument *qmlJsEditorDocument() const; QmlJSEditorDocument *qmlJsEditorDocument() const;
@@ -146,19 +146,17 @@ class QmlJSEditor : public TextEditor::BaseTextEditor
public: public:
QmlJSEditor(); QmlJSEditor();
Core::IEditor *duplicate();
bool open(QString *errorString, const QString &fileName, const QString &realFileName); bool open(QString *errorString, const QString &fileName, const QString &realFileName);
bool isDesignModePreferred() const; bool isDesignModePreferred() const;
void finalizeInitialization();
}; };
class QmlJSEditorFactory : public Core::IEditorFactory class QmlJSEditorFactory : public TextEditor::BaseTextEditorFactory
{ {
Q_OBJECT Q_OBJECT
public: public:
QmlJSEditorFactory(); QmlJSEditorFactory();
Core::IEditor *createEditor();
}; };
} // namespace Internal } // namespace Internal

View File

@@ -29,6 +29,7 @@
#include "qmljshoverhandler.h" #include "qmljshoverhandler.h"
#include "qmljseditor.h" #include "qmljseditor.h"
#include "qmljseditorconstants.h"
#include "qmljseditordocument.h" #include "qmljseditordocument.h"
#include "qmlexpressionundercursor.h" #include "qmlexpressionundercursor.h"
@@ -97,10 +98,7 @@ HoverHandler::HoverHandler(QObject *parent) : BaseHoverHandler(parent), m_modelM
bool HoverHandler::acceptEditor(IEditor *editor) bool HoverHandler::acceptEditor(IEditor *editor)
{ {
QmlJSEditor *qmlEditor = qobject_cast<QmlJSEditor *>(editor); return editor->context().contains(Constants::C_QMLJSEDITOR_ID);
if (qmlEditor)
return true;
return false;
} }
static inline QString getModuleName(const ScopeChain &scopeChain, const Document::Ptr &qmlDocument, static inline QString getModuleName(const ScopeChain &scopeChain, const Document::Ptr &qmlDocument,