wxParseWildcard added instead of methods hidden under wxUSE_FILEDLG and wxUSE_DIRDLG.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@27811 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Włodzimierz Skiba 2004-06-15 15:25:33 +00:00
parent f5f3247dcc
commit 9e152a5578
9 changed files with 90 additions and 52 deletions

View File

@ -55,6 +55,8 @@ INCOMPATIBLE CHANGES SINCE 2.4.x
simply switch to using const methods.
- EVT_XXX macros are now type-safe; code that uses wrong type for event
handler's argument will no longer compile.
- Identical functionality of wxFileDialog::ParseWildcard and
wxGenericDirCtrl::ParseFilter is now accessible in ::wxParseWildcard

View File

@ -181,6 +181,7 @@ the corresponding topic.
\helpref{wxNow}{wxnow}\\
\helpref{wxOnAssert}{wxonassert}\\
\helpref{wxOpenClipboard}{wxopenclipboard}\\
\helpref{wxParseWildcard}{wxparsewildcard}\\
\helpref{wxPathOnly}{wxpathonly}\\
\helpref{wxPostDelete}{wxpostdelete}\\
\helpref{wxPostEvent}{wxpostevent}\\
@ -1093,6 +1094,18 @@ Makes the directory {\it dir}, returning true if successful.
supported (Unix) and doesn't have effect for the other ones.
\membersection{::wxParseWildcard}\label{wxparsewildcard}
\func{int}{wxParseWildcard}{\param{const wxString\& }{wildCard}, \param{wxArrayString\& }{descriptions}, \param{wxArrayString\& }{filters}}
Parses the wildCard, returning the number of filters.
Returns 0 if none or if there's a problem,
The arrays will contain an equal number of items found before the error.
{\it wildCard} is in the form:
\begin{verbatim}
"All files (*)|*|Image Files (*.jpeg *.png)|*.jpg;*.png"
\end{verbatim}
\membersection{::wxRemoveFile}\label{wxremovefile}
\func{bool}{wxRemoveFile}{\param{const wxString\& }{file}}

View File

@ -78,6 +78,7 @@ public:
// Utility functions
#if WXWIN_COMPATIBILITY_2_4
// Parses the wildCard, returning the number of filters.
// Returns 0 if none or if there's a problem,
// The arrays will contain an equal number of items found before the error.
@ -86,6 +87,7 @@ public:
static int ParseWildcard(const wxString& wildCard,
wxArrayString& descriptions,
wxArrayString& filters);
#endif // WXWIN_COMPATIBILITY_2_4
// Append first extension to filePath from a ';' separated extensionList
// if filePath = "path/foo.bar" just return it as is

View File

@ -353,6 +353,13 @@ WXDLLIMPEXP_BASE wxString wxGetOSDirectory();
// Get file modification time
WXDLLIMPEXP_BASE time_t wxFileModificationTime(const wxString& filename);
// Parses the wildCard, returning the number of filters.
// Returns 0 if none or if there's a problem,
// The arrays will contain an equal number of items found before the error.
// wildCard is in the form:
// "All files (*)|*|Image Files (*.jpeg *.png)|*.jpg;*.png"
WXDLLIMPEXP_BASE int wxParseWildcard(const wxString& wildCard, wxArrayString& descriptions, wxArrayString& filters);
// ----------------------------------------------------------------------------
// classes
// ----------------------------------------------------------------------------

View File

@ -147,8 +147,10 @@ public:
// Helper
virtual void SetupSections();
#if WXWIN_COMPATIBILITY_2_4
// Parse the filter into an array of filters and an array of descriptions
virtual int ParseFilter(const wxString& filterStr, wxArrayString& filters, wxArrayString& descriptions);
#endif // WXWIN_COMPATIBILITY_2_4
// Find the child that matches the first part of 'path'.
// E.g. if a child path is "/usr" and 'path' is "/usr/include"

View File

@ -1836,6 +1836,60 @@ time_t WXDLLEXPORT wxFileModificationTime(const wxString& filename)
}
// Parses the filterStr, returning the number of filters.
// Returns 0 if none or if there's a problem.
// filterStr is in the form: "All files (*.*)|*.*|JPEG Files (*.jpeg)|*.jpg"
int WXDLLEXPORT wxParseWildcard(const wxString& filterStr, wxArrayString& descriptions, wxArrayString& filters)
{
descriptions.Clear();
filters.Clear();
wxString str(filterStr);
wxString description, filter;
int pos = 0;
while( pos != wxNOT_FOUND )
{
pos = str.Find(wxT('|'));
if ( pos == wxNOT_FOUND )
{
// if there are no '|'s at all in the string just take the entire
// string as filter
if ( filters.IsEmpty() )
{
descriptions.Add(filterStr);
filters.Add(filterStr);
}
else
{
wxFAIL_MSG( _T("missing '|' in the wildcard string!") );
}
break;
}
description = str.Left(pos);
str = str.Mid(pos + 1);
pos = str.Find(wxT('|'));
if ( pos == wxNOT_FOUND )
{
filter = str;
}
else
{
filter = str.Left(pos);
str = str.Mid(pos + 1);
}
descriptions.Add(description);
filters.Add(filter);
}
return filters.GetCount();
}
//------------------------------------------------------------------------
// wild character routines
//------------------------------------------------------------------------

View File

@ -80,59 +80,17 @@ wxFileDialogBase::wxFileDialogBase(wxWindow *parent,
}
}
#if WXWIN_COMPATIBILITY_2_4
// Parses the filterStr, returning the number of filters.
// Returns 0 if none or if there's a problem.
// filterStr is in the form: "All files (*.*)|*.*|JPEG Files (*.jpeg)|*.jpg"
int wxFileDialogBase::ParseWildcard(const wxString& filterStr,
wxArrayString& descriptions,
wxArrayString& filters)
{
descriptions.Clear();
filters.Clear();
wxString str(filterStr);
wxString description, filter;
for ( int pos = 0; pos != wxNOT_FOUND; )
{
pos = str.Find(wxT('|'));
if ( pos == wxNOT_FOUND )
{
// if there are no '|'s at all in the string just take the entire
// string as filter
if ( filters.IsEmpty() )
{
descriptions.Add(filterStr);
filters.Add(filterStr);
}
else
{
wxFAIL_MSG( _T("missing '|' in the wildcard string!") );
}
break;
}
description = str.Left(pos);
str = str.Mid(pos + 1);
pos = str.Find(wxT('|'));
if ( pos == wxNOT_FOUND )
{
filter = str;
}
else
{
filter = str.Left(pos);
str = str.Mid(pos + 1);
}
descriptions.Add(description);
filters.Add(filter);
}
return filters.GetCount();
return ::wxParseWildcard(filterStr, descriptions, filters);
}
#endif // WXWIN_COMPATIBILITY_2_4
wxString wxFileDialogBase::AppendExtension(const wxString &filePath,
const wxString &extensionList)
@ -217,7 +175,7 @@ wxString wxFileSelector(const wxChar *title,
wxArrayString descriptions, filters;
// don't care about errors, handled already by wxFileDialog
(void)wxFileDialogBase::ParseWildcard(filter2, descriptions, filters);
(void)wxParseWildcard(filter2, descriptions, filters);
for (size_t n=0; n<filters.GetCount(); n++)
{
if (filters[n].Contains(defaultExtension))

View File

@ -47,7 +47,6 @@
#include "wx/mimetype.h"
#include "wx/image.h"
#include "wx/choice.h"
#include "wx/filedlg.h" // for wxFileDialogBase::ParseWildcard
#if wxUSE_STATLINE
#include "wx/statline.h"
@ -1132,7 +1131,7 @@ void wxGenericDirCtrl::SetFilter(const wxString& filter)
bool wxGenericDirCtrl::ExtractWildcard(const wxString& filterStr, int n, wxString& filter, wxString& description)
{
wxArrayString filters, descriptions;
int count = ParseFilter(filterStr, filters, descriptions);
int count = wxParseWildcard(filterStr, filters, descriptions);
if (count > 0 && n < count)
{
filter = filters[n];
@ -1143,14 +1142,15 @@ bool wxGenericDirCtrl::ExtractWildcard(const wxString& filterStr, int n, wxStrin
return FALSE;
}
#if WXWIN_COMPATIBILITY_2_4
// Parses the global filter, returning the number of filters.
// Returns 0 if none or if there's a problem.
// filterStr is in the form: "All files (*.*)|*.*|JPEG Files (*.jpeg)|*.jpg"
int wxGenericDirCtrl::ParseFilter(const wxString& filterStr, wxArrayString& filters, wxArrayString& descriptions)
{
return wxFileDialogBase::ParseWildcard(filterStr, descriptions, filters );
return wxParseWildcard(filterStr, descriptions, filters );
}
#endif // WXWIN_COMPATIBILITY_2_4
void wxGenericDirCtrl::DoResize()
{
@ -1252,7 +1252,7 @@ void wxDirFilterListCtrl::FillFilterList(const wxString& filter, int defaultFilt
{
Clear();
wxArrayString descriptions, filters;
size_t n = (size_t) m_dirCtrl->ParseFilter(filter, filters, descriptions);
size_t n = (size_t) wxParseWildcard(filter, filters, descriptions);
if (n > 0 && defaultFilter < (int) n)
{

View File

@ -900,7 +900,7 @@ wxGenericFileDialog::wxGenericFileDialog(wxWindow *parent,
// interpret wildcards
wxArrayString wildDescriptions, wildFilters;
if ( !ParseWildcard(m_wildCard, wildDescriptions, wildFilters) )
if ( !wxParseWildcard(m_wildCard, wildDescriptions, wildFilters) )
{
wxFAIL_MSG( wxT("Wrong file type description") );
}