]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/docview.cpp
Added wxRichTextTableBlock class to help with table UI operations
[wxWidgets.git] / src / common / docview.cpp
index fc1c256337baa61a4766a83b34d5bf24dc56f954..45205f0e0076b3f126af0490fa32d98fa0a24ae5 100644 (file)
@@ -4,7 +4,6 @@
 // Author:      Julian Smart
 // Modified by: Vadim Zeitlin
 // Created:     01/02/97
-// RCS-ID:      $Id$
 // Copyright:   (c) Julian Smart
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
@@ -858,19 +857,25 @@ 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 false;
-
-    g.Dismiss(); // no need to call DeleteAllViews() anymore
+    // Normally, if wxDocument::OnCreate() fails, it happens because the view
+    // initialization fails and then the document is destroyed due to the
+    // destruction of its last view. But take into account the (currently
+    // unrealized, AFAICS) possibility of other failures as well and ensure
+    // that the document is always destroyed if it can't be initialized.
+    wxTRY
+    {
+        doc->SetFilename(path);
+        doc->SetDocumentTemplate(this);
+        GetDocumentManager()->AddDocument(doc);
+        doc->SetCommandProcessor(doc->OnCreateCommandProcessor());
 
-    return true;
+        return doc->OnCreate(path, flags);
+    }
+    wxCATCH_ALL(
+        if ( GetDocumentManager()->GetDocuments().Member(doc) )
+            doc->DeleteAllViews();
+        throw;
+    )
 }
 
 wxView *wxDocTemplate::CreateView(wxDocument *doc, long flags)
@@ -1506,7 +1511,6 @@ wxDocument *wxDocManager::CreateDocument(const wxString& pathOrig, long flags)
         return NULL;
 
     docNew->SetDocumentName(temp->GetDocumentName());
-    docNew->SetDocumentTemplate(temp);
 
     wxTRY
     {