2020-11-28 00:33:26 +01:00
|
|
|
#include "views/view_bookmarks.hpp"
|
|
|
|
|
|
|
|
#include "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 {
|
|
|
|
|
2020-12-27 15:39:06 +01:00
|
|
|
ViewBookmarks::ViewBookmarks() : View("Bookmarks") {
|
2020-11-28 00:33:26 +01:00
|
|
|
View::subscribeEvent(Events::AddBookmark, [this](const void *userData) {
|
2020-12-01 02:21:40 +01:00
|
|
|
Bookmark bookmark = *reinterpret_cast<const Bookmark*>(userData);
|
2020-11-28 00:33:26 +01:00
|
|
|
bookmark.name.resize(64);
|
|
|
|
bookmark.comment.resize(0xF'FFFF);
|
|
|
|
|
2020-12-01 02:21:40 +01:00
|
|
|
if (bookmark.name.empty()) {
|
|
|
|
std::memset(bookmark.name.data(), 0x00, 64);
|
|
|
|
std::strcpy(bookmark.name.data(), ("Bookmark " + std::to_string(this->m_bookmarks.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
|
|
|
|
|
|
|
this->m_bookmarks.push_back(bookmark);
|
2020-11-30 00:03:12 +01:00
|
|
|
ProjectFile::markDirty();
|
|
|
|
});
|
|
|
|
|
|
|
|
View::subscribeEvent(Events::ProjectFileLoad, [this](const void*) {
|
|
|
|
this->m_bookmarks = ProjectFile::getBookmarks();
|
|
|
|
});
|
|
|
|
View::subscribeEvent(Events::ProjectFileStore, [this](const void*) {
|
|
|
|
ProjectFile::setBookmarks(this->m_bookmarks);
|
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() {
|
2020-11-28 00:33:26 +01:00
|
|
|
if (ImGui::Begin("Bookmarks", &this->getWindowOpenState())) {
|
|
|
|
if (ImGui::BeginChild("##scrolling")) {
|
|
|
|
|
2021-01-08 19:34:29 +01:00
|
|
|
if (this->m_bookmarks.empty()) {
|
|
|
|
ImGui::NewLine();
|
|
|
|
ImGui::Indent(30);
|
|
|
|
ImGui::TextWrapped("No bookmarks created yet. Add one with Edit -> Add Bookmark");
|
|
|
|
}
|
|
|
|
|
2020-11-28 00:33:26 +01:00
|
|
|
u32 id = 1;
|
|
|
|
std::list<Bookmark>::const_iterator bookmarkToRemove = this->m_bookmarks.end();
|
|
|
|
for (auto iter = this->m_bookmarks.begin(); iter != this->m_bookmarks.end(); iter++) {
|
|
|
|
auto &[region, name, comment] = *iter;
|
|
|
|
|
|
|
|
if (ImGui::CollapsingHeader((std::string(name.data()) + "###" + std::to_string((u64)comment.data())).c_str())) {
|
|
|
|
ImGui::TextUnformatted("Information");
|
|
|
|
ImGui::Separator();
|
|
|
|
ImGui::Text("0x%08lx : 0x%08lx (%lu bytes)", region.address, region.address + region.size - 1, region.size);
|
|
|
|
|
|
|
|
{
|
|
|
|
u8 bytes[10] = { 0 };
|
2021-01-04 00:19:56 +01:00
|
|
|
(*SharedData::get().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 += "...";
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::TextColored(ImColor(0xFF9BC64D), bytesString.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ImGui::Button("Jump to"))
|
|
|
|
View::postEvent(Events::SelectionChangeRequest, ®ion);
|
|
|
|
|
|
|
|
ImGui::SameLine(0, 15);
|
|
|
|
|
|
|
|
if (ImGui::Button("Remove"))
|
|
|
|
bookmarkToRemove = iter;
|
|
|
|
|
|
|
|
ImGui::NewLine();
|
|
|
|
ImGui::TextUnformatted("Name");
|
|
|
|
ImGui::Separator();
|
|
|
|
ImGui::PushID(id);
|
|
|
|
ImGui::InputText("##nolabel", name.data(), 64);
|
|
|
|
ImGui::PopID();
|
|
|
|
ImGui::NewLine();
|
|
|
|
ImGui::TextUnformatted("Comment");
|
|
|
|
ImGui::Separator();
|
|
|
|
ImGui::PushID(id + 1);
|
|
|
|
ImGui::InputTextMultiline("##nolabel", comment.data(), 0xF'FFFF);
|
|
|
|
ImGui::PopID();
|
|
|
|
ImGui::NewLine();
|
|
|
|
|
|
|
|
id += 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-30 00:03:12 +01:00
|
|
|
if (bookmarkToRemove != this->m_bookmarks.end()) {
|
2020-11-28 00:33:26 +01:00
|
|
|
this->m_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
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|