From 4a1de5d1cb11cbab8f779996c789a4daa2784f83 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Wed, 24 Feb 2021 21:42:18 +0100 Subject: [PATCH] bookmarks: Added ability to lock bookmarks --- .../libimhex/include/hex/api/imhex_api.hpp | 1 + plugins/libimhex/source/api/imhex_api.cpp | 1 + source/helpers/project_file_handler.cpp | 3 ++- source/views/view_bookmarks.cpp | 24 +++++++++++++++---- source/views/view_hexeditor.cpp | 4 ++-- 5 files changed, 25 insertions(+), 8 deletions(-) diff --git a/plugins/libimhex/include/hex/api/imhex_api.hpp b/plugins/libimhex/include/hex/api/imhex_api.hpp index 524b5b71a..01a4f2779 100644 --- a/plugins/libimhex/include/hex/api/imhex_api.hpp +++ b/plugins/libimhex/include/hex/api/imhex_api.hpp @@ -19,6 +19,7 @@ namespace hex { std::vector name; std::vector comment; u32 color; + bool locked; }; static void add(Region region, std::string_view name, std::string_view comment, u32 color = 0x00000000); diff --git a/plugins/libimhex/source/api/imhex_api.cpp b/plugins/libimhex/source/api/imhex_api.cpp index 0aa1ab103..9462e9ea2 100644 --- a/plugins/libimhex/source/api/imhex_api.cpp +++ b/plugins/libimhex/source/api/imhex_api.cpp @@ -14,6 +14,7 @@ namespace hex { entry.comment.reserve(comment.length()); std::copy(name.begin(), name.end(), std::back_inserter(entry.name)); std::copy(comment.begin(), comment.end(), std::back_inserter(entry.comment)); + entry.locked = false; entry.color = color; diff --git a/source/helpers/project_file_handler.cpp b/source/helpers/project_file_handler.cpp index ae5d43469..049962cca 100644 --- a/source/helpers/project_file_handler.cpp +++ b/source/helpers/project_file_handler.cpp @@ -8,7 +8,7 @@ using json = nlohmann::json; namespace hex { void to_json(json& j, const ImHexApi::Bookmarks::Entry& b) { - j = json{ { "address", b.region.address }, { "size", b.region.size }, { "name", b.name.data() }, { "comment", b.comment.data() } }; + j = json{ { "address", b.region.address }, { "size", b.region.size }, { "name", b.name.data() }, { "comment", b.comment.data() }, { "locked", b.locked } }; } void from_json(const json& j, ImHexApi::Bookmarks::Entry& b) { @@ -18,6 +18,7 @@ namespace hex { j.at("size").get_to(b.region.size); j.at("name").get_to(name); j.at("comment").get_to(comment); + j.at("locked").get_to(b.locked); std::copy(name.begin(), name.end(), std::back_inserter(b.name)); std::copy(comment.begin(), comment.end(), std::back_inserter(b.comment)); diff --git a/source/views/view_bookmarks.cpp b/source/views/view_bookmarks.cpp index 79262bafd..30822b612 100644 --- a/source/views/view_bookmarks.cpp +++ b/source/views/view_bookmarks.cpp @@ -58,7 +58,7 @@ namespace hex { u32 id = 1; auto bookmarkToRemove = bookmarks.end(); for (auto iter = bookmarks.begin(); iter != bookmarks.end(); iter++) { - auto &[region, name, comment, color] = *iter; + auto &[region, name, comment, color, locked] = *iter; auto headerColor = ImColor(color); auto hoverColor = ImColor(color); @@ -95,18 +95,32 @@ namespace hex { if (ImGui::Button("hex.view.bookmarks.button.remove"_lang)) bookmarkToRemove = iter; + ImGui::SameLine(0, 15); + + ImGui::Checkbox("Locked", &locked); ImGui::NewLine(); ImGui::TextUnformatted("hex.view.bookmarks.header.name"_lang); ImGui::Separator(); - ImGui::InputText("##nameInput", name.data(), 64); - ImGui::SameLine(); - ImGui::ColorEdit4("hex.view.bookmarks.header.color"_lang, (float*)&headerColor.Value, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel | ImGuiColorEditFlags_NoAlpha); + + ImGui::ColorEdit4("hex.view.bookmarks.header.color"_lang, (float*)&headerColor.Value, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel | ImGuiColorEditFlags_NoAlpha | (locked ? ImGuiColorEditFlags_NoPicker : ImGuiColorEditFlags_None)); color = headerColor; + ImGui::SameLine(); + + if (locked) + ImGui::TextUnformatted(name.data()); + else + ImGui::InputText("##nameInput", name.data(), 64); + ImGui::NewLine(); ImGui::TextUnformatted("hex.view.bookmarks.header.comment"_lang); ImGui::Separator(); - ImGui::InputTextMultiline("##colorInput", comment.data(), 0xF'FFFF); + + if (locked) + ImGui::TextWrapped("%s", comment.data()); + else + ImGui::InputTextMultiline("##commentInput", comment.data(), 0xF'FFFF); + ImGui::NewLine(); } diff --git a/source/views/view_hexeditor.cpp b/source/views/view_hexeditor.cpp index 784e4c8ce..742ede4a9 100644 --- a/source/views/view_hexeditor.cpp +++ b/source/views/view_hexeditor.cpp @@ -56,7 +56,7 @@ namespace hex { off += SharedData::currentProvider->getBaseAddress(); - for (const auto &[region, name, comment, color] : ImHexApi::Bookmarks::getEntries()) { + for (const auto &[region, name, comment, color, locked] : ImHexApi::Bookmarks::getEntries()) { if (off >= region.address && off < (region.address + region.size)) currColor = (color & 0x00FFFFFF) | 0x80000000; if ((off - 1) >= region.address && (off - 1) < (region.address + region.size)) @@ -90,7 +90,7 @@ namespace hex { off += SharedData::currentProvider->getBaseAddress(); - for (const auto &[region, name, comment, color] : ImHexApi::Bookmarks::getEntries()) { + for (const auto &[region, name, comment, color, locked] : ImHexApi::Bookmarks::getEntries()) { if (off >= region.address && off < (region.address + region.size)) { if (!tooltipShown) { ImGui::BeginTooltip();