From 386feaba50fbbb013ba18d9cd9b12bb9a1ad806c Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 11 Nov 2014 00:59:08 +0000 Subject: [PATCH] Re-add wxFD_OVERWRITE_PROMPT and wxFD_FILE_MUST_EXIST to wxGenericFileDialog. Support for these styles was accidentally removed in r48733, re-add them back. Closes #16652. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_3_0_BRANCH@78121 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 2 ++ src/generic/filedlgg.cpp | 28 +++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/docs/changes.txt b/docs/changes.txt index b7880e5327..5ab0e195d7 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -580,6 +580,8 @@ Major new features in this release All (GUI): - Fix several floating point rounding bugs in wxPropertyGrid (Artur Wieczorek). +- Restore support for wxFD_OVERWRITE_PROMPT and wxFD_FILE_MUST_EXIST in + wxGenericFileDialog which was accidentally lost some time ago (Carl Godkin). wxGTK: diff --git a/src/generic/filedlgg.cpp b/src/generic/filedlgg.cpp index 9ec0842c64..98ee38f0fd 100644 --- a/src/generic/filedlgg.cpp +++ b/src/generic/filedlgg.cpp @@ -344,9 +344,35 @@ void wxGenericFileDialog::OnOk( wxCommandEvent &WXUNUSED(event) ) if (selectedFiles.Count() == 0) return; + const wxString& path = selectedFiles[0]; + if (selectedFiles.Count() == 1) { - SetPath( selectedFiles[0] ); + SetPath(path); + } + + // check that the file [doesn't] exist if necessary + if ( HasFdFlag(wxFD_SAVE) && HasFdFlag(wxFD_OVERWRITE_PROMPT) && + wxFileExists(path) ) + { + if ( wxMessageBox + ( + wxString::Format + ( + _("File '%s' already exists, do you really want to overwrite it?"), + path + ), + _("Confirm"), + wxYES_NO + ) != wxYES) + return; + } + else if ( HasFdFlag(wxFD_OPEN) && HasFdFlag(wxFD_FILE_MUST_EXIST) && + !wxFileExists(path) ) + { + wxMessageBox(_("Please choose an existing file."), _("Error"), + wxOK | wxICON_ERROR ); + return; } EndModal(wxID_OK);