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
24 #include "TortoiseProc.h"
26 #include "progressdlg.h"
27 #include "MessageBox.h"
28 #include "ImportPatchDlg.h"
29 #include "PathUtils.h"
30 #include "RebaseDlg.h"
34 IMPLEMENT_DYNAMIC(CSyncDlg
, CResizableStandAloneDialog
)
36 CSyncDlg::CSyncDlg(CWnd
* pParent
/*=NULL*/)
37 : CResizableStandAloneDialog(CSyncDlg::IDD
, pParent
)
39 m_pTooltip
=&this->m_tooltips
;
42 m_bAutoLoadPuttyKey
= CAppUtils::IsSSHPutty();
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
);
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
)
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
)
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
100 CurrentEntry
= this->m_ctrlPull
.GetCurrentEntry();
101 this->m_regPullButton
= CurrentEntry
;
104 this->m_bAbort
=false;
105 this->m_GitCmdList
.clear();
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
);
121 if(this->m_strURL
.IsEmpty())
123 CMessageBox::Show(NULL
,_T("URL can't Empty"),_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
127 if(this->m_bAutoLoadPuttyKey
)
129 CAppUtils::LaunchPAgent(NULL
,&this->m_strURL
);
136 force
= _T(" --force ");
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
);
149 if(CurrentEntry
== 0) //Pull
151 cmd
.Format(_T("git.exe pull %s \"%s\" %s"),
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
);
162 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
166 m_pThread
->m_bAutoDelete
= TRUE
;
167 m_pThread
->ResumeThread();
173 if(CurrentEntry
== 1 || CurrentEntry
==2 ) //Fetch
175 CString remotebranch
;
176 if(this->IsURL() || m_strRemoteBranch
.IsEmpty())
178 remotebranch
=this->m_strRemoteBranch
;
183 remotebranch
.Format(_T("remotes/%s/%s"),
184 m_strURL
,m_strRemoteBranch
);
185 if(g_Git
.GetHash(remotebranch
).IsEmpty())
186 remotebranch
=m_strRemoteBranch
;
188 remotebranch
=m_strRemoteBranch
+_T(":")+remotebranch
;
191 cmd
.Format(_T("git.exe fetch %s \"%s\" %s"),
196 if(CurrentEntry
== 1)
197 m_CurrentCmd
= GIT_COMMAND_FETCH
;
199 m_CurrentCmd
= GIT_COMMAND_FETCHANDREBASE
;
200 m_GitCmdList
.push_back(cmd
);
202 m_pThread
= AfxBeginThread(ProgressThreadEntry
, this, THREAD_PRIORITY_NORMAL
,0,CREATE_SUSPENDED
);
205 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
209 m_pThread
->m_bAutoDelete
= TRUE
;
210 m_pThread
->ResumeThread();
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
);
226 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
227 InterlockedExchange(&m_bBlock
, FALSE
);
231 m_pThread
->m_bAutoDelete
= TRUE
;
232 m_pThread
->ResumeThread();
238 void CSyncDlg::PullComplete()
240 EnableControlButton(true);
242 this->FetchOutList(true);
245 newhash
= g_Git
.GetHash(CString(_T("HEAD")));
249 if( this ->m_GitCmdStatus
)
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
);
261 if(list
.GetCount()>0)
263 this->m_ConflictFileList
.Clear();
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
);
277 this->ShowTab(IDC_CMD_LOG
);
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);
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);
305 this->FetchOutList(true);
307 ShowTab(IDC_CMD_LOG
);
308 if( (!this->m_GitCmdStatus
) && this->m_CurrentCmd
== GIT_COMMAND_FETCHANDREBASE
)
311 dlg
.m_PostButtonTexts
.Add(_T("Email &Patch..."));
312 int response
= dlg
.DoModal();
318 if(response
== IDC_REBASE_POST_BUTTON
)
321 cmd
.Format(_T("git.exe format-patch -o \"%s\" %s..%s"),
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
);
330 CAppUtils::SendPatchMail(cmd
,out
);
335 void CSyncDlg::OnBnClickedButtonPush()
337 // TODO: Add your control notification handler code here
341 if(this->m_strURL
.IsEmpty())
343 CMessageBox::Show(NULL
,_T("URL can't Empty"),_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
347 this->m_regPushButton
=this->m_ctrlPush
.GetCurrentEntry();
349 this->m_bAbort
=false;
350 this->m_GitCmdList
.clear();
352 ShowTab(IDC_CMD_LOG
);
361 switch (m_ctrlPush
.GetCurrentEntry())
364 tags
= _T(" --tags ");
372 force
= _T(" --force ");
374 cmd
.Format(_T("git.exe push %s %s %s \"%s\" %s"),
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
);
396 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
400 m_pThread
->m_bAutoDelete
= TRUE
;
401 m_pThread
->ResumeThread();
406 void CSyncDlg::OnBnClickedButtonApply()
408 // TODO: Add your control notification handler code here
410 oldhash
=g_Git
.GetHash(CString(_T("HEAD")));
415 if(dlg
.DoModal() == IDOK
)
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
);
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);
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
,
456 this->FetchOutList(true);
460 this->m_ctrlTabCtrl
.ShowTab(IDC_CMD_LOG
-1,true);
464 this->ShowTab(IDC_CMD_LOG
);
468 this->ShowTab(IDC_IN_LOGLIST
);
473 void CSyncDlg::OnBnClickedButtonEmail()
475 // TODO: Add your control notification handler code here
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"),
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
);
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
);
504 this->m_ctrlAnimate
.Play(0,-1,-1);
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->GetDlgItem(IDC_CHECK_PUTTY_KEY
)->EnableWindow(CAppUtils::IsSSHPutty());
532 this->m_ctrlAnimate.ShowWindow(SW_NORMAL);
533 this->m_ctrlAnimate.Open(IDR_DOWNLOAD);
534 this->m_ctrlAnimate.Play(0,-1,-1);
537 // ------------------ Create Tabctrl -----------
538 CWnd
*pwnd
=this->GetDlgItem(IDC_BUTTON_TABCTRL
);
540 pwnd
->GetWindowRect(&rectDummy
);
541 this->ScreenToClient(rectDummy
);
543 if (!m_ctrlTabCtrl
.Create(CMFCTabCtrl::STYLE_FLAT
, rectDummy
, this, IDC_SYNC_TAB
))
545 TRACE0("Failed to create output tab window\n");
546 return FALSE
; // fail to create
548 m_ctrlTabCtrl
.SetResizeMode(CMFCTabCtrl::RESIZE_NO
);
550 // -------------Create Command Log Ctrl ---------
552 dwStyle
= ES_MULTILINE
| ES_READONLY
| WS_CHILD
| WS_VISIBLE
| ES_AUTOHSCROLL
| ES_AUTOVSCROLL
|WS_VSCROLL
;
554 if( !m_ctrlCmdOut
.Create(dwStyle
,rectDummy
,&m_ctrlTabCtrl
,IDC_CMD_LOG
))
556 TRACE0("Failed to create Log commits window\n");
557 return FALSE
; // fail to create
560 m_ctrlTabCtrl
.InsertTab(&m_ctrlCmdOut
,_T("Log"),-1);
562 //m_ctrlCmdOut.ReplaceSel(_T("Hello"));
564 //---------- Create in coming list ctrl -----------
565 dwStyle
=LVS_REPORT
| LVS_SHOWSELALWAYS
| LVS_ALIGNLEFT
| LVS_OWNERDATA
| WS_BORDER
| WS_TABSTOP
| WS_CHILD
| WS_VISIBLE
;;
567 if( !m_InLogList
.Create(dwStyle
,rectDummy
,&m_ctrlTabCtrl
,IDC_IN_LOGLIST
))
569 TRACE0("Failed to create output commits window\n");
570 return FALSE
; // fail to create
574 m_ctrlTabCtrl
.InsertTab(&m_InLogList
,_T("In Commits"),-1);
576 m_InLogList
.InsertGitColumn();
578 //----------- Create In Change file list -----------
579 dwStyle
= LVS_REPORT
| LVS_SHOWSELALWAYS
| LVS_ALIGNLEFT
| WS_BORDER
| WS_TABSTOP
|LVS_SINGLESEL
|WS_CHILD
| WS_VISIBLE
;
581 if( !m_InChangeFileList
.Create(dwStyle
,rectDummy
,&m_ctrlTabCtrl
,IDC_IN_CHANGELIST
))
583 TRACE0("Failed to create output change files window\n");
584 return FALSE
; // fail to create
586 m_ctrlTabCtrl
.InsertTab(&m_InChangeFileList
,_T("In ChangeList"),-1);
588 m_InChangeFileList
.Init(SVNSLC_COLEXT
| SVNSLC_COLSTATUS
|SVNSLC_COLADD
|SVNSLC_COLDEL
, _T("OutSyncDlg"),
589 (CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDSVNLC_COMPARETWO
)|
590 CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDSVNLC_GNUDIFF2
)),false);
593 //---------- Create Conflict List Ctrl -----------------
594 dwStyle
= LVS_REPORT
| LVS_SHOWSELALWAYS
| LVS_ALIGNLEFT
| WS_BORDER
| WS_TABSTOP
|LVS_SINGLESEL
|WS_CHILD
| WS_VISIBLE
;
596 if( !m_ConflictFileList
.Create(dwStyle
,rectDummy
,&m_ctrlTabCtrl
,IDC_IN_CONFLICT
))
598 TRACE0("Failed to create output change files window\n");
599 return FALSE
; // fail to create
601 m_ctrlTabCtrl
.InsertTab(&m_ConflictFileList
,_T("Conflict"),-1);
603 m_ConflictFileList
.Init(SVNSLC_COLEXT
| SVNSLC_COLSTATUS
|SVNSLC_COLADD
|SVNSLC_COLDEL
, _T("OutSyncDlg"),
604 (CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDSVNLC_COMPARETWO
)|
605 CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDSVNLC_GNUDIFF2
)|
606 SVNSLC_POPCONFLICT
|SVNSLC_POPRESOLVE
),false);
609 //---------- Create Commit Out List Ctrl---------------
611 dwStyle
=LVS_REPORT
| LVS_SHOWSELALWAYS
| LVS_ALIGNLEFT
| LVS_OWNERDATA
| WS_BORDER
| WS_TABSTOP
| WS_CHILD
| WS_VISIBLE
;;
613 if( !m_OutLogList
.Create(dwStyle
,rectDummy
,&m_ctrlTabCtrl
,IDC_OUT_LOGLIST
))
615 TRACE0("Failed to create output commits window\n");
616 return FALSE
; // fail to create
620 m_ctrlTabCtrl
.InsertTab(&m_OutLogList
,_T("Out Commits"),-1);
623 m_OutLogList
.InsertGitColumn();
625 //------------- Create Change File List Control ----------------
627 dwStyle
= LVS_REPORT
| LVS_SHOWSELALWAYS
| LVS_ALIGNLEFT
| WS_BORDER
| WS_TABSTOP
|LVS_SINGLESEL
|WS_CHILD
| WS_VISIBLE
;
629 if( !m_OutChangeFileList
.Create(dwStyle
,rectDummy
,&m_ctrlTabCtrl
,IDC_OUT_CHANGELIST
))
631 TRACE0("Failed to create output change files window\n");
632 return FALSE
; // fail to create
634 m_ctrlTabCtrl
.InsertTab(&m_OutChangeFileList
,_T("Out ChangeList"),-1);
636 m_OutChangeFileList
.Init(SVNSLC_COLEXT
| SVNSLC_COLSTATUS
|SVNSLC_COLADD
|SVNSLC_COLDEL
, _T("OutSyncDlg"),
637 (CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDSVNLC_COMPARETWO
)|
638 CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDSVNLC_GNUDIFF2
)),false);
640 this->m_tooltips
.Create(this);
642 AddAnchor(IDC_SYNC_TAB
,TOP_LEFT
,BOTTOM_RIGHT
);
644 AddAnchor(IDC_GROUP_INFO
,TOP_LEFT
,TOP_RIGHT
);
645 AddAnchor(IDC_COMBOBOXEX_URL
,TOP_LEFT
,TOP_RIGHT
);
646 AddAnchor(IDC_BUTTON_MANAGE
,TOP_RIGHT
);
647 AddAnchor(IDC_BUTTON_PULL
,BOTTOM_LEFT
);
648 AddAnchor(IDC_BUTTON_PUSH
,BOTTOM_LEFT
);
649 AddAnchor(IDC_BUTTON_SUBMODULE
,BOTTOM_LEFT
);
650 AddAnchor(IDC_BUTTON_APPLY
,BOTTOM_RIGHT
);
651 AddAnchor(IDC_BUTTON_EMAIL
,BOTTOM_RIGHT
);
652 AddAnchor(IDC_PROGRESS_SYNC
,TOP_LEFT
,TOP_RIGHT
);
653 AddAnchor(IDOK
,BOTTOM_RIGHT
);
654 AddAnchor(IDHELP
,BOTTOM_RIGHT
);
655 AddAnchor(IDC_STATIC_STATUS
,BOTTOM_LEFT
);
656 AddAnchor(IDC_ANIMATE_SYNC
,TOP_LEFT
);
657 AddAnchor(IDC_BUTTON_COMMIT
,BOTTOM_LEFT
);
659 BRANCH_COMBOX_ADD_ANCHOR();
661 this->GetDlgItem(IDC_BUTTON_COMMIT
)->ShowWindow(SW_HIDE
);
663 CString WorkingDir
=g_Git
.m_CurrentDir
;
664 WorkingDir
.Replace(_T(':'),_T('_'));
665 m_RegKeyRemoteBranch
= CString(_T("Software\\TortoiseGit\\History\\SyncBranch\\"))+WorkingDir
;
668 this->AddOthersToAnchor();
669 // TODO: Add extra initialization here
671 this->m_ctrlPush
.AddEntry(CString(_T("Pus&h")));
672 this->m_ctrlPush
.AddEntry(CString(_T("Push ta&gs")));
673 ///this->m_ctrlPush.AddEntry(CString(_T("Push All")));
675 this->m_ctrlPull
.AddEntry(CString(_T("&Pull")));
676 this->m_ctrlPull
.AddEntry(CString(_T("Fetc&h")));
677 this->m_ctrlPull
.AddEntry(CString(_T("Fetch&&Re&base")));
678 this->m_ctrlPull
.AddEntry(CString(_T("Remote Update")));
680 this->m_ctrlSubmodule
.AddEntry(CString(_T("Submodule Update")));
681 this->m_ctrlSubmodule
.AddEntry(CString(_T("Submodule Init")));
682 this->m_ctrlSubmodule
.AddEntry(CString(_T("Submodule Sync")));
684 WorkingDir
.Replace(_T(':'),_T('_'));
687 regkey
.Format(_T("Software\\TortoiseGit\\TortoiseProc\\Sync\\%s"),WorkingDir
);
689 this->m_regPullButton
= CRegDWORD(regkey
+_T("\\Pull"),0);
690 this->m_regPushButton
= CRegDWORD(regkey
+_T("\\Push"),0);
691 this->m_regSubmoduleButton
= CRegDWORD(regkey
+_T("\\Submodule"));
692 this->m_regAutoLoadPutty
= CRegDWORD(regkey
+ _T("\\AutoLoadPutty"), CAppUtils::IsSSHPutty());
695 this->m_bAutoLoadPuttyKey
= m_regAutoLoadPutty
;
696 if(!CAppUtils::IsSSHPutty())
697 m_bAutoLoadPuttyKey
= false;
698 this->UpdateData(FALSE
);
700 this->m_ctrlPull
.SetCurrentEntry(this->m_regPullButton
);
701 this->m_ctrlPush
.SetCurrentEntry(this->m_regPushButton
);
702 this->m_ctrlSubmodule
.SetCurrentEntry(this->m_regSubmoduleButton
);
705 this->GetWindowText(str
);
706 str
+= _T(" - ") + g_Git
.m_CurrentDir
;
707 this->SetWindowText(str
);
709 EnableSaveRestore(_T("SyncDlg"));
711 this->m_ctrlURL
.LoadHistory(CString(_T("Software\\TortoiseGit\\History\\SyncURL\\"))+WorkingDir
, _T("url"));
715 if(!g_Git
.GetRemoteList(list
))
717 for(unsigned int i
=0;i
<list
.size();i
++)
719 m_ctrlURL
.AddString(list
[i
]);
722 m_ctrlURL
.SetCurSel(0);
723 m_ctrlRemoteBranch
.SetCurSel(0);
724 m_ctrlURL
.SetURLHistory(true);
726 this->LoadBranchInfo();
728 this->m_bInited
=true;
731 m_ctrlTabCtrl
.ShowTab(IDC_CMD_LOG
-1,false);
732 m_ctrlTabCtrl
.ShowTab(IDC_IN_LOGLIST
-1,false);
733 m_ctrlTabCtrl
.ShowTab(IDC_IN_CHANGELIST
-1,false);
734 m_ctrlTabCtrl
.ShowTab(IDC_IN_CONFLICT
-1,false);
737 m_ctrlRemoteBranch
.m_bWantReturn
= TRUE
;
738 m_ctrlURL
.m_bWantReturn
= TRUE
;
740 return TRUE
; // return TRUE unless you set the focus to a control
741 // EXCEPTION: OCX Property Pages should return FALSE
744 void CSyncDlg::OnBnClickedButtonManage()
746 // TODO: Add your control notification handler code here
747 CAppUtils::LaunchRemoteSetting();
750 void CSyncDlg::Refresh()
752 theApp
.DoWaitCursor(1);
757 this->m_ctrlLocalBranch
.GetWindowText(local
);
758 this->m_ctrlRemoteBranch
.GetWindowText(remote
);
759 this->m_ctrlURL
.GetWindowText(url
);
761 this->LoadBranchInfo();
763 this->m_ctrlLocalBranch
.AddString(local
);
764 this->m_ctrlRemoteBranch
.AddString(remote
);
765 this->m_ctrlURL
.AddString(url
);
767 m_OutLogList
.ShowText(_T("Refresh ..."));
768 this->FetchOutList(true);
769 theApp
.DoWaitCursor(-1);
772 BOOL
CSyncDlg::PreTranslateMessage(MSG
* pMsg
)
774 // TODO: Add your specialized code here and/or call the base class
776 if (pMsg
->message
== WM_KEYDOWN
)
778 switch (pMsg
->wParam
)
784 return CResizableStandAloneDialog::PreTranslateMessage(pMsg
);
789 /* Avoid TAB control destroy but dialog exist*/
794 ::GetClassName(pMsg
->hwnd
,buff
,128);
796 if(_tcsnicmp(buff
,_T("RichEdit20W"),128)==0)
798 this->PostMessage(WM_KEYDOWN
,VK_ESCAPE
,0);
804 m_tooltips
.RelayEvent(pMsg
);
805 return __super::PreTranslateMessage(pMsg
);
807 void CSyncDlg::FetchOutList(bool force
)
811 m_OutChangeFileList
.Clear();
812 this->m_OutLogList
.Clear();
815 this->m_ctrlURL
.GetWindowText(remote
);
816 CString remotebranch
;
817 this->m_ctrlRemoteBranch
.GetWindowText(remotebranch
);
818 remotebranch
=remote
+_T("/")+remotebranch
;
823 str
=_T("Don't know what will push because you enter URL");
824 m_OutLogList
.ShowText(str
);
825 this->m_ctrlTabCtrl
.ShowTab(m_OutChangeFileList
.GetDlgCtrlID()-1,FALSE
);
826 m_OutLocalBranch
.Empty();
827 m_OutRemoteBranch
.Empty();
829 this->GetDlgItem(IDC_BUTTON_EMAIL
)->EnableWindow(FALSE
);
832 }else if(g_Git
.GetHash(remotebranch
).GetLength()<40)
835 str
.Format(_T("Don't know what will push because unknown \"%s\""),remotebranch
);
836 m_OutLogList
.ShowText(str
);
837 this->m_ctrlTabCtrl
.ShowTab(m_OutChangeFileList
.GetDlgCtrlID()-1,FALSE
);
838 m_OutLocalBranch
.Empty();
839 m_OutRemoteBranch
.Empty();
841 this->GetDlgItem(IDC_BUTTON_EMAIL
)->EnableWindow(FALSE
);
847 localbranch
=this->m_ctrlLocalBranch
.GetString();
849 if(localbranch
!= m_OutLocalBranch
|| m_OutRemoteBranch
!= remotebranch
|| force
)
851 m_OutLogList
.ClearText();
852 m_OutLogList
.FillGitLog(NULL
,CGit:: LOG_INFO_STAT
| CGit::LOG_INFO_FILESTATE
| CGit::LOG_INFO_SHOW_MERGEDFILE
,
853 &remotebranch
,&localbranch
);
856 if(m_OutLogList
.GetItemCount() == 0)
858 str
.Format(_T("No commits ahead \"%s\""),remotebranch
);
859 m_OutLogList
.ShowText(str
);
860 this->m_ctrlStatus
.SetWindowText(str
);
861 this->m_ctrlTabCtrl
.ShowTab(m_OutChangeFileList
.GetDlgCtrlID()-1,FALSE
);
862 this->GetDlgItem(IDC_BUTTON_EMAIL
)->EnableWindow(FALSE
);
866 str
.Format(_T("%d commits ahead \"%s\""),m_OutLogList
.GetItemCount(),remotebranch
);
867 this->m_ctrlStatus
.SetWindowText(str
);
869 AddDiffFileList(&m_OutChangeFileList
,&m_arOutChangeList
,localbranch
,remotebranch
);
871 this->m_ctrlTabCtrl
.ShowTab(m_OutChangeFileList
.GetDlgCtrlID()-1,TRUE
);
872 this->GetDlgItem(IDC_BUTTON_EMAIL
)->EnableWindow(TRUE
);
875 this->m_OutLocalBranch
=localbranch
;
876 this->m_OutRemoteBranch
=remotebranch
;
881 bool CSyncDlg::IsURL()
884 this->m_ctrlURL
.GetWindowText(str
);
885 if(str
.Find(_T('\\'))>=0 || str
.Find(_T('/'))>=0)
890 void CSyncDlg::OnCbenEndeditComboboxexUrl(NMHDR
*pNMHDR
, LRESULT
*pResult
)
892 // TODO: Add your control notification handler code here
896 void CSyncDlg::OnCbnEditchangeComboboxex()
898 SetTimer(IDT_INPUT
, 1000, NULL
);
899 this->m_OutLogList
.ShowText(_T("Wait for input"));
901 //this->FetchOutList();
902 // TODO: Add your control notification handler code here
905 UINT
CSyncDlg::ProgressThread()
907 m_GitCmdStatus
=CProgressDlg::RunCmdList(this,m_GitCmdList
,true,NULL
,&this->m_bAbort
);
908 InterlockedExchange(&m_bBlock
, FALSE
);
913 LRESULT
CSyncDlg::OnProgressUpdateUI(WPARAM wParam
,LPARAM lParam
)
915 if(wParam
== MSG_PROGRESSDLG_START
)
917 m_ctrlAnimate
.Play(0,-1,-1);
918 this->m_ctrlProgress
.SetPos(0);
921 if(wParam
== MSG_PROGRESSDLG_END
|| wParam
== MSG_PROGRESSDLG_FAILED
)
924 m_ctrlAnimate
.Stop();
925 m_ctrlProgress
.SetPos(100);
926 //this->DialogEnableWindow(IDOK,TRUE);
928 //if(wParam == MSG_PROGRESSDLG_END)
929 if(this->m_CurrentCmd
== GIT_COMMAND_PUSH
)
931 EnableControlButton(true);
933 this->FetchOutList(true);
935 if(this->m_CurrentCmd
== GIT_COMMAND_PULL
)
939 if(this->m_CurrentCmd
== GIT_COMMAND_FETCH
|| this->m_CurrentCmd
== GIT_COMMAND_FETCHANDREBASE
)
943 if(this->m_CurrentCmd
== GIT_COMMAND_SUBMODULE
)
945 //this->m_ctrlCmdOut.SetSel(-1,-1);
946 //this->m_ctrlCmdOut.ReplaceSel(_T("Done\r\n"));
947 //this->m_ctrlCmdOut.SetSel(-1,-1);
948 EnableControlButton(true);
951 if(this->m_CurrentCmd
== GIT_COMMAND_REMOTE
)
953 this->FetchOutList(true);
954 EnableControlButton(true);
960 ParserCmdOutput((TCHAR
)lParam
);
966 void CSyncDlg::ParserCmdOutput(char ch
)
968 CProgressDlg::ParserCmdOutput(m_ctrlCmdOut
,m_ctrlProgress
,m_LogText
,ch
);
970 void CSyncDlg::OnBnClickedButtonCommit()
972 // TODO: Add your control notification handler code here
973 CString proc
=CPathUtils::GetAppDirectory();
974 proc
+= _T("TortoiseProc.exe /command:commit");
975 proc
+= _T(" /path:\"");
976 proc
+= g_Git
.m_CurrentDir
;
978 CAppUtils::LaunchApplication(proc
,IDS_ERROR_CANNON_FIND_TORTOISEPROC
,false);
981 void CSyncDlg::OnOK()
983 // TODO: Add your specialized code here and/or call the base class
986 m_ctrlURL
.SaveHistory();
988 m_regAutoLoadPutty
= this->m_bAutoLoadPuttyKey
;
992 void CSyncDlg::OnBnClickedButtonSubmodule()
994 // TODO: Add your control notification handler code here
995 // TODO: Add your control notification handler code here
999 this->m_regSubmoduleButton
= this->m_ctrlSubmodule
.GetCurrentEntry();
1001 this->SwitchToRun();
1003 this->m_bAbort
=false;
1004 this->m_GitCmdList
.clear();
1006 ShowTab(IDC_CMD_LOG
);
1010 switch (m_ctrlSubmodule
.GetCurrentEntry())
1013 cmd
=_T("git.exe submodule update");
1016 cmd
=_T("git.exe submodule init");
1019 cmd
=_T("git.exe submodule sync");
1024 m_GitCmdList
.push_back(cmd
);
1026 m_CurrentCmd
= GIT_COMMAND_SUBMODULE
;
1028 m_pThread
= AfxBeginThread(ProgressThreadEntry
, this, THREAD_PRIORITY_NORMAL
,0,CREATE_SUSPENDED
);
1029 if (m_pThread
==NULL
)
1031 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
1035 m_pThread
->m_bAutoDelete
= TRUE
;
1036 m_pThread
->ResumeThread();
1042 void CSyncDlg::OnTimer(UINT_PTR nIDEvent
)
1044 if( nIDEvent
== IDT_INPUT
)
1046 KillTimer(IDT_INPUT
);
1047 this->FetchOutList(true);