776bb24cdfa28b356c98b50e4238fb0299851954
[TortoiseGit.git] / src / TortoiseProc / GitProgressDlg.cpp
blob776bb24cdfa28b356c98b50e4238fb0299851954
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2013 - TortoiseGit
4 // Copyright (C) 2003-2008 - TortoiseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "stdafx.h"
21 #include "TortoiseProc.h"
22 #include "messagebox.h"
23 #include "GITProgressDlg.h"
24 #include "LogDlg.h"
25 #include "TGitPath.h"
26 #include "registry.h"
27 #include "GitStatus.h"
28 #include "AppUtils.h"
29 #include "PathUtils.h"
30 #include "StringUtils.h"
31 #include "TempFile.h"
32 #include "UnicodeUtils.h"
33 #include "SoundUtils.h"
34 #include "GitDiff.h"
35 #include "Hooks.h"
36 #include "DropFiles.h"
37 //#include "GitLogHelper.h"
38 #include "RegHistory.h"
39 //#include "ConflictResolveDlg.h"
40 #include "LogFile.h"
41 #include "ShellUpdater.h"
42 #include "IconMenu.h"
43 #include "BugTraqAssociations.h"
44 #include "patch.h"
45 #include "MassiveGitTask.h"
46 #include "git2.h"
47 #include "SmartHandle.h"
49 static UINT WM_GITPROGRESS = RegisterWindowMessage(_T("TORTOISEGIT_GITPROGRESS_MSG"));
51 BOOL CGitProgressDlg::m_bAscending = FALSE;
52 int CGitProgressDlg::m_nSortedColumn = -1;
54 #define TRANSFERTIMER 100
55 #define VISIBLETIMER 101
57 enum GITProgressDlgContextMenuCommands
59 // needs to start with 1, since 0 is the return value if *nothing* is clicked on in the context menu
60 ID_COMPARE = 1,
61 ID_EDITCONFLICT,
62 ID_CONFLICTRESOLVE,
63 ID_CONFLICTUSETHEIRS,
64 ID_CONFLICTUSEMINE,
65 ID_LOG,
66 ID_OPEN,
67 ID_OPENWITH,
68 ID_EXPLORE,
69 ID_COPY
72 IMPLEMENT_DYNAMIC(CGitProgressDlg, CResizableStandAloneDialog)
73 CGitProgressDlg::CGitProgressDlg(CWnd* pParent /*=NULL*/)
74 : CResizableStandAloneDialog(CGitProgressDlg::IDD, pParent)
75 , m_bCancelled(FALSE)
76 , m_pThread(NULL)
77 , m_bErrorsOccurred(false)
78 , m_bBare(false)
79 , m_bNoCheckout(false)
80 #if 0
81 , m_Revision(_T("HEAD"))
82 //, m_RevisionEnd(0)
83 , m_bLockWarning(false)
84 , m_bLockExists(false)
85 , m_bThreadRunning(FALSE)
86 , m_nConflicts(0)
87 , m_bMergesAddsDeletesOccurred(FALSE)
89 , m_options(ProgOptNone)
90 , m_dwCloseOnEnd((DWORD)-1)
91 , m_bFinishedItemAdded(false)
92 , m_bLastVisible(false)
93 // , m_depth(svn_depth_unknown)
94 , m_itemCount(-1)
95 , m_itemCountTotal(-1)
96 , m_AlwaysConflicted(false)
97 , m_BugTraqProvider(NULL)
98 , sDryRun(MAKEINTRESOURCE(IDS_PROGRS_DRYRUN))
99 , sRecordOnly(MAKEINTRESOURCE(IDS_MERGE_RECORDONLY))
100 #endif
104 CGitProgressDlg::~CGitProgressDlg()
106 for (size_t i = 0; i < m_arData.size(); ++i)
108 delete m_arData[i];
110 if(m_pThread != NULL)
112 delete m_pThread;
116 void CGitProgressDlg::DoDataExchange(CDataExchange* pDX)
118 CResizableStandAloneDialog::DoDataExchange(pDX);
119 DDX_Control(pDX, IDC_SVNPROGRESS, m_ProgList);
120 DDX_Control(pDX, IDC_TITLE_ANIMATE, m_Animate);
123 BEGIN_MESSAGE_MAP(CGitProgressDlg, CResizableStandAloneDialog)
124 ON_BN_CLICKED(IDC_LOGBUTTON, OnBnClickedLogbutton)
125 ON_NOTIFY(NM_CUSTOMDRAW, IDC_SVNPROGRESS, OnNMCustomdrawSvnprogress)
126 ON_WM_CLOSE()
127 ON_NOTIFY(NM_DBLCLK, IDC_SVNPROGRESS, OnNMDblclkSvnprogress)
128 ON_NOTIFY(HDN_ITEMCLICK, 0, OnHdnItemclickSvnprogress)
129 ON_WM_SETCURSOR()
130 ON_WM_CONTEXTMENU()
131 ON_REGISTERED_MESSAGE(WM_GITPROGRESS, OnGitProgress)
132 ON_WM_TIMER()
133 ON_EN_SETFOCUS(IDC_INFOTEXT, &CGitProgressDlg::OnEnSetfocusInfotext)
134 ON_NOTIFY(LVN_BEGINDRAG, IDC_SVNPROGRESS, &CGitProgressDlg::OnLvnBegindragSvnprogress)
135 ON_WM_SIZE()
136 ON_NOTIFY(LVN_GETDISPINFO, IDC_SVNPROGRESS, &CGitProgressDlg::OnLvnGetdispinfoSvnprogress)
137 ON_BN_CLICKED(IDC_NONINTERACTIVE, &CGitProgressDlg::OnBnClickedNoninteractive)
138 ON_MESSAGE(WM_SHOWCONFLICTRESOLVER, OnShowConflictResolver)
139 ON_REGISTERED_MESSAGE(WM_TASKBARBTNCREATED, OnTaskbarBtnCreated)
140 ON_WM_CTLCOLOR()
141 END_MESSAGE_MAP()
143 BOOL CGitProgressDlg::Cancel()
145 return m_bCancelled;
148 LRESULT CGitProgressDlg::OnShowConflictResolver(WPARAM /*wParam*/, LPARAM /*lParam*/)
150 #if 0
151 CConflictResolveDlg dlg(this);
152 const svn_wc_conflict_description_t *description = (svn_wc_conflict_description_t *)lParam;
153 if (description)
155 dlg.SetConflictDescription(description);
156 if (m_pTaskbarList)
158 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_PAUSED);
160 if (dlg.DoModal() == IDOK)
162 if (dlg.GetResult() == svn_wc_conflict_choose_postpone)
164 // if the result is conflicted and the dialog returned IDOK,
165 // that means we should not ask again in case of a conflict
166 m_AlwaysConflicted = true;
167 ::SendMessage(GetDlgItem(IDC_NONINTERACTIVE)->GetSafeHwnd(), BM_SETCHECK, BST_CHECKED, 0);
170 m_mergedfile = dlg.GetMergedFile();
171 m_bCancelled = dlg.IsCancelled();
172 if (m_pTaskbarList)
173 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_INDETERMINATE);
174 return dlg.GetResult();
177 return svn_wc_conflict_choose_postpone;
178 #endif
179 return 0;
181 #if 0
182 svn_wc_conflict_choice_t CGitProgressDlg::ConflictResolveCallback(const svn_wc_conflict_description_t *description, CString& mergedfile)
184 // we only bother the user when merging
185 if (((m_Command == GitProgress_Merge)||(m_Command == GitProgress_MergeAll)||(m_Command == GitProgress_MergeReintegrate))&&(!m_AlwaysConflicted)&&(description))
187 // we're in a worker thread here. That means we must not show a dialog from the thread
188 // but let the UI thread do it.
189 // To do that, we send a message to the UI thread and let it show the conflict resolver dialog.
190 LRESULT dlgResult = ::SendMessage(GetSafeHwnd(), WM_SHOWCONFLICTRESOLVER, 0, (LPARAM)description);
191 mergedfile = m_mergedfile;
192 return (svn_wc_conflict_choice_t)dlgResult;
195 return svn_wc_conflict_choose_postpone;
197 #endif
198 void CGitProgressDlg::AddItemToList()
200 int totalcount = m_ProgList.GetItemCount();
202 m_ProgList.SetItemCountEx(totalcount+1, LVSICF_NOSCROLL|LVSICF_NOINVALIDATEALL);
203 // make columns width fit
204 if (iFirstResized < 30)
206 // only resize the columns for the first 30 or so entries.
207 // after that, don't resize them anymore because that's an
208 // expensive function call and the columns will be sized
209 // close enough already.
210 ResizeColumns();
211 ++iFirstResized;
214 // Make sure the item is *entirely* visible even if the horizontal
215 // scroll bar is visible.
216 int count = m_ProgList.GetCountPerPage();
217 if (totalcount <= (m_ProgList.GetTopIndex() + count + nEnsureVisibleCount + 2))
219 ++nEnsureVisibleCount;
220 m_bLastVisible = true;
222 else
224 nEnsureVisibleCount = 0;
225 if (IsIconic() == 0)
226 m_bLastVisible = false;
231 BOOL CGitProgressDlg::Notify(const CTGitPath& path, git_wc_notify_action_t action,
232 int /*status*/ ,
233 CString *strErr
235 svn_node_kind_t kind, const CString& mime_type,
236 svn_wc_notify_state_t content_state,
237 svn_wc_notify_state_t prop_state, LONG rev,
238 const svn_lock_t * lock, svn_wc_notify_lock_state_t lock_state,
239 const CString& changelistname,
240 svn_merge_range_t * range,
241 svn_error_t * err, apr_pool_t * pool
244 bool bNoNotify = false;
245 bool bDoAddData = true;
246 NotificationData * data = new NotificationData();
247 data->path = path;
248 data->action = action;
249 data->sPathColumnText=path.GetGitPathString();
250 data->bAuxItem = false;
252 this->m_Animate.ShowWindow(SW_HIDE);
254 #if 0
255 data->kind = kind;
256 data->mime_type = mime_type;
257 data->content_state = content_state;
258 data->prop_state = prop_state;
259 data->rev = rev;
260 data->lock_state = lock_state;
261 data->changelistname = changelistname;
262 if ((lock)&&(lock->owner))
263 data->owner = CUnicodeUtils::GetUnicode(lock->owner);
264 data->sPathColumnText = path.GetUIPathString();
265 if (!m_basePath.IsEmpty())
266 data->basepath = m_basePath;
267 if (range)
268 data->merge_range = *range;
269 #endif
270 switch (data->action)
272 case git_wc_notify_add:
273 //case svn_wc_notify_update_add:
274 // if ((data->content_state == svn_wc_notify_state_conflicted) || (data->prop_state == svn_wc_notify_state_conflicted))
275 // {
276 // data->color = m_Colors.GetColor(CColors::Conflict);
277 // data->bConflictedActionItem = true;
278 // data->sActionColumnText.LoadString(IDS_SVNACTION_CONFLICTED);
279 // ++m_nConflicts;
280 // }
281 // else
282 // {
283 // m_bMergesAddsDeletesOccurred = true;
284 data->sActionColumnText.LoadString(IDS_SVNACTION_ADD);
285 data->color = m_Colors.GetColor(CColors::Added);
286 // }
287 break;
288 case git_wc_notify_sendmail_start:
289 data->bAuxItem = true;
290 data->sActionColumnText.LoadString(IDS_SVNACTION_SENDMAIL_START);
291 data->color = m_Colors.GetColor(CColors::Modified);
292 break;
294 case git_wc_notify_sendmail_error:
295 data->bAuxItem = true;
296 data->sActionColumnText.LoadString(IDS_SVNACTION_SENDMAIL_ERROR);
297 if(strErr)
298 data->sPathColumnText = *strErr;
299 else
300 data->sPathColumnText.Empty();
301 data->color = m_Colors.GetColor(CColors::Modified);
302 break;
304 case git_wc_notify_sendmail_done:
306 data->sActionColumnText.LoadString(IDS_SVNACTION_SENDMAIL_DONE);
307 data->sPathColumnText.Empty();
308 data->color = m_Colors.GetColor(CColors::Modified);
309 break;
311 case git_wc_notify_sendmail_retry:
312 data->sActionColumnText.LoadString(IDS_SVNACTION_SENDMAIL_RETRY);
313 data->sPathColumnText.Empty();
314 data->color = m_Colors.GetColor(CColors::Modified);
315 break;
318 case git_wc_notify_resolved:
319 data->sActionColumnText.LoadString(IDS_SVNACTION_RESOLVE);
320 break;
322 case git_wc_notify_revert:
323 data->sActionColumnText.LoadString(IDS_SVNACTION_REVERT);
324 break;
326 case git_wc_notify_checkout:
327 data->sActionColumnText.LoadString(IDS_PROGRS_CMD_CHECKOUT);
328 data->color = m_Colors.GetColor(CColors::Added);
329 data->bAuxItem = false;
330 break;
332 #if 0
333 case svn_wc_notify_commit_added:
334 data->sActionColumnText.LoadString(IDS_SVNACTION_ADDING);
335 data->color = m_Colors.GetColor(CColors::Added);
336 break;
337 case svn_wc_notify_copy:
338 data->sActionColumnText.LoadString(IDS_SVNACTION_COPY);
339 break;
340 case svn_wc_notify_commit_modified:
341 data->sActionColumnText.LoadString(IDS_SVNACTION_MODIFIED);
342 data->color = m_Colors.GetColor(CColors::Modified);
343 break;
344 case svn_wc_notify_delete:
345 case svn_wc_notify_update_delete:
346 data->sActionColumnText.LoadString(IDS_SVNACTION_DELETE);
347 m_bMergesAddsDeletesOccurred = true;
348 data->color = m_Colors.GetColor(CColors::Deleted);
349 break;
350 case svn_wc_notify_commit_deleted:
351 data->sActionColumnText.LoadString(IDS_SVNACTION_DELETING);
352 data->color = m_Colors.GetColor(CColors::Deleted);
353 break;
354 case svn_wc_notify_restore:
355 data->sActionColumnText.LoadString(IDS_SVNACTION_RESTORE);
356 break;
358 case svn_wc_notify_update_replace:
359 case svn_wc_notify_commit_replaced:
360 data->sActionColumnText.LoadString(IDS_SVNACTION_REPLACED);
361 data->color = m_Colors.GetColor(CColors::Deleted);
362 break;
363 case svn_wc_notify_exists:
364 if ((data->content_state == svn_wc_notify_state_conflicted) || (data->prop_state == svn_wc_notify_state_conflicted))
366 data->color = m_Colors.GetColor(CColors::Conflict);
367 data->bConflictedActionItem = true;
368 ++m_nConflicts;
369 data->sActionColumnText.LoadString(IDS_SVNACTION_CONFLICTED);
371 else if ((data->content_state == svn_wc_notify_state_merged) || (data->prop_state == svn_wc_notify_state_merged))
373 data->color = m_Colors.GetColor(CColors::Merged);
374 m_bMergesAddsDeletesOccurred = true;
375 data->sActionColumnText.LoadString(IDS_SVNACTION_MERGED);
377 else
378 data->sActionColumnText.LoadString(IDS_SVNACTION_EXISTS);
379 break;
380 case svn_wc_notify_update_update:
381 // if this is an inoperative dir change, don't show the notification.
382 // an inoperative dir change is when a directory gets updated without
383 // any real change in either text or properties.
384 if ((kind == svn_node_dir)
385 && ((prop_state == svn_wc_notify_state_inapplicable)
386 || (prop_state == svn_wc_notify_state_unknown)
387 || (prop_state == svn_wc_notify_state_unchanged)))
389 bNoNotify = true;
390 break;
392 if ((data->content_state == svn_wc_notify_state_conflicted) || (data->prop_state == svn_wc_notify_state_conflicted))
394 data->color = m_Colors.GetColor(CColors::Conflict);
395 data->bConflictedActionItem = true;
396 ++m_nConflicts;
397 data->sActionColumnText.LoadString(IDS_SVNACTION_CONFLICTED);
399 else if ((data->content_state == svn_wc_notify_state_merged) || (data->prop_state == svn_wc_notify_state_merged))
401 data->color = m_Colors.GetColor(CColors::Merged);
402 m_bMergesAddsDeletesOccurred = true;
403 data->sActionColumnText.LoadString(IDS_SVNACTION_MERGED);
405 else if (((data->content_state != svn_wc_notify_state_unchanged)&&(data->content_state != svn_wc_notify_state_unknown)) ||
406 ((data->prop_state != svn_wc_notify_state_unchanged)&&(data->prop_state != svn_wc_notify_state_unknown)))
408 data->sActionColumnText.LoadString(IDS_SVNACTION_UPDATE);
410 else
412 bNoNotify = true;
413 break;
415 if (lock_state == svn_wc_notify_lock_state_unlocked)
417 CString temp(MAKEINTRESOURCE(IDS_SVNACTION_UNLOCKED));
418 data->sActionColumnText += _T(", ") + temp;
420 break;
422 case svn_wc_notify_update_external:
423 // For some reason we build a list of externals...
424 m_ExtStack.AddHead(path.GetUIPathString());
425 data->sActionColumnText.LoadString(IDS_SVNACTION_EXTERNAL);
426 data->bAuxItem = true;
427 break;
429 case svn_wc_notify_update_completed:
431 data->sActionColumnText.LoadString(IDS_SVNACTION_COMPLETED);
432 data->bAuxItem = true;
433 bool bEmpty = !!m_ExtStack.IsEmpty();
434 if (!bEmpty)
435 data->sPathColumnText.Format(IDS_PROGRS_PATHATREV, (LPCTSTR)m_ExtStack.RemoveHead(), rev);
436 else
437 data->sPathColumnText.Format(IDS_PROGRS_ATREV, rev);
439 if ((m_nConflicts>0)&&(bEmpty))
441 // We're going to add another aux item - let's shove this current onto the list first
442 // I don't really like this, but it will do for the moment.
443 m_arData.push_back(data);
444 AddItemToList();
446 data = new NotificationData();
447 data->bAuxItem = true;
448 data->sActionColumnText.LoadString(IDS_PROGRS_CONFLICTSOCCURED_WARNING);
449 data->sPathColumnText.LoadString(IDS_PROGRS_CONFLICTSOCCURED);
450 data->color = m_Colors.GetColor(CColors::Conflict);
451 CSoundUtils::PlayTSVNWarning();
452 // This item will now be added after the switch statement
454 if (!m_basePath.IsEmpty())
455 m_FinishedRevMap[m_basePath.GetSVNApiPath(pool)] = rev;
456 m_RevisionEnd = rev;
457 m_bFinishedItemAdded = true;
459 break;
460 case svn_wc_notify_commit_postfix_txdelta:
461 data->sActionColumnText.LoadString(IDS_SVNACTION_POSTFIX);
462 break;
463 case svn_wc_notify_failed_revert:
464 data->sActionColumnText.LoadString(IDS_SVNACTION_FAILEDREVERT);
465 break;
466 case svn_wc_notify_status_completed:
467 case svn_wc_notify_status_external:
468 data->sActionColumnText.LoadString(IDS_SVNACTION_STATUS);
469 break;
470 case svn_wc_notify_skip:
471 if ((content_state == svn_wc_notify_state_missing)||(content_state == svn_wc_notify_state_obstructed)||(content_state == svn_wc_notify_state_conflicted))
473 data->sActionColumnText.LoadString(IDS_SVNACTION_SKIPMISSING);
475 // The color settings dialog describes the red color with
476 // "possible or real conflict / obstructed" which also applies to
477 // skipped targets during a merge. So we just use the same color.
478 data->color = m_Colors.GetColor(CColors::Conflict);
480 else
481 data->sActionColumnText.LoadString(IDS_SVNACTION_SKIP);
482 break;
483 case svn_wc_notify_locked:
484 if ((lock)&&(lock->owner))
485 data->sActionColumnText.Format(IDS_SVNACTION_LOCKEDBY, (LPCTSTR)CUnicodeUtils::GetUnicode(lock->owner));
486 break;
487 case svn_wc_notify_unlocked:
488 data->sActionColumnText.LoadString(IDS_SVNACTION_UNLOCKED);
489 break;
490 case svn_wc_notify_failed_lock:
491 data->sActionColumnText.LoadString(IDS_SVNACTION_FAILEDLOCK);
492 m_arData.push_back(data);
493 AddItemToList();
494 ReportError(SVN::GetErrorString(err));
495 bDoAddData = false;
496 if (err->apr_err == SVN_ERR_FS_OUT_OF_DATE)
497 m_bLockWarning = true;
498 if (err->apr_err == SVN_ERR_FS_PATH_ALREADY_LOCKED)
499 m_bLockExists = true;
500 break;
501 case svn_wc_notify_failed_unlock:
502 data->sActionColumnText.LoadString(IDS_SVNACTION_FAILEDUNLOCK);
503 m_arData.push_back(data);
504 AddItemToList();
505 ReportError(SVN::GetErrorString(err));
506 bDoAddData = false;
507 if (err->apr_err == SVN_ERR_FS_OUT_OF_DATE)
508 m_bLockWarning = true;
509 break;
510 case svn_wc_notify_changelist_set:
511 data->sActionColumnText.Format(IDS_SVNACTION_CHANGELISTSET, (LPCTSTR)data->changelistname);
512 break;
513 case svn_wc_notify_changelist_clear:
514 data->sActionColumnText.LoadString(IDS_SVNACTION_CHANGELISTCLEAR);
515 break;
516 case svn_wc_notify_changelist_moved:
517 data->sActionColumnText.Format(IDS_SVNACTION_CHANGELISTMOVED, (LPCTSTR)data->changelistname);
518 break;
519 case svn_wc_notify_foreign_merge_begin:
520 case svn_wc_notify_merge_begin:
521 if (range == NULL)
522 data->sActionColumnText.LoadString(IDS_SVNACTION_MERGEBEGINNONE);
523 else if ((data->merge_range.start == data->merge_range.end) || (data->merge_range.start == data->merge_range.end - 1))
524 data->sActionColumnText.Format(IDS_SVNACTION_MERGEBEGINSINGLE, data->merge_range.end);
525 else if (data->merge_range.start - 1 == data->merge_range.end)
526 data->sActionColumnText.Format(IDS_SVNACTION_MERGEBEGINSINGLEREVERSE, data->merge_range.start);
527 else if (data->merge_range.start < data->merge_range.end)
528 data->sActionColumnText.Format(IDS_SVNACTION_MERGEBEGINMULTIPLE, data->merge_range.start + 1, data->merge_range.end);
529 else
530 data->sActionColumnText.Format(IDS_SVNACTION_MERGEBEGINMULTIPLEREVERSE, data->merge_range.start, data->merge_range.end + 1);
531 data->bAuxItem = true;
532 break;
533 #endif
534 default:
535 break;
536 } // switch (data->action)
538 if (bNoNotify)
539 delete data;
540 else
542 if (bDoAddData)
544 m_arData.push_back(data);
545 AddItemToList();
546 if ((!data->bAuxItem) && (m_itemCount > 0))
548 CProgressCtrl * progControl = (CProgressCtrl *)GetDlgItem(IDC_PROGRESSBAR);
549 progControl->ShowWindow(SW_SHOW);
550 progControl->SetPos(m_itemCount);
551 progControl->SetRange32(0, m_itemCountTotal);
552 if (m_pTaskbarList)
554 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
555 m_pTaskbarList->SetProgressValue(m_hWnd, m_itemCountTotal - m_itemCount, m_itemCountTotal);
556 m_pTaskbarList->SetProgressValue(m_hWnd, m_itemCount, m_itemCountTotal);
560 //if ((action == svn_wc_notify_commit_postfix_txdelta)&&(bSecondResized == FALSE))
562 // ResizeColumns();
563 // bSecondResized = TRUE;
567 return TRUE;
571 CString CGitProgressDlg::BuildInfoString()
573 CString infotext;
574 if(this->m_Command == GitProgress_Resolve)
575 infotext = _T("You need commit your change after resolve conflict");
576 #if 0
578 CString temp;
579 int added = 0;
580 int copied = 0;
581 int deleted = 0;
582 int restored = 0;
583 int reverted = 0;
584 int resolved = 0;
585 int conflicted = 0;
586 int updated = 0;
587 int merged = 0;
588 int modified = 0;
589 int skipped = 0;
590 int replaced = 0;
592 for (size_t i=0; i<m_arData.size(); ++i)
594 const NotificationData * dat = m_arData[i];
595 switch (dat->action)
597 case svn_wc_notify_add:
598 case svn_wc_notify_update_add:
599 case svn_wc_notify_commit_added:
600 if (dat->bConflictedActionItem)
601 ++conflicted;
602 else
603 ++added;
604 break;
605 case svn_wc_notify_copy:
606 ++copied;
607 break;
608 case svn_wc_notify_delete:
609 case svn_wc_notify_update_delete:
610 case svn_wc_notify_commit_deleted:
611 ++deleted;
612 break;
613 case svn_wc_notify_restore:
614 ++restored;
615 break;
616 case svn_wc_notify_revert:
617 ++reverted;
618 break;
619 case svn_wc_notify_resolved:
620 ++resolved;
621 break;
622 case svn_wc_notify_update_update:
623 if (dat->bConflictedActionItem)
624 ++conflicted;
625 else if ((dat->content_state == svn_wc_notify_state_merged) || (dat->prop_state == svn_wc_notify_state_merged))
626 ++merged;
627 else
628 ++updated;
629 break;
630 case svn_wc_notify_commit_modified:
631 ++modified;
632 break;
633 case svn_wc_notify_skip:
634 ++skipped;
635 break;
636 case svn_wc_notify_commit_replaced:
637 ++replaced;
638 break;
641 if (conflicted)
643 temp.LoadString(IDS_SVNACTION_CONFLICTED);
644 infotext += temp;
645 temp.Format(_T(":%d "), conflicted);
646 infotext += temp;
648 if (skipped)
650 temp.LoadString(IDS_SVNACTION_SKIP);
651 infotext += temp;
652 infotext.AppendFormat(_T(":%d "), skipped);
654 if (merged)
656 temp.LoadString(IDS_SVNACTION_MERGED);
657 infotext += temp;
658 infotext.AppendFormat(_T(":%d "), merged);
660 if (added)
662 temp.LoadString(IDS_SVNACTION_ADD);
663 infotext += temp;
664 infotext.AppendFormat(_T(":%d "), added);
666 if (deleted)
668 temp.LoadString(IDS_SVNACTION_DELETE);
669 infotext += temp;
670 infotext.AppendFormat(_T(":%d "), deleted);
672 if (modified)
674 temp.LoadString(IDS_SVNACTION_MODIFIED);
675 infotext += temp;
676 infotext.AppendFormat(_T(":%d "), modified);
678 if (copied)
680 temp.LoadString(IDS_SVNACTION_COPY);
681 infotext += temp;
682 infotext.AppendFormat(_T(":%d "), copied);
684 if (replaced)
686 temp.LoadString(IDS_SVNACTION_REPLACED);
687 infotext += temp;
688 infotext.AppendFormat(_T(":%d "), replaced);
690 if (updated)
692 temp.LoadString(IDS_SVNACTION_UPDATE);
693 infotext += temp;
694 infotext.AppendFormat(_T(":%d "), updated);
696 if (restored)
698 temp.LoadString(IDS_SVNACTION_RESTORE);
699 infotext += temp;
700 infotext.AppendFormat(_T(":%d "), restored);
702 if (reverted)
704 temp.LoadString(IDS_SVNACTION_REVERT);
705 infotext += temp;
706 infotext.AppendFormat(_T(":%d "), reverted);
708 if (resolved)
710 temp.LoadString(IDS_SVNACTION_RESOLVE);
711 infotext += temp;
712 infotext.AppendFormat(_T(":%d "), resolved);
714 #endif
715 return infotext;
718 void CGitProgressDlg::SetSelectedList(const CTGitPathList& selPaths)
720 m_selectedPaths = selPaths;
723 void CGitProgressDlg::ResizeColumns()
725 m_ProgList.SetRedraw(FALSE);
727 TCHAR textbuf[MAX_PATH];
729 int maxcol = ((CHeaderCtrl*)(m_ProgList.GetDlgItem(0)))->GetItemCount()-1;
730 for (int col = 0; col <= maxcol; ++col)
732 // find the longest width of all items
733 int count = m_ProgList.GetItemCount();
734 HDITEM hdi = {0};
735 hdi.mask = HDI_TEXT;
736 hdi.pszText = textbuf;
737 hdi.cchTextMax = sizeof(textbuf);
738 ((CHeaderCtrl*)(m_ProgList.GetDlgItem(0)))->GetItem(col, &hdi);
739 int cx = m_ProgList.GetStringWidth(hdi.pszText)+20; // 20 pixels for col separator and margin
741 for (int index = 0; index<count; ++index)
743 // get the width of the string and add 12 pixels for the column separator and margins
744 int linewidth = cx;
745 switch (col)
747 case 0:
748 linewidth = m_ProgList.GetStringWidth(m_arData[index]->sActionColumnText) + 12;
749 break;
750 case 1:
751 linewidth = m_ProgList.GetStringWidth(m_arData[index]->sPathColumnText) + 12;
752 break;
754 if (cx < linewidth)
755 cx = linewidth;
757 m_ProgList.SetColumnWidth(col, cx);
760 m_ProgList.SetRedraw(TRUE);
763 BOOL CGitProgressDlg::OnInitDialog()
765 __super::OnInitDialog();
767 // Let the TaskbarButtonCreated message through the UIPI filter. If we don't
768 // do this, Explorer would be unable to send that message to our window if we
769 // were running elevated. It's OK to make the call all the time, since if we're
770 // not elevated, this is a no-op.
771 CHANGEFILTERSTRUCT cfs = { sizeof(CHANGEFILTERSTRUCT) };
772 typedef BOOL STDAPICALLTYPE ChangeWindowMessageFilterExDFN(HWND hWnd, UINT message, DWORD action, PCHANGEFILTERSTRUCT pChangeFilterStruct);
773 CAutoLibrary hUser = AtlLoadSystemLibraryUsingFullPath(_T("user32.dll"));
774 if (hUser)
776 ChangeWindowMessageFilterExDFN *pfnChangeWindowMessageFilterEx = (ChangeWindowMessageFilterExDFN*)GetProcAddress(hUser, "ChangeWindowMessageFilterEx");
777 if (pfnChangeWindowMessageFilterEx)
779 pfnChangeWindowMessageFilterEx(m_hWnd, WM_TASKBARBTNCREATED, MSGFLT_ALLOW, &cfs);
782 m_pTaskbarList.Release();
783 if (FAILED(m_pTaskbarList.CoCreateInstance(CLSID_TaskbarList)))
784 m_pTaskbarList = nullptr;
786 m_ProgList.SetExtendedStyle (LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER);
788 m_ProgList.DeleteAllItems();
789 int c = ((CHeaderCtrl*)(m_ProgList.GetDlgItem(0)))->GetItemCount()-1;
790 while (c>=0)
791 m_ProgList.DeleteColumn(c--);
792 CString temp;
793 temp.LoadString(IDS_PROGRS_ACTION);
794 m_ProgList.InsertColumn(0, temp);
795 temp.LoadString(IDS_PROGRS_PATH);
796 m_ProgList.InsertColumn(1, temp);
798 m_pThread = AfxBeginThread(ProgressThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
799 if (m_pThread==NULL)
801 ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
803 else
805 m_pThread->m_bAutoDelete = FALSE;
806 m_pThread->ResumeThread();
809 UpdateData(FALSE);
811 // Call this early so that the column headings aren't hidden before any
812 // text gets added.
813 ResizeColumns();
815 SetTimer(VISIBLETIMER, 300, NULL);
817 AddAnchor(IDC_SVNPROGRESS, TOP_LEFT, BOTTOM_RIGHT);
818 AddAnchor(IDC_TITLE_ANIMATE, TOP_LEFT, BOTTOM_RIGHT);
819 AddAnchor(IDC_PROGRESSLABEL, BOTTOM_LEFT, BOTTOM_CENTER);
820 AddAnchor(IDC_PROGRESSBAR, BOTTOM_CENTER, BOTTOM_RIGHT);
821 AddAnchor(IDC_INFOTEXT, BOTTOM_LEFT, BOTTOM_RIGHT);
822 AddAnchor(IDC_NONINTERACTIVE, BOTTOM_LEFT, BOTTOM_RIGHT);
823 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
824 AddAnchor(IDOK, BOTTOM_RIGHT);
825 AddAnchor(IDC_LOGBUTTON, BOTTOM_RIGHT);
826 //SetPromptParentWindow(this->m_hWnd);
828 m_Animate.Open(IDR_DOWNLOAD);
830 if (hWndExplorer)
831 CenterWindow(CWnd::FromHandle(hWndExplorer));
832 EnableSaveRestore(_T("GITProgressDlg"));
834 m_background_brush.CreateSolidBrush(GetSysColor(COLOR_WINDOW));
835 return TRUE;
838 bool CGitProgressDlg::SetBackgroundImage(UINT nID)
840 return CAppUtils::SetListCtrlBackgroundImage(m_ProgList.GetSafeHwnd(), nID);
843 void CGitProgressDlg::ReportGitError()
845 ReportError(CGit::GetLibGit2LastErr());
848 void CGitProgressDlg::ReportError(const CString& sError)
850 CSoundUtils::PlayTGitError();
851 ReportString(sError, CString(MAKEINTRESOURCE(IDS_ERR_ERROR)), m_Colors.GetColor(CColors::Conflict));
852 m_bErrorsOccurred = true;
855 void CGitProgressDlg::ReportWarning(const CString& sWarning)
857 CSoundUtils::PlayTGitWarning();
858 ReportString(sWarning, CString(MAKEINTRESOURCE(IDS_WARN_WARNING)), m_Colors.GetColor(CColors::Conflict));
861 void CGitProgressDlg::ReportNotification(const CString& sNotification)
863 CSoundUtils::PlayTGitNotification();
864 ReportString(sNotification, CString(MAKEINTRESOURCE(IDS_WARN_NOTE)));
867 void CGitProgressDlg::ReportCmd(const CString& sCmd)
869 ReportString(sCmd, CString(MAKEINTRESOURCE(IDS_PROGRS_CMDINFO)), m_Colors.GetColor(CColors::Cmd));
872 void CGitProgressDlg::ReportString(CString sMessage, const CString& sMsgKind, COLORREF color)
874 // instead of showing a dialog box with the error message or notification,
875 // just insert the error text into the list control.
876 // that way the user isn't 'interrupted' by a dialog box popping up!
878 // the message may be split up into different lines
879 // so add a new entry for each line of the message
880 while (!sMessage.IsEmpty())
882 NotificationData * data = new NotificationData();
883 data->bAuxItem = true;
884 data->sActionColumnText = sMsgKind;
885 if (sMessage.Find('\n')>=0)
886 data->sPathColumnText = sMessage.Left(sMessage.Find('\n'));
887 else
888 data->sPathColumnText = sMessage;
889 data->sPathColumnText.Trim(_T("\n\r"));
890 data->color = color;
891 if (sMessage.Find('\n')>=0)
893 sMessage = sMessage.Mid(sMessage.Find('\n'));
894 sMessage.Trim(_T("\n\r"));
896 else
897 sMessage.Empty();
898 m_arData.push_back(data);
899 AddItemToList();
903 UINT CGitProgressDlg::ProgressThreadEntry(LPVOID pVoid)
905 return ((CGitProgressDlg*)pVoid)->ProgressThread();
908 UINT CGitProgressDlg::ProgressThread()
910 // The SetParams function should have loaded something for us
912 CString temp;
913 CString sWindowTitle;
914 bool localoperation = false;
915 bool bSuccess = false;
916 m_AlwaysConflicted = false;
918 DialogEnableWindow(IDOK, FALSE);
919 DialogEnableWindow(IDCANCEL, TRUE);
920 // SetAndClearProgressInfo(m_hWnd);
921 m_itemCount = m_itemCountTotal;
923 InterlockedExchange(&m_bThreadRunning, TRUE);
924 iFirstResized = 0;
925 bSecondResized = FALSE;
926 m_bFinishedItemAdded = false;
927 CTime startTime = CTime::GetCurrentTime();
929 if (m_pTaskbarList)
930 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_INDETERMINATE);
932 switch (m_Command)
934 case GitProgress_Add:
935 bSuccess = CmdAdd(sWindowTitle, localoperation);
936 break;
937 case GitProgress_Copy:
938 bSuccess = CmdCopy(sWindowTitle, localoperation);
939 break;
940 case GitProgress_Export:
941 bSuccess = CmdExport(sWindowTitle, localoperation);
942 break;
943 case GitProgress_Rename:
944 bSuccess = CmdRename(sWindowTitle, localoperation);
945 break;
946 case GitProgress_Resolve:
947 bSuccess = CmdResolve(sWindowTitle, localoperation);
948 break;
949 case GitProgress_Revert:
950 bSuccess = CmdRevert(sWindowTitle, localoperation);
951 break;
952 case GitProgress_Switch:
953 bSuccess = CmdSwitch(sWindowTitle, localoperation);
954 break;
955 case GitProgress_SendMail:
956 bSuccess = CmdSendMail(sWindowTitle, localoperation);
957 break;
958 case GitProgress_Clone:
959 bSuccess = CmdClone(sWindowTitle, localoperation);
960 break;
962 if (!bSuccess)
963 temp.LoadString(IDS_PROGRS_TITLEFAILED);
964 else
965 temp.LoadString(IDS_PROGRS_TITLEFIN);
966 sWindowTitle = sWindowTitle + _T(" ") + temp;
967 SetWindowText(sWindowTitle);
969 KillTimer(TRANSFERTIMER);
970 KillTimer(VISIBLETIMER);
972 if (m_pTaskbarList)
974 if (DidErrorsOccur())
976 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_ERROR);
977 m_pTaskbarList->SetProgressValue(m_hWnd, 100, 100);
979 else
980 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NOPROGRESS);
983 DialogEnableWindow(IDCANCEL, FALSE);
984 DialogEnableWindow(IDOK, TRUE);
986 CString info = BuildInfoString();
987 if (!bSuccess)
988 info.LoadString(IDS_PROGRS_INFOFAILED);
989 SetDlgItemText(IDC_INFOTEXT, info);
990 ResizeColumns();
991 CWnd * pWndOk = GetDlgItem(IDOK);
992 if (pWndOk && ::IsWindow(pWndOk->GetSafeHwnd()))
994 SendMessage(DM_SETDEFID, IDOK);
995 GetDlgItem(IDOK)->SetFocus();
998 CString sFinalInfo;
999 if (!m_sTotalBytesTransferred.IsEmpty())
1001 CTimeSpan time = CTime::GetCurrentTime() - startTime;
1002 temp.Format(IDS_PROGRS_TIME, (LONG)time.GetTotalMinutes(), (LONG)time.GetSeconds());
1003 sFinalInfo.Format(IDS_PROGRS_FINALINFO, m_sTotalBytesTransferred, (LPCTSTR)temp);
1004 SetDlgItemText(IDC_PROGRESSLABEL, sFinalInfo);
1006 else
1007 GetDlgItem(IDC_PROGRESSLABEL)->ShowWindow(SW_HIDE);
1009 GetDlgItem(IDC_PROGRESSBAR)->ShowWindow(SW_HIDE);
1011 if (!m_bFinishedItemAdded)
1013 // there's no "finished: xxx" line at the end. We add one here to make
1014 // sure the user sees that the command is actually finished.
1015 NotificationData * data = new NotificationData();
1016 data->bAuxItem = true;
1017 data->sActionColumnText.LoadString(IDS_PROGRS_FINISHED);
1018 m_arData.push_back(data);
1019 AddItemToList();
1022 int count = m_ProgList.GetItemCount();
1023 if ((count > 0)&&(m_bLastVisible))
1024 m_ProgList.EnsureVisible(count-1, FALSE);
1026 CLogFile logfile;
1027 if (logfile.Open())
1029 logfile.AddTimeLine();
1030 for (size_t i = 0; i < m_arData.size(); ++i)
1032 NotificationData * data = m_arData[i];
1033 temp.Format(_T("%-20s : %s"), (LPCTSTR)data->sActionColumnText, (LPCTSTR)data->sPathColumnText);
1034 logfile.AddLine(temp);
1036 if (!sFinalInfo.IsEmpty())
1037 logfile.AddLine(sFinalInfo);
1038 logfile.Close();
1041 m_bCancelled = TRUE;
1042 InterlockedExchange(&m_bThreadRunning, FALSE);
1043 RefreshCursor();
1045 #if 0
1046 DWORD dwAutoClose = CRegStdDWORD(_T("Software\\TortoiseGit\\AutoClose"), CLOSE_MANUAL);
1047 if (m_options & ProgOptDryRun)
1048 dwAutoClose = 0; // dry run means progress dialog doesn't auto close at all
1049 if (!m_bLastVisible)
1050 dwAutoClose = 0;
1051 if (m_dwCloseOnEnd != (DWORD)-1)
1052 dwAutoClose = m_dwCloseOnEnd; // command line value has priority over setting value
1053 if ((dwAutoClose == CLOSE_NOERRORS)&&(!m_bErrorsOccurred))
1054 PostMessage(WM_COMMAND, 1, (LPARAM)GetDlgItem(IDOK)->m_hWnd);
1055 if ((dwAutoClose == CLOSE_NOCONFLICTS)&&(!m_bErrorsOccurred)&&(m_nConflicts==0))
1056 PostMessage(WM_COMMAND, 1, (LPARAM)GetDlgItem(IDOK)->m_hWnd);
1057 if ((dwAutoClose == CLOSE_NOMERGES)&&(!m_bErrorsOccurred)&&(m_nConflicts==0)&&(!m_bMergesAddsDeletesOccurred))
1058 PostMessage(WM_COMMAND, 1, (LPARAM)GetDlgItem(IDOK)->m_hWnd);
1059 if ((dwAutoClose == CLOSE_LOCAL)&&(!m_bErrorsOccurred)&&(m_nConflicts==0)&&(localoperation))
1060 PostMessage(WM_COMMAND, 1, (LPARAM)GetDlgItem(IDOK)->m_hWnd);
1061 #endif
1063 //Don't do anything here which might cause messages to be sent to the window
1064 //The window thread is probably now blocked in OnOK if we've done an auto close
1065 return 0;
1068 void CGitProgressDlg::OnBnClickedLogbutton()
1070 switch(this->m_Command)
1072 case GitProgress_Add:
1073 case GitProgress_Resolve:
1075 CString cmd = _T(" /command:commit");
1076 cmd += _T(" /path:\"")+g_Git.m_CurrentDir+_T("\"");
1078 CAppUtils::RunTortoiseGitProc(cmd);
1079 this->EndDialog(IDOK);
1080 break;
1083 #if 0
1084 if (m_targetPathList.GetCount() != 1)
1085 return;
1086 StringRevMap::iterator it = m_UpdateStartRevMap.begin();
1087 svn_revnum_t rev = -1;
1088 if (it != m_UpdateStartRevMap.end())
1090 rev = it->second;
1092 CLogDlg dlg;
1093 dlg.SetParams(m_targetPathList[0], m_RevisionEnd, m_RevisionEnd, rev, 0, TRUE);
1094 dlg.DoModal();
1095 #endif
1099 void CGitProgressDlg::OnClose()
1101 if (m_bCancelled)
1103 TerminateThread(m_pThread->m_hThread, (DWORD)-1);
1104 InterlockedExchange(&m_bThreadRunning, FALSE);
1106 else
1108 m_bCancelled = TRUE;
1109 return;
1111 DialogEnableWindow(IDCANCEL, TRUE);
1112 __super::OnClose();
1115 void CGitProgressDlg::OnOK()
1117 if ((m_bCancelled)&&(!m_bThreadRunning))
1119 // I have made this wait a sensible amount of time (10 seconds) for the thread to finish
1120 // You must be careful in the thread that after posting the WM_COMMAND/IDOK message, you
1121 // don't do any more operations on the window which might require message passing
1122 // If you try to send windows messages once we're waiting here, then the thread can't finished
1123 // because the Window's message loop is blocked at this wait
1124 WaitForSingleObject(m_pThread->m_hThread, 10000);
1125 __super::OnOK();
1127 m_bCancelled = TRUE;
1130 void CGitProgressDlg::OnCancel()
1132 if ((m_bCancelled)&&(!m_bThreadRunning))
1133 __super::OnCancel();
1134 m_bCancelled = TRUE;
1137 void CGitProgressDlg::OnLvnGetdispinfoSvnprogress(NMHDR *pNMHDR, LRESULT *pResult)
1139 NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
1141 if (pDispInfo)
1143 if (pDispInfo->item.mask & LVIF_TEXT)
1145 if (pDispInfo->item.iItem < (int)m_arData.size())
1147 const NotificationData * data = m_arData[pDispInfo->item.iItem];
1148 switch (pDispInfo->item.iSubItem)
1150 case 0:
1151 lstrcpyn(m_columnbuf, data->sActionColumnText, MAX_PATH);
1152 break;
1153 case 1:
1154 lstrcpyn(m_columnbuf, data->sPathColumnText, pDispInfo->item.cchTextMax);
1155 if (!data->bAuxItem)
1157 int cWidth = m_ProgList.GetColumnWidth(1);
1158 cWidth = max(12, cWidth-12);
1159 CDC * pDC = m_ProgList.GetDC();
1160 if (pDC != NULL)
1162 CFont * pFont = pDC->SelectObject(m_ProgList.GetFont());
1163 PathCompactPath(pDC->GetSafeHdc(), m_columnbuf, cWidth);
1164 pDC->SelectObject(pFont);
1165 ReleaseDC(pDC);
1168 break;
1169 default:
1170 m_columnbuf[0] = 0;
1172 pDispInfo->item.pszText = m_columnbuf;
1176 *pResult = 0;
1179 void CGitProgressDlg::OnNMCustomdrawSvnprogress(NMHDR *pNMHDR, LRESULT *pResult)
1181 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
1183 // Take the default processing unless we set this to something else below.
1184 *pResult = CDRF_DODEFAULT;
1186 // First thing - check the draw stage. If it's the control's prepaint
1187 // stage, then tell Windows we want messages for every item.
1189 if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )
1191 *pResult = CDRF_NOTIFYITEMDRAW;
1193 else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )
1195 // This is the prepaint stage for an item. Here's where we set the
1196 // item's text color. Our return value will tell Windows to draw the
1197 // item itself, but it will use the new color we set here.
1199 // Tell Windows to paint the control itself.
1200 *pResult = CDRF_DODEFAULT;
1202 ASSERT(pLVCD->nmcd.dwItemSpec < m_arData.size());
1203 if(pLVCD->nmcd.dwItemSpec >= m_arData.size())
1205 return;
1207 const NotificationData * data = m_arData[pLVCD->nmcd.dwItemSpec];
1208 ASSERT(data != NULL);
1209 if (data == NULL)
1210 return;
1212 // Store the color back in the NMLVCUSTOMDRAW struct.
1213 pLVCD->clrText = data->color;
1217 void CGitProgressDlg::OnNMDblclkSvnprogress(NMHDR * /*pNMHDR*/, LRESULT * /*pResult*/)
1219 #if 0
1220 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1221 *pResult = 0;
1222 if (pNMLV->iItem < 0)
1223 return;
1224 if (m_options & ProgOptDryRun)
1225 return; //don't do anything in a dry-run.
1227 const NotificationData * data = m_arData[pNMLV->iItem];
1228 if (data == NULL)
1229 return;
1231 if (data->bConflictedActionItem)
1233 // We've double-clicked on a conflicted item - do a three-way merge on it
1234 SVNDiff::StartConflictEditor(data->path);
1236 else if ((data->action == svn_wc_notify_update_update) && ((data->content_state == svn_wc_notify_state_merged)||(GitProgress_Merge == m_Command)) || (data->action == svn_wc_notify_resolved))
1238 // This is a modified file which has been merged on update. Diff it against base
1239 CTGitPath temporaryFile;
1240 SVNDiff diff(this, this->m_hWnd, true);
1241 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
1242 svn_revnum_t baseRev = 0;
1243 diff.DiffFileAgainstBase(data->path, baseRev);
1245 else if ((!data->bAuxItem)&&(data->path.Exists())&&(!data->path.IsDirectory()))
1247 bool bOpenWith = false;
1248 int ret = (int)ShellExecute(m_hWnd, NULL, data->path.GetWinPath(), NULL, NULL, SW_SHOWNORMAL);
1249 if (ret <= HINSTANCE_ERROR)
1250 bOpenWith = true;
1251 if (bOpenWith)
1253 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
1254 cmd += data->path.GetWinPathString() + _T(" ");
1255 CAppUtils::LaunchApplication(cmd, NULL, false);
1258 #endif
1261 void CGitProgressDlg::OnHdnItemclickSvnprogress(NMHDR *pNMHDR, LRESULT *pResult)
1263 LPNMHEADER phdr = reinterpret_cast<LPNMHEADER>(pNMHDR);
1264 if (m_bThreadRunning)
1265 return;
1266 if (m_nSortedColumn == phdr->iItem)
1267 m_bAscending = !m_bAscending;
1268 else
1269 m_bAscending = TRUE;
1270 m_nSortedColumn = phdr->iItem;
1271 Sort();
1273 CString temp;
1274 m_ProgList.SetRedraw(FALSE);
1275 m_ProgList.DeleteAllItems();
1276 m_ProgList.SetItemCountEx (static_cast<int>(m_arData.size()));
1278 m_ProgList.SetRedraw(TRUE);
1280 *pResult = 0;
1283 bool CGitProgressDlg::NotificationDataIsAux(const NotificationData* pData)
1285 return pData->bAuxItem;
1288 BOOL CGitProgressDlg::Notify(const git_wc_notify_action_t /*action*/, const git_transfer_progress *stat)
1290 static unsigned int start = 0;
1291 unsigned int dt = GetCurrentTime() - start;
1292 size_t ds;
1293 double speed = 0;
1294 if (dt > 100)
1296 start = GetCurrentTime();
1297 ds = stat->received_bytes - m_TotalBytesTransferred;
1298 speed = ds * 1000.0/dt;
1299 m_TotalBytesTransferred = stat->received_bytes;
1301 else
1303 return TRUE;
1306 CProgressCtrl * progControl = (CProgressCtrl *)GetDlgItem(IDC_PROGRESSBAR);
1308 int progress;
1309 progress = stat->received_objects + stat->indexed_objects;
1311 if ((stat->total_objects > 1000) && (!progControl->IsWindowVisible()))
1313 progControl->ShowWindow(SW_SHOW);
1314 if (m_pTaskbarList)
1315 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
1317 if (!GetDlgItem(IDC_PROGRESSLABEL)->IsWindowVisible())
1318 GetDlgItem(IDC_PROGRESSLABEL)->ShowWindow(SW_SHOW);
1320 progControl->SetPos(progress);
1321 progControl->SetRange32(0, 2 * stat->total_objects);
1322 if (m_pTaskbarList)
1324 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
1325 m_pTaskbarList->SetProgressValue(m_hWnd, progress, stat->total_objects);
1328 CString progText;
1329 if (stat->received_bytes < 1024)
1330 m_sTotalBytesTransferred.Format(IDS_SVN_PROGRESS_TOTALBYTESTRANSFERRED, (int64_t)stat->received_bytes);
1331 else if (stat->received_bytes < 1200000)
1332 m_sTotalBytesTransferred.Format(IDS_SVN_PROGRESS_TOTALTRANSFERRED, (int64_t)stat->received_bytes / 1024);
1333 else
1334 m_sTotalBytesTransferred.Format(IDS_SVN_PROGRESS_TOTALMBTRANSFERRED, (double)((double)stat->received_bytes / 1024000.0));
1336 CString str;
1337 if(speed < 1024)
1338 str.Format(_T("%fB/s"), speed);
1339 else if(speed < 1024 * 1024)
1340 str.Format(_T("%.2fKB/s"), speed / 1024);
1341 else
1342 str.Format(_T("%.2fMB/s"), speed / 1024000.0);
1344 progText.Format(IDS_SVN_PROGRESS_TOTALANDSPEED, (LPCTSTR)m_sTotalBytesTransferred, (LPCTSTR)str);
1345 SetDlgItemText(IDC_PROGRESSLABEL, progText);
1347 return TRUE;
1350 LRESULT CGitProgressDlg::OnGitProgress(WPARAM /*wParam*/, LPARAM /*lParam*/)
1352 #if 0
1353 SVNProgress * pProgressData = (SVNProgress *)lParam;
1354 CProgressCtrl * progControl = (CProgressCtrl *)GetDlgItem(IDC_PROGRESSBAR);
1355 if ((pProgressData->total > 1000)&&(!progControl->IsWindowVisible()))
1357 progControl->ShowWindow(SW_SHOW);
1358 if (m_pTaskbarList)
1359 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
1361 if (((pProgressData->total < 0)&&(pProgressData->progress > 1000)&&(progControl->IsWindowVisible()))&&(m_itemCountTotal<0))
1363 progControl->ShowWindow(SW_HIDE);
1364 if (m_pTaskbarList)
1365 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_INDETERMINATE);
1367 if (!GetDlgItem(IDC_PROGRESSLABEL)->IsWindowVisible())
1368 GetDlgItem(IDC_PROGRESSLABEL)->ShowWindow(SW_SHOW);
1369 SetTimer(TRANSFERTIMER, 2000, NULL);
1370 if ((pProgressData->total > 0)&&(pProgressData->progress > 1000))
1372 progControl->SetPos((int)pProgressData->progress);
1373 progControl->SetRange32(0, (int)pProgressData->total);
1374 if (m_pTaskbarList)
1376 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
1377 m_pTaskbarList->SetProgressValue(m_hWnd, pProgressData->progress, pProgressData->total);
1380 CString progText;
1381 if (pProgressData->overall_total < 1024)
1382 m_sTotalBytesTransferred.Format(IDS_SVN_PROGRESS_TOTALBYTESTRANSFERRED, pProgressData->overall_total);
1383 else if (pProgressData->overall_total < 1200000)
1384 m_sTotalBytesTransferred.Format(IDS_SVN_PROGRESS_TOTALTRANSFERRED, pProgressData->overall_total / 1024);
1385 else
1386 m_sTotalBytesTransferred.Format(IDS_SVN_PROGRESS_TOTALMBTRANSFERRED, (double)((double)pProgressData->overall_total / 1024000.0));
1387 progText.Format(IDS_SVN_PROGRESS_TOTALANDSPEED, (LPCTSTR)m_sTotalBytesTransferred, (LPCTSTR)pProgressData->SpeedString);
1388 SetDlgItemText(IDC_PROGRESSLABEL, progText);
1389 #endif
1390 return 0;
1393 void CGitProgressDlg::OnTimer(UINT_PTR nIDEvent)
1395 if (nIDEvent == TRANSFERTIMER)
1397 CString progText;
1398 CString progSpeed;
1399 progSpeed.Format(IDS_SVN_PROGRESS_BYTES_SEC, 0);
1400 progText.Format(IDS_SVN_PROGRESS_TOTALANDSPEED, (LPCTSTR)m_sTotalBytesTransferred, (LPCTSTR)progSpeed);
1401 SetDlgItemText(IDC_PROGRESSLABEL, progText);
1402 KillTimer(TRANSFERTIMER);
1404 if (nIDEvent == VISIBLETIMER)
1406 if (nEnsureVisibleCount)
1407 m_ProgList.EnsureVisible(m_ProgList.GetItemCount()-1, false);
1408 nEnsureVisibleCount = 0;
1412 void CGitProgressDlg::Sort()
1414 if(m_arData.size() < 2)
1416 return;
1419 // We need to sort the blocks which lie between the auxiliary entries
1420 // This is so that any aux data stays where it was
1421 NotificationDataVect::iterator actionBlockBegin;
1422 NotificationDataVect::iterator actionBlockEnd = m_arData.begin(); // We start searching from here
1424 for(;;)
1426 // Search to the start of the non-aux entry in the next block
1427 actionBlockBegin = std::find_if(actionBlockEnd, m_arData.end(), std::not1(std::ptr_fun(&CGitProgressDlg::NotificationDataIsAux)));
1428 if(actionBlockBegin == m_arData.end())
1430 // There are no more actions
1431 break;
1433 // Now search to find the end of the block
1434 actionBlockEnd = std::find_if(actionBlockBegin+1, m_arData.end(), std::ptr_fun(&CGitProgressDlg::NotificationDataIsAux));
1435 // Now sort the block
1436 std::sort(actionBlockBegin, actionBlockEnd, &CGitProgressDlg::SortCompare);
1440 bool CGitProgressDlg::SortCompare(const NotificationData * pData1, const NotificationData * pData2)
1442 int result = 0;
1443 switch (m_nSortedColumn)
1445 case 0: //action column
1446 result = pData1->sActionColumnText.Compare(pData2->sActionColumnText);
1447 break;
1448 case 1: //path column
1449 // Compare happens after switch()
1450 break;
1451 default:
1452 break;
1455 // Sort by path if everything else is equal
1456 if (result == 0)
1458 result = CTGitPath::Compare(pData1->path, pData2->path);
1461 if (!m_bAscending)
1462 result = -result;
1463 return result < 0;
1466 BOOL CGitProgressDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
1468 if (!GetDlgItem(IDOK)->IsWindowEnabled())
1470 // only show the wait cursor over the list control
1471 if ((pWnd)&&(pWnd == GetDlgItem(IDC_SVNPROGRESS)))
1473 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT));
1474 SetCursor(hCur);
1475 return TRUE;
1478 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));
1479 SetCursor(hCur);
1480 return CResizableStandAloneDialog::OnSetCursor(pWnd, nHitTest, message);
1483 BOOL CGitProgressDlg::PreTranslateMessage(MSG* pMsg)
1485 if (pMsg->message == WM_KEYDOWN)
1487 if (pMsg->wParam == VK_ESCAPE)
1489 // pressing the ESC key should close the dialog. But since we disabled the escape
1490 // key (so the user doesn't get the idea that he could simply undo an e.g. update)
1491 // this won't work.
1492 // So if the user presses the ESC key, change it to VK_RETURN so the dialog gets
1493 // the impression that the OK button was pressed.
1494 if ((!m_bThreadRunning)&&(!GetDlgItem(IDCANCEL)->IsWindowEnabled())
1495 &&(GetDlgItem(IDOK)->IsWindowEnabled())&&(GetDlgItem(IDOK)->IsWindowVisible()))
1497 // since we convert ESC to RETURN, make sure the OK button has the focus.
1498 GetDlgItem(IDOK)->SetFocus();
1499 pMsg->wParam = VK_RETURN;
1502 if (pMsg->wParam == 'A')
1504 if (GetKeyState(VK_CONTROL)&0x8000)
1506 // Ctrl-A -> select all
1507 m_ProgList.SetSelectionMark(0);
1508 for (int i=0; i<m_ProgList.GetItemCount(); ++i)
1510 m_ProgList.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
1514 if ((pMsg->wParam == 'C')||(pMsg->wParam == VK_INSERT))
1516 int selIndex = m_ProgList.GetSelectionMark();
1517 if (selIndex >= 0)
1519 if (GetKeyState(VK_CONTROL)&0x8000)
1521 //Ctrl-C -> copy to clipboard
1522 CString sClipdata;
1523 POSITION pos = m_ProgList.GetFirstSelectedItemPosition();
1524 if (pos != NULL)
1526 while (pos)
1528 int nItem = m_ProgList.GetNextSelectedItem(pos);
1529 CString sAction = m_ProgList.GetItemText(nItem, 0);
1530 CString sPath = m_ProgList.GetItemText(nItem, 1);
1531 CString sMime = m_ProgList.GetItemText(nItem, 2);
1532 CString sLogCopyText;
1533 sLogCopyText.Format(_T("%s: %s %s\r\n"),
1534 (LPCTSTR)sAction, (LPCTSTR)sPath, (LPCTSTR)sMime);
1535 sClipdata += sLogCopyText;
1537 CStringUtils::WriteAsciiStringToClipboard(sClipdata);
1542 } // if (pMsg->message == WM_KEYDOWN)
1543 return __super::PreTranslateMessage(pMsg);
1546 void CGitProgressDlg::OnContextMenu(CWnd* /*pWnd*/, CPoint /*point*/)
1548 #if 0
1549 if (m_options & ProgOptDryRun)
1550 return; // don't do anything in a dry-run.
1552 if (pWnd == &m_ProgList)
1554 int selIndex = m_ProgList.GetSelectionMark();
1555 if ((point.x == -1) && (point.y == -1))
1557 // Menu was invoked from the keyboard rather than by right-clicking
1558 CRect rect;
1559 m_ProgList.GetItemRect(selIndex, &rect, LVIR_LABEL);
1560 m_ProgList.ClientToScreen(&rect);
1561 point = rect.CenterPoint();
1564 if ((selIndex >= 0)&&(!m_bThreadRunning))
1566 // entry is selected, thread has finished with updating so show the popup menu
1567 CIconMenu popup;
1568 if (popup.CreatePopupMenu())
1570 bool bAdded = false;
1571 NotificationData * data = m_arData[selIndex];
1572 if ((data)&&(!data->path.IsDirectory()))
1574 if (data->action == svn_wc_notify_update_update || data->action == svn_wc_notify_resolved)
1576 if (m_ProgList.GetSelectedCount() == 1)
1578 popup.AppendMenuIcon(ID_COMPARE, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1579 bAdded = true;
1582 if (data->bConflictedActionItem)
1584 if (m_ProgList.GetSelectedCount() == 1)
1586 popup.AppendMenuIcon(ID_EDITCONFLICT, IDS_MENUCONFLICT,IDI_CONFLICT);
1587 popup.SetDefaultItem(ID_EDITCONFLICT, FALSE);
1588 popup.AppendMenuIcon(ID_CONFLICTRESOLVE, IDS_SVNPROGRESS_MENUMARKASRESOLVED,IDI_RESOLVE);
1590 popup.AppendMenuIcon(ID_CONFLICTUSETHEIRS, IDS_SVNPROGRESS_MENUUSETHEIRS,IDI_RESOLVE);
1591 popup.AppendMenuIcon(ID_CONFLICTUSEMINE, IDS_SVNPROGRESS_MENUUSEMINE,IDI_RESOLVE);
1593 else if ((data->content_state == svn_wc_notify_state_merged)||(GitProgress_Merge == m_Command)||(data->action == svn_wc_notify_resolved))
1594 popup.SetDefaultItem(ID_COMPARE, FALSE);
1596 if (m_ProgList.GetSelectedCount() == 1)
1598 if ((data->action == svn_wc_notify_add)||
1599 (data->action == svn_wc_notify_update_add)||
1600 (data->action == svn_wc_notify_commit_added)||
1601 (data->action == svn_wc_notify_commit_modified)||
1602 (data->action == svn_wc_notify_restore)||
1603 (data->action == svn_wc_notify_revert)||
1604 (data->action == svn_wc_notify_resolved)||
1605 (data->action == svn_wc_notify_commit_replaced)||
1606 (data->action == svn_wc_notify_commit_modified)||
1607 (data->action == svn_wc_notify_commit_postfix_txdelta)||
1608 (data->action == svn_wc_notify_update_update))
1610 popup.AppendMenuIcon(ID_LOG, IDS_MENULOG,IDI_LOG);
1611 if (data->action == svn_wc_notify_update_update)
1612 popup.AppendMenu(MF_SEPARATOR, NULL);
1613 popup.AppendMenuIcon(ID_OPEN, IDS_LOG_POPUP_OPEN, IDI_OPEN);
1614 popup.AppendMenuIcon(ID_OPENWITH, IDS_LOG_POPUP_OPENWITH, IDI_OPEN);
1615 bAdded = true;
1618 } // if ((data)&&(!data->path.IsDirectory()))
1619 if (m_ProgList.GetSelectedCount() == 1)
1621 if (data)
1623 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1624 if ((!sPath.IsEmpty())&&(!SVN::PathIsURL(CTGitPath(sPath))))
1626 CTGitPath path = CTGitPath(sPath);
1627 if (path.GetDirectory().Exists())
1629 popup.AppendMenuIcon(ID_EXPLORE, IDS_SVNPROGRESS_MENUOPENPARENT, IDI_EXPLORER);
1630 bAdded = true;
1635 if (m_ProgList.GetSelectedCount() > 0)
1637 if (bAdded)
1638 popup.AppendMenu(MF_SEPARATOR, NULL);
1639 popup.AppendMenuIcon(ID_COPY, IDS_LOG_POPUP_COPYTOCLIPBOARD,IDI_COPYCLIP);
1640 bAdded = true;
1642 if (bAdded)
1644 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
1645 DialogEnableWindow(IDOK, FALSE);
1646 this->SetPromptApp(&theApp);
1647 theApp.DoWaitCursor(1);
1648 bool bOpenWith = false;
1649 switch (cmd)
1651 case ID_COPY:
1653 CString sLines;
1654 POSITION pos = m_ProgList.GetFirstSelectedItemPosition();
1655 while (pos)
1657 int nItem = m_ProgList.GetNextSelectedItem(pos);
1658 NotificationData * data = m_arData[nItem];
1659 if (data)
1661 sLines += data->sPathColumnText;
1662 sLines += _T("\r\n");
1665 sLines.TrimRight();
1666 if (!sLines.IsEmpty())
1668 CStringUtils::WriteAsciiStringToClipboard(sLines, GetSafeHwnd());
1671 break;
1672 case ID_EXPLORE:
1674 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1676 CTGitPath path = CTGitPath(sPath);
1677 ShellExecute(m_hWnd, _T("explore"), path.GetDirectory().GetWinPath(), NULL, path.GetDirectory().GetWinPath(), SW_SHOW);
1679 break;
1680 case ID_COMPARE:
1682 svn_revnum_t rev = -1;
1683 StringRevMap::iterator it = m_UpdateStartRevMap.end();
1684 if (data->basepath.IsEmpty())
1685 it = m_UpdateStartRevMap.begin();
1686 else
1687 it = m_UpdateStartRevMap.find(data->basepath.GetSVNApiPath(pool));
1688 if (it != m_UpdateStartRevMap.end())
1689 rev = it->second;
1690 // if the file was merged during update, do a three way diff between OLD, MINE, THEIRS
1691 if (data->content_state == svn_wc_notify_state_merged)
1693 CTGitPath basefile = CTempFiles::Instance().GetTempFilePath(false, data->path, rev);
1694 CTGitPath newfile = CTempFiles::Instance().GetTempFilePath(false, data->path, SVNRev::REV_HEAD);
1695 SVN svn;
1696 if (!svn.Cat(data->path, SVNRev(SVNRev::REV_WC), rev, basefile))
1698 CMessageBox::Show(m_hWnd, svn.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1699 DialogEnableWindow(IDOK, TRUE);
1700 break;
1702 // If necessary, convert the line-endings on the file before diffing
1703 if ((DWORD)CRegDWORD(_T("Software\\TortoiseGit\\ConvertBase"), TRUE))
1705 CTGitPath temporaryFile = CTempFiles::Instance().GetTempFilePath(false, data->path, SVNRev::REV_BASE);
1706 if (!svn.Cat(data->path, SVNRev(SVNRev::REV_BASE), SVNRev(SVNRev::REV_BASE), temporaryFile))
1708 temporaryFile.Reset();
1709 break;
1711 else
1713 newfile = temporaryFile;
1717 SetFileAttributes(newfile.GetWinPath(), FILE_ATTRIBUTE_READONLY);
1718 SetFileAttributes(basefile.GetWinPath(), FILE_ATTRIBUTE_READONLY);
1719 CString revname, wcname, basename;
1720 revname.Format(_T("%s Revision %ld"), (LPCTSTR)data->path.GetUIFileOrDirectoryName(), rev);
1721 wcname.Format(IDS_DIFF_WCNAME, (LPCTSTR)data->path.GetUIFileOrDirectoryName());
1722 basename.Format(IDS_DIFF_BASENAME, (LPCTSTR)data->path.GetUIFileOrDirectoryName());
1723 CAppUtils::StartExtMerge(basefile, newfile, data->path, data->path, basename, revname, wcname, CString(), true);
1725 else
1727 CTGitPath tempfile = CTempFiles::Instance().GetTempFilePath(false, data->path, rev);
1728 SVN svn;
1729 if (!svn.Cat(data->path, SVNRev(SVNRev::REV_WC), rev, tempfile))
1731 CMessageBox::Show(m_hWnd, svn.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1732 DialogEnableWindow(IDOK, TRUE);
1733 break;
1735 else
1737 SetFileAttributes(tempfile.GetWinPath(), FILE_ATTRIBUTE_READONLY);
1738 CString revname, wcname;
1739 revname.Format(_T("%s Revision %ld"), (LPCTSTR)data->path.GetUIFileOrDirectoryName(), rev);
1740 wcname.Format(IDS_DIFF_WCNAME, (LPCTSTR)data->path.GetUIFileOrDirectoryName());
1741 CAppUtils::StartExtDiff(
1742 tempfile, data->path, revname, wcname,
1743 CAppUtils::DiffFlags().AlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000)));
1747 break;
1748 case ID_EDITCONFLICT:
1750 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1751 SVNDiff::StartConflictEditor(CTGitPath(sPath));
1753 break;
1754 case ID_CONFLICTUSETHEIRS:
1755 case ID_CONFLICTUSEMINE:
1756 case ID_CONFLICTRESOLVE:
1758 svn_wc_conflict_choice_t result = svn_wc_conflict_choose_merged;
1759 switch (cmd)
1761 case ID_CONFLICTUSETHEIRS:
1762 result = svn_wc_conflict_choose_theirs_full;
1763 break;
1764 case ID_CONFLICTUSEMINE:
1765 result = svn_wc_conflict_choose_mine_full;
1766 break;
1767 case ID_CONFLICTRESOLVE:
1768 result = svn_wc_conflict_choose_merged;
1769 break;
1771 SVN svn;
1772 POSITION pos = m_ProgList.GetFirstSelectedItemPosition();
1773 CString sResolvedPaths;
1774 while (pos)
1776 int nItem = m_ProgList.GetNextSelectedItem(pos);
1777 NotificationData * data = m_arData[nItem];
1778 if (data)
1780 if (data->bConflictedActionItem)
1782 if (!svn.Resolve(data->path, result, FALSE))
1784 CMessageBox::Show(m_hWnd, svn.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1785 DialogEnableWindow(IDOK, TRUE);
1786 break;
1788 else
1790 data->color = ::GetSysColor(COLOR_WINDOWTEXT);
1791 data->action = svn_wc_notify_resolved;
1792 data->sActionColumnText.LoadString(IDS_SVNACTION_RESOLVE);
1793 data->bConflictedActionItem = false;
1794 m_nConflicts--;
1796 if (m_nConflicts==0)
1798 // When the last conflict is resolved we remove
1799 // the warning which we assume is in the last line.
1800 int nIndex = m_ProgList.GetItemCount()-1;
1801 VERIFY(m_ProgList.DeleteItem(nIndex));
1803 delete m_arData[nIndex];
1804 m_arData.pop_back();
1806 sResolvedPaths += data->path.GetWinPathString() + _T("\n");
1811 m_ProgList.Invalidate();
1812 CString info = BuildInfoString();
1813 SetDlgItemText(IDC_INFOTEXT, info);
1815 if (!sResolvedPaths.IsEmpty())
1817 CString msg;
1818 msg.Format(IDS_SVNPROGRESS_RESOLVED, (LPCTSTR)sResolvedPaths);
1819 CMessageBox::Show(m_hWnd, msg, _T("TortoiseGit"), MB_OK | MB_ICONINFORMATION);
1822 break;
1823 case ID_LOG:
1825 svn_revnum_t rev = m_RevisionEnd;
1826 if (!data->basepath.IsEmpty())
1828 StringRevMap::iterator it = m_FinishedRevMap.find(data->basepath.GetSVNApiPath(pool));
1829 if (it != m_FinishedRevMap.end())
1830 rev = it->second;
1832 CLogDlg dlg;
1833 // fetch the log from HEAD, not the revision we updated to:
1834 // the path might be inside an external folder which has its own
1835 // revisions.
1836 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1837 dlg.SetParams(CTGitPath(sPath), SVNRev(), SVNRev::REV_HEAD, 1, -1, TRUE);
1838 dlg.DoModal();
1840 break;
1841 case ID_OPENWITH:
1842 bOpenWith = true;
1843 case ID_OPEN:
1845 int ret = 0;
1846 CString sWinPath = GetPathFromColumnText(data->sPathColumnText);
1847 if (!bOpenWith)
1848 ret = (int)ShellExecute(this->m_hWnd, NULL, (LPCTSTR)sWinPath, NULL, NULL, SW_SHOWNORMAL);
1849 if ((ret <= HINSTANCE_ERROR)||bOpenWith)
1851 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
1852 cmd += sWinPath + _T(" ");
1853 CAppUtils::LaunchApplication(cmd, NULL, false);
1857 DialogEnableWindow(IDOK, TRUE);
1858 theApp.DoWaitCursor(-1);
1859 } // if (bAdded)
1863 #endif
1866 void CGitProgressDlg::OnEnSetfocusInfotext()
1868 CString sTemp;
1869 GetDlgItemText(IDC_INFOTEXT, sTemp);
1870 if (sTemp.IsEmpty())
1871 GetDlgItem(IDC_INFOTEXT)->HideCaret();
1874 void CGitProgressDlg::OnLvnBegindragSvnprogress(NMHDR* , LRESULT *pResult)
1876 //LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1877 #if 0
1878 int selIndex = m_ProgList.GetSelectionMark();
1879 if (selIndex < 0)
1880 return;
1882 CDropFiles dropFiles; // class for creating DROPFILES struct
1884 int index;
1885 POSITION pos = m_ProgList.GetFirstSelectedItemPosition();
1886 while ( (index = m_ProgList.GetNextSelectedItem(pos)) >= 0 )
1888 NotificationData * data = m_arData[index];
1890 if ( data->kind==svn_node_file || data->kind==svn_node_dir )
1892 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1894 dropFiles.AddFile( sPath );
1898 if ( dropFiles.GetCount()>0 )
1900 dropFiles.CreateStructure();
1902 #endif
1903 *pResult = 0;
1906 void CGitProgressDlg::OnSize(UINT nType, int cx, int cy)
1908 CResizableStandAloneDialog::OnSize(nType, cx, cy);
1909 if ((nType == SIZE_RESTORED)&&(m_bLastVisible))
1911 if(!m_ProgList.m_hWnd)
1912 return;
1914 int count = m_ProgList.GetItemCount();
1915 if (count > 0)
1916 m_ProgList.EnsureVisible(count-1, false);
1920 //////////////////////////////////////////////////////////////////////////
1921 /// commands
1922 //////////////////////////////////////////////////////////////////////////
1923 bool CGitProgressDlg::CmdAdd(CString& sWindowTitle, bool& localoperation)
1925 localoperation = true;
1926 sWindowTitle.LoadString(IDS_PROGRS_TITLE_ADD);
1927 CAppUtils::SetWindowTitle(m_hWnd, m_targetPathList.GetCommonRoot().GetUIPathString(), sWindowTitle);
1928 SetBackgroundImage(IDI_ADD_BKG);
1929 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_ADD)));
1931 if (CRegDWORD(_T("Software\\TortoiseGit\\UseLibgit2"), TRUE) == TRUE)
1933 git_repository *repo = NULL;
1934 git_index *index;
1936 CStringA gitdir = CUnicodeUtils::GetMulti(CTGitPath(g_Git.m_CurrentDir).GetGitPathString(), CP_UTF8);
1937 if (git_repository_open(&repo, gitdir.GetBuffer()))
1939 gitdir.ReleaseBuffer();
1940 ReportGitError();
1941 return false;
1943 gitdir.ReleaseBuffer();
1945 git_config * config;
1946 git_config_new(&config);
1948 CStringA projectConfigA = CUnicodeUtils::GetMulti(g_Git.GetGitLocalConfig(), CP_UTF8);
1949 if (git_config_add_file_ondisk(config, projectConfigA.GetBuffer(), 4, FALSE))
1951 projectConfigA.ReleaseBuffer();
1952 ReportGitError();
1953 git_config_free(config);
1954 git_repository_free(repo);
1955 return false;
1957 projectConfigA.ReleaseBuffer();
1958 CString globalConfig = g_Git.GetGitGlobalConfig();
1959 if (PathFileExists(globalConfig))
1961 CStringA globalConfigA = CUnicodeUtils::GetMulti(globalConfig, CP_UTF8);
1962 if (git_config_add_file_ondisk(config, globalConfigA.GetBuffer(), 3, FALSE))
1964 globalConfigA.ReleaseBuffer();
1965 ReportGitError();
1966 git_config_free(config);
1967 git_repository_free(repo);
1968 return false;
1970 globalConfigA.ReleaseBuffer();
1972 CString globalXDGConfig = g_Git.GetGitGlobalXDGConfig();
1973 if (PathFileExists(globalXDGConfig))
1975 CStringA globalXDGConfigA = CUnicodeUtils::GetMulti(globalXDGConfig, CP_UTF8);
1976 if (git_config_add_file_ondisk(config, globalXDGConfigA.GetBuffer(), 2, FALSE))
1978 globalXDGConfigA.ReleaseBuffer();
1979 ReportGitError();
1980 git_config_free(config);
1981 git_repository_free(repo);
1982 return false;
1984 globalXDGConfigA.ReleaseBuffer();
1986 CString systemConfig = g_Git.GetGitSystemConfig();
1987 if (!systemConfig.IsEmpty())
1989 CStringA systemConfigA = CUnicodeUtils::GetMulti(systemConfig, CP_UTF8);
1990 if (git_config_add_file_ondisk(config, systemConfigA.GetBuffer(), 1, FALSE))
1992 systemConfigA.ReleaseBuffer();
1993 ReportGitError();
1994 git_config_free(config);
1995 git_repository_free(repo);
1996 return false;
1998 systemConfigA.ReleaseBuffer();
2001 git_repository_set_config(repo, config);
2003 if (git_repository_index(&index, repo))
2005 ReportGitError();
2006 git_repository_free(repo);
2007 return false;
2009 if (git_index_read(index))
2011 ReportGitError();
2012 git_index_free(index);
2013 git_repository_free(repo);
2014 return false;
2017 for (int i = 0; i < m_targetPathList.GetCount(); ++i)
2019 if (git_index_add_bypath(index, CStringA(CUnicodeUtils::GetMulti(m_targetPathList[i].GetGitPathString(), CP_UTF8)).GetBuffer()))
2021 ReportGitError();
2022 git_index_free(index);
2023 git_repository_free(repo);
2024 return false;
2026 Notify(m_targetPathList[i],git_wc_notify_add);
2029 if (git_index_write(index))
2031 ReportGitError();
2032 git_index_free(index);
2033 git_repository_free(repo);
2034 return false;
2037 git_index_free(index);
2038 git_repository_free(repo);
2040 else
2042 CMassiveGitTask mgt(L"add -f");
2043 mgt.ExecuteWithNotify(&m_targetPathList, m_bCancelled, git_wc_notify_add, this, &CGitProgressDlg::Notify);
2046 CShellUpdater::Instance().AddPathsForUpdate(m_targetPathList);
2048 this->GetDlgItem(IDC_LOGBUTTON)->SetWindowText(_T("Commit ..."));
2049 this->GetDlgItem(IDC_LOGBUTTON)->ShowWindow(SW_SHOW);
2050 return true;
2053 bool CGitProgressDlg::CmdCopy(CString& /*sWindowTitle*/, bool& /*localoperation*/)
2055 #if 0
2056 ASSERT(m_targetPathList.GetCount() == 1);
2057 sWindowTitle.LoadString(IDS_PROGRS_TITLE_COPY);
2058 SetWindowText(sWindowTitle); // needs to be updated, see TSVN rev. 21375
2059 SetBackgroundImage(IDI_COPY_BKG);
2061 CString sCmdInfo;
2062 sCmdInfo.Format(IDS_PROGRS_CMD_COPY,
2063 m_targetPathList[0].IsUrl() ? (LPCTSTR)m_targetPathList[0].GetSVNPathString() : m_targetPathList[0].GetWinPath(),
2064 (LPCTSTR)m_url.GetSVNPathString(), (LPCTSTR)m_Revision.ToString());
2065 ReportCmd(sCmdInfo);
2067 if (!Copy(m_targetPathList, m_url, m_Revision, m_pegRev, m_sMessage))
2069 ReportSVNError();
2070 return false;
2072 if (m_options & ProgOptSwitchAfterCopy)
2074 sCmdInfo.Format(IDS_PROGRS_CMD_SWITCH,
2075 m_targetPathList[0].GetWinPath(),
2076 (LPCTSTR)m_url.GetSVNPathString(), (LPCTSTR)m_Revision.ToString());
2077 ReportCmd(sCmdInfo);
2078 if (!Switch(m_targetPathList[0], m_url, SVNRev::REV_HEAD, SVNRev::REV_HEAD, m_depth, TRUE, m_options & ProgOptIgnoreExternals))
2080 if (!Switch(m_targetPathList[0], m_url, SVNRev::REV_HEAD, m_Revision, m_depth, TRUE, m_options & ProgOptIgnoreExternals))
2082 ReportSVNError();
2083 return false;
2087 else
2089 if (SVN::PathIsURL(m_url))
2091 CString sMsg(MAKEINTRESOURCE(IDS_PROGRS_COPY_WARNING));
2092 ReportNotification(sMsg);
2095 #endif
2096 return true;
2099 bool CGitProgressDlg::CmdExport(CString& /*sWindowTitle*/, bool& /*localoperation*/)
2101 #if 0
2102 ASSERT(m_targetPathList.GetCount() == 1);
2103 sWindowTitle.LoadString(IDS_PROGRS_TITLE_EXPORT);
2104 sWindowTitle = m_url.GetUIFileOrDirectoryName()+_T(" - ")+sWindowTitle;
2105 SetWindowText(sWindowTitle); // needs to be updated, see TSVN rev. 21375
2106 SetBackgroundImage(IDI_EXPORT_BKG);
2107 CString eol;
2108 if (m_options & ProgOptEolCRLF)
2109 eol = _T("CRLF");
2110 if (m_options & ProgOptEolLF)
2111 eol = _T("LF");
2112 if (m_options & ProgOptEolCR)
2113 eol = _T("CR");
2114 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_EXPORT)));
2115 if (!Export(m_url, m_targetPathList[0], m_Revision, m_Revision, TRUE, m_options & ProgOptIgnoreExternals, m_depth, NULL, FALSE, eol))
2117 ReportSVNError();
2118 return false;
2120 #endif
2121 return true;
2124 bool CGitProgressDlg::CmdRename(CString& /*sWindowTitle*/, bool& /*localoperation*/)
2126 #if 0
2127 ASSERT(m_targetPathList.GetCount() == 1);
2128 if ((!m_targetPathList[0].IsUrl())&&(!m_url.IsUrl()))
2129 localoperation = true;
2130 sWindowTitle.LoadString(IDS_PROGRS_TITLE_RENAME);
2131 SetWindowText(sWindowTitle); // needs to be updated, see TSVN rev. 21375
2132 SetBackgroundImage(IDI_RENAME_BKG);
2133 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RENAME)));
2134 if (!Move(m_targetPathList, m_url, m_Revision, m_sMessage))
2136 ReportSVNError();
2137 return false;
2139 #endif
2140 return true;
2143 bool CGitProgressDlg::CmdResolve(CString& sWindowTitle, bool& localoperation)
2146 localoperation = true;
2147 ASSERT(m_targetPathList.GetCount() == 1);
2148 sWindowTitle.LoadString(IDS_PROGRS_TITLE_RESOLVE);
2149 CAppUtils::SetWindowTitle(m_hWnd, m_targetPathList.GetCommonRoot().GetUIPathString(), sWindowTitle);
2150 SetBackgroundImage(IDI_RESOLVE_BKG);
2151 // check if the file may still have conflict markers in it.
2152 //BOOL bMarkers = FALSE;
2154 for (int i = 0; i < m_targetPathList.GetCount(); ++i)
2156 CString cmd,out,tempmergefile;
2157 cmd.Format(_T("git.exe add -f -- \"%s\""),m_targetPathList[i].GetGitPathString());
2158 if (g_Git.Run(cmd, &out, CP_UTF8))
2160 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
2161 m_bErrorsOccurred=true;
2162 return false;
2165 CAppUtils::RemoveTempMergeFile((CTGitPath &)m_targetPathList[i]);
2167 Notify(m_targetPathList[i],git_wc_notify_resolved);
2169 #if 0
2170 if ((m_options & ProgOptSkipConflictCheck) == 0)
2174 for (INT_PTR fileindex=0; (fileindex<m_targetPathList.GetCount()) && (bMarkers==FALSE); ++fileindex)
2176 if (!m_targetPathList[fileindex].IsDirectory())
2178 CStdioFile file(m_targetPathList[fileindex].GetWinPath(), CFile::typeBinary | CFile::modeRead);
2179 CString strLine = _T("");
2180 while (file.ReadString(strLine))
2182 if (strLine.Find(_T("<<<<<<<"))==0)
2184 bMarkers = TRUE;
2185 break;
2188 file.Close();
2192 catch (CFileException* pE)
2194 TRACE(_T("CFileException in Resolve!\n"));
2195 TCHAR error[10000] = {0};
2196 pE->GetErrorMessage(error, 10000);
2197 ReportError(error);
2198 pE->Delete();
2199 return false;
2202 if (bMarkers)
2204 if (CMessageBox::Show(m_hWnd, IDS_PROGRS_REVERTMARKERS, IDS_APPNAME, MB_YESNO | MB_ICONQUESTION)==IDYES)
2206 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RESOLVE)));
2207 for (INT_PTR fileindex=0; fileindex<m_targetPathList.GetCount(); ++fileindex)
2208 Resolve(m_targetPathList[fileindex], svn_wc_conflict_choose_merged, true);
2211 else
2213 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RESOLVE)));
2214 for (INT_PTR fileindex=0; fileindex<m_targetPathList.GetCount(); ++fileindex)
2215 Resolve(m_targetPathList[fileindex], svn_wc_conflict_choose_merged, true);
2217 #endif
2218 CShellUpdater::Instance().AddPathsForUpdate(m_targetPathList);
2220 this->GetDlgItem(IDC_LOGBUTTON)->SetWindowText(CString(MAKEINTRESOURCE(IDS_COMMITBUTTON)));
2221 this->GetDlgItem(IDC_LOGBUTTON)->ShowWindow(SW_SHOW);
2223 return true;
2226 bool CGitProgressDlg::CmdRevert(CString& sWindowTitle, bool& localoperation)
2229 localoperation = true;
2230 sWindowTitle.LoadString(IDS_PROGRS_TITLE_REVERT);
2231 CAppUtils::SetWindowTitle(m_hWnd, m_targetPathList.GetCommonRoot().GetUIPathString(), sWindowTitle);
2232 SetBackgroundImage(IDI_REVERT_BKG);
2234 CTGitPathList delList;
2235 for (int i = 0; i < m_selectedPaths.GetCount(); ++i)
2237 CTGitPath path;
2238 int action;
2239 path.SetFromWin(g_Git.m_CurrentDir+_T("\\")+m_selectedPaths[i].GetWinPath());
2240 action = m_selectedPaths[i].m_Action;
2241 /* rename file can't delete because it needs original file*/
2242 if((!(action & CTGitPath::LOGACTIONS_ADDED)) &&
2243 (!(action & CTGitPath::LOGACTIONS_REPLACED)))
2244 delList.AddPath(path);
2246 if (DWORD(CRegDWORD(_T("Software\\TortoiseGit\\RevertWithRecycleBin"), TRUE)))
2247 delList.DeleteAllFiles(true);
2249 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_REVERT)));
2250 for (int i = 0; i < m_selectedPaths.GetCount(); ++i)
2252 if(g_Git.Revert(_T("HEAD"), (CTGitPath&)m_selectedPaths[i]))
2254 CMessageBox::Show(NULL,_T("Revert Fail"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
2255 m_bErrorsOccurred=true;
2256 return false;
2258 Notify(m_selectedPaths[i],git_wc_notify_revert);
2261 CShellUpdater::Instance().AddPathsForUpdate(m_selectedPaths);
2263 return true;
2266 bool CGitProgressDlg::CmdSwitch(CString& /*sWindowTitle*/, bool& /*localoperation*/)
2268 #if 0
2269 ASSERT(m_targetPathList.GetCount() == 1);
2270 SVNStatus st;
2271 sWindowTitle.LoadString(IDS_PROGRS_TITLE_SWITCH);
2272 SetWindowText(sWindowTitle); // needs to be updated, see TSVN rev. 21375
2273 SetBackgroundImage(IDI_SWITCH_BKG);
2274 LONG rev = 0;
2275 if (st.GetStatus(m_targetPathList[0]) != (-2))
2277 if (st.status->entry != NULL)
2279 rev = st.status->entry->revision;
2283 CString sCmdInfo;
2284 sCmdInfo.Format(IDS_PROGRS_CMD_SWITCH,
2285 m_targetPathList[0].GetWinPath(), (LPCTSTR)m_url.GetSVNPathString(),
2286 (LPCTSTR)m_Revision.ToString());
2287 ReportCmd(sCmdInfo);
2289 bool depthIsSticky = true;
2290 if (m_depth == svn_depth_unknown)
2291 depthIsSticky = false;
2292 if (!Switch(m_targetPathList[0], m_url, m_Revision, m_Revision, m_depth, depthIsSticky, m_options & ProgOptIgnoreExternals))
2294 ReportSVNError();
2295 return false;
2297 m_UpdateStartRevMap[m_targetPathList[0].GetSVNApiPath(pool)] = rev;
2298 if ((m_RevisionEnd >= 0)&&(rev >= 0)
2299 &&((LONG)m_RevisionEnd > (LONG)rev))
2301 GetDlgItem(IDC_LOGBUTTON)->ShowWindow(SW_SHOW);
2303 #endif
2304 return true;
2306 bool CGitProgressDlg::CmdClone(CString& sWindowTitle, bool& /*localoperation*/)
2308 if (!g_Git.UsingLibGit2(CGit::GIT_CMD_CLONE))
2310 // should never run to here
2311 ASSERT(FALSE);
2312 return false;
2314 this->m_TotalBytesTransferred = 0;
2316 sWindowTitle.LoadString(IDS_PROGRS_TITLE_CLONE);
2317 CAppUtils::SetWindowTitle(m_hWnd, m_url.GetGitPathString(), sWindowTitle);
2318 SetBackgroundImage(IDI_SWITCH_BKG);
2319 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROG_CLONE)));
2321 if (m_url.IsEmpty() || m_targetPathList.GetCount() == 0)
2322 return false;
2324 CStringA url = CUnicodeUtils::GetMulti(m_url.GetGitPathString(), CP_UTF8);
2325 CStringA path = CUnicodeUtils::GetMulti(m_targetPathList[0].GetWinPathString(),CP_UTF8);
2327 git_repository *cloned_repo = NULL;
2328 git_remote *origin = NULL;
2329 git_checkout_opts checkout_opts = GIT_CHECKOUT_OPTS_INIT;
2331 int error = 0;
2333 git_clone_options clone_opts = GIT_CLONE_OPTIONS_INIT;
2335 clone_opts.checkout_opts = checkout_opts;
2337 clone_opts.checkout_opts.checkout_strategy = m_bNoCheckout? GIT_CHECKOUT_NONE : GIT_CHECKOUT_SAFE_CREATE;
2338 clone_opts.checkout_opts.progress_cb = CheckoutCallback;
2339 clone_opts.checkout_opts.progress_payload = this;
2341 if (!m_RefSpec.IsEmpty())
2342 clone_opts.checkout_branch = CUnicodeUtils::GetMulti(m_RefSpec, CP_UTF8).GetBuffer();
2344 clone_opts.fetch_progress_cb = FetchCallback;
2345 clone_opts.fetch_progress_payload = this;
2347 clone_opts.cred_acquire_cb = CAppUtils::Git2GetUserPassword;
2349 clone_opts.bare = m_bBare;
2351 m_Animate.ShowWindow(SW_SHOW);
2352 m_Animate.Play(0, INT_MAX, INT_MAX);
2353 error = git_clone(&cloned_repo, url, path, &clone_opts);
2354 m_Animate.Stop();
2355 m_Animate.ShowWindow(SW_HIDE);
2357 git_remote_free(origin);
2358 if (error)
2360 ReportGitError();
2361 return false;
2363 else if (cloned_repo)
2364 git_repository_free(cloned_repo);
2365 return true;
2368 void CGitProgressDlg::OnBnClickedNoninteractive()
2370 LRESULT res = ::SendMessage(GetDlgItem(IDC_NONINTERACTIVE)->GetSafeHwnd(), BM_GETCHECK, 0, 0);
2371 m_AlwaysConflicted = (res == BST_CHECKED);
2372 CRegDWORD nonint = CRegDWORD(_T("Software\\TortoiseGit\\MergeNonInteractive"), FALSE);
2373 nonint = m_AlwaysConflicted;
2376 CString CGitProgressDlg::GetPathFromColumnText(const CString& sColumnText)
2378 CString sPath = CPathUtils::ParsePathInString(sColumnText);
2379 if (sPath.Find(':')<0)
2381 // the path is not absolute: add the common root of all paths to it
2382 sPath = m_targetPathList.GetCommonRoot().GetDirectory().GetWinPathString() + _T("\\") + CPathUtils::ParsePathInString(sColumnText);
2384 return sPath;
2387 bool CGitProgressDlg::CmdSendMail(CString& sWindowTitle, bool& /*localoperation*/)
2389 sWindowTitle.LoadString(IDS_PROGRS_TITLE_SENDMAIL);
2390 CAppUtils::SetWindowTitle(m_hWnd, m_targetPathList.GetCommonRoot().GetUIPathString(), sWindowTitle);
2391 //SetBackgroundImage(IDI_ADD_BKG);
2392 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_SENDMAIL)));
2393 bool ret=true;
2394 if(this->m_SendMailFlags&SENDMAIL_COMBINED)
2396 CString error;
2397 CTGitPath path;
2398 Notify(path,git_wc_notify_sendmail_start);
2399 CString err;
2400 int retry=0;
2401 while(retry <3)
2403 if(!!CPatch::SendPatchesCombined(m_targetPathList,m_SendMailTO,m_SendMailCC,m_SendMailSubject,!!(this->m_SendMailFlags&SENDMAIL_ATTACHMENT),!!(this->m_SendMailFlags&SENDMAIL_MAPI),&err))
2405 Notify(path,git_wc_notify_sendmail_error,ret,&err);
2406 ret = false;
2408 else
2410 break;
2413 ++retry;
2414 if (retry < 3)
2415 Notify(path,git_wc_notify_sendmail_retry,ret,&err);
2416 Sleep(2000);
2417 if(m_bCancelled)
2419 CString str;
2420 str.LoadString(IDS_SVN_USERCANCELLED);
2421 Notify(path,git_wc_notify_sendmail_error,ret,&str);
2422 return false;
2425 if (ret)
2426 Notify(path,git_wc_notify_sendmail_done,ret);
2428 else
2430 for (int i = 0; ret && i < m_targetPathList.GetCount(); ++i)
2432 CPatch patch;
2433 Notify(m_targetPathList[i],git_wc_notify_sendmail_start);
2435 int retry=0;
2436 while(retry<3)
2438 if(!!patch.Send((CString&)m_targetPathList[i].GetWinPathString(),this->m_SendMailTO,
2439 this->m_SendMailCC,!!(this->m_SendMailFlags&SENDMAIL_ATTACHMENT),!!(this->m_SendMailFlags&SENDMAIL_MAPI)))
2441 Notify(m_targetPathList[i],git_wc_notify_sendmail_error,ret,&patch.m_LastError);
2442 ret = false;
2445 else
2447 ret = true;
2448 break;
2450 ++retry;
2451 if (retry < 3)
2452 Notify(m_targetPathList[i],git_wc_notify_sendmail_retry,ret,&patch.m_LastError);
2453 Sleep(2000);
2454 if(m_bCancelled)
2456 CString str;
2457 str.LoadString(IDS_SVN_USERCANCELLED);
2458 Notify(m_targetPathList[i],git_wc_notify_sendmail_error,ret,&str);
2459 return false;
2462 if (ret)
2463 Notify(m_targetPathList[i],git_wc_notify_sendmail_done,ret);
2466 return ret;
2469 LRESULT CGitProgressDlg::OnTaskbarBtnCreated(WPARAM /*wParam*/, LPARAM /*lParam*/)
2471 m_pTaskbarList.Release();
2472 m_pTaskbarList.CoCreateInstance(CLSID_TaskbarList);
2473 return 0;
2476 HBRUSH CGitProgressDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
2478 HBRUSH hbr;
2479 if (pWnd->GetDlgCtrlID() == IDC_TITLE_ANIMATE)
2481 pDC->SetBkColor(GetSysColor(COLOR_WINDOW)); // add this
2482 pDC->SetBkMode(TRANSPARENT);
2483 return (HBRUSH)m_background_brush.GetSafeHandle();
2485 else
2486 hbr = CResizableStandAloneDialog::OnCtlColor(pDC, pWnd, nCtlColor);
2488 // TODO: Return a different brush if the default is not desired
2489 return hbr;
2491 LRESULT CGitProgressDlg::OnCtlColorStatic(WPARAM wParam, LPARAM lParam)
2493 HDC hDC = (HDC)wParam;
2494 HWND hwndCtl = (HWND)lParam;
2496 if (::GetDlgCtrlID(hwndCtl) == IDC_TITLE_ANIMATE)
2498 CDC *pDC = CDC::FromHandle(hDC);
2499 pDC->SetBkColor(GetSysColor(COLOR_WINDOW));
2500 pDC->SetBkMode(TRANSPARENT);
2501 return (LRESULT)(HBRUSH)m_background_brush.GetSafeHandle();
2503 return FALSE;