1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2012-2013 - TortoiseGit
4 // Copyright (C) 2009-2011, 2013 - 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
"AutoCompleteMinChars";
34 settings
[i
].type
= CSettingsAdvanced::SettingTypeNumber
;
35 settings
[i
++].def
.l
= 3;
37 settings
[i
].sName
= L
"AutocompleteRemovesExtensions";
38 settings
[i
].type
= CSettingsAdvanced::SettingTypeBoolean
;
39 settings
[i
++].def
.b
= false;
41 settings
[i
].sName
= L
"BlockStatus";
42 settings
[i
].type
= CSettingsAdvanced::SettingTypeBoolean
;
43 settings
[i
++].def
.b
= false;
45 settings
[i
].sName
= L
"CacheTrayIcon";
46 settings
[i
].type
= CSettingsAdvanced::SettingTypeBoolean
;
47 settings
[i
++].def
.b
= false;
49 settings
[i
].sName
= L
"ColumnsEveryWhere";
50 settings
[i
].type
= CSettingsAdvanced::SettingTypeBoolean
;
51 settings
[i
++].def
.b
= false;
53 settings
[i
].sName
= L
"Debug";
54 settings
[i
].type
= CSettingsAdvanced::SettingTypeBoolean
;
55 settings
[i
++].def
.b
= false;
57 settings
[i
].sName
= L
"DiffBlamesWithTortoiseMerge";
58 settings
[i
].type
= CSettingsAdvanced::SettingTypeBoolean
;
59 settings
[i
++].def
.b
= false;
61 settings
[i
].sName
= L
"FullRowSelect";
62 settings
[i
].type
= CSettingsAdvanced::SettingTypeBoolean
;
63 settings
[i
++].def
.b
= true;
65 settings
[i
].sName
= L
"LogIncludeBoundaryCommits";
66 settings
[i
].type
= CSettingsAdvanced::SettingTypeBoolean
;
67 settings
[i
++].def
.b
= false;
69 settings
[i
].sName
= L
"NoSortLocalBranchesFirst";
70 settings
[i
].type
= CSettingsAdvanced::SettingTypeBoolean
;
71 settings
[i
++].def
.b
= false;
73 settings
[i
].sName
= L
"NumDiffWarning";
74 settings
[i
].type
= CSettingsAdvanced::SettingTypeNumber
;
75 settings
[i
++].def
.l
= 10;
77 settings
[i
].sName
= L
"ReaddUnselectedAddedFilesAfterCommit";
78 settings
[i
].type
= CSettingsAdvanced::SettingTypeBoolean
;
79 settings
[i
++].def
.b
= true;
81 settings
[i
].sName
= L
"ScintillaDirect2D";
82 settings
[i
].type
= CSettingsAdvanced::SettingTypeBoolean
;
83 settings
[i
++].def
.b
= false;
85 settings
[i
].sName
= L
"ShowContextMenuIcons";
86 settings
[i
].type
= CSettingsAdvanced::SettingTypeBoolean
;
87 settings
[i
++].def
.b
= true;
89 settings
[i
].sName
= L
"ShowListBackgroundImage";
90 settings
[i
].type
= CSettingsAdvanced::SettingTypeBoolean
;
91 settings
[i
++].def
.b
= true;
93 settings
[i
].sName
= L
"StyleCommitMessages";
94 settings
[i
].type
= CSettingsAdvanced::SettingTypeBoolean
;
95 settings
[i
++].def
.b
= true;
97 settings
[i
].sName
= L
"TGitCacheCheckContent";
98 settings
[i
].type
= CSettingsAdvanced::SettingTypeBoolean
;
99 settings
[i
++].def
.b
= true;
101 settings
[i
].sName
= L
"UseLibgit2";
102 settings
[i
].type
= CSettingsAdvanced::SettingTypeBoolean
;
103 settings
[i
++].def
.b
= true;
105 settings
[i
].sName
= L
"VersionCheck";
106 settings
[i
].type
= CSettingsAdvanced::SettingTypeBoolean
;
107 settings
[i
++].def
.b
= true;
109 settings
[i
].sName
= L
"VersionCheckPreview";
110 settings
[i
].type
= CSettingsAdvanced::SettingTypeBoolean
;
111 settings
[i
++].def
.b
= false;
113 settings
[i
].sName
= L
"";
114 settings
[i
].type
= CSettingsAdvanced::SettingTypeNone
;
115 settings
[i
++].def
.b
= false;
118 CSettingsAdvanced::~CSettingsAdvanced()
122 void CSettingsAdvanced::DoDataExchange(CDataExchange
* pDX
)
124 ISettingsPropPage::DoDataExchange(pDX
);
125 DDX_Control(pDX
, IDC_CONFIG
, m_ListCtrl
);
129 BEGIN_MESSAGE_MAP(CSettingsAdvanced
, ISettingsPropPage
)
130 ON_NOTIFY(LVN_BEGINLABELEDIT
, IDC_CONFIG
, &CSettingsAdvanced::OnLvnBeginlabeledit
)
131 ON_NOTIFY(LVN_ENDLABELEDIT
, IDC_CONFIG
, &CSettingsAdvanced::OnLvnEndlabeledit
)
132 ON_NOTIFY(NM_DBLCLK
, IDC_CONFIG
, &CSettingsAdvanced::OnNMDblclkConfig
)
136 BOOL
CSettingsAdvanced::OnInitDialog()
138 ISettingsPropPage::OnInitDialog();
140 m_ListCtrl
.DeleteAllItems();
141 int c
= ((CHeaderCtrl
*)(m_ListCtrl
.GetDlgItem(0)))->GetItemCount() - 1;
143 m_ListCtrl
.DeleteColumn(c
--);
145 SetWindowTheme(m_ListCtrl
.GetSafeHwnd(), L
"Explorer", NULL
);
148 temp
.LoadString(IDS_SETTINGS_CONF_VALUECOL
);
149 m_ListCtrl
.InsertColumn(0, temp
);
150 temp
.LoadString(IDS_SETTINGS_CONF_NAMECOL
);
151 m_ListCtrl
.InsertColumn(1, temp
);
153 m_ListCtrl
.SetRedraw(FALSE
);
156 while (settings
[i
].type
!= SettingTypeNone
)
158 m_ListCtrl
.InsertItem(i
, settings
[i
].sName
);
159 m_ListCtrl
.SetItemText(i
, 1, settings
[i
].sName
);
160 switch (settings
[i
].type
)
162 case SettingTypeBoolean
:
164 CRegDWORD
s(_T("Software\\TortoiseGit\\") + settings
[i
].sName
, settings
[i
].def
.b
);
165 m_ListCtrl
.SetItemText(i
, 0, DWORD(s
) ? _T("true") : _T("false"));
168 case SettingTypeNumber
:
170 CRegDWORD
s(_T("Software\\TortoiseGit\\") + settings
[i
].sName
, settings
[i
].def
.l
);
171 temp
.Format(_T("%ld"), (DWORD
)s
);
172 m_ListCtrl
.SetItemText(i
, 0, temp
);
175 case SettingTypeString
:
177 CRegString
s(_T("Software\\TortoiseGit\\") + settings
[i
].sName
, settings
[i
].def
.s
);
178 m_ListCtrl
.SetItemText(i
, 0, CString(s
));
186 int maxcol
= ((CHeaderCtrl
*)(m_ListCtrl
.GetDlgItem(0)))->GetItemCount() - 1;
188 for (col
= mincol
; col
<= maxcol
; ++col
)
190 m_ListCtrl
.SetColumnWidth(col
, LVSCW_AUTOSIZE_USEHEADER
);
193 m_ListCtrl
.SetColumnOrderArray(2, arr
);
194 m_ListCtrl
.SetRedraw(TRUE
);
199 BOOL
CSettingsAdvanced::OnApply()
202 while (settings
[i
].type
!= SettingTypeNone
)
204 CString sValue
= m_ListCtrl
.GetItemText(i
, 0);
205 switch (settings
[i
].type
)
207 case SettingTypeBoolean
:
209 CRegDWORD
s(_T("Software\\TortoiseGit\\") + settings
[i
].sName
, settings
[i
].def
.b
);
210 if (sValue
.IsEmpty())
214 DWORD newValue
= sValue
.Compare(_T("true")) == 0;
215 if (DWORD(s
) != newValue
)
222 case SettingTypeNumber
:
224 CRegDWORD
s(_T("Software\\TortoiseGit\\") + settings
[i
].sName
, settings
[i
].def
.l
);
225 if (DWORD(_tstol(sValue
)) != DWORD(s
))
231 case SettingTypeString
:
233 CRegString
s(_T("Software\\TortoiseGit\\") + settings
[i
].sName
, settings
[i
].def
.s
);
234 if (sValue
.Compare(CString(s
)))
244 return ISettingsPropPage::OnApply();
247 void CSettingsAdvanced::OnLvnBeginlabeledit(NMHDR
* /*pNMHDR*/, LRESULT
*pResult
)
252 void CSettingsAdvanced::OnLvnEndlabeledit(NMHDR
*pNMHDR
, LRESULT
*pResult
)
254 NMLVDISPINFO
*pDispInfo
= reinterpret_cast<NMLVDISPINFO
*>(pNMHDR
);
256 if (pDispInfo
->item
.pszText
== NULL
)
259 bool allowEdit
= false;
260 switch (settings
[pDispInfo
->item
.iItem
].type
)
262 case SettingTypeBoolean
:
264 if ((pDispInfo
->item
.pszText
[0] == 0) ||
265 (_tcscmp(pDispInfo
->item
.pszText
, _T("true")) == 0) ||
266 (_tcscmp(pDispInfo
->item
.pszText
, _T("false")) == 0))
272 case SettingTypeNumber
:
274 TCHAR
* pChar
= pDispInfo
->item
.pszText
;
278 if (!_istdigit(*pChar
))
287 case SettingTypeString
:
295 *pResult
= allowEdit
? TRUE
: FALSE
;
298 BOOL
CSettingsAdvanced::PreTranslateMessage(MSG
* pMsg
)
300 if (pMsg
->message
== WM_KEYDOWN
)
302 switch (pMsg
->wParam
)
306 m_ListCtrl
.EditLabel(m_ListCtrl
.GetSelectionMark());
311 return ISettingsPropPage::PreTranslateMessage(pMsg
);
314 void CSettingsAdvanced::OnNMDblclkConfig(NMHDR
*pNMHDR
, LRESULT
*pResult
)
316 LPNMITEMACTIVATE pNMItemActivate
= reinterpret_cast<LPNMITEMACTIVATE
>(pNMHDR
);
317 m_ListCtrl
.EditLabel(pNMItemActivate
->iItem
);