From 2645b45a757dfd92214e8a395398982f4d1bb9fd Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 12 Jul 2002 18:17:24 +0000 Subject: [PATCH 1/1] treat NULL extension properly in wxLoad/SaveFileSelector; don't crash if NULL ext or what pointers are passed to them git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@16154 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/generic/filedlgg.cpp | 60 +++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 23 deletions(-) diff --git a/src/generic/filedlgg.cpp b/src/generic/filedlgg.cpp index 3d7e58d701..19570dec88 100644 --- a/src/generic/filedlgg.cpp +++ b/src/generic/filedlgg.cpp @@ -1540,39 +1540,53 @@ wxString wxFileSelector( const wxChar *title, } } -wxString wxLoadFileSelector( const wxChar *what, const wxChar *ext, const wxChar *default_name, wxWindow *parent ) +static wxString GetWildcardString(const wxChar *ext) { - wxString prompt = wxString::Format(_("Load %s file"), what); - - if (*ext == wxT('.')) - ext++; + wxString wild; + if ( ext ) + { + if ( *ext == wxT('.') ) + ext++; - wxString wild = wxString::Format(_T("*.%s"), ext); + wild << _T("*.") << ext; + } + else // no extension specified + { + wild = wxFileSelectorDefaultWildcardStr; + } - return wxFileSelector(prompt, (const wxChar *) NULL, default_name, - ext, wild, 0, parent); + return wild; } -wxString wxSaveFileSelector(const wxChar *what, const wxChar *extension, const wxChar *default_name, - wxWindow *parent ) +wxString wxLoadFileSelector(const wxChar *what, + const wxChar *ext, + const wxChar *nameDef, + wxWindow *parent) { - wxChar *ext = (wxChar *)extension; - - wxString prompt = wxString::Format(_("Save %s file"), what); - - if (*ext == wxT('.')) - ext++; - - wxString wild = wxString::Format(_T("*.%s"), ext); + wxString prompt; + if ( what && *what ) + prompt = wxString::Format(_("Load %s file"), what); + else + prompt = _("Load file"); - return wxFileSelector(prompt, (const wxChar *) NULL, default_name, - ext, wild, 0, parent); + return wxFileSelector(prompt, NULL, nameDef, ext, + GetWildcardString(ext), 0, parent); } +wxString wxSaveFileSelector(const wxChar *what, + const wxChar *ext, + const wxChar *nameDef, + wxWindow *parent) +{ + wxString prompt; + if ( what && *what ) + prompt = wxString::Format(_("Save %s file"), what); + else + prompt = _("Save file"); - - - + return wxFileSelector(prompt, NULL, nameDef, ext, + GetWildcardString(ext), 0, parent); +} // A module to allow icons table cleanup -- 2.47.2