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.
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
)
43 , m_bViewLinenumbers(FALSE
)
44 , m_bReloadNeeded(FALSE
)
45 , m_bCaseInsensitive(FALSE
)
46 , m_bUTF8Default(FALSE
)
51 m_regBackup
= CRegDWORD(_T("Software\\TortoiseGitMerge\\Backup"));
52 m_regFirstDiffOnLoad
= CRegDWORD(_T("Software\\TortoiseGitMerge\\FirstDiffOnLoad"), TRUE
);
53 m_regFirstConflictOnLoad
= CRegDWORD(_T("Software\\TortoiseGitMerge\\FirstConflictOnLoad"), TRUE
);
54 m_regTabMode
= CRegDWORD(_T("Software\\TortoiseGitMerge\\TabMode"), 0);
55 m_regTabSize
= CRegDWORD(_T("Software\\TortoiseGitMerge\\TabSize"), 4);
56 m_regEnableEditorConfig
= CRegDWORD(_T("Software\\TortoiseGitMerge\\EnableEditorConfig"), FALSE
);
57 m_regIgnoreEOL
= CRegDWORD(_T("Software\\TortoiseGitMerge\\IgnoreEOL"), TRUE
);
58 m_regOnePane
= CRegDWORD(_T("Software\\TortoiseGitMerge\\OnePane"));
59 m_regViewLinenumbers
= CRegDWORD(_T("Software\\TortoiseGitMerge\\ViewLinenumbers"), 1);
60 m_regFontName
= CRegString(_T("Software\\TortoiseGitMerge\\LogFontName"), _T("Courier New"));
61 m_regFontSize
= CRegDWORD(_T("Software\\TortoiseGitMerge\\LogFontSize"), 10);
62 m_regCaseInsensitive
= CRegDWORD(_T("Software\\TortoiseGitMerge\\CaseInsensitive"), FALSE
);
63 m_regUTF8Default
= CRegDWORD(_T("Software\\TortoiseGitMerge\\UseUTF8"), FALSE
);
64 m_regAutoAdd
= CRegDWORD(_T("Software\\TortoiseGitMerge\\AutoAdd"), TRUE
);
65 m_regMaxInline
= CRegDWORD(_T("Software\\TortoiseGitMerge\\InlineDiffMaxLineLength"), 3000);
66 m_regUseRibbons
= CRegDWORD(L
"Software\\TortoiseGitMerge\\UseRibbons", TRUE
);
67 m_regUseTaskDialog
= CRegDWORD(L
"Software\\TortoiseGitMerge\\UseTaskDialog", TRUE
);
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_bIgnoreEOL
= m_regIgnoreEOL
;
77 m_bOnePane
= m_regOnePane
;
78 m_bViewLinenumbers
= m_regViewLinenumbers
;
79 m_bCaseInsensitive
= m_regCaseInsensitive
;
80 m_bUTF8Default
= m_regUTF8Default
;
81 m_bAutoAdd
= m_regAutoAdd
;
82 m_nMaxInline
= m_regMaxInline
;
83 m_bUseRibbons
= m_regUseRibbons
;
84 m_bUseTaskDialog
= CTaskDialog::IsSupported() && (DWORD
)m_regUseTaskDialog
;
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_Check(pDX
, IDC_IGNORELF
, m_bIgnoreEOL
);
103 DDX_Check(pDX
, IDC_ONEPANE
, m_bOnePane
);
104 DDX_Control(pDX
, IDC_FONTSIZES
, m_cFontSizes
);
105 m_dwFontSize
= (DWORD
)m_cFontSizes
.GetItemData(m_cFontSizes
.GetCurSel());
106 if ((m_dwFontSize
==0)||(m_dwFontSize
== -1))
109 m_cFontSizes
.GetWindowText(t
);
110 m_dwFontSize
= _ttoi(t
);
112 DDX_Control(pDX
, IDC_FONTNAMES
, m_cFontNames
);
113 DDX_Check(pDX
, IDC_LINENUMBERS
, m_bViewLinenumbers
);
114 DDX_Check(pDX
, IDC_CASEINSENSITIVE
, m_bCaseInsensitive
);
115 DDX_Check(pDX
, IDC_UTF8DEFAULT
, m_bUTF8Default
);
116 DDX_Check(pDX
, IDC_AUTOADD
, m_bAutoAdd
);
117 DDX_Text(pDX
, IDC_MAXINLINE
, m_nMaxInline
);
118 DDX_Check(pDX
, IDC_USERIBBONS
, m_bUseRibbons
);
119 DDX_Check(pDX
, IDC_USETASKDIALOG
, m_bUseTaskDialog
);
122 void CSetMainPage::SaveData()
124 m_regBackup
= m_bBackup
;
125 m_regFirstDiffOnLoad
= m_bFirstDiffOnLoad
;
126 m_regFirstConflictOnLoad
= m_bFirstConflictOnLoad
;
127 m_regTabMode
= (m_bUseSpaces
? TABMODE_USESPACES
: TABMODE_NONE
) | (m_bSmartTabChar
? TABMODE_SMARTINDENT
: TABMODE_NONE
);
128 m_regTabSize
= m_nTabSize
;
129 m_regEnableEditorConfig
= m_bEnableEditorConfig
;
130 m_regIgnoreEOL
= m_bIgnoreEOL
;
131 m_regOnePane
= m_bOnePane
;
132 m_regFontName
= m_sFontName
;
133 m_regFontSize
= m_dwFontSize
;
134 m_regViewLinenumbers
= m_bViewLinenumbers
;
135 m_regCaseInsensitive
= m_bCaseInsensitive
;
136 m_regUTF8Default
= m_bUTF8Default
;
137 m_regAutoAdd
= m_bAutoAdd
;
138 m_regMaxInline
= m_nMaxInline
;
139 m_regUseRibbons
= m_bUseRibbons
;
140 m_regUseTaskDialog
= m_bUseTaskDialog
;
143 BOOL
CSetMainPage::OnApply()
146 if (m_cFontNames
.GetSelFont())
147 m_sFontName
= m_cFontNames
.GetSelFont()->m_strName
;
149 m_sFontName
= m_regFontName
;
152 return CPropertyPage::OnApply();
155 BOOL
CSetMainPage::OnInitDialog()
157 CMFCFontComboBox::m_bDrawUsingFont
= true;
159 CPropertyPage::OnInitDialog();
161 m_bBackup
= m_regBackup
;
162 m_bFirstDiffOnLoad
= m_regFirstDiffOnLoad
;
163 m_bFirstConflictOnLoad
= m_regFirstConflictOnLoad
;
164 m_bUseSpaces
= (m_regTabMode
& TABMODE_USESPACES
) ? TRUE
: FALSE
;
165 m_bSmartTabChar
= (m_regTabMode
& TABMODE_SMARTINDENT
) ? TRUE
: FALSE
;
166 m_nTabSize
= m_regTabSize
;
167 m_bEnableEditorConfig
= m_regEnableEditorConfig
;
168 m_bIgnoreEOL
= m_regIgnoreEOL
;
169 m_bOnePane
= m_regOnePane
;
170 m_sFontName
= m_regFontName
;
171 m_dwFontSize
= m_regFontSize
;
172 m_bViewLinenumbers
= m_regViewLinenumbers
;
173 m_bCaseInsensitive
= m_regCaseInsensitive
;
174 m_bUTF8Default
= m_regUTF8Default
;
175 m_bAutoAdd
= m_regAutoAdd
;
176 m_nMaxInline
= m_regMaxInline
;
177 m_bUseRibbons
= m_regUseRibbons
;
179 if (SysInfo::Instance().IsXP())
181 DialogEnableWindow(IDC_USERIBBONS
, FALSE
);
182 m_bUseRibbons
= FALSE
;
185 m_bUseTaskDialog
= CTaskDialog::IsSupported() && (DWORD
)m_regUseTaskDialog
;
187 DialogEnableWindow(IDC_FIRSTCONFLICTONLOAD
, m_bFirstDiffOnLoad
);
188 DialogEnableWindow(IDC_USETASKDIALOG
, CTaskDialog::IsSupported());
192 for (int i
=6; i
<32; i
=i
+2)
194 temp
.Format(_T("%d"), i
);
195 m_cFontSizes
.AddString(temp
);
196 m_cFontSizes
.SetItemData(count
++, i
);
198 BOOL foundfont
= FALSE
;
199 for (int i
=0; i
<m_cFontSizes
.GetCount(); i
++)
201 if (m_cFontSizes
.GetItemData(i
) == m_dwFontSize
)
203 m_cFontSizes
.SetCurSel(i
);
209 temp
.Format(_T("%lu"), m_dwFontSize
);
210 m_cFontSizes
.SetWindowText(temp
);
212 m_cFontNames
.Setup(DEVICE_FONTTYPE
|RASTER_FONTTYPE
|TRUETYPE_FONTTYPE
, 1, FIXED_PITCH
);
213 m_cFontNames
.SelectFont(m_sFontName
);
216 return TRUE
; // return TRUE unless you set the focus to a control
217 // EXCEPTION: OCX Property Pages should return FALSE
220 BEGIN_MESSAGE_MAP(CSetMainPage
, CPropertyPage
)
221 ON_BN_CLICKED(IDC_BACKUP
, &CSetMainPage::OnModified
)
222 ON_BN_CLICKED(IDC_IGNORELF
, &CSetMainPage::OnModifiedWithReload
)
223 ON_BN_CLICKED(IDC_ONEPANE
, &CSetMainPage::OnModified
)
224 ON_BN_CLICKED(IDC_FIRSTDIFFONLOAD
, &CSetMainPage::OnModified
)
225 ON_BN_CLICKED(IDC_FIRSTCONFLICTONLOAD
, &CSetMainPage::OnModified
)
226 ON_BN_CLICKED(IDC_LINENUMBERS
, &CSetMainPage::OnModified
)
227 ON_BN_CLICKED(IDC_USESPACES
, &CSetMainPage::OnModified
)
228 ON_BN_CLICKED(IDC_SMARTTABCHAR
, &CSetMainPage::OnModified
)
229 ON_EN_CHANGE(IDC_TABSIZE
, &CSetMainPage::OnModified
)
230 ON_BN_CLICKED(IDC_ENABLEEDITORCONFIG
, &CSetMainPage::OnModified
)
231 ON_CBN_SELCHANGE(IDC_FONTSIZES
, &CSetMainPage::OnModified
)
232 ON_CBN_SELCHANGE(IDC_FONTNAMES
, &CSetMainPage::OnModified
)
233 ON_BN_CLICKED(IDC_CASEINSENSITIVE
, &CSetMainPage::OnModified
)
234 ON_BN_CLICKED(IDC_UTF8DEFAULT
, &CSetMainPage::OnModified
)
235 ON_BN_CLICKED(IDC_AUTOADD
, &CSetMainPage::OnModified
)
236 ON_EN_CHANGE(IDC_MAXINLINE
, &CSetMainPage::OnModifiedWithReload
)
237 ON_BN_CLICKED(IDC_USERIBBONS
, &CSetMainPage::OnModified
)
238 ON_BN_CLICKED(IDC_USETASKDIALOG
, &CSetMainPage::OnModified
)
242 // CSetMainPage message handlers
244 void CSetMainPage::OnModified()
248 DialogEnableWindow(IDC_FIRSTCONFLICTONLOAD
, m_bFirstDiffOnLoad
);
251 void CSetMainPage::OnModifiedWithReload()
253 m_bReloadNeeded
= TRUE
;
257 void CSetMainPage::OnBnClickedWhitespace()
259 m_bReloadNeeded
= TRUE
;
263 BOOL
CSetMainPage::DialogEnableWindow(UINT nID
, BOOL bEnable
)
265 CWnd
* pwndDlgItem
= GetDlgItem(nID
);
266 if (pwndDlgItem
== NULL
)
269 return pwndDlgItem
->EnableWindow(bEnable
);
270 if (GetFocus() == pwndDlgItem
)
272 SendMessage(WM_NEXTDLGCTL
, 0, FALSE
);
274 return pwndDlgItem
->EnableWindow(bEnable
);