1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2012 - TortoiseGit
4 // Copyright (C) 2009-2011 - TortoiseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "TortoiseProc.h"
23 #include "SettingsAdvanced.h"
27 IMPLEMENT_DYNAMIC(CSettingsAdvanced
, ISettingsPropPage
)
29 CSettingsAdvanced::CSettingsAdvanced()
30 : ISettingsPropPage(CSettingsAdvanced::IDD
)
33 settings
[i
].sName
= L
"AutocompleteRemovesExtensions";
34 settings
[i
].type
= CSettingsAdvanced::SettingTypeBoolean
;
35 settings
[i
++].def
.b
= false;
37 settings
[i
].sName
= L
"BlockStatus";
38 settings
[i
].type
= CSettingsAdvanced::SettingTypeBoolean
;
39 settings
[i
++].def
.b
= false;
41 settings
[i
].sName
= L
"CacheTrayIcon";
42 settings
[i
].type
= CSettingsAdvanced::SettingTypeBoolean
;
43 settings
[i
++].def
.b
= false;
45 settings
[i
].sName
= L
"ColumnsEveryWhere";
46 settings
[i
].type
= CSettingsAdvanced::SettingTypeBoolean
;
47 settings
[i
++].def
.b
= false;
49 settings
[i
].sName
= L
"Debug";
50 settings
[i
].type
= CSettingsAdvanced::SettingTypeBoolean
;
51 settings
[i
++].def
.b
= false;
53 settings
[i
].sName
= L
"DiffBlamesWithTortoiseMerge";
54 settings
[i
].type
= CSettingsAdvanced::SettingTypeBoolean
;
55 settings
[i
++].def
.b
= false;
57 settings
[i
].sName
= L
"FullRowSelect";
58 settings
[i
].type
= CSettingsAdvanced::SettingTypeBoolean
;
59 settings
[i
++].def
.b
= true;
61 settings
[i
].sName
= L
"ReaddUnselectedAddedFilesAfterCommit";
62 settings
[i
].type
= CSettingsAdvanced::SettingTypeBoolean
;
63 settings
[i
++].def
.b
= true;
65 settings
[i
].sName
= L
"ScintillaDirect2D";
66 settings
[i
].type
= CSettingsAdvanced::SettingTypeBoolean
;
67 settings
[i
++].def
.b
= false;
69 settings
[i
].sName
= L
"ShowContextMenuIcons";
70 settings
[i
].type
= CSettingsAdvanced::SettingTypeBoolean
;
71 settings
[i
++].def
.b
= true;
73 settings
[i
].sName
= L
"ShowListBackgroundImage";
74 settings
[i
].type
= CSettingsAdvanced::SettingTypeBoolean
;
75 settings
[i
++].def
.b
= true;
77 settings
[i
].sName
= L
"TGitCacheCheckContent";
78 settings
[i
].type
= CSettingsAdvanced::SettingTypeBoolean
;
79 settings
[i
++].def
.b
= false;
81 settings
[i
].sName
= L
"UseLibgit2";
82 settings
[i
].type
= CSettingsAdvanced::SettingTypeBoolean
;
83 settings
[i
++].def
.b
= true;
85 settings
[i
].sName
= L
"VersionCheck";
86 settings
[i
].type
= CSettingsAdvanced::SettingTypeBoolean
;
87 settings
[i
++].def
.b
= true;
89 settings
[i
].sName
= L
"VersionCheckPreview";
90 settings
[i
].type
= CSettingsAdvanced::SettingTypeBoolean
;
91 settings
[i
++].def
.b
= false;
93 settings
[i
].sName
= L
"";
94 settings
[i
].type
= CSettingsAdvanced::SettingTypeNone
;
95 settings
[i
++].def
.b
= false;
98 CSettingsAdvanced::~CSettingsAdvanced()
102 void CSettingsAdvanced::DoDataExchange(CDataExchange
* pDX
)
104 ISettingsPropPage::DoDataExchange(pDX
);
105 DDX_Control(pDX
, IDC_CONFIG
, m_ListCtrl
);
109 BEGIN_MESSAGE_MAP(CSettingsAdvanced
, ISettingsPropPage
)
110 ON_NOTIFY(LVN_BEGINLABELEDIT
, IDC_CONFIG
, &CSettingsAdvanced::OnLvnBeginlabeledit
)
111 ON_NOTIFY(LVN_ENDLABELEDIT
, IDC_CONFIG
, &CSettingsAdvanced::OnLvnEndlabeledit
)
112 ON_NOTIFY(NM_DBLCLK
, IDC_CONFIG
, &CSettingsAdvanced::OnNMDblclkConfig
)
116 BOOL
CSettingsAdvanced::OnInitDialog()
118 ISettingsPropPage::OnInitDialog();
120 m_ListCtrl
.DeleteAllItems();
121 int c
= ((CHeaderCtrl
*)(m_ListCtrl
.GetDlgItem(0)))->GetItemCount() - 1;
123 m_ListCtrl
.DeleteColumn(c
--);
125 SetWindowTheme(m_ListCtrl
.GetSafeHwnd(), L
"Explorer", NULL
);
128 temp
.LoadString(IDS_SETTINGS_CONF_VALUECOL
);
129 m_ListCtrl
.InsertColumn(0, temp
);
130 temp
.LoadString(IDS_SETTINGS_CONF_NAMECOL
);
131 m_ListCtrl
.InsertColumn(1, temp
);
133 m_ListCtrl
.SetRedraw(FALSE
);
136 while (settings
[i
].type
!= SettingTypeNone
)
138 m_ListCtrl
.InsertItem(i
, settings
[i
].sName
);
139 m_ListCtrl
.SetItemText(i
, 1, settings
[i
].sName
);
140 switch (settings
[i
].type
)
142 case SettingTypeBoolean
:
144 CRegDWORD
s(_T("Software\\TortoiseGit\\") + settings
[i
].sName
, settings
[i
].def
.b
);
145 m_ListCtrl
.SetItemText(i
, 0, DWORD(s
) ? _T("true") : _T("false"));
148 case SettingTypeNumber
:
150 CRegDWORD
s(_T("Software\\TortoiseGit\\") + settings
[i
].sName
, settings
[i
].def
.l
);
151 temp
.Format(_T("%ld"), (DWORD
)s
);
152 m_ListCtrl
.SetItemText(i
, 0, temp
);
155 case SettingTypeString
:
157 CRegString
s(_T("Software\\TortoiseGit\\") + settings
[i
].sName
, settings
[i
].def
.s
);
158 m_ListCtrl
.SetItemText(i
, 0, CString(s
));
166 int maxcol
= ((CHeaderCtrl
*)(m_ListCtrl
.GetDlgItem(0)))->GetItemCount() - 1;
168 for (col
= mincol
; col
<= maxcol
; col
++)
170 m_ListCtrl
.SetColumnWidth(col
, LVSCW_AUTOSIZE_USEHEADER
);
173 m_ListCtrl
.SetColumnOrderArray(2, arr
);
174 m_ListCtrl
.SetRedraw(TRUE
);
179 BOOL
CSettingsAdvanced::OnApply()
182 while (settings
[i
].type
!= SettingTypeNone
)
184 CString sValue
= m_ListCtrl
.GetItemText(i
, 0);
185 switch (settings
[i
].type
)
187 case SettingTypeBoolean
:
189 CRegDWORD
s(_T("Software\\TortoiseGit\\") + settings
[i
].sName
, settings
[i
].def
.b
);
190 if (sValue
.IsEmpty())
194 DWORD newValue
= sValue
.Compare(_T("true")) == 0;
195 if (DWORD(s
) != newValue
)
202 case SettingTypeNumber
:
204 CRegDWORD
s(_T("Software\\TortoiseGit\\") + settings
[i
].sName
, settings
[i
].def
.l
);
205 if (DWORD(_tstol(sValue
)) != DWORD(s
))
211 case SettingTypeString
:
213 CRegString
s(_T("Software\\TortoiseGit\\") + settings
[i
].sName
, settings
[i
].def
.s
);
214 if (sValue
.Compare(CString(s
)))
224 return ISettingsPropPage::OnApply();
227 void CSettingsAdvanced::OnLvnBeginlabeledit(NMHDR
* /*pNMHDR*/, LRESULT
*pResult
)
232 void CSettingsAdvanced::OnLvnEndlabeledit(NMHDR
*pNMHDR
, LRESULT
*pResult
)
234 NMLVDISPINFO
*pDispInfo
= reinterpret_cast<NMLVDISPINFO
*>(pNMHDR
);
236 if (pDispInfo
->item
.pszText
== NULL
)
239 bool allowEdit
= false;
240 switch (settings
[pDispInfo
->item
.iItem
].type
)
242 case SettingTypeBoolean
:
244 if ((pDispInfo
->item
.pszText
[0] == 0) ||
245 (_tcscmp(pDispInfo
->item
.pszText
, _T("true")) == 0) ||
246 (_tcscmp(pDispInfo
->item
.pszText
, _T("false")) == 0))
252 case SettingTypeNumber
:
254 TCHAR
* pChar
= pDispInfo
->item
.pszText
;
258 if (!_istdigit(*pChar
))
267 case SettingTypeString
:
275 *pResult
= allowEdit
? TRUE
: FALSE
;
278 BOOL
CSettingsAdvanced::PreTranslateMessage(MSG
* pMsg
)
280 if (pMsg
->message
== WM_KEYDOWN
)
282 switch (pMsg
->wParam
)
286 m_ListCtrl
.EditLabel(m_ListCtrl
.GetSelectionMark());
291 return ISettingsPropPage::PreTranslateMessage(pMsg
);
294 void CSettingsAdvanced::OnNMDblclkConfig(NMHDR
*pNMHDR
, LRESULT
*pResult
)
296 LPNMITEMACTIVATE pNMItemActivate
= reinterpret_cast<LPNMITEMACTIVATE
>(pNMHDR
);
297 m_ListCtrl
.EditLabel(pNMItemActivate
->iItem
);