mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-03-27 23:37:05 -05:00
impr: Make close button on macOS close providers if any are open instead of closing ImHex
This commit is contained in:
@@ -12,6 +12,13 @@ namespace hex {
|
||||
*/
|
||||
EVENT_DEF(EventImHexStartupFinished);
|
||||
|
||||
/**
|
||||
* @brief Called when the user presses the close button on the main window
|
||||
*
|
||||
* This is currently only used and implemented on macOS
|
||||
*/
|
||||
EVENT_DEF(EventCloseButtonPressed);
|
||||
|
||||
/**
|
||||
* @brief Called when ImHex is closing, to trigger the last shutdown hooks
|
||||
*
|
||||
|
||||
@@ -822,10 +822,7 @@ namespace hex {
|
||||
}
|
||||
|
||||
extern "C" void macOSCloseButtonPressed() {
|
||||
auto windowHandle = ImHexApi::System::getMainWindowHandle();
|
||||
|
||||
glfwHideWindow(windowHandle);
|
||||
glfwIconifyWindow(windowHandle);
|
||||
EventCloseButtonPressed::post();
|
||||
}
|
||||
|
||||
extern "C" void macosEventDataReceived(const u8 *data, size_t length) {
|
||||
|
||||
@@ -103,7 +103,8 @@ namespace hex {
|
||||
}
|
||||
|
||||
void Window::beginNativeWindowFrame() {
|
||||
|
||||
if (!ImHexApi::Provider::isValid())
|
||||
macosMarkContentEdited(m_window, false);
|
||||
}
|
||||
|
||||
void Window::endNativeWindowFrame() {
|
||||
|
||||
@@ -10,8 +10,9 @@ namespace hex::plugin::builtin {
|
||||
|
||||
class PopupTasksWaiting : public Popup<PopupTasksWaiting> {
|
||||
public:
|
||||
PopupTasksWaiting()
|
||||
: hex::Popup<PopupTasksWaiting>("hex.builtin.popup.waiting_for_tasks.title", false) { }
|
||||
PopupTasksWaiting(std::function<void()> onFinish)
|
||||
: hex::Popup<PopupTasksWaiting>("hex.builtin.popup.waiting_for_tasks.title", false),
|
||||
m_onFinish(std::move(onFinish)){ }
|
||||
|
||||
void drawContent() override {
|
||||
ImGui::TextUnformatted("hex.builtin.popup.waiting_for_tasks.desc"_lang);
|
||||
@@ -26,13 +27,16 @@ namespace hex::plugin::builtin {
|
||||
|
||||
if (TaskManager::getRunningTaskCount() == 0 && TaskManager::getRunningBackgroundTaskCount() == 0) {
|
||||
ImGui::CloseCurrentPopup();
|
||||
ImHexApi::System::closeImHex();
|
||||
m_onFinish();
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] ImGuiWindowFlags getFlags() const override {
|
||||
return ImGuiWindowFlags_NoResize | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoMove;
|
||||
}
|
||||
|
||||
private:
|
||||
std::function<void()> m_onFinish;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -95,11 +95,40 @@ namespace hex::plugin::builtin {
|
||||
TaskManager::doLater([] {
|
||||
for (auto &task : TaskManager::getRunningTasks())
|
||||
task->interrupt();
|
||||
PopupTasksWaiting::open();
|
||||
PopupTasksWaiting::open([]() {
|
||||
ImHexApi::System::closeImHex();
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
EventCloseButtonPressed::subscribe([]() {
|
||||
if (ImHexApi::Provider::isValid()) {
|
||||
if (ImHexApi::Provider::isDirty()) {
|
||||
ui::PopupQuestion::open("hex.builtin.popup.exit_application.desc"_lang,
|
||||
[] {
|
||||
for (const auto &provider : ImHexApi::Provider::getProviders())
|
||||
ImHexApi::Provider::remove(provider);
|
||||
},
|
||||
[] { }
|
||||
);
|
||||
} else if (TaskManager::getRunningTaskCount() > 0 || TaskManager::getRunningBackgroundTaskCount() > 0) {
|
||||
TaskManager::doLater([] {
|
||||
for (auto &task : TaskManager::getRunningTasks())
|
||||
task->interrupt();
|
||||
PopupTasksWaiting::open([]() {
|
||||
EventCloseButtonPressed::post();
|
||||
});
|
||||
});
|
||||
} else {
|
||||
for (const auto &provider : ImHexApi::Provider::getProviders())
|
||||
ImHexApi::Provider::remove(provider);
|
||||
}
|
||||
} else {
|
||||
ImHexApi::System::closeImHex();
|
||||
}
|
||||
});
|
||||
|
||||
EventProviderClosing::subscribe([](const prv::Provider *provider, bool *shouldClose) {
|
||||
if (provider->isDirty()) {
|
||||
*shouldClose = false;
|
||||
|
||||
Reference in New Issue
Block a user