Update wxFileDialog filter index when setting its path.
This ensures that GetFilename() and GetFilterIndex() always return consistent results, even if the path was set programmatically, e.g. during unattended tests using wxExpectModal<wxFileDialog>. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@77471 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -200,7 +200,12 @@ void wxFileDialogBase::SetPath(const wxString& path)
|
||||
wxString ext;
|
||||
wxFileName::SplitPath(path, &m_dir, &m_fileName, &ext);
|
||||
if ( !ext.empty() )
|
||||
{
|
||||
SetFilterIndexFromExt(ext);
|
||||
|
||||
m_fileName << wxT('.') << ext;
|
||||
}
|
||||
|
||||
m_path = path;
|
||||
}
|
||||
|
||||
@@ -216,6 +221,30 @@ void wxFileDialogBase::SetFilename(const wxString& name)
|
||||
m_path = wxFileName(m_dir, m_fileName).GetFullPath();
|
||||
}
|
||||
|
||||
void wxFileDialogBase::SetFilterIndexFromExt(const wxString& ext)
|
||||
{
|
||||
// if filter is of form "All files (*)|*|..." set correct filter index
|
||||
if ( !ext.empty() && m_wildCard.find(wxT('|')) != wxString::npos )
|
||||
{
|
||||
int filterIndex = -1;
|
||||
|
||||
wxArrayString descriptions, filters;
|
||||
// don't care about errors, handled already by wxFileDialog
|
||||
(void)wxParseCommonDialogsFilter(m_wildCard, descriptions, filters);
|
||||
for (size_t n=0; n<filters.GetCount(); n++)
|
||||
{
|
||||
if (filters[n].Contains(ext))
|
||||
{
|
||||
filterIndex = n;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (filterIndex >= 0)
|
||||
SetFilterIndex(filterIndex);
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// wxFileDialog convenience functions
|
||||
//----------------------------------------------------------------------------
|
||||
@@ -250,26 +279,7 @@ wxString wxFileSelector(const wxString& title,
|
||||
defaultFileName, filter2,
|
||||
flags, wxPoint(x, y));
|
||||
|
||||
// if filter is of form "All files (*)|*|..." set correct filter index
|
||||
if ( !defaultExtension.empty() && filter2.find(wxT('|')) != wxString::npos )
|
||||
{
|
||||
int filterIndex = 0;
|
||||
|
||||
wxArrayString descriptions, filters;
|
||||
// don't care about errors, handled already by wxFileDialog
|
||||
(void)wxParseCommonDialogsFilter(filter2, descriptions, filters);
|
||||
for (size_t n=0; n<filters.GetCount(); n++)
|
||||
{
|
||||
if (filters[n].Contains(defaultExtension))
|
||||
{
|
||||
filterIndex = n;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (filterIndex > 0)
|
||||
fileDialog.SetFilterIndex(filterIndex);
|
||||
}
|
||||
fileDialog.SetFilterIndexFromExt(defaultExtension);
|
||||
|
||||
wxString filename;
|
||||
if ( fileDialog.ShowModal() == wxID_OK )
|
||||
|
Reference in New Issue
Block a user