1 // TortoiseGitMerge - a Diff/Patch program
3 // Copyright (C) 2013-2014 - TortoiseGit
4 // Copyright (C) 2006-2010, 2012-2014 - 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.
21 #include "TortoiseMerge.h"
22 #include "DirFileEnum.h"
24 #include "PathUtils.h"
25 #include "SetMainPage.h"
29 // CSetMainPage dialog
31 IMPLEMENT_DYNAMIC(CSetMainPage
, CPropertyPage
)
32 CSetMainPage::CSetMainPage()
33 : CPropertyPage(CSetMainPage::IDD
)
35 , m_bFirstDiffOnLoad(FALSE
)
36 , m_bFirstConflictOnLoad(FALSE
)
38 , m_bSmartTabChar(FALSE
)
40 , m_bEnableEditorConfig(FALSE
)
44 , m_bViewLinenumbers(FALSE
)
45 , m_bReloadNeeded(FALSE
)
46 , m_bCaseInsensitive(FALSE
)
47 , m_bUTF8Default(FALSE
)
52 m_regBackup
= CRegDWORD(_T("Software\\TortoiseGitMerge\\Backup"));
53 m_regFirstDiffOnLoad
= CRegDWORD(_T("Software\\TortoiseGitMerge\\FirstDiffOnLoad"), TRUE
);
54 m_regFirstConflictOnLoad
= CRegDWORD(_T("Software\\TortoiseGitMerge\\FirstConflictOnLoad"), TRUE
);
55 m_regTabMode
= CRegDWORD(_T("Software\\TortoiseGitMerge\\TabMode"), 0);
56 m_regTabSize
= CRegDWORD(_T("Software\\TortoiseGitMerge\\TabSize"), 4);
57 m_regEnableEditorConfig
= CRegDWORD(_T("Software\\TortoiseGitMerge\\EnableEditorConfig"), FALSE
);
58 m_regIgnoreEOL
= CRegDWORD(_T("Software\\TortoiseGitMerge\\IgnoreEOL"), TRUE
);
59 m_regOnePane
= CRegDWORD(_T("Software\\TortoiseGitMerge\\OnePane"));
60 m_regViewLinenumbers
= CRegDWORD(_T("Software\\TortoiseGitMerge\\ViewLinenumbers"), 1);
61 m_regFontName
= CRegString(_T("Software\\TortoiseGitMerge\\LogFontName"), _T("Courier New"));
62 m_regFontSize
= CRegDWORD(_T("Software\\TortoiseGitMerge\\LogFontSize"), 10);
63 m_regCaseInsensitive
= CRegDWORD(_T("Software\\TortoiseGitMerge\\CaseInsensitive"), FALSE
);
64 m_regUTF8Default
= CRegDWORD(_T("Software\\TortoiseGitMerge\\UseUTF8"), FALSE
);
65 m_regAutoAdd
= CRegDWORD(_T("Software\\TortoiseGitMerge\\AutoAdd"), TRUE
);
66 m_regMaxInline
= CRegDWORD(_T("Software\\TortoiseGitMerge\\InlineDiffMaxLineLength"), 3000);
67 m_regUseRibbons
= CRegDWORD(L
"Software\\TortoiseGitMerge\\UseRibbons", TRUE
);
68 m_regUseTaskDialog
= CRegDWORD(L
"Software\\TortoiseGitMerge\\UseTaskDialog", TRUE
);
69 m_regContextLines
= CRegDWORD(L
"Software\\TortoiseGitMerge\\ContextLines", (DWORD
)-1);
71 m_bBackup
= m_regBackup
;
72 m_bFirstDiffOnLoad
= m_regFirstDiffOnLoad
;
73 m_bFirstConflictOnLoad
= m_regFirstConflictOnLoad
;
74 m_bUseSpaces
= (m_regTabMode
& TABMODE_USESPACES
) ? TRUE
: FALSE
;
75 m_bSmartTabChar
= (m_regTabMode
& TABMODE_SMARTINDENT
) ? TRUE
: FALSE
;
76 m_nTabSize
= m_regTabSize
;
77 m_bEnableEditorConfig
= m_regEnableEditorConfig
;
78 m_nContextLines
= m_regContextLines
;
79 m_bIgnoreEOL
= m_regIgnoreEOL
;
80 m_bOnePane
= m_regOnePane
;
81 m_bViewLinenumbers
= m_regViewLinenumbers
;
82 m_bCaseInsensitive
= m_regCaseInsensitive
;
83 m_bUTF8Default
= m_regUTF8Default
;
84 m_bAutoAdd
= m_regAutoAdd
;
85 m_nMaxInline
= m_regMaxInline
;
86 m_bUseRibbons
= m_regUseRibbons
;
87 m_bUseTaskDialog
= CTaskDialog::IsSupported() && (DWORD
)m_regUseTaskDialog
;
90 CSetMainPage::~CSetMainPage()
94 void CSetMainPage::DoDataExchange(CDataExchange
* pDX
)
96 CPropertyPage::DoDataExchange(pDX
);
97 DDX_Check(pDX
, IDC_BACKUP
, m_bBackup
);
98 DDX_Check(pDX
, IDC_FIRSTDIFFONLOAD
, m_bFirstDiffOnLoad
);
99 DDX_Check(pDX
, IDC_FIRSTCONFLICTONLOAD
, m_bFirstConflictOnLoad
);
100 DDX_Check(pDX
, IDC_USESPACES
, m_bUseSpaces
);
101 DDX_Check(pDX
, IDC_SMARTTABCHAR
, m_bSmartTabChar
);
102 DDX_Text(pDX
, IDC_TABSIZE
, m_nTabSize
);
103 DDV_MinMaxInt(pDX
, m_nTabSize
, 1, 1000);
104 DDX_Check(pDX
, IDC_ENABLEEDITORCONFIG
, m_bEnableEditorConfig
);
105 DDX_Text(pDX
, IDC_CONTEXTLINES
, m_nContextLines
);
106 DDV_MinMaxInt(pDX
, m_nContextLines
, -1, 1000);
107 DDX_Check(pDX
, IDC_IGNORELF
, m_bIgnoreEOL
);
108 DDX_Check(pDX
, IDC_ONEPANE
, m_bOnePane
);
109 DDX_Control(pDX
, IDC_FONTSIZES
, m_cFontSizes
);
110 m_dwFontSize
= (DWORD
)m_cFontSizes
.GetItemData(m_cFontSizes
.GetCurSel());
111 if ((m_dwFontSize
==0)||(m_dwFontSize
== -1))
114 m_cFontSizes
.GetWindowText(t
);
115 m_dwFontSize
= _ttoi(t
);
117 DDX_Control(pDX
, IDC_FONTNAMES
, m_cFontNames
);
118 DDX_Check(pDX
, IDC_LINENUMBERS
, m_bViewLinenumbers
);
119 DDX_Check(pDX
, IDC_CASEINSENSITIVE
, m_bCaseInsensitive
);
120 DDX_Check(pDX
, IDC_UTF8DEFAULT
, m_bUTF8Default
);
121 DDX_Check(pDX
, IDC_AUTOADD
, m_bAutoAdd
);
122 DDX_Text(pDX
, IDC_MAXINLINE
, m_nMaxInline
);
123 DDX_Check(pDX
, IDC_USERIBBONS
, m_bUseRibbons
);
124 DDX_Check(pDX
, IDC_USETASKDIALOG
, m_bUseTaskDialog
);
127 void CSetMainPage::SaveData()
129 m_regBackup
= m_bBackup
;
130 m_regFirstDiffOnLoad
= m_bFirstDiffOnLoad
;
131 m_regFirstConflictOnLoad
= m_bFirstConflictOnLoad
;
132 m_regTabMode
= (m_bUseSpaces
? TABMODE_USESPACES
: TABMODE_NONE
) | (m_bSmartTabChar
? TABMODE_SMARTINDENT
: TABMODE_NONE
);
133 m_regTabSize
= m_nTabSize
;
134 m_regEnableEditorConfig
= m_bEnableEditorConfig
;
135 m_regContextLines
= m_nContextLines
;
136 m_regIgnoreEOL
= m_bIgnoreEOL
;
137 m_regOnePane
= m_bOnePane
;
138 m_regFontName
= m_sFontName
;
139 m_regFontSize
= m_dwFontSize
;
140 m_regViewLinenumbers
= m_bViewLinenumbers
;
141 m_regCaseInsensitive
= m_bCaseInsensitive
;
142 m_regUTF8Default
= m_bUTF8Default
;
143 m_regAutoAdd
= m_bAutoAdd
;
144 m_regMaxInline
= m_nMaxInline
;
145 m_regUseRibbons
= m_bUseRibbons
;
146 m_regUseTaskDialog
= m_bUseTaskDialog
;
149 BOOL
CSetMainPage::OnApply()
152 if (m_cFontNames
.GetSelFont())
153 m_sFontName
= m_cFontNames
.GetSelFont()->m_strName
;
155 m_sFontName
= m_regFontName
;
158 return CPropertyPage::OnApply();
161 BOOL
CSetMainPage::OnInitDialog()
163 CMFCFontComboBox::m_bDrawUsingFont
= true;
165 CPropertyPage::OnInitDialog();
167 m_bBackup
= m_regBackup
;
168 m_bFirstDiffOnLoad
= m_regFirstDiffOnLoad
;
169 m_bFirstConflictOnLoad
= m_regFirstConflictOnLoad
;
170 m_bUseSpaces
= (m_regTabMode
& TABMODE_USESPACES
) ? TRUE
: FALSE
;
171 m_bSmartTabChar
= (m_regTabMode
& TABMODE_SMARTINDENT
) ? TRUE
: FALSE
;
172 m_nTabSize
= m_regTabSize
;
173 m_bEnableEditorConfig
= m_regEnableEditorConfig
;
174 m_nContextLines
= m_regContextLines
;
175 m_bIgnoreEOL
= m_regIgnoreEOL
;
176 m_bOnePane
= m_regOnePane
;
177 m_sFontName
= m_regFontName
;
178 m_dwFontSize
= m_regFontSize
;
179 m_bViewLinenumbers
= m_regViewLinenumbers
;
180 m_bCaseInsensitive
= m_regCaseInsensitive
;
181 m_bUTF8Default
= m_regUTF8Default
;
182 m_bAutoAdd
= m_regAutoAdd
;
183 m_nMaxInline
= m_regMaxInline
;
184 m_bUseRibbons
= m_regUseRibbons
;
186 if (SysInfo::Instance().IsXP())
188 DialogEnableWindow(IDC_USERIBBONS
, FALSE
);
189 m_bUseRibbons
= FALSE
;
192 m_bUseTaskDialog
= CTaskDialog::IsSupported() && (DWORD
)m_regUseTaskDialog
;
194 DialogEnableWindow(IDC_FIRSTCONFLICTONLOAD
, m_bFirstDiffOnLoad
);
195 DialogEnableWindow(IDC_USETASKDIALOG
, CTaskDialog::IsSupported());
199 for (int i
=6; i
<32; i
=i
+2)
201 temp
.Format(_T("%d"), i
);
202 m_cFontSizes
.AddString(temp
);
203 m_cFontSizes
.SetItemData(count
++, i
);
205 BOOL foundfont
= FALSE
;
206 for (int i
=0; i
<m_cFontSizes
.GetCount(); i
++)
208 if (m_cFontSizes
.GetItemData(i
) == m_dwFontSize
)
210 m_cFontSizes
.SetCurSel(i
);
216 temp
.Format(_T("%lu"), m_dwFontSize
);
217 m_cFontSizes
.SetWindowText(temp
);
219 m_cFontNames
.Setup(DEVICE_FONTTYPE
|RASTER_FONTTYPE
|TRUETYPE_FONTTYPE
, 1, FIXED_PITCH
);
220 m_cFontNames
.SelectFont(m_sFontName
);
223 return TRUE
; // return TRUE unless you set the focus to a control
224 // EXCEPTION: OCX Property Pages should return FALSE
227 BEGIN_MESSAGE_MAP(CSetMainPage
, CPropertyPage
)
228 ON_BN_CLICKED(IDC_BACKUP
, &CSetMainPage::OnModified
)
229 ON_BN_CLICKED(IDC_IGNORELF
, &CSetMainPage::OnModifiedWithReload
)
230 ON_BN_CLICKED(IDC_ONEPANE
, &CSetMainPage::OnModified
)
231 ON_BN_CLICKED(IDC_FIRSTDIFFONLOAD
, &CSetMainPage::OnModified
)
232 ON_BN_CLICKED(IDC_FIRSTCONFLICTONLOAD
, &CSetMainPage::OnModified
)
233 ON_BN_CLICKED(IDC_LINENUMBERS
, &CSetMainPage::OnModified
)
234 ON_BN_CLICKED(IDC_USESPACES
, &CSetMainPage::OnModified
)
235 ON_BN_CLICKED(IDC_SMARTTABCHAR
, &CSetMainPage::OnModified
)
236 ON_EN_CHANGE(IDC_TABSIZE
, &CSetMainPage::OnModified
)
237 ON_BN_CLICKED(IDC_ENABLEEDITORCONFIG
, &CSetMainPage::OnModified
)
238 ON_EN_CHANGE(IDC_CONTEXTLINES
, &CSetMainPage::OnModified
)
239 ON_CBN_SELCHANGE(IDC_FONTSIZES
, &CSetMainPage::OnModified
)
240 ON_CBN_SELCHANGE(IDC_FONTNAMES
, &CSetMainPage::OnModified
)
241 ON_BN_CLICKED(IDC_CASEINSENSITIVE
, &CSetMainPage::OnModified
)
242 ON_BN_CLICKED(IDC_UTF8DEFAULT
, &CSetMainPage::OnModified
)
243 ON_BN_CLICKED(IDC_AUTOADD
, &CSetMainPage::OnModified
)
244 ON_EN_CHANGE(IDC_MAXINLINE
, &CSetMainPage::OnModifiedWithReload
)
245 ON_BN_CLICKED(IDC_USERIBBONS
, &CSetMainPage::OnModified
)
246 ON_BN_CLICKED(IDC_USETASKDIALOG
, &CSetMainPage::OnModified
)
250 // CSetMainPage message handlers
252 void CSetMainPage::OnModified()
256 DialogEnableWindow(IDC_FIRSTCONFLICTONLOAD
, m_bFirstDiffOnLoad
);
259 void CSetMainPage::OnModifiedWithReload()
261 m_bReloadNeeded
= TRUE
;
265 void CSetMainPage::OnBnClickedWhitespace()
267 m_bReloadNeeded
= TRUE
;
271 BOOL
CSetMainPage::DialogEnableWindow(UINT nID
, BOOL bEnable
)
273 CWnd
* pwndDlgItem
= GetDlgItem(nID
);
274 if (pwndDlgItem
== NULL
)
277 return pwndDlgItem
->EnableWindow(bEnable
);
278 if (GetFocus() == pwndDlgItem
)
280 SendMessage(WM_NEXTDLGCTL
, 0, FALSE
);
282 return pwndDlgItem
->EnableWindow(bEnable
);