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_EDITGLOBALXDGGITCONFIG
, &CSettingGitConfig::OnBnClickedEditglobalxdggitconfig
)
73 ON_BN_CLICKED(IDC_EDITLOCALGITCONFIG
, &CSettingGitConfig::OnBnClickedEditlocalgitconfig
)
74 ON_BN_CLICKED(IDC_CHECK_WARN_NO_SIGNED_OFF_BY
, &CSettingGitConfig::OnBnClickedCheckWarnNoSignedOffBy
)
75 ON_BN_CLICKED(IDC_EDITSYSTEMGITCONFIG
, &CSettingGitConfig::OnBnClickedEditsystemgitconfig
)
76 ON_BN_CLICKED(IDC_VIEWSYSTEMGITCONFIG
, &CSettingGitConfig::OnBnClickedViewsystemgitconfig
)
79 BOOL
CSettingGitConfig::OnInitDialog()
81 ISettingsPropPage::OnInitDialog();
83 m_cSafeCrLf
.AddString(_T("false"));
84 m_cSafeCrLf
.AddString(_T("true"));
85 m_cSafeCrLf
.AddString(_T("warn"));
87 m_UserName
= g_Git
.GetUserName();
88 m_UserEmail
= g_Git
.GetUserEmail();
89 m_UserSigningKey
= g_Git
.GetConfigValue(_T("user.signingkey"));
91 ProjectProperties::GetBOOLProps(this->m_bAutoCrlf
, _T("core.autocrlf"));
92 BOOL bSafeCrLf
= FALSE
;
93 ProjectProperties::GetBOOLProps(bSafeCrLf
, _T("core.safecrlf"));
95 m_cSafeCrLf
.SetCurSel(1);
99 ProjectProperties::GetStringProps(sSafeCrLf
, _T("core.safecrlf"));
100 sSafeCrLf
= sSafeCrLf
.MakeLower().Trim();
101 if (sSafeCrLf
== _T("warn"))
102 m_cSafeCrLf
.SetCurSel(2);
104 m_cSafeCrLf
.SetCurSel(0);
106 ProjectProperties::GetBOOLProps(this->m_bWarnNoSignedOffBy
, _T("tgit.warnnosignedoffby"));
108 CString str
= ((CSettings
*)GetParent())->m_CmdPath
.GetWinPath();
109 bool isBareRepo
= g_GitAdminDir
.IsBareRepo(str
);
111 if (g_GitAdminDir
.HasAdminDir(str
, &proj
) || isBareRepo
)
114 this->GetWindowText(title
);
115 this->SetWindowText(title
+ _T(" - ") + proj
);
116 this->GetDlgItem(IDC_CHECK_GLOBAL
)->EnableWindow(TRUE
);
117 this->GetDlgItem(IDC_EDITLOCALGITCONFIG
)->EnableWindow(TRUE
);
122 this->GetDlgItem(IDC_CHECK_GLOBAL
)->EnableWindow(FALSE
);
123 this->GetDlgItem(IDC_EDITLOCALGITCONFIG
)->EnableWindow(FALSE
);
127 this->GetDlgItem(IDC_EDITLOCALGITCONFIG
)->SetWindowText(CString(MAKEINTRESOURCE(IDS_PROC_GITCONFIG_EDITLOCALGONCFIG
)));
129 if (!CAppUtils::IsAdminLogin())
131 ((CButton
*)this->GetDlgItem(IDC_EDITSYSTEMGITCONFIG
))->SetShield(TRUE
);
132 this->GetDlgItem(IDC_VIEWSYSTEMGITCONFIG
)->ShowWindow(SW_SHOW
);
135 if (PathIsDirectory(g_Git
.GetGitGlobalXDGConfigPath()))
136 this->GetDlgItem(IDC_EDITGLOBALXDGGITCONFIG
)->ShowWindow(SW_SHOW
);
138 this->UpdateData(FALSE
);
141 // CSettingGitConfig message handlers
143 void CSettingGitConfig::OnBnClickedCheckGlobal()
148 void CSettingGitConfig::OnEnChangeGitUsername()
150 m_ChangeMask
|= GIT_NAME
;
154 void CSettingGitConfig::OnEnChangeGitUseremail()
156 m_ChangeMask
|= GIT_EMAIL
;
160 void CSettingGitConfig::OnEnChangeGitUserSigningKey()
162 m_ChangeMask
|= GIT_SIGNINGKEY
;
166 BOOL
CSettingGitConfig::OnApply()
169 CONFIG_TYPE type
=CONFIG_LOCAL
;
170 this->UpdateData(FALSE
);
173 type
= CONFIG_GLOBAL
;
175 if(m_ChangeMask
&GIT_NAME
)
176 if (!Save(_T("user.name"), this->m_UserName
, type
))
179 if(m_ChangeMask
&GIT_EMAIL
)
180 if (!Save(_T("user.email"), this->m_UserEmail
,type
))
183 if(m_ChangeMask
&GIT_SIGNINGKEY
)
184 if (!Save(_T("user.signingkey"), this->m_UserSigningKey
, type
))
187 if(m_ChangeMask
&GIT_WARNNOSIGNEDOFFBY
)
188 if (!Save(_T("tgit.warnnosignedoffby"), this->m_bWarnNoSignedOffBy
? _T("true") : _T("false"), type
))
191 if(m_ChangeMask
&GIT_CRLF
)
192 if (!Save(_T("core.autocrlf"), this->m_bAutoCrlf
? _T("true") : _T("false"), type
))
195 if(m_ChangeMask
&GIT_SAFECRLF
)
198 this->m_cSafeCrLf
.GetWindowText(safecrlf
);
199 if (!Save(_T("core.safecrlf"), safecrlf
, type
))
205 return ISettingsPropPage::OnApply();
207 bool CSettingGitConfig::Save(CString key
, CString value
, CONFIG_TYPE type
)
210 if (g_Git
.SetConfigValue(key
, value
, type
, g_Git
.GetGitEncode(L
"i18n.commitencoding"), &g_Git
.m_CurrentDir
))
213 msg
.Format(IDS_PROC_SAVECONFIGFAILED
, key
, value
);
214 CMessageBox::Show(NULL
, msg
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
219 void CSettingGitConfig::OnBnClickedCheckWarnNoSignedOffBy()
221 m_ChangeMask
|= GIT_WARNNOSIGNEDOFFBY
;
224 void CSettingGitConfig::OnBnClickedCheckAutocrlf()
226 m_ChangeMask
|= GIT_CRLF
;
230 void CSettingGitConfig::OnCbnSelchangeSafeCrLf()
232 m_ChangeMask
|= GIT_SAFECRLF
;
236 void CSettingGitConfig::OnBnClickedEditglobalgitconfig()
238 // use alternative editor because of LineEndings
239 CAppUtils::LaunchAlternativeEditor(g_Git
.GetGitGlobalConfig());
242 void CSettingGitConfig::OnBnClickedEditglobalxdggitconfig()
244 // use alternative editor because of LineEndings
245 CAppUtils::LaunchAlternativeEditor(g_Git
.GetGitGlobalXDGConfig());
248 void CSettingGitConfig::OnBnClickedEditlocalgitconfig()
250 // use alternative editor because of LineEndings
251 CAppUtils::LaunchAlternativeEditor(g_Git
.GetGitLocalConfig());
254 void CSettingGitConfig::OnBnClickedEditsystemgitconfig()
256 CString filename
= g_Git
.GetGitSystemConfig();
257 if (filename
.IsEmpty())
259 CMessageBox::Show(NULL
, IDS_PROC_GITCONFIG_NOMSYSGIT
, IDS_APPNAME
, MB_ICONERROR
);
262 // use alternative editor because of LineEndings
263 CAppUtils::LaunchAlternativeEditor(filename
, true);
266 void CSettingGitConfig::OnBnClickedViewsystemgitconfig()
268 CString filename
= g_Git
.GetGitSystemConfig();
269 if (filename
.IsEmpty())
271 CMessageBox::Show(NULL
, IDS_PROC_GITCONFIG_NOMSYSGIT
, IDS_APPNAME
, MB_ICONERROR
);
274 // use alternative editor because of LineEndings
275 CAppUtils::LaunchAlternativeEditor(filename
);