diff --git a/docs/changes.txt b/docs/changes.txt index 2d07d90137..0d4964a3c6 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -264,6 +264,7 @@ wxMSW: - Fix return value of wxZoomGestureEvent::GetZoomFactor() (s-murphree, #22818). - Update top level icon resolution on DPI change (#22807). - Remove "Printing" from title when printing to PDF (Blake-Madden, #22836). +- Fix sometimes missing overvwrite prompt in "Save" file dialog (#22898). wxOSX: diff --git a/src/msw/filedlg.cpp b/src/msw/filedlg.cpp index a298bdaaab..89104ce539 100644 --- a/src/msw/filedlg.cpp +++ b/src/msw/filedlg.cpp @@ -1597,6 +1597,16 @@ int wxFileDialog::ShowIFileDialog(WXHWND hWndParent) hr = fileDialog->SetFileTypeIndex(m_filterIndex + 1); if ( FAILED(hr) ) wxLogApiError(wxS("IFileDialog::SetFileTypeIndex"), hr); + + // We need to call SetDefaultExtension() to make the file dialog append + // the selected extension by default. It will append the correct + // extension depending on the current file type choice if we call this + // function, but won't do anything at all without it, so find the first + // extension associated with the selected filter and use it here. + wxString defExt = + wildFilters[m_filterIndex].BeforeFirst(';').AfterFirst('.'); + if ( !defExt.empty() && defExt != wxS("*") ) + fileDialog->SetDefaultExtension(defExt.wc_str()); } if ( !m_dir.empty() ) @@ -1608,7 +1618,7 @@ int wxFileDialog::ShowIFileDialog(WXHWND hWndParent) { hr = fileDialog->SetFileName(m_fileName.wc_str()); if ( FAILED(hr) ) - wxLogApiError(wxS("IFileDialog::SetDefaultExtension"), hr); + wxLogApiError(wxS("IFileDialog::SetFileName"), hr); }