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.
21 #include "TortoiseProc.h"
22 #include "messagebox.h"
23 #include "GITProgressDlg.h"
27 #include "GitStatus.h"
29 #include "PathUtils.h"
30 #include "StringUtils.h"
32 #include "UnicodeUtils.h"
33 #include "SoundUtils.h"
36 #include "DropFiles.h"
37 //#include "GitLogHelper.h"
38 #include "RegHistory.h"
39 //#include "ConflictResolveDlg.h"
41 #include "ShellUpdater.h"
43 #include "BugTraqAssociations.h"
45 #include "MassiveGitTask.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
72 IMPLEMENT_DYNAMIC(CGitProgressDlg
, CResizableStandAloneDialog
)
73 CGitProgressDlg::CGitProgressDlg(CWnd
* pParent
/*=NULL*/)
74 : CResizableStandAloneDialog(CGitProgressDlg::IDD
, pParent
)
77 , m_bErrorsOccurred(false)
79 , m_bNoCheckout(false)
81 , m_Revision(_T("HEAD"))
83 , m_bLockWarning(false)
84 , m_bLockExists(false)
85 , m_bThreadRunning(FALSE
)
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)
95 , m_itemCountTotal(-1)
96 , m_AlwaysConflicted(false)
97 , m_BugTraqProvider(NULL
)
98 , sDryRun(MAKEINTRESOURCE(IDS_PROGRS_DRYRUN
))
99 , sRecordOnly(MAKEINTRESOURCE(IDS_MERGE_RECORDONLY
))
104 CGitProgressDlg::~CGitProgressDlg()
106 for (size_t i
= 0; i
< m_arData
.size(); ++i
)
110 if(m_pThread
!= NULL
)
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
)
127 ON_NOTIFY(NM_DBLCLK
, IDC_SVNPROGRESS
, OnNMDblclkSvnprogress
)
128 ON_NOTIFY(HDN_ITEMCLICK
, 0, OnHdnItemclickSvnprogress
)
131 ON_REGISTERED_MESSAGE(WM_GITPROGRESS
, OnGitProgress
)
133 ON_EN_SETFOCUS(IDC_INFOTEXT
, &CGitProgressDlg::OnEnSetfocusInfotext
)
134 ON_NOTIFY(LVN_BEGINDRAG
, IDC_SVNPROGRESS
, &CGitProgressDlg::OnLvnBegindragSvnprogress
)
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
)
143 BOOL
CGitProgressDlg::Cancel()
148 LRESULT
CGitProgressDlg::OnShowConflictResolver(WPARAM
/*wParam*/, LPARAM
/*lParam*/)
151 CConflictResolveDlg
dlg(this);
152 const svn_wc_conflict_description_t
*description
= (svn_wc_conflict_description_t
*)lParam
;
155 dlg
.SetConflictDescription(description
);
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();
173 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_INDETERMINATE
);
174 return dlg
.GetResult();
177 return svn_wc_conflict_choose_postpone
;
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
;
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.
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;
224 nEnsureVisibleCount
= 0;
226 m_bLastVisible
= false;
231 BOOL
CGitProgressDlg::Notify(const CTGitPath
& path
, git_wc_notify_action_t action
,
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();
248 data
->action
= action
;
249 data
->sPathColumnText
=path
.GetGitPathString();
250 data
->bAuxItem
= false;
252 this->m_Animate
.ShowWindow(SW_HIDE
);
256 data
->mime_type
= mime_type
;
257 data
->content_state
= content_state
;
258 data
->prop_state
= prop_state
;
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
;
268 data
->merge_range
= *range
;
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))
276 // data->color = m_Colors.GetColor(CColors::Conflict);
277 // data->bConflictedActionItem = true;
278 // data->sActionColumnText.LoadString(IDS_SVNACTION_CONFLICTED);
283 // m_bMergesAddsDeletesOccurred = true;
284 data
->sActionColumnText
.LoadString(IDS_SVNACTION_ADD
);
285 data
->color
= m_Colors
.GetColor(CColors::Added
);
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
);
294 case git_wc_notify_sendmail_error
:
295 data
->bAuxItem
= true;
296 data
->sActionColumnText
.LoadString(IDS_SVNACTION_SENDMAIL_ERROR
);
298 data
->sPathColumnText
= *strErr
;
300 data
->sPathColumnText
.Empty();
301 data
->color
= m_Colors
.GetColor(CColors::Modified
);
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
);
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
);
318 case git_wc_notify_resolved
:
319 data
->sActionColumnText
.LoadString(IDS_SVNACTION_RESOLVE
);
322 case git_wc_notify_revert
:
323 data
->sActionColumnText
.LoadString(IDS_SVNACTION_REVERT
);
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;
333 case svn_wc_notify_commit_added
:
334 data
->sActionColumnText
.LoadString(IDS_SVNACTION_ADDING
);
335 data
->color
= m_Colors
.GetColor(CColors::Added
);
337 case svn_wc_notify_copy
:
338 data
->sActionColumnText
.LoadString(IDS_SVNACTION_COPY
);
340 case svn_wc_notify_commit_modified
:
341 data
->sActionColumnText
.LoadString(IDS_SVNACTION_MODIFIED
);
342 data
->color
= m_Colors
.GetColor(CColors::Modified
);
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
);
350 case svn_wc_notify_commit_deleted
:
351 data
->sActionColumnText
.LoadString(IDS_SVNACTION_DELETING
);
352 data
->color
= m_Colors
.GetColor(CColors::Deleted
);
354 case svn_wc_notify_restore
:
355 data
->sActionColumnText
.LoadString(IDS_SVNACTION_RESTORE
);
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
);
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;
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
);
378 data
->sActionColumnText
.LoadString(IDS_SVNACTION_EXISTS
);
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
)))
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;
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
);
415 if (lock_state
== svn_wc_notify_lock_state_unlocked
)
417 CString
temp(MAKEINTRESOURCE(IDS_SVNACTION_UNLOCKED
));
418 data
->sActionColumnText
+= _T(", ") + temp
;
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;
429 case svn_wc_notify_update_completed
:
431 data
->sActionColumnText
.LoadString(IDS_SVNACTION_COMPLETED
);
432 data
->bAuxItem
= true;
433 bool bEmpty
= !!m_ExtStack
.IsEmpty();
435 data
->sPathColumnText
.Format(IDS_PROGRS_PATHATREV
, (LPCTSTR
)m_ExtStack
.RemoveHead(), rev
);
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
);
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
;
457 m_bFinishedItemAdded
= true;
460 case svn_wc_notify_commit_postfix_txdelta
:
461 data
->sActionColumnText
.LoadString(IDS_SVNACTION_POSTFIX
);
463 case svn_wc_notify_failed_revert
:
464 data
->sActionColumnText
.LoadString(IDS_SVNACTION_FAILEDREVERT
);
466 case svn_wc_notify_status_completed
:
467 case svn_wc_notify_status_external
:
468 data
->sActionColumnText
.LoadString(IDS_SVNACTION_STATUS
);
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
);
481 data
->sActionColumnText
.LoadString(IDS_SVNACTION_SKIP
);
483 case svn_wc_notify_locked
:
484 if ((lock
)&&(lock
->owner
))
485 data
->sActionColumnText
.Format(IDS_SVNACTION_LOCKEDBY
, (LPCTSTR
)CUnicodeUtils::GetUnicode(lock
->owner
));
487 case svn_wc_notify_unlocked
:
488 data
->sActionColumnText
.LoadString(IDS_SVNACTION_UNLOCKED
);
490 case svn_wc_notify_failed_lock
:
491 data
->sActionColumnText
.LoadString(IDS_SVNACTION_FAILEDLOCK
);
492 m_arData
.push_back(data
);
494 ReportError(SVN::GetErrorString(err
));
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;
501 case svn_wc_notify_failed_unlock
:
502 data
->sActionColumnText
.LoadString(IDS_SVNACTION_FAILEDUNLOCK
);
503 m_arData
.push_back(data
);
505 ReportError(SVN::GetErrorString(err
));
507 if (err
->apr_err
== SVN_ERR_FS_OUT_OF_DATE
)
508 m_bLockWarning
= true;
510 case svn_wc_notify_changelist_set
:
511 data
->sActionColumnText
.Format(IDS_SVNACTION_CHANGELISTSET
, (LPCTSTR
)data
->changelistname
);
513 case svn_wc_notify_changelist_clear
:
514 data
->sActionColumnText
.LoadString(IDS_SVNACTION_CHANGELISTCLEAR
);
516 case svn_wc_notify_changelist_moved
:
517 data
->sActionColumnText
.Format(IDS_SVNACTION_CHANGELISTMOVED
, (LPCTSTR
)data
->changelistname
);
519 case svn_wc_notify_foreign_merge_begin
:
520 case svn_wc_notify_merge_begin
:
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
);
530 data
->sActionColumnText
.Format(IDS_SVNACTION_MERGEBEGINMULTIPLEREVERSE
, data
->merge_range
.start
, data
->merge_range
.end
+ 1);
531 data
->bAuxItem
= true;
536 } // switch (data->action)
544 m_arData
.push_back(data
);
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
);
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))
563 // bSecondResized = TRUE;
571 CString
CGitProgressDlg::BuildInfoString()
574 if(this->m_Command
== GitProgress_Resolve
)
575 infotext
= _T("You need commit your change after resolve conflict");
592 for (size_t i
=0; i
<m_arData
.size(); ++i
)
594 const NotificationData
* dat
= m_arData
[i
];
597 case svn_wc_notify_add
:
598 case svn_wc_notify_update_add
:
599 case svn_wc_notify_commit_added
:
600 if (dat
->bConflictedActionItem
)
605 case svn_wc_notify_copy
:
608 case svn_wc_notify_delete
:
609 case svn_wc_notify_update_delete
:
610 case svn_wc_notify_commit_deleted
:
613 case svn_wc_notify_restore
:
616 case svn_wc_notify_revert
:
619 case svn_wc_notify_resolved
:
622 case svn_wc_notify_update_update
:
623 if (dat
->bConflictedActionItem
)
625 else if ((dat
->content_state
== svn_wc_notify_state_merged
) || (dat
->prop_state
== svn_wc_notify_state_merged
))
630 case svn_wc_notify_commit_modified
:
633 case svn_wc_notify_skip
:
636 case svn_wc_notify_commit_replaced
:
643 temp
.LoadString(IDS_SVNACTION_CONFLICTED
);
645 temp
.Format(_T(":%d "), conflicted
);
650 temp
.LoadString(IDS_SVNACTION_SKIP
);
652 infotext
.AppendFormat(_T(":%d "), skipped
);
656 temp
.LoadString(IDS_SVNACTION_MERGED
);
658 infotext
.AppendFormat(_T(":%d "), merged
);
662 temp
.LoadString(IDS_SVNACTION_ADD
);
664 infotext
.AppendFormat(_T(":%d "), added
);
668 temp
.LoadString(IDS_SVNACTION_DELETE
);
670 infotext
.AppendFormat(_T(":%d "), deleted
);
674 temp
.LoadString(IDS_SVNACTION_MODIFIED
);
676 infotext
.AppendFormat(_T(":%d "), modified
);
680 temp
.LoadString(IDS_SVNACTION_COPY
);
682 infotext
.AppendFormat(_T(":%d "), copied
);
686 temp
.LoadString(IDS_SVNACTION_REPLACED
);
688 infotext
.AppendFormat(_T(":%d "), replaced
);
692 temp
.LoadString(IDS_SVNACTION_UPDATE
);
694 infotext
.AppendFormat(_T(":%d "), updated
);
698 temp
.LoadString(IDS_SVNACTION_RESTORE
);
700 infotext
.AppendFormat(_T(":%d "), restored
);
704 temp
.LoadString(IDS_SVNACTION_REVERT
);
706 infotext
.AppendFormat(_T(":%d "), reverted
);
710 temp
.LoadString(IDS_SVNACTION_RESOLVE
);
712 infotext
.AppendFormat(_T(":%d "), resolved
);
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();
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
748 linewidth
= m_ProgList
.GetStringWidth(m_arData
[index
]->sActionColumnText
) + 12;
751 linewidth
= m_ProgList
.GetStringWidth(m_arData
[index
]->sPathColumnText
) + 12;
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"));
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;
791 m_ProgList
.DeleteColumn(c
--);
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
);
801 ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED
)));
805 m_pThread
->m_bAutoDelete
= FALSE
;
806 m_pThread
->ResumeThread();
811 // Call this early so that the column headings aren't hidden before any
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
);
831 CenterWindow(CWnd::FromHandle(hWndExplorer
));
832 EnableSaveRestore(_T("GITProgressDlg"));
834 m_background_brush
.CreateSolidBrush(GetSysColor(COLOR_WINDOW
));
838 bool CGitProgressDlg::SetBackgroundImage(UINT nID
)
840 return CAppUtils::SetListCtrlBackgroundImage(m_ProgList
.GetSafeHwnd(), nID
);
843 void CGitProgressDlg::ReportGitError()
845 const git_error
*err
= giterr_last();
847 ReportError(_T("An error occoured in libgit2, but no message is available."));
849 ReportError(CUnicodeUtils::GetUnicode(giterr_last()->message
));
852 void CGitProgressDlg::ReportError(const CString
& sError
)
854 CSoundUtils::PlayTGitError();
855 ReportString(sError
, CString(MAKEINTRESOURCE(IDS_ERR_ERROR
)), m_Colors
.GetColor(CColors::Conflict
));
856 m_bErrorsOccurred
= true;
859 void CGitProgressDlg::ReportWarning(const CString
& sWarning
)
861 CSoundUtils::PlayTGitWarning();
862 ReportString(sWarning
, CString(MAKEINTRESOURCE(IDS_WARN_WARNING
)), m_Colors
.GetColor(CColors::Conflict
));
865 void CGitProgressDlg::ReportNotification(const CString
& sNotification
)
867 CSoundUtils::PlayTGitNotification();
868 ReportString(sNotification
, CString(MAKEINTRESOURCE(IDS_WARN_NOTE
)));
871 void CGitProgressDlg::ReportCmd(const CString
& sCmd
)
873 ReportString(sCmd
, CString(MAKEINTRESOURCE(IDS_PROGRS_CMDINFO
)), m_Colors
.GetColor(CColors::Cmd
));
876 void CGitProgressDlg::ReportString(CString sMessage
, const CString
& sMsgKind
, COLORREF color
)
878 // instead of showing a dialog box with the error message or notification,
879 // just insert the error text into the list control.
880 // that way the user isn't 'interrupted' by a dialog box popping up!
882 // the message may be split up into different lines
883 // so add a new entry for each line of the message
884 while (!sMessage
.IsEmpty())
886 NotificationData
* data
= new NotificationData();
887 data
->bAuxItem
= true;
888 data
->sActionColumnText
= sMsgKind
;
889 if (sMessage
.Find('\n')>=0)
890 data
->sPathColumnText
= sMessage
.Left(sMessage
.Find('\n'));
892 data
->sPathColumnText
= sMessage
;
893 data
->sPathColumnText
.Trim(_T("\n\r"));
895 if (sMessage
.Find('\n')>=0)
897 sMessage
= sMessage
.Mid(sMessage
.Find('\n'));
898 sMessage
.Trim(_T("\n\r"));
902 m_arData
.push_back(data
);
907 UINT
CGitProgressDlg::ProgressThreadEntry(LPVOID pVoid
)
909 return ((CGitProgressDlg
*)pVoid
)->ProgressThread();
912 UINT
CGitProgressDlg::ProgressThread()
914 // The SetParams function should have loaded something for us
917 CString sWindowTitle
;
918 bool localoperation
= false;
919 bool bSuccess
= false;
920 m_AlwaysConflicted
= false;
922 DialogEnableWindow(IDOK
, FALSE
);
923 DialogEnableWindow(IDCANCEL
, TRUE
);
924 // SetAndClearProgressInfo(m_hWnd);
925 m_itemCount
= m_itemCountTotal
;
927 InterlockedExchange(&m_bThreadRunning
, TRUE
);
929 bSecondResized
= FALSE
;
930 m_bFinishedItemAdded
= false;
931 CTime startTime
= CTime::GetCurrentTime();
934 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_INDETERMINATE
);
938 case GitProgress_Add
:
939 bSuccess
= CmdAdd(sWindowTitle
, localoperation
);
941 case GitProgress_Copy
:
942 bSuccess
= CmdCopy(sWindowTitle
, localoperation
);
944 case GitProgress_Export
:
945 bSuccess
= CmdExport(sWindowTitle
, localoperation
);
947 case GitProgress_Rename
:
948 bSuccess
= CmdRename(sWindowTitle
, localoperation
);
950 case GitProgress_Resolve
:
951 bSuccess
= CmdResolve(sWindowTitle
, localoperation
);
953 case GitProgress_Revert
:
954 bSuccess
= CmdRevert(sWindowTitle
, localoperation
);
956 case GitProgress_Switch
:
957 bSuccess
= CmdSwitch(sWindowTitle
, localoperation
);
959 case GitProgress_SendMail
:
960 bSuccess
= CmdSendMail(sWindowTitle
, localoperation
);
962 case GitProgress_Clone
:
963 bSuccess
= CmdClone(sWindowTitle
, localoperation
);
967 temp
.LoadString(IDS_PROGRS_TITLEFAILED
);
969 temp
.LoadString(IDS_PROGRS_TITLEFIN
);
970 sWindowTitle
= sWindowTitle
+ _T(" ") + temp
;
971 SetWindowText(sWindowTitle
);
973 KillTimer(TRANSFERTIMER
);
974 KillTimer(VISIBLETIMER
);
978 if (DidErrorsOccur())
980 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_ERROR
);
981 m_pTaskbarList
->SetProgressValue(m_hWnd
, 100, 100);
984 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_NOPROGRESS
);
987 DialogEnableWindow(IDCANCEL
, FALSE
);
988 DialogEnableWindow(IDOK
, TRUE
);
990 CString info
= BuildInfoString();
992 info
.LoadString(IDS_PROGRS_INFOFAILED
);
993 SetDlgItemText(IDC_INFOTEXT
, info
);
995 CWnd
* pWndOk
= GetDlgItem(IDOK
);
996 if (pWndOk
&& ::IsWindow(pWndOk
->GetSafeHwnd()))
998 SendMessage(DM_SETDEFID
, IDOK
);
999 GetDlgItem(IDOK
)->SetFocus();
1003 if (!m_sTotalBytesTransferred
.IsEmpty())
1005 CTimeSpan time
= CTime::GetCurrentTime() - startTime
;
1006 temp
.Format(IDS_PROGRS_TIME
, (LONG
)time
.GetTotalMinutes(), (LONG
)time
.GetSeconds());
1007 sFinalInfo
.Format(IDS_PROGRS_FINALINFO
, m_sTotalBytesTransferred
, (LPCTSTR
)temp
);
1008 SetDlgItemText(IDC_PROGRESSLABEL
, sFinalInfo
);
1011 GetDlgItem(IDC_PROGRESSLABEL
)->ShowWindow(SW_HIDE
);
1013 GetDlgItem(IDC_PROGRESSBAR
)->ShowWindow(SW_HIDE
);
1015 if (!m_bFinishedItemAdded
)
1017 // there's no "finished: xxx" line at the end. We add one here to make
1018 // sure the user sees that the command is actually finished.
1019 NotificationData
* data
= new NotificationData();
1020 data
->bAuxItem
= true;
1021 data
->sActionColumnText
.LoadString(IDS_PROGRS_FINISHED
);
1022 m_arData
.push_back(data
);
1026 int count
= m_ProgList
.GetItemCount();
1027 if ((count
> 0)&&(m_bLastVisible
))
1028 m_ProgList
.EnsureVisible(count
-1, FALSE
);
1033 logfile
.AddTimeLine();
1034 for (size_t i
= 0; i
< m_arData
.size(); ++i
)
1036 NotificationData
* data
= m_arData
[i
];
1037 temp
.Format(_T("%-20s : %s"), (LPCTSTR
)data
->sActionColumnText
, (LPCTSTR
)data
->sPathColumnText
);
1038 logfile
.AddLine(temp
);
1040 if (!sFinalInfo
.IsEmpty())
1041 logfile
.AddLine(sFinalInfo
);
1045 m_bCancelled
= TRUE
;
1046 InterlockedExchange(&m_bThreadRunning
, FALSE
);
1050 DWORD dwAutoClose
= CRegStdDWORD(_T("Software\\TortoiseGit\\AutoClose"), CLOSE_MANUAL
);
1051 if (m_options
& ProgOptDryRun
)
1052 dwAutoClose
= 0; // dry run means progress dialog doesn't auto close at all
1053 if (!m_bLastVisible
)
1055 if (m_dwCloseOnEnd
!= (DWORD
)-1)
1056 dwAutoClose
= m_dwCloseOnEnd
; // command line value has priority over setting value
1057 if ((dwAutoClose
== CLOSE_NOERRORS
)&&(!m_bErrorsOccurred
))
1058 PostMessage(WM_COMMAND
, 1, (LPARAM
)GetDlgItem(IDOK
)->m_hWnd
);
1059 if ((dwAutoClose
== CLOSE_NOCONFLICTS
)&&(!m_bErrorsOccurred
)&&(m_nConflicts
==0))
1060 PostMessage(WM_COMMAND
, 1, (LPARAM
)GetDlgItem(IDOK
)->m_hWnd
);
1061 if ((dwAutoClose
== CLOSE_NOMERGES
)&&(!m_bErrorsOccurred
)&&(m_nConflicts
==0)&&(!m_bMergesAddsDeletesOccurred
))
1062 PostMessage(WM_COMMAND
, 1, (LPARAM
)GetDlgItem(IDOK
)->m_hWnd
);
1063 if ((dwAutoClose
== CLOSE_LOCAL
)&&(!m_bErrorsOccurred
)&&(m_nConflicts
==0)&&(localoperation
))
1064 PostMessage(WM_COMMAND
, 1, (LPARAM
)GetDlgItem(IDOK
)->m_hWnd
);
1067 //Don't do anything here which might cause messages to be sent to the window
1068 //The window thread is probably now blocked in OnOK if we've done an auto close
1072 void CGitProgressDlg::OnBnClickedLogbutton()
1074 switch(this->m_Command
)
1076 case GitProgress_Add
:
1077 case GitProgress_Resolve
:
1079 CString cmd
= _T(" /command:commit");
1080 cmd
+= _T(" /path:\"")+g_Git
.m_CurrentDir
+_T("\"");
1082 CAppUtils::RunTortoiseGitProc(cmd
);
1083 this->EndDialog(IDOK
);
1088 if (m_targetPathList
.GetCount() != 1)
1090 StringRevMap::iterator it
= m_UpdateStartRevMap
.begin();
1091 svn_revnum_t rev
= -1;
1092 if (it
!= m_UpdateStartRevMap
.end())
1097 dlg
.SetParams(m_targetPathList
[0], m_RevisionEnd
, m_RevisionEnd
, rev
, 0, TRUE
);
1103 void CGitProgressDlg::OnClose()
1107 TerminateThread(m_pThread
->m_hThread
, (DWORD
)-1);
1108 InterlockedExchange(&m_bThreadRunning
, FALSE
);
1112 m_bCancelled
= TRUE
;
1115 DialogEnableWindow(IDCANCEL
, TRUE
);
1119 void CGitProgressDlg::OnOK()
1121 if ((m_bCancelled
)&&(!m_bThreadRunning
))
1123 // I have made this wait a sensible amount of time (10 seconds) for the thread to finish
1124 // You must be careful in the thread that after posting the WM_COMMAND/IDOK message, you
1125 // don't do any more operations on the window which might require message passing
1126 // If you try to send windows messages once we're waiting here, then the thread can't finished
1127 // because the Window's message loop is blocked at this wait
1128 WaitForSingleObject(m_pThread
->m_hThread
, 10000);
1131 m_bCancelled
= TRUE
;
1134 void CGitProgressDlg::OnCancel()
1136 if ((m_bCancelled
)&&(!m_bThreadRunning
))
1137 __super::OnCancel();
1138 m_bCancelled
= TRUE
;
1141 void CGitProgressDlg::OnLvnGetdispinfoSvnprogress(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1143 NMLVDISPINFO
*pDispInfo
= reinterpret_cast<NMLVDISPINFO
*>(pNMHDR
);
1147 if (pDispInfo
->item
.mask
& LVIF_TEXT
)
1149 if (pDispInfo
->item
.iItem
< (int)m_arData
.size())
1151 const NotificationData
* data
= m_arData
[pDispInfo
->item
.iItem
];
1152 switch (pDispInfo
->item
.iSubItem
)
1155 lstrcpyn(m_columnbuf
, data
->sActionColumnText
, MAX_PATH
);
1158 lstrcpyn(m_columnbuf
, data
->sPathColumnText
, pDispInfo
->item
.cchTextMax
);
1159 if (!data
->bAuxItem
)
1161 int cWidth
= m_ProgList
.GetColumnWidth(1);
1162 cWidth
= max(12, cWidth
-12);
1163 CDC
* pDC
= m_ProgList
.GetDC();
1166 CFont
* pFont
= pDC
->SelectObject(m_ProgList
.GetFont());
1167 PathCompactPath(pDC
->GetSafeHdc(), m_columnbuf
, cWidth
);
1168 pDC
->SelectObject(pFont
);
1176 pDispInfo
->item
.pszText
= m_columnbuf
;
1183 void CGitProgressDlg::OnNMCustomdrawSvnprogress(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1185 NMLVCUSTOMDRAW
* pLVCD
= reinterpret_cast<NMLVCUSTOMDRAW
*>( pNMHDR
);
1187 // Take the default processing unless we set this to something else below.
1188 *pResult
= CDRF_DODEFAULT
;
1190 // First thing - check the draw stage. If it's the control's prepaint
1191 // stage, then tell Windows we want messages for every item.
1193 if ( CDDS_PREPAINT
== pLVCD
->nmcd
.dwDrawStage
)
1195 *pResult
= CDRF_NOTIFYITEMDRAW
;
1197 else if ( CDDS_ITEMPREPAINT
== pLVCD
->nmcd
.dwDrawStage
)
1199 // This is the prepaint stage for an item. Here's where we set the
1200 // item's text color. Our return value will tell Windows to draw the
1201 // item itself, but it will use the new color we set here.
1203 // Tell Windows to paint the control itself.
1204 *pResult
= CDRF_DODEFAULT
;
1206 ASSERT(pLVCD
->nmcd
.dwItemSpec
< m_arData
.size());
1207 if(pLVCD
->nmcd
.dwItemSpec
>= m_arData
.size())
1211 const NotificationData
* data
= m_arData
[pLVCD
->nmcd
.dwItemSpec
];
1212 ASSERT(data
!= NULL
);
1216 // Store the color back in the NMLVCUSTOMDRAW struct.
1217 pLVCD
->clrText
= data
->color
;
1221 void CGitProgressDlg::OnNMDblclkSvnprogress(NMHDR
* /*pNMHDR*/, LRESULT
* /*pResult*/)
1224 LPNMLISTVIEW pNMLV
= reinterpret_cast<LPNMLISTVIEW
>(pNMHDR
);
1226 if (pNMLV
->iItem
< 0)
1228 if (m_options
& ProgOptDryRun
)
1229 return; //don't do anything in a dry-run.
1231 const NotificationData
* data
= m_arData
[pNMLV
->iItem
];
1235 if (data
->bConflictedActionItem
)
1237 // We've double-clicked on a conflicted item - do a three-way merge on it
1238 SVNDiff::StartConflictEditor(data
->path
);
1240 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
))
1242 // This is a modified file which has been merged on update. Diff it against base
1243 CTGitPath temporaryFile
;
1244 SVNDiff
diff(this, this->m_hWnd
, true);
1245 diff
.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
1246 svn_revnum_t baseRev
= 0;
1247 diff
.DiffFileAgainstBase(data
->path
, baseRev
);
1249 else if ((!data
->bAuxItem
)&&(data
->path
.Exists())&&(!data
->path
.IsDirectory()))
1251 bool bOpenWith
= false;
1252 int ret
= (int)ShellExecute(m_hWnd
, NULL
, data
->path
.GetWinPath(), NULL
, NULL
, SW_SHOWNORMAL
);
1253 if (ret
<= HINSTANCE_ERROR
)
1257 CString cmd
= _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
1258 cmd
+= data
->path
.GetWinPathString() + _T(" ");
1259 CAppUtils::LaunchApplication(cmd
, NULL
, false);
1265 void CGitProgressDlg::OnHdnItemclickSvnprogress(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1267 LPNMHEADER phdr
= reinterpret_cast<LPNMHEADER
>(pNMHDR
);
1268 if (m_bThreadRunning
)
1270 if (m_nSortedColumn
== phdr
->iItem
)
1271 m_bAscending
= !m_bAscending
;
1273 m_bAscending
= TRUE
;
1274 m_nSortedColumn
= phdr
->iItem
;
1278 m_ProgList
.SetRedraw(FALSE
);
1279 m_ProgList
.DeleteAllItems();
1280 m_ProgList
.SetItemCountEx (static_cast<int>(m_arData
.size()));
1282 m_ProgList
.SetRedraw(TRUE
);
1287 bool CGitProgressDlg::NotificationDataIsAux(const NotificationData
* pData
)
1289 return pData
->bAuxItem
;
1292 BOOL
CGitProgressDlg::Notify(const git_wc_notify_action_t
/*action*/, const git_transfer_progress
*stat
)
1294 static unsigned int start
= 0;
1295 unsigned int dt
= GetCurrentTime() - start
;
1300 start
= GetCurrentTime();
1301 ds
= stat
->received_bytes
- m_TotalBytesTransferred
;
1302 speed
= ds
* 1000.0/dt
;
1303 m_TotalBytesTransferred
= stat
->received_bytes
;
1310 CProgressCtrl
* progControl
= (CProgressCtrl
*)GetDlgItem(IDC_PROGRESSBAR
);
1313 progress
= stat
->received_objects
+ stat
->indexed_objects
;
1315 if ((stat
->total_objects
> 1000) && (!progControl
->IsWindowVisible()))
1317 progControl
->ShowWindow(SW_SHOW
);
1319 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_NORMAL
);
1321 if (!GetDlgItem(IDC_PROGRESSLABEL
)->IsWindowVisible())
1322 GetDlgItem(IDC_PROGRESSLABEL
)->ShowWindow(SW_SHOW
);
1324 progControl
->SetPos(progress
);
1325 progControl
->SetRange32(0, 2 * stat
->total_objects
);
1328 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_NORMAL
);
1329 m_pTaskbarList
->SetProgressValue(m_hWnd
, progress
, stat
->total_objects
);
1333 if (stat
->received_bytes
< 1024)
1334 m_sTotalBytesTransferred
.Format(IDS_SVN_PROGRESS_TOTALBYTESTRANSFERRED
, (int64_t)stat
->received_bytes
);
1335 else if (stat
->received_bytes
< 1200000)
1336 m_sTotalBytesTransferred
.Format(IDS_SVN_PROGRESS_TOTALTRANSFERRED
, (int64_t)stat
->received_bytes
/ 1024);
1338 m_sTotalBytesTransferred
.Format(IDS_SVN_PROGRESS_TOTALMBTRANSFERRED
, (double)((double)stat
->received_bytes
/ 1024000.0));
1342 str
.Format(_T("%fB/s"), speed
);
1343 else if(speed
< 1024 * 1024)
1344 str
.Format(_T("%.2fKB/s"), speed
/ 1024);
1346 str
.Format(_T("%.2fMB/s"), speed
/ 1024000.0);
1348 progText
.Format(IDS_SVN_PROGRESS_TOTALANDSPEED
, (LPCTSTR
)m_sTotalBytesTransferred
, (LPCTSTR
)str
);
1349 SetDlgItemText(IDC_PROGRESSLABEL
, progText
);
1354 LRESULT
CGitProgressDlg::OnGitProgress(WPARAM
/*wParam*/, LPARAM
/*lParam*/)
1357 SVNProgress
* pProgressData
= (SVNProgress
*)lParam
;
1358 CProgressCtrl
* progControl
= (CProgressCtrl
*)GetDlgItem(IDC_PROGRESSBAR
);
1359 if ((pProgressData
->total
> 1000)&&(!progControl
->IsWindowVisible()))
1361 progControl
->ShowWindow(SW_SHOW
);
1363 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_NORMAL
);
1365 if (((pProgressData
->total
< 0)&&(pProgressData
->progress
> 1000)&&(progControl
->IsWindowVisible()))&&(m_itemCountTotal
<0))
1367 progControl
->ShowWindow(SW_HIDE
);
1369 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_INDETERMINATE
);
1371 if (!GetDlgItem(IDC_PROGRESSLABEL
)->IsWindowVisible())
1372 GetDlgItem(IDC_PROGRESSLABEL
)->ShowWindow(SW_SHOW
);
1373 SetTimer(TRANSFERTIMER
, 2000, NULL
);
1374 if ((pProgressData
->total
> 0)&&(pProgressData
->progress
> 1000))
1376 progControl
->SetPos((int)pProgressData
->progress
);
1377 progControl
->SetRange32(0, (int)pProgressData
->total
);
1380 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_NORMAL
);
1381 m_pTaskbarList
->SetProgressValue(m_hWnd
, pProgressData
->progress
, pProgressData
->total
);
1385 if (pProgressData
->overall_total
< 1024)
1386 m_sTotalBytesTransferred
.Format(IDS_SVN_PROGRESS_TOTALBYTESTRANSFERRED
, pProgressData
->overall_total
);
1387 else if (pProgressData
->overall_total
< 1200000)
1388 m_sTotalBytesTransferred
.Format(IDS_SVN_PROGRESS_TOTALTRANSFERRED
, pProgressData
->overall_total
/ 1024);
1390 m_sTotalBytesTransferred
.Format(IDS_SVN_PROGRESS_TOTALMBTRANSFERRED
, (double)((double)pProgressData
->overall_total
/ 1024000.0));
1391 progText
.Format(IDS_SVN_PROGRESS_TOTALANDSPEED
, (LPCTSTR
)m_sTotalBytesTransferred
, (LPCTSTR
)pProgressData
->SpeedString
);
1392 SetDlgItemText(IDC_PROGRESSLABEL
, progText
);
1397 void CGitProgressDlg::OnTimer(UINT_PTR nIDEvent
)
1399 if (nIDEvent
== TRANSFERTIMER
)
1403 progSpeed
.Format(IDS_SVN_PROGRESS_BYTES_SEC
, 0);
1404 progText
.Format(IDS_SVN_PROGRESS_TOTALANDSPEED
, (LPCTSTR
)m_sTotalBytesTransferred
, (LPCTSTR
)progSpeed
);
1405 SetDlgItemText(IDC_PROGRESSLABEL
, progText
);
1406 KillTimer(TRANSFERTIMER
);
1408 if (nIDEvent
== VISIBLETIMER
)
1410 if (nEnsureVisibleCount
)
1411 m_ProgList
.EnsureVisible(m_ProgList
.GetItemCount()-1, false);
1412 nEnsureVisibleCount
= 0;
1416 void CGitProgressDlg::Sort()
1418 if(m_arData
.size() < 2)
1423 // We need to sort the blocks which lie between the auxiliary entries
1424 // This is so that any aux data stays where it was
1425 NotificationDataVect::iterator actionBlockBegin
;
1426 NotificationDataVect::iterator actionBlockEnd
= m_arData
.begin(); // We start searching from here
1430 // Search to the start of the non-aux entry in the next block
1431 actionBlockBegin
= std::find_if(actionBlockEnd
, m_arData
.end(), std::not1(std::ptr_fun(&CGitProgressDlg::NotificationDataIsAux
)));
1432 if(actionBlockBegin
== m_arData
.end())
1434 // There are no more actions
1437 // Now search to find the end of the block
1438 actionBlockEnd
= std::find_if(actionBlockBegin
+1, m_arData
.end(), std::ptr_fun(&CGitProgressDlg::NotificationDataIsAux
));
1439 // Now sort the block
1440 std::sort(actionBlockBegin
, actionBlockEnd
, &CGitProgressDlg::SortCompare
);
1444 bool CGitProgressDlg::SortCompare(const NotificationData
* pData1
, const NotificationData
* pData2
)
1447 switch (m_nSortedColumn
)
1449 case 0: //action column
1450 result
= pData1
->sActionColumnText
.Compare(pData2
->sActionColumnText
);
1452 case 1: //path column
1453 // Compare happens after switch()
1459 // Sort by path if everything else is equal
1462 result
= CTGitPath::Compare(pData1
->path
, pData2
->path
);
1470 BOOL
CGitProgressDlg::OnSetCursor(CWnd
* pWnd
, UINT nHitTest
, UINT message
)
1472 if (!GetDlgItem(IDOK
)->IsWindowEnabled())
1474 // only show the wait cursor over the list control
1475 if ((pWnd
)&&(pWnd
== GetDlgItem(IDC_SVNPROGRESS
)))
1477 HCURSOR hCur
= LoadCursor(NULL
, MAKEINTRESOURCE(IDC_WAIT
));
1482 HCURSOR hCur
= LoadCursor(NULL
, MAKEINTRESOURCE(IDC_ARROW
));
1484 return CResizableStandAloneDialog::OnSetCursor(pWnd
, nHitTest
, message
);
1487 BOOL
CGitProgressDlg::PreTranslateMessage(MSG
* pMsg
)
1489 if (pMsg
->message
== WM_KEYDOWN
)
1491 if (pMsg
->wParam
== VK_ESCAPE
)
1493 // pressing the ESC key should close the dialog. But since we disabled the escape
1494 // key (so the user doesn't get the idea that he could simply undo an e.g. update)
1496 // So if the user presses the ESC key, change it to VK_RETURN so the dialog gets
1497 // the impression that the OK button was pressed.
1498 if ((!m_bThreadRunning
)&&(!GetDlgItem(IDCANCEL
)->IsWindowEnabled())
1499 &&(GetDlgItem(IDOK
)->IsWindowEnabled())&&(GetDlgItem(IDOK
)->IsWindowVisible()))
1501 // since we convert ESC to RETURN, make sure the OK button has the focus.
1502 GetDlgItem(IDOK
)->SetFocus();
1503 pMsg
->wParam
= VK_RETURN
;
1506 if (pMsg
->wParam
== 'A')
1508 if (GetKeyState(VK_CONTROL
)&0x8000)
1510 // Ctrl-A -> select all
1511 m_ProgList
.SetSelectionMark(0);
1512 for (int i
=0; i
<m_ProgList
.GetItemCount(); ++i
)
1514 m_ProgList
.SetItemState(i
, LVIS_SELECTED
, LVIS_SELECTED
);
1518 if ((pMsg
->wParam
== 'C')||(pMsg
->wParam
== VK_INSERT
))
1520 int selIndex
= m_ProgList
.GetSelectionMark();
1523 if (GetKeyState(VK_CONTROL
)&0x8000)
1525 //Ctrl-C -> copy to clipboard
1527 POSITION pos
= m_ProgList
.GetFirstSelectedItemPosition();
1532 int nItem
= m_ProgList
.GetNextSelectedItem(pos
);
1533 CString sAction
= m_ProgList
.GetItemText(nItem
, 0);
1534 CString sPath
= m_ProgList
.GetItemText(nItem
, 1);
1535 CString sMime
= m_ProgList
.GetItemText(nItem
, 2);
1536 CString sLogCopyText
;
1537 sLogCopyText
.Format(_T("%s: %s %s\r\n"),
1538 (LPCTSTR
)sAction
, (LPCTSTR
)sPath
, (LPCTSTR
)sMime
);
1539 sClipdata
+= sLogCopyText
;
1541 CStringUtils::WriteAsciiStringToClipboard(sClipdata
);
1546 } // if (pMsg->message == WM_KEYDOWN)
1547 return __super::PreTranslateMessage(pMsg
);
1550 void CGitProgressDlg::OnContextMenu(CWnd
* /*pWnd*/, CPoint
/*point*/)
1553 if (m_options
& ProgOptDryRun
)
1554 return; // don't do anything in a dry-run.
1556 if (pWnd
== &m_ProgList
)
1558 int selIndex
= m_ProgList
.GetSelectionMark();
1559 if ((point
.x
== -1) && (point
.y
== -1))
1561 // Menu was invoked from the keyboard rather than by right-clicking
1563 m_ProgList
.GetItemRect(selIndex
, &rect
, LVIR_LABEL
);
1564 m_ProgList
.ClientToScreen(&rect
);
1565 point
= rect
.CenterPoint();
1568 if ((selIndex
>= 0)&&(!m_bThreadRunning
))
1570 // entry is selected, thread has finished with updating so show the popup menu
1572 if (popup
.CreatePopupMenu())
1574 bool bAdded
= false;
1575 NotificationData
* data
= m_arData
[selIndex
];
1576 if ((data
)&&(!data
->path
.IsDirectory()))
1578 if (data
->action
== svn_wc_notify_update_update
|| data
->action
== svn_wc_notify_resolved
)
1580 if (m_ProgList
.GetSelectedCount() == 1)
1582 popup
.AppendMenuIcon(ID_COMPARE
, IDS_LOG_POPUP_COMPARE
, IDI_DIFF
);
1586 if (data
->bConflictedActionItem
)
1588 if (m_ProgList
.GetSelectedCount() == 1)
1590 popup
.AppendMenuIcon(ID_EDITCONFLICT
, IDS_MENUCONFLICT
,IDI_CONFLICT
);
1591 popup
.SetDefaultItem(ID_EDITCONFLICT
, FALSE
);
1592 popup
.AppendMenuIcon(ID_CONFLICTRESOLVE
, IDS_SVNPROGRESS_MENUMARKASRESOLVED
,IDI_RESOLVE
);
1594 popup
.AppendMenuIcon(ID_CONFLICTUSETHEIRS
, IDS_SVNPROGRESS_MENUUSETHEIRS
,IDI_RESOLVE
);
1595 popup
.AppendMenuIcon(ID_CONFLICTUSEMINE
, IDS_SVNPROGRESS_MENUUSEMINE
,IDI_RESOLVE
);
1597 else if ((data
->content_state
== svn_wc_notify_state_merged
)||(GitProgress_Merge
== m_Command
)||(data
->action
== svn_wc_notify_resolved
))
1598 popup
.SetDefaultItem(ID_COMPARE
, FALSE
);
1600 if (m_ProgList
.GetSelectedCount() == 1)
1602 if ((data
->action
== svn_wc_notify_add
)||
1603 (data
->action
== svn_wc_notify_update_add
)||
1604 (data
->action
== svn_wc_notify_commit_added
)||
1605 (data
->action
== svn_wc_notify_commit_modified
)||
1606 (data
->action
== svn_wc_notify_restore
)||
1607 (data
->action
== svn_wc_notify_revert
)||
1608 (data
->action
== svn_wc_notify_resolved
)||
1609 (data
->action
== svn_wc_notify_commit_replaced
)||
1610 (data
->action
== svn_wc_notify_commit_modified
)||
1611 (data
->action
== svn_wc_notify_commit_postfix_txdelta
)||
1612 (data
->action
== svn_wc_notify_update_update
))
1614 popup
.AppendMenuIcon(ID_LOG
, IDS_MENULOG
,IDI_LOG
);
1615 if (data
->action
== svn_wc_notify_update_update
)
1616 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1617 popup
.AppendMenuIcon(ID_OPEN
, IDS_LOG_POPUP_OPEN
, IDI_OPEN
);
1618 popup
.AppendMenuIcon(ID_OPENWITH
, IDS_LOG_POPUP_OPENWITH
, IDI_OPEN
);
1622 } // if ((data)&&(!data->path.IsDirectory()))
1623 if (m_ProgList
.GetSelectedCount() == 1)
1627 CString sPath
= GetPathFromColumnText(data
->sPathColumnText
);
1628 if ((!sPath
.IsEmpty())&&(!SVN::PathIsURL(CTGitPath(sPath
))))
1630 CTGitPath path
= CTGitPath(sPath
);
1631 if (path
.GetDirectory().Exists())
1633 popup
.AppendMenuIcon(ID_EXPLORE
, IDS_SVNPROGRESS_MENUOPENPARENT
, IDI_EXPLORER
);
1639 if (m_ProgList
.GetSelectedCount() > 0)
1642 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1643 popup
.AppendMenuIcon(ID_COPY
, IDS_LOG_POPUP_COPYTOCLIPBOARD
,IDI_COPYCLIP
);
1648 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, this, 0);
1649 DialogEnableWindow(IDOK
, FALSE
);
1650 this->SetPromptApp(&theApp
);
1651 theApp
.DoWaitCursor(1);
1652 bool bOpenWith
= false;
1658 POSITION pos
= m_ProgList
.GetFirstSelectedItemPosition();
1661 int nItem
= m_ProgList
.GetNextSelectedItem(pos
);
1662 NotificationData
* data
= m_arData
[nItem
];
1665 sLines
+= data
->sPathColumnText
;
1666 sLines
+= _T("\r\n");
1670 if (!sLines
.IsEmpty())
1672 CStringUtils::WriteAsciiStringToClipboard(sLines
, GetSafeHwnd());
1678 CString sPath
= GetPathFromColumnText(data
->sPathColumnText
);
1680 CTGitPath path
= CTGitPath(sPath
);
1681 ShellExecute(m_hWnd
, _T("explore"), path
.GetDirectory().GetWinPath(), NULL
, path
.GetDirectory().GetWinPath(), SW_SHOW
);
1686 svn_revnum_t rev
= -1;
1687 StringRevMap::iterator it
= m_UpdateStartRevMap
.end();
1688 if (data
->basepath
.IsEmpty())
1689 it
= m_UpdateStartRevMap
.begin();
1691 it
= m_UpdateStartRevMap
.find(data
->basepath
.GetSVNApiPath(pool
));
1692 if (it
!= m_UpdateStartRevMap
.end())
1694 // if the file was merged during update, do a three way diff between OLD, MINE, THEIRS
1695 if (data
->content_state
== svn_wc_notify_state_merged
)
1697 CTGitPath basefile
= CTempFiles::Instance().GetTempFilePath(false, data
->path
, rev
);
1698 CTGitPath newfile
= CTempFiles::Instance().GetTempFilePath(false, data
->path
, SVNRev::REV_HEAD
);
1700 if (!svn
.Cat(data
->path
, SVNRev(SVNRev::REV_WC
), rev
, basefile
))
1702 CMessageBox::Show(m_hWnd
, svn
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
1703 DialogEnableWindow(IDOK
, TRUE
);
1706 // If necessary, convert the line-endings on the file before diffing
1707 if ((DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\ConvertBase"), TRUE
))
1709 CTGitPath temporaryFile
= CTempFiles::Instance().GetTempFilePath(false, data
->path
, SVNRev::REV_BASE
);
1710 if (!svn
.Cat(data
->path
, SVNRev(SVNRev::REV_BASE
), SVNRev(SVNRev::REV_BASE
), temporaryFile
))
1712 temporaryFile
.Reset();
1717 newfile
= temporaryFile
;
1721 SetFileAttributes(newfile
.GetWinPath(), FILE_ATTRIBUTE_READONLY
);
1722 SetFileAttributes(basefile
.GetWinPath(), FILE_ATTRIBUTE_READONLY
);
1723 CString revname
, wcname
, basename
;
1724 revname
.Format(_T("%s Revision %ld"), (LPCTSTR
)data
->path
.GetUIFileOrDirectoryName(), rev
);
1725 wcname
.Format(IDS_DIFF_WCNAME
, (LPCTSTR
)data
->path
.GetUIFileOrDirectoryName());
1726 basename
.Format(IDS_DIFF_BASENAME
, (LPCTSTR
)data
->path
.GetUIFileOrDirectoryName());
1727 CAppUtils::StartExtMerge(basefile
, newfile
, data
->path
, data
->path
, basename
, revname
, wcname
, CString(), true);
1731 CTGitPath tempfile
= CTempFiles::Instance().GetTempFilePath(false, data
->path
, rev
);
1733 if (!svn
.Cat(data
->path
, SVNRev(SVNRev::REV_WC
), rev
, tempfile
))
1735 CMessageBox::Show(m_hWnd
, svn
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
1736 DialogEnableWindow(IDOK
, TRUE
);
1741 SetFileAttributes(tempfile
.GetWinPath(), FILE_ATTRIBUTE_READONLY
);
1742 CString revname
, wcname
;
1743 revname
.Format(_T("%s Revision %ld"), (LPCTSTR
)data
->path
.GetUIFileOrDirectoryName(), rev
);
1744 wcname
.Format(IDS_DIFF_WCNAME
, (LPCTSTR
)data
->path
.GetUIFileOrDirectoryName());
1745 CAppUtils::StartExtDiff(
1746 tempfile
, data
->path
, revname
, wcname
,
1747 CAppUtils::DiffFlags().AlternativeTool(!!(GetAsyncKeyState(VK_SHIFT
) & 0x8000)));
1752 case ID_EDITCONFLICT
:
1754 CString sPath
= GetPathFromColumnText(data
->sPathColumnText
);
1755 SVNDiff::StartConflictEditor(CTGitPath(sPath
));
1758 case ID_CONFLICTUSETHEIRS
:
1759 case ID_CONFLICTUSEMINE
:
1760 case ID_CONFLICTRESOLVE
:
1762 svn_wc_conflict_choice_t result
= svn_wc_conflict_choose_merged
;
1765 case ID_CONFLICTUSETHEIRS
:
1766 result
= svn_wc_conflict_choose_theirs_full
;
1768 case ID_CONFLICTUSEMINE
:
1769 result
= svn_wc_conflict_choose_mine_full
;
1771 case ID_CONFLICTRESOLVE
:
1772 result
= svn_wc_conflict_choose_merged
;
1776 POSITION pos
= m_ProgList
.GetFirstSelectedItemPosition();
1777 CString sResolvedPaths
;
1780 int nItem
= m_ProgList
.GetNextSelectedItem(pos
);
1781 NotificationData
* data
= m_arData
[nItem
];
1784 if (data
->bConflictedActionItem
)
1786 if (!svn
.Resolve(data
->path
, result
, FALSE
))
1788 CMessageBox::Show(m_hWnd
, svn
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
1789 DialogEnableWindow(IDOK
, TRUE
);
1794 data
->color
= ::GetSysColor(COLOR_WINDOWTEXT
);
1795 data
->action
= svn_wc_notify_resolved
;
1796 data
->sActionColumnText
.LoadString(IDS_SVNACTION_RESOLVE
);
1797 data
->bConflictedActionItem
= false;
1800 if (m_nConflicts
==0)
1802 // When the last conflict is resolved we remove
1803 // the warning which we assume is in the last line.
1804 int nIndex
= m_ProgList
.GetItemCount()-1;
1805 VERIFY(m_ProgList
.DeleteItem(nIndex
));
1807 delete m_arData
[nIndex
];
1808 m_arData
.pop_back();
1810 sResolvedPaths
+= data
->path
.GetWinPathString() + _T("\n");
1815 m_ProgList
.Invalidate();
1816 CString info
= BuildInfoString();
1817 SetDlgItemText(IDC_INFOTEXT
, info
);
1819 if (!sResolvedPaths
.IsEmpty())
1822 msg
.Format(IDS_SVNPROGRESS_RESOLVED
, (LPCTSTR
)sResolvedPaths
);
1823 CMessageBox::Show(m_hWnd
, msg
, _T("TortoiseGit"), MB_OK
| MB_ICONINFORMATION
);
1829 svn_revnum_t rev
= m_RevisionEnd
;
1830 if (!data
->basepath
.IsEmpty())
1832 StringRevMap::iterator it
= m_FinishedRevMap
.find(data
->basepath
.GetSVNApiPath(pool
));
1833 if (it
!= m_FinishedRevMap
.end())
1837 // fetch the log from HEAD, not the revision we updated to:
1838 // the path might be inside an external folder which has its own
1840 CString sPath
= GetPathFromColumnText(data
->sPathColumnText
);
1841 dlg
.SetParams(CTGitPath(sPath
), SVNRev(), SVNRev::REV_HEAD
, 1, -1, TRUE
);
1850 CString sWinPath
= GetPathFromColumnText(data
->sPathColumnText
);
1852 ret
= (int)ShellExecute(this->m_hWnd
, NULL
, (LPCTSTR
)sWinPath
, NULL
, NULL
, SW_SHOWNORMAL
);
1853 if ((ret
<= HINSTANCE_ERROR
)||bOpenWith
)
1855 CString cmd
= _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
1856 cmd
+= sWinPath
+ _T(" ");
1857 CAppUtils::LaunchApplication(cmd
, NULL
, false);
1861 DialogEnableWindow(IDOK
, TRUE
);
1862 theApp
.DoWaitCursor(-1);
1870 void CGitProgressDlg::OnEnSetfocusInfotext()
1873 GetDlgItemText(IDC_INFOTEXT
, sTemp
);
1874 if (sTemp
.IsEmpty())
1875 GetDlgItem(IDC_INFOTEXT
)->HideCaret();
1878 void CGitProgressDlg::OnLvnBegindragSvnprogress(NMHDR
* , LRESULT
*pResult
)
1880 //LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1882 int selIndex
= m_ProgList
.GetSelectionMark();
1886 CDropFiles dropFiles
; // class for creating DROPFILES struct
1889 POSITION pos
= m_ProgList
.GetFirstSelectedItemPosition();
1890 while ( (index
= m_ProgList
.GetNextSelectedItem(pos
)) >= 0 )
1892 NotificationData
* data
= m_arData
[index
];
1894 if ( data
->kind
==svn_node_file
|| data
->kind
==svn_node_dir
)
1896 CString sPath
= GetPathFromColumnText(data
->sPathColumnText
);
1898 dropFiles
.AddFile( sPath
);
1902 if ( dropFiles
.GetCount()>0 )
1904 dropFiles
.CreateStructure();
1910 void CGitProgressDlg::OnSize(UINT nType
, int cx
, int cy
)
1912 CResizableStandAloneDialog::OnSize(nType
, cx
, cy
);
1913 if ((nType
== SIZE_RESTORED
)&&(m_bLastVisible
))
1915 if(!m_ProgList
.m_hWnd
)
1918 int count
= m_ProgList
.GetItemCount();
1920 m_ProgList
.EnsureVisible(count
-1, false);
1924 //////////////////////////////////////////////////////////////////////////
1926 //////////////////////////////////////////////////////////////////////////
1927 bool CGitProgressDlg::CmdAdd(CString
& sWindowTitle
, bool& localoperation
)
1929 localoperation
= true;
1930 sWindowTitle
.LoadString(IDS_PROGRS_TITLE_ADD
);
1931 CAppUtils::SetWindowTitle(m_hWnd
, m_targetPathList
.GetCommonRoot().GetUIPathString(), sWindowTitle
);
1932 SetBackgroundImage(IDI_ADD_BKG
);
1933 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_ADD
)));
1935 if (CRegDWORD(_T("Software\\TortoiseGit\\UseLibgit2"), TRUE
) == TRUE
)
1937 git_repository
*repo
= NULL
;
1940 CStringA gitdir
= CUnicodeUtils::GetMulti(CTGitPath(g_Git
.m_CurrentDir
).GetGitPathString(), CP_UTF8
);
1941 if (git_repository_open(&repo
, gitdir
.GetBuffer()))
1943 gitdir
.ReleaseBuffer();
1947 gitdir
.ReleaseBuffer();
1949 git_config
* config
;
1950 git_config_new(&config
);
1952 CStringA projectConfigA
= CUnicodeUtils::GetMulti(g_Git
.GetGitLocalConfig(), CP_UTF8
);
1953 if (git_config_add_file_ondisk(config
, projectConfigA
.GetBuffer(), 4, FALSE
))
1955 projectConfigA
.ReleaseBuffer();
1957 git_config_free(config
);
1958 git_repository_free(repo
);
1961 projectConfigA
.ReleaseBuffer();
1962 CString globalConfig
= g_Git
.GetGitGlobalConfig();
1963 if (PathFileExists(globalConfig
))
1965 CStringA globalConfigA
= CUnicodeUtils::GetMulti(globalConfig
, CP_UTF8
);
1966 if (git_config_add_file_ondisk(config
, globalConfigA
.GetBuffer(), 3, FALSE
))
1968 globalConfigA
.ReleaseBuffer();
1970 git_config_free(config
);
1971 git_repository_free(repo
);
1974 globalConfigA
.ReleaseBuffer();
1976 CString globalXDGConfig
= g_Git
.GetGitGlobalXDGConfig();
1977 if (PathFileExists(globalXDGConfig
))
1979 CStringA globalXDGConfigA
= CUnicodeUtils::GetMulti(globalXDGConfig
, CP_UTF8
);
1980 if (git_config_add_file_ondisk(config
, globalXDGConfigA
.GetBuffer(), 2, FALSE
))
1982 globalXDGConfigA
.ReleaseBuffer();
1984 git_config_free(config
);
1985 git_repository_free(repo
);
1988 globalXDGConfigA
.ReleaseBuffer();
1990 CString systemConfig
= g_Git
.GetGitSystemConfig();
1991 if (!systemConfig
.IsEmpty())
1993 CStringA systemConfigA
= CUnicodeUtils::GetMulti(systemConfig
, CP_UTF8
);
1994 if (git_config_add_file_ondisk(config
, systemConfigA
.GetBuffer(), 1, FALSE
))
1996 systemConfigA
.ReleaseBuffer();
1998 git_config_free(config
);
1999 git_repository_free(repo
);
2002 systemConfigA
.ReleaseBuffer();
2005 git_repository_set_config(repo
, config
);
2007 if (git_repository_index(&index
, repo
))
2010 git_repository_free(repo
);
2013 if (git_index_read(index
))
2016 git_index_free(index
);
2017 git_repository_free(repo
);
2021 for (int i
= 0; i
< m_targetPathList
.GetCount(); ++i
)
2023 if (git_index_add_bypath(index
, CStringA(CUnicodeUtils::GetMulti(m_targetPathList
[i
].GetGitPathString(), CP_UTF8
)).GetBuffer()))
2026 git_index_free(index
);
2027 git_repository_free(repo
);
2030 Notify(m_targetPathList
[i
],git_wc_notify_add
);
2033 if (git_index_write(index
))
2036 git_index_free(index
);
2037 git_repository_free(repo
);
2041 git_index_free(index
);
2042 git_repository_free(repo
);
2046 CMassiveGitTask
mgt(L
"add -f");
2047 mgt
.ExecuteWithNotify(&m_targetPathList
, m_bCancelled
, git_wc_notify_add
, this, &CGitProgressDlg::Notify
);
2050 CShellUpdater::Instance().AddPathsForUpdate(m_targetPathList
);
2052 this->GetDlgItem(IDC_LOGBUTTON
)->SetWindowText(_T("Commit ..."));
2053 this->GetDlgItem(IDC_LOGBUTTON
)->ShowWindow(SW_SHOW
);
2057 bool CGitProgressDlg::CmdCopy(CString
& /*sWindowTitle*/, bool& /*localoperation*/)
2060 ASSERT(m_targetPathList
.GetCount() == 1);
2061 sWindowTitle
.LoadString(IDS_PROGRS_TITLE_COPY
);
2062 SetWindowText(sWindowTitle
); // needs to be updated, see TSVN rev. 21375
2063 SetBackgroundImage(IDI_COPY_BKG
);
2066 sCmdInfo
.Format(IDS_PROGRS_CMD_COPY
,
2067 m_targetPathList
[0].IsUrl() ? (LPCTSTR
)m_targetPathList
[0].GetSVNPathString() : m_targetPathList
[0].GetWinPath(),
2068 (LPCTSTR
)m_url
.GetSVNPathString(), (LPCTSTR
)m_Revision
.ToString());
2069 ReportCmd(sCmdInfo
);
2071 if (!Copy(m_targetPathList
, m_url
, m_Revision
, m_pegRev
, m_sMessage
))
2076 if (m_options
& ProgOptSwitchAfterCopy
)
2078 sCmdInfo
.Format(IDS_PROGRS_CMD_SWITCH
,
2079 m_targetPathList
[0].GetWinPath(),
2080 (LPCTSTR
)m_url
.GetSVNPathString(), (LPCTSTR
)m_Revision
.ToString());
2081 ReportCmd(sCmdInfo
);
2082 if (!Switch(m_targetPathList
[0], m_url
, SVNRev::REV_HEAD
, SVNRev::REV_HEAD
, m_depth
, TRUE
, m_options
& ProgOptIgnoreExternals
))
2084 if (!Switch(m_targetPathList
[0], m_url
, SVNRev::REV_HEAD
, m_Revision
, m_depth
, TRUE
, m_options
& ProgOptIgnoreExternals
))
2093 if (SVN::PathIsURL(m_url
))
2095 CString
sMsg(MAKEINTRESOURCE(IDS_PROGRS_COPY_WARNING
));
2096 ReportNotification(sMsg
);
2103 bool CGitProgressDlg::CmdExport(CString
& /*sWindowTitle*/, bool& /*localoperation*/)
2106 ASSERT(m_targetPathList
.GetCount() == 1);
2107 sWindowTitle
.LoadString(IDS_PROGRS_TITLE_EXPORT
);
2108 sWindowTitle
= m_url
.GetUIFileOrDirectoryName()+_T(" - ")+sWindowTitle
;
2109 SetWindowText(sWindowTitle
); // needs to be updated, see TSVN rev. 21375
2110 SetBackgroundImage(IDI_EXPORT_BKG
);
2112 if (m_options
& ProgOptEolCRLF
)
2114 if (m_options
& ProgOptEolLF
)
2116 if (m_options
& ProgOptEolCR
)
2118 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_EXPORT
)));
2119 if (!Export(m_url
, m_targetPathList
[0], m_Revision
, m_Revision
, TRUE
, m_options
& ProgOptIgnoreExternals
, m_depth
, NULL
, FALSE
, eol
))
2128 bool CGitProgressDlg::CmdRename(CString
& /*sWindowTitle*/, bool& /*localoperation*/)
2131 ASSERT(m_targetPathList
.GetCount() == 1);
2132 if ((!m_targetPathList
[0].IsUrl())&&(!m_url
.IsUrl()))
2133 localoperation
= true;
2134 sWindowTitle
.LoadString(IDS_PROGRS_TITLE_RENAME
);
2135 SetWindowText(sWindowTitle
); // needs to be updated, see TSVN rev. 21375
2136 SetBackgroundImage(IDI_RENAME_BKG
);
2137 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RENAME
)));
2138 if (!Move(m_targetPathList
, m_url
, m_Revision
, m_sMessage
))
2147 bool CGitProgressDlg::CmdResolve(CString
& sWindowTitle
, bool& localoperation
)
2150 localoperation
= true;
2151 ASSERT(m_targetPathList
.GetCount() == 1);
2152 sWindowTitle
.LoadString(IDS_PROGRS_TITLE_RESOLVE
);
2153 CAppUtils::SetWindowTitle(m_hWnd
, m_targetPathList
.GetCommonRoot().GetUIPathString(), sWindowTitle
);
2154 SetBackgroundImage(IDI_RESOLVE_BKG
);
2155 // check if the file may still have conflict markers in it.
2156 //BOOL bMarkers = FALSE;
2158 for (int i
= 0; i
< m_targetPathList
.GetCount(); ++i
)
2160 CString cmd
,out
,tempmergefile
;
2161 cmd
.Format(_T("git.exe add -f -- \"%s\""),m_targetPathList
[i
].GetGitPathString());
2162 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
2164 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
2165 m_bErrorsOccurred
=true;
2169 CAppUtils::RemoveTempMergeFile((CTGitPath
&)m_targetPathList
[i
]);
2171 Notify(m_targetPathList
[i
],git_wc_notify_resolved
);
2174 if ((m_options
& ProgOptSkipConflictCheck
) == 0)
2178 for (INT_PTR fileindex
=0; (fileindex
<m_targetPathList
.GetCount()) && (bMarkers
==FALSE
); ++fileindex
)
2180 if (!m_targetPathList
[fileindex
].IsDirectory())
2182 CStdioFile
file(m_targetPathList
[fileindex
].GetWinPath(), CFile::typeBinary
| CFile::modeRead
);
2183 CString strLine
= _T("");
2184 while (file
.ReadString(strLine
))
2186 if (strLine
.Find(_T("<<<<<<<"))==0)
2196 catch (CFileException
* pE
)
2198 TRACE(_T("CFileException in Resolve!\n"));
2199 TCHAR error
[10000] = {0};
2200 pE
->GetErrorMessage(error
, 10000);
2208 if (CMessageBox::Show(m_hWnd
, IDS_PROGRS_REVERTMARKERS
, IDS_APPNAME
, MB_YESNO
| MB_ICONQUESTION
)==IDYES
)
2210 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RESOLVE
)));
2211 for (INT_PTR fileindex
=0; fileindex
<m_targetPathList
.GetCount(); ++fileindex
)
2212 Resolve(m_targetPathList
[fileindex
], svn_wc_conflict_choose_merged
, true);
2217 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RESOLVE
)));
2218 for (INT_PTR fileindex
=0; fileindex
<m_targetPathList
.GetCount(); ++fileindex
)
2219 Resolve(m_targetPathList
[fileindex
], svn_wc_conflict_choose_merged
, true);
2222 CShellUpdater::Instance().AddPathsForUpdate(m_targetPathList
);
2224 this->GetDlgItem(IDC_LOGBUTTON
)->SetWindowText(CString(MAKEINTRESOURCE(IDS_COMMITBUTTON
)));
2225 this->GetDlgItem(IDC_LOGBUTTON
)->ShowWindow(SW_SHOW
);
2230 bool CGitProgressDlg::CmdRevert(CString
& sWindowTitle
, bool& localoperation
)
2233 localoperation
= true;
2234 sWindowTitle
.LoadString(IDS_PROGRS_TITLE_REVERT
);
2235 CAppUtils::SetWindowTitle(m_hWnd
, m_targetPathList
.GetCommonRoot().GetUIPathString(), sWindowTitle
);
2236 SetBackgroundImage(IDI_REVERT_BKG
);
2238 CTGitPathList delList
;
2239 for (int i
= 0; i
< m_selectedPaths
.GetCount(); ++i
)
2243 path
.SetFromWin(g_Git
.m_CurrentDir
+_T("\\")+m_selectedPaths
[i
].GetWinPath());
2244 action
= m_selectedPaths
[i
].m_Action
;
2245 /* rename file can't delete because it needs original file*/
2246 if((!(action
& CTGitPath::LOGACTIONS_ADDED
)) &&
2247 (!(action
& CTGitPath::LOGACTIONS_REPLACED
)))
2248 delList
.AddPath(path
);
2250 if (DWORD(CRegDWORD(_T("Software\\TortoiseGit\\RevertWithRecycleBin"), TRUE
)))
2251 delList
.DeleteAllFiles(true);
2253 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_REVERT
)));
2254 for (int i
= 0; i
< m_selectedPaths
.GetCount(); ++i
)
2256 if(g_Git
.Revert(_T("HEAD"), (CTGitPath
&)m_selectedPaths
[i
]))
2258 CMessageBox::Show(NULL
,_T("Revert Fail"),_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
2259 m_bErrorsOccurred
=true;
2262 Notify(m_selectedPaths
[i
],git_wc_notify_revert
);
2265 CShellUpdater::Instance().AddPathsForUpdate(m_selectedPaths
);
2270 bool CGitProgressDlg::CmdSwitch(CString
& /*sWindowTitle*/, bool& /*localoperation*/)
2273 ASSERT(m_targetPathList
.GetCount() == 1);
2275 sWindowTitle
.LoadString(IDS_PROGRS_TITLE_SWITCH
);
2276 SetWindowText(sWindowTitle
); // needs to be updated, see TSVN rev. 21375
2277 SetBackgroundImage(IDI_SWITCH_BKG
);
2279 if (st
.GetStatus(m_targetPathList
[0]) != (-2))
2281 if (st
.status
->entry
!= NULL
)
2283 rev
= st
.status
->entry
->revision
;
2288 sCmdInfo
.Format(IDS_PROGRS_CMD_SWITCH
,
2289 m_targetPathList
[0].GetWinPath(), (LPCTSTR
)m_url
.GetSVNPathString(),
2290 (LPCTSTR
)m_Revision
.ToString());
2291 ReportCmd(sCmdInfo
);
2293 bool depthIsSticky
= true;
2294 if (m_depth
== svn_depth_unknown
)
2295 depthIsSticky
= false;
2296 if (!Switch(m_targetPathList
[0], m_url
, m_Revision
, m_Revision
, m_depth
, depthIsSticky
, m_options
& ProgOptIgnoreExternals
))
2301 m_UpdateStartRevMap
[m_targetPathList
[0].GetSVNApiPath(pool
)] = rev
;
2302 if ((m_RevisionEnd
>= 0)&&(rev
>= 0)
2303 &&((LONG
)m_RevisionEnd
> (LONG
)rev
))
2305 GetDlgItem(IDC_LOGBUTTON
)->ShowWindow(SW_SHOW
);
2310 bool CGitProgressDlg::CmdClone(CString
& sWindowTitle
, bool& /*localoperation*/)
2312 if (!g_Git
.UsingLibGit2(CGit::GIT_CMD_CLONE
))
2314 // should never run to here
2318 this->m_TotalBytesTransferred
= 0;
2320 sWindowTitle
.LoadString(IDS_PROGRS_TITLE_CLONE
);
2321 CAppUtils::SetWindowTitle(m_hWnd
, m_url
.GetGitPathString(), sWindowTitle
);
2322 SetBackgroundImage(IDI_SWITCH_BKG
);
2323 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROG_CLONE
)));
2325 if (m_url
.IsEmpty() || m_targetPathList
.GetCount() == 0)
2328 CStringA url
= CUnicodeUtils::GetMulti(m_url
.GetGitPathString(), CP_UTF8
);
2329 CStringA path
= CUnicodeUtils::GetMulti(m_targetPathList
[0].GetWinPathString(),CP_UTF8
);
2331 git_repository
*cloned_repo
= NULL
;
2332 git_remote
*origin
= NULL
;
2333 git_checkout_opts checkout_opts
= GIT_CHECKOUT_OPTS_INIT
;
2337 git_clone_options clone_opts
= GIT_CLONE_OPTIONS_INIT
;
2339 clone_opts
.checkout_opts
= checkout_opts
;
2341 clone_opts
.checkout_opts
.checkout_strategy
= m_bNoCheckout
? GIT_CHECKOUT_NONE
: GIT_CHECKOUT_SAFE_CREATE
;
2342 clone_opts
.checkout_opts
.progress_cb
= CheckoutCallback
;
2343 clone_opts
.checkout_opts
.progress_payload
= this;
2345 if (!m_RefSpec
.IsEmpty())
2346 clone_opts
.checkout_branch
= CUnicodeUtils::GetMulti(m_RefSpec
, CP_UTF8
).GetBuffer();
2348 clone_opts
.fetch_progress_cb
= FetchCallback
;
2349 clone_opts
.fetch_progress_payload
= this;
2351 clone_opts
.cred_acquire_cb
= CAppUtils::Git2GetUserPassword
;
2353 clone_opts
.bare
= m_bBare
;
2355 m_Animate
.ShowWindow(SW_SHOW
);
2356 m_Animate
.Play(0, INT_MAX
, INT_MAX
);
2357 error
= git_clone(&cloned_repo
, url
, path
, &clone_opts
);
2359 m_Animate
.ShowWindow(SW_HIDE
);
2361 git_remote_free(origin
);
2367 else if (cloned_repo
)
2368 git_repository_free(cloned_repo
);
2372 void CGitProgressDlg::OnBnClickedNoninteractive()
2374 LRESULT res
= ::SendMessage(GetDlgItem(IDC_NONINTERACTIVE
)->GetSafeHwnd(), BM_GETCHECK
, 0, 0);
2375 m_AlwaysConflicted
= (res
== BST_CHECKED
);
2376 CRegDWORD nonint
= CRegDWORD(_T("Software\\TortoiseGit\\MergeNonInteractive"), FALSE
);
2377 nonint
= m_AlwaysConflicted
;
2380 CString
CGitProgressDlg::GetPathFromColumnText(const CString
& sColumnText
)
2382 CString sPath
= CPathUtils::ParsePathInString(sColumnText
);
2383 if (sPath
.Find(':')<0)
2385 // the path is not absolute: add the common root of all paths to it
2386 sPath
= m_targetPathList
.GetCommonRoot().GetDirectory().GetWinPathString() + _T("\\") + CPathUtils::ParsePathInString(sColumnText
);
2391 bool CGitProgressDlg::CmdSendMail(CString
& sWindowTitle
, bool& /*localoperation*/)
2393 sWindowTitle
.LoadString(IDS_PROGRS_TITLE_SENDMAIL
);
2394 CAppUtils::SetWindowTitle(m_hWnd
, m_targetPathList
.GetCommonRoot().GetUIPathString(), sWindowTitle
);
2395 //SetBackgroundImage(IDI_ADD_BKG);
2396 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_SENDMAIL
)));
2398 if(this->m_SendMailFlags
&SENDMAIL_COMBINED
)
2402 Notify(path
,git_wc_notify_sendmail_start
);
2407 if(!!CPatch::SendPatchesCombined(m_targetPathList
,m_SendMailTO
,m_SendMailCC
,m_SendMailSubject
,!!(this->m_SendMailFlags
&SENDMAIL_ATTACHMENT
),!!(this->m_SendMailFlags
&SENDMAIL_MAPI
),&err
))
2409 Notify(path
,git_wc_notify_sendmail_error
,ret
,&err
);
2419 Notify(path
,git_wc_notify_sendmail_retry
,ret
,&err
);
2424 str
.LoadString(IDS_SVN_USERCANCELLED
);
2425 Notify(path
,git_wc_notify_sendmail_error
,ret
,&str
);
2430 Notify(path
,git_wc_notify_sendmail_done
,ret
);
2434 for (int i
= 0; ret
&& i
< m_targetPathList
.GetCount(); ++i
)
2437 Notify(m_targetPathList
[i
],git_wc_notify_sendmail_start
);
2442 if(!!patch
.Send((CString
&)m_targetPathList
[i
].GetWinPathString(),this->m_SendMailTO
,
2443 this->m_SendMailCC
,!!(this->m_SendMailFlags
&SENDMAIL_ATTACHMENT
),!!(this->m_SendMailFlags
&SENDMAIL_MAPI
)))
2445 Notify(m_targetPathList
[i
],git_wc_notify_sendmail_error
,ret
,&patch
.m_LastError
);
2456 Notify(m_targetPathList
[i
],git_wc_notify_sendmail_retry
,ret
,&patch
.m_LastError
);
2461 str
.LoadString(IDS_SVN_USERCANCELLED
);
2462 Notify(m_targetPathList
[i
],git_wc_notify_sendmail_error
,ret
,&str
);
2467 Notify(m_targetPathList
[i
],git_wc_notify_sendmail_done
,ret
);
2473 LRESULT
CGitProgressDlg::OnTaskbarBtnCreated(WPARAM
/*wParam*/, LPARAM
/*lParam*/)
2475 m_pTaskbarList
.Release();
2476 m_pTaskbarList
.CoCreateInstance(CLSID_TaskbarList
);
2480 HBRUSH
CGitProgressDlg::OnCtlColor(CDC
* pDC
, CWnd
* pWnd
, UINT nCtlColor
)
2483 if (pWnd
->GetDlgCtrlID() == IDC_TITLE_ANIMATE
)
2485 pDC
->SetBkColor(GetSysColor(COLOR_WINDOW
)); // add this
2486 pDC
->SetBkMode(TRANSPARENT
);
2487 return (HBRUSH
)m_background_brush
.GetSafeHandle();
2490 hbr
= CResizableStandAloneDialog::OnCtlColor(pDC
, pWnd
, nCtlColor
);
2492 // TODO: Return a different brush if the default is not desired
2495 LRESULT
CGitProgressDlg::OnCtlColorStatic(WPARAM wParam
, LPARAM lParam
)
2497 HDC hDC
= (HDC
)wParam
;
2498 HWND hwndCtl
= (HWND
)lParam
;
2500 if (::GetDlgCtrlID(hwndCtl
) == IDC_TITLE_ANIMATE
)
2502 CDC
*pDC
= CDC::FromHandle(hDC
);
2503 pDC
->SetBkColor(GetSysColor(COLOR_WINDOW
));
2504 pDC
->SetBkMode(TRANSPARENT
);
2505 return (LRESULT
)(HBRUSH
)m_background_brush
.GetSafeHandle();