PathConfigDlg.cpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /*
  2. * PathConfigDlg.cpp
  3. * -----------------
  4. * Purpose: Default paths and auto save setup dialog.
  5. * Notes : (currently none)
  6. * Authors: OpenMPT Devs
  7. * The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
  8. */
  9. #include "stdafx.h"
  10. #include "resource.h"
  11. #include "PathConfigDlg.h"
  12. #include "FileDialog.h"
  13. #include "Mainfrm.h"
  14. OPENMPT_NAMESPACE_BEGIN
  15. static constexpr std::pair<ConfigurableDirectory TrackerSettings::*, int> PathSettings[] =
  16. {
  17. { &TrackerSettings::PathSongs, IDC_OPTIONS_DIR_MODS },
  18. { &TrackerSettings::PathSamples, IDC_OPTIONS_DIR_SAMPS },
  19. { &TrackerSettings::PathInstruments, IDC_OPTIONS_DIR_INSTS },
  20. { &TrackerSettings::PathPlugins, IDC_OPTIONS_DIR_VSTS },
  21. { &TrackerSettings::PathPluginPresets, IDC_OPTIONS_DIR_VSTPRESETS },
  22. { &TrackerSettings::AutosavePath, IDC_AUTOSAVE_PATH },
  23. };
  24. IMPLEMENT_DYNAMIC(PathConfigDlg, CPropertyPage)
  25. PathConfigDlg::PathConfigDlg()
  26. : CPropertyPage(IDD_OPTIONS_AUTOSAVE)
  27. {
  28. }
  29. void PathConfigDlg::DoDataExchange(CDataExchange* pDX)
  30. {
  31. CPropertyPage::DoDataExchange(pDX);
  32. }
  33. BEGIN_MESSAGE_MAP(PathConfigDlg, CPropertyPage)
  34. // Paths
  35. ON_EN_CHANGE(IDC_OPTIONS_DIR_MODS, &PathConfigDlg::OnSettingsChanged)
  36. ON_EN_CHANGE(IDC_OPTIONS_DIR_SAMPS, &PathConfigDlg::OnSettingsChanged)
  37. ON_EN_CHANGE(IDC_OPTIONS_DIR_INSTS, &PathConfigDlg::OnSettingsChanged)
  38. ON_EN_CHANGE(IDC_OPTIONS_DIR_VSTPRESETS, &PathConfigDlg::OnSettingsChanged)
  39. ON_COMMAND(IDC_BUTTON_CHANGE_MODDIR, &PathConfigDlg::OnBrowseSongs)
  40. ON_COMMAND(IDC_BUTTON_CHANGE_SAMPDIR, &PathConfigDlg::OnBrowseSamples)
  41. ON_COMMAND(IDC_BUTTON_CHANGE_INSTRDIR, &PathConfigDlg::OnBrowseInstruments)
  42. ON_COMMAND(IDC_BUTTON_CHANGE_VSTDIR, &PathConfigDlg::OnBrowsePlugins)
  43. ON_COMMAND(IDC_BUTTON_CHANGE_VSTPRESETSDIR, &PathConfigDlg::OnBrowsePresets)
  44. // Autosave
  45. ON_COMMAND(IDC_CHECK1, &PathConfigDlg::OnSettingsChanged)
  46. ON_BN_CLICKED(IDC_AUTOSAVE_BROWSE, &PathConfigDlg::OnBrowseAutosavePath)
  47. ON_BN_CLICKED(IDC_AUTOSAVE_ENABLE, &PathConfigDlg::OnAutosaveEnable)
  48. ON_BN_CLICKED(IDC_AUTOSAVE_USEORIGDIR, &PathConfigDlg::OnAutosaveUseOrigDir)
  49. ON_BN_CLICKED(IDC_AUTOSAVE_USECUSTOMDIR, &PathConfigDlg::OnAutosaveUseOrigDir)
  50. ON_EN_UPDATE(IDC_AUTOSAVE_PATH, &PathConfigDlg::OnSettingsChanged)
  51. ON_EN_UPDATE(IDC_AUTOSAVE_HISTORY, &PathConfigDlg::OnSettingsChanged)
  52. ON_EN_UPDATE(IDC_AUTOSAVE_INTERVAL, &PathConfigDlg::OnSettingsChanged)
  53. END_MESSAGE_MAP()
  54. BOOL PathConfigDlg::OnInitDialog()
  55. {
  56. CPropertyPage::OnInitDialog();
  57. const auto &settings = TrackerSettings::Instance();
  58. // Default paths
  59. for(const auto & [path, id] : PathSettings)
  60. {
  61. SetDlgItemText(id, (settings.*path).GetDefaultDir().AsNative().c_str());
  62. }
  63. // Autosave
  64. CheckDlgButton(IDC_CHECK1, settings.CreateBackupFiles ? BST_CHECKED : BST_UNCHECKED);
  65. static_cast<CSpinButtonCtrl *>(GetDlgItem(IDC_SPIN1))->SetRange32(1, int32_max);
  66. static_cast<CSpinButtonCtrl *>(GetDlgItem(IDC_SPIN2))->SetRange32(1, int32_max);
  67. CheckDlgButton(IDC_AUTOSAVE_ENABLE, settings.AutosaveEnabled ? BST_CHECKED : BST_UNCHECKED);
  68. SetDlgItemInt(IDC_AUTOSAVE_HISTORY, settings.AutosaveHistoryDepth);
  69. SetDlgItemInt(IDC_AUTOSAVE_INTERVAL, settings.AutosaveIntervalMinutes);
  70. CheckDlgButton(IDC_AUTOSAVE_USEORIGDIR, settings.AutosaveUseOriginalPath ? BST_CHECKED : BST_UNCHECKED);
  71. CheckDlgButton(IDC_AUTOSAVE_USECUSTOMDIR, settings.AutosaveUseOriginalPath ? BST_UNCHECKED : BST_CHECKED);
  72. //enable/disable stuff as appropriate
  73. OnAutosaveEnable();
  74. OnAutosaveUseOrigDir();
  75. return TRUE;
  76. }
  77. mpt::PathString PathConfigDlg::GetPath(int id)
  78. {
  79. return mpt::PathString::FromCString(GetWindowTextString(*GetDlgItem(id))).EnsureTrailingSlash();
  80. }
  81. void PathConfigDlg::OnOK()
  82. {
  83. auto &settings = TrackerSettings::Instance();
  84. // Default paths
  85. for(const auto &path : PathSettings)
  86. {
  87. (settings.*path.first).SetDefaultDir(GetPath(path.second));
  88. }
  89. // Autosave
  90. settings.CreateBackupFiles = IsDlgButtonChecked(IDC_CHECK1) != BST_UNCHECKED;
  91. settings.AutosaveEnabled = (IsDlgButtonChecked(IDC_AUTOSAVE_ENABLE) != BST_UNCHECKED);
  92. settings.AutosaveHistoryDepth = (GetDlgItemInt(IDC_AUTOSAVE_HISTORY));
  93. settings.AutosaveIntervalMinutes = (GetDlgItemInt(IDC_AUTOSAVE_INTERVAL));
  94. settings.AutosaveUseOriginalPath = (IsDlgButtonChecked(IDC_AUTOSAVE_USEORIGDIR) == BST_CHECKED);
  95. CPropertyPage::OnOK();
  96. }
  97. void PathConfigDlg::BrowseFolder(UINT nID)
  98. {
  99. const TCHAR *prompt = (nID == IDC_AUTOSAVE_PATH)
  100. ? _T("Select a folder to store autosaved files in...")
  101. : _T("Select a default folder...");
  102. BrowseForFolder dlg(GetPath(nID), prompt);
  103. if(dlg.Show(this))
  104. {
  105. SetDlgItemText(nID, dlg.GetDirectory().AsNative().c_str());
  106. OnSettingsChanged();
  107. }
  108. }
  109. void PathConfigDlg::OnAutosaveEnable()
  110. {
  111. BOOL enabled = IsDlgButtonChecked(IDC_AUTOSAVE_ENABLE);
  112. GetDlgItem(IDC_AUTOSAVE_INTERVAL)->EnableWindow(enabled);
  113. GetDlgItem(IDC_SPIN1)->EnableWindow(enabled);
  114. GetDlgItem(IDC_AUTOSAVE_HISTORY)->EnableWindow(enabled);
  115. GetDlgItem(IDC_SPIN2)->EnableWindow(enabled);
  116. GetDlgItem(IDC_AUTOSAVE_USEORIGDIR)->EnableWindow(enabled);
  117. GetDlgItem(IDC_AUTOSAVE_USECUSTOMDIR)->EnableWindow(enabled);
  118. GetDlgItem(IDC_AUTOSAVE_PATH)->EnableWindow(enabled);
  119. GetDlgItem(IDC_AUTOSAVE_BROWSE)->EnableWindow(enabled);
  120. OnSettingsChanged();
  121. return;
  122. }
  123. void PathConfigDlg::OnAutosaveUseOrigDir()
  124. {
  125. if (IsDlgButtonChecked(IDC_AUTOSAVE_ENABLE))
  126. {
  127. BOOL enabled = IsDlgButtonChecked(IDC_AUTOSAVE_USEORIGDIR);
  128. GetDlgItem(IDC_AUTOSAVE_PATH)->EnableWindow(!enabled);
  129. GetDlgItem(IDC_AUTOSAVE_BROWSE)->EnableWindow(!enabled);
  130. OnSettingsChanged();
  131. }
  132. return;
  133. }
  134. void PathConfigDlg::OnSettingsChanged()
  135. {
  136. SetModified(TRUE);
  137. }
  138. BOOL PathConfigDlg::OnSetActive()
  139. {
  140. CMainFrame::m_nLastOptionsPage = OPTIONS_PAGE_PATHS;
  141. return CPropertyPage::OnSetActive();
  142. }
  143. BOOL PathConfigDlg::OnKillActive()
  144. {
  145. mpt::PathString path = GetPath(IDC_AUTOSAVE_PATH);
  146. if (!path.IsDirectory() && IsDlgButtonChecked(IDC_AUTOSAVE_ENABLE) && !IsDlgButtonChecked(IDC_AUTOSAVE_USEORIGDIR))
  147. {
  148. Reporting::Error("Backup path does not exist.");
  149. GetDlgItem(IDC_AUTOSAVE_PATH)->SetFocus();
  150. return 0;
  151. }
  152. return CPropertyPage::OnKillActive();
  153. }
  154. OPENMPT_NAMESPACE_END