api: Added api function to create pattern

This commit is contained in:
WerWolv
2022-08-06 22:29:59 +02:00
parent 88f8bb9848
commit 69d000488e
5 changed files with 12 additions and 4 deletions

View File

@@ -135,6 +135,8 @@ namespace hex {
void remove(prv::Provider *provider);
prv::Provider* createProvider(const std::string &unlocalizedName);
}
namespace Tasks {

View File

@@ -271,6 +271,13 @@ namespace hex {
delete provider;
}
prv::Provider* createProvider(const std::string &unlocalizedName) {
prv::Provider* result = nullptr;
EventManager::post<RequestCreateProvider>(unlocalizedName, &result);
return result;
}
}

View File

@@ -15,8 +15,7 @@
namespace hex::plugin::builtin {
static void openFile(const std::fs::path &path) {
hex::prv::Provider *provider = nullptr;
EventManager::post<RequestCreateProvider>("hex.builtin.provider.file", &provider);
auto provider = ImHexApi::Provider::createProvider("hex.builtin.provider.file");
if (auto fileProvider = dynamic_cast<prv::FileProvider *>(provider)) {
fileProvider->setPath(path);

View File

@@ -32,7 +32,7 @@ namespace hex::plugin::builtin {
for (const auto &unlocalizedProviderName : ContentRegistry::Provider::getEntries()) {
if (ImGui::MenuItem(LangEntry(unlocalizedProviderName))) {
EventManager::post<RequestCreateProvider>(unlocalizedProviderName, nullptr);
ImHexApi::Provider::createProvider(unlocalizedProviderName);
}
}

View File

@@ -144,7 +144,7 @@ namespace hex::plugin::builtin {
for (const auto &unlocalizedProviderName : ContentRegistry::Provider::getEntries()) {
if (ImGui::Hyperlink(LangEntry(unlocalizedProviderName))) {
EventManager::post<RequestCreateProvider>(unlocalizedProviderName, nullptr);
ImHexApi::Provider::createProvider(unlocalizedProviderName);
ImGui::CloseCurrentPopup();
}
}