Commit 77008bc4 authored by Friedemann Kleint's avatar Friedemann Kleint
Browse files

Exported Header cleanup: QmlJSEditor



Move internal classes QmlJSEditorEditable/SemanticHighlighter
out of qmljseditor.h. Move QmlJSEditor from namespace
QmlJSEditor::Internal to QmlJSEditor.
Reviewed-by: default avatarChristian Kamm <christian.d.kamm@nokia.com>
parent b3c2be6e
......@@ -70,7 +70,7 @@ int BaseTextEditModifier::indentDepth() const
bool BaseTextEditModifier::renameId(const QString &oldId, const QString &newId)
{
if (QmlJSEditor::Internal::QmlJSTextEditor *qmljse = qobject_cast<QmlJSEditor::Internal::QmlJSTextEditor*>(plainTextEdit())) {
if (QmlJSEditor::QmlJSTextEditor *qmljse = qobject_cast<QmlJSEditor::QmlJSTextEditor*>(plainTextEdit())) {
qmljse->renameId(oldId, newId);
return true;
} else {
......
......@@ -28,6 +28,7 @@
**************************************************************************/
#include "qmljseditor.h"
#include "qmljseditoreditable.h"
#include "qmljseditorconstants.h"
#include "qmljshighlighter.h"
#include "qmljseditorplugin.h"
......@@ -36,13 +37,12 @@
#include "qmljsquickfix.h"
#include "qmloutlinemodel.h"
#include "qmljsfindreferences.h"
#include "qmljssemantichighlighter.h"
#include <qmljs/qmljsbind.h>
#include <qmljs/qmljscheck.h>
#include <qmljs/qmljsdocument.h>
#include <qmljs/qmljsicontextpane.h>
#include <qmljs/qmljslookupcontext.h>
#include <qmljs/qmljslink.h>
#include <qmljs/parser/qmljsastvisitor_p.h>
#include <qmljs/parser/qmljsast_p.h>
#include <qmljs/parser/qmljsengine_p.h>
......@@ -52,9 +52,6 @@
#include <coreplugin/actionmanager/command.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/icore.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/modemanager.h>
#include <coreplugin/designmode.h>
#include <coreplugin/mimedatabase.h>
#include <extensionsystem/pluginmanager.h>
#include <texteditor/basetextdocument.h>
......@@ -89,6 +86,7 @@ enum {
using namespace QmlJS;
using namespace QmlJS::AST;
using namespace QmlJSEditor;
using namespace QmlJSEditor::Internal;
static int blockStartState(const QTextBlock &block)
......@@ -628,51 +626,6 @@ int SemanticInfo::revision() const
return 0;
}
QmlJSEditorEditable::QmlJSEditorEditable(QmlJSTextEditor *editor)
: BaseTextEditorEditable(editor)
{
m_context.add(QmlJSEditor::Constants::C_QMLJSEDITOR_ID);
m_context.add(TextEditor::Constants::C_TEXTEDITOR);
}
// Use preferred mode from Bauhaus settings
static bool openInDesignMode()
{
static bool bauhausDetected = false;
static bool bauhausPresent = false;
// Check if Bauhaus is loaded, that is, a Design mode widget is
// registered for the QML mime type.
if (!bauhausDetected) {
if (const Core::IMode *dm = Core::ModeManager::instance()->mode(QLatin1String(Core::Constants::MODE_DESIGN)))
if (const Core::DesignMode *designMode = qobject_cast<const Core::DesignMode *>(dm))
bauhausPresent = designMode->registeredMimeTypes().contains(QLatin1String(QmlJSEditor::Constants::QML_MIMETYPE));
bauhausDetected = true;
}
if (!bauhausPresent)
return false;
return bool(QmlDesigner::Constants::QML_OPENDESIGNMODE_DEFAULT);
}
QString QmlJSEditorEditable::preferredModeType() const
{
Core::ModeManager *modeManager = Core::ModeManager::instance();
if (modeManager->currentMode()
&& (modeManager->currentMode()->type() == Core::Constants::MODE_DESIGN_TYPE
|| modeManager->currentMode()->type() == Core::Constants::MODE_EDIT_TYPE))
{
return modeManager->currentMode()->type();
}
// if we are in other mode than edit or design, use the hard-coded default.
// because the editor opening decision is modal, it would be confusing to
// have the user also access to this failsafe setting.
if (editor()->mimeType() == QLatin1String(QmlJSEditor::Constants::QML_MIMETYPE)
&& openInDesignMode())
return QLatin1String(Core::Constants::MODE_DESIGN_TYPE);
return QString();
}
QmlJSTextEditor::QmlJSTextEditor(QWidget *parent) :
TextEditor::BaseTextEditor(parent),
m_outlineCombo(0),
......@@ -682,7 +635,7 @@ QmlJSTextEditor::QmlJSTextEditor(QWidget *parent) :
m_updateSelectedElements(false),
m_findReferences(new FindReferences(this))
{
qRegisterMetaType<QmlJSEditor::Internal::SemanticInfo>("QmlJSEditor::Internal::SemanticInfo");
qRegisterMetaType<QmlJSEditor::SemanticInfo>("QmlJSEditor::SemanticInfo");
m_semanticHighlighter = new SemanticHighlighter(this);
m_semanticHighlighter->start();
......@@ -748,8 +701,8 @@ QmlJSTextEditor::QmlJSTextEditor(QWidget *parent) :
connect(this->document(), SIGNAL(modificationChanged(bool)), this, SLOT(modificationChanged(bool)));
}
connect(m_semanticHighlighter, SIGNAL(changed(QmlJSEditor::Internal::SemanticInfo)),
this, SLOT(updateSemanticInfo(QmlJSEditor::Internal::SemanticInfo)));
connect(m_semanticHighlighter, SIGNAL(changed(QmlJSEditor::SemanticInfo)),
this, SLOT(updateSemanticInfo(QmlJSEditor::SemanticInfo)));
connect(this, SIGNAL(refactorMarkerClicked(TextEditor::RefactorMarker)),
SLOT(onRefactorMarkerClicked(TextEditor::RefactorMarker)));
......@@ -885,7 +838,7 @@ void QmlJSTextEditor::onDocumentUpdated(QmlJS::Document::Ptr doc)
if (doc->ast()) {
// got a correctly parsed (or recovered) file.
const SemanticHighlighter::Source source = currentSource(/*force = */ true);
const SemanticHighlighterSource source = currentSource(/*force = */ true);
m_semanticHighlighter->rehighlight(source);
} else {
// show parsing errors
......@@ -1857,7 +1810,7 @@ bool QmlJSTextEditor::hideContextPane()
return b;
}
SemanticHighlighter::Source QmlJSTextEditor::currentSource(bool force)
SemanticHighlighterSource QmlJSTextEditor::currentSource(bool force)
{
int line = 0, column = 0;
convertPosition(position(), &line, &column);
......@@ -1870,119 +1823,8 @@ SemanticHighlighter::Source QmlJSTextEditor::currentSource(bool force)
code = toPlainText(); // get the source code only when needed.
const unsigned revision = document()->revision();
SemanticHighlighter::Source source(snapshot, fileName, code,
SemanticHighlighterSource source(snapshot, fileName, code,
line, column, revision);
source.force = force;
return source;
}
SemanticHighlighter::SemanticHighlighter(QObject *parent)
: QThread(parent),
m_done(false),
m_modelManager(0)
{
}
SemanticHighlighter::~SemanticHighlighter()
{
}
void SemanticHighlighter::abort()
{
QMutexLocker locker(&m_mutex);
m_done = true;
m_condition.wakeOne();
}
void SemanticHighlighter::rehighlight(const Source &source)
{
QMutexLocker locker(&m_mutex);
m_source = source;
m_condition.wakeOne();
}
bool SemanticHighlighter::isOutdated()
{
QMutexLocker locker(&m_mutex);
const bool outdated = ! m_source.fileName.isEmpty() || m_done;
return outdated;
}
void SemanticHighlighter::run()
{
setPriority(QThread::LowestPriority);
forever {
m_mutex.lock();
while (! (m_done || ! m_source.fileName.isEmpty()))
m_condition.wait(&m_mutex);
const bool done = m_done;
const Source source = m_source;
m_source.clear();
m_mutex.unlock();
if (done)
break;
const SemanticInfo info = semanticInfo(source);
if (! isOutdated()) {
m_mutex.lock();
m_lastSemanticInfo = info;
m_mutex.unlock();
emit changed(info);
}
}
}
SemanticInfo SemanticHighlighter::semanticInfo(const Source &source)
{
m_mutex.lock();
const int revision = m_lastSemanticInfo.revision();
m_mutex.unlock();
Snapshot snapshot;
Document::Ptr doc;
if (! source.force && revision == source.revision) {
m_mutex.lock();
snapshot = m_lastSemanticInfo.snapshot;
doc = m_lastSemanticInfo.document;
m_mutex.unlock();
}
if (! doc) {
snapshot = source.snapshot;
doc = snapshot.documentFromSource(source.code, source.fileName);
doc->setEditorRevision(source.revision);
doc->parse();
snapshot.insert(doc);
}
SemanticInfo semanticInfo;
semanticInfo.snapshot = snapshot;
semanticInfo.document = doc;
Interpreter::Context *ctx = new Interpreter::Context;
Link link(ctx, doc, snapshot, ModelManagerInterface::instance()->importPaths());
semanticInfo.m_context = QSharedPointer<const QmlJS::Interpreter::Context>(ctx);
semanticInfo.semanticMessages = link.diagnosticMessages();
QStringList importPaths;
if (m_modelManager)
importPaths = m_modelManager->importPaths();
Check checker(doc, snapshot, ctx);
semanticInfo.semanticMessages.append(checker());
return semanticInfo;
}
void SemanticHighlighter::setModelManager(QmlJS::ModelManagerInterface *modelManager)
{
m_modelManager = modelManager;
}
......@@ -38,10 +38,8 @@
#include <texteditor/basetexteditor.h>
#include <texteditor/quickfix.h>
#include <QtCore/QWaitCondition>
#include <QtCore/QSharedPointer>
#include <QtCore/QModelIndex>
#include <QtCore/QMutex>
#include <QtCore/QThread>
QT_BEGIN_NAMESPACE
class QComboBox;
......@@ -62,34 +60,16 @@ namespace QmlJS {
The top-level namespace of the QmlJSEditor plug-in.
*/
namespace QmlJSEditor {
class Highlighter;
class FindReferences;
namespace Internal {
class QmlJSTextEditor;
class QmlOutlineModel;
class QmlJSEditorEditable;
class SemanticHighlighter;
struct SemanticHighlighterSource;
} // namespace Internal
class QmlJSEditorEditable : public TextEditor::BaseTextEditorEditable
{
Q_OBJECT
public:
QmlJSEditorEditable(QmlJSTextEditor *);
Core::Context context() const;
bool duplicateSupported() const { return true; }
Core::IEditor *duplicate(QWidget *parent);
QString id() const;
bool isTemporary() const { return false; }
virtual bool open(const QString & fileName);
virtual QString preferredModeType() const;
private:
Core::Context m_context;
};
struct Declaration
struct QMLJSEDITOR_EXPORT Declaration
{
QString text;
int startLine;
......@@ -105,7 +85,7 @@ struct Declaration
{ }
};
class Range
class QMLJSEDITOR_EXPORT Range
{
public:
Range(): ast(0) {}
......@@ -116,8 +96,6 @@ public: // attributes
QTextCursor end;
};
class SemanticHighlighter;
class QMLJSEDITOR_EXPORT SemanticInfo
{
public:
......@@ -152,75 +130,7 @@ public: // attributes
private:
QSharedPointer<const QmlJS::Interpreter::Context> m_context;
friend class SemanticHighlighter;
};
class SemanticHighlighter: public QThread
{
Q_OBJECT
public:
SemanticHighlighter(QObject *parent = 0);
virtual ~SemanticHighlighter();
void abort();
struct Source
{
QmlJS::Snapshot snapshot;
QString fileName;
QString code;
int line;
int column;
int revision;
bool force;
Source()
: line(0), column(0), revision(0), force(false)
{ }
Source(const QmlJS::Snapshot &snapshot,
const QString &fileName,
const QString &code,
int line, int column,
int revision)
: snapshot(snapshot), fileName(fileName),
code(code), line(line), column(column),
revision(revision), force(false)
{ }
void clear()
{
snapshot = QmlJS::Snapshot();
fileName.clear();
code.clear();
line = 0;
column = 0;
revision = 0;
force = false;
}
};
void rehighlight(const Source &source);
void setModelManager(QmlJS::ModelManagerInterface *modelManager);
Q_SIGNALS:
void changed(const QmlJSEditor::Internal::SemanticInfo &semanticInfo);
protected:
virtual void run();
private:
bool isOutdated();
SemanticInfo semanticInfo(const Source &source);
private:
QMutex m_mutex;
QWaitCondition m_condition;
bool m_done;
Source m_source;
SemanticInfo m_lastSemanticInfo;
QmlJS::ModelManagerInterface *m_modelManager;
friend class Internal::SemanticHighlighter;
};
class QMLJSEDITOR_EXPORT QmlJSTextEditor : public TextEditor::BaseTextEditor
......@@ -237,7 +147,7 @@ public:
int editorRevision() const;
bool isOutdated() const;
QmlOutlineModel *outlineModel() const;
Internal::QmlOutlineModel *outlineModel() const;
QModelIndex outlineModelIndex();
bool updateSelectedElements() const;
......@@ -276,7 +186,7 @@ private slots:
void semanticRehighlight();
void forceSemanticRehighlight();
void updateSemanticInfo(const QmlJSEditor::Internal::SemanticInfo &semanticInfo);
void updateSemanticInfo(const QmlJSEditor::SemanticInfo &semanticInfo);
void onCursorPositionChanged();
void onRefactorMarkerClicked(const TextEditor::RefactorMarker &marker);
......@@ -289,7 +199,7 @@ protected:
void resizeEvent(QResizeEvent *event);
void scrollContentsBy(int dx, int dy);
TextEditor::BaseTextEditorEditable *createEditableInterface();
void createToolBar(QmlJSEditorEditable *editable);
void createToolBar(Internal::QmlJSEditorEditable *editable);
TextEditor::BaseTextEditor::Link findLinkAt(const QTextCursor &cursor, bool resolveTarget = true);
//// brace matching
......@@ -307,7 +217,7 @@ private:
void setSelectedElements();
QString wordUnderCursor() const;
SemanticHighlighter::Source currentSource(bool force = false);
Internal::SemanticHighlighterSource currentSource(bool force = false);
QModelIndex indexForPosition(unsigned cursorPosition, const QModelIndex &rootIndex = QModelIndex()) const;
bool hideContextPane();
......@@ -320,14 +230,14 @@ private:
QTimer *m_updateOutlineIndexTimer;
QTimer *m_cursorPositionTimer;
QComboBox *m_outlineCombo;
QmlOutlineModel *m_outlineModel;
Internal::QmlOutlineModel *m_outlineModel;
QModelIndex m_outlineModelIndex;
QmlJS::ModelManagerInterface *m_modelManager;
QTextCharFormat m_occurrencesFormat;
QTextCharFormat m_occurrencesUnusedFormat;
QTextCharFormat m_occurrenceRenameFormat;
SemanticHighlighter *m_semanticHighlighter;
Internal::SemanticHighlighter *m_semanticHighlighter;
SemanticInfo m_semanticInfo;
QList<TextEditor::QuickFixOperation::Ptr> m_quickFixes;
......@@ -339,7 +249,6 @@ private:
FindReferences *m_findReferences;
};
} // namespace Internal
} // namespace QmlJSEditor
#endif // QMLJSEDITOR_H
......@@ -32,7 +32,9 @@ HEADERS += \
quicktoolbarsettingspage.h \
quicktoolbar.h \
qmljscomponentnamedialog.h \
qmljsfindreferences.h
qmljsfindreferences.h \
qmljseditoreditable.h \
qmljssemantichighlighter.h
SOURCES += \
qmljscodecompletion.cpp \
......@@ -58,7 +60,9 @@ SOURCES += \
quicktoolbarsettingspage.cpp \
quicktoolbar.cpp \
qmljscomponentnamedialog.cpp \
qmljsfindreferences.cpp
qmljsfindreferences.cpp \
qmljseditoreditable.cpp \
qmljssemantichighlighter.cpp
RESOURCES += qmljseditor.qrc
OTHER_FILES += QmlJSEditor.pluginspec QmlJSEditor.mimetypes.xml
......
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#include "qmljseditoreditable.h"
#include "qmljseditor.h"
#include "qmljseditorconstants.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>
namespace QmlJSEditor {
namespace Internal {
QmlJSEditorEditable::QmlJSEditorEditable(QmlJSTextEditor *editor)
: BaseTextEditorEditable(editor)
{
m_context.add(QmlJSEditor::Constants::C_QMLJSEDITOR_ID);
m_context.add(TextEditor::Constants::C_TEXTEDITOR);
}
// Use preferred mode from Bauhaus settings
static bool openInDesignMode()
{
static bool bauhausDetected = false;
static bool bauhausPresent = false;
// Check if Bauhaus is loaded, that is, a Design mode widget is
// registered for the QML mime type.
if (!bauhausDetected) {
if (const Core::IMode *dm = Core::ModeManager::instance()->mode(QLatin1String(Core::Constants::MODE_DESIGN)))
if (const Core::DesignMode *designMode = qobject_cast<const Core::DesignMode *>(dm))
bauhausPresent = designMode->registeredMimeTypes().contains(QLatin1String(QmlJSEditor::Constants::QML_MIMETYPE));
bauhausDetected = true;
}
if (!bauhausPresent)
return false;
return bool(QmlDesigner::Constants::QML_OPENDESIGNMODE_DEFAULT);
}
QString QmlJSEditorEditable::preferredModeType() const
{
Core::ModeManager *modeManager = Core::ModeManager::instance();
if (modeManager->currentMode()
&& (modeManager->currentMode()->type() == Core::Constants::MODE_DESIGN_TYPE
|| modeManager->currentMode()->type() == Core::Constants::MODE_EDIT_TYPE))
{
return modeManager->currentMode()->type();
}
// if we are in other mode than edit or design, use the hard-coded default.
// because the editor opening decision is modal, it would be confusing to
// have the user also access to this failsafe setting.
if (editor()->mimeType() == QLatin1String(QmlJSEditor::Constants::QML_MIMETYPE)
&& openInDesignMode())
return QLatin1String(Core::Constants::MODE_DESIGN_TYPE);
return QString();
}
} // namespace Internal
} // namespace QmlJSEditor
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#ifndef QMLJSEDITOREDITABLE_H