Commit 8d48c511 authored by Kai Koehne's avatar Kai Koehne

QmlJSEditor: Delay update of outline by 150 ms

parent 2bafdb71
......@@ -80,7 +80,7 @@
enum {
UPDATE_DOCUMENT_DEFAULT_INTERVAL = 50,
UPDATE_USES_DEFAULT_INTERVAL = 150,
UPDATE_METHOD_BOX_INTERVAL = 150
UPDATE_OUTLINE_INTERVAL = 150 // msecs after new semantic info has been arrived / cursor has moved
};
using namespace QmlJS;
......@@ -648,8 +648,13 @@ QmlJSTextEditor::QmlJSTextEditor(QWidget *parent) :
connect(this, SIGNAL(textChanged()), this, SLOT(updateDocument()));
connect(this, SIGNAL(textChanged()), this, SLOT(updateUses()));
m_updateOutlineTimer = new QTimer(this);
m_updateOutlineTimer->setInterval(UPDATE_OUTLINE_INTERVAL);
m_updateOutlineTimer->setSingleShot(true);
connect(m_updateOutlineTimer, SIGNAL(timeout()), this, SLOT(updateOutlineNow()));
m_updateMethodBoxTimer = new QTimer(this);
m_updateMethodBoxTimer->setInterval(UPDATE_METHOD_BOX_INTERVAL);
m_updateMethodBoxTimer->setInterval(UPDATE_OUTLINE_INTERVAL);
m_updateMethodBoxTimer->setSingleShot(true);
connect(m_updateMethodBoxTimer, SIGNAL(timeout()), this, SLOT(updateMethodBoxIndex()));
......@@ -804,6 +809,8 @@ void QmlJSTextEditor::onDocumentUpdated(QmlJS::Document::Ptr doc)
const SemanticHighlighter::Source source = currentSource(/*force = */ true);
m_semanticHighlighter->rehighlight(source);
m_updateOutlineTimer->start();
} else {
// show parsing errors
QList<QTextEdit::ExtraSelection> selections;
......@@ -830,12 +837,29 @@ void QmlJSTextEditor::jumpToMethod(int /*index*/)
setFocus();
}
void QmlJSTextEditor::updateOutlineNow()
{
const Snapshot snapshot = m_modelManager->snapshot();
Document::Ptr document = snapshot.document(file()->fileName());
if (!document)
return;
if (document->editorRevision() != editorRevision()) {
m_updateOutlineTimer->start();
return;
}
m_outlineModel->update(document);
updateMethodBoxIndex();
}
void QmlJSTextEditor::updateMethodBoxIndex()
{
if (!m_semanticInfo.document)
if (!m_outlineModel->document())
return;
if (m_semanticInfo.document->editorRevision() != editorRevision()) {
if (m_outlineModel->document()->editorRevision() != editorRevision()) {
m_updateMethodBoxTimer->start();
return;
}
......@@ -1375,9 +1399,6 @@ void QmlJSTextEditor::updateSemanticInfo(const SemanticInfo &semanticInfo)
FindDeclarations findDeclarations;
m_semanticInfo.declarations = findDeclarations(doc->ast());
m_outlineModel->update(doc);
updateMethodBoxIndex();
QTreeView *treeView = static_cast<QTreeView*>(m_methodCombo->view());
treeView->expandAll();
......
......@@ -233,6 +233,7 @@ private slots:
void updateDocument();
void updateDocumentNow();
void jumpToMethod(int index);
void updateOutlineNow();
void updateMethodBoxIndex();
void updateMethodBoxToolTip();
void updateFileName();
......@@ -278,6 +279,7 @@ private:
QTimer *m_updateDocumentTimer;
QTimer *m_updateUsesTimer;
QTimer *m_semanticRehighlightTimer;
QTimer *m_updateOutlineTimer;
QTimer *m_updateMethodBoxTimer;
QComboBox *m_methodCombo;
QmlOutlineModel *m_outlineModel;
......
......@@ -140,8 +140,15 @@ QmlOutlineModel::QmlOutlineModel(QObject *parent) :
{
}
QmlJS::Document::Ptr QmlOutlineModel::document() const
{
return m_document;
}
void QmlOutlineModel::update(QmlJS::Document::Ptr doc)
{
m_document = doc;
m_treePos.clear();
m_treePos.append(0);
m_currentItem = invisibleRootItem();
......
......@@ -19,6 +19,7 @@ public:
QmlOutlineModel(QObject *parent = 0);
QmlJS::Document::Ptr document() const;
void update(QmlJS::Document::Ptr doc);
QModelIndex enterElement(const QString &typeName, const QString &id, const QmlJS::AST::SourceLocation &location);
......@@ -36,6 +37,7 @@ private:
QStandardItem *parentItem();
QmlJS::Document::Ptr m_document;
QList<int> m_treePos;
QStandardItem *m_currentItem;
QmlJS::Icons m_icons;
......
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