Improve bookmark API

This commit is contained in:
WerWolv
2021-01-20 20:16:24 +01:00
parent be738eb5e7
commit b2648afc7b
17 changed files with 108 additions and 67 deletions

View File

@@ -17,6 +17,7 @@ set(CMAKE_SHARED_LIBRARY_PREFIX "")
add_library(libimhex SHARED
source/api/event.cpp
source/api/imhex_api.cpp
source/api/content_registry.cpp
source/helpers/utils.cpp
source/helpers/shared_data.cpp

View File

@@ -22,8 +22,7 @@ namespace hex {
It allows you to add/register new content that will be picked up and used by the ImHex core or by other
plugins when needed.
*/
class ContentRegistry {
public:
struct ContentRegistry {
ContentRegistry() = delete;
/* Settings Registry. Allows adding of new entries into the ImHex preferences window. */

View File

@@ -0,0 +1,31 @@
#pragma once
#include <hex.hpp>
#include <hex/helpers/utils.hpp>
#include <list>
namespace hex {
struct ImHexApi {
ImHexApi() = delete;
struct Bookmarks {
Bookmarks() = delete;
struct Entry {
Region region;
std::vector<char> name;
std::vector<char> comment;
u32 color;
};
static void add(Region region, std::string_view name, std::string_view comment, u32 color = 0x00000000);
static void add(u64 addr, size_t size, std::string_view name, std::string_view comment, u32 color = 0x00000000);
static std::list<Entry>& getEntries();
};
};
}

View File

@@ -2,10 +2,12 @@
#include <any>
#include <functional>
#include <vector>
#include <list>
#include <map>
#include <vector>
#include <hex/api/content_registry.hpp>
#include <hex/api/imhex_api.hpp>
#include <hex/api/event.hpp>
#include <hex/views/view.hpp>
@@ -55,6 +57,7 @@ namespace hex {
static std::vector<ContentRegistry::DataInspector::Entry> dataInspectorEntries;
static u32 patternPaletteOffset;
static std::string errorPopupMessage;
static std::list<ImHexApi::Bookmarks::Entry> bookmarkEntries;
static int mainArgc;
static char **mainArgv;

View File

@@ -197,11 +197,4 @@ namespace hex {
size_t size;
};
struct Bookmark {
Region region;
std::vector<char> name;
std::vector<char> comment;
u32 color;
};
}

View File

@@ -4,6 +4,7 @@
#include <imgui.h>
#include <hex.hpp>
#include <hex/api/imhex_api.hpp>
#include <hex/api/content_registry.hpp>
#include <hex/views/view.hpp>
#include <hex/providers/provider.hpp>

View File

@@ -0,0 +1,31 @@
#include <hex/api/imhex_api.hpp>
#include <hex/api/event.hpp>
#include <hex/helpers/shared_data.hpp>
namespace hex {
void ImHexApi::Bookmarks::add(Region region, std::string_view name, std::string_view comment, u32 color) {
Entry entry;
entry.region = region;
entry.name.reserve(name.length());
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.color = color;
EventManager::post(Events::AddBookmark, &entry);
}
void ImHexApi::Bookmarks::add(u64 addr, size_t size, std::string_view name, std::string_view comment, u32 color) {
Bookmarks::add(Region{addr, size}, name, comment, color);
}
std::list<ImHexApi::Bookmarks::Entry>& ImHexApi::Bookmarks::getEntries() {
return SharedData::bookmarkEntries;
}
}

View File

@@ -16,6 +16,7 @@ namespace hex {
std::vector<ContentRegistry::DataInspector::Entry> SharedData::dataInspectorEntries;
u32 SharedData::patternPaletteOffset;
std::string SharedData::errorPopupMessage;
std::list<ImHexApi::Bookmarks::Entry> SharedData::bookmarkEntries;
int SharedData::mainArgc;
char **SharedData::mainArgv;