]> git.saurik.com Git - wxWidgets.git/commitdiff
Applied patch [ 1163322 ] Patch to prevent MDI app from opening the same file twice
authorJulian Smart <julian@anthemion.co.uk>
Wed, 30 Mar 2005 16:35:07 +0000 (16:35 +0000)
committerJulian Smart <julian@anthemion.co.uk>
Wed, 30 Mar 2005 16:35:07 +0000 (16:35 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@33185 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/common/docview.cpp

index 850a94090d9b2aefe433d4b81aa2d71801b79212..9946ac26687d7d0806b1984ee3c7ac4ab094207d 100644 (file)
@@ -1288,6 +1288,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)
         {