Include version.h and CrashReport.h only where needed
[TortoiseGit.git] / src / TortoiseMerge / SetMainPage.cpp
blob235bd117d64c51331876b31a9f98f9505d7f96e1
1 // TortoiseGitMerge - a Diff/Patch program
3 // Copyright (C) 2006-2010, 2012 - TortoiseSVN
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include "stdafx.h"
20 #include "TortoiseMerge.h"
21 #include "DirFileEnum.h"
22 #include "AppUtils.h"
23 #include "PathUtils.h"
24 #include "SetMainPage.h"
25 #include "setmainpage.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);
61 m_bBackup = m_regBackup;
62 m_bFirstDiffOnLoad = m_regFirstDiffOnLoad;
63 m_bFirstConflictOnLoad = m_regFirstConflictOnLoad;
64 m_nTabSize = m_regTabSize;
65 m_bIgnoreEOL = m_regIgnoreEOL;
66 m_bOnePane = m_regOnePane;
67 m_bViewLinenumbers = m_regViewLinenumbers;
68 m_bCaseInsensitive = m_regCaseInsensitive;
69 m_bUTF8Default = m_regUTF8Default;
70 m_bAutoAdd = m_regAutoAdd;
71 m_nMaxInline = m_regMaxInline;
74 CSetMainPage::~CSetMainPage()
78 void CSetMainPage::DoDataExchange(CDataExchange* pDX)
80 CPropertyPage::DoDataExchange(pDX);
81 DDX_Check(pDX, IDC_BACKUP, m_bBackup);
82 DDX_Check(pDX, IDC_FIRSTDIFFONLOAD, m_bFirstDiffOnLoad);
83 DDX_Check(pDX, IDC_FIRSTCONFLICTONLOAD, m_bFirstConflictOnLoad);
84 DDX_Text(pDX, IDC_TABSIZE, m_nTabSize);
85 DDV_MinMaxInt(pDX, m_nTabSize, 1, 1000);
86 DDX_Check(pDX, IDC_IGNORELF, m_bIgnoreEOL);
87 DDX_Check(pDX, IDC_ONEPANE, m_bOnePane);
88 DDX_Control(pDX, IDC_FONTSIZES, m_cFontSizes);
89 m_dwFontSize = (DWORD)m_cFontSizes.GetItemData(m_cFontSizes.GetCurSel());
90 if ((m_dwFontSize==0)||(m_dwFontSize == -1))
92 CString t;
93 m_cFontSizes.GetWindowText(t);
94 m_dwFontSize = _ttoi(t);
96 DDX_Control(pDX, IDC_FONTNAMES, m_cFontNames);
97 DDX_Check(pDX, IDC_LINENUMBERS, m_bViewLinenumbers);
98 DDX_Check(pDX, IDC_CASEINSENSITIVE, m_bCaseInsensitive);
99 DDX_Check(pDX, IDC_UTF8DEFAULT, m_bUTF8Default);
100 DDX_Check(pDX, IDC_AUTOADD, m_bAutoAdd);
101 DDX_Text(pDX, IDC_MAXINLINE, m_nMaxInline);
104 void CSetMainPage::SaveData()
106 m_regBackup = m_bBackup;
107 m_regFirstDiffOnLoad = m_bFirstDiffOnLoad;
108 m_regFirstConflictOnLoad = m_bFirstConflictOnLoad;
109 m_regTabSize = m_nTabSize;
110 m_regIgnoreEOL = m_bIgnoreEOL;
111 m_regOnePane = m_bOnePane;
112 m_regFontName = m_sFontName;
113 m_regFontSize = m_dwFontSize;
114 m_regViewLinenumbers = m_bViewLinenumbers;
115 m_regCaseInsensitive = m_bCaseInsensitive;
116 m_regUTF8Default = m_bUTF8Default;
117 m_regAutoAdd = m_bAutoAdd;
118 m_regMaxInline = m_nMaxInline;
121 BOOL CSetMainPage::OnApply()
123 UpdateData();
124 if (m_cFontNames.GetSelFont())
125 m_sFontName = m_cFontNames.GetSelFont()->m_strName;
126 else
127 m_sFontName = m_regFontName;
128 SaveData();
129 SetModified(FALSE);
130 return CPropertyPage::OnApply();
133 BOOL CSetMainPage::OnInitDialog()
135 CMFCFontComboBox::m_bDrawUsingFont = true;
137 CPropertyPage::OnInitDialog();
139 m_bBackup = m_regBackup;
140 m_bFirstDiffOnLoad = m_regFirstDiffOnLoad;
141 m_bFirstConflictOnLoad = m_regFirstConflictOnLoad;
142 m_nTabSize = m_regTabSize;
143 m_bIgnoreEOL = m_regIgnoreEOL;
144 m_bOnePane = m_regOnePane;
145 m_sFontName = m_regFontName;
146 m_dwFontSize = m_regFontSize;
147 m_bViewLinenumbers = m_regViewLinenumbers;
148 m_bCaseInsensitive = m_regCaseInsensitive;
149 m_bUTF8Default = m_regUTF8Default;
150 m_bAutoAdd = m_regAutoAdd;
151 m_nMaxInline = m_regMaxInline;
153 DialogEnableWindow(IDC_FIRSTCONFLICTONLOAD, m_bFirstDiffOnLoad);
155 CString temp;
156 int count = 0;
157 for (int i=6; i<32; i=i+2)
159 temp.Format(_T("%d"), i);
160 m_cFontSizes.AddString(temp);
161 m_cFontSizes.SetItemData(count++, i);
163 BOOL foundfont = FALSE;
164 for (int i=0; i<m_cFontSizes.GetCount(); i++)
166 if (m_cFontSizes.GetItemData(i) == m_dwFontSize)
168 m_cFontSizes.SetCurSel(i);
169 foundfont = TRUE;
172 if (!foundfont)
174 temp.Format(_T("%d"), m_dwFontSize);
175 m_cFontSizes.SetWindowText(temp);
177 m_cFontNames.Setup(DEVICE_FONTTYPE|RASTER_FONTTYPE|TRUETYPE_FONTTYPE, 1, FIXED_PITCH);
178 m_cFontNames.SelectFont(m_sFontName);
180 UpdateData(FALSE);
181 return TRUE; // return TRUE unless you set the focus to a control
182 // EXCEPTION: OCX Property Pages should return FALSE
185 BEGIN_MESSAGE_MAP(CSetMainPage, CPropertyPage)
186 ON_BN_CLICKED(IDC_BACKUP, &CSetMainPage::OnModified)
187 ON_BN_CLICKED(IDC_IGNORELF, &CSetMainPage::OnModifiedWithReload)
188 ON_BN_CLICKED(IDC_ONEPANE, &CSetMainPage::OnModified)
189 ON_BN_CLICKED(IDC_FIRSTDIFFONLOAD, &CSetMainPage::OnModified)
190 ON_BN_CLICKED(IDC_FIRSTCONFLICTONLOAD, &CSetMainPage::OnModified)
191 ON_BN_CLICKED(IDC_LINENUMBERS, &CSetMainPage::OnModified)
192 ON_EN_CHANGE(IDC_TABSIZE, &CSetMainPage::OnModified)
193 ON_CBN_SELCHANGE(IDC_FONTSIZES, &CSetMainPage::OnModified)
194 ON_CBN_SELCHANGE(IDC_FONTNAMES, &CSetMainPage::OnModified)
195 ON_BN_CLICKED(IDC_CASEINSENSITIVE, &CSetMainPage::OnModified)
196 ON_BN_CLICKED(IDC_UTF8DEFAULT, &CSetMainPage::OnModified)
197 ON_BN_CLICKED(IDC_AUTOADD, &CSetMainPage::OnModified)
198 ON_EN_CHANGE(IDC_MAXINLINE, &CSetMainPage::OnModifiedWithReload)
199 END_MESSAGE_MAP()
202 // CSetMainPage message handlers
204 void CSetMainPage::OnModified()
206 UpdateData();
207 SetModified();
208 DialogEnableWindow(IDC_FIRSTCONFLICTONLOAD, m_bFirstDiffOnLoad);
211 void CSetMainPage::OnModifiedWithReload()
213 m_bReloadNeeded = TRUE;
214 SetModified();
217 void CSetMainPage::OnBnClickedWhitespace()
219 m_bReloadNeeded = TRUE;
220 SetModified();
223 BOOL CSetMainPage::DialogEnableWindow(UINT nID, BOOL bEnable)
225 CWnd * pwndDlgItem = GetDlgItem(nID);
226 if (pwndDlgItem == NULL)
227 return FALSE;
228 if (bEnable)
229 return pwndDlgItem->EnableWindow(bEnable);
230 if (GetFocus() == pwndDlgItem)
232 SendMessage(WM_NEXTDLGCTL, 0, FALSE);
234 return pwndDlgItem->EnableWindow(bEnable);