mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-03-30 05:05:19 -05:00
Improve bookmark API
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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. */
|
||||
|
||||
31
plugins/libimhex/include/hex/api/imhex_api.hpp
Normal file
31
plugins/libimhex/include/hex/api/imhex_api.hpp
Normal 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();
|
||||
};
|
||||
};
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -197,11 +197,4 @@ namespace hex {
|
||||
size_t size;
|
||||
};
|
||||
|
||||
struct Bookmark {
|
||||
Region region;
|
||||
|
||||
std::vector<char> name;
|
||||
std::vector<char> comment;
|
||||
u32 color;
|
||||
};
|
||||
}
|
||||
@@ -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>
|
||||
|
||||
31
plugins/libimhex/source/api/imhex_api.cpp
Normal file
31
plugins/libimhex/source/api/imhex_api.cpp
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user