some spaces-tabs code cleanup
[TortoiseGit.git] / src / TortoiseProc / Settings / SettingGitConfig.cpp
blobb781e659f24f105a660585e6a01be66d1765c8e2
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2011 - 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
22 #include "stdafx.h"
23 #include "TortoiseProc.h"
24 #include "SettingGitConfig.h"
25 #include "Git.h"
26 #include "Settings.h"
27 #include "GitAdminDir.h"
28 #include "MessageBox.h"
29 #include "ProjectProperties.h"
30 #include "AppUtils.h"
31 #include "PathUtils.h"
32 // CSettingGitConfig dialog
34 IMPLEMENT_DYNAMIC(CSettingGitConfig, ISettingsPropPage)
36 CSettingGitConfig::CSettingGitConfig()
37 : ISettingsPropPage(CSettingGitConfig::IDD)
38 , m_UserName(_T(""))
39 , m_UserEmail(_T(""))
40 , m_UserSigningKey(_T(""))
41 , m_bGlobal(FALSE)
42 , m_bAutoCrlf(FALSE)
43 , m_bSafeCrLf(FALSE)
44 , m_bWarnNoSignedOffBy(FALSE)
46 m_ChangeMask=0;
49 CSettingGitConfig::~CSettingGitConfig()
53 void CSettingGitConfig::DoDataExchange(CDataExchange* pDX)
55 CPropertyPage::DoDataExchange(pDX);
56 DDX_Text(pDX, IDC_GIT_USERNAME, m_UserName);
57 DDX_Text(pDX, IDC_GIT_USEREMAIL, m_UserEmail);
58 DDX_Text(pDX, IDC_GIT_USERESINGNINGKEY, m_UserSigningKey);
59 DDX_Check(pDX, IDC_CHECK_GLOBAL, m_bGlobal);
60 DDX_Check(pDX, IDC_CHECK_AUTOCRLF, m_bAutoCrlf);
61 DDX_Check(pDX, IDC_CHECK_SAFECRLF, m_bSafeCrLf);
62 DDX_Check(pDX, IDC_CHECK_WARN_NO_SIGNED_OFF_BY, m_bWarnNoSignedOffBy);
65 BEGIN_MESSAGE_MAP(CSettingGitConfig, CPropertyPage)
66 ON_BN_CLICKED(IDC_CHECK_GLOBAL, &CSettingGitConfig::OnBnClickedCheckGlobal)
67 ON_EN_CHANGE(IDC_GIT_USERNAME, &CSettingGitConfig::OnEnChangeGitUsername)
68 ON_EN_CHANGE(IDC_GIT_USEREMAIL, &CSettingGitConfig::OnEnChangeGitUseremail)
69 ON_EN_CHANGE(IDC_GIT_USERESINGNINGKEY, &CSettingGitConfig::OnEnChangeGitUserSigningKey)
70 ON_BN_CLICKED(IDC_CHECK_AUTOCRLF, &CSettingGitConfig::OnBnClickedCheckAutocrlf)
71 ON_BN_CLICKED(IDC_CHECK_SAFECRLF, &CSettingGitConfig::OnBnClickedCheckSafecrlf)
72 ON_BN_CLICKED(IDC_EDITGLOBALGITCONFIG, &CSettingGitConfig::OnBnClickedEditglobalgitconfig)
73 ON_BN_CLICKED(IDC_EDITLOCALGITCONFIG, &CSettingGitConfig::OnBnClickedEditlocalgitconfig)
74 ON_BN_CLICKED(IDC_CHECK_WARN_NO_SIGNED_OFF_BY, &CSettingGitConfig::OnBnClickedCheckWarnNoSignedOffBy)
75 END_MESSAGE_MAP()
77 BOOL CSettingGitConfig::OnInitDialog()
79 ISettingsPropPage::OnInitDialog();
81 m_UserName = g_Git.GetUserName();
82 m_UserEmail = g_Git.GetUserEmail();
83 m_UserSigningKey = g_Git.GetConfigValue(_T("user.signingkey"));
85 ProjectProperties::GetBOOLProps(this->m_bAutoCrlf, _T("core.autocrlf"));
86 ProjectProperties::GetBOOLProps(this->m_bSafeCrLf, _T("core.safecrlf"));
87 ProjectProperties::GetBOOLProps(this->m_bWarnNoSignedOffBy, _T("tgit.warnnosignedoffby"));
89 CString str = ((CSettings*)GetParent())->m_CmdPath.GetWinPath();
90 CString proj;
91 if(g_GitAdminDir.HasAdminDir(str, &proj))
93 this->SetWindowText(_T("Config - ") + proj);
94 this->GetDlgItem(IDC_CHECK_GLOBAL)->EnableWindow(TRUE);
95 this->GetDlgItem(IDC_EDITLOCALGITCONFIG)->EnableWindow(TRUE);
97 else
99 m_bGlobal = TRUE;
100 this->GetDlgItem(IDC_CHECK_GLOBAL)->EnableWindow(FALSE);
101 this->GetDlgItem(IDC_EDITLOCALGITCONFIG)->EnableWindow(FALSE);
104 this->UpdateData(FALSE);
105 return TRUE;
107 // CSettingGitConfig message handlers
109 void CSettingGitConfig::OnBnClickedCheckGlobal()
111 SetModified();
114 void CSettingGitConfig::OnEnChangeGitUsername()
116 m_ChangeMask |= GIT_NAME;
117 SetModified();
120 void CSettingGitConfig::OnEnChangeGitUseremail()
122 m_ChangeMask |= GIT_EMAIL;
123 SetModified();
126 void CSettingGitConfig::OnEnChangeGitUserSigningKey()
128 m_ChangeMask |= GIT_SIGNINGKEY;
129 SetModified();
132 BOOL CSettingGitConfig::OnApply()
134 CString cmd, out;
135 CONFIG_TYPE type=CONFIG_LOCAL;
136 this->UpdateData(FALSE);
138 if(this->m_bGlobal)
139 type = CONFIG_GLOBAL;
141 if(m_ChangeMask&GIT_NAME)
142 if(g_Git.SetConfigValue(_T("user.name"), this->m_UserName,type, g_Git.GetGitEncode(L"i18n.commitencoding")))
144 CMessageBox::Show(NULL, _T("Fail to save user name"), _T("TortoiseGit"), MB_OK|MB_ICONERROR);
145 return FALSE;
148 if(m_ChangeMask&GIT_EMAIL)
149 if(g_Git.SetConfigValue(_T("user.email"), this->m_UserEmail,type, g_Git.GetGitEncode(L"i18n.commitencoding")))
151 CMessageBox::Show(NULL, _T("Fail to save user email"), _T("TortoiseGit"), MB_OK|MB_ICONERROR);
152 return FALSE;
155 if(m_ChangeMask&GIT_SIGNINGKEY)
156 if(g_Git.SetConfigValue(_T("user.signingkey"), this->m_UserSigningKey, type, g_Git.GetGitEncode(L"i18n.commitencoding")))
158 CMessageBox::Show(NULL,_T("Fail to save user signingkey"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
159 return FALSE;
162 if(m_ChangeMask&GIT_WARNNOSIGNEDOFFBY)
163 if(g_Git.SetConfigValue(_T("tgit.warnnosignedoffby"), this->m_bWarnNoSignedOffBy?_T("true"):_T("false"), type))
165 CMessageBox::Show(NULL, _T("Fail to save warnnosignedoffby"), _T("TortoiseGit"), MB_OK|MB_ICONERROR);
166 return FALSE;
169 if(m_ChangeMask&GIT_CRLF)
170 if(g_Git.SetConfigValue(_T("core.autocrlf"), this->m_bAutoCrlf?_T("true"):_T("false"), type))
172 CMessageBox::Show(NULL, _T("Fail to save autocrlf"), _T("TortoiseGit"), MB_OK|MB_ICONERROR);
173 return FALSE;
176 if(m_ChangeMask&GIT_SAFECRLF)
177 if(g_Git.SetConfigValue(_T("core.safecrlf"), this->m_bSafeCrLf?_T("true"):_T("false"), type))
179 CMessageBox::Show(NULL, _T("Fail to save safecrlf"), _T("TortoiseGit"), MB_OK|MB_ICONERROR);
180 return FALSE;
183 m_ChangeMask = 0;
184 SetModified(FALSE);
185 return ISettingsPropPage::OnApply();
187 void CSettingGitConfig::OnBnClickedCheckWarnNoSignedOffBy()
189 m_ChangeMask |= GIT_WARNNOSIGNEDOFFBY;
190 SetModified();
192 void CSettingGitConfig::OnBnClickedCheckAutocrlf()
194 m_ChangeMask |= GIT_CRLF;
195 SetModified();
198 void CSettingGitConfig::OnBnClickedCheckSafecrlf()
200 m_ChangeMask |= GIT_SAFECRLF;
201 SetModified();
204 void CSettingGitConfig::OnBnClickedEditglobalgitconfig()
206 TCHAR buf[MAX_PATH];
207 SHGetFolderPath(NULL, CSIDL_PROFILE, NULL, SHGFP_TYPE_CURRENT, buf);
208 CString path = buf;
209 path += _T("\\.gitconfig");
210 // use alternative editor because of LineEndings
211 CAppUtils::LaunchAlternativeEditor(path);
214 void CSettingGitConfig::OnBnClickedEditlocalgitconfig()
216 CString path = g_Git.m_CurrentDir;
217 path += _T("\\.git\\config");
218 // use alternative editor because of LineEndings
219 CAppUtils::LaunchAlternativeEditor(path);