Skip to content

Commit

Permalink
[Mod] When browsing for folders, use modern browser style when availa…
Browse files Browse the repository at this point in the history
…ble. Old style can be enforced by hidden setting Display.UseOldStyleFolderBrowser (https://bugs.openmpt.org/view.php?id=1687).

git-svn-id: https://source.openmpt.org/svn/openmpt/trunk/OpenMPT@21643 56274372-70c3-4bfc-bfc3-4c3a0b034d27
  • Loading branch information
sagamusix committed Sep 19, 2024
1 parent c3d85d5 commit 54f3769
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 22 deletions.
76 changes: 54 additions & 22 deletions mptrack/FileDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -31,16 +38,36 @@ class CFileDialogEx : public CFileDialog
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()
Expand Down Expand Up @@ -68,10 +95,16 @@ class CFileDialogEx : public CFileDialog
}
#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
{
Expand All @@ -98,14 +131,14 @@ bool FileDialog::Show(CWnd *parent)
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;
Expand All @@ -114,18 +147,6 @@ bool FileDialog::Show(CWnd *parent)
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);
Expand Down Expand Up @@ -211,13 +232,24 @@ int CALLBACK BrowseForFolder::BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM /*
// 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;
Expand Down
1 change: 1 addition & 0 deletions mptrack/TrackerSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ TrackerSettings::TrackerSettings(SettingsContainer &conf)
, 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
Expand Down
1 change: 1 addition & 0 deletions mptrack/TrackerSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,7 @@ class TrackerSettings
CachedSetting<bool> accidentalFlats;
Setting<bool> rememberSongWindows;
Setting<bool> showDirsInSampleBrowser;
Setting<bool> useOldStyleFolderBrowser;
Setting<DefaultChannelColors> defaultRainbowChannelColors;

Setting<FontSetting> commentsFont;
Expand Down

0 comments on commit 54f3769

Please sign in to comment.