OSDN Git Service

SyncDlg Show Conflict when pull
[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 // CSyncDlg dialog\r
31 \r
32 IMPLEMENT_DYNAMIC(CSyncDlg, CResizableStandAloneDialog)\r
33 \r
34 CSyncDlg::CSyncDlg(CWnd* pParent /*=NULL*/)\r
35         : CResizableStandAloneDialog(CSyncDlg::IDD, pParent)\r
36 {\r
37         m_pTooltip=&this->m_tooltips;\r
38         m_bInited=false;\r
39         m_CmdOutCurrentPos=0;\r
40         m_bAutoLoadPuttyKey = CAppUtils::IsSSHPutty();\r
41 }\r
42 \r
43 CSyncDlg::~CSyncDlg()\r
44 {\r
45 }\r
46 \r
47 void CSyncDlg::DoDataExchange(CDataExchange* pDX)\r
48 {\r
49         CDialog::DoDataExchange(pDX);\r
50         DDX_Check(pDX, IDC_CHECK_PUTTY_KEY, m_bAutoLoadPuttyKey);\r
51         DDX_Check(pDX, IDC_CHECK_FORCE,m_bForce);\r
52         DDX_Control(pDX, IDC_COMBOBOXEX_URL, m_ctrlURL);\r
53         DDX_Control(pDX, IDC_BUTTON_TABCTRL, m_ctrlDumyButton);\r
54         DDX_Control(pDX, IDC_BUTTON_PULL, m_ctrlPull);\r
55         DDX_Control(pDX, IDC_BUTTON_PUSH, m_ctrlPush);\r
56         DDX_Control(pDX, IDC_STATIC_STATUS, m_ctrlStatus);\r
57         DDX_Control(pDX, IDC_PROGRESS_SYNC, m_ctrlProgress);\r
58         DDX_Control(pDX, IDC_ANIMATE_SYNC, m_ctrlAnimate);\r
59 \r
60         BRANCH_COMBOX_DDX;\r
61 }\r
62 \r
63 \r
64 BEGIN_MESSAGE_MAP(CSyncDlg, CResizableStandAloneDialog)\r
65         ON_BN_CLICKED(IDC_BUTTON_PULL, &CSyncDlg::OnBnClickedButtonPull)\r
66         ON_BN_CLICKED(IDC_BUTTON_PUSH, &CSyncDlg::OnBnClickedButtonPush)\r
67         ON_BN_CLICKED(IDC_BUTTON_APPLY, &CSyncDlg::OnBnClickedButtonApply)\r
68         ON_BN_CLICKED(IDC_BUTTON_EMAIL, &CSyncDlg::OnBnClickedButtonEmail)\r
69         ON_BN_CLICKED(IDC_BUTTON_MANAGE, &CSyncDlg::OnBnClickedButtonManage)\r
70         BRANCH_COMBOX_EVENT\r
71         ON_NOTIFY(CBEN_ENDEDIT, IDC_COMBOBOXEX_URL, &CSyncDlg::OnCbenEndeditComboboxexUrl)\r
72         ON_CBN_EDITCHANGE(IDC_COMBOBOXEX_URL, &CSyncDlg::OnCbnEditchangeComboboxexUrl)\r
73         ON_MESSAGE(MSG_PROGRESSDLG_UPDATE_UI, OnProgressUpdateUI)\r
74         ON_BN_CLICKED(IDC_BUTTON_COMMIT, &CSyncDlg::OnBnClickedButtonCommit)\r
75 END_MESSAGE_MAP()\r
76 \r
77 \r
78 void CSyncDlg::EnableControlButton(bool bEnabled)\r
79 {\r
80         GetDlgItem(IDC_BUTTON_PULL)->EnableWindow(bEnabled);\r
81         GetDlgItem(IDC_BUTTON_PUSH)->EnableWindow(bEnabled);\r
82         GetDlgItem(IDC_BUTTON_APPLY)->EnableWindow(bEnabled);\r
83         GetDlgItem(IDC_BUTTON_EMAIL)->EnableWindow(bEnabled);\r
84         GetDlgItem(IDOK)->EnableWindow(bEnabled);\r
85 }\r
86 // CSyncDlg message handlers\r
87 \r
88 void CSyncDlg::OnBnClickedButtonPull()\r
89 {\r
90         // TODO: Add your control notification handler code here\r
91         int CurrentEntry;\r
92         CurrentEntry = this->m_ctrlPull.GetCurrentEntry();                   \r
93         this->m_regPullButton = CurrentEntry;\r
94 \r
95 \r
96         this->m_bAbort=false;\r
97         this->m_GitCmdList.clear();\r
98 \r
99         this->UpdateData();\r
100         UpateCombox();\r
101 \r
102         m_oldHash = g_Git.GetHash(CString(_T("HEAD")));\r
103 \r
104         if( CurrentEntry == 0)\r
105         {\r
106                 if( g_Git.GetHash(this->m_strLocalBranch) != m_oldHash)\r
107                 {\r
108                         CMessageBox::Show(NULL,_T("Pull require local branch must be current branch"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);\r
109                         return;                                                 \r
110                 }\r
111         }\r
112 \r
113         if(this->m_strURL.IsEmpty())\r
114         {\r
115                 CMessageBox::Show(NULL,_T("URL can't Empty"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);\r
116                 return;\r
117         }\r
118 \r
119         if(this->m_bAutoLoadPuttyKey)\r
120         {\r
121                 CAppUtils::LaunchPAgent(NULL,&this->m_strURL);\r
122         }\r
123 \r
124         this->SwitchToRun();\r
125 \r
126         CString force;\r
127         if(this->m_bForce)\r
128                 force = _T(" --force ");\r
129 \r
130         CString cmd;\r
131 \r
132         ShowTab(IDC_CMD_LOG);\r
133 \r
134         this->m_ctrlTabCtrl.ShowTab(IDC_IN_LOGLIST-1,false);\r
135         this->m_ctrlTabCtrl.ShowTab(IDC_IN_CHANGELIST-1,false);\r
136         this->m_ctrlTabCtrl.ShowTab(IDC_IN_CONFLICT-1,false);\r
137 \r
138         this->GetDlgItem(IDC_BUTTON_COMMIT)->ShowWindow(SW_HIDE);\r
139 \r
140         ///Pull \r
141         if(CurrentEntry == 0) //Pull\r
142         {\r
143                 cmd.Format(_T("git.exe pull %s \"%s\" %s"),\r
144                                 force,\r
145                                 m_strURL,\r
146                                 this->m_strRemoteBranch);\r
147 \r
148                 m_CurrentCmd = GIT_COMMAND_PULL;\r
149                 m_GitCmdList.push_back(cmd);\r
150 \r
151                 m_pThread = AfxBeginThread(ProgressThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);\r
152                 if (m_pThread==NULL)\r
153                 {\r
154                 //              ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));\r
155                 }\r
156                 else\r
157                 {\r
158                         m_pThread->m_bAutoDelete = TRUE;\r
159                         m_pThread->ResumeThread();\r
160                 }\r
161 \r
162         }\r
163         \r
164 }\r
165 \r
166 void CSyncDlg::PullComplete()\r
167 {\r
168         EnableControlButton(true);\r
169         SwitchToInput();\r
170         this->FetchOutList(true);\r
171 \r
172         CString newhash;\r
173         newhash = g_Git.GetHash(CString(_T("HEAD")));\r
174 \r
175         \r
176 \r
177         if( this ->m_GitCmdStatus )\r
178         {\r
179                 CTGitPathList list;\r
180                 if(g_Git.ListConflictFile(list))\r
181                 {\r
182                         this->m_ctrlCmdOut.SetSel(-1,-1);\r
183                         this->m_ctrlCmdOut.ReplaceSel(_T("Get conflict files fail\n"));\r
184 \r
185                         this->ShowTab(IDC_CMD_LOG);\r
186                         return;\r
187                 }\r
188 \r
189                 if(list.GetCount()>0)\r
190                 {\r
191                         this->m_ConflictFileList.Clear();       \r
192                         CTGitPathList list;\r
193                         CTGitPath path;\r
194                         list.AddPath(path);\r
195 \r
196                         this->m_ConflictFileList.GetStatus(&list,true);\r
197                         this->m_ConflictFileList.Show(CTGitPath::LOGACTIONS_UNMERGED,\r
198                                                                           CTGitPath::LOGACTIONS_UNMERGED);\r
199                         \r
200                         this->ShowTab(IDC_IN_CONFLICT);\r
201 \r
202                         this->GetDlgItem(IDC_BUTTON_COMMIT)->ShowWindow(SW_NORMAL);\r
203                 }\r
204                 else\r
205                         this->ShowTab(IDC_CMD_LOG);\r
206 \r
207         }else\r
208         {\r
209                 if(newhash == this->m_oldHash)\r
210                 {\r
211                         this->m_ctrlTabCtrl.ShowTab(IDC_IN_CHANGELIST-1,false);\r
212                         this->m_InLogList.ShowText(_T("No commits get after pull"));\r
213                         this->m_ctrlTabCtrl.ShowTab(IDC_IN_LOGLIST-1,true);\r
214                 }\r
215                 else\r
216                 {\r
217                         this->m_ctrlTabCtrl.ShowTab(IDC_IN_CHANGELIST-1,true);\r
218                         this->m_ctrlTabCtrl.ShowTab(IDC_IN_LOGLIST-1,true);\r
219                         \r
220                         this->AddDiffFileList(&m_InChangeFileList,&m_arInChangeList,newhash,m_oldHash);\r
221                 \r
222                         m_InLogList.FillGitLog(NULL,CGit::      LOG_INFO_STAT| CGit::LOG_INFO_FILESTATE | CGit::LOG_INFO_SHOW_MERGEDFILE,\r
223                                 &this->m_oldHash,&newhash);\r
224                 }\r
225                 this->ShowTab(IDC_IN_LOGLIST);\r
226         }\r
227 }\r
228 \r
229 \r
230 void CSyncDlg::OnBnClickedButtonPush()\r
231 {\r
232         // TODO: Add your control notification handler code here\r
233         this->UpdateData();\r
234 \r
235         this->m_regPushButton=this->m_ctrlPush.GetCurrentEntry();\r
236         this->SwitchToRun();\r
237         this->m_bAbort=false;\r
238         this->m_GitCmdList.clear();\r
239 \r
240         ShowTab(IDC_CMD_LOG);\r
241 \r
242         CString cmd;\r
243         CString tags;\r
244         CString force;\r
245         CString all;\r
246 \r
247         UpateCombox();\r
248 \r
249         switch (m_ctrlPush.GetCurrentEntry())\r
250         {\r
251         case 1:\r
252                 tags = _T(" --tags ");\r
253                 break;\r
254         case 2:\r
255                 all = _T(" --all ");\r
256                 break;\r
257         }\r
258 \r
259         if(this->m_bForce)\r
260                 force = _T(" --force ");\r
261 \r
262         cmd.Format(_T("git.exe push %s %s %s \"%s\" %s"),\r
263                                 tags,force,all,\r
264                                 m_strURL,\r
265                                 m_strLocalBranch);\r
266 \r
267         if (!m_strRemoteBranch.IsEmpty())\r
268         {\r
269                 cmd += _T(":") + m_strRemoteBranch;\r
270         }\r
271         \r
272         m_GitCmdList.push_back(cmd);\r
273 \r
274         m_CurrentCmd = GIT_COMMAND_PUSH;\r
275 \r
276         if(this->m_bAutoLoadPuttyKey)\r
277         {\r
278                 CAppUtils::LaunchPAgent(NULL,&this->m_strURL);\r
279         }\r
280 \r
281         m_pThread = AfxBeginThread(ProgressThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);\r
282         if (m_pThread==NULL)\r
283         {\r
284 //              ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));\r
285         }\r
286         else\r
287         {\r
288                 m_pThread->m_bAutoDelete = TRUE;\r
289                 m_pThread->ResumeThread();\r
290         }\r
291         \r
292 }\r
293 \r
294 void CSyncDlg::OnBnClickedButtonApply()\r
295 {\r
296         // TODO: Add your control notification handler code here\r
297         CString oldhash;\r
298         oldhash=g_Git.GetHash(CString(_T("HEAD")));\r
299         \r
300         CImportPatchDlg dlg;\r
301         CString cmd,output;\r
302 \r
303         if(dlg.DoModal() == IDOK)\r
304         {\r
305                 int err=0;\r
306                 for(int i=0;i<dlg.m_PathList.GetCount();i++)\r
307                 {                       \r
308                         cmd.Format(_T("git.exe am \"%s\""),dlg.m_PathList[i].GetGitPathString());\r
309                         \r
310                         if(g_Git.Run(cmd,&output,CP_ACP))\r
311                         {\r
312                                 CMessageBox::Show(NULL,output,_T("TortoiseGit"),MB_OK);\r
313 \r
314                                 err=1;\r
315                                 break;\r
316                         }\r
317                         this->m_ctrlCmdOut.SetSel(-1,-1);\r
318                         this->m_ctrlCmdOut.ReplaceSel(cmd+_T("\n"));\r
319                         this->m_ctrlCmdOut.SetSel(-1,-1);\r
320                         this->m_ctrlCmdOut.ReplaceSel(output);\r
321                 }\r
322                 \r
323 \r
324                 CString newhash=g_Git.GetHash(CString(_T("HEAD")));             \r
325 \r
326                 this->m_InLogList.Clear();\r
327                 this->m_InChangeFileList.Clear();\r
328 \r
329                 if(newhash == oldhash)\r
330                 {\r
331                         this->m_ctrlTabCtrl.ShowTab(IDC_IN_CHANGELIST-1,false);\r
332                         this->m_InLogList.ShowText(_T("No commits get from patch"));\r
333                         this->m_ctrlTabCtrl.ShowTab(IDC_IN_LOGLIST-1,true);\r
334 \r
335                 }else\r
336                 {\r
337                         this->m_ctrlTabCtrl.ShowTab(IDC_IN_CHANGELIST-1,true);\r
338                         this->m_ctrlTabCtrl.ShowTab(IDC_IN_LOGLIST-1,true);\r
339                         \r
340                         this->AddDiffFileList(&m_InChangeFileList,&m_arInChangeList,newhash,oldhash);\r
341                         m_InLogList.FillGitLog(NULL,CGit::      LOG_INFO_STAT| CGit::LOG_INFO_FILESTATE | CGit::LOG_INFO_SHOW_MERGEDFILE,\r
342                                 &oldhash,&newhash);\r
343 \r
344                         this->FetchOutList(true);\r
345 \r
346                 }\r
347 \r
348                 this->m_ctrlTabCtrl.ShowTab(IDC_CMD_LOG-1,true);\r
349 \r
350                 if(err)\r
351                 {\r
352                         this->ShowTab(IDC_CMD_LOG);\r
353 \r
354                 }else\r
355                 {\r
356                         this->ShowTab(IDC_IN_LOGLIST);\r
357                 }\r
358         }\r
359 }\r
360 \r
361 void CSyncDlg::OnBnClickedButtonEmail()\r
362 {\r
363         // TODO: Add your control notification handler code here\r
364         CString cmd,out;\r
365         \r
366         this->m_strLocalBranch = this->m_ctrlLocalBranch.GetString();\r
367         this->m_ctrlRemoteBranch.GetWindowText(this->m_strRemoteBranch);\r
368         this->m_ctrlURL.GetWindowText(this->m_strURL);\r
369         m_strURL=m_strURL.Trim();\r
370         m_strRemoteBranch=m_strRemoteBranch.Trim();\r
371         \r
372         cmd.Format(_T("git.exe  format-patch -o \"%s\" %s..%s"),\r
373                                         g_Git.m_CurrentDir,\r
374                                         m_strURL+_T('/')+m_strRemoteBranch,m_strLocalBranch);\r
375         \r
376         if(g_Git.Run(cmd,&out,CP_ACP))\r
377         {\r
378                 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);\r
379                 return ;\r
380         }\r
381 \r
382         CAppUtils::SendPatchMail(cmd,out);      \r
383 \r
384 }\r
385 void CSyncDlg::ShowProgressCtrl(bool bShow)\r
386 {\r
387         int b=bShow?SW_NORMAL:SW_HIDE;\r
388         this->m_ctrlAnimate.ShowWindow(b);\r
389         this->m_ctrlProgress.ShowWindow(b);\r
390         this->m_ctrlAnimate.Open(IDR_DOWNLOAD);\r
391         if(b == SW_NORMAL)\r
392                 this->m_ctrlAnimate.Play(0,-1,-1);\r
393         else\r
394                 this->m_ctrlAnimate.Stop();\r
395 }\r
396 void CSyncDlg::ShowInputCtrl(bool bShow)\r
397 {\r
398         int b=bShow?SW_NORMAL:SW_HIDE;\r
399         this->m_ctrlURL.ShowWindow(b);\r
400         this->m_ctrlLocalBranch.ShowWindow(b);\r
401         this->m_ctrlRemoteBranch.ShowWindow(b);\r
402         this->GetDlgItem(IDC_BUTTON_LOCAL_BRANCH)->ShowWindow(b);\r
403         this->GetDlgItem(IDC_BUTTON_REMOTE_BRANCH)->ShowWindow(b);\r
404         this->GetDlgItem(IDC_STATIC_LOCAL_BRANCH)->ShowWindow(b);\r
405         this->GetDlgItem(IDC_STATIC_REMOTE_BRANCH)->ShowWindow(b);\r
406         this->GetDlgItem(IDC_BUTTON_MANAGE)->ShowWindow(b);\r
407         this->GetDlgItem(IDC_CHECK_PUTTY_KEY)->ShowWindow(b);\r
408         this->GetDlgItem(IDC_CHECK_FORCE)->ShowWindow(b);\r
409         this->GetDlgItem(IDC_STATIC_REMOTE_URL)->ShowWindow(b);\r
410         \r
411 }\r
412 BOOL CSyncDlg::OnInitDialog()\r
413 {\r
414         CResizableStandAloneDialog::OnInitDialog();\r
415 \r
416         /*\r
417         this->m_ctrlAnimate.ShowWindow(SW_NORMAL);\r
418         this->m_ctrlAnimate.Open(IDR_DOWNLOAD);\r
419         this->m_ctrlAnimate.Play(0,-1,-1);\r
420     */\r
421 \r
422         // ------------------ Create Tabctrl -----------\r
423         CWnd *pwnd=this->GetDlgItem(IDC_BUTTON_TABCTRL);\r
424         CRect rectDummy;\r
425         pwnd->GetWindowRect(&rectDummy);\r
426         this->ScreenToClient(rectDummy);\r
427 \r
428         if (!m_ctrlTabCtrl.Create(CMFCTabCtrl::STYLE_FLAT, rectDummy, this, IDC_SYNC_TAB))\r
429         {\r
430                 TRACE0("Failed to create output tab window\n");\r
431                 return FALSE;      // fail to create\r
432         }\r
433         m_ctrlTabCtrl.SetResizeMode(CMFCTabCtrl::RESIZE_NO);\r
434 \r
435         // -------------Create Command Log Ctrl ---------\r
436         DWORD dwStyle;\r
437         dwStyle= ES_MULTILINE | ES_READONLY | WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL | ES_AUTOVSCROLL |WS_VSCROLL  ;\r
438 \r
439         if( !m_ctrlCmdOut.Create(dwStyle,rectDummy,&m_ctrlTabCtrl,IDC_CMD_LOG))\r
440         {\r
441                 TRACE0("Failed to create Log commits window\n");\r
442                 return FALSE;      // fail to create\r
443         }\r
444 \r
445         m_ctrlTabCtrl.InsertTab(&m_ctrlCmdOut,_T("Log"),-1);\r
446         \r
447         //m_ctrlCmdOut.ReplaceSel(_T("Hello"));\r
448 \r
449         //----------  Create in coming list ctrl -----------\r
450         dwStyle =LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | LVS_OWNERDATA | WS_BORDER | WS_TABSTOP | WS_CHILD | WS_VISIBLE;;\r
451 \r
452         if( !m_InLogList.Create(dwStyle,rectDummy,&m_ctrlTabCtrl,IDC_IN_LOGLIST))\r
453         {\r
454                 TRACE0("Failed to create output commits window\n");\r
455                 return FALSE;      // fail to create\r
456 \r
457         }\r
458 \r
459         m_ctrlTabCtrl.InsertTab(&m_InLogList,_T("In Commits"),-1);\r
460 \r
461         m_InLogList.InsertGitColumn();\r
462 \r
463         //----------- Create In Change file list -----------\r
464         dwStyle = LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP |LVS_SINGLESEL |WS_CHILD | WS_VISIBLE;\r
465         \r
466         if( !m_InChangeFileList.Create(dwStyle,rectDummy,&m_ctrlTabCtrl,IDC_IN_CHANGELIST))\r
467         {\r
468                 TRACE0("Failed to create output change files window\n");\r
469                 return FALSE;      // fail to create\r
470         }\r
471         m_ctrlTabCtrl.InsertTab(&m_InChangeFileList,_T("In ChangeList"),-1);\r
472 \r
473         m_InChangeFileList.Init(SVNSLC_COLEXT | SVNSLC_COLSTATUS |SVNSLC_COLADD|SVNSLC_COLDEL , _T("OutSyncDlg"),\r
474                                     (CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDSVNLC_COMPARETWO)|\r
475                                                         CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDSVNLC_GNUDIFF2)),false);\r
476 \r
477 \r
478         //---------- Create Conflict List Ctrl -----------------\r
479         dwStyle = LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP |LVS_SINGLESEL |WS_CHILD | WS_VISIBLE;\r
480         \r
481         if( !m_ConflictFileList.Create(dwStyle,rectDummy,&m_ctrlTabCtrl,IDC_IN_CONFLICT))\r
482         {\r
483                 TRACE0("Failed to create output change files window\n");\r
484                 return FALSE;      // fail to create\r
485         }\r
486         m_ctrlTabCtrl.InsertTab(&m_ConflictFileList,_T("Conflict"),-1);\r
487 \r
488         m_ConflictFileList.Init(SVNSLC_COLEXT | SVNSLC_COLSTATUS |SVNSLC_COLADD|SVNSLC_COLDEL , _T("OutSyncDlg"),\r
489                                     (CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDSVNLC_COMPARETWO)|\r
490                                                         CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDSVNLC_GNUDIFF2)|\r
491                                                         SVNSLC_POPCONFLICT|SVNSLC_POPRESOLVE),false);\r
492 \r
493 \r
494         //----------  Create Commit Out List Ctrl---------------\r
495                         \r
496         dwStyle =LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | LVS_OWNERDATA | WS_BORDER | WS_TABSTOP | WS_CHILD | WS_VISIBLE;;\r
497 \r
498         if( !m_OutLogList.Create(dwStyle,rectDummy,&m_ctrlTabCtrl,IDC_OUT_LOGLIST))\r
499         {\r
500                 TRACE0("Failed to create output commits window\n");\r
501                 return FALSE;      // fail to create\r
502 \r
503         }\r
504 \r
505         m_ctrlTabCtrl.InsertTab(&m_OutLogList,_T("Out Commits"),-1);\r
506         \r
507 \r
508         m_OutLogList.InsertGitColumn();\r
509 \r
510         //------------- Create Change File List Control ----------------\r
511 \r
512         dwStyle = LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP |LVS_SINGLESEL |WS_CHILD | WS_VISIBLE;\r
513         \r
514         if( !m_OutChangeFileList.Create(dwStyle,rectDummy,&m_ctrlTabCtrl,IDC_OUT_CHANGELIST))\r
515         {\r
516                 TRACE0("Failed to create output change files window\n");\r
517                 return FALSE;      // fail to create\r
518         }\r
519         m_ctrlTabCtrl.InsertTab(&m_OutChangeFileList,_T("Out ChangeList"),-1);\r
520 \r
521         m_OutChangeFileList.Init(SVNSLC_COLEXT | SVNSLC_COLSTATUS |SVNSLC_COLADD|SVNSLC_COLDEL , _T("OutSyncDlg"),\r
522                                     (CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDSVNLC_COMPARETWO)|\r
523                                                         CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDSVNLC_GNUDIFF2)),false);\r
524 \r
525         this->m_tooltips.Create(this);\r
526 \r
527         AddAnchor(IDC_SYNC_TAB,TOP_LEFT,BOTTOM_RIGHT);\r
528 \r
529         AddAnchor(IDC_GROUP_INFO,TOP_LEFT,TOP_RIGHT);\r
530         AddAnchor(IDC_COMBOBOXEX_URL,TOP_LEFT,TOP_RIGHT);\r
531         AddAnchor(IDC_BUTTON_MANAGE,TOP_RIGHT);\r
532         AddAnchor(IDC_BUTTON_PULL,BOTTOM_LEFT);\r
533         AddAnchor(IDC_BUTTON_PUSH,BOTTOM_LEFT);\r
534         AddAnchor(IDC_BUTTON_APPLY,BOTTOM_LEFT);\r
535         AddAnchor(IDC_BUTTON_EMAIL,BOTTOM_LEFT);\r
536         AddAnchor(IDC_PROGRESS_SYNC,TOP_LEFT,TOP_RIGHT);\r
537         AddAnchor(IDOK,BOTTOM_RIGHT);\r
538         AddAnchor(IDHELP,BOTTOM_RIGHT);\r
539         AddAnchor(IDC_STATIC_STATUS,BOTTOM_LEFT);\r
540         AddAnchor(IDC_ANIMATE_SYNC,TOP_LEFT);\r
541         AddAnchor(IDC_BUTTON_COMMIT,BOTTOM_LEFT);\r
542         \r
543         BRANCH_COMBOX_ADD_ANCHOR();\r
544 \r
545         this->GetDlgItem(IDC_BUTTON_COMMIT)->ShowWindow(SW_HIDE);\r
546 \r
547         CString WorkingDir=g_Git.m_CurrentDir;\r
548         WorkingDir.Replace(_T(':'),_T('_'));\r
549         m_RegKeyRemoteBranch = CString(_T("Software\\TortoiseGit\\History\\SyncBranch\\"))+WorkingDir;\r
550 \r
551 \r
552         this->AddOthersToAnchor();\r
553         // TODO:  Add extra initialization here\r
554 \r
555         this->m_ctrlPush.AddEntry(CString(_T("Push")));\r
556         this->m_ctrlPush.AddEntry(CString(_T("Push tags")));\r
557         ///this->m_ctrlPush.AddEntry(CString(_T("Push All")));\r
558 \r
559         this->m_ctrlPull.AddEntry(CString(_T("&Pull")));\r
560         this->m_ctrlPull.AddEntry(CString(_T("&Fetch")));\r
561         this->m_ctrlPull.AddEntry(CString(_T("Fetch&&Rebase")));\r
562 \r
563         \r
564         WorkingDir.Replace(_T(':'),_T('_'));\r
565 \r
566         CString regkey ;\r
567         regkey.Format(_T("Software\\TortoiseGit\\TortoiseProc\\Sync\\%s"),WorkingDir);\r
568 \r
569         this->m_regPullButton = CRegDWORD(regkey+_T("\\Pull"),0);\r
570         this->m_regPushButton = CRegDWORD(regkey+_T("\\Push"),0);\r
571 \r
572         this->m_ctrlPull.SetCurrentEntry(this->m_regPullButton);\r
573         this->m_ctrlPush.SetCurrentEntry(this->m_regPushButton);\r
574 \r
575         CString str;\r
576         this->GetWindowText(str);\r
577         str += _T(" - ") + g_Git.m_CurrentDir;\r
578         this->SetWindowText(str);\r
579 \r
580         EnableSaveRestore(_T("SyncDlg"));\r
581 \r
582         this->LoadBranchInfo();\r
583 \r
584         this->m_bInited=true;\r
585         FetchOutList();\r
586         \r
587         m_ctrlTabCtrl.ShowTab(IDC_CMD_LOG-1,false);\r
588         m_ctrlTabCtrl.ShowTab(IDC_IN_LOGLIST-1,false);\r
589         m_ctrlTabCtrl.ShowTab(IDC_IN_CHANGELIST-1,false);\r
590         m_ctrlTabCtrl.ShowTab(IDC_IN_CONFLICT-1,false);\r
591                 \r
592         return TRUE;  // return TRUE unless you set the focus to a control\r
593         // EXCEPTION: OCX Property Pages should return FALSE\r
594 }\r
595 \r
596 void CSyncDlg::OnBnClickedButtonManage()\r
597 {\r
598         // TODO: Add your control notification handler code here\r
599         CAppUtils::LaunchRemoteSetting();\r
600 }\r
601 \r
602 BOOL CSyncDlg::PreTranslateMessage(MSG* pMsg)\r
603 {\r
604         // TODO: Add your specialized code here and/or call the base class\r
605         m_tooltips.RelayEvent(pMsg);\r
606         return __super::PreTranslateMessage(pMsg);\r
607 }\r
608 void CSyncDlg::FetchOutList(bool force)\r
609 {\r
610         if(!m_bInited)\r
611                 return;\r
612         m_OutChangeFileList.Clear();\r
613         this->m_OutLogList.Clear();\r
614 \r
615         CString remote;\r
616         this->m_ctrlURL.GetWindowText(remote);\r
617         CString remotebranch;\r
618         this->m_ctrlRemoteBranch.GetWindowText(remotebranch);\r
619         remotebranch=remote+_T("/")+remotebranch;\r
620 \r
621         if(IsURL())\r
622         {\r
623                 CString str;\r
624                 str=_T("Don't know what will push befause you enter URL");\r
625                 m_OutLogList.ShowText(str);\r
626                 this->m_ctrlTabCtrl.ShowTab(m_OutChangeFileList.GetDlgCtrlID()-1,FALSE);\r
627                 m_OutLocalBranch.Empty();\r
628                 m_OutRemoteBranch.Empty();\r
629 \r
630                 this->GetDlgItem(IDC_BUTTON_EMAIL)->EnableWindow(FALSE);\r
631                 return ;\r
632         \r
633         }else if(g_Git.GetHash(remotebranch).GetLength()<40)\r
634         {\r
635                 CString str;\r
636                 str.Format(_T("Don't know what will push befause unkown \"%s\""),remotebranch);\r
637                 m_OutLogList.ShowText(str);\r
638                 this->m_ctrlTabCtrl.ShowTab(m_OutChangeFileList.GetDlgCtrlID()-1,FALSE);\r
639                 m_OutLocalBranch.Empty();\r
640                 m_OutRemoteBranch.Empty();\r
641 \r
642                 this->GetDlgItem(IDC_BUTTON_EMAIL)->EnableWindow(FALSE);\r
643                 return ;\r
644         }\r
645         else\r
646         {\r
647                 CString localbranch;\r
648                 localbranch=this->m_ctrlLocalBranch.GetString();\r
649 \r
650                 if(localbranch != m_OutLocalBranch || m_OutRemoteBranch != remotebranch || force)\r
651                 {\r
652                         m_OutLogList.ClearText();\r
653                         m_OutLogList.FillGitLog(NULL,CGit::     LOG_INFO_STAT| CGit::LOG_INFO_FILESTATE | CGit::LOG_INFO_SHOW_MERGEDFILE,\r
654                                 &remotebranch,&localbranch);\r
655                         \r
656                         CString str;\r
657                         if(m_OutLogList.GetItemCount() == 0)\r
658                         {                       \r
659                                 str.Format(_T("No commits ahead \"%s\""),remotebranch);\r
660                                 m_OutLogList.ShowText(str);\r
661                                 this->m_ctrlStatus.SetWindowText(str);\r
662                                 this->m_ctrlTabCtrl.ShowTab(m_OutChangeFileList.GetDlgCtrlID()-1,FALSE);\r
663                                 this->GetDlgItem(IDC_BUTTON_EMAIL)->EnableWindow(FALSE);\r
664                         }\r
665                         else\r
666                         {\r
667                                 str.Format(_T("%d commits ahead \"%s\""),m_OutLogList.GetItemCount(),remotebranch);\r
668                                 this->m_ctrlStatus.SetWindowText(str);\r
669 \r
670                                 AddDiffFileList(&m_OutChangeFileList,&m_arOutChangeList,localbranch,remotebranch);\r
671                                 \r
672                                 this->m_ctrlTabCtrl.ShowTab(m_OutChangeFileList.GetDlgCtrlID()-1,TRUE);\r
673                                 this->GetDlgItem(IDC_BUTTON_EMAIL)->EnableWindow(TRUE);\r
674                         }\r
675                 }\r
676                 this->m_OutLocalBranch=localbranch;\r
677                 this->m_OutRemoteBranch=remotebranch;\r
678         }\r
679 \r
680 }\r
681 \r
682 bool CSyncDlg::IsURL()\r
683 {\r
684         CString str;\r
685         this->m_ctrlURL.GetWindowText(str);\r
686         if(str.Find(_T('\\'))>=0 || str.Find(_T('/'))>=0)\r
687                 return true;\r
688         else\r
689                 return false;\r
690 }\r
691 void CSyncDlg::OnCbenEndeditComboboxexUrl(NMHDR *pNMHDR, LRESULT *pResult)\r
692 {\r
693         // TODO: Add your control notification handler code here\r
694         *pResult = 0;\r
695 }\r
696 \r
697 void CSyncDlg::OnCbnEditchangeComboboxexUrl()\r
698 {\r
699         this->FetchOutList();\r
700         // TODO: Add your control notification handler code here\r
701 }\r
702 \r
703 UINT CSyncDlg::ProgressThread()\r
704 {\r
705         m_GitCmdStatus=CProgressDlg::RunCmdList(this,m_GitCmdList,true,NULL,&this->m_bAbort);\r
706         return 0;\r
707 }\r
708 \r
709 \r
710 LRESULT CSyncDlg::OnProgressUpdateUI(WPARAM wParam,LPARAM lParam)\r
711 {\r
712         if(wParam == MSG_PROGRESSDLG_START)\r
713         {\r
714                 m_ctrlAnimate.Play(0,-1,-1);\r
715                 this->m_ctrlProgress.SetPos(0);\r
716         }\r
717 \r
718         if(wParam == MSG_PROGRESSDLG_END || wParam == MSG_PROGRESSDLG_FAILED)\r
719         {\r
720                 //m_bDone = true;\r
721                 m_ctrlAnimate.Stop();\r
722                 m_ctrlProgress.SetPos(100);\r
723                 //this->DialogEnableWindow(IDOK,TRUE);\r
724 \r
725                 //if(wParam == MSG_PROGRESSDLG_END)\r
726                 if(this->m_CurrentCmd == GIT_COMMAND_PUSH )\r
727                 {\r
728                         EnableControlButton(true);\r
729                         SwitchToInput();\r
730                         this->FetchOutList(true);\r
731                 }\r
732                 if(this->m_CurrentCmd == GIT_COMMAND_PULL )\r
733                 {\r
734                         PullComplete();\r
735                 }\r
736         }\r
737 \r
738         if(lParam != 0)\r
739                 ParserCmdOutput((TCHAR)lParam);\r
740 \r
741         return 0;\r
742 }\r
743 \r
744 \r
745 void CSyncDlg::ParserCmdOutput(TCHAR ch)\r
746 {\r
747         //TRACE(_T("%c"),ch);\r
748         int linenum;\r
749         int index;\r
750         linenum = this->m_ctrlCmdOut.GetLineCount();\r
751 \r
752         if( ch == _T('\r') )\r
753         {\r
754                 if(linenum>0)\r
755                         m_CmdOutCurrentPos = this->m_ctrlCmdOut.LineIndex(linenum-1);\r
756                 else\r
757                         m_CmdOutCurrentPos = 0;\r
758 \r
759                 //TRACE(_T("line %d - %d\n"),index,m_ctrlCmdOut.GetTextLength());\r
760         }else\r
761                 m_CmdOutCurrentPos++;\r
762                 \r
763         this->m_ctrlCmdOut.SetSel(m_CmdOutCurrentPos,m_CmdOutCurrentPos+1);\r
764         \r
765         if( ch != _T('\r') )\r
766                 this->m_ctrlCmdOut.ReplaceSel(CString(ch));\r
767         \r
768         int firstline = m_ctrlCmdOut.GetFirstVisibleLine();\r
769         if( linenum - firstline > 4 )\r
770                 this->m_ctrlCmdOut.LineScroll(linenum - firstline -4);\r
771 \r
772         if( ch == _T('\r') || ch == _T('\n') )\r
773         {\r
774                 int s1=m_LogText.Find(_T(':'));\r
775                 int s2=m_LogText.Find(_T('%'));\r
776                 if(s1>0 && s2>0)\r
777                 {\r
778                         //      this->m_CurrentWork.SetWindowTextW(m_LogText.Left(s1));\r
779                         int pos=CProgressDlg::FindPercentage(m_LogText);\r
780                         TRACE(_T("Pos %d\r\n"),pos);\r
781                         if(pos>0)\r
782                                 this->m_ctrlProgress.SetPos(pos);\r
783                 }\r
784                 m_LogText=_T("");       \r
785         }\r
786         m_LogText+=ch;\r
787 \r
788 }\r
789 void CSyncDlg::OnBnClickedButtonCommit()\r
790 {\r
791         // TODO: Add your control notification handler code here\r
792     CString proc=CPathUtils::GetAppDirectory();\r
793     proc += _T("TortoiseProc.exe /command:commit");\r
794     proc += _T(" /path:\"");\r
795     proc += g_Git.m_CurrentDir;\r
796     \r
797         CAppUtils::LaunchApplication(proc,IDS_ERROR_CANNON_FIND_TORTOISEPROC,false);\r
798 }\r