wxParseWildcard renamed to wxParseCommonDialogsFilter. Its usage is extended from generic dialogs to MSW, Motif and other incoming ports.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@27941 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
e835546c77
commit
daf3246330
@ -55,8 +55,9 @@ 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
|
||||
- Identical functionality of wxFileDialog::ParseWildcard,
|
||||
wxGenericDirCtrl::ParseFilter, Motif and MSW parsing native dialogs
|
||||
is now accessible in ::wxParseCommonDialogsFilter
|
||||
|
||||
|
||||
|
||||
|
@ -181,7 +181,7 @@ the corresponding topic.
|
||||
\helpref{wxNow}{wxnow}\\
|
||||
\helpref{wxOnAssert}{wxonassert}\\
|
||||
\helpref{wxOpenClipboard}{wxopenclipboard}\\
|
||||
\helpref{wxParseWildcard}{wxparsewildcard}\\
|
||||
\helpref{wxParseCommonDialogsFilter}{wxparsecommondialogsfilter}\\
|
||||
\helpref{wxPathOnly}{wxpathonly}\\
|
||||
\helpref{wxPostDelete}{wxpostdelete}\\
|
||||
\helpref{wxPostEvent}{wxpostevent}\\
|
||||
@ -1094,13 +1094,15 @@ Makes the directory \arg{dir}, returning true if successful.
|
||||
supported (Unix) and doesn't have effect for the other ones.
|
||||
|
||||
|
||||
\membersection{::wxParseWildcard}\label{wxparsewildcard}
|
||||
\membersection{::wxParseCommonDialogsFilter}\label{wxparsecommondialogsfilter}
|
||||
|
||||
\func{int}{wxParseWildcard}{\param{const wxString\& }{wildCard}, \param{wxArrayString\& }{descriptions}, \param{wxArrayString\& }{filters}}
|
||||
\func{int}{wxParseCommonDialogsFilter}{\param{const wxString\& }{wildCard}, \param{wxArrayString\& }{descriptions}, \param{wxArrayString\& }{filters}}
|
||||
|
||||
Parses the \arg{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.
|
||||
On platforms where native dialogs handle only one filter per entry,
|
||||
entries in arrays are automatically adjusted.
|
||||
\arg{wildCard} is in the form:
|
||||
\begin{verbatim}
|
||||
"All files (*)|*|Image Files (*.jpeg *.png)|*.jpg;*.png"
|
||||
|
@ -359,7 +359,7 @@ WXDLLIMPEXP_BASE time_t wxFileModificationTime(const wxString& filename);
|
||||
// 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);
|
||||
WXDLLIMPEXP_BASE int wxParseCommonDialogsFilter(const wxString& wildCard, wxArrayString& descriptions, wxArrayString& filters);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// classes
|
||||
|
@ -647,7 +647,7 @@ void MyFrame::FileOpen(wxCommandEvent& WXUNUSED(event) )
|
||||
#ifdef __WXMOTIF__
|
||||
_T("C++ files (*.cpp)|*.cpp")
|
||||
#else
|
||||
_T("C++ files (*.h;*.cpp)|*.h;*.cpp")
|
||||
_T("C++ files (*.cpp;*.h)|*.cpp;*.h")
|
||||
#endif
|
||||
);
|
||||
|
||||
@ -698,7 +698,7 @@ void MyFrame::FilesOpen(wxCommandEvent& WXUNUSED(event) )
|
||||
#ifdef __WXMOTIF__
|
||||
_T("C++ files (*.cpp)|*.cpp");
|
||||
#else
|
||||
_T("All files (*.*)|*.*|C++ files (*.h;*.cpp)|*.h;*.cpp");
|
||||
_T("All files (*.*)|*.*|C++ files (*.cpp;*.h)|*.cpp;*.h");
|
||||
#endif
|
||||
wxFileDialog dialog(this, _T("Testing open multiple file dialog"),
|
||||
wxEmptyString, wxEmptyString, wildcards,
|
||||
@ -756,7 +756,7 @@ void MyFrame::FileOpenGeneric(wxCommandEvent& WXUNUSED(event) )
|
||||
_T("Testing open file dialog"),
|
||||
wxEmptyString,
|
||||
wxEmptyString,
|
||||
_T("C++ files (*.h;*.cpp)|*.h;*.cpp")
|
||||
_T("C++ files (*.cpp;*.h)|*.cpp;*.h")
|
||||
);
|
||||
|
||||
dialog.SetDirectory(wxGetHomeDir());
|
||||
@ -777,7 +777,7 @@ void MyFrame::FileOpenGeneric(wxCommandEvent& WXUNUSED(event) )
|
||||
|
||||
void MyFrame::FilesOpenGeneric(wxCommandEvent& WXUNUSED(event) )
|
||||
{
|
||||
wxString wildcards = _T("All files (*.*)|*.*|C++ files (*.h;*.cpp)|*.h;*.cpp");
|
||||
wxString wildcards = _T("All files (*.*)|*.*|C++ files (*.cpp;*.h)|*.cpp;*.h");
|
||||
wxGenericFileDialog dialog(this, _T("Testing open multiple file dialog"),
|
||||
wxEmptyString, wxEmptyString, wildcards,
|
||||
wxMULTIPLE);
|
||||
|
@ -1838,9 +1838,9 @@ 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"
|
||||
// filterStr is in the form: "All files (*.*)|*.*|JPEG Files (*.jpeg)|*.jpeg"
|
||||
|
||||
int WXDLLEXPORT wxParseWildcard(const wxString& filterStr, wxArrayString& descriptions, wxArrayString& filters)
|
||||
int WXDLLEXPORT wxParseCommonDialogsFilter(const wxString& filterStr, wxArrayString& descriptions, wxArrayString& filters)
|
||||
{
|
||||
descriptions.Clear();
|
||||
filters.Clear();
|
||||
@ -1855,10 +1855,10 @@ int WXDLLEXPORT wxParseWildcard(const wxString& filterStr, wxArrayString& descri
|
||||
if ( pos == wxNOT_FOUND )
|
||||
{
|
||||
// if there are no '|'s at all in the string just take the entire
|
||||
// string as filter
|
||||
// string as filter and make description empty for later autocompletion
|
||||
if ( filters.IsEmpty() )
|
||||
{
|
||||
descriptions.Add(filterStr);
|
||||
descriptions.Add(wxEmptyString);
|
||||
filters.Add(filterStr);
|
||||
}
|
||||
else
|
||||
@ -1886,6 +1886,62 @@ int WXDLLEXPORT wxParseWildcard(const wxString& filterStr, wxArrayString& descri
|
||||
filters.Add(filter);
|
||||
}
|
||||
|
||||
#if defined(__WXMOTIF__)
|
||||
// split it so there is one wildcard per entry
|
||||
for( size_t i = 0 ; i < descriptions.GetCount() ; i++ )
|
||||
{
|
||||
pos = filters[i].Find(wxT(';'));
|
||||
if (pos != wxNOT_FOUND)
|
||||
{
|
||||
// first split only filters
|
||||
descriptions.Insert(descriptions[i],i+1);
|
||||
filters.Insert(filters[i].Mid(pos+1),i+1);
|
||||
filters[i]=filters[i].Left(pos);
|
||||
|
||||
// autoreplace new filter in description with pattern:
|
||||
// C/C++ Files(*.cpp;*.c;*.h)|*.cpp;*.c;*.h
|
||||
// cause split into:
|
||||
// C/C++ Files(*.cpp)|*.cpp
|
||||
// C/C++ Files(*.c;*.h)|*.c;*.h
|
||||
// and next iteration cause another split into:
|
||||
// C/C++ Files(*.cpp)|*.cpp
|
||||
// C/C++ Files(*.c)|*.c
|
||||
// C/C++ Files(*.h)|*.h
|
||||
for ( size_t k=i;k<i+2;k++ )
|
||||
{
|
||||
pos = descriptions[k].Find(filters[k]);
|
||||
if (pos != wxNOT_FOUND)
|
||||
{
|
||||
wxString before = descriptions[k].Left(pos);
|
||||
wxString after = descriptions[k].Mid(pos+filters[k].Len());
|
||||
pos = before.Find(_T('('),true);
|
||||
if (pos>before.Find(_T(')'),true))
|
||||
{
|
||||
before = before.Left(pos+1);
|
||||
before << filters[k];
|
||||
pos = after.Find(_T(')'));
|
||||
int pos1 = after.Find(_T('('));
|
||||
if (pos != wxNOT_FOUND && (pos<pos1 || pos1==wxNOT_FOUND))
|
||||
{
|
||||
before << after.Mid(pos);
|
||||
descriptions[k] = before;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// autocompletion
|
||||
for( size_t j = 0 ; j < descriptions.GetCount() ; j++ )
|
||||
{
|
||||
if ( descriptions[j] == wxEmptyString && filters[j] != wxEmptyString )
|
||||
{
|
||||
descriptions[j].Printf(_("Files (%s)"), filters[j].c_str());
|
||||
}
|
||||
}
|
||||
|
||||
return filters.GetCount();
|
||||
}
|
||||
|
||||
|
@ -88,7 +88,7 @@ int wxFileDialogBase::ParseWildcard(const wxString& filterStr,
|
||||
wxArrayString& descriptions,
|
||||
wxArrayString& filters)
|
||||
{
|
||||
return ::wxParseWildcard(filterStr, descriptions, filters);
|
||||
return ::wxParseCommonDialogsFilter(filterStr, descriptions, filters);
|
||||
}
|
||||
#endif // WXWIN_COMPATIBILITY_2_4
|
||||
|
||||
@ -175,7 +175,7 @@ wxString wxFileSelector(const wxChar *title,
|
||||
|
||||
wxArrayString descriptions, filters;
|
||||
// don't care about errors, handled already by wxFileDialog
|
||||
(void)wxParseWildcard(filter2, descriptions, filters);
|
||||
(void)wxParseCommonDialogsFilter(filter2, descriptions, filters);
|
||||
for (size_t n=0; n<filters.GetCount(); n++)
|
||||
{
|
||||
if (filters[n].Contains(defaultExtension))
|
||||
|
@ -1137,7 +1137,7 @@ void wxGenericDirCtrl::SetFilter(const wxString& filter)
|
||||
bool wxGenericDirCtrl::ExtractWildcard(const wxString& filterStr, int n, wxString& filter, wxString& description)
|
||||
{
|
||||
wxArrayString filters, descriptions;
|
||||
int count = wxParseWildcard(filterStr, filters, descriptions);
|
||||
int count = wxParseCommonDialogsFilter(filterStr, descriptions, filters);
|
||||
if (count > 0 && n < count)
|
||||
{
|
||||
filter = filters[n];
|
||||
@ -1154,7 +1154,7 @@ bool wxGenericDirCtrl::ExtractWildcard(const wxString& filterStr, int n, wxStrin
|
||||
// filterStr is in the form: "All files (*.*)|*.*|JPEG Files (*.jpeg)|*.jpg"
|
||||
int wxGenericDirCtrl::ParseFilter(const wxString& filterStr, wxArrayString& filters, wxArrayString& descriptions)
|
||||
{
|
||||
return wxParseWildcard(filterStr, descriptions, filters );
|
||||
return wxParseCommonDialogsFilter(filterStr, descriptions, filters );
|
||||
}
|
||||
#endif // WXWIN_COMPATIBILITY_2_4
|
||||
|
||||
@ -1266,7 +1266,7 @@ void wxDirFilterListCtrl::FillFilterList(const wxString& filter, int defaultFilt
|
||||
{
|
||||
Clear();
|
||||
wxArrayString descriptions, filters;
|
||||
size_t n = (size_t) wxParseWildcard(filter, filters, descriptions);
|
||||
size_t n = (size_t) wxParseCommonDialogsFilter(filter, filters, descriptions);
|
||||
|
||||
if (n > 0 && defaultFilter < (int) n)
|
||||
{
|
||||
|
@ -901,7 +901,7 @@ wxGenericFileDialog::wxGenericFileDialog(wxWindow *parent,
|
||||
|
||||
// interpret wildcards
|
||||
wxArrayString wildDescriptions, wildFilters;
|
||||
if ( !wxParseWildcard(m_wildCard, wildDescriptions, wildFilters) )
|
||||
if ( !wxParseCommonDialogsFilter(m_wildCard, wildDescriptions, wildFilters) )
|
||||
{
|
||||
wxFAIL_MSG( wxT("Wrong file type description") );
|
||||
}
|
||||
|
@ -230,37 +230,22 @@ int wxFileDialog::ShowModal()
|
||||
|
||||
of.Flags = msw_flags;
|
||||
|
||||
wxArrayString wildDescriptions, wildFilters;
|
||||
|
||||
//=== Like Alejandro Sierra's wildcard modification >>===================
|
||||
/*
|
||||
In wxFileSelector you can put, instead of a single wild_card,
|
||||
pairs of strings separated by '|'.
|
||||
The first string is a description, and the
|
||||
second is the wild card. You can put any number of pairs.
|
||||
size_t items = wxParseCommonDialogsFilter(m_wildCard, wildDescriptions, wildFilters);
|
||||
|
||||
eg. "description1 (*.ex1)|*.ex1|description2 (*.ex2)|*.ex2"
|
||||
wxASSERT_MSG( items > 0 , _T("empty wildcard list") );
|
||||
|
||||
If you put a single wild card, it works as before the modification.
|
||||
*/
|
||||
//=======================================================================
|
||||
|
||||
wxString theFilter;
|
||||
if ( wxStrlen(m_wildCard) == 0 )
|
||||
theFilter = wxString(wxT("*.*"));
|
||||
else
|
||||
theFilter = m_wildCard ;
|
||||
wxString filterBuffer;
|
||||
|
||||
if ( !wxStrchr( theFilter, wxT('|') ) ) { // only one filter ==> default text
|
||||
filterBuffer.Printf(_("Files (%s)|%s"),
|
||||
theFilter.c_str(), theFilter.c_str());
|
||||
}
|
||||
else { // more then one filter
|
||||
filterBuffer = theFilter;
|
||||
|
||||
for (i = 0; i < items ; i++)
|
||||
{
|
||||
filterBuffer += wildDescriptions[i];
|
||||
filterBuffer += wxT("|");
|
||||
filterBuffer += wildFilters[i];
|
||||
filterBuffer += wxT("|");
|
||||
}
|
||||
|
||||
filterBuffer += wxT("|");
|
||||
// Replace | with \0
|
||||
for (i = 0; i < filterBuffer.Len(); i++ ) {
|
||||
if ( filterBuffer.GetChar(i) == wxT('|') ) {
|
||||
@ -268,7 +253,7 @@ int wxFileDialog::ShowModal()
|
||||
}
|
||||
}
|
||||
|
||||
of.lpstrFilter = (LPTSTR)(const wxChar *)filterBuffer;
|
||||
of.lpstrFilter = (LPTSTR)filterBuffer.c_str();
|
||||
of.nFilterIndex = m_filterIndex + 1;
|
||||
|
||||
//=== Setting defaultFileName >>=========================================
|
||||
|
@ -57,7 +57,7 @@ wxString wxGetOsDescription();
|
||||
// // 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"
|
||||
// int wxParseWildcard(const wxString& wildCard, wxArrayString& descriptions, wxArrayString& filters);
|
||||
// int wxParseCommonDialogsFilter(const wxString& wildCard, wxArrayString& descriptions, wxArrayString& filters);
|
||||
|
||||
#if defined(__WXMSW__) || defined(__WXMAC__)
|
||||
long wxGetFreeMemory();
|
||||
|
Loading…
Reference in New Issue
Block a user