Commit 782e0d37 authored by Eike Ziller's avatar Eike Ziller

QmlJSEditor: Move reparse trigger to document

Change-Id: I65bb9002a44343bb1d13b9c5c92f5057c1d5b25e
Reviewed-by: default avatarFawzi Mohamed <fawzi.mohamed@digia.com>
parent 34229955
......@@ -479,11 +479,6 @@ void QmlJSTextEditorWidget::ctor()
setAutoCompleter(new AutoCompleter);
setLanguageSettingsId(QmlJSTools::Constants::QML_JS_SETTINGS_ID);
m_updateDocumentTimer = new QTimer(this);
m_updateDocumentTimer->setInterval(UPDATE_DOCUMENT_DEFAULT_INTERVAL);
m_updateDocumentTimer->setSingleShot(true);
connect(m_updateDocumentTimer, SIGNAL(timeout()), this, SLOT(reparseDocumentNow()));
m_updateUsesTimer = new QTimer(this);
m_updateUsesTimer->setInterval(UPDATE_USES_DEFAULT_INTERVAL);
m_updateUsesTimer->setSingleShot(true);
......@@ -494,8 +489,6 @@ void QmlJSTextEditorWidget::ctor()
m_updateSemanticInfoTimer->setSingleShot(true);
connect(m_updateSemanticInfoTimer, SIGNAL(timeout()), this, SLOT(updateSemanticInfoNow()));
connect(this, SIGNAL(textChanged()), this, SLOT(reparseDocument()));
connect(this, SIGNAL(textChanged()), this, SLOT(updateUses()));
connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(updateUses()));
......@@ -610,19 +603,6 @@ bool QmlJSEditor::open(QString *errorString, const QString &fileName, const QStr
return b;
}
void QmlJSTextEditorWidget::reparseDocument()
{
m_updateDocumentTimer->start();
}
void QmlJSTextEditorWidget::reparseDocumentNow()
{
m_updateDocumentTimer->stop();
const QString fileName = baseTextDocument()->filePath();
m_modelManager->updateSourceFiles(QStringList() << fileName, false);
}
static void appendExtraSelectionsForMessages(
QList<QTextEdit::ExtraSelection> *selections,
const QList<DiagnosticMessage> &messages,
......
......@@ -119,8 +119,6 @@ public:
TextEditor::IAssistInterface *createAssistInterface(TextEditor::AssistKind assistKind,
TextEditor::AssistReason reason) const;
public slots:
void reparseDocument();
void reparseDocumentNow();
void updateSemanticInfo();
void updateSemanticInfoNow();
void findUsages();
......@@ -177,7 +175,6 @@ private:
QModelIndex indexForPosition(unsigned cursorPosition, const QModelIndex &rootIndex = QModelIndex()) const;
bool hideContextPane();
QTimer *m_updateDocumentTimer;
QTimer *m_updateUsesTimer;
QTimer *m_updateSemanticInfoTimer;
QTimer *m_updateOutlineTimer;
......
......@@ -36,7 +36,8 @@ HEADERS += \
qmljssemanticinfoupdater.h \
qmljssemantichighlighter.h \
qmljswrapinloader.h \
qmljseditordocument.h
qmljseditordocument.h \
qmljseditordocument_p.h
SOURCES += \
qmljseditor.cpp \
......
......@@ -38,6 +38,7 @@ QtcPlugin {
"qmljseditorconstants.h",
"qmljseditordocument.cpp",
"qmljseditordocument.h",
"qmljseditordocument_p.h",
"qmljseditoreditable.cpp",
"qmljseditoreditable.h",
"qmljseditorfactory.cpp",
......
......@@ -29,22 +29,54 @@
#include "qmljseditordocument.h"
#include "qmljseditordocument_p.h"
#include "qmljshighlighter.h"
#include <qmljstools/qmljsqtstylecodeformatter.h>
#include <qmljstools/qmljsmodelmanager.h>
using namespace QmlJSEditor;
using namespace QmlJSEditor::Internal;
namespace {
enum {
UPDATE_DOCUMENT_DEFAULT_INTERVAL = 100
};
}
QmlJSEditorDocumentPrivate::QmlJSEditorDocumentPrivate(QmlJSEditorDocument *parent)
: m_q(parent)
{
m_updateDocumentTimer = new QTimer(this);
m_updateDocumentTimer->setInterval(UPDATE_DOCUMENT_DEFAULT_INTERVAL);
m_updateDocumentTimer->setSingleShot(true);
connect(m_q->document(), SIGNAL(contentsChanged()), m_updateDocumentTimer, SLOT(start()));
connect(m_updateDocumentTimer, SIGNAL(timeout()), this, SLOT(reparseDocument()));
}
void QmlJSEditorDocumentPrivate::invalidateFormatterCache()
{
QmlJSTools::CreatorCodeFormatter formatter(m_q->tabSettings());
formatter.invalidateCache(m_q->document());
}
void QmlJSEditorDocumentPrivate::reparseDocument()
{
QmlJS::ModelManagerInterface::instance()->updateSourceFiles(QStringList() << m_q->filePath(),
false);
}
QmlJSEditorDocument::QmlJSEditorDocument()
: m_d(new QmlJSEditorDocumentPrivate(this))
{
connect(this, SIGNAL(tabSettingsChanged()),
this, SLOT(invalidateFormatterCache()));
m_d, SLOT(invalidateFormatterCache()));
setSyntaxHighlighter(new Highlighter(document()));
}
void QmlJSEditorDocument::invalidateFormatterCache()
QmlJSEditorDocument::~QmlJSEditorDocument()
{
QmlJSTools::CreatorCodeFormatter formatter(tabSettings());
formatter.invalidateCache(document());
delete m_d;
}
......@@ -35,13 +35,17 @@
namespace QmlJSEditor {
namespace Internal {
class QmlJSEditorDocumentPrivate;
class QmlJSEditorDocument : public TextEditor::BaseTextDocument
{
Q_OBJECT
public:
QmlJSEditorDocument();
private slots:
void invalidateFormatterCache();
~QmlJSEditorDocument();
private:
QmlJSEditorDocumentPrivate *m_d;
};
} // Internal
......
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** 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.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef QMLJSEDITORDOCUMENT_P_H
#define QMLJSEDITORDOCUMENT_P_H
#include <QObject>
#include <QTimer>
namespace QmlJSEditor {
namespace Internal {
class QmlJSEditorDocument;
class QmlJSEditorDocumentPrivate : public QObject
{
Q_OBJECT
public:
QmlJSEditorDocumentPrivate(QmlJSEditorDocument *parent);
public slots:
void invalidateFormatterCache();
void reparseDocument();
public:
QmlJSEditorDocument *m_q;
QTimer *m_updateDocumentTimer;
};
} // Internal
} // QmlJSEditor
#endif // QMLJSEDITORDOCUMENT_P_H
......@@ -320,7 +320,6 @@ void QmlJSEditorPlugin::currentEditorChanged(Core::IEditor *editor)
this, SLOT(checkCurrentEditorSemanticInfoUpToDate()));
connect(newTextEditor, SIGNAL(semanticInfoUpdated()),
this, SLOT(checkCurrentEditorSemanticInfoUpToDate()));
newTextEditor->reparseDocumentNow();
}
}
......
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