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();
49 void CSyncDlg::DoDataExchange(CDataExchange
* pDX
)
51 CDialog::DoDataExchange(pDX
);
52 DDX_Check(pDX
, IDC_CHECK_PUTTY_KEY
, m_bAutoLoadPuttyKey
);
53 DDX_Check(pDX
, IDC_CHECK_FORCE
,m_bForce
);
54 DDX_Control(pDX
, IDC_COMBOBOXEX_URL
, m_ctrlURL
);
55 DDX_Control(pDX
, IDC_BUTTON_TABCTRL
, m_ctrlDumyButton
);
56 DDX_Control(pDX
, IDC_BUTTON_PULL
, m_ctrlPull
);
57 DDX_Control(pDX
, IDC_BUTTON_PUSH
, m_ctrlPush
);
58 DDX_Control(pDX
, IDC_STATIC_STATUS
, m_ctrlStatus
);
59 DDX_Control(pDX
, IDC_PROGRESS_SYNC
, m_ctrlProgress
);
60 DDX_Control(pDX
, IDC_ANIMATE_SYNC
, m_ctrlAnimate
);
66 BEGIN_MESSAGE_MAP(CSyncDlg
, CResizableStandAloneDialog
)
67 ON_BN_CLICKED(IDC_BUTTON_PULL
, &CSyncDlg::OnBnClickedButtonPull
)
68 ON_BN_CLICKED(IDC_BUTTON_PUSH
, &CSyncDlg::OnBnClickedButtonPush
)
69 ON_BN_CLICKED(IDC_BUTTON_APPLY
, &CSyncDlg::OnBnClickedButtonApply
)
70 ON_BN_CLICKED(IDC_BUTTON_EMAIL
, &CSyncDlg::OnBnClickedButtonEmail
)
71 ON_BN_CLICKED(IDC_BUTTON_MANAGE
, &CSyncDlg::OnBnClickedButtonManage
)
73 ON_NOTIFY(CBEN_ENDEDIT
, IDC_COMBOBOXEX_URL
, &CSyncDlg::OnCbenEndeditComboboxexUrl
)
74 ON_CBN_EDITCHANGE(IDC_COMBOBOXEX_URL
, &CSyncDlg::OnCbnEditchangeComboboxexUrl
)
75 ON_MESSAGE(MSG_PROGRESSDLG_UPDATE_UI
, OnProgressUpdateUI
)
76 ON_BN_CLICKED(IDC_BUTTON_COMMIT
, &CSyncDlg::OnBnClickedButtonCommit
)
80 void CSyncDlg::EnableControlButton(bool bEnabled
)
82 GetDlgItem(IDC_BUTTON_PULL
)->EnableWindow(bEnabled
);
83 GetDlgItem(IDC_BUTTON_PUSH
)->EnableWindow(bEnabled
);
84 GetDlgItem(IDC_BUTTON_APPLY
)->EnableWindow(bEnabled
);
85 GetDlgItem(IDC_BUTTON_EMAIL
)->EnableWindow(bEnabled
);
86 GetDlgItem(IDOK
)->EnableWindow(bEnabled
);
88 // CSyncDlg message handlers
90 void CSyncDlg::OnBnClickedButtonPull()
92 // TODO: Add your control notification handler code here
94 CurrentEntry
= this->m_ctrlPull
.GetCurrentEntry();
95 this->m_regPullButton
= CurrentEntry
;
99 this->m_GitCmdList
.clear();
104 m_oldHash
= g_Git
.GetHash(CString(_T("HEAD")));
106 if( CurrentEntry
== 0)
108 if( g_Git
.GetHash(this->m_strLocalBranch
) != m_oldHash
)
110 CMessageBox::Show(NULL
,_T("Pull require local branch must be current branch"),_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
115 if(this->m_strURL
.IsEmpty())
117 CMessageBox::Show(NULL
,_T("URL can't Empty"),_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
121 if(this->m_bAutoLoadPuttyKey
)
123 CAppUtils::LaunchPAgent(NULL
,&this->m_strURL
);
130 force
= _T(" --force ");
134 ShowTab(IDC_CMD_LOG
);
136 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_LOGLIST
-1,false);
137 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_CHANGELIST
-1,false);
138 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_CONFLICT
-1,false);
140 this->GetDlgItem(IDC_BUTTON_COMMIT
)->ShowWindow(SW_HIDE
);
143 if(CurrentEntry
== 0) //Pull
145 cmd
.Format(_T("git.exe pull %s \"%s\" %s"),
148 this->m_strRemoteBranch
);
150 m_CurrentCmd
= GIT_COMMAND_PULL
;
151 m_GitCmdList
.push_back(cmd
);
153 m_pThread
= AfxBeginThread(ProgressThreadEntry
, this, THREAD_PRIORITY_NORMAL
,0,CREATE_SUSPENDED
);
156 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
160 m_pThread
->m_bAutoDelete
= TRUE
;
161 m_pThread
->ResumeThread();
167 if(CurrentEntry
== 1 || CurrentEntry
==2 ) //Fetch
169 cmd
.Format(_T("git.exe fetch %s \"%s\" %s"),
172 this->m_strRemoteBranch
);
173 if(CurrentEntry
== 1)
174 m_CurrentCmd
= GIT_COMMAND_FETCH
;
176 m_CurrentCmd
= GIT_COMMAND_FETCHANDREBASE
;
177 m_GitCmdList
.push_back(cmd
);
179 m_pThread
= AfxBeginThread(ProgressThreadEntry
, this, THREAD_PRIORITY_NORMAL
,0,CREATE_SUSPENDED
);
182 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
186 m_pThread
->m_bAutoDelete
= TRUE
;
187 m_pThread
->ResumeThread();
195 void CSyncDlg::PullComplete()
197 EnableControlButton(true);
199 this->FetchOutList(true);
202 newhash
= g_Git
.GetHash(CString(_T("HEAD")));
206 if( this ->m_GitCmdStatus
)
209 if(g_Git
.ListConflictFile(list
))
211 this->m_ctrlCmdOut
.SetSel(-1,-1);
212 this->m_ctrlCmdOut
.ReplaceSel(_T("Get conflict files fail\n"));
214 this->ShowTab(IDC_CMD_LOG
);
218 if(list
.GetCount()>0)
220 this->m_ConflictFileList
.Clear();
225 this->m_ConflictFileList
.GetStatus(&list
,true);
226 this->m_ConflictFileList
.Show(CTGitPath::LOGACTIONS_UNMERGED
,
227 CTGitPath::LOGACTIONS_UNMERGED
);
229 this->ShowTab(IDC_IN_CONFLICT
);
231 this->GetDlgItem(IDC_BUTTON_COMMIT
)->ShowWindow(SW_NORMAL
);
234 this->ShowTab(IDC_CMD_LOG
);
238 if(newhash
== this->m_oldHash
)
240 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_CHANGELIST
-1,false);
241 this->m_InLogList
.ShowText(_T("No commits get after pull"));
242 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_LOGLIST
-1,true);
246 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_CHANGELIST
-1,true);
247 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_LOGLIST
-1,true);
249 this->AddDiffFileList(&m_InChangeFileList
,&m_arInChangeList
,newhash
,m_oldHash
);
251 m_InLogList
.FillGitLog(NULL
,CGit:: LOG_INFO_STAT
| CGit::LOG_INFO_FILESTATE
| CGit::LOG_INFO_SHOW_MERGEDFILE
,
252 &this->m_oldHash
,&newhash
);
254 this->ShowTab(IDC_IN_LOGLIST
);
258 void CSyncDlg::FetchComplete()
260 EnableControlButton(true);
262 this->FetchOutList(true);
264 ShowTab(IDC_CMD_LOG
);
265 if( (!this->m_GitCmdStatus
) && this->m_CurrentCmd
== GIT_COMMAND_FETCHANDREBASE
)
268 dlg
.m_PostButtonText
=_T("Email &Patch...");
269 int response
= dlg
.DoModal();
275 if(response
== IDC_REBASE_POST_BUTTON
)
278 cmd
.Format(_T("git.exe format-patch -o \"%s\" %s..%s"),
280 dlg
.m_Upstream
,dlg
.m_Branch
);
281 if(g_Git
.Run(cmd
,&out
,CP_ACP
))
283 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
287 CAppUtils::SendPatchMail(cmd
,out
);
292 void CSyncDlg::OnBnClickedButtonPush()
294 // TODO: Add your control notification handler code here
298 if(this->m_strURL
.IsEmpty())
300 CMessageBox::Show(NULL
,_T("URL can't Empty"),_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
304 this->m_regPushButton
=this->m_ctrlPush
.GetCurrentEntry();
306 this->m_bAbort
=false;
307 this->m_GitCmdList
.clear();
309 ShowTab(IDC_CMD_LOG
);
318 switch (m_ctrlPush
.GetCurrentEntry())
321 tags
= _T(" --tags ");
329 force
= _T(" --force ");
331 cmd
.Format(_T("git.exe push %s %s %s \"%s\" %s"),
336 if (!m_strRemoteBranch
.IsEmpty())
338 cmd
+= _T(":") + m_strRemoteBranch
;
341 m_GitCmdList
.push_back(cmd
);
343 m_CurrentCmd
= GIT_COMMAND_PUSH
;
345 if(this->m_bAutoLoadPuttyKey
)
347 CAppUtils::LaunchPAgent(NULL
,&this->m_strURL
);
350 m_pThread
= AfxBeginThread(ProgressThreadEntry
, this, THREAD_PRIORITY_NORMAL
,0,CREATE_SUSPENDED
);
353 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
357 m_pThread
->m_bAutoDelete
= TRUE
;
358 m_pThread
->ResumeThread();
363 void CSyncDlg::OnBnClickedButtonApply()
365 // TODO: Add your control notification handler code here
367 oldhash
=g_Git
.GetHash(CString(_T("HEAD")));
372 if(dlg
.DoModal() == IDOK
)
375 for(int i
=0;i
<dlg
.m_PathList
.GetCount();i
++)
377 cmd
.Format(_T("git.exe am \"%s\""),dlg
.m_PathList
[i
].GetGitPathString());
379 if(g_Git
.Run(cmd
,&output
,CP_ACP
))
381 CMessageBox::Show(NULL
,output
,_T("TortoiseGit"),MB_OK
);
386 this->m_ctrlCmdOut
.SetSel(-1,-1);
387 this->m_ctrlCmdOut
.ReplaceSel(cmd
+_T("\n"));
388 this->m_ctrlCmdOut
.SetSel(-1,-1);
389 this->m_ctrlCmdOut
.ReplaceSel(output
);
393 CString newhash
=g_Git
.GetHash(CString(_T("HEAD")));
395 this->m_InLogList
.Clear();
396 this->m_InChangeFileList
.Clear();
398 if(newhash
== oldhash
)
400 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_CHANGELIST
-1,false);
401 this->m_InLogList
.ShowText(_T("No commits get from patch"));
402 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_LOGLIST
-1,true);
406 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_CHANGELIST
-1,true);
407 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_LOGLIST
-1,true);
409 this->AddDiffFileList(&m_InChangeFileList
,&m_arInChangeList
,newhash
,oldhash
);
410 m_InLogList
.FillGitLog(NULL
,CGit:: LOG_INFO_STAT
| CGit::LOG_INFO_FILESTATE
| CGit::LOG_INFO_SHOW_MERGEDFILE
,
413 this->FetchOutList(true);
417 this->m_ctrlTabCtrl
.ShowTab(IDC_CMD_LOG
-1,true);
421 this->ShowTab(IDC_CMD_LOG
);
425 this->ShowTab(IDC_IN_LOGLIST
);
430 void CSyncDlg::OnBnClickedButtonEmail()
432 // TODO: Add your control notification handler code here
435 this->m_strLocalBranch
= this->m_ctrlLocalBranch
.GetString();
436 this->m_ctrlRemoteBranch
.GetWindowText(this->m_strRemoteBranch
);
437 this->m_ctrlURL
.GetWindowText(this->m_strURL
);
438 m_strURL
=m_strURL
.Trim();
439 m_strRemoteBranch
=m_strRemoteBranch
.Trim();
441 cmd
.Format(_T("git.exe format-patch -o \"%s\" %s..%s"),
443 m_strURL
+_T('/')+m_strRemoteBranch
,m_strLocalBranch
);
445 if(g_Git
.Run(cmd
,&out
,CP_ACP
))
447 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
451 CAppUtils::SendPatchMail(cmd
,out
);
454 void CSyncDlg::ShowProgressCtrl(bool bShow
)
456 int b
=bShow
?SW_NORMAL
:SW_HIDE
;
457 this->m_ctrlAnimate
.ShowWindow(b
);
458 this->m_ctrlProgress
.ShowWindow(b
);
459 this->m_ctrlAnimate
.Open(IDR_DOWNLOAD
);
461 this->m_ctrlAnimate
.Play(0,-1,-1);
463 this->m_ctrlAnimate
.Stop();
465 void CSyncDlg::ShowInputCtrl(bool bShow
)
467 int b
=bShow
?SW_NORMAL
:SW_HIDE
;
468 this->m_ctrlURL
.ShowWindow(b
);
469 this->m_ctrlLocalBranch
.ShowWindow(b
);
470 this->m_ctrlRemoteBranch
.ShowWindow(b
);
471 this->GetDlgItem(IDC_BUTTON_LOCAL_BRANCH
)->ShowWindow(b
);
472 this->GetDlgItem(IDC_BUTTON_REMOTE_BRANCH
)->ShowWindow(b
);
473 this->GetDlgItem(IDC_STATIC_LOCAL_BRANCH
)->ShowWindow(b
);
474 this->GetDlgItem(IDC_STATIC_REMOTE_BRANCH
)->ShowWindow(b
);
475 this->GetDlgItem(IDC_BUTTON_MANAGE
)->ShowWindow(b
);
476 this->GetDlgItem(IDC_CHECK_PUTTY_KEY
)->ShowWindow(b
);
477 this->GetDlgItem(IDC_CHECK_FORCE
)->ShowWindow(b
);
478 this->GetDlgItem(IDC_STATIC_REMOTE_URL
)->ShowWindow(b
);
481 BOOL
CSyncDlg::OnInitDialog()
483 CResizableStandAloneDialog::OnInitDialog();
486 this->m_ctrlAnimate.ShowWindow(SW_NORMAL);
487 this->m_ctrlAnimate.Open(IDR_DOWNLOAD);
488 this->m_ctrlAnimate.Play(0,-1,-1);
491 // ------------------ Create Tabctrl -----------
492 CWnd
*pwnd
=this->GetDlgItem(IDC_BUTTON_TABCTRL
);
494 pwnd
->GetWindowRect(&rectDummy
);
495 this->ScreenToClient(rectDummy
);
497 if (!m_ctrlTabCtrl
.Create(CMFCTabCtrl::STYLE_FLAT
, rectDummy
, this, IDC_SYNC_TAB
))
499 TRACE0("Failed to create output tab window\n");
500 return FALSE
; // fail to create
502 m_ctrlTabCtrl
.SetResizeMode(CMFCTabCtrl::RESIZE_NO
);
504 // -------------Create Command Log Ctrl ---------
506 dwStyle
= ES_MULTILINE
| ES_READONLY
| WS_CHILD
| WS_VISIBLE
| ES_AUTOHSCROLL
| ES_AUTOVSCROLL
|WS_VSCROLL
;
508 if( !m_ctrlCmdOut
.Create(dwStyle
,rectDummy
,&m_ctrlTabCtrl
,IDC_CMD_LOG
))
510 TRACE0("Failed to create Log commits window\n");
511 return FALSE
; // fail to create
514 m_ctrlTabCtrl
.InsertTab(&m_ctrlCmdOut
,_T("Log"),-1);
516 //m_ctrlCmdOut.ReplaceSel(_T("Hello"));
518 //---------- Create in coming list ctrl -----------
519 dwStyle
=LVS_REPORT
| LVS_SHOWSELALWAYS
| LVS_ALIGNLEFT
| LVS_OWNERDATA
| WS_BORDER
| WS_TABSTOP
| WS_CHILD
| WS_VISIBLE
;;
521 if( !m_InLogList
.Create(dwStyle
,rectDummy
,&m_ctrlTabCtrl
,IDC_IN_LOGLIST
))
523 TRACE0("Failed to create output commits window\n");
524 return FALSE
; // fail to create
528 m_ctrlTabCtrl
.InsertTab(&m_InLogList
,_T("In Commits"),-1);
530 m_InLogList
.InsertGitColumn();
532 //----------- Create In Change file list -----------
533 dwStyle
= LVS_REPORT
| LVS_SHOWSELALWAYS
| LVS_ALIGNLEFT
| WS_BORDER
| WS_TABSTOP
|LVS_SINGLESEL
|WS_CHILD
| WS_VISIBLE
;
535 if( !m_InChangeFileList
.Create(dwStyle
,rectDummy
,&m_ctrlTabCtrl
,IDC_IN_CHANGELIST
))
537 TRACE0("Failed to create output change files window\n");
538 return FALSE
; // fail to create
540 m_ctrlTabCtrl
.InsertTab(&m_InChangeFileList
,_T("In ChangeList"),-1);
542 m_InChangeFileList
.Init(SVNSLC_COLEXT
| SVNSLC_COLSTATUS
|SVNSLC_COLADD
|SVNSLC_COLDEL
, _T("OutSyncDlg"),
543 (CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDSVNLC_COMPARETWO
)|
544 CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDSVNLC_GNUDIFF2
)),false);
547 //---------- Create Conflict List Ctrl -----------------
548 dwStyle
= LVS_REPORT
| LVS_SHOWSELALWAYS
| LVS_ALIGNLEFT
| WS_BORDER
| WS_TABSTOP
|LVS_SINGLESEL
|WS_CHILD
| WS_VISIBLE
;
550 if( !m_ConflictFileList
.Create(dwStyle
,rectDummy
,&m_ctrlTabCtrl
,IDC_IN_CONFLICT
))
552 TRACE0("Failed to create output change files window\n");
553 return FALSE
; // fail to create
555 m_ctrlTabCtrl
.InsertTab(&m_ConflictFileList
,_T("Conflict"),-1);
557 m_ConflictFileList
.Init(SVNSLC_COLEXT
| SVNSLC_COLSTATUS
|SVNSLC_COLADD
|SVNSLC_COLDEL
, _T("OutSyncDlg"),
558 (CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDSVNLC_COMPARETWO
)|
559 CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDSVNLC_GNUDIFF2
)|
560 SVNSLC_POPCONFLICT
|SVNSLC_POPRESOLVE
),false);
563 //---------- Create Commit Out List Ctrl---------------
565 dwStyle
=LVS_REPORT
| LVS_SHOWSELALWAYS
| LVS_ALIGNLEFT
| LVS_OWNERDATA
| WS_BORDER
| WS_TABSTOP
| WS_CHILD
| WS_VISIBLE
;;
567 if( !m_OutLogList
.Create(dwStyle
,rectDummy
,&m_ctrlTabCtrl
,IDC_OUT_LOGLIST
))
569 TRACE0("Failed to create output commits window\n");
570 return FALSE
; // fail to create
574 m_ctrlTabCtrl
.InsertTab(&m_OutLogList
,_T("Out Commits"),-1);
577 m_OutLogList
.InsertGitColumn();
579 //------------- Create Change File List Control ----------------
581 dwStyle
= LVS_REPORT
| LVS_SHOWSELALWAYS
| LVS_ALIGNLEFT
| WS_BORDER
| WS_TABSTOP
|LVS_SINGLESEL
|WS_CHILD
| WS_VISIBLE
;
583 if( !m_OutChangeFileList
.Create(dwStyle
,rectDummy
,&m_ctrlTabCtrl
,IDC_OUT_CHANGELIST
))
585 TRACE0("Failed to create output change files window\n");
586 return FALSE
; // fail to create
588 m_ctrlTabCtrl
.InsertTab(&m_OutChangeFileList
,_T("Out ChangeList"),-1);
590 m_OutChangeFileList
.Init(SVNSLC_COLEXT
| SVNSLC_COLSTATUS
|SVNSLC_COLADD
|SVNSLC_COLDEL
, _T("OutSyncDlg"),
591 (CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDSVNLC_COMPARETWO
)|
592 CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDSVNLC_GNUDIFF2
)),false);
594 this->m_tooltips
.Create(this);
596 AddAnchor(IDC_SYNC_TAB
,TOP_LEFT
,BOTTOM_RIGHT
);
598 AddAnchor(IDC_GROUP_INFO
,TOP_LEFT
,TOP_RIGHT
);
599 AddAnchor(IDC_COMBOBOXEX_URL
,TOP_LEFT
,TOP_RIGHT
);
600 AddAnchor(IDC_BUTTON_MANAGE
,TOP_RIGHT
);
601 AddAnchor(IDC_BUTTON_PULL
,BOTTOM_LEFT
);
602 AddAnchor(IDC_BUTTON_PUSH
,BOTTOM_LEFT
);
603 AddAnchor(IDC_BUTTON_APPLY
,BOTTOM_LEFT
);
604 AddAnchor(IDC_BUTTON_EMAIL
,BOTTOM_LEFT
);
605 AddAnchor(IDC_PROGRESS_SYNC
,TOP_LEFT
,TOP_RIGHT
);
606 AddAnchor(IDOK
,BOTTOM_RIGHT
);
607 AddAnchor(IDHELP
,BOTTOM_RIGHT
);
608 AddAnchor(IDC_STATIC_STATUS
,BOTTOM_LEFT
);
609 AddAnchor(IDC_ANIMATE_SYNC
,TOP_LEFT
);
610 AddAnchor(IDC_BUTTON_COMMIT
,BOTTOM_LEFT
);
612 BRANCH_COMBOX_ADD_ANCHOR();
614 this->GetDlgItem(IDC_BUTTON_COMMIT
)->ShowWindow(SW_HIDE
);
616 CString WorkingDir
=g_Git
.m_CurrentDir
;
617 WorkingDir
.Replace(_T(':'),_T('_'));
618 m_RegKeyRemoteBranch
= CString(_T("Software\\TortoiseGit\\History\\SyncBranch\\"))+WorkingDir
;
621 this->AddOthersToAnchor();
622 // TODO: Add extra initialization here
624 this->m_ctrlPush
.AddEntry(CString(_T("Pus&h")));
625 this->m_ctrlPush
.AddEntry(CString(_T("Push ta&gs")));
626 ///this->m_ctrlPush.AddEntry(CString(_T("Push All")));
628 this->m_ctrlPull
.AddEntry(CString(_T("&Pull")));
629 this->m_ctrlPull
.AddEntry(CString(_T("Fetc&h")));
630 this->m_ctrlPull
.AddEntry(CString(_T("Fetch&&Re&base")));
633 WorkingDir
.Replace(_T(':'),_T('_'));
636 regkey
.Format(_T("Software\\TortoiseGit\\TortoiseProc\\Sync\\%s"),WorkingDir
);
638 this->m_regPullButton
= CRegDWORD(regkey
+_T("\\Pull"),0);
639 this->m_regPushButton
= CRegDWORD(regkey
+_T("\\Push"),0);
641 this->m_ctrlPull
.SetCurrentEntry(this->m_regPullButton
);
642 this->m_ctrlPush
.SetCurrentEntry(this->m_regPushButton
);
645 this->GetWindowText(str
);
646 str
+= _T(" - ") + g_Git
.m_CurrentDir
;
647 this->SetWindowText(str
);
649 EnableSaveRestore(_T("SyncDlg"));
651 this->m_ctrlURL
.LoadHistory(CString(_T("Software\\TortoiseGit\\History\\SyncURL\\"))+WorkingDir
, _T("url"));
653 m_ctrlURL
.SetCurSel(0);
654 m_ctrlRemoteBranch
.SetCurSel(0);
656 this->LoadBranchInfo();
658 this->m_bInited
=true;
661 m_ctrlTabCtrl
.ShowTab(IDC_CMD_LOG
-1,false);
662 m_ctrlTabCtrl
.ShowTab(IDC_IN_LOGLIST
-1,false);
663 m_ctrlTabCtrl
.ShowTab(IDC_IN_CHANGELIST
-1,false);
664 m_ctrlTabCtrl
.ShowTab(IDC_IN_CONFLICT
-1,false);
666 return TRUE
; // return TRUE unless you set the focus to a control
667 // EXCEPTION: OCX Property Pages should return FALSE
670 void CSyncDlg::OnBnClickedButtonManage()
672 // TODO: Add your control notification handler code here
673 CAppUtils::LaunchRemoteSetting();
676 BOOL
CSyncDlg::PreTranslateMessage(MSG
* pMsg
)
678 // TODO: Add your specialized code here and/or call the base class
679 m_tooltips
.RelayEvent(pMsg
);
680 return __super::PreTranslateMessage(pMsg
);
682 void CSyncDlg::FetchOutList(bool force
)
686 m_OutChangeFileList
.Clear();
687 this->m_OutLogList
.Clear();
690 this->m_ctrlURL
.GetWindowText(remote
);
691 CString remotebranch
;
692 this->m_ctrlRemoteBranch
.GetWindowText(remotebranch
);
693 remotebranch
=remote
+_T("/")+remotebranch
;
698 str
=_T("Don't know what will push befause you enter URL");
699 m_OutLogList
.ShowText(str
);
700 this->m_ctrlTabCtrl
.ShowTab(m_OutChangeFileList
.GetDlgCtrlID()-1,FALSE
);
701 m_OutLocalBranch
.Empty();
702 m_OutRemoteBranch
.Empty();
704 this->GetDlgItem(IDC_BUTTON_EMAIL
)->EnableWindow(FALSE
);
707 }else if(g_Git
.GetHash(remotebranch
).GetLength()<40)
710 str
.Format(_T("Don't know what will push befause unkown \"%s\""),remotebranch
);
711 m_OutLogList
.ShowText(str
);
712 this->m_ctrlTabCtrl
.ShowTab(m_OutChangeFileList
.GetDlgCtrlID()-1,FALSE
);
713 m_OutLocalBranch
.Empty();
714 m_OutRemoteBranch
.Empty();
716 this->GetDlgItem(IDC_BUTTON_EMAIL
)->EnableWindow(FALSE
);
722 localbranch
=this->m_ctrlLocalBranch
.GetString();
724 if(localbranch
!= m_OutLocalBranch
|| m_OutRemoteBranch
!= remotebranch
|| force
)
726 m_OutLogList
.ClearText();
727 m_OutLogList
.FillGitLog(NULL
,CGit:: LOG_INFO_STAT
| CGit::LOG_INFO_FILESTATE
| CGit::LOG_INFO_SHOW_MERGEDFILE
,
728 &remotebranch
,&localbranch
);
731 if(m_OutLogList
.GetItemCount() == 0)
733 str
.Format(_T("No commits ahead \"%s\""),remotebranch
);
734 m_OutLogList
.ShowText(str
);
735 this->m_ctrlStatus
.SetWindowText(str
);
736 this->m_ctrlTabCtrl
.ShowTab(m_OutChangeFileList
.GetDlgCtrlID()-1,FALSE
);
737 this->GetDlgItem(IDC_BUTTON_EMAIL
)->EnableWindow(FALSE
);
741 str
.Format(_T("%d commits ahead \"%s\""),m_OutLogList
.GetItemCount(),remotebranch
);
742 this->m_ctrlStatus
.SetWindowText(str
);
744 AddDiffFileList(&m_OutChangeFileList
,&m_arOutChangeList
,localbranch
,remotebranch
);
746 this->m_ctrlTabCtrl
.ShowTab(m_OutChangeFileList
.GetDlgCtrlID()-1,TRUE
);
747 this->GetDlgItem(IDC_BUTTON_EMAIL
)->EnableWindow(TRUE
);
750 this->m_OutLocalBranch
=localbranch
;
751 this->m_OutRemoteBranch
=remotebranch
;
756 bool CSyncDlg::IsURL()
759 this->m_ctrlURL
.GetWindowText(str
);
760 if(str
.Find(_T('\\'))>=0 || str
.Find(_T('/'))>=0)
765 void CSyncDlg::OnCbenEndeditComboboxexUrl(NMHDR
*pNMHDR
, LRESULT
*pResult
)
767 // TODO: Add your control notification handler code here
771 void CSyncDlg::OnCbnEditchangeComboboxexUrl()
773 this->FetchOutList();
774 // TODO: Add your control notification handler code here
777 UINT
CSyncDlg::ProgressThread()
779 m_GitCmdStatus
=CProgressDlg::RunCmdList(this,m_GitCmdList
,true,NULL
,&this->m_bAbort
);
784 LRESULT
CSyncDlg::OnProgressUpdateUI(WPARAM wParam
,LPARAM lParam
)
786 if(wParam
== MSG_PROGRESSDLG_START
)
788 m_ctrlAnimate
.Play(0,-1,-1);
789 this->m_ctrlProgress
.SetPos(0);
792 if(wParam
== MSG_PROGRESSDLG_END
|| wParam
== MSG_PROGRESSDLG_FAILED
)
795 m_ctrlAnimate
.Stop();
796 m_ctrlProgress
.SetPos(100);
797 //this->DialogEnableWindow(IDOK,TRUE);
799 //if(wParam == MSG_PROGRESSDLG_END)
800 if(this->m_CurrentCmd
== GIT_COMMAND_PUSH
)
802 EnableControlButton(true);
804 this->FetchOutList(true);
806 if(this->m_CurrentCmd
== GIT_COMMAND_PULL
)
810 if(this->m_CurrentCmd
== GIT_COMMAND_FETCH
|| this->m_CurrentCmd
== GIT_COMMAND_FETCHANDREBASE
)
817 ParserCmdOutput((TCHAR
)lParam
);
823 void CSyncDlg::ParserCmdOutput(TCHAR ch
)
825 //TRACE(_T("%c"),ch);
828 linenum
= this->m_ctrlCmdOut
.GetLineCount();
833 m_CmdOutCurrentPos
= this->m_ctrlCmdOut
.LineIndex(linenum
-1);
835 m_CmdOutCurrentPos
= 0;
837 //TRACE(_T("line %d - %d\n"),index,m_ctrlCmdOut.GetTextLength());
839 m_CmdOutCurrentPos
++;
841 this->m_ctrlCmdOut
.SetSel(m_CmdOutCurrentPos
,m_CmdOutCurrentPos
+1);
844 this->m_ctrlCmdOut
.ReplaceSel(CString(ch
));
846 int firstline
= m_ctrlCmdOut
.GetFirstVisibleLine();
847 if( linenum
- firstline
> 4 )
848 this->m_ctrlCmdOut
.LineScroll(linenum
- firstline
-4);
850 if( ch
== _T('\r') || ch
== _T('\n') )
852 int s1
=m_LogText
.Find(_T(':'));
853 int s2
=m_LogText
.Find(_T('%'));
856 // this->m_CurrentWork.SetWindowTextW(m_LogText.Left(s1));
857 int pos
=CProgressDlg::FindPercentage(m_LogText
);
858 TRACE(_T("Pos %d\r\n"),pos
);
860 this->m_ctrlProgress
.SetPos(pos
);
867 void CSyncDlg::OnBnClickedButtonCommit()
869 // TODO: Add your control notification handler code here
870 CString proc
=CPathUtils::GetAppDirectory();
871 proc
+= _T("TortoiseProc.exe /command:commit");
872 proc
+= _T(" /path:\"");
873 proc
+= g_Git
.m_CurrentDir
;
875 CAppUtils::LaunchApplication(proc
,IDS_ERROR_CANNON_FIND_TORTOISEPROC
,false);
878 void CSyncDlg::OnOK()
880 // TODO: Add your specialized code here and/or call the base class
882 m_ctrlURL
.SaveHistory();