diff --git a/docs/changes.txt b/docs/changes.txt index cb0f3d7627..8c06d25629 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -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 diff --git a/docs/latex/wx/function.tex b/docs/latex/wx/function.tex index 6a95f696cc..d31df54da0 100644 --- a/docs/latex/wx/function.tex +++ b/docs/latex/wx/function.tex @@ -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" diff --git a/include/wx/filefn.h b/include/wx/filefn.h index 03fa8300d2..0c1bfcbe37 100644 --- a/include/wx/filefn.h +++ b/include/wx/filefn.h @@ -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 diff --git a/samples/dialogs/dialogs.cpp b/samples/dialogs/dialogs.cpp index d0e3f37835..598fe7f515 100644 --- a/samples/dialogs/dialogs.cpp +++ b/samples/dialogs/dialogs.cpp @@ -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); diff --git a/src/common/filefn.cpp b/src/common/filefn.cpp index c98cb1d890..3c0a2f5285 100644 --- a/src/common/filefn.cpp +++ b/src/common/filefn.cpp @@ -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;kbefore.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 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) { diff --git a/src/generic/filedlgg.cpp b/src/generic/filedlgg.cpp index c457e404e7..e3af623719 100644 --- a/src/generic/filedlgg.cpp +++ b/src/generic/filedlgg.cpp @@ -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") ); } diff --git a/src/msw/filedlg.cpp b/src/msw/filedlg.cpp index 775affb082..de26b29ef6 100644 --- a/src/msw/filedlg.cpp +++ b/src/msw/filedlg.cpp @@ -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 >>========================================= diff --git a/wxPython/src/_functions.i b/wxPython/src/_functions.i index 60285dafde..efc60338f3 100644 --- a/wxPython/src/_functions.i +++ b/wxPython/src/_functions.i @@ -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();