Fix #9917: File save dialog does not honor file extension on GTK
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@55350 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -48,8 +48,14 @@ public:
|
||||
void SetWildcard( const wxString& wildCard );
|
||||
void SetFilterIndex( int filterIndex );
|
||||
|
||||
wxString GetCurrentWildCard() const
|
||||
{ return m_wildcards[GetFilterIndex()]; }
|
||||
|
||||
private:
|
||||
GtkFileChooser *m_widget;
|
||||
// First wildcard in filter, to be used when the user
|
||||
// saves a file without giving an extension.
|
||||
wxArrayString m_wildcards;
|
||||
};
|
||||
|
||||
#if wxUSE_FILECTRL
|
||||
|
@@ -111,6 +111,8 @@ wxString wxGtkFileChooser::GetFilename() const
|
||||
|
||||
void wxGtkFileChooser::SetWildcard( const wxString& wildCard )
|
||||
{
|
||||
m_wildcards.Empty();
|
||||
|
||||
// parse filters
|
||||
wxArrayString wildDescriptions, wildFilters;
|
||||
|
||||
@@ -144,10 +146,16 @@ void wxGtkFileChooser::SetWildcard( const wxString& wildCard )
|
||||
gtk_file_filter_set_name( filter, wxGTK_CONV_SYS( wildDescriptions[n] ) );
|
||||
|
||||
wxStringTokenizer exttok( wildFilters[n], wxT( ";" ) );
|
||||
|
||||
int n = 1;
|
||||
while ( exttok.HasMoreTokens() )
|
||||
{
|
||||
wxString token = exttok.GetNextToken();
|
||||
gtk_file_filter_add_pattern( filter, wxGTK_CONV_SYS( token ) );
|
||||
|
||||
if (n == 1)
|
||||
m_wildcards.Add( token ); // Only add first pattern to list, used later when saving
|
||||
n++;
|
||||
}
|
||||
|
||||
gtk_file_chooser_add_filter( chooser, filter );
|
||||
|
@@ -335,7 +335,21 @@ void wxFileDialog::OnSize(wxSizeEvent&)
|
||||
|
||||
wxString wxFileDialog::GetPath() const
|
||||
{
|
||||
return m_fc.GetPath();
|
||||
wxFileName fn = m_fc.GetPath();
|
||||
|
||||
if (HasFdFlag(wxFD_SAVE))
|
||||
{
|
||||
// add extension
|
||||
if (!fn.HasExt())
|
||||
{
|
||||
wxFileName wildcard( "/dummy", m_fc.GetCurrentWildCard() );
|
||||
wxString ext = wildcard.GetExt();
|
||||
if (!ext.empty() && (ext.Find('?') == wxNOT_FOUND) && (ext.Find('*') == wxNOT_FOUND))
|
||||
fn.SetExt( ext );
|
||||
}
|
||||
}
|
||||
|
||||
return fn.GetFullPath();
|
||||
}
|
||||
|
||||
void wxFileDialog::GetFilenames(wxArrayString& files) const
|
||||
|
Reference in New Issue
Block a user