improv: further reformatting of text editor in an effort to bring it into the ui plugin. (#2385)

Added the ui namespace and broke the main rendering function into a set
of smaller functions. Reorganized the header code separating functions
into rough groups that eventually will be in separate files.
This commit is contained in:
paxcut
2025-08-08 12:47:52 -07:00
committed by GitHub
parent 82ceb2e11f
commit df1e97af0a
8 changed files with 4826 additions and 4713 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -27,9 +27,9 @@ namespace hex::plugin::builtin {
using TokenIter = pl::hlp::SafeIterator<std::vector<Token>::const_iterator>;
using VariableScopes = std::map<std::string,Scopes>;
using Inheritances = std::map<std::string,std::vector<std::string>>;
using IdentifierTypeColor = std::map<Identifier::IdentifierType,TextEditor::PaletteIndex>;
using TokenTypeColor = std::map<Token::Type,TextEditor::PaletteIndex>;
using TokenColor = std::map<Token *,TextEditor::PaletteIndex>;
using IdentifierTypeColor = std::map<Identifier::IdentifierType,ui::TextEditor::PaletteIndex>;
using TokenTypeColor = std::map<Token::Type,ui::TextEditor::PaletteIndex>;
using TokenColor = std::map<Token *,ui::TextEditor::PaletteIndex>;
struct ParentDefinition;
struct Definition {
@@ -218,7 +218,7 @@ namespace hex::plugin::builtin {
/// Loads the source code and calculates the first token index of each line
void loadText();
/// Used to obtain the color to be applied.
TextEditor::PaletteIndex getPaletteIndex(Token::Literal *literal);
ui::TextEditor::PaletteIndex getPaletteIndex(Token::Literal *literal);
/// The complement of a set is also known as its inverse
void invertGlobalTokenRange();
/// Starting at the identifier, it tracks all the scope resolution and dot operators and returns the full chain without arrays, templates, pointers,...
@@ -269,8 +269,8 @@ namespace hex::plugin::builtin {
///Creates a map from function name to argument type
void linkAttribute();
/// Comment and strings usethese function to determine their coordinates
template<typename T> TextEditor::Coordinates commentCoordinates(Token *token);
TextEditor::Coordinates stringCoordinates();
template<typename T> ui::TextEditor::Coordinates commentCoordinates(Token *token);
ui::TextEditor::Coordinates stringCoordinates();
/// Returns the number of tasks highlighting code. Shouldn't be > 1
i32 getRunningColorizers() {
return m_runningColorizers;

View File

@@ -73,7 +73,7 @@ namespace hex::plugin::builtin {
return &m_editorRuntime;
}
TextEditor &getTextEditor() {
ui::TextEditor &getTextEditor() {
return m_textEditor;
}
@@ -262,7 +262,7 @@ namespace hex::plugin::builtin {
PerProvider<bool> m_hasUnevaluatedChanges;
std::chrono::time_point<std::chrono::steady_clock> m_lastEditorChangeTime;
PerProvider<TextEditor> m_textEditor, m_consoleEditor;
PerProvider<ui::TextEditor> m_textEditor, m_consoleEditor;
std::atomic<bool> m_consoleNeedsUpdate = false;
std::atomic<bool> m_dangerousFunctionCalled = false;
@@ -279,15 +279,15 @@ namespace hex::plugin::builtin {
std::mutex m_logMutex;
PerProvider<TextEditor::Coordinates> m_cursorPosition;
PerProvider<ui::TextEditor::Coordinates> m_cursorPosition;
PerProvider<TextEditor::Coordinates> m_consoleCursorPosition;
PerProvider<ui::TextEditor::Coordinates> m_consoleCursorPosition;
PerProvider<bool> m_cursorNeedsUpdate;
PerProvider<bool> m_consoleCursorNeedsUpdate;
PerProvider<TextEditor::Selection> m_selection;
PerProvider<TextEditor::Selection> m_consoleSelection;
PerProvider<ui::TextEditor::Selection> m_selection;
PerProvider<ui::TextEditor::Selection> m_consoleSelection;
PerProvider<size_t> m_consoleLongestLineLength;
PerProvider<TextEditor::Breakpoints> m_breakpoints;
PerProvider<ui::TextEditor::Breakpoints> m_breakpoints;
PerProvider<std::optional<pl::core::err::PatternLanguageError>> m_lastEvaluationError;
PerProvider<std::vector<pl::core::err::CompileError>> m_lastCompileError;
PerProvider<const std::vector<pl::core::Evaluator::StackTrace>*> m_callStack;
@@ -343,8 +343,8 @@ namespace hex::plugin::builtin {
void drawPatternTooltip(pl::ptrn::Pattern *pattern);
void drawTextEditorFindReplacePopup(TextEditor *textEditor);
void drawTextEditorGotoLinePopup(TextEditor *textEditor);
void drawTextEditorFindReplacePopup(ui::TextEditor *textEditor);
void drawTextEditorGotoLinePopup(ui::TextEditor *textEditor);
void historyInsert(std::array<std::string, 256> &history, u32 &size, u32 &index, const std::string &value);
@@ -355,9 +355,9 @@ namespace hex::plugin::builtin {
void parsePattern(const std::string &code, prv::Provider *provider);
void evaluatePattern(const std::string &code, prv::Provider *provider);
TextEditor *getEditorFromFocusedWindow();
void setupFindReplace(TextEditor *editor);
void setupGotoLine(TextEditor *editor);
ui::TextEditor *getEditorFromFocusedWindow();
void setupFindReplace(ui::TextEditor *editor);
void setupGotoLine(ui::TextEditor *editor);
void registerEvents();
void registerMenuItems();

View File

@@ -1176,52 +1176,52 @@ namespace hex::plugin::builtin {
}
const TextHighlighter::TokenTypeColor TextHighlighter::m_tokenTypeColor = {
{Token::Type::Keyword, TextEditor::PaletteIndex::Keyword},
{Token::Type::ValueType, TextEditor::PaletteIndex::BuiltInType},
{Token::Type::Operator, TextEditor::PaletteIndex::Operator},
{Token::Type::Separator, TextEditor::PaletteIndex::Separator},
{Token::Type::String, TextEditor::PaletteIndex::StringLiteral},
{Token::Type::Directive, TextEditor::PaletteIndex::Directive},
{Token::Type::Comment, TextEditor::PaletteIndex::Comment},
{Token::Type::Integer, TextEditor::PaletteIndex::NumericLiteral},
{Token::Type::Identifier, TextEditor::PaletteIndex::Identifier},
{Token::Type::DocComment, TextEditor::PaletteIndex::DocComment}
{Token::Type::Keyword, ui::TextEditor::PaletteIndex::Keyword},
{Token::Type::ValueType, ui::TextEditor::PaletteIndex::BuiltInType},
{Token::Type::Operator, ui::TextEditor::PaletteIndex::Operator},
{Token::Type::Separator, ui::TextEditor::PaletteIndex::Separator},
{Token::Type::String, ui::TextEditor::PaletteIndex::StringLiteral},
{Token::Type::Directive, ui::TextEditor::PaletteIndex::Directive},
{Token::Type::Comment, ui::TextEditor::PaletteIndex::Comment},
{Token::Type::Integer, ui::TextEditor::PaletteIndex::NumericLiteral},
{Token::Type::Identifier, ui::TextEditor::PaletteIndex::Identifier},
{Token::Type::DocComment, ui::TextEditor::PaletteIndex::DocComment}
};
const TextHighlighter::IdentifierTypeColor TextHighlighter::m_identifierTypeColor = {
{Identifier::IdentifierType::Macro, TextEditor::PaletteIndex::PreprocIdentifier},
{Identifier::IdentifierType::UDT, TextEditor::PaletteIndex::UserDefinedType},
{Identifier::IdentifierType::Function, TextEditor::PaletteIndex::Function},
{Identifier::IdentifierType::Attribute, TextEditor::PaletteIndex::Attribute},
{Identifier::IdentifierType::NameSpace, TextEditor::PaletteIndex::NameSpace},
{Identifier::IdentifierType::Typedef, TextEditor::PaletteIndex::TypeDef},
{Identifier::IdentifierType::PatternVariable, TextEditor::PaletteIndex::PatternVariable},
{Identifier::IdentifierType::LocalVariable, TextEditor::PaletteIndex::LocalVariable},
{Identifier::IdentifierType::CalculatedPointer, TextEditor::PaletteIndex::CalculatedPointer},
{Identifier::IdentifierType::TemplateArgument, TextEditor::PaletteIndex::TemplateArgument},
{Identifier::IdentifierType::PlacedVariable, TextEditor::PaletteIndex::PlacedVariable},
{Identifier::IdentifierType::View, TextEditor::PaletteIndex::View},
{Identifier::IdentifierType::FunctionVariable, TextEditor::PaletteIndex::FunctionVariable},
{Identifier::IdentifierType::FunctionParameter, TextEditor::PaletteIndex::FunctionParameter},
{Identifier::IdentifierType::Unknown, TextEditor::PaletteIndex::UnkIdentifier},
{Identifier::IdentifierType::FunctionUnknown, TextEditor::PaletteIndex::UnkIdentifier},
{Identifier::IdentifierType::MemberUnknown, TextEditor::PaletteIndex::UnkIdentifier},
{Identifier::IdentifierType::ScopeResolutionUnknown, TextEditor::PaletteIndex::UnkIdentifier},
{Identifier::IdentifierType::GlobalVariable, TextEditor::PaletteIndex::GlobalVariable},
{Identifier::IdentifierType::Macro, ui::TextEditor::PaletteIndex::PreprocIdentifier},
{Identifier::IdentifierType::UDT, ui::TextEditor::PaletteIndex::UserDefinedType},
{Identifier::IdentifierType::Function, ui::TextEditor::PaletteIndex::Function},
{Identifier::IdentifierType::Attribute, ui::TextEditor::PaletteIndex::Attribute},
{Identifier::IdentifierType::NameSpace, ui::TextEditor::PaletteIndex::NameSpace},
{Identifier::IdentifierType::Typedef, ui::TextEditor::PaletteIndex::TypeDef},
{Identifier::IdentifierType::PatternVariable, ui::TextEditor::PaletteIndex::PatternVariable},
{Identifier::IdentifierType::LocalVariable, ui::TextEditor::PaletteIndex::LocalVariable},
{Identifier::IdentifierType::CalculatedPointer, ui::TextEditor::PaletteIndex::CalculatedPointer},
{Identifier::IdentifierType::TemplateArgument, ui::TextEditor::PaletteIndex::TemplateArgument},
{Identifier::IdentifierType::PlacedVariable, ui::TextEditor::PaletteIndex::PlacedVariable},
{Identifier::IdentifierType::View, ui::TextEditor::PaletteIndex::View},
{Identifier::IdentifierType::FunctionVariable, ui::TextEditor::PaletteIndex::FunctionVariable},
{Identifier::IdentifierType::FunctionParameter, ui::TextEditor::PaletteIndex::FunctionParameter},
{Identifier::IdentifierType::Unknown, ui::TextEditor::PaletteIndex::UnkIdentifier},
{Identifier::IdentifierType::FunctionUnknown, ui::TextEditor::PaletteIndex::UnkIdentifier},
{Identifier::IdentifierType::MemberUnknown, ui::TextEditor::PaletteIndex::UnkIdentifier},
{Identifier::IdentifierType::ScopeResolutionUnknown, ui::TextEditor::PaletteIndex::UnkIdentifier},
{Identifier::IdentifierType::GlobalVariable, ui::TextEditor::PaletteIndex::GlobalVariable},
};
// Second paletteIndex called from processLineTokens to process literals
TextEditor::PaletteIndex TextHighlighter::getPaletteIndex(Literal *literal) {
ui::TextEditor::PaletteIndex TextHighlighter::getPaletteIndex(Literal *literal) {
if (literal->isFloatingPoint() || literal->isSigned() || literal->isUnsigned())
return TextEditor::PaletteIndex::NumericLiteral;
return ui::TextEditor::PaletteIndex::NumericLiteral;
else if (literal->isCharacter() || literal->isBoolean()) return TextEditor::PaletteIndex::CharLiteral;
else if (literal->isCharacter() || literal->isBoolean()) return ui::TextEditor::PaletteIndex::CharLiteral;
else if (literal->isString()) return TextEditor::PaletteIndex::StringLiteral;
else if (literal->isString()) return ui::TextEditor::PaletteIndex::StringLiteral;
else return TextEditor::PaletteIndex::Default;
else return ui::TextEditor::PaletteIndex::Default;
}
// Render the compilation errors using squiggly lines
@@ -1239,13 +1239,13 @@ namespace hex::plugin::builtin {
return wolv::util::combineStrings(lines, "\n");
};
TextEditor::ErrorMarkers errorMarkers;
ui::TextEditor::ErrorMarkers errorMarkers;
if (!m_compileErrors.empty()) {
for (const auto &error: m_compileErrors) {
if (isLocationValid(error.getLocation())) {
auto key = TextEditor::Coordinates(error.getLocation().line, error.getLocation().column);
auto key = ui::TextEditor::Coordinates(error.getLocation().line, error.getLocation().column);
if (!errorMarkers.contains(key) || errorMarkers[key].first < error.getLocation().length)
errorMarkers[key] = std::make_pair(error.getLocation().length, processMessage(error.getMessage()));
@@ -1399,7 +1399,7 @@ namespace hex::plugin::builtin {
else
token = const_cast<Token *>(&m_tokens[tokenId]);
if (token->type == Token::Type::Identifier && (!m_tokenColors.contains(token) || m_tokenColors.at(token) == TextEditor::PaletteIndex::Default || m_tokenColors.at(token) == TextEditor::PaletteIndex::UnkIdentifier))
if (token->type == Token::Type::Identifier && (!m_tokenColors.contains(token) || m_tokenColors.at(token) == ui::TextEditor::PaletteIndex::Default || m_tokenColors.at(token) == ui::TextEditor::PaletteIndex::UnkIdentifier))
m_tokenColors[token] = m_identifierTypeColor.at(type);
else if (!m_tokenColors.contains(token))
m_tokenColors[token] = m_tokenTypeColor.at(token->type);
@@ -1426,11 +1426,11 @@ namespace hex::plugin::builtin {
if (docComment != nullptr && !m_tokenColors.contains(token)) {
if (docComment->singleLine)
m_tokenColors[token] = TextEditor::PaletteIndex::DocComment;
m_tokenColors[token] = ui::TextEditor::PaletteIndex::DocComment;
else if (docComment->global)
m_tokenColors[token] = TextEditor::PaletteIndex::GlobalDocComment;
m_tokenColors[token] = ui::TextEditor::PaletteIndex::GlobalDocComment;
else
m_tokenColors[token] = TextEditor::PaletteIndex::DocBlockComment;
m_tokenColors[token] = ui::TextEditor::PaletteIndex::DocBlockComment;
}
} else if (token->type == Token::Type::Comment) {
auto comment = getValue<Token::Comment>(0);
@@ -1438,9 +1438,9 @@ namespace hex::plugin::builtin {
if (comment != nullptr && !m_tokenColors.contains(token)) {
if (comment->singleLine)
m_tokenColors[token] = TextEditor::PaletteIndex::Comment;
m_tokenColors[token] = ui::TextEditor::PaletteIndex::Comment;
else
m_tokenColors[token] = TextEditor::PaletteIndex::BlockComment;
m_tokenColors[token] = ui::TextEditor::PaletteIndex::BlockComment;
}
} else
setIdentifierColor(tokenId, type);
@@ -1499,7 +1499,7 @@ namespace hex::plugin::builtin {
identifierType = identifier->getType();
std::string variableName = identifier->get();
if (m_tokenColors.contains(token) && (m_tokenColors.at(token) != TextEditor::PaletteIndex::Default && identifierType != IdentifierType::Unknown)) {
if (m_tokenColors.contains(token) && (m_tokenColors.at(token) != ui::TextEditor::PaletteIndex::Default && identifierType != IdentifierType::Unknown)) {
next();
continue;
}

View File

@@ -213,61 +213,61 @@ namespace hex::plugin::builtin {
}
{
const static ThemeManager::ColorMap TextEditorColorMap = {
{ "attribute", u32(TextEditor::PaletteIndex::Attribute) },
{ "background", u32(TextEditor::PaletteIndex::Background) },
{ "breakpoint", u32(TextEditor::PaletteIndex::Breakpoint) },
{ "calculated-pointer", u32(TextEditor::PaletteIndex::CalculatedPointer) },
{ "char-literal", u32(TextEditor::PaletteIndex::CharLiteral) },
{ "comment", u32(TextEditor::PaletteIndex::Comment) },
{ "current-line-edge", u32(TextEditor::PaletteIndex::CurrentLineEdge) },
{ "current-line-fill", u32(TextEditor::PaletteIndex::CurrentLineFill) },
{ "current-line-fill-inactive", u32(TextEditor::PaletteIndex::CurrentLineFillInactive) },
{ "cursor", u32(TextEditor::PaletteIndex::Cursor) },
{ "debug-text", u32(TextEditor::PaletteIndex::DebugText) },
{ "default", u32(TextEditor::PaletteIndex::Default) },
{ "default-text", u32(TextEditor::PaletteIndex::DefaultText) },
{ "doc-block-comment", u32(TextEditor::PaletteIndex::DocBlockComment) },
{ "doc-comment", u32(TextEditor::PaletteIndex::DocComment) },
{ "doc-global-comment", u32(TextEditor::PaletteIndex::GlobalDocComment) },
{ "error-marker", u32(TextEditor::PaletteIndex::ErrorMarker) },
{ "error-text", u32(TextEditor::PaletteIndex::ErrorText) },
{ "function", u32(TextEditor::PaletteIndex::Function) },
{ "function-parameter", u32(TextEditor::PaletteIndex::FunctionParameter) },
{ "function-variable", u32(TextEditor::PaletteIndex::FunctionVariable) },
{ "global-variable", u32(TextEditor::PaletteIndex::GlobalVariable) },
{ "identifier" , u32(TextEditor::PaletteIndex::Identifier) },
{ "keyword", u32(TextEditor::PaletteIndex::Keyword) },
{ "known-identifier", u32(TextEditor::PaletteIndex::BuiltInType) },
{ "line-number", u32(TextEditor::PaletteIndex::LineNumber) },
{ "local-variable", u32(TextEditor::PaletteIndex::LocalVariable) },
{ "multi-line-comment", u32(TextEditor::PaletteIndex::BlockComment) },
{ "namespace", u32(TextEditor::PaletteIndex::NameSpace) },
{ "number", u32(TextEditor::PaletteIndex::NumericLiteral) },
{ "pattern-variable", u32(TextEditor::PaletteIndex::PatternVariable) },
{ "placed-variable", u32(TextEditor::PaletteIndex::PlacedVariable) },
{ "preprocessor", u32(TextEditor::PaletteIndex::Directive) },
{ "preprocessor-deactivated", u32(TextEditor::PaletteIndex::PreprocessorDeactivated) },
{ "preproc-identifier", u32(TextEditor::PaletteIndex::PreprocIdentifier) },
{ "punctuation", u32(TextEditor::PaletteIndex::Operator) },
{ "selection", u32(TextEditor::PaletteIndex::Selection) },
{ "separator", u32(TextEditor::PaletteIndex::Separator) },
{ "string", u32(TextEditor::PaletteIndex::StringLiteral) },
{ "template-variable", u32(TextEditor::PaletteIndex::TemplateArgument) },
{ "typedef", u32(TextEditor::PaletteIndex::TypeDef) },
{ "unknown-identifier", u32(TextEditor::PaletteIndex::UnkIdentifier) },
{ "user-defined-type", u32(TextEditor::PaletteIndex::UserDefinedType) },
{ "view", u32(TextEditor::PaletteIndex::View) },
{ "warning-text", u32(TextEditor::PaletteIndex::WarningText) }
{ "attribute", u32(ui::TextEditor::PaletteIndex::Attribute) },
{ "background", u32(ui::TextEditor::PaletteIndex::Background) },
{ "breakpoint", u32(ui::TextEditor::PaletteIndex::Breakpoint) },
{ "calculated-pointer", u32(ui::TextEditor::PaletteIndex::CalculatedPointer) },
{ "char-literal", u32(ui::TextEditor::PaletteIndex::CharLiteral) },
{ "comment", u32(ui::TextEditor::PaletteIndex::Comment) },
{ "current-line-edge", u32(ui::TextEditor::PaletteIndex::CurrentLineEdge) },
{ "current-line-fill", u32(ui::TextEditor::PaletteIndex::CurrentLineFill) },
{ "current-line-fill-inactive", u32(ui::TextEditor::PaletteIndex::CurrentLineFillInactive) },
{ "cursor", u32(ui::TextEditor::PaletteIndex::Cursor) },
{ "debug-text", u32(ui::TextEditor::PaletteIndex::DebugText) },
{ "default", u32(ui::TextEditor::PaletteIndex::Default) },
{ "default-text", u32(ui::TextEditor::PaletteIndex::DefaultText) },
{ "doc-block-comment", u32(ui::TextEditor::PaletteIndex::DocBlockComment) },
{ "doc-comment", u32(ui::TextEditor::PaletteIndex::DocComment) },
{ "doc-global-comment", u32(ui::TextEditor::PaletteIndex::GlobalDocComment) },
{ "error-marker", u32(ui::TextEditor::PaletteIndex::ErrorMarker) },
{ "error-text", u32(ui::TextEditor::PaletteIndex::ErrorText) },
{ "function", u32(ui::TextEditor::PaletteIndex::Function) },
{ "function-parameter", u32(ui::TextEditor::PaletteIndex::FunctionParameter) },
{ "function-variable", u32(ui::TextEditor::PaletteIndex::FunctionVariable) },
{ "global-variable", u32(ui::TextEditor::PaletteIndex::GlobalVariable) },
{ "identifier" , u32(ui::TextEditor::PaletteIndex::Identifier) },
{ "keyword", u32(ui::TextEditor::PaletteIndex::Keyword) },
{ "known-identifier", u32(ui::TextEditor::PaletteIndex::BuiltInType) },
{ "line-number", u32(ui::TextEditor::PaletteIndex::LineNumber) },
{ "local-variable", u32(ui::TextEditor::PaletteIndex::LocalVariable) },
{ "multi-line-comment", u32(ui::TextEditor::PaletteIndex::BlockComment) },
{ "namespace", u32(ui::TextEditor::PaletteIndex::NameSpace) },
{ "number", u32(ui::TextEditor::PaletteIndex::NumericLiteral) },
{ "pattern-variable", u32(ui::TextEditor::PaletteIndex::PatternVariable) },
{ "placed-variable", u32(ui::TextEditor::PaletteIndex::PlacedVariable) },
{ "preprocessor", u32(ui::TextEditor::PaletteIndex::Directive) },
{ "preprocessor-deactivated", u32(ui::TextEditor::PaletteIndex::PreprocessorDeactivated) },
{ "preproc-identifier", u32(ui::TextEditor::PaletteIndex::PreprocIdentifier) },
{ "punctuation", u32(ui::TextEditor::PaletteIndex::Operator) },
{ "selection", u32(ui::TextEditor::PaletteIndex::Selection) },
{ "separator", u32(ui::TextEditor::PaletteIndex::Separator) },
{ "string", u32(ui::TextEditor::PaletteIndex::StringLiteral) },
{ "template-variable", u32(ui::TextEditor::PaletteIndex::TemplateArgument) },
{ "typedef", u32(ui::TextEditor::PaletteIndex::TypeDef) },
{ "unknown-identifier", u32(ui::TextEditor::PaletteIndex::UnkIdentifier) },
{ "user-defined-type", u32(ui::TextEditor::PaletteIndex::UserDefinedType) },
{ "view", u32(ui::TextEditor::PaletteIndex::View) },
{ "warning-text", u32(ui::TextEditor::PaletteIndex::WarningText) }
};
ThemeManager::addThemeHandler("text-editor", TextEditorColorMap,
[](u32 colorId) -> ImColor {
return TextEditor::getPalette()[colorId];
return ui::TextEditor::getPalette()[colorId];
},
[](u32 colorId, ImColor color) {
auto palette = TextEditor::getPalette();
auto palette = ui::TextEditor::getPalette();
palette[colorId] = color;
TextEditor::setPalette(palette);
ui::TextEditor::setPalette(palette);
}
);
}

View File

@@ -11,15 +11,15 @@ namespace hex::plugin::builtin {
void drawDemangler() {
static std::string mangledName, demangledName, wrappedDemangledName;
static TextEditor outputField = []{
TextEditor editor;
static ui::TextEditor outputField = []{
ui::TextEditor editor;
editor.setReadOnly(true);
editor.setShowLineNumbers(false);
editor.setShowWhitespaces(false);
editor.setShowCursor(false);
editor.setImGuiChildIgnored(true);
auto languageDef = TextEditor::LanguageDefinition::CPlusPlus();
auto languageDef = ui::TextEditor::LanguageDefinition::CPlusPlus();
for (auto &[name, identifier] : languageDef.m_identifiers)
identifier.m_declaration = "";

View File

@@ -44,9 +44,9 @@ namespace hex::plugin::builtin {
using namespace hex::literals;
static const TextEditor::LanguageDefinition &PatternLanguage() {
static const ui::TextEditor::LanguageDefinition &PatternLanguage() {
static bool initialized = false;
static TextEditor::LanguageDefinition langDef;
static ui::TextEditor::LanguageDefinition langDef;
if (!initialized) {
constexpr static std::array keywords = {
"using", "struct", "union", "enum", "bitfield", "be", "le", "if", "else", "match", "false", "true", "this", "parent", "addressof", "sizeof", "typenameof", "while", "for", "fn", "return", "break", "continue", "namespace", "in", "out", "ref", "null", "const", "unsigned", "signed", "try", "catch", "import", "as", "from"
@@ -58,7 +58,7 @@ namespace hex::plugin::builtin {
"u8", "u16", "u24", "u32", "u48", "u64", "u96", "u128", "s8", "s16", "s24", "s32", "s48", "s64", "s96", "s128", "float", "double", "char", "char16", "bool", "padding", "str", "auto"
};
for (const auto name : builtInTypes) {
TextEditor::Identifier id;
ui::TextEditor::Identifier id;
id.m_declaration = "";
langDef.m_identifiers.insert(std::make_pair(std::string(name), id));
}
@@ -66,12 +66,12 @@ namespace hex::plugin::builtin {
"include", "define", "ifdef", "ifndef", "endif", "undef", "pragma", "error"
};
for (const auto name : directives) {
TextEditor::Identifier id;
ui::TextEditor::Identifier id;
id.m_declaration = "";
langDef.m_preprocIdentifiers.insert(std::make_pair(std::string(name), id));
}
langDef.m_tokenize = [](std::string::const_iterator inBegin, std::string::const_iterator inEnd, std::string::const_iterator &outBegin, std::string::const_iterator &outEnd, TextEditor::PaletteIndex &paletteIndex) -> bool {
paletteIndex = TextEditor::PaletteIndex::Max;
langDef.m_tokenize = [](std::string::const_iterator inBegin, std::string::const_iterator inEnd, std::string::const_iterator &outBegin, std::string::const_iterator &outEnd, ui::TextEditor::PaletteIndex &paletteIndex) -> bool {
paletteIndex = ui::TextEditor::PaletteIndex::Max;
while (inBegin < inEnd && isascii(*inBegin) && std::isblank(*inBegin))
++inBegin;
@@ -79,21 +79,21 @@ namespace hex::plugin::builtin {
if (inBegin == inEnd) {
outBegin = inEnd;
outEnd = inEnd;
paletteIndex = TextEditor::PaletteIndex::Default;
} else if (tokenizeCStyleIdentifier(inBegin, inEnd, outBegin, outEnd)) {
paletteIndex = TextEditor::PaletteIndex::Identifier;
} else if (tokenizeCStyleNumber(inBegin, inEnd, outBegin, outEnd)) {
paletteIndex = TextEditor::PaletteIndex::NumericLiteral;
} else if (tokenizeCStyleCharacterLiteral(inBegin, inEnd, outBegin, outEnd)) {
paletteIndex = TextEditor::PaletteIndex::CharLiteral;
} else if (tokenizeCStyleString(inBegin, inEnd, outBegin, outEnd)) {
paletteIndex = TextEditor::PaletteIndex::StringLiteral;
} else if (tokenizeCStyleSeparator(inBegin, inEnd, outBegin, outEnd)) {
paletteIndex = TextEditor::PaletteIndex::Separator;
} else if (tokenizeCStyleOperator(inBegin, inEnd, outBegin, outEnd)) {
paletteIndex = TextEditor::PaletteIndex::Operator;
paletteIndex = ui::TextEditor::PaletteIndex::Default;
} else if (ui::tokenizeCStyleIdentifier(inBegin, inEnd, outBegin, outEnd)) {
paletteIndex = ui::TextEditor::PaletteIndex::Identifier;
} else if (ui::tokenizeCStyleNumber(inBegin, inEnd, outBegin, outEnd)) {
paletteIndex = ui::TextEditor::PaletteIndex::NumericLiteral;
} else if (ui::tokenizeCStyleCharacterLiteral(inBegin, inEnd, outBegin, outEnd)) {
paletteIndex = ui::TextEditor::PaletteIndex::CharLiteral;
} else if (ui::tokenizeCStyleString(inBegin, inEnd, outBegin, outEnd)) {
paletteIndex = ui::TextEditor::PaletteIndex::StringLiteral;
} else if (ui::tokenizeCStyleSeparator(inBegin, inEnd, outBegin, outEnd)) {
paletteIndex = ui::TextEditor::PaletteIndex::Separator;
} else if (ui::tokenizeCStyleOperator(inBegin, inEnd, outBegin, outEnd)) {
paletteIndex = ui::TextEditor::PaletteIndex::Operator;
}
return paletteIndex != TextEditor::PaletteIndex::Max;
return paletteIndex != ui::TextEditor::PaletteIndex::Max;
};
langDef.m_commentStart = "/*";
@@ -116,22 +116,22 @@ namespace hex::plugin::builtin {
return langDef;
}
static const TextEditor::LanguageDefinition &ConsoleLog() {
static const ui::TextEditor::LanguageDefinition &ConsoleLog() {
static bool initialized = false;
static TextEditor::LanguageDefinition langDef;
static ui::TextEditor::LanguageDefinition langDef;
if (!initialized) {
langDef.m_tokenize = [](std::string::const_iterator inBegin, std::string::const_iterator inEnd, std::string::const_iterator &outBegin, std::string::const_iterator &outEnd, TextEditor::PaletteIndex &paletteIndex) -> bool {
langDef.m_tokenize = [](std::string::const_iterator inBegin, std::string::const_iterator inEnd, std::string::const_iterator &outBegin, std::string::const_iterator &outEnd, ui::TextEditor::PaletteIndex &paletteIndex) -> bool {
std::string_view inView(inBegin, inEnd);
if (inView.starts_with("D: "))
paletteIndex = TextEditor::PaletteIndex::DefaultText;
paletteIndex = ui::TextEditor::PaletteIndex::DefaultText;
else if (inView.starts_with("I: "))
paletteIndex = TextEditor::PaletteIndex::DebugText;
paletteIndex = ui::TextEditor::PaletteIndex::DebugText;
else if (inView.starts_with("W: "))
paletteIndex = TextEditor::PaletteIndex::WarningText;
paletteIndex = ui::TextEditor::PaletteIndex::WarningText;
else if (inView.starts_with("E: "))
paletteIndex = TextEditor::PaletteIndex::ErrorText;
paletteIndex = ui::TextEditor::PaletteIndex::ErrorText;
else
paletteIndex = TextEditor::PaletteIndex::Max;
paletteIndex = ui::TextEditor::PaletteIndex::Max;
outBegin = inBegin;
outEnd = inEnd;
@@ -241,7 +241,7 @@ namespace hex::plugin::builtin {
RequestAddVirtualFile::unsubscribe(this);
}
void ViewPatternEditor::setupFindReplace(TextEditor *editor) {
void ViewPatternEditor::setupFindReplace(ui::TextEditor *editor) {
if (editor == nullptr)
return;
if (m_openFindReplacePopUp) {
@@ -280,7 +280,7 @@ namespace hex::plugin::builtin {
}
void ViewPatternEditor::setupGotoLine(TextEditor *editor) {
void ViewPatternEditor::setupGotoLine(ui::TextEditor *editor) {
// Context menu entries that open the goto line popup
if (m_openGotoLinePopUp) {
@@ -614,7 +614,7 @@ namespace hex::plugin::builtin {
}
}
void ViewPatternEditor::drawTextEditorFindReplacePopup(TextEditor *textEditor) {
void ViewPatternEditor::drawTextEditorFindReplacePopup(ui::TextEditor *textEditor) {
auto provider = ImHexApi::Provider::get();
ImGuiWindowFlags popupFlags = ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar;
if (ImGui::BeginPopup("##text_editor_view_find_replace_popup", popupFlags)) {
@@ -624,7 +624,7 @@ namespace hex::plugin::builtin {
static u64 count = 0;
static bool updateCount = false;
static bool canReplace = true;
TextEditor::FindReplaceHandler *findReplaceHandler = textEditor->getFindReplaceHandler();
ui::TextEditor::FindReplaceHandler *findReplaceHandler = textEditor->getFindReplaceHandler();
if (ImGui::IsWindowAppearing()) {
findReplaceHandler->resetMatches();
@@ -940,7 +940,7 @@ namespace hex::plugin::builtin {
}
}
void ViewPatternEditor::drawTextEditorGotoLinePopup(TextEditor *textEditor) {
void ViewPatternEditor::drawTextEditorGotoLinePopup(ui::TextEditor *textEditor) {
auto provider = ImHexApi::Provider::get();
ImGuiWindowFlags popupFlags = ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar;
if (ImGui::BeginPopup("##text_editor_view_goto_line_popup", popupFlags)) {
@@ -1320,7 +1320,7 @@ namespace hex::plugin::builtin {
return wolv::util::combineStrings(lines, "\n");
};
TextEditor::ErrorMarkers errorMarkers;
ui::TextEditor::ErrorMarkers errorMarkers;
if (*m_callStack != nullptr && !(*m_callStack)->empty()) {
for (const auto &frame : **m_callStack | std::views::reverse) {
auto location = frame.node->getLocation();
@@ -1328,13 +1328,13 @@ namespace hex::plugin::builtin {
std::string message = "";
if (m_lastEvaluationError->has_value())
message = processMessage((*m_lastEvaluationError)->message);
auto key = TextEditor::Coordinates(location.line, location.column);
auto key = ui::TextEditor::Coordinates(location.line, location.column);
errorMarkers[key] = std::make_pair(u32(location.length), message);
}
}
} else {
if (m_lastEvaluationError->has_value()) {
auto key = TextEditor::Coordinates((*m_lastEvaluationError)->line, 0);
auto key = ui::TextEditor::Coordinates((*m_lastEvaluationError)->line, 0);
errorMarkers[key] = std::make_pair(0,processMessage((*m_lastEvaluationError)->message));
}
}
@@ -1343,7 +1343,7 @@ namespace hex::plugin::builtin {
for (const auto &error : *m_lastCompileError) {
auto source = error.getLocation().source;
if (source != nullptr && source->mainSource) {
auto key = TextEditor::Coordinates(error.getLocation().line, error.getLocation().column);
auto key = ui::TextEditor::Coordinates(error.getLocation().line, error.getLocation().column);
if (!errorMarkers.contains(key) ||errorMarkers[key].first < error.getLocation().length)
errorMarkers[key] = std::make_pair(u32(error.getLocation().length), processMessage(error.getMessage()));
}
@@ -1527,7 +1527,7 @@ namespace hex::plugin::builtin {
const bool shiftHeld = ImGui::GetIO().KeyShift;
ImGui::ColorButton(pattern->getVariableName().c_str(), ImColor(pattern->getColor()), ImGuiColorEditFlags_AlphaOpaque);
ImGui::SameLine(0, 10);
ImGuiExt::TextFormattedColored(TextEditor::getPalette()[u32(TextEditor::PaletteIndex::BuiltInType)], "{} ", pattern->getFormattedName());
ImGuiExt::TextFormattedColored(ui::TextEditor::getPalette()[u32(ui::TextEditor::PaletteIndex::BuiltInType)], "{} ", pattern->getFormattedName());
ImGui::SameLine(0, 5);
ImGuiExt::TextFormatted("{}", pattern->getDisplayName());
ImGui::SameLine();
@@ -1846,7 +1846,7 @@ namespace hex::plugin::builtin {
if (line == 0)
return;
const TextEditor::Coordinates coords = { int(line) - 1, int(column) };
const ui::TextEditor::Coordinates coords = { int(line) - 1, int(column) };
m_textEditor.get(provider).setCursorPosition(coords);
});
@@ -1900,7 +1900,7 @@ namespace hex::plugin::builtin {
m_envVarEntries.get(provider).emplace_back(0, "", i128(0), EnvVarType::Integer);
m_debuggerDrawer.get(provider) = std::make_unique<ui::PatternDrawer>();
m_cursorPosition.get(provider) = TextEditor::Coordinates(0, 0);
m_cursorPosition.get(provider) = ui::TextEditor::Coordinates(0, 0);
});
EventProviderChanged::subscribe(this, [this](prv::Provider *oldProvider, prv::Provider *newProvider) {
@@ -1919,7 +1919,7 @@ namespace hex::plugin::builtin {
if (newProvider != nullptr) {
m_textEditor.get(newProvider).setText(wolv::util::preprocessText(m_sourceCode.get(newProvider)));
m_textEditor.get(newProvider).setCursorPosition(m_cursorPosition.get(newProvider));
TextEditor::Selection selection = m_selection.get(newProvider);
ui::TextEditor::Selection selection = m_selection.get(newProvider);
m_textEditor.get(newProvider).setSelection(selection);
m_textEditor.get(newProvider).setBreakpoints(m_breakpoints.get(newProvider));
m_consoleEditor.get(newProvider).setText(wolv::util::combineStrings(m_console.get(newProvider), "\n"));
@@ -1976,7 +1976,7 @@ namespace hex::plugin::builtin {
appendEditorText(fmt::format("{0} {0}_array_at_0x{1:02X}[0x{2:02X}] @ 0x{1:02X};", type, selection->getStartAddress(), (selection->getSize() + (size - 1)) / size));
}
TextEditor *ViewPatternEditor::getEditorFromFocusedWindow() {
ui::TextEditor *ViewPatternEditor::getEditorFromFocusedWindow() {
auto provider = ImHexApi::Provider::get();
if (provider != nullptr) {
if (m_focusedSubWindowName.contains(consoleView)) {
@@ -2030,7 +2030,7 @@ namespace hex::plugin::builtin {
/* Find Next */
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.file", "hex.builtin.view.pattern_editor.menu.find_next" }, 1520, AllowWhileTyping + Keys::F3, [this] {
if (auto editor = getEditorFromFocusedWindow(); editor != nullptr) {
TextEditor::FindReplaceHandler *findReplaceHandler = editor->getFindReplaceHandler();
ui::TextEditor::FindReplaceHandler *findReplaceHandler = editor->getFindReplaceHandler();
findReplaceHandler->findMatch(editor, true);
} else {
m_textEditor->getFindReplaceHandler()->findMatch(&*m_textEditor, true);
@@ -2048,7 +2048,7 @@ namespace hex::plugin::builtin {
/* Find Previous */
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.file", "hex.builtin.view.pattern_editor.menu.find_previous" }, 1530, AllowWhileTyping + SHIFT + Keys::F3, [this] {
if (auto editor = getEditorFromFocusedWindow(); editor != nullptr) {
TextEditor::FindReplaceHandler *findReplaceHandler = editor->getFindReplaceHandler();
ui::TextEditor::FindReplaceHandler *findReplaceHandler = editor->getFindReplaceHandler();
findReplaceHandler->findMatch(editor, false);
} else {
m_textEditor->getFindReplaceHandler()->findMatch(&*m_textEditor, false);
@@ -2392,21 +2392,21 @@ namespace hex::plugin::builtin {
ShortcutManager::addShortcut(this, CTRL + SHIFT + Keys::C + AllowWhileTyping, "hex.builtin.view.pattern_editor.shortcut.match_case_toggle", [this] {
if (auto editor = getEditorFromFocusedWindow(); editor != nullptr) {
TextEditor::FindReplaceHandler *findReplaceHandler = editor->getFindReplaceHandler();
ui::TextEditor::FindReplaceHandler *findReplaceHandler = editor->getFindReplaceHandler();
findReplaceHandler->setMatchCase(editor, !findReplaceHandler->getMatchCase());
}
});
ShortcutManager::addShortcut(this, CTRL + SHIFT + Keys::R + AllowWhileTyping, "hex.builtin.view.pattern_editor.shortcut.regex_toggle", [this] {
if (auto editor = getEditorFromFocusedWindow(); editor != nullptr) {
TextEditor::FindReplaceHandler *findReplaceHandler = editor->getFindReplaceHandler();
ui::TextEditor::FindReplaceHandler *findReplaceHandler = editor->getFindReplaceHandler();
findReplaceHandler->setFindRegEx(editor, !findReplaceHandler->getFindRegEx());
}
});
ShortcutManager::addShortcut(this, CTRL + SHIFT + Keys::W + AllowWhileTyping, "hex.builtin.view.pattern_editor.shortcut.whole_word_toggle", [this] {
if (auto editor = getEditorFromFocusedWindow(); editor != nullptr) {
TextEditor::FindReplaceHandler *findReplaceHandler = editor->getFindReplaceHandler();
ui::TextEditor::FindReplaceHandler *findReplaceHandler = editor->getFindReplaceHandler();
findReplaceHandler->setWholeWord(editor, !findReplaceHandler->getWholeWord());
}
});