- // Check we're really deleted
- if (m_docs.Member(doc))
- delete doc;
- }
- else
- return (wxDocument *) NULL;
- }
-
- // New document: user chooses a template, unless there's only one.
- if (flags & wxDOC_NEW)
- {
- if (n == 1)
- {
- wxDocTemplate *temp = templates[0];
- delete[] templates;
- wxDocument *newDoc = temp->CreateDocument(path, flags);
- if (newDoc)
- {
- newDoc->SetDocumentName(temp->GetDocumentName());
- newDoc->SetDocumentTemplate(temp);
- newDoc->OnNewDocument();
- }
- return newDoc;
- }
-
- wxDocTemplate *temp = SelectDocumentType(templates, n);
- delete[] templates;
- if (temp)
- {
- wxDocument *newDoc = temp->CreateDocument(path, flags);
- if (newDoc)
- {
- newDoc->SetDocumentName(temp->GetDocumentName());
- newDoc->SetDocumentTemplate(temp);
- newDoc->OnNewDocument();
- }
- return newDoc;
- }
- else
- return (wxDocument *) NULL;
- }
-
- // Existing document
- wxDocTemplate *temp = (wxDocTemplate *) NULL;
-
- wxString path2("");
- if (path != "")
- path2 = path;
-
- if (flags & wxDOC_SILENT)
- temp = FindTemplateForPath(path2);
- else
- temp = SelectDocumentPath(templates, n, path2, flags);
-
- delete[] templates;
-
- if (temp)
- {
- wxDocument *newDoc = temp->CreateDocument(path2, flags);
- if (newDoc)
- {
- newDoc->SetDocumentName(temp->GetDocumentName());
- newDoc->SetDocumentTemplate(temp);
- if (!newDoc->OnOpenDocument(path2))
- {
- delete newDoc;
- return (wxDocument *) NULL;
- }
- AddFileToHistory(path2);
- }
- return newDoc;
- }
- else
- return (wxDocument *) NULL;