Doc: Fix broken link
[TortoiseGit.git] / src / TortoiseMerge / SetMainPage.cpp
blob407b34c822b48579be38d3fd04b85a9e44e3339c
1 // TortoiseGitMerge - a Diff/Patch program
3 // Copyright (C) 2013-2014 - TortoiseGit
4 // Copyright (C) 2006-2010, 2012-2014, 2016 - 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.
20 #include "stdafx.h"
21 #include "TortoiseMerge.h"
22 #include "DirFileEnum.h"
23 #include "AppUtils.h"
24 #include "PathUtils.h"
25 #include "SetMainPage.h"
26 #include "MainFrm.h"
28 // CSetMainPage dialog
30 IMPLEMENT_DYNAMIC(CSetMainPage, CPropertyPage)
31 CSetMainPage::CSetMainPage()
32 : CPropertyPage(CSetMainPage::IDD)
33 , m_bBackup(FALSE)
34 , m_bFirstDiffOnLoad(FALSE)
35 , m_bFirstConflictOnLoad(FALSE)
36 , m_bUseSpaces(FALSE)
37 , m_bSmartTabChar(FALSE)
38 , m_nTabSize(0)
39 , m_bEnableEditorConfig(FALSE)
40 , m_nContextLines(-1)
41 , m_bIgnoreEOL(FALSE)
42 , m_bOnePane(FALSE)
43 , m_bViewLinenumbers(FALSE)
44 , m_bReloadNeeded(FALSE)
45 , m_bCaseInsensitive(FALSE)
46 , m_bUTF8Default(FALSE)
47 , m_bAutoAdd(TRUE)
48 , m_nMaxInline(3000)
49 , m_dwFontSize(0)
51 m_regBackup = CRegDWORD(L"Software\\TortoiseGitMerge\\Backup");
52 m_regFirstDiffOnLoad = CRegDWORD(L"Software\\TortoiseGitMerge\\FirstDiffOnLoad", TRUE);
53 m_regFirstConflictOnLoad = CRegDWORD(L"Software\\TortoiseGitMerge\\FirstConflictOnLoad", TRUE);
54 m_regTabMode = CRegDWORD(L"Software\\TortoiseGitMerge\\TabMode", 0);
55 m_regTabSize = CRegDWORD(L"Software\\TortoiseGitMerge\\TabSize", 4);
56 m_regEnableEditorConfig = CRegDWORD(L"Software\\TortoiseGitMerge\\EnableEditorConfig", FALSE);
57 m_regIgnoreEOL = CRegDWORD(L"Software\\TortoiseGitMerge\\IgnoreEOL", TRUE);
58 m_regOnePane = CRegDWORD(L"Software\\TortoiseGitMerge\\OnePane");
59 m_regViewLinenumbers = CRegDWORD(L"Software\\TortoiseGitMerge\\ViewLinenumbers", 1);
60 m_regFontName = CRegString(L"Software\\TortoiseGitMerge\\LogFontName", L"Consolas");
61 m_regFontSize = CRegDWORD(L"Software\\TortoiseGitMerge\\LogFontSize", 10);
62 m_regCaseInsensitive = CRegDWORD(L"Software\\TortoiseGitMerge\\CaseInsensitive", FALSE);
63 m_regUTF8Default = CRegDWORD(L"Software\\TortoiseGitMerge\\UseUTF8", FALSE);
64 m_regAutoAdd = CRegDWORD(L"Software\\TortoiseGitMerge\\AutoAdd", TRUE);
65 m_regMaxInline = CRegDWORD(L"Software\\TortoiseGitMerge\\InlineDiffMaxLineLength", 3000);
66 m_regUseRibbons = CRegDWORD(L"Software\\TortoiseGitMerge\\UseRibbons", TRUE);
67 m_regContextLines = CRegDWORD(L"Software\\TortoiseGitMerge\\ContextLines", (DWORD)-1);
69 m_bBackup = m_regBackup;
70 m_bFirstDiffOnLoad = m_regFirstDiffOnLoad;
71 m_bFirstConflictOnLoad = m_regFirstConflictOnLoad;
72 m_bUseSpaces = (m_regTabMode & TABMODE_USESPACES) ? TRUE : FALSE;
73 m_bSmartTabChar = (m_regTabMode & TABMODE_SMARTINDENT) ? TRUE : FALSE;
74 m_nTabSize = m_regTabSize;
75 m_bEnableEditorConfig = m_regEnableEditorConfig;
76 m_nContextLines = m_regContextLines;
77 m_bIgnoreEOL = m_regIgnoreEOL;
78 m_bOnePane = m_regOnePane;
79 m_bViewLinenumbers = m_regViewLinenumbers;
80 m_bCaseInsensitive = m_regCaseInsensitive;
81 m_bUTF8Default = m_regUTF8Default;
82 m_bAutoAdd = m_regAutoAdd;
83 m_nMaxInline = m_regMaxInline;
84 m_bUseRibbons = m_regUseRibbons;
87 CSetMainPage::~CSetMainPage()
91 void CSetMainPage::DoDataExchange(CDataExchange* pDX)
93 CPropertyPage::DoDataExchange(pDX);
94 DDX_Check(pDX, IDC_BACKUP, m_bBackup);
95 DDX_Check(pDX, IDC_FIRSTDIFFONLOAD, m_bFirstDiffOnLoad);
96 DDX_Check(pDX, IDC_FIRSTCONFLICTONLOAD, m_bFirstConflictOnLoad);
97 DDX_Check(pDX, IDC_USESPACES, m_bUseSpaces);
98 DDX_Check(pDX, IDC_SMARTTABCHAR, m_bSmartTabChar);
99 DDX_Text(pDX, IDC_TABSIZE, m_nTabSize);
100 DDV_MinMaxInt(pDX, m_nTabSize, 1, 1000);
101 DDX_Check(pDX, IDC_ENABLEEDITORCONFIG, m_bEnableEditorConfig);
102 DDX_Text(pDX, IDC_CONTEXTLINES, m_nContextLines);
103 DDV_MinMaxInt(pDX, m_nContextLines, -1, 1000);
104 DDX_Check(pDX, IDC_IGNORELF, m_bIgnoreEOL);
105 DDX_Check(pDX, IDC_ONEPANE, m_bOnePane);
106 DDX_Control(pDX, IDC_FONTSIZES, m_cFontSizes);
107 m_dwFontSize = (DWORD)m_cFontSizes.GetItemData(m_cFontSizes.GetCurSel());
108 if ((m_dwFontSize==0)||(m_dwFontSize == -1))
110 CString t;
111 m_cFontSizes.GetWindowText(t);
112 m_dwFontSize = _wtoi(t);
114 DDX_Control(pDX, IDC_FONTNAMES, m_cFontNames);
115 DDX_Check(pDX, IDC_LINENUMBERS, m_bViewLinenumbers);
116 DDX_Check(pDX, IDC_CASEINSENSITIVE, m_bCaseInsensitive);
117 DDX_Check(pDX, IDC_UTF8DEFAULT, m_bUTF8Default);
118 DDX_Check(pDX, IDC_AUTOADD, m_bAutoAdd);
119 DDX_Text(pDX, IDC_MAXINLINE, m_nMaxInline);
120 DDX_Check(pDX, IDC_USERIBBONS, m_bUseRibbons);
123 void CSetMainPage::SaveData()
125 m_regBackup = m_bBackup;
126 m_regFirstDiffOnLoad = m_bFirstDiffOnLoad;
127 m_regFirstConflictOnLoad = m_bFirstConflictOnLoad;
128 m_regTabMode = (m_bUseSpaces ? TABMODE_USESPACES : TABMODE_NONE) | (m_bSmartTabChar ? TABMODE_SMARTINDENT : TABMODE_NONE);
129 m_regTabSize = m_nTabSize;
130 m_regEnableEditorConfig = m_bEnableEditorConfig;
131 m_regContextLines = m_nContextLines;
132 m_regIgnoreEOL = m_bIgnoreEOL;
133 m_regOnePane = m_bOnePane;
134 m_regFontName = m_sFontName;
135 m_regFontSize = m_dwFontSize;
136 m_regViewLinenumbers = m_bViewLinenumbers;
137 m_regCaseInsensitive = m_bCaseInsensitive;
138 m_regUTF8Default = m_bUTF8Default;
139 m_regAutoAdd = m_bAutoAdd;
140 m_regMaxInline = m_nMaxInline;
141 m_regUseRibbons = m_bUseRibbons;
144 BOOL CSetMainPage::OnApply()
146 UpdateData();
147 if (m_cFontNames.GetSelFont())
148 m_sFontName = m_cFontNames.GetSelFont()->m_strName;
149 else
150 m_sFontName = m_regFontName;
151 SaveData();
152 SetModified(FALSE);
153 return CPropertyPage::OnApply();
156 BOOL CSetMainPage::OnInitDialog()
158 CMFCFontComboBox::m_bDrawUsingFont = true;
160 CPropertyPage::OnInitDialog();
162 m_bBackup = m_regBackup;
163 m_bFirstDiffOnLoad = m_regFirstDiffOnLoad;
164 m_bFirstConflictOnLoad = m_regFirstConflictOnLoad;
165 m_bUseSpaces = (m_regTabMode & TABMODE_USESPACES) ? TRUE : FALSE;
166 m_bSmartTabChar = (m_regTabMode & TABMODE_SMARTINDENT) ? TRUE : FALSE;
167 m_nTabSize = m_regTabSize;
168 m_bEnableEditorConfig = m_regEnableEditorConfig;
169 m_nContextLines = m_regContextLines;
170 m_bIgnoreEOL = m_regIgnoreEOL;
171 m_bOnePane = m_regOnePane;
172 m_sFontName = m_regFontName;
173 m_dwFontSize = m_regFontSize;
174 m_bViewLinenumbers = m_regViewLinenumbers;
175 m_bCaseInsensitive = m_regCaseInsensitive;
176 m_bUTF8Default = m_regUTF8Default;
177 m_bAutoAdd = m_regAutoAdd;
178 m_nMaxInline = m_regMaxInline;
179 m_bUseRibbons = m_regUseRibbons;
181 DialogEnableWindow(IDC_FIRSTCONFLICTONLOAD, m_bFirstDiffOnLoad);
183 CString temp;
184 int count = 0;
185 for (int i=6; i<32; i=i+2)
187 temp.Format(L"%d", i);
188 m_cFontSizes.AddString(temp);
189 m_cFontSizes.SetItemData(count++, i);
191 BOOL foundfont = FALSE;
192 for (int i=0; i<m_cFontSizes.GetCount(); i++)
194 if (m_cFontSizes.GetItemData(i) == m_dwFontSize)
196 m_cFontSizes.SetCurSel(i);
197 foundfont = TRUE;
200 if (!foundfont)
202 temp.Format(L"%lu", m_dwFontSize);
203 m_cFontSizes.SetWindowText(temp);
205 m_cFontNames.Setup(DEVICE_FONTTYPE|RASTER_FONTTYPE|TRUETYPE_FONTTYPE, 1, FIXED_PITCH);
206 m_cFontNames.SelectFont(m_sFontName);
208 UpdateData(FALSE);
209 return TRUE; // return TRUE unless you set the focus to a control
210 // EXCEPTION: OCX Property Pages should return FALSE
213 BEGIN_MESSAGE_MAP(CSetMainPage, CPropertyPage)
214 ON_BN_CLICKED(IDC_BACKUP, &CSetMainPage::OnModified)
215 ON_BN_CLICKED(IDC_IGNORELF, &CSetMainPage::OnModifiedWithReload)
216 ON_BN_CLICKED(IDC_ONEPANE, &CSetMainPage::OnModified)
217 ON_BN_CLICKED(IDC_FIRSTDIFFONLOAD, &CSetMainPage::OnModified)
218 ON_BN_CLICKED(IDC_FIRSTCONFLICTONLOAD, &CSetMainPage::OnModified)
219 ON_BN_CLICKED(IDC_LINENUMBERS, &CSetMainPage::OnModified)
220 ON_BN_CLICKED(IDC_USESPACES, &CSetMainPage::OnModified)
221 ON_BN_CLICKED(IDC_SMARTTABCHAR, &CSetMainPage::OnModified)
222 ON_EN_CHANGE(IDC_TABSIZE, &CSetMainPage::OnModified)
223 ON_BN_CLICKED(IDC_ENABLEEDITORCONFIG, &CSetMainPage::OnModified)
224 ON_EN_CHANGE(IDC_CONTEXTLINES, &CSetMainPage::OnModified)
225 ON_CBN_SELCHANGE(IDC_FONTSIZES, &CSetMainPage::OnModifiedWithReload)
226 ON_CBN_SELCHANGE(IDC_FONTNAMES, &CSetMainPage::OnModifiedWithReload)
227 ON_BN_CLICKED(IDC_CASEINSENSITIVE, &CSetMainPage::OnModified)
228 ON_BN_CLICKED(IDC_UTF8DEFAULT, &CSetMainPage::OnModified)
229 ON_BN_CLICKED(IDC_AUTOADD, &CSetMainPage::OnModified)
230 ON_EN_CHANGE(IDC_MAXINLINE, &CSetMainPage::OnModifiedWithReload)
231 ON_BN_CLICKED(IDC_USERIBBONS, &CSetMainPage::OnModified)
232 ON_WM_MEASUREITEM()
233 END_MESSAGE_MAP()
236 // CSetMainPage message handlers
238 void CSetMainPage::OnModified()
240 UpdateData();
241 SetModified();
242 DialogEnableWindow(IDC_FIRSTCONFLICTONLOAD, m_bFirstDiffOnLoad);
245 void CSetMainPage::OnModifiedWithReload()
247 m_bReloadNeeded = TRUE;
248 SetModified();
251 void CSetMainPage::OnBnClickedWhitespace()
253 m_bReloadNeeded = TRUE;
254 SetModified();
257 BOOL CSetMainPage::DialogEnableWindow(UINT nID, BOOL bEnable)
259 CWnd * pwndDlgItem = GetDlgItem(nID);
260 if (!pwndDlgItem)
261 return FALSE;
262 if (bEnable)
263 return pwndDlgItem->EnableWindow(bEnable);
264 if (GetFocus() == pwndDlgItem)
266 SendMessage(WM_NEXTDLGCTL, 0, FALSE);
268 return pwndDlgItem->EnableWindow(bEnable);
271 void CSetMainPage::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct)
273 CFont* pFont = GetFont();
274 if (pFont)
276 CDC* pDC = GetDC();
277 CFont* pFontPrev = pDC->SelectObject(pFont);
278 int iborder = ::GetSystemMetrics(SM_CYBORDER);
279 CSize sz = pDC->GetTextExtent(L"0");
280 lpMeasureItemStruct->itemHeight = sz.cy + 2 * iborder;
281 pDC->SelectObject(pFontPrev);
282 ReleaseDC(pDC);
284 CPropertyPage::OnMeasureItem(nIDCtl, lpMeasureItemStruct);