pulled latest translations from Transifex
[TortoiseGit.git] / src / TortoiseProc / SyncDlg.cpp
blobb2ea8d93a9fc8a01a99bb408341dabd685c95f86
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2012 - 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 "AppUtils.h"
27 #include "progressdlg.h"
28 #include "MessageBox.h"
29 #include "ImportPatchDlg.h"
30 #include "RebaseDlg.h"
31 #include "hooks.h"
32 #include "SmartHandle.h"
34 // CSyncDlg dialog
36 IMPLEMENT_DYNAMIC(CSyncDlg, CResizableStandAloneDialog)
38 CSyncDlg::CSyncDlg(CWnd* pParent /*=NULL*/)
39 : CResizableStandAloneDialog(CSyncDlg::IDD, pParent)
41 m_pTooltip=&this->m_tooltips;
42 m_bInited=false;
43 m_CmdOutCurrentPos=0;
44 m_bAutoLoadPuttyKey = CAppUtils::IsSSHPutty();
45 m_bForce=false;
46 m_bBlock = false;
49 CSyncDlg::~CSyncDlg()
53 void CSyncDlg::DoDataExchange(CDataExchange* pDX)
55 CDialog::DoDataExchange(pDX);
56 DDX_Check(pDX, IDC_CHECK_PUTTY_KEY, m_bAutoLoadPuttyKey);
57 DDX_Check(pDX, IDC_CHECK_FORCE,m_bForce);
58 DDX_Control(pDX, IDC_COMBOBOXEX_URL, m_ctrlURL);
59 DDX_Control(pDX, IDC_BUTTON_TABCTRL, m_ctrlDumyButton);
60 DDX_Control(pDX, IDC_BUTTON_PULL, m_ctrlPull);
61 DDX_Control(pDX, IDC_BUTTON_PUSH, m_ctrlPush);
62 DDX_Control(pDX, IDC_STATIC_STATUS, m_ctrlStatus);
63 DDX_Control(pDX, IDC_PROGRESS_SYNC, m_ctrlProgress);
64 DDX_Control(pDX, IDC_ANIMATE_SYNC, m_ctrlAnimate);
65 DDX_Control(pDX, IDC_BUTTON_SUBMODULE,m_ctrlSubmodule);
66 BRANCH_COMBOX_DDX;
70 BEGIN_MESSAGE_MAP(CSyncDlg, CResizableStandAloneDialog)
71 ON_BN_CLICKED(IDC_BUTTON_PULL, &CSyncDlg::OnBnClickedButtonPull)
72 ON_BN_CLICKED(IDC_BUTTON_PUSH, &CSyncDlg::OnBnClickedButtonPush)
73 ON_BN_CLICKED(IDC_BUTTON_APPLY, &CSyncDlg::OnBnClickedButtonApply)
74 ON_BN_CLICKED(IDC_BUTTON_EMAIL, &CSyncDlg::OnBnClickedButtonEmail)
75 ON_BN_CLICKED(IDC_BUTTON_MANAGE, &CSyncDlg::OnBnClickedButtonManage)
76 BRANCH_COMBOX_EVENT
77 ON_CBN_EDITCHANGE(IDC_COMBOBOXEX_URL, &CSyncDlg::OnCbnEditchangeComboboxex)
78 ON_CBN_EDITCHANGE(IDC_COMBOBOXEX_REMOTE_BRANCH, &CSyncDlg::OnCbnEditchangeComboboxex)
79 ON_MESSAGE(MSG_PROGRESSDLG_UPDATE_UI, OnProgressUpdateUI)
80 ON_NOTIFY(LVN_COLUMNCLICK, IDC_IN_LOGLIST, OnLvnInLogListColumnClick)
81 ON_BN_CLICKED(IDC_BUTTON_COMMIT, &CSyncDlg::OnBnClickedButtonCommit)
82 ON_BN_CLICKED(IDC_BUTTON_SUBMODULE, &CSyncDlg::OnBnClickedButtonSubmodule)
83 ON_WM_TIMER()
84 ON_REGISTERED_MESSAGE(WM_TASKBARBTNCREATED, OnTaskbarBtnCreated)
85 END_MESSAGE_MAP()
88 void CSyncDlg::EnableControlButton(bool bEnabled)
90 GetDlgItem(IDC_BUTTON_PULL)->EnableWindow(bEnabled);
91 GetDlgItem(IDC_BUTTON_PUSH)->EnableWindow(bEnabled);
92 GetDlgItem(IDC_BUTTON_APPLY)->EnableWindow(bEnabled);
93 GetDlgItem(IDC_BUTTON_EMAIL)->EnableWindow(bEnabled);
94 GetDlgItem(IDOK)->EnableWindow(bEnabled);
95 GetDlgItem(IDC_BUTTON_SUBMODULE)->EnableWindow(bEnabled);
97 // CSyncDlg message handlers
99 void CSyncDlg::OnBnClickedButtonPull()
101 int CurrentEntry;
102 CurrentEntry = this->m_ctrlPull.GetCurrentEntry();
103 this->m_regPullButton = CurrentEntry;
105 this->m_bAbort=false;
106 this->m_GitCmdList.clear();
108 this->UpdateData();
109 UpdateCombox();
111 m_oldHash = g_Git.GetHash(_T("HEAD"));
113 if( CurrentEntry == 0)
115 if( g_Git.GetHash(this->m_strLocalBranch) != m_oldHash)
117 CMessageBox::Show(NULL, IDS_PROC_SYNC_PULLWRONGBRANCH, IDS_APPNAME, MB_OK | MB_ICONERROR);
118 return;
122 if(this->m_strURL.IsEmpty())
124 CMessageBox::Show(NULL, IDS_PROC_GITCONFIG_URLEMPTY, IDS_APPNAME, MB_OK | MB_ICONERROR);
125 return;
128 if(this->m_bAutoLoadPuttyKey)
130 CAppUtils::LaunchPAgent(NULL,&this->m_strURL);
133 this->SwitchToRun();
135 CString force;
136 if(this->m_bForce)
137 force = _T(" --force ");
139 CString cmd;
141 ShowTab(IDC_CMD_LOG);
143 this->m_ctrlTabCtrl.ShowTab(IDC_IN_LOGLIST-1,false);
144 this->m_ctrlTabCtrl.ShowTab(IDC_IN_CHANGELIST-1,false);
145 this->m_ctrlTabCtrl.ShowTab(IDC_IN_CONFLICT-1,false);
147 this->GetDlgItem(IDC_BUTTON_COMMIT)->ShowWindow(SW_HIDE);
149 ///Pull
150 if(CurrentEntry == 0) //Pull
152 CString remotebranch;
153 remotebranch = m_strRemoteBranch;
155 if(!IsURL())
157 CString configName;
158 configName.Format(L"branch.%s.merge", this->m_strLocalBranch);
159 CString pullBranch = CGit::StripRefName(g_Git.GetConfigValue(configName));
161 configName.Format(L"branch.%s.remote", m_strLocalBranch);
162 CString pullRemote = g_Git.GetConfigValue(configName);
164 if(pullBranch == remotebranch && pullRemote == this->m_strURL)
165 remotebranch.Empty();
168 if(m_Gitverion >= 0x01070203) //above 1.7.0.2
169 force += _T("--progress ");
171 cmd.Format(_T("git.exe pull -v %s \"%s\" %s"),
172 force,
173 m_strURL,
174 remotebranch);
176 m_CurrentCmd = GIT_COMMAND_PULL;
177 m_GitCmdList.push_back(cmd);
179 m_pThread = AfxBeginThread(ProgressThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
180 if (m_pThread==NULL)
182 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
184 else
186 m_pThread->m_bAutoDelete = TRUE;
187 m_pThread->ResumeThread();
192 ///Fetch
193 if(CurrentEntry == 1 || CurrentEntry ==2 ) //Fetch
195 CString remotebranch;
196 if(this->IsURL() || m_strRemoteBranch.IsEmpty())
198 remotebranch=this->m_strRemoteBranch;
201 else
203 remotebranch.Format(_T("remotes/%s/%s"),
204 m_strURL,m_strRemoteBranch);
205 if(g_Git.GetHash(remotebranch).IsEmpty())
206 remotebranch=m_strRemoteBranch;
207 else
208 remotebranch=m_strRemoteBranch+_T(":")+remotebranch;
211 if(m_Gitverion >= 0x01070203) //above 1.7.0.2
212 force += _T("--progress ");
214 cmd.Format(_T("git.exe fetch -v %s \"%s\" %s"),
215 force,
216 m_strURL,
217 remotebranch);
219 if(CurrentEntry == 1)
220 m_CurrentCmd = GIT_COMMAND_FETCH;
221 else
222 m_CurrentCmd = GIT_COMMAND_FETCHANDREBASE;
223 m_GitCmdList.push_back(cmd);
225 m_pThread = AfxBeginThread(ProgressThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
226 if (m_pThread==NULL)
228 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
230 else
232 m_pThread->m_bAutoDelete = TRUE;
233 m_pThread->ResumeThread();
237 ///Remote Update
238 if(CurrentEntry == 3)
240 m_CurrentCmd = GIT_COMMAND_REMOTE;
241 cmd=_T("git.exe remote update");
242 m_GitCmdList.push_back(cmd);
244 InterlockedExchange(&m_bBlock, TRUE);
246 m_pThread = AfxBeginThread(ProgressThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
247 if (m_pThread==NULL)
249 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
250 InterlockedExchange(&m_bBlock, FALSE);
252 else
254 m_pThread->m_bAutoDelete = TRUE;
255 m_pThread->ResumeThread();
259 ///Cleanup stale remote banches
260 if(CurrentEntry == 4)
262 m_CurrentCmd = GIT_COMMAND_REMOTE;
263 cmd.Format(_T("git.exe remote prune \"%s\""), m_strURL);
264 m_GitCmdList.push_back(cmd);
266 InterlockedExchange(&m_bBlock, TRUE);
268 m_pThread = AfxBeginThread(ProgressThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
269 if (m_pThread==NULL)
271 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
272 InterlockedExchange(&m_bBlock, FALSE);
274 else
276 m_pThread->m_bAutoDelete = TRUE;
277 m_pThread->ResumeThread();
282 void CSyncDlg::PullComplete()
284 EnableControlButton(true);
285 SwitchToInput();
286 this->FetchOutList(true);
288 CString newhash;
289 newhash = g_Git.GetHash(_T("HEAD"));
291 if( this ->m_GitCmdStatus )
293 CTGitPathList list;
294 if(g_Git.ListConflictFile(list))
296 this->m_ctrlCmdOut.SetSel(-1,-1);
297 this->m_ctrlCmdOut.ReplaceSel(_T("Get conflict files fail\n"));
299 this->ShowTab(IDC_CMD_LOG);
300 return;
303 if(list.GetCount()>0)
305 this->m_ConflictFileList.Clear();
306 CTGitPathList list;
307 CTGitPath path;
308 list.AddPath(path);
310 this->m_ConflictFileList.GetStatus(&list,true);
311 this->m_ConflictFileList.Show(CTGitPath::LOGACTIONS_UNMERGED,
312 CTGitPath::LOGACTIONS_UNMERGED);
314 this->ShowTab(IDC_IN_CONFLICT);
316 this->GetDlgItem(IDC_BUTTON_COMMIT)->ShowWindow(SW_NORMAL);
318 else
319 this->ShowTab(IDC_CMD_LOG);
322 else
324 if(newhash == this->m_oldHash)
326 this->m_ctrlTabCtrl.ShowTab(IDC_IN_CHANGELIST-1,false);
327 this->m_InLogList.ShowText(CString(MAKEINTRESOURCE(IDS_UPTODATE)));
328 this->m_ctrlTabCtrl.ShowTab(IDC_IN_LOGLIST-1,true);
330 else
332 this->m_ctrlTabCtrl.ShowTab(IDC_IN_CHANGELIST-1,true);
333 this->m_ctrlTabCtrl.ShowTab(IDC_IN_LOGLIST-1,true);
335 CString oldhash=m_oldHash.ToString();
336 this->AddDiffFileList(&m_InChangeFileList,&m_arInChangeList,newhash,oldhash);
338 m_InLogList.FillGitLog(NULL,CGit:: LOG_INFO_STAT| CGit::LOG_INFO_FILESTATE | CGit::LOG_INFO_SHOW_MERGEDFILE,
339 &oldhash,&newhash);
341 this->ShowTab(IDC_IN_LOGLIST);
345 void CSyncDlg::FetchComplete()
347 EnableControlButton(true);
348 SwitchToInput();
349 this->FetchOutList(true);
351 ShowTab(IDC_CMD_LOG);
352 if( (!this->m_GitCmdStatus) && this->m_CurrentCmd == GIT_COMMAND_FETCHANDREBASE)
354 CRebaseDlg dlg;
355 dlg.m_PostButtonTexts.Add(_T("Email &Patch..."));
356 int response = dlg.DoModal();
357 if(response == IDOK)
359 return ;
362 if(response == IDC_REBASE_POST_BUTTON)
364 CString cmd, out, err;
365 cmd.Format(_T("git.exe format-patch -o \"%s\" %s..%s"),
366 g_Git.m_CurrentDir,
367 g_Git.FixBranchName(dlg.m_Upstream),
368 g_Git.FixBranchName(dlg.m_Branch));
369 if (g_Git.Run(cmd, &out, &err, CP_UTF8))
371 CMessageBox::Show(NULL, out + L"\n" + err, _T("TortoiseGit"), MB_OK|MB_ICONERROR);
372 return ;
375 CAppUtils::SendPatchMail(cmd,out);
380 void CSyncDlg::OnBnClickedButtonPush()
382 this->UpdateData();
383 UpdateCombox();
385 if(this->m_strURL.IsEmpty())
387 CMessageBox::Show(NULL, IDS_PROC_GITCONFIG_URLEMPTY, IDS_APPNAME, MB_OK | MB_ICONERROR);
388 return;
391 this->m_regPushButton=this->m_ctrlPush.GetCurrentEntry();
392 this->SwitchToRun();
393 this->m_bAbort=false;
394 this->m_GitCmdList.clear();
396 ShowTab(IDC_CMD_LOG);
398 CString cmd;
399 CString arg;
401 CString error;
402 DWORD exitcode;
403 CTGitPathList list;
404 list.AddPath(CTGitPath(g_Git.m_CurrentDir));
406 if (CHooks::Instance().PrePush(list,exitcode, error))
408 if (exitcode)
410 CString temp;
411 temp.Format(IDS_ERR_HOOKFAILED, (LPCTSTR)error);
412 //ReportError(temp);
413 CMessageBox::Show(NULL,temp,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
414 return ;
418 switch (m_ctrlPush.GetCurrentEntry())
420 case 1:
421 arg += _T(" --tags ");
422 break;
423 case 2:
424 arg += _T(" --all ");
425 break;
428 if(this->m_bForce)
429 arg += _T(" --force ");
431 if(m_Gitverion >= 0x01070203) //above 1.7.0.2
432 arg += _T("--progress ");
434 cmd.Format(_T("git.exe push -v %s \"%s\" %s"),
435 arg,
436 m_strURL,
437 g_Git.FixBranchName(m_strLocalBranch));
439 if (!m_strRemoteBranch.IsEmpty())
441 cmd += _T(":") + m_strRemoteBranch;
444 m_GitCmdList.push_back(cmd);
446 m_CurrentCmd = GIT_COMMAND_PUSH;
448 if(this->m_bAutoLoadPuttyKey)
450 CAppUtils::LaunchPAgent(NULL,&this->m_strURL);
453 m_pThread = AfxBeginThread(ProgressThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
454 if (m_pThread==NULL)
456 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
458 else
460 m_pThread->m_bAutoDelete = TRUE;
461 m_pThread->ResumeThread();
465 void CSyncDlg::OnBnClickedButtonApply()
467 CString oldhash;
468 oldhash=g_Git.GetHash(_T("HEAD"));
470 CImportPatchDlg dlg;
471 CString cmd,output;
473 if(dlg.DoModal() == IDOK)
475 int err=0;
476 for(int i=0;i<dlg.m_PathList.GetCount();i++)
478 cmd.Format(_T("git.exe am \"%s\""),dlg.m_PathList[i].GetGitPathString());
480 if (g_Git.Run(cmd, &output, CP_UTF8))
482 CMessageBox::Show(NULL,output,_T("TortoiseGit"),MB_OK);
484 err=1;
485 break;
487 this->m_ctrlCmdOut.SetSel(-1,-1);
488 this->m_ctrlCmdOut.ReplaceSel(cmd+_T("\n"));
489 this->m_ctrlCmdOut.SetSel(-1,-1);
490 this->m_ctrlCmdOut.ReplaceSel(output);
493 CString newhash=g_Git.GetHash(_T("HEAD"));
495 this->m_InLogList.Clear();
496 this->m_InChangeFileList.Clear();
498 if(newhash == oldhash)
500 this->m_ctrlTabCtrl.ShowTab(IDC_IN_CHANGELIST-1,false);
501 this->m_InLogList.ShowText(_T("No commits get from patch"));
502 this->m_ctrlTabCtrl.ShowTab(IDC_IN_LOGLIST-1,true);
505 else
507 this->m_ctrlTabCtrl.ShowTab(IDC_IN_CHANGELIST-1,true);
508 this->m_ctrlTabCtrl.ShowTab(IDC_IN_LOGLIST-1,true);
510 this->AddDiffFileList(&m_InChangeFileList,&m_arInChangeList,newhash,oldhash);
511 m_InLogList.FillGitLog(NULL,CGit:: LOG_INFO_STAT| CGit::LOG_INFO_FILESTATE | CGit::LOG_INFO_SHOW_MERGEDFILE,
512 &oldhash,&newhash);
514 this->FetchOutList(true);
517 this->m_ctrlTabCtrl.ShowTab(IDC_CMD_LOG-1,true);
519 if(err)
521 this->ShowTab(IDC_CMD_LOG);
523 else
525 this->ShowTab(IDC_IN_LOGLIST);
530 void CSyncDlg::OnBnClickedButtonEmail()
532 CString cmd, out, err;
534 this->m_strLocalBranch = this->m_ctrlLocalBranch.GetString();
535 this->m_ctrlRemoteBranch.GetWindowText(this->m_strRemoteBranch);
536 this->m_ctrlURL.GetWindowText(this->m_strURL);
537 m_strURL=m_strURL.Trim();
538 m_strRemoteBranch=m_strRemoteBranch.Trim();
540 cmd.Format(_T("git.exe format-patch -o \"%s\" %s..%s"),
541 g_Git.m_CurrentDir,
542 m_strURL+_T('/')+m_strRemoteBranch,g_Git.FixBranchName(m_strLocalBranch));
544 if (g_Git.Run(cmd, &out, &err, CP_UTF8))
546 CMessageBox::Show(NULL, out + L"\n" + err, _T("TortoiseGit"), MB_OK|MB_ICONERROR);
547 return ;
550 CAppUtils::SendPatchMail(cmd,out);
553 void CSyncDlg::ShowProgressCtrl(bool bShow)
555 int b=bShow?SW_NORMAL:SW_HIDE;
556 this->m_ctrlAnimate.ShowWindow(b);
557 this->m_ctrlProgress.ShowWindow(b);
558 this->m_ctrlAnimate.Open(IDR_DOWNLOAD);
559 if(b == SW_NORMAL)
560 this->m_ctrlAnimate.Play(0,-1,-1);
561 else
562 this->m_ctrlAnimate.Stop();
564 void CSyncDlg::ShowInputCtrl(bool bShow)
566 int b=bShow?SW_NORMAL:SW_HIDE;
567 this->m_ctrlURL.ShowWindow(b);
568 this->m_ctrlLocalBranch.ShowWindow(b);
569 this->m_ctrlRemoteBranch.ShowWindow(b);
570 this->GetDlgItem(IDC_BUTTON_LOCAL_BRANCH)->ShowWindow(b);
571 this->GetDlgItem(IDC_BUTTON_REMOTE_BRANCH)->ShowWindow(b);
572 this->GetDlgItem(IDC_STATIC_LOCAL_BRANCH)->ShowWindow(b);
573 this->GetDlgItem(IDC_STATIC_REMOTE_BRANCH)->ShowWindow(b);
574 this->GetDlgItem(IDC_BUTTON_MANAGE)->ShowWindow(b);
575 this->GetDlgItem(IDC_CHECK_PUTTY_KEY)->ShowWindow(b);
576 this->GetDlgItem(IDC_CHECK_FORCE)->ShowWindow(b);
577 this->GetDlgItem(IDC_STATIC_REMOTE_URL)->ShowWindow(b);
579 BOOL CSyncDlg::OnInitDialog()
581 CResizableStandAloneDialog::OnInitDialog();
582 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
584 // Let the TaskbarButtonCreated message through the UIPI filter. If we don't
585 // do this, Explorer would be unable to send that message to our window if we
586 // were running elevated. It's OK to make the call all the time, since if we're
587 // not elevated, this is a no-op.
588 CHANGEFILTERSTRUCT cfs = { sizeof(CHANGEFILTERSTRUCT) };
589 typedef BOOL STDAPICALLTYPE ChangeWindowMessageFilterExDFN(HWND hWnd, UINT message, DWORD action, PCHANGEFILTERSTRUCT pChangeFilterStruct);
590 CAutoLibrary hUser = ::LoadLibrary(_T("user32.dll"));
591 if (hUser)
593 ChangeWindowMessageFilterExDFN *pfnChangeWindowMessageFilterEx = (ChangeWindowMessageFilterExDFN*)GetProcAddress(hUser, "ChangeWindowMessageFilterEx");
594 if (pfnChangeWindowMessageFilterEx)
596 pfnChangeWindowMessageFilterEx(m_hWnd, WM_TASKBARBTNCREATED, MSGFLT_ALLOW, &cfs);
599 m_pTaskbarList.Release();
600 m_pTaskbarList.CoCreateInstance(CLSID_TaskbarList);
602 this->GetDlgItem(IDC_CHECK_PUTTY_KEY)->EnableWindow(CAppUtils::IsSSHPutty());
605 this->m_ctrlAnimate.ShowWindow(SW_NORMAL);
606 this->m_ctrlAnimate.Open(IDR_DOWNLOAD);
607 this->m_ctrlAnimate.Play(0,-1,-1);
610 // ------------------ Create Tabctrl -----------
611 CWnd *pwnd=this->GetDlgItem(IDC_BUTTON_TABCTRL);
612 CRect rectDummy;
613 pwnd->GetWindowRect(&rectDummy);
614 this->ScreenToClient(rectDummy);
616 if (!m_ctrlTabCtrl.Create(CMFCTabCtrl::STYLE_FLAT, rectDummy, this, IDC_SYNC_TAB))
618 TRACE0("Failed to create output tab window\n");
619 return FALSE; // fail to create
621 m_ctrlTabCtrl.SetResizeMode(CMFCTabCtrl::RESIZE_NO);
623 // -------------Create Command Log Ctrl ---------
624 DWORD dwStyle;
625 dwStyle= ES_MULTILINE | ES_READONLY | WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL | ES_AUTOVSCROLL |WS_VSCROLL ;
627 if( !m_ctrlCmdOut.Create(dwStyle,rectDummy,&m_ctrlTabCtrl,IDC_CMD_LOG))
629 TRACE0("Failed to create Log commits window\n");
630 return FALSE; // fail to create
633 // set the font to use in the log message view, configured in the settings dialog
634 CFont m_logFont;
635 CAppUtils::CreateFontForLogs(m_logFont);
636 //GetDlgItem(IDC_CMD_LOG)->SetFont(&m_logFont);
637 m_ctrlCmdOut.SetFont(&m_logFont);
638 m_ctrlTabCtrl.InsertTab(&m_ctrlCmdOut, CString(MAKEINTRESOURCE(IDS_LOG)), -1);
640 //m_ctrlCmdOut.ReplaceSel(_T("Hello"));
642 //---------- Create in coming list ctrl -----------
643 dwStyle =LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | LVS_OWNERDATA | WS_BORDER | WS_TABSTOP | WS_CHILD | WS_VISIBLE;;
645 if( !m_InLogList.Create(dwStyle,rectDummy,&m_ctrlTabCtrl,IDC_IN_LOGLIST))
647 TRACE0("Failed to create output commits window\n");
648 return FALSE; // fail to create
651 m_ctrlTabCtrl.InsertTab(&m_InLogList, CString(MAKEINTRESOURCE(IDS_PROC_SYNC_INCOMMITS)), -1);
653 m_InLogList.m_ColumnRegKey=_T("SyncIn");
654 m_InLogList.InsertGitColumn();
656 //----------- Create In Change file list -----------
657 dwStyle = LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP |LVS_SINGLESEL |WS_CHILD | WS_VISIBLE;
659 if( !m_InChangeFileList.Create(dwStyle,rectDummy,&m_ctrlTabCtrl,IDC_IN_CHANGELIST))
661 TRACE0("Failed to create output change files window\n");
662 return FALSE; // fail to create
664 m_ctrlTabCtrl.InsertTab(&m_InChangeFileList, CString(MAKEINTRESOURCE(IDS_PROC_SYNC_INCHANGELIST)), -1);
666 m_InChangeFileList.Init(GITSLC_COLEXT | GITSLC_COLSTATUS |GITSLC_COLADD|GITSLC_COLDEL , _T("OutSyncDlg"),
667 (CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_COMPARETWO)|
668 CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_GNUDIFF2)),false);
671 //---------- Create Conflict List Ctrl -----------------
672 dwStyle = LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP |LVS_SINGLESEL |WS_CHILD | WS_VISIBLE;
674 if( !m_ConflictFileList.Create(dwStyle,rectDummy,&m_ctrlTabCtrl,IDC_IN_CONFLICT))
676 TRACE0("Failed to create output change files window\n");
677 return FALSE; // fail to create
679 m_ctrlTabCtrl.InsertTab(&m_ConflictFileList,_T("Conflict"),-1);
681 m_ConflictFileList.Init(GITSLC_COLEXT | GITSLC_COLSTATUS |GITSLC_COLADD|GITSLC_COLDEL , _T("OutSyncDlg"),
682 (CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_COMPARETWO)|
683 CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_GNUDIFF2)|
684 GITSLC_POPCONFLICT|GITSLC_POPRESOLVE),false);
687 //---------- Create Commit Out List Ctrl---------------
689 dwStyle =LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | LVS_OWNERDATA | WS_BORDER | WS_TABSTOP | WS_CHILD | WS_VISIBLE;;
691 if( !m_OutLogList.Create(dwStyle,rectDummy,&m_ctrlTabCtrl,IDC_OUT_LOGLIST))
693 TRACE0("Failed to create output commits window\n");
694 return FALSE; // fail to create
698 m_ctrlTabCtrl.InsertTab(&m_OutLogList, CString(MAKEINTRESOURCE(IDS_PROC_SYNC_OUTCOMMITS)), -1);
700 m_OutLogList.m_ColumnRegKey = _T("SyncOut");
701 m_OutLogList.InsertGitColumn();
703 //------------- Create Change File List Control ----------------
705 dwStyle = LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP |LVS_SINGLESEL |WS_CHILD | WS_VISIBLE;
707 if( !m_OutChangeFileList.Create(dwStyle,rectDummy,&m_ctrlTabCtrl,IDC_OUT_CHANGELIST))
709 TRACE0("Failed to create output change files window\n");
710 return FALSE; // fail to create
712 m_ctrlTabCtrl.InsertTab(&m_OutChangeFileList, CString(MAKEINTRESOURCE(IDS_PROC_SYNC_OUTCHANGELIST)), -1);
714 m_OutChangeFileList.Init(GITSLC_COLEXT | GITSLC_COLSTATUS |GITSLC_COLADD|GITSLC_COLDEL , _T("OutSyncDlg"),
715 (CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_COMPARETWO)|
716 CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_GNUDIFF2)),false);
718 this->m_tooltips.Create(this);
720 AddAnchor(IDC_SYNC_TAB,TOP_LEFT,BOTTOM_RIGHT);
722 AddAnchor(IDC_GROUP_INFO,TOP_LEFT,TOP_RIGHT);
723 AddAnchor(IDC_COMBOBOXEX_URL,TOP_LEFT,TOP_RIGHT);
724 AddAnchor(IDC_BUTTON_MANAGE,TOP_RIGHT);
725 AddAnchor(IDC_BUTTON_PULL,BOTTOM_LEFT);
726 AddAnchor(IDC_BUTTON_PUSH,BOTTOM_LEFT);
727 AddAnchor(IDC_BUTTON_SUBMODULE,BOTTOM_LEFT);
728 AddAnchor(IDC_BUTTON_APPLY,BOTTOM_RIGHT);
729 AddAnchor(IDC_BUTTON_EMAIL,BOTTOM_RIGHT);
730 AddAnchor(IDC_PROGRESS_SYNC,TOP_LEFT,TOP_RIGHT);
731 AddAnchor(IDOK,BOTTOM_RIGHT);
732 AddAnchor(IDHELP,BOTTOM_RIGHT);
733 AddAnchor(IDC_STATIC_STATUS,BOTTOM_LEFT);
734 AddAnchor(IDC_ANIMATE_SYNC,TOP_LEFT);
735 AddAnchor(IDC_BUTTON_COMMIT,BOTTOM_LEFT);
737 // do not use BRANCH_COMBOX_ADD_ANCHOR here, we want to have different stylings
738 AddAnchor(IDC_COMBOBOXEX_LOCAL_BRANCH, TOP_LEFT,TOP_CENTER);
739 AddAnchor(IDC_COMBOBOXEX_REMOTE_BRANCH, TOP_CENTER, TOP_RIGHT);
740 AddAnchor(IDC_BUTTON_LOCAL_BRANCH, TOP_CENTER);
741 AddAnchor(IDC_BUTTON_REMOTE_BRANCH, TOP_RIGHT);
742 AddAnchor(IDC_STATIC_REMOTE_BRANCH, TOP_CENTER);
744 this->GetDlgItem(IDC_BUTTON_COMMIT)->ShowWindow(SW_HIDE);
746 CString WorkingDir=g_Git.m_CurrentDir;
747 WorkingDir.Replace(_T(':'),_T('_'));
748 m_RegKeyRemoteBranch = CString(_T("Software\\TortoiseGit\\History\\SyncBranch\\"))+WorkingDir;
751 this->AddOthersToAnchor();
753 this->m_ctrlPush.AddEntry(CString(MAKEINTRESOURCE(IDS_PROC_SYNC_PUSH)));
754 this->m_ctrlPush.AddEntry(CString(MAKEINTRESOURCE(IDS_PROC_SYNC_PUSHTAGS)));
755 ///this->m_ctrlPush.AddEntry(CString(_T("Push All")));
757 this->m_ctrlPull.AddEntry(CString(MAKEINTRESOURCE(IDS_PROC_SYNC_PULL)));
758 this->m_ctrlPull.AddEntry(CString(MAKEINTRESOURCE(IDS_PROC_SYNC_FETCH)));
759 this->m_ctrlPull.AddEntry(CString(MAKEINTRESOURCE(IDS_PROC_SYNC_FETCHREBASE)));
760 this->m_ctrlPull.AddEntry(CString(MAKEINTRESOURCE(IDS_PROC_SYNC_REMOTEUPDATE)));
761 this->m_ctrlPull.AddEntry(CString(MAKEINTRESOURCE(IDS_PROC_SYNC_CLEANUPSTALEBRANCHES)));
763 this->m_ctrlSubmodule.AddEntry(CString(MAKEINTRESOURCE(IDS_PROC_SYNC_SUBKODULEUPDATE)));
764 this->m_ctrlSubmodule.AddEntry(CString(MAKEINTRESOURCE(IDS_PROC_SYNC_SUBKODULEINIT)));
765 this->m_ctrlSubmodule.AddEntry(CString(MAKEINTRESOURCE(IDS_PROC_SYNC_SUBKODULESYNC)));
767 WorkingDir.Replace(_T(':'),_T('_'));
769 CString regkey ;
770 regkey.Format(_T("Software\\TortoiseGit\\TortoiseProc\\Sync\\%s"),WorkingDir);
772 this->m_regPullButton = CRegDWORD(regkey+_T("\\Pull"),0);
773 this->m_regPushButton = CRegDWORD(regkey+_T("\\Push"),0);
774 this->m_regSubmoduleButton = CRegDWORD(regkey+_T("\\Submodule"));
775 this->m_regAutoLoadPutty = CRegDWORD(regkey + _T("\\AutoLoadPutty"), CAppUtils::IsSSHPutty());
777 m_tooltips.Create(this);
778 this->UpdateData();
779 this->m_bAutoLoadPuttyKey = m_regAutoLoadPutty;
780 if(!CAppUtils::IsSSHPutty())
781 m_bAutoLoadPuttyKey = false;
782 this->UpdateData(FALSE);
784 this->m_ctrlPull.SetCurrentEntry(this->m_regPullButton);
785 this->m_ctrlPush.SetCurrentEntry(this->m_regPushButton);
786 this->m_ctrlSubmodule.SetCurrentEntry(this->m_regSubmoduleButton);
788 CString sWindowTitle;
789 GetWindowText(sWindowTitle);
790 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, sWindowTitle);
792 EnableSaveRestore(_T("SyncDlg"));
794 this->m_ctrlURL.LoadHistory(CString(_T("Software\\TortoiseGit\\History\\SyncURL\\"))+WorkingDir, _T("url"));
796 STRING_VECTOR list;
798 if(!g_Git.GetRemoteList(list))
800 for(unsigned int i=0;i<list.size();i++)
802 m_ctrlURL.AddString(list[i]);
805 m_ctrlURL.SetCurSel(0);
806 m_ctrlRemoteBranch.SetCurSel(0);
807 m_ctrlURL.SetURLHistory(true);
809 this->LoadBranchInfo();
811 this->m_bInited=true;
812 FetchOutList();
814 m_ctrlTabCtrl.ShowTab(IDC_CMD_LOG-1,false);
815 m_ctrlTabCtrl.ShowTab(IDC_IN_LOGLIST-1,false);
816 m_ctrlTabCtrl.ShowTab(IDC_IN_CHANGELIST-1,false);
817 m_ctrlTabCtrl.ShowTab(IDC_IN_CONFLICT-1,false);
819 m_ctrlRemoteBranch.m_bWantReturn = TRUE;
820 m_ctrlURL.m_bWantReturn = TRUE;
822 this->m_Gitverion = CAppUtils::GetMsysgitVersion();
824 return TRUE; // return TRUE unless you set the focus to a control
825 // EXCEPTION: OCX Property Pages should return FALSE
828 void CSyncDlg::OnBnClickedButtonManage()
830 CAppUtils::LaunchRemoteSetting();
831 Refresh();
834 void CSyncDlg::Refresh()
836 theApp.DoWaitCursor(1);
838 CString local;
839 CString remote;
840 CString url;
841 this->m_ctrlLocalBranch.GetWindowText(local);
842 this->m_ctrlRemoteBranch.GetWindowText(remote);
843 this->m_ctrlURL.GetWindowText(url);
845 this->LoadBranchInfo();
847 this->m_ctrlLocalBranch.AddString(local);
848 this->m_ctrlRemoteBranch.AddString(remote);
849 this->m_ctrlURL.AddString(url);
851 m_OutLogList.ShowText(CString(MAKEINTRESOURCE(IDS_PROC_SYNC_REFRESHING)));
852 this->FetchOutList(true);
853 theApp.DoWaitCursor(-1);
856 BOOL CSyncDlg::PreTranslateMessage(MSG* pMsg)
858 if (pMsg->message == WM_KEYDOWN)
860 switch (pMsg->wParam)
863 case VK_F5:
865 if (m_bBlock)
866 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
867 Refresh();
869 break;
871 /* Avoid TAB control destroy but dialog exist*/
872 case VK_ESCAPE:
873 case VK_CANCEL:
875 TCHAR buff[128];
876 ::GetClassName(pMsg->hwnd,buff,128);
878 if(_tcsnicmp(buff,_T("RichEdit20W"),128)==0)
880 this->PostMessage(WM_KEYDOWN,VK_ESCAPE,0);
881 return TRUE;
886 m_tooltips.RelayEvent(pMsg);
887 return __super::PreTranslateMessage(pMsg);
889 void CSyncDlg::FetchOutList(bool force)
891 if(!m_bInited)
892 return;
893 m_OutChangeFileList.Clear();
894 this->m_OutLogList.Clear();
896 CString remote;
897 this->m_ctrlURL.GetWindowText(remote);
898 CString remotebranch;
899 this->m_ctrlRemoteBranch.GetWindowText(remotebranch);
900 remotebranch=remote+_T("/")+remotebranch;
902 if(IsURL())
904 CString str;
905 str.LoadString(IDS_PROC_SYNC_PUSH_UNKNOWN);
906 m_OutLogList.ShowText(str);
907 this->m_ctrlTabCtrl.ShowTab(m_OutChangeFileList.GetDlgCtrlID()-1,FALSE);
908 m_OutLocalBranch.Empty();
909 m_OutRemoteBranch.Empty();
911 this->GetDlgItem(IDC_BUTTON_EMAIL)->EnableWindow(FALSE);
912 return ;
915 else if(g_Git.GetHash(remotebranch).IsEmpty())
917 CString str;
918 str.Format(IDS_PROC_SYNC_PUSH_UNKNOWNBRANCH, remotebranch);
919 m_OutLogList.ShowText(str);
920 this->m_ctrlTabCtrl.ShowTab(m_OutChangeFileList.GetDlgCtrlID()-1,FALSE);
921 m_OutLocalBranch.Empty();
922 m_OutRemoteBranch.Empty();
924 this->GetDlgItem(IDC_BUTTON_EMAIL)->EnableWindow(FALSE);
925 return ;
927 else
929 CString localbranch;
930 localbranch=this->m_ctrlLocalBranch.GetString();
932 if(localbranch != m_OutLocalBranch || m_OutRemoteBranch != remotebranch || force)
934 m_OutLogList.ClearText();
935 m_OutLogList.FillGitLog(NULL,CGit:: LOG_INFO_STAT| CGit::LOG_INFO_FILESTATE | CGit::LOG_INFO_SHOW_MERGEDFILE,
936 &remotebranch,&localbranch);
938 CString str;
939 if(m_OutLogList.GetItemCount() == 0)
941 str.Format(IDS_PROC_SYNC_COMMITSAHEAD, 0, remotebranch);
942 m_OutLogList.ShowText(str);
943 this->m_ctrlStatus.SetWindowText(str);
944 this->m_ctrlTabCtrl.ShowTab(m_OutChangeFileList.GetDlgCtrlID()-1,FALSE);
945 this->GetDlgItem(IDC_BUTTON_EMAIL)->EnableWindow(FALSE);
947 else
949 str.Format(IDS_PROC_SYNC_COMMITSAHEAD, m_OutLogList.GetItemCount(), remotebranch);
950 this->m_ctrlStatus.SetWindowText(str);
952 AddDiffFileList(&m_OutChangeFileList,&m_arOutChangeList,localbranch,remotebranch);
954 this->m_ctrlTabCtrl.ShowTab(m_OutChangeFileList.GetDlgCtrlID()-1,TRUE);
955 this->GetDlgItem(IDC_BUTTON_EMAIL)->EnableWindow(TRUE);
958 this->m_OutLocalBranch=localbranch;
959 this->m_OutRemoteBranch=remotebranch;
964 bool CSyncDlg::IsURL()
966 CString str;
967 this->m_ctrlURL.GetWindowText(str);
968 if(str.Find(_T('\\'))>=0 || str.Find(_T('/'))>=0)
969 return true;
970 else
971 return false;
973 void CSyncDlg::OnCbnEditchangeComboboxex()
975 SetTimer(IDT_INPUT, 1000, NULL);
976 this->m_OutLogList.ShowText(CString(MAKEINTRESOURCE(IDS_PROC_SYNC_WAINTINPUT)));
978 //this->FetchOutList();
981 UINT CSyncDlg::ProgressThread()
983 m_GitCmdStatus=CProgressDlg::RunCmdList(this,m_GitCmdList,true,NULL,&this->m_bAbort);
984 InterlockedExchange(&m_bBlock, FALSE);
985 return 0;
989 LRESULT CSyncDlg::OnProgressUpdateUI(WPARAM wParam,LPARAM lParam)
991 if(wParam == MSG_PROGRESSDLG_START)
993 m_ctrlAnimate.Play(0,-1,-1);
994 this->m_ctrlProgress.SetPos(0);
995 if (m_pTaskbarList)
997 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
998 m_pTaskbarList->SetProgressValue(m_hWnd, 0, 100);
1002 if(wParam == MSG_PROGRESSDLG_END || wParam == MSG_PROGRESSDLG_FAILED)
1004 //m_bDone = true;
1005 m_ctrlAnimate.Stop();
1006 m_ctrlProgress.SetPos(100);
1007 //this->DialogEnableWindow(IDOK,TRUE);
1008 if (m_pTaskbarList)
1009 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NOPROGRESS);
1011 //if(wParam == MSG_PROGRESSDLG_END)
1012 if(this->m_CurrentCmd == GIT_COMMAND_PUSH )
1014 if(!m_GitCmdStatus)
1016 CTGitPathList list;
1017 list.AddPath(CTGitPath(g_Git.m_CurrentDir));
1018 DWORD exitcode;
1019 CString error;
1020 if (CHooks::Instance().PostPush(list,exitcode, error))
1022 if (exitcode)
1024 CString temp;
1025 temp.Format(IDS_ERR_HOOKFAILED, (LPCTSTR)error);
1026 //ReportError(temp);
1027 CMessageBox::Show(NULL,temp,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
1028 return false;
1033 EnableControlButton(true);
1034 SwitchToInput();
1035 this->FetchOutList(true);
1037 if(this->m_CurrentCmd == GIT_COMMAND_PULL )
1039 PullComplete();
1041 if(this->m_CurrentCmd == GIT_COMMAND_FETCH || this->m_CurrentCmd == GIT_COMMAND_FETCHANDREBASE)
1043 FetchComplete();
1045 if(this->m_CurrentCmd == GIT_COMMAND_SUBMODULE)
1047 //this->m_ctrlCmdOut.SetSel(-1,-1);
1048 //this->m_ctrlCmdOut.ReplaceSel(_T("Done\r\n"));
1049 //this->m_ctrlCmdOut.SetSel(-1,-1);
1050 EnableControlButton(true);
1051 SwitchToInput();
1053 if(this->m_CurrentCmd == GIT_COMMAND_REMOTE)
1055 this->FetchOutList(true);
1056 EnableControlButton(true);
1057 SwitchToInput();
1061 if(lParam != 0)
1062 ParserCmdOutput((char)lParam);
1064 return 0;
1068 void CSyncDlg::ParserCmdOutput(char ch)
1070 CProgressDlg::ParserCmdOutput(m_ctrlCmdOut,m_ctrlProgress,m_hWnd,m_pTaskbarList,m_LogText,ch);
1072 void CSyncDlg::OnBnClickedButtonCommit()
1074 CString cmd = _T("/command:commit");
1075 cmd += _T(" /path:\"");
1076 cmd += g_Git.m_CurrentDir;
1077 cmd += _T("\"");
1079 CAppUtils::RunTortoiseProc(cmd);
1082 void CSyncDlg::OnOK()
1084 UpdateCombox();
1085 this->UpdateData();
1086 m_ctrlURL.SaveHistory();
1087 SaveHistory();
1088 m_regAutoLoadPutty = this->m_bAutoLoadPuttyKey;
1089 __super::OnOK();
1092 void CSyncDlg::OnBnClickedButtonSubmodule()
1094 this->UpdateData();
1095 UpdateCombox();
1097 this->m_regSubmoduleButton = this->m_ctrlSubmodule.GetCurrentEntry();
1099 this->SwitchToRun();
1101 this->m_bAbort=false;
1102 this->m_GitCmdList.clear();
1104 ShowTab(IDC_CMD_LOG);
1106 CString cmd;
1108 switch (m_ctrlSubmodule.GetCurrentEntry())
1110 case 0:
1111 cmd=_T("git.exe submodule update --init");
1112 break;
1113 case 1:
1114 cmd=_T("git.exe submodule init");
1115 break;
1116 case 2:
1117 cmd=_T("git.exe submodule sync");
1118 break;
1121 m_GitCmdList.push_back(cmd);
1123 m_CurrentCmd = GIT_COMMAND_SUBMODULE;
1125 m_pThread = AfxBeginThread(ProgressThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
1126 if (m_pThread==NULL)
1128 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
1130 else
1132 m_pThread->m_bAutoDelete = TRUE;
1133 m_pThread->ResumeThread();
1137 void CSyncDlg::OnTimer(UINT_PTR nIDEvent)
1139 if( nIDEvent == IDT_INPUT)
1141 KillTimer(IDT_INPUT);
1142 this->FetchOutList(true);
1147 void CSyncDlg::OnLvnInLogListColumnClick(NMHDR *pNMHDR, LRESULT *pResult)
1149 *pResult = 0;
1152 LRESULT CSyncDlg::OnTaskbarBtnCreated(WPARAM /*wParam*/, LPARAM /*lParam*/)
1154 m_pTaskbarList.Release();
1155 m_pTaskbarList.CoCreateInstance(CLSID_TaskbarList);
1156 return 0;