X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3285e9a347c8b67774de6110444ed50bd6b8cd21..64ea838d8f4d1853b7d850db93ee565e901d099a:/src/common/docview.cpp diff --git a/src/common/docview.cpp b/src/common/docview.cpp index 0154cbdf1e..8ed6b129aa 100644 --- a/src/common/docview.cpp +++ b/src/common/docview.cpp @@ -60,6 +60,7 @@ #include "wx/vector.h" #include "wx/scopedarray.h" #include "wx/scopedptr.h" +#include "wx/scopeguard.h" #include "wx/except.h" #if wxUSE_STD_IOSTREAM @@ -859,17 +860,19 @@ wxDocument *wxDocTemplate::CreateDocument(const wxString& path, long flags) bool wxDocTemplate::InitDocument(wxDocument* doc, const wxString& path, long flags) { + wxScopeGuard g = wxMakeObjGuard(*doc, &wxDocument::DeleteAllViews); + doc->SetFilename(path); doc->SetDocumentTemplate(this); GetDocumentManager()->AddDocument(doc); doc->SetCommandProcessor(doc->OnCreateCommandProcessor()); - if (doc->OnCreate(path, flags)) - return true; + if ( !doc->OnCreate(path, flags) ) + return false; - if (GetDocumentManager()->GetDocuments().Member(doc)) - doc->DeleteAllViews(); - return false; + g.Dismiss(); // no need to call DeleteAllViews() anymore + + return true; } wxView *wxDocTemplate::CreateView(wxDocument *doc, long flags)