Restore cwd even if wxFileDialog is cancelled in wxMSW
Sometimes the file dialog changes the current directory even if it is
cancelled, so restore it in any case, not only after successful return.
See https://github.com/wxWidgets/wxWidgets/pull/263
(cherry picked from commit ceaa840d7b
)
This commit is contained in:
committed by
Vadim Zeitlin
parent
f358979d35
commit
7b224881d0
@@ -676,23 +676,30 @@ int wxFileDialog::ShowModal()
|
||||
}
|
||||
}
|
||||
|
||||
// Create a temporary struct to restore the CWD when we exit this function
|
||||
// store off before the standard windows dialog can possibly change it
|
||||
const wxString cwdOrig = wxGetCwd();
|
||||
|
||||
//== Execute FileDialog >>=================================================
|
||||
|
||||
if ( !ShowCommFileDialog(&of, m_windowStyle) )
|
||||
return wxID_CANCEL;
|
||||
struct CwdRestore
|
||||
{
|
||||
wxString value;
|
||||
~CwdRestore()
|
||||
{
|
||||
if (!value.empty())
|
||||
wxSetWorkingDirectory(value);
|
||||
}
|
||||
} cwdOrig;
|
||||
|
||||
// GetOpenFileName will always change the current working directory on
|
||||
// (according to MSDN) "Windows NT 4.0/2000/XP" because the flag
|
||||
// OFN_NOCHANGEDIR has no effect. If the user did not specify
|
||||
// wxFD_CHANGE_DIR let's restore the current working directory to what it
|
||||
// was before the dialog was shown.
|
||||
if ( msw_flags & OFN_NOCHANGEDIR )
|
||||
{
|
||||
wxSetWorkingDirectory(cwdOrig);
|
||||
}
|
||||
if (msw_flags & OFN_NOCHANGEDIR)
|
||||
cwdOrig.value = wxGetCwd();
|
||||
|
||||
//== Execute FileDialog >>=================================================
|
||||
|
||||
if ( !ShowCommFileDialog(&of, m_windowStyle) )
|
||||
return wxID_CANCEL;
|
||||
|
||||
m_fileNames.Empty();
|
||||
|
||||
|
Reference in New Issue
Block a user