+ wxString& path,
+ long WXUNUSED(flags),
+ bool WXUNUSED(save))
+{
+ // We can only have multiple filters in Windows and GTK
+#if defined(__WXMSW__) || defined(__WXGTK__) || defined(__WXMAC__)
+ wxString descrBuf;
+
+ int i;
+ for (i = 0; i < noTemplates; i++)
+ {
+ if (templates[i]->IsVisible())
+ {
+ // add a '|' to separate this filter from the previous one
+ if ( !descrBuf.IsEmpty() )
+ descrBuf << wxT('|');
+
+ descrBuf << templates[i]->GetDescription()
+ << wxT(" (") << templates[i]->GetFileFilter() << wxT(") |")
+ << templates[i]->GetFileFilter();
+ }
+ }
+#else
+ wxString descrBuf = wxT("*.*");
+#endif
+
+ int FilterIndex = -1;
+
+ wxWindow* parent = wxFindSuitableParent();
+
+ wxString pathTmp = wxFileSelectorEx(_("Select a file"),
+ m_lastDirectory,
+ wxT(""),
+ &FilterIndex,
+ descrBuf,
+ 0,
+ parent);
+
+ wxDocTemplate *theTemplate = (wxDocTemplate *)NULL;
+ 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;
+
+ // first choose the template using the extension, if this fails (i.e.
+ // wxFileSelectorEx() didn't fill it), then use the path
+ if ( FilterIndex != -1 )
+ theTemplate = templates[FilterIndex];
+ if ( !theTemplate )
+ theTemplate = FindTemplateForPath(path);
+ }
+ else
+ {
+ path = wxT("");
+ }
+
+ return theTemplate;
+
+#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