From 9a17c0983494cf56ff985fdb932e80ebe7168bb6 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 15 May 2022 18:54:59 +0100 Subject: [PATCH] Pass FOS_xxx options to InitIFileOpenDialog() directly This is more flexible and will allow using this function for the file (and not just directory) dialog too in the future and makes the code more readable and robust already because it removes the use of non-obvious boolean parameters. No real changes. --- src/msw/dirdlg.cpp | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/msw/dirdlg.cpp b/src/msw/dirdlg.cpp index 9b6dd029c9..959c3be1d1 100644 --- a/src/msw/dirdlg.cpp +++ b/src/msw/dirdlg.cpp @@ -90,7 +90,8 @@ wxIMPLEMENT_CLASS(wxDirDialog, wxDialog); // helper functions for wxDirDialog::ShowIFileOpenDialog() bool InitIFileOpenDialog(const wxString& message, const wxString& defaultPath, - bool multipleSelection, bool showHidden, wxCOMPtr& fileDialog); + int options, + wxCOMPtr& fileDialog); bool GetPathsFromIFileOpenDialog(const wxCOMPtr& fileDialog, bool multipleSelection, wxArrayString& paths); bool ConvertIShellItemToPath(const wxCOMPtr& item, wxString& path); @@ -256,8 +257,15 @@ int wxDirDialog::ShowIFileOpenDialog(WXHWND owner) HRESULT hr = S_OK; wxCOMPtr fileDialog; - if ( !InitIFileOpenDialog(m_message, m_path, HasFlag(wxDD_MULTIPLE), - HasFlag(wxDD_SHOW_HIDDEN), fileDialog) ) + // We currently always use FOS_NOCHANGEDIR even if wxDD_CHANGE_DIR was + // specified because we change the directory ourselves in this case. + int options = FOS_PICKFOLDERS | FOS_NOCHANGEDIR; + if ( HasFlag(wxDD_MULTIPLE) ) + options |= FOS_ALLOWMULTISELECT; + if ( HasFlag(wxDD_SHOW_HIDDEN) ) + options |= FOS_FORCESHOWHIDDEN; + + if ( !InitIFileOpenDialog(m_message, m_path, options, fileDialog) ) { return wxID_NONE; // Failed to initialize the dialog } @@ -296,13 +304,11 @@ int wxDirDialog::ShowIFileOpenDialog(WXHWND owner) // helper function for wxDirDialog::ShowIFileOpenDialog() bool InitIFileOpenDialog(const wxString& message, const wxString& defaultPath, - bool multipleSelection, bool showHidden, + int options, wxCOMPtr& fileDialog) { HRESULT hr = S_OK; wxCOMPtr dlg; - // allow to select only a file system folder, do not change the CWD - long options = FOS_PICKFOLDERS | FOS_FORCEFILESYSTEM | FOS_NOCHANGEDIR; hr = ::CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, wxIID_PPV_ARGS(IFileOpenDialog, &dlg)); @@ -312,12 +318,8 @@ bool InitIFileOpenDialog(const wxString& message, const wxString& defaultPath, return false; } - if ( multipleSelection ) - options |= FOS_ALLOWMULTISELECT; - if ( showHidden ) - options |= FOS_FORCESHOWHIDDEN; - - hr = dlg->SetOptions(options); + // allow to select only a file system object + hr = dlg->SetOptions(options | FOS_FORCEFILESYSTEM); if ( FAILED(hr) ) { wxLogApiError(wxS("IFileOpenDialog::SetOptions"), hr);