1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2012 - TortoiseGit
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 // SettingGitConfig.cpp : implementation file
23 #include "TortoiseProc.h"
24 #include "SettingGitConfig.h"
27 #include "GitAdminDir.h"
28 #include "MessageBox.h"
29 #include "ProjectProperties.h"
31 #include "PathUtils.h"
32 // CSettingGitConfig dialog
34 IMPLEMENT_DYNAMIC(CSettingGitConfig
, ISettingsPropPage
)
36 CSettingGitConfig::CSettingGitConfig()
37 : ISettingsPropPage(CSettingGitConfig::IDD
)
40 , m_UserSigningKey(_T(""))
43 , m_bWarnNoSignedOffBy(FALSE
)
48 CSettingGitConfig::~CSettingGitConfig()
52 void CSettingGitConfig::DoDataExchange(CDataExchange
* pDX
)
54 CPropertyPage::DoDataExchange(pDX
);
55 DDX_Text(pDX
, IDC_GIT_USERNAME
, m_UserName
);
56 DDX_Text(pDX
, IDC_GIT_USEREMAIL
, m_UserEmail
);
57 DDX_Text(pDX
, IDC_GIT_USERESINGNINGKEY
, m_UserSigningKey
);
58 DDX_Check(pDX
, IDC_CHECK_GLOBAL
, m_bGlobal
);
59 DDX_Check(pDX
, IDC_CHECK_AUTOCRLF
, m_bAutoCrlf
);
60 DDX_Control(pDX
, IDC_COMBO_SAFECRLF
, m_cSafeCrLf
);
61 DDX_Check(pDX
, IDC_CHECK_WARN_NO_SIGNED_OFF_BY
, m_bWarnNoSignedOffBy
);
64 BEGIN_MESSAGE_MAP(CSettingGitConfig
, CPropertyPage
)
65 ON_BN_CLICKED(IDC_CHECK_GLOBAL
, &CSettingGitConfig::OnBnClickedCheckGlobal
)
66 ON_EN_CHANGE(IDC_GIT_USERNAME
, &CSettingGitConfig::OnEnChangeGitUsername
)
67 ON_EN_CHANGE(IDC_GIT_USEREMAIL
, &CSettingGitConfig::OnEnChangeGitUseremail
)
68 ON_EN_CHANGE(IDC_GIT_USERESINGNINGKEY
, &CSettingGitConfig::OnEnChangeGitUserSigningKey
)
69 ON_BN_CLICKED(IDC_CHECK_AUTOCRLF
, &CSettingGitConfig::OnBnClickedCheckAutocrlf
)
70 ON_CBN_SELCHANGE(IDC_COMBO_SAFECRLF
, &CSettingGitConfig::OnCbnSelchangeSafeCrLf
)
71 ON_BN_CLICKED(IDC_EDITGLOBALGITCONFIG
, &CSettingGitConfig::OnBnClickedEditglobalgitconfig
)
72 ON_BN_CLICKED(IDC_EDITLOCALGITCONFIG
, &CSettingGitConfig::OnBnClickedEditlocalgitconfig
)
73 ON_BN_CLICKED(IDC_CHECK_WARN_NO_SIGNED_OFF_BY
, &CSettingGitConfig::OnBnClickedCheckWarnNoSignedOffBy
)
74 ON_BN_CLICKED(IDC_EDITSYSTEMGITCONFIG
, &CSettingGitConfig::OnBnClickedEditsystemgitconfig
)
77 BOOL
CSettingGitConfig::OnInitDialog()
79 ISettingsPropPage::OnInitDialog();
81 m_cSafeCrLf
.AddString(_T("false"));
82 m_cSafeCrLf
.AddString(_T("true"));
83 m_cSafeCrLf
.AddString(_T("warn"));
85 m_UserName
= g_Git
.GetUserName();
86 m_UserEmail
= g_Git
.GetUserEmail();
87 m_UserSigningKey
= g_Git
.GetConfigValue(_T("user.signingkey"));
89 ProjectProperties::GetBOOLProps(this->m_bAutoCrlf
, _T("core.autocrlf"));
90 BOOL bSafeCrLf
= FALSE
;
91 ProjectProperties::GetBOOLProps(bSafeCrLf
, _T("core.safecrlf"));
93 m_cSafeCrLf
.SetCurSel(1);
97 ProjectProperties::GetStringProps(sSafeCrLf
, _T("core.safecrlf"));
98 sSafeCrLf
= sSafeCrLf
.MakeLower().Trim();
99 if (sSafeCrLf
== _T("warn"))
100 m_cSafeCrLf
.SetCurSel(2);
102 m_cSafeCrLf
.SetCurSel(0);
104 ProjectProperties::GetBOOLProps(this->m_bWarnNoSignedOffBy
, _T("tgit.warnnosignedoffby"));
106 CString str
= ((CSettings
*)GetParent())->m_CmdPath
.GetWinPath();
107 bool isBareRepo
= g_GitAdminDir
.IsBareRepo(str
);
109 if (g_GitAdminDir
.HasAdminDir(str
, &proj
) || isBareRepo
)
112 this->GetWindowText(title
);
113 this->SetWindowText(title
+ _T(" - ") + proj
);
114 this->GetDlgItem(IDC_CHECK_GLOBAL
)->EnableWindow(TRUE
);
115 this->GetDlgItem(IDC_EDITLOCALGITCONFIG
)->EnableWindow(TRUE
);
120 this->GetDlgItem(IDC_CHECK_GLOBAL
)->EnableWindow(FALSE
);
121 this->GetDlgItem(IDC_EDITLOCALGITCONFIG
)->EnableWindow(FALSE
);
125 this->GetDlgItem(IDC_EDITLOCALGITCONFIG
)->SetWindowText(CString(MAKEINTRESOURCE(IDS_PROC_GITCONFIG_EDITLOCALGONCFIG
)));
127 this->UpdateData(FALSE
);
130 // CSettingGitConfig message handlers
132 void CSettingGitConfig::OnBnClickedCheckGlobal()
137 void CSettingGitConfig::OnEnChangeGitUsername()
139 m_ChangeMask
|= GIT_NAME
;
143 void CSettingGitConfig::OnEnChangeGitUseremail()
145 m_ChangeMask
|= GIT_EMAIL
;
149 void CSettingGitConfig::OnEnChangeGitUserSigningKey()
151 m_ChangeMask
|= GIT_SIGNINGKEY
;
155 BOOL
CSettingGitConfig::OnApply()
158 CONFIG_TYPE type
=CONFIG_LOCAL
;
159 this->UpdateData(FALSE
);
162 type
= CONFIG_GLOBAL
;
164 if(m_ChangeMask
&GIT_NAME
)
165 if (!Save(_T("user.name"), this->m_UserName
, type
))
168 if(m_ChangeMask
&GIT_EMAIL
)
169 if (!Save(_T("user.email"), this->m_UserEmail
,type
))
172 if(m_ChangeMask
&GIT_SIGNINGKEY
)
173 if (!Save(_T("user.signingkey"), this->m_UserSigningKey
, type
))
176 if(m_ChangeMask
&GIT_WARNNOSIGNEDOFFBY
)
177 if (!Save(_T("tgit.warnnosignedoffby"), this->m_bWarnNoSignedOffBy
? _T("true") : _T("false"), type
))
180 if(m_ChangeMask
&GIT_CRLF
)
181 if (!Save(_T("core.autocrlf"), this->m_bAutoCrlf
? _T("true") : _T("false"), type
))
184 if(m_ChangeMask
&GIT_SAFECRLF
)
187 this->m_cSafeCrLf
.GetWindowText(safecrlf
);
188 if (!Save(_T("core.safecrlf"), safecrlf
, type
))
194 return ISettingsPropPage::OnApply();
196 bool CSettingGitConfig::Save(CString key
, CString value
, CONFIG_TYPE type
)
199 if (g_Git
.SetConfigValue(key
, value
, type
, g_Git
.GetGitEncode(L
"i18n.commitencoding"), &g_Git
.m_CurrentDir
))
202 msg
.Format(IDS_PROC_SAVECONFIGFAILED
, key
, value
);
203 CMessageBox::Show(NULL
, msg
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
208 void CSettingGitConfig::OnBnClickedCheckWarnNoSignedOffBy()
210 m_ChangeMask
|= GIT_WARNNOSIGNEDOFFBY
;
213 void CSettingGitConfig::OnBnClickedCheckAutocrlf()
215 m_ChangeMask
|= GIT_CRLF
;
219 void CSettingGitConfig::OnCbnSelchangeSafeCrLf()
221 m_ChangeMask
|= GIT_SAFECRLF
;
225 void CSettingGitConfig::OnBnClickedEditglobalgitconfig()
227 CString filename
= g_Git
.GetHomeDirectory() + _T("\\.gitconfig");
228 // use alternative editor because of LineEndings
229 CAppUtils::LaunchAlternativeEditor(filename
);
232 void CSettingGitConfig::OnBnClickedEditlocalgitconfig()
235 g_GitAdminDir
.GetAdminDirPath(g_Git
.m_CurrentDir
, path
);
236 path
+= _T("config");
237 // use alternative editor because of LineEndings
238 CAppUtils::LaunchAlternativeEditor(path
);
241 void CSettingGitConfig::OnBnClickedEditsystemgitconfig()
244 const char * systemdir
= get_msysgit_etc();
247 CMessageBox::Show(NULL
, IDS_PROC_GITCONFIG_NOMSYSGIT
, IDS_APPNAME
, MB_ICONERROR
);
250 _tcscpy_s(buf
, MAX_PATH
, CA2CT(systemdir
));
251 // use alternative editor because of LineEndings
252 CAppUtils::LaunchAlternativeEditor(buf
);