OSDN Git Service

Fix build errors
[winmerge-jp/winmerge-jp.git] / Src / PropRegistry.cpp
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /**
3  * @file  PropRegistry.cpp
4  *
5  * @brief PropRegistry implementation file
6  */
7
8 #include "stdafx.h"
9 #include "PropRegistry.h"
10 #include "RegKey.h"
11 #include "FileOrFolderSelect.h"
12 #include "OptionsDef.h"
13 #include "OptionsMgr.h"
14 #include "OptionsPanel.h"
15
16 #ifdef _DEBUG
17 #define new DEBUG_NEW
18 #endif
19
20 // registry values
21 static LPCTSTR f_RegValueEnabled = _T("ContextMenuEnabled");
22 static LPCTSTR f_RegValuePath = _T("Executable");
23
24 PropRegistry::PropRegistry(COptionsMgr *optionsMgr)
25 : OptionsPanel(optionsMgr, PropRegistry::IDD)
26 , m_bUseRecycleBin(true)
27 , m_tempFolderType(0)
28 {
29 }
30
31 void PropRegistry::DoDataExchange(CDataExchange* pDX)
32 {
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);
40         //}}AFX_DATA_MAP
41 }
42
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)
48         //}}AFX_MSG_MAP
49 END_MESSAGE_MAP()
50
51 /** 
52  * @brief Reads options values from storage to UI.
53  */
54 void PropRegistry::ReadOptions()
55 {
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);
61 }
62
63 /** 
64  * @brief Writes options values from UI to storage.
65  */
66 void PropRegistry::WriteOptions()
67 {
68         GetOptionsMgr()->SaveOption(OPT_USE_RECYCLE_BIN, m_bUseRecycleBin);
69
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);
74
75         String sFilterPath = strutils::trim_ws(m_strUserFilterPath);
76         GetOptionsMgr()->SaveOption(OPT_FILTER_USERPATH, sFilterPath);
77
78         bool useSysTemp = m_tempFolderType == 0;
79         GetOptionsMgr()->SaveOption(OPT_USE_SYSTEM_TEMP_PATH, useSysTemp);
80
81         String tempFolder = strutils::trim_ws(m_tempFolder);
82         GetOptionsMgr()->SaveOption(OPT_CUSTOM_TEMP_PATH, tempFolder);
83 }
84
85 BOOL PropRegistry::OnInitDialog()
86 {
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());
94         return TRUE;
95 }
96
97 /// Open file browse dialog to locate editor
98 void PropRegistry::OnBrowseEditor()
99 {
100         String path;
101         if (SelectFile(GetSafeHwnd(), path, true, m_strEditorPath.c_str(), _T(""), _("Programs|*.exe;*.bat;*.cmd|All Files (*.*)|*.*||")))
102         {
103                 SetDlgItemText(IDC_EXT_EDITOR_PATH, path);
104         }
105 }
106
107 /// Open Folder selection dialog for user to select filter folder.
108 void PropRegistry::OnBrowseFilterPath()
109 {
110         String path;
111         if (SelectFolder(path, m_strUserFilterPath.c_str(), _("Open"), GetSafeHwnd()))
112         {
113                 SetDlgItemText(IDC_FILTER_USER_PATH, path);
114         }
115 }
116
117 /// Select temporary files folder.
118 void PropRegistry::OnBrowseTmpFolder()
119 {
120         String path;
121         if (SelectFolder(path, m_tempFolder.c_str(), _T(""), GetSafeHwnd()))
122         {
123                 SetDlgItemText(IDC_TMPFOLDER_NAME, path);
124         }
125 }
126
127 BOOL PropRegistry::PreTranslateMessage(MSG* pMsg)
128 {
129         if (pMsg->message == WM_LBUTTONDOWN ||
130                 pMsg->message == WM_LBUTTONUP ||
131                 pMsg->message == WM_MOUSEMOVE)
132         {
133                 m_tooltips.RelayEvent(pMsg);
134         }
135
136         return OptionsPanel::PreTranslateMessage(pMsg);
137 }