Improve behaviour of "force closing" wxDocuments

When the document was forced to close, OnSaveModified() was still called
and allowed the user to cancel closing the document -- but it was still
closed after OnSaveModified() returned.

Be more upfront about it and tell the user that the document will be
closed anyhow, but still propose them to save it if necessary.

An alternative solution might be to just deprecate "force closing"
entirely, as this seems very user-unfriendly.
This commit is contained in:
Vadim Zeitlin 2022-07-15 00:36:45 +01:00
parent ee6d58abe2
commit dcee1cd025
5 changed files with 85 additions and 7 deletions

View file

@ -75,6 +75,7 @@ wxIMPLEMENT_APP(MyApp);
wxBEGIN_EVENT_TABLE(MyApp, wxApp)
EVT_MENU(wxID_ABOUT, MyApp::OnAbout)
EVT_MENU(wxID_CLEAR, MyApp::OnForceCloseAll)
wxEND_EVENT_TABLE()
MyApp::MyApp()
@ -315,6 +316,7 @@ void MyApp::AppendDocumentFileCommands(wxMenu *menu, bool supportsPrinting)
menu->Append(wxID_SAVE);
menu->Append(wxID_SAVEAS);
menu->Append(wxID_REVERT, _("Re&vert..."));
menu->Append(wxID_CLEAR, "&Force close all");
if ( supportsPrinting )
{
@ -437,6 +439,13 @@ wxFrame *MyApp::CreateChildFrame(wxView *view, bool isCanvas)
return subframe;
}
void MyApp::OnForceCloseAll(wxCommandEvent& WXUNUSED(event))
{
// Pass "true" here to force closing just for testing this functionality,
// there is no real reason to force the issue here.
wxDocManager::GetDocumentManager()->CloseDocuments(true);
}
void MyApp::OnAbout(wxCommandEvent& WXUNUSED(event))
{
wxString modeName;

View file

@ -71,6 +71,9 @@ private:
void CreateMenuBarForFrame(wxFrame *frame, wxMenu *file, wxMenu *edit);
// force close all windows
void OnForceCloseAll(wxCommandEvent& event);
// show the about box: as we can have different frames it's more
// convenient, even if somewhat less usual, to handle this in the
// application object itself