Moved #include "git2.h" to stdafx.h
[TortoiseGit.git] / src / TortoiseProc / GitProgressDlg.cpp
blob34de015b0ef04e25655fa6a99f7f8e1584710f9b
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 "SmartHandle.h"
48 static UINT WM_GITPROGRESS = RegisterWindowMessage(_T("TORTOISEGIT_GITPROGRESS_MSG"));
50 BOOL CGitProgressDlg::m_bAscending = FALSE;
51 int CGitProgressDlg::m_nSortedColumn = -1;
53 #define TRANSFERTIMER 100
54 #define VISIBLETIMER 101
56 enum GITProgressDlgContextMenuCommands
58 // needs to start with 1, since 0 is the return value if *nothing* is clicked on in the context menu
59 ID_COMPARE = 1,
60 ID_EDITCONFLICT,
61 ID_CONFLICTRESOLVE,
62 ID_CONFLICTUSETHEIRS,
63 ID_CONFLICTUSEMINE,
64 ID_LOG,
65 ID_OPEN,
66 ID_OPENWITH,
67 ID_EXPLORE,
68 ID_COPY
71 IMPLEMENT_DYNAMIC(CGitProgressDlg, CResizableStandAloneDialog)
72 CGitProgressDlg::CGitProgressDlg(CWnd* pParent /*=NULL*/)
73 : CResizableStandAloneDialog(CGitProgressDlg::IDD, pParent)
74 , m_bCancelled(FALSE)
75 , m_pThread(NULL)
76 , m_bErrorsOccurred(false)
77 , m_bBare(false)
78 , m_bNoCheckout(false)
79 #if 0
80 , m_Revision(_T("HEAD"))
81 //, m_RevisionEnd(0)
82 , m_bLockWarning(false)
83 , m_bLockExists(false)
84 , m_bThreadRunning(FALSE)
85 , m_nConflicts(0)
86 , m_bMergesAddsDeletesOccurred(FALSE)
88 , m_options(ProgOptNone)
89 , m_dwCloseOnEnd((DWORD)-1)
90 , m_bFinishedItemAdded(false)
91 , m_bLastVisible(false)
92 // , m_depth(svn_depth_unknown)
93 , m_itemCount(-1)
94 , m_itemCountTotal(-1)
95 , m_AlwaysConflicted(false)
96 , m_BugTraqProvider(NULL)
97 , sDryRun(MAKEINTRESOURCE(IDS_PROGRS_DRYRUN))
98 , sRecordOnly(MAKEINTRESOURCE(IDS_MERGE_RECORDONLY))
99 #endif
103 CGitProgressDlg::~CGitProgressDlg()
105 for (size_t i = 0; i < m_arData.size(); ++i)
107 delete m_arData[i];
109 if(m_pThread != NULL)
111 delete m_pThread;
115 void CGitProgressDlg::DoDataExchange(CDataExchange* pDX)
117 CResizableStandAloneDialog::DoDataExchange(pDX);
118 DDX_Control(pDX, IDC_SVNPROGRESS, m_ProgList);
119 DDX_Control(pDX, IDC_TITLE_ANIMATE, m_Animate);
122 BEGIN_MESSAGE_MAP(CGitProgressDlg, CResizableStandAloneDialog)
123 ON_BN_CLICKED(IDC_LOGBUTTON, OnBnClickedLogbutton)
124 ON_NOTIFY(NM_CUSTOMDRAW, IDC_SVNPROGRESS, OnNMCustomdrawSvnprogress)
125 ON_WM_CLOSE()
126 ON_NOTIFY(NM_DBLCLK, IDC_SVNPROGRESS, OnNMDblclkSvnprogress)
127 ON_NOTIFY(HDN_ITEMCLICK, 0, OnHdnItemclickSvnprogress)
128 ON_WM_SETCURSOR()
129 ON_WM_CONTEXTMENU()
130 ON_REGISTERED_MESSAGE(WM_GITPROGRESS, OnGitProgress)
131 ON_WM_TIMER()
132 ON_EN_SETFOCUS(IDC_INFOTEXT, &CGitProgressDlg::OnEnSetfocusInfotext)
133 ON_NOTIFY(LVN_BEGINDRAG, IDC_SVNPROGRESS, &CGitProgressDlg::OnLvnBegindragSvnprogress)
134 ON_WM_SIZE()
135 ON_NOTIFY(LVN_GETDISPINFO, IDC_SVNPROGRESS, &CGitProgressDlg::OnLvnGetdispinfoSvnprogress)
136 ON_BN_CLICKED(IDC_NONINTERACTIVE, &CGitProgressDlg::OnBnClickedNoninteractive)
137 ON_MESSAGE(WM_SHOWCONFLICTRESOLVER, OnShowConflictResolver)
138 ON_REGISTERED_MESSAGE(WM_TASKBARBTNCREATED, OnTaskbarBtnCreated)
139 ON_WM_CTLCOLOR()
140 END_MESSAGE_MAP()
142 BOOL CGitProgressDlg::Cancel()
144 return m_bCancelled;
147 LRESULT CGitProgressDlg::OnShowConflictResolver(WPARAM /*wParam*/, LPARAM /*lParam*/)
149 #if 0
150 CConflictResolveDlg dlg(this);
151 const svn_wc_conflict_description_t *description = (svn_wc_conflict_description_t *)lParam;
152 if (description)
154 dlg.SetConflictDescription(description);
155 if (m_pTaskbarList)
157 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_PAUSED);
159 if (dlg.DoModal() == IDOK)
161 if (dlg.GetResult() == svn_wc_conflict_choose_postpone)
163 // if the result is conflicted and the dialog returned IDOK,
164 // that means we should not ask again in case of a conflict
165 m_AlwaysConflicted = true;
166 ::SendMessage(GetDlgItem(IDC_NONINTERACTIVE)->GetSafeHwnd(), BM_SETCHECK, BST_CHECKED, 0);
169 m_mergedfile = dlg.GetMergedFile();
170 m_bCancelled = dlg.IsCancelled();
171 if (m_pTaskbarList)
172 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_INDETERMINATE);
173 return dlg.GetResult();
176 return svn_wc_conflict_choose_postpone;
177 #endif
178 return 0;
180 #if 0
181 svn_wc_conflict_choice_t CGitProgressDlg::ConflictResolveCallback(const svn_wc_conflict_description_t *description, CString& mergedfile)
183 // we only bother the user when merging
184 if (((m_Command == GitProgress_Merge)||(m_Command == GitProgress_MergeAll)||(m_Command == GitProgress_MergeReintegrate))&&(!m_AlwaysConflicted)&&(description))
186 // we're in a worker thread here. That means we must not show a dialog from the thread
187 // but let the UI thread do it.
188 // To do that, we send a message to the UI thread and let it show the conflict resolver dialog.
189 LRESULT dlgResult = ::SendMessage(GetSafeHwnd(), WM_SHOWCONFLICTRESOLVER, 0, (LPARAM)description);
190 mergedfile = m_mergedfile;
191 return (svn_wc_conflict_choice_t)dlgResult;
194 return svn_wc_conflict_choose_postpone;
196 #endif
197 void CGitProgressDlg::AddItemToList()
199 int totalcount = m_ProgList.GetItemCount();
201 m_ProgList.SetItemCountEx(totalcount+1, LVSICF_NOSCROLL|LVSICF_NOINVALIDATEALL);
202 // make columns width fit
203 if (iFirstResized < 30)
205 // only resize the columns for the first 30 or so entries.
206 // after that, don't resize them anymore because that's an
207 // expensive function call and the columns will be sized
208 // close enough already.
209 ResizeColumns();
210 ++iFirstResized;
213 // Make sure the item is *entirely* visible even if the horizontal
214 // scroll bar is visible.
215 int count = m_ProgList.GetCountPerPage();
216 if (totalcount <= (m_ProgList.GetTopIndex() + count + nEnsureVisibleCount + 2))
218 ++nEnsureVisibleCount;
219 m_bLastVisible = true;
221 else
223 nEnsureVisibleCount = 0;
224 if (IsIconic() == 0)
225 m_bLastVisible = false;
230 BOOL CGitProgressDlg::Notify(const CTGitPath& path, git_wc_notify_action_t action,
231 int /*status*/ ,
232 CString *strErr
234 svn_node_kind_t kind, const CString& mime_type,
235 svn_wc_notify_state_t content_state,
236 svn_wc_notify_state_t prop_state, LONG rev,
237 const svn_lock_t * lock, svn_wc_notify_lock_state_t lock_state,
238 const CString& changelistname,
239 svn_merge_range_t * range,
240 svn_error_t * err, apr_pool_t * pool
243 bool bNoNotify = false;
244 bool bDoAddData = true;
245 NotificationData * data = new NotificationData();
246 data->path = path;
247 data->action = action;
248 data->sPathColumnText=path.GetGitPathString();
249 data->bAuxItem = false;
251 this->m_Animate.ShowWindow(SW_HIDE);
253 #if 0
254 data->kind = kind;
255 data->mime_type = mime_type;
256 data->content_state = content_state;
257 data->prop_state = prop_state;
258 data->rev = rev;
259 data->lock_state = lock_state;
260 data->changelistname = changelistname;
261 if ((lock)&&(lock->owner))
262 data->owner = CUnicodeUtils::GetUnicode(lock->owner);
263 data->sPathColumnText = path.GetUIPathString();
264 if (!m_basePath.IsEmpty())
265 data->basepath = m_basePath;
266 if (range)
267 data->merge_range = *range;
268 #endif
269 switch (data->action)
271 case git_wc_notify_add:
272 //case svn_wc_notify_update_add:
273 // if ((data->content_state == svn_wc_notify_state_conflicted) || (data->prop_state == svn_wc_notify_state_conflicted))
274 // {
275 // data->color = m_Colors.GetColor(CColors::Conflict);
276 // data->bConflictedActionItem = true;
277 // data->sActionColumnText.LoadString(IDS_SVNACTION_CONFLICTED);
278 // ++m_nConflicts;
279 // }
280 // else
281 // {
282 // m_bMergesAddsDeletesOccurred = true;
283 data->sActionColumnText.LoadString(IDS_SVNACTION_ADD);
284 data->color = m_Colors.GetColor(CColors::Added);
285 // }
286 break;
287 case git_wc_notify_sendmail_start:
288 data->bAuxItem = true;
289 data->sActionColumnText.LoadString(IDS_SVNACTION_SENDMAIL_START);
290 data->color = m_Colors.GetColor(CColors::Modified);
291 break;
293 case git_wc_notify_sendmail_error:
294 data->bAuxItem = true;
295 data->sActionColumnText.LoadString(IDS_SVNACTION_SENDMAIL_ERROR);
296 if(strErr)
297 data->sPathColumnText = *strErr;
298 else
299 data->sPathColumnText.Empty();
300 data->color = m_Colors.GetColor(CColors::Modified);
301 break;
303 case git_wc_notify_sendmail_done:
305 data->sActionColumnText.LoadString(IDS_SVNACTION_SENDMAIL_DONE);
306 data->sPathColumnText.Empty();
307 data->color = m_Colors.GetColor(CColors::Modified);
308 break;
310 case git_wc_notify_sendmail_retry:
311 data->sActionColumnText.LoadString(IDS_SVNACTION_SENDMAIL_RETRY);
312 data->sPathColumnText.Empty();
313 data->color = m_Colors.GetColor(CColors::Modified);
314 break;
317 case git_wc_notify_resolved:
318 data->sActionColumnText.LoadString(IDS_SVNACTION_RESOLVE);
319 break;
321 case git_wc_notify_revert:
322 data->sActionColumnText.LoadString(IDS_SVNACTION_REVERT);
323 break;
325 case git_wc_notify_checkout:
326 data->sActionColumnText.LoadString(IDS_PROGRS_CMD_CHECKOUT);
327 data->color = m_Colors.GetColor(CColors::Added);
328 data->bAuxItem = false;
329 break;
331 #if 0
332 case svn_wc_notify_commit_added:
333 data->sActionColumnText.LoadString(IDS_SVNACTION_ADDING);
334 data->color = m_Colors.GetColor(CColors::Added);
335 break;
336 case svn_wc_notify_copy:
337 data->sActionColumnText.LoadString(IDS_SVNACTION_COPY);
338 break;
339 case svn_wc_notify_commit_modified:
340 data->sActionColumnText.LoadString(IDS_SVNACTION_MODIFIED);
341 data->color = m_Colors.GetColor(CColors::Modified);
342 break;
343 case svn_wc_notify_delete:
344 case svn_wc_notify_update_delete:
345 data->sActionColumnText.LoadString(IDS_SVNACTION_DELETE);
346 m_bMergesAddsDeletesOccurred = true;
347 data->color = m_Colors.GetColor(CColors::Deleted);
348 break;
349 case svn_wc_notify_commit_deleted:
350 data->sActionColumnText.LoadString(IDS_SVNACTION_DELETING);
351 data->color = m_Colors.GetColor(CColors::Deleted);
352 break;
353 case svn_wc_notify_restore:
354 data->sActionColumnText.LoadString(IDS_SVNACTION_RESTORE);
355 break;
357 case svn_wc_notify_update_replace:
358 case svn_wc_notify_commit_replaced:
359 data->sActionColumnText.LoadString(IDS_SVNACTION_REPLACED);
360 data->color = m_Colors.GetColor(CColors::Deleted);
361 break;
362 case svn_wc_notify_exists:
363 if ((data->content_state == svn_wc_notify_state_conflicted) || (data->prop_state == svn_wc_notify_state_conflicted))
365 data->color = m_Colors.GetColor(CColors::Conflict);
366 data->bConflictedActionItem = true;
367 ++m_nConflicts;
368 data->sActionColumnText.LoadString(IDS_SVNACTION_CONFLICTED);
370 else if ((data->content_state == svn_wc_notify_state_merged) || (data->prop_state == svn_wc_notify_state_merged))
372 data->color = m_Colors.GetColor(CColors::Merged);
373 m_bMergesAddsDeletesOccurred = true;
374 data->sActionColumnText.LoadString(IDS_SVNACTION_MERGED);
376 else
377 data->sActionColumnText.LoadString(IDS_SVNACTION_EXISTS);
378 break;
379 case svn_wc_notify_update_update:
380 // if this is an inoperative dir change, don't show the notification.
381 // an inoperative dir change is when a directory gets updated without
382 // any real change in either text or properties.
383 if ((kind == svn_node_dir)
384 && ((prop_state == svn_wc_notify_state_inapplicable)
385 || (prop_state == svn_wc_notify_state_unknown)
386 || (prop_state == svn_wc_notify_state_unchanged)))
388 bNoNotify = true;
389 break;
391 if ((data->content_state == svn_wc_notify_state_conflicted) || (data->prop_state == svn_wc_notify_state_conflicted))
393 data->color = m_Colors.GetColor(CColors::Conflict);
394 data->bConflictedActionItem = true;
395 ++m_nConflicts;
396 data->sActionColumnText.LoadString(IDS_SVNACTION_CONFLICTED);
398 else if ((data->content_state == svn_wc_notify_state_merged) || (data->prop_state == svn_wc_notify_state_merged))
400 data->color = m_Colors.GetColor(CColors::Merged);
401 m_bMergesAddsDeletesOccurred = true;
402 data->sActionColumnText.LoadString(IDS_SVNACTION_MERGED);
404 else if (((data->content_state != svn_wc_notify_state_unchanged)&&(data->content_state != svn_wc_notify_state_unknown)) ||
405 ((data->prop_state != svn_wc_notify_state_unchanged)&&(data->prop_state != svn_wc_notify_state_unknown)))
407 data->sActionColumnText.LoadString(IDS_SVNACTION_UPDATE);
409 else
411 bNoNotify = true;
412 break;
414 if (lock_state == svn_wc_notify_lock_state_unlocked)
416 CString temp(MAKEINTRESOURCE(IDS_SVNACTION_UNLOCKED));
417 data->sActionColumnText += _T(", ") + temp;
419 break;
421 case svn_wc_notify_update_external:
422 // For some reason we build a list of externals...
423 m_ExtStack.AddHead(path.GetUIPathString());
424 data->sActionColumnText.LoadString(IDS_SVNACTION_EXTERNAL);
425 data->bAuxItem = true;
426 break;
428 case svn_wc_notify_update_completed:
430 data->sActionColumnText.LoadString(IDS_SVNACTION_COMPLETED);
431 data->bAuxItem = true;
432 bool bEmpty = !!m_ExtStack.IsEmpty();
433 if (!bEmpty)
434 data->sPathColumnText.Format(IDS_PROGRS_PATHATREV, (LPCTSTR)m_ExtStack.RemoveHead(), rev);
435 else
436 data->sPathColumnText.Format(IDS_PROGRS_ATREV, rev);
438 if ((m_nConflicts>0)&&(bEmpty))
440 // We're going to add another aux item - let's shove this current onto the list first
441 // I don't really like this, but it will do for the moment.
442 m_arData.push_back(data);
443 AddItemToList();
445 data = new NotificationData();
446 data->bAuxItem = true;
447 data->sActionColumnText.LoadString(IDS_PROGRS_CONFLICTSOCCURED_WARNING);
448 data->sPathColumnText.LoadString(IDS_PROGRS_CONFLICTSOCCURED);
449 data->color = m_Colors.GetColor(CColors::Conflict);
450 CSoundUtils::PlayTSVNWarning();
451 // This item will now be added after the switch statement
453 if (!m_basePath.IsEmpty())
454 m_FinishedRevMap[m_basePath.GetSVNApiPath(pool)] = rev;
455 m_RevisionEnd = rev;
456 m_bFinishedItemAdded = true;
458 break;
459 case svn_wc_notify_commit_postfix_txdelta:
460 data->sActionColumnText.LoadString(IDS_SVNACTION_POSTFIX);
461 break;
462 case svn_wc_notify_failed_revert:
463 data->sActionColumnText.LoadString(IDS_SVNACTION_FAILEDREVERT);
464 break;
465 case svn_wc_notify_status_completed:
466 case svn_wc_notify_status_external:
467 data->sActionColumnText.LoadString(IDS_SVNACTION_STATUS);
468 break;
469 case svn_wc_notify_skip:
470 if ((content_state == svn_wc_notify_state_missing)||(content_state == svn_wc_notify_state_obstructed)||(content_state == svn_wc_notify_state_conflicted))
472 data->sActionColumnText.LoadString(IDS_SVNACTION_SKIPMISSING);
474 // The color settings dialog describes the red color with
475 // "possible or real conflict / obstructed" which also applies to
476 // skipped targets during a merge. So we just use the same color.
477 data->color = m_Colors.GetColor(CColors::Conflict);
479 else
480 data->sActionColumnText.LoadString(IDS_SVNACTION_SKIP);
481 break;
482 case svn_wc_notify_locked:
483 if ((lock)&&(lock->owner))
484 data->sActionColumnText.Format(IDS_SVNACTION_LOCKEDBY, (LPCTSTR)CUnicodeUtils::GetUnicode(lock->owner));
485 break;
486 case svn_wc_notify_unlocked:
487 data->sActionColumnText.LoadString(IDS_SVNACTION_UNLOCKED);
488 break;
489 case svn_wc_notify_failed_lock:
490 data->sActionColumnText.LoadString(IDS_SVNACTION_FAILEDLOCK);
491 m_arData.push_back(data);
492 AddItemToList();
493 ReportError(SVN::GetErrorString(err));
494 bDoAddData = false;
495 if (err->apr_err == SVN_ERR_FS_OUT_OF_DATE)
496 m_bLockWarning = true;
497 if (err->apr_err == SVN_ERR_FS_PATH_ALREADY_LOCKED)
498 m_bLockExists = true;
499 break;
500 case svn_wc_notify_failed_unlock:
501 data->sActionColumnText.LoadString(IDS_SVNACTION_FAILEDUNLOCK);
502 m_arData.push_back(data);
503 AddItemToList();
504 ReportError(SVN::GetErrorString(err));
505 bDoAddData = false;
506 if (err->apr_err == SVN_ERR_FS_OUT_OF_DATE)
507 m_bLockWarning = true;
508 break;
509 case svn_wc_notify_changelist_set:
510 data->sActionColumnText.Format(IDS_SVNACTION_CHANGELISTSET, (LPCTSTR)data->changelistname);
511 break;
512 case svn_wc_notify_changelist_clear:
513 data->sActionColumnText.LoadString(IDS_SVNACTION_CHANGELISTCLEAR);
514 break;
515 case svn_wc_notify_changelist_moved:
516 data->sActionColumnText.Format(IDS_SVNACTION_CHANGELISTMOVED, (LPCTSTR)data->changelistname);
517 break;
518 case svn_wc_notify_foreign_merge_begin:
519 case svn_wc_notify_merge_begin:
520 if (range == NULL)
521 data->sActionColumnText.LoadString(IDS_SVNACTION_MERGEBEGINNONE);
522 else if ((data->merge_range.start == data->merge_range.end) || (data->merge_range.start == data->merge_range.end - 1))
523 data->sActionColumnText.Format(IDS_SVNACTION_MERGEBEGINSINGLE, data->merge_range.end);
524 else if (data->merge_range.start - 1 == data->merge_range.end)
525 data->sActionColumnText.Format(IDS_SVNACTION_MERGEBEGINSINGLEREVERSE, data->merge_range.start);
526 else if (data->merge_range.start < data->merge_range.end)
527 data->sActionColumnText.Format(IDS_SVNACTION_MERGEBEGINMULTIPLE, data->merge_range.start + 1, data->merge_range.end);
528 else
529 data->sActionColumnText.Format(IDS_SVNACTION_MERGEBEGINMULTIPLEREVERSE, data->merge_range.start, data->merge_range.end + 1);
530 data->bAuxItem = true;
531 break;
532 #endif
533 default:
534 break;
535 } // switch (data->action)
537 if (bNoNotify)
538 delete data;
539 else
541 if (bDoAddData)
543 m_arData.push_back(data);
544 AddItemToList();
545 if ((!data->bAuxItem) && (m_itemCount > 0))
547 CProgressCtrl * progControl = (CProgressCtrl *)GetDlgItem(IDC_PROGRESSBAR);
548 progControl->ShowWindow(SW_SHOW);
549 progControl->SetPos(m_itemCount);
550 progControl->SetRange32(0, m_itemCountTotal);
551 if (m_pTaskbarList)
553 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
554 m_pTaskbarList->SetProgressValue(m_hWnd, m_itemCountTotal - m_itemCount, m_itemCountTotal);
555 m_pTaskbarList->SetProgressValue(m_hWnd, m_itemCount, m_itemCountTotal);
559 //if ((action == svn_wc_notify_commit_postfix_txdelta)&&(bSecondResized == FALSE))
561 // ResizeColumns();
562 // bSecondResized = TRUE;
566 return TRUE;
570 CString CGitProgressDlg::BuildInfoString()
572 CString infotext;
573 if(this->m_Command == GitProgress_Resolve)
574 infotext = _T("You need commit your change after resolve conflict");
575 #if 0
577 CString temp;
578 int added = 0;
579 int copied = 0;
580 int deleted = 0;
581 int restored = 0;
582 int reverted = 0;
583 int resolved = 0;
584 int conflicted = 0;
585 int updated = 0;
586 int merged = 0;
587 int modified = 0;
588 int skipped = 0;
589 int replaced = 0;
591 for (size_t i=0; i<m_arData.size(); ++i)
593 const NotificationData * dat = m_arData[i];
594 switch (dat->action)
596 case svn_wc_notify_add:
597 case svn_wc_notify_update_add:
598 case svn_wc_notify_commit_added:
599 if (dat->bConflictedActionItem)
600 ++conflicted;
601 else
602 ++added;
603 break;
604 case svn_wc_notify_copy:
605 ++copied;
606 break;
607 case svn_wc_notify_delete:
608 case svn_wc_notify_update_delete:
609 case svn_wc_notify_commit_deleted:
610 ++deleted;
611 break;
612 case svn_wc_notify_restore:
613 ++restored;
614 break;
615 case svn_wc_notify_revert:
616 ++reverted;
617 break;
618 case svn_wc_notify_resolved:
619 ++resolved;
620 break;
621 case svn_wc_notify_update_update:
622 if (dat->bConflictedActionItem)
623 ++conflicted;
624 else if ((dat->content_state == svn_wc_notify_state_merged) || (dat->prop_state == svn_wc_notify_state_merged))
625 ++merged;
626 else
627 ++updated;
628 break;
629 case svn_wc_notify_commit_modified:
630 ++modified;
631 break;
632 case svn_wc_notify_skip:
633 ++skipped;
634 break;
635 case svn_wc_notify_commit_replaced:
636 ++replaced;
637 break;
640 if (conflicted)
642 temp.LoadString(IDS_SVNACTION_CONFLICTED);
643 infotext += temp;
644 temp.Format(_T(":%d "), conflicted);
645 infotext += temp;
647 if (skipped)
649 temp.LoadString(IDS_SVNACTION_SKIP);
650 infotext += temp;
651 infotext.AppendFormat(_T(":%d "), skipped);
653 if (merged)
655 temp.LoadString(IDS_SVNACTION_MERGED);
656 infotext += temp;
657 infotext.AppendFormat(_T(":%d "), merged);
659 if (added)
661 temp.LoadString(IDS_SVNACTION_ADD);
662 infotext += temp;
663 infotext.AppendFormat(_T(":%d "), added);
665 if (deleted)
667 temp.LoadString(IDS_SVNACTION_DELETE);
668 infotext += temp;
669 infotext.AppendFormat(_T(":%d "), deleted);
671 if (modified)
673 temp.LoadString(IDS_SVNACTION_MODIFIED);
674 infotext += temp;
675 infotext.AppendFormat(_T(":%d "), modified);
677 if (copied)
679 temp.LoadString(IDS_SVNACTION_COPY);
680 infotext += temp;
681 infotext.AppendFormat(_T(":%d "), copied);
683 if (replaced)
685 temp.LoadString(IDS_SVNACTION_REPLACED);
686 infotext += temp;
687 infotext.AppendFormat(_T(":%d "), replaced);
689 if (updated)
691 temp.LoadString(IDS_SVNACTION_UPDATE);
692 infotext += temp;
693 infotext.AppendFormat(_T(":%d "), updated);
695 if (restored)
697 temp.LoadString(IDS_SVNACTION_RESTORE);
698 infotext += temp;
699 infotext.AppendFormat(_T(":%d "), restored);
701 if (reverted)
703 temp.LoadString(IDS_SVNACTION_REVERT);
704 infotext += temp;
705 infotext.AppendFormat(_T(":%d "), reverted);
707 if (resolved)
709 temp.LoadString(IDS_SVNACTION_RESOLVE);
710 infotext += temp;
711 infotext.AppendFormat(_T(":%d "), resolved);
713 #endif
714 return infotext;
717 void CGitProgressDlg::SetSelectedList(const CTGitPathList& selPaths)
719 m_selectedPaths = selPaths;
722 void CGitProgressDlg::ResizeColumns()
724 m_ProgList.SetRedraw(FALSE);
726 TCHAR textbuf[MAX_PATH];
728 int maxcol = ((CHeaderCtrl*)(m_ProgList.GetDlgItem(0)))->GetItemCount()-1;
729 for (int col = 0; col <= maxcol; ++col)
731 // find the longest width of all items
732 int count = m_ProgList.GetItemCount();
733 HDITEM hdi = {0};
734 hdi.mask = HDI_TEXT;
735 hdi.pszText = textbuf;
736 hdi.cchTextMax = sizeof(textbuf);
737 ((CHeaderCtrl*)(m_ProgList.GetDlgItem(0)))->GetItem(col, &hdi);
738 int cx = m_ProgList.GetStringWidth(hdi.pszText)+20; // 20 pixels for col separator and margin
740 for (int index = 0; index<count; ++index)
742 // get the width of the string and add 12 pixels for the column separator and margins
743 int linewidth = cx;
744 switch (col)
746 case 0:
747 linewidth = m_ProgList.GetStringWidth(m_arData[index]->sActionColumnText) + 12;
748 break;
749 case 1:
750 linewidth = m_ProgList.GetStringWidth(m_arData[index]->sPathColumnText) + 12;
751 break;
753 if (cx < linewidth)
754 cx = linewidth;
756 m_ProgList.SetColumnWidth(col, cx);
759 m_ProgList.SetRedraw(TRUE);
762 BOOL CGitProgressDlg::OnInitDialog()
764 __super::OnInitDialog();
766 // Let the TaskbarButtonCreated message through the UIPI filter. If we don't
767 // do this, Explorer would be unable to send that message to our window if we
768 // were running elevated. It's OK to make the call all the time, since if we're
769 // not elevated, this is a no-op.
770 CHANGEFILTERSTRUCT cfs = { sizeof(CHANGEFILTERSTRUCT) };
771 typedef BOOL STDAPICALLTYPE ChangeWindowMessageFilterExDFN(HWND hWnd, UINT message, DWORD action, PCHANGEFILTERSTRUCT pChangeFilterStruct);
772 CAutoLibrary hUser = AtlLoadSystemLibraryUsingFullPath(_T("user32.dll"));
773 if (hUser)
775 ChangeWindowMessageFilterExDFN *pfnChangeWindowMessageFilterEx = (ChangeWindowMessageFilterExDFN*)GetProcAddress(hUser, "ChangeWindowMessageFilterEx");
776 if (pfnChangeWindowMessageFilterEx)
778 pfnChangeWindowMessageFilterEx(m_hWnd, WM_TASKBARBTNCREATED, MSGFLT_ALLOW, &cfs);
781 m_pTaskbarList.Release();
782 if (FAILED(m_pTaskbarList.CoCreateInstance(CLSID_TaskbarList)))
783 m_pTaskbarList = nullptr;
785 m_ProgList.SetExtendedStyle (LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER);
787 m_ProgList.DeleteAllItems();
788 int c = ((CHeaderCtrl*)(m_ProgList.GetDlgItem(0)))->GetItemCount()-1;
789 while (c>=0)
790 m_ProgList.DeleteColumn(c--);
791 CString temp;
792 temp.LoadString(IDS_PROGRS_ACTION);
793 m_ProgList.InsertColumn(0, temp);
794 temp.LoadString(IDS_PROGRS_PATH);
795 m_ProgList.InsertColumn(1, temp);
797 m_pThread = AfxBeginThread(ProgressThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
798 if (m_pThread==NULL)
800 ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
802 else
804 m_pThread->m_bAutoDelete = FALSE;
805 m_pThread->ResumeThread();
808 UpdateData(FALSE);
810 // Call this early so that the column headings aren't hidden before any
811 // text gets added.
812 ResizeColumns();
814 SetTimer(VISIBLETIMER, 300, NULL);
816 AddAnchor(IDC_SVNPROGRESS, TOP_LEFT, BOTTOM_RIGHT);
817 AddAnchor(IDC_TITLE_ANIMATE, TOP_LEFT, BOTTOM_RIGHT);
818 AddAnchor(IDC_PROGRESSLABEL, BOTTOM_LEFT, BOTTOM_CENTER);
819 AddAnchor(IDC_PROGRESSBAR, BOTTOM_CENTER, BOTTOM_RIGHT);
820 AddAnchor(IDC_INFOTEXT, BOTTOM_LEFT, BOTTOM_RIGHT);
821 AddAnchor(IDC_NONINTERACTIVE, BOTTOM_LEFT, BOTTOM_RIGHT);
822 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
823 AddAnchor(IDOK, BOTTOM_RIGHT);
824 AddAnchor(IDC_LOGBUTTON, BOTTOM_RIGHT);
825 //SetPromptParentWindow(this->m_hWnd);
827 m_Animate.Open(IDR_DOWNLOAD);
829 if (hWndExplorer)
830 CenterWindow(CWnd::FromHandle(hWndExplorer));
831 EnableSaveRestore(_T("GITProgressDlg"));
833 m_background_brush.CreateSolidBrush(GetSysColor(COLOR_WINDOW));
834 return TRUE;
837 bool CGitProgressDlg::SetBackgroundImage(UINT nID)
839 return CAppUtils::SetListCtrlBackgroundImage(m_ProgList.GetSafeHwnd(), nID);
842 void CGitProgressDlg::ReportGitError()
844 ReportError(CGit::GetLibGit2LastErr());
847 void CGitProgressDlg::ReportError(const CString& sError)
849 CSoundUtils::PlayTGitError();
850 ReportString(sError, CString(MAKEINTRESOURCE(IDS_ERR_ERROR)), m_Colors.GetColor(CColors::Conflict));
851 m_bErrorsOccurred = true;
854 void CGitProgressDlg::ReportWarning(const CString& sWarning)
856 CSoundUtils::PlayTGitWarning();
857 ReportString(sWarning, CString(MAKEINTRESOURCE(IDS_WARN_WARNING)), m_Colors.GetColor(CColors::Conflict));
860 void CGitProgressDlg::ReportNotification(const CString& sNotification)
862 CSoundUtils::PlayTGitNotification();
863 ReportString(sNotification, CString(MAKEINTRESOURCE(IDS_WARN_NOTE)));
866 void CGitProgressDlg::ReportCmd(const CString& sCmd)
868 ReportString(sCmd, CString(MAKEINTRESOURCE(IDS_PROGRS_CMDINFO)), m_Colors.GetColor(CColors::Cmd));
871 void CGitProgressDlg::ReportString(CString sMessage, const CString& sMsgKind, COLORREF color)
873 // instead of showing a dialog box with the error message or notification,
874 // just insert the error text into the list control.
875 // that way the user isn't 'interrupted' by a dialog box popping up!
877 // the message may be split up into different lines
878 // so add a new entry for each line of the message
879 while (!sMessage.IsEmpty())
881 NotificationData * data = new NotificationData();
882 data->bAuxItem = true;
883 data->sActionColumnText = sMsgKind;
884 if (sMessage.Find('\n')>=0)
885 data->sPathColumnText = sMessage.Left(sMessage.Find('\n'));
886 else
887 data->sPathColumnText = sMessage;
888 data->sPathColumnText.Trim(_T("\n\r"));
889 data->color = color;
890 if (sMessage.Find('\n')>=0)
892 sMessage = sMessage.Mid(sMessage.Find('\n'));
893 sMessage.Trim(_T("\n\r"));
895 else
896 sMessage.Empty();
897 m_arData.push_back(data);
898 AddItemToList();
902 UINT CGitProgressDlg::ProgressThreadEntry(LPVOID pVoid)
904 return ((CGitProgressDlg*)pVoid)->ProgressThread();
907 UINT CGitProgressDlg::ProgressThread()
909 // The SetParams function should have loaded something for us
911 CString temp;
912 CString sWindowTitle;
913 bool localoperation = false;
914 bool bSuccess = false;
915 m_AlwaysConflicted = false;
917 DialogEnableWindow(IDOK, FALSE);
918 DialogEnableWindow(IDCANCEL, TRUE);
919 // SetAndClearProgressInfo(m_hWnd);
920 m_itemCount = m_itemCountTotal;
922 InterlockedExchange(&m_bThreadRunning, TRUE);
923 iFirstResized = 0;
924 bSecondResized = FALSE;
925 m_bFinishedItemAdded = false;
926 CTime startTime = CTime::GetCurrentTime();
928 if (m_pTaskbarList)
929 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_INDETERMINATE);
931 switch (m_Command)
933 case GitProgress_Add:
934 bSuccess = CmdAdd(sWindowTitle, localoperation);
935 break;
936 case GitProgress_Copy:
937 bSuccess = CmdCopy(sWindowTitle, localoperation);
938 break;
939 case GitProgress_Export:
940 bSuccess = CmdExport(sWindowTitle, localoperation);
941 break;
942 case GitProgress_Rename:
943 bSuccess = CmdRename(sWindowTitle, localoperation);
944 break;
945 case GitProgress_Resolve:
946 bSuccess = CmdResolve(sWindowTitle, localoperation);
947 break;
948 case GitProgress_Revert:
949 bSuccess = CmdRevert(sWindowTitle, localoperation);
950 break;
951 case GitProgress_Switch:
952 bSuccess = CmdSwitch(sWindowTitle, localoperation);
953 break;
954 case GitProgress_SendMail:
955 bSuccess = CmdSendMail(sWindowTitle, localoperation);
956 break;
957 case GitProgress_Clone:
958 bSuccess = CmdClone(sWindowTitle, localoperation);
959 break;
961 if (!bSuccess)
962 temp.LoadString(IDS_PROGRS_TITLEFAILED);
963 else
964 temp.LoadString(IDS_PROGRS_TITLEFIN);
965 sWindowTitle = sWindowTitle + _T(" ") + temp;
966 SetWindowText(sWindowTitle);
968 KillTimer(TRANSFERTIMER);
969 KillTimer(VISIBLETIMER);
971 if (m_pTaskbarList)
973 if (DidErrorsOccur())
975 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_ERROR);
976 m_pTaskbarList->SetProgressValue(m_hWnd, 100, 100);
978 else
979 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NOPROGRESS);
982 DialogEnableWindow(IDCANCEL, FALSE);
983 DialogEnableWindow(IDOK, TRUE);
985 CString info = BuildInfoString();
986 if (!bSuccess)
987 info.LoadString(IDS_PROGRS_INFOFAILED);
988 SetDlgItemText(IDC_INFOTEXT, info);
989 ResizeColumns();
990 CWnd * pWndOk = GetDlgItem(IDOK);
991 if (pWndOk && ::IsWindow(pWndOk->GetSafeHwnd()))
993 SendMessage(DM_SETDEFID, IDOK);
994 GetDlgItem(IDOK)->SetFocus();
997 CString sFinalInfo;
998 if (!m_sTotalBytesTransferred.IsEmpty())
1000 CTimeSpan time = CTime::GetCurrentTime() - startTime;
1001 temp.Format(IDS_PROGRS_TIME, (LONG)time.GetTotalMinutes(), (LONG)time.GetSeconds());
1002 sFinalInfo.Format(IDS_PROGRS_FINALINFO, m_sTotalBytesTransferred, (LPCTSTR)temp);
1003 SetDlgItemText(IDC_PROGRESSLABEL, sFinalInfo);
1005 else
1006 GetDlgItem(IDC_PROGRESSLABEL)->ShowWindow(SW_HIDE);
1008 GetDlgItem(IDC_PROGRESSBAR)->ShowWindow(SW_HIDE);
1010 if (!m_bFinishedItemAdded)
1012 // there's no "finished: xxx" line at the end. We add one here to make
1013 // sure the user sees that the command is actually finished.
1014 NotificationData * data = new NotificationData();
1015 data->bAuxItem = true;
1016 data->sActionColumnText.LoadString(IDS_PROGRS_FINISHED);
1017 m_arData.push_back(data);
1018 AddItemToList();
1021 int count = m_ProgList.GetItemCount();
1022 if ((count > 0)&&(m_bLastVisible))
1023 m_ProgList.EnsureVisible(count-1, FALSE);
1025 CLogFile logfile;
1026 if (logfile.Open())
1028 logfile.AddTimeLine();
1029 for (size_t i = 0; i < m_arData.size(); ++i)
1031 NotificationData * data = m_arData[i];
1032 temp.Format(_T("%-20s : %s"), (LPCTSTR)data->sActionColumnText, (LPCTSTR)data->sPathColumnText);
1033 logfile.AddLine(temp);
1035 if (!sFinalInfo.IsEmpty())
1036 logfile.AddLine(sFinalInfo);
1037 logfile.Close();
1040 m_bCancelled = TRUE;
1041 InterlockedExchange(&m_bThreadRunning, FALSE);
1042 RefreshCursor();
1044 #if 0
1045 DWORD dwAutoClose = CRegStdDWORD(_T("Software\\TortoiseGit\\AutoClose"), CLOSE_MANUAL);
1046 if (m_options & ProgOptDryRun)
1047 dwAutoClose = 0; // dry run means progress dialog doesn't auto close at all
1048 if (!m_bLastVisible)
1049 dwAutoClose = 0;
1050 if (m_dwCloseOnEnd != (DWORD)-1)
1051 dwAutoClose = m_dwCloseOnEnd; // command line value has priority over setting value
1052 if ((dwAutoClose == CLOSE_NOERRORS)&&(!m_bErrorsOccurred))
1053 PostMessage(WM_COMMAND, 1, (LPARAM)GetDlgItem(IDOK)->m_hWnd);
1054 if ((dwAutoClose == CLOSE_NOCONFLICTS)&&(!m_bErrorsOccurred)&&(m_nConflicts==0))
1055 PostMessage(WM_COMMAND, 1, (LPARAM)GetDlgItem(IDOK)->m_hWnd);
1056 if ((dwAutoClose == CLOSE_NOMERGES)&&(!m_bErrorsOccurred)&&(m_nConflicts==0)&&(!m_bMergesAddsDeletesOccurred))
1057 PostMessage(WM_COMMAND, 1, (LPARAM)GetDlgItem(IDOK)->m_hWnd);
1058 if ((dwAutoClose == CLOSE_LOCAL)&&(!m_bErrorsOccurred)&&(m_nConflicts==0)&&(localoperation))
1059 PostMessage(WM_COMMAND, 1, (LPARAM)GetDlgItem(IDOK)->m_hWnd);
1060 #endif
1062 //Don't do anything here which might cause messages to be sent to the window
1063 //The window thread is probably now blocked in OnOK if we've done an auto close
1064 return 0;
1067 void CGitProgressDlg::OnBnClickedLogbutton()
1069 switch(this->m_Command)
1071 case GitProgress_Add:
1072 case GitProgress_Resolve:
1074 CString cmd = _T(" /command:commit");
1075 cmd += _T(" /path:\"")+g_Git.m_CurrentDir+_T("\"");
1077 CAppUtils::RunTortoiseGitProc(cmd);
1078 this->EndDialog(IDOK);
1079 break;
1082 #if 0
1083 if (m_targetPathList.GetCount() != 1)
1084 return;
1085 StringRevMap::iterator it = m_UpdateStartRevMap.begin();
1086 svn_revnum_t rev = -1;
1087 if (it != m_UpdateStartRevMap.end())
1089 rev = it->second;
1091 CLogDlg dlg;
1092 dlg.SetParams(m_targetPathList[0], m_RevisionEnd, m_RevisionEnd, rev, 0, TRUE);
1093 dlg.DoModal();
1094 #endif
1098 void CGitProgressDlg::OnClose()
1100 if (m_bCancelled)
1102 TerminateThread(m_pThread->m_hThread, (DWORD)-1);
1103 InterlockedExchange(&m_bThreadRunning, FALSE);
1105 else
1107 m_bCancelled = TRUE;
1108 return;
1110 DialogEnableWindow(IDCANCEL, TRUE);
1111 __super::OnClose();
1114 void CGitProgressDlg::OnOK()
1116 if ((m_bCancelled)&&(!m_bThreadRunning))
1118 // I have made this wait a sensible amount of time (10 seconds) for the thread to finish
1119 // You must be careful in the thread that after posting the WM_COMMAND/IDOK message, you
1120 // don't do any more operations on the window which might require message passing
1121 // If you try to send windows messages once we're waiting here, then the thread can't finished
1122 // because the Window's message loop is blocked at this wait
1123 WaitForSingleObject(m_pThread->m_hThread, 10000);
1124 __super::OnOK();
1126 m_bCancelled = TRUE;
1129 void CGitProgressDlg::OnCancel()
1131 if ((m_bCancelled)&&(!m_bThreadRunning))
1132 __super::OnCancel();
1133 m_bCancelled = TRUE;
1136 void CGitProgressDlg::OnLvnGetdispinfoSvnprogress(NMHDR *pNMHDR, LRESULT *pResult)
1138 NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
1140 if (pDispInfo)
1142 if (pDispInfo->item.mask & LVIF_TEXT)
1144 if (pDispInfo->item.iItem < (int)m_arData.size())
1146 const NotificationData * data = m_arData[pDispInfo->item.iItem];
1147 switch (pDispInfo->item.iSubItem)
1149 case 0:
1150 lstrcpyn(m_columnbuf, data->sActionColumnText, MAX_PATH);
1151 break;
1152 case 1:
1153 lstrcpyn(m_columnbuf, data->sPathColumnText, pDispInfo->item.cchTextMax);
1154 if (!data->bAuxItem)
1156 int cWidth = m_ProgList.GetColumnWidth(1);
1157 cWidth = max(12, cWidth-12);
1158 CDC * pDC = m_ProgList.GetDC();
1159 if (pDC != NULL)
1161 CFont * pFont = pDC->SelectObject(m_ProgList.GetFont());
1162 PathCompactPath(pDC->GetSafeHdc(), m_columnbuf, cWidth);
1163 pDC->SelectObject(pFont);
1164 ReleaseDC(pDC);
1167 break;
1168 default:
1169 m_columnbuf[0] = 0;
1171 pDispInfo->item.pszText = m_columnbuf;
1175 *pResult = 0;
1178 void CGitProgressDlg::OnNMCustomdrawSvnprogress(NMHDR *pNMHDR, LRESULT *pResult)
1180 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
1182 // Take the default processing unless we set this to something else below.
1183 *pResult = CDRF_DODEFAULT;
1185 // First thing - check the draw stage. If it's the control's prepaint
1186 // stage, then tell Windows we want messages for every item.
1188 if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )
1190 *pResult = CDRF_NOTIFYITEMDRAW;
1192 else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )
1194 // This is the prepaint stage for an item. Here's where we set the
1195 // item's text color. Our return value will tell Windows to draw the
1196 // item itself, but it will use the new color we set here.
1198 // Tell Windows to paint the control itself.
1199 *pResult = CDRF_DODEFAULT;
1201 ASSERT(pLVCD->nmcd.dwItemSpec < m_arData.size());
1202 if(pLVCD->nmcd.dwItemSpec >= m_arData.size())
1204 return;
1206 const NotificationData * data = m_arData[pLVCD->nmcd.dwItemSpec];
1207 ASSERT(data != NULL);
1208 if (data == NULL)
1209 return;
1211 // Store the color back in the NMLVCUSTOMDRAW struct.
1212 pLVCD->clrText = data->color;
1216 void CGitProgressDlg::OnNMDblclkSvnprogress(NMHDR * /*pNMHDR*/, LRESULT * /*pResult*/)
1218 #if 0
1219 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1220 *pResult = 0;
1221 if (pNMLV->iItem < 0)
1222 return;
1223 if (m_options & ProgOptDryRun)
1224 return; //don't do anything in a dry-run.
1226 const NotificationData * data = m_arData[pNMLV->iItem];
1227 if (data == NULL)
1228 return;
1230 if (data->bConflictedActionItem)
1232 // We've double-clicked on a conflicted item - do a three-way merge on it
1233 SVNDiff::StartConflictEditor(data->path);
1235 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))
1237 // This is a modified file which has been merged on update. Diff it against base
1238 CTGitPath temporaryFile;
1239 SVNDiff diff(this, this->m_hWnd, true);
1240 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
1241 svn_revnum_t baseRev = 0;
1242 diff.DiffFileAgainstBase(data->path, baseRev);
1244 else if ((!data->bAuxItem)&&(data->path.Exists())&&(!data->path.IsDirectory()))
1246 bool bOpenWith = false;
1247 int ret = (int)ShellExecute(m_hWnd, NULL, data->path.GetWinPath(), NULL, NULL, SW_SHOWNORMAL);
1248 if (ret <= HINSTANCE_ERROR)
1249 bOpenWith = true;
1250 if (bOpenWith)
1252 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
1253 cmd += data->path.GetWinPathString() + _T(" ");
1254 CAppUtils::LaunchApplication(cmd, NULL, false);
1257 #endif
1260 void CGitProgressDlg::OnHdnItemclickSvnprogress(NMHDR *pNMHDR, LRESULT *pResult)
1262 LPNMHEADER phdr = reinterpret_cast<LPNMHEADER>(pNMHDR);
1263 if (m_bThreadRunning)
1264 return;
1265 if (m_nSortedColumn == phdr->iItem)
1266 m_bAscending = !m_bAscending;
1267 else
1268 m_bAscending = TRUE;
1269 m_nSortedColumn = phdr->iItem;
1270 Sort();
1272 CString temp;
1273 m_ProgList.SetRedraw(FALSE);
1274 m_ProgList.DeleteAllItems();
1275 m_ProgList.SetItemCountEx (static_cast<int>(m_arData.size()));
1277 m_ProgList.SetRedraw(TRUE);
1279 *pResult = 0;
1282 bool CGitProgressDlg::NotificationDataIsAux(const NotificationData* pData)
1284 return pData->bAuxItem;
1287 BOOL CGitProgressDlg::Notify(const git_wc_notify_action_t /*action*/, const git_transfer_progress *stat)
1289 static unsigned int start = 0;
1290 unsigned int dt = GetCurrentTime() - start;
1291 size_t ds;
1292 double speed = 0;
1293 if (dt > 100)
1295 start = GetCurrentTime();
1296 ds = stat->received_bytes - m_TotalBytesTransferred;
1297 speed = ds * 1000.0/dt;
1298 m_TotalBytesTransferred = stat->received_bytes;
1300 else
1302 return TRUE;
1305 CProgressCtrl * progControl = (CProgressCtrl *)GetDlgItem(IDC_PROGRESSBAR);
1307 int progress;
1308 progress = stat->received_objects + stat->indexed_objects;
1310 if ((stat->total_objects > 1000) && (!progControl->IsWindowVisible()))
1312 progControl->ShowWindow(SW_SHOW);
1313 if (m_pTaskbarList)
1314 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
1316 if (!GetDlgItem(IDC_PROGRESSLABEL)->IsWindowVisible())
1317 GetDlgItem(IDC_PROGRESSLABEL)->ShowWindow(SW_SHOW);
1319 progControl->SetPos(progress);
1320 progControl->SetRange32(0, 2 * stat->total_objects);
1321 if (m_pTaskbarList)
1323 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
1324 m_pTaskbarList->SetProgressValue(m_hWnd, progress, stat->total_objects);
1327 CString progText;
1328 if (stat->received_bytes < 1024)
1329 m_sTotalBytesTransferred.Format(IDS_SVN_PROGRESS_TOTALBYTESTRANSFERRED, (int64_t)stat->received_bytes);
1330 else if (stat->received_bytes < 1200000)
1331 m_sTotalBytesTransferred.Format(IDS_SVN_PROGRESS_TOTALTRANSFERRED, (int64_t)stat->received_bytes / 1024);
1332 else
1333 m_sTotalBytesTransferred.Format(IDS_SVN_PROGRESS_TOTALMBTRANSFERRED, (double)((double)stat->received_bytes / 1024000.0));
1335 CString str;
1336 if(speed < 1024)
1337 str.Format(_T("%fB/s"), speed);
1338 else if(speed < 1024 * 1024)
1339 str.Format(_T("%.2fKB/s"), speed / 1024);
1340 else
1341 str.Format(_T("%.2fMB/s"), speed / 1024000.0);
1343 progText.Format(IDS_SVN_PROGRESS_TOTALANDSPEED, (LPCTSTR)m_sTotalBytesTransferred, (LPCTSTR)str);
1344 SetDlgItemText(IDC_PROGRESSLABEL, progText);
1346 return TRUE;
1349 LRESULT CGitProgressDlg::OnGitProgress(WPARAM /*wParam*/, LPARAM /*lParam*/)
1351 #if 0
1352 SVNProgress * pProgressData = (SVNProgress *)lParam;
1353 CProgressCtrl * progControl = (CProgressCtrl *)GetDlgItem(IDC_PROGRESSBAR);
1354 if ((pProgressData->total > 1000)&&(!progControl->IsWindowVisible()))
1356 progControl->ShowWindow(SW_SHOW);
1357 if (m_pTaskbarList)
1358 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
1360 if (((pProgressData->total < 0)&&(pProgressData->progress > 1000)&&(progControl->IsWindowVisible()))&&(m_itemCountTotal<0))
1362 progControl->ShowWindow(SW_HIDE);
1363 if (m_pTaskbarList)
1364 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_INDETERMINATE);
1366 if (!GetDlgItem(IDC_PROGRESSLABEL)->IsWindowVisible())
1367 GetDlgItem(IDC_PROGRESSLABEL)->ShowWindow(SW_SHOW);
1368 SetTimer(TRANSFERTIMER, 2000, NULL);
1369 if ((pProgressData->total > 0)&&(pProgressData->progress > 1000))
1371 progControl->SetPos((int)pProgressData->progress);
1372 progControl->SetRange32(0, (int)pProgressData->total);
1373 if (m_pTaskbarList)
1375 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
1376 m_pTaskbarList->SetProgressValue(m_hWnd, pProgressData->progress, pProgressData->total);
1379 CString progText;
1380 if (pProgressData->overall_total < 1024)
1381 m_sTotalBytesTransferred.Format(IDS_SVN_PROGRESS_TOTALBYTESTRANSFERRED, pProgressData->overall_total);
1382 else if (pProgressData->overall_total < 1200000)
1383 m_sTotalBytesTransferred.Format(IDS_SVN_PROGRESS_TOTALTRANSFERRED, pProgressData->overall_total / 1024);
1384 else
1385 m_sTotalBytesTransferred.Format(IDS_SVN_PROGRESS_TOTALMBTRANSFERRED, (double)((double)pProgressData->overall_total / 1024000.0));
1386 progText.Format(IDS_SVN_PROGRESS_TOTALANDSPEED, (LPCTSTR)m_sTotalBytesTransferred, (LPCTSTR)pProgressData->SpeedString);
1387 SetDlgItemText(IDC_PROGRESSLABEL, progText);
1388 #endif
1389 return 0;
1392 void CGitProgressDlg::OnTimer(UINT_PTR nIDEvent)
1394 if (nIDEvent == TRANSFERTIMER)
1396 CString progText;
1397 CString progSpeed;
1398 progSpeed.Format(IDS_SVN_PROGRESS_BYTES_SEC, 0);
1399 progText.Format(IDS_SVN_PROGRESS_TOTALANDSPEED, (LPCTSTR)m_sTotalBytesTransferred, (LPCTSTR)progSpeed);
1400 SetDlgItemText(IDC_PROGRESSLABEL, progText);
1401 KillTimer(TRANSFERTIMER);
1403 if (nIDEvent == VISIBLETIMER)
1405 if (nEnsureVisibleCount)
1406 m_ProgList.EnsureVisible(m_ProgList.GetItemCount()-1, false);
1407 nEnsureVisibleCount = 0;
1411 void CGitProgressDlg::Sort()
1413 if(m_arData.size() < 2)
1415 return;
1418 // We need to sort the blocks which lie between the auxiliary entries
1419 // This is so that any aux data stays where it was
1420 NotificationDataVect::iterator actionBlockBegin;
1421 NotificationDataVect::iterator actionBlockEnd = m_arData.begin(); // We start searching from here
1423 for(;;)
1425 // Search to the start of the non-aux entry in the next block
1426 actionBlockBegin = std::find_if(actionBlockEnd, m_arData.end(), std::not1(std::ptr_fun(&CGitProgressDlg::NotificationDataIsAux)));
1427 if(actionBlockBegin == m_arData.end())
1429 // There are no more actions
1430 break;
1432 // Now search to find the end of the block
1433 actionBlockEnd = std::find_if(actionBlockBegin+1, m_arData.end(), std::ptr_fun(&CGitProgressDlg::NotificationDataIsAux));
1434 // Now sort the block
1435 std::sort(actionBlockBegin, actionBlockEnd, &CGitProgressDlg::SortCompare);
1439 bool CGitProgressDlg::SortCompare(const NotificationData * pData1, const NotificationData * pData2)
1441 int result = 0;
1442 switch (m_nSortedColumn)
1444 case 0: //action column
1445 result = pData1->sActionColumnText.Compare(pData2->sActionColumnText);
1446 break;
1447 case 1: //path column
1448 // Compare happens after switch()
1449 break;
1450 default:
1451 break;
1454 // Sort by path if everything else is equal
1455 if (result == 0)
1457 result = CTGitPath::Compare(pData1->path, pData2->path);
1460 if (!m_bAscending)
1461 result = -result;
1462 return result < 0;
1465 BOOL CGitProgressDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
1467 if (!GetDlgItem(IDOK)->IsWindowEnabled())
1469 // only show the wait cursor over the list control
1470 if ((pWnd)&&(pWnd == GetDlgItem(IDC_SVNPROGRESS)))
1472 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT));
1473 SetCursor(hCur);
1474 return TRUE;
1477 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));
1478 SetCursor(hCur);
1479 return CResizableStandAloneDialog::OnSetCursor(pWnd, nHitTest, message);
1482 BOOL CGitProgressDlg::PreTranslateMessage(MSG* pMsg)
1484 if (pMsg->message == WM_KEYDOWN)
1486 if (pMsg->wParam == VK_ESCAPE)
1488 // pressing the ESC key should close the dialog. But since we disabled the escape
1489 // key (so the user doesn't get the idea that he could simply undo an e.g. update)
1490 // this won't work.
1491 // So if the user presses the ESC key, change it to VK_RETURN so the dialog gets
1492 // the impression that the OK button was pressed.
1493 if ((!m_bThreadRunning)&&(!GetDlgItem(IDCANCEL)->IsWindowEnabled())
1494 &&(GetDlgItem(IDOK)->IsWindowEnabled())&&(GetDlgItem(IDOK)->IsWindowVisible()))
1496 // since we convert ESC to RETURN, make sure the OK button has the focus.
1497 GetDlgItem(IDOK)->SetFocus();
1498 pMsg->wParam = VK_RETURN;
1501 if (pMsg->wParam == 'A')
1503 if (GetKeyState(VK_CONTROL)&0x8000)
1505 // Ctrl-A -> select all
1506 m_ProgList.SetSelectionMark(0);
1507 for (int i=0; i<m_ProgList.GetItemCount(); ++i)
1509 m_ProgList.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
1513 if ((pMsg->wParam == 'C')||(pMsg->wParam == VK_INSERT))
1515 int selIndex = m_ProgList.GetSelectionMark();
1516 if (selIndex >= 0)
1518 if (GetKeyState(VK_CONTROL)&0x8000)
1520 //Ctrl-C -> copy to clipboard
1521 CString sClipdata;
1522 POSITION pos = m_ProgList.GetFirstSelectedItemPosition();
1523 if (pos != NULL)
1525 while (pos)
1527 int nItem = m_ProgList.GetNextSelectedItem(pos);
1528 CString sAction = m_ProgList.GetItemText(nItem, 0);
1529 CString sPath = m_ProgList.GetItemText(nItem, 1);
1530 CString sMime = m_ProgList.GetItemText(nItem, 2);
1531 CString sLogCopyText;
1532 sLogCopyText.Format(_T("%s: %s %s\r\n"),
1533 (LPCTSTR)sAction, (LPCTSTR)sPath, (LPCTSTR)sMime);
1534 sClipdata += sLogCopyText;
1536 CStringUtils::WriteAsciiStringToClipboard(sClipdata);
1541 } // if (pMsg->message == WM_KEYDOWN)
1542 return __super::PreTranslateMessage(pMsg);
1545 void CGitProgressDlg::OnContextMenu(CWnd* /*pWnd*/, CPoint /*point*/)
1547 #if 0
1548 if (m_options & ProgOptDryRun)
1549 return; // don't do anything in a dry-run.
1551 if (pWnd == &m_ProgList)
1553 int selIndex = m_ProgList.GetSelectionMark();
1554 if ((point.x == -1) && (point.y == -1))
1556 // Menu was invoked from the keyboard rather than by right-clicking
1557 CRect rect;
1558 m_ProgList.GetItemRect(selIndex, &rect, LVIR_LABEL);
1559 m_ProgList.ClientToScreen(&rect);
1560 point = rect.CenterPoint();
1563 if ((selIndex >= 0)&&(!m_bThreadRunning))
1565 // entry is selected, thread has finished with updating so show the popup menu
1566 CIconMenu popup;
1567 if (popup.CreatePopupMenu())
1569 bool bAdded = false;
1570 NotificationData * data = m_arData[selIndex];
1571 if ((data)&&(!data->path.IsDirectory()))
1573 if (data->action == svn_wc_notify_update_update || data->action == svn_wc_notify_resolved)
1575 if (m_ProgList.GetSelectedCount() == 1)
1577 popup.AppendMenuIcon(ID_COMPARE, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1578 bAdded = true;
1581 if (data->bConflictedActionItem)
1583 if (m_ProgList.GetSelectedCount() == 1)
1585 popup.AppendMenuIcon(ID_EDITCONFLICT, IDS_MENUCONFLICT,IDI_CONFLICT);
1586 popup.SetDefaultItem(ID_EDITCONFLICT, FALSE);
1587 popup.AppendMenuIcon(ID_CONFLICTRESOLVE, IDS_SVNPROGRESS_MENUMARKASRESOLVED,IDI_RESOLVE);
1589 popup.AppendMenuIcon(ID_CONFLICTUSETHEIRS, IDS_SVNPROGRESS_MENUUSETHEIRS,IDI_RESOLVE);
1590 popup.AppendMenuIcon(ID_CONFLICTUSEMINE, IDS_SVNPROGRESS_MENUUSEMINE,IDI_RESOLVE);
1592 else if ((data->content_state == svn_wc_notify_state_merged)||(GitProgress_Merge == m_Command)||(data->action == svn_wc_notify_resolved))
1593 popup.SetDefaultItem(ID_COMPARE, FALSE);
1595 if (m_ProgList.GetSelectedCount() == 1)
1597 if ((data->action == svn_wc_notify_add)||
1598 (data->action == svn_wc_notify_update_add)||
1599 (data->action == svn_wc_notify_commit_added)||
1600 (data->action == svn_wc_notify_commit_modified)||
1601 (data->action == svn_wc_notify_restore)||
1602 (data->action == svn_wc_notify_revert)||
1603 (data->action == svn_wc_notify_resolved)||
1604 (data->action == svn_wc_notify_commit_replaced)||
1605 (data->action == svn_wc_notify_commit_modified)||
1606 (data->action == svn_wc_notify_commit_postfix_txdelta)||
1607 (data->action == svn_wc_notify_update_update))
1609 popup.AppendMenuIcon(ID_LOG, IDS_MENULOG,IDI_LOG);
1610 if (data->action == svn_wc_notify_update_update)
1611 popup.AppendMenu(MF_SEPARATOR, NULL);
1612 popup.AppendMenuIcon(ID_OPEN, IDS_LOG_POPUP_OPEN, IDI_OPEN);
1613 popup.AppendMenuIcon(ID_OPENWITH, IDS_LOG_POPUP_OPENWITH, IDI_OPEN);
1614 bAdded = true;
1617 } // if ((data)&&(!data->path.IsDirectory()))
1618 if (m_ProgList.GetSelectedCount() == 1)
1620 if (data)
1622 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1623 if ((!sPath.IsEmpty())&&(!SVN::PathIsURL(CTGitPath(sPath))))
1625 CTGitPath path = CTGitPath(sPath);
1626 if (path.GetDirectory().Exists())
1628 popup.AppendMenuIcon(ID_EXPLORE, IDS_SVNPROGRESS_MENUOPENPARENT, IDI_EXPLORER);
1629 bAdded = true;
1634 if (m_ProgList.GetSelectedCount() > 0)
1636 if (bAdded)
1637 popup.AppendMenu(MF_SEPARATOR, NULL);
1638 popup.AppendMenuIcon(ID_COPY, IDS_LOG_POPUP_COPYTOCLIPBOARD,IDI_COPYCLIP);
1639 bAdded = true;
1641 if (bAdded)
1643 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
1644 DialogEnableWindow(IDOK, FALSE);
1645 this->SetPromptApp(&theApp);
1646 theApp.DoWaitCursor(1);
1647 bool bOpenWith = false;
1648 switch (cmd)
1650 case ID_COPY:
1652 CString sLines;
1653 POSITION pos = m_ProgList.GetFirstSelectedItemPosition();
1654 while (pos)
1656 int nItem = m_ProgList.GetNextSelectedItem(pos);
1657 NotificationData * data = m_arData[nItem];
1658 if (data)
1660 sLines += data->sPathColumnText;
1661 sLines += _T("\r\n");
1664 sLines.TrimRight();
1665 if (!sLines.IsEmpty())
1667 CStringUtils::WriteAsciiStringToClipboard(sLines, GetSafeHwnd());
1670 break;
1671 case ID_EXPLORE:
1673 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1675 CTGitPath path = CTGitPath(sPath);
1676 ShellExecute(m_hWnd, _T("explore"), path.GetDirectory().GetWinPath(), NULL, path.GetDirectory().GetWinPath(), SW_SHOW);
1678 break;
1679 case ID_COMPARE:
1681 svn_revnum_t rev = -1;
1682 StringRevMap::iterator it = m_UpdateStartRevMap.end();
1683 if (data->basepath.IsEmpty())
1684 it = m_UpdateStartRevMap.begin();
1685 else
1686 it = m_UpdateStartRevMap.find(data->basepath.GetSVNApiPath(pool));
1687 if (it != m_UpdateStartRevMap.end())
1688 rev = it->second;
1689 // if the file was merged during update, do a three way diff between OLD, MINE, THEIRS
1690 if (data->content_state == svn_wc_notify_state_merged)
1692 CTGitPath basefile = CTempFiles::Instance().GetTempFilePath(false, data->path, rev);
1693 CTGitPath newfile = CTempFiles::Instance().GetTempFilePath(false, data->path, SVNRev::REV_HEAD);
1694 SVN svn;
1695 if (!svn.Cat(data->path, SVNRev(SVNRev::REV_WC), rev, basefile))
1697 CMessageBox::Show(m_hWnd, svn.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1698 DialogEnableWindow(IDOK, TRUE);
1699 break;
1701 // If necessary, convert the line-endings on the file before diffing
1702 if ((DWORD)CRegDWORD(_T("Software\\TortoiseGit\\ConvertBase"), TRUE))
1704 CTGitPath temporaryFile = CTempFiles::Instance().GetTempFilePath(false, data->path, SVNRev::REV_BASE);
1705 if (!svn.Cat(data->path, SVNRev(SVNRev::REV_BASE), SVNRev(SVNRev::REV_BASE), temporaryFile))
1707 temporaryFile.Reset();
1708 break;
1710 else
1712 newfile = temporaryFile;
1716 SetFileAttributes(newfile.GetWinPath(), FILE_ATTRIBUTE_READONLY);
1717 SetFileAttributes(basefile.GetWinPath(), FILE_ATTRIBUTE_READONLY);
1718 CString revname, wcname, basename;
1719 revname.Format(_T("%s Revision %ld"), (LPCTSTR)data->path.GetUIFileOrDirectoryName(), rev);
1720 wcname.Format(IDS_DIFF_WCNAME, (LPCTSTR)data->path.GetUIFileOrDirectoryName());
1721 basename.Format(IDS_DIFF_BASENAME, (LPCTSTR)data->path.GetUIFileOrDirectoryName());
1722 CAppUtils::StartExtMerge(basefile, newfile, data->path, data->path, basename, revname, wcname, CString(), true);
1724 else
1726 CTGitPath tempfile = CTempFiles::Instance().GetTempFilePath(false, data->path, rev);
1727 SVN svn;
1728 if (!svn.Cat(data->path, SVNRev(SVNRev::REV_WC), rev, tempfile))
1730 CMessageBox::Show(m_hWnd, svn.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1731 DialogEnableWindow(IDOK, TRUE);
1732 break;
1734 else
1736 SetFileAttributes(tempfile.GetWinPath(), FILE_ATTRIBUTE_READONLY);
1737 CString revname, wcname;
1738 revname.Format(_T("%s Revision %ld"), (LPCTSTR)data->path.GetUIFileOrDirectoryName(), rev);
1739 wcname.Format(IDS_DIFF_WCNAME, (LPCTSTR)data->path.GetUIFileOrDirectoryName());
1740 CAppUtils::StartExtDiff(
1741 tempfile, data->path, revname, wcname,
1742 CAppUtils::DiffFlags().AlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000)));
1746 break;
1747 case ID_EDITCONFLICT:
1749 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1750 SVNDiff::StartConflictEditor(CTGitPath(sPath));
1752 break;
1753 case ID_CONFLICTUSETHEIRS:
1754 case ID_CONFLICTUSEMINE:
1755 case ID_CONFLICTRESOLVE:
1757 svn_wc_conflict_choice_t result = svn_wc_conflict_choose_merged;
1758 switch (cmd)
1760 case ID_CONFLICTUSETHEIRS:
1761 result = svn_wc_conflict_choose_theirs_full;
1762 break;
1763 case ID_CONFLICTUSEMINE:
1764 result = svn_wc_conflict_choose_mine_full;
1765 break;
1766 case ID_CONFLICTRESOLVE:
1767 result = svn_wc_conflict_choose_merged;
1768 break;
1770 SVN svn;
1771 POSITION pos = m_ProgList.GetFirstSelectedItemPosition();
1772 CString sResolvedPaths;
1773 while (pos)
1775 int nItem = m_ProgList.GetNextSelectedItem(pos);
1776 NotificationData * data = m_arData[nItem];
1777 if (data)
1779 if (data->bConflictedActionItem)
1781 if (!svn.Resolve(data->path, result, FALSE))
1783 CMessageBox::Show(m_hWnd, svn.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1784 DialogEnableWindow(IDOK, TRUE);
1785 break;
1787 else
1789 data->color = ::GetSysColor(COLOR_WINDOWTEXT);
1790 data->action = svn_wc_notify_resolved;
1791 data->sActionColumnText.LoadString(IDS_SVNACTION_RESOLVE);
1792 data->bConflictedActionItem = false;
1793 m_nConflicts--;
1795 if (m_nConflicts==0)
1797 // When the last conflict is resolved we remove
1798 // the warning which we assume is in the last line.
1799 int nIndex = m_ProgList.GetItemCount()-1;
1800 VERIFY(m_ProgList.DeleteItem(nIndex));
1802 delete m_arData[nIndex];
1803 m_arData.pop_back();
1805 sResolvedPaths += data->path.GetWinPathString() + _T("\n");
1810 m_ProgList.Invalidate();
1811 CString info = BuildInfoString();
1812 SetDlgItemText(IDC_INFOTEXT, info);
1814 if (!sResolvedPaths.IsEmpty())
1816 CString msg;
1817 msg.Format(IDS_SVNPROGRESS_RESOLVED, (LPCTSTR)sResolvedPaths);
1818 CMessageBox::Show(m_hWnd, msg, _T("TortoiseGit"), MB_OK | MB_ICONINFORMATION);
1821 break;
1822 case ID_LOG:
1824 svn_revnum_t rev = m_RevisionEnd;
1825 if (!data->basepath.IsEmpty())
1827 StringRevMap::iterator it = m_FinishedRevMap.find(data->basepath.GetSVNApiPath(pool));
1828 if (it != m_FinishedRevMap.end())
1829 rev = it->second;
1831 CLogDlg dlg;
1832 // fetch the log from HEAD, not the revision we updated to:
1833 // the path might be inside an external folder which has its own
1834 // revisions.
1835 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1836 dlg.SetParams(CTGitPath(sPath), SVNRev(), SVNRev::REV_HEAD, 1, -1, TRUE);
1837 dlg.DoModal();
1839 break;
1840 case ID_OPENWITH:
1841 bOpenWith = true;
1842 case ID_OPEN:
1844 int ret = 0;
1845 CString sWinPath = GetPathFromColumnText(data->sPathColumnText);
1846 if (!bOpenWith)
1847 ret = (int)ShellExecute(this->m_hWnd, NULL, (LPCTSTR)sWinPath, NULL, NULL, SW_SHOWNORMAL);
1848 if ((ret <= HINSTANCE_ERROR)||bOpenWith)
1850 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
1851 cmd += sWinPath + _T(" ");
1852 CAppUtils::LaunchApplication(cmd, NULL, false);
1856 DialogEnableWindow(IDOK, TRUE);
1857 theApp.DoWaitCursor(-1);
1858 } // if (bAdded)
1862 #endif
1865 void CGitProgressDlg::OnEnSetfocusInfotext()
1867 CString sTemp;
1868 GetDlgItemText(IDC_INFOTEXT, sTemp);
1869 if (sTemp.IsEmpty())
1870 GetDlgItem(IDC_INFOTEXT)->HideCaret();
1873 void CGitProgressDlg::OnLvnBegindragSvnprogress(NMHDR* , LRESULT *pResult)
1875 //LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1876 #if 0
1877 int selIndex = m_ProgList.GetSelectionMark();
1878 if (selIndex < 0)
1879 return;
1881 CDropFiles dropFiles; // class for creating DROPFILES struct
1883 int index;
1884 POSITION pos = m_ProgList.GetFirstSelectedItemPosition();
1885 while ( (index = m_ProgList.GetNextSelectedItem(pos)) >= 0 )
1887 NotificationData * data = m_arData[index];
1889 if ( data->kind==svn_node_file || data->kind==svn_node_dir )
1891 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1893 dropFiles.AddFile( sPath );
1897 if ( dropFiles.GetCount()>0 )
1899 dropFiles.CreateStructure();
1901 #endif
1902 *pResult = 0;
1905 void CGitProgressDlg::OnSize(UINT nType, int cx, int cy)
1907 CResizableStandAloneDialog::OnSize(nType, cx, cy);
1908 if ((nType == SIZE_RESTORED)&&(m_bLastVisible))
1910 if(!m_ProgList.m_hWnd)
1911 return;
1913 int count = m_ProgList.GetItemCount();
1914 if (count > 0)
1915 m_ProgList.EnsureVisible(count-1, false);
1919 //////////////////////////////////////////////////////////////////////////
1920 /// commands
1921 //////////////////////////////////////////////////////////////////////////
1922 bool CGitProgressDlg::CmdAdd(CString& sWindowTitle, bool& localoperation)
1924 localoperation = true;
1925 sWindowTitle.LoadString(IDS_PROGRS_TITLE_ADD);
1926 CAppUtils::SetWindowTitle(m_hWnd, m_targetPathList.GetCommonRoot().GetUIPathString(), sWindowTitle);
1927 SetBackgroundImage(IDI_ADD_BKG);
1928 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_ADD)));
1930 if (CRegDWORD(_T("Software\\TortoiseGit\\UseLibgit2"), TRUE) == TRUE)
1932 git_repository *repo = NULL;
1933 git_index *index;
1935 CStringA gitdir = CUnicodeUtils::GetMulti(CTGitPath(g_Git.m_CurrentDir).GetGitPathString(), CP_UTF8);
1936 if (git_repository_open(&repo, gitdir.GetBuffer()))
1938 gitdir.ReleaseBuffer();
1939 ReportGitError();
1940 return false;
1942 gitdir.ReleaseBuffer();
1944 git_config * config;
1945 git_config_new(&config);
1947 CStringA projectConfigA = CUnicodeUtils::GetMulti(g_Git.GetGitLocalConfig(), CP_UTF8);
1948 if (git_config_add_file_ondisk(config, projectConfigA.GetBuffer(), 4, FALSE))
1950 projectConfigA.ReleaseBuffer();
1951 ReportGitError();
1952 git_config_free(config);
1953 git_repository_free(repo);
1954 return false;
1956 projectConfigA.ReleaseBuffer();
1957 CString globalConfig = g_Git.GetGitGlobalConfig();
1958 if (PathFileExists(globalConfig))
1960 CStringA globalConfigA = CUnicodeUtils::GetMulti(globalConfig, CP_UTF8);
1961 if (git_config_add_file_ondisk(config, globalConfigA.GetBuffer(), 3, FALSE))
1963 globalConfigA.ReleaseBuffer();
1964 ReportGitError();
1965 git_config_free(config);
1966 git_repository_free(repo);
1967 return false;
1969 globalConfigA.ReleaseBuffer();
1971 CString globalXDGConfig = g_Git.GetGitGlobalXDGConfig();
1972 if (PathFileExists(globalXDGConfig))
1974 CStringA globalXDGConfigA = CUnicodeUtils::GetMulti(globalXDGConfig, CP_UTF8);
1975 if (git_config_add_file_ondisk(config, globalXDGConfigA.GetBuffer(), 2, FALSE))
1977 globalXDGConfigA.ReleaseBuffer();
1978 ReportGitError();
1979 git_config_free(config);
1980 git_repository_free(repo);
1981 return false;
1983 globalXDGConfigA.ReleaseBuffer();
1985 CString systemConfig = g_Git.GetGitSystemConfig();
1986 if (!systemConfig.IsEmpty())
1988 CStringA systemConfigA = CUnicodeUtils::GetMulti(systemConfig, CP_UTF8);
1989 if (git_config_add_file_ondisk(config, systemConfigA.GetBuffer(), 1, FALSE))
1991 systemConfigA.ReleaseBuffer();
1992 ReportGitError();
1993 git_config_free(config);
1994 git_repository_free(repo);
1995 return false;
1997 systemConfigA.ReleaseBuffer();
2000 git_repository_set_config(repo, config);
2002 if (git_repository_index(&index, repo))
2004 ReportGitError();
2005 git_repository_free(repo);
2006 return false;
2008 if (git_index_read(index))
2010 ReportGitError();
2011 git_index_free(index);
2012 git_repository_free(repo);
2013 return false;
2016 for (int i = 0; i < m_targetPathList.GetCount(); ++i)
2018 if (git_index_add_bypath(index, CStringA(CUnicodeUtils::GetMulti(m_targetPathList[i].GetGitPathString(), CP_UTF8)).GetBuffer()))
2020 ReportGitError();
2021 git_index_free(index);
2022 git_repository_free(repo);
2023 return false;
2025 Notify(m_targetPathList[i],git_wc_notify_add);
2028 if (git_index_write(index))
2030 ReportGitError();
2031 git_index_free(index);
2032 git_repository_free(repo);
2033 return false;
2036 git_index_free(index);
2037 git_repository_free(repo);
2039 else
2041 CMassiveGitTask mgt(L"add -f");
2042 mgt.ExecuteWithNotify(&m_targetPathList, m_bCancelled, git_wc_notify_add, this, &CGitProgressDlg::Notify);
2045 CShellUpdater::Instance().AddPathsForUpdate(m_targetPathList);
2047 this->GetDlgItem(IDC_LOGBUTTON)->SetWindowText(_T("Commit ..."));
2048 this->GetDlgItem(IDC_LOGBUTTON)->ShowWindow(SW_SHOW);
2049 return true;
2052 bool CGitProgressDlg::CmdCopy(CString& /*sWindowTitle*/, bool& /*localoperation*/)
2054 #if 0
2055 ASSERT(m_targetPathList.GetCount() == 1);
2056 sWindowTitle.LoadString(IDS_PROGRS_TITLE_COPY);
2057 SetWindowText(sWindowTitle); // needs to be updated, see TSVN rev. 21375
2058 SetBackgroundImage(IDI_COPY_BKG);
2060 CString sCmdInfo;
2061 sCmdInfo.Format(IDS_PROGRS_CMD_COPY,
2062 m_targetPathList[0].IsUrl() ? (LPCTSTR)m_targetPathList[0].GetSVNPathString() : m_targetPathList[0].GetWinPath(),
2063 (LPCTSTR)m_url.GetSVNPathString(), (LPCTSTR)m_Revision.ToString());
2064 ReportCmd(sCmdInfo);
2066 if (!Copy(m_targetPathList, m_url, m_Revision, m_pegRev, m_sMessage))
2068 ReportSVNError();
2069 return false;
2071 if (m_options & ProgOptSwitchAfterCopy)
2073 sCmdInfo.Format(IDS_PROGRS_CMD_SWITCH,
2074 m_targetPathList[0].GetWinPath(),
2075 (LPCTSTR)m_url.GetSVNPathString(), (LPCTSTR)m_Revision.ToString());
2076 ReportCmd(sCmdInfo);
2077 if (!Switch(m_targetPathList[0], m_url, SVNRev::REV_HEAD, SVNRev::REV_HEAD, m_depth, TRUE, m_options & ProgOptIgnoreExternals))
2079 if (!Switch(m_targetPathList[0], m_url, SVNRev::REV_HEAD, m_Revision, m_depth, TRUE, m_options & ProgOptIgnoreExternals))
2081 ReportSVNError();
2082 return false;
2086 else
2088 if (SVN::PathIsURL(m_url))
2090 CString sMsg(MAKEINTRESOURCE(IDS_PROGRS_COPY_WARNING));
2091 ReportNotification(sMsg);
2094 #endif
2095 return true;
2098 bool CGitProgressDlg::CmdExport(CString& /*sWindowTitle*/, bool& /*localoperation*/)
2100 #if 0
2101 ASSERT(m_targetPathList.GetCount() == 1);
2102 sWindowTitle.LoadString(IDS_PROGRS_TITLE_EXPORT);
2103 sWindowTitle = m_url.GetUIFileOrDirectoryName()+_T(" - ")+sWindowTitle;
2104 SetWindowText(sWindowTitle); // needs to be updated, see TSVN rev. 21375
2105 SetBackgroundImage(IDI_EXPORT_BKG);
2106 CString eol;
2107 if (m_options & ProgOptEolCRLF)
2108 eol = _T("CRLF");
2109 if (m_options & ProgOptEolLF)
2110 eol = _T("LF");
2111 if (m_options & ProgOptEolCR)
2112 eol = _T("CR");
2113 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_EXPORT)));
2114 if (!Export(m_url, m_targetPathList[0], m_Revision, m_Revision, TRUE, m_options & ProgOptIgnoreExternals, m_depth, NULL, FALSE, eol))
2116 ReportSVNError();
2117 return false;
2119 #endif
2120 return true;
2123 bool CGitProgressDlg::CmdRename(CString& /*sWindowTitle*/, bool& /*localoperation*/)
2125 #if 0
2126 ASSERT(m_targetPathList.GetCount() == 1);
2127 if ((!m_targetPathList[0].IsUrl())&&(!m_url.IsUrl()))
2128 localoperation = true;
2129 sWindowTitle.LoadString(IDS_PROGRS_TITLE_RENAME);
2130 SetWindowText(sWindowTitle); // needs to be updated, see TSVN rev. 21375
2131 SetBackgroundImage(IDI_RENAME_BKG);
2132 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RENAME)));
2133 if (!Move(m_targetPathList, m_url, m_Revision, m_sMessage))
2135 ReportSVNError();
2136 return false;
2138 #endif
2139 return true;
2142 bool CGitProgressDlg::CmdResolve(CString& sWindowTitle, bool& localoperation)
2145 localoperation = true;
2146 ASSERT(m_targetPathList.GetCount() == 1);
2147 sWindowTitle.LoadString(IDS_PROGRS_TITLE_RESOLVE);
2148 CAppUtils::SetWindowTitle(m_hWnd, m_targetPathList.GetCommonRoot().GetUIPathString(), sWindowTitle);
2149 SetBackgroundImage(IDI_RESOLVE_BKG);
2150 // check if the file may still have conflict markers in it.
2151 //BOOL bMarkers = FALSE;
2153 for (int i = 0; i < m_targetPathList.GetCount(); ++i)
2155 CString cmd,out,tempmergefile;
2156 cmd.Format(_T("git.exe add -f -- \"%s\""),m_targetPathList[i].GetGitPathString());
2157 if (g_Git.Run(cmd, &out, CP_UTF8))
2159 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
2160 m_bErrorsOccurred=true;
2161 return false;
2164 CAppUtils::RemoveTempMergeFile((CTGitPath &)m_targetPathList[i]);
2166 Notify(m_targetPathList[i],git_wc_notify_resolved);
2168 #if 0
2169 if ((m_options & ProgOptSkipConflictCheck) == 0)
2173 for (INT_PTR fileindex=0; (fileindex<m_targetPathList.GetCount()) && (bMarkers==FALSE); ++fileindex)
2175 if (!m_targetPathList[fileindex].IsDirectory())
2177 CStdioFile file(m_targetPathList[fileindex].GetWinPath(), CFile::typeBinary | CFile::modeRead);
2178 CString strLine = _T("");
2179 while (file.ReadString(strLine))
2181 if (strLine.Find(_T("<<<<<<<"))==0)
2183 bMarkers = TRUE;
2184 break;
2187 file.Close();
2191 catch (CFileException* pE)
2193 TRACE(_T("CFileException in Resolve!\n"));
2194 TCHAR error[10000] = {0};
2195 pE->GetErrorMessage(error, 10000);
2196 ReportError(error);
2197 pE->Delete();
2198 return false;
2201 if (bMarkers)
2203 if (CMessageBox::Show(m_hWnd, IDS_PROGRS_REVERTMARKERS, IDS_APPNAME, MB_YESNO | MB_ICONQUESTION)==IDYES)
2205 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RESOLVE)));
2206 for (INT_PTR fileindex=0; fileindex<m_targetPathList.GetCount(); ++fileindex)
2207 Resolve(m_targetPathList[fileindex], svn_wc_conflict_choose_merged, true);
2210 else
2212 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RESOLVE)));
2213 for (INT_PTR fileindex=0; fileindex<m_targetPathList.GetCount(); ++fileindex)
2214 Resolve(m_targetPathList[fileindex], svn_wc_conflict_choose_merged, true);
2216 #endif
2217 CShellUpdater::Instance().AddPathsForUpdate(m_targetPathList);
2219 this->GetDlgItem(IDC_LOGBUTTON)->SetWindowText(CString(MAKEINTRESOURCE(IDS_COMMITBUTTON)));
2220 this->GetDlgItem(IDC_LOGBUTTON)->ShowWindow(SW_SHOW);
2222 return true;
2225 bool CGitProgressDlg::CmdRevert(CString& sWindowTitle, bool& localoperation)
2228 localoperation = true;
2229 sWindowTitle.LoadString(IDS_PROGRS_TITLE_REVERT);
2230 CAppUtils::SetWindowTitle(m_hWnd, m_targetPathList.GetCommonRoot().GetUIPathString(), sWindowTitle);
2231 SetBackgroundImage(IDI_REVERT_BKG);
2233 CTGitPathList delList;
2234 for (int i = 0; i < m_selectedPaths.GetCount(); ++i)
2236 CTGitPath path;
2237 int action;
2238 path.SetFromWin(g_Git.m_CurrentDir+_T("\\")+m_selectedPaths[i].GetWinPath());
2239 action = m_selectedPaths[i].m_Action;
2240 /* rename file can't delete because it needs original file*/
2241 if((!(action & CTGitPath::LOGACTIONS_ADDED)) &&
2242 (!(action & CTGitPath::LOGACTIONS_REPLACED)))
2243 delList.AddPath(path);
2245 if (DWORD(CRegDWORD(_T("Software\\TortoiseGit\\RevertWithRecycleBin"), TRUE)))
2246 delList.DeleteAllFiles(true);
2248 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_REVERT)));
2249 for (int i = 0; i < m_selectedPaths.GetCount(); ++i)
2251 if(g_Git.Revert(_T("HEAD"), (CTGitPath&)m_selectedPaths[i]))
2253 CMessageBox::Show(NULL,_T("Revert Fail"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
2254 m_bErrorsOccurred=true;
2255 return false;
2257 Notify(m_selectedPaths[i],git_wc_notify_revert);
2260 CShellUpdater::Instance().AddPathsForUpdate(m_selectedPaths);
2262 return true;
2265 bool CGitProgressDlg::CmdSwitch(CString& /*sWindowTitle*/, bool& /*localoperation*/)
2267 #if 0
2268 ASSERT(m_targetPathList.GetCount() == 1);
2269 SVNStatus st;
2270 sWindowTitle.LoadString(IDS_PROGRS_TITLE_SWITCH);
2271 SetWindowText(sWindowTitle); // needs to be updated, see TSVN rev. 21375
2272 SetBackgroundImage(IDI_SWITCH_BKG);
2273 LONG rev = 0;
2274 if (st.GetStatus(m_targetPathList[0]) != (-2))
2276 if (st.status->entry != NULL)
2278 rev = st.status->entry->revision;
2282 CString sCmdInfo;
2283 sCmdInfo.Format(IDS_PROGRS_CMD_SWITCH,
2284 m_targetPathList[0].GetWinPath(), (LPCTSTR)m_url.GetSVNPathString(),
2285 (LPCTSTR)m_Revision.ToString());
2286 ReportCmd(sCmdInfo);
2288 bool depthIsSticky = true;
2289 if (m_depth == svn_depth_unknown)
2290 depthIsSticky = false;
2291 if (!Switch(m_targetPathList[0], m_url, m_Revision, m_Revision, m_depth, depthIsSticky, m_options & ProgOptIgnoreExternals))
2293 ReportSVNError();
2294 return false;
2296 m_UpdateStartRevMap[m_targetPathList[0].GetSVNApiPath(pool)] = rev;
2297 if ((m_RevisionEnd >= 0)&&(rev >= 0)
2298 &&((LONG)m_RevisionEnd > (LONG)rev))
2300 GetDlgItem(IDC_LOGBUTTON)->ShowWindow(SW_SHOW);
2302 #endif
2303 return true;
2305 bool CGitProgressDlg::CmdClone(CString& sWindowTitle, bool& /*localoperation*/)
2307 if (!g_Git.UsingLibGit2(CGit::GIT_CMD_CLONE))
2309 // should never run to here
2310 ASSERT(FALSE);
2311 return false;
2313 this->m_TotalBytesTransferred = 0;
2315 sWindowTitle.LoadString(IDS_PROGRS_TITLE_CLONE);
2316 CAppUtils::SetWindowTitle(m_hWnd, m_url.GetGitPathString(), sWindowTitle);
2317 SetBackgroundImage(IDI_SWITCH_BKG);
2318 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROG_CLONE)));
2320 if (m_url.IsEmpty() || m_targetPathList.GetCount() == 0)
2321 return false;
2323 CStringA url = CUnicodeUtils::GetMulti(m_url.GetGitPathString(), CP_UTF8);
2324 CStringA path = CUnicodeUtils::GetMulti(m_targetPathList[0].GetWinPathString(),CP_UTF8);
2326 git_repository *cloned_repo = NULL;
2327 git_remote *origin = NULL;
2328 git_checkout_opts checkout_opts = GIT_CHECKOUT_OPTS_INIT;
2330 int error = 0;
2332 git_clone_options clone_opts = GIT_CLONE_OPTIONS_INIT;
2334 clone_opts.checkout_opts = checkout_opts;
2336 clone_opts.checkout_opts.checkout_strategy = m_bNoCheckout? GIT_CHECKOUT_NONE : GIT_CHECKOUT_SAFE_CREATE;
2337 clone_opts.checkout_opts.progress_cb = CheckoutCallback;
2338 clone_opts.checkout_opts.progress_payload = this;
2340 if (!m_RefSpec.IsEmpty())
2341 clone_opts.checkout_branch = CUnicodeUtils::GetMulti(m_RefSpec, CP_UTF8).GetBuffer();
2343 clone_opts.fetch_progress_cb = FetchCallback;
2344 clone_opts.fetch_progress_payload = this;
2346 clone_opts.cred_acquire_cb = CAppUtils::Git2GetUserPassword;
2348 clone_opts.bare = m_bBare;
2350 m_Animate.ShowWindow(SW_SHOW);
2351 m_Animate.Play(0, INT_MAX, INT_MAX);
2352 error = git_clone(&cloned_repo, url, path, &clone_opts);
2353 m_Animate.Stop();
2354 m_Animate.ShowWindow(SW_HIDE);
2356 git_remote_free(origin);
2357 if (error)
2359 ReportGitError();
2360 return false;
2362 else if (cloned_repo)
2363 git_repository_free(cloned_repo);
2364 return true;
2367 void CGitProgressDlg::OnBnClickedNoninteractive()
2369 LRESULT res = ::SendMessage(GetDlgItem(IDC_NONINTERACTIVE)->GetSafeHwnd(), BM_GETCHECK, 0, 0);
2370 m_AlwaysConflicted = (res == BST_CHECKED);
2371 CRegDWORD nonint = CRegDWORD(_T("Software\\TortoiseGit\\MergeNonInteractive"), FALSE);
2372 nonint = m_AlwaysConflicted;
2375 CString CGitProgressDlg::GetPathFromColumnText(const CString& sColumnText)
2377 CString sPath = CPathUtils::ParsePathInString(sColumnText);
2378 if (sPath.Find(':')<0)
2380 // the path is not absolute: add the common root of all paths to it
2381 sPath = m_targetPathList.GetCommonRoot().GetDirectory().GetWinPathString() + _T("\\") + CPathUtils::ParsePathInString(sColumnText);
2383 return sPath;
2386 bool CGitProgressDlg::CmdSendMail(CString& sWindowTitle, bool& /*localoperation*/)
2388 sWindowTitle.LoadString(IDS_PROGRS_TITLE_SENDMAIL);
2389 CAppUtils::SetWindowTitle(m_hWnd, m_targetPathList.GetCommonRoot().GetUIPathString(), sWindowTitle);
2390 //SetBackgroundImage(IDI_ADD_BKG);
2391 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_SENDMAIL)));
2392 bool ret=true;
2393 if(this->m_SendMailFlags&SENDMAIL_COMBINED)
2395 CString error;
2396 CTGitPath path;
2397 Notify(path,git_wc_notify_sendmail_start);
2398 CString err;
2399 int retry=0;
2400 while(retry <3)
2402 if(!!CPatch::SendPatchesCombined(m_targetPathList,m_SendMailTO,m_SendMailCC,m_SendMailSubject,!!(this->m_SendMailFlags&SENDMAIL_ATTACHMENT),!!(this->m_SendMailFlags&SENDMAIL_MAPI),&err))
2404 Notify(path,git_wc_notify_sendmail_error,ret,&err);
2405 ret = false;
2407 else
2409 break;
2412 ++retry;
2413 if (retry < 3)
2414 Notify(path,git_wc_notify_sendmail_retry,ret,&err);
2415 Sleep(2000);
2416 if(m_bCancelled)
2418 CString str;
2419 str.LoadString(IDS_SVN_USERCANCELLED);
2420 Notify(path,git_wc_notify_sendmail_error,ret,&str);
2421 return false;
2424 if (ret)
2425 Notify(path,git_wc_notify_sendmail_done,ret);
2427 else
2429 for (int i = 0; ret && i < m_targetPathList.GetCount(); ++i)
2431 CPatch patch;
2432 Notify(m_targetPathList[i],git_wc_notify_sendmail_start);
2434 int retry=0;
2435 while(retry<3)
2437 if(!!patch.Send((CString&)m_targetPathList[i].GetWinPathString(),this->m_SendMailTO,
2438 this->m_SendMailCC,!!(this->m_SendMailFlags&SENDMAIL_ATTACHMENT),!!(this->m_SendMailFlags&SENDMAIL_MAPI)))
2440 Notify(m_targetPathList[i],git_wc_notify_sendmail_error,ret,&patch.m_LastError);
2441 ret = false;
2444 else
2446 ret = true;
2447 break;
2449 ++retry;
2450 if (retry < 3)
2451 Notify(m_targetPathList[i],git_wc_notify_sendmail_retry,ret,&patch.m_LastError);
2452 Sleep(2000);
2453 if(m_bCancelled)
2455 CString str;
2456 str.LoadString(IDS_SVN_USERCANCELLED);
2457 Notify(m_targetPathList[i],git_wc_notify_sendmail_error,ret,&str);
2458 return false;
2461 if (ret)
2462 Notify(m_targetPathList[i],git_wc_notify_sendmail_done,ret);
2465 return ret;
2468 LRESULT CGitProgressDlg::OnTaskbarBtnCreated(WPARAM /*wParam*/, LPARAM /*lParam*/)
2470 m_pTaskbarList.Release();
2471 m_pTaskbarList.CoCreateInstance(CLSID_TaskbarList);
2472 return 0;
2475 HBRUSH CGitProgressDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
2477 HBRUSH hbr;
2478 if (pWnd->GetDlgCtrlID() == IDC_TITLE_ANIMATE)
2480 pDC->SetBkColor(GetSysColor(COLOR_WINDOW)); // add this
2481 pDC->SetBkMode(TRANSPARENT);
2482 return (HBRUSH)m_background_brush.GetSafeHandle();
2484 else
2485 hbr = CResizableStandAloneDialog::OnCtlColor(pDC, pWnd, nCtlColor);
2487 // TODO: Return a different brush if the default is not desired
2488 return hbr;
2490 LRESULT CGitProgressDlg::OnCtlColorStatic(WPARAM wParam, LPARAM lParam)
2492 HDC hDC = (HDC)wParam;
2493 HWND hwndCtl = (HWND)lParam;
2495 if (::GetDlgCtrlID(hwndCtl) == IDC_TITLE_ANIMATE)
2497 CDC *pDC = CDC::FromHandle(hDC);
2498 pDC->SetBkColor(GetSysColor(COLOR_WINDOW));
2499 pDC->SetBkMode(TRANSPARENT);
2500 return (LRESULT)(HBRUSH)m_background_brush.GetSafeHandle();
2502 return FALSE;