diff --git a/plugins/libimhex/include/hex/api/content_registry.hpp b/plugins/libimhex/include/hex/api/content_registry.hpp index d7ba8c7e8..31895b0cb 100644 --- a/plugins/libimhex/include/hex/api/content_registry.hpp +++ b/plugins/libimhex/include/hex/api/content_registry.hpp @@ -104,14 +104,14 @@ namespace hex { Views() = delete; template T, typename ... Args> - static T* add(Args&& ... args) { - return static_cast(add(new T(std::forward(args)...))); + static void add(Args&& ... args) { + return add(std::make_unique(std::forward(args)...)); } - static std::vector& getEntries(); + static std::vector>& getEntries(); private: - static View* add(View *view); + static void add(std::unique_ptr &&view); }; diff --git a/plugins/libimhex/include/hex/helpers/shared_data.hpp b/plugins/libimhex/include/hex/helpers/shared_data.hpp index 41f527be8..7bddff038 100644 --- a/plugins/libimhex/include/hex/helpers/shared_data.hpp +++ b/plugins/libimhex/include/hex/helpers/shared_data.hpp @@ -4,11 +4,13 @@ #include #include #include +#include #include #include #include #include +#include #include #include @@ -55,7 +57,7 @@ namespace hex { static u32 customEventsLastId; static std::vector commandPaletteCommands; static std::map patternLanguageFunctions; - static std::vector views; + static std::vector> views; static std::vector toolsEntries; static std::vector dataInspectorEntries; static u32 patternPaletteOffset; diff --git a/plugins/libimhex/include/hex/views/view.hpp b/plugins/libimhex/include/hex/views/view.hpp index 081489fdc..a9e859f19 100644 --- a/plugins/libimhex/include/hex/views/view.hpp +++ b/plugins/libimhex/include/hex/views/view.hpp @@ -6,7 +6,6 @@ #include #include -#include #include #include @@ -24,7 +23,7 @@ namespace hex { virtual void drawContent() = 0; virtual void drawMenu(); virtual bool handleShortcut(int key, int mods); - virtual bool isAvailable() { return SharedData::currentProvider != nullptr && SharedData::currentProvider->isAvailable(); } + virtual bool isAvailable(); static void openFileBrowser(std::string title, imgui_addons::ImGuiFileBrowser::DialogMode mode, std::string validExtensions, const std::function &callback); static void doLater(std::function &&function); diff --git a/plugins/libimhex/source/api/content_registry.cpp b/plugins/libimhex/source/api/content_registry.cpp index 6ad99c2db..eac85e222 100644 --- a/plugins/libimhex/source/api/content_registry.cpp +++ b/plugins/libimhex/source/api/content_registry.cpp @@ -149,11 +149,11 @@ namespace hex { /* Views */ - View* ContentRegistry::Views::add(View *view) { - return getEntries().emplace_back(view); + void ContentRegistry::Views::add(std::unique_ptr &&view) { + getEntries().emplace_back(std::move(view)); } - std::vector& ContentRegistry::Views::getEntries() { + std::vector>& ContentRegistry::Views::getEntries() { return SharedData::views; } diff --git a/plugins/libimhex/source/helpers/shared_data.cpp b/plugins/libimhex/source/helpers/shared_data.cpp index abf24ff8b..a941a0adc 100644 --- a/plugins/libimhex/source/helpers/shared_data.cpp +++ b/plugins/libimhex/source/helpers/shared_data.cpp @@ -11,7 +11,7 @@ namespace hex { u32 SharedData::customEventsLastId; std::vector SharedData::commandPaletteCommands; std::map SharedData::patternLanguageFunctions; - std::vector SharedData::views; + std::vector> SharedData::views; std::vector SharedData::toolsEntries; std::vector SharedData::dataInspectorEntries; u32 SharedData::patternPaletteOffset; diff --git a/plugins/libimhex/source/views/view.cpp b/plugins/libimhex/source/views/view.cpp index 5d0349ace..39a7a808a 100644 --- a/plugins/libimhex/source/views/view.cpp +++ b/plugins/libimhex/source/views/view.cpp @@ -16,6 +16,10 @@ namespace hex { void View::drawMenu() { } bool View::handleShortcut(int key, int mods) { return false; } + bool View::isAvailable() { + return SharedData::currentProvider != nullptr && SharedData::currentProvider->isAvailable(); + } + std::vector>& View::getDeferedCalls() { return SharedData::deferredCalls; } diff --git a/source/window.cpp b/source/window.cpp index 5ee984e47..74d7750e3 100644 --- a/source/window.cpp +++ b/source/window.cpp @@ -134,10 +134,6 @@ namespace hex { this->deinitGLFW(); ContentRegistry::Settings::store(); - for (auto &view : ContentRegistry::Views::getEntries()) - delete view; - ContentRegistry::Views::getEntries().clear(); - this->deinitPlugins(); EventManager::unsubscribe(Events::SettingsChanged, this); @@ -473,9 +469,11 @@ namespace hex { void Window::initImGui() { IMGUI_CHECKVERSION(); + auto *ctx = ImGui::CreateContext(); GImGui = ctx; + ImGuiIO& io = ImGui::GetIO(); ImGuiStyle& style = ImGui::GetStyle();