mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-21 11:23:51 +00:00
moved syntax highlighter from ScriptSubView to ScriptEdit
This commit is contained in:
parent
d4981c3037
commit
c2e3709d0f
4 changed files with 42 additions and 41 deletions
|
@ -6,9 +6,13 @@
|
||||||
#include <QRegExp>
|
#include <QRegExp>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
|
#include "../../model/doc/document.hpp"
|
||||||
|
|
||||||
#include "../../model/world/universalid.hpp"
|
#include "../../model/world/universalid.hpp"
|
||||||
#include "../../model/world/tablemimedata.hpp"
|
#include "../../model/world/tablemimedata.hpp"
|
||||||
|
|
||||||
|
#include "scripthighlighter.hpp"
|
||||||
|
|
||||||
CSVWorld::ScriptEdit::ChangeLock::ChangeLock (ScriptEdit& edit) : mEdit (edit)
|
CSVWorld::ScriptEdit::ChangeLock::ChangeLock (ScriptEdit& edit) : mEdit (edit)
|
||||||
{
|
{
|
||||||
++mEdit.mChangeLocked;
|
++mEdit.mChangeLocked;
|
||||||
|
@ -60,6 +64,14 @@ CSVWorld::ScriptEdit::ScriptEdit (QWidget* parent, const CSMDoc::Document& docum
|
||||||
<<CSMWorld::UniversalId::Type_Weapon
|
<<CSMWorld::UniversalId::Type_Weapon
|
||||||
<<CSMWorld::UniversalId::Type_Script
|
<<CSMWorld::UniversalId::Type_Script
|
||||||
<<CSMWorld::UniversalId::Type_Region;
|
<<CSMWorld::UniversalId::Type_Region;
|
||||||
|
|
||||||
|
mHighlighter = new ScriptHighlighter (document.getData(), ScriptEdit::document());
|
||||||
|
|
||||||
|
connect (&document.getData(), SIGNAL (idListChanged()), this, SLOT (idListChanged()));
|
||||||
|
|
||||||
|
connect (&mUpdateTimer, SIGNAL (timeout()), this, SLOT (updateHighlighting()));
|
||||||
|
|
||||||
|
mUpdateTimer.setSingleShot (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CSVWorld::ScriptEdit::isChangeLocked() const
|
bool CSVWorld::ScriptEdit::isChangeLocked() const
|
||||||
|
@ -127,3 +139,21 @@ bool CSVWorld::ScriptEdit::stringNeedsQuote (const std::string& id) const
|
||||||
//I'm not quite sure when do we need to put quotes. To be safe we will use quotes for anything other than…
|
//I'm not quite sure when do we need to put quotes. To be safe we will use quotes for anything other than…
|
||||||
return !(string.contains(mWhiteListQoutes));
|
return !(string.contains(mWhiteListQoutes));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CSVWorld::ScriptEdit::idListChanged()
|
||||||
|
{
|
||||||
|
mHighlighter->invalidateIds();
|
||||||
|
|
||||||
|
if (!mUpdateTimer.isActive())
|
||||||
|
mUpdateTimer.start (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSVWorld::ScriptEdit::updateHighlighting()
|
||||||
|
{
|
||||||
|
if (isChangeLocked())
|
||||||
|
return;
|
||||||
|
|
||||||
|
ChangeLock lock (*this);
|
||||||
|
|
||||||
|
mHighlighter->rehighlight();
|
||||||
|
}
|
|
@ -1,8 +1,9 @@
|
||||||
#ifndef SCRIPTEDIT_H
|
#ifndef SCRIPTEDIT_H
|
||||||
#define SCRIPTEDIT_H
|
#define SCRIPTEDIT_H
|
||||||
|
|
||||||
#include <qtextedit.h>
|
#include <QTextEdit>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
#include "../../model/world/universalid.hpp"
|
#include "../../model/world/universalid.hpp"
|
||||||
|
|
||||||
|
@ -16,6 +17,8 @@ namespace CSMDoc
|
||||||
|
|
||||||
namespace CSVWorld
|
namespace CSVWorld
|
||||||
{
|
{
|
||||||
|
class ScriptHighlighter;
|
||||||
|
|
||||||
class ScriptEdit : public QTextEdit
|
class ScriptEdit : public QTextEdit
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -40,6 +43,8 @@ namespace CSVWorld
|
||||||
private:
|
private:
|
||||||
|
|
||||||
int mChangeLocked;
|
int mChangeLocked;
|
||||||
|
ScriptHighlighter *mHighlighter;
|
||||||
|
QTimer mUpdateTimer;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -62,6 +67,12 @@ namespace CSVWorld
|
||||||
void dragMoveEvent (QDragMoveEvent* event);
|
void dragMoveEvent (QDragMoveEvent* event);
|
||||||
|
|
||||||
bool stringNeedsQuote(const std::string& id) const;
|
bool stringNeedsQuote(const std::string& id) const;
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
|
||||||
|
void idListChanged();
|
||||||
|
|
||||||
|
void updateHighlighting();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif // SCRIPTEDIT_H
|
#endif // SCRIPTEDIT_H
|
|
@ -3,8 +3,6 @@
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
#include <QTextEdit>
|
|
||||||
|
|
||||||
#include "../../model/doc/document.hpp"
|
#include "../../model/doc/document.hpp"
|
||||||
#include "../../model/world/universalid.hpp"
|
#include "../../model/world/universalid.hpp"
|
||||||
#include "../../model/world/data.hpp"
|
#include "../../model/world/data.hpp"
|
||||||
|
@ -12,7 +10,6 @@
|
||||||
#include "../../model/world/commands.hpp"
|
#include "../../model/world/commands.hpp"
|
||||||
#include "../../model/world/idtable.hpp"
|
#include "../../model/world/idtable.hpp"
|
||||||
|
|
||||||
#include "scripthighlighter.hpp"
|
|
||||||
#include "scriptedit.hpp"
|
#include "scriptedit.hpp"
|
||||||
|
|
||||||
CSVWorld::ScriptSubView::ScriptSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document)
|
CSVWorld::ScriptSubView::ScriptSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document)
|
||||||
|
@ -43,14 +40,6 @@ CSVWorld::ScriptSubView::ScriptSubView (const CSMWorld::UniversalId& id, CSMDoc:
|
||||||
|
|
||||||
connect (mModel, SIGNAL (rowsAboutToBeRemoved (const QModelIndex&, int, int)),
|
connect (mModel, SIGNAL (rowsAboutToBeRemoved (const QModelIndex&, int, int)),
|
||||||
this, SLOT (rowsAboutToBeRemoved (const QModelIndex&, int, int)));
|
this, SLOT (rowsAboutToBeRemoved (const QModelIndex&, int, int)));
|
||||||
|
|
||||||
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)
|
void CSVWorld::ScriptSubView::setEditLock (bool locked)
|
||||||
|
@ -58,14 +47,6 @@ void CSVWorld::ScriptSubView::setEditLock (bool locked)
|
||||||
mEditor->setReadOnly (locked);
|
mEditor->setReadOnly (locked);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSVWorld::ScriptSubView::idListChanged()
|
|
||||||
{
|
|
||||||
mHighlighter->invalidateIds();
|
|
||||||
|
|
||||||
if (!mUpdateTimer.isActive())
|
|
||||||
mUpdateTimer.start (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CSVWorld::ScriptSubView::textChanged()
|
void CSVWorld::ScriptSubView::textChanged()
|
||||||
{
|
{
|
||||||
if (mEditor->isChangeLocked())
|
if (mEditor->isChangeLocked())
|
||||||
|
@ -103,12 +84,3 @@ void CSVWorld::ScriptSubView::rowsAboutToBeRemoved (const QModelIndex& parent, i
|
||||||
deleteLater();
|
deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSVWorld::ScriptSubView::updateHighlighting()
|
|
||||||
{
|
|
||||||
if (mEditor->isChangeLocked())
|
|
||||||
return;
|
|
||||||
|
|
||||||
ScriptEdit::ChangeLock lock (*mEditor);
|
|
||||||
|
|
||||||
mHighlighter->rehighlight();
|
|
||||||
}
|
|
|
@ -3,9 +3,6 @@
|
||||||
|
|
||||||
#include "../doc/subview.hpp"
|
#include "../doc/subview.hpp"
|
||||||
|
|
||||||
#include <QTimer>
|
|
||||||
|
|
||||||
class QTextEdit;
|
|
||||||
class QModelIndex;
|
class QModelIndex;
|
||||||
|
|
||||||
namespace CSMDoc
|
namespace CSMDoc
|
||||||
|
@ -20,7 +17,6 @@ namespace CSMWorld
|
||||||
|
|
||||||
namespace CSVWorld
|
namespace CSVWorld
|
||||||
{
|
{
|
||||||
class ScriptHighlighter;
|
|
||||||
class ScriptEdit;
|
class ScriptEdit;
|
||||||
|
|
||||||
class ScriptSubView : public CSVDoc::SubView
|
class ScriptSubView : public CSVDoc::SubView
|
||||||
|
@ -31,8 +27,6 @@ namespace CSVWorld
|
||||||
CSMDoc::Document& mDocument;
|
CSMDoc::Document& mDocument;
|
||||||
CSMWorld::IdTable *mModel;
|
CSMWorld::IdTable *mModel;
|
||||||
int mColumn;
|
int mColumn;
|
||||||
ScriptHighlighter *mHighlighter;
|
|
||||||
QTimer mUpdateTimer;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -42,17 +36,11 @@ namespace CSVWorld
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
void idListChanged();
|
|
||||||
|
|
||||||
void textChanged();
|
void textChanged();
|
||||||
|
|
||||||
void dataChanged (const QModelIndex& topLeft, const QModelIndex& bottomRight);
|
void dataChanged (const QModelIndex& topLeft, const QModelIndex& bottomRight);
|
||||||
|
|
||||||
void rowsAboutToBeRemoved (const QModelIndex& parent, int start, int end);
|
void rowsAboutToBeRemoved (const QModelIndex& parent, int start, int end);
|
||||||
|
|
||||||
private slots:
|
|
||||||
|
|
||||||
void updateHighlighting();
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue