Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Texteditor code to ImHex standards. #1891

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
536 changes: 268 additions & 268 deletions lib/third_party/imgui/ColorTextEditor/include/TextEditor.h

Large diffs are not rendered by default.

2,657 changes: 1,334 additions & 1,323 deletions lib/third_party/imgui/ColorTextEditor/source/TextEditor.cpp

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ namespace hex::plugin::builtin {
fs::DialogMode::Save, { {"Pattern", "hexpat"} },
[this](const auto &path) {
wolv::io::File file(path, wolv::io::File::Mode::Create);
file.writeString(wolv::util::trim(m_textEditor.GetText()));
file.writeString(wolv::util::trim(m_textEditor.getText()));
}
);
};
Expand Down
6 changes: 3 additions & 3 deletions plugins/builtin/source/content/themes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,12 @@ namespace hex::plugin::builtin {

ThemeManager::addThemeHandler("text-editor", TextEditorColorMap,
[](u32 colorId) -> ImColor {
return TextEditor::GetPalette()[colorId];
return TextEditor::getPalette()[colorId];
},
[](u32 colorId, ImColor color) {
auto palette = TextEditor::GetPalette();
auto palette = TextEditor::getPalette();
palette[colorId] = color;
TextEditor::SetPalette(palette);
TextEditor::setPalette(palette);
}
);
}
Expand Down
26 changes: 13 additions & 13 deletions plugins/builtin/source/content/tools/demangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@
namespace hex::plugin::builtin {

void drawDemangler() {
static std::string mangledName, demangledName, wrappedDemangledName;
static TextEditor outputField = []{
TextEditor editor;
editor.SetReadOnly(true);
editor.SetShowLineNumbers(false);
editor.SetShowWhitespaces(false);
editor.SetShowCursor(false);
editor.SetImGuiChildIgnored(true);
editor.setReadOnly(true);
editor.setShowLineNumbers(false);
editor.setShowWhitespaces(false);
editor.setShowCursor(false);
editor.setImGuiChildIgnored(true);

auto languageDef = TextEditor::LanguageDefinition::CPlusPlus();
for (auto &[name, identifier] : languageDef.mIdentifiers)
identifier.mDeclaration = "";
for (auto &[name, identifier] : languageDef.m_identifiers)
identifier.m_declaration = "";

editor.SetLanguageDefinition(languageDef);
editor.setLanguageDefinition(languageDef);

return editor;
}();
static float prevWindowWidth;

static float prevWindowWidth;
static std::string mangledName,demangledName;
if (ImGui::InputTextWithHint("hex.builtin.tools.demangler.mangled"_lang, "Itanium, MSVC, Dlang & Rust", mangledName)) {
demangledName = hex::plugin::builtin::demangle(mangledName);

Expand All @@ -42,20 +42,20 @@ namespace hex::plugin::builtin {

const auto windowWidth = ImGui::GetContentRegionAvail().x;
if (prevWindowWidth != windowWidth) {
wrappedDemangledName = wolv::util::wrapMonospacedString(
static std::string wrappedDemangledName = wolv::util::wrapMonospacedString(
demangledName,
ImGui::CalcTextSize("M").x,
ImGui::GetContentRegionAvail().x - ImGui::GetStyle().ScrollbarSize - ImGui::GetStyle().FrameBorderSize
);

outputField.SetText(wrappedDemangledName);
outputField.setText(wrappedDemangledName);
prevWindowWidth = windowWidth;
}

ImGuiExt::Header("hex.builtin.tools.demangler.demangled"_lang);

if (ImGui::BeginChild("Demangled", ImVec2(ImGui::GetContentRegionAvail().x, 150_scaled), true, ImGuiWindowFlags_NoMove)) {
outputField.Render("Demangled", ImVec2(ImGui::GetContentRegionAvail().x, 150_scaled), true);
outputField.render("Demangled", ImVec2(ImGui::GetContentRegionAvail().x, 150_scaled), true);
}
ImGui::EndChild();
}
Expand Down
50 changes: 25 additions & 25 deletions plugins/builtin/source/content/tools/http_requests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,29 @@ namespace hex::plugin::builtin {
static std::future<HttpRequest::Result<std::string>> response;

AT_FIRST_TIME {
responseEditor.SetReadOnly(true);
responseEditor.SetShowLineNumbers(false);
responseEditor.SetShowWhitespaces(true);
responseEditor.SetShowCursor(false);
responseEditor.setReadOnly(true);
responseEditor.setShowLineNumbers(false);
responseEditor.setShowWhitespaces(true);
responseEditor.setShowCursor(false);

auto languageDef = TextEditor::LanguageDefinition();
for (auto &[name, identifier] : languageDef.mIdentifiers)
identifier.mDeclaration = "";
languageDef.mCaseSensitive = false;
languageDef.mAutoIndentation = false;
languageDef.mCommentStart = "";
languageDef.mCommentEnd = "";
languageDef.mSingleLineComment = "";
languageDef.mDocComment = "";
languageDef.mGlobalDocComment = "";

responseEditor.SetLanguageDefinition(languageDef);

bodyEditor.SetShowLineNumbers(true);
bodyEditor.SetShowWhitespaces(true);
bodyEditor.SetShowCursor(true);

bodyEditor.SetLanguageDefinition(languageDef);
for (auto &[name, identifier] : languageDef.m_identifiers)
identifier.m_declaration = "";
languageDef.m_caseSensitive = false;
languageDef.m_autoIndentation = false;
languageDef.m_commentStart = "";
languageDef.m_commentEnd = "";
languageDef.m_singleLineComment = "";
languageDef.m_docComment = "";
languageDef.m_globalDocComment = "";

responseEditor.setLanguageDefinition(languageDef);

bodyEditor.setShowLineNumbers(true);
bodyEditor.setShowWhitespaces(true);
bodyEditor.setShowCursor(true);

bodyEditor.setLanguageDefinition(languageDef);
};

constexpr static auto Methods = std::array{
Expand Down Expand Up @@ -130,7 +130,7 @@ namespace hex::plugin::builtin {
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("hex.builtin.tools.http_requests.body"_lang)) {
bodyEditor.Render("Body", ImGui::GetContentRegionAvail(), true);
bodyEditor.render("Body", ImGui::GetContentRegionAvail(), true);
ImGui::EndTabItem();
}

Expand All @@ -140,16 +140,16 @@ namespace hex::plugin::builtin {
ImGui::EndChild();

ImGuiExt::Header("hex.builtin.tools.http_requests.response"_lang);
responseEditor.Render("Response", ImVec2(ImGui::GetContentRegionAvail().x, 150_scaled), true);
responseEditor.render("Response", ImVec2(ImGui::GetContentRegionAvail().x, 150_scaled), true);

if (response.valid() && response.wait_for(0s) != std::future_status::timeout) {
const auto result = response.get();
const auto data = result.getData();

if (const auto status = result.getStatusCode(); status != 0)
responseEditor.SetText("Status: " + std::to_string(result.getStatusCode()) + "\n\n" + data);
responseEditor.setText("Status: " + std::to_string(result.getStatusCode()) + "\n\n" + data);
else
responseEditor.SetText("Status: No Response");
responseEditor.setText("Status: No Response");
}

}
Expand Down
20 changes: 10 additions & 10 deletions plugins/builtin/source/content/views/view_bookmarks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,17 +490,17 @@ namespace hex::plugin::builtin {
}

// Draw comment if the bookmark is locked or an input text box if it's unlocked
editor.SetReadOnly(locked);
editor.SetShowLineNumbers(!locked);
editor.SetShowCursor(!locked);
editor.SetShowWhitespaces(false);
editor.setReadOnly(locked);
editor.setShowLineNumbers(!locked);
editor.setShowCursor(!locked);
editor.setShowWhitespaces(false);

if (!locked || (locked && !comment.empty())) {
if (!locked || !comment.empty()) {
ImGuiExt::Header("hex.builtin.view.bookmarks.header.comment"_lang);
editor.Render("##comment", ImVec2(ImGui::GetContentRegionAvail().x, 150_scaled), true);
editor.render("##comment", ImVec2(ImGui::GetContentRegionAvail().x, 150_scaled), true);

if (editor.IsTextChanged())
comment = editor.GetText();
if (editor.isTextChanged())
comment = editor.getText();
}

ImGui::NewLine();
Expand Down Expand Up @@ -533,7 +533,7 @@ namespace hex::plugin::builtin {
continue;

TextEditor editor;
editor.SetText(bookmark["comment"]);
editor.setText(bookmark["comment"]);
m_bookmarks.get(provider).push_back({
{
.region = { region["address"], region["size"] },
Expand All @@ -560,7 +560,7 @@ namespace hex::plugin::builtin {
for (const auto &[bookmark, editor] : m_bookmarks.get(provider)) {
json["bookmarks"][index] = {
{ "name", bookmark.name },
{ "comment", editor.GetText() },
{ "comment", editor.getText() },
{ "color", bookmark.color },
{ "region", {
{ "address", bookmark.region.address },
Expand Down
Loading
Loading