diff --git a/lib/libimhex/include/hex/api/event_manager.hpp b/lib/libimhex/include/hex/api/event_manager.hpp index 0b87448d2..8f6a99f99 100644 --- a/lib/libimhex/include/hex/api/event_manager.hpp +++ b/lib/libimhex/include/hex/api/event_manager.hpp @@ -13,12 +13,18 @@ #include -#define EVENT_DEF_IMPL(event_name, event_name_string, should_log, ...) \ - struct event_name final : public hex::impl::Event<__VA_ARGS__> { \ - constexpr static auto Id = [] { return hex::impl::EventId(event_name_string); }(); \ - constexpr static auto ShouldLog = (should_log); \ - explicit event_name(Callback func) noexcept : Event(std::move(func)) { } \ - } +#define EVENT_DEF_IMPL(event_name, event_name_string, should_log, ...) \ + struct event_name final : public hex::impl::Event<__VA_ARGS__> { \ + constexpr static auto Id = [] { return hex::impl::EventId(event_name_string); }(); \ + constexpr static auto ShouldLog = (should_log); \ + explicit event_name(Callback func) noexcept : Event(std::move(func)) { } \ + \ + static EventManager::EventList::iterator subscribe(Event::Callback function) { return EventManager::subscribe(function); } \ + static void subscribe(void *token, Event::Callback function) { EventManager::subscribe(token, function); } \ + static void unsubscribe(const EventManager::EventList::iterator &token) noexcept { EventManager::unsubscribe(token); } \ + static void unsubscribe(void *token) noexcept { EventManager::unsubscribe(token); } \ + static void post(auto &&...args) noexcept { EventManager::post(std::forward(args)...); } \ + }; #define EVENT_DEF(event_name, ...) EVENT_DEF_IMPL(event_name, #event_name, true, __VA_ARGS__) #define EVENT_DEF_NO_LOG(event_name, ...) EVENT_DEF_IMPL(event_name, #event_name, false, __VA_ARGS__) diff --git a/lib/libimhex/include/hex/providers/provider.hpp b/lib/libimhex/include/hex/providers/provider.hpp index 069970fcf..acb056982 100644 --- a/lib/libimhex/include/hex/providers/provider.hpp +++ b/lib/libimhex/include/hex/providers/provider.hpp @@ -156,13 +156,13 @@ namespace hex::prv { */ [[nodiscard]] virtual std::string getName() const = 0; - void resize(size_t newSize); - void insert(u64 offset, size_t size); - void remove(u64 offset, size_t size); + void resize(u64 newSize); + void insert(u64 offset, u64 size); + void remove(u64 offset, u64 size); - virtual void resizeRaw(size_t newSize) { hex::unused(newSize); } - virtual void insertRaw(u64 offset, size_t size) { hex::unused(offset, size); } - virtual void removeRaw(u64 offset, size_t size) { hex::unused(offset, size); } + virtual void resizeRaw(u64 newSize) { hex::unused(newSize); } + virtual void insertRaw(u64 offset, u64 size) { hex::unused(offset, size); } + virtual void removeRaw(u64 offset, u64 size) { hex::unused(offset, size); } virtual void save(); virtual void saveAs(const std::fs::path &path); @@ -172,8 +172,8 @@ namespace hex::prv { void applyOverlays(u64 offset, void *buffer, size_t size) const; [[nodiscard]] const std::list> &getOverlays() const; - [[nodiscard]] size_t getPageSize() const; - void setPageSize(size_t pageSize); + [[nodiscard]] u64 getPageSize() const; + void setPageSize(u64 pageSize); [[nodiscard]] u32 getPageCount() const; [[nodiscard]] u32 getCurrentPage() const; @@ -255,7 +255,7 @@ namespace hex::prv { std::string m_errorMessage; - size_t m_pageSize = MaxPageSize; + u64 m_pageSize = MaxPageSize; }; } \ No newline at end of file diff --git a/lib/libimhex/include/hex/providers/provider_data.hpp b/lib/libimhex/include/hex/providers/provider_data.hpp index 9f3ab4648..5dd158e2b 100644 --- a/lib/libimhex/include/hex/providers/provider_data.hpp +++ b/lib/libimhex/include/hex/providers/provider_data.hpp @@ -73,20 +73,20 @@ namespace hex { private: void onCreate() { - EventManager::subscribe(this, [this](prv::Provider *provider) { + EventProviderOpened::subscribe(this, [this](prv::Provider *provider) { this->m_data.emplace(provider, T()); }); - EventManager::subscribe(this, [this](prv::Provider *provider){ + EventProviderDeleted::subscribe(this, [this](prv::Provider *provider){ this->m_data.erase(provider); }); - EventManager::subscribe(this, [this] { + EventImHexClosing::subscribe(this, [this] { this->m_data.clear(); }); // Moves the data of this PerProvider instance from one provider to another - EventManager::subscribe(this, [this](prv::Provider *from, prv::Provider *to) { + MovePerProviderData::subscribe(this, [this](prv::Provider *from, prv::Provider *to) { // Get the value from the old provider, (removes it from the map) auto node = m_data.extract(from); @@ -103,9 +103,9 @@ namespace hex { } void onDestroy() { - EventManager::unsubscribe(this); - EventManager::unsubscribe(this); - EventManager::unsubscribe(this); + EventProviderOpened::unsubscribe(this); + EventProviderDeleted::unsubscribe(this); + EventImHexClosing::unsubscribe(this); } private: diff --git a/lib/libimhex/source/api/achievement_manager.cpp b/lib/libimhex/source/api/achievement_manager.cpp index 3259de55f..c1681fe94 100644 --- a/lib/libimhex/source/api/achievement_manager.cpp +++ b/lib/libimhex/source/api/achievement_manager.cpp @@ -128,7 +128,7 @@ namespace hex { achievement->setUnlocked(true); if (achievement->isUnlocked()) - EventManager::post(*achievement); + EventAchievementUnlocked::post(*achievement); return; } diff --git a/lib/libimhex/source/api/content_registry.cpp b/lib/libimhex/source/api/content_registry.cpp index 750b4cd8f..7a3113c21 100644 --- a/lib/libimhex/source/api/content_registry.cpp +++ b/lib/libimhex/source/api/content_registry.cpp @@ -809,7 +809,7 @@ namespace hex { namespace impl { void add(const std::string &typeName, ProviderCreationFunction creationFunction) { - (void)EventManager::subscribe([expectedName = typeName, creationFunction](const std::string &name, bool skipLoadInterface, bool selectProvider, prv::Provider **provider) { + (void)RequestCreateProvider::subscribe([expectedName = typeName, creationFunction](const std::string &name, bool skipLoadInterface, bool selectProvider, prv::Provider **provider) { if (name != expectedName) return; prv::Provider *newProvider = creationFunction(); diff --git a/lib/libimhex/source/api/imhex_api.cpp b/lib/libimhex/source/api/imhex_api.cpp index 9f7a87790..5b8cbdb91 100644 --- a/lib/libimhex/source/api/imhex_api.cpp +++ b/lib/libimhex/source/api/imhex_api.cpp @@ -82,7 +82,7 @@ namespace hex { id, Highlighting {region, color} }); - EventManager::post(); + EventHighlightingChanged::post(); return id; } @@ -90,7 +90,7 @@ namespace hex { void removeBackgroundHighlight(u32 id) { impl::getBackgroundHighlights().erase(id); - EventManager::post(); + EventHighlightingChanged::post(); } u32 addBackgroundHighlightingProvider(const impl::HighlightingFunction &function) { @@ -100,7 +100,7 @@ namespace hex { impl::getBackgroundHighlightingFunctions().insert({ id, function }); - EventManager::post(); + EventHighlightingChanged::post(); return id; } @@ -108,7 +108,7 @@ namespace hex { void removeBackgroundHighlightingProvider(u32 id) { impl::getBackgroundHighlightingFunctions().erase(id); - EventManager::post(); + EventHighlightingChanged::post(); } u32 addForegroundHighlight(const Region ®ion, color_t color) { @@ -120,7 +120,7 @@ namespace hex { id, Highlighting {region, color} }); - EventManager::post(); + EventHighlightingChanged::post(); return id; } @@ -128,7 +128,7 @@ namespace hex { void removeForegroundHighlight(u32 id) { impl::getForegroundHighlights().erase(id); - EventManager::post(); + EventHighlightingChanged::post(); } u32 addForegroundHighlightingProvider(const impl::HighlightingFunction &function) { @@ -138,7 +138,7 @@ namespace hex { impl::getForegroundHighlightingFunctions().insert({ id, function }); - EventManager::post(); + EventHighlightingChanged::post(); return id; } @@ -146,7 +146,7 @@ namespace hex { void removeForegroundHighlightingProvider(u32 id) { impl::getForegroundHighlightingFunctions().erase(id); - EventManager::post(); + EventHighlightingChanged::post(); } static u32 tooltipId = 0; @@ -190,7 +190,7 @@ namespace hex { } void setSelection(const ProviderRegion ®ion) { - EventManager::post(region); + RequestSelectionChange::post(region); } void setSelection(u64 address, size_t size, prv::Provider *provider) { @@ -204,7 +204,7 @@ namespace hex { u64 add(Region region, const std::string &name, const std::string &comment, u32 color) { u64 id = 0; - EventManager::post(region, name, comment, color, &id); + RequestAddBookmark::post(region, name, comment, color, &id); return id; } @@ -214,7 +214,7 @@ namespace hex { } void remove(u64 id) { - EventManager::post(id); + RequestRemoveBookmark::post(id); } } @@ -256,7 +256,7 @@ namespace hex { if (index < s_providers.size() && s_currentProvider != index) { auto oldProvider = get(); s_currentProvider = index; - EventManager::post(oldProvider, get()); + EventProviderChanged::post(oldProvider, get()); } } @@ -291,7 +291,7 @@ namespace hex { provider->skipLoadInterface(); s_providers.push_back(provider); - EventManager::post(provider); + EventProviderCreated::post(provider); if (select || s_providers.size() == 1) setCurrentProvider(s_providers.size() - 1); @@ -308,7 +308,7 @@ namespace hex { impl::s_closingProviders.push_back(provider); bool shouldClose = true; - EventManager::post(provider, &shouldClose); + EventProviderClosing::post(provider, &shouldClose); if (!shouldClose) return; } @@ -350,13 +350,13 @@ namespace hex { setCurrentProvider(0); if (s_providers.empty()) - EventManager::post(provider, nullptr); + EventProviderChanged::post(provider, nullptr); provider->close(); - EventManager::post(provider); + EventProviderClosed::post(provider); TaskManager::runWhenTasksFinished([provider] { - EventManager::post(provider); + EventProviderDeleted::post(provider); std::erase(impl::s_closingProviders, provider); delete provider; }); @@ -364,7 +364,7 @@ namespace hex { prv::Provider* createProvider(const std::string &unlocalizedName, bool skipLoadInterface, bool select) { prv::Provider* result = nullptr; - EventManager::post(unlocalizedName, skipLoadInterface, select, &result); + RequestCreateProvider::post(unlocalizedName, skipLoadInterface, select, &result); return result; } @@ -440,16 +440,16 @@ namespace hex { } void closeImHex(bool noQuestions) { - EventManager::post(noQuestions); + RequestCloseImHex::post(noQuestions); } void restartImHex() { - EventManager::post(); - EventManager::post(false); + RequestRestartImHex::post(); + RequestCloseImHex::post(false); } void setTaskBarProgress(TaskProgressState state, TaskProgressType type, u32 progress) { - EventManager::post(u32(state), u32(type), progress); + EventSetTaskBarIconState::post(u32(state), u32(type), progress); } @@ -503,8 +503,8 @@ namespace hex { void enableSystemThemeDetection(bool enabled) { s_systemThemeDetection = enabled; - EventManager::post(); - EventManager::post(); + EventSettingsChanged::post(); + EventOSThemeChanged::post(); } bool usesSystemThemeDetection() { @@ -666,7 +666,7 @@ namespace hex { break; } - EventManager::subscribe([executablePath, updateTypeString] { + EventImHexClosing::subscribe([executablePath, updateTypeString] { hex::executeCommand( hex::format("{} {}", wolv::util::toUTF8String(executablePath), @@ -681,7 +681,7 @@ namespace hex { } void addStartupTask(const std::string &name, bool async, const std::function &function) { - EventManager::post(name, async, function); + RequestAddInitTask::post(name, async, function); } } diff --git a/lib/libimhex/source/api/theme_manager.cpp b/lib/libimhex/source/api/theme_manager.cpp index 29f3d7ea9..a0aa636b6 100644 --- a/lib/libimhex/source/api/theme_manager.cpp +++ b/lib/libimhex/source/api/theme_manager.cpp @@ -194,7 +194,7 @@ namespace hex { s_currTheme = name; - EventManager::post(); + EventThemeChanged::post(); } const std::string &ThemeManager::getImageTheme() { diff --git a/lib/libimhex/source/providers/provider.cpp b/lib/libimhex/source/providers/provider.cpp index fc9d0ea89..655bfc71a 100644 --- a/lib/libimhex/source/providers/provider.cpp +++ b/lib/libimhex/source/providers/provider.cpp @@ -32,12 +32,10 @@ namespace hex::prv { this->m_overlays.clear(); if (auto selection = ImHexApi::HexEditor::getSelection(); selection.has_value() && selection->provider == this) - EventManager::post(ImHexApi::HexEditor::ProviderRegion { { 0x00, 0x00 }, nullptr }); + EventRegionSelected::post(ImHexApi::HexEditor::ProviderRegion { { 0x00, 0x00 }, nullptr }); } void Provider::read(u64 offset, void *buffer, size_t size, bool overlays) { - hex::unused(overlays); - this->readRaw(offset - this->getBaseAddress(), buffer, size); if (overlays) @@ -45,12 +43,12 @@ namespace hex::prv { } void Provider::write(u64 offset, const void *buffer, size_t size) { - EventManager::post(this, offset, size, static_cast(buffer)); + EventProviderDataModified::post(this, offset, size, static_cast(buffer)); this->markDirty(); } void Provider::save() { - EventManager::post(this); + EventProviderSaved::post(this); } void Provider::saveAs(const std::fs::path &path) { wolv::io::File file(path, wolv::io::File::Mode::Create); @@ -66,29 +64,29 @@ namespace hex::prv { file.writeBuffer(buffer.data(), bufferSize); } - EventManager::post(this); + EventProviderSaved::post(this); } } - void Provider::resize(size_t newSize) { + void Provider::resize(u64 newSize) { i64 difference = newSize - this->getActualSize(); if (difference > 0) - EventManager::post(this, this->getActualSize(), difference); + EventProviderDataInserted::post(this, this->getActualSize(), difference); else if (difference < 0) - EventManager::post(this, this->getActualSize(), -difference); + EventProviderDataRemoved::post(this, this->getActualSize(), -difference); this->markDirty(); } - void Provider::insert(u64 offset, size_t size) { - EventManager::post(this, offset, size); + void Provider::insert(u64 offset, u64 size) { + EventProviderDataInserted::post(this, offset, size); this->markDirty(); } - void Provider::remove(u64 offset, size_t size) { - EventManager::post(this, offset, size); + void Provider::remove(u64 offset, u64 size) { + EventProviderDataRemoved::post(this, offset, size); this->markDirty(); } @@ -120,11 +118,11 @@ namespace hex::prv { } - size_t Provider::getPageSize() const { + u64 Provider::getPageSize() const { return this->m_pageSize; } - void Provider::setPageSize(size_t pageSize) { + void Provider::setPageSize(u64 pageSize) { if (pageSize > MaxPageSize) pageSize = MaxPageSize; if (pageSize == 0) diff --git a/lib/libimhex/source/subcommands/subcommands.cpp b/lib/libimhex/source/subcommands/subcommands.cpp index ffe88978d..f7809f410 100644 --- a/lib/libimhex/source/subcommands/subcommands.cpp +++ b/lib/libimhex/source/subcommands/subcommands.cpp @@ -101,7 +101,7 @@ namespace hex::subcommands { } data.erase(data.end()-1); - EventManager::post(hex::format("command/{}", cmdName), data); + SendMessageToMainInstance::post(hex::format("command/{}", cmdName), data); } void registerSubCommand(const std::string &cmdName, const ForwardCommandHandler &handler) { diff --git a/main/gui/include/init/splash_window.hpp b/main/gui/include/init/splash_window.hpp index 1bef8b489..a8d0c2a8c 100644 --- a/main/gui/include/init/splash_window.hpp +++ b/main/gui/include/init/splash_window.hpp @@ -23,7 +23,7 @@ namespace hex::init { bool async; }; - enum FrameResult{ success, failure, wait }; + enum FrameResult{ Success, Failure, Running }; struct Highlight { ImVec2 start; @@ -59,8 +59,8 @@ namespace hex::init { void initImGui(); void initMyself(); - void exitGLFW(); - void exitImGui(); + void exitGLFW() const; + void exitImGui() const; std::future processTasksAsync(); diff --git a/main/gui/source/crash_handlers.cpp b/main/gui/source/crash_handlers.cpp index 25b256417..46ac227dc 100644 --- a/main/gui/source/crash_handlers.cpp +++ b/main/gui/source/crash_handlers.cpp @@ -73,7 +73,7 @@ namespace hex::crash { extern "C" void triggerSafeShutdown(int signalNumber = 0) { // Trigger an event so that plugins can handle crashes - EventManager::post(signalNumber); + EventAbnormalTermination::post(signalNumber); // Run exit tasks init::runExitTasks(); @@ -174,8 +174,8 @@ namespace hex::crash { // because this save is responsible for telling us which files // were opened in case there wasn't a project // Only do it when ImHex has finished its loading - EventManager::subscribe([] { - EventManager::subscribe([](int) { + EventImHexStartupFinished::subscribe([] { + EventAbnormalTermination::subscribe([](int) { // Save ImGui settings auto imguiSettingsPath = hex::getImGuiSettingsPath(); if (!imguiSettingsPath.empty()) @@ -192,7 +192,7 @@ namespace hex::crash { }); // Change the crash callback when ImHex has finished startup - EventManager::subscribe([]{ + EventImHexStartupFinished::subscribe([]{ crashCallback = saveCrashFile; }); } diff --git a/main/gui/source/init/splash_window.cpp b/main/gui/source/init/splash_window.cpp index f317c9e3d..b71cbc552 100644 --- a/main/gui/source/init/splash_window.cpp +++ b/main/gui/source/init/splash_window.cpp @@ -44,7 +44,7 @@ namespace hex::init { ImHexApi::System::impl::setGPUVendor(reinterpret_cast(glGetString(GL_VENDOR))); - EventManager::subscribe([this](const std::string& name, bool async, const TaskFunction &function){ + RequestAddInitTask::subscribe([this](const std::string& name, bool async, const TaskFunction &function){ this->m_tasks.push_back(Task{ name, function, async }); }); } @@ -295,23 +295,26 @@ namespace hex::init { // Check if all background tasks have finished so the splash screen can be closed if (this->tasksSucceeded.wait_for(0s) == std::future_status::ready) { if (this->tasksSucceeded.get()) { - log::debug("All tasks finished with success !"); - return FrameResult::success; + log::debug("All tasks finished successfully!"); + return FrameResult::Success; } else { log::warn("All tasks finished, but some failed"); - return FrameResult::failure; + return FrameResult::Failure; } } - return FrameResult::wait; + return FrameResult::Running; } bool WindowSplash::loop() { // Splash window rendering loop while (true) { - auto res = this->fullFrame(); - if (res == FrameResult::success) return true; - else if (res == FrameResult::failure) return false; + auto frameResult = this->fullFrame(); + + if (frameResult == FrameResult::Success) + return true; + else if (frameResult == FrameResult::Failure) + return false; } } @@ -457,10 +460,10 @@ namespace hex::init { u32 lastPos = 0; u32 lastCount = 0; for (auto &highlight : this->highlights) { - auto newPos = lastPos + lastCount + (rng() % 40); - auto newCount = (rng() % 7) + 3; - highlight.start.x = newPos % 13; - highlight.start.y = newPos / 13; + u32 newPos = lastPos + lastCount + (rng() % 40); + u32 newCount = (rng() % 7) + 3; + highlight.start.x = float(newPos % 13); + highlight.start.y = float(newPos / 13); highlight.count = newCount; { @@ -483,12 +486,12 @@ namespace hex::init { this->tasksSucceeded = processTasksAsync(); } - void WindowSplash::exitGLFW() { + void WindowSplash::exitGLFW() const { glfwDestroyWindow(this->m_window); glfwTerminate(); } - void WindowSplash::exitImGui() { + void WindowSplash::exitImGui() const { ImGui_ImplOpenGL3_Shutdown(); ImGui_ImplGlfw_Shutdown(); ImGui::DestroyContext(); diff --git a/main/gui/source/init/tasks.cpp b/main/gui/source/init/tasks.cpp index 66872809e..2fb1a00d2 100644 --- a/main/gui/source/init/tasks.cpp +++ b/main/gui/source/init/tasks.cpp @@ -62,7 +62,7 @@ namespace hex::init { // This is a bit of a hack but necessary because when ImHex gets closed, all plugins are unloaded in order for // destructors to be called correctly. To prevent crashes when ImHex exits, we need to delete all shared data - EventManager::post(); + EventImHexClosing::post(); EventManager::clear(); // Terminate all asynchronous tasks diff --git a/main/gui/source/main.cpp b/main/gui/source/main.cpp index 1e204df27..8e5e3eb51 100644 --- a/main/gui/source/main.cpp +++ b/main/gui/source/main.cpp @@ -129,7 +129,7 @@ namespace { */ void handleFileOpenRequest() { if (auto path = hex::getInitialFilePath(); path.has_value()) { - EventManager::post(path.value()); + RequestOpenFile::post(path.value()); } } @@ -160,7 +160,7 @@ namespace { splashWindow->startStartupTasks(); - EventManager::subscribe([&] { + RequestRestartImHex::subscribe([&] { MAIN_THREAD_EM_ASM({ location.reload(); }); @@ -214,7 +214,7 @@ namespace { do { // Register an event handler that will make ImHex restart when requested shouldRestart = false; - EventManager::subscribe([&] { + RequestRestartImHex::subscribe([&] { shouldRestart = true; }); diff --git a/main/gui/source/messaging/common.cpp b/main/gui/source/messaging/common.cpp index 79a15dd1f..931dc64c6 100644 --- a/main/gui/source/messaging/common.cpp +++ b/main/gui/source/messaging/common.cpp @@ -14,10 +14,10 @@ namespace hex::messaging { } void setupEvents() { - EventManager::subscribe([](const std::string &eventName, const std::vector &eventData) { + SendMessageToMainInstance::subscribe([](const std::string &eventName, const std::vector &eventData) { log::debug("Forwarding message {} (maybe to us)", eventName); if (ImHexApi::System::isMainInstance()) { - EventManager::subscribe([eventName, eventData]{ + EventImHexStartupFinished::subscribe([eventName, eventData]{ ImHexApi::Messaging::impl::runHandler(eventName, eventData); }); } else { diff --git a/main/gui/source/window/linux_window.cpp b/main/gui/source/window/linux_window.cpp index bf02328b5..bc80ebf92 100644 --- a/main/gui/source/window/linux_window.cpp +++ b/main/gui/source/window/linux_window.cpp @@ -67,7 +67,7 @@ namespace hex { void Window::setupNativeWindow() { bool themeFollowSystem = ImHexApi::System::usesSystemThemeDetection(); - EventManager::subscribe(this, [themeFollowSystem] { + EventOSThemeChanged::subscribe(this, [themeFollowSystem] { if (!themeFollowSystem) return; std::array buffer = { 0 }; @@ -83,11 +83,11 @@ namespace hex { auto exitCode = WEXITSTATUS(pclose(pipe)); if (exitCode != 0) return; - EventManager::post(hex::containsIgnoreCase(result, "uint32 1") ? "Light" : "Dark"); + RequestChangeTheme::post(hex::containsIgnoreCase(result, "uint32 1") ? "Light" : "Dark"); }); if (themeFollowSystem) - EventManager::post(); + EventOSThemeChanged::post(); } void Window::beginNativeWindowFrame() { diff --git a/main/gui/source/window/macos_window.cpp b/main/gui/source/window/macos_window.cpp index c8db32332..9b9edebda 100644 --- a/main/gui/source/window/macos_window.cpp +++ b/main/gui/source/window/macos_window.cpp @@ -42,17 +42,17 @@ namespace hex { void Window::setupNativeWindow() { bool themeFollowSystem = ImHexApi::System::usesSystemThemeDetection(); - EventManager::subscribe(this, [themeFollowSystem] { + EventOSThemeChanged::subscribe(this, [themeFollowSystem] { if (!themeFollowSystem) return; if (!isMacosSystemDarkModeEnabled()) - EventManager::post("Light"); + RequestChangeTheme::post("Light"); else - EventManager::post("Dark"); + RequestChangeTheme::post("Dark"); }); if (themeFollowSystem) - EventManager::post(); + EventOSThemeChanged::post(); } void Window::beginNativeWindowFrame() { diff --git a/main/gui/source/window/web_window.cpp b/main/gui/source/window/web_window.cpp index 0220ce28f..20c738039 100644 --- a/main/gui/source/window/web_window.cpp +++ b/main/gui/source/window/web_window.cpp @@ -34,7 +34,7 @@ EM_JS(bool, isDarkModeEnabled, (), { EMSCRIPTEN_KEEPALIVE extern "C" void handleThemeChange() { - hex::EventManager::post(); + hex::hex::EventOSThemeChanged::post(); } namespace hex { @@ -65,14 +65,14 @@ namespace hex { setupThemeListener(); bool themeFollowSystem = ImHexApi::System::usesSystemThemeDetection(); - EventManager::subscribe(this, [themeFollowSystem] { + EventOSThemeChanged::subscribe(this, [themeFollowSystem] { if (!themeFollowSystem) return; - EventManager::post(!isDarkModeEnabled() ? "Light" : "Dark"); + RequestChangeTheme::post(!isDarkModeEnabled() ? "Light" : "Dark"); }); if (themeFollowSystem) - EventManager::post(); + EventOSThemeChanged::post(); } void Window::beginNativeWindowFrame() { diff --git a/main/gui/source/window/win_window.cpp b/main/gui/source/window/win_window.cpp index a4c96d69f..b5f0ede16 100644 --- a/main/gui/source/window/win_window.cpp +++ b/main/gui/source/window/win_window.cpp @@ -76,7 +76,7 @@ namespace hex { if (lParam == 0) break; if (LPCTSTR(lParam) == std::string_view("ImmersiveColorSet")) { - EventManager::post(); + EventOSThemeChanged::post(); } break; @@ -336,7 +336,7 @@ namespace hex { CoCreateInstance(CLSID_TaskbarList, nullptr, CLSCTX_INPROC_SERVER, IID_ITaskbarList4, &g_taskbarList); } - EventManager::subscribe([hwnd](u32 state, u32 type, u32 progress){ + EventSetTaskBarIconState::subscribe([hwnd](u32 state, u32 type, u32 progress){ using enum ImHexApi::System::TaskProgressState; switch (ImHexApi::System::TaskProgressState(state)) { case Reset: @@ -379,7 +379,7 @@ namespace hex { ULONG dataSize; }; - EventManager::subscribe([this]{ + EventThemeChanged::subscribe([this]{ auto hwnd = glfwGetWin32Window(this->m_window); static auto user32Dll = WinUniquePtr(LoadLibraryA("user32.dll"), FreeLibrary); diff --git a/main/gui/source/window/window.cpp b/main/gui/source/window/window.cpp index 4bca0994f..fb116279b 100644 --- a/main/gui/source/window/window.cpp +++ b/main/gui/source/window/window.cpp @@ -86,17 +86,17 @@ namespace hex { this->m_logoTexture = ImGuiExt::Texture(romfs::get("logo.png").span()); ContentRegistry::Settings::impl::store(); - EventManager::post(); - EventManager::post(); - EventManager::post(); + EventSettingsChanged::post(); + EventWindowInitialized::post(); + EventImHexStartupFinished::post(); } Window::~Window() { - EventManager::unsubscribe(this); - EventManager::unsubscribe(this); - EventManager::unsubscribe(this); - EventManager::unsubscribe(this); - EventManager::unsubscribe(this); + EventProviderDeleted::unsubscribe(this); + RequestCloseImHex::unsubscribe(this); + RequestUpdateWindowTitle::unsubscribe(this); + EventAbnormalTermination::unsubscribe(this); + RequestOpenPopup::unsubscribe(this); this->exitImGui(); this->exitGLFW(); @@ -104,18 +104,18 @@ namespace hex { void Window::registerEventHandlers() { // Initialize default theme - EventManager::post("Dark"); + RequestChangeTheme::post("Dark"); // Handle the close window request by telling GLFW to shut down - EventManager::subscribe(this, [this](bool noQuestions) { + RequestCloseImHex::subscribe(this, [this](bool noQuestions) { glfwSetWindowShouldClose(this->m_window, GLFW_TRUE); if (!noQuestions) - EventManager::post(this->m_window); + EventWindowClosing::post(this->m_window); }); // Handle updating the window title - EventManager::subscribe(this, [this] { + RequestUpdateWindowTitle::subscribe(this, [this] { std::string title = "ImHex"; if (ProjectFile::hasPath()) { @@ -150,7 +150,7 @@ namespace hex { }); // Handle opening popups - EventManager::subscribe(this, [this](auto name) { + RequestOpenPopup::subscribe(this, [this](auto name) { std::scoped_lock lock(this->m_popupMutex); this->m_popupsToOpen.push_back(name); @@ -325,7 +325,7 @@ namespace hex { ImGui::SetCursorPos(searchBoxPos); if (ImGui::Button(this->m_windowTitle.c_str(), searchBoxSize)) { - EventManager::post(); + EventSearchBoxClicked::post(); } ImGui::PopStyleVar(3); @@ -756,7 +756,7 @@ namespace hex { } } - EventManager::post(); + EventFrameBegin::post(); } void Window::frame() { @@ -828,7 +828,7 @@ namespace hex { } void Window::frameEnd() { - EventManager::post(); + EventFrameEnd::post(); // Clean up all tasks that are done TaskManager::collectGarbage(); @@ -1063,7 +1063,7 @@ namespace hex { // Register window close callback glfwSetWindowCloseCallback(this->m_window, [](GLFWwindow *window) { - EventManager::post(window); + EventWindowClosing::post(window); }); // Register file drop callback @@ -1090,7 +1090,7 @@ namespace hex { // If no custom handler was found, just open the file regularly if (!handled) - EventManager::post(path); + RequestOpenFile::post(path); } }); @@ -1224,7 +1224,7 @@ namespace hex { for (const auto &plugin : PluginManager::getPlugins()) plugin.setImGuiContext(ImGui::GetCurrentContext()); - EventManager::post(); + RequestInitThemeHandlers::post(); } void Window::exitGLFW() { diff --git a/plugins/builtin/include/content/providers/null_provider.hpp b/plugins/builtin/include/content/providers/null_provider.hpp index 2a8747230..675a8abaa 100644 --- a/plugins/builtin/include/content/providers/null_provider.hpp +++ b/plugins/builtin/include/content/providers/null_provider.hpp @@ -8,7 +8,7 @@ namespace hex::plugin::builtin { class NullProvider : public hex::prv::Provider { public: NullProvider() { - EventManager::subscribe([this](auto *newProvider) { + EventProviderOpened::subscribe([this](auto *newProvider) { if (newProvider == this) return; @@ -17,7 +17,7 @@ namespace hex::plugin::builtin { } ~NullProvider() override { - EventManager::unsubscribe(this); + EventProviderOpened::unsubscribe(this); } [[nodiscard]] bool isAvailable() const override { return true; } diff --git a/plugins/builtin/include/content/providers/view_provider.hpp b/plugins/builtin/include/content/providers/view_provider.hpp index 0f8afec8b..2a8ec08f5 100644 --- a/plugins/builtin/include/content/providers/view_provider.hpp +++ b/plugins/builtin/include/content/providers/view_provider.hpp @@ -10,13 +10,13 @@ namespace hex::plugin::builtin { class ViewProvider : public hex::prv::Provider { public: explicit ViewProvider() { - EventManager::subscribe(this, [this](const prv::Provider *provider, bool*) { + EventProviderClosing::subscribe(this, [this](const prv::Provider *provider, bool*) { if (this->m_provider == provider) ImHexApi::Provider::remove(this, false); }); } ~ViewProvider() override { - EventManager::unsubscribe(this); + EventProviderClosing::unsubscribe(this); } [[nodiscard]] bool isAvailable() const override { diff --git a/plugins/builtin/include/ui/hex_editor.hpp b/plugins/builtin/include/ui/hex_editor.hpp index 554c3db32..02850d657 100644 --- a/plugins/builtin/include/ui/hex_editor.hpp +++ b/plugins/builtin/include/ui/hex_editor.hpp @@ -81,7 +81,7 @@ namespace hex::plugin::builtin::ui { if (this->m_selectionChanged) { auto selection = this->getSelection(); - EventManager::post(ImHexApi::HexEditor::ProviderRegion{ { selection.address, selection.size }, this->m_provider }); + EventRegionSelected::post(ImHexApi::HexEditor::ProviderRegion{ { selection.address, selection.size }, this->m_provider }); this->m_shouldModifyValue = true; } } diff --git a/plugins/builtin/source/content/achievements.cpp b/plugins/builtin/source/content/achievements.cpp index 73251472a..0c69fe7f5 100644 --- a/plugins/builtin/source/content/achievements.cpp +++ b/plugins/builtin/source/content/achievements.cpp @@ -187,27 +187,27 @@ namespace hex::plugin::builtin { void registerEvents() { - EventManager::subscribe([](const auto ®ion) { + EventRegionSelected::subscribe([](const auto ®ion) { if (region.getSize() > 1) AchievementManager::unlockAchievement("hex.builtin.achievement.hex_editor", "hex.builtin.achievement.hex_editor.select_byte.name"); }); - EventManager::subscribe([](const auto&) { + EventBookmarkCreated::subscribe([](const auto&) { AchievementManager::unlockAchievement("hex.builtin.achievement.hex_editor", "hex.builtin.achievement.hex_editor.create_bookmark.name"); }); - EventManager::subscribe([](u64, u8, u8) { + EventPatchCreated::subscribe([](u64, u8, u8) { AchievementManager::unlockAchievement("hex.builtin.achievement.hex_editor", "hex.builtin.achievement.hex_editor.modify_byte.name"); }); - EventManager::subscribe(AchievementManager::loadProgress); - EventManager::subscribe([](const Achievement &) { + EventImHexStartupFinished::subscribe(AchievementManager::loadProgress); + EventAchievementUnlocked::subscribe([](const Achievement &) { AchievementManager::storeProgress(); }); // Clear temporary achievements when the last provider is closed - EventManager::subscribe([](hex::prv::Provider *oldProvider, const hex::prv::Provider *newProvider) { + EventProviderChanged::subscribe([](hex::prv::Provider *oldProvider, const hex::prv::Provider *newProvider) { hex::unused(oldProvider); if (newProvider == nullptr) { AchievementManager::clearTemporary(); diff --git a/plugins/builtin/source/content/background_services.cpp b/plugins/builtin/source/content/background_services.cpp index 9eba78144..944d80e23 100644 --- a/plugins/builtin/source/content/background_services.cpp +++ b/plugins/builtin/source/content/background_services.cpp @@ -24,7 +24,7 @@ namespace hex::plugin::builtin { static wolv::net::SocketServer networkInterfaceServer(31337); AT_FIRST_TIME { - EventManager::subscribe([]{ + EventImHexClosing::subscribe([]{ networkInterfaceServer.shutdown(); }); }; @@ -61,7 +61,7 @@ namespace hex::plugin::builtin { } void registerBackgroundServices() { - EventManager::subscribe([]{ + EventSettingsChanged::subscribe([]{ networkInterfaceServiceEnabled = bool(ContentRegistry::Settings::read("hex.builtin.setting.general", "hex.builtin.setting.general.network_interface", false)); }); diff --git a/plugins/builtin/source/content/command_line_interface.cpp b/plugins/builtin/source/content/command_line_interface.cpp index 659995c4f..f780133bc 100644 --- a/plugins/builtin/source/content/command_line_interface.cpp +++ b/plugins/builtin/source/content/command_line_interface.cpp @@ -306,7 +306,7 @@ namespace hex::plugin::builtin { void registerCommandForwarders() { hex::subcommands::registerSubCommand("open", [](const std::vector &args){ for (auto &arg : args) { - EventManager::post(arg); + RequestOpenFile::post(arg); } }); } diff --git a/plugins/builtin/source/content/communication_interface.cpp b/plugins/builtin/source/content/communication_interface.cpp index b828d0147..f719f8e9d 100644 --- a/plugins/builtin/source/content/communication_interface.cpp +++ b/plugins/builtin/source/content/communication_interface.cpp @@ -9,7 +9,7 @@ namespace hex::plugin::builtin { ContentRegistry::CommunicationInterface::registerNetworkEndpoint("pattern_editor/set_code", [](const nlohmann::json &data) -> nlohmann::json { auto code = data.at("code").get(); - EventManager::post(code); + RequestSetPatternLanguageCode::post(code); return { }; }); diff --git a/plugins/builtin/source/content/data_processor_nodes/other_nodes.cpp b/plugins/builtin/source/content/data_processor_nodes/other_nodes.cpp index aa503c602..06d51eb06 100644 --- a/plugins/builtin/source/content/data_processor_nodes/other_nodes.cpp +++ b/plugins/builtin/source/content/data_processor_nodes/other_nodes.cpp @@ -60,14 +60,14 @@ namespace hex::plugin::builtin { class NodeDataSelection : public dp::Node { public: NodeDataSelection() : Node("hex.builtin.nodes.data_access.selection.header", { dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "hex.builtin.nodes.data_access.selection.address"), dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "hex.builtin.nodes.data_access.selection.size") }) { - EventManager::subscribe(this, [this](const auto ®ion) { + EventRegionSelected::subscribe(this, [this](const auto ®ion) { this->m_address = region.address; this->m_size = region.size; }); } ~NodeDataSelection() override { - EventManager::unsubscribe(this); + EventRegionSelected::unsubscribe(this); } void process() override { diff --git a/plugins/builtin/source/content/events.cpp b/plugins/builtin/source/content/events.cpp index 7227c0246..0ba07ecf2 100644 --- a/plugins/builtin/source/content/events.cpp +++ b/plugins/builtin/source/content/events.cpp @@ -29,7 +29,7 @@ namespace hex::plugin::builtin { PopupError::open(hex::format("hex.builtin.provider.error.open"_lang, provider->getErrorMessage())); TaskManager::doLater([provider] { ImHexApi::Provider::remove(provider); }); } else { - EventManager::post(fileProvider); + EventProviderOpened::post(fileProvider); } } } @@ -37,7 +37,7 @@ namespace hex::plugin::builtin { void registerEventHandlers() { static bool imhexClosing = false; - EventManager::subscribe([](GLFWwindow *window) { + EventWindowClosing::subscribe([](GLFWwindow *window) { imhexClosing = false; if (ImHexApi::Provider::isDirty() && !imhexClosing) { glfwSetWindowShouldClose(window, GLFW_FALSE); @@ -59,7 +59,7 @@ namespace hex::plugin::builtin { } }); - EventManager::subscribe([](const prv::Provider *provider, bool *shouldClose) { + EventProviderClosing::subscribe([](const prv::Provider *provider, bool *shouldClose) { if (provider->isDirty()) { *shouldClose = false; PopupUnsavedChanges::open("hex.builtin.popup.close_provider.desc"_lang, @@ -78,28 +78,28 @@ namespace hex::plugin::builtin { } }); - EventManager::subscribe([](hex::prv::Provider *oldProvider, hex::prv::Provider *newProvider) { + EventProviderChanged::subscribe([](hex::prv::Provider *oldProvider, hex::prv::Provider *newProvider) { hex::unused(oldProvider); hex::unused(newProvider); - EventManager::post(); + RequestUpdateWindowTitle::post(); }); - EventManager::subscribe([](hex::prv::Provider *provider) { + EventProviderOpened::subscribe([](hex::prv::Provider *provider) { if (provider != nullptr && ImHexApi::Provider::get() == provider) - EventManager::post(); - EventManager::post(nullptr, provider); + RequestUpdateWindowTitle::post(); + EventProviderChanged::post(nullptr, provider); }); - EventManager::subscribe(openFile); + RequestOpenFile::subscribe(openFile); - EventManager::subscribe([](const std::string &name) { + RequestOpenWindow::subscribe([](const std::string &name) { if (name == "Create File") { auto newProvider = hex::ImHexApi::Provider::createProvider("hex.builtin.provider.mem_file", true); if (newProvider != nullptr && !newProvider->open()) hex::ImHexApi::Provider::remove(newProvider); else - EventManager::post(newProvider); + EventProviderOpened::post(newProvider); } else if (name == "Open File") { fs::openFileBrowser(fs::DialogMode::Open, { }, [](const auto &path) { if (path.extension() == ".hexproj") { @@ -118,7 +118,7 @@ namespace hex::plugin::builtin { if (!newProvider->open()) hex::ImHexApi::Provider::remove(newProvider); else { - EventManager::post(newProvider); + EventProviderOpened::post(newProvider); AchievementManager::unlockAchievement("hex.builtin.achievement.starting_out", "hex.builtin.achievement.starting_out.open_file.name"); } @@ -134,12 +134,12 @@ namespace hex::plugin::builtin { } }); - EventManager::subscribe([](auto, auto) { - EventManager::post(); + EventProviderChanged::subscribe([](auto, auto) { + EventHighlightingChanged::post(); }); // Handles the provider initialization, and calls EventProviderOpened if successful - EventManager::subscribe([](hex::prv::Provider *provider) { + EventProviderCreated::subscribe([](hex::prv::Provider *provider) { if (provider->shouldSkipLoadInterface()) return; @@ -154,7 +154,7 @@ namespace hex::plugin::builtin { return; } - EventManager::post(provider); + EventProviderOpened::post(provider); } else if (!provider->hasLoadInterface()) { if (!provider->open() || !provider->isAvailable()) { @@ -163,23 +163,23 @@ namespace hex::plugin::builtin { return; } - EventManager::post(provider); + EventProviderOpened::post(provider); } }); - EventManager::subscribe([](const ImHexApi::HexEditor::ProviderRegion ®ion) { + EventRegionSelected::subscribe([](const ImHexApi::HexEditor::ProviderRegion ®ion) { ImHexApi::HexEditor::impl::setCurrentSelection(region); }); - EventManager::subscribe([](const std::string &message) { + RequestOpenInfoPopup::subscribe([](const std::string &message) { PopupInfo::open(message); }); - EventManager::subscribe([](const std::string &message) { + RequestOpenErrorPopup::subscribe([](const std::string &message) { PopupError::open(message); }); - EventManager::subscribe([](const std::string &message) { + RequestOpenFatalPopup::subscribe([](const std::string &message) { PopupFatal::open(message); }); diff --git a/plugins/builtin/source/content/main_menu_items.cpp b/plugins/builtin/source/content/main_menu_items.cpp index 6d92da30e..f44e75206 100644 --- a/plugins/builtin/source/content/main_menu_items.cpp +++ b/plugins/builtin/source/content/main_menu_items.cpp @@ -377,12 +377,12 @@ namespace hex::plugin::builtin { if (newProvider != nullptr && !newProvider->open()) hex::ImHexApi::Provider::remove(newProvider); else - EventManager::post(newProvider); + EventProviderOpened::post(newProvider); }, noRunningTasks); /* Open File */ ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.file", "hex.builtin.menu.file.open_file" }, 1100, CTRLCMD + Keys::O, [] { - EventManager::post("Open File"); + RequestOpenWindow::post("Open File"); }, noRunningTasks); /* Open Other */ @@ -596,7 +596,7 @@ namespace hex::plugin::builtin { createExtrasMenu(); createHelpMenu(); - (void)EventManager::subscribe([] { + (void)EventFrameEnd::subscribe([] { if (g_demoWindowOpen) { ImGui::ShowDemoWindow(&g_demoWindowOpen); ImPlot::ShowDemoWindow(&g_demoWindowOpen); diff --git a/plugins/builtin/source/content/project.cpp b/plugins/builtin/source/content/project.cpp index b3541587c..1b64204fa 100644 --- a/plugins/builtin/source/content/project.cpp +++ b/plugins/builtin/source/content/project.cpp @@ -106,8 +106,8 @@ namespace hex::plugin::builtin { } resetPath.release(); - EventManager::post(); - EventManager::post(); + EventProjectOpened::post(); + RequestUpdateWindowTitle::post(); return true; } @@ -169,7 +169,7 @@ namespace hex::plugin::builtin { AchievementManager::unlockAchievement("hex.builtin.achievement.starting_out", "hex.builtin.achievement.starting_out.save_project.name"); // Request, as this puts us into a project state - EventManager::post(); + RequestUpdateWindowTitle::post(); return result; } diff --git a/plugins/builtin/source/content/providers.cpp b/plugins/builtin/source/content/providers.cpp index ef8b23bfc..797f85b07 100644 --- a/plugins/builtin/source/content/providers.cpp +++ b/plugins/builtin/source/content/providers.cpp @@ -87,7 +87,7 @@ namespace hex::plugin::builtin { if (!newProvider->open() || !newProvider->isAvailable() || !newProvider->isReadable()) { providerWarnings[newProvider] = newProvider->getErrorMessage(); } else - EventManager::post(newProvider); + EventProviderOpened::post(newProvider); } } diff --git a/plugins/builtin/source/content/providers/memory_file_provider.cpp b/plugins/builtin/source/content/providers/memory_file_provider.cpp index 0f1545fc5..4a5a42f13 100644 --- a/plugins/builtin/source/content/providers/memory_file_provider.cpp +++ b/plugins/builtin/source/content/providers/memory_file_provider.cpp @@ -56,10 +56,10 @@ namespace hex::plugin::builtin { if (!fileProvider->open()) ImHexApi::Provider::remove(newProvider); else { - EventManager::post(this, fileProvider); + MovePerProviderData::post(this, fileProvider); fileProvider->markDirty(false); - EventManager::post(newProvider); + EventProviderOpened::post(newProvider); ImHexApi::Provider::remove(this, true); } } diff --git a/plugins/builtin/source/content/providers/process_memory_provider.cpp b/plugins/builtin/source/content/providers/process_memory_provider.cpp index 92426bfae..1f0a1d42d 100644 --- a/plugins/builtin/source/content/providers/process_memory_provider.cpp +++ b/plugins/builtin/source/content/providers/process_memory_provider.cpp @@ -294,7 +294,7 @@ namespace hex::plugin::builtin { if (loadLibraryW != nullptr) { if (auto threadHandle = CreateRemoteThread(this->m_processHandle, nullptr, 0, loadLibraryW, pathAddress, 0, nullptr); threadHandle != nullptr) { WaitForSingleObject(threadHandle, INFINITE); - EventManager::post(hex::format("hex.builtin.provider.process_memory.utils.inject_dll.success"_lang, path.filename().string())); + RequestOpenErrorPopup::post(hex::format("hex.builtin.provider.process_memory.utils.inject_dll.success"_lang, path.filename().string())); this->reloadProcessModules(); CloseHandle(threadHandle); return; @@ -303,7 +303,7 @@ namespace hex::plugin::builtin { } } - EventManager::post(hex::format("hex.builtin.provider.process_memory.utils.inject_dll.failure"_lang, path.filename().string())); + RequestOpenErrorPopup::post(hex::format("hex.builtin.provider.process_memory.utils.inject_dll.failure"_lang, path.filename().string())); }); } #endif diff --git a/plugins/builtin/source/content/recent.cpp b/plugins/builtin/source/content/recent.cpp index e885f3b88..d340682d3 100644 --- a/plugins/builtin/source/content/recent.cpp +++ b/plugins/builtin/source/content/recent.cpp @@ -28,7 +28,7 @@ namespace hex::plugin::builtin::recent { void registerEventHandlers() { // Save every opened provider as a "recent" shortcut - (void)EventManager::subscribe([](const prv::Provider *provider) { + (void)EventProviderOpened::subscribe([](const prv::Provider *provider) { if (ContentRegistry::Settings::read("hex.builtin.setting.general", "hex.builtin.setting.general.save_recent_providers", true)) { auto fileName = hex::format("{:%y%m%d_%H%M%S}.json", fmt::gmtime(std::chrono::system_clock::now())); @@ -62,7 +62,7 @@ namespace hex::plugin::builtin::recent { }); // Save opened projects as a "recent" shortcut - (void)EventManager::subscribe([] { + (void)EventProjectOpened::subscribe([] { if (ContentRegistry::Settings::read("hex.builtin.setting.general", "hex.builtin.setting.general.save_recent_providers", true)) { auto fileName = hex::format("{:%y%m%d_%H%M%S}.json", fmt::gmtime(std::chrono::system_clock::now())); @@ -164,7 +164,7 @@ namespace hex::plugin::builtin::recent { return; } - EventManager::post(provider); + EventProviderOpened::post(provider); updateRecentEntries(); } diff --git a/plugins/builtin/source/content/settings_entries.cpp b/plugins/builtin/source/content/settings_entries.cpp index b3b967137..c2f38c17b 100644 --- a/plugins/builtin/source/content/settings_entries.cpp +++ b/plugins/builtin/source/content/settings_entries.cpp @@ -464,7 +464,7 @@ namespace hex::plugin::builtin { /* Experiments */ ContentRegistry::Settings::setCategoryDescription("hex.builtin.setting.experiments", "hex.builtin.setting.experiments.description"); - EventManager::subscribe([]{ + EventImHexStartupFinished::subscribe([]{ for (const auto &[name, experiment] : ContentRegistry::Experiments::impl::getExperiments()) { ContentRegistry::Settings::add("hex.builtin.setting.experiments", "", experiment.unlocalizedName, false) .setTooltip(Lang(experiment.unlocalizedDescription)) @@ -477,7 +477,7 @@ namespace hex::plugin::builtin { }); /* Shorcuts */ - EventManager::subscribe([]{ + EventImHexStartupFinished::subscribe([]{ for (const auto &shortcutEntry : ShortcutManager::getGlobalShortcuts()) { ContentRegistry::Settings::add("hex.builtin.setting.shortcuts", "hex.builtin.setting.shortcuts.global", shortcutEntry.unlocalizedName, nullptr, shortcutEntry.shortcut); } diff --git a/plugins/builtin/source/content/themes.cpp b/plugins/builtin/source/content/themes.cpp index e689d2ba2..82ab444bb 100644 --- a/plugins/builtin/source/content/themes.cpp +++ b/plugins/builtin/source/content/themes.cpp @@ -17,7 +17,7 @@ namespace hex::plugin::builtin { void registerThemeHandlers() { - EventManager::subscribe([] { + RequestInitThemeHandlers::subscribe([] { { const static ThemeManager::ColorMap ImGuiColorMap = { { "text", ImGuiCol_Text }, @@ -253,7 +253,7 @@ namespace hex::plugin::builtin { } void registerStyleHandlers() { - EventManager::subscribe([] { + RequestInitThemeHandlers::subscribe([] { { auto &style = ImGui::GetStyle(); const static ThemeManager::StyleMap ImGuiStyleMap = { diff --git a/plugins/builtin/source/content/ui_items.cpp b/plugins/builtin/source/content/ui_items.cpp index ca817aa89..ecffad16b 100644 --- a/plugins/builtin/source/content/ui_items.cpp +++ b/plugins/builtin/source/content/ui_items.cpp @@ -53,7 +53,7 @@ namespace hex::plugin::builtin { } void addGlobalUIItems() { - EventManager::subscribe(drawGlobalPopups); + EventFrameEnd::subscribe(drawGlobalPopups); } void addFooterItems() { @@ -163,7 +163,7 @@ namespace hex::plugin::builtin { }); static bool providerJustChanged = true; - EventManager::subscribe([](auto, auto) { providerJustChanged = true; }); + EventProviderChanged::subscribe([](auto, auto) { providerJustChanged = true; }); ContentRegistry::Interface::addToolbarItem([] { auto provider = ImHexApi::Provider::get(); @@ -196,12 +196,12 @@ namespace hex::plugin::builtin { if (newProvider != nullptr && !newProvider->open()) hex::ImHexApi::Provider::remove(newProvider); else - EventManager::post(newProvider); + EventProviderOpened::post(newProvider); } // Open file if (ImGuiExt::ToolBarButton(ICON_VS_FOLDER_OPENED, ImGuiExt::GetCustomColorVec4(ImGuiCustomCol_ToolbarBrown))) - EventManager::post("Open File"); + RequestOpenWindow::post("Open File"); } ImGui::EndDisabled(); diff --git a/plugins/builtin/source/content/views/view_achievements.cpp b/plugins/builtin/source/content/views/view_achievements.cpp index 209825491..a4c5c8983 100644 --- a/plugins/builtin/source/content/views/view_achievements.cpp +++ b/plugins/builtin/source/content/views/view_achievements.cpp @@ -16,11 +16,11 @@ namespace hex::plugin::builtin { }); // Add newly unlocked achievements to the display queue - EventManager::subscribe(this, [this](const Achievement &achievement) { + EventAchievementUnlocked::subscribe(this, [this](const Achievement &achievement) { this->m_achievementUnlockQueue.push_back(&achievement); }); - EventManager::subscribe(this, [this](const std::string &name) { + RequestOpenWindow::subscribe(this, [this](const std::string &name) { if (name == "Achievements") { TaskManager::doLater([this] { this->getWindowOpenState() = true; @@ -33,7 +33,7 @@ namespace hex::plugin::builtin { } ViewAchievements::~ViewAchievements() { - EventManager::unsubscribe(this); + EventAchievementUnlocked::unsubscribe(this); } void drawAchievement(ImDrawList *drawList, const AchievementManager::AchievementNode *node, ImVec2 position) { diff --git a/plugins/builtin/source/content/views/view_bookmarks.cpp b/plugins/builtin/source/content/views/view_bookmarks.cpp index 411b2186d..398ed6cd5 100644 --- a/plugins/builtin/source/content/views/view_bookmarks.cpp +++ b/plugins/builtin/source/content/views/view_bookmarks.cpp @@ -20,7 +20,7 @@ namespace hex::plugin::builtin { ViewBookmarks::ViewBookmarks() : View::Window("hex.builtin.view.bookmarks.name") { // Handle bookmark add requests sent by the API - EventManager::subscribe(this, [this](Region region, std::string name, std::string comment, color_t color, u64 *id) { + RequestAddBookmark::subscribe(this, [this](Region region, std::string name, std::string comment, color_t color, u64 *id) { if (name.empty()) { name = hex::format("hex.builtin.view.bookmarks.default_title"_lang, region.address, region.address + region.size - 1); } @@ -46,11 +46,11 @@ namespace hex::plugin::builtin { ImHexApi::Provider::markDirty(); - EventManager::post(this->m_bookmarks->back().entry); - EventManager::post(); + EventBookmarkCreated::post(this->m_bookmarks->back().entry); + EventHighlightingChanged::post(); }); - EventManager::subscribe([this](u64 id) { + RequestRemoveBookmark::subscribe([this](u64 id) { std::erase_if(this->m_bookmarks.get(), [id](const auto &bookmark) { return bookmark.entry.id == id; }); @@ -188,8 +188,8 @@ namespace hex::plugin::builtin { } ViewBookmarks::~ViewBookmarks() { - EventManager::unsubscribe(this); - EventManager::unsubscribe(this); + RequestAddBookmark::unsubscribe(this); + EventProviderDeleted::unsubscribe(this); } static void drawColorPopup(ImColor &color) { @@ -235,7 +235,7 @@ namespace hex::plugin::builtin { } if (colorChanged) - EventManager::post(); + EventHighlightingChanged::post(); } void ViewBookmarks::drawContent() { @@ -372,7 +372,7 @@ namespace hex::plugin::builtin { if (auto *viewProvider = dynamic_cast(newProvider); viewProvider != nullptr) { viewProvider->setProvider(region.getStartAddress(), region.getSize(), provider); if (viewProvider->open()) { - EventManager::post(viewProvider); + EventProviderOpened::post(viewProvider); AchievementManager::unlockAchievement("hex.builtin.achievement.hex_editor", "hex.builtin.achievement.hex_editor.open_new_view.name"); } } @@ -434,7 +434,7 @@ namespace hex::plugin::builtin { // Remove the bookmark that was marked for removal if (bookmarkToRemove != this->m_bookmarks->end()) { this->m_bookmarks->erase(bookmarkToRemove); - EventManager::post(); + EventHighlightingChanged::post(); } } ImGui::EndChild(); diff --git a/plugins/builtin/source/content/views/view_command_palette.cpp b/plugins/builtin/source/content/views/view_command_palette.cpp index 9d2f226e8..b438c43f5 100644 --- a/plugins/builtin/source/content/views/view_command_palette.cpp +++ b/plugins/builtin/source/content/views/view_command_palette.cpp @@ -8,13 +8,13 @@ namespace hex::plugin::builtin { ViewCommandPalette::ViewCommandPalette() : View::Special("hex.builtin.view.command_palette.name") { // Add global shortcut to open the command palette ShortcutManager::addGlobalShortcut(CTRLCMD + SHIFT + Keys::P, "hex.builtin.view.command_palette.name", [this] { - EventManager::post("hex.builtin.view.command_palette.name"_lang); + RequestOpenPopup::post("hex.builtin.view.command_palette.name"_lang); this->m_commandPaletteOpen = true; this->m_justOpened = true; }); - EventManager::subscribe([this] { - EventManager::post("hex.builtin.view.command_palette.name"_lang); + EventSearchBoxClicked::subscribe([this] { + RequestOpenPopup::post("hex.builtin.view.command_palette.name"_lang); this->m_commandPaletteOpen = true; this->m_justOpened = true; }); diff --git a/plugins/builtin/source/content/views/view_data_inspector.cpp b/plugins/builtin/source/content/views/view_data_inspector.cpp index a3dc9466d..df0b3e055 100644 --- a/plugins/builtin/source/content/views/view_data_inspector.cpp +++ b/plugins/builtin/source/content/views/view_data_inspector.cpp @@ -19,7 +19,7 @@ namespace hex::plugin::builtin { ViewDataInspector::ViewDataInspector() : View::Window("hex.builtin.view.data_inspector.name") { // Handle region selection - EventManager::subscribe(this, [this](const auto ®ion) { + EventRegionSelected::subscribe(this, [this](const auto ®ion) { // Save current selection if (!ImHexApi::Provider::isValid() || region == Region::Invalid()) { @@ -35,11 +35,11 @@ namespace hex::plugin::builtin { this->m_shouldInvalidate = true; }); - EventManager::subscribe(this, [this](const auto*) { + EventProviderClosed::subscribe(this, [this](const auto*) { this->m_selectedProvider = nullptr; }); - EventManager::subscribe(this, [this] { + EventSettingsChanged::subscribe(this, [this] { auto filterValues = ContentRegistry::Settings::read("hex.builtin.setting.data_inspector", "hex.builtin.setting.data_inspector.hidden_rows", nlohmann::json::array()).get>(); this->m_hiddenValues = std::set(filterValues.begin(), filterValues.end()); @@ -47,9 +47,9 @@ namespace hex::plugin::builtin { } ViewDataInspector::~ViewDataInspector() { - EventManager::unsubscribe(this); - EventManager::unsubscribe(this); - EventManager::unsubscribe(this); + EventRegionSelected::unsubscribe(this); + EventProviderClosed::unsubscribe(this); + EventSettingsChanged::unsubscribe(this); } diff --git a/plugins/builtin/source/content/views/view_data_processor.cpp b/plugins/builtin/source/content/views/view_data_processor.cpp index 191fd21a0..e927434b1 100644 --- a/plugins/builtin/source/content/views/view_data_processor.cpp +++ b/plugins/builtin/source/content/views/view_data_processor.cpp @@ -370,12 +370,12 @@ namespace hex::plugin::builtin { } }); - EventManager::subscribe(this, [this](auto *provider) { + EventProviderCreated::subscribe(this, [this](auto *provider) { this->m_mainWorkspace.get(provider) = { }; this->m_workspaceStack.get(provider).push_back(&this->m_mainWorkspace.get(provider)); }); - EventManager::subscribe(this, [this](const auto *, const auto *) { + EventProviderChanged::subscribe(this, [this](const auto *, const auto *) { for (auto *workspace : *this->m_workspaceStack) { for (auto &node : workspace->nodes) { node->setCurrentOverlay(nullptr); @@ -387,7 +387,7 @@ namespace hex::plugin::builtin { this->m_updateNodePositions = true; }); - EventManager::subscribe(this, [this] { + EventDataChanged::subscribe(this, [this] { ViewDataProcessor::processNodes(*this->m_workspaceStack->back()); }); @@ -427,11 +427,11 @@ namespace hex::plugin::builtin { } ViewDataProcessor::~ViewDataProcessor() { - EventManager::unsubscribe(this); - EventManager::unsubscribe(this); - EventManager::unsubscribe(this); - EventManager::unsubscribe(this); - EventManager::unsubscribe(this); + EventProviderCreated::unsubscribe(this); + EventProviderChanged::unsubscribe(this); + RequestChangeTheme::unsubscribe(this); + EventFileLoaded::unsubscribe(this); + EventDataChanged::unsubscribe(this); } diff --git a/plugins/builtin/source/content/views/view_diff.cpp b/plugins/builtin/source/content/views/view_diff.cpp index 25b149a0b..18eceff77 100644 --- a/plugins/builtin/source/content/views/view_diff.cpp +++ b/plugins/builtin/source/content/views/view_diff.cpp @@ -18,7 +18,7 @@ namespace hex::plugin::builtin { ViewDiff::ViewDiff() : View::Window("hex.builtin.view.diff.name") { // Clear the selected diff providers when a provider is closed - EventManager::subscribe(this, [this](prv::Provider *) { + EventProviderClosed::subscribe(this, [this](prv::Provider *) { for (u8 i = 0; i < 2; i++) { this->m_columns[i].provider = -1; this->m_columns[i].hexEditor.setSelectionUnchecked(std::nullopt, std::nullopt); @@ -33,7 +33,7 @@ namespace hex::plugin::builtin { } ViewDiff::~ViewDiff() { - EventManager::unsubscribe(this); + EventProviderClosed::unsubscribe(this); } namespace { diff --git a/plugins/builtin/source/content/views/view_disassembler.cpp b/plugins/builtin/source/content/views/view_disassembler.cpp index 1c771e488..4ebf50014 100644 --- a/plugins/builtin/source/content/views/view_disassembler.cpp +++ b/plugins/builtin/source/content/views/view_disassembler.cpp @@ -10,15 +10,15 @@ using namespace std::literals::string_literals; namespace hex::plugin::builtin { ViewDisassembler::ViewDisassembler() : View::Window("hex.builtin.view.disassembler.name") { - EventManager::subscribe(this, [this](const auto*) { + EventProviderDeleted::subscribe(this, [this](const auto*) { this->m_disassembly.clear(); }); } ViewDisassembler::~ViewDisassembler() { - EventManager::unsubscribe(this); - EventManager::unsubscribe(this); - EventManager::unsubscribe(this); + EventDataChanged::unsubscribe(this); + EventRegionSelected::unsubscribe(this); + EventProviderDeleted::unsubscribe(this); } void ViewDisassembler::disassemble() { diff --git a/plugins/builtin/source/content/views/view_find.cpp b/plugins/builtin/source/content/views/view_find.cpp index 0712a2e96..3393e8d7f 100644 --- a/plugins/builtin/source/content/views/view_find.cpp +++ b/plugins/builtin/source/content/views/view_find.cpp @@ -452,7 +452,7 @@ namespace hex::plugin::builtin { } this->m_occurrenceTree->clear(); - EventManager::post(); + EventHighlightingChanged::post(); this->m_searchTask = TaskManager::createTask("hex.builtin.view.find.searching", searchRegion.getSize(), [this, settings = this->m_searchSettings, searchRegion](auto &task) { auto provider = ImHexApi::Provider::get(); @@ -482,7 +482,7 @@ namespace hex::plugin::builtin { this->m_occurrenceTree->insert({ occurrence.region.getStartAddress(), occurrence.region.getEndAddress() }, occurrence); TaskManager::doLater([] { - EventManager::post(); + EventHighlightingChanged::post(); }); }); } @@ -828,7 +828,7 @@ namespace hex::plugin::builtin { this->m_sortedOccurrences->clear(); this->m_occurrenceTree->clear(); - EventManager::post(); + EventHighlightingChanged::post(); } } ImGui::EndDisabled(); diff --git a/plugins/builtin/source/content/views/view_hashes.cpp b/plugins/builtin/source/content/views/view_hashes.cpp index eee359c61..dae5373a2 100644 --- a/plugins/builtin/source/content/views/view_hashes.cpp +++ b/plugins/builtin/source/content/views/view_hashes.cpp @@ -49,7 +49,7 @@ namespace hex::plugin::builtin { }; ViewHashes::ViewHashes() : View::Window("hex.builtin.view.hashes.name") { - EventManager::subscribe(this, [this](const auto &providerRegion) { + EventRegionSelected::subscribe(this, [this](const auto &providerRegion) { for (auto &function : this->m_hashFunctions.get(providerRegion.getProvider())) function.reset(); }); @@ -124,7 +124,7 @@ namespace hex::plugin::builtin { } ViewHashes::~ViewHashes() { - EventManager::unsubscribe(this); + EventRegionSelected::unsubscribe(this); } diff --git a/plugins/builtin/source/content/views/view_hex_editor.cpp b/plugins/builtin/source/content/views/view_hex_editor.cpp index 831175ab0..1b190c2dd 100644 --- a/plugins/builtin/source/content/views/view_hex_editor.cpp +++ b/plugins/builtin/source/content/views/view_hex_editor.cpp @@ -157,14 +157,14 @@ namespace hex::plugin::builtin { class PopupFind : public ViewHexEditor::Popup { public: PopupFind() { - EventManager::subscribe(this, [this](Region region) { + EventRegionSelected::subscribe(this, [this](Region region) { this->m_searchPosition = this->m_nextSearchPosition.value_or(region.getStartAddress()); this->m_nextSearchPosition.reset(); }); } ~PopupFind() override { - EventManager::unsubscribe(this); + EventRegionSelected::unsubscribe(this); } void draw(ViewHexEditor *editor) override { @@ -636,10 +636,10 @@ namespace hex::plugin::builtin { } ViewHexEditor::~ViewHexEditor() { - EventManager::unsubscribe(this); - EventManager::unsubscribe(this); - EventManager::unsubscribe(this); - EventManager::unsubscribe(this); + RequestSelectionChange::unsubscribe(this); + EventProviderChanged::unsubscribe(this); + EventProviderOpened::unsubscribe(this); + EventHighlightingChanged::unsubscribe(this); } void ViewHexEditor::drawPopup() { @@ -676,7 +676,7 @@ namespace hex::plugin::builtin { // Right click menu if (ImGui::IsMouseReleased(ImGuiMouseButton_Right) && ImGui::IsWindowHovered(ImGuiHoveredFlags_ChildWindows)) - EventManager::post("hex.builtin.menu.edit"); + RequestOpenPopup::post("hex.builtin.menu.edit"); } void ViewHexEditor::drawContent() { @@ -774,7 +774,7 @@ namespace hex::plugin::builtin { this->m_selectionStart->reset(); this->m_selectionEnd->reset(); - EventManager::post(ImHexApi::HexEditor::ProviderRegion{ this->getSelection(), provider }); + EventRegionSelected::post(ImHexApi::HexEditor::ProviderRegion{ this->getSelection(), provider }); }); ShortcutManager::addShortcut(this, Keys::Enter, "hex.builtin.view.hex_editor.shortcut.enter_editing", [this] { @@ -953,13 +953,13 @@ namespace hex::plugin::builtin { } void ViewHexEditor::registerEvents() { - EventManager::subscribe(this, [this](Region region) { + RequestSelectionChange::subscribe(this, [this](Region region) { auto provider = ImHexApi::Provider::get(); if (region == Region::Invalid()) { this->m_selectionStart->reset(); this->m_selectionEnd->reset(); - EventManager::post(ImHexApi::HexEditor::ProviderRegion({ Region::Invalid(), nullptr })); + EventRegionSelected::post(ImHexApi::HexEditor::ProviderRegion({ Region::Invalid(), nullptr })); return; } @@ -975,7 +975,7 @@ namespace hex::plugin::builtin { } }); - EventManager::subscribe(this, [this](auto *oldProvider, auto *newProvider) { + EventProviderChanged::subscribe(this, [this](auto *oldProvider, auto *newProvider) { if (oldProvider != nullptr) { auto selection = this->m_hexEditor.getSelection(); @@ -998,15 +998,15 @@ namespace hex::plugin::builtin { this->m_hexEditor.forceUpdateScrollPosition(); if (isSelectionValid()) { - EventManager::post(ImHexApi::HexEditor::ProviderRegion{ this->getSelection(), newProvider }); + EventRegionSelected::post(ImHexApi::HexEditor::ProviderRegion{ this->getSelection(), newProvider }); } }); - EventManager::subscribe(this, [](auto *) { + EventProviderOpened::subscribe(this, [](auto *) { ImHexApi::HexEditor::clearSelection(); }); - EventManager::subscribe(this, [this]{ + EventHighlightingChanged::subscribe(this, [this]{ this->m_foregroundHighlights->clear(); this->m_backgroundHighlights->clear(); }); @@ -1311,7 +1311,7 @@ namespace hex::plugin::builtin { if (auto *viewProvider = dynamic_cast(newProvider); viewProvider != nullptr) { viewProvider->setProvider(selection->getStartAddress(), selection->getSize(), selection->getProvider()); if (viewProvider->open()) - EventManager::post(viewProvider); + EventProviderOpened::post(viewProvider); } }, [] { return ImHexApi::HexEditor::isSelectionValid() && ImHexApi::Provider::isValid(); }); diff --git a/plugins/builtin/source/content/views/view_highlight_rules.cpp b/plugins/builtin/source/content/views/view_highlight_rules.cpp index e9c9f2b05..a25d08284 100644 --- a/plugins/builtin/source/content/views/view_highlight_rules.cpp +++ b/plugins/builtin/source/content/views/view_highlight_rules.cpp @@ -164,7 +164,7 @@ namespace hex::plugin::builtin { // Initialize the selected rule iterators to point to the end of the rules lists this->m_selectedRule = this->m_rules->end(); - EventManager::subscribe([this](prv::Provider *provider) { + EventProviderCreated::subscribe([this](prv::Provider *provider) { this->m_selectedRule.get(provider) = this->m_rules.get(provider).end(); }); } @@ -193,7 +193,7 @@ namespace hex::plugin::builtin { ImGui::TableNextColumn(); ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2()); if (ImGui::Checkbox("##enabled", &rule.enabled)) { - EventManager::post(); + EventHighlightingChanged::post(); } ImGui::PopStyleVar(); @@ -273,7 +273,7 @@ namespace hex::plugin::builtin { // If any of the inputs have changed, update the highlight if (updateHighlight) - EventManager::post(); + EventHighlightingChanged::post(); } ImGui::EndTable(); diff --git a/plugins/builtin/source/content/views/view_information.cpp b/plugins/builtin/source/content/views/view_information.cpp index cb10e7f1e..dc3de4069 100644 --- a/plugins/builtin/source/content/views/view_information.cpp +++ b/plugins/builtin/source/content/views/view_information.cpp @@ -21,7 +21,7 @@ namespace hex::plugin::builtin { using namespace hex::literals; ViewInformation::ViewInformation() : View::Window("hex.builtin.view.information.name") { - EventManager::subscribe(this, [this] { + EventDataChanged::subscribe(this, [this] { this->m_dataValid = false; this->m_plainTextCharacterPercentage = -1.0; this->m_averageEntropy = -1.0; @@ -32,7 +32,7 @@ namespace hex::plugin::builtin { this->m_analyzedRegion = { 0, 0 }; }); - EventManager::subscribe(this, [this](Region region) { + EventRegionSelected::subscribe(this, [this](Region region) { // Set the position of the diagram relative to the place where // the user clicked inside the hex editor view if (this->m_blockSize != 0) { @@ -41,7 +41,7 @@ namespace hex::plugin::builtin { } }); - EventManager::subscribe(this, [this](const auto*) { + EventProviderDeleted::subscribe(this, [this](const auto*) { this->m_dataValid = false; }); @@ -58,9 +58,9 @@ namespace hex::plugin::builtin { } ViewInformation::~ViewInformation() { - EventManager::unsubscribe(this); - EventManager::unsubscribe(this); - EventManager::unsubscribe(this); + EventDataChanged::unsubscribe(this); + EventRegionSelected::unsubscribe(this); + EventProviderDeleted::unsubscribe(this); } void ViewInformation::analyze() { diff --git a/plugins/builtin/source/content/views/view_patches.cpp b/plugins/builtin/source/content/views/view_patches.cpp index e39d0f0f6..5603ac386 100644 --- a/plugins/builtin/source/content/views/view_patches.cpp +++ b/plugins/builtin/source/content/views/view_patches.cpp @@ -60,11 +60,11 @@ namespace hex::plugin::builtin { return std::nullopt; }); - EventManager::subscribe([](auto *) { - EventManager::post(); + EventProviderSaved::subscribe([](auto *) { + EventHighlightingChanged::post(); }); - EventManager::subscribe(this, [](prv::Provider *provider, u64 offset, u64 size, const u8 *data) { + EventProviderDataModified::subscribe(this, [](prv::Provider *provider, u64 offset, u64 size, const u8 *data) { if (size == 0) return; @@ -75,13 +75,13 @@ namespace hex::plugin::builtin { provider->getUndoStack().add(offset, size, oldData.data(), data); }); - EventManager::subscribe(this, [](prv::Provider *provider, u64 offset, u64 size) { + EventProviderDataInserted::subscribe(this, [](prv::Provider *provider, u64 offset, u64 size) { offset -= provider->getBaseAddress(); provider->getUndoStack().add(offset, size); }); - EventManager::subscribe(this, [](prv::Provider *provider, u64 offset, u64 size) { + EventProviderDataRemoved::subscribe(this, [](prv::Provider *provider, u64 offset, u64 size) { offset -= provider->getBaseAddress(); provider->getUndoStack().add(offset, size); @@ -177,7 +177,7 @@ namespace hex::plugin::builtin { const auto &operations = provider->getUndoStack().getAppliedOperations(); if (this->m_numOperations.get(provider) != operations.size()) { this->m_numOperations.get(provider) = operations.size(); - EventManager::post(); + EventHighlightingChanged::post(); } } } diff --git a/plugins/builtin/source/content/views/view_pattern_data.cpp b/plugins/builtin/source/content/views/view_pattern_data.cpp index a4c2abebd..d8a5dd1ed 100644 --- a/plugins/builtin/source/content/views/view_pattern_data.cpp +++ b/plugins/builtin/source/content/views/view_pattern_data.cpp @@ -12,7 +12,7 @@ namespace hex::plugin::builtin { this->m_patternDrawer = std::make_unique(); // Handle tree style setting changes - EventManager::subscribe(this, [this] { + EventSettingsChanged::subscribe(this, [this] { auto patternStyle = ContentRegistry::Settings::read("hex.builtin.setting.interface", "hex.builtin.setting.interface.pattern_tree_style", 0); this->m_patternDrawer->setTreeStyle(patternStyle); @@ -21,15 +21,15 @@ namespace hex::plugin::builtin { }); // Reset the pattern drawer when the provider changes - EventManager::subscribe(this, [this](auto, auto) { + EventProviderChanged::subscribe(this, [this](auto, auto) { this->m_patternDrawer->reset(); }); - EventManager::subscribe(this, [this]{ + EventPatternEvaluating::subscribe(this, [this]{ this->m_patternDrawer->reset(); }); - EventManager::subscribe(this, [this](auto){ + EventPatternExecuted::subscribe(this, [this](auto){ this->m_patternDrawer->reset(); }); @@ -38,10 +38,10 @@ namespace hex::plugin::builtin { } ViewPatternData::~ViewPatternData() { - EventManager::unsubscribe(this); - EventManager::unsubscribe(this); - EventManager::unsubscribe(this); - EventManager::unsubscribe(this); + EventSettingsChanged::unsubscribe(this); + EventProviderChanged::unsubscribe(this); + EventPatternEvaluating::unsubscribe(this); + EventPatternExecuted::unsubscribe(this); } void ViewPatternData::drawContent() { diff --git a/plugins/builtin/source/content/views/view_pattern_editor.cpp b/plugins/builtin/source/content/views/view_pattern_editor.cpp index 3af1c79f6..7b69f1ef6 100644 --- a/plugins/builtin/source/content/views/view_pattern_editor.cpp +++ b/plugins/builtin/source/content/views/view_pattern_editor.cpp @@ -144,10 +144,10 @@ namespace hex::plugin::builtin { } ViewPatternEditor::~ViewPatternEditor() { - EventManager::unsubscribe(this); - EventManager::unsubscribe(this); - EventManager::unsubscribe(this); - EventManager::unsubscribe(this); + RequestSetPatternLanguageCode::unsubscribe(this); + EventFileLoaded::unsubscribe(this); + EventProviderChanged::unsubscribe(this); + EventProviderClosed::unsubscribe(this); } void ViewPatternEditor::drawContent() { @@ -345,7 +345,7 @@ namespace hex::plugin::builtin { this->m_hasUnevaluatedChanges = false; auto code = this->m_textEditor.GetText(); - EventManager::post(code); + EventPatternEditorChanged::post(code); TaskManager::createBackgroundTask("Pattern Parsing", [this, code, provider](auto &){ this->parsePattern(code, provider); @@ -749,7 +749,7 @@ namespace hex::plugin::builtin { variable.value = this->m_lastEvaluationOutVars->at(name); } - EventManager::post(); + EventHighlightingChanged::post(); } this->m_lastEvaluationProcessed = true; @@ -996,7 +996,7 @@ namespace hex::plugin::builtin { } void ViewPatternEditor::evaluatePattern(const std::string &code, prv::Provider *provider) { - EventManager::post(); + EventPatternEvaluating::post(); auto lock = std::scoped_lock(ContentRegistry::PatternLanguage::getRuntimeLock()); @@ -1014,7 +1014,7 @@ namespace hex::plugin::builtin { this->m_accessHistory = {}; this->m_accessHistoryIndex = 0; - EventManager::post(); + EventHighlightingChanged::post(); TaskManager::createTask("hex.builtin.view.pattern_editor.evaluating", TaskManager::NoProgress, [this, code, provider](auto &task) { auto lock = std::scoped_lock(ContentRegistry::PatternLanguage::getRuntimeLock()); @@ -1095,40 +1095,40 @@ namespace hex::plugin::builtin { } TaskManager::doLater([code] { - EventManager::post(code); + EventPatternExecuted::post(code); }); }); } void ViewPatternEditor::registerEvents() { - EventManager::subscribe(this, [this](const std::fs::path &path) { + RequestLoadPatternLanguageFile::subscribe(this, [this](const std::fs::path &path) { this->loadPatternFile(path, ImHexApi::Provider::get()); }); - EventManager::subscribe(this, [this](const std::fs::path &path) { + RequestSavePatternLanguageFile::subscribe(this, [this](const std::fs::path &path) { wolv::io::File file(path, wolv::io::File::Mode::Create); file.writeString(wolv::util::trim(this->m_textEditor.GetText())); }); - EventManager::subscribe(this, [this](const std::string &code) { + RequestSetPatternLanguageCode::subscribe(this, [this](const std::string &code) { this->m_textEditor.SetText(code); this->m_sourceCode = code; this->m_hasUnevaluatedChanges = true; }); - EventManager::subscribe(this, [this] { + EventSettingsChanged::subscribe(this, [this] { this->m_syncPatternSourceCode = ContentRegistry::Settings::read("hex.builtin.setting.general", "hex.builtin.setting.general.sync_pattern_source", false); this->m_autoLoadPatterns = ContentRegistry::Settings::read("hex.builtin.setting.general", "hex.builtin.setting.general.auto_load_patterns", true); }); - EventManager::subscribe(this, [this](prv::Provider *provider) { + EventProviderOpened::subscribe(this, [this](prv::Provider *provider) { this->m_shouldAnalyze.get(provider) = true; this->m_envVarEntries->push_back({ 0, "", 0, EnvVarType::Integer }); this->m_debuggerDrawer.get(provider) = std::make_unique(); }); - EventManager::subscribe(this, [this](prv::Provider *oldProvider, prv::Provider *newProvider) { + EventProviderChanged::subscribe(this, [this](prv::Provider *oldProvider, prv::Provider *newProvider) { if (!this->m_syncPatternSourceCode) { if (oldProvider != nullptr) this->m_sourceCode.get(oldProvider) = this->m_textEditor.GetText(); @@ -1144,7 +1144,7 @@ namespace hex::plugin::builtin { } }); - EventManager::subscribe(this, [this](prv::Provider *) { + EventProviderClosed::subscribe(this, [this](prv::Provider *) { if (this->m_syncPatternSourceCode && ImHexApi::Provider::getProviders().empty()) { this->m_textEditor.SetText(""); this->m_sourceCode = ""; @@ -1286,7 +1286,7 @@ namespace hex::plugin::builtin { wolv::io::File file(path, wolv::io::File::Mode::Read); if (file.isValid()) { - EventManager::post(file.readString()); + RequestSetPatternLanguageCode::post(file.readString()); return true; } else { return false; diff --git a/plugins/builtin/source/content/views/view_provider_settings.cpp b/plugins/builtin/source/content/views/view_provider_settings.cpp index aced4d072..f4405d180 100644 --- a/plugins/builtin/source/content/views/view_provider_settings.cpp +++ b/plugins/builtin/source/content/views/view_provider_settings.cpp @@ -6,7 +6,7 @@ namespace hex::plugin::builtin { ViewProviderSettings::ViewProviderSettings() : View::Modal("hex.builtin.view.provider_settings.name") { - EventManager::subscribe(this, [this](const hex::prv::Provider *provider) { + EventProviderCreated::subscribe(this, [this](const hex::prv::Provider *provider) { if (provider->hasLoadInterface() && !provider->shouldSkipLoadInterface()) this->getWindowOpenState() = true; }); @@ -25,7 +25,7 @@ namespace hex::plugin::builtin { } ViewProviderSettings::~ViewProviderSettings() { - EventManager::unsubscribe(this); + EventProviderCreated::unsubscribe(this); } void ViewProviderSettings::drawContent() { @@ -39,7 +39,7 @@ namespace hex::plugin::builtin { ImGui::BeginDisabled(!settingsValid); if (ImGui::Button("hex.builtin.common.open"_lang)) { if (provider->open()) { - EventManager::post(provider); + EventProviderOpened::post(provider); this->getWindowOpenState() = false; ImGui::CloseCurrentPopup(); diff --git a/plugins/builtin/source/content/views/view_settings.cpp b/plugins/builtin/source/content/views/view_settings.cpp index 8b25f6675..8c47e4a24 100644 --- a/plugins/builtin/source/content/views/view_settings.cpp +++ b/plugins/builtin/source/content/views/view_settings.cpp @@ -11,7 +11,7 @@ namespace hex::plugin::builtin { ViewSettings::ViewSettings() : View::Modal("hex.builtin.view.settings.name") { // Handle window open requests - EventManager::subscribe(this, [this](const std::string &name) { + RequestOpenWindow::subscribe(this, [this](const std::string &name) { if (name == "Settings") { TaskManager::doLater([this] { this->getWindowOpenState() = true; @@ -27,7 +27,7 @@ namespace hex::plugin::builtin { } ViewSettings::~ViewSettings() { - EventManager::unsubscribe(this); + RequestOpenWindow::unsubscribe(this); } void ViewSettings::drawContent() { @@ -83,7 +83,7 @@ namespace hex::plugin::builtin { log::debug("Setting [{} / {}]: Value was changed to {}", category.unlocalizedName, setting.unlocalizedName, nlohmann::to_string(newValue)); // Signal that the setting was changed - EventManager::post(); + EventSettingsChanged::post(); widget->onChanged(); // Request a restart if the setting requires it diff --git a/plugins/builtin/source/content/views/view_store.cpp b/plugins/builtin/source/content/views/view_store.cpp index f371dbfa2..6d2505fed 100644 --- a/plugins/builtin/source/content/views/view_store.cpp +++ b/plugins/builtin/source/content/views/view_store.cpp @@ -327,7 +327,7 @@ namespace hex::plugin::builtin { wolv::io::fs::removeAll(folderPath); removed = removed && !wolv::io::fs::exists(filePath) && !wolv::io::fs::exists(folderPath); - EventManager::post(filePath); + EventStoreContentRemoved::post(filePath); } return removed; @@ -352,9 +352,9 @@ namespace hex::plugin::builtin { if (entry.isFolder) { Tar tar(this->m_downloadPath, Tar::Mode::Read); tar.extractAll(this->m_downloadPath.parent_path() / this->m_downloadPath.stem()); - EventManager::post(this->m_downloadPath.parent_path() / this->m_downloadPath.stem()); + EventStoreContentDownloaded::post(this->m_downloadPath.parent_path() / this->m_downloadPath.stem()); } else { - EventManager::post(this->m_downloadPath); + EventStoreContentDownloaded::post(this->m_downloadPath); } category.downloadCallback(); diff --git a/plugins/builtin/source/content/views/view_theme_manager.cpp b/plugins/builtin/source/content/views/view_theme_manager.cpp index 5e1ea9069..6828647b3 100644 --- a/plugins/builtin/source/content/views/view_theme_manager.cpp +++ b/plugins/builtin/source/content/views/view_theme_manager.cpp @@ -41,7 +41,7 @@ namespace hex::plugin::builtin { if (ImGui::ColorEdit4(colorName.c_str(), reinterpret_cast(&color.Value), ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaBar | ImGuiColorEditFlags_AlphaPreviewHalf)) { // Update the color value handler.setFunction(colorId, color); - EventManager::post(); + EventThemeChanged::post(); } if (ImGui::IsItemHovered()) { @@ -96,11 +96,11 @@ namespace hex::plugin::builtin { // Determine which one it is and draw the appropriate slider if (auto floatValue = std::get_if(&value); floatValue != nullptr) { if (ImGui::SliderFloat(styleName.c_str(), *floatValue, min, max, "%.1f")) { - EventManager::post(); + EventThemeChanged::post(); } } else if (auto vecValue = std::get_if(&value); vecValue != nullptr) { if (ImGui::SliderFloat2(styleName.c_str(), &(*vecValue)->x, min, max, "%.1f")) { - EventManager::post(); + EventThemeChanged::post(); } } } diff --git a/plugins/builtin/source/content/welcome_screen.cpp b/plugins/builtin/source/content/welcome_screen.cpp index 54ca90ded..f700e2c9a 100644 --- a/plugins/builtin/source/content/welcome_screen.cpp +++ b/plugins/builtin/source/content/welcome_screen.cpp @@ -187,12 +187,12 @@ namespace hex::plugin::builtin { if (newProvider != nullptr && !newProvider->open()) hex::ImHexApi::Provider::remove(newProvider); else - EventManager::post(newProvider); + EventProviderOpened::post(newProvider); } if (ImGuiExt::IconHyperlink(ICON_VS_GO_TO_FILE, "hex.builtin.welcome.start.open_file"_lang)) - EventManager::post("Open File"); + RequestOpenWindow::post("Open File"); if (ImGuiExt::IconHyperlink(ICON_VS_NOTEBOOK, "hex.builtin.welcome.start.open_project"_lang)) - EventManager::post("Open Project"); + RequestOpenWindow::post("Open Project"); if (ImGuiExt::IconHyperlink(ICON_VS_TELESCOPE, "hex.builtin.welcome.start.open_other"_lang)) otherProvidersVisible = !otherProvidersVisible; } @@ -300,7 +300,7 @@ namespace hex::plugin::builtin { ImGuiExt::BeginSubWindow("hex.builtin.welcome.header.customize"_lang, ImVec2(ImGui::GetContentRegionAvail().x - windowPadding, 0), ImGuiChildFlags_AutoResizeX); { if (ImGuiExt::DescriptionButton("hex.builtin.welcome.customize.settings.title"_lang, "hex.builtin.welcome.customize.settings.desc"_lang, ImVec2(ImGui::GetContentRegionAvail().x, 0))) - EventManager::post("Settings"); + RequestOpenWindow::post("Settings"); } ImGuiExt::EndSubWindow(); ImGui::TableNextRow(ImGuiTableRowFlags_None, ImGui::GetTextLineHeightWithSpacing() * 5); @@ -322,7 +322,7 @@ namespace hex::plugin::builtin { if (auto [unlocked, total] = AchievementManager::getProgress(); unlocked != total) { if (ImGuiExt::DescriptionButtonProgress("hex.builtin.welcome.learn.achievements.title"_lang, "hex.builtin.welcome.learn.achievements.desc"_lang, float(unlocked) / float(total), size)) { - EventManager::post("Achievements"); + RequestOpenWindow::post("Achievements"); } } } @@ -362,7 +362,7 @@ namespace hex::plugin::builtin { auto provider = ImHexApi::Provider::createProvider("hex.builtin.provider.null"); if (provider != nullptr) if (provider->open()) - EventManager::post(provider); + EventProviderOpened::post(provider); } } @@ -462,15 +462,15 @@ namespace hex::plugin::builtin { recent::registerEventHandlers(); recent::updateRecentEntries(); - (void)EventManager::subscribe(drawWelcomeScreen); + (void)EventFrameBegin::subscribe(drawWelcomeScreen); // Sets a background when they are no views - (void)EventManager::subscribe([]{ + (void)EventFrameBegin::subscribe([]{ if (ImHexApi::Provider::isValid() && !isAnyViewOpen()) drawNoViewsBackground(); }); - (void)EventManager::subscribe([] { + (void)EventSettingsChanged::subscribe([] { { auto theme = ContentRegistry::Settings::read("hex.builtin.setting.interface", "hex.builtin.setting.interface.color", ThemeManager::NativeTheme).get(); @@ -478,7 +478,7 @@ namespace hex::plugin::builtin { static std::string lastTheme; if (theme != lastTheme) { - EventManager::post(theme); + RequestChangeTheme::post(theme); lastTheme = theme; } } @@ -500,7 +500,7 @@ namespace hex::plugin::builtin { } }); - (void)EventManager::subscribe([](const std::string &theme) { + (void)RequestChangeTheme::subscribe([](const std::string &theme) { auto changeTexture = [&](const std::string &path) { return ImGuiExt::Texture(romfs::get(path).span()); }; @@ -514,12 +514,12 @@ namespace hex::plugin::builtin { } }); - EventManager::subscribe([](auto) { + EventProviderCreated::subscribe([](auto) { if (!isAnyViewOpen()) loadDefaultLayout(); }); - EventManager::subscribe([] { + EventWindowInitialized::subscribe([] { // Documentation of the value above the setting definition auto allowServerContact = ContentRegistry::Settings::read("hex.builtin.setting.general", "hex.builtin.setting.general.server_contact", 2); if (allowServerContact == 2) { @@ -533,11 +533,11 @@ namespace hex::plugin::builtin { }); // Clear project context if we go back to the welcome screen - EventManager::subscribe([](const hex::prv::Provider *oldProvider, const hex::prv::Provider *newProvider) { + EventProviderChanged::subscribe([](const hex::prv::Provider *oldProvider, const hex::prv::Provider *newProvider) { hex::unused(oldProvider); if (newProvider == nullptr) { ProjectFile::clearPath(); - EventManager::post(); + RequestUpdateWindowTitle::post(); } }); @@ -582,7 +582,7 @@ namespace hex::plugin::builtin { } else { ProjectFile::setPath(""); } - EventManager::post(); + RequestUpdateWindowTitle::post(); }else{ if (hasProject) { ProjectFile::setPath(crashFileData["project"].get()); diff --git a/plugins/builtin/source/ui/hex_editor.cpp b/plugins/builtin/source/ui/hex_editor.cpp index 179d4b29b..b8f14803e 100644 --- a/plugins/builtin/source/ui/hex_editor.cpp +++ b/plugins/builtin/source/ui/hex_editor.cpp @@ -73,7 +73,7 @@ namespace hex::plugin::builtin::ui { this->m_currDataVisualizer = ContentRegistry::HexEditor::getVisualizerByName("hex.builtin.visualizer.hexadecimal.8bit"); this->m_bytesPerRow = ContentRegistry::Settings::read("hex.builtin.setting.hex_editor", "hex.builtin.setting.hex_editor.bytes_per_row", this->m_bytesPerRow); - EventManager::subscribe(this, [this] { + EventSettingsChanged::subscribe(this, [this] { this->m_selectionColor = ContentRegistry::Settings::read("hex.builtin.setting.hex_editor", "hex.builtin.setting.hex_editor.highlight_color", 0x60C08080); this->m_syncScrolling = ContentRegistry::Settings::read("hex.builtin.setting.hex_editor", "hex.builtin.setting.hex_editor.sync_scrolling", false); this->m_byteCellPadding = ContentRegistry::Settings::read("hex.builtin.setting.hex_editor", "hex.builtin.setting.hex_editor.byte_padding", false); @@ -82,7 +82,7 @@ namespace hex::plugin::builtin::ui { } HexEditor::~HexEditor() { - EventManager::unsubscribe(this); + EventSettingsChanged::unsubscribe(this); } constexpr static u16 getByteColumnSeparatorCount(u16 columnCount) { diff --git a/plugins/script_loader/source/script_api/v1/ui.cpp b/plugins/script_loader/source/script_api/v1/ui.cpp index 24112eaef..5fe0d02d7 100644 --- a/plugins/script_loader/source/script_api/v1/ui.cpp +++ b/plugins/script_loader/source/script_api/v1/ui.cpp @@ -114,7 +114,7 @@ private: }; SCRIPT_API(void showMessageBox, const char *message) { - hex::EventManager::post(message); + hex::RequestOpenInfoPopup::post(message); } SCRIPT_API(void showInputTextBox, const char *title, const char *message, char *buffer, u32 bufferSize) { diff --git a/plugins/windows/source/content/ui_items.cpp b/plugins/windows/source/content/ui_items.cpp index dd8185498..b7410cbb5 100644 --- a/plugins/windows/source/content/ui_items.cpp +++ b/plugins/windows/source/content/ui_items.cpp @@ -16,7 +16,7 @@ namespace hex::plugin::windows { void addFooterItems() { static bool showResourceUsage = true; - EventManager::subscribe([]{ + EventSettingsChanged::subscribe([]{ showResourceUsage = ContentRegistry::Settings::read("hex.builtin.setting.interface", "hex.builtin.setting.interface.show_resource_usage", true); }); diff --git a/plugins/windows/source/plugin_windows.cpp b/plugins/windows/source/plugin_windows.cpp index 9f9692c7b..60c9bb94b 100644 --- a/plugins/windows/source/plugin_windows.cpp +++ b/plugins/windows/source/plugin_windows.cpp @@ -23,7 +23,7 @@ namespace hex::plugin::windows { static void detectSystemTheme() { // Setup system theme change detector - EventManager::subscribe([] { + EventOSThemeChanged::subscribe([] { bool themeFollowSystem = ContentRegistry::Settings::read("hex.builtin.setting.interface", "hex.builtin.setting.interface.color", ThemeManager::NativeTheme).get() == ThemeManager::NativeTheme; if (!themeFollowSystem) return; @@ -35,7 +35,7 @@ static void detectSystemTheme() { auto error = RegQueryValueEx(hkey, "AppsUseLightTheme", nullptr, nullptr, reinterpret_cast(&value), &size); if (error == ERROR_SUCCESS) { - EventManager::post(value == 0 ? "Dark" : "Light"); + RequestChangeTheme::post(value == 0 ? "Dark" : "Light"); } else { ImHexApi::System::impl::setBorderlessWindowMode(false); } @@ -44,11 +44,11 @@ static void detectSystemTheme() { } }); - EventManager::subscribe([=] { + EventWindowInitialized::subscribe([=] { bool themeFollowSystem = ContentRegistry::Settings::read("hex.builtin.setting.interface", "hex.builtin.setting.interface.color", ThemeManager::NativeTheme).get() == ThemeManager::NativeTheme; if (themeFollowSystem) - EventManager::post(); + EventOSThemeChanged::post(); }); } diff --git a/plugins/windows/source/views/view_tty_console.cpp b/plugins/windows/source/views/view_tty_console.cpp index 554ca1fa2..fb3f1b114 100644 --- a/plugins/windows/source/views/view_tty_console.cpp +++ b/plugins/windows/source/views/view_tty_console.cpp @@ -85,7 +85,7 @@ namespace hex::plugin::windows { if (this->m_portHandle == INVALID_HANDLE_VALUE) { if (ImGui::Button("hex.windows.view.tty_console.connect"_lang)) if (!this->connect()) - EventManager::post("hex.windows.view.tty_console.connect_error"_lang); + RequestOpenErrorPopup::post("hex.windows.view.tty_console.connect_error"_lang); } else { if (ImGui::Button("hex.windows.view.tty_console.disconnect"_lang)) this->disconnect(); @@ -184,7 +184,7 @@ namespace hex::plugin::windows { bool ViewTTYConsole::connect() { if (this->m_comPorts.empty() || static_cast(this->m_selectedPort) >= this->m_comPorts.size()) { - EventManager::post("hex.windows.view.tty_console.no_available_port"_lang); + RequestOpenErrorPopup::post("hex.windows.view.tty_console.no_available_port"_lang); return true; // If false, connect_error error popup will override this error popup } this->m_portHandle = ::CreateFile((R"(\\.\)" + this->m_comPorts[this->m_selectedPort].first).c_str(),