]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/docview.cpp
Add missing WXK constants for the control keys
[wxWidgets.git] / src / common / docview.cpp
index 0154cbdf1e80d09337faf21e4d73318a2b08297b..8ed6b129aaf1deb94fd699058af14ef691ef78c4 100644 (file)
@@ -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)