]> git.saurik.com Git - wxWidgets.git/commitdiff
Fix #9917: File save dialog does not honor file extension on GTK
authorRobert Roebling <robert@roebling.de>
Fri, 29 Aug 2008 13:57:03 +0000 (13:57 +0000)
committerRobert Roebling <robert@roebling.de>
Fri, 29 Aug 2008 13:57:03 +0000 (13:57 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@55350 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/gtk/filectrl.h
src/gtk/filectrl.cpp
src/gtk/filedlg.cpp

index d5a462ef81d09575dde829bea4f33d51ec891acb..e194bfc49fa41ae26f4de1162ce3bfec3d362b15 100644 (file)
@@ -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
index dace1751e773a88f90abb84daad02da6e18936b6..d4ff4dcdf9010a723489ee90dff2d51744b470de 100644 (file)
@@ -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 );
index e8906dfd4feab3be5e413f36ad8c770df496c39f..a472332a8b17273e73571a3b99bff299f0f12a39 100644 (file)
@@ -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