Appending the extension after the dialog was hidden is a bad idea as it
misleads the user by using a different file name from the one shown in the
dialog. It is also dangerous as it bypassed wxFD_OVERWRITE_PROMPT check.
So just append the default extension to the initial file name if it doesn't
have any but don't modify the file name once it was accepted by user.
Closes #11256.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62351
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
g_signal_connect (m_widget, "response",
G_CALLBACK (gtk_filedialog_response_callback), this);
g_signal_connect (m_widget, "response",
G_CALLBACK (gtk_filedialog_response_callback), this);
+
+ // deal with extensions/filters
+ wxString defaultFileNameWithExt = defaultFileName;
+ if ( !wildCard.empty() && !defaultFileName.empty() &&
+ !wxFileName(defaultFileName).HasExt() )
+ {
+ // append the default extension to the initial file name: GTK won't do
+ // it for us by default (unlike e.g. MSW)
+ const wxString defaultExt = m_fc.GetCurrentWildCard().AfterFirst('.');
+ if ( defaultExt.find_first_of("?*") == wxString::npos )
+ defaultFileNameWithExt += "." + defaultExt;
+ }
+
+
// if defaultDir is specified it should contain the directory and
// defaultFileName should contain the default name of the file, however if
// directory is not given, defaultFileName contains both
wxFileName fn;
if ( defaultDir.empty() )
// if defaultDir is specified it should contain the directory and
// defaultFileName should contain the default name of the file, however if
// directory is not given, defaultFileName contains both
wxFileName fn;
if ( defaultDir.empty() )
- fn.Assign(defaultFileName);
- else if ( !defaultFileName.empty() )
- fn.Assign(defaultDir, defaultFileName);
+ fn.Assign(defaultFileNameWithExt);
+ else if ( !defaultFileNameWithExt.empty() )
+ fn.Assign(defaultDir, defaultFileNameWithExt);
else
fn.AssignDir(defaultDir);
else
fn.AssignDir(defaultDir);
wxString wxFileDialog::GetPath() const
{
wxString wxFileDialog::GetPath() const
{
- 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
}
void wxFileDialog::GetFilenames(wxArrayString& files) const