From: <sv...@op...> - 2024-09-19 17:28:00
|
Author: sagamusix Date: Thu Sep 19 19:27:48 2024 New Revision: 21643 URL: https://source.openmpt.org/browse/openmpt/?op=revision&rev=21643 Log: [Mod] When browsing for folders, use modern browser style when available. Old style can be enforced by hidden setting Display.UseOldStyleFolderBrowser (https://bugs.openmpt.org/view.php?id=1687). Modified: trunk/OpenMPT/mptrack/FileDialog.cpp trunk/OpenMPT/mptrack/TrackerSettings.cpp trunk/OpenMPT/mptrack/TrackerSettings.h Modified: trunk/OpenMPT/mptrack/FileDialog.cpp ============================================================================== --- trunk/OpenMPT/mptrack/FileDialog.cpp Thu Sep 19 18:51:42 2024 (r21642) +++ trunk/OpenMPT/mptrack/FileDialog.cpp Thu Sep 19 19:27:48 2024 (r21643) @@ -19,10 +19,17 @@ OPENMPT_NAMESPACE_BEGIN +enum class FileDialogType +{ + OpenFile, + SaveFile, + BrowseForFolder, +}; + class CFileDialogEx : public CFileDialog { public: - CFileDialogEx(bool bOpenFileDialog, + CFileDialogEx(FileDialogType type, LPCTSTR lpszDefExt, LPCTSTR lpszFileName, DWORD dwFlags, @@ -31,16 +38,36 @@ DWORD dwSize, BOOL bVistaStyle, bool preview) - : CFileDialog(bOpenFileDialog ? TRUE : FALSE, lpszDefExt, lpszFileName, dwFlags, lpszFilter, pParentWnd, dwSize, bVistaStyle) + : CFileDialog((type != FileDialogType::SaveFile) ? TRUE : FALSE, lpszDefExt, lpszFileName, dwFlags, lpszFilter, pParentWnd, dwSize, bVistaStyle) , m_fileNameBuf(65536) , doPreview(preview) - , played(false) { // MFC's filename buffer is way too small for multi-selections of a large number of files. _tcsncpy(m_fileNameBuf.data(), lpszFileName, m_fileNameBuf.size()); m_fileNameBuf.back() = '\0'; m_ofn.lpstrFile = m_fileNameBuf.data(); m_ofn.nMaxFile = mpt::saturate_cast<DWORD>(m_fileNameBuf.size()); + + if(type == FileDialogType::BrowseForFolder) + { + m_bPickFoldersMode = TRUE; + m_bPickNonFileSysFoldersMode = FALSE; + } + +#if MPT_WINNT_AT_LEAST(MPT_WIN_VISTA) + const auto places = + { + &TrackerSettings::Instance().PathPluginPresets, + &TrackerSettings::Instance().PathPlugins, + &TrackerSettings::Instance().PathSamples, + &TrackerSettings::Instance().PathInstruments, + &TrackerSettings::Instance().PathSongs, + }; + for(const auto place : places) + { + AddPlace(place->GetDefaultDir()); + } +#endif } ~CFileDialogEx() @@ -68,10 +95,16 @@ } #endif + static bool CanUseModernStyle() + { + return !mpt::OS::Windows::IsWine() && mpt::osinfo::windows::Version::Current().IsAtLeast(mpt::osinfo::windows::Version::WinVista); + } + protected: std::vector<TCHAR> m_fileNameBuf; CString oldName; - bool doPreview, played; + const bool doPreview; + bool played = false; void OnFileNameChange() override { @@ -98,14 +131,14 @@ m_filenames.clear(); // First, set up the dialog... - CFileDialogEx dlg(m_load, + CFileDialogEx dlg(m_load ? FileDialogType::OpenFile : FileDialogType::SaveFile, m_defaultExtension.empty() ? nullptr : m_defaultExtension.c_str(), m_defaultFilename.c_str(), OFN_EXPLORER | OFN_NOCHANGEDIR | OFN_HIDEREADONLY | OFN_ENABLESIZING | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | (m_multiSelect ? OFN_ALLOWMULTISELECT : 0) | (m_load ? 0 : (OFN_OVERWRITEPROMPT | OFN_NOREADONLYRETURN)), m_extFilter.c_str(), parent != nullptr ? parent : CMainFrame::GetMainFrame(), 0, - (mpt::OS::Windows::IsWine() || mpt::osinfo::windows::Version::Current().IsBefore(mpt::osinfo::windows::Version::WinVista)) ? FALSE : TRUE, + CFileDialogEx::CanUseModernStyle() ? TRUE : FALSE, m_preview && TrackerSettings::Instance().previewInFileDialogs); OPENFILENAME &ofn = dlg.GetOFN(); ofn.nFilterIndex = m_filterIndex != nullptr ? *m_filterIndex : 0; @@ -114,18 +147,6 @@ ofn.lpstrInitialDir = m_workingDirectory.c_str(); } #if MPT_WINNT_AT_LEAST(MPT_WIN_VISTA) - const auto places = - { - &TrackerSettings::Instance().PathPluginPresets, - &TrackerSettings::Instance().PathPlugins, - &TrackerSettings::Instance().PathSamples, - &TrackerSettings::Instance().PathInstruments, - &TrackerSettings::Instance().PathSongs, - }; - for(const auto place : places) - { - dlg.AddPlace(place->GetDefaultDir()); - } for(const auto &place : m_places) { dlg.AddPlace(place); @@ -211,13 +232,24 @@ // Display the folder dialog. bool BrowseForFolder::Show(CWnd *parent) { - // Note: MFC's CFolderPickerDialog won't work on pre-Vista systems, as it tries to use OPENFILENAME. BypassInputHandler bih; + + // Note: MFC's CFolderPickerDialog won't work on pre-Vista systems, as it tries to use OPENFILENAME unconditionally. + if(CFileDialogEx::CanUseModernStyle() && !TrackerSettings::Instance().useOldStyleFolderBrowser) + { + CFileDialogEx dlg{FileDialogType::BrowseForFolder, nullptr, m_workingDirectory.AsNative().c_str(), 0, nullptr, parent, 0, TRUE, false}; + dlg.m_ofn.lpstrTitle = m_caption; + if(dlg.DoModal() != IDOK) + return false; + m_workingDirectory = mpt::PathString::FromCString(dlg.GetFolderPath()); + return true; + } + TCHAR path[MAX_PATH]; - BROWSEINFO bi; - MemsetZero(bi); + BROWSEINFO bi{}; bi.hwndOwner = (parent != nullptr ? parent : theApp.m_pMainWnd)->m_hWnd; - if(!m_caption.IsEmpty()) bi.lpszTitle = m_caption; + if(!m_caption.IsEmpty()) + bi.lpszTitle = m_caption; bi.pszDisplayName = path; bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_USENEWUI; bi.lpfn = BrowseCallbackProc; Modified: trunk/OpenMPT/mptrack/TrackerSettings.cpp ============================================================================== --- trunk/OpenMPT/mptrack/TrackerSettings.cpp Thu Sep 19 18:51:42 2024 (r21642) +++ trunk/OpenMPT/mptrack/TrackerSettings.cpp Thu Sep 19 19:27:48 2024 (r21643) @@ -196,6 +196,7 @@ , accidentalFlats(conf, U_("Display"), U_("AccidentalFlats"), false) , rememberSongWindows(conf, U_("Display"), U_("RememberSongWindows"), true) , showDirsInSampleBrowser(conf, U_("Display"), U_("ShowDirsInSampleBrowser"), false) + , useOldStyleFolderBrowser(conf, U_("Display"), U_("UseOldStyleFolderBrowser"), false) , defaultRainbowChannelColors(conf, U_("Display"), U_("DefaultChannelColors"), DefaultChannelColors::Random) , commentsFont(conf, U_("Display"), U_("Comments Font"), FontSetting(U_("Courier New"), 120)) // Misc Modified: trunk/OpenMPT/mptrack/TrackerSettings.h ============================================================================== --- trunk/OpenMPT/mptrack/TrackerSettings.h Thu Sep 19 18:51:42 2024 (r21642) +++ trunk/OpenMPT/mptrack/TrackerSettings.h Thu Sep 19 19:27:48 2024 (r21643) @@ -693,6 +693,7 @@ CachedSetting<bool> accidentalFlats; Setting<bool> rememberSongWindows; Setting<bool> showDirsInSampleBrowser; + Setting<bool> useOldStyleFolderBrowser; Setting<DefaultChannelColors> defaultRainbowChannelColors; Setting<FontSetting> commentsFont; |