From 5ff42d94690a3c46c11987b9494db564ff28a4a0 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Tue, 9 Jul 2013 08:33:04 -0700 Subject: [PATCH] Also handle wxID_CANCEL in DialogManager wxEVT_CLOSE_WINDOW is only triggered from the platform's close buttons, not cancel buttons/ESC, so modeless dialogs closed in that way were not getting deleted. --- aegisub/src/dialog_manager.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/aegisub/src/dialog_manager.h b/aegisub/src/dialog_manager.h index edf54c897..adbd471f4 100644 --- a/aegisub/src/dialog_manager.h +++ b/aegisub/src/dialog_manager.h @@ -42,9 +42,11 @@ class DialogManager { DialogMap created_dialogs; /// Close handler which deletes and unregisters closed modeless dialogs - void OnClose(wxCloseEvent &evt) { + template + void OnClose(Event &evt) { evt.Skip(); - wxDialog *dialog = static_cast(evt.GetEventObject()); + auto dialog = static_cast(evt.GetEventObject()); + while (!dialog->IsTopLevel()) dialog = dialog->GetParent(); dialog->Destroy(); for (auto it = created_dialogs.begin(); it != created_dialogs.end(); ++it) { @@ -70,7 +72,8 @@ public: try { wxDialog *d = new DialogType(c); created_dialogs[&typeid(DialogType)] = d; - d->Bind(wxEVT_CLOSE_WINDOW, &DialogManager::OnClose, this); + d->Bind(wxEVT_CLOSE_WINDOW, &DialogManager::OnClose, this); + d->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &DialogManager::OnClose, this, wxID_CANCEL); d->Show(); SetFloatOnParent(d); } @@ -105,7 +108,8 @@ public: ~DialogManager() { for (auto const& it : created_dialogs) { - it.second->Unbind(wxEVT_CLOSE_WINDOW, &DialogManager::OnClose, this); + it.second->Unbind(wxEVT_CLOSE_WINDOW, &DialogManager::OnClose, this); + it.second->Unbind(wxEVT_COMMAND_BUTTON_CLICKED, &DialogManager::OnClose, this, wxID_CANCEL); it.second->Destroy(); } created_dialogs.clear();