1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * @file PropRegistry.cpp
5 * @brief PropRegistry implementation file
9 #include "PropRegistry.h"
11 #include "FileOrFolderSelect.h"
12 #include "OptionsDef.h"
13 #include "OptionsMgr.h"
14 #include "OptionsPanel.h"
21 static LPCTSTR f_RegValueEnabled = _T("ContextMenuEnabled");
22 static LPCTSTR f_RegValuePath = _T("Executable");
24 PropRegistry::PropRegistry(COptionsMgr *optionsMgr)
25 : OptionsPanel(optionsMgr, PropRegistry::IDD)
26 , m_bUseRecycleBin(true)
31 void PropRegistry::DoDataExchange(CDataExchange* pDX)
33 CDialog::DoDataExchange(pDX);
34 //{{AFX_DATA_MAP(PropRegistry)
35 DDX_Text(pDX, IDC_EXT_EDITOR_PATH, m_strEditorPath);
36 DDX_Check(pDX, IDC_USE_RECYCLE_BIN, m_bUseRecycleBin);
37 DDX_Text(pDX, IDC_FILTER_USER_PATH, m_strUserFilterPath);
38 DDX_Radio(pDX, IDC_TMPFOLDER_SYSTEM, m_tempFolderType);
39 DDX_Text(pDX, IDC_TMPFOLDER_NAME, m_tempFolder);
43 BEGIN_MESSAGE_MAP(PropRegistry, OptionsPanel)
44 //{{AFX_MSG_MAP(PropRegistry)
45 ON_BN_CLICKED(IDC_EXT_EDITOR_BROWSE, OnBrowseEditor)
46 ON_BN_CLICKED(IDC_FILTER_USER_BROWSE, OnBrowseFilterPath)
47 ON_BN_CLICKED(IDC_TMPFOLDER_BROWSE, OnBrowseTmpFolder)
52 * @brief Reads options values from storage to UI.
54 void PropRegistry::ReadOptions()
56 m_strEditorPath = GetOptionsMgr()->GetString(OPT_EXT_EDITOR_CMD);
57 m_bUseRecycleBin = GetOptionsMgr()->GetBool(OPT_USE_RECYCLE_BIN);
58 m_strUserFilterPath = GetOptionsMgr()->GetString(OPT_FILTER_USERPATH);
59 m_tempFolderType = GetOptionsMgr()->GetBool(OPT_USE_SYSTEM_TEMP_PATH) ? 0 : 1;
60 m_tempFolder = GetOptionsMgr()->GetString(OPT_CUSTOM_TEMP_PATH);
64 * @brief Writes options values from UI to storage.
66 void PropRegistry::WriteOptions()
68 GetOptionsMgr()->SaveOption(OPT_USE_RECYCLE_BIN, m_bUseRecycleBin);
70 String sExtEditor = strutils::trim_ws(m_strEditorPath);
71 if (sExtEditor.empty())
72 sExtEditor = GetOptionsMgr()->GetDefault<String>(OPT_EXT_EDITOR_CMD);
73 GetOptionsMgr()->SaveOption(OPT_EXT_EDITOR_CMD, sExtEditor);
75 String sFilterPath = strutils::trim_ws(m_strUserFilterPath);
76 GetOptionsMgr()->SaveOption(OPT_FILTER_USERPATH, sFilterPath);
78 bool useSysTemp = m_tempFolderType == 0;
79 GetOptionsMgr()->SaveOption(OPT_USE_SYSTEM_TEMP_PATH, useSysTemp);
81 String tempFolder = strutils::trim_ws(m_tempFolder);
82 GetOptionsMgr()->SaveOption(OPT_CUSTOM_TEMP_PATH, tempFolder);
85 BOOL PropRegistry::OnInitDialog()
87 OptionsPanel::OnInitDialog();
88 m_tooltips.Create(this);
89 m_tooltips.SetMaxTipWidth(600);
90 m_tooltips.AddTool(GetDlgItem(IDC_EXT_EDITOR_PATH),
91 _("You can specify the following parameters to the path:\n"
92 "$file: Path name of the current file\n"
93 "$linenum: Line number of the current cursor position").c_str());
97 /// Open file browse dialog to locate editor
98 void PropRegistry::OnBrowseEditor()
101 if (SelectFile(GetSafeHwnd(), path, true, m_strEditorPath.c_str(), _T(""), _("Programs|*.exe;*.bat;*.cmd|All Files (*.*)|*.*||")))
103 SetDlgItemText(IDC_EXT_EDITOR_PATH, path);
107 /// Open Folder selection dialog for user to select filter folder.
108 void PropRegistry::OnBrowseFilterPath()
111 if (SelectFolder(path, m_strUserFilterPath.c_str(), _("Open"), GetSafeHwnd()))
113 SetDlgItemText(IDC_FILTER_USER_PATH, path);
117 /// Select temporary files folder.
118 void PropRegistry::OnBrowseTmpFolder()
121 if (SelectFolder(path, m_tempFolder.c_str(), _T(""), GetSafeHwnd()))
123 SetDlgItemText(IDC_TMPFOLDER_NAME, path);
127 BOOL PropRegistry::PreTranslateMessage(MSG* pMsg)
129 if (pMsg->message == WM_LBUTTONDOWN ||
130 pMsg->message == WM_LBUTTONUP ||
131 pMsg->message == WM_MOUSEMOVE)
133 m_tooltips.RelayEvent(pMsg);
136 return OptionsPanel::PreTranslateMessage(pMsg);