Add start and pre commit hooks
[TortoiseGit.git] / src / TortoiseMerge / SetMainPage.cpp
blob7ef095db2a11fd2829e6b2085810bd6d114e7fd9
1 // TortoiseGitMerge - a Diff/Patch program
3 // Copyright (C) 2013-2014 - TortoiseGit
4 // Copyright (C) 2006-2010, 2012-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.
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 "SysInfo.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_nTabSize(0)
37 , m_bIgnoreEOL(FALSE)
38 , m_bOnePane(FALSE)
39 , m_bViewLinenumbers(FALSE)
40 , m_bReloadNeeded(FALSE)
41 , m_bCaseInsensitive(FALSE)
42 , m_bUTF8Default(FALSE)
43 , m_bAutoAdd(TRUE)
44 , m_nMaxInline(3000)
45 , m_dwFontSize(0)
47 m_regBackup = CRegDWORD(_T("Software\\TortoiseGitMerge\\Backup"));
48 m_regFirstDiffOnLoad = CRegDWORD(_T("Software\\TortoiseGitMerge\\FirstDiffOnLoad"), TRUE);
49 m_regFirstConflictOnLoad = CRegDWORD(_T("Software\\TortoiseGitMerge\\FirstConflictOnLoad"), TRUE);
50 m_regTabSize = CRegDWORD(_T("Software\\TortoiseGitMerge\\TabSize"), 4);
51 m_regIgnoreEOL = CRegDWORD(_T("Software\\TortoiseGitMerge\\IgnoreEOL"), TRUE);
52 m_regOnePane = CRegDWORD(_T("Software\\TortoiseGitMerge\\OnePane"));
53 m_regViewLinenumbers = CRegDWORD(_T("Software\\TortoiseGitMerge\\ViewLinenumbers"), 1);
54 m_regFontName = CRegString(_T("Software\\TortoiseGitMerge\\LogFontName"), _T("Courier New"));
55 m_regFontSize = CRegDWORD(_T("Software\\TortoiseGitMerge\\LogFontSize"), 10);
56 m_regCaseInsensitive = CRegDWORD(_T("Software\\TortoiseGitMerge\\CaseInsensitive"), FALSE);
57 m_regUTF8Default = CRegDWORD(_T("Software\\TortoiseGitMerge\\UseUTF8"), FALSE);
58 m_regAutoAdd = CRegDWORD(_T("Software\\TortoiseGitMerge\\AutoAdd"), TRUE);
59 m_regMaxInline = CRegDWORD(_T("Software\\TortoiseGitMerge\\InlineDiffMaxLineLength"), 3000);
60 m_regUseRibbons = CRegDWORD(L"Software\\TortoiseGitMerge\\UseRibbons", TRUE);
61 m_regUseTaskDialog = CRegDWORD(L"Software\\TortoiseGitMerge\\UseTaskDialog", TRUE);
63 m_bBackup = m_regBackup;
64 m_bFirstDiffOnLoad = m_regFirstDiffOnLoad;
65 m_bFirstConflictOnLoad = m_regFirstConflictOnLoad;
66 m_nTabSize = m_regTabSize;
67 m_bIgnoreEOL = m_regIgnoreEOL;
68 m_bOnePane = m_regOnePane;
69 m_bViewLinenumbers = m_regViewLinenumbers;
70 m_bCaseInsensitive = m_regCaseInsensitive;
71 m_bUTF8Default = m_regUTF8Default;
72 m_bAutoAdd = m_regAutoAdd;
73 m_nMaxInline = m_regMaxInline;
74 m_bUseRibbons = m_regUseRibbons;
75 m_bUseTaskDialog = CTaskDialog::IsSupported() && (DWORD)m_regUseTaskDialog;
78 CSetMainPage::~CSetMainPage()
82 void CSetMainPage::DoDataExchange(CDataExchange* pDX)
84 CPropertyPage::DoDataExchange(pDX);
85 DDX_Check(pDX, IDC_BACKUP, m_bBackup);
86 DDX_Check(pDX, IDC_FIRSTDIFFONLOAD, m_bFirstDiffOnLoad);
87 DDX_Check(pDX, IDC_FIRSTCONFLICTONLOAD, m_bFirstConflictOnLoad);
88 DDX_Text(pDX, IDC_TABSIZE, m_nTabSize);
89 DDV_MinMaxInt(pDX, m_nTabSize, 1, 1000);
90 DDX_Check(pDX, IDC_IGNORELF, m_bIgnoreEOL);
91 DDX_Check(pDX, IDC_ONEPANE, m_bOnePane);
92 DDX_Control(pDX, IDC_FONTSIZES, m_cFontSizes);
93 m_dwFontSize = (DWORD)m_cFontSizes.GetItemData(m_cFontSizes.GetCurSel());
94 if ((m_dwFontSize==0)||(m_dwFontSize == -1))
96 CString t;
97 m_cFontSizes.GetWindowText(t);
98 m_dwFontSize = _ttoi(t);
100 DDX_Control(pDX, IDC_FONTNAMES, m_cFontNames);
101 DDX_Check(pDX, IDC_LINENUMBERS, m_bViewLinenumbers);
102 DDX_Check(pDX, IDC_CASEINSENSITIVE, m_bCaseInsensitive);
103 DDX_Check(pDX, IDC_UTF8DEFAULT, m_bUTF8Default);
104 DDX_Check(pDX, IDC_AUTOADD, m_bAutoAdd);
105 DDX_Text(pDX, IDC_MAXINLINE, m_nMaxInline);
106 DDX_Check(pDX, IDC_USERIBBONS, m_bUseRibbons);
107 DDX_Check(pDX, IDC_USETASKDIALOG, m_bUseTaskDialog);
110 void CSetMainPage::SaveData()
112 m_regBackup = m_bBackup;
113 m_regFirstDiffOnLoad = m_bFirstDiffOnLoad;
114 m_regFirstConflictOnLoad = m_bFirstConflictOnLoad;
115 m_regTabSize = m_nTabSize;
116 m_regIgnoreEOL = m_bIgnoreEOL;
117 m_regOnePane = m_bOnePane;
118 m_regFontName = m_sFontName;
119 m_regFontSize = m_dwFontSize;
120 m_regViewLinenumbers = m_bViewLinenumbers;
121 m_regCaseInsensitive = m_bCaseInsensitive;
122 m_regUTF8Default = m_bUTF8Default;
123 m_regAutoAdd = m_bAutoAdd;
124 m_regMaxInline = m_nMaxInline;
125 m_regUseRibbons = m_bUseRibbons;
126 m_regUseTaskDialog = m_bUseTaskDialog;
129 BOOL CSetMainPage::OnApply()
131 UpdateData();
132 if (m_cFontNames.GetSelFont())
133 m_sFontName = m_cFontNames.GetSelFont()->m_strName;
134 else
135 m_sFontName = m_regFontName;
136 SaveData();
137 SetModified(FALSE);
138 return CPropertyPage::OnApply();
141 BOOL CSetMainPage::OnInitDialog()
143 CMFCFontComboBox::m_bDrawUsingFont = true;
145 CPropertyPage::OnInitDialog();
147 m_bBackup = m_regBackup;
148 m_bFirstDiffOnLoad = m_regFirstDiffOnLoad;
149 m_bFirstConflictOnLoad = m_regFirstConflictOnLoad;
150 m_nTabSize = m_regTabSize;
151 m_bIgnoreEOL = m_regIgnoreEOL;
152 m_bOnePane = m_regOnePane;
153 m_sFontName = m_regFontName;
154 m_dwFontSize = m_regFontSize;
155 m_bViewLinenumbers = m_regViewLinenumbers;
156 m_bCaseInsensitive = m_regCaseInsensitive;
157 m_bUTF8Default = m_regUTF8Default;
158 m_bAutoAdd = m_regAutoAdd;
159 m_nMaxInline = m_regMaxInline;
160 m_bUseRibbons = m_regUseRibbons;
161 #if _WIN64
162 if (SysInfo::Instance().IsXP())
164 DialogEnableWindow(IDC_USERIBBONS, FALSE);
165 m_bUseRibbons = FALSE;
167 #endif
168 m_bUseTaskDialog = CTaskDialog::IsSupported() && (DWORD)m_regUseTaskDialog;
170 DialogEnableWindow(IDC_FIRSTCONFLICTONLOAD, m_bFirstDiffOnLoad);
171 DialogEnableWindow(IDC_USETASKDIALOG, CTaskDialog::IsSupported());
173 CString temp;
174 int count = 0;
175 for (int i=6; i<32; i=i+2)
177 temp.Format(_T("%d"), i);
178 m_cFontSizes.AddString(temp);
179 m_cFontSizes.SetItemData(count++, i);
181 BOOL foundfont = FALSE;
182 for (int i=0; i<m_cFontSizes.GetCount(); i++)
184 if (m_cFontSizes.GetItemData(i) == m_dwFontSize)
186 m_cFontSizes.SetCurSel(i);
187 foundfont = TRUE;
190 if (!foundfont)
192 temp.Format(_T("%lu"), m_dwFontSize);
193 m_cFontSizes.SetWindowText(temp);
195 m_cFontNames.Setup(DEVICE_FONTTYPE|RASTER_FONTTYPE|TRUETYPE_FONTTYPE, 1, FIXED_PITCH);
196 m_cFontNames.SelectFont(m_sFontName);
198 UpdateData(FALSE);
199 return TRUE; // return TRUE unless you set the focus to a control
200 // EXCEPTION: OCX Property Pages should return FALSE
203 BEGIN_MESSAGE_MAP(CSetMainPage, CPropertyPage)
204 ON_BN_CLICKED(IDC_BACKUP, &CSetMainPage::OnModified)
205 ON_BN_CLICKED(IDC_IGNORELF, &CSetMainPage::OnModifiedWithReload)
206 ON_BN_CLICKED(IDC_ONEPANE, &CSetMainPage::OnModified)
207 ON_BN_CLICKED(IDC_FIRSTDIFFONLOAD, &CSetMainPage::OnModified)
208 ON_BN_CLICKED(IDC_FIRSTCONFLICTONLOAD, &CSetMainPage::OnModified)
209 ON_BN_CLICKED(IDC_LINENUMBERS, &CSetMainPage::OnModified)
210 ON_EN_CHANGE(IDC_TABSIZE, &CSetMainPage::OnModified)
211 ON_CBN_SELCHANGE(IDC_FONTSIZES, &CSetMainPage::OnModified)
212 ON_CBN_SELCHANGE(IDC_FONTNAMES, &CSetMainPage::OnModified)
213 ON_BN_CLICKED(IDC_CASEINSENSITIVE, &CSetMainPage::OnModified)
214 ON_BN_CLICKED(IDC_UTF8DEFAULT, &CSetMainPage::OnModified)
215 ON_BN_CLICKED(IDC_AUTOADD, &CSetMainPage::OnModified)
216 ON_EN_CHANGE(IDC_MAXINLINE, &CSetMainPage::OnModifiedWithReload)
217 ON_BN_CLICKED(IDC_USERIBBONS, &CSetMainPage::OnModified)
218 ON_BN_CLICKED(IDC_USETASKDIALOG, &CSetMainPage::OnModified)
219 END_MESSAGE_MAP()
222 // CSetMainPage message handlers
224 void CSetMainPage::OnModified()
226 UpdateData();
227 SetModified();
228 DialogEnableWindow(IDC_FIRSTCONFLICTONLOAD, m_bFirstDiffOnLoad);
231 void CSetMainPage::OnModifiedWithReload()
233 m_bReloadNeeded = TRUE;
234 SetModified();
237 void CSetMainPage::OnBnClickedWhitespace()
239 m_bReloadNeeded = TRUE;
240 SetModified();
243 BOOL CSetMainPage::DialogEnableWindow(UINT nID, BOOL bEnable)
245 CWnd * pwndDlgItem = GetDlgItem(nID);
246 if (pwndDlgItem == NULL)
247 return FALSE;
248 if (bEnable)
249 return pwndDlgItem->EnableWindow(bEnable);
250 if (GetFocus() == pwndDlgItem)
252 SendMessage(WM_NEXTDLGCTL, 0, FALSE);
254 return pwndDlgItem->EnableWindow(bEnable);