1 // SettingGitConfig.cpp : implementation file
5 #include "TortoiseProc.h"
6 #include "SettingGitConfig.h"
9 #include "GitAdminDir.h"
10 #include "MessageBox.h"
11 #include "ProjectProperties.h"
13 #include "PathUtils.h"
14 // CSettingGitConfig dialog
16 IMPLEMENT_DYNAMIC(CSettingGitConfig
, ISettingsPropPage
)
18 CSettingGitConfig::CSettingGitConfig()
19 : ISettingsPropPage(CSettingGitConfig::IDD
)
29 CSettingGitConfig::~CSettingGitConfig()
33 void CSettingGitConfig::DoDataExchange(CDataExchange
* pDX
)
35 CPropertyPage::DoDataExchange(pDX
);
36 DDX_Text(pDX
, IDC_GIT_USERNAME
, m_UserName
);
37 DDX_Text(pDX
, IDC_GIT_USEREMAIL
, m_UserEmail
);
38 DDX_Check(pDX
, IDC_CHECK_GLOBAL
, m_bGlobal
);
39 DDX_Check(pDX
, IDC_CHECK_AUTOCRLF
, m_bAutoCrlf
);
40 DDX_Check(pDX
, IDC_CHECK_SAFECRLF
, m_bSafeCrLf
);
44 BEGIN_MESSAGE_MAP(CSettingGitConfig
, CPropertyPage
)
45 ON_BN_CLICKED(IDC_CHECK_GLOBAL
, &CSettingGitConfig::OnBnClickedCheckGlobal
)
46 ON_EN_CHANGE(IDC_GIT_USERNAME
, &CSettingGitConfig::OnEnChangeGitUsername
)
47 ON_EN_CHANGE(IDC_GIT_USEREMAIL
, &CSettingGitConfig::OnEnChangeGitUseremail
)
48 ON_BN_CLICKED(IDC_CHECK_AUTOCRLF
, &CSettingGitConfig::OnBnClickedCheckAutocrlf
)
49 ON_BN_CLICKED(IDC_CHECK_SAFECRLF
, &CSettingGitConfig::OnBnClickedCheckSafecrlf
)
50 ON_BN_CLICKED(IDC_EDITGLOBALGITCONFIG
, &CSettingGitConfig::OnBnClickedEditglobalgitconfig
)
51 ON_BN_CLICKED(IDC_EDITLOCALGITCONFIG
, &CSettingGitConfig::OnBnClickedEditlocalgitconfig
)
54 BOOL
CSettingGitConfig::OnInitDialog()
56 ISettingsPropPage::OnInitDialog();
58 m_UserName
=g_Git
.GetUserName();
59 m_UserEmail
=g_Git
.GetUserEmail();
61 ProjectProperties::GetBOOLProps(this->m_bAutoCrlf
,_T("core.autocrlf"));
62 ProjectProperties::GetBOOLProps(this->m_bSafeCrLf
, _T("core.safecrlf"));
64 CString str
=((CSettings
*)GetParent())->m_CmdPath
.GetWinPath();
66 if( g_GitAdminDir
.HasAdminDir(str
,&proj
) )
68 this->SetWindowText(CString(_T("Config - "))+proj
);
69 this->GetDlgItem(IDC_CHECK_GLOBAL
)->EnableWindow(TRUE
);
70 this->GetDlgItem(IDC_EDITLOCALGITCONFIG
)->EnableWindow(TRUE
);
75 this->GetDlgItem(IDC_CHECK_GLOBAL
)->EnableWindow(FALSE
);
76 this->GetDlgItem(IDC_EDITLOCALGITCONFIG
)->EnableWindow(FALSE
);
79 this->UpdateData(FALSE
);
82 // CSettingGitConfig message handlers
84 void CSettingGitConfig::OnBnClickedCheckGlobal()
89 void CSettingGitConfig::OnEnChangeGitUsername()
91 m_ChangeMask
|=GIT_NAME
;
95 void CSettingGitConfig::OnEnChangeGitUseremail()
97 m_ChangeMask
|=GIT_EMAIL
;
101 BOOL
CSettingGitConfig::OnApply()
104 CONFIG_TYPE type
=CONFIG_LOCAL
;
105 this->UpdateData(FALSE
);
108 type
= CONFIG_GLOBAL
;
110 if(m_ChangeMask
&GIT_NAME
)
111 if(g_Git
.SetConfigValue(_T("user.name"), this->m_UserName
,type
, g_Git
.GetGitEncode(L
"i18n.commitencoding")))
113 CMessageBox::Show(NULL
,_T("Fail to save user name"),_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
117 if(m_ChangeMask
&GIT_EMAIL
)
118 if(g_Git
.SetConfigValue(_T("user.email"), this->m_UserEmail
,type
, g_Git
.GetGitEncode(L
"i18n.commitencoding")))
120 CMessageBox::Show(NULL
,_T("Fail to save user email"),_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
124 if(m_ChangeMask
&GIT_CRLF
)
125 if(g_Git
.SetConfigValue(_T("core.autocrlf"), this->m_bAutoCrlf
?_T("true"):_T("false"),type
))
127 CMessageBox::Show(NULL
,_T("Fail to save autocrlf"),_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
131 if(m_ChangeMask
&GIT_SAFECRLF
)
132 if(g_Git
.SetConfigValue(_T("core.safecrlf"), this->m_bSafeCrLf
?_T("true"):_T("false"),type
))
134 CMessageBox::Show(NULL
,_T("Fail to save safecrlf"),_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
140 return ISettingsPropPage::OnApply();
142 void CSettingGitConfig::OnBnClickedCheckAutocrlf()
144 m_ChangeMask
|=GIT_CRLF
;
148 void CSettingGitConfig::OnBnClickedCheckSafecrlf()
150 m_ChangeMask
|=GIT_SAFECRLF
;
154 void CSettingGitConfig::OnBnClickedEditglobalgitconfig()
157 SHGetFolderPath(NULL
, CSIDL_PROFILE
, NULL
, SHGFP_TYPE_CURRENT
, buf
);
159 path
+= _T("\\.gitconfig");
160 // use alternative editor because of LineEndings
161 CAppUtils::LaunchAlternativeEditor(path
);
164 void CSettingGitConfig::OnBnClickedEditlocalgitconfig()
166 CString path
= g_Git
.m_CurrentDir
;
167 path
+= _T("\\.git\\config");
168 // use alternative editor because of LineEndings
169 CAppUtils::LaunchAlternativeEditor(path
);