2020-11-28 00:33:26 +01:00
|
|
|
#include "views/view_bookmarks.hpp"
|
|
|
|
|
2021-01-13 17:28:27 +01:00
|
|
|
#include <hex/providers/provider.hpp>
|
2020-11-30 00:03:12 +01:00
|
|
|
#include "helpers/project_file_handler.hpp"
|
2020-11-28 00:33:26 +01:00
|
|
|
|
|
|
|
#include <cstring>
|
|
|
|
|
|
|
|
namespace hex {
|
|
|
|
|
2021-02-11 23:09:45 +01:00
|
|
|
ViewBookmarks::ViewBookmarks() : View("hex.view.bookmarks.name"_lang) {
|
2021-01-21 10:53:12 +01:00
|
|
|
View::subscribeEvent(Events::AddBookmark, [](auto userData) {
|
|
|
|
auto bookmark = std::any_cast<ImHexApi::Bookmarks::Entry>(userData);
|
2020-11-28 00:33:26 +01:00
|
|
|
bookmark.comment.resize(0xF'FFFF);
|
|
|
|
|
2021-01-14 17:01:44 +01:00
|
|
|
if (bookmark.name.empty()) {
|
|
|
|
bookmark.name.resize(64);
|
|
|
|
std::memset(bookmark.name.data(), 0x00, 64);
|
2021-02-11 23:09:45 +01:00
|
|
|
std::strcpy(bookmark.name.data(), hex::format("hex.view.bookmarks.default_title"_lang,
|
2021-01-14 17:01:44 +01:00
|
|
|
bookmark.region.address,
|
|
|
|
bookmark.region.address + bookmark.region.size - 1).c_str());
|
|
|
|
}
|
2020-11-28 00:33:26 +01:00
|
|
|
|
2020-12-01 02:21:40 +01:00
|
|
|
if (bookmark.comment.empty())
|
|
|
|
std::memset(bookmark.comment.data(), 0x00, 0xF'FFFF);
|
2020-11-28 00:33:26 +01:00
|
|
|
|
2021-01-13 14:11:23 +01:00
|
|
|
bookmark.color = ImGui::GetColorU32(ImGuiCol_Header);
|
|
|
|
|
2021-01-20 20:16:24 +01:00
|
|
|
SharedData::bookmarkEntries.push_back(bookmark);
|
2020-11-30 00:03:12 +01:00
|
|
|
ProjectFile::markDirty();
|
|
|
|
});
|
|
|
|
|
2021-01-21 10:53:12 +01:00
|
|
|
View::subscribeEvent(Events::ProjectFileLoad, [](auto) {
|
2021-01-20 20:16:24 +01:00
|
|
|
SharedData::bookmarkEntries = ProjectFile::getBookmarks();
|
2020-11-30 00:03:12 +01:00
|
|
|
});
|
2021-01-21 10:53:12 +01:00
|
|
|
View::subscribeEvent(Events::ProjectFileStore, [](auto) {
|
2021-01-20 20:16:24 +01:00
|
|
|
ProjectFile::setBookmarks(SharedData::bookmarkEntries);
|
2020-11-28 00:33:26 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
ViewBookmarks::~ViewBookmarks() {
|
|
|
|
View::unsubscribeEvent(Events::AddBookmark);
|
2020-11-30 00:03:12 +01:00
|
|
|
View::unsubscribeEvent(Events::ProjectFileLoad);
|
|
|
|
View::unsubscribeEvent(Events::ProjectFileStore);
|
2020-11-28 00:33:26 +01:00
|
|
|
}
|
|
|
|
|
2020-12-22 18:10:01 +01:00
|
|
|
void ViewBookmarks::drawContent() {
|
2021-02-11 23:09:45 +01:00
|
|
|
if (ImGui::Begin("hex.view.bookmarks.name"_lang, &this->getWindowOpenState())) {
|
2020-11-28 00:33:26 +01:00
|
|
|
if (ImGui::BeginChild("##scrolling")) {
|
|
|
|
|
2021-01-20 20:16:24 +01:00
|
|
|
auto &bookmarks = ImHexApi::Bookmarks::getEntries();
|
|
|
|
|
|
|
|
if (bookmarks.empty()) {
|
2021-01-08 19:34:29 +01:00
|
|
|
ImGui::NewLine();
|
|
|
|
ImGui::Indent(30);
|
2021-02-11 23:09:45 +01:00
|
|
|
ImGui::TextWrapped("%s", static_cast<const char*>("hex.view.bookmarks.no_bookmarks"_lang));
|
2021-01-08 19:34:29 +01:00
|
|
|
}
|
|
|
|
|
2020-11-28 00:33:26 +01:00
|
|
|
u32 id = 1;
|
2021-01-20 20:16:24 +01:00
|
|
|
auto bookmarkToRemove = bookmarks.end();
|
|
|
|
for (auto iter = bookmarks.begin(); iter != bookmarks.end(); iter++) {
|
2021-02-24 21:42:18 +01:00
|
|
|
auto &[region, name, comment, color, locked] = *iter;
|
2021-01-13 14:11:23 +01:00
|
|
|
|
|
|
|
auto headerColor = ImColor(color);
|
|
|
|
auto hoverColor = ImColor(color);
|
|
|
|
hoverColor.Value.w *= 1.3F;
|
2020-11-28 00:33:26 +01:00
|
|
|
|
2021-01-13 16:55:42 +01:00
|
|
|
ImGui::PushID(id);
|
2021-01-13 14:11:23 +01:00
|
|
|
ImGui::PushStyleColor(ImGuiCol_Header, color);
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_HeaderActive, color);
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_HeaderHovered, u32(hoverColor));
|
2020-11-28 00:33:26 +01:00
|
|
|
if (ImGui::CollapsingHeader((std::string(name.data()) + "###" + std::to_string((u64)comment.data())).c_str())) {
|
2021-02-11 23:09:45 +01:00
|
|
|
ImGui::TextUnformatted("hex.view.bookmarks.title.info"_lang);
|
2020-11-28 00:33:26 +01:00
|
|
|
ImGui::Separator();
|
2021-02-11 23:09:45 +01:00
|
|
|
ImGui::Text("hex.view.bookmarks.address"_lang, region.address, region.address + region.size - 1, region.size);
|
2020-11-28 00:33:26 +01:00
|
|
|
|
|
|
|
{
|
|
|
|
u8 bytes[10] = { 0 };
|
2021-01-12 23:28:41 +01:00
|
|
|
(SharedData::currentProvider)->read(region.address, bytes, std::min(region.size, size_t(10)));
|
2020-11-28 00:33:26 +01:00
|
|
|
|
|
|
|
std::string bytesString;
|
|
|
|
for (u8 i = 0; i < std::min(region.size, size_t(10)); i++) {
|
|
|
|
bytesString += hex::format("%02X ", bytes[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (region.size > 10) {
|
|
|
|
bytesString.pop_back();
|
|
|
|
bytesString += "...";
|
|
|
|
}
|
|
|
|
|
2021-02-24 21:24:43 +01:00
|
|
|
ImGui::TextColored(ImColor(0xFF9BC64D), "%s", bytesString.c_str());
|
2020-11-28 00:33:26 +01:00
|
|
|
}
|
2021-02-11 23:09:45 +01:00
|
|
|
if (ImGui::Button("hex.view.bookmarks.button.jump"_lang))
|
2021-01-21 10:53:12 +01:00
|
|
|
View::postEvent(Events::SelectionChangeRequest, region);
|
2020-11-28 00:33:26 +01:00
|
|
|
ImGui::SameLine(0, 15);
|
|
|
|
|
2021-02-11 23:09:45 +01:00
|
|
|
if (ImGui::Button("hex.view.bookmarks.button.remove"_lang))
|
2020-11-28 00:33:26 +01:00
|
|
|
bookmarkToRemove = iter;
|
2021-02-24 21:42:18 +01:00
|
|
|
ImGui::SameLine(0, 15);
|
|
|
|
|
2021-02-25 21:51:12 +01:00
|
|
|
if (locked) {
|
|
|
|
if (ImGui::Button(ICON_FA_LOCK)) locked = false;
|
|
|
|
} else {
|
|
|
|
if (ImGui::Button(ICON_FA_UNLOCK)) locked = true;
|
|
|
|
}
|
2020-11-28 00:33:26 +01:00
|
|
|
|
|
|
|
ImGui::NewLine();
|
2021-02-11 23:09:45 +01:00
|
|
|
ImGui::TextUnformatted("hex.view.bookmarks.header.name"_lang);
|
2020-11-28 00:33:26 +01:00
|
|
|
ImGui::Separator();
|
2021-02-24 21:42:18 +01:00
|
|
|
|
|
|
|
ImGui::ColorEdit4("hex.view.bookmarks.header.color"_lang, (float*)&headerColor.Value, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel | ImGuiColorEditFlags_NoAlpha | (locked ? ImGuiColorEditFlags_NoPicker : ImGuiColorEditFlags_None));
|
2021-01-13 14:11:23 +01:00
|
|
|
color = headerColor;
|
2021-02-24 21:42:18 +01:00
|
|
|
ImGui::SameLine();
|
|
|
|
|
|
|
|
if (locked)
|
|
|
|
ImGui::TextUnformatted(name.data());
|
|
|
|
else
|
|
|
|
ImGui::InputText("##nameInput", name.data(), 64);
|
|
|
|
|
2020-11-28 00:33:26 +01:00
|
|
|
ImGui::NewLine();
|
2021-02-11 23:09:45 +01:00
|
|
|
ImGui::TextUnformatted("hex.view.bookmarks.header.comment"_lang);
|
2020-11-28 00:33:26 +01:00
|
|
|
ImGui::Separator();
|
2021-02-24 21:42:18 +01:00
|
|
|
|
|
|
|
if (locked)
|
|
|
|
ImGui::TextWrapped("%s", comment.data());
|
|
|
|
else
|
|
|
|
ImGui::InputTextMultiline("##commentInput", comment.data(), 0xF'FFFF);
|
|
|
|
|
2020-11-28 00:33:26 +01:00
|
|
|
ImGui::NewLine();
|
|
|
|
|
|
|
|
}
|
2021-01-13 16:55:42 +01:00
|
|
|
ImGui::PopID();
|
2021-01-13 14:11:23 +01:00
|
|
|
ImGui::PopStyleColor(3);
|
2021-01-13 16:55:42 +01:00
|
|
|
id++;
|
2020-11-28 00:33:26 +01:00
|
|
|
}
|
|
|
|
|
2021-01-20 20:16:24 +01:00
|
|
|
if (bookmarkToRemove != bookmarks.end()) {
|
|
|
|
bookmarks.erase(bookmarkToRemove);
|
2020-11-30 00:03:12 +01:00
|
|
|
ProjectFile::markDirty();
|
|
|
|
}
|
2020-11-28 00:33:26 +01:00
|
|
|
|
|
|
|
ImGui::EndChild();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ImGui::End();
|
|
|
|
}
|
|
|
|
|
2020-12-22 18:10:01 +01:00
|
|
|
void ViewBookmarks::drawMenu() {
|
2020-11-28 00:33:26 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|