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.
This commit is contained in:
parent
791c1f88ad
commit
5ff42d9469
1 changed files with 8 additions and 4 deletions
|
@ -42,9 +42,11 @@ class DialogManager {
|
||||||
DialogMap created_dialogs;
|
DialogMap created_dialogs;
|
||||||
|
|
||||||
/// Close handler which deletes and unregisters closed modeless dialogs
|
/// Close handler which deletes and unregisters closed modeless dialogs
|
||||||
void OnClose(wxCloseEvent &evt) {
|
template<typename Event>
|
||||||
|
void OnClose(Event &evt) {
|
||||||
evt.Skip();
|
evt.Skip();
|
||||||
wxDialog *dialog = static_cast<wxDialog*>(evt.GetEventObject());
|
auto dialog = static_cast<wxWindow *>(evt.GetEventObject());
|
||||||
|
while (!dialog->IsTopLevel()) dialog = dialog->GetParent();
|
||||||
dialog->Destroy();
|
dialog->Destroy();
|
||||||
|
|
||||||
for (auto it = created_dialogs.begin(); it != created_dialogs.end(); ++it) {
|
for (auto it = created_dialogs.begin(); it != created_dialogs.end(); ++it) {
|
||||||
|
@ -70,7 +72,8 @@ public:
|
||||||
try {
|
try {
|
||||||
wxDialog *d = new DialogType(c);
|
wxDialog *d = new DialogType(c);
|
||||||
created_dialogs[&typeid(DialogType)] = d;
|
created_dialogs[&typeid(DialogType)] = d;
|
||||||
d->Bind(wxEVT_CLOSE_WINDOW, &DialogManager::OnClose, this);
|
d->Bind(wxEVT_CLOSE_WINDOW, &DialogManager::OnClose<wxCloseEvent>, this);
|
||||||
|
d->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &DialogManager::OnClose<wxCommandEvent>, this, wxID_CANCEL);
|
||||||
d->Show();
|
d->Show();
|
||||||
SetFloatOnParent(d);
|
SetFloatOnParent(d);
|
||||||
}
|
}
|
||||||
|
@ -105,7 +108,8 @@ public:
|
||||||
|
|
||||||
~DialogManager() {
|
~DialogManager() {
|
||||||
for (auto const& it : created_dialogs) {
|
for (auto const& it : created_dialogs) {
|
||||||
it.second->Unbind(wxEVT_CLOSE_WINDOW, &DialogManager::OnClose, this);
|
it.second->Unbind(wxEVT_CLOSE_WINDOW, &DialogManager::OnClose<wxCloseEvent>, this);
|
||||||
|
it.second->Unbind(wxEVT_COMMAND_BUTTON_CLICKED, &DialogManager::OnClose<wxCommandEvent>, this, wxID_CANCEL);
|
||||||
it.second->Destroy();
|
it.second->Destroy();
|
||||||
}
|
}
|
||||||
created_dialogs.clear();
|
created_dialogs.clear();
|
||||||
|
|
Loading…
Reference in a new issue