1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2013 - 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"
29 // CSettingGitConfig dialog
31 IMPLEMENT_DYNAMIC(CSettingGitConfig
, ISettingsPropPage
)
33 CSettingGitConfig::CSettingGitConfig()
34 : ISettingsPropPage(CSettingGitConfig::IDD
)
37 , m_UserSigningKey(_T(""))
44 CSettingGitConfig::~CSettingGitConfig()
48 void CSettingGitConfig::DoDataExchange(CDataExchange
* pDX
)
50 CPropertyPage::DoDataExchange(pDX
);
51 DDX_Text(pDX
, IDC_GIT_USERNAME
, m_UserName
);
52 DDX_Text(pDX
, IDC_GIT_USEREMAIL
, m_UserEmail
);
53 DDX_Text(pDX
, IDC_GIT_USERESINGNINGKEY
, m_UserSigningKey
);
54 DDX_Check(pDX
, IDC_CHECK_AUTOCRLF
, m_bAutoCrlf
);
55 DDX_Check(pDX
, IDC_CHECK_QUOTEPATH
, m_bQuotePath
);
56 DDX_Control(pDX
, IDC_COMBO_SAFECRLF
, m_cSafeCrLf
);
60 BEGIN_MESSAGE_MAP(CSettingGitConfig
, CPropertyPage
)
61 ON_EN_CHANGE(IDC_GIT_USERNAME
, &CSettingGitConfig::OnChange
)
62 ON_EN_CHANGE(IDC_GIT_USEREMAIL
, &CSettingGitConfig::OnChange
)
63 ON_EN_CHANGE(IDC_GIT_USERESINGNINGKEY
, &CSettingGitConfig::OnChange
)
64 ON_BN_CLICKED(IDC_CHECK_AUTOCRLF
, &CSettingGitConfig::OnChange
)
65 ON_BN_CLICKED(IDC_CHECK_QUOTEPATH
, &CSettingGitConfig::OnChange
)
66 ON_CBN_SELCHANGE(IDC_COMBO_SAFECRLF
, &CSettingGitConfig::OnChange
)
67 ON_BN_CLICKED(IDC_EDITGLOBALGITCONFIG
, &CSettingGitConfig::OnBnClickedEditglobalgitconfig
)
68 ON_BN_CLICKED(IDC_EDITGLOBALXDGGITCONFIG
, &CSettingGitConfig::OnBnClickedEditglobalxdggitconfig
)
69 ON_BN_CLICKED(IDC_EDITLOCALGITCONFIG
, &CSettingGitConfig::OnBnClickedEditlocalgitconfig
)
70 ON_BN_CLICKED(IDC_EDITTGITCONFIG
, &CSettingGitConfig::OnBnClickedEdittgitconfig
)
71 ON_BN_CLICKED(IDC_EDITSYSTEMGITCONFIG
, &CSettingGitConfig::OnBnClickedEditsystemgitconfig
)
72 ON_BN_CLICKED(IDC_VIEWSYSTEMGITCONFIG
, &CSettingGitConfig::OnBnClickedViewsystemgitconfig
)
73 GITSETTINGS_RADIO_EVENT
76 BOOL
CSettingGitConfig::OnInitDialog()
78 ISettingsPropPage::OnInitDialog();
80 m_cSafeCrLf
.AddString(_T(""));
81 m_cSafeCrLf
.AddString(_T("false"));
82 m_cSafeCrLf
.AddString(_T("true"));
83 m_cSafeCrLf
.AddString(_T("warn"));
85 m_tooltips
.Create(this);
87 InitGitSettings(this, false, &m_tooltips
);
89 if (!m_bGlobal
|| m_bIsBareRepo
)
90 this->GetDlgItem(IDC_EDITLOCALGITCONFIG
)->EnableWindow(TRUE
);
92 this->GetDlgItem(IDC_EDITLOCALGITCONFIG
)->EnableWindow(FALSE
);
96 this->GetDlgItem(IDC_EDITLOCALGITCONFIG
)->SetWindowText(CString(MAKEINTRESOURCE(IDS_PROC_GITCONFIG_EDITLOCALGONCFIG
)));
97 this->GetDlgItem(IDC_EDITTGITCONFIG
)->SetWindowText(CString(MAKEINTRESOURCE(IDS_PROC_GITCONFIG_VIEWTGITCONFIG
)));
100 if (!CAppUtils::IsAdminLogin())
102 ((CButton
*)this->GetDlgItem(IDC_EDITSYSTEMGITCONFIG
))->SetShield(TRUE
);
103 this->GetDlgItem(IDC_VIEWSYSTEMGITCONFIG
)->ShowWindow(SW_SHOW
);
106 if (PathIsDirectory(g_Git
.GetGitGlobalXDGConfigPath()))
107 this->GetDlgItem(IDC_EDITGLOBALXDGGITCONFIG
)->ShowWindow(SW_SHOW
);
109 this->UpdateData(FALSE
);
112 // CSettingGitConfig message handlers
114 void CSettingGitConfig::LoadDataImpl(git_config
* config
)
116 // special handling for UserName and UserEmail, because these can also be defined as environment variables for effective settings
117 if (m_iConfigSource
== 0)
119 m_UserName
= g_Git
.GetUserName();
120 m_UserEmail
= g_Git
.GetUserEmail();
124 GetConfigValue(config
, _T("user.name"), m_UserName
);
125 GetConfigValue(config
, _T("user.email"), m_UserEmail
);
127 GetConfigValue(config
, _T("user.signingkey"), m_UserSigningKey
);
129 if (git_config_get_bool(&m_bAutoCrlf
, config
, "core.autocrlf") == GIT_ENOTFOUND
)
130 m_bAutoCrlf
= BST_INDETERMINATE
;
132 if (git_config_get_bool(&m_bQuotePath
, config
, "core.quotepath") == GIT_ENOTFOUND
)
133 m_bQuotePath
= BST_INDETERMINATE
;
135 BOOL bSafeCrLf
= FALSE
;
136 if (git_config_get_bool(&bSafeCrLf
, config
, "core.safecrlf") == GIT_ENOTFOUND
)
137 m_cSafeCrLf
.SetCurSel(0);
139 m_cSafeCrLf
.SetCurSel(2);
143 GetConfigValue(config
, _T("core.safecrlf"), sSafeCrLf
);
144 sSafeCrLf
= sSafeCrLf
.MakeLower().Trim();
145 if (sSafeCrLf
== _T("warn"))
146 m_cSafeCrLf
.SetCurSel(3);
148 m_cSafeCrLf
.SetCurSel(1);
156 void CSettingGitConfig::EnDisableControls()
158 GetDlgItem(IDC_GIT_USERNAME
)->SendMessage(EM_SETREADONLY
, m_iConfigSource
== 0, 0);
159 GetDlgItem(IDC_GIT_USEREMAIL
)->SendMessage(EM_SETREADONLY
, m_iConfigSource
== 0, 0);
160 GetDlgItem(IDC_GIT_USERESINGNINGKEY
)->SendMessage(EM_SETREADONLY
, m_iConfigSource
== 0, 0);
161 GetDlgItem(IDC_CHECK_AUTOCRLF
)->EnableWindow(m_iConfigSource
!= 0);
162 GetDlgItem(IDC_CHECK_QUOTEPATH
)->EnableWindow(m_iConfigSource
!= 0);
163 GetDlgItem(IDC_COMBO_SAFECRLF
)->EnableWindow(m_iConfigSource
!= 0);
164 GetDlgItem(IDC_COMBO_SETTINGS_SAFETO
)->EnableWindow(m_iConfigSource
!= 0);
167 void CSettingGitConfig::OnChange()
173 BOOL
CSettingGitConfig::SafeDataImpl(git_config
* config
)
175 if (!Save(config
, _T("user.name"), this->m_UserName
))
178 if (!Save(config
, _T("user.email"), this->m_UserEmail
))
181 if (!Save(config
, _T("user.signingkey"), this->m_UserSigningKey
, true))
184 if (!Save(config
, _T("core.quotepath"), m_bQuotePath
== BST_INDETERMINATE
? _T("") : m_bQuotePath
? _T("true") : _T("false")))
187 if (!Save(config
, _T("core.autocrlf"), m_bAutoCrlf
== BST_INDETERMINATE
? _T("") : m_bAutoCrlf
? _T("true") : _T("false")))
192 this->m_cSafeCrLf
.GetWindowText(safecrlf
);
193 if (!Save(config
, _T("core.safecrlf"), safecrlf
))
200 BOOL
CSettingGitConfig::PreTranslateMessage(MSG
* pMsg
)
202 m_tooltips
.RelayEvent(pMsg
);
203 return ISettingsPropPage::PreTranslateMessage(pMsg
);
206 BOOL
CSettingGitConfig::OnApply()
215 return ISettingsPropPage::OnApply();
218 void CSettingGitConfig::OnBnClickedEditglobalgitconfig()
220 // use alternative editor because of LineEndings
221 CAppUtils::LaunchAlternativeEditor(g_Git
.GetGitGlobalConfig());
224 void CSettingGitConfig::OnBnClickedEditglobalxdggitconfig()
226 // use alternative editor because of LineEndings
227 CAppUtils::LaunchAlternativeEditor(g_Git
.GetGitGlobalXDGConfig());
230 void CSettingGitConfig::OnBnClickedEditlocalgitconfig()
232 // use alternative editor because of LineEndings
233 CAppUtils::LaunchAlternativeEditor(g_Git
.GetGitLocalConfig());
236 void CSettingGitConfig::OnBnClickedEdittgitconfig()
238 // use alternative editor because of LineEndings
239 if (g_GitAdminDir
.IsBareRepo(g_Git
.m_CurrentDir
))
241 CString tmpFile
= GetTempFile();
242 CTGitPath
path(_T(".tgitconfig"));
243 if (g_Git
.GetOneFile(_T("HEAD"), path
, tmpFile
) == 0)
245 CAppUtils::LaunchAlternativeEditor(tmpFile
);
250 CAppUtils::LaunchAlternativeEditor(g_Git
.m_CurrentDir
+ _T("\\.tgitconfig"));
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
);