mirror of
https://github.com/OpenMW/openmw.git
synced 2025-04-01 07:06:43 +00:00
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/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)
|
||||||
{
|
{
|
||||||
|
@ -24,8 +23,9 @@ CSVWorld::ScriptEdit::ChangeLock::~ChangeLock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CSVWorld::ScriptEdit::ScriptEdit (const CSMDoc::Document& document, QWidget* parent) :
|
CSVWorld::ScriptEdit::ScriptEdit (const CSMDoc::Document& document, ScriptHighlighter::Mode mode,
|
||||||
QTextEdit (parent),
|
QWidget* parent)
|
||||||
|
: QTextEdit (parent),
|
||||||
mDocument (document),
|
mDocument (document),
|
||||||
mWhiteListQoutes("^[a-z|_]{1}[a-z|0-9|_]{0,}$", Qt::CaseInsensitive),
|
mWhiteListQoutes("^[a-z|_]{1}[a-z|0-9|_]{0,}$", Qt::CaseInsensitive),
|
||||||
mChangeLocked (0)
|
mChangeLocked (0)
|
||||||
|
@ -65,7 +65,7 @@ CSVWorld::ScriptEdit::ScriptEdit (const CSMDoc::Document& document, QWidget* par
|
||||||
<<CSMWorld::UniversalId::Type_Script
|
<<CSMWorld::UniversalId::Type_Script
|
||||||
<<CSMWorld::UniversalId::Type_Region;
|
<<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()));
|
connect (&document.getData(), SIGNAL (idListChanged()), this, SLOT (idListChanged()));
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
|
|
||||||
#include "../../model/world/universalid.hpp"
|
#include "../../model/world/universalid.hpp"
|
||||||
|
|
||||||
|
#include "scripthighlighter.hpp"
|
||||||
|
|
||||||
class QWidget;
|
class QWidget;
|
||||||
class QRegExp;
|
class QRegExp;
|
||||||
|
|
||||||
|
@ -17,8 +19,6 @@ namespace CSMDoc
|
||||||
|
|
||||||
namespace CSVWorld
|
namespace CSVWorld
|
||||||
{
|
{
|
||||||
class ScriptHighlighter;
|
|
||||||
|
|
||||||
class ScriptEdit : public QTextEdit
|
class ScriptEdit : public QTextEdit
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -48,7 +48,8 @@ namespace CSVWorld
|
||||||
|
|
||||||
public:
|
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)?
|
/// 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,
|
bool CSVWorld::ScriptHighlighter::parseKeyword (int keyword, const Compiler::TokenLoc& loc,
|
||||||
Compiler::Scanner& scanner)
|
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);
|
highlight (loc, Type_Keyword);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -63,8 +73,10 @@ void CSVWorld::ScriptHighlighter::highlight (const Compiler::TokenLoc& loc, Type
|
||||||
setFormat (index, length, mScheme[type]);
|
setFormat (index, length, mScheme[type]);
|
||||||
}
|
}
|
||||||
|
|
||||||
CSVWorld::ScriptHighlighter::ScriptHighlighter (const CSMWorld::Data& data, QTextDocument *parent)
|
CSVWorld::ScriptHighlighter::ScriptHighlighter (const CSMWorld::Data& data, Mode mode,
|
||||||
: QSyntaxHighlighter (parent), Compiler::Parser (mErrorHandler, mContext), mContext (data)
|
QTextDocument *parent)
|
||||||
|
: QSyntaxHighlighter (parent), Compiler::Parser (mErrorHandler, mContext), mContext (data),
|
||||||
|
mMode (mode)
|
||||||
{
|
{
|
||||||
/// \todo replace this with user settings
|
/// \todo replace this with user settings
|
||||||
{
|
{
|
||||||
|
|
|
@ -28,12 +28,20 @@ namespace CSVWorld
|
||||||
Type_Id
|
Type_Id
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum Mode
|
||||||
|
{
|
||||||
|
Mode_General,
|
||||||
|
Mode_Console,
|
||||||
|
Mode_Dialogue
|
||||||
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
Compiler::NullErrorHandler mErrorHandler;
|
Compiler::NullErrorHandler mErrorHandler;
|
||||||
Compiler::Extensions mExtensions;
|
Compiler::Extensions mExtensions;
|
||||||
CSMWorld::ScriptContext mContext;
|
CSMWorld::ScriptContext mContext;
|
||||||
std::map<Type, QTextCharFormat> mScheme;
|
std::map<Type, QTextCharFormat> mScheme;
|
||||||
|
Mode mMode;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -74,7 +82,7 @@ namespace CSVWorld
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
ScriptHighlighter (const CSMWorld::Data& data, QTextDocument *parent);
|
ScriptHighlighter (const CSMWorld::Data& data, Mode mode, QTextDocument *parent);
|
||||||
|
|
||||||
virtual void highlightBlock (const QString& text);
|
virtual void highlightBlock (const QString& text);
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
CSVWorld::ScriptSubView::ScriptSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document)
|
CSVWorld::ScriptSubView::ScriptSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document)
|
||||||
: SubView (id), mDocument (document), mColumn (-1)
|
: 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&> (
|
mModel = &dynamic_cast<CSMWorld::IdTable&> (
|
||||||
*document.getData().getTableModel (CSMWorld::UniversalId::Type_Scripts));
|
*document.getData().getTableModel (CSMWorld::UniversalId::Type_Scripts));
|
||||||
|
|
|
@ -195,7 +195,7 @@ QWidget *CSVWorld::CommandDelegate::createEditor (QWidget *parent, const QStyleO
|
||||||
|
|
||||||
case CSMWorld::ColumnBase::Display_ScriptLines:
|
case CSMWorld::ColumnBase::Display_ScriptLines:
|
||||||
|
|
||||||
return new ScriptEdit (mDocument, parent);
|
return new ScriptEdit (mDocument, ScriptHighlighter::Mode_Console, parent);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue