OSDN Git Service

a1ee832359cc04cd69988f6a6c98c093cf1d1040
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / SyncDlg.cpp
1 // TortoiseGit - a Windows shell extension for easy version control\r
2 \r
3 // Copyright (C) 2008-2009 - TortoiseGit\r
4 \r
5 // This program is free software; you can redistribute it and/or\r
6 // modify it under the terms of the GNU General Public License\r
7 // as published by the Free Software Foundation; either version 2\r
8 // of the License, or (at your option) any later version.\r
9 \r
10 // This program is distributed in the hope that it will be useful,\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13 // GNU General Public License for more details.\r
14 \r
15 // You should have received a copy of the GNU General Public License\r
16 // along with this program; if not, write to the Free Software Foundation,\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\r
18 //\r
19 \r
20 // SyncDlg.cpp : implementation file\r
21 //\r
22 \r
23 #include "stdafx.h"\r
24 #include "TortoiseProc.h"\r
25 #include "SyncDlg.h"\r
26 #include "progressdlg.h"\r
27 #include "MessageBox.h"\r
28 #include "ImportPatchDlg.h"\r
29 // CSyncDlg dialog\r
30 \r
31 IMPLEMENT_DYNAMIC(CSyncDlg, CResizableStandAloneDialog)\r
32 \r
33 CSyncDlg::CSyncDlg(CWnd* pParent /*=NULL*/)\r
34         : CResizableStandAloneDialog(CSyncDlg::IDD, pParent)\r
35 {\r
36         m_pTooltip=&this->m_tooltips;\r
37         m_bInited=false;\r
38         m_CmdOutCurrentPos=0;\r
39         m_bAutoLoadPuttyKey = CAppUtils::IsSSHPutty();\r
40 }\r
41 \r
42 CSyncDlg::~CSyncDlg()\r
43 {\r
44 }\r
45 \r
46 void CSyncDlg::DoDataExchange(CDataExchange* pDX)\r
47 {\r
48         CDialog::DoDataExchange(pDX);\r
49         DDX_Check(pDX, IDC_CHECK_PUTTY_KEY, m_bAutoLoadPuttyKey);\r
50         DDX_Check(pDX, IDC_CHECK_FORCE,m_bForce);\r
51         DDX_Control(pDX, IDC_COMBOBOXEX_URL, m_ctrlURL);\r
52         DDX_Control(pDX, IDC_BUTTON_TABCTRL, m_ctrlDumyButton);\r
53         DDX_Control(pDX, IDC_BUTTON_PULL, m_ctrlPull);\r
54         DDX_Control(pDX, IDC_BUTTON_PUSH, m_ctrlPush);\r
55         DDX_Control(pDX, IDC_STATIC_STATUS, m_ctrlStatus);\r
56         DDX_Control(pDX, IDC_PROGRESS_SYNC, m_ctrlProgress);\r
57         DDX_Control(pDX, IDC_ANIMATE_SYNC, m_ctrlAnimate);\r
58 \r
59         BRANCH_COMBOX_DDX;\r
60 }\r
61 \r
62 \r
63 BEGIN_MESSAGE_MAP(CSyncDlg, CResizableStandAloneDialog)\r
64         ON_BN_CLICKED(IDC_BUTTON_PULL, &CSyncDlg::OnBnClickedButtonPull)\r
65         ON_BN_CLICKED(IDC_BUTTON_PUSH, &CSyncDlg::OnBnClickedButtonPush)\r
66         ON_BN_CLICKED(IDC_BUTTON_APPLY, &CSyncDlg::OnBnClickedButtonApply)\r
67         ON_BN_CLICKED(IDC_BUTTON_EMAIL, &CSyncDlg::OnBnClickedButtonEmail)\r
68         ON_BN_CLICKED(IDC_BUTTON_MANAGE, &CSyncDlg::OnBnClickedButtonManage)\r
69         BRANCH_COMBOX_EVENT\r
70         ON_NOTIFY(CBEN_ENDEDIT, IDC_COMBOBOXEX_URL, &CSyncDlg::OnCbenEndeditComboboxexUrl)\r
71         ON_CBN_EDITCHANGE(IDC_COMBOBOXEX_URL, &CSyncDlg::OnCbnEditchangeComboboxexUrl)\r
72         ON_MESSAGE(MSG_PROGRESSDLG_UPDATE_UI, OnProgressUpdateUI)\r
73 END_MESSAGE_MAP()\r
74 \r
75 \r
76 void CSyncDlg::EnableControlButton(bool bEnabled)\r
77 {\r
78         GetDlgItem(IDC_BUTTON_PULL)->EnableWindow(bEnabled);\r
79         GetDlgItem(IDC_BUTTON_PUSH)->EnableWindow(bEnabled);\r
80         GetDlgItem(IDC_BUTTON_APPLY)->EnableWindow(bEnabled);\r
81         GetDlgItem(IDC_BUTTON_EMAIL)->EnableWindow(bEnabled);\r
82         GetDlgItem(IDOK)->EnableWindow(bEnabled);\r
83 }\r
84 // CSyncDlg message handlers\r
85 \r
86 void CSyncDlg::OnBnClickedButtonPull()\r
87 {\r
88         // TODO: Add your control notification handler code here\r
89         this->m_regPullButton =this->m_ctrlPull.GetCurrentEntry();\r
90 }\r
91 \r
92 void CSyncDlg::OnBnClickedButtonPush()\r
93 {\r
94         // TODO: Add your control notification handler code here\r
95         this->UpdateData();\r
96 \r
97         this->m_regPushButton=this->m_ctrlPush.GetCurrentEntry();\r
98         this->SwitchToRun();\r
99         this->m_bAbort=false;\r
100         this->m_GitCmdList.clear();\r
101 \r
102         ShowTab(IDC_CMD_LOG);\r
103 \r
104         CString cmd;\r
105         CString tags;\r
106         CString force;\r
107         CString all;\r
108         this->m_strLocalBranch = this->m_ctrlLocalBranch.GetString();\r
109         this->m_ctrlRemoteBranch.GetWindowText(this->m_strRemoteBranch);\r
110         this->m_ctrlURL.GetWindowText(this->m_strURL);\r
111         m_strRemoteBranch=m_strRemoteBranch.Trim();\r
112         \r
113         this->GetDlgItem(IDC_CHECK_PUTTY_KEY)->EnableWindow(this->m_bAutoLoadPuttyKey);\r
114 \r
115         switch (m_ctrlPush.GetCurrentEntry())\r
116         {\r
117         case 1:\r
118                 tags = _T(" --tags ");\r
119                 break;\r
120         case 2:\r
121                 all = _T(" --all ");\r
122                 break;\r
123         }\r
124 \r
125         if(this->m_bForce)\r
126                 force = _T(" --force ");\r
127 \r
128         cmd.Format(_T("git.exe push %s %s %s \"%s\" %s"),\r
129                                 tags,force,all,\r
130                                 m_strURL,\r
131                                 m_strLocalBranch);\r
132 \r
133         if (!m_strRemoteBranch.IsEmpty())\r
134         {\r
135                 cmd += _T(":") + m_strRemoteBranch;\r
136         }\r
137         \r
138         m_GitCmdList.push_back(cmd);\r
139 \r
140         m_CurrentCmd = GIT_COMMAND_PUSH;\r
141 \r
142         if(this->m_bAutoLoadPuttyKey)\r
143         {\r
144                 CAppUtils::LaunchPAgent(NULL,&this->m_strURL);\r
145         }\r
146 \r
147         m_pThread = AfxBeginThread(ProgressThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);\r
148         if (m_pThread==NULL)\r
149         {\r
150 //              ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));\r
151         }\r
152         else\r
153         {\r
154                 m_pThread->m_bAutoDelete = TRUE;\r
155                 m_pThread->ResumeThread();\r
156         }\r
157         \r
158 }\r
159 \r
160 void CSyncDlg::OnBnClickedButtonApply()\r
161 {\r
162         // TODO: Add your control notification handler code here\r
163         CString oldhash;\r
164         oldhash=g_Git.GetHash(CString(_T("HEAD")));\r
165         \r
166         CImportPatchDlg dlg;\r
167         CString cmd,output;\r
168 \r
169         if(dlg.DoModal() == IDOK)\r
170         {\r
171                 int err=0;\r
172                 for(int i=0;i<dlg.m_PathList.GetCount();i++)\r
173                 {                       \r
174                         cmd.Format(_T("git.exe am \"%s\""),dlg.m_PathList[i].GetGitPathString());\r
175                         \r
176                         if(g_Git.Run(cmd,&output,CP_ACP))\r
177                         {\r
178                                 CMessageBox::Show(NULL,output,_T("TortoiseGit"),MB_OK);\r
179 \r
180                                 err=1;\r
181                                 break;\r
182                         }\r
183                         this->m_ctrlCmdOut.SetSel(-1,-1);\r
184                         this->m_ctrlCmdOut.ReplaceSel(cmd+_T("\n"));\r
185                         this->m_ctrlCmdOut.SetSel(-1,-1);\r
186                         this->m_ctrlCmdOut.ReplaceSel(output);\r
187                 }\r
188                 \r
189 \r
190                 CString newhash=g_Git.GetHash(CString(_T("HEAD")));             \r
191 \r
192                 this->m_InLogList.Clear();\r
193                 this->m_InChangeFileList.Clear();\r
194 \r
195                 if(newhash == oldhash)\r
196                 {\r
197                         this->m_ctrlTabCtrl.ShowTab(IDC_IN_CHANGELIST-1,false);\r
198                         this->m_InLogList.ShowText(_T("No commits get from patch"));\r
199                         this->m_ctrlTabCtrl.ShowTab(IDC_IN_LOGLIST-1,true);\r
200 \r
201                 }else\r
202                 {\r
203                         this->m_ctrlTabCtrl.ShowTab(IDC_IN_CHANGELIST-1,true);\r
204                         this->m_ctrlTabCtrl.ShowTab(IDC_IN_LOGLIST-1,true);\r
205                         \r
206                         this->AddDiffFileList(&m_InChangeFileList,&m_arInChangeList,newhash,oldhash);\r
207                         m_InLogList.FillGitLog(NULL,CGit::      LOG_INFO_STAT| CGit::LOG_INFO_FILESTATE | CGit::LOG_INFO_SHOW_MERGEDFILE,\r
208                                 &oldhash,&newhash);\r
209                 }\r
210 \r
211                 this->m_ctrlTabCtrl.ShowTab(IDC_CMD_LOG-1,true);\r
212 \r
213                 if(err)\r
214                 {\r
215                         this->ShowTab(IDC_CMD_LOG);\r
216 \r
217                 }else\r
218                 {\r
219                         this->ShowTab(IDC_IN_LOGLIST);\r
220                 }\r
221         }\r
222 }\r
223 \r
224 void CSyncDlg::OnBnClickedButtonEmail()\r
225 {\r
226         // TODO: Add your control notification handler code here\r
227         CString cmd,out;\r
228         \r
229         this->m_strLocalBranch = this->m_ctrlLocalBranch.GetString();\r
230         this->m_ctrlRemoteBranch.GetWindowText(this->m_strRemoteBranch);\r
231         this->m_ctrlURL.GetWindowText(this->m_strURL);\r
232         m_strURL=m_strURL.Trim();\r
233         m_strRemoteBranch=m_strRemoteBranch.Trim();\r
234         \r
235         cmd.Format(_T("git.exe  format-patch -o \"%s\" %s..%s"),\r
236                                         g_Git.m_CurrentDir,\r
237                                         m_strURL+_T('/')+m_strRemoteBranch,m_strLocalBranch);\r
238         \r
239         if(g_Git.Run(cmd,&out,CP_ACP))\r
240         {\r
241                 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);\r
242                 return ;\r
243         }\r
244 \r
245         CAppUtils::SendPatchMail(cmd,out);      \r
246 \r
247 }\r
248 void CSyncDlg::ShowProgressCtrl(bool bShow)\r
249 {\r
250         int b=bShow?SW_NORMAL:SW_HIDE;\r
251         this->m_ctrlAnimate.ShowWindow(b);\r
252         this->m_ctrlProgress.ShowWindow(b);\r
253         this->m_ctrlAnimate.Open(IDR_DOWNLOAD);\r
254         if(b == SW_NORMAL)\r
255                 this->m_ctrlAnimate.Play(0,-1,-1);\r
256         else\r
257                 this->m_ctrlAnimate.Stop();\r
258 }\r
259 void CSyncDlg::ShowInputCtrl(bool bShow)\r
260 {\r
261         int b=bShow?SW_NORMAL:SW_HIDE;\r
262         this->m_ctrlURL.ShowWindow(b);\r
263         this->m_ctrlLocalBranch.ShowWindow(b);\r
264         this->m_ctrlRemoteBranch.ShowWindow(b);\r
265         this->GetDlgItem(IDC_BUTTON_LOCAL_BRANCH)->ShowWindow(b);\r
266         this->GetDlgItem(IDC_BUTTON_REMOTE_BRANCH)->ShowWindow(b);\r
267         this->GetDlgItem(IDC_STATIC_LOCAL_BRANCH)->ShowWindow(b);\r
268         this->GetDlgItem(IDC_STATIC_REMOTE_BRANCH)->ShowWindow(b);\r
269         this->GetDlgItem(IDC_BUTTON_MANAGE)->ShowWindow(b);\r
270         this->GetDlgItem(IDC_CHECK_PUTTY_KEY)->ShowWindow(b);\r
271         this->GetDlgItem(IDC_CHECK_FORCE)->ShowWindow(b);\r
272         this->GetDlgItem(IDC_STATIC_REMOTE_URL)->ShowWindow(b);\r
273         \r
274 }\r
275 BOOL CSyncDlg::OnInitDialog()\r
276 {\r
277         CResizableStandAloneDialog::OnInitDialog();\r
278 \r
279         /*\r
280         this->m_ctrlAnimate.ShowWindow(SW_NORMAL);\r
281         this->m_ctrlAnimate.Open(IDR_DOWNLOAD);\r
282         this->m_ctrlAnimate.Play(0,-1,-1);\r
283     */\r
284 \r
285         // ------------------ Create Tabctrl -----------\r
286         CWnd *pwnd=this->GetDlgItem(IDC_BUTTON_TABCTRL);\r
287         CRect rectDummy;\r
288         pwnd->GetWindowRect(&rectDummy);\r
289         this->ScreenToClient(rectDummy);\r
290 \r
291         if (!m_ctrlTabCtrl.Create(CMFCTabCtrl::STYLE_FLAT, rectDummy, this, IDC_SYNC_TAB))\r
292         {\r
293                 TRACE0("Failed to create output tab window\n");\r
294                 return FALSE;      // fail to create\r
295         }\r
296         m_ctrlTabCtrl.SetResizeMode(CMFCTabCtrl::RESIZE_NO);\r
297 \r
298         // -------------Create Command Log Ctrl ---------\r
299         DWORD dwStyle;\r
300         dwStyle= ES_MULTILINE | ES_READONLY | WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL | ES_AUTOVSCROLL |WS_VSCROLL  ;\r
301 \r
302         if( !m_ctrlCmdOut.Create(dwStyle,rectDummy,&m_ctrlTabCtrl,IDC_CMD_LOG))\r
303         {\r
304                 TRACE0("Failed to create Log commits window\n");\r
305                 return FALSE;      // fail to create\r
306         }\r
307 \r
308         m_ctrlTabCtrl.InsertTab(&m_ctrlCmdOut,_T("Log"),-1);\r
309         \r
310         //m_ctrlCmdOut.ReplaceSel(_T("Hello"));\r
311 \r
312         //----------  Create in coming list ctrl -----------\r
313         dwStyle =LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | LVS_OWNERDATA | WS_BORDER | WS_TABSTOP | WS_CHILD | WS_VISIBLE;;\r
314 \r
315         if( !m_InLogList.Create(dwStyle,rectDummy,&m_ctrlTabCtrl,IDC_IN_LOGLIST))\r
316         {\r
317                 TRACE0("Failed to create output commits window\n");\r
318                 return FALSE;      // fail to create\r
319 \r
320         }\r
321 \r
322         m_ctrlTabCtrl.InsertTab(&m_InLogList,_T("In Commits"),-1);\r
323 \r
324         m_InLogList.InsertGitColumn();\r
325 \r
326         //----------- Create In Change file list -----------\r
327         dwStyle = LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP |LVS_SINGLESEL |WS_CHILD | WS_VISIBLE;\r
328         \r
329         if( !m_InChangeFileList.Create(dwStyle,rectDummy,&m_ctrlTabCtrl,IDC_IN_CHANGELIST))\r
330         {\r
331                 TRACE0("Failed to create output change files window\n");\r
332                 return FALSE;      // fail to create\r
333         }\r
334         m_ctrlTabCtrl.InsertTab(&m_InChangeFileList,_T("In ChangeList"),-1);\r
335 \r
336         m_InChangeFileList.Init(SVNSLC_COLEXT | SVNSLC_COLSTATUS |SVNSLC_COLADD|SVNSLC_COLDEL , _T("OutSyncDlg"),\r
337                                     (CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDSVNLC_COMPARETWO)|\r
338                                                         CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDSVNLC_GNUDIFF2)),false);\r
339 \r
340 \r
341         //----------  Create Commit List Ctrl---------------\r
342                         \r
343         dwStyle =LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | LVS_OWNERDATA | WS_BORDER | WS_TABSTOP | WS_CHILD | WS_VISIBLE;;\r
344 \r
345         if( !m_OutLogList.Create(dwStyle,rectDummy,&m_ctrlTabCtrl,IDC_OUT_LOGLIST))\r
346         {\r
347                 TRACE0("Failed to create output commits window\n");\r
348                 return FALSE;      // fail to create\r
349 \r
350         }\r
351 \r
352         m_ctrlTabCtrl.InsertTab(&m_OutLogList,_T("Out Commits"),-1);\r
353         \r
354 \r
355         m_OutLogList.InsertGitColumn();\r
356 \r
357         //------------- Create Change File List Control ----------------\r
358 \r
359         dwStyle = LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP |LVS_SINGLESEL |WS_CHILD | WS_VISIBLE;\r
360         \r
361         if( !m_OutChangeFileList.Create(dwStyle,rectDummy,&m_ctrlTabCtrl,IDC_OUT_CHANGELIST))\r
362         {\r
363                 TRACE0("Failed to create output change files window\n");\r
364                 return FALSE;      // fail to create\r
365         }\r
366         m_ctrlTabCtrl.InsertTab(&m_OutChangeFileList,_T("Out ChangeList"),-1);\r
367 \r
368         m_OutChangeFileList.Init(SVNSLC_COLEXT | SVNSLC_COLSTATUS |SVNSLC_COLADD|SVNSLC_COLDEL , _T("OutSyncDlg"),\r
369                                     (CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDSVNLC_COMPARETWO)|\r
370                                                         CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDSVNLC_GNUDIFF2)),false);\r
371 \r
372         this->m_tooltips.Create(this);\r
373 \r
374         AddAnchor(IDC_SYNC_TAB,TOP_LEFT,BOTTOM_RIGHT);\r
375 \r
376         AddAnchor(IDC_GROUP_INFO,TOP_LEFT,TOP_RIGHT);\r
377         AddAnchor(IDC_COMBOBOXEX_URL,TOP_LEFT,TOP_RIGHT);\r
378         AddAnchor(IDC_BUTTON_MANAGE,TOP_RIGHT);\r
379         AddAnchor(IDC_BUTTON_PULL,BOTTOM_LEFT);\r
380         AddAnchor(IDC_BUTTON_PUSH,BOTTOM_LEFT);\r
381         AddAnchor(IDC_BUTTON_APPLY,BOTTOM_LEFT);\r
382         AddAnchor(IDC_BUTTON_EMAIL,BOTTOM_LEFT);\r
383         AddAnchor(IDC_PROGRESS_SYNC,TOP_LEFT,TOP_RIGHT);\r
384         AddAnchor(IDOK,BOTTOM_RIGHT);\r
385         AddAnchor(IDHELP,BOTTOM_RIGHT);\r
386         AddAnchor(IDC_STATIC_STATUS,BOTTOM_LEFT);\r
387         AddAnchor(IDC_ANIMATE_SYNC,TOP_LEFT);\r
388         \r
389         BRANCH_COMBOX_ADD_ANCHOR();\r
390 \r
391         CString WorkingDir=g_Git.m_CurrentDir;\r
392         WorkingDir.Replace(_T(':'),_T('_'));\r
393         m_RegKeyRemoteBranch = CString(_T("Software\\TortoiseGit\\History\\SyncBranch\\"))+WorkingDir;\r
394 \r
395 \r
396         this->AddOthersToAnchor();\r
397         // TODO:  Add extra initialization here\r
398 \r
399         this->m_ctrlPush.AddEntry(CString(_T("Push")));\r
400         this->m_ctrlPush.AddEntry(CString(_T("Push tags")));\r
401         ///this->m_ctrlPush.AddEntry(CString(_T("Push All")));\r
402 \r
403         this->m_ctrlPull.AddEntry(CString(_T("&Pull")));\r
404         this->m_ctrlPull.AddEntry(CString(_T("&Fetch")));\r
405         this->m_ctrlPull.AddEntry(CString(_T("Fetch&&Rebase")));\r
406 \r
407         \r
408         WorkingDir.Replace(_T(':'),_T('_'));\r
409 \r
410         CString regkey ;\r
411         regkey.Format(_T("Software\\TortoiseGit\\TortoiseProc\\Sync\\%s"),WorkingDir);\r
412 \r
413         this->m_regPullButton = CRegDWORD(regkey+_T("\\Pull"),0);\r
414         this->m_regPushButton = CRegDWORD(regkey+_T("\\Push"),0);\r
415 \r
416         this->m_ctrlPull.SetCurrentEntry(this->m_regPullButton);\r
417         this->m_ctrlPush.SetCurrentEntry(this->m_regPushButton);\r
418 \r
419         CString str;\r
420         this->GetWindowText(str);\r
421         str += _T(" - ") + g_Git.m_CurrentDir;\r
422         this->SetWindowText(str);\r
423 \r
424         EnableSaveRestore(_T("SyncDlg"));\r
425 \r
426         this->LoadBranchInfo();\r
427 \r
428         this->m_bInited=true;\r
429         FetchOutList();\r
430         \r
431         m_ctrlTabCtrl.ShowTab(IDC_CMD_LOG-1,false);\r
432         m_ctrlTabCtrl.ShowTab(IDC_IN_LOGLIST-1,false);\r
433         m_ctrlTabCtrl.ShowTab(IDC_IN_CHANGELIST-1,false);\r
434         \r
435         return TRUE;  // return TRUE unless you set the focus to a control\r
436         // EXCEPTION: OCX Property Pages should return FALSE\r
437 }\r
438 \r
439 void CSyncDlg::OnBnClickedButtonManage()\r
440 {\r
441         // TODO: Add your control notification handler code here\r
442         CAppUtils::LaunchRemoteSetting();\r
443 }\r
444 \r
445 BOOL CSyncDlg::PreTranslateMessage(MSG* pMsg)\r
446 {\r
447         // TODO: Add your specialized code here and/or call the base class\r
448         m_tooltips.RelayEvent(pMsg);\r
449         return __super::PreTranslateMessage(pMsg);\r
450 }\r
451 void CSyncDlg::FetchOutList(bool force)\r
452 {\r
453         if(!m_bInited)\r
454                 return;\r
455         m_OutChangeFileList.Clear();\r
456         this->m_OutLogList.Clear();\r
457 \r
458         CString remote;\r
459         this->m_ctrlURL.GetWindowText(remote);\r
460         CString remotebranch;\r
461         this->m_ctrlRemoteBranch.GetWindowText(remotebranch);\r
462         remotebranch=remote+_T("/")+remotebranch;\r
463 \r
464         if(IsURL())\r
465         {\r
466                 CString str;\r
467                 str=_T("Don't know what will push befause you enter URL");\r
468                 m_OutLogList.ShowText(str);\r
469                 this->m_ctrlTabCtrl.ShowTab(m_OutChangeFileList.GetDlgCtrlID()-1,FALSE);\r
470                 m_OutLocalBranch.Empty();\r
471                 m_OutRemoteBranch.Empty();\r
472 \r
473                 this->GetDlgItem(IDC_BUTTON_EMAIL)->EnableWindow(FALSE);\r
474                 return ;\r
475         \r
476         }else if(g_Git.GetHash(remotebranch).GetLength()<40)\r
477         {\r
478                 CString str;\r
479                 str.Format(_T("Don't know what will push befause unkown \"%s\""),remotebranch);\r
480                 m_OutLogList.ShowText(str);\r
481                 this->m_ctrlTabCtrl.ShowTab(m_OutChangeFileList.GetDlgCtrlID()-1,FALSE);\r
482                 m_OutLocalBranch.Empty();\r
483                 m_OutRemoteBranch.Empty();\r
484 \r
485                 this->GetDlgItem(IDC_BUTTON_EMAIL)->EnableWindow(FALSE);\r
486                 return ;\r
487         }\r
488         else\r
489         {\r
490                 CString localbranch;\r
491                 localbranch=this->m_ctrlLocalBranch.GetString();\r
492 \r
493                 if(localbranch != m_OutLocalBranch || m_OutRemoteBranch != remotebranch || force)\r
494                 {\r
495                         m_OutLogList.ClearText();\r
496                         m_OutLogList.FillGitLog(NULL,CGit::     LOG_INFO_STAT| CGit::LOG_INFO_FILESTATE | CGit::LOG_INFO_SHOW_MERGEDFILE,\r
497                                 &remotebranch,&localbranch);\r
498                         \r
499                         CString str;\r
500                         if(m_OutLogList.GetItemCount() == 0)\r
501                         {                       \r
502                                 str.Format(_T("No commits ahead \"%s\""),remotebranch);\r
503                                 m_OutLogList.ShowText(str);\r
504                                 this->m_ctrlStatus.SetWindowText(str);\r
505                                 this->m_ctrlTabCtrl.ShowTab(m_OutChangeFileList.GetDlgCtrlID()-1,FALSE);\r
506                                 this->GetDlgItem(IDC_BUTTON_EMAIL)->EnableWindow(FALSE);\r
507                         }\r
508                         else\r
509                         {\r
510                                 str.Format(_T("%d commits ahead \"%s\""),m_OutLogList.GetItemCount(),remotebranch);\r
511                                 this->m_ctrlStatus.SetWindowText(str);\r
512 \r
513                                 AddDiffFileList(&m_OutChangeFileList,&m_arOutChangeList,localbranch,remotebranch);\r
514                                 \r
515                                 this->m_ctrlTabCtrl.ShowTab(m_OutChangeFileList.GetDlgCtrlID()-1,TRUE);\r
516                                 this->GetDlgItem(IDC_BUTTON_EMAIL)->EnableWindow(TRUE);\r
517                         }\r
518                 }\r
519                 this->m_OutLocalBranch=localbranch;\r
520                 this->m_OutRemoteBranch=remotebranch;\r
521         }\r
522 \r
523 }\r
524 \r
525 bool CSyncDlg::IsURL()\r
526 {\r
527         CString str;\r
528         this->m_ctrlURL.GetWindowText(str);\r
529         if(str.Find(_T('\\'))>=0 || str.Find(_T('/'))>=0)\r
530                 return true;\r
531         else\r
532                 return false;\r
533 }\r
534 void CSyncDlg::OnCbenEndeditComboboxexUrl(NMHDR *pNMHDR, LRESULT *pResult)\r
535 {\r
536         // TODO: Add your control notification handler code here\r
537         *pResult = 0;\r
538 }\r
539 \r
540 void CSyncDlg::OnCbnEditchangeComboboxexUrl()\r
541 {\r
542         this->FetchOutList();\r
543         // TODO: Add your control notification handler code here\r
544 }\r
545 \r
546 UINT CSyncDlg::ProgressThread()\r
547 {\r
548         m_GitCmdStatus=CProgressDlg::RunCmdList(this,m_GitCmdList,true,NULL,&this->m_bAbort);\r
549         return 0;\r
550 }\r
551 \r
552 \r
553 LRESULT CSyncDlg::OnProgressUpdateUI(WPARAM wParam,LPARAM lParam)\r
554 {\r
555         if(wParam == MSG_PROGRESSDLG_START)\r
556         {\r
557                 m_ctrlAnimate.Play(0,-1,-1);\r
558                 this->m_ctrlProgress.SetPos(0);\r
559         }\r
560 \r
561         if(wParam == MSG_PROGRESSDLG_END || wParam == MSG_PROGRESSDLG_FAILED)\r
562         {\r
563                 //m_bDone = true;\r
564                 m_ctrlAnimate.Stop();\r
565                 m_ctrlProgress.SetPos(100);\r
566                 //this->DialogEnableWindow(IDOK,TRUE);\r
567 \r
568                 //if(wParam == MSG_PROGRESSDLG_END)\r
569                 {\r
570                         EnableControlButton(true);\r
571                         SwitchToInput();\r
572                         this->FetchOutList(true);\r
573                 }\r
574         }\r
575 \r
576         if(lParam != 0)\r
577                 ParserCmdOutput((TCHAR)lParam);\r
578 \r
579         return 0;\r
580 }\r
581 \r
582 void CSyncDlg::ParserCmdOutput(TCHAR ch)\r
583 {\r
584         //TRACE(_T("%c"),ch);\r
585         int linenum;\r
586         int index;\r
587         linenum = this->m_ctrlCmdOut.GetLineCount();\r
588 \r
589         if( ch == _T('\r') )\r
590         {\r
591                 if(linenum>0)\r
592                         m_CmdOutCurrentPos = this->m_ctrlCmdOut.LineIndex(linenum-1);\r
593                 else\r
594                         m_CmdOutCurrentPos = 0;\r
595 \r
596                 //TRACE(_T("line %d - %d\n"),index,m_ctrlCmdOut.GetTextLength());\r
597         }else\r
598                 m_CmdOutCurrentPos++;\r
599                 \r
600         this->m_ctrlCmdOut.SetSel(m_CmdOutCurrentPos,m_CmdOutCurrentPos+1);\r
601         \r
602         if( ch != _T('\r') )\r
603                 this->m_ctrlCmdOut.ReplaceSel(CString(ch));\r
604         \r
605         int firstline = m_ctrlCmdOut.GetFirstVisibleLine();\r
606         if( linenum - firstline > 4 )\r
607                 this->m_ctrlCmdOut.LineScroll(linenum - firstline -4);\r
608 \r
609         if( ch == _T('\r') || ch == _T('\n') )\r
610         {\r
611                 int s1=m_LogText.Find(_T(':'));\r
612                 int s2=m_LogText.Find(_T('%'));\r
613                 if(s1>0 && s2>0)\r
614                 {\r
615                         //      this->m_CurrentWork.SetWindowTextW(m_LogText.Left(s1));\r
616                         int pos=CProgressDlg::FindPercentage(m_LogText);\r
617                         TRACE(_T("Pos %d\r\n"),pos);\r
618                         if(pos>0)\r
619                                 this->m_ctrlProgress.SetPos(pos);\r
620                 }\r
621                 m_LogText=_T("");       \r
622         }\r
623         m_LogText+=ch;\r
624 \r
625 }