OSDN Git Service

merge original branch.
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / Settings / SettingGitConfig.cpp
1 // SettingGitConfig.cpp : implementation file\r
2 //\r
3 \r
4 #include "stdafx.h"\r
5 #include "TortoiseProc.h"\r
6 #include "SettingGitConfig.h"\r
7 #include "Git.h"\r
8 #include "Settings.h"\r
9 #include "GitAdminDir.h"\r
10 #include "MessageBox.h"\r
11 #include "ProjectProperties.h"\r
12 // CSettingGitConfig dialog\r
13 \r
14 IMPLEMENT_DYNAMIC(CSettingGitConfig, ISettingsPropPage)\r
15 \r
16 CSettingGitConfig::CSettingGitConfig()\r
17         : ISettingsPropPage(CSettingGitConfig::IDD)\r
18     , m_UserName(_T(""))\r
19     , m_UserEmail(_T(""))\r
20     , m_bGlobal(FALSE)\r
21         , m_bAutoCrlf(FALSE)\r
22         , m_bSafeCrLf(FALSE)\r
23 {\r
24 \r
25 }\r
26 \r
27 CSettingGitConfig::~CSettingGitConfig()\r
28 {\r
29 }\r
30 \r
31 void CSettingGitConfig::DoDataExchange(CDataExchange* pDX)\r
32 {\r
33         CPropertyPage::DoDataExchange(pDX);\r
34         DDX_Text(pDX, IDC_GIT_USERNAME, m_UserName);\r
35         DDX_Text(pDX, IDC_GIT_USEREMAIL, m_UserEmail);\r
36         DDX_Check(pDX, IDC_CHECK_GLOBAL, m_bGlobal);\r
37         DDX_Check(pDX, IDC_CHECK_AUTOCRLF, m_bAutoCrlf);\r
38         DDX_Check(pDX, IDC_CHECK_SAFECRLF, m_bSafeCrLf);\r
39 }\r
40 \r
41 \r
42 BEGIN_MESSAGE_MAP(CSettingGitConfig, CPropertyPage)\r
43     ON_BN_CLICKED(IDC_CHECK_GLOBAL, &CSettingGitConfig::OnBnClickedCheckGlobal)\r
44     ON_EN_CHANGE(IDC_GIT_USERNAME, &CSettingGitConfig::OnEnChangeGitUsername)\r
45     ON_EN_CHANGE(IDC_GIT_USEREMAIL, &CSettingGitConfig::OnEnChangeGitUseremail)\r
46         ON_BN_CLICKED(IDC_CHECK_AUTOCRLF, &CSettingGitConfig::OnBnClickedCheckAutocrlf)\r
47         ON_BN_CLICKED(IDC_CHECK_SAFECRLF, &CSettingGitConfig::OnBnClickedCheckSafecrlf)\r
48 END_MESSAGE_MAP()\r
49 \r
50 BOOL CSettingGitConfig::OnInitDialog()\r
51 {\r
52         ISettingsPropPage::OnInitDialog();\r
53 \r
54         m_UserName=g_Git.GetUserName();\r
55         m_UserEmail=g_Git.GetUserEmail();\r
56 \r
57         ProjectProperties::GetBOOLProps(this->m_bAutoCrlf,_T("core.autocrlf"));\r
58         ProjectProperties::GetBOOLProps(this->m_bSafeCrLf, _T("core.safecrlf"));\r
59 \r
60         CString str=((CSettings*)GetParent())->m_CmdPath.GetWinPath();\r
61         CString proj;\r
62         if(     g_GitAdminDir.HasAdminDir(str,&proj) )\r
63         {\r
64                 this->SetWindowText(CString(_T("Config - "))+proj);\r
65                 this->GetDlgItem(IDC_CHECK_GLOBAL)->EnableWindow(TRUE);\r
66         }\r
67         else\r
68         {\r
69                 m_bGlobal = TRUE;\r
70                 this->GetDlgItem(IDC_CHECK_GLOBAL)->EnableWindow(FALSE);\r
71         }\r
72         \r
73         this->UpdateData(FALSE);\r
74         return TRUE;\r
75 }\r
76 // CSettingGitConfig message handlers\r
77 \r
78 void CSettingGitConfig::OnBnClickedCheckGlobal()\r
79 {\r
80     // TODO: Add your control notification handler code here\r
81     SetModified();\r
82 }\r
83 \r
84 void CSettingGitConfig::OnEnChangeGitUsername()\r
85 {\r
86     // TODO:  If this is a RICHEDIT control, the control will not\r
87     // send this notification unless you override the ISettingsPropPage::OnInitDialog()\r
88     // function and call CRichEditCtrl().SetEventMask()\r
89     // with the ENM_CHANGE flag ORed into the mask.\r
90 \r
91     // TODO:  Add your control notification handler code here\r
92     SetModified();\r
93 }\r
94 \r
95 void CSettingGitConfig::OnEnChangeGitUseremail()\r
96 {\r
97     // TODO:  If this is a RICHEDIT control, the control will not\r
98     // send this notification unless you override the ISettingsPropPage::OnInitDialog()\r
99     // function and call CRichEditCtrl().SetEventMask()\r
100     // with the ENM_CHANGE flag ORed into the mask.\r
101 \r
102     // TODO:  Add your control notification handler code here\r
103     SetModified();\r
104 }\r
105 \r
106 BOOL CSettingGitConfig::OnApply()\r
107 {\r
108     CString cmd, out,global;\r
109     this->UpdateData(FALSE);\r
110         \r
111         if(this->m_bGlobal)\r
112                 global = _T(" --global ");\r
113 \r
114     cmd.Format(_T("git.exe config %s user.name \"%s\""),global,this->m_UserName);\r
115         if(g_Git.Run(cmd,&out,CP_ACP))\r
116         {\r
117                 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);\r
118                 return FALSE;\r
119         }\r
120         out.Empty();\r
121     cmd.Format(_T("git.exe config %s user.email \"%s\""),global,this->m_UserEmail);\r
122         if(g_Git.Run(cmd,&out,CP_ACP))\r
123         {\r
124                 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);\r
125                 return FALSE;\r
126         }\r
127 \r
128         out.Empty();\r
129         cmd.Format(_T("git.exe config %s core.autocrlf \"%s\""),global,this->m_bAutoCrlf?_T("true"):_T("false"));\r
130         if(g_Git.Run(cmd,&out,CP_ACP))\r
131         {\r
132                 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);\r
133                 return FALSE;\r
134         }\r
135 \r
136         out.Empty();\r
137         cmd.Format(_T("git.exe config %s core.safecrlf \"%s\""),global,this->m_bSafeCrLf?_T("true"):_T("false"));\r
138         if(g_Git.Run(cmd,&out,CP_ACP))\r
139         {\r
140                 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);\r
141                 return FALSE;\r
142         }\r
143     SetModified(FALSE);\r
144         return ISettingsPropPage::OnApply();\r
145 }\r
146 void CSettingGitConfig::OnBnClickedCheckAutocrlf()\r
147 {\r
148         // TODO: Add your control notification handler code here\r
149         SetModified();\r
150 }\r
151 \r
152 void CSettingGitConfig::OnBnClickedCheckSafecrlf()\r
153 {\r
154         // TODO: Add your control notification handler code here\r
155         SetModified();\r
156 }\r