- char *pathTmp = wxFileSelector(_("Select a file"), "", "",
- temp->GetDefaultExtension(),
- temp->GetFileFilter(),
- 0, wxTheApp->GetTopWindow());
-
- if (pathTmp)
- {
- path = pathTmp;
- return temp;
- }
- else
- return (wxDocTemplate *) NULL;
-#endif
+ wxWindow* parent = wxFindSuitableParent();
+
+ wxString pathTmp = wxFileSelectorEx(_("Select a file"),
+ m_lastDirectory,
+ wxT(""),
+ &FilterIndex,
+ descrBuf,
+ 0,
+ parent);
+
+ if (!pathTmp.IsEmpty())
+ {
+ if (!wxFileExists(pathTmp))
+ {
+ wxString msgTitle;
+ if (!wxTheApp->GetAppName().IsEmpty())
+ msgTitle = wxTheApp->GetAppName();
+ else
+ msgTitle = wxString(_("File error"));
+
+ (void)wxMessageBox(_("Sorry, could not open this file."), msgTitle, wxOK | wxICON_EXCLAMATION,
+ parent);
+
+ path = wxT("");
+ return (wxDocTemplate *) NULL;
+ }
+ m_lastDirectory = wxPathOnly(pathTmp);
+
+ path = pathTmp;
+
+ // This is dodgy in that we're selecting the template on the
+ // basis of the file extension, which may not be a standard
+ // one. We really want to know exactly which template was
+ // chosen by using a more advanced file selector.
+ wxDocTemplate *theTemplate = FindTemplateForPath(path);
+ if ( !theTemplate )
+ theTemplate = templates[FilterIndex];
+
+ return theTemplate;
+ }
+ else
+ {
+ path = wxT("");
+ return (wxDocTemplate *) NULL;
+ }
+#if 0
+ // In all other windowing systems, until we have more advanced
+ // file selectors, we must select the document type (template) first, and
+ // _then_ pop up the file selector.
+ wxDocTemplate *temp = SelectDocumentType(templates, noTemplates);
+ if (!temp)
+ return (wxDocTemplate *) NULL;
+
+ wxChar *pathTmp = wxFileSelector(_("Select a file"), wxT(""), wxT(""),
+ temp->GetDefaultExtension(),
+ temp->GetFileFilter(),
+ 0, wxTheApp->GetTopWindow());
+
+ if (pathTmp)
+ {
+ path = pathTmp;
+ return temp;
+ }
+ else
+ return (wxDocTemplate *) NULL;
+#endif // 0