Fixed issue #444: Crash rebase dialog when press ESC and move split bar
[TortoiseGit.git] / src / TortoiseProc / SyncDlg.cpp
blob1d8337dfb6305f47811f334593fab41cf8e62027
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2009 - 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.
20 // SyncDlg.cpp : implementation file
23 #include "stdafx.h"
24 #include "TortoiseProc.h"
25 #include "SyncDlg.h"
26 #include "progressdlg.h"
27 #include "MessageBox.h"
28 #include "ImportPatchDlg.h"
29 #include "PathUtils.h"
30 #include "RebaseDlg.h"
32 // CSyncDlg dialog
34 IMPLEMENT_DYNAMIC(CSyncDlg, CResizableStandAloneDialog)
36 CSyncDlg::CSyncDlg(CWnd* pParent /*=NULL*/)
37 : CResizableStandAloneDialog(CSyncDlg::IDD, pParent)
39 m_pTooltip=&this->m_tooltips;
40 m_bInited=false;
41 m_CmdOutCurrentPos=0;
42 m_bAutoLoadPuttyKey = CAppUtils::IsSSHPutty();
43 m_bForce=false;
44 m_bBlock = false;
47 CSyncDlg::~CSyncDlg()
51 void CSyncDlg::DoDataExchange(CDataExchange* pDX)
53 CDialog::DoDataExchange(pDX);
54 DDX_Check(pDX, IDC_CHECK_PUTTY_KEY, m_bAutoLoadPuttyKey);
55 DDX_Check(pDX, IDC_CHECK_FORCE,m_bForce);
56 DDX_Control(pDX, IDC_COMBOBOXEX_URL, m_ctrlURL);
57 DDX_Control(pDX, IDC_BUTTON_TABCTRL, m_ctrlDumyButton);
58 DDX_Control(pDX, IDC_BUTTON_PULL, m_ctrlPull);
59 DDX_Control(pDX, IDC_BUTTON_PUSH, m_ctrlPush);
60 DDX_Control(pDX, IDC_STATIC_STATUS, m_ctrlStatus);
61 DDX_Control(pDX, IDC_PROGRESS_SYNC, m_ctrlProgress);
62 DDX_Control(pDX, IDC_ANIMATE_SYNC, m_ctrlAnimate);
63 DDX_Control(pDX, IDC_BUTTON_SUBMODULE,m_ctrlSubmodule);
64 BRANCH_COMBOX_DDX;
68 BEGIN_MESSAGE_MAP(CSyncDlg, CResizableStandAloneDialog)
69 ON_BN_CLICKED(IDC_BUTTON_PULL, &CSyncDlg::OnBnClickedButtonPull)
70 ON_BN_CLICKED(IDC_BUTTON_PUSH, &CSyncDlg::OnBnClickedButtonPush)
71 ON_BN_CLICKED(IDC_BUTTON_APPLY, &CSyncDlg::OnBnClickedButtonApply)
72 ON_BN_CLICKED(IDC_BUTTON_EMAIL, &CSyncDlg::OnBnClickedButtonEmail)
73 ON_BN_CLICKED(IDC_BUTTON_MANAGE, &CSyncDlg::OnBnClickedButtonManage)
74 BRANCH_COMBOX_EVENT
75 ON_NOTIFY(CBEN_ENDEDIT, IDC_COMBOBOXEX_URL, &CSyncDlg::OnCbenEndeditComboboxexUrl)
76 ON_CBN_EDITCHANGE(IDC_COMBOBOXEX_URL, &CSyncDlg::OnCbnEditchangeComboboxex)
77 ON_CBN_EDITCHANGE(IDC_COMBOBOXEX_REMOTE_BRANCH, &CSyncDlg::OnCbnEditchangeComboboxex)
78 ON_MESSAGE(MSG_PROGRESSDLG_UPDATE_UI, OnProgressUpdateUI)
79 ON_BN_CLICKED(IDC_BUTTON_COMMIT, &CSyncDlg::OnBnClickedButtonCommit)
80 ON_BN_CLICKED(IDC_BUTTON_SUBMODULE, &CSyncDlg::OnBnClickedButtonSubmodule)
81 ON_WM_TIMER()
82 END_MESSAGE_MAP()
85 void CSyncDlg::EnableControlButton(bool bEnabled)
87 GetDlgItem(IDC_BUTTON_PULL)->EnableWindow(bEnabled);
88 GetDlgItem(IDC_BUTTON_PUSH)->EnableWindow(bEnabled);
89 GetDlgItem(IDC_BUTTON_APPLY)->EnableWindow(bEnabled);
90 GetDlgItem(IDC_BUTTON_EMAIL)->EnableWindow(bEnabled);
91 GetDlgItem(IDOK)->EnableWindow(bEnabled);
92 GetDlgItem(IDC_BUTTON_SUBMODULE)->EnableWindow(bEnabled);
94 // CSyncDlg message handlers
96 void CSyncDlg::OnBnClickedButtonPull()
98 // TODO: Add your control notification handler code here
99 int CurrentEntry;
100 CurrentEntry = this->m_ctrlPull.GetCurrentEntry();
101 this->m_regPullButton = CurrentEntry;
104 this->m_bAbort=false;
105 this->m_GitCmdList.clear();
107 this->UpdateData();
108 UpdateCombox();
110 m_oldHash = g_Git.GetHash(CString(_T("HEAD")));
112 if( CurrentEntry == 0)
114 if( g_Git.GetHash(this->m_strLocalBranch) != m_oldHash)
116 CMessageBox::Show(NULL,_T("Pull require local branch must be current branch"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
117 return;
121 if(this->m_strURL.IsEmpty())
123 CMessageBox::Show(NULL,_T("URL can't Empty"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
124 return;
127 if(this->m_bAutoLoadPuttyKey)
129 CAppUtils::LaunchPAgent(NULL,&this->m_strURL);
132 this->SwitchToRun();
134 CString force;
135 if(this->m_bForce)
136 force = _T(" --force ");
138 CString cmd;
140 ShowTab(IDC_CMD_LOG);
142 this->m_ctrlTabCtrl.ShowTab(IDC_IN_LOGLIST-1,false);
143 this->m_ctrlTabCtrl.ShowTab(IDC_IN_CHANGELIST-1,false);
144 this->m_ctrlTabCtrl.ShowTab(IDC_IN_CONFLICT-1,false);
146 this->GetDlgItem(IDC_BUTTON_COMMIT)->ShowWindow(SW_HIDE);
148 ///Pull
149 if(CurrentEntry == 0) //Pull
151 cmd.Format(_T("git.exe pull %s \"%s\" %s"),
152 force,
153 m_strURL,
154 this->m_strRemoteBranch);
156 m_CurrentCmd = GIT_COMMAND_PULL;
157 m_GitCmdList.push_back(cmd);
159 m_pThread = AfxBeginThread(ProgressThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
160 if (m_pThread==NULL)
162 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
164 else
166 m_pThread->m_bAutoDelete = TRUE;
167 m_pThread->ResumeThread();
172 ///Fetch
173 if(CurrentEntry == 1 || CurrentEntry ==2 ) //Fetch
175 CString remotebranch;
176 if(this->IsURL() || m_strRemoteBranch.IsEmpty())
178 remotebranch=this->m_strRemoteBranch;
180 }else
183 remotebranch.Format(_T("remotes/%s/%s"),
184 m_strURL,m_strRemoteBranch);
185 if(g_Git.GetHash(remotebranch).IsEmpty())
186 remotebranch=m_strRemoteBranch;
187 else
188 remotebranch=m_strRemoteBranch+_T(":")+remotebranch;
191 cmd.Format(_T("git.exe fetch %s \"%s\" %s"),
192 force,
193 m_strURL,
194 remotebranch);
196 if(CurrentEntry == 1)
197 m_CurrentCmd = GIT_COMMAND_FETCH;
198 else
199 m_CurrentCmd = GIT_COMMAND_FETCHANDREBASE;
200 m_GitCmdList.push_back(cmd);
202 m_pThread = AfxBeginThread(ProgressThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
203 if (m_pThread==NULL)
205 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
207 else
209 m_pThread->m_bAutoDelete = TRUE;
210 m_pThread->ResumeThread();
214 ///Remote Update
215 if(CurrentEntry == 3)
217 m_CurrentCmd = GIT_COMMAND_REMOTE;
218 cmd=_T("git.exe remote update");
219 m_GitCmdList.push_back(cmd);
221 InterlockedExchange(&m_bBlock, TRUE);
223 m_pThread = AfxBeginThread(ProgressThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
224 if (m_pThread==NULL)
226 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
227 InterlockedExchange(&m_bBlock, FALSE);
229 else
231 m_pThread->m_bAutoDelete = TRUE;
232 m_pThread->ResumeThread();
238 void CSyncDlg::PullComplete()
240 EnableControlButton(true);
241 SwitchToInput();
242 this->FetchOutList(true);
244 CString newhash;
245 newhash = g_Git.GetHash(CString(_T("HEAD")));
249 if( this ->m_GitCmdStatus )
251 CTGitPathList list;
252 if(g_Git.ListConflictFile(list))
254 this->m_ctrlCmdOut.SetSel(-1,-1);
255 this->m_ctrlCmdOut.ReplaceSel(_T("Get conflict files fail\n"));
257 this->ShowTab(IDC_CMD_LOG);
258 return;
261 if(list.GetCount()>0)
263 this->m_ConflictFileList.Clear();
264 CTGitPathList list;
265 CTGitPath path;
266 list.AddPath(path);
268 this->m_ConflictFileList.GetStatus(&list,true);
269 this->m_ConflictFileList.Show(CTGitPath::LOGACTIONS_UNMERGED,
270 CTGitPath::LOGACTIONS_UNMERGED);
272 this->ShowTab(IDC_IN_CONFLICT);
274 this->GetDlgItem(IDC_BUTTON_COMMIT)->ShowWindow(SW_NORMAL);
276 else
277 this->ShowTab(IDC_CMD_LOG);
279 }else
281 if(newhash == this->m_oldHash)
283 this->m_ctrlTabCtrl.ShowTab(IDC_IN_CHANGELIST-1,false);
284 this->m_InLogList.ShowText(_T("No commits get after pull"));
285 this->m_ctrlTabCtrl.ShowTab(IDC_IN_LOGLIST-1,true);
287 else
289 this->m_ctrlTabCtrl.ShowTab(IDC_IN_CHANGELIST-1,true);
290 this->m_ctrlTabCtrl.ShowTab(IDC_IN_LOGLIST-1,true);
292 this->AddDiffFileList(&m_InChangeFileList,&m_arInChangeList,newhash,m_oldHash);
294 m_InLogList.FillGitLog(NULL,CGit:: LOG_INFO_STAT| CGit::LOG_INFO_FILESTATE | CGit::LOG_INFO_SHOW_MERGEDFILE,
295 &this->m_oldHash,&newhash);
297 this->ShowTab(IDC_IN_LOGLIST);
301 void CSyncDlg::FetchComplete()
303 EnableControlButton(true);
304 SwitchToInput();
305 this->FetchOutList(true);
307 ShowTab(IDC_CMD_LOG);
308 if( (!this->m_GitCmdStatus) && this->m_CurrentCmd == GIT_COMMAND_FETCHANDREBASE)
310 CRebaseDlg dlg;
311 dlg.m_PostButtonTexts.Add(_T("Email &Patch..."));
312 int response = dlg.DoModal();
313 if(response == IDOK)
315 return ;
318 if(response == IDC_REBASE_POST_BUTTON)
320 CString cmd,out;
321 cmd.Format(_T("git.exe format-patch -o \"%s\" %s..%s"),
322 g_Git.m_CurrentDir,
323 dlg.m_Upstream,dlg.m_Branch);
324 if(g_Git.Run(cmd,&out,CP_ACP))
326 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
327 return ;
330 CAppUtils::SendPatchMail(cmd,out);
335 void CSyncDlg::OnBnClickedButtonPush()
337 // TODO: Add your control notification handler code here
338 this->UpdateData();
339 UpdateCombox();
341 if(this->m_strURL.IsEmpty())
343 CMessageBox::Show(NULL,_T("URL can't Empty"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
344 return;
347 this->m_regPushButton=this->m_ctrlPush.GetCurrentEntry();
348 this->SwitchToRun();
349 this->m_bAbort=false;
350 this->m_GitCmdList.clear();
352 ShowTab(IDC_CMD_LOG);
354 CString cmd;
355 CString tags;
356 CString force;
357 CString all;
361 switch (m_ctrlPush.GetCurrentEntry())
363 case 1:
364 tags = _T(" --tags ");
365 break;
366 case 2:
367 all = _T(" --all ");
368 break;
371 if(this->m_bForce)
372 force = _T(" --force ");
374 cmd.Format(_T("git.exe push %s %s %s \"%s\" %s"),
375 tags,force,all,
376 m_strURL,
377 m_strLocalBranch);
379 if (!m_strRemoteBranch.IsEmpty())
381 cmd += _T(":") + m_strRemoteBranch;
384 m_GitCmdList.push_back(cmd);
386 m_CurrentCmd = GIT_COMMAND_PUSH;
388 if(this->m_bAutoLoadPuttyKey)
390 CAppUtils::LaunchPAgent(NULL,&this->m_strURL);
393 m_pThread = AfxBeginThread(ProgressThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
394 if (m_pThread==NULL)
396 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
398 else
400 m_pThread->m_bAutoDelete = TRUE;
401 m_pThread->ResumeThread();
406 void CSyncDlg::OnBnClickedButtonApply()
408 // TODO: Add your control notification handler code here
409 CString oldhash;
410 oldhash=g_Git.GetHash(CString(_T("HEAD")));
412 CImportPatchDlg dlg;
413 CString cmd,output;
415 if(dlg.DoModal() == IDOK)
417 int err=0;
418 for(int i=0;i<dlg.m_PathList.GetCount();i++)
420 cmd.Format(_T("git.exe am \"%s\""),dlg.m_PathList[i].GetGitPathString());
422 if(g_Git.Run(cmd,&output,CP_ACP))
424 CMessageBox::Show(NULL,output,_T("TortoiseGit"),MB_OK);
426 err=1;
427 break;
429 this->m_ctrlCmdOut.SetSel(-1,-1);
430 this->m_ctrlCmdOut.ReplaceSel(cmd+_T("\n"));
431 this->m_ctrlCmdOut.SetSel(-1,-1);
432 this->m_ctrlCmdOut.ReplaceSel(output);
436 CString newhash=g_Git.GetHash(CString(_T("HEAD")));
438 this->m_InLogList.Clear();
439 this->m_InChangeFileList.Clear();
441 if(newhash == oldhash)
443 this->m_ctrlTabCtrl.ShowTab(IDC_IN_CHANGELIST-1,false);
444 this->m_InLogList.ShowText(_T("No commits get from patch"));
445 this->m_ctrlTabCtrl.ShowTab(IDC_IN_LOGLIST-1,true);
447 }else
449 this->m_ctrlTabCtrl.ShowTab(IDC_IN_CHANGELIST-1,true);
450 this->m_ctrlTabCtrl.ShowTab(IDC_IN_LOGLIST-1,true);
452 this->AddDiffFileList(&m_InChangeFileList,&m_arInChangeList,newhash,oldhash);
453 m_InLogList.FillGitLog(NULL,CGit:: LOG_INFO_STAT| CGit::LOG_INFO_FILESTATE | CGit::LOG_INFO_SHOW_MERGEDFILE,
454 &oldhash,&newhash);
456 this->FetchOutList(true);
460 this->m_ctrlTabCtrl.ShowTab(IDC_CMD_LOG-1,true);
462 if(err)
464 this->ShowTab(IDC_CMD_LOG);
466 }else
468 this->ShowTab(IDC_IN_LOGLIST);
473 void CSyncDlg::OnBnClickedButtonEmail()
475 // TODO: Add your control notification handler code here
476 CString cmd,out;
478 this->m_strLocalBranch = this->m_ctrlLocalBranch.GetString();
479 this->m_ctrlRemoteBranch.GetWindowText(this->m_strRemoteBranch);
480 this->m_ctrlURL.GetWindowText(this->m_strURL);
481 m_strURL=m_strURL.Trim();
482 m_strRemoteBranch=m_strRemoteBranch.Trim();
484 cmd.Format(_T("git.exe format-patch -o \"%s\" %s..%s"),
485 g_Git.m_CurrentDir,
486 m_strURL+_T('/')+m_strRemoteBranch,m_strLocalBranch);
488 if(g_Git.Run(cmd,&out,CP_ACP))
490 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
491 return ;
494 CAppUtils::SendPatchMail(cmd,out);
497 void CSyncDlg::ShowProgressCtrl(bool bShow)
499 int b=bShow?SW_NORMAL:SW_HIDE;
500 this->m_ctrlAnimate.ShowWindow(b);
501 this->m_ctrlProgress.ShowWindow(b);
502 this->m_ctrlAnimate.Open(IDR_DOWNLOAD);
503 if(b == SW_NORMAL)
504 this->m_ctrlAnimate.Play(0,-1,-1);
505 else
506 this->m_ctrlAnimate.Stop();
508 void CSyncDlg::ShowInputCtrl(bool bShow)
510 int b=bShow?SW_NORMAL:SW_HIDE;
511 this->m_ctrlURL.ShowWindow(b);
512 this->m_ctrlLocalBranch.ShowWindow(b);
513 this->m_ctrlRemoteBranch.ShowWindow(b);
514 this->GetDlgItem(IDC_BUTTON_LOCAL_BRANCH)->ShowWindow(b);
515 this->GetDlgItem(IDC_BUTTON_REMOTE_BRANCH)->ShowWindow(b);
516 this->GetDlgItem(IDC_STATIC_LOCAL_BRANCH)->ShowWindow(b);
517 this->GetDlgItem(IDC_STATIC_REMOTE_BRANCH)->ShowWindow(b);
518 this->GetDlgItem(IDC_BUTTON_MANAGE)->ShowWindow(b);
519 this->GetDlgItem(IDC_CHECK_PUTTY_KEY)->ShowWindow(b);
520 this->GetDlgItem(IDC_CHECK_FORCE)->ShowWindow(b);
521 this->GetDlgItem(IDC_STATIC_REMOTE_URL)->ShowWindow(b);
524 BOOL CSyncDlg::OnInitDialog()
526 CResizableStandAloneDialog::OnInitDialog();
529 this->m_ctrlAnimate.ShowWindow(SW_NORMAL);
530 this->m_ctrlAnimate.Open(IDR_DOWNLOAD);
531 this->m_ctrlAnimate.Play(0,-1,-1);
534 // ------------------ Create Tabctrl -----------
535 CWnd *pwnd=this->GetDlgItem(IDC_BUTTON_TABCTRL);
536 CRect rectDummy;
537 pwnd->GetWindowRect(&rectDummy);
538 this->ScreenToClient(rectDummy);
540 if (!m_ctrlTabCtrl.Create(CMFCTabCtrl::STYLE_FLAT, rectDummy, this, IDC_SYNC_TAB))
542 TRACE0("Failed to create output tab window\n");
543 return FALSE; // fail to create
545 m_ctrlTabCtrl.SetResizeMode(CMFCTabCtrl::RESIZE_NO);
547 // -------------Create Command Log Ctrl ---------
548 DWORD dwStyle;
549 dwStyle= ES_MULTILINE | ES_READONLY | WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL | ES_AUTOVSCROLL |WS_VSCROLL ;
551 if( !m_ctrlCmdOut.Create(dwStyle,rectDummy,&m_ctrlTabCtrl,IDC_CMD_LOG))
553 TRACE0("Failed to create Log commits window\n");
554 return FALSE; // fail to create
557 m_ctrlTabCtrl.InsertTab(&m_ctrlCmdOut,_T("Log"),-1);
559 //m_ctrlCmdOut.ReplaceSel(_T("Hello"));
561 //---------- Create in coming list ctrl -----------
562 dwStyle =LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | LVS_OWNERDATA | WS_BORDER | WS_TABSTOP | WS_CHILD | WS_VISIBLE;;
564 if( !m_InLogList.Create(dwStyle,rectDummy,&m_ctrlTabCtrl,IDC_IN_LOGLIST))
566 TRACE0("Failed to create output commits window\n");
567 return FALSE; // fail to create
571 m_ctrlTabCtrl.InsertTab(&m_InLogList,_T("In Commits"),-1);
573 m_InLogList.InsertGitColumn();
575 //----------- Create In Change file list -----------
576 dwStyle = LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP |LVS_SINGLESEL |WS_CHILD | WS_VISIBLE;
578 if( !m_InChangeFileList.Create(dwStyle,rectDummy,&m_ctrlTabCtrl,IDC_IN_CHANGELIST))
580 TRACE0("Failed to create output change files window\n");
581 return FALSE; // fail to create
583 m_ctrlTabCtrl.InsertTab(&m_InChangeFileList,_T("In ChangeList"),-1);
585 m_InChangeFileList.Init(SVNSLC_COLEXT | SVNSLC_COLSTATUS |SVNSLC_COLADD|SVNSLC_COLDEL , _T("OutSyncDlg"),
586 (CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDSVNLC_COMPARETWO)|
587 CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDSVNLC_GNUDIFF2)),false);
590 //---------- Create Conflict List Ctrl -----------------
591 dwStyle = LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP |LVS_SINGLESEL |WS_CHILD | WS_VISIBLE;
593 if( !m_ConflictFileList.Create(dwStyle,rectDummy,&m_ctrlTabCtrl,IDC_IN_CONFLICT))
595 TRACE0("Failed to create output change files window\n");
596 return FALSE; // fail to create
598 m_ctrlTabCtrl.InsertTab(&m_ConflictFileList,_T("Conflict"),-1);
600 m_ConflictFileList.Init(SVNSLC_COLEXT | SVNSLC_COLSTATUS |SVNSLC_COLADD|SVNSLC_COLDEL , _T("OutSyncDlg"),
601 (CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDSVNLC_COMPARETWO)|
602 CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDSVNLC_GNUDIFF2)|
603 SVNSLC_POPCONFLICT|SVNSLC_POPRESOLVE),false);
606 //---------- Create Commit Out List Ctrl---------------
608 dwStyle =LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | LVS_OWNERDATA | WS_BORDER | WS_TABSTOP | WS_CHILD | WS_VISIBLE;;
610 if( !m_OutLogList.Create(dwStyle,rectDummy,&m_ctrlTabCtrl,IDC_OUT_LOGLIST))
612 TRACE0("Failed to create output commits window\n");
613 return FALSE; // fail to create
617 m_ctrlTabCtrl.InsertTab(&m_OutLogList,_T("Out Commits"),-1);
620 m_OutLogList.InsertGitColumn();
622 //------------- Create Change File List Control ----------------
624 dwStyle = LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP |LVS_SINGLESEL |WS_CHILD | WS_VISIBLE;
626 if( !m_OutChangeFileList.Create(dwStyle,rectDummy,&m_ctrlTabCtrl,IDC_OUT_CHANGELIST))
628 TRACE0("Failed to create output change files window\n");
629 return FALSE; // fail to create
631 m_ctrlTabCtrl.InsertTab(&m_OutChangeFileList,_T("Out ChangeList"),-1);
633 m_OutChangeFileList.Init(SVNSLC_COLEXT | SVNSLC_COLSTATUS |SVNSLC_COLADD|SVNSLC_COLDEL , _T("OutSyncDlg"),
634 (CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDSVNLC_COMPARETWO)|
635 CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDSVNLC_GNUDIFF2)),false);
637 this->m_tooltips.Create(this);
639 AddAnchor(IDC_SYNC_TAB,TOP_LEFT,BOTTOM_RIGHT);
641 AddAnchor(IDC_GROUP_INFO,TOP_LEFT,TOP_RIGHT);
642 AddAnchor(IDC_COMBOBOXEX_URL,TOP_LEFT,TOP_RIGHT);
643 AddAnchor(IDC_BUTTON_MANAGE,TOP_RIGHT);
644 AddAnchor(IDC_BUTTON_PULL,BOTTOM_LEFT);
645 AddAnchor(IDC_BUTTON_PUSH,BOTTOM_LEFT);
646 AddAnchor(IDC_BUTTON_SUBMODULE,BOTTOM_LEFT);
647 AddAnchor(IDC_BUTTON_APPLY,BOTTOM_RIGHT);
648 AddAnchor(IDC_BUTTON_EMAIL,BOTTOM_RIGHT);
649 AddAnchor(IDC_PROGRESS_SYNC,TOP_LEFT,TOP_RIGHT);
650 AddAnchor(IDOK,BOTTOM_RIGHT);
651 AddAnchor(IDHELP,BOTTOM_RIGHT);
652 AddAnchor(IDC_STATIC_STATUS,BOTTOM_LEFT);
653 AddAnchor(IDC_ANIMATE_SYNC,TOP_LEFT);
654 AddAnchor(IDC_BUTTON_COMMIT,BOTTOM_LEFT);
656 BRANCH_COMBOX_ADD_ANCHOR();
658 this->GetDlgItem(IDC_BUTTON_COMMIT)->ShowWindow(SW_HIDE);
660 CString WorkingDir=g_Git.m_CurrentDir;
661 WorkingDir.Replace(_T(':'),_T('_'));
662 m_RegKeyRemoteBranch = CString(_T("Software\\TortoiseGit\\History\\SyncBranch\\"))+WorkingDir;
665 this->AddOthersToAnchor();
666 // TODO: Add extra initialization here
668 this->m_ctrlPush.AddEntry(CString(_T("Pus&h")));
669 this->m_ctrlPush.AddEntry(CString(_T("Push ta&gs")));
670 ///this->m_ctrlPush.AddEntry(CString(_T("Push All")));
672 this->m_ctrlPull.AddEntry(CString(_T("&Pull")));
673 this->m_ctrlPull.AddEntry(CString(_T("Fetc&h")));
674 this->m_ctrlPull.AddEntry(CString(_T("Fetch&&Re&base")));
675 this->m_ctrlPull.AddEntry(CString(_T("Remote Update")));
677 this->m_ctrlSubmodule.AddEntry(CString(_T("Submodule Update")));
678 this->m_ctrlSubmodule.AddEntry(CString(_T("Submodule Init")));
679 this->m_ctrlSubmodule.AddEntry(CString(_T("Submodule Sync")));
681 WorkingDir.Replace(_T(':'),_T('_'));
683 CString regkey ;
684 regkey.Format(_T("Software\\TortoiseGit\\TortoiseProc\\Sync\\%s"),WorkingDir);
686 this->m_regPullButton = CRegDWORD(regkey+_T("\\Pull"),0);
687 this->m_regPushButton = CRegDWORD(regkey+_T("\\Push"),0);
688 this->m_regSubmoduleButton = CRegDWORD(regkey+_T("\\Submodule"));
690 this->m_ctrlPull.SetCurrentEntry(this->m_regPullButton);
691 this->m_ctrlPush.SetCurrentEntry(this->m_regPushButton);
692 this->m_ctrlSubmodule.SetCurrentEntry(this->m_regSubmoduleButton);
694 CString str;
695 this->GetWindowText(str);
696 str += _T(" - ") + g_Git.m_CurrentDir;
697 this->SetWindowText(str);
699 EnableSaveRestore(_T("SyncDlg"));
701 this->m_ctrlURL.LoadHistory(CString(_T("Software\\TortoiseGit\\History\\SyncURL\\"))+WorkingDir, _T("url"));
703 STRING_VECTOR list;
705 if(!g_Git.GetRemoteList(list))
707 for(unsigned int i=0;i<list.size();i++)
709 m_ctrlURL.AddString(list[i]);
712 m_ctrlURL.SetCurSel(0);
713 m_ctrlRemoteBranch.SetCurSel(0);
714 m_ctrlURL.SetURLHistory(true);
716 this->LoadBranchInfo();
718 this->m_bInited=true;
719 FetchOutList();
721 m_ctrlTabCtrl.ShowTab(IDC_CMD_LOG-1,false);
722 m_ctrlTabCtrl.ShowTab(IDC_IN_LOGLIST-1,false);
723 m_ctrlTabCtrl.ShowTab(IDC_IN_CHANGELIST-1,false);
724 m_ctrlTabCtrl.ShowTab(IDC_IN_CONFLICT-1,false);
727 m_ctrlRemoteBranch.m_bWantReturn = TRUE;
728 m_ctrlURL.m_bWantReturn = TRUE;
730 return TRUE; // return TRUE unless you set the focus to a control
731 // EXCEPTION: OCX Property Pages should return FALSE
734 void CSyncDlg::OnBnClickedButtonManage()
736 // TODO: Add your control notification handler code here
737 CAppUtils::LaunchRemoteSetting();
740 void CSyncDlg::Refresh()
742 theApp.DoWaitCursor(1);
744 CString local;
745 CString remote;
746 CString url;
747 this->m_ctrlLocalBranch.GetWindowText(local);
748 this->m_ctrlRemoteBranch.GetWindowText(remote);
749 this->m_ctrlURL.GetWindowText(url);
751 this->LoadBranchInfo();
753 this->m_ctrlLocalBranch.AddString(local);
754 this->m_ctrlRemoteBranch.AddString(remote);
755 this->m_ctrlURL.AddString(url);
757 m_OutLogList.ShowText(_T("Refresh ..."));
758 this->FetchOutList(true);
759 theApp.DoWaitCursor(-1);
762 BOOL CSyncDlg::PreTranslateMessage(MSG* pMsg)
764 // TODO: Add your specialized code here and/or call the base class
766 if (pMsg->message == WM_KEYDOWN)
768 switch (pMsg->wParam)
771 case VK_F5:
773 if (m_bBlock)
774 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
775 Refresh();
777 break;
779 /* Avoid TAB control destroy but dialog exist*/
780 case VK_ESCAPE:
781 case VK_CANCEL:
783 TCHAR buff[128];
784 ::GetClassName(pMsg->hwnd,buff,128);
786 if(_tcsnicmp(buff,_T("RichEdit20W"),128)==0)
788 this->PostMessage(WM_KEYDOWN,VK_ESCAPE,0);
789 return TRUE;
794 m_tooltips.RelayEvent(pMsg);
795 return __super::PreTranslateMessage(pMsg);
797 void CSyncDlg::FetchOutList(bool force)
799 if(!m_bInited)
800 return;
801 m_OutChangeFileList.Clear();
802 this->m_OutLogList.Clear();
804 CString remote;
805 this->m_ctrlURL.GetWindowText(remote);
806 CString remotebranch;
807 this->m_ctrlRemoteBranch.GetWindowText(remotebranch);
808 remotebranch=remote+_T("/")+remotebranch;
810 if(IsURL())
812 CString str;
813 str=_T("Don't know what will push because you enter URL");
814 m_OutLogList.ShowText(str);
815 this->m_ctrlTabCtrl.ShowTab(m_OutChangeFileList.GetDlgCtrlID()-1,FALSE);
816 m_OutLocalBranch.Empty();
817 m_OutRemoteBranch.Empty();
819 this->GetDlgItem(IDC_BUTTON_EMAIL)->EnableWindow(FALSE);
820 return ;
822 }else if(g_Git.GetHash(remotebranch).GetLength()<40)
824 CString str;
825 str.Format(_T("Don't know what will push because unknown \"%s\""),remotebranch);
826 m_OutLogList.ShowText(str);
827 this->m_ctrlTabCtrl.ShowTab(m_OutChangeFileList.GetDlgCtrlID()-1,FALSE);
828 m_OutLocalBranch.Empty();
829 m_OutRemoteBranch.Empty();
831 this->GetDlgItem(IDC_BUTTON_EMAIL)->EnableWindow(FALSE);
832 return ;
834 else
836 CString localbranch;
837 localbranch=this->m_ctrlLocalBranch.GetString();
839 if(localbranch != m_OutLocalBranch || m_OutRemoteBranch != remotebranch || force)
841 m_OutLogList.ClearText();
842 m_OutLogList.FillGitLog(NULL,CGit:: LOG_INFO_STAT| CGit::LOG_INFO_FILESTATE | CGit::LOG_INFO_SHOW_MERGEDFILE,
843 &remotebranch,&localbranch);
845 CString str;
846 if(m_OutLogList.GetItemCount() == 0)
848 str.Format(_T("No commits ahead \"%s\""),remotebranch);
849 m_OutLogList.ShowText(str);
850 this->m_ctrlStatus.SetWindowText(str);
851 this->m_ctrlTabCtrl.ShowTab(m_OutChangeFileList.GetDlgCtrlID()-1,FALSE);
852 this->GetDlgItem(IDC_BUTTON_EMAIL)->EnableWindow(FALSE);
854 else
856 str.Format(_T("%d commits ahead \"%s\""),m_OutLogList.GetItemCount(),remotebranch);
857 this->m_ctrlStatus.SetWindowText(str);
859 AddDiffFileList(&m_OutChangeFileList,&m_arOutChangeList,localbranch,remotebranch);
861 this->m_ctrlTabCtrl.ShowTab(m_OutChangeFileList.GetDlgCtrlID()-1,TRUE);
862 this->GetDlgItem(IDC_BUTTON_EMAIL)->EnableWindow(TRUE);
865 this->m_OutLocalBranch=localbranch;
866 this->m_OutRemoteBranch=remotebranch;
871 bool CSyncDlg::IsURL()
873 CString str;
874 this->m_ctrlURL.GetWindowText(str);
875 if(str.Find(_T('\\'))>=0 || str.Find(_T('/'))>=0)
876 return true;
877 else
878 return false;
880 void CSyncDlg::OnCbenEndeditComboboxexUrl(NMHDR *pNMHDR, LRESULT *pResult)
882 // TODO: Add your control notification handler code here
883 *pResult = 0;
886 void CSyncDlg::OnCbnEditchangeComboboxex()
888 SetTimer(IDT_INPUT, 1000, NULL);
889 this->m_OutLogList.ShowText(_T("Wait for input"));
891 //this->FetchOutList();
892 // TODO: Add your control notification handler code here
895 UINT CSyncDlg::ProgressThread()
897 m_GitCmdStatus=CProgressDlg::RunCmdList(this,m_GitCmdList,true,NULL,&this->m_bAbort);
898 InterlockedExchange(&m_bBlock, FALSE);
899 return 0;
903 LRESULT CSyncDlg::OnProgressUpdateUI(WPARAM wParam,LPARAM lParam)
905 if(wParam == MSG_PROGRESSDLG_START)
907 m_ctrlAnimate.Play(0,-1,-1);
908 this->m_ctrlProgress.SetPos(0);
911 if(wParam == MSG_PROGRESSDLG_END || wParam == MSG_PROGRESSDLG_FAILED)
913 //m_bDone = true;
914 m_ctrlAnimate.Stop();
915 m_ctrlProgress.SetPos(100);
916 //this->DialogEnableWindow(IDOK,TRUE);
918 //if(wParam == MSG_PROGRESSDLG_END)
919 if(this->m_CurrentCmd == GIT_COMMAND_PUSH )
921 EnableControlButton(true);
922 SwitchToInput();
923 this->FetchOutList(true);
925 if(this->m_CurrentCmd == GIT_COMMAND_PULL )
927 PullComplete();
929 if(this->m_CurrentCmd == GIT_COMMAND_FETCH || this->m_CurrentCmd == GIT_COMMAND_FETCHANDREBASE)
931 FetchComplete();
933 if(this->m_CurrentCmd == GIT_COMMAND_SUBMODULE)
935 //this->m_ctrlCmdOut.SetSel(-1,-1);
936 //this->m_ctrlCmdOut.ReplaceSel(_T("Done\r\n"));
937 //this->m_ctrlCmdOut.SetSel(-1,-1);
938 EnableControlButton(true);
939 SwitchToInput();
941 if(this->m_CurrentCmd == GIT_COMMAND_REMOTE)
943 this->FetchOutList(true);
944 EnableControlButton(true);
945 SwitchToInput();
949 if(lParam != 0)
950 ParserCmdOutput((TCHAR)lParam);
952 return 0;
956 void CSyncDlg::ParserCmdOutput(char ch)
958 CProgressDlg::ParserCmdOutput(m_ctrlCmdOut,m_ctrlProgress,m_LogText,ch);
960 void CSyncDlg::OnBnClickedButtonCommit()
962 // TODO: Add your control notification handler code here
963 CString proc=CPathUtils::GetAppDirectory();
964 proc += _T("TortoiseProc.exe /command:commit");
965 proc += _T(" /path:\"");
966 proc += g_Git.m_CurrentDir;
968 CAppUtils::LaunchApplication(proc,IDS_ERROR_CANNON_FIND_TORTOISEPROC,false);
971 void CSyncDlg::OnOK()
973 // TODO: Add your specialized code here and/or call the base class
974 UpdateCombox();
975 m_ctrlURL.SaveHistory();
976 SaveHistory();
977 __super::OnOK();
980 void CSyncDlg::OnBnClickedButtonSubmodule()
982 // TODO: Add your control notification handler code here
983 // TODO: Add your control notification handler code here
984 this->UpdateData();
985 UpdateCombox();
987 this->m_regSubmoduleButton = this->m_ctrlSubmodule.GetCurrentEntry();
989 this->SwitchToRun();
991 this->m_bAbort=false;
992 this->m_GitCmdList.clear();
994 ShowTab(IDC_CMD_LOG);
996 CString cmd;
998 switch (m_ctrlSubmodule.GetCurrentEntry())
1000 case 0:
1001 cmd=_T("git.exe submodule update");
1002 break;
1003 case 1:
1004 cmd=_T("git.exe submodule init");
1005 break;
1006 case 2:
1007 cmd=_T("git.exe submodule sync");
1008 break;
1012 m_GitCmdList.push_back(cmd);
1014 m_CurrentCmd = GIT_COMMAND_SUBMODULE;
1016 m_pThread = AfxBeginThread(ProgressThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
1017 if (m_pThread==NULL)
1019 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
1021 else
1023 m_pThread->m_bAutoDelete = TRUE;
1024 m_pThread->ResumeThread();
1030 void CSyncDlg::OnTimer(UINT_PTR nIDEvent)
1032 if( nIDEvent == IDT_INPUT)
1034 KillTimer(IDT_INPUT);
1035 this->FetchOutList(true);