1
0
mirror of synced 2024-11-28 01:20:51 +01:00

refactor: Better interface for the event system

This commit is contained in:
WerWolv 2023-12-08 10:29:44 +01:00
parent f08d1e265c
commit b4813660b5
63 changed files with 327 additions and 320 deletions

View File

@ -13,12 +13,18 @@
#include <wolv/types/type_name.hpp>
#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<event_name>(function); } \
static void subscribe(void *token, Event::Callback function) { EventManager::subscribe<event_name>(token, function); } \
static void unsubscribe(const EventManager::EventList::iterator &token) noexcept { EventManager::unsubscribe(token); } \
static void unsubscribe(void *token) noexcept { EventManager::unsubscribe<event_name>(token); } \
static void post(auto &&...args) noexcept { EventManager::post<event_name>(std::forward<decltype(args)>(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__)

View File

@ -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<std::unique_ptr<Overlay>> &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;
};
}

View File

@ -73,20 +73,20 @@ namespace hex {
private:
void onCreate() {
EventManager::subscribe<EventProviderOpened>(this, [this](prv::Provider *provider) {
EventProviderOpened::subscribe(this, [this](prv::Provider *provider) {
this->m_data.emplace(provider, T());
});
EventManager::subscribe<EventProviderDeleted>(this, [this](prv::Provider *provider){
EventProviderDeleted::subscribe(this, [this](prv::Provider *provider){
this->m_data.erase(provider);
});
EventManager::subscribe<EventImHexClosing>(this, [this] {
EventImHexClosing::subscribe(this, [this] {
this->m_data.clear();
});
// Moves the data of this PerProvider instance from one provider to another
EventManager::subscribe<MovePerProviderData>(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<EventProviderOpened>(this);
EventManager::unsubscribe<EventProviderDeleted>(this);
EventManager::unsubscribe<EventImHexClosing>(this);
EventProviderOpened::unsubscribe(this);
EventProviderDeleted::unsubscribe(this);
EventImHexClosing::unsubscribe(this);
}
private:

View File

@ -128,7 +128,7 @@ namespace hex {
achievement->setUnlocked(true);
if (achievement->isUnlocked())
EventManager::post<EventAchievementUnlocked>(*achievement);
EventAchievementUnlocked::post(*achievement);
return;
}

View File

@ -809,7 +809,7 @@ namespace hex {
namespace impl {
void add(const std::string &typeName, ProviderCreationFunction creationFunction) {
(void)EventManager::subscribe<RequestCreateProvider>([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();

View File

@ -82,7 +82,7 @@ namespace hex {
id, Highlighting {region, color}
});
EventManager::post<EventHighlightingChanged>();
EventHighlightingChanged::post();
return id;
}
@ -90,7 +90,7 @@ namespace hex {
void removeBackgroundHighlight(u32 id) {
impl::getBackgroundHighlights().erase(id);
EventManager::post<EventHighlightingChanged>();
EventHighlightingChanged::post();
}
u32 addBackgroundHighlightingProvider(const impl::HighlightingFunction &function) {
@ -100,7 +100,7 @@ namespace hex {
impl::getBackgroundHighlightingFunctions().insert({ id, function });
EventManager::post<EventHighlightingChanged>();
EventHighlightingChanged::post();
return id;
}
@ -108,7 +108,7 @@ namespace hex {
void removeBackgroundHighlightingProvider(u32 id) {
impl::getBackgroundHighlightingFunctions().erase(id);
EventManager::post<EventHighlightingChanged>();
EventHighlightingChanged::post();
}
u32 addForegroundHighlight(const Region &region, color_t color) {
@ -120,7 +120,7 @@ namespace hex {
id, Highlighting {region, color}
});
EventManager::post<EventHighlightingChanged>();
EventHighlightingChanged::post();
return id;
}
@ -128,7 +128,7 @@ namespace hex {
void removeForegroundHighlight(u32 id) {
impl::getForegroundHighlights().erase(id);
EventManager::post<EventHighlightingChanged>();
EventHighlightingChanged::post();
}
u32 addForegroundHighlightingProvider(const impl::HighlightingFunction &function) {
@ -138,7 +138,7 @@ namespace hex {
impl::getForegroundHighlightingFunctions().insert({ id, function });
EventManager::post<EventHighlightingChanged>();
EventHighlightingChanged::post();
return id;
}
@ -146,7 +146,7 @@ namespace hex {
void removeForegroundHighlightingProvider(u32 id) {
impl::getForegroundHighlightingFunctions().erase(id);
EventManager::post<EventHighlightingChanged>();
EventHighlightingChanged::post();
}
static u32 tooltipId = 0;
@ -190,7 +190,7 @@ namespace hex {
}
void setSelection(const ProviderRegion &region) {
EventManager::post<RequestSelectionChange>(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<RequestAddBookmark>(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<RequestRemoveBookmark>(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<EventProviderChanged>(oldProvider, get());
EventProviderChanged::post(oldProvider, get());
}
}
@ -291,7 +291,7 @@ namespace hex {
provider->skipLoadInterface();
s_providers.push_back(provider);
EventManager::post<EventProviderCreated>(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<EventProviderClosing>(provider, &shouldClose);
EventProviderClosing::post(provider, &shouldClose);
if (!shouldClose)
return;
}
@ -350,13 +350,13 @@ namespace hex {
setCurrentProvider(0);
if (s_providers.empty())
EventManager::post<EventProviderChanged>(provider, nullptr);
EventProviderChanged::post(provider, nullptr);
provider->close();
EventManager::post<EventProviderClosed>(provider);
EventProviderClosed::post(provider);
TaskManager::runWhenTasksFinished([provider] {
EventManager::post<EventProviderDeleted>(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<RequestCreateProvider>(unlocalizedName, skipLoadInterface, select, &result);
RequestCreateProvider::post(unlocalizedName, skipLoadInterface, select, &result);
return result;
}
@ -440,16 +440,16 @@ namespace hex {
}
void closeImHex(bool noQuestions) {
EventManager::post<RequestCloseImHex>(noQuestions);
RequestCloseImHex::post(noQuestions);
}
void restartImHex() {
EventManager::post<RequestRestartImHex>();
EventManager::post<RequestCloseImHex>(false);
RequestRestartImHex::post();
RequestCloseImHex::post(false);
}
void setTaskBarProgress(TaskProgressState state, TaskProgressType type, u32 progress) {
EventManager::post<EventSetTaskBarIconState>(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<EventSettingsChanged>();
EventManager::post<EventOSThemeChanged>();
EventSettingsChanged::post();
EventOSThemeChanged::post();
}
bool usesSystemThemeDetection() {
@ -666,7 +666,7 @@ namespace hex {
break;
}
EventManager::subscribe<EventImHexClosing>([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<bool()> &function) {
EventManager::post<RequestAddInitTask>(name, async, function);
RequestAddInitTask::post(name, async, function);
}
}

View File

@ -194,7 +194,7 @@ namespace hex {
s_currTheme = name;
EventManager::post<EventThemeChanged>();
EventThemeChanged::post();
}
const std::string &ThemeManager::getImageTheme() {

View File

@ -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<EventRegionSelected>(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<EventProviderDataModified>(this, offset, size, static_cast<const u8*>(buffer));
EventProviderDataModified::post(this, offset, size, static_cast<const u8*>(buffer));
this->markDirty();
}
void Provider::save() {
EventManager::post<EventProviderSaved>(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<EventProviderSaved>(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<EventProviderDataInserted>(this, this->getActualSize(), difference);
EventProviderDataInserted::post(this, this->getActualSize(), difference);
else if (difference < 0)
EventManager::post<EventProviderDataRemoved>(this, this->getActualSize(), -difference);
EventProviderDataRemoved::post(this, this->getActualSize(), -difference);
this->markDirty();
}
void Provider::insert(u64 offset, size_t size) {
EventManager::post<EventProviderDataInserted>(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<EventProviderDataRemoved>(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)

View File

@ -101,7 +101,7 @@ namespace hex::subcommands {
}
data.erase(data.end()-1);
EventManager::post<SendMessageToMainInstance>(hex::format("command/{}", cmdName), data);
SendMessageToMainInstance::post(hex::format("command/{}", cmdName), data);
}
void registerSubCommand(const std::string &cmdName, const ForwardCommandHandler &handler) {

View File

@ -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<bool> processTasksAsync();

View File

@ -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<EventAbnormalTermination>(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<EventImHexStartupFinished>([] {
EventManager::subscribe<EventAbnormalTermination>([](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>([]{
EventImHexStartupFinished::subscribe([]{
crashCallback = saveCrashFile;
});
}

View File

@ -44,7 +44,7 @@ namespace hex::init {
ImHexApi::System::impl::setGPUVendor(reinterpret_cast<const char *>(glGetString(GL_VENDOR)));
EventManager::subscribe<RequestAddInitTask>([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();

View File

@ -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>();
EventImHexClosing::post();
EventManager::clear();
// Terminate all asynchronous tasks

View File

@ -129,7 +129,7 @@ namespace {
*/
void handleFileOpenRequest() {
if (auto path = hex::getInitialFilePath(); path.has_value()) {
EventManager::post<RequestOpenFile>(path.value());
RequestOpenFile::post(path.value());
}
}
@ -160,7 +160,7 @@ namespace {
splashWindow->startStartupTasks();
EventManager::subscribe<RequestRestartImHex>([&] {
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>([&] {
RequestRestartImHex::subscribe([&] {
shouldRestart = true;
});

View File

@ -14,10 +14,10 @@ namespace hex::messaging {
}
void setupEvents() {
EventManager::subscribe<SendMessageToMainInstance>([](const std::string &eventName, const std::vector<u8> &eventData) {
SendMessageToMainInstance::subscribe([](const std::string &eventName, const std::vector<u8> &eventData) {
log::debug("Forwarding message {} (maybe to us)", eventName);
if (ImHexApi::System::isMainInstance()) {
EventManager::subscribe<EventImHexStartupFinished>([eventName, eventData]{
EventImHexStartupFinished::subscribe([eventName, eventData]{
ImHexApi::Messaging::impl::runHandler(eventName, eventData);
});
} else {

View File

@ -67,7 +67,7 @@ namespace hex {
void Window::setupNativeWindow() {
bool themeFollowSystem = ImHexApi::System::usesSystemThemeDetection();
EventManager::subscribe<EventOSThemeChanged>(this, [themeFollowSystem] {
EventOSThemeChanged::subscribe(this, [themeFollowSystem] {
if (!themeFollowSystem) return;
std::array<char, 128> buffer = { 0 };
@ -83,11 +83,11 @@ namespace hex {
auto exitCode = WEXITSTATUS(pclose(pipe));
if (exitCode != 0) return;
EventManager::post<RequestChangeTheme>(hex::containsIgnoreCase(result, "uint32 1") ? "Light" : "Dark");
RequestChangeTheme::post(hex::containsIgnoreCase(result, "uint32 1") ? "Light" : "Dark");
});
if (themeFollowSystem)
EventManager::post<EventOSThemeChanged>();
EventOSThemeChanged::post();
}
void Window::beginNativeWindowFrame() {

View File

@ -42,17 +42,17 @@ namespace hex {
void Window::setupNativeWindow() {
bool themeFollowSystem = ImHexApi::System::usesSystemThemeDetection();
EventManager::subscribe<EventOSThemeChanged>(this, [themeFollowSystem] {
EventOSThemeChanged::subscribe(this, [themeFollowSystem] {
if (!themeFollowSystem) return;
if (!isMacosSystemDarkModeEnabled())
EventManager::post<RequestChangeTheme>("Light");
RequestChangeTheme::post("Light");
else
EventManager::post<RequestChangeTheme>("Dark");
RequestChangeTheme::post("Dark");
});
if (themeFollowSystem)
EventManager::post<EventOSThemeChanged>();
EventOSThemeChanged::post();
}
void Window::beginNativeWindowFrame() {

View File

@ -34,7 +34,7 @@ EM_JS(bool, isDarkModeEnabled, (), {
EMSCRIPTEN_KEEPALIVE
extern "C" void handleThemeChange() {
hex::EventManager::post<hex::EventOSThemeChanged>();
hex::hex::EventOSThemeChanged::post();
}
namespace hex {
@ -65,14 +65,14 @@ namespace hex {
setupThemeListener();
bool themeFollowSystem = ImHexApi::System::usesSystemThemeDetection();
EventManager::subscribe<EventOSThemeChanged>(this, [themeFollowSystem] {
EventOSThemeChanged::subscribe(this, [themeFollowSystem] {
if (!themeFollowSystem) return;
EventManager::post<RequestChangeTheme>(!isDarkModeEnabled() ? "Light" : "Dark");
RequestChangeTheme::post(!isDarkModeEnabled() ? "Light" : "Dark");
});
if (themeFollowSystem)
EventManager::post<EventOSThemeChanged>();
EventOSThemeChanged::post();
}
void Window::beginNativeWindowFrame() {

View File

@ -76,7 +76,7 @@ namespace hex {
if (lParam == 0) break;
if (LPCTSTR(lParam) == std::string_view("ImmersiveColorSet")) {
EventManager::post<EventOSThemeChanged>();
EventOSThemeChanged::post();
}
break;
@ -336,7 +336,7 @@ namespace hex {
CoCreateInstance(CLSID_TaskbarList, nullptr, CLSCTX_INPROC_SERVER, IID_ITaskbarList4, &g_taskbarList);
}
EventManager::subscribe<EventSetTaskBarIconState>([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<EventThemeChanged>([this]{
EventThemeChanged::subscribe([this]{
auto hwnd = glfwGetWin32Window(this->m_window);
static auto user32Dll = WinUniquePtr<HMODULE>(LoadLibraryA("user32.dll"), FreeLibrary);

View File

@ -86,17 +86,17 @@ namespace hex {
this->m_logoTexture = ImGuiExt::Texture(romfs::get("logo.png").span());
ContentRegistry::Settings::impl::store();
EventManager::post<EventSettingsChanged>();
EventManager::post<EventWindowInitialized>();
EventManager::post<EventImHexStartupFinished>();
EventSettingsChanged::post();
EventWindowInitialized::post();
EventImHexStartupFinished::post();
}
Window::~Window() {
EventManager::unsubscribe<EventProviderDeleted>(this);
EventManager::unsubscribe<RequestCloseImHex>(this);
EventManager::unsubscribe<RequestUpdateWindowTitle>(this);
EventManager::unsubscribe<EventAbnormalTermination>(this);
EventManager::unsubscribe<RequestOpenPopup>(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<RequestChangeTheme>("Dark");
RequestChangeTheme::post("Dark");
// Handle the close window request by telling GLFW to shut down
EventManager::subscribe<RequestCloseImHex>(this, [this](bool noQuestions) {
RequestCloseImHex::subscribe(this, [this](bool noQuestions) {
glfwSetWindowShouldClose(this->m_window, GLFW_TRUE);
if (!noQuestions)
EventManager::post<EventWindowClosing>(this->m_window);
EventWindowClosing::post(this->m_window);
});
// Handle updating the window title
EventManager::subscribe<RequestUpdateWindowTitle>(this, [this] {
RequestUpdateWindowTitle::subscribe(this, [this] {
std::string title = "ImHex";
if (ProjectFile::hasPath()) {
@ -150,7 +150,7 @@ namespace hex {
});
// Handle opening popups
EventManager::subscribe<RequestOpenPopup>(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>();
EventSearchBoxClicked::post();
}
ImGui::PopStyleVar(3);
@ -756,7 +756,7 @@ namespace hex {
}
}
EventManager::post<EventFrameBegin>();
EventFrameBegin::post();
}
void Window::frame() {
@ -828,7 +828,7 @@ namespace hex {
}
void Window::frameEnd() {
EventManager::post<EventFrameEnd>();
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<EventWindowClosing>(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<RequestOpenFile>(path);
RequestOpenFile::post(path);
}
});
@ -1224,7 +1224,7 @@ namespace hex {
for (const auto &plugin : PluginManager::getPlugins())
plugin.setImGuiContext(ImGui::GetCurrentContext());
EventManager::post<RequestInitThemeHandlers>();
RequestInitThemeHandlers::post();
}
void Window::exitGLFW() {

View File

@ -8,7 +8,7 @@ namespace hex::plugin::builtin {
class NullProvider : public hex::prv::Provider {
public:
NullProvider() {
EventManager::subscribe<EventProviderOpened>([this](auto *newProvider) {
EventProviderOpened::subscribe([this](auto *newProvider) {
if (newProvider == this)
return;
@ -17,7 +17,7 @@ namespace hex::plugin::builtin {
}
~NullProvider() override {
EventManager::unsubscribe<EventProviderOpened>(this);
EventProviderOpened::unsubscribe(this);
}
[[nodiscard]] bool isAvailable() const override { return true; }

View File

@ -10,13 +10,13 @@ namespace hex::plugin::builtin {
class ViewProvider : public hex::prv::Provider {
public:
explicit ViewProvider() {
EventManager::subscribe<EventProviderClosing>(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<EventProviderClosing>(this);
EventProviderClosing::unsubscribe(this);
}
[[nodiscard]] bool isAvailable() const override {

View File

@ -81,7 +81,7 @@ namespace hex::plugin::builtin::ui {
if (this->m_selectionChanged) {
auto selection = this->getSelection();
EventManager::post<EventRegionSelected>(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;
}
}

View File

@ -187,27 +187,27 @@ namespace hex::plugin::builtin {
void registerEvents() {
EventManager::subscribe<EventRegionSelected>([](const auto &region) {
EventRegionSelected::subscribe([](const auto &region) {
if (region.getSize() > 1)
AchievementManager::unlockAchievement("hex.builtin.achievement.hex_editor", "hex.builtin.achievement.hex_editor.select_byte.name");
});
EventManager::subscribe<EventBookmarkCreated>([](const auto&) {
EventBookmarkCreated::subscribe([](const auto&) {
AchievementManager::unlockAchievement("hex.builtin.achievement.hex_editor", "hex.builtin.achievement.hex_editor.create_bookmark.name");
});
EventManager::subscribe<EventPatchCreated>([](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<EventImHexStartupFinished>(AchievementManager::loadProgress);
EventManager::subscribe<EventAchievementUnlocked>([](const Achievement &) {
EventImHexStartupFinished::subscribe(AchievementManager::loadProgress);
EventAchievementUnlocked::subscribe([](const Achievement &) {
AchievementManager::storeProgress();
});
// Clear temporary achievements when the last provider is closed
EventManager::subscribe<EventProviderChanged>([](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();

View File

@ -24,7 +24,7 @@ namespace hex::plugin::builtin {
static wolv::net::SocketServer networkInterfaceServer(31337);
AT_FIRST_TIME {
EventManager::subscribe<EventImHexClosing>([]{
EventImHexClosing::subscribe([]{
networkInterfaceServer.shutdown();
});
};
@ -61,7 +61,7 @@ namespace hex::plugin::builtin {
}
void registerBackgroundServices() {
EventManager::subscribe<EventSettingsChanged>([]{
EventSettingsChanged::subscribe([]{
networkInterfaceServiceEnabled = bool(ContentRegistry::Settings::read("hex.builtin.setting.general", "hex.builtin.setting.general.network_interface", false));
});

View File

@ -306,7 +306,7 @@ namespace hex::plugin::builtin {
void registerCommandForwarders() {
hex::subcommands::registerSubCommand("open", [](const std::vector<std::string> &args){
for (auto &arg : args) {
EventManager::post<RequestOpenFile>(arg);
RequestOpenFile::post(arg);
}
});
}

View File

@ -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<std::string>();
EventManager::post<RequestSetPatternLanguageCode>(code);
RequestSetPatternLanguageCode::post(code);
return { };
});

View File

@ -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<EventRegionSelected>(this, [this](const auto &region) {
EventRegionSelected::subscribe(this, [this](const auto &region) {
this->m_address = region.address;
this->m_size = region.size;
});
}
~NodeDataSelection() override {
EventManager::unsubscribe<EventRegionSelected>(this);
EventRegionSelected::unsubscribe(this);
}
void process() override {

View File

@ -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<EventProviderOpened>(fileProvider);
EventProviderOpened::post(fileProvider);
}
}
}
@ -37,7 +37,7 @@ namespace hex::plugin::builtin {
void registerEventHandlers() {
static bool imhexClosing = false;
EventManager::subscribe<EventWindowClosing>([](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<EventProviderClosing>([](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<EventProviderChanged>([](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>();
RequestUpdateWindowTitle::post();
});
EventManager::subscribe<EventProviderOpened>([](hex::prv::Provider *provider) {
EventProviderOpened::subscribe([](hex::prv::Provider *provider) {
if (provider != nullptr && ImHexApi::Provider::get() == provider)
EventManager::post<RequestUpdateWindowTitle>();
EventManager::post<EventProviderChanged>(nullptr, provider);
RequestUpdateWindowTitle::post();
EventProviderChanged::post(nullptr, provider);
});
EventManager::subscribe<RequestOpenFile>(openFile);
RequestOpenFile::subscribe(openFile);
EventManager::subscribe<RequestOpenWindow>([](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<EventProviderOpened>(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<EventProviderOpened>(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<EventProviderChanged>([](auto, auto) {
EventManager::post<EventHighlightingChanged>();
EventProviderChanged::subscribe([](auto, auto) {
EventHighlightingChanged::post();
});
// Handles the provider initialization, and calls EventProviderOpened if successful
EventManager::subscribe<EventProviderCreated>([](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<EventProviderOpened>(provider);
EventProviderOpened::post(provider);
}
else if (!provider->hasLoadInterface()) {
if (!provider->open() || !provider->isAvailable()) {
@ -163,23 +163,23 @@ namespace hex::plugin::builtin {
return;
}
EventManager::post<EventProviderOpened>(provider);
EventProviderOpened::post(provider);
}
});
EventManager::subscribe<EventRegionSelected>([](const ImHexApi::HexEditor::ProviderRegion &region) {
EventRegionSelected::subscribe([](const ImHexApi::HexEditor::ProviderRegion &region) {
ImHexApi::HexEditor::impl::setCurrentSelection(region);
});
EventManager::subscribe<RequestOpenInfoPopup>([](const std::string &message) {
RequestOpenInfoPopup::subscribe([](const std::string &message) {
PopupInfo::open(message);
});
EventManager::subscribe<RequestOpenErrorPopup>([](const std::string &message) {
RequestOpenErrorPopup::subscribe([](const std::string &message) {
PopupError::open(message);
});
EventManager::subscribe<RequestOpenFatalPopup>([](const std::string &message) {
RequestOpenFatalPopup::subscribe([](const std::string &message) {
PopupFatal::open(message);
});

View File

@ -377,12 +377,12 @@ namespace hex::plugin::builtin {
if (newProvider != nullptr && !newProvider->open())
hex::ImHexApi::Provider::remove(newProvider);
else
EventManager::post<EventProviderOpened>(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<RequestOpenWindow>("Open File");
RequestOpenWindow::post("Open File");
}, noRunningTasks);
/* Open Other */
@ -596,7 +596,7 @@ namespace hex::plugin::builtin {
createExtrasMenu();
createHelpMenu();
(void)EventManager::subscribe<EventFrameEnd>([] {
(void)EventFrameEnd::subscribe([] {
if (g_demoWindowOpen) {
ImGui::ShowDemoWindow(&g_demoWindowOpen);
ImPlot::ShowDemoWindow(&g_demoWindowOpen);

View File

@ -106,8 +106,8 @@ namespace hex::plugin::builtin {
}
resetPath.release();
EventManager::post<EventProjectOpened>();
EventManager::post<RequestUpdateWindowTitle>();
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>();
RequestUpdateWindowTitle::post();
return result;
}

View File

@ -87,7 +87,7 @@ namespace hex::plugin::builtin {
if (!newProvider->open() || !newProvider->isAvailable() || !newProvider->isReadable()) {
providerWarnings[newProvider] = newProvider->getErrorMessage();
} else
EventManager::post<EventProviderOpened>(newProvider);
EventProviderOpened::post(newProvider);
}
}

View File

@ -56,10 +56,10 @@ namespace hex::plugin::builtin {
if (!fileProvider->open())
ImHexApi::Provider::remove(newProvider);
else {
EventManager::post<MovePerProviderData>(this, fileProvider);
MovePerProviderData::post(this, fileProvider);
fileProvider->markDirty(false);
EventManager::post<EventProviderOpened>(newProvider);
EventProviderOpened::post(newProvider);
ImHexApi::Provider::remove(this, true);
}
}

View File

@ -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<RequestOpenErrorPopup>(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<RequestOpenErrorPopup>(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

View File

@ -28,7 +28,7 @@ namespace hex::plugin::builtin::recent {
void registerEventHandlers() {
// Save every opened provider as a "recent" shortcut
(void)EventManager::subscribe<EventProviderOpened>([](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<EventProjectOpened>([] {
(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<EventProviderOpened>(provider);
EventProviderOpened::post(provider);
updateRecentEntries();
}

View File

@ -464,7 +464,7 @@ namespace hex::plugin::builtin {
/* Experiments */
ContentRegistry::Settings::setCategoryDescription("hex.builtin.setting.experiments", "hex.builtin.setting.experiments.description");
EventManager::subscribe<EventImHexStartupFinished>([]{
EventImHexStartupFinished::subscribe([]{
for (const auto &[name, experiment] : ContentRegistry::Experiments::impl::getExperiments()) {
ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.experiments", "", experiment.unlocalizedName, false)
.setTooltip(Lang(experiment.unlocalizedDescription))
@ -477,7 +477,7 @@ namespace hex::plugin::builtin {
});
/* Shorcuts */
EventManager::subscribe<EventImHexStartupFinished>([]{
EventImHexStartupFinished::subscribe([]{
for (const auto &shortcutEntry : ShortcutManager::getGlobalShortcuts()) {
ContentRegistry::Settings::add<KeybindingWidget>("hex.builtin.setting.shortcuts", "hex.builtin.setting.shortcuts.global", shortcutEntry.unlocalizedName, nullptr, shortcutEntry.shortcut);
}

View File

@ -17,7 +17,7 @@
namespace hex::plugin::builtin {
void registerThemeHandlers() {
EventManager::subscribe<RequestInitThemeHandlers>([] {
RequestInitThemeHandlers::subscribe([] {
{
const static ThemeManager::ColorMap ImGuiColorMap = {
{ "text", ImGuiCol_Text },
@ -253,7 +253,7 @@ namespace hex::plugin::builtin {
}
void registerStyleHandlers() {
EventManager::subscribe<RequestInitThemeHandlers>([] {
RequestInitThemeHandlers::subscribe([] {
{
auto &style = ImGui::GetStyle();
const static ThemeManager::StyleMap ImGuiStyleMap = {

View File

@ -53,7 +53,7 @@ namespace hex::plugin::builtin {
}
void addGlobalUIItems() {
EventManager::subscribe<EventFrameEnd>(drawGlobalPopups);
EventFrameEnd::subscribe(drawGlobalPopups);
}
void addFooterItems() {
@ -163,7 +163,7 @@ namespace hex::plugin::builtin {
});
static bool providerJustChanged = true;
EventManager::subscribe<EventProviderChanged>([](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<EventProviderOpened>(newProvider);
EventProviderOpened::post(newProvider);
}
// Open file
if (ImGuiExt::ToolBarButton(ICON_VS_FOLDER_OPENED, ImGuiExt::GetCustomColorVec4(ImGuiCustomCol_ToolbarBrown)))
EventManager::post<RequestOpenWindow>("Open File");
RequestOpenWindow::post("Open File");
}
ImGui::EndDisabled();

View File

@ -16,11 +16,11 @@ namespace hex::plugin::builtin {
});
// Add newly unlocked achievements to the display queue
EventManager::subscribe<EventAchievementUnlocked>(this, [this](const Achievement &achievement) {
EventAchievementUnlocked::subscribe(this, [this](const Achievement &achievement) {
this->m_achievementUnlockQueue.push_back(&achievement);
});
EventManager::subscribe<RequestOpenWindow>(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<EventAchievementUnlocked>(this);
EventAchievementUnlocked::unsubscribe(this);
}
void drawAchievement(ImDrawList *drawList, const AchievementManager::AchievementNode *node, ImVec2 position) {

View File

@ -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<RequestAddBookmark>(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<EventBookmarkCreated>(this->m_bookmarks->back().entry);
EventManager::post<EventHighlightingChanged>();
EventBookmarkCreated::post(this->m_bookmarks->back().entry);
EventHighlightingChanged::post();
});
EventManager::subscribe<RequestRemoveBookmark>([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<RequestAddBookmark>(this);
EventManager::unsubscribe<EventProviderDeleted>(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>();
EventHighlightingChanged::post();
}
void ViewBookmarks::drawContent() {
@ -372,7 +372,7 @@ namespace hex::plugin::builtin {
if (auto *viewProvider = dynamic_cast<ViewProvider*>(newProvider); viewProvider != nullptr) {
viewProvider->setProvider(region.getStartAddress(), region.getSize(), provider);
if (viewProvider->open()) {
EventManager::post<EventProviderOpened>(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>();
EventHighlightingChanged::post();
}
}
ImGui::EndChild();

View File

@ -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<RequestOpenPopup>("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<EventSearchBoxClicked>([this] {
EventManager::post<RequestOpenPopup>("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;
});

View File

@ -19,7 +19,7 @@ namespace hex::plugin::builtin {
ViewDataInspector::ViewDataInspector() : View::Window("hex.builtin.view.data_inspector.name") {
// Handle region selection
EventManager::subscribe<EventRegionSelected>(this, [this](const auto &region) {
EventRegionSelected::subscribe(this, [this](const auto &region) {
// Save current selection
if (!ImHexApi::Provider::isValid() || region == Region::Invalid()) {
@ -35,11 +35,11 @@ namespace hex::plugin::builtin {
this->m_shouldInvalidate = true;
});
EventManager::subscribe<EventProviderClosed>(this, [this](const auto*) {
EventProviderClosed::subscribe(this, [this](const auto*) {
this->m_selectedProvider = nullptr;
});
EventManager::subscribe<EventSettingsChanged>(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<std::vector<std::string>>();
this->m_hiddenValues = std::set(filterValues.begin(), filterValues.end());
@ -47,9 +47,9 @@ namespace hex::plugin::builtin {
}
ViewDataInspector::~ViewDataInspector() {
EventManager::unsubscribe<EventRegionSelected>(this);
EventManager::unsubscribe<EventProviderClosed>(this);
EventManager::unsubscribe<EventSettingsChanged>(this);
EventRegionSelected::unsubscribe(this);
EventProviderClosed::unsubscribe(this);
EventSettingsChanged::unsubscribe(this);
}

View File

@ -370,12 +370,12 @@ namespace hex::plugin::builtin {
}
});
EventManager::subscribe<EventProviderCreated>(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<EventProviderChanged>(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<EventDataChanged>(this, [this] {
EventDataChanged::subscribe(this, [this] {
ViewDataProcessor::processNodes(*this->m_workspaceStack->back());
});
@ -427,11 +427,11 @@ namespace hex::plugin::builtin {
}
ViewDataProcessor::~ViewDataProcessor() {
EventManager::unsubscribe<EventProviderCreated>(this);
EventManager::unsubscribe<EventProviderChanged>(this);
EventManager::unsubscribe<RequestChangeTheme>(this);
EventManager::unsubscribe<EventFileLoaded>(this);
EventManager::unsubscribe<EventDataChanged>(this);
EventProviderCreated::unsubscribe(this);
EventProviderChanged::unsubscribe(this);
RequestChangeTheme::unsubscribe(this);
EventFileLoaded::unsubscribe(this);
EventDataChanged::unsubscribe(this);
}

View File

@ -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<EventProviderClosed>(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<EventProviderClosed>(this);
EventProviderClosed::unsubscribe(this);
}
namespace {

View File

@ -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<EventProviderDeleted>(this, [this](const auto*) {
EventProviderDeleted::subscribe(this, [this](const auto*) {
this->m_disassembly.clear();
});
}
ViewDisassembler::~ViewDisassembler() {
EventManager::unsubscribe<EventDataChanged>(this);
EventManager::unsubscribe<EventRegionSelected>(this);
EventManager::unsubscribe<EventProviderDeleted>(this);
EventDataChanged::unsubscribe(this);
EventRegionSelected::unsubscribe(this);
EventProviderDeleted::unsubscribe(this);
}
void ViewDisassembler::disassemble() {

View File

@ -452,7 +452,7 @@ namespace hex::plugin::builtin {
}
this->m_occurrenceTree->clear();
EventManager::post<EventHighlightingChanged>();
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>();
EventHighlightingChanged::post();
});
});
}
@ -828,7 +828,7 @@ namespace hex::plugin::builtin {
this->m_sortedOccurrences->clear();
this->m_occurrenceTree->clear();
EventManager::post<EventHighlightingChanged>();
EventHighlightingChanged::post();
}
}
ImGui::EndDisabled();

View File

@ -49,7 +49,7 @@ namespace hex::plugin::builtin {
};
ViewHashes::ViewHashes() : View::Window("hex.builtin.view.hashes.name") {
EventManager::subscribe<EventRegionSelected>(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<EventRegionSelected>(this);
EventRegionSelected::unsubscribe(this);
}

View File

@ -157,14 +157,14 @@ namespace hex::plugin::builtin {
class PopupFind : public ViewHexEditor::Popup {
public:
PopupFind() {
EventManager::subscribe<EventRegionSelected>(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<EventRegionSelected>(this);
EventRegionSelected::unsubscribe(this);
}
void draw(ViewHexEditor *editor) override {
@ -636,10 +636,10 @@ namespace hex::plugin::builtin {
}
ViewHexEditor::~ViewHexEditor() {
EventManager::unsubscribe<RequestSelectionChange>(this);
EventManager::unsubscribe<EventProviderChanged>(this);
EventManager::unsubscribe<EventProviderOpened>(this);
EventManager::unsubscribe<EventHighlightingChanged>(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<RequestOpenPopup>("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<EventRegionSelected>(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<RequestSelectionChange>(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<EventRegionSelected>(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<EventProviderChanged>(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<EventRegionSelected>(ImHexApi::HexEditor::ProviderRegion{ this->getSelection(), newProvider });
EventRegionSelected::post(ImHexApi::HexEditor::ProviderRegion{ this->getSelection(), newProvider });
}
});
EventManager::subscribe<EventProviderOpened>(this, [](auto *) {
EventProviderOpened::subscribe(this, [](auto *) {
ImHexApi::HexEditor::clearSelection();
});
EventManager::subscribe<EventHighlightingChanged>(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<ViewProvider*>(newProvider); viewProvider != nullptr) {
viewProvider->setProvider(selection->getStartAddress(), selection->getSize(), selection->getProvider());
if (viewProvider->open())
EventManager::post<EventProviderOpened>(viewProvider);
EventProviderOpened::post(viewProvider);
}
},
[] { return ImHexApi::HexEditor::isSelectionValid() && ImHexApi::Provider::isValid(); });

View File

@ -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<EventProviderCreated>([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>();
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>();
EventHighlightingChanged::post();
}
ImGui::EndTable();

View File

@ -21,7 +21,7 @@ namespace hex::plugin::builtin {
using namespace hex::literals;
ViewInformation::ViewInformation() : View::Window("hex.builtin.view.information.name") {
EventManager::subscribe<EventDataChanged>(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<EventRegionSelected>(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<EventProviderDeleted>(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<EventDataChanged>(this);
EventManager::unsubscribe<EventRegionSelected>(this);
EventManager::unsubscribe<EventProviderDeleted>(this);
EventDataChanged::unsubscribe(this);
EventRegionSelected::unsubscribe(this);
EventProviderDeleted::unsubscribe(this);
}
void ViewInformation::analyze() {

View File

@ -60,11 +60,11 @@ namespace hex::plugin::builtin {
return std::nullopt;
});
EventManager::subscribe<EventProviderSaved>([](auto *) {
EventManager::post<EventHighlightingChanged>();
EventProviderSaved::subscribe([](auto *) {
EventHighlightingChanged::post();
});
EventManager::subscribe<EventProviderDataModified>(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<undo::OperationWrite>(offset, size, oldData.data(), data);
});
EventManager::subscribe<EventProviderDataInserted>(this, [](prv::Provider *provider, u64 offset, u64 size) {
EventProviderDataInserted::subscribe(this, [](prv::Provider *provider, u64 offset, u64 size) {
offset -= provider->getBaseAddress();
provider->getUndoStack().add<undo::OperationInsert>(offset, size);
});
EventManager::subscribe<EventProviderDataRemoved>(this, [](prv::Provider *provider, u64 offset, u64 size) {
EventProviderDataRemoved::subscribe(this, [](prv::Provider *provider, u64 offset, u64 size) {
offset -= provider->getBaseAddress();
provider->getUndoStack().add<undo::OperationRemove>(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>();
EventHighlightingChanged::post();
}
}
}

View File

@ -12,7 +12,7 @@ namespace hex::plugin::builtin {
this->m_patternDrawer = std::make_unique<ui::PatternDrawer>();
// Handle tree style setting changes
EventManager::subscribe<EventSettingsChanged>(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<EventProviderChanged>(this, [this](auto, auto) {
EventProviderChanged::subscribe(this, [this](auto, auto) {
this->m_patternDrawer->reset();
});
EventManager::subscribe<EventPatternEvaluating>(this, [this]{
EventPatternEvaluating::subscribe(this, [this]{
this->m_patternDrawer->reset();
});
EventManager::subscribe<EventPatternExecuted>(this, [this](auto){
EventPatternExecuted::subscribe(this, [this](auto){
this->m_patternDrawer->reset();
});
@ -38,10 +38,10 @@ namespace hex::plugin::builtin {
}
ViewPatternData::~ViewPatternData() {
EventManager::unsubscribe<EventSettingsChanged>(this);
EventManager::unsubscribe<EventProviderChanged>(this);
EventManager::unsubscribe<EventPatternEvaluating>(this);
EventManager::unsubscribe<EventPatternExecuted>(this);
EventSettingsChanged::unsubscribe(this);
EventProviderChanged::unsubscribe(this);
EventPatternEvaluating::unsubscribe(this);
EventPatternExecuted::unsubscribe(this);
}
void ViewPatternData::drawContent() {

View File

@ -144,10 +144,10 @@ namespace hex::plugin::builtin {
}
ViewPatternEditor::~ViewPatternEditor() {
EventManager::unsubscribe<RequestSetPatternLanguageCode>(this);
EventManager::unsubscribe<EventFileLoaded>(this);
EventManager::unsubscribe<EventProviderChanged>(this);
EventManager::unsubscribe<EventProviderClosed>(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<EventPatternEditorChanged>(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>();
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>();
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>();
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<EventPatternExecuted>(code);
EventPatternExecuted::post(code);
});
});
}
void ViewPatternEditor::registerEvents() {
EventManager::subscribe<RequestLoadPatternLanguageFile>(this, [this](const std::fs::path &path) {
RequestLoadPatternLanguageFile::subscribe(this, [this](const std::fs::path &path) {
this->loadPatternFile(path, ImHexApi::Provider::get());
});
EventManager::subscribe<RequestSavePatternLanguageFile>(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<RequestSetPatternLanguageCode>(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<EventSettingsChanged>(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<EventProviderOpened>(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<ui::PatternDrawer>();
});
EventManager::subscribe<EventProviderChanged>(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<EventProviderClosed>(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<RequestSetPatternLanguageCode>(file.readString());
RequestSetPatternLanguageCode::post(file.readString());
return true;
} else {
return false;

View File

@ -6,7 +6,7 @@
namespace hex::plugin::builtin {
ViewProviderSettings::ViewProviderSettings() : View::Modal("hex.builtin.view.provider_settings.name") {
EventManager::subscribe<EventProviderCreated>(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<EventProviderCreated>(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<EventProviderOpened>(provider);
EventProviderOpened::post(provider);
this->getWindowOpenState() = false;
ImGui::CloseCurrentPopup();

View File

@ -11,7 +11,7 @@ namespace hex::plugin::builtin {
ViewSettings::ViewSettings() : View::Modal("hex.builtin.view.settings.name") {
// Handle window open requests
EventManager::subscribe<RequestOpenWindow>(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<RequestOpenWindow>(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>();
EventSettingsChanged::post();
widget->onChanged();
// Request a restart if the setting requires it

View File

@ -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<EventStoreContentRemoved>(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<EventStoreContentDownloaded>(this->m_downloadPath.parent_path() / this->m_downloadPath.stem());
EventStoreContentDownloaded::post(this->m_downloadPath.parent_path() / this->m_downloadPath.stem());
} else {
EventManager::post<EventStoreContentDownloaded>(this->m_downloadPath);
EventStoreContentDownloaded::post(this->m_downloadPath);
}
category.downloadCallback();

View File

@ -41,7 +41,7 @@ namespace hex::plugin::builtin {
if (ImGui::ColorEdit4(colorName.c_str(), reinterpret_cast<float*>(&color.Value), ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaBar | ImGuiColorEditFlags_AlphaPreviewHalf)) {
// Update the color value
handler.setFunction(colorId, color);
EventManager::post<EventThemeChanged>();
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<float*>(&value); floatValue != nullptr) {
if (ImGui::SliderFloat(styleName.c_str(), *floatValue, min, max, "%.1f")) {
EventManager::post<EventThemeChanged>();
EventThemeChanged::post();
}
} else if (auto vecValue = std::get_if<ImVec2*>(&value); vecValue != nullptr) {
if (ImGui::SliderFloat2(styleName.c_str(), &(*vecValue)->x, min, max, "%.1f")) {
EventManager::post<EventThemeChanged>();
EventThemeChanged::post();
}
}
}

View File

@ -187,12 +187,12 @@ namespace hex::plugin::builtin {
if (newProvider != nullptr && !newProvider->open())
hex::ImHexApi::Provider::remove(newProvider);
else
EventManager::post<EventProviderOpened>(newProvider);
EventProviderOpened::post(newProvider);
}
if (ImGuiExt::IconHyperlink(ICON_VS_GO_TO_FILE, "hex.builtin.welcome.start.open_file"_lang))
EventManager::post<RequestOpenWindow>("Open File");
RequestOpenWindow::post("Open File");
if (ImGuiExt::IconHyperlink(ICON_VS_NOTEBOOK, "hex.builtin.welcome.start.open_project"_lang))
EventManager::post<RequestOpenWindow>("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<RequestOpenWindow>("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<RequestOpenWindow>("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<EventProviderOpened>(provider);
EventProviderOpened::post(provider);
}
}
@ -462,15 +462,15 @@ namespace hex::plugin::builtin {
recent::registerEventHandlers();
recent::updateRecentEntries();
(void)EventManager::subscribe<EventFrameBegin>(drawWelcomeScreen);
(void)EventFrameBegin::subscribe(drawWelcomeScreen);
// Sets a background when they are no views
(void)EventManager::subscribe<EventFrameBegin>([]{
(void)EventFrameBegin::subscribe([]{
if (ImHexApi::Provider::isValid() && !isAnyViewOpen())
drawNoViewsBackground();
});
(void)EventManager::subscribe<EventSettingsChanged>([] {
(void)EventSettingsChanged::subscribe([] {
{
auto theme = ContentRegistry::Settings::read("hex.builtin.setting.interface", "hex.builtin.setting.interface.color", ThemeManager::NativeTheme).get<std::string>();
@ -478,7 +478,7 @@ namespace hex::plugin::builtin {
static std::string lastTheme;
if (theme != lastTheme) {
EventManager::post<RequestChangeTheme>(theme);
RequestChangeTheme::post(theme);
lastTheme = theme;
}
}
@ -500,7 +500,7 @@ namespace hex::plugin::builtin {
}
});
(void)EventManager::subscribe<RequestChangeTheme>([](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<EventProviderCreated>([](auto) {
EventProviderCreated::subscribe([](auto) {
if (!isAnyViewOpen())
loadDefaultLayout();
});
EventManager::subscribe<EventWindowInitialized>([] {
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<EventProviderChanged>([](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>();
RequestUpdateWindowTitle::post();
}
});
@ -582,7 +582,7 @@ namespace hex::plugin::builtin {
} else {
ProjectFile::setPath("");
}
EventManager::post<RequestUpdateWindowTitle>();
RequestUpdateWindowTitle::post();
}else{
if (hasProject) {
ProjectFile::setPath(crashFileData["project"].get<std::string>());

View File

@ -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<EventSettingsChanged>(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<EventSettingsChanged>(this);
EventSettingsChanged::unsubscribe(this);
}
constexpr static u16 getByteColumnSeparatorCount(u16 columnCount) {

View File

@ -114,7 +114,7 @@ private:
};
SCRIPT_API(void showMessageBox, const char *message) {
hex::EventManager::post<hex::RequestOpenInfoPopup>(message);
hex::RequestOpenInfoPopup::post(message);
}
SCRIPT_API(void showInputTextBox, const char *title, const char *message, char *buffer, u32 bufferSize) {

View File

@ -16,7 +16,7 @@ namespace hex::plugin::windows {
void addFooterItems() {
static bool showResourceUsage = true;
EventManager::subscribe<EventSettingsChanged>([]{
EventSettingsChanged::subscribe([]{
showResourceUsage = ContentRegistry::Settings::read("hex.builtin.setting.interface", "hex.builtin.setting.interface.show_resource_usage", true);
});

View File

@ -23,7 +23,7 @@ namespace hex::plugin::windows {
static void detectSystemTheme() {
// Setup system theme change detector
EventManager::subscribe<EventOSThemeChanged>([] {
EventOSThemeChanged::subscribe([] {
bool themeFollowSystem = ContentRegistry::Settings::read("hex.builtin.setting.interface", "hex.builtin.setting.interface.color", ThemeManager::NativeTheme).get<std::string>() == ThemeManager::NativeTheme;
if (!themeFollowSystem)
return;
@ -35,7 +35,7 @@ static void detectSystemTheme() {
auto error = RegQueryValueEx(hkey, "AppsUseLightTheme", nullptr, nullptr, reinterpret_cast<LPBYTE>(&value), &size);
if (error == ERROR_SUCCESS) {
EventManager::post<RequestChangeTheme>(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>([=] {
EventWindowInitialized::subscribe([=] {
bool themeFollowSystem = ContentRegistry::Settings::read("hex.builtin.setting.interface", "hex.builtin.setting.interface.color", ThemeManager::NativeTheme).get<std::string>() == ThemeManager::NativeTheme;
if (themeFollowSystem)
EventManager::post<EventOSThemeChanged>();
EventOSThemeChanged::post();
});
}

View File

@ -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<RequestOpenErrorPopup>("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<size_t>(this->m_selectedPort) >= this->m_comPorts.size()) {
EventManager::post<RequestOpenErrorPopup>("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(),