OSDN Git Service

Add "remote update" command at Sync Dialog
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / SyncDlg.cpp
1 // TortoiseGit - a Windows shell extension for easy version control\r
2 \r
3 // Copyright (C) 2008-2009 - TortoiseGit\r
4 \r
5 // This program is free software; you can redistribute it and/or\r
6 // modify it under the terms of the GNU General Public License\r
7 // as published by the Free Software Foundation; either version 2\r
8 // of the License, or (at your option) any later version.\r
9 \r
10 // This program is distributed in the hope that it will be useful,\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13 // GNU General Public License for more details.\r
14 \r
15 // You should have received a copy of the GNU General Public License\r
16 // along with this program; if not, write to the Free Software Foundation,\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\r
18 //\r
19 \r
20 // SyncDlg.cpp : implementation file\r
21 //\r
22 \r
23 #include "stdafx.h"\r
24 #include "TortoiseProc.h"\r
25 #include "SyncDlg.h"\r
26 #include "progressdlg.h"\r
27 #include "MessageBox.h"\r
28 #include "ImportPatchDlg.h"\r
29 #include "PathUtils.h"\r
30 #include "RebaseDlg.h"\r
31 \r
32 // CSyncDlg dialog\r
33 \r
34 IMPLEMENT_DYNAMIC(CSyncDlg, CResizableStandAloneDialog)\r
35 \r
36 CSyncDlg::CSyncDlg(CWnd* pParent /*=NULL*/)\r
37         : CResizableStandAloneDialog(CSyncDlg::IDD, pParent)\r
38 {\r
39         m_pTooltip=&this->m_tooltips;\r
40         m_bInited=false;\r
41         m_CmdOutCurrentPos=0;\r
42         m_bAutoLoadPuttyKey = CAppUtils::IsSSHPutty();\r
43 }\r
44 \r
45 CSyncDlg::~CSyncDlg()\r
46 {\r
47 }\r
48 \r
49 void CSyncDlg::DoDataExchange(CDataExchange* pDX)\r
50 {\r
51         CDialog::DoDataExchange(pDX);\r
52         DDX_Check(pDX, IDC_CHECK_PUTTY_KEY, m_bAutoLoadPuttyKey);\r
53         DDX_Check(pDX, IDC_CHECK_FORCE,m_bForce);\r
54         DDX_Control(pDX, IDC_COMBOBOXEX_URL, m_ctrlURL);\r
55         DDX_Control(pDX, IDC_BUTTON_TABCTRL, m_ctrlDumyButton);\r
56         DDX_Control(pDX, IDC_BUTTON_PULL, m_ctrlPull);\r
57         DDX_Control(pDX, IDC_BUTTON_PUSH, m_ctrlPush);\r
58         DDX_Control(pDX, IDC_STATIC_STATUS, m_ctrlStatus);\r
59         DDX_Control(pDX, IDC_PROGRESS_SYNC, m_ctrlProgress);\r
60         DDX_Control(pDX, IDC_ANIMATE_SYNC, m_ctrlAnimate);\r
61         DDX_Control(pDX, IDC_BUTTON_SUBMODULE,m_ctrlSubmodule);\r
62         BRANCH_COMBOX_DDX;\r
63 }\r
64 \r
65 \r
66 BEGIN_MESSAGE_MAP(CSyncDlg, CResizableStandAloneDialog)\r
67         ON_BN_CLICKED(IDC_BUTTON_PULL, &CSyncDlg::OnBnClickedButtonPull)\r
68         ON_BN_CLICKED(IDC_BUTTON_PUSH, &CSyncDlg::OnBnClickedButtonPush)\r
69         ON_BN_CLICKED(IDC_BUTTON_APPLY, &CSyncDlg::OnBnClickedButtonApply)\r
70         ON_BN_CLICKED(IDC_BUTTON_EMAIL, &CSyncDlg::OnBnClickedButtonEmail)\r
71         ON_BN_CLICKED(IDC_BUTTON_MANAGE, &CSyncDlg::OnBnClickedButtonManage)\r
72         BRANCH_COMBOX_EVENT\r
73         ON_NOTIFY(CBEN_ENDEDIT, IDC_COMBOBOXEX_URL, &CSyncDlg::OnCbenEndeditComboboxexUrl)\r
74         ON_CBN_EDITCHANGE(IDC_COMBOBOXEX_URL, &CSyncDlg::OnCbnEditchangeComboboxexUrl)\r
75         ON_MESSAGE(MSG_PROGRESSDLG_UPDATE_UI, OnProgressUpdateUI)\r
76         ON_BN_CLICKED(IDC_BUTTON_COMMIT, &CSyncDlg::OnBnClickedButtonCommit)\r
77         ON_BN_CLICKED(IDC_BUTTON_SUBMODULE, &CSyncDlg::OnBnClickedButtonSubmodule)\r
78 END_MESSAGE_MAP()\r
79 \r
80 \r
81 void CSyncDlg::EnableControlButton(bool bEnabled)\r
82 {\r
83         GetDlgItem(IDC_BUTTON_PULL)->EnableWindow(bEnabled);\r
84         GetDlgItem(IDC_BUTTON_PUSH)->EnableWindow(bEnabled);\r
85         GetDlgItem(IDC_BUTTON_APPLY)->EnableWindow(bEnabled);\r
86         GetDlgItem(IDC_BUTTON_EMAIL)->EnableWindow(bEnabled);\r
87         GetDlgItem(IDOK)->EnableWindow(bEnabled);\r
88         GetDlgItem(IDC_BUTTON_SUBMODULE)->EnableWindow(bEnabled);\r
89 }\r
90 // CSyncDlg message handlers\r
91 \r
92 void CSyncDlg::OnBnClickedButtonPull()\r
93 {\r
94         // TODO: Add your control notification handler code here\r
95         int CurrentEntry;\r
96         CurrentEntry = this->m_ctrlPull.GetCurrentEntry();                   \r
97         this->m_regPullButton = CurrentEntry;\r
98 \r
99 \r
100         this->m_bAbort=false;\r
101         this->m_GitCmdList.clear();\r
102 \r
103         this->UpdateData();\r
104         UpdateCombox();\r
105 \r
106         m_oldHash = g_Git.GetHash(CString(_T("HEAD")));\r
107 \r
108         if( CurrentEntry == 0)\r
109         {\r
110                 if( g_Git.GetHash(this->m_strLocalBranch) != m_oldHash)\r
111                 {\r
112                         CMessageBox::Show(NULL,_T("Pull require local branch must be current branch"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);\r
113                         return;                                                 \r
114                 }\r
115         }\r
116 \r
117         if(this->m_strURL.IsEmpty())\r
118         {\r
119                 CMessageBox::Show(NULL,_T("URL can't Empty"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);\r
120                 return;\r
121         }\r
122 \r
123         if(this->m_bAutoLoadPuttyKey)\r
124         {\r
125                 CAppUtils::LaunchPAgent(NULL,&this->m_strURL);\r
126         }\r
127 \r
128         this->SwitchToRun();\r
129 \r
130         CString force;\r
131         if(this->m_bForce)\r
132                 force = _T(" --force ");\r
133 \r
134         CString cmd;\r
135 \r
136         ShowTab(IDC_CMD_LOG);\r
137 \r
138         this->m_ctrlTabCtrl.ShowTab(IDC_IN_LOGLIST-1,false);\r
139         this->m_ctrlTabCtrl.ShowTab(IDC_IN_CHANGELIST-1,false);\r
140         this->m_ctrlTabCtrl.ShowTab(IDC_IN_CONFLICT-1,false);\r
141 \r
142         this->GetDlgItem(IDC_BUTTON_COMMIT)->ShowWindow(SW_HIDE);\r
143 \r
144         ///Pull \r
145         if(CurrentEntry == 0) //Pull\r
146         {\r
147                 cmd.Format(_T("git.exe pull %s \"%s\" %s"),\r
148                                 force,\r
149                                 m_strURL,\r
150                                 this->m_strRemoteBranch);\r
151 \r
152                 m_CurrentCmd = GIT_COMMAND_PULL;\r
153                 m_GitCmdList.push_back(cmd);\r
154 \r
155                 m_pThread = AfxBeginThread(ProgressThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);\r
156                 if (m_pThread==NULL)\r
157                 {\r
158                 //              ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));\r
159                 }\r
160                 else\r
161                 {\r
162                         m_pThread->m_bAutoDelete = TRUE;\r
163                         m_pThread->ResumeThread();\r
164                 }\r
165 \r
166         }\r
167 \r
168         ///Fetch\r
169         if(CurrentEntry == 1 || CurrentEntry ==2 ) //Fetch\r
170         {\r
171                 cmd.Format(_T("git.exe fetch %s \"%s\" %s"),\r
172                                 force,\r
173                                 m_strURL,\r
174                                 this->m_strRemoteBranch);\r
175                 if(CurrentEntry == 1) \r
176                         m_CurrentCmd = GIT_COMMAND_FETCH;\r
177                 else\r
178                         m_CurrentCmd = GIT_COMMAND_FETCHANDREBASE;\r
179                 m_GitCmdList.push_back(cmd);\r
180 \r
181                 m_pThread = AfxBeginThread(ProgressThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);\r
182                 if (m_pThread==NULL)\r
183                 {\r
184                 //              ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));\r
185                 }\r
186                 else\r
187                 {\r
188                         m_pThread->m_bAutoDelete = TRUE;\r
189                         m_pThread->ResumeThread();\r
190                 }\r
191         }\r
192 \r
193         ///Remote Update\r
194         if(CurrentEntry == 3)\r
195         {\r
196                 m_CurrentCmd = GIT_COMMAND_REMOTE;\r
197                 cmd=_T("git.exe remote update");\r
198                 m_GitCmdList.push_back(cmd);\r
199 \r
200                 m_pThread = AfxBeginThread(ProgressThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);\r
201                 if (m_pThread==NULL)\r
202                 {\r
203                 //              ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));\r
204                 }\r
205                 else\r
206                 {\r
207                         m_pThread->m_bAutoDelete = TRUE;\r
208                         m_pThread->ResumeThread();\r
209                 }\r
210         }\r
211         \r
212 }\r
213 \r
214 void CSyncDlg::PullComplete()\r
215 {\r
216         EnableControlButton(true);\r
217         SwitchToInput();\r
218         this->FetchOutList(true);\r
219 \r
220         CString newhash;\r
221         newhash = g_Git.GetHash(CString(_T("HEAD")));\r
222 \r
223         \r
224 \r
225         if( this ->m_GitCmdStatus )\r
226         {\r
227                 CTGitPathList list;\r
228                 if(g_Git.ListConflictFile(list))\r
229                 {\r
230                         this->m_ctrlCmdOut.SetSel(-1,-1);\r
231                         this->m_ctrlCmdOut.ReplaceSel(_T("Get conflict files fail\n"));\r
232 \r
233                         this->ShowTab(IDC_CMD_LOG);\r
234                         return;\r
235                 }\r
236 \r
237                 if(list.GetCount()>0)\r
238                 {\r
239                         this->m_ConflictFileList.Clear();       \r
240                         CTGitPathList list;\r
241                         CTGitPath path;\r
242                         list.AddPath(path);\r
243 \r
244                         this->m_ConflictFileList.GetStatus(&list,true);\r
245                         this->m_ConflictFileList.Show(CTGitPath::LOGACTIONS_UNMERGED,\r
246                                                                           CTGitPath::LOGACTIONS_UNMERGED);\r
247                         \r
248                         this->ShowTab(IDC_IN_CONFLICT);\r
249 \r
250                         this->GetDlgItem(IDC_BUTTON_COMMIT)->ShowWindow(SW_NORMAL);\r
251                 }\r
252                 else\r
253                         this->ShowTab(IDC_CMD_LOG);\r
254 \r
255         }else\r
256         {\r
257                 if(newhash == this->m_oldHash)\r
258                 {\r
259                         this->m_ctrlTabCtrl.ShowTab(IDC_IN_CHANGELIST-1,false);\r
260                         this->m_InLogList.ShowText(_T("No commits get after pull"));\r
261                         this->m_ctrlTabCtrl.ShowTab(IDC_IN_LOGLIST-1,true);\r
262                 }\r
263                 else\r
264                 {\r
265                         this->m_ctrlTabCtrl.ShowTab(IDC_IN_CHANGELIST-1,true);\r
266                         this->m_ctrlTabCtrl.ShowTab(IDC_IN_LOGLIST-1,true);\r
267                         \r
268                         this->AddDiffFileList(&m_InChangeFileList,&m_arInChangeList,newhash,m_oldHash);\r
269                 \r
270                         m_InLogList.FillGitLog(NULL,CGit::      LOG_INFO_STAT| CGit::LOG_INFO_FILESTATE | CGit::LOG_INFO_SHOW_MERGEDFILE,\r
271                                 &this->m_oldHash,&newhash);\r
272                 }\r
273                 this->ShowTab(IDC_IN_LOGLIST);\r
274         }\r
275 }\r
276 \r
277 void CSyncDlg::FetchComplete()\r
278 {\r
279         EnableControlButton(true);\r
280         SwitchToInput();\r
281         this->FetchOutList(true);\r
282 \r
283         ShowTab(IDC_CMD_LOG);\r
284         if( (!this->m_GitCmdStatus) && this->m_CurrentCmd == GIT_COMMAND_FETCHANDREBASE)\r
285         {\r
286                 CRebaseDlg dlg;\r
287                 dlg.m_PostButtonTexts.Add(_T("Email &Patch..."));\r
288                 int response = dlg.DoModal();\r
289                 if(response == IDOK)\r
290                 {\r
291                         return ;\r
292                 }\r
293 \r
294                 if(response == IDC_REBASE_POST_BUTTON)\r
295                 {\r
296                         CString cmd,out;\r
297                         cmd.Format(_T("git.exe  format-patch -o \"%s\" %s..%s"),\r
298                                         g_Git.m_CurrentDir,\r
299                                         dlg.m_Upstream,dlg.m_Branch);\r
300                         if(g_Git.Run(cmd,&out,CP_ACP))\r
301                         {\r
302                                 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);\r
303                                 return ;\r
304                         }\r
305 \r
306                         CAppUtils::SendPatchMail(cmd,out);\r
307                 }\r
308         }\r
309 }\r
310 \r
311 void CSyncDlg::OnBnClickedButtonPush()\r
312 {\r
313         // TODO: Add your control notification handler code here\r
314         this->UpdateData();\r
315         UpdateCombox();\r
316 \r
317         if(this->m_strURL.IsEmpty())\r
318         {\r
319                 CMessageBox::Show(NULL,_T("URL can't Empty"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);\r
320                 return;\r
321         }\r
322 \r
323         this->m_regPushButton=this->m_ctrlPush.GetCurrentEntry();\r
324         this->SwitchToRun();\r
325         this->m_bAbort=false;\r
326         this->m_GitCmdList.clear();\r
327 \r
328         ShowTab(IDC_CMD_LOG);\r
329 \r
330         CString cmd;\r
331         CString tags;\r
332         CString force;\r
333         CString all;\r
334 \r
335 \r
336 \r
337         switch (m_ctrlPush.GetCurrentEntry())\r
338         {\r
339         case 1:\r
340                 tags = _T(" --tags ");\r
341                 break;\r
342         case 2:\r
343                 all = _T(" --all ");\r
344                 break;\r
345         }\r
346 \r
347         if(this->m_bForce)\r
348                 force = _T(" --force ");\r
349 \r
350         cmd.Format(_T("git.exe push %s %s %s \"%s\" %s"),\r
351                                 tags,force,all,\r
352                                 m_strURL,\r
353                                 m_strLocalBranch);\r
354 \r
355         if (!m_strRemoteBranch.IsEmpty())\r
356         {\r
357                 cmd += _T(":") + m_strRemoteBranch;\r
358         }\r
359         \r
360         m_GitCmdList.push_back(cmd);\r
361 \r
362         m_CurrentCmd = GIT_COMMAND_PUSH;\r
363 \r
364         if(this->m_bAutoLoadPuttyKey)\r
365         {\r
366                 CAppUtils::LaunchPAgent(NULL,&this->m_strURL);\r
367         }\r
368 \r
369         m_pThread = AfxBeginThread(ProgressThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);\r
370         if (m_pThread==NULL)\r
371         {\r
372 //              ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));\r
373         }\r
374         else\r
375         {\r
376                 m_pThread->m_bAutoDelete = TRUE;\r
377                 m_pThread->ResumeThread();\r
378         }\r
379         \r
380 }\r
381 \r
382 void CSyncDlg::OnBnClickedButtonApply()\r
383 {\r
384         // TODO: Add your control notification handler code here\r
385         CString oldhash;\r
386         oldhash=g_Git.GetHash(CString(_T("HEAD")));\r
387         \r
388         CImportPatchDlg dlg;\r
389         CString cmd,output;\r
390 \r
391         if(dlg.DoModal() == IDOK)\r
392         {\r
393                 int err=0;\r
394                 for(int i=0;i<dlg.m_PathList.GetCount();i++)\r
395                 {                       \r
396                         cmd.Format(_T("git.exe am \"%s\""),dlg.m_PathList[i].GetGitPathString());\r
397                         \r
398                         if(g_Git.Run(cmd,&output,CP_ACP))\r
399                         {\r
400                                 CMessageBox::Show(NULL,output,_T("TortoiseGit"),MB_OK);\r
401 \r
402                                 err=1;\r
403                                 break;\r
404                         }\r
405                         this->m_ctrlCmdOut.SetSel(-1,-1);\r
406                         this->m_ctrlCmdOut.ReplaceSel(cmd+_T("\n"));\r
407                         this->m_ctrlCmdOut.SetSel(-1,-1);\r
408                         this->m_ctrlCmdOut.ReplaceSel(output);\r
409                 }\r
410                 \r
411 \r
412                 CString newhash=g_Git.GetHash(CString(_T("HEAD")));             \r
413 \r
414                 this->m_InLogList.Clear();\r
415                 this->m_InChangeFileList.Clear();\r
416 \r
417                 if(newhash == oldhash)\r
418                 {\r
419                         this->m_ctrlTabCtrl.ShowTab(IDC_IN_CHANGELIST-1,false);\r
420                         this->m_InLogList.ShowText(_T("No commits get from patch"));\r
421                         this->m_ctrlTabCtrl.ShowTab(IDC_IN_LOGLIST-1,true);\r
422 \r
423                 }else\r
424                 {\r
425                         this->m_ctrlTabCtrl.ShowTab(IDC_IN_CHANGELIST-1,true);\r
426                         this->m_ctrlTabCtrl.ShowTab(IDC_IN_LOGLIST-1,true);\r
427                         \r
428                         this->AddDiffFileList(&m_InChangeFileList,&m_arInChangeList,newhash,oldhash);\r
429                         m_InLogList.FillGitLog(NULL,CGit::      LOG_INFO_STAT| CGit::LOG_INFO_FILESTATE | CGit::LOG_INFO_SHOW_MERGEDFILE,\r
430                                 &oldhash,&newhash);\r
431 \r
432                         this->FetchOutList(true);\r
433 \r
434                 }\r
435 \r
436                 this->m_ctrlTabCtrl.ShowTab(IDC_CMD_LOG-1,true);\r
437 \r
438                 if(err)\r
439                 {\r
440                         this->ShowTab(IDC_CMD_LOG);\r
441 \r
442                 }else\r
443                 {\r
444                         this->ShowTab(IDC_IN_LOGLIST);\r
445                 }\r
446         }\r
447 }\r
448 \r
449 void CSyncDlg::OnBnClickedButtonEmail()\r
450 {\r
451         // TODO: Add your control notification handler code here\r
452         CString cmd,out;\r
453         \r
454         this->m_strLocalBranch = this->m_ctrlLocalBranch.GetString();\r
455         this->m_ctrlRemoteBranch.GetWindowText(this->m_strRemoteBranch);\r
456         this->m_ctrlURL.GetWindowText(this->m_strURL);\r
457         m_strURL=m_strURL.Trim();\r
458         m_strRemoteBranch=m_strRemoteBranch.Trim();\r
459         \r
460         cmd.Format(_T("git.exe  format-patch -o \"%s\" %s..%s"),\r
461                                         g_Git.m_CurrentDir,\r
462                                         m_strURL+_T('/')+m_strRemoteBranch,m_strLocalBranch);\r
463         \r
464         if(g_Git.Run(cmd,&out,CP_ACP))\r
465         {\r
466                 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);\r
467                 return ;\r
468         }\r
469 \r
470         CAppUtils::SendPatchMail(cmd,out);      \r
471 \r
472 }\r
473 void CSyncDlg::ShowProgressCtrl(bool bShow)\r
474 {\r
475         int b=bShow?SW_NORMAL:SW_HIDE;\r
476         this->m_ctrlAnimate.ShowWindow(b);\r
477         this->m_ctrlProgress.ShowWindow(b);\r
478         this->m_ctrlAnimate.Open(IDR_DOWNLOAD);\r
479         if(b == SW_NORMAL)\r
480                 this->m_ctrlAnimate.Play(0,-1,-1);\r
481         else\r
482                 this->m_ctrlAnimate.Stop();\r
483 }\r
484 void CSyncDlg::ShowInputCtrl(bool bShow)\r
485 {\r
486         int b=bShow?SW_NORMAL:SW_HIDE;\r
487         this->m_ctrlURL.ShowWindow(b);\r
488         this->m_ctrlLocalBranch.ShowWindow(b);\r
489         this->m_ctrlRemoteBranch.ShowWindow(b);\r
490         this->GetDlgItem(IDC_BUTTON_LOCAL_BRANCH)->ShowWindow(b);\r
491         this->GetDlgItem(IDC_BUTTON_REMOTE_BRANCH)->ShowWindow(b);\r
492         this->GetDlgItem(IDC_STATIC_LOCAL_BRANCH)->ShowWindow(b);\r
493         this->GetDlgItem(IDC_STATIC_REMOTE_BRANCH)->ShowWindow(b);\r
494         this->GetDlgItem(IDC_BUTTON_MANAGE)->ShowWindow(b);\r
495         this->GetDlgItem(IDC_CHECK_PUTTY_KEY)->ShowWindow(b);\r
496         this->GetDlgItem(IDC_CHECK_FORCE)->ShowWindow(b);\r
497         this->GetDlgItem(IDC_STATIC_REMOTE_URL)->ShowWindow(b);\r
498         \r
499 }\r
500 BOOL CSyncDlg::OnInitDialog()\r
501 {\r
502         CResizableStandAloneDialog::OnInitDialog();\r
503 \r
504         /*\r
505         this->m_ctrlAnimate.ShowWindow(SW_NORMAL);\r
506         this->m_ctrlAnimate.Open(IDR_DOWNLOAD);\r
507         this->m_ctrlAnimate.Play(0,-1,-1);\r
508     */\r
509 \r
510         // ------------------ Create Tabctrl -----------\r
511         CWnd *pwnd=this->GetDlgItem(IDC_BUTTON_TABCTRL);\r
512         CRect rectDummy;\r
513         pwnd->GetWindowRect(&rectDummy);\r
514         this->ScreenToClient(rectDummy);\r
515 \r
516         if (!m_ctrlTabCtrl.Create(CMFCTabCtrl::STYLE_FLAT, rectDummy, this, IDC_SYNC_TAB))\r
517         {\r
518                 TRACE0("Failed to create output tab window\n");\r
519                 return FALSE;      // fail to create\r
520         }\r
521         m_ctrlTabCtrl.SetResizeMode(CMFCTabCtrl::RESIZE_NO);\r
522 \r
523         // -------------Create Command Log Ctrl ---------\r
524         DWORD dwStyle;\r
525         dwStyle= ES_MULTILINE | ES_READONLY | WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL | ES_AUTOVSCROLL |WS_VSCROLL  ;\r
526 \r
527         if( !m_ctrlCmdOut.Create(dwStyle,rectDummy,&m_ctrlTabCtrl,IDC_CMD_LOG))\r
528         {\r
529                 TRACE0("Failed to create Log commits window\n");\r
530                 return FALSE;      // fail to create\r
531         }\r
532 \r
533         m_ctrlTabCtrl.InsertTab(&m_ctrlCmdOut,_T("Log"),-1);\r
534         \r
535         //m_ctrlCmdOut.ReplaceSel(_T("Hello"));\r
536 \r
537         //----------  Create in coming list ctrl -----------\r
538         dwStyle =LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | LVS_OWNERDATA | WS_BORDER | WS_TABSTOP | WS_CHILD | WS_VISIBLE;;\r
539 \r
540         if( !m_InLogList.Create(dwStyle,rectDummy,&m_ctrlTabCtrl,IDC_IN_LOGLIST))\r
541         {\r
542                 TRACE0("Failed to create output commits window\n");\r
543                 return FALSE;      // fail to create\r
544 \r
545         }\r
546 \r
547         m_ctrlTabCtrl.InsertTab(&m_InLogList,_T("In Commits"),-1);\r
548 \r
549         m_InLogList.InsertGitColumn();\r
550 \r
551         //----------- Create In Change file list -----------\r
552         dwStyle = LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP |LVS_SINGLESEL |WS_CHILD | WS_VISIBLE;\r
553         \r
554         if( !m_InChangeFileList.Create(dwStyle,rectDummy,&m_ctrlTabCtrl,IDC_IN_CHANGELIST))\r
555         {\r
556                 TRACE0("Failed to create output change files window\n");\r
557                 return FALSE;      // fail to create\r
558         }\r
559         m_ctrlTabCtrl.InsertTab(&m_InChangeFileList,_T("In ChangeList"),-1);\r
560 \r
561         m_InChangeFileList.Init(SVNSLC_COLEXT | SVNSLC_COLSTATUS |SVNSLC_COLADD|SVNSLC_COLDEL , _T("OutSyncDlg"),\r
562                                     (CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDSVNLC_COMPARETWO)|\r
563                                                         CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDSVNLC_GNUDIFF2)),false);\r
564 \r
565 \r
566         //---------- Create Conflict List Ctrl -----------------\r
567         dwStyle = LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP |LVS_SINGLESEL |WS_CHILD | WS_VISIBLE;\r
568         \r
569         if( !m_ConflictFileList.Create(dwStyle,rectDummy,&m_ctrlTabCtrl,IDC_IN_CONFLICT))\r
570         {\r
571                 TRACE0("Failed to create output change files window\n");\r
572                 return FALSE;      // fail to create\r
573         }\r
574         m_ctrlTabCtrl.InsertTab(&m_ConflictFileList,_T("Conflict"),-1);\r
575 \r
576         m_ConflictFileList.Init(SVNSLC_COLEXT | SVNSLC_COLSTATUS |SVNSLC_COLADD|SVNSLC_COLDEL , _T("OutSyncDlg"),\r
577                                     (CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDSVNLC_COMPARETWO)|\r
578                                                         CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDSVNLC_GNUDIFF2)|\r
579                                                         SVNSLC_POPCONFLICT|SVNSLC_POPRESOLVE),false);\r
580 \r
581 \r
582         //----------  Create Commit Out List Ctrl---------------\r
583                         \r
584         dwStyle =LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | LVS_OWNERDATA | WS_BORDER | WS_TABSTOP | WS_CHILD | WS_VISIBLE;;\r
585 \r
586         if( !m_OutLogList.Create(dwStyle,rectDummy,&m_ctrlTabCtrl,IDC_OUT_LOGLIST))\r
587         {\r
588                 TRACE0("Failed to create output commits window\n");\r
589                 return FALSE;      // fail to create\r
590 \r
591         }\r
592 \r
593         m_ctrlTabCtrl.InsertTab(&m_OutLogList,_T("Out Commits"),-1);\r
594         \r
595 \r
596         m_OutLogList.InsertGitColumn();\r
597 \r
598         //------------- Create Change File List Control ----------------\r
599 \r
600         dwStyle = LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP |LVS_SINGLESEL |WS_CHILD | WS_VISIBLE;\r
601         \r
602         if( !m_OutChangeFileList.Create(dwStyle,rectDummy,&m_ctrlTabCtrl,IDC_OUT_CHANGELIST))\r
603         {\r
604                 TRACE0("Failed to create output change files window\n");\r
605                 return FALSE;      // fail to create\r
606         }\r
607         m_ctrlTabCtrl.InsertTab(&m_OutChangeFileList,_T("Out ChangeList"),-1);\r
608 \r
609         m_OutChangeFileList.Init(SVNSLC_COLEXT | SVNSLC_COLSTATUS |SVNSLC_COLADD|SVNSLC_COLDEL , _T("OutSyncDlg"),\r
610                                     (CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDSVNLC_COMPARETWO)|\r
611                                                         CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDSVNLC_GNUDIFF2)),false);\r
612 \r
613         this->m_tooltips.Create(this);\r
614 \r
615         AddAnchor(IDC_SYNC_TAB,TOP_LEFT,BOTTOM_RIGHT);\r
616 \r
617         AddAnchor(IDC_GROUP_INFO,TOP_LEFT,TOP_RIGHT);\r
618         AddAnchor(IDC_COMBOBOXEX_URL,TOP_LEFT,TOP_RIGHT);\r
619         AddAnchor(IDC_BUTTON_MANAGE,TOP_RIGHT);\r
620         AddAnchor(IDC_BUTTON_PULL,BOTTOM_LEFT);\r
621         AddAnchor(IDC_BUTTON_PUSH,BOTTOM_LEFT);\r
622         AddAnchor(IDC_BUTTON_SUBMODULE,BOTTOM_LEFT);\r
623         AddAnchor(IDC_BUTTON_APPLY,BOTTOM_RIGHT);\r
624         AddAnchor(IDC_BUTTON_EMAIL,BOTTOM_RIGHT);\r
625         AddAnchor(IDC_PROGRESS_SYNC,TOP_LEFT,TOP_RIGHT);\r
626         AddAnchor(IDOK,BOTTOM_RIGHT);\r
627         AddAnchor(IDHELP,BOTTOM_RIGHT);\r
628         AddAnchor(IDC_STATIC_STATUS,BOTTOM_LEFT);\r
629         AddAnchor(IDC_ANIMATE_SYNC,TOP_LEFT);\r
630         AddAnchor(IDC_BUTTON_COMMIT,BOTTOM_LEFT);\r
631 \r
632         BRANCH_COMBOX_ADD_ANCHOR();\r
633 \r
634         this->GetDlgItem(IDC_BUTTON_COMMIT)->ShowWindow(SW_HIDE);\r
635 \r
636         CString WorkingDir=g_Git.m_CurrentDir;\r
637         WorkingDir.Replace(_T(':'),_T('_'));\r
638         m_RegKeyRemoteBranch = CString(_T("Software\\TortoiseGit\\History\\SyncBranch\\"))+WorkingDir;\r
639 \r
640 \r
641         this->AddOthersToAnchor();\r
642         // TODO:  Add extra initialization here\r
643 \r
644         this->m_ctrlPush.AddEntry(CString(_T("Pus&h")));\r
645         this->m_ctrlPush.AddEntry(CString(_T("Push ta&gs")));\r
646         ///this->m_ctrlPush.AddEntry(CString(_T("Push All")));\r
647 \r
648         this->m_ctrlPull.AddEntry(CString(_T("&Pull")));\r
649         this->m_ctrlPull.AddEntry(CString(_T("Fetc&h")));\r
650         this->m_ctrlPull.AddEntry(CString(_T("Fetch&&Re&base")));\r
651         this->m_ctrlPull.AddEntry(CString(_T("Remote Update")));\r
652 \r
653         this->m_ctrlSubmodule.AddEntry(CString(_T("Submodule Update")));\r
654         this->m_ctrlSubmodule.AddEntry(CString(_T("Submodule Init")));\r
655         this->m_ctrlSubmodule.AddEntry(CString(_T("Submodule Sync")));\r
656         \r
657         WorkingDir.Replace(_T(':'),_T('_'));\r
658 \r
659         CString regkey ;\r
660         regkey.Format(_T("Software\\TortoiseGit\\TortoiseProc\\Sync\\%s"),WorkingDir);\r
661 \r
662         this->m_regPullButton = CRegDWORD(regkey+_T("\\Pull"),0);\r
663         this->m_regPushButton = CRegDWORD(regkey+_T("\\Push"),0);\r
664         this->m_regSubmoduleButton = CRegDWORD(regkey+_T("\\Submodule"));\r
665 \r
666         this->m_ctrlPull.SetCurrentEntry(this->m_regPullButton);\r
667         this->m_ctrlPush.SetCurrentEntry(this->m_regPushButton);\r
668         this->m_ctrlSubmodule.SetCurrentEntry(this->m_regSubmoduleButton);\r
669 \r
670         CString str;\r
671         this->GetWindowText(str);\r
672         str += _T(" - ") + g_Git.m_CurrentDir;\r
673         this->SetWindowText(str);\r
674 \r
675         EnableSaveRestore(_T("SyncDlg"));\r
676 \r
677         this->m_ctrlURL.LoadHistory(CString(_T("Software\\TortoiseGit\\History\\SyncURL\\"))+WorkingDir, _T("url"));\r
678 \r
679         STRING_VECTOR list;\r
680         \r
681         if(!g_Git.GetRemoteList(list))\r
682         {       \r
683                 for(unsigned int i=0;i<list.size();i++)\r
684                 {\r
685                         m_ctrlURL.AddString(list[i]);\r
686                 }\r
687         }       \r
688         m_ctrlURL.SetCurSel(0);\r
689         m_ctrlRemoteBranch.SetCurSel(0);\r
690         m_ctrlURL.SetURLHistory(true);\r
691         \r
692         this->LoadBranchInfo();\r
693 \r
694         this->m_bInited=true;\r
695         FetchOutList();\r
696         \r
697         m_ctrlTabCtrl.ShowTab(IDC_CMD_LOG-1,false);\r
698         m_ctrlTabCtrl.ShowTab(IDC_IN_LOGLIST-1,false);\r
699         m_ctrlTabCtrl.ShowTab(IDC_IN_CHANGELIST-1,false);\r
700         m_ctrlTabCtrl.ShowTab(IDC_IN_CONFLICT-1,false);\r
701                 \r
702         return TRUE;  // return TRUE unless you set the focus to a control\r
703         // EXCEPTION: OCX Property Pages should return FALSE\r
704 }\r
705 \r
706 void CSyncDlg::OnBnClickedButtonManage()\r
707 {\r
708         // TODO: Add your control notification handler code here\r
709         CAppUtils::LaunchRemoteSetting();\r
710 }\r
711 \r
712 BOOL CSyncDlg::PreTranslateMessage(MSG* pMsg)\r
713 {\r
714         // TODO: Add your specialized code here and/or call the base class\r
715         m_tooltips.RelayEvent(pMsg);\r
716         return __super::PreTranslateMessage(pMsg);\r
717 }\r
718 void CSyncDlg::FetchOutList(bool force)\r
719 {\r
720         if(!m_bInited)\r
721                 return;\r
722         m_OutChangeFileList.Clear();\r
723         this->m_OutLogList.Clear();\r
724 \r
725         CString remote;\r
726         this->m_ctrlURL.GetWindowText(remote);\r
727         CString remotebranch;\r
728         this->m_ctrlRemoteBranch.GetWindowText(remotebranch);\r
729         remotebranch=remote+_T("/")+remotebranch;\r
730 \r
731         if(IsURL())\r
732         {\r
733                 CString str;\r
734                 str=_T("Don't know what will push befause you enter URL");\r
735                 m_OutLogList.ShowText(str);\r
736                 this->m_ctrlTabCtrl.ShowTab(m_OutChangeFileList.GetDlgCtrlID()-1,FALSE);\r
737                 m_OutLocalBranch.Empty();\r
738                 m_OutRemoteBranch.Empty();\r
739 \r
740                 this->GetDlgItem(IDC_BUTTON_EMAIL)->EnableWindow(FALSE);\r
741                 return ;\r
742         \r
743         }else if(g_Git.GetHash(remotebranch).GetLength()<40)\r
744         {\r
745                 CString str;\r
746                 str.Format(_T("Don't know what will push befause unkown \"%s\""),remotebranch);\r
747                 m_OutLogList.ShowText(str);\r
748                 this->m_ctrlTabCtrl.ShowTab(m_OutChangeFileList.GetDlgCtrlID()-1,FALSE);\r
749                 m_OutLocalBranch.Empty();\r
750                 m_OutRemoteBranch.Empty();\r
751 \r
752                 this->GetDlgItem(IDC_BUTTON_EMAIL)->EnableWindow(FALSE);\r
753                 return ;\r
754         }\r
755         else\r
756         {\r
757                 CString localbranch;\r
758                 localbranch=this->m_ctrlLocalBranch.GetString();\r
759 \r
760                 if(localbranch != m_OutLocalBranch || m_OutRemoteBranch != remotebranch || force)\r
761                 {\r
762                         m_OutLogList.ClearText();\r
763                         m_OutLogList.FillGitLog(NULL,CGit::     LOG_INFO_STAT| CGit::LOG_INFO_FILESTATE | CGit::LOG_INFO_SHOW_MERGEDFILE,\r
764                                 &remotebranch,&localbranch);\r
765                         \r
766                         CString str;\r
767                         if(m_OutLogList.GetItemCount() == 0)\r
768                         {                       \r
769                                 str.Format(_T("No commits ahead \"%s\""),remotebranch);\r
770                                 m_OutLogList.ShowText(str);\r
771                                 this->m_ctrlStatus.SetWindowText(str);\r
772                                 this->m_ctrlTabCtrl.ShowTab(m_OutChangeFileList.GetDlgCtrlID()-1,FALSE);\r
773                                 this->GetDlgItem(IDC_BUTTON_EMAIL)->EnableWindow(FALSE);\r
774                         }\r
775                         else\r
776                         {\r
777                                 str.Format(_T("%d commits ahead \"%s\""),m_OutLogList.GetItemCount(),remotebranch);\r
778                                 this->m_ctrlStatus.SetWindowText(str);\r
779 \r
780                                 AddDiffFileList(&m_OutChangeFileList,&m_arOutChangeList,localbranch,remotebranch);\r
781                                 \r
782                                 this->m_ctrlTabCtrl.ShowTab(m_OutChangeFileList.GetDlgCtrlID()-1,TRUE);\r
783                                 this->GetDlgItem(IDC_BUTTON_EMAIL)->EnableWindow(TRUE);\r
784                         }\r
785                 }\r
786                 this->m_OutLocalBranch=localbranch;\r
787                 this->m_OutRemoteBranch=remotebranch;\r
788         }\r
789 \r
790 }\r
791 \r
792 bool CSyncDlg::IsURL()\r
793 {\r
794         CString str;\r
795         this->m_ctrlURL.GetWindowText(str);\r
796         if(str.Find(_T('\\'))>=0 || str.Find(_T('/'))>=0)\r
797                 return true;\r
798         else\r
799                 return false;\r
800 }\r
801 void CSyncDlg::OnCbenEndeditComboboxexUrl(NMHDR *pNMHDR, LRESULT *pResult)\r
802 {\r
803         // TODO: Add your control notification handler code here\r
804         *pResult = 0;\r
805 }\r
806 \r
807 void CSyncDlg::OnCbnEditchangeComboboxexUrl()\r
808 {\r
809         this->FetchOutList();\r
810         // TODO: Add your control notification handler code here\r
811 }\r
812 \r
813 UINT CSyncDlg::ProgressThread()\r
814 {\r
815         m_GitCmdStatus=CProgressDlg::RunCmdList(this,m_GitCmdList,true,NULL,&this->m_bAbort);\r
816         return 0;\r
817 }\r
818 \r
819 \r
820 LRESULT CSyncDlg::OnProgressUpdateUI(WPARAM wParam,LPARAM lParam)\r
821 {\r
822         if(wParam == MSG_PROGRESSDLG_START)\r
823         {\r
824                 m_ctrlAnimate.Play(0,-1,-1);\r
825                 this->m_ctrlProgress.SetPos(0);\r
826         }\r
827 \r
828         if(wParam == MSG_PROGRESSDLG_END || wParam == MSG_PROGRESSDLG_FAILED)\r
829         {\r
830                 //m_bDone = true;\r
831                 m_ctrlAnimate.Stop();\r
832                 m_ctrlProgress.SetPos(100);\r
833                 //this->DialogEnableWindow(IDOK,TRUE);\r
834 \r
835                 //if(wParam == MSG_PROGRESSDLG_END)\r
836                 if(this->m_CurrentCmd == GIT_COMMAND_PUSH )\r
837                 {\r
838                         EnableControlButton(true);\r
839                         SwitchToInput();\r
840                         this->FetchOutList(true);\r
841                 }\r
842                 if(this->m_CurrentCmd == GIT_COMMAND_PULL )\r
843                 {\r
844                         PullComplete();\r
845                 }\r
846                 if(this->m_CurrentCmd == GIT_COMMAND_FETCH || this->m_CurrentCmd == GIT_COMMAND_FETCHANDREBASE)\r
847                 {\r
848                         FetchComplete();\r
849                 }\r
850                 if(this->m_CurrentCmd == GIT_COMMAND_SUBMODULE)\r
851                 {\r
852                         //this->m_ctrlCmdOut.SetSel(-1,-1);\r
853                         //this->m_ctrlCmdOut.ReplaceSel(_T("Done\r\n"));\r
854                         //this->m_ctrlCmdOut.SetSel(-1,-1);\r
855                         EnableControlButton(true);\r
856                         SwitchToInput();\r
857                 }\r
858                 if(this->m_CurrentCmd == GIT_COMMAND_REMOTE)\r
859                 {\r
860                         this->FetchOutList(true);\r
861                         EnableControlButton(true);\r
862                         SwitchToInput();\r
863                 }\r
864         }\r
865 \r
866         if(lParam != 0)\r
867                 ParserCmdOutput((TCHAR)lParam);\r
868 \r
869         return 0;\r
870 }\r
871 \r
872 \r
873 void CSyncDlg::ParserCmdOutput(TCHAR ch)\r
874 {\r
875         CProgressDlg::ParserCmdOutput(m_ctrlCmdOut,m_ctrlProgress,m_LogText,ch);\r
876 }\r
877 void CSyncDlg::OnBnClickedButtonCommit()\r
878 {\r
879         // TODO: Add your control notification handler code here\r
880     CString proc=CPathUtils::GetAppDirectory();\r
881     proc += _T("TortoiseProc.exe /command:commit");\r
882     proc += _T(" /path:\"");\r
883     proc += g_Git.m_CurrentDir;\r
884     \r
885         CAppUtils::LaunchApplication(proc,IDS_ERROR_CANNON_FIND_TORTOISEPROC,false);\r
886 }\r
887 \r
888 void CSyncDlg::OnOK()\r
889 {\r
890         // TODO: Add your specialized code here and/or call the base class\r
891         UpdateCombox();\r
892         m_ctrlURL.SaveHistory();\r
893         SaveHistory();\r
894         __super::OnOK();\r
895 }\r
896 \r
897 void CSyncDlg::OnBnClickedButtonSubmodule()\r
898 {\r
899         // TODO: Add your control notification handler code here\r
900                 // TODO: Add your control notification handler code here\r
901         this->UpdateData();\r
902         UpdateCombox();\r
903 \r
904         this->m_regSubmoduleButton = this->m_ctrlSubmodule.GetCurrentEntry();\r
905 \r
906         this->SwitchToRun();\r
907         \r
908         this->m_bAbort=false;\r
909         this->m_GitCmdList.clear();\r
910 \r
911         ShowTab(IDC_CMD_LOG);\r
912 \r
913         CString cmd;\r
914 \r
915         switch (m_ctrlSubmodule.GetCurrentEntry())\r
916         {\r
917         case 0:\r
918                 cmd=_T("git.exe submodule update");\r
919                 break;\r
920         case 1:\r
921                 cmd=_T("git.exe submodule init");\r
922                 break;\r
923         case 2:\r
924                 cmd=_T("git.exe submodule sync");\r
925                 break;\r
926         }\r
927 \r
928         \r
929         m_GitCmdList.push_back(cmd);\r
930 \r
931         m_CurrentCmd = GIT_COMMAND_SUBMODULE;\r
932 \r
933         m_pThread = AfxBeginThread(ProgressThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);\r
934         if (m_pThread==NULL)\r
935         {\r
936 //              ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));\r
937         }\r
938         else\r
939         {\r
940                 m_pThread->m_bAutoDelete = TRUE;\r
941                 m_pThread->ResumeThread();\r
942         }\r
943 \r
944 }\r