From: Vadim Zeitlin Date: Sun, 5 May 2013 16:17:50 +0000 (+0000) Subject: Don't use gtk_file_chooser_set_filename() for save file dialogs. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/9618496b6acd2c74ee2fabc76f241d9dd0faebc0?ds=sidebyside Don't use gtk_file_chooser_set_filename() for save file dialogs. This seems to be broken in old GTK+ versions, so use gtk_file_chooser_set_current_name() and gtk_file_chooser_set_current_folder() for save file dialogs which seem to work in all versions. Closes #15133. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@73932 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/gtk/filectrl.cpp b/src/gtk/filectrl.cpp index 4613ff18a6..b6c642fcab 100644 --- a/src/gtk/filectrl.cpp +++ b/src/gtk/filectrl.cpp @@ -82,7 +82,32 @@ bool wxGtkFileChooser::SetPath( const wxString& path ) if ( path.empty() ) return true; - return gtk_file_chooser_set_filename( m_widget, path.utf8_str() ) != 0; + switch ( gtk_file_chooser_get_action( m_widget ) ) + { + case GTK_FILE_CHOOSER_ACTION_SAVE: + { + wxFileName fn(path); + + const wxString fname = fn.GetFullName(); + gtk_file_chooser_set_current_name( m_widget, fname.utf8_str() ); + + // set the initial file name and/or directory + const wxString dir = fn.GetPath(); + return gtk_file_chooser_set_current_folder( m_widget, + dir.utf8_str() ) != 0; + } + + case GTK_FILE_CHOOSER_ACTION_OPEN: + return gtk_file_chooser_set_filename( m_widget, path.utf8_str() ) != 0; + + case GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER: + case GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER: + break; + } + + wxFAIL_MSG( "Unexpected file chooser type" ); + + return false; } bool wxGtkFileChooser::SetDirectory( const wxString& dir )