Added data inspector to content registry

This commit is contained in:
WerWolv
2021-01-13 01:24:27 +01:00
parent ac76e47b94
commit d15307a237
7 changed files with 229 additions and 165 deletions

View File

@@ -108,10 +108,36 @@ namespace hex {
/* Tools Registry. Allows adding new entries to the tools window */
struct Tools {
Tools() = delete;
static void add(const std::function<void()> &function);
static std::vector<std::function<void()>>& getEntries();
};
/* Data Inspector Registry. Allows adding of new types to the data inspector */
struct DataInspector {
DataInspector() = delete;
enum class NumberDisplayStyle {
Decimal,
Hexadecimal,
Octal
};
using DisplayFunction = std::function<void()>;
using GeneratorFunction = std::function<DisplayFunction(const std::vector<u8>&, std::endian, NumberDisplayStyle)>;
struct Entry {
std::string name;
size_t requiredSize;
GeneratorFunction generatorFunction;
};
static void add(std::string_view name, size_t requiredSize, GeneratorFunction function);
static std::vector<Entry>& getEntries();
};
};
}

View File

@@ -51,7 +51,8 @@ namespace hex {
static std::vector<ContentRegistry::CommandPaletteCommands::Entry> commandPaletteCommands;
static std::map<std::string, ContentRegistry::PatternLanguageFunctions::Function> patternLanguageFunctions;
static std::vector<View*> views;
static std::vector<std::function<void()>> tools;
static std::vector<std::function<void()>> toolsEntries;
static std::vector<ContentRegistry::DataInspector::Entry> dataInspectorEntries;
static int mainArgc;
static char **mainArgv;

View File

@@ -9,10 +9,7 @@
#include <helpers/shared_data.hpp>
#include <helpers/content_registry.hpp>
#define IMHEX_PLUGIN_SETUP namespace hex::plugin { void setup(); } \
namespace hex::plugin::internal { \
void initializePlugin() { \
hex::plugin::setup(); \
} \
} \
void hex::plugin::setup()
#define IMHEX_PLUGIN_SETUP namespace hex::plugin::internal { \
void initializePlugin(); \
} \
void hex::plugin::internal::initializePlugin()

View File

@@ -107,7 +107,17 @@ namespace hex {
}
std::vector<std::function<void()>>& ContentRegistry::Tools::getEntries() {
return SharedData::tools;
return SharedData::toolsEntries;
}
/* Data Inspector */
void ContentRegistry::DataInspector::add(std::string_view name, size_t requiredSize, ContentRegistry::DataInspector::GeneratorFunction function) {
getEntries().push_back(Entry{ name.data(), requiredSize, function });
}
std::vector<ContentRegistry::DataInspector::Entry>& ContentRegistry::DataInspector::getEntries() {
return SharedData::dataInspectorEntries;
}
}

View File

@@ -12,7 +12,8 @@ namespace hex {
std::vector<ContentRegistry::CommandPaletteCommands::Entry> SharedData::commandPaletteCommands;
std::map<std::string, ContentRegistry::PatternLanguageFunctions::Function> SharedData::patternLanguageFunctions;
std::vector<View*> SharedData::views;
std::vector<std::function<void()>> SharedData::tools;
std::vector<std::function<void()>> SharedData::toolsEntries;
std::vector<ContentRegistry::DataInspector::Entry> SharedData::dataInspectorEntries;
int SharedData::mainArgc;
char **SharedData::mainArgv;