update syntax highlighting when ID list changes

actorid
Marc Zinnschlag 11 years ago
parent ba5e2a0330
commit 8d4f4e395f

@ -125,5 +125,9 @@ void CSVWorld::ScriptHighlighter::highlightBlock (const QString& text)
scanner.scan (*this);
}
catch (...) {} // ignore syntax errors
}
void CSVWorld::ScriptHighlighter::invalidateIds()
{
mContext.invalidateIds();
}

@ -77,6 +77,8 @@ namespace CSVWorld
ScriptHighlighter (const CSMWorld::Data& data, QTextDocument *parent);
virtual void highlightBlock (const QString& text);
void invalidateIds();
};
}

@ -58,7 +58,13 @@ CSVWorld::ScriptSubView::ScriptSubView (const CSMWorld::UniversalId& id, CSMDoc:
connect (mModel, SIGNAL (rowsAboutToBeRemoved (const QModelIndex&, int, int)),
this, SLOT (rowsAboutToBeRemoved (const QModelIndex&, int, int)));
new ScriptHighlighter (document.getData(), mEditor->document());
connect (&document.getData(), SIGNAL (idListChanged()), this, SLOT (idListChanged()));
mHighlighter = new ScriptHighlighter (document.getData(), mEditor->document());
connect (&mUpdateTimer, SIGNAL (timeout()), this, SLOT (updateHighlighting()));
mUpdateTimer.setSingleShot (true);
}
void CSVWorld::ScriptSubView::setEditLock (bool locked)
@ -66,8 +72,19 @@ void CSVWorld::ScriptSubView::setEditLock (bool locked)
mEditor->setReadOnly (locked);
}
void CSVWorld::ScriptSubView::idListChanged()
{
mHighlighter->invalidateIds();
if (!mUpdateTimer.isActive())
mUpdateTimer.start (0);
}
void CSVWorld::ScriptSubView::textChanged()
{
if (mChangeLocked)
return;
ChangeLock lock (*this);
mDocument.getUndoStack().push (new CSMWorld::ModifyCommand (*mModel,
@ -79,6 +96,8 @@ void CSVWorld::ScriptSubView::dataChanged (const QModelIndex& topLeft, const QMo
if (mChangeLocked)
return;
ChangeLock lock (*this);
QModelIndex index = mModel->getModelIndex (getUniversalId().getId(), mColumn);
if (index.row()>=topLeft.row() && index.row()<=bottomRight.row() &&
@ -96,4 +115,14 @@ void CSVWorld::ScriptSubView::rowsAboutToBeRemoved (const QModelIndex& parent, i
if (!parent.isValid() && index.row()>=start && index.row()<=end)
deleteLater();
}
void CSVWorld::ScriptSubView::updateHighlighting()
{
if (mChangeLocked)
return;
ChangeLock lock (*this);
mHighlighter->rehighlight();
}

@ -3,6 +3,8 @@
#include "../doc/subview.hpp"
#include <QTimer>
class QTextEdit;
class QModelIndex;
@ -18,6 +20,8 @@ namespace CSMWorld
namespace CSVWorld
{
class ScriptHighlighter;
class ScriptSubView : public CSVDoc::SubView
{
Q_OBJECT
@ -27,6 +31,8 @@ namespace CSVWorld
CSMWorld::IdTable *mModel;
int mColumn;
int mChangeLocked;
ScriptHighlighter *mHighlighter;
QTimer mUpdateTimer;
class ChangeLock
{
@ -49,13 +55,19 @@ namespace CSVWorld
virtual void setEditLock (bool locked);
private slots:
public slots:
void idListChanged();
void textChanged();
void dataChanged (const QModelIndex& topLeft, const QModelIndex& bottomRight);
void rowsAboutToBeRemoved (const QModelIndex& parent, int start, int end);
private slots:
void updateHighlighting();
};
}

Loading…
Cancel
Save