mirror of
https://github.com/dhewm/dhewm3.git
synced 2025-04-19 08:58:56 +00:00
Switch to the original ImGuiColorTextEdit.
Apply PRs: - https://github.com/BalazsJako/ImGuiColorTextEdit/pull/153 - https://github.com/BalazsJako/ImGuiColorTextEdit/pull/135 - https://github.com/BalazsJako/ImGuiColorTextEdit/pull/127 - https://github.com/BalazsJako/ImGuiColorTextEdit/pull/134 - https://github.com/BalazsJako/ImGuiColorTextEdit/pull/132 - https://github.com/BalazsJako/ImGuiColorTextEdit/pull/100
This commit is contained in:
parent
4f592a8675
commit
ebe4c2e370
9 changed files with 3084 additions and 3768 deletions
|
@ -828,9 +828,8 @@ set(src_imgui ${src_imgui}
|
|||
libs/imgui/imgui_demo.cpp
|
||||
|
||||
libs/ImGuiColorTextEdit/TextEditor.h
|
||||
libs/ImGuiColorTextEdit/LanguageDefinitions.cpp
|
||||
libs/ImGuiColorTextEdit/TextEditor.cpp
|
||||
|
||||
|
||||
sys/sys_imgui.h
|
||||
sys/sys_imgui.cpp
|
||||
sys/imgui_savestyle.cpp
|
||||
|
@ -1299,7 +1298,6 @@ if(CORE)
|
|||
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} PREFIX neo FILES ${src_core} ${src_sys_base} ${src_sys_core} ${src_imgui} ${src_editor_tools})
|
||||
|
||||
target_include_directories(${DHEWM3BINARY} PRIVATE "${CMAKE_SOURCE_DIR}/libs/imgui")
|
||||
target_include_directories(${DHEWM3BINARY} PRIVATE "${CMAKE_SOURCE_DIR}/libs/zep/include")
|
||||
|
||||
if(HARDLINK_GAME)
|
||||
set_target_properties(${DHEWM3BINARY} PROPERTIES COMPILE_DEFINITIONS "${TOOLS_DEFINES}")
|
||||
|
|
|
@ -1,937 +0,0 @@
|
|||
#include "TextEditor.h"
|
||||
|
||||
static bool TokenizeCStyleString(const char* in_begin, const char* in_end, const char*& out_begin, const char*& out_end)
|
||||
{
|
||||
const char* p = in_begin;
|
||||
|
||||
if (*p == '"')
|
||||
{
|
||||
p++;
|
||||
|
||||
while (p < in_end)
|
||||
{
|
||||
// handle end of string
|
||||
if (*p == '"')
|
||||
{
|
||||
out_begin = in_begin;
|
||||
out_end = p + 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
// handle escape character for "
|
||||
if (*p == '\\' && p + 1 < in_end && p[1] == '"')
|
||||
p++;
|
||||
|
||||
p++;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool TokenizeCStyleCharacterLiteral(const char* in_begin, const char* in_end, const char*& out_begin, const char*& out_end)
|
||||
{
|
||||
const char* p = in_begin;
|
||||
|
||||
if (*p == '\'')
|
||||
{
|
||||
p++;
|
||||
|
||||
// handle escape characters
|
||||
if (p < in_end && *p == '\\')
|
||||
p++;
|
||||
|
||||
if (p < in_end)
|
||||
p++;
|
||||
|
||||
// handle end of character literal
|
||||
if (p < in_end && *p == '\'')
|
||||
{
|
||||
out_begin = in_begin;
|
||||
out_end = p + 1;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool TokenizeCStyleIdentifier(const char* in_begin, const char* in_end, const char*& out_begin, const char*& out_end)
|
||||
{
|
||||
const char* p = in_begin;
|
||||
|
||||
if ((*p >= 'a' && *p <= 'z') || (*p >= 'A' && *p <= 'Z') || *p == '_')
|
||||
{
|
||||
p++;
|
||||
|
||||
while ((p < in_end) && ((*p >= 'a' && *p <= 'z') || (*p >= 'A' && *p <= 'Z') || (*p >= '0' && *p <= '9') || *p == '_'))
|
||||
p++;
|
||||
|
||||
out_begin = in_begin;
|
||||
out_end = p;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool TokenizeCStyleNumber(const char* in_begin, const char* in_end, const char*& out_begin, const char*& out_end)
|
||||
{
|
||||
const char* p = in_begin;
|
||||
|
||||
const bool startsWithNumber = *p >= '0' && *p <= '9';
|
||||
|
||||
if (*p != '+' && *p != '-' && !startsWithNumber)
|
||||
return false;
|
||||
|
||||
p++;
|
||||
|
||||
bool hasNumber = startsWithNumber;
|
||||
|
||||
while (p < in_end && (*p >= '0' && *p <= '9'))
|
||||
{
|
||||
hasNumber = true;
|
||||
|
||||
p++;
|
||||
}
|
||||
|
||||
if (hasNumber == false)
|
||||
return false;
|
||||
|
||||
bool isFloat = false;
|
||||
bool isHex = false;
|
||||
bool isBinary = false;
|
||||
|
||||
if (p < in_end)
|
||||
{
|
||||
if (*p == '.')
|
||||
{
|
||||
isFloat = true;
|
||||
|
||||
p++;
|
||||
|
||||
while (p < in_end && (*p >= '0' && *p <= '9'))
|
||||
p++;
|
||||
}
|
||||
else if (*p == 'x' || *p == 'X')
|
||||
{
|
||||
// hex formatted integer of the type 0xef80
|
||||
|
||||
isHex = true;
|
||||
|
||||
p++;
|
||||
|
||||
while (p < in_end && ((*p >= '0' && *p <= '9') || (*p >= 'a' && *p <= 'f') || (*p >= 'A' && *p <= 'F')))
|
||||
p++;
|
||||
}
|
||||
else if (*p == 'b' || *p == 'B')
|
||||
{
|
||||
// binary formatted integer of the type 0b01011101
|
||||
|
||||
isBinary = true;
|
||||
|
||||
p++;
|
||||
|
||||
while (p < in_end && (*p >= '0' && *p <= '1'))
|
||||
p++;
|
||||
}
|
||||
}
|
||||
|
||||
if (isHex == false && isBinary == false)
|
||||
{
|
||||
// floating point exponent
|
||||
if (p < in_end && (*p == 'e' || *p == 'E'))
|
||||
{
|
||||
isFloat = true;
|
||||
|
||||
p++;
|
||||
|
||||
if (p < in_end && (*p == '+' || *p == '-'))
|
||||
p++;
|
||||
|
||||
bool hasDigits = false;
|
||||
|
||||
while (p < in_end && (*p >= '0' && *p <= '9'))
|
||||
{
|
||||
hasDigits = true;
|
||||
|
||||
p++;
|
||||
}
|
||||
|
||||
if (hasDigits == false)
|
||||
return false;
|
||||
}
|
||||
|
||||
// single precision floating point type
|
||||
if (p < in_end && *p == 'f')
|
||||
p++;
|
||||
}
|
||||
|
||||
if (isFloat == false)
|
||||
{
|
||||
// integer size type
|
||||
while (p < in_end && (*p == 'u' || *p == 'U' || *p == 'l' || *p == 'L'))
|
||||
p++;
|
||||
}
|
||||
|
||||
out_begin = in_begin;
|
||||
out_end = p;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool TokenizeCStylePunctuation(const char* in_begin, const char* in_end, const char*& out_begin, const char*& out_end)
|
||||
{
|
||||
(void)in_end;
|
||||
|
||||
switch (*in_begin)
|
||||
{
|
||||
case '[':
|
||||
case ']':
|
||||
case '{':
|
||||
case '}':
|
||||
case '!':
|
||||
case '%':
|
||||
case '^':
|
||||
case '&':
|
||||
case '*':
|
||||
case '(':
|
||||
case ')':
|
||||
case '-':
|
||||
case '+':
|
||||
case '=':
|
||||
case '~':
|
||||
case '|':
|
||||
case '<':
|
||||
case '>':
|
||||
case '?':
|
||||
case ':':
|
||||
case '/':
|
||||
case ';':
|
||||
case ',':
|
||||
case '.':
|
||||
out_begin = in_begin;
|
||||
out_end = in_begin + 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool TokenizeLuaStyleString(const char* in_begin, const char* in_end, const char*& out_begin, const char*& out_end)
|
||||
{
|
||||
const char* p = in_begin;
|
||||
|
||||
bool is_single_quote = false;
|
||||
bool is_double_quotes = false;
|
||||
bool is_double_square_brackets = false;
|
||||
|
||||
switch (*p)
|
||||
{
|
||||
case '\'':
|
||||
is_single_quote = true;
|
||||
break;
|
||||
case '"':
|
||||
is_double_quotes = true;
|
||||
break;
|
||||
case '[':
|
||||
p++;
|
||||
if (p < in_end && *(p) == '[')
|
||||
is_double_square_brackets = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (is_single_quote || is_double_quotes || is_double_square_brackets)
|
||||
{
|
||||
p++;
|
||||
|
||||
while (p < in_end)
|
||||
{
|
||||
// handle end of string
|
||||
if ((is_single_quote && *p == '\'') || (is_double_quotes && *p == '"') || (is_double_square_brackets && *p == ']' && p + 1 < in_end && *(p + 1) == ']'))
|
||||
{
|
||||
out_begin = in_begin;
|
||||
|
||||
if (is_double_square_brackets)
|
||||
out_end = p + 2;
|
||||
else
|
||||
out_end = p + 1;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// handle escape character for "
|
||||
if (*p == '\\' && p + 1 < in_end && (is_single_quote || is_double_quotes))
|
||||
p++;
|
||||
|
||||
p++;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool TokenizeLuaStyleIdentifier(const char* in_begin, const char* in_end, const char*& out_begin, const char*& out_end)
|
||||
{
|
||||
const char* p = in_begin;
|
||||
|
||||
if ((*p >= 'a' && *p <= 'z') || (*p >= 'A' && *p <= 'Z') || *p == '_')
|
||||
{
|
||||
p++;
|
||||
|
||||
while ((p < in_end) && ((*p >= 'a' && *p <= 'z') || (*p >= 'A' && *p <= 'Z') || (*p >= '0' && *p <= '9') || *p == '_'))
|
||||
p++;
|
||||
|
||||
out_begin = in_begin;
|
||||
out_end = p;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool TokenizeLuaStyleNumber(const char* in_begin, const char* in_end, const char*& out_begin, const char*& out_end)
|
||||
{
|
||||
const char* p = in_begin;
|
||||
|
||||
const bool startsWithNumber = *p >= '0' && *p <= '9';
|
||||
|
||||
if (*p != '+' && *p != '-' && !startsWithNumber)
|
||||
return false;
|
||||
|
||||
p++;
|
||||
|
||||
bool hasNumber = startsWithNumber;
|
||||
|
||||
while (p < in_end && (*p >= '0' && *p <= '9'))
|
||||
{
|
||||
hasNumber = true;
|
||||
|
||||
p++;
|
||||
}
|
||||
|
||||
if (hasNumber == false)
|
||||
return false;
|
||||
|
||||
if (p < in_end)
|
||||
{
|
||||
if (*p == '.')
|
||||
{
|
||||
p++;
|
||||
|
||||
while (p < in_end && (*p >= '0' && *p <= '9'))
|
||||
p++;
|
||||
}
|
||||
|
||||
// floating point exponent
|
||||
if (p < in_end && (*p == 'e' || *p == 'E'))
|
||||
{
|
||||
p++;
|
||||
|
||||
if (p < in_end && (*p == '+' || *p == '-'))
|
||||
p++;
|
||||
|
||||
bool hasDigits = false;
|
||||
|
||||
while (p < in_end && (*p >= '0' && *p <= '9'))
|
||||
{
|
||||
hasDigits = true;
|
||||
|
||||
p++;
|
||||
}
|
||||
|
||||
if (hasDigits == false)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
out_begin = in_begin;
|
||||
out_end = p;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool TokenizeLuaStylePunctuation(const char* in_begin, const char* in_end, const char*& out_begin, const char*& out_end)
|
||||
{
|
||||
(void)in_end;
|
||||
|
||||
switch (*in_begin)
|
||||
{
|
||||
case '[':
|
||||
case ']':
|
||||
case '{':
|
||||
case '}':
|
||||
case '!':
|
||||
case '%':
|
||||
case '#':
|
||||
case '^':
|
||||
case '&':
|
||||
case '*':
|
||||
case '(':
|
||||
case ')':
|
||||
case '-':
|
||||
case '+':
|
||||
case '=':
|
||||
case '~':
|
||||
case '|':
|
||||
case '<':
|
||||
case '>':
|
||||
case '?':
|
||||
case ':':
|
||||
case '/':
|
||||
case ';':
|
||||
case ',':
|
||||
case '.':
|
||||
out_begin = in_begin;
|
||||
out_end = in_begin + 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
const TextEditor::LanguageDefinition& TextEditor::LanguageDefinition::Cpp()
|
||||
{
|
||||
static bool inited = false;
|
||||
static LanguageDefinition langDef;
|
||||
if (!inited)
|
||||
{
|
||||
static const char* const cppKeywords[] = {
|
||||
"alignas", "alignof", "and", "and_eq", "asm", "atomic_cancel", "atomic_commit", "atomic_noexcept", "auto", "bitand", "bitor", "bool", "break", "case", "catch", "char", "char16_t", "char32_t", "class",
|
||||
"compl", "concept", "const", "constexpr", "const_cast", "continue", "decltype", "default", "delete", "do", "double", "dynamic_cast", "else", "enum", "explicit", "export", "extern", "false", "float",
|
||||
"for", "friend", "goto", "if", "import", "inline", "int", "long", "module", "mutable", "namespace", "new", "noexcept", "not", "not_eq", "nullptr", "operator", "or", "or_eq", "private", "protected", "public",
|
||||
"register", "reinterpret_cast", "requires", "return", "short", "signed", "sizeof", "static", "static_assert", "static_cast", "struct", "switch", "synchronized", "template", "this", "thread_local",
|
||||
"throw", "true", "try", "typedef", "typeid", "typename", "union", "unsigned", "using", "virtual", "void", "volatile", "wchar_t", "while", "xor", "xor_eq"
|
||||
};
|
||||
for (auto& k : cppKeywords)
|
||||
langDef.mKeywords.insert(k);
|
||||
|
||||
static const char* const identifiers[] = {
|
||||
"abort", "abs", "acos", "asin", "atan", "atexit", "atof", "atoi", "atol", "ceil", "clock", "cosh", "ctime", "div", "exit", "fabs", "floor", "fmod", "getchar", "getenv", "isalnum", "isalpha", "isdigit", "isgraph",
|
||||
"ispunct", "isspace", "isupper", "kbhit", "log10", "log2", "log", "memcmp", "modf", "pow", "printf", "sprintf", "snprintf", "putchar", "putenv", "puts", "rand", "remove", "rename", "sinh", "sqrt", "srand", "strcat", "strcmp", "strerror", "time", "tolower", "toupper",
|
||||
"std", "string", "vector", "map", "unordered_map", "set", "unordered_set", "min", "max"
|
||||
};
|
||||
for (auto& k : identifiers)
|
||||
{
|
||||
Identifier id;
|
||||
id.mDeclaration = "Built-in function";
|
||||
langDef.mIdentifiers.insert(std::make_pair(std::string(k), id));
|
||||
}
|
||||
|
||||
langDef.mTokenize = [](const char* in_begin, const char* in_end, const char*& out_begin, const char*& out_end, PaletteIndex& paletteIndex) -> bool
|
||||
{
|
||||
paletteIndex = PaletteIndex::Max;
|
||||
|
||||
while (in_begin < in_end && isascii(*in_begin) && isblank(*in_begin))
|
||||
in_begin++;
|
||||
|
||||
if (in_begin == in_end)
|
||||
{
|
||||
out_begin = in_end;
|
||||
out_end = in_end;
|
||||
paletteIndex = PaletteIndex::Default;
|
||||
}
|
||||
else if (TokenizeCStyleString(in_begin, in_end, out_begin, out_end))
|
||||
paletteIndex = PaletteIndex::String;
|
||||
else if (TokenizeCStyleCharacterLiteral(in_begin, in_end, out_begin, out_end))
|
||||
paletteIndex = PaletteIndex::CharLiteral;
|
||||
else if (TokenizeCStyleIdentifier(in_begin, in_end, out_begin, out_end))
|
||||
paletteIndex = PaletteIndex::Identifier;
|
||||
else if (TokenizeCStyleNumber(in_begin, in_end, out_begin, out_end))
|
||||
paletteIndex = PaletteIndex::Number;
|
||||
else if (TokenizeCStylePunctuation(in_begin, in_end, out_begin, out_end))
|
||||
paletteIndex = PaletteIndex::Punctuation;
|
||||
|
||||
return paletteIndex != PaletteIndex::Max;
|
||||
};
|
||||
|
||||
langDef.mCommentStart = "/*";
|
||||
langDef.mCommentEnd = "*/";
|
||||
langDef.mSingleLineComment = "//";
|
||||
|
||||
langDef.mCaseSensitive = true;
|
||||
|
||||
langDef.mName = "C++";
|
||||
|
||||
inited = true;
|
||||
}
|
||||
return langDef;
|
||||
}
|
||||
|
||||
const TextEditor::LanguageDefinition& TextEditor::LanguageDefinition::Hlsl()
|
||||
{
|
||||
static bool inited = false;
|
||||
static LanguageDefinition langDef;
|
||||
if (!inited)
|
||||
{
|
||||
static const char* const keywords[] = {
|
||||
"AppendStructuredBuffer", "asm", "asm_fragment", "BlendState", "bool", "break", "Buffer", "ByteAddressBuffer", "case", "cbuffer", "centroid", "class", "column_major", "compile", "compile_fragment",
|
||||
"CompileShader", "const", "continue", "ComputeShader", "ConsumeStructuredBuffer", "default", "DepthStencilState", "DepthStencilView", "discard", "do", "double", "DomainShader", "dword", "else",
|
||||
"export", "extern", "false", "float", "for", "fxgroup", "GeometryShader", "groupshared", "half", "Hullshader", "if", "in", "inline", "inout", "InputPatch", "int", "interface", "line", "lineadj",
|
||||
"linear", "LineStream", "matrix", "min16float", "min10float", "min16int", "min12int", "min16uint", "namespace", "nointerpolation", "noperspective", "NULL", "out", "OutputPatch", "packoffset",
|
||||
"pass", "pixelfragment", "PixelShader", "point", "PointStream", "precise", "RasterizerState", "RenderTargetView", "return", "register", "row_major", "RWBuffer", "RWByteAddressBuffer", "RWStructuredBuffer",
|
||||
"RWTexture1D", "RWTexture1DArray", "RWTexture2D", "RWTexture2DArray", "RWTexture3D", "sample", "sampler", "SamplerState", "SamplerComparisonState", "shared", "snorm", "stateblock", "stateblock_state",
|
||||
"static", "string", "struct", "switch", "StructuredBuffer", "tbuffer", "technique", "technique10", "technique11", "texture", "Texture1D", "Texture1DArray", "Texture2D", "Texture2DArray", "Texture2DMS",
|
||||
"Texture2DMSArray", "Texture3D", "TextureCube", "TextureCubeArray", "true", "typedef", "triangle", "triangleadj", "TriangleStream", "uint", "uniform", "unorm", "unsigned", "vector", "vertexfragment",
|
||||
"VertexShader", "void", "volatile", "while",
|
||||
"bool1","bool2","bool3","bool4","double1","double2","double3","double4", "float1", "float2", "float3", "float4", "int1", "int2", "int3", "int4", "in", "out", "inout",
|
||||
"uint1", "uint2", "uint3", "uint4", "dword1", "dword2", "dword3", "dword4", "half1", "half2", "half3", "half4",
|
||||
"float1x1","float2x1","float3x1","float4x1","float1x2","float2x2","float3x2","float4x2",
|
||||
"float1x3","float2x3","float3x3","float4x3","float1x4","float2x4","float3x4","float4x4",
|
||||
"half1x1","half2x1","half3x1","half4x1","half1x2","half2x2","half3x2","half4x2",
|
||||
"half1x3","half2x3","half3x3","half4x3","half1x4","half2x4","half3x4","half4x4",
|
||||
};
|
||||
for (auto& k : keywords)
|
||||
langDef.mKeywords.insert(k);
|
||||
|
||||
static const char* const identifiers[] = {
|
||||
"abort", "abs", "acos", "all", "AllMemoryBarrier", "AllMemoryBarrierWithGroupSync", "any", "asdouble", "asfloat", "asin", "asint", "asint", "asuint",
|
||||
"asuint", "atan", "atan2", "ceil", "CheckAccessFullyMapped", "clamp", "clip", "cos", "cosh", "countbits", "cross", "D3DCOLORtoUBYTE4", "ddx",
|
||||
"ddx_coarse", "ddx_fine", "ddy", "ddy_coarse", "ddy_fine", "degrees", "determinant", "DeviceMemoryBarrier", "DeviceMemoryBarrierWithGroupSync",
|
||||
"distance", "dot", "dst", "errorf", "EvaluateAttributeAtCentroid", "EvaluateAttributeAtSample", "EvaluateAttributeSnapped", "exp", "exp2",
|
||||
"f16tof32", "f32tof16", "faceforward", "firstbithigh", "firstbitlow", "floor", "fma", "fmod", "frac", "frexp", "fwidth", "GetRenderTargetSampleCount",
|
||||
"GetRenderTargetSamplePosition", "GroupMemoryBarrier", "GroupMemoryBarrierWithGroupSync", "InterlockedAdd", "InterlockedAnd", "InterlockedCompareExchange",
|
||||
"InterlockedCompareStore", "InterlockedExchange", "InterlockedMax", "InterlockedMin", "InterlockedOr", "InterlockedXor", "isfinite", "isinf", "isnan",
|
||||
"ldexp", "length", "lerp", "lit", "log", "log10", "log2", "mad", "max", "min", "modf", "msad4", "mul", "noise", "normalize", "pow", "printf",
|
||||
"Process2DQuadTessFactorsAvg", "Process2DQuadTessFactorsMax", "Process2DQuadTessFactorsMin", "ProcessIsolineTessFactors", "ProcessQuadTessFactorsAvg",
|
||||
"ProcessQuadTessFactorsMax", "ProcessQuadTessFactorsMin", "ProcessTriTessFactorsAvg", "ProcessTriTessFactorsMax", "ProcessTriTessFactorsMin",
|
||||
"radians", "rcp", "reflect", "refract", "reversebits", "round", "rsqrt", "saturate", "sign", "sin", "sincos", "sinh", "smoothstep", "sqrt", "step",
|
||||
"tan", "tanh", "tex1D", "tex1D", "tex1Dbias", "tex1Dgrad", "tex1Dlod", "tex1Dproj", "tex2D", "tex2D", "tex2Dbias", "tex2Dgrad", "tex2Dlod", "tex2Dproj",
|
||||
"tex3D", "tex3D", "tex3Dbias", "tex3Dgrad", "tex3Dlod", "tex3Dproj", "texCUBE", "texCUBE", "texCUBEbias", "texCUBEgrad", "texCUBElod", "texCUBEproj", "transpose", "trunc"
|
||||
};
|
||||
for (auto& k : identifiers)
|
||||
{
|
||||
Identifier id;
|
||||
id.mDeclaration = "Built-in function";
|
||||
langDef.mIdentifiers.insert(std::make_pair(std::string(k), id));
|
||||
}
|
||||
|
||||
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##([ \t]*#[ \t]*[a-zA-Z_]+)##", PaletteIndex::Preprocessor));
|
||||
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##(L?\"(\\.|[^\"])*\")##", PaletteIndex::String));
|
||||
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##(\'\\?[^\']\')##", PaletteIndex::CharLiteral));
|
||||
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##([+-]?([0-9]+([.][0-9]*)?|[.][0-9]+)([eE][+-]?[0-9]+)?[fF]?)##", PaletteIndex::Number));
|
||||
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##([+-]?[0-9]+[Uu]?[lL]?[lL]?)##", PaletteIndex::Number));
|
||||
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##(0[0-7]+[Uu]?[lL]?[lL]?)##", PaletteIndex::Number));
|
||||
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##(0[xX][0-9a-fA-F]+[uU]?[lL]?[lL]?)##", PaletteIndex::Number));
|
||||
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##([a-zA-Z_][a-zA-Z0-9_]*)##", PaletteIndex::Identifier));
|
||||
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##([\[\]\{\}\!\%\^\&\*\(\)\-\+\=\~\|\<\>\?\/\;\,\.])##", PaletteIndex::Punctuation));
|
||||
|
||||
langDef.mCommentStart = "/*";
|
||||
langDef.mCommentEnd = "*/";
|
||||
langDef.mSingleLineComment = "//";
|
||||
|
||||
langDef.mCaseSensitive = true;
|
||||
|
||||
langDef.mName = "HLSL";
|
||||
|
||||
inited = true;
|
||||
}
|
||||
return langDef;
|
||||
}
|
||||
|
||||
const TextEditor::LanguageDefinition& TextEditor::LanguageDefinition::Glsl()
|
||||
{
|
||||
static bool inited = false;
|
||||
static LanguageDefinition langDef;
|
||||
if (!inited)
|
||||
{
|
||||
static const char* const keywords[] = {
|
||||
"auto", "break", "case", "char", "const", "continue", "default", "do", "double", "else", "enum", "extern", "float", "for", "goto", "if", "inline", "int", "long", "register", "restrict", "return", "short",
|
||||
"signed", "sizeof", "static", "struct", "switch", "typedef", "union", "unsigned", "void", "volatile", "while", "_Alignas", "_Alignof", "_Atomic", "_Bool", "_Complex", "_Generic", "_Imaginary",
|
||||
"_Noreturn", "_Static_assert", "_Thread_local"
|
||||
};
|
||||
for (auto& k : keywords)
|
||||
langDef.mKeywords.insert(k);
|
||||
|
||||
static const char* const identifiers[] = {
|
||||
"abort", "abs", "acos", "asin", "atan", "atexit", "atof", "atoi", "atol", "ceil", "clock", "cosh", "ctime", "div", "exit", "fabs", "floor", "fmod", "getchar", "getenv", "isalnum", "isalpha", "isdigit", "isgraph",
|
||||
"ispunct", "isspace", "isupper", "kbhit", "log10", "log2", "log", "memcmp", "modf", "pow", "putchar", "putenv", "puts", "rand", "remove", "rename", "sinh", "sqrt", "srand", "strcat", "strcmp", "strerror", "time", "tolower", "toupper"
|
||||
};
|
||||
for (auto& k : identifiers)
|
||||
{
|
||||
Identifier id;
|
||||
id.mDeclaration = "Built-in function";
|
||||
langDef.mIdentifiers.insert(std::make_pair(std::string(k), id));
|
||||
}
|
||||
|
||||
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##([ \t]*#[ \t]*[a-zA-Z_]+)##", PaletteIndex::Preprocessor));
|
||||
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##(L?\"(\\.|[^\"])*\")##", PaletteIndex::String));
|
||||
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##(\'\\?[^\']\')##", PaletteIndex::CharLiteral));
|
||||
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##([+-]?([0-9]+([.][0-9]*)?|[.][0-9]+)([eE][+-]?[0-9]+)?[fF]?)##", PaletteIndex::Number));
|
||||
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##([+-]?[0-9]+[Uu]?[lL]?[lL]?)##", PaletteIndex::Number));
|
||||
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##(0[0-7]+[Uu]?[lL]?[lL]?)##", PaletteIndex::Number));
|
||||
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##(0[xX][0-9a-fA-F]+[uU]?[lL]?[lL]?)##", PaletteIndex::Number));
|
||||
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##([a-zA-Z_][a-zA-Z0-9_]*)##", PaletteIndex::Identifier));
|
||||
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##([\[\]\{\}\!\%\^\&\*\(\)\-\+\=\~\|\<\>\?\/\;\,\.])##", PaletteIndex::Punctuation));
|
||||
|
||||
langDef.mCommentStart = "/*";
|
||||
langDef.mCommentEnd = "*/";
|
||||
langDef.mSingleLineComment = "//";
|
||||
|
||||
langDef.mCaseSensitive = true;
|
||||
|
||||
langDef.mName = "GLSL";
|
||||
|
||||
inited = true;
|
||||
}
|
||||
return langDef;
|
||||
}
|
||||
|
||||
const TextEditor::LanguageDefinition& TextEditor::LanguageDefinition::Python()
|
||||
{
|
||||
static bool inited = false;
|
||||
static LanguageDefinition langDef;
|
||||
if (!inited)
|
||||
{
|
||||
static const char* const keywords[] = {
|
||||
"False", "await", "else", "import", "pass", "None", "break", "except", "in", "raise", "True", "class", "finally", "is", "return", "and", "continue", "for", "lambda", "try", "as", "def", "from", "nonlocal", "while", "assert", "del", "global", "not", "with", "async", "elif", "if", "or", "yield"
|
||||
};
|
||||
for (auto& k : keywords)
|
||||
langDef.mKeywords.insert(k);
|
||||
|
||||
static const char* const identifiers[] = {
|
||||
"abs", "aiter", "all", "any", "anext", "ascii", "bin", "bool", "breakpoint", "bytearray", "bytes", "callable", "chr", "classmethod", "compile", "complex", "delattr", "dict", "dir", "divmod", "enumerate", "eval", "exec", "filter", "float", "format", "frozenset", "getattr", "globals", "hasattr", "hash", "help", "hex", "id", "input", "int", "isinstance", "issubclass", "iter", "len", "list", "locals", "map", "max", "memoryview", "min", "next", "object", "oct", "open", "ord", "pow", "print", "property", "range", "repr", "reversed", "round", "set", "setattr", "slice", "sorted", "staticmethod", "str", "sum", "super", "tuple", "type", "vars", "zip", "__import__"
|
||||
};
|
||||
for (auto& k : identifiers)
|
||||
{
|
||||
Identifier id;
|
||||
id.mDeclaration = "Built-in function";
|
||||
langDef.mIdentifiers.insert(std::make_pair(std::string(k), id));
|
||||
}
|
||||
|
||||
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##((b|u|f|r)?\"(\\.|[^\"])*\")##", PaletteIndex::String));
|
||||
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##((b|u|f|r)?'(\\.|[^'])*')##", PaletteIndex::String));
|
||||
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##([+-]?([0-9]+([.][0-9]*)?|[.][0-9]+)([eE][+-]?[0-9]+)?[fF]?)##", PaletteIndex::Number));
|
||||
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##([+-]?[0-9]+[Uu]?[lL]?[lL]?)##", PaletteIndex::Number));
|
||||
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##(0[0-7]+[Uu]?[lL]?[lL]?)##", PaletteIndex::Number));
|
||||
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##(0[xX][0-9a-fA-F]+[uU]?[lL]?[lL]?)##", PaletteIndex::Number));
|
||||
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##([a-zA-Z_][a-zA-Z0-9_]*)##", PaletteIndex::Identifier));
|
||||
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##([\[\]\{\}\!\%\^\&\*\(\)\-\+\=\~\|\<\>\?\/\;\,\.\:])##", PaletteIndex::Punctuation));
|
||||
|
||||
langDef.mCommentStart = "\"\"\"";
|
||||
langDef.mCommentEnd = "\"\"\"";
|
||||
langDef.mSingleLineComment = "#";
|
||||
|
||||
langDef.mCaseSensitive = true;
|
||||
|
||||
langDef.mName = "Python";
|
||||
|
||||
inited = true;
|
||||
}
|
||||
return langDef;
|
||||
}
|
||||
|
||||
const TextEditor::LanguageDefinition& TextEditor::LanguageDefinition::C()
|
||||
{
|
||||
static bool inited = false;
|
||||
static LanguageDefinition langDef;
|
||||
if (!inited)
|
||||
{
|
||||
static const char* const keywords[] = {
|
||||
"auto", "break", "case", "char", "const", "continue", "default", "do", "double", "else", "enum", "extern", "float", "for", "goto", "if", "inline", "int", "long", "register", "restrict", "return", "short",
|
||||
"signed", "sizeof", "static", "struct", "switch", "typedef", "union", "unsigned", "void", "volatile", "while", "_Alignas", "_Alignof", "_Atomic", "_Bool", "_Complex", "_Generic", "_Imaginary",
|
||||
"_Noreturn", "_Static_assert", "_Thread_local"
|
||||
};
|
||||
for (auto& k : keywords)
|
||||
langDef.mKeywords.insert(k);
|
||||
|
||||
static const char* const identifiers[] = {
|
||||
"abort", "abs", "acos", "asin", "atan", "atexit", "atof", "atoi", "atol", "ceil", "clock", "cosh", "ctime", "div", "exit", "fabs", "floor", "fmod", "getchar", "getenv", "isalnum", "isalpha", "isdigit", "isgraph",
|
||||
"ispunct", "isspace", "isupper", "kbhit", "log10", "log2", "log", "memcmp", "modf", "pow", "putchar", "putenv", "puts", "rand", "remove", "rename", "sinh", "sqrt", "srand", "strcat", "strcmp", "strerror", "time", "tolower", "toupper"
|
||||
};
|
||||
for (auto& k : identifiers)
|
||||
{
|
||||
Identifier id;
|
||||
id.mDeclaration = "Built-in function";
|
||||
langDef.mIdentifiers.insert(std::make_pair(std::string(k), id));
|
||||
}
|
||||
|
||||
langDef.mTokenize = [](const char* in_begin, const char* in_end, const char*& out_begin, const char*& out_end, PaletteIndex& paletteIndex) -> bool
|
||||
{
|
||||
paletteIndex = PaletteIndex::Max;
|
||||
|
||||
while (in_begin < in_end && isascii(*in_begin) && isblank(*in_begin))
|
||||
in_begin++;
|
||||
|
||||
if (in_begin == in_end)
|
||||
{
|
||||
out_begin = in_end;
|
||||
out_end = in_end;
|
||||
paletteIndex = PaletteIndex::Default;
|
||||
}
|
||||
else if (TokenizeCStyleString(in_begin, in_end, out_begin, out_end))
|
||||
paletteIndex = PaletteIndex::String;
|
||||
else if (TokenizeCStyleCharacterLiteral(in_begin, in_end, out_begin, out_end))
|
||||
paletteIndex = PaletteIndex::CharLiteral;
|
||||
else if (TokenizeCStyleIdentifier(in_begin, in_end, out_begin, out_end))
|
||||
paletteIndex = PaletteIndex::Identifier;
|
||||
else if (TokenizeCStyleNumber(in_begin, in_end, out_begin, out_end))
|
||||
paletteIndex = PaletteIndex::Number;
|
||||
else if (TokenizeCStylePunctuation(in_begin, in_end, out_begin, out_end))
|
||||
paletteIndex = PaletteIndex::Punctuation;
|
||||
|
||||
return paletteIndex != PaletteIndex::Max;
|
||||
};
|
||||
|
||||
langDef.mCommentStart = "/*";
|
||||
langDef.mCommentEnd = "*/";
|
||||
langDef.mSingleLineComment = "//";
|
||||
|
||||
langDef.mCaseSensitive = true;
|
||||
|
||||
langDef.mName = "C";
|
||||
|
||||
inited = true;
|
||||
}
|
||||
return langDef;
|
||||
}
|
||||
|
||||
const TextEditor::LanguageDefinition& TextEditor::LanguageDefinition::Sql()
|
||||
{
|
||||
static bool inited = false;
|
||||
static LanguageDefinition langDef;
|
||||
if (!inited)
|
||||
{
|
||||
static const char* const keywords[] = {
|
||||
"ADD", "EXCEPT", "PERCENT", "ALL", "EXEC", "PLAN", "ALTER", "EXECUTE", "PRECISION", "AND", "EXISTS", "PRIMARY", "ANY", "EXIT", "PRINT", "AS", "FETCH", "PROC", "ASC", "FILE", "PROCEDURE",
|
||||
"AUTHORIZATION", "FILLFACTOR", "PUBLIC", "BACKUP", "FOR", "RAISERROR", "BEGIN", "FOREIGN", "READ", "BETWEEN", "FREETEXT", "READTEXT", "BREAK", "FREETEXTTABLE", "RECONFIGURE",
|
||||
"BROWSE", "FROM", "REFERENCES", "BULK", "FULL", "REPLICATION", "BY", "FUNCTION", "RESTORE", "CASCADE", "GOTO", "RESTRICT", "CASE", "GRANT", "RETURN", "CHECK", "GROUP", "REVOKE",
|
||||
"CHECKPOINT", "HAVING", "RIGHT", "CLOSE", "HOLDLOCK", "ROLLBACK", "CLUSTERED", "IDENTITY", "ROWCOUNT", "COALESCE", "IDENTITY_INSERT", "ROWGUIDCOL", "COLLATE", "IDENTITYCOL", "RULE",
|
||||
"COLUMN", "IF", "SAVE", "COMMIT", "IN", "SCHEMA", "COMPUTE", "INDEX", "SELECT", "CONSTRAINT", "INNER", "SESSION_USER", "CONTAINS", "INSERT", "SET", "CONTAINSTABLE", "INTERSECT", "SETUSER",
|
||||
"CONTINUE", "INTO", "SHUTDOWN", "CONVERT", "IS", "SOME", "CREATE", "JOIN", "STATISTICS", "CROSS", "KEY", "SYSTEM_USER", "CURRENT", "KILL", "TABLE", "CURRENT_DATE", "LEFT", "TEXTSIZE",
|
||||
"CURRENT_TIME", "LIKE", "THEN", "CURRENT_TIMESTAMP", "LINENO", "TO", "CURRENT_USER", "LOAD", "TOP", "CURSOR", "NATIONAL", "TRAN", "DATABASE", "NOCHECK", "TRANSACTION",
|
||||
"DBCC", "NONCLUSTERED", "TRIGGER", "DEALLOCATE", "NOT", "TRUNCATE", "DECLARE", "NULL", "TSEQUAL", "DEFAULT", "NULLIF", "UNION", "DELETE", "OF", "UNIQUE", "DENY", "OFF", "UPDATE",
|
||||
"DESC", "OFFSETS", "UPDATETEXT", "DISK", "ON", "USE", "DISTINCT", "OPEN", "USER", "DISTRIBUTED", "OPENDATASOURCE", "VALUES", "DOUBLE", "OPENQUERY", "VARYING","DROP", "OPENROWSET", "VIEW",
|
||||
"DUMMY", "OPENXML", "WAITFOR", "DUMP", "OPTION", "WHEN", "ELSE", "OR", "WHERE", "END", "ORDER", "WHILE", "ERRLVL", "OUTER", "WITH", "ESCAPE", "OVER", "WRITETEXT"
|
||||
};
|
||||
|
||||
for (auto& k : keywords)
|
||||
langDef.mKeywords.insert(k);
|
||||
|
||||
static const char* const identifiers[] = {
|
||||
"ABS", "ACOS", "ADD_MONTHS", "ASCII", "ASCIISTR", "ASIN", "ATAN", "ATAN2", "AVG", "BFILENAME", "BIN_TO_NUM", "BITAND", "CARDINALITY", "CASE", "CAST", "CEIL",
|
||||
"CHARTOROWID", "CHR", "COALESCE", "COMPOSE", "CONCAT", "CONVERT", "CORR", "COS", "COSH", "COUNT", "COVAR_POP", "COVAR_SAMP", "CUME_DIST", "CURRENT_DATE",
|
||||
"CURRENT_TIMESTAMP", "DBTIMEZONE", "DECODE", "DECOMPOSE", "DENSE_RANK", "DUMP", "EMPTY_BLOB", "EMPTY_CLOB", "EXP", "EXTRACT", "FIRST_VALUE", "FLOOR", "FROM_TZ", "GREATEST",
|
||||
"GROUP_ID", "HEXTORAW", "INITCAP", "INSTR", "INSTR2", "INSTR4", "INSTRB", "INSTRC", "LAG", "LAST_DAY", "LAST_VALUE", "LEAD", "LEAST", "LENGTH", "LENGTH2", "LENGTH4",
|
||||
"LENGTHB", "LENGTHC", "LISTAGG", "LN", "LNNVL", "LOCALTIMESTAMP", "LOG", "LOWER", "LPAD", "LTRIM", "MAX", "MEDIAN", "MIN", "MOD", "MONTHS_BETWEEN", "NANVL", "NCHR",
|
||||
"NEW_TIME", "NEXT_DAY", "NTH_VALUE", "NULLIF", "NUMTODSINTERVAL", "NUMTOYMINTERVAL", "NVL", "NVL2", "POWER", "RANK", "RAWTOHEX", "REGEXP_COUNT", "REGEXP_INSTR",
|
||||
"REGEXP_REPLACE", "REGEXP_SUBSTR", "REMAINDER", "REPLACE", "ROUND", "ROWNUM", "RPAD", "RTRIM", "SESSIONTIMEZONE", "SIGN", "SIN", "SINH",
|
||||
"SOUNDEX", "SQRT", "STDDEV", "SUBSTR", "SUM", "SYS_CONTEXT", "SYSDATE", "SYSTIMESTAMP", "TAN", "TANH", "TO_CHAR", "TO_CLOB", "TO_DATE", "TO_DSINTERVAL", "TO_LOB",
|
||||
"TO_MULTI_BYTE", "TO_NCLOB", "TO_NUMBER", "TO_SINGLE_BYTE", "TO_TIMESTAMP", "TO_TIMESTAMP_TZ", "TO_YMINTERVAL", "TRANSLATE", "TRIM", "TRUNC", "TZ_OFFSET", "UID", "UPPER",
|
||||
"USER", "USERENV", "VAR_POP", "VAR_SAMP", "VARIANCE", "VSIZE"
|
||||
};
|
||||
for (auto& k : identifiers)
|
||||
{
|
||||
Identifier id;
|
||||
id.mDeclaration = "Built-in function";
|
||||
langDef.mIdentifiers.insert(std::make_pair(std::string(k), id));
|
||||
}
|
||||
|
||||
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##(L?\"(\\.|[^\"])*\")##", PaletteIndex::String));
|
||||
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##(\'[^\']*\')##", PaletteIndex::String));
|
||||
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##([+-]?([0-9]+([.][0-9]*)?|[.][0-9]+)([eE][+-]?[0-9]+)?[fF]?)##", PaletteIndex::Number));
|
||||
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##([+-]?[0-9]+[Uu]?[lL]?[lL]?)##", PaletteIndex::Number));
|
||||
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##(0[0-7]+[Uu]?[lL]?[lL]?)##", PaletteIndex::Number));
|
||||
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##(0[xX][0-9a-fA-F]+[uU]?[lL]?[lL]?)##", PaletteIndex::Number));
|
||||
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##([a-zA-Z_][a-zA-Z0-9_]*)##", PaletteIndex::Identifier));
|
||||
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##([\[\]\{\}\!\%\^\&\*\(\)\-\+\=\~\|\<\>\?\/\;\,\.])##", PaletteIndex::Punctuation));
|
||||
|
||||
langDef.mCommentStart = "/*";
|
||||
langDef.mCommentEnd = "*/";
|
||||
langDef.mSingleLineComment = "--";
|
||||
|
||||
langDef.mCaseSensitive = false;
|
||||
|
||||
langDef.mName = "SQL";
|
||||
|
||||
inited = true;
|
||||
}
|
||||
return langDef;
|
||||
}
|
||||
|
||||
const TextEditor::LanguageDefinition& TextEditor::LanguageDefinition::AngelScript()
|
||||
{
|
||||
static bool inited = false;
|
||||
static LanguageDefinition langDef;
|
||||
if (!inited)
|
||||
{
|
||||
static const char* const keywords[] = {
|
||||
"and", "abstract", "auto", "bool", "break", "case", "cast", "class", "const", "continue", "default", "do", "double", "else", "enum", "false", "final", "float", "for",
|
||||
"from", "funcdef", "function", "get", "if", "import", "in", "inout", "int", "interface", "int8", "int16", "int32", "int64", "is", "mixin", "namespace", "not",
|
||||
"null", "or", "out", "override", "private", "protected", "return", "set", "shared", "super", "switch", "this ", "true", "typedef", "uint", "uint8", "uint16", "uint32",
|
||||
"uint64", "void", "while", "xor"
|
||||
};
|
||||
|
||||
for (auto& k : keywords)
|
||||
langDef.mKeywords.insert(k);
|
||||
|
||||
static const char* const identifiers[] = {
|
||||
"cos", "sin", "tab", "acos", "asin", "atan", "atan2", "cosh", "sinh", "tanh", "log", "log10", "pow", "sqrt", "abs", "ceil", "floor", "fraction", "closeTo", "fpFromIEEE", "fpToIEEE",
|
||||
"complex", "opEquals", "opAddAssign", "opSubAssign", "opMulAssign", "opDivAssign", "opAdd", "opSub", "opMul", "opDiv"
|
||||
};
|
||||
for (auto& k : identifiers)
|
||||
{
|
||||
Identifier id;
|
||||
id.mDeclaration = "Built-in function";
|
||||
langDef.mIdentifiers.insert(std::make_pair(std::string(k), id));
|
||||
}
|
||||
|
||||
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##(L?\"(\\.|[^\"])*\")##", PaletteIndex::String));
|
||||
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##(\'\\?[^\']\')##", PaletteIndex::String));
|
||||
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##([+-]?([0-9]+([.][0-9]*)?|[.][0-9]+)([eE][+-]?[0-9]+)?[fF]?)##", PaletteIndex::Number));
|
||||
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##([+-]?[0-9]+[Uu]?[lL]?[lL]?)##", PaletteIndex::Number));
|
||||
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##(0[0-7]+[Uu]?[lL]?[lL]?)##", PaletteIndex::Number));
|
||||
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##(0[xX][0-9a-fA-F]+[uU]?[lL]?[lL]?)##", PaletteIndex::Number));
|
||||
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##([a-zA-Z_][a-zA-Z0-9_]*)##", PaletteIndex::Identifier));
|
||||
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##([\[\]\{\}\!\%\^\&\*\(\)\-\+\=\~\|\<\>\?\/\;\,\.])##", PaletteIndex::Punctuation));
|
||||
|
||||
langDef.mCommentStart = "/*";
|
||||
langDef.mCommentEnd = "*/";
|
||||
langDef.mSingleLineComment = "//";
|
||||
|
||||
langDef.mCaseSensitive = true;
|
||||
|
||||
langDef.mName = "AngelScript";
|
||||
|
||||
inited = true;
|
||||
}
|
||||
return langDef;
|
||||
}
|
||||
|
||||
const TextEditor::LanguageDefinition& TextEditor::LanguageDefinition::Lua()
|
||||
{
|
||||
static bool inited = false;
|
||||
static LanguageDefinition langDef;
|
||||
if (!inited)
|
||||
{
|
||||
static const char* const keywords[] = {
|
||||
"and", "break", "do", "else", "elseif", "end", "false", "for", "function", "goto", "if", "in", "local", "nil", "not", "or", "repeat", "return", "then", "true", "until", "while"
|
||||
};
|
||||
|
||||
for (auto& k : keywords)
|
||||
langDef.mKeywords.insert(k);
|
||||
|
||||
static const char* const identifiers[] = {
|
||||
"assert", "collectgarbage", "dofile", "error", "getmetatable", "ipairs", "loadfile", "load", "loadstring", "next", "pairs", "pcall", "print", "rawequal", "rawlen", "rawget", "rawset",
|
||||
"select", "setmetatable", "tonumber", "tostring", "type", "xpcall", "_G", "_VERSION","arshift", "band", "bnot", "bor", "bxor", "btest", "extract", "lrotate", "lshift", "replace",
|
||||
"rrotate", "rshift", "create", "resume", "running", "status", "wrap", "yield", "isyieldable", "debug","getuservalue", "gethook", "getinfo", "getlocal", "getregistry", "getmetatable",
|
||||
"getupvalue", "upvaluejoin", "upvalueid", "setuservalue", "sethook", "setlocal", "setmetatable", "setupvalue", "traceback", "close", "flush", "input", "lines", "open", "output", "popen",
|
||||
"read", "tmpfile", "type", "write", "close", "flush", "lines", "read", "seek", "setvbuf", "write", "__gc", "__tostring", "abs", "acos", "asin", "atan", "ceil", "cos", "deg", "exp", "tointeger",
|
||||
"floor", "fmod", "ult", "log", "max", "min", "modf", "rad", "random", "randomseed", "sin", "sqrt", "string", "tan", "type", "atan2", "cosh", "sinh", "tanh",
|
||||
"pow", "frexp", "ldexp", "log10", "pi", "huge", "maxinteger", "mininteger", "loadlib", "searchpath", "seeall", "preload", "cpath", "path", "searchers", "loaded", "module", "require", "clock",
|
||||
"date", "difftime", "execute", "exit", "getenv", "remove", "rename", "setlocale", "time", "tmpname", "byte", "char", "dump", "find", "format", "gmatch", "gsub", "len", "lower", "match", "rep",
|
||||
"reverse", "sub", "upper", "pack", "packsize", "unpack", "concat", "maxn", "insert", "pack", "unpack", "remove", "move", "sort", "offset", "codepoint", "char", "len", "codes", "charpattern",
|
||||
"coroutine", "table", "io", "os", "string", "utf8", "bit32", "math", "debug", "package"
|
||||
};
|
||||
for (auto& k : identifiers)
|
||||
{
|
||||
Identifier id;
|
||||
id.mDeclaration = "Built-in function";
|
||||
langDef.mIdentifiers.insert(std::make_pair(std::string(k), id));
|
||||
}
|
||||
|
||||
langDef.mTokenize = [](const char* in_begin, const char* in_end, const char*& out_begin, const char*& out_end, PaletteIndex& paletteIndex) -> bool
|
||||
{
|
||||
paletteIndex = PaletteIndex::Max;
|
||||
|
||||
while (in_begin < in_end && isascii(*in_begin) && isblank(*in_begin))
|
||||
in_begin++;
|
||||
|
||||
if (in_begin == in_end)
|
||||
{
|
||||
out_begin = in_end;
|
||||
out_end = in_end;
|
||||
paletteIndex = PaletteIndex::Default;
|
||||
}
|
||||
else if (TokenizeLuaStyleString(in_begin, in_end, out_begin, out_end))
|
||||
paletteIndex = PaletteIndex::String;
|
||||
else if (TokenizeLuaStyleIdentifier(in_begin, in_end, out_begin, out_end))
|
||||
paletteIndex = PaletteIndex::Identifier;
|
||||
else if (TokenizeLuaStyleNumber(in_begin, in_end, out_begin, out_end))
|
||||
paletteIndex = PaletteIndex::Number;
|
||||
else if (TokenizeLuaStylePunctuation(in_begin, in_end, out_begin, out_end))
|
||||
paletteIndex = PaletteIndex::Punctuation;
|
||||
|
||||
return paletteIndex != PaletteIndex::Max;
|
||||
};
|
||||
|
||||
langDef.mCommentStart = "--[[";
|
||||
langDef.mCommentEnd = "]]";
|
||||
langDef.mSingleLineComment = "--";
|
||||
|
||||
langDef.mCaseSensitive = true;
|
||||
|
||||
langDef.mName = "Lua";
|
||||
|
||||
inited = true;
|
||||
}
|
||||
return langDef;
|
||||
}
|
||||
|
||||
const TextEditor::LanguageDefinition& TextEditor::LanguageDefinition::Cs()
|
||||
{
|
||||
static bool inited = false;
|
||||
static LanguageDefinition langDef;
|
||||
if (!inited)
|
||||
{
|
||||
static const char* const keywords[] = {
|
||||
"abstract", "as", "base", "bool", "break", "byte", "case", "catch", "char", "checked", "class", "const", "continue", "decimal", "default", "delegate", "do", "double", "else", "enum", "event", "explicit", "extern", "false", "finally", "fixed", "float", "for", "foreach", "goto", "if", "implicit", "in", "in (generic modifier)", "int", "interface", "internal", "is", "lock", "long", "namespace", "new", "null", "object", "operator", "out", "out (generic modifier)", "override", "params", "private", "protected", "public", "readonly", "ref", "return", "sbyte", "sealed", "short", "sizeof", "stackalloc", "static", "string", "struct", "switch", "this", "throw", "true", "try", "typeof", "uint", "ulong", "unchecked", "unsafe", "ushort", "using", "using static", "void", "volatile", "while"
|
||||
};
|
||||
for (auto& k : keywords)
|
||||
langDef.mKeywords.insert(k);
|
||||
|
||||
static const char* const identifiers[] = {
|
||||
"add", "alias", "ascending", "async", "await", "descending", "dynamic", "from", "get", "global", "group", "into", "join", "let", "orderby", "partial", "remove", "select", "set", "value", "var", "when", "where", "yield"
|
||||
};
|
||||
for (auto& k : identifiers)
|
||||
{
|
||||
Identifier id;
|
||||
id.mDeclaration = "Built-in function";
|
||||
langDef.mIdentifiers.insert(std::make_pair(std::string(k), id));
|
||||
}
|
||||
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##(($|@)?\"(\\.|[^\"])*\")##", PaletteIndex::String));
|
||||
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##([+-]?([0-9]+([.][0-9]*)?|[.][0-9]+)([eE][+-]?[0-9]+)?[fF]?)##", PaletteIndex::Number));
|
||||
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##([+-]?[0-9]+[Uu]?[lL]?[lL]?)##", PaletteIndex::Number));
|
||||
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##(0[0-7]+[Uu]?[lL]?[lL]?)##", PaletteIndex::Number));
|
||||
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##(0[xX][0-9a-fA-F]+[uU]?[lL]?[lL]?)##", PaletteIndex::Number));
|
||||
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##([a-zA-Z_][a-zA-Z0-9_]*)##", PaletteIndex::Identifier));
|
||||
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##([\[\]\{\}\!\%\^\&\*\(\)\-\+\=\~\|\<\>\?\/\;\,\.])##", PaletteIndex::Punctuation));
|
||||
|
||||
langDef.mCommentStart = "/*";
|
||||
langDef.mCommentEnd = "*/";
|
||||
langDef.mSingleLineComment = "//";
|
||||
|
||||
langDef.mCaseSensitive = true;
|
||||
|
||||
langDef.mName = "C#";
|
||||
|
||||
inited = true;
|
||||
}
|
||||
return langDef;
|
||||
}
|
||||
|
||||
const TextEditor::LanguageDefinition& TextEditor::LanguageDefinition::Json()
|
||||
{
|
||||
static bool inited = false;
|
||||
static LanguageDefinition langDef;
|
||||
if (!inited)
|
||||
{
|
||||
langDef.mKeywords.clear();
|
||||
langDef.mIdentifiers.clear();
|
||||
|
||||
|
||||
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##(\"(\\.|[^\"])*\")##", PaletteIndex::String));
|
||||
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##([+-]?([0-9]+([.][0-9]*)?|[.][0-9]+)([eE][+-]?[0-9]+)?)##", PaletteIndex::Number));
|
||||
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##([\[\]\{\}\!\%\^\&\*\(\)\-\+\=\~\|\<\>\?\/\;\,\.\:])##", PaletteIndex::Punctuation));
|
||||
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##(false|true)##", PaletteIndex::Keyword));
|
||||
|
||||
langDef.mCommentStart = "/*";
|
||||
langDef.mCommentEnd = "*/";
|
||||
langDef.mSingleLineComment = "//";
|
||||
|
||||
langDef.mCaseSensitive = true;
|
||||
|
||||
langDef.mName = "Json";
|
||||
|
||||
inited = true;
|
||||
}
|
||||
return langDef;
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -1,469 +1,402 @@
|
|||
#pragma once
|
||||
|
||||
#include <cmath>
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <array>
|
||||
#include <memory>
|
||||
#include <unordered_set>
|
||||
#include <unordered_map>
|
||||
#include <map>
|
||||
#include "imgui.h"
|
||||
|
||||
class IMGUI_API TextEditor
|
||||
{
|
||||
public:
|
||||
// ------------- Exposed API ------------- //
|
||||
|
||||
TextEditor();
|
||||
~TextEditor();
|
||||
|
||||
enum class PaletteId
|
||||
{
|
||||
Dark, Light, Mariana, RetroBlue
|
||||
};
|
||||
enum class LanguageDefinitionId
|
||||
{
|
||||
None, Cpp, C, Cs, Python, Lua, Json, Sql, AngelScript, Glsl, Hlsl
|
||||
};
|
||||
enum class SetViewAtLineMode
|
||||
{
|
||||
FirstVisibleLine, Centered, LastVisibleLine
|
||||
};
|
||||
|
||||
inline void SetReadOnlyEnabled(bool aValue) { mReadOnly = aValue; }
|
||||
inline bool IsReadOnlyEnabled() const { return mReadOnly; }
|
||||
inline void SetAutoIndentEnabled(bool aValue) { mAutoIndent = aValue; }
|
||||
inline bool IsAutoIndentEnabled() const { return mAutoIndent; }
|
||||
inline void SetShowWhitespacesEnabled(bool aValue) { mShowWhitespaces = aValue; }
|
||||
inline bool IsShowWhitespacesEnabled() const { return mShowWhitespaces; }
|
||||
inline void SetShowLineNumbersEnabled(bool aValue) { mShowLineNumbers = aValue; }
|
||||
inline bool IsShowLineNumbersEnabled() const { return mShowLineNumbers; }
|
||||
inline void SetShortTabsEnabled(bool aValue) { mShortTabs = aValue; }
|
||||
inline bool IsShortTabsEnabled() const { return mShortTabs; }
|
||||
inline int GetLineCount() const { return mLines.size(); }
|
||||
inline bool IsOverwriteEnabled() const { return mOverwrite; }
|
||||
void SetPalette(PaletteId aValue);
|
||||
PaletteId GetPalette() const { return mPaletteId; }
|
||||
void SetLanguageDefinition(LanguageDefinitionId aValue);
|
||||
LanguageDefinitionId GetLanguageDefinition() const { return mLanguageDefinitionId; };
|
||||
const char* GetLanguageDefinitionName() const;
|
||||
void SetTabSize(int aValue);
|
||||
inline int GetTabSize() const { return mTabSize; }
|
||||
void SetLineSpacing(float aValue);
|
||||
inline float GetLineSpacing() const { return mLineSpacing; }
|
||||
|
||||
inline static void SetDefaultPalette(PaletteId aValue) { defaultPalette = aValue; }
|
||||
inline static PaletteId GetDefaultPalette() { return defaultPalette; }
|
||||
|
||||
void SelectAll();
|
||||
void SelectLine(int aLine);
|
||||
void SelectRegion(int aStartLine, int aStartChar, int aEndLine, int aEndChar);
|
||||
void SelectNextOccurrenceOf(const char* aText, int aTextSize, bool aCaseSensitive = true);
|
||||
void SelectAllOccurrencesOf(const char* aText, int aTextSize, bool aCaseSensitive = true);
|
||||
bool AnyCursorHasSelection() const;
|
||||
bool AllCursorsHaveSelection() const;
|
||||
void ClearExtraCursors();
|
||||
void ClearSelections();
|
||||
void SetCursorPosition(int aLine, int aCharIndex);
|
||||
inline void GetCursorPosition(int& outLine, int& outColumn) const
|
||||
{
|
||||
auto coords = GetActualCursorCoordinates();
|
||||
outLine = coords.mLine;
|
||||
outColumn = coords.mColumn;
|
||||
}
|
||||
int GetFirstVisibleLine();
|
||||
int GetLastVisibleLine();
|
||||
void SetViewAtLine(int aLine, SetViewAtLineMode aMode);
|
||||
|
||||
void Copy();
|
||||
void Cut();
|
||||
void Paste();
|
||||
void Undo(int aSteps = 1);
|
||||
void Redo(int aSteps = 1);
|
||||
inline bool CanUndo() const { return !mReadOnly && mUndoIndex > 0; };
|
||||
inline bool CanRedo() const { return !mReadOnly && mUndoIndex < (int)mUndoBuffer.size(); };
|
||||
inline int GetUndoIndex() const { return mUndoIndex; };
|
||||
|
||||
void SetText(const std::string& aText);
|
||||
std::string GetText() const;
|
||||
|
||||
void SetTextLines(const std::vector<std::string>& aLines);
|
||||
std::vector<std::string> GetTextLines() const;
|
||||
|
||||
bool Render(const char* aTitle, bool aParentIsFocused = false, const ImVec2& aSize = ImVec2(), bool aBorder = false);
|
||||
|
||||
void ImGuiDebugPanel(const std::string& panelName = "Debug");
|
||||
void UnitTests();
|
||||
|
||||
private:
|
||||
// ------------- Generic utils ------------- //
|
||||
|
||||
static inline ImVec4 U32ColorToVec4(ImU32 in)
|
||||
{
|
||||
float s = 1.0f / 255.0f;
|
||||
return ImVec4(
|
||||
((in >> IM_COL32_A_SHIFT) & 0xFF) * s,
|
||||
((in >> IM_COL32_B_SHIFT) & 0xFF) * s,
|
||||
((in >> IM_COL32_G_SHIFT) & 0xFF) * s,
|
||||
((in >> IM_COL32_R_SHIFT) & 0xFF) * s);
|
||||
}
|
||||
static inline bool IsUTFSequence(char c)
|
||||
{
|
||||
return (c & 0xC0) == 0x80;
|
||||
}
|
||||
static inline float Distance(const ImVec2& a, const ImVec2& b)
|
||||
{
|
||||
float x = a.x - b.x;
|
||||
float y = a.y - b.y;
|
||||
return sqrt(x * x + y * y);
|
||||
}
|
||||
template<typename T>
|
||||
static inline T Max(T a, T b) { return a > b ? a : b; }
|
||||
template<typename T>
|
||||
static inline T Min(T a, T b) { return a < b ? a : b; }
|
||||
|
||||
// ------------- Internal ------------- //
|
||||
|
||||
enum class PaletteIndex
|
||||
{
|
||||
Default,
|
||||
Keyword,
|
||||
Number,
|
||||
String,
|
||||
CharLiteral,
|
||||
Punctuation,
|
||||
Preprocessor,
|
||||
Identifier,
|
||||
KnownIdentifier,
|
||||
PreprocIdentifier,
|
||||
Comment,
|
||||
MultiLineComment,
|
||||
Background,
|
||||
Cursor,
|
||||
Selection,
|
||||
ErrorMarker,
|
||||
ControlCharacter,
|
||||
Breakpoint,
|
||||
LineNumber,
|
||||
CurrentLineFill,
|
||||
CurrentLineFillInactive,
|
||||
CurrentLineEdge,
|
||||
Max
|
||||
};
|
||||
|
||||
// Represents a character coordinate from the user's point of view,
|
||||
// i. e. consider an uniform grid (assuming fixed-width font) on the
|
||||
// screen as it is rendered, and each cell has its own coordinate, starting from 0.
|
||||
// Tabs are counted as [1..mTabSize] count empty spaces, depending on
|
||||
// how many space is necessary to reach the next tab stop.
|
||||
// For example, coordinate (1, 5) represents the character 'B' in a line "\tABC", when mTabSize = 4,
|
||||
// because it is rendered as " ABC" on the screen.
|
||||
struct Coordinates
|
||||
{
|
||||
int mLine, mColumn;
|
||||
Coordinates() : mLine(0), mColumn(0) {}
|
||||
Coordinates(int aLine, int aColumn) : mLine(aLine), mColumn(aColumn)
|
||||
{
|
||||
assert(aLine >= 0);
|
||||
assert(aColumn >= 0);
|
||||
}
|
||||
static Coordinates Invalid() { static Coordinates invalid(-1, -1); return invalid; }
|
||||
|
||||
bool operator ==(const Coordinates& o) const
|
||||
{
|
||||
return
|
||||
mLine == o.mLine &&
|
||||
mColumn == o.mColumn;
|
||||
}
|
||||
|
||||
bool operator !=(const Coordinates& o) const
|
||||
{
|
||||
return
|
||||
mLine != o.mLine ||
|
||||
mColumn != o.mColumn;
|
||||
}
|
||||
|
||||
bool operator <(const Coordinates& o) const
|
||||
{
|
||||
if (mLine != o.mLine)
|
||||
return mLine < o.mLine;
|
||||
return mColumn < o.mColumn;
|
||||
}
|
||||
|
||||
bool operator >(const Coordinates& o) const
|
||||
{
|
||||
if (mLine != o.mLine)
|
||||
return mLine > o.mLine;
|
||||
return mColumn > o.mColumn;
|
||||
}
|
||||
|
||||
bool operator <=(const Coordinates& o) const
|
||||
{
|
||||
if (mLine != o.mLine)
|
||||
return mLine < o.mLine;
|
||||
return mColumn <= o.mColumn;
|
||||
}
|
||||
|
||||
bool operator >=(const Coordinates& o) const
|
||||
{
|
||||
if (mLine != o.mLine)
|
||||
return mLine > o.mLine;
|
||||
return mColumn >= o.mColumn;
|
||||
}
|
||||
|
||||
Coordinates operator -(const Coordinates& o)
|
||||
{
|
||||
return Coordinates(mLine - o.mLine, mColumn - o.mColumn);
|
||||
}
|
||||
|
||||
Coordinates operator +(const Coordinates& o)
|
||||
{
|
||||
return Coordinates(mLine + o.mLine, mColumn + o.mColumn);
|
||||
}
|
||||
};
|
||||
|
||||
struct Cursor
|
||||
{
|
||||
Coordinates mInteractiveStart = { 0, 0 };
|
||||
Coordinates mInteractiveEnd = { 0, 0 };
|
||||
inline Coordinates GetSelectionStart() const { return mInteractiveStart < mInteractiveEnd ? mInteractiveStart : mInteractiveEnd; }
|
||||
inline Coordinates GetSelectionEnd() const { return mInteractiveStart > mInteractiveEnd ? mInteractiveStart : mInteractiveEnd; }
|
||||
inline bool HasSelection() const { return mInteractiveStart != mInteractiveEnd; }
|
||||
};
|
||||
|
||||
struct EditorState // state to be restored with undo/redo
|
||||
{
|
||||
int mCurrentCursor = 0;
|
||||
int mLastAddedCursor = 0;
|
||||
std::vector<Cursor> mCursors = { {{0,0}} };
|
||||
void AddCursor();
|
||||
int GetLastAddedCursorIndex();
|
||||
void SortCursorsFromTopToBottom();
|
||||
};
|
||||
|
||||
struct Identifier
|
||||
{
|
||||
Coordinates mLocation;
|
||||
std::string mDeclaration;
|
||||
};
|
||||
|
||||
typedef std::unordered_map<std::string, Identifier> Identifiers;
|
||||
typedef std::array<ImU32, (unsigned)PaletteIndex::Max> Palette;
|
||||
|
||||
struct Glyph
|
||||
{
|
||||
char mChar;
|
||||
PaletteIndex mColorIndex = PaletteIndex::Default;
|
||||
bool mComment : 1;
|
||||
bool mMultiLineComment : 1;
|
||||
bool mPreprocessor : 1;
|
||||
|
||||
Glyph(char aChar, PaletteIndex aColorIndex) : mChar(aChar), mColorIndex(aColorIndex),
|
||||
mComment(false), mMultiLineComment(false), mPreprocessor(false) {}
|
||||
};
|
||||
|
||||
typedef std::vector<Glyph> Line;
|
||||
|
||||
struct LanguageDefinition
|
||||
{
|
||||
typedef std::pair<std::string, PaletteIndex> TokenRegexString;
|
||||
typedef bool(*TokenizeCallback)(const char* in_begin, const char* in_end, const char*& out_begin, const char*& out_end, PaletteIndex& paletteIndex);
|
||||
|
||||
std::string mName;
|
||||
std::unordered_set<std::string> mKeywords;
|
||||
Identifiers mIdentifiers;
|
||||
Identifiers mPreprocIdentifiers;
|
||||
std::string mCommentStart, mCommentEnd, mSingleLineComment;
|
||||
char mPreprocChar = '#';
|
||||
TokenizeCallback mTokenize = nullptr;
|
||||
std::vector<TokenRegexString> mTokenRegexStrings;
|
||||
bool mCaseSensitive = true;
|
||||
|
||||
static const LanguageDefinition& Cpp();
|
||||
static const LanguageDefinition& Hlsl();
|
||||
static const LanguageDefinition& Glsl();
|
||||
static const LanguageDefinition& Python();
|
||||
static const LanguageDefinition& C();
|
||||
static const LanguageDefinition& Sql();
|
||||
static const LanguageDefinition& AngelScript();
|
||||
static const LanguageDefinition& Lua();
|
||||
static const LanguageDefinition& Cs();
|
||||
static const LanguageDefinition& Json();
|
||||
};
|
||||
|
||||
enum class UndoOperationType { Add, Delete };
|
||||
struct UndoOperation
|
||||
{
|
||||
std::string mText;
|
||||
TextEditor::Coordinates mStart;
|
||||
TextEditor::Coordinates mEnd;
|
||||
UndoOperationType mType;
|
||||
};
|
||||
|
||||
|
||||
class UndoRecord
|
||||
{
|
||||
public:
|
||||
UndoRecord() {}
|
||||
~UndoRecord() {}
|
||||
|
||||
UndoRecord(
|
||||
const std::vector<UndoOperation>& aOperations,
|
||||
TextEditor::EditorState& aBefore,
|
||||
TextEditor::EditorState& aAfter);
|
||||
|
||||
void Undo(TextEditor* aEditor);
|
||||
void Redo(TextEditor* aEditor);
|
||||
|
||||
std::vector<UndoOperation> mOperations;
|
||||
|
||||
EditorState mBefore;
|
||||
EditorState mAfter;
|
||||
};
|
||||
|
||||
std::string GetText(const Coordinates& aStart, const Coordinates& aEnd) const;
|
||||
std::string GetClipboardText() const;
|
||||
std::string GetSelectedText(int aCursor = -1) const;
|
||||
|
||||
void SetCursorPosition(const Coordinates& aPosition, int aCursor = -1, bool aClearSelection = true);
|
||||
|
||||
int InsertTextAt(Coordinates& aWhere, const char* aValue);
|
||||
void InsertTextAtCursor(const char* aValue, int aCursor = -1);
|
||||
|
||||
enum class MoveDirection { Right = 0, Left = 1, Up = 2, Down = 3 };
|
||||
bool Move(int& aLine, int& aCharIndex, bool aLeft = false, bool aLockLine = false) const;
|
||||
void MoveCharIndexAndColumn(int aLine, int& aCharIndex, int& aColumn) const;
|
||||
void MoveCoords(Coordinates& aCoords, MoveDirection aDirection, bool aWordMode = false, int aLineCount = 1) const;
|
||||
|
||||
void MoveUp(int aAmount = 1, bool aSelect = false);
|
||||
void MoveDown(int aAmount = 1, bool aSelect = false);
|
||||
void MoveLeft(bool aSelect = false, bool aWordMode = false);
|
||||
void MoveRight(bool aSelect = false, bool aWordMode = false);
|
||||
void MoveTop(bool aSelect = false);
|
||||
void MoveBottom(bool aSelect = false);
|
||||
void MoveHome(bool aSelect = false);
|
||||
void MoveEnd(bool aSelect = false);
|
||||
void EnterCharacter(ImWchar aChar, bool aShift);
|
||||
void Backspace(bool aWordMode = false);
|
||||
void Delete(bool aWordMode = false, const EditorState* aEditorState = nullptr);
|
||||
|
||||
void SetSelection(Coordinates aStart, Coordinates aEnd, int aCursor = -1);
|
||||
void SetSelection(int aStartLine, int aStartChar, int aEndLine, int aEndChar, int aCursor = -1);
|
||||
|
||||
void SelectNextOccurrenceOf(const char* aText, int aTextSize, int aCursor = -1, bool aCaseSensitive = true);
|
||||
void AddCursorForNextOccurrence(bool aCaseSensitive = true);
|
||||
bool FindNextOccurrence(const char* aText, int aTextSize, const Coordinates& aFrom, Coordinates& outStart, Coordinates& outEnd, bool aCaseSensitive = true);
|
||||
bool FindMatchingBracket(int aLine, int aCharIndex, Coordinates& out);
|
||||
void ChangeCurrentLinesIndentation(bool aIncrease);
|
||||
void MoveUpCurrentLines();
|
||||
void MoveDownCurrentLines();
|
||||
void ToggleLineComment();
|
||||
void RemoveCurrentLines();
|
||||
|
||||
float TextDistanceToLineStart(const Coordinates& aFrom, bool aSanitizeCoords = true) const;
|
||||
void EnsureCursorVisible(int aCursor = -1, bool aStartToo = false);
|
||||
|
||||
Coordinates SanitizeCoordinates(const Coordinates& aValue) const;
|
||||
Coordinates GetActualCursorCoordinates(int aCursor = -1, bool aStart = false) const;
|
||||
Coordinates ScreenPosToCoordinates(const ImVec2& aPosition, bool aInsertionMode = false, bool* isOverLineNumber = nullptr) const;
|
||||
Coordinates FindWordStart(const Coordinates& aFrom) const;
|
||||
Coordinates FindWordEnd(const Coordinates& aFrom) const;
|
||||
int GetCharacterIndexL(const Coordinates& aCoordinates) const;
|
||||
int GetCharacterIndexR(const Coordinates& aCoordinates) const;
|
||||
int GetCharacterColumn(int aLine, int aIndex) const;
|
||||
int GetFirstVisibleCharacterIndex(int aLine) const;
|
||||
int GetLineMaxColumn(int aLine, int aLimit = -1) const;
|
||||
|
||||
Line& InsertLine(int aIndex);
|
||||
void RemoveLine(int aIndex, const std::unordered_set<int>* aHandledCursors = nullptr);
|
||||
void RemoveLines(int aStart, int aEnd);
|
||||
void DeleteRange(const Coordinates& aStart, const Coordinates& aEnd);
|
||||
void DeleteSelection(int aCursor = -1);
|
||||
|
||||
void RemoveGlyphsFromLine(int aLine, int aStartChar, int aEndChar = -1);
|
||||
void AddGlyphsToLine(int aLine, int aTargetIndex, Line::iterator aSourceStart, Line::iterator aSourceEnd);
|
||||
void AddGlyphToLine(int aLine, int aTargetIndex, Glyph aGlyph);
|
||||
ImU32 GetGlyphColor(const Glyph& aGlyph) const;
|
||||
|
||||
void HandleKeyboardInputs(bool aParentIsFocused = false);
|
||||
void HandleMouseInputs();
|
||||
void UpdateViewVariables(float aScrollX, float aScrollY);
|
||||
void Render(bool aParentIsFocused = false);
|
||||
|
||||
void OnCursorPositionChanged();
|
||||
void OnLineChanged(bool aBeforeChange, int aLine, int aColumn, int aCharCount, bool aDeleted);
|
||||
void MergeCursorsIfPossible();
|
||||
|
||||
void AddUndo(UndoRecord& aValue);
|
||||
|
||||
void Colorize(int aFromLine = 0, int aCount = -1);
|
||||
void ColorizeRange(int aFromLine = 0, int aToLine = 0);
|
||||
void ColorizeInternal();
|
||||
|
||||
std::vector<Line> mLines;
|
||||
EditorState mState;
|
||||
std::vector<UndoRecord> mUndoBuffer;
|
||||
int mUndoIndex = 0;
|
||||
|
||||
int mTabSize = 4;
|
||||
float mLineSpacing = 1.0f;
|
||||
bool mOverwrite = false;
|
||||
bool mReadOnly = false;
|
||||
bool mAutoIndent = true;
|
||||
bool mShowWhitespaces = true;
|
||||
bool mShowLineNumbers = true;
|
||||
bool mShortTabs = false;
|
||||
|
||||
int mSetViewAtLine = -1;
|
||||
SetViewAtLineMode mSetViewAtLineMode;
|
||||
int mEnsureCursorVisible = -1;
|
||||
bool mEnsureCursorVisibleStartToo = false;
|
||||
bool mScrollToTop = false;
|
||||
|
||||
float mTextStart = 20.0f; // position (in pixels) where a code line starts relative to the left of the TextEditor.
|
||||
int mLeftMargin = 10;
|
||||
ImVec2 mCharAdvance;
|
||||
float mCurrentSpaceHeight = 20.0f;
|
||||
float mCurrentSpaceWidth = 20.0f;
|
||||
float mLastClickTime = -1.0f;
|
||||
ImVec2 mLastClickPos;
|
||||
int mFirstVisibleLine = 0;
|
||||
int mLastVisibleLine = 0;
|
||||
int mVisibleLineCount = 0;
|
||||
int mFirstVisibleColumn = 0;
|
||||
int mLastVisibleColumn = 0;
|
||||
int mVisibleColumnCount = 0;
|
||||
float mContentWidth = 0.0f;
|
||||
float mContentHeight = 0.0f;
|
||||
float mScrollX = 0.0f;
|
||||
float mScrollY = 0.0f;
|
||||
bool mPanning = false;
|
||||
bool mDraggingSelection = false;
|
||||
ImVec2 mLastMousePos;
|
||||
bool mCursorPositionChanged = false;
|
||||
bool mCursorOnBracket = false;
|
||||
Coordinates mMatchingBracketCoords;
|
||||
|
||||
int mColorRangeMin = 0;
|
||||
int mColorRangeMax = 0;
|
||||
bool mCheckComments = true;
|
||||
PaletteId mPaletteId;
|
||||
Palette mPalette;
|
||||
LanguageDefinitionId mLanguageDefinitionId;
|
||||
const LanguageDefinition* mLanguageDefinition = nullptr;
|
||||
|
||||
inline bool IsHorizontalScrollbarVisible() const { return mCurrentSpaceWidth > mContentWidth; }
|
||||
inline bool IsVerticalScrollbarVisible() const { return mCurrentSpaceHeight > mContentHeight; }
|
||||
inline int TabSizeAtColumn(int aColumn) const { return mTabSize - (aColumn % mTabSize); }
|
||||
|
||||
static const Palette& GetDarkPalette();
|
||||
static const Palette& GetMarianaPalette();
|
||||
static const Palette& GetLightPalette();
|
||||
static const Palette& GetRetroBluePalette();
|
||||
static const std::unordered_map<char, char> OPEN_TO_CLOSE_CHAR;
|
||||
static const std::unordered_map<char, char> CLOSE_TO_OPEN_CHAR;
|
||||
static PaletteId defaultPalette;
|
||||
};
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <array>
|
||||
#include <memory>
|
||||
#include <unordered_set>
|
||||
#include <unordered_map>
|
||||
#include <map>
|
||||
#include <regex>
|
||||
#include "imgui.h"
|
||||
|
||||
class TextEditor
|
||||
{
|
||||
public:
|
||||
enum class PaletteIndex
|
||||
{
|
||||
Default,
|
||||
Keyword,
|
||||
Number,
|
||||
String,
|
||||
CharLiteral,
|
||||
Punctuation,
|
||||
Preprocessor,
|
||||
Identifier,
|
||||
KnownIdentifier,
|
||||
PreprocIdentifier,
|
||||
Comment,
|
||||
MultiLineComment,
|
||||
Background,
|
||||
Cursor,
|
||||
Selection,
|
||||
ErrorMarker,
|
||||
Breakpoint,
|
||||
LineNumber,
|
||||
CurrentLineFill,
|
||||
CurrentLineFillInactive,
|
||||
CurrentLineEdge,
|
||||
Max
|
||||
};
|
||||
|
||||
enum class SelectionMode
|
||||
{
|
||||
Normal,
|
||||
Word,
|
||||
Line
|
||||
};
|
||||
|
||||
struct Breakpoint
|
||||
{
|
||||
int mLine;
|
||||
bool mEnabled;
|
||||
std::string mCondition;
|
||||
|
||||
Breakpoint()
|
||||
: mLine(-1)
|
||||
, mEnabled(false)
|
||||
{}
|
||||
};
|
||||
|
||||
// Represents a character coordinate from the user's point of view,
|
||||
// i. e. consider an uniform grid (assuming fixed-width font) on the
|
||||
// screen as it is rendered, and each cell has its own coordinate, starting from 0.
|
||||
// Tabs are counted as [1..mTabSize] count empty spaces, depending on
|
||||
// how many space is necessary to reach the next tab stop.
|
||||
// For example, coordinate (1, 5) represents the character 'B' in a line "\tABC", when mTabSize = 4,
|
||||
// because it is rendered as " ABC" on the screen.
|
||||
struct Coordinates
|
||||
{
|
||||
int mLine, mColumn;
|
||||
Coordinates() : mLine(0), mColumn(0) {}
|
||||
Coordinates(int aLine, int aColumn) : mLine(aLine), mColumn(aColumn)
|
||||
{
|
||||
assert(aLine >= 0);
|
||||
assert(aColumn >= 0);
|
||||
}
|
||||
static Coordinates Invalid() { static Coordinates invalid(-1, -1); return invalid; }
|
||||
|
||||
bool operator ==(const Coordinates& o) const
|
||||
{
|
||||
return
|
||||
mLine == o.mLine &&
|
||||
mColumn == o.mColumn;
|
||||
}
|
||||
|
||||
bool operator !=(const Coordinates& o) const
|
||||
{
|
||||
return
|
||||
mLine != o.mLine ||
|
||||
mColumn != o.mColumn;
|
||||
}
|
||||
|
||||
bool operator <(const Coordinates& o) const
|
||||
{
|
||||
if (mLine != o.mLine)
|
||||
return mLine < o.mLine;
|
||||
return mColumn < o.mColumn;
|
||||
}
|
||||
|
||||
bool operator >(const Coordinates& o) const
|
||||
{
|
||||
if (mLine != o.mLine)
|
||||
return mLine > o.mLine;
|
||||
return mColumn > o.mColumn;
|
||||
}
|
||||
|
||||
bool operator <=(const Coordinates& o) const
|
||||
{
|
||||
if (mLine != o.mLine)
|
||||
return mLine < o.mLine;
|
||||
return mColumn <= o.mColumn;
|
||||
}
|
||||
|
||||
bool operator >=(const Coordinates& o) const
|
||||
{
|
||||
if (mLine != o.mLine)
|
||||
return mLine > o.mLine;
|
||||
return mColumn >= o.mColumn;
|
||||
}
|
||||
};
|
||||
|
||||
struct Identifier
|
||||
{
|
||||
Coordinates mLocation;
|
||||
std::string mDeclaration;
|
||||
};
|
||||
|
||||
typedef std::string String;
|
||||
typedef std::unordered_map<std::string, Identifier> Identifiers;
|
||||
typedef std::unordered_set<std::string> Keywords;
|
||||
typedef std::map<int, std::string> ErrorMarkers;
|
||||
typedef std::unordered_set<int> Breakpoints;
|
||||
typedef std::array<ImU32, (unsigned)PaletteIndex::Max> Palette;
|
||||
typedef uint8_t Char;
|
||||
|
||||
struct Glyph
|
||||
{
|
||||
Char mChar;
|
||||
PaletteIndex mColorIndex = PaletteIndex::Default;
|
||||
bool mComment : 1;
|
||||
bool mMultiLineComment : 1;
|
||||
bool mPreprocessor : 1;
|
||||
|
||||
Glyph(Char aChar, PaletteIndex aColorIndex) : mChar(aChar), mColorIndex(aColorIndex),
|
||||
mComment(false), mMultiLineComment(false), mPreprocessor(false) {}
|
||||
};
|
||||
|
||||
typedef std::vector<Glyph> Line;
|
||||
typedef std::vector<Line> Lines;
|
||||
|
||||
struct LanguageDefinition
|
||||
{
|
||||
typedef std::pair<std::string, PaletteIndex> TokenRegexString;
|
||||
typedef std::vector<TokenRegexString> TokenRegexStrings;
|
||||
typedef bool(*TokenizeCallback)(const char * in_begin, const char * in_end, const char *& out_begin, const char *& out_end, PaletteIndex & paletteIndex);
|
||||
|
||||
std::string mName;
|
||||
Keywords mKeywords;
|
||||
Identifiers mIdentifiers;
|
||||
Identifiers mPreprocIdentifiers;
|
||||
std::string mCommentStart, mCommentEnd, mSingleLineComment;
|
||||
char mPreprocChar;
|
||||
bool mAutoIndentation;
|
||||
|
||||
TokenizeCallback mTokenize;
|
||||
|
||||
TokenRegexStrings mTokenRegexStrings;
|
||||
|
||||
bool mCaseSensitive;
|
||||
|
||||
LanguageDefinition()
|
||||
: mPreprocChar('#'), mAutoIndentation(true), mTokenize(nullptr), mCaseSensitive(true)
|
||||
{
|
||||
}
|
||||
|
||||
static const LanguageDefinition& CPlusPlus();
|
||||
static const LanguageDefinition& HLSL();
|
||||
static const LanguageDefinition& GLSL();
|
||||
static const LanguageDefinition& C();
|
||||
static const LanguageDefinition& SQL();
|
||||
static const LanguageDefinition& AngelScript();
|
||||
static const LanguageDefinition& Lua();
|
||||
};
|
||||
|
||||
TextEditor();
|
||||
~TextEditor();
|
||||
|
||||
void SetLanguageDefinition(const LanguageDefinition& aLanguageDef);
|
||||
const LanguageDefinition& GetLanguageDefinition() const { return mLanguageDefinition; }
|
||||
|
||||
const Palette& GetPalette() const { return mPaletteBase; }
|
||||
void SetPalette(const Palette& aValue);
|
||||
|
||||
void SetErrorMarkers(const ErrorMarkers& aMarkers) { mErrorMarkers = aMarkers; }
|
||||
void SetBreakpoints(const Breakpoints& aMarkers) { mBreakpoints = aMarkers; }
|
||||
|
||||
void Render(const char* aTitle, const ImVec2& aSize = ImVec2(), bool aBorder = false);
|
||||
void SetText(const std::string& aText);
|
||||
std::string GetText() const;
|
||||
|
||||
void SetTextLines(const std::vector<std::string>& aLines);
|
||||
std::vector<std::string> GetTextLines() const;
|
||||
|
||||
std::string GetSelectedText() const;
|
||||
std::string GetCurrentLineText()const;
|
||||
|
||||
int GetTotalLines() const { return (int)mLines.size(); }
|
||||
bool IsOverwrite() const { return mOverwrite; }
|
||||
|
||||
void SetReadOnly(bool aValue);
|
||||
bool IsReadOnly() const { return mReadOnly; }
|
||||
bool IsTextChanged() const { return mTextChanged; }
|
||||
bool IsCursorPositionChanged() const { return mCursorPositionChanged; }
|
||||
|
||||
bool IsColorizerEnabled() const { return mColorizerEnabled; }
|
||||
void SetColorizerEnable(bool aValue);
|
||||
|
||||
Coordinates GetCursorPosition() const { return GetActualCursorCoordinates(); }
|
||||
void SetCursorPosition(const Coordinates& aPosition);
|
||||
|
||||
inline void SetHandleMouseInputs (bool aValue){ mHandleMouseInputs = aValue;}
|
||||
inline bool IsHandleMouseInputsEnabled() const { return mHandleMouseInputs; }
|
||||
|
||||
inline void SetHandleKeyboardInputs (bool aValue){ mHandleKeyboardInputs = aValue;}
|
||||
inline bool IsHandleKeyboardInputsEnabled() const { return mHandleKeyboardInputs; }
|
||||
|
||||
inline void SetImGuiChildIgnored (bool aValue){ mIgnoreImGuiChild = aValue;}
|
||||
inline bool IsImGuiChildIgnored() const { return mIgnoreImGuiChild; }
|
||||
|
||||
inline void SetShowWhitespaces(bool aValue) { mShowWhitespaces = aValue; }
|
||||
inline bool IsShowingWhitespaces() const { return mShowWhitespaces; }
|
||||
|
||||
void SetTabSize(int aValue);
|
||||
inline int GetTabSize() const { return mTabSize; }
|
||||
|
||||
void InsertText(const std::string& aValue);
|
||||
void InsertText(const char* aValue);
|
||||
|
||||
void MoveUp(int aAmount = 1, bool aSelect = false);
|
||||
void MoveDown(int aAmount = 1, bool aSelect = false);
|
||||
void MoveLeft(int aAmount = 1, bool aSelect = false, bool aWordMode = false);
|
||||
void MoveRight(int aAmount = 1, bool aSelect = false, bool aWordMode = false);
|
||||
void MoveTop(bool aSelect = false);
|
||||
void MoveBottom(bool aSelect = false);
|
||||
void MoveHome(bool aSelect = false);
|
||||
void MoveEnd(bool aSelect = false);
|
||||
|
||||
void SetSelectionStart(const Coordinates& aPosition);
|
||||
void SetSelectionEnd(const Coordinates& aPosition);
|
||||
void SetSelection(const Coordinates& aStart, const Coordinates& aEnd, SelectionMode aMode = SelectionMode::Normal);
|
||||
void SelectWordUnderCursor();
|
||||
void SelectAll();
|
||||
bool HasSelection() const;
|
||||
|
||||
void Copy();
|
||||
void Cut();
|
||||
void Paste();
|
||||
void Delete();
|
||||
|
||||
bool CanUndo() const;
|
||||
bool CanRedo() const;
|
||||
void Undo(int aSteps = 1);
|
||||
void Redo(int aSteps = 1);
|
||||
|
||||
int GetUndoIndex() const;
|
||||
size_t GetUndoBufferSize() const;
|
||||
|
||||
void MarkSaved();
|
||||
void MarkUnsaved();
|
||||
void MarkSaved(bool saveState);
|
||||
bool IsSaved() const;
|
||||
|
||||
static const Palette& GetDarkPalette();
|
||||
static const Palette& GetLightPalette();
|
||||
static const Palette& GetRetroBluePalette();
|
||||
|
||||
private:
|
||||
typedef std::vector<std::pair<std::regex, PaletteIndex>> RegexList;
|
||||
|
||||
struct EditorState
|
||||
{
|
||||
Coordinates mSelectionStart;
|
||||
Coordinates mSelectionEnd;
|
||||
Coordinates mCursorPosition;
|
||||
};
|
||||
|
||||
class UndoRecord
|
||||
{
|
||||
public:
|
||||
UndoRecord() {}
|
||||
~UndoRecord() {}
|
||||
|
||||
UndoRecord(
|
||||
const std::string& aAdded,
|
||||
const TextEditor::Coordinates aAddedStart,
|
||||
const TextEditor::Coordinates aAddedEnd,
|
||||
|
||||
const std::string& aRemoved,
|
||||
const TextEditor::Coordinates aRemovedStart,
|
||||
const TextEditor::Coordinates aRemovedEnd,
|
||||
|
||||
TextEditor::EditorState& aBefore,
|
||||
TextEditor::EditorState& aAfter);
|
||||
|
||||
void Undo(TextEditor* aEditor);
|
||||
void Redo(TextEditor* aEditor);
|
||||
|
||||
std::string mAdded;
|
||||
Coordinates mAddedStart;
|
||||
Coordinates mAddedEnd;
|
||||
|
||||
std::string mRemoved;
|
||||
Coordinates mRemovedStart;
|
||||
Coordinates mRemovedEnd;
|
||||
|
||||
EditorState mBefore;
|
||||
EditorState mAfter;
|
||||
};
|
||||
|
||||
typedef std::vector<UndoRecord> UndoBuffer;
|
||||
|
||||
void ProcessInputs();
|
||||
void Colorize(int aFromLine = 0, int aCount = -1);
|
||||
void ColorizeRange(int aFromLine = 0, int aToLine = 0);
|
||||
void ColorizeInternal();
|
||||
float TextDistanceToLineStart(const Coordinates& aFrom) const;
|
||||
void EnsureCursorVisible();
|
||||
int GetPageSize() const;
|
||||
std::string GetText(const Coordinates& aStart, const Coordinates& aEnd) const;
|
||||
Coordinates GetActualCursorCoordinates() const;
|
||||
Coordinates SanitizeCoordinates(const Coordinates& aValue) const;
|
||||
void Advance(Coordinates& aCoordinates) const;
|
||||
void DeleteRange(const Coordinates& aStart, const Coordinates& aEnd);
|
||||
int InsertTextAt(Coordinates& aWhere, const char* aValue);
|
||||
void AddUndo(UndoRecord& aValue);
|
||||
Coordinates ScreenPosToCoordinates(const ImVec2& aPosition) const;
|
||||
Coordinates FindWordStart(const Coordinates& aFrom) const;
|
||||
Coordinates FindWordEnd(const Coordinates& aFrom) const;
|
||||
Coordinates FindNextWord(const Coordinates& aFrom) const;
|
||||
int GetCharacterIndex(const Coordinates& aCoordinates) const;
|
||||
int GetCharacterColumn(int aLine, int aIndex) const;
|
||||
int GetLineCharacterCount(int aLine) const;
|
||||
int GetLineMaxColumn(int aLine) const;
|
||||
bool IsOnWordBoundary(const Coordinates& aAt) const;
|
||||
void RemoveLine(int aStart, int aEnd);
|
||||
void RemoveLine(int aIndex);
|
||||
Line& InsertLine(int aIndex);
|
||||
void EnterCharacter(ImWchar aChar, bool aShift);
|
||||
void Backspace();
|
||||
void DeleteSelection();
|
||||
std::string GetWordUnderCursor() const;
|
||||
std::string GetWordAt(const Coordinates& aCoords) const;
|
||||
ImU32 GetGlyphColor(const Glyph& aGlyph) const;
|
||||
|
||||
void HandleKeyboardInputs();
|
||||
void HandleMouseInputs();
|
||||
void Render();
|
||||
|
||||
float mLineSpacing;
|
||||
Lines mLines;
|
||||
EditorState mState;
|
||||
UndoBuffer mUndoBuffer;
|
||||
int mUndoIndex;
|
||||
|
||||
int mTabSize;
|
||||
bool mOverwrite;
|
||||
bool mReadOnly;
|
||||
bool mWithinRender;
|
||||
bool mScrollToCursor;
|
||||
bool mScrollToTop;
|
||||
bool mTextChanged;
|
||||
bool mColorizerEnabled;
|
||||
float mTextStart; // position (in pixels) where a code line starts relative to the left of the TextEditor.
|
||||
int mLeftMargin;
|
||||
bool mCursorPositionChanged;
|
||||
int mColorRangeMin, mColorRangeMax;
|
||||
SelectionMode mSelectionMode;
|
||||
bool mHandleKeyboardInputs;
|
||||
bool mHandleMouseInputs;
|
||||
bool mIgnoreImGuiChild;
|
||||
bool mShowWhitespaces;
|
||||
|
||||
Palette mPaletteBase;
|
||||
Palette mPalette;
|
||||
LanguageDefinition mLanguageDefinition;
|
||||
RegexList mRegexList;
|
||||
|
||||
bool mCheckComments;
|
||||
Breakpoints mBreakpoints;
|
||||
ErrorMarkers mErrorMarkers;
|
||||
ImVec2 mCharAdvance;
|
||||
Coordinates mInteractiveStart, mInteractiveEnd;
|
||||
std::string mLineBuffer;
|
||||
uint64_t mStartTime;
|
||||
|
||||
float mLastClick;
|
||||
|
||||
bool mSaveState;
|
||||
bool mMarkedUnsaved;
|
||||
int mUndoIndexFirstEdit;
|
||||
int mUndoIndexLastSave;
|
||||
};
|
||||
|
|
BIN
neo/sys/win32/rc/doom.aps
Normal file
BIN
neo/sys/win32/rc/doom.aps
Normal file
Binary file not shown.
|
@ -75,6 +75,8 @@ ScriptEditor::ScriptEditor()
|
|||
, scriptEdit(NULL)
|
||||
, okButtonEnabled( false )
|
||||
, cancelButtonEnabled( true )
|
||||
, errorText()
|
||||
, gotoDlg()
|
||||
, findStr()
|
||||
, replaceStr()
|
||||
, matchCase( false )
|
||||
|
@ -87,12 +89,13 @@ ScriptEditor::ScriptEditor()
|
|||
}
|
||||
|
||||
void ScriptEditor::Reset() {
|
||||
windowText = "Script Editor";
|
||||
windowText = "Script Editor###ScriptEditor";
|
||||
statusBarText.Clear();
|
||||
scriptEdit->SetText( std::string( "" ) );
|
||||
scriptEdit->SetTabSize( TAB_SIZE );
|
||||
okButtonEnabled = false;
|
||||
cancelButtonEnabled = true;
|
||||
errorText.Clear();
|
||||
findStr.Clear();
|
||||
replaceStr.Clear();
|
||||
matchCase = false;
|
||||
|
@ -111,7 +114,7 @@ void ScriptEditor::Draw()
|
|||
|
||||
showTool = isShown;
|
||||
|
||||
if (ImGui::Begin("Script Editor", &showTool, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_MenuBar)) {
|
||||
if ( ImGui::Begin( windowText.c_str(), &showTool, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_MenuBar ) ) {
|
||||
impl::SetReleaseToolMouse(true);
|
||||
|
||||
if (ImGui::BeginMenuBar())
|
||||
|
@ -130,7 +133,7 @@ void ScriptEditor::Draw()
|
|||
|
||||
if (ImGui::MenuItem("Save", "Ctrl+S"))
|
||||
{
|
||||
//OnBnClickedButtonSave();
|
||||
OnBnClickedOk();
|
||||
}
|
||||
|
||||
if (ImGui::MenuItem("Close", "Ctrl+W"))
|
||||
|
@ -140,6 +143,13 @@ void ScriptEditor::Draw()
|
|||
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
if ( ImGui::BeginMenu( "Edit" ) ) {
|
||||
if ( ImGui::MenuItem( "Go To...", "Ctrl+G" ) ) {
|
||||
OnEditGoToLine();
|
||||
}
|
||||
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
ImGui::EndMenuBar();
|
||||
}
|
||||
|
||||
|
@ -148,12 +158,15 @@ void ScriptEditor::Draw()
|
|||
if (clickedSelect) {
|
||||
}
|
||||
|
||||
scriptEdit->Render( "Text", false, ImVec2( 800, 600 ) );
|
||||
scriptEdit->Render( "Text", ImVec2( 800, 600 ), false );
|
||||
if ( !scriptEdit->IsSaved() ) {
|
||||
okButtonEnabled = true;
|
||||
}
|
||||
UpdateStatusBar();
|
||||
|
||||
ImGui::BeginDisabled( !okButtonEnabled );
|
||||
if ( ImGui::Button( "OK" ) ) {
|
||||
|
||||
OnBnClickedOk();
|
||||
}
|
||||
ImGui::EndDisabled();
|
||||
ImGui::SameLine();
|
||||
|
@ -162,7 +175,18 @@ void ScriptEditor::Draw()
|
|||
showTool = false;
|
||||
}
|
||||
ImGui::EndDisabled();
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Go to")) {
|
||||
OnEditGoToLine();
|
||||
}
|
||||
|
||||
if ( gotoDlg.Draw() ) {
|
||||
TextEditor::Coordinates coords( gotoDlg.GetLine() - 1 - firstLine, 0 );
|
||||
|
||||
scriptEdit->SetCursorPosition( coords );
|
||||
}
|
||||
|
||||
ImGui::TextColored( ImVec4( 1, 0, 0, 1 ), "%s", errorText.c_str() );
|
||||
ImGui::TextUnformatted( statusBarText.c_str() );
|
||||
}
|
||||
ImGui::End();
|
||||
|
@ -195,10 +219,8 @@ ScriptEditor::UpdateStatusBar
|
|||
================
|
||||
*/
|
||||
void ScriptEditor::UpdateStatusBar( void ) {
|
||||
int line, column;
|
||||
|
||||
scriptEdit->GetCursorPosition( line, column );
|
||||
statusBarText = idStr::Format( "Line: %d, Column: %d", line, column );
|
||||
TextEditor::Coordinates coords = scriptEdit->GetCursorPosition();
|
||||
statusBarText = idStr::Format( "Line: %d, Column: %d", coords.mLine + 1, coords.mColumn + 1 );
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -315,7 +337,7 @@ void ScriptEditor::OpenFile( const char *fileName ) {
|
|||
|
||||
if ( extension.Icmp( "script" ) == 0 ) {
|
||||
InitScriptEvents();
|
||||
scriptEdit->SetLanguageDefinition( TextEditor::LanguageDefinitionId::Cpp );
|
||||
scriptEdit->SetLanguageDefinition( TextEditor::LanguageDefinition::CPlusPlus() );
|
||||
/*
|
||||
scriptEdit.SetCaseSensitive( true );
|
||||
scriptEdit.LoadKeyWordsFromFile( "editors/script.def" );
|
||||
|
@ -328,10 +350,11 @@ void ScriptEditor::OpenFile( const char *fileName ) {
|
|||
scriptEdit.SetStringColor(SRE_COLOR_DARK_CYAN, SRE_COLOR_LIGHT_BROWN);
|
||||
scriptEdit.LoadKeyWordsFromFile( "editors/gui.def" );
|
||||
*/
|
||||
scriptEdit->SetLanguageDefinition( TextEditor::LanguageDefinitionId::Json );
|
||||
scriptEdit->SetLanguageDefinition( TextEditor::LanguageDefinition::C() );
|
||||
}
|
||||
|
||||
if ( fileSystem->ReadFile( fileName, &buffer ) == -1 ) {
|
||||
errorText = "Unable to read the selected file";
|
||||
return;
|
||||
}
|
||||
scriptText = (char *) buffer;
|
||||
|
@ -355,7 +378,7 @@ void ScriptEditor::OpenFile( const char *fileName ) {
|
|||
}
|
||||
}
|
||||
|
||||
windowText = va( "Script Editor (%s)", fileName );
|
||||
windowText = va( "Script Editor (%s)###ScriptEditor", fileName );
|
||||
/*
|
||||
rect.left = initialRect.left;
|
||||
rect.right = rect.left + maxCharsPerLine * FONT_WIDTH + 32;
|
||||
|
@ -381,60 +404,6 @@ void ScriptEditor::OpenFile( const char *fileName ) {
|
|||
//scriptEdit.SetFocus();
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
ScriptEditor::OnInitDialog
|
||||
================
|
||||
*/
|
||||
bool ScriptEditor::OnInitDialog() {
|
||||
|
||||
//com_editors |= EDITOR_SCRIPT;
|
||||
|
||||
// load accelerator table
|
||||
//m_hAccel = ::LoadAccelerators( AfxGetResourceHandle(), MAKEINTRESOURCE( IDR_ACCELERATOR_SCRIPTEDITOR ) );
|
||||
|
||||
// create status bar
|
||||
//statusBar.CreateEx( SBARS_SIZEGRIP, WS_CHILD | WS_VISIBLE | CBRS_BOTTOM, initialRect, this, AFX_IDW_STATUS_BAR );
|
||||
|
||||
//scriptEdit.LimitText( 1024 * 1024 );
|
||||
scriptEdit->SetTabSize( TAB_SIZE );
|
||||
|
||||
//GetClientRect( initialRect );
|
||||
|
||||
windowText = "Script Editor";
|
||||
|
||||
//EnableToolTips( TRUE );
|
||||
|
||||
okButtonEnabled = false;
|
||||
cancelButtonEnabled = true;
|
||||
|
||||
UpdateStatusBar();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
BEGIN_MESSAGE_MAP(DialogScriptEditor, CDialog)
|
||||
ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, OnToolTipNotify)
|
||||
ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, OnToolTipNotify)
|
||||
ON_WM_DESTROY()
|
||||
ON_WM_ACTIVATE()
|
||||
ON_WM_MOVE()
|
||||
ON_WM_SIZE()
|
||||
ON_WM_SIZING()
|
||||
ON_WM_SETFOCUS()
|
||||
ON_COMMAND(ID_EDIT_FIND, OnEditFind)
|
||||
ON_COMMAND(ID_EDIT_REPLACE, OnEditReplace)
|
||||
ON_COMMAND(ID_SCRIPTEDITOR_FIND_NEXT, OnEditFindNext)
|
||||
ON_COMMAND(ID_SCRIPTEDITOR_GOTOLINE, OnEditGoToLine)
|
||||
ON_REGISTERED_MESSAGE(FindDialogMessage, OnFindDialogMessage)
|
||||
ON_NOTIFY(EN_CHANGE, IDC_SCRIPTEDITOR_EDIT_TEXT, OnEnChangeEdit)
|
||||
ON_NOTIFY(EN_MSGFILTER, IDC_SCRIPTEDITOR_EDIT_TEXT, OnEnInputEdit)
|
||||
ON_BN_CLICKED(IDOK, OnBnClickedOk)
|
||||
ON_BN_CLICKED(IDCANCEL, OnBnClickedCancel)
|
||||
END_MESSAGE_MAP()
|
||||
*/
|
||||
|
||||
// ScriptEditor message handlers
|
||||
|
||||
#define BORDER_SIZE 0
|
||||
|
@ -447,6 +416,10 @@ ScriptEditor::OnEditGoToLine
|
|||
================
|
||||
*/
|
||||
void ScriptEditor::OnEditGoToLine() {
|
||||
TextEditor::Coordinates coords = scriptEdit->GetCursorPosition();
|
||||
|
||||
gotoDlg.Start( firstLine + 1, firstLine + scriptEdit->GetTotalLines(), coords.mLine + 1 );
|
||||
|
||||
/*DialogGoToLine goToLineDlg;
|
||||
|
||||
goToLineDlg.SetRange( firstLine, firstLine + scriptEdit.GetLineCount() - 1 );
|
||||
|
@ -463,12 +436,12 @@ ScriptEditor::OnEditFind
|
|||
================
|
||||
*/
|
||||
void ScriptEditor::OnEditFind() {
|
||||
/*
|
||||
idStr selText = scriptEdit.GetSelText();
|
||||
idStr selText = scriptEdit->GetSelectedText().c_str();
|
||||
if ( selText.Length() ) {
|
||||
findStr = selText;
|
||||
}
|
||||
|
||||
/*
|
||||
// create find/replace dialog
|
||||
if ( !findDlg ) {
|
||||
findDlg = new CFindReplaceDialog(); // Must be created on the heap
|
||||
|
@ -483,13 +456,12 @@ ScriptEditor::OnEditFindNext
|
|||
================
|
||||
*/
|
||||
void ScriptEditor::OnEditFindNext() {
|
||||
/*
|
||||
if ( scriptEdit.FindNext( findStr, matchCase, matchWholeWords, searchForward ) ) {
|
||||
scriptEdit.SetFocus();
|
||||
|
||||
if ( searchForward ) {
|
||||
//scriptEdit->( findStr.c_str(), findStr.Length(), matchCase ); // TODO: implement whole word match
|
||||
} else {
|
||||
AfxMessageBox( "The specified text was not found.", MB_OK | MB_ICONINFORMATION, 0 );
|
||||
// TODO: implement search backward
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -499,7 +471,8 @@ ScriptEditor::OnEditReplace
|
|||
*/
|
||||
void ScriptEditor::OnEditReplace() {
|
||||
/*
|
||||
idStr selText = scriptEdit.GetSelText();
|
||||
* TODO: get selected text?
|
||||
idStr selText = scriptEdit->GetSelText();
|
||||
if ( selText.Length() ) {
|
||||
findStr = selText;
|
||||
}
|
||||
|
@ -601,7 +574,7 @@ void ScriptEditor::OnBnClickedOk() {
|
|||
scriptText = scriptEdit->GetText().c_str();
|
||||
|
||||
if ( fileSystem->WriteFile( fileName, scriptText, scriptText.Length(), "fs_devpath" ) == -1 ) {
|
||||
//MessageBox( va( "Couldn't save: %s", fileName.c_str() ), va( "Error saving: %s", fileName.c_str() ), MB_OK | MB_ICONERROR );
|
||||
errorText = va( "Couldn't save: %s", fileName.c_str() );
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ public:
|
|||
|
||||
static ScriptEditor& Instance();
|
||||
|
||||
void OpenFile( const char *fileName );
|
||||
void OpenFile( const char *fileName );
|
||||
|
||||
void Reset();
|
||||
void Draw();
|
||||
|
@ -58,12 +58,6 @@ public:
|
|||
return isShown;
|
||||
}
|
||||
|
||||
//{{AFX_VIRTUAL(DialogScriptEditor)
|
||||
bool OnInitDialog();
|
||||
//virtual void DoDataExchange( CDataExchange* pDX ); // DDX/DDV support
|
||||
//virtual BOOL PreTranslateMessage( MSG* pMsg );
|
||||
//}}AFX_VIRTUAL
|
||||
|
||||
protected:
|
||||
void OnEditGoToLine();
|
||||
void OnEditFind();
|
||||
|
@ -82,16 +76,11 @@ private:
|
|||
TextEditor * scriptEdit;
|
||||
bool okButtonEnabled;
|
||||
bool cancelButtonEnabled;
|
||||
idStr errorText;
|
||||
/*
|
||||
CButton okButton;
|
||||
CButton cancelButton;
|
||||
|
||||
static toolTip_t toolTips[];
|
||||
|
||||
HACCEL m_hAccel;
|
||||
CRect initialRect;
|
||||
CFindReplaceDialog *findDlg;
|
||||
*/
|
||||
GoToLineDialog gotoDlg;
|
||||
idStr findStr;
|
||||
idStr replaceStr;
|
||||
bool matchCase;
|
||||
|
|
|
@ -412,6 +412,73 @@ bool DeclSelect::Draw() {
|
|||
return accepted;
|
||||
}
|
||||
|
||||
GoToLineDialog::GoToLineDialog()
|
||||
: numberEdit(0)
|
||||
, firstLine(0)
|
||||
, lastLine(0)
|
||||
, waiting(false)
|
||||
, valid(false)
|
||||
, caption()
|
||||
{
|
||||
}
|
||||
|
||||
void GoToLineDialog::Start( int _firstLine, int _lastLine, int _line ) {
|
||||
firstLine = _firstLine;
|
||||
lastLine = _lastLine;
|
||||
numberEdit = _line;
|
||||
valid = ( idMath::ClampInt( firstLine, lastLine, numberEdit ) == numberEdit );
|
||||
waiting = true;
|
||||
caption = va( "Line number (%d - %d)", firstLine, lastLine );
|
||||
ImGui::OpenPopup( "Go To Line" );
|
||||
}
|
||||
|
||||
bool GoToLineDialog::Draw() {
|
||||
bool accepted = false;
|
||||
|
||||
if ( ImGui::BeginPopup( "Go To Line" ) ) {
|
||||
if ( ImGui::InputInt( caption.c_str(), &numberEdit, 0, 0 ) ) {
|
||||
valid = ( idMath::ClampInt( firstLine, lastLine, numberEdit ) == numberEdit );
|
||||
}
|
||||
|
||||
ImGui::BeginDisabled( !valid );
|
||||
if ( ImGui::Button( "OK" ) ) {
|
||||
waiting = false;
|
||||
accepted = true;
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
ImGui::EndDisabled();
|
||||
ImGui::SameLine();
|
||||
if ( ImGui::Button( "Cancel" ) ) {
|
||||
waiting = false;
|
||||
accepted = false;
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
||||
return accepted;
|
||||
}
|
||||
|
||||
/*
|
||||
class GoToLineDialog {
|
||||
public:
|
||||
GoToLineDialog();
|
||||
|
||||
void Start(int firstLine, int lastLine);
|
||||
ID_INLINE int GetLine() const { return line; }
|
||||
bool Draw();
|
||||
|
||||
private:
|
||||
|
||||
int numberEdit;
|
||||
int firstLine;
|
||||
int lastLine;
|
||||
int line;
|
||||
bool accepted;
|
||||
};
|
||||
*/
|
||||
|
||||
} //namespace ImGuiTools
|
||||
|
||||
|
||||
|
|
|
@ -134,6 +134,24 @@ private:
|
|||
state_t state;
|
||||
};
|
||||
|
||||
class GoToLineDialog {
|
||||
public:
|
||||
GoToLineDialog();
|
||||
|
||||
void Start( int firstLine, int lastLine, int line );
|
||||
ID_INLINE int GetLine() const { return numberEdit; }
|
||||
bool Draw();
|
||||
|
||||
private:
|
||||
|
||||
int numberEdit;
|
||||
int firstLine;
|
||||
int lastLine;
|
||||
bool waiting;
|
||||
bool valid;
|
||||
idStr caption;
|
||||
};
|
||||
|
||||
} //namespace ImGuiTools
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue