forked from mirror/openmw-tes3mp
syntax highlighter modes
This commit is contained in:
parent
5c536d571b
commit
ea4cd94c25
6 changed files with 33 additions and 12 deletions
|
@ -11,7 +11,6 @@
|
|||
#include "../../model/world/universalid.hpp"
|
||||
#include "../../model/world/tablemimedata.hpp"
|
||||
|
||||
#include "scripthighlighter.hpp"
|
||||
|
||||
CSVWorld::ScriptEdit::ChangeLock::ChangeLock (ScriptEdit& edit) : mEdit (edit)
|
||||
{
|
||||
|
@ -24,8 +23,9 @@ CSVWorld::ScriptEdit::ChangeLock::~ChangeLock()
|
|||
}
|
||||
|
||||
|
||||
CSVWorld::ScriptEdit::ScriptEdit (const CSMDoc::Document& document, QWidget* parent) :
|
||||
QTextEdit (parent),
|
||||
CSVWorld::ScriptEdit::ScriptEdit (const CSMDoc::Document& document, ScriptHighlighter::Mode mode,
|
||||
QWidget* parent)
|
||||
: QTextEdit (parent),
|
||||
mDocument (document),
|
||||
mWhiteListQoutes("^[a-z|_]{1}[a-z|0-9|_]{0,}$", Qt::CaseInsensitive),
|
||||
mChangeLocked (0)
|
||||
|
@ -65,7 +65,7 @@ CSVWorld::ScriptEdit::ScriptEdit (const CSMDoc::Document& document, QWidget* par
|
|||
<<CSMWorld::UniversalId::Type_Script
|
||||
<<CSMWorld::UniversalId::Type_Region;
|
||||
|
||||
mHighlighter = new ScriptHighlighter (document.getData(), ScriptEdit::document());
|
||||
mHighlighter = new ScriptHighlighter (document.getData(), mode, ScriptEdit::document());
|
||||
|
||||
connect (&document.getData(), SIGNAL (idListChanged()), this, SLOT (idListChanged()));
|
||||
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
|
||||
#include "../../model/world/universalid.hpp"
|
||||
|
||||
#include "scripthighlighter.hpp"
|
||||
|
||||
class QWidget;
|
||||
class QRegExp;
|
||||
|
||||
|
@ -17,8 +19,6 @@ namespace CSMDoc
|
|||
|
||||
namespace CSVWorld
|
||||
{
|
||||
class ScriptHighlighter;
|
||||
|
||||
class ScriptEdit : public QTextEdit
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -48,7 +48,8 @@ namespace CSVWorld
|
|||
|
||||
public:
|
||||
|
||||
ScriptEdit (const CSMDoc::Document& document, QWidget* parent);
|
||||
ScriptEdit (const CSMDoc::Document& document, ScriptHighlighter::Mode mode,
|
||||
QWidget* parent);
|
||||
|
||||
/// Should changes to the data be ignored (i.e. not cause updated)?
|
||||
///
|
||||
|
|
|
@ -30,6 +30,16 @@ bool CSVWorld::ScriptHighlighter::parseName (const std::string& name, const Comp
|
|||
bool CSVWorld::ScriptHighlighter::parseKeyword (int keyword, const Compiler::TokenLoc& loc,
|
||||
Compiler::Scanner& scanner)
|
||||
{
|
||||
if (((mMode==Mode_Console || mMode==Mode_Dialogue) &&
|
||||
(keyword==Compiler::Scanner::K_begin || keyword==Compiler::Scanner::K_end ||
|
||||
keyword==Compiler::Scanner::K_short || keyword==Compiler::Scanner::K_long ||
|
||||
keyword==Compiler::Scanner::K_float))
|
||||
|| (mMode==Mode_Console && (keyword==Compiler::Scanner::K_if ||
|
||||
keyword==Compiler::Scanner::K_endif || keyword==Compiler::Scanner::K_else ||
|
||||
keyword==Compiler::Scanner::K_elseif || keyword==Compiler::Scanner::K_while ||
|
||||
keyword==Compiler::Scanner::K_endwhile)))
|
||||
return parseName (loc.mLiteral, loc, scanner);
|
||||
|
||||
highlight (loc, Type_Keyword);
|
||||
return true;
|
||||
}
|
||||
|
@ -63,8 +73,10 @@ void CSVWorld::ScriptHighlighter::highlight (const Compiler::TokenLoc& loc, Type
|
|||
setFormat (index, length, mScheme[type]);
|
||||
}
|
||||
|
||||
CSVWorld::ScriptHighlighter::ScriptHighlighter (const CSMWorld::Data& data, QTextDocument *parent)
|
||||
: QSyntaxHighlighter (parent), Compiler::Parser (mErrorHandler, mContext), mContext (data)
|
||||
CSVWorld::ScriptHighlighter::ScriptHighlighter (const CSMWorld::Data& data, Mode mode,
|
||||
QTextDocument *parent)
|
||||
: QSyntaxHighlighter (parent), Compiler::Parser (mErrorHandler, mContext), mContext (data),
|
||||
mMode (mode)
|
||||
{
|
||||
/// \todo replace this with user settings
|
||||
{
|
||||
|
|
|
@ -28,12 +28,20 @@ namespace CSVWorld
|
|||
Type_Id
|
||||
};
|
||||
|
||||
enum Mode
|
||||
{
|
||||
Mode_General,
|
||||
Mode_Console,
|
||||
Mode_Dialogue
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
Compiler::NullErrorHandler mErrorHandler;
|
||||
Compiler::Extensions mExtensions;
|
||||
CSMWorld::ScriptContext mContext;
|
||||
std::map<Type, QTextCharFormat> mScheme;
|
||||
Mode mMode;
|
||||
|
||||
private:
|
||||
|
||||
|
@ -74,7 +82,7 @@ namespace CSVWorld
|
|||
|
||||
public:
|
||||
|
||||
ScriptHighlighter (const CSMWorld::Data& data, QTextDocument *parent);
|
||||
ScriptHighlighter (const CSMWorld::Data& data, Mode mode, QTextDocument *parent);
|
||||
|
||||
virtual void highlightBlock (const QString& text);
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
CSVWorld::ScriptSubView::ScriptSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document)
|
||||
: SubView (id), mDocument (document), mColumn (-1)
|
||||
{
|
||||
setWidget (mEditor = new ScriptEdit (mDocument, this));
|
||||
setWidget (mEditor = new ScriptEdit (mDocument, ScriptHighlighter::Mode_General, this));
|
||||
|
||||
mModel = &dynamic_cast<CSMWorld::IdTable&> (
|
||||
*document.getData().getTableModel (CSMWorld::UniversalId::Type_Scripts));
|
||||
|
|
|
@ -195,7 +195,7 @@ QWidget *CSVWorld::CommandDelegate::createEditor (QWidget *parent, const QStyleO
|
|||
|
||||
case CSMWorld::ColumnBase::Display_ScriptLines:
|
||||
|
||||
return new ScriptEdit (mDocument, parent);
|
||||
return new ScriptEdit (mDocument, ScriptHighlighter::Mode_Console, parent);
|
||||
|
||||
default:
|
||||
|
||||
|
|
Loading…
Reference in a new issue