1
0
mirror of synced 2024-11-12 02:00:52 +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

@ -18,7 +18,13 @@
constexpr static auto Id = [] { return hex::impl::EventId(event_name_string); }(); \ constexpr static auto Id = [] { return hex::impl::EventId(event_name_string); }(); \
constexpr static auto ShouldLog = (should_log); \ constexpr static auto ShouldLog = (should_log); \
explicit event_name(Callback func) noexcept : Event(std::move(func)) { } \ 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(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__) #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; [[nodiscard]] virtual std::string getName() const = 0;
void resize(size_t newSize); void resize(u64 newSize);
void insert(u64 offset, size_t size); void insert(u64 offset, u64 size);
void remove(u64 offset, size_t size); void remove(u64 offset, u64 size);
virtual void resizeRaw(size_t newSize) { hex::unused(newSize); } virtual void resizeRaw(u64 newSize) { hex::unused(newSize); }
virtual void insertRaw(u64 offset, size_t size) { hex::unused(offset, size); } virtual void insertRaw(u64 offset, u64 size) { hex::unused(offset, size); }
virtual void removeRaw(u64 offset, size_t size) { hex::unused(offset, size); } virtual void removeRaw(u64 offset, u64 size) { hex::unused(offset, size); }
virtual void save(); virtual void save();
virtual void saveAs(const std::fs::path &path); 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; void applyOverlays(u64 offset, void *buffer, size_t size) const;
[[nodiscard]] const std::list<std::unique_ptr<Overlay>> &getOverlays() const; [[nodiscard]] const std::list<std::unique_ptr<Overlay>> &getOverlays() const;
[[nodiscard]] size_t getPageSize() const; [[nodiscard]] u64 getPageSize() const;
void setPageSize(size_t pageSize); void setPageSize(u64 pageSize);
[[nodiscard]] u32 getPageCount() const; [[nodiscard]] u32 getPageCount() const;
[[nodiscard]] u32 getCurrentPage() const; [[nodiscard]] u32 getCurrentPage() const;
@ -255,7 +255,7 @@ namespace hex::prv {
std::string m_errorMessage; std::string m_errorMessage;
size_t m_pageSize = MaxPageSize; u64 m_pageSize = MaxPageSize;
}; };
} }

View File

@ -73,20 +73,20 @@ namespace hex {
private: private:
void onCreate() { void onCreate() {
EventManager::subscribe<EventProviderOpened>(this, [this](prv::Provider *provider) { EventProviderOpened::subscribe(this, [this](prv::Provider *provider) {
this->m_data.emplace(provider, T()); 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); this->m_data.erase(provider);
}); });
EventManager::subscribe<EventImHexClosing>(this, [this] { EventImHexClosing::subscribe(this, [this] {
this->m_data.clear(); this->m_data.clear();
}); });
// Moves the data of this PerProvider instance from one provider to another // 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) // Get the value from the old provider, (removes it from the map)
auto node = m_data.extract(from); auto node = m_data.extract(from);
@ -103,9 +103,9 @@ namespace hex {
} }
void onDestroy() { void onDestroy() {
EventManager::unsubscribe<EventProviderOpened>(this); EventProviderOpened::unsubscribe(this);
EventManager::unsubscribe<EventProviderDeleted>(this); EventProviderDeleted::unsubscribe(this);
EventManager::unsubscribe<EventImHexClosing>(this); EventImHexClosing::unsubscribe(this);
} }
private: private:

View File

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

View File

@ -809,7 +809,7 @@ namespace hex {
namespace impl { namespace impl {
void add(const std::string &typeName, ProviderCreationFunction creationFunction) { 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; if (name != expectedName) return;
prv::Provider *newProvider = creationFunction(); prv::Provider *newProvider = creationFunction();

View File

@ -82,7 +82,7 @@ namespace hex {
id, Highlighting {region, color} id, Highlighting {region, color}
}); });
EventManager::post<EventHighlightingChanged>(); EventHighlightingChanged::post();
return id; return id;
} }
@ -90,7 +90,7 @@ namespace hex {
void removeBackgroundHighlight(u32 id) { void removeBackgroundHighlight(u32 id) {
impl::getBackgroundHighlights().erase(id); impl::getBackgroundHighlights().erase(id);
EventManager::post<EventHighlightingChanged>(); EventHighlightingChanged::post();
} }
u32 addBackgroundHighlightingProvider(const impl::HighlightingFunction &function) { u32 addBackgroundHighlightingProvider(const impl::HighlightingFunction &function) {
@ -100,7 +100,7 @@ namespace hex {
impl::getBackgroundHighlightingFunctions().insert({ id, function }); impl::getBackgroundHighlightingFunctions().insert({ id, function });
EventManager::post<EventHighlightingChanged>(); EventHighlightingChanged::post();
return id; return id;
} }
@ -108,7 +108,7 @@ namespace hex {
void removeBackgroundHighlightingProvider(u32 id) { void removeBackgroundHighlightingProvider(u32 id) {
impl::getBackgroundHighlightingFunctions().erase(id); impl::getBackgroundHighlightingFunctions().erase(id);
EventManager::post<EventHighlightingChanged>(); EventHighlightingChanged::post();
} }
u32 addForegroundHighlight(const Region &region, color_t color) { u32 addForegroundHighlight(const Region &region, color_t color) {
@ -120,7 +120,7 @@ namespace hex {
id, Highlighting {region, color} id, Highlighting {region, color}
}); });
EventManager::post<EventHighlightingChanged>(); EventHighlightingChanged::post();
return id; return id;
} }
@ -128,7 +128,7 @@ namespace hex {
void removeForegroundHighlight(u32 id) { void removeForegroundHighlight(u32 id) {
impl::getForegroundHighlights().erase(id); impl::getForegroundHighlights().erase(id);
EventManager::post<EventHighlightingChanged>(); EventHighlightingChanged::post();
} }
u32 addForegroundHighlightingProvider(const impl::HighlightingFunction &function) { u32 addForegroundHighlightingProvider(const impl::HighlightingFunction &function) {
@ -138,7 +138,7 @@ namespace hex {
impl::getForegroundHighlightingFunctions().insert({ id, function }); impl::getForegroundHighlightingFunctions().insert({ id, function });
EventManager::post<EventHighlightingChanged>(); EventHighlightingChanged::post();
return id; return id;
} }
@ -146,7 +146,7 @@ namespace hex {
void removeForegroundHighlightingProvider(u32 id) { void removeForegroundHighlightingProvider(u32 id) {
impl::getForegroundHighlightingFunctions().erase(id); impl::getForegroundHighlightingFunctions().erase(id);
EventManager::post<EventHighlightingChanged>(); EventHighlightingChanged::post();
} }
static u32 tooltipId = 0; static u32 tooltipId = 0;
@ -190,7 +190,7 @@ namespace hex {
} }
void setSelection(const ProviderRegion &region) { void setSelection(const ProviderRegion &region) {
EventManager::post<RequestSelectionChange>(region); RequestSelectionChange::post(region);
} }
void setSelection(u64 address, size_t size, prv::Provider *provider) { 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 add(Region region, const std::string &name, const std::string &comment, u32 color) {
u64 id = 0; u64 id = 0;
EventManager::post<RequestAddBookmark>(region, name, comment, color, &id); RequestAddBookmark::post(region, name, comment, color, &id);
return id; return id;
} }
@ -214,7 +214,7 @@ namespace hex {
} }
void remove(u64 id) { 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) { if (index < s_providers.size() && s_currentProvider != index) {
auto oldProvider = get(); auto oldProvider = get();
s_currentProvider = index; s_currentProvider = index;
EventManager::post<EventProviderChanged>(oldProvider, get()); EventProviderChanged::post(oldProvider, get());
} }
} }
@ -291,7 +291,7 @@ namespace hex {
provider->skipLoadInterface(); provider->skipLoadInterface();
s_providers.push_back(provider); s_providers.push_back(provider);
EventManager::post<EventProviderCreated>(provider); EventProviderCreated::post(provider);
if (select || s_providers.size() == 1) if (select || s_providers.size() == 1)
setCurrentProvider(s_providers.size() - 1); setCurrentProvider(s_providers.size() - 1);
@ -308,7 +308,7 @@ namespace hex {
impl::s_closingProviders.push_back(provider); impl::s_closingProviders.push_back(provider);
bool shouldClose = true; bool shouldClose = true;
EventManager::post<EventProviderClosing>(provider, &shouldClose); EventProviderClosing::post(provider, &shouldClose);
if (!shouldClose) if (!shouldClose)
return; return;
} }
@ -350,13 +350,13 @@ namespace hex {
setCurrentProvider(0); setCurrentProvider(0);
if (s_providers.empty()) if (s_providers.empty())
EventManager::post<EventProviderChanged>(provider, nullptr); EventProviderChanged::post(provider, nullptr);
provider->close(); provider->close();
EventManager::post<EventProviderClosed>(provider); EventProviderClosed::post(provider);
TaskManager::runWhenTasksFinished([provider] { TaskManager::runWhenTasksFinished([provider] {
EventManager::post<EventProviderDeleted>(provider); EventProviderDeleted::post(provider);
std::erase(impl::s_closingProviders, provider); std::erase(impl::s_closingProviders, provider);
delete provider; delete provider;
}); });
@ -364,7 +364,7 @@ namespace hex {
prv::Provider* createProvider(const std::string &unlocalizedName, bool skipLoadInterface, bool select) { prv::Provider* createProvider(const std::string &unlocalizedName, bool skipLoadInterface, bool select) {
prv::Provider* result = nullptr; prv::Provider* result = nullptr;
EventManager::post<RequestCreateProvider>(unlocalizedName, skipLoadInterface, select, &result); RequestCreateProvider::post(unlocalizedName, skipLoadInterface, select, &result);
return result; return result;
} }
@ -440,16 +440,16 @@ namespace hex {
} }
void closeImHex(bool noQuestions) { void closeImHex(bool noQuestions) {
EventManager::post<RequestCloseImHex>(noQuestions); RequestCloseImHex::post(noQuestions);
} }
void restartImHex() { void restartImHex() {
EventManager::post<RequestRestartImHex>(); RequestRestartImHex::post();
EventManager::post<RequestCloseImHex>(false); RequestCloseImHex::post(false);
} }
void setTaskBarProgress(TaskProgressState state, TaskProgressType type, u32 progress) { 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) { void enableSystemThemeDetection(bool enabled) {
s_systemThemeDetection = enabled; s_systemThemeDetection = enabled;
EventManager::post<EventSettingsChanged>(); EventSettingsChanged::post();
EventManager::post<EventOSThemeChanged>(); EventOSThemeChanged::post();
} }
bool usesSystemThemeDetection() { bool usesSystemThemeDetection() {
@ -666,7 +666,7 @@ namespace hex {
break; break;
} }
EventManager::subscribe<EventImHexClosing>([executablePath, updateTypeString] { EventImHexClosing::subscribe([executablePath, updateTypeString] {
hex::executeCommand( hex::executeCommand(
hex::format("{} {}", hex::format("{} {}",
wolv::util::toUTF8String(executablePath), wolv::util::toUTF8String(executablePath),
@ -681,7 +681,7 @@ namespace hex {
} }
void addStartupTask(const std::string &name, bool async, const std::function<bool()> &function) { 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; s_currTheme = name;
EventManager::post<EventThemeChanged>(); EventThemeChanged::post();
} }
const std::string &ThemeManager::getImageTheme() { const std::string &ThemeManager::getImageTheme() {

View File

@ -32,12 +32,10 @@ namespace hex::prv {
this->m_overlays.clear(); this->m_overlays.clear();
if (auto selection = ImHexApi::HexEditor::getSelection(); selection.has_value() && selection->provider == this) 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) { void Provider::read(u64 offset, void *buffer, size_t size, bool overlays) {
hex::unused(overlays);
this->readRaw(offset - this->getBaseAddress(), buffer, size); this->readRaw(offset - this->getBaseAddress(), buffer, size);
if (overlays) if (overlays)
@ -45,12 +43,12 @@ namespace hex::prv {
} }
void Provider::write(u64 offset, const void *buffer, size_t size) { 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(); this->markDirty();
} }
void Provider::save() { void Provider::save() {
EventManager::post<EventProviderSaved>(this); EventProviderSaved::post(this);
} }
void Provider::saveAs(const std::fs::path &path) { void Provider::saveAs(const std::fs::path &path) {
wolv::io::File file(path, wolv::io::File::Mode::Create); wolv::io::File file(path, wolv::io::File::Mode::Create);
@ -66,29 +64,29 @@ namespace hex::prv {
file.writeBuffer(buffer.data(), bufferSize); 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(); i64 difference = newSize - this->getActualSize();
if (difference > 0) if (difference > 0)
EventManager::post<EventProviderDataInserted>(this, this->getActualSize(), difference); EventProviderDataInserted::post(this, this->getActualSize(), difference);
else if (difference < 0) else if (difference < 0)
EventManager::post<EventProviderDataRemoved>(this, this->getActualSize(), -difference); EventProviderDataRemoved::post(this, this->getActualSize(), -difference);
this->markDirty(); this->markDirty();
} }
void Provider::insert(u64 offset, size_t size) { void Provider::insert(u64 offset, u64 size) {
EventManager::post<EventProviderDataInserted>(this, offset, size); EventProviderDataInserted::post(this, offset, size);
this->markDirty(); this->markDirty();
} }
void Provider::remove(u64 offset, size_t size) { void Provider::remove(u64 offset, u64 size) {
EventManager::post<EventProviderDataRemoved>(this, offset, size); EventProviderDataRemoved::post(this, offset, size);
this->markDirty(); this->markDirty();
} }
@ -120,11 +118,11 @@ namespace hex::prv {
} }
size_t Provider::getPageSize() const { u64 Provider::getPageSize() const {
return this->m_pageSize; return this->m_pageSize;
} }
void Provider::setPageSize(size_t pageSize) { void Provider::setPageSize(u64 pageSize) {
if (pageSize > MaxPageSize) if (pageSize > MaxPageSize)
pageSize = MaxPageSize; pageSize = MaxPageSize;
if (pageSize == 0) if (pageSize == 0)

View File

@ -101,7 +101,7 @@ namespace hex::subcommands {
} }
data.erase(data.end()-1); 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) { void registerSubCommand(const std::string &cmdName, const ForwardCommandHandler &handler) {

View File

@ -23,7 +23,7 @@ namespace hex::init {
bool async; bool async;
}; };
enum FrameResult{ success, failure, wait }; enum FrameResult{ Success, Failure, Running };
struct Highlight { struct Highlight {
ImVec2 start; ImVec2 start;
@ -59,8 +59,8 @@ namespace hex::init {
void initImGui(); void initImGui();
void initMyself(); void initMyself();
void exitGLFW(); void exitGLFW() const;
void exitImGui(); void exitImGui() const;
std::future<bool> processTasksAsync(); std::future<bool> processTasksAsync();

View File

@ -73,7 +73,7 @@ namespace hex::crash {
extern "C" void triggerSafeShutdown(int signalNumber = 0) { extern "C" void triggerSafeShutdown(int signalNumber = 0) {
// Trigger an event so that plugins can handle crashes // Trigger an event so that plugins can handle crashes
EventManager::post<EventAbnormalTermination>(signalNumber); EventAbnormalTermination::post(signalNumber);
// Run exit tasks // Run exit tasks
init::runExitTasks(); init::runExitTasks();
@ -174,8 +174,8 @@ namespace hex::crash {
// because this save is responsible for telling us which files // because this save is responsible for telling us which files
// were opened in case there wasn't a project // were opened in case there wasn't a project
// Only do it when ImHex has finished its loading // Only do it when ImHex has finished its loading
EventManager::subscribe<EventImHexStartupFinished>([] { EventImHexStartupFinished::subscribe([] {
EventManager::subscribe<EventAbnormalTermination>([](int) { EventAbnormalTermination::subscribe([](int) {
// Save ImGui settings // Save ImGui settings
auto imguiSettingsPath = hex::getImGuiSettingsPath(); auto imguiSettingsPath = hex::getImGuiSettingsPath();
if (!imguiSettingsPath.empty()) if (!imguiSettingsPath.empty())
@ -192,7 +192,7 @@ namespace hex::crash {
}); });
// Change the crash callback when ImHex has finished startup // Change the crash callback when ImHex has finished startup
EventManager::subscribe<EventImHexStartupFinished>([]{ EventImHexStartupFinished::subscribe([]{
crashCallback = saveCrashFile; crashCallback = saveCrashFile;
}); });
} }

View File

@ -44,7 +44,7 @@ namespace hex::init {
ImHexApi::System::impl::setGPUVendor(reinterpret_cast<const char *>(glGetString(GL_VENDOR))); 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 }); 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 // 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.wait_for(0s) == std::future_status::ready) {
if (this->tasksSucceeded.get()) { if (this->tasksSucceeded.get()) {
log::debug("All tasks finished with success !"); log::debug("All tasks finished successfully!");
return FrameResult::success; return FrameResult::Success;
} else { } else {
log::warn("All tasks finished, but some failed"); log::warn("All tasks finished, but some failed");
return FrameResult::failure; return FrameResult::Failure;
} }
} }
return FrameResult::wait; return FrameResult::Running;
} }
bool WindowSplash::loop() { bool WindowSplash::loop() {
// Splash window rendering loop // Splash window rendering loop
while (true) { while (true) {
auto res = this->fullFrame(); auto frameResult = this->fullFrame();
if (res == FrameResult::success) return true;
else if (res == FrameResult::failure) return false; if (frameResult == FrameResult::Success)
return true;
else if (frameResult == FrameResult::Failure)
return false;
} }
} }
@ -457,10 +460,10 @@ namespace hex::init {
u32 lastPos = 0; u32 lastPos = 0;
u32 lastCount = 0; u32 lastCount = 0;
for (auto &highlight : this->highlights) { for (auto &highlight : this->highlights) {
auto newPos = lastPos + lastCount + (rng() % 40); u32 newPos = lastPos + lastCount + (rng() % 40);
auto newCount = (rng() % 7) + 3; u32 newCount = (rng() % 7) + 3;
highlight.start.x = newPos % 13; highlight.start.x = float(newPos % 13);
highlight.start.y = newPos / 13; highlight.start.y = float(newPos / 13);
highlight.count = newCount; highlight.count = newCount;
{ {
@ -483,12 +486,12 @@ namespace hex::init {
this->tasksSucceeded = processTasksAsync(); this->tasksSucceeded = processTasksAsync();
} }
void WindowSplash::exitGLFW() { void WindowSplash::exitGLFW() const {
glfwDestroyWindow(this->m_window); glfwDestroyWindow(this->m_window);
glfwTerminate(); glfwTerminate();
} }
void WindowSplash::exitImGui() { void WindowSplash::exitImGui() const {
ImGui_ImplOpenGL3_Shutdown(); ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown(); ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext(); 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 // 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 // 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(); EventManager::clear();
// Terminate all asynchronous tasks // Terminate all asynchronous tasks

View File

@ -129,7 +129,7 @@ namespace {
*/ */
void handleFileOpenRequest() { void handleFileOpenRequest() {
if (auto path = hex::getInitialFilePath(); path.has_value()) { if (auto path = hex::getInitialFilePath(); path.has_value()) {
EventManager::post<RequestOpenFile>(path.value()); RequestOpenFile::post(path.value());
} }
} }
@ -160,7 +160,7 @@ namespace {
splashWindow->startStartupTasks(); splashWindow->startStartupTasks();
EventManager::subscribe<RequestRestartImHex>([&] { RequestRestartImHex::subscribe([&] {
MAIN_THREAD_EM_ASM({ MAIN_THREAD_EM_ASM({
location.reload(); location.reload();
}); });
@ -214,7 +214,7 @@ namespace {
do { do {
// Register an event handler that will make ImHex restart when requested // Register an event handler that will make ImHex restart when requested
shouldRestart = false; shouldRestart = false;
EventManager::subscribe<RequestRestartImHex>([&] { RequestRestartImHex::subscribe([&] {
shouldRestart = true; shouldRestart = true;
}); });

View File

@ -14,10 +14,10 @@ namespace hex::messaging {
} }
void setupEvents() { 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); log::debug("Forwarding message {} (maybe to us)", eventName);
if (ImHexApi::System::isMainInstance()) { if (ImHexApi::System::isMainInstance()) {
EventManager::subscribe<EventImHexStartupFinished>([eventName, eventData]{ EventImHexStartupFinished::subscribe([eventName, eventData]{
ImHexApi::Messaging::impl::runHandler(eventName, eventData); ImHexApi::Messaging::impl::runHandler(eventName, eventData);
}); });
} else { } else {

View File

@ -67,7 +67,7 @@ namespace hex {
void Window::setupNativeWindow() { void Window::setupNativeWindow() {
bool themeFollowSystem = ImHexApi::System::usesSystemThemeDetection(); bool themeFollowSystem = ImHexApi::System::usesSystemThemeDetection();
EventManager::subscribe<EventOSThemeChanged>(this, [themeFollowSystem] { EventOSThemeChanged::subscribe(this, [themeFollowSystem] {
if (!themeFollowSystem) return; if (!themeFollowSystem) return;
std::array<char, 128> buffer = { 0 }; std::array<char, 128> buffer = { 0 };
@ -83,11 +83,11 @@ namespace hex {
auto exitCode = WEXITSTATUS(pclose(pipe)); auto exitCode = WEXITSTATUS(pclose(pipe));
if (exitCode != 0) return; 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) if (themeFollowSystem)
EventManager::post<EventOSThemeChanged>(); EventOSThemeChanged::post();
} }
void Window::beginNativeWindowFrame() { void Window::beginNativeWindowFrame() {

View File

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

View File

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

View File

@ -76,7 +76,7 @@ namespace hex {
if (lParam == 0) break; if (lParam == 0) break;
if (LPCTSTR(lParam) == std::string_view("ImmersiveColorSet")) { if (LPCTSTR(lParam) == std::string_view("ImmersiveColorSet")) {
EventManager::post<EventOSThemeChanged>(); EventOSThemeChanged::post();
} }
break; break;
@ -336,7 +336,7 @@ namespace hex {
CoCreateInstance(CLSID_TaskbarList, nullptr, CLSCTX_INPROC_SERVER, IID_ITaskbarList4, &g_taskbarList); 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; using enum ImHexApi::System::TaskProgressState;
switch (ImHexApi::System::TaskProgressState(state)) { switch (ImHexApi::System::TaskProgressState(state)) {
case Reset: case Reset:
@ -379,7 +379,7 @@ namespace hex {
ULONG dataSize; ULONG dataSize;
}; };
EventManager::subscribe<EventThemeChanged>([this]{ EventThemeChanged::subscribe([this]{
auto hwnd = glfwGetWin32Window(this->m_window); auto hwnd = glfwGetWin32Window(this->m_window);
static auto user32Dll = WinUniquePtr<HMODULE>(LoadLibraryA("user32.dll"), FreeLibrary); 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()); this->m_logoTexture = ImGuiExt::Texture(romfs::get("logo.png").span());
ContentRegistry::Settings::impl::store(); ContentRegistry::Settings::impl::store();
EventManager::post<EventSettingsChanged>(); EventSettingsChanged::post();
EventManager::post<EventWindowInitialized>(); EventWindowInitialized::post();
EventManager::post<EventImHexStartupFinished>(); EventImHexStartupFinished::post();
} }
Window::~Window() { Window::~Window() {
EventManager::unsubscribe<EventProviderDeleted>(this); EventProviderDeleted::unsubscribe(this);
EventManager::unsubscribe<RequestCloseImHex>(this); RequestCloseImHex::unsubscribe(this);
EventManager::unsubscribe<RequestUpdateWindowTitle>(this); RequestUpdateWindowTitle::unsubscribe(this);
EventManager::unsubscribe<EventAbnormalTermination>(this); EventAbnormalTermination::unsubscribe(this);
EventManager::unsubscribe<RequestOpenPopup>(this); RequestOpenPopup::unsubscribe(this);
this->exitImGui(); this->exitImGui();
this->exitGLFW(); this->exitGLFW();
@ -104,18 +104,18 @@ namespace hex {
void Window::registerEventHandlers() { void Window::registerEventHandlers() {
// Initialize default theme // Initialize default theme
EventManager::post<RequestChangeTheme>("Dark"); RequestChangeTheme::post("Dark");
// Handle the close window request by telling GLFW to shut down // 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); glfwSetWindowShouldClose(this->m_window, GLFW_TRUE);
if (!noQuestions) if (!noQuestions)
EventManager::post<EventWindowClosing>(this->m_window); EventWindowClosing::post(this->m_window);
}); });
// Handle updating the window title // Handle updating the window title
EventManager::subscribe<RequestUpdateWindowTitle>(this, [this] { RequestUpdateWindowTitle::subscribe(this, [this] {
std::string title = "ImHex"; std::string title = "ImHex";
if (ProjectFile::hasPath()) { if (ProjectFile::hasPath()) {
@ -150,7 +150,7 @@ namespace hex {
}); });
// Handle opening popups // Handle opening popups
EventManager::subscribe<RequestOpenPopup>(this, [this](auto name) { RequestOpenPopup::subscribe(this, [this](auto name) {
std::scoped_lock lock(this->m_popupMutex); std::scoped_lock lock(this->m_popupMutex);
this->m_popupsToOpen.push_back(name); this->m_popupsToOpen.push_back(name);
@ -325,7 +325,7 @@ namespace hex {
ImGui::SetCursorPos(searchBoxPos); ImGui::SetCursorPos(searchBoxPos);
if (ImGui::Button(this->m_windowTitle.c_str(), searchBoxSize)) { if (ImGui::Button(this->m_windowTitle.c_str(), searchBoxSize)) {
EventManager::post<EventSearchBoxClicked>(); EventSearchBoxClicked::post();
} }
ImGui::PopStyleVar(3); ImGui::PopStyleVar(3);
@ -756,7 +756,7 @@ namespace hex {
} }
} }
EventManager::post<EventFrameBegin>(); EventFrameBegin::post();
} }
void Window::frame() { void Window::frame() {
@ -828,7 +828,7 @@ namespace hex {
} }
void Window::frameEnd() { void Window::frameEnd() {
EventManager::post<EventFrameEnd>(); EventFrameEnd::post();
// Clean up all tasks that are done // Clean up all tasks that are done
TaskManager::collectGarbage(); TaskManager::collectGarbage();
@ -1063,7 +1063,7 @@ namespace hex {
// Register window close callback // Register window close callback
glfwSetWindowCloseCallback(this->m_window, [](GLFWwindow *window) { glfwSetWindowCloseCallback(this->m_window, [](GLFWwindow *window) {
EventManager::post<EventWindowClosing>(window); EventWindowClosing::post(window);
}); });
// Register file drop callback // Register file drop callback
@ -1090,7 +1090,7 @@ namespace hex {
// If no custom handler was found, just open the file regularly // If no custom handler was found, just open the file regularly
if (!handled) if (!handled)
EventManager::post<RequestOpenFile>(path); RequestOpenFile::post(path);
} }
}); });
@ -1224,7 +1224,7 @@ namespace hex {
for (const auto &plugin : PluginManager::getPlugins()) for (const auto &plugin : PluginManager::getPlugins())
plugin.setImGuiContext(ImGui::GetCurrentContext()); plugin.setImGuiContext(ImGui::GetCurrentContext());
EventManager::post<RequestInitThemeHandlers>(); RequestInitThemeHandlers::post();
} }
void Window::exitGLFW() { void Window::exitGLFW() {

View File

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

View File

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

View File

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

View File

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

View File

@ -24,7 +24,7 @@ namespace hex::plugin::builtin {
static wolv::net::SocketServer networkInterfaceServer(31337); static wolv::net::SocketServer networkInterfaceServer(31337);
AT_FIRST_TIME { AT_FIRST_TIME {
EventManager::subscribe<EventImHexClosing>([]{ EventImHexClosing::subscribe([]{
networkInterfaceServer.shutdown(); networkInterfaceServer.shutdown();
}); });
}; };
@ -61,7 +61,7 @@ namespace hex::plugin::builtin {
} }
void registerBackgroundServices() { void registerBackgroundServices() {
EventManager::subscribe<EventSettingsChanged>([]{ EventSettingsChanged::subscribe([]{
networkInterfaceServiceEnabled = bool(ContentRegistry::Settings::read("hex.builtin.setting.general", "hex.builtin.setting.general.network_interface", false)); 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() { void registerCommandForwarders() {
hex::subcommands::registerSubCommand("open", [](const std::vector<std::string> &args){ hex::subcommands::registerSubCommand("open", [](const std::vector<std::string> &args){
for (auto &arg : 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 { ContentRegistry::CommunicationInterface::registerNetworkEndpoint("pattern_editor/set_code", [](const nlohmann::json &data) -> nlohmann::json {
auto code = data.at("code").get<std::string>(); auto code = data.at("code").get<std::string>();
EventManager::post<RequestSetPatternLanguageCode>(code); RequestSetPatternLanguageCode::post(code);
return { }; return { };
}); });

View File

@ -60,14 +60,14 @@ namespace hex::plugin::builtin {
class NodeDataSelection : public dp::Node { class NodeDataSelection : public dp::Node {
public: 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") }) { 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_address = region.address;
this->m_size = region.size; this->m_size = region.size;
}); });
} }
~NodeDataSelection() override { ~NodeDataSelection() override {
EventManager::unsubscribe<EventRegionSelected>(this); EventRegionSelected::unsubscribe(this);
} }
void process() override { 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())); PopupError::open(hex::format("hex.builtin.provider.error.open"_lang, provider->getErrorMessage()));
TaskManager::doLater([provider] { ImHexApi::Provider::remove(provider); }); TaskManager::doLater([provider] { ImHexApi::Provider::remove(provider); });
} else { } else {
EventManager::post<EventProviderOpened>(fileProvider); EventProviderOpened::post(fileProvider);
} }
} }
} }
@ -37,7 +37,7 @@ namespace hex::plugin::builtin {
void registerEventHandlers() { void registerEventHandlers() {
static bool imhexClosing = false; static bool imhexClosing = false;
EventManager::subscribe<EventWindowClosing>([](GLFWwindow *window) { EventWindowClosing::subscribe([](GLFWwindow *window) {
imhexClosing = false; imhexClosing = false;
if (ImHexApi::Provider::isDirty() && !imhexClosing) { if (ImHexApi::Provider::isDirty() && !imhexClosing) {
glfwSetWindowShouldClose(window, GLFW_FALSE); 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()) { if (provider->isDirty()) {
*shouldClose = false; *shouldClose = false;
PopupUnsavedChanges::open("hex.builtin.popup.close_provider.desc"_lang, 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(oldProvider);
hex::unused(newProvider); 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) if (provider != nullptr && ImHexApi::Provider::get() == provider)
EventManager::post<RequestUpdateWindowTitle>(); RequestUpdateWindowTitle::post();
EventManager::post<EventProviderChanged>(nullptr, provider); 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") { if (name == "Create File") {
auto newProvider = hex::ImHexApi::Provider::createProvider("hex.builtin.provider.mem_file", true); auto newProvider = hex::ImHexApi::Provider::createProvider("hex.builtin.provider.mem_file", true);
if (newProvider != nullptr && !newProvider->open()) if (newProvider != nullptr && !newProvider->open())
hex::ImHexApi::Provider::remove(newProvider); hex::ImHexApi::Provider::remove(newProvider);
else else
EventManager::post<EventProviderOpened>(newProvider); EventProviderOpened::post(newProvider);
} else if (name == "Open File") { } else if (name == "Open File") {
fs::openFileBrowser(fs::DialogMode::Open, { }, [](const auto &path) { fs::openFileBrowser(fs::DialogMode::Open, { }, [](const auto &path) {
if (path.extension() == ".hexproj") { if (path.extension() == ".hexproj") {
@ -118,7 +118,7 @@ namespace hex::plugin::builtin {
if (!newProvider->open()) if (!newProvider->open())
hex::ImHexApi::Provider::remove(newProvider); hex::ImHexApi::Provider::remove(newProvider);
else { else {
EventManager::post<EventProviderOpened>(newProvider); EventProviderOpened::post(newProvider);
AchievementManager::unlockAchievement("hex.builtin.achievement.starting_out", "hex.builtin.achievement.starting_out.open_file.name"); 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) { EventProviderChanged::subscribe([](auto, auto) {
EventManager::post<EventHighlightingChanged>(); EventHighlightingChanged::post();
}); });
// Handles the provider initialization, and calls EventProviderOpened if successful // 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()) if (provider->shouldSkipLoadInterface())
return; return;
@ -154,7 +154,7 @@ namespace hex::plugin::builtin {
return; return;
} }
EventManager::post<EventProviderOpened>(provider); EventProviderOpened::post(provider);
} }
else if (!provider->hasLoadInterface()) { else if (!provider->hasLoadInterface()) {
if (!provider->open() || !provider->isAvailable()) { if (!provider->open() || !provider->isAvailable()) {
@ -163,23 +163,23 @@ namespace hex::plugin::builtin {
return; 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); ImHexApi::HexEditor::impl::setCurrentSelection(region);
}); });
EventManager::subscribe<RequestOpenInfoPopup>([](const std::string &message) { RequestOpenInfoPopup::subscribe([](const std::string &message) {
PopupInfo::open(message); PopupInfo::open(message);
}); });
EventManager::subscribe<RequestOpenErrorPopup>([](const std::string &message) { RequestOpenErrorPopup::subscribe([](const std::string &message) {
PopupError::open(message); PopupError::open(message);
}); });
EventManager::subscribe<RequestOpenFatalPopup>([](const std::string &message) { RequestOpenFatalPopup::subscribe([](const std::string &message) {
PopupFatal::open(message); PopupFatal::open(message);
}); });

View File

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

View File

@ -106,8 +106,8 @@ namespace hex::plugin::builtin {
} }
resetPath.release(); resetPath.release();
EventManager::post<EventProjectOpened>(); EventProjectOpened::post();
EventManager::post<RequestUpdateWindowTitle>(); RequestUpdateWindowTitle::post();
return true; 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"); AchievementManager::unlockAchievement("hex.builtin.achievement.starting_out", "hex.builtin.achievement.starting_out.save_project.name");
// Request, as this puts us into a project state // Request, as this puts us into a project state
EventManager::post<RequestUpdateWindowTitle>(); RequestUpdateWindowTitle::post();
return result; return result;
} }

View File

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

View File

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

View File

@ -294,7 +294,7 @@ namespace hex::plugin::builtin {
if (loadLibraryW != nullptr) { if (loadLibraryW != nullptr) {
if (auto threadHandle = CreateRemoteThread(this->m_processHandle, nullptr, 0, loadLibraryW, pathAddress, 0, nullptr); threadHandle != nullptr) { if (auto threadHandle = CreateRemoteThread(this->m_processHandle, nullptr, 0, loadLibraryW, pathAddress, 0, nullptr); threadHandle != nullptr) {
WaitForSingleObject(threadHandle, INFINITE); 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(); this->reloadProcessModules();
CloseHandle(threadHandle); CloseHandle(threadHandle);
return; 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 #endif

View File

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

View File

@ -464,7 +464,7 @@ namespace hex::plugin::builtin {
/* Experiments */ /* Experiments */
ContentRegistry::Settings::setCategoryDescription("hex.builtin.setting.experiments", "hex.builtin.setting.experiments.description"); 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()) { for (const auto &[name, experiment] : ContentRegistry::Experiments::impl::getExperiments()) {
ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.experiments", "", experiment.unlocalizedName, false) ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.experiments", "", experiment.unlocalizedName, false)
.setTooltip(Lang(experiment.unlocalizedDescription)) .setTooltip(Lang(experiment.unlocalizedDescription))
@ -477,7 +477,7 @@ namespace hex::plugin::builtin {
}); });
/* Shorcuts */ /* Shorcuts */
EventManager::subscribe<EventImHexStartupFinished>([]{ EventImHexStartupFinished::subscribe([]{
for (const auto &shortcutEntry : ShortcutManager::getGlobalShortcuts()) { for (const auto &shortcutEntry : ShortcutManager::getGlobalShortcuts()) {
ContentRegistry::Settings::add<KeybindingWidget>("hex.builtin.setting.shortcuts", "hex.builtin.setting.shortcuts.global", shortcutEntry.unlocalizedName, nullptr, shortcutEntry.shortcut); 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 { namespace hex::plugin::builtin {
void registerThemeHandlers() { void registerThemeHandlers() {
EventManager::subscribe<RequestInitThemeHandlers>([] { RequestInitThemeHandlers::subscribe([] {
{ {
const static ThemeManager::ColorMap ImGuiColorMap = { const static ThemeManager::ColorMap ImGuiColorMap = {
{ "text", ImGuiCol_Text }, { "text", ImGuiCol_Text },
@ -253,7 +253,7 @@ namespace hex::plugin::builtin {
} }
void registerStyleHandlers() { void registerStyleHandlers() {
EventManager::subscribe<RequestInitThemeHandlers>([] { RequestInitThemeHandlers::subscribe([] {
{ {
auto &style = ImGui::GetStyle(); auto &style = ImGui::GetStyle();
const static ThemeManager::StyleMap ImGuiStyleMap = { const static ThemeManager::StyleMap ImGuiStyleMap = {

View File

@ -53,7 +53,7 @@ namespace hex::plugin::builtin {
} }
void addGlobalUIItems() { void addGlobalUIItems() {
EventManager::subscribe<EventFrameEnd>(drawGlobalPopups); EventFrameEnd::subscribe(drawGlobalPopups);
} }
void addFooterItems() { void addFooterItems() {
@ -163,7 +163,7 @@ namespace hex::plugin::builtin {
}); });
static bool providerJustChanged = true; static bool providerJustChanged = true;
EventManager::subscribe<EventProviderChanged>([](auto, auto) { providerJustChanged = true; }); EventProviderChanged::subscribe([](auto, auto) { providerJustChanged = true; });
ContentRegistry::Interface::addToolbarItem([] { ContentRegistry::Interface::addToolbarItem([] {
auto provider = ImHexApi::Provider::get(); auto provider = ImHexApi::Provider::get();
@ -196,12 +196,12 @@ namespace hex::plugin::builtin {
if (newProvider != nullptr && !newProvider->open()) if (newProvider != nullptr && !newProvider->open())
hex::ImHexApi::Provider::remove(newProvider); hex::ImHexApi::Provider::remove(newProvider);
else else
EventManager::post<EventProviderOpened>(newProvider); EventProviderOpened::post(newProvider);
} }
// Open file // Open file
if (ImGuiExt::ToolBarButton(ICON_VS_FOLDER_OPENED, ImGuiExt::GetCustomColorVec4(ImGuiCustomCol_ToolbarBrown))) if (ImGuiExt::ToolBarButton(ICON_VS_FOLDER_OPENED, ImGuiExt::GetCustomColorVec4(ImGuiCustomCol_ToolbarBrown)))
EventManager::post<RequestOpenWindow>("Open File"); RequestOpenWindow::post("Open File");
} }
ImGui::EndDisabled(); ImGui::EndDisabled();

View File

@ -16,11 +16,11 @@ namespace hex::plugin::builtin {
}); });
// Add newly unlocked achievements to the display queue // 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); 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") { if (name == "Achievements") {
TaskManager::doLater([this] { TaskManager::doLater([this] {
this->getWindowOpenState() = true; this->getWindowOpenState() = true;
@ -33,7 +33,7 @@ namespace hex::plugin::builtin {
} }
ViewAchievements::~ViewAchievements() { ViewAchievements::~ViewAchievements() {
EventManager::unsubscribe<EventAchievementUnlocked>(this); EventAchievementUnlocked::unsubscribe(this);
} }
void drawAchievement(ImDrawList *drawList, const AchievementManager::AchievementNode *node, ImVec2 position) { 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") { ViewBookmarks::ViewBookmarks() : View::Window("hex.builtin.view.bookmarks.name") {
// Handle bookmark add requests sent by the API // 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()) { if (name.empty()) {
name = hex::format("hex.builtin.view.bookmarks.default_title"_lang, region.address, region.address + region.size - 1); 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(); ImHexApi::Provider::markDirty();
EventManager::post<EventBookmarkCreated>(this->m_bookmarks->back().entry); EventBookmarkCreated::post(this->m_bookmarks->back().entry);
EventManager::post<EventHighlightingChanged>(); EventHighlightingChanged::post();
}); });
EventManager::subscribe<RequestRemoveBookmark>([this](u64 id) { RequestRemoveBookmark::subscribe([this](u64 id) {
std::erase_if(this->m_bookmarks.get(), [id](const auto &bookmark) { std::erase_if(this->m_bookmarks.get(), [id](const auto &bookmark) {
return bookmark.entry.id == id; return bookmark.entry.id == id;
}); });
@ -188,8 +188,8 @@ namespace hex::plugin::builtin {
} }
ViewBookmarks::~ViewBookmarks() { ViewBookmarks::~ViewBookmarks() {
EventManager::unsubscribe<RequestAddBookmark>(this); RequestAddBookmark::unsubscribe(this);
EventManager::unsubscribe<EventProviderDeleted>(this); EventProviderDeleted::unsubscribe(this);
} }
static void drawColorPopup(ImColor &color) { static void drawColorPopup(ImColor &color) {
@ -235,7 +235,7 @@ namespace hex::plugin::builtin {
} }
if (colorChanged) if (colorChanged)
EventManager::post<EventHighlightingChanged>(); EventHighlightingChanged::post();
} }
void ViewBookmarks::drawContent() { void ViewBookmarks::drawContent() {
@ -372,7 +372,7 @@ namespace hex::plugin::builtin {
if (auto *viewProvider = dynamic_cast<ViewProvider*>(newProvider); viewProvider != nullptr) { if (auto *viewProvider = dynamic_cast<ViewProvider*>(newProvider); viewProvider != nullptr) {
viewProvider->setProvider(region.getStartAddress(), region.getSize(), provider); viewProvider->setProvider(region.getStartAddress(), region.getSize(), provider);
if (viewProvider->open()) { 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"); 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 // Remove the bookmark that was marked for removal
if (bookmarkToRemove != this->m_bookmarks->end()) { if (bookmarkToRemove != this->m_bookmarks->end()) {
this->m_bookmarks->erase(bookmarkToRemove); this->m_bookmarks->erase(bookmarkToRemove);
EventManager::post<EventHighlightingChanged>(); EventHighlightingChanged::post();
} }
} }
ImGui::EndChild(); ImGui::EndChild();

View File

@ -8,13 +8,13 @@ namespace hex::plugin::builtin {
ViewCommandPalette::ViewCommandPalette() : View::Special("hex.builtin.view.command_palette.name") { ViewCommandPalette::ViewCommandPalette() : View::Special("hex.builtin.view.command_palette.name") {
// Add global shortcut to open the command palette // Add global shortcut to open the command palette
ShortcutManager::addGlobalShortcut(CTRLCMD + SHIFT + Keys::P, "hex.builtin.view.command_palette.name", [this] { 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_commandPaletteOpen = true;
this->m_justOpened = true; this->m_justOpened = true;
}); });
EventManager::subscribe<EventSearchBoxClicked>([this] { EventSearchBoxClicked::subscribe([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_commandPaletteOpen = true;
this->m_justOpened = 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") { ViewDataInspector::ViewDataInspector() : View::Window("hex.builtin.view.data_inspector.name") {
// Handle region selection // Handle region selection
EventManager::subscribe<EventRegionSelected>(this, [this](const auto &region) { EventRegionSelected::subscribe(this, [this](const auto &region) {
// Save current selection // Save current selection
if (!ImHexApi::Provider::isValid() || region == Region::Invalid()) { if (!ImHexApi::Provider::isValid() || region == Region::Invalid()) {
@ -35,11 +35,11 @@ namespace hex::plugin::builtin {
this->m_shouldInvalidate = true; this->m_shouldInvalidate = true;
}); });
EventManager::subscribe<EventProviderClosed>(this, [this](const auto*) { EventProviderClosed::subscribe(this, [this](const auto*) {
this->m_selectedProvider = nullptr; 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>>(); 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()); this->m_hiddenValues = std::set(filterValues.begin(), filterValues.end());
@ -47,9 +47,9 @@ namespace hex::plugin::builtin {
} }
ViewDataInspector::~ViewDataInspector() { ViewDataInspector::~ViewDataInspector() {
EventManager::unsubscribe<EventRegionSelected>(this); EventRegionSelected::unsubscribe(this);
EventManager::unsubscribe<EventProviderClosed>(this); EventProviderClosed::unsubscribe(this);
EventManager::unsubscribe<EventSettingsChanged>(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_mainWorkspace.get(provider) = { };
this->m_workspaceStack.get(provider).push_back(&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 *workspace : *this->m_workspaceStack) {
for (auto &node : workspace->nodes) { for (auto &node : workspace->nodes) {
node->setCurrentOverlay(nullptr); node->setCurrentOverlay(nullptr);
@ -387,7 +387,7 @@ namespace hex::plugin::builtin {
this->m_updateNodePositions = true; this->m_updateNodePositions = true;
}); });
EventManager::subscribe<EventDataChanged>(this, [this] { EventDataChanged::subscribe(this, [this] {
ViewDataProcessor::processNodes(*this->m_workspaceStack->back()); ViewDataProcessor::processNodes(*this->m_workspaceStack->back());
}); });
@ -427,11 +427,11 @@ namespace hex::plugin::builtin {
} }
ViewDataProcessor::~ViewDataProcessor() { ViewDataProcessor::~ViewDataProcessor() {
EventManager::unsubscribe<EventProviderCreated>(this); EventProviderCreated::unsubscribe(this);
EventManager::unsubscribe<EventProviderChanged>(this); EventProviderChanged::unsubscribe(this);
EventManager::unsubscribe<RequestChangeTheme>(this); RequestChangeTheme::unsubscribe(this);
EventManager::unsubscribe<EventFileLoaded>(this); EventFileLoaded::unsubscribe(this);
EventManager::unsubscribe<EventDataChanged>(this); EventDataChanged::unsubscribe(this);
} }

View File

@ -18,7 +18,7 @@ namespace hex::plugin::builtin {
ViewDiff::ViewDiff() : View::Window("hex.builtin.view.diff.name") { ViewDiff::ViewDiff() : View::Window("hex.builtin.view.diff.name") {
// Clear the selected diff providers when a provider is closed // 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++) { for (u8 i = 0; i < 2; i++) {
this->m_columns[i].provider = -1; this->m_columns[i].provider = -1;
this->m_columns[i].hexEditor.setSelectionUnchecked(std::nullopt, std::nullopt); this->m_columns[i].hexEditor.setSelectionUnchecked(std::nullopt, std::nullopt);
@ -33,7 +33,7 @@ namespace hex::plugin::builtin {
} }
ViewDiff::~ViewDiff() { ViewDiff::~ViewDiff() {
EventManager::unsubscribe<EventProviderClosed>(this); EventProviderClosed::unsubscribe(this);
} }
namespace { namespace {

View File

@ -10,15 +10,15 @@ using namespace std::literals::string_literals;
namespace hex::plugin::builtin { namespace hex::plugin::builtin {
ViewDisassembler::ViewDisassembler() : View::Window("hex.builtin.view.disassembler.name") { 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(); this->m_disassembly.clear();
}); });
} }
ViewDisassembler::~ViewDisassembler() { ViewDisassembler::~ViewDisassembler() {
EventManager::unsubscribe<EventDataChanged>(this); EventDataChanged::unsubscribe(this);
EventManager::unsubscribe<EventRegionSelected>(this); EventRegionSelected::unsubscribe(this);
EventManager::unsubscribe<EventProviderDeleted>(this); EventProviderDeleted::unsubscribe(this);
} }
void ViewDisassembler::disassemble() { void ViewDisassembler::disassemble() {

View File

@ -452,7 +452,7 @@ namespace hex::plugin::builtin {
} }
this->m_occurrenceTree->clear(); 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) { 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(); auto provider = ImHexApi::Provider::get();
@ -482,7 +482,7 @@ namespace hex::plugin::builtin {
this->m_occurrenceTree->insert({ occurrence.region.getStartAddress(), occurrence.region.getEndAddress() }, occurrence); this->m_occurrenceTree->insert({ occurrence.region.getStartAddress(), occurrence.region.getEndAddress() }, occurrence);
TaskManager::doLater([] { TaskManager::doLater([] {
EventManager::post<EventHighlightingChanged>(); EventHighlightingChanged::post();
}); });
}); });
} }
@ -828,7 +828,7 @@ namespace hex::plugin::builtin {
this->m_sortedOccurrences->clear(); this->m_sortedOccurrences->clear();
this->m_occurrenceTree->clear(); this->m_occurrenceTree->clear();
EventManager::post<EventHighlightingChanged>(); EventHighlightingChanged::post();
} }
} }
ImGui::EndDisabled(); ImGui::EndDisabled();

View File

@ -49,7 +49,7 @@ namespace hex::plugin::builtin {
}; };
ViewHashes::ViewHashes() : View::Window("hex.builtin.view.hashes.name") { 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())) for (auto &function : this->m_hashFunctions.get(providerRegion.getProvider()))
function.reset(); function.reset();
}); });
@ -124,7 +124,7 @@ namespace hex::plugin::builtin {
} }
ViewHashes::~ViewHashes() { ViewHashes::~ViewHashes() {
EventManager::unsubscribe<EventRegionSelected>(this); EventRegionSelected::unsubscribe(this);
} }

View File

@ -157,14 +157,14 @@ namespace hex::plugin::builtin {
class PopupFind : public ViewHexEditor::Popup { class PopupFind : public ViewHexEditor::Popup {
public: public:
PopupFind() { 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_searchPosition = this->m_nextSearchPosition.value_or(region.getStartAddress());
this->m_nextSearchPosition.reset(); this->m_nextSearchPosition.reset();
}); });
} }
~PopupFind() override { ~PopupFind() override {
EventManager::unsubscribe<EventRegionSelected>(this); EventRegionSelected::unsubscribe(this);
} }
void draw(ViewHexEditor *editor) override { void draw(ViewHexEditor *editor) override {
@ -636,10 +636,10 @@ namespace hex::plugin::builtin {
} }
ViewHexEditor::~ViewHexEditor() { ViewHexEditor::~ViewHexEditor() {
EventManager::unsubscribe<RequestSelectionChange>(this); RequestSelectionChange::unsubscribe(this);
EventManager::unsubscribe<EventProviderChanged>(this); EventProviderChanged::unsubscribe(this);
EventManager::unsubscribe<EventProviderOpened>(this); EventProviderOpened::unsubscribe(this);
EventManager::unsubscribe<EventHighlightingChanged>(this); EventHighlightingChanged::unsubscribe(this);
} }
void ViewHexEditor::drawPopup() { void ViewHexEditor::drawPopup() {
@ -676,7 +676,7 @@ namespace hex::plugin::builtin {
// Right click menu // Right click menu
if (ImGui::IsMouseReleased(ImGuiMouseButton_Right) && ImGui::IsWindowHovered(ImGuiHoveredFlags_ChildWindows)) 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() { void ViewHexEditor::drawContent() {
@ -774,7 +774,7 @@ namespace hex::plugin::builtin {
this->m_selectionStart->reset(); this->m_selectionStart->reset();
this->m_selectionEnd->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] { 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() { void ViewHexEditor::registerEvents() {
EventManager::subscribe<RequestSelectionChange>(this, [this](Region region) { RequestSelectionChange::subscribe(this, [this](Region region) {
auto provider = ImHexApi::Provider::get(); auto provider = ImHexApi::Provider::get();
if (region == Region::Invalid()) { if (region == Region::Invalid()) {
this->m_selectionStart->reset(); this->m_selectionStart->reset();
this->m_selectionEnd->reset(); this->m_selectionEnd->reset();
EventManager::post<EventRegionSelected>(ImHexApi::HexEditor::ProviderRegion({ Region::Invalid(), nullptr })); EventRegionSelected::post(ImHexApi::HexEditor::ProviderRegion({ Region::Invalid(), nullptr }));
return; 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) { if (oldProvider != nullptr) {
auto selection = this->m_hexEditor.getSelection(); auto selection = this->m_hexEditor.getSelection();
@ -998,15 +998,15 @@ namespace hex::plugin::builtin {
this->m_hexEditor.forceUpdateScrollPosition(); this->m_hexEditor.forceUpdateScrollPosition();
if (isSelectionValid()) { 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(); ImHexApi::HexEditor::clearSelection();
}); });
EventManager::subscribe<EventHighlightingChanged>(this, [this]{ EventHighlightingChanged::subscribe(this, [this]{
this->m_foregroundHighlights->clear(); this->m_foregroundHighlights->clear();
this->m_backgroundHighlights->clear(); this->m_backgroundHighlights->clear();
}); });
@ -1311,7 +1311,7 @@ namespace hex::plugin::builtin {
if (auto *viewProvider = dynamic_cast<ViewProvider*>(newProvider); viewProvider != nullptr) { if (auto *viewProvider = dynamic_cast<ViewProvider*>(newProvider); viewProvider != nullptr) {
viewProvider->setProvider(selection->getStartAddress(), selection->getSize(), selection->getProvider()); viewProvider->setProvider(selection->getStartAddress(), selection->getSize(), selection->getProvider());
if (viewProvider->open()) if (viewProvider->open())
EventManager::post<EventProviderOpened>(viewProvider); EventProviderOpened::post(viewProvider);
} }
}, },
[] { return ImHexApi::HexEditor::isSelectionValid() && ImHexApi::Provider::isValid(); }); [] { 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 // Initialize the selected rule iterators to point to the end of the rules lists
this->m_selectedRule = this->m_rules->end(); 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(); this->m_selectedRule.get(provider) = this->m_rules.get(provider).end();
}); });
} }
@ -193,7 +193,7 @@ namespace hex::plugin::builtin {
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2()); ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2());
if (ImGui::Checkbox("##enabled", &rule.enabled)) { if (ImGui::Checkbox("##enabled", &rule.enabled)) {
EventManager::post<EventHighlightingChanged>(); EventHighlightingChanged::post();
} }
ImGui::PopStyleVar(); ImGui::PopStyleVar();
@ -273,7 +273,7 @@ namespace hex::plugin::builtin {
// If any of the inputs have changed, update the highlight // If any of the inputs have changed, update the highlight
if (updateHighlight) if (updateHighlight)
EventManager::post<EventHighlightingChanged>(); EventHighlightingChanged::post();
} }
ImGui::EndTable(); ImGui::EndTable();

View File

@ -21,7 +21,7 @@ namespace hex::plugin::builtin {
using namespace hex::literals; using namespace hex::literals;
ViewInformation::ViewInformation() : View::Window("hex.builtin.view.information.name") { ViewInformation::ViewInformation() : View::Window("hex.builtin.view.information.name") {
EventManager::subscribe<EventDataChanged>(this, [this] { EventDataChanged::subscribe(this, [this] {
this->m_dataValid = false; this->m_dataValid = false;
this->m_plainTextCharacterPercentage = -1.0; this->m_plainTextCharacterPercentage = -1.0;
this->m_averageEntropy = -1.0; this->m_averageEntropy = -1.0;
@ -32,7 +32,7 @@ namespace hex::plugin::builtin {
this->m_analyzedRegion = { 0, 0 }; 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 // Set the position of the diagram relative to the place where
// the user clicked inside the hex editor view // the user clicked inside the hex editor view
if (this->m_blockSize != 0) { 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; this->m_dataValid = false;
}); });
@ -58,9 +58,9 @@ namespace hex::plugin::builtin {
} }
ViewInformation::~ViewInformation() { ViewInformation::~ViewInformation() {
EventManager::unsubscribe<EventDataChanged>(this); EventDataChanged::unsubscribe(this);
EventManager::unsubscribe<EventRegionSelected>(this); EventRegionSelected::unsubscribe(this);
EventManager::unsubscribe<EventProviderDeleted>(this); EventProviderDeleted::unsubscribe(this);
} }
void ViewInformation::analyze() { void ViewInformation::analyze() {

View File

@ -60,11 +60,11 @@ namespace hex::plugin::builtin {
return std::nullopt; return std::nullopt;
}); });
EventManager::subscribe<EventProviderSaved>([](auto *) { EventProviderSaved::subscribe([](auto *) {
EventManager::post<EventHighlightingChanged>(); 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) if (size == 0)
return; return;
@ -75,13 +75,13 @@ namespace hex::plugin::builtin {
provider->getUndoStack().add<undo::OperationWrite>(offset, size, oldData.data(), data); 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(); offset -= provider->getBaseAddress();
provider->getUndoStack().add<undo::OperationInsert>(offset, size); 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(); offset -= provider->getBaseAddress();
provider->getUndoStack().add<undo::OperationRemove>(offset, size); provider->getUndoStack().add<undo::OperationRemove>(offset, size);
@ -177,7 +177,7 @@ namespace hex::plugin::builtin {
const auto &operations = provider->getUndoStack().getAppliedOperations(); const auto &operations = provider->getUndoStack().getAppliedOperations();
if (this->m_numOperations.get(provider) != operations.size()) { if (this->m_numOperations.get(provider) != operations.size()) {
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>(); this->m_patternDrawer = std::make_unique<ui::PatternDrawer>();
// Handle tree style setting changes // 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); auto patternStyle = ContentRegistry::Settings::read("hex.builtin.setting.interface", "hex.builtin.setting.interface.pattern_tree_style", 0);
this->m_patternDrawer->setTreeStyle(patternStyle); this->m_patternDrawer->setTreeStyle(patternStyle);
@ -21,15 +21,15 @@ namespace hex::plugin::builtin {
}); });
// Reset the pattern drawer when the provider changes // 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(); this->m_patternDrawer->reset();
}); });
EventManager::subscribe<EventPatternEvaluating>(this, [this]{ EventPatternEvaluating::subscribe(this, [this]{
this->m_patternDrawer->reset(); this->m_patternDrawer->reset();
}); });
EventManager::subscribe<EventPatternExecuted>(this, [this](auto){ EventPatternExecuted::subscribe(this, [this](auto){
this->m_patternDrawer->reset(); this->m_patternDrawer->reset();
}); });
@ -38,10 +38,10 @@ namespace hex::plugin::builtin {
} }
ViewPatternData::~ViewPatternData() { ViewPatternData::~ViewPatternData() {
EventManager::unsubscribe<EventSettingsChanged>(this); EventSettingsChanged::unsubscribe(this);
EventManager::unsubscribe<EventProviderChanged>(this); EventProviderChanged::unsubscribe(this);
EventManager::unsubscribe<EventPatternEvaluating>(this); EventPatternEvaluating::unsubscribe(this);
EventManager::unsubscribe<EventPatternExecuted>(this); EventPatternExecuted::unsubscribe(this);
} }
void ViewPatternData::drawContent() { void ViewPatternData::drawContent() {

View File

@ -144,10 +144,10 @@ namespace hex::plugin::builtin {
} }
ViewPatternEditor::~ViewPatternEditor() { ViewPatternEditor::~ViewPatternEditor() {
EventManager::unsubscribe<RequestSetPatternLanguageCode>(this); RequestSetPatternLanguageCode::unsubscribe(this);
EventManager::unsubscribe<EventFileLoaded>(this); EventFileLoaded::unsubscribe(this);
EventManager::unsubscribe<EventProviderChanged>(this); EventProviderChanged::unsubscribe(this);
EventManager::unsubscribe<EventProviderClosed>(this); EventProviderClosed::unsubscribe(this);
} }
void ViewPatternEditor::drawContent() { void ViewPatternEditor::drawContent() {
@ -345,7 +345,7 @@ namespace hex::plugin::builtin {
this->m_hasUnevaluatedChanges = false; this->m_hasUnevaluatedChanges = false;
auto code = this->m_textEditor.GetText(); auto code = this->m_textEditor.GetText();
EventManager::post<EventPatternEditorChanged>(code); EventPatternEditorChanged::post(code);
TaskManager::createBackgroundTask("Pattern Parsing", [this, code, provider](auto &){ TaskManager::createBackgroundTask("Pattern Parsing", [this, code, provider](auto &){
this->parsePattern(code, provider); this->parsePattern(code, provider);
@ -749,7 +749,7 @@ namespace hex::plugin::builtin {
variable.value = this->m_lastEvaluationOutVars->at(name); variable.value = this->m_lastEvaluationOutVars->at(name);
} }
EventManager::post<EventHighlightingChanged>(); EventHighlightingChanged::post();
} }
this->m_lastEvaluationProcessed = true; this->m_lastEvaluationProcessed = true;
@ -996,7 +996,7 @@ namespace hex::plugin::builtin {
} }
void ViewPatternEditor::evaluatePattern(const std::string &code, prv::Provider *provider) { void ViewPatternEditor::evaluatePattern(const std::string &code, prv::Provider *provider) {
EventManager::post<EventPatternEvaluating>(); EventPatternEvaluating::post();
auto lock = std::scoped_lock(ContentRegistry::PatternLanguage::getRuntimeLock()); auto lock = std::scoped_lock(ContentRegistry::PatternLanguage::getRuntimeLock());
@ -1014,7 +1014,7 @@ namespace hex::plugin::builtin {
this->m_accessHistory = {}; this->m_accessHistory = {};
this->m_accessHistoryIndex = 0; this->m_accessHistoryIndex = 0;
EventManager::post<EventHighlightingChanged>(); EventHighlightingChanged::post();
TaskManager::createTask("hex.builtin.view.pattern_editor.evaluating", TaskManager::NoProgress, [this, code, provider](auto &task) { TaskManager::createTask("hex.builtin.view.pattern_editor.evaluating", TaskManager::NoProgress, [this, code, provider](auto &task) {
auto lock = std::scoped_lock(ContentRegistry::PatternLanguage::getRuntimeLock()); auto lock = std::scoped_lock(ContentRegistry::PatternLanguage::getRuntimeLock());
@ -1095,40 +1095,40 @@ namespace hex::plugin::builtin {
} }
TaskManager::doLater([code] { TaskManager::doLater([code] {
EventManager::post<EventPatternExecuted>(code); EventPatternExecuted::post(code);
}); });
}); });
} }
void ViewPatternEditor::registerEvents() { 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()); 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); wolv::io::File file(path, wolv::io::File::Mode::Create);
file.writeString(wolv::util::trim(this->m_textEditor.GetText())); 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_textEditor.SetText(code);
this->m_sourceCode = code; this->m_sourceCode = code;
this->m_hasUnevaluatedChanges = true; 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_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); 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_shouldAnalyze.get(provider) = true;
this->m_envVarEntries->push_back({ 0, "", 0, EnvVarType::Integer }); this->m_envVarEntries->push_back({ 0, "", 0, EnvVarType::Integer });
this->m_debuggerDrawer.get(provider) = std::make_unique<ui::PatternDrawer>(); 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 (!this->m_syncPatternSourceCode) {
if (oldProvider != nullptr) if (oldProvider != nullptr)
this->m_sourceCode.get(oldProvider) = this->m_textEditor.GetText(); 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()) { if (this->m_syncPatternSourceCode && ImHexApi::Provider::getProviders().empty()) {
this->m_textEditor.SetText(""); this->m_textEditor.SetText("");
this->m_sourceCode = ""; this->m_sourceCode = "";
@ -1286,7 +1286,7 @@ namespace hex::plugin::builtin {
wolv::io::File file(path, wolv::io::File::Mode::Read); wolv::io::File file(path, wolv::io::File::Mode::Read);
if (file.isValid()) { if (file.isValid()) {
EventManager::post<RequestSetPatternLanguageCode>(file.readString()); RequestSetPatternLanguageCode::post(file.readString());
return true; return true;
} else { } else {
return false; return false;

View File

@ -6,7 +6,7 @@
namespace hex::plugin::builtin { namespace hex::plugin::builtin {
ViewProviderSettings::ViewProviderSettings() : View::Modal("hex.builtin.view.provider_settings.name") { 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()) if (provider->hasLoadInterface() && !provider->shouldSkipLoadInterface())
this->getWindowOpenState() = true; this->getWindowOpenState() = true;
}); });
@ -25,7 +25,7 @@ namespace hex::plugin::builtin {
} }
ViewProviderSettings::~ViewProviderSettings() { ViewProviderSettings::~ViewProviderSettings() {
EventManager::unsubscribe<EventProviderCreated>(this); EventProviderCreated::unsubscribe(this);
} }
void ViewProviderSettings::drawContent() { void ViewProviderSettings::drawContent() {
@ -39,7 +39,7 @@ namespace hex::plugin::builtin {
ImGui::BeginDisabled(!settingsValid); ImGui::BeginDisabled(!settingsValid);
if (ImGui::Button("hex.builtin.common.open"_lang)) { if (ImGui::Button("hex.builtin.common.open"_lang)) {
if (provider->open()) { if (provider->open()) {
EventManager::post<EventProviderOpened>(provider); EventProviderOpened::post(provider);
this->getWindowOpenState() = false; this->getWindowOpenState() = false;
ImGui::CloseCurrentPopup(); ImGui::CloseCurrentPopup();

View File

@ -11,7 +11,7 @@ namespace hex::plugin::builtin {
ViewSettings::ViewSettings() : View::Modal("hex.builtin.view.settings.name") { ViewSettings::ViewSettings() : View::Modal("hex.builtin.view.settings.name") {
// Handle window open requests // Handle window open requests
EventManager::subscribe<RequestOpenWindow>(this, [this](const std::string &name) { RequestOpenWindow::subscribe(this, [this](const std::string &name) {
if (name == "Settings") { if (name == "Settings") {
TaskManager::doLater([this] { TaskManager::doLater([this] {
this->getWindowOpenState() = true; this->getWindowOpenState() = true;
@ -27,7 +27,7 @@ namespace hex::plugin::builtin {
} }
ViewSettings::~ViewSettings() { ViewSettings::~ViewSettings() {
EventManager::unsubscribe<RequestOpenWindow>(this); RequestOpenWindow::unsubscribe(this);
} }
void ViewSettings::drawContent() { 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)); log::debug("Setting [{} / {}]: Value was changed to {}", category.unlocalizedName, setting.unlocalizedName, nlohmann::to_string(newValue));
// Signal that the setting was changed // Signal that the setting was changed
EventManager::post<EventSettingsChanged>(); EventSettingsChanged::post();
widget->onChanged(); widget->onChanged();
// Request a restart if the setting requires it // Request a restart if the setting requires it

View File

@ -327,7 +327,7 @@ namespace hex::plugin::builtin {
wolv::io::fs::removeAll(folderPath); wolv::io::fs::removeAll(folderPath);
removed = removed && !wolv::io::fs::exists(filePath) && !wolv::io::fs::exists(folderPath); removed = removed && !wolv::io::fs::exists(filePath) && !wolv::io::fs::exists(folderPath);
EventManager::post<EventStoreContentRemoved>(filePath); EventStoreContentRemoved::post(filePath);
} }
return removed; return removed;
@ -352,9 +352,9 @@ namespace hex::plugin::builtin {
if (entry.isFolder) { if (entry.isFolder) {
Tar tar(this->m_downloadPath, Tar::Mode::Read); Tar tar(this->m_downloadPath, Tar::Mode::Read);
tar.extractAll(this->m_downloadPath.parent_path() / this->m_downloadPath.stem()); 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 { } else {
EventManager::post<EventStoreContentDownloaded>(this->m_downloadPath); EventStoreContentDownloaded::post(this->m_downloadPath);
} }
category.downloadCallback(); 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)) { if (ImGui::ColorEdit4(colorName.c_str(), reinterpret_cast<float*>(&color.Value), ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaBar | ImGuiColorEditFlags_AlphaPreviewHalf)) {
// Update the color value // Update the color value
handler.setFunction(colorId, color); handler.setFunction(colorId, color);
EventManager::post<EventThemeChanged>(); EventThemeChanged::post();
} }
if (ImGui::IsItemHovered()) { if (ImGui::IsItemHovered()) {
@ -96,11 +96,11 @@ namespace hex::plugin::builtin {
// Determine which one it is and draw the appropriate slider // Determine which one it is and draw the appropriate slider
if (auto floatValue = std::get_if<float*>(&value); floatValue != nullptr) { if (auto floatValue = std::get_if<float*>(&value); floatValue != nullptr) {
if (ImGui::SliderFloat(styleName.c_str(), *floatValue, min, max, "%.1f")) { 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) { } else if (auto vecValue = std::get_if<ImVec2*>(&value); vecValue != nullptr) {
if (ImGui::SliderFloat2(styleName.c_str(), &(*vecValue)->x, min, max, "%.1f")) { 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()) if (newProvider != nullptr && !newProvider->open())
hex::ImHexApi::Provider::remove(newProvider); hex::ImHexApi::Provider::remove(newProvider);
else else
EventManager::post<EventProviderOpened>(newProvider); EventProviderOpened::post(newProvider);
} }
if (ImGuiExt::IconHyperlink(ICON_VS_GO_TO_FILE, "hex.builtin.welcome.start.open_file"_lang)) 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)) 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)) if (ImGuiExt::IconHyperlink(ICON_VS_TELESCOPE, "hex.builtin.welcome.start.open_other"_lang))
otherProvidersVisible = !otherProvidersVisible; 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); 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))) 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(); ImGuiExt::EndSubWindow();
ImGui::TableNextRow(ImGuiTableRowFlags_None, ImGui::GetTextLineHeightWithSpacing() * 5); ImGui::TableNextRow(ImGuiTableRowFlags_None, ImGui::GetTextLineHeightWithSpacing() * 5);
@ -322,7 +322,7 @@ namespace hex::plugin::builtin {
if (auto [unlocked, total] = AchievementManager::getProgress(); unlocked != total) { 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)) { 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"); auto provider = ImHexApi::Provider::createProvider("hex.builtin.provider.null");
if (provider != nullptr) if (provider != nullptr)
if (provider->open()) if (provider->open())
EventManager::post<EventProviderOpened>(provider); EventProviderOpened::post(provider);
} }
} }
@ -462,15 +462,15 @@ namespace hex::plugin::builtin {
recent::registerEventHandlers(); recent::registerEventHandlers();
recent::updateRecentEntries(); recent::updateRecentEntries();
(void)EventManager::subscribe<EventFrameBegin>(drawWelcomeScreen); (void)EventFrameBegin::subscribe(drawWelcomeScreen);
// Sets a background when they are no views // Sets a background when they are no views
(void)EventManager::subscribe<EventFrameBegin>([]{ (void)EventFrameBegin::subscribe([]{
if (ImHexApi::Provider::isValid() && !isAnyViewOpen()) if (ImHexApi::Provider::isValid() && !isAnyViewOpen())
drawNoViewsBackground(); 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>(); 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; static std::string lastTheme;
if (theme != lastTheme) { if (theme != lastTheme) {
EventManager::post<RequestChangeTheme>(theme); RequestChangeTheme::post(theme);
lastTheme = 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) { auto changeTexture = [&](const std::string &path) {
return ImGuiExt::Texture(romfs::get(path).span()); return ImGuiExt::Texture(romfs::get(path).span());
}; };
@ -514,12 +514,12 @@ namespace hex::plugin::builtin {
} }
}); });
EventManager::subscribe<EventProviderCreated>([](auto) { EventProviderCreated::subscribe([](auto) {
if (!isAnyViewOpen()) if (!isAnyViewOpen())
loadDefaultLayout(); loadDefaultLayout();
}); });
EventManager::subscribe<EventWindowInitialized>([] { EventWindowInitialized::subscribe([] {
// Documentation of the value above the setting definition // Documentation of the value above the setting definition
auto allowServerContact = ContentRegistry::Settings::read("hex.builtin.setting.general", "hex.builtin.setting.general.server_contact", 2); auto allowServerContact = ContentRegistry::Settings::read("hex.builtin.setting.general", "hex.builtin.setting.general.server_contact", 2);
if (allowServerContact == 2) { if (allowServerContact == 2) {
@ -533,11 +533,11 @@ namespace hex::plugin::builtin {
}); });
// Clear project context if we go back to the welcome screen // 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); hex::unused(oldProvider);
if (newProvider == nullptr) { if (newProvider == nullptr) {
ProjectFile::clearPath(); ProjectFile::clearPath();
EventManager::post<RequestUpdateWindowTitle>(); RequestUpdateWindowTitle::post();
} }
}); });
@ -582,7 +582,7 @@ namespace hex::plugin::builtin {
} else { } else {
ProjectFile::setPath(""); ProjectFile::setPath("");
} }
EventManager::post<RequestUpdateWindowTitle>(); RequestUpdateWindowTitle::post();
}else{ }else{
if (hasProject) { if (hasProject) {
ProjectFile::setPath(crashFileData["project"].get<std::string>()); 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_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); 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_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_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); 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() { HexEditor::~HexEditor() {
EventManager::unsubscribe<EventSettingsChanged>(this); EventSettingsChanged::unsubscribe(this);
} }
constexpr static u16 getByteColumnSeparatorCount(u16 columnCount) { constexpr static u16 getByteColumnSeparatorCount(u16 columnCount) {

View File

@ -114,7 +114,7 @@ private:
}; };
SCRIPT_API(void showMessageBox, const char *message) { 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) { 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() { void addFooterItems() {
static bool showResourceUsage = true; 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); 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() { static void detectSystemTheme() {
// Setup system theme change detector // 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; bool themeFollowSystem = ContentRegistry::Settings::read("hex.builtin.setting.interface", "hex.builtin.setting.interface.color", ThemeManager::NativeTheme).get<std::string>() == ThemeManager::NativeTheme;
if (!themeFollowSystem) if (!themeFollowSystem)
return; return;
@ -35,7 +35,7 @@ static void detectSystemTheme() {
auto error = RegQueryValueEx(hkey, "AppsUseLightTheme", nullptr, nullptr, reinterpret_cast<LPBYTE>(&value), &size); auto error = RegQueryValueEx(hkey, "AppsUseLightTheme", nullptr, nullptr, reinterpret_cast<LPBYTE>(&value), &size);
if (error == ERROR_SUCCESS) { if (error == ERROR_SUCCESS) {
EventManager::post<RequestChangeTheme>(value == 0 ? "Dark" : "Light"); RequestChangeTheme::post(value == 0 ? "Dark" : "Light");
} else { } else {
ImHexApi::System::impl::setBorderlessWindowMode(false); 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; bool themeFollowSystem = ContentRegistry::Settings::read("hex.builtin.setting.interface", "hex.builtin.setting.interface.color", ThemeManager::NativeTheme).get<std::string>() == ThemeManager::NativeTheme;
if (themeFollowSystem) 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 (this->m_portHandle == INVALID_HANDLE_VALUE) {
if (ImGui::Button("hex.windows.view.tty_console.connect"_lang)) if (ImGui::Button("hex.windows.view.tty_console.connect"_lang))
if (!this->connect()) 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 { } else {
if (ImGui::Button("hex.windows.view.tty_console.disconnect"_lang)) if (ImGui::Button("hex.windows.view.tty_console.disconnect"_lang))
this->disconnect(); this->disconnect();
@ -184,7 +184,7 @@ namespace hex::plugin::windows {
bool ViewTTYConsole::connect() { bool ViewTTYConsole::connect() {
if (this->m_comPorts.empty() || static_cast<size_t>(this->m_selectedPort) >= this->m_comPorts.size()) { 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 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(), this->m_portHandle = ::CreateFile((R"(\\.\)" + this->m_comPorts[this->m_selectedPort].first).c_str(),