QmlJSEditor: Move reparse trigger to document

Change-Id: I65bb9002a44343bb1d13b9c5c92f5057c1d5b25e
Reviewed-by: Fawzi Mohamed <fawzi.mohamed@digia.com>
This commit is contained in:
Eike Ziller
2014-01-23 15:28:06 +01:00
parent 3422995521
commit 782e0d37c3
8 changed files with 105 additions and 31 deletions

View File

@@ -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;
}