From 8524e934452f391b023b07892b40a0481fa18e00 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Tue, 11 Jul 2023 00:04:26 +0200 Subject: [PATCH] impr: Display encoding types in header of hex editor Closes #1186 --- lib/libimhex/include/hex/helpers/encoding_file.hpp | 3 +++ lib/libimhex/source/helpers/encoding_file.cpp | 13 +++++++++++++ plugins/builtin/source/ui/hex_editor.cpp | 10 ++++++++-- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/lib/libimhex/include/hex/helpers/encoding_file.hpp b/lib/libimhex/include/hex/helpers/encoding_file.hpp index e650712ab..e534044d5 100644 --- a/lib/libimhex/include/hex/helpers/encoding_file.hpp +++ b/lib/libimhex/include/hex/helpers/encoding_file.hpp @@ -37,11 +37,14 @@ namespace hex { [[nodiscard]] const std::string& getTableContent() const { return this->m_tableContent; } + [[nodiscard]] const std::string& getName() const { return this->m_name; } + private: void parse(const std::string &content); bool m_valid = false; + std::string m_name; std::string m_tableContent; std::unique_ptr, std::string>>> m_mapping; size_t m_longestSequence = 0; diff --git a/lib/libimhex/source/helpers/encoding_file.cpp b/lib/libimhex/source/helpers/encoding_file.cpp index 1a1fc49fc..f8421e198 100644 --- a/lib/libimhex/source/helpers/encoding_file.cpp +++ b/lib/libimhex/source/helpers/encoding_file.cpp @@ -16,6 +16,7 @@ namespace hex { this->m_tableContent = other.m_tableContent; this->m_longestSequence = other.m_longestSequence; this->m_valid = other.m_valid; + this->m_name = other.m_name; } EncodingFile::EncodingFile(EncodingFile &&other) { @@ -23,6 +24,7 @@ namespace hex { this->m_tableContent = std::move(other.m_tableContent); this->m_longestSequence = other.m_longestSequence; this->m_valid = other.m_valid; + this->m_name = std::move(other.m_name); } EncodingFile::EncodingFile(Type type, const std::fs::path &path) : EncodingFile() { @@ -35,6 +37,14 @@ namespace hex { return; } + { + this->m_name = path.stem().string(); + this->m_name = wolv::util::replaceStrings(this->m_name, "_", " "); + + if (!this->m_name.empty()) + this->m_name[0] = std::toupper(this->m_name[0]); + } + this->m_valid = true; } @@ -47,6 +57,7 @@ namespace hex { return; } + this->m_name = "Unknown"; this->m_valid = true; } @@ -56,6 +67,7 @@ namespace hex { this->m_tableContent = other.m_tableContent; this->m_longestSequence = other.m_longestSequence; this->m_valid = other.m_valid; + this->m_name = other.m_name; return *this; } @@ -65,6 +77,7 @@ namespace hex { this->m_tableContent = std::move(other.m_tableContent); this->m_longestSequence = other.m_longestSequence; this->m_valid = other.m_valid; + this->m_name = std::move(other.m_name); return *this; } diff --git a/plugins/builtin/source/ui/hex_editor.cpp b/plugins/builtin/source/ui/hex_editor.cpp index eac99b05a..18357f32c 100644 --- a/plugins/builtin/source/ui/hex_editor.cpp +++ b/plugins/builtin/source/ui/hex_editor.cpp @@ -285,11 +285,17 @@ namespace hex::plugin::builtin::ui { // ASCII column ImGui::TableSetupColumn(""); - ImGui::TableSetupColumn("", ImGuiTableColumnFlags_WidthFixed, this->m_showAscii ? (CharacterSize.x + this->m_characterCellPadding * 1_scaled) * this->m_bytesPerRow : 0); + ImGui::TableSetupColumn("hex.builtin.common.encoding.ascii"_lang, ImGuiTableColumnFlags_WidthFixed, this->m_showAscii ? (CharacterSize.x + this->m_characterCellPadding * 1_scaled) * this->m_bytesPerRow : 0); // Custom encoding column ImGui::TableSetupColumn(""); - ImGui::TableSetupColumn("", ImGuiTableColumnFlags_WidthStretch); + { + if (this->m_currCustomEncoding.has_value()) { + ImGui::TableSetupColumn(this->m_currCustomEncoding->getName().c_str(), ImGuiTableColumnFlags_WidthStretch); + } else { + ImGui::TableSetupColumn("", ImGuiTableColumnFlags_WidthStretch); + } + } ImGui::TableNextRow(); for (i32 i = 0; i < ImGui::TableGetColumnCount(); i++) {