mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 21:53:51 +00:00
separate highlight colour for IDs
This commit is contained in:
parent
3d2281fe80
commit
9c751ae370
5 changed files with 50 additions and 8 deletions
|
@ -1,6 +1,14 @@
|
|||
|
||||
#include "scriptcontext.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <components/misc/stringops.hpp>
|
||||
|
||||
#include "data.hpp"
|
||||
|
||||
CSMWorld::ScriptContext::ScriptContext (const Data& data) : mData (data), mIdsUpdated (false) {}
|
||||
|
||||
bool CSMWorld::ScriptContext::canDeclareLocals() const
|
||||
{
|
||||
return false;
|
||||
|
@ -18,5 +26,19 @@ char CSMWorld::ScriptContext::getMemberType (const std::string& name, const std:
|
|||
|
||||
bool CSMWorld::ScriptContext::isId (const std::string& name) const
|
||||
{
|
||||
return false;
|
||||
if (!mIdsUpdated)
|
||||
{
|
||||
mIds = mData.getIds();
|
||||
|
||||
std::for_each (mIds.begin(), mIds.end(), &Misc::StringUtils::lowerCase);
|
||||
|
||||
mIdsUpdated = true;
|
||||
}
|
||||
|
||||
return std::binary_search (mIds.begin(), mIds.end(), Misc::StringUtils::lowerCase (name));
|
||||
}
|
||||
|
||||
void CSMWorld::ScriptContext::invalidateIds()
|
||||
{
|
||||
mIdsUpdated = false;
|
||||
}
|
|
@ -1,14 +1,25 @@
|
|||
#ifndef CSM_WORLD_SCRIPTCONTEXT_H
|
||||
#define CSM_WORLD_SCRIPTCONTEXT_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <components/compiler/context.hpp>
|
||||
|
||||
namespace CSMWorld
|
||||
{
|
||||
class Data;
|
||||
|
||||
class ScriptContext : public Compiler::Context
|
||||
{
|
||||
const Data& mData;
|
||||
mutable std::vector<std::string> mIds;
|
||||
mutable bool mIdsUpdated;
|
||||
|
||||
public:
|
||||
|
||||
ScriptContext (const Data& data);
|
||||
|
||||
virtual bool canDeclareLocals() const;
|
||||
///< Is the compiler allowed to declare local variables?
|
||||
|
||||
|
@ -20,6 +31,8 @@ namespace CSMWorld
|
|||
|
||||
virtual bool isId (const std::string& name) const;
|
||||
///< Does \a name match an ID, that can be referenced?
|
||||
|
||||
void invalidateIds();
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ bool CSVWorld::ScriptHighlighter::parseFloat (float value, const Compiler::Token
|
|||
bool CSVWorld::ScriptHighlighter::parseName (const std::string& name, const Compiler::TokenLoc& loc,
|
||||
Compiler::Scanner& scanner)
|
||||
{
|
||||
highlight (loc, Type_Name);
|
||||
highlight (loc, mContext.isId (name) ? Type_Id : Type_Name);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -63,10 +63,10 @@ void CSVWorld::ScriptHighlighter::highlight (const Compiler::TokenLoc& loc, Type
|
|||
setFormat (index, length, mScheme[type]);
|
||||
}
|
||||
|
||||
CSVWorld::ScriptHighlighter::ScriptHighlighter (QTextDocument *parent)
|
||||
: QSyntaxHighlighter (parent), Compiler::Parser (mErrorHandler, mContext)
|
||||
CSVWorld::ScriptHighlighter::ScriptHighlighter (const CSMWorld::Data& data, QTextDocument *parent)
|
||||
: QSyntaxHighlighter (parent), Compiler::Parser (mErrorHandler, mContext), mContext (data)
|
||||
{
|
||||
/// \ŧodo replace this with user settings
|
||||
/// \todo replace this with user settings
|
||||
{
|
||||
QTextCharFormat format;
|
||||
format.setForeground (Qt::darkMagenta);
|
||||
|
@ -103,6 +103,12 @@ CSVWorld::ScriptHighlighter::ScriptHighlighter (QTextDocument *parent)
|
|||
mScheme.insert (std::make_pair (Type_Comment, format));
|
||||
}
|
||||
|
||||
{
|
||||
QTextCharFormat format;
|
||||
format.setForeground (Qt::blue);
|
||||
mScheme.insert (std::make_pair (Type_Id, format));
|
||||
}
|
||||
|
||||
// configure compiler
|
||||
Compiler::registerExtensions (mExtensions);
|
||||
mContext.setExtensions (&mExtensions);
|
||||
|
|
|
@ -24,7 +24,8 @@ namespace CSVWorld
|
|||
Type_Name,
|
||||
Type_Keyword,
|
||||
Type_Special,
|
||||
Type_Comment
|
||||
Type_Comment,
|
||||
Type_Id
|
||||
};
|
||||
|
||||
private:
|
||||
|
@ -73,7 +74,7 @@ namespace CSVWorld
|
|||
|
||||
public:
|
||||
|
||||
ScriptHighlighter (QTextDocument *parent);
|
||||
ScriptHighlighter (const CSMWorld::Data& data, QTextDocument *parent);
|
||||
|
||||
virtual void highlightBlock (const QString& text);
|
||||
};
|
||||
|
|
|
@ -58,7 +58,7 @@ 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 (mEditor->document());
|
||||
new ScriptHighlighter (document.getData(), mEditor->document());
|
||||
}
|
||||
|
||||
void CSVWorld::ScriptSubView::setEditLock (bool locked)
|
||||
|
|
Loading…
Reference in a new issue