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
)
76 BOOL
CSettingGitConfig::OnInitDialog()
78 ISettingsPropPage::OnInitDialog();
80 m_cSafeCrLf
.AddString(_T("false"));
81 m_cSafeCrLf
.AddString(_T("true"));
82 m_cSafeCrLf
.AddString(_T("warn"));
84 m_UserName
= g_Git
.GetUserName();
85 m_UserEmail
= g_Git
.GetUserEmail();
86 m_UserSigningKey
= g_Git
.GetConfigValue(_T("user.signingkey"));
88 ProjectProperties::GetBOOLProps(this->m_bAutoCrlf
, _T("core.autocrlf"));
89 BOOL bSafeCrLf
= FALSE
;
90 ProjectProperties::GetBOOLProps(bSafeCrLf
, _T("core.safecrlf"));
92 m_cSafeCrLf
.SetCurSel(1);
96 ProjectProperties::GetStringProps(sSafeCrLf
, _T("core.safecrlf"));
97 sSafeCrLf
= sSafeCrLf
.MakeLower().Trim();
98 if (sSafeCrLf
== _T("warn"))
99 m_cSafeCrLf
.SetCurSel(2);
101 m_cSafeCrLf
.SetCurSel(0);
103 ProjectProperties::GetBOOLProps(this->m_bWarnNoSignedOffBy
, _T("tgit.warnnosignedoffby"));
105 CString str
= ((CSettings
*)GetParent())->m_CmdPath
.GetWinPath();
106 bool isBareRepo
= g_GitAdminDir
.IsBareRepo(str
);
108 if (g_GitAdminDir
.HasAdminDir(str
, &proj
) || isBareRepo
)
110 this->SetWindowText(_T("Config - ") + proj
);
111 this->GetDlgItem(IDC_CHECK_GLOBAL
)->EnableWindow(TRUE
);
112 this->GetDlgItem(IDC_EDITLOCALGITCONFIG
)->EnableWindow(TRUE
);
117 this->GetDlgItem(IDC_CHECK_GLOBAL
)->EnableWindow(FALSE
);
118 this->GetDlgItem(IDC_EDITLOCALGITCONFIG
)->EnableWindow(FALSE
);
122 this->GetDlgItem(IDC_EDITLOCALGITCONFIG
)->SetWindowText(_T("Edit local git config"));
124 this->UpdateData(FALSE
);
127 // CSettingGitConfig message handlers
129 void CSettingGitConfig::OnBnClickedCheckGlobal()
134 void CSettingGitConfig::OnEnChangeGitUsername()
136 m_ChangeMask
|= GIT_NAME
;
140 void CSettingGitConfig::OnEnChangeGitUseremail()
142 m_ChangeMask
|= GIT_EMAIL
;
146 void CSettingGitConfig::OnEnChangeGitUserSigningKey()
148 m_ChangeMask
|= GIT_SIGNINGKEY
;
152 BOOL
CSettingGitConfig::OnApply()
155 CONFIG_TYPE type
=CONFIG_LOCAL
;
156 this->UpdateData(FALSE
);
159 type
= CONFIG_GLOBAL
;
161 if(m_ChangeMask
&GIT_NAME
)
162 if(g_Git
.SetConfigValue(_T("user.name"), this->m_UserName
,type
, g_Git
.GetGitEncode(L
"i18n.commitencoding")))
164 CMessageBox::Show(NULL
, _T("Fail to save user name"), _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
168 if(m_ChangeMask
&GIT_EMAIL
)
169 if(g_Git
.SetConfigValue(_T("user.email"), this->m_UserEmail
,type
, g_Git
.GetGitEncode(L
"i18n.commitencoding")))
171 CMessageBox::Show(NULL
, _T("Fail to save user email"), _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
175 if(m_ChangeMask
&GIT_SIGNINGKEY
)
176 if(g_Git
.SetConfigValue(_T("user.signingkey"), this->m_UserSigningKey
, type
, g_Git
.GetGitEncode(L
"i18n.commitencoding")))
178 CMessageBox::Show(NULL
,_T("Fail to save user signingkey"),_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
182 if(m_ChangeMask
&GIT_WARNNOSIGNEDOFFBY
)
183 if(g_Git
.SetConfigValue(_T("tgit.warnnosignedoffby"), this->m_bWarnNoSignedOffBy
?_T("true"):_T("false"), type
))
185 CMessageBox::Show(NULL
, _T("Fail to save warnnosignedoffby"), _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
189 if(m_ChangeMask
&GIT_CRLF
)
190 if(g_Git
.SetConfigValue(_T("core.autocrlf"), this->m_bAutoCrlf
?_T("true"):_T("false"), type
))
192 CMessageBox::Show(NULL
, _T("Fail to save autocrlf"), _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
196 if(m_ChangeMask
&GIT_SAFECRLF
)
199 this->m_cSafeCrLf
.GetWindowText(safecrlf
);
200 if(g_Git
.SetConfigValue(_T("core.safecrlf"), safecrlf
, type
))
202 CMessageBox::Show(NULL
, _T("Fail to save safecrlf"), _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
209 return ISettingsPropPage::OnApply();
211 void CSettingGitConfig::OnBnClickedCheckWarnNoSignedOffBy()
213 m_ChangeMask
|= GIT_WARNNOSIGNEDOFFBY
;
216 void CSettingGitConfig::OnBnClickedCheckAutocrlf()
218 m_ChangeMask
|= GIT_CRLF
;
222 void CSettingGitConfig::OnCbnSelchangeSafeCrLf()
224 m_ChangeMask
|= GIT_SAFECRLF
;
228 void CSettingGitConfig::OnBnClickedEditglobalgitconfig()
230 char charBuf
[MAX_PATH
];
232 strcpy_s(charBuf
, MAX_PATH
, get_windows_home_directory());
233 _tcscpy_s(buf
, MAX_PATH
, CA2CT(charBuf
));
234 _tcscat_s(buf
, MAX_PATH
, _T("\\.gitconfig"));
235 // use alternative editor because of LineEndings
236 CAppUtils::LaunchAlternativeEditor(buf
);
239 void CSettingGitConfig::OnBnClickedEditlocalgitconfig()
242 g_GitAdminDir
.GetAdminDirPath(g_Git
.m_CurrentDir
, path
);
243 path
+= _T("config");
244 // use alternative editor because of LineEndings
245 CAppUtils::LaunchAlternativeEditor(path
);