]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/docview.cpp
Hopefully fixed library names generated by wx-config for OS/2's PM port.
[wxWidgets.git] / src / common / docview.cpp
index 850a94090d9b2aefe433d4b81aa2d71801b79212..221ce1b1364ab66a3209fe731c1727f3cf1e0d9a 100644 (file)
@@ -1225,7 +1225,12 @@ wxDocument *wxDocManager::CreateDocument(const wxString& path, long flags)
             {
                 newDoc->SetDocumentName(temp->GetDocumentName());
                 newDoc->SetDocumentTemplate(temp);
-                newDoc->OnNewDocument();
+                if (!newDoc->OnNewDocument() )
+                {
+                     // Document is implicitly deleted by DeleteAllViews
+                     newDoc->DeleteAllViews();
+                     return NULL;
+                }
             }
             return newDoc;
         }
@@ -1248,7 +1253,12 @@ wxDocument *wxDocManager::CreateDocument(const wxString& path, long flags)
             {
                 newDoc->SetDocumentName(temp->GetDocumentName());
                 newDoc->SetDocumentTemplate(temp);
-                newDoc->OnNewDocument();
+                if (!newDoc->OnNewDocument() )
+                {
+                     // Document is implicitly deleted by DeleteAllViews
+                     newDoc->DeleteAllViews();
+                     return NULL;
+                }
             }
             return newDoc;
         }
@@ -1288,6 +1298,28 @@ wxDocument *wxDocManager::CreateDocument(const wxString& path, long flags)
             }
         }
 
+        //see if this file is already open
+        for (size_t i = 0; i < GetDocuments().GetCount(); ++i)
+        {
+            wxDocument* currentDoc = (wxDocument*)(GetDocuments().Item(i)->GetData());
+#ifdef __WXMSW__
+            //file paths are case-insensitive on Windows
+            if (path2.CmpNoCase(currentDoc->GetFilename()) == 0)
+#else
+            if (path2.Cmp(currentDoc->GetFilename()) == 0)
+#endif
+            {
+                //file already open. Just activate it and return
+                if (currentDoc->GetFirstView())
+                {
+                    ActivateView(currentDoc->GetFirstView(), true);
+                    if (currentDoc->GetDocumentWindow())
+                        currentDoc->GetDocumentWindow()->SetFocus();
+                    return currentDoc;
+                }
+            }
+        }
+
         wxDocument *newDoc = temp->CreateDocument(path2, flags);
         if (newDoc)
         {