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"
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
71 IMPLEMENT_DYNAMIC(CGitProgressDlg
, CResizableStandAloneDialog
)
72 CGitProgressDlg::CGitProgressDlg(CWnd
* pParent
/*=NULL*/)
73 : CResizableStandAloneDialog(CGitProgressDlg::IDD
, pParent
)
76 , m_bErrorsOccurred(false)
78 , m_bNoCheckout(false)
80 , m_Revision(_T("HEAD"))
82 , m_bLockWarning(false)
83 , m_bLockExists(false)
84 , m_bThreadRunning(FALSE
)
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)
94 , m_itemCountTotal(-1)
95 , m_AlwaysConflicted(false)
96 , m_BugTraqProvider(NULL
)
97 , sDryRun(MAKEINTRESOURCE(IDS_PROGRS_DRYRUN
))
98 , sRecordOnly(MAKEINTRESOURCE(IDS_MERGE_RECORDONLY
))
103 CGitProgressDlg::~CGitProgressDlg()
105 for (size_t i
= 0; i
< m_arData
.size(); ++i
)
109 if(m_pThread
!= NULL
)
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
)
126 ON_NOTIFY(NM_DBLCLK
, IDC_SVNPROGRESS
, OnNMDblclkSvnprogress
)
127 ON_NOTIFY(HDN_ITEMCLICK
, 0, OnHdnItemclickSvnprogress
)
130 ON_REGISTERED_MESSAGE(WM_GITPROGRESS
, OnGitProgress
)
132 ON_EN_SETFOCUS(IDC_INFOTEXT
, &CGitProgressDlg::OnEnSetfocusInfotext
)
133 ON_NOTIFY(LVN_BEGINDRAG
, IDC_SVNPROGRESS
, &CGitProgressDlg::OnLvnBegindragSvnprogress
)
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
)
142 BOOL
CGitProgressDlg::Cancel()
147 LRESULT
CGitProgressDlg::OnShowConflictResolver(WPARAM
/*wParam*/, LPARAM
/*lParam*/)
150 CConflictResolveDlg
dlg(this);
151 const svn_wc_conflict_description_t
*description
= (svn_wc_conflict_description_t
*)lParam
;
154 dlg
.SetConflictDescription(description
);
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();
172 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_INDETERMINATE
);
173 return dlg
.GetResult();
176 return svn_wc_conflict_choose_postpone
;
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
;
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.
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;
223 nEnsureVisibleCount
= 0;
225 m_bLastVisible
= false;
230 BOOL
CGitProgressDlg::Notify(const CTGitPath
& path
, git_wc_notify_action_t action
,
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();
247 data
->action
= action
;
248 data
->sPathColumnText
=path
.GetGitPathString();
249 data
->bAuxItem
= false;
251 this->m_Animate
.ShowWindow(SW_HIDE
);
255 data
->mime_type
= mime_type
;
256 data
->content_state
= content_state
;
257 data
->prop_state
= prop_state
;
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
;
267 data
->merge_range
= *range
;
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))
275 // data->color = m_Colors.GetColor(CColors::Conflict);
276 // data->bConflictedActionItem = true;
277 // data->sActionColumnText.LoadString(IDS_SVNACTION_CONFLICTED);
282 // m_bMergesAddsDeletesOccurred = true;
283 data
->sActionColumnText
.LoadString(IDS_SVNACTION_ADD
);
284 data
->color
= m_Colors
.GetColor(CColors::Added
);
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
);
293 case git_wc_notify_sendmail_error
:
294 data
->bAuxItem
= true;
295 data
->sActionColumnText
.LoadString(IDS_SVNACTION_SENDMAIL_ERROR
);
297 data
->sPathColumnText
= *strErr
;
299 data
->sPathColumnText
.Empty();
300 data
->color
= m_Colors
.GetColor(CColors::Modified
);
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
);
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
);
317 case git_wc_notify_resolved
:
318 data
->sActionColumnText
.LoadString(IDS_SVNACTION_RESOLVE
);
321 case git_wc_notify_revert
:
322 data
->sActionColumnText
.LoadString(IDS_SVNACTION_REVERT
);
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;
332 case svn_wc_notify_commit_added
:
333 data
->sActionColumnText
.LoadString(IDS_SVNACTION_ADDING
);
334 data
->color
= m_Colors
.GetColor(CColors::Added
);
336 case svn_wc_notify_copy
:
337 data
->sActionColumnText
.LoadString(IDS_SVNACTION_COPY
);
339 case svn_wc_notify_commit_modified
:
340 data
->sActionColumnText
.LoadString(IDS_SVNACTION_MODIFIED
);
341 data
->color
= m_Colors
.GetColor(CColors::Modified
);
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
);
349 case svn_wc_notify_commit_deleted
:
350 data
->sActionColumnText
.LoadString(IDS_SVNACTION_DELETING
);
351 data
->color
= m_Colors
.GetColor(CColors::Deleted
);
353 case svn_wc_notify_restore
:
354 data
->sActionColumnText
.LoadString(IDS_SVNACTION_RESTORE
);
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
);
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;
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
);
377 data
->sActionColumnText
.LoadString(IDS_SVNACTION_EXISTS
);
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
)))
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;
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
);
414 if (lock_state
== svn_wc_notify_lock_state_unlocked
)
416 CString
temp(MAKEINTRESOURCE(IDS_SVNACTION_UNLOCKED
));
417 data
->sActionColumnText
+= _T(", ") + temp
;
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;
428 case svn_wc_notify_update_completed
:
430 data
->sActionColumnText
.LoadString(IDS_SVNACTION_COMPLETED
);
431 data
->bAuxItem
= true;
432 bool bEmpty
= !!m_ExtStack
.IsEmpty();
434 data
->sPathColumnText
.Format(IDS_PROGRS_PATHATREV
, (LPCTSTR
)m_ExtStack
.RemoveHead(), rev
);
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
);
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
;
456 m_bFinishedItemAdded
= true;
459 case svn_wc_notify_commit_postfix_txdelta
:
460 data
->sActionColumnText
.LoadString(IDS_SVNACTION_POSTFIX
);
462 case svn_wc_notify_failed_revert
:
463 data
->sActionColumnText
.LoadString(IDS_SVNACTION_FAILEDREVERT
);
465 case svn_wc_notify_status_completed
:
466 case svn_wc_notify_status_external
:
467 data
->sActionColumnText
.LoadString(IDS_SVNACTION_STATUS
);
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
);
480 data
->sActionColumnText
.LoadString(IDS_SVNACTION_SKIP
);
482 case svn_wc_notify_locked
:
483 if ((lock
)&&(lock
->owner
))
484 data
->sActionColumnText
.Format(IDS_SVNACTION_LOCKEDBY
, (LPCTSTR
)CUnicodeUtils::GetUnicode(lock
->owner
));
486 case svn_wc_notify_unlocked
:
487 data
->sActionColumnText
.LoadString(IDS_SVNACTION_UNLOCKED
);
489 case svn_wc_notify_failed_lock
:
490 data
->sActionColumnText
.LoadString(IDS_SVNACTION_FAILEDLOCK
);
491 m_arData
.push_back(data
);
493 ReportError(SVN::GetErrorString(err
));
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;
500 case svn_wc_notify_failed_unlock
:
501 data
->sActionColumnText
.LoadString(IDS_SVNACTION_FAILEDUNLOCK
);
502 m_arData
.push_back(data
);
504 ReportError(SVN::GetErrorString(err
));
506 if (err
->apr_err
== SVN_ERR_FS_OUT_OF_DATE
)
507 m_bLockWarning
= true;
509 case svn_wc_notify_changelist_set
:
510 data
->sActionColumnText
.Format(IDS_SVNACTION_CHANGELISTSET
, (LPCTSTR
)data
->changelistname
);
512 case svn_wc_notify_changelist_clear
:
513 data
->sActionColumnText
.LoadString(IDS_SVNACTION_CHANGELISTCLEAR
);
515 case svn_wc_notify_changelist_moved
:
516 data
->sActionColumnText
.Format(IDS_SVNACTION_CHANGELISTMOVED
, (LPCTSTR
)data
->changelistname
);
518 case svn_wc_notify_foreign_merge_begin
:
519 case svn_wc_notify_merge_begin
:
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
);
529 data
->sActionColumnText
.Format(IDS_SVNACTION_MERGEBEGINMULTIPLEREVERSE
, data
->merge_range
.start
, data
->merge_range
.end
+ 1);
530 data
->bAuxItem
= true;
535 } // switch (data->action)
543 m_arData
.push_back(data
);
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
);
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))
562 // bSecondResized = TRUE;
570 CString
CGitProgressDlg::BuildInfoString()
573 if(this->m_Command
== GitProgress_Resolve
)
574 infotext
= _T("You need commit your change after resolve conflict");
591 for (size_t i
=0; i
<m_arData
.size(); ++i
)
593 const NotificationData
* dat
= m_arData
[i
];
596 case svn_wc_notify_add
:
597 case svn_wc_notify_update_add
:
598 case svn_wc_notify_commit_added
:
599 if (dat
->bConflictedActionItem
)
604 case svn_wc_notify_copy
:
607 case svn_wc_notify_delete
:
608 case svn_wc_notify_update_delete
:
609 case svn_wc_notify_commit_deleted
:
612 case svn_wc_notify_restore
:
615 case svn_wc_notify_revert
:
618 case svn_wc_notify_resolved
:
621 case svn_wc_notify_update_update
:
622 if (dat
->bConflictedActionItem
)
624 else if ((dat
->content_state
== svn_wc_notify_state_merged
) || (dat
->prop_state
== svn_wc_notify_state_merged
))
629 case svn_wc_notify_commit_modified
:
632 case svn_wc_notify_skip
:
635 case svn_wc_notify_commit_replaced
:
642 temp
.LoadString(IDS_SVNACTION_CONFLICTED
);
644 temp
.Format(_T(":%d "), conflicted
);
649 temp
.LoadString(IDS_SVNACTION_SKIP
);
651 infotext
.AppendFormat(_T(":%d "), skipped
);
655 temp
.LoadString(IDS_SVNACTION_MERGED
);
657 infotext
.AppendFormat(_T(":%d "), merged
);
661 temp
.LoadString(IDS_SVNACTION_ADD
);
663 infotext
.AppendFormat(_T(":%d "), added
);
667 temp
.LoadString(IDS_SVNACTION_DELETE
);
669 infotext
.AppendFormat(_T(":%d "), deleted
);
673 temp
.LoadString(IDS_SVNACTION_MODIFIED
);
675 infotext
.AppendFormat(_T(":%d "), modified
);
679 temp
.LoadString(IDS_SVNACTION_COPY
);
681 infotext
.AppendFormat(_T(":%d "), copied
);
685 temp
.LoadString(IDS_SVNACTION_REPLACED
);
687 infotext
.AppendFormat(_T(":%d "), replaced
);
691 temp
.LoadString(IDS_SVNACTION_UPDATE
);
693 infotext
.AppendFormat(_T(":%d "), updated
);
697 temp
.LoadString(IDS_SVNACTION_RESTORE
);
699 infotext
.AppendFormat(_T(":%d "), restored
);
703 temp
.LoadString(IDS_SVNACTION_REVERT
);
705 infotext
.AppendFormat(_T(":%d "), reverted
);
709 temp
.LoadString(IDS_SVNACTION_RESOLVE
);
711 infotext
.AppendFormat(_T(":%d "), resolved
);
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();
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
747 linewidth
= m_ProgList
.GetStringWidth(m_arData
[index
]->sActionColumnText
) + 12;
750 linewidth
= m_ProgList
.GetStringWidth(m_arData
[index
]->sPathColumnText
) + 12;
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"));
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;
790 m_ProgList
.DeleteColumn(c
--);
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
);
800 ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED
)));
804 m_pThread
->m_bAutoDelete
= FALSE
;
805 m_pThread
->ResumeThread();
810 // Call this early so that the column headings aren't hidden before any
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
);
830 CenterWindow(CWnd::FromHandle(hWndExplorer
));
831 EnableSaveRestore(_T("GITProgressDlg"));
833 m_background_brush
.CreateSolidBrush(GetSysColor(COLOR_WINDOW
));
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'));
887 data
->sPathColumnText
= sMessage
;
888 data
->sPathColumnText
.Trim(_T("\n\r"));
890 if (sMessage
.Find('\n')>=0)
892 sMessage
= sMessage
.Mid(sMessage
.Find('\n'));
893 sMessage
.Trim(_T("\n\r"));
897 m_arData
.push_back(data
);
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
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
);
924 bSecondResized
= FALSE
;
925 m_bFinishedItemAdded
= false;
926 CTime startTime
= CTime::GetCurrentTime();
929 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_INDETERMINATE
);
933 case GitProgress_Add
:
934 bSuccess
= CmdAdd(sWindowTitle
, localoperation
);
936 case GitProgress_Copy
:
937 bSuccess
= CmdCopy(sWindowTitle
, localoperation
);
939 case GitProgress_Export
:
940 bSuccess
= CmdExport(sWindowTitle
, localoperation
);
942 case GitProgress_Rename
:
943 bSuccess
= CmdRename(sWindowTitle
, localoperation
);
945 case GitProgress_Resolve
:
946 bSuccess
= CmdResolve(sWindowTitle
, localoperation
);
948 case GitProgress_Revert
:
949 bSuccess
= CmdRevert(sWindowTitle
, localoperation
);
951 case GitProgress_Switch
:
952 bSuccess
= CmdSwitch(sWindowTitle
, localoperation
);
954 case GitProgress_SendMail
:
955 bSuccess
= CmdSendMail(sWindowTitle
, localoperation
);
957 case GitProgress_Clone
:
958 bSuccess
= CmdClone(sWindowTitle
, localoperation
);
962 temp
.LoadString(IDS_PROGRS_TITLEFAILED
);
964 temp
.LoadString(IDS_PROGRS_TITLEFIN
);
965 sWindowTitle
= sWindowTitle
+ _T(" ") + temp
;
966 SetWindowText(sWindowTitle
);
968 KillTimer(TRANSFERTIMER
);
969 KillTimer(VISIBLETIMER
);
973 if (DidErrorsOccur())
975 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_ERROR
);
976 m_pTaskbarList
->SetProgressValue(m_hWnd
, 100, 100);
979 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_NOPROGRESS
);
982 DialogEnableWindow(IDCANCEL
, FALSE
);
983 DialogEnableWindow(IDOK
, TRUE
);
985 CString info
= BuildInfoString();
987 info
.LoadString(IDS_PROGRS_INFOFAILED
);
988 SetDlgItemText(IDC_INFOTEXT
, info
);
990 CWnd
* pWndOk
= GetDlgItem(IDOK
);
991 if (pWndOk
&& ::IsWindow(pWndOk
->GetSafeHwnd()))
993 SendMessage(DM_SETDEFID
, IDOK
);
994 GetDlgItem(IDOK
)->SetFocus();
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
);
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
);
1021 int count
= m_ProgList
.GetItemCount();
1022 if ((count
> 0)&&(m_bLastVisible
))
1023 m_ProgList
.EnsureVisible(count
-1, FALSE
);
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
);
1040 m_bCancelled
= TRUE
;
1041 InterlockedExchange(&m_bThreadRunning
, FALSE
);
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
)
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
);
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
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
);
1083 if (m_targetPathList
.GetCount() != 1)
1085 StringRevMap::iterator it
= m_UpdateStartRevMap
.begin();
1086 svn_revnum_t rev
= -1;
1087 if (it
!= m_UpdateStartRevMap
.end())
1092 dlg
.SetParams(m_targetPathList
[0], m_RevisionEnd
, m_RevisionEnd
, rev
, 0, TRUE
);
1098 void CGitProgressDlg::OnClose()
1102 TerminateThread(m_pThread
->m_hThread
, (DWORD
)-1);
1103 InterlockedExchange(&m_bThreadRunning
, FALSE
);
1107 m_bCancelled
= TRUE
;
1110 DialogEnableWindow(IDCANCEL
, TRUE
);
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);
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
);
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
)
1150 lstrcpyn(m_columnbuf
, data
->sActionColumnText
, MAX_PATH
);
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();
1161 CFont
* pFont
= pDC
->SelectObject(m_ProgList
.GetFont());
1162 PathCompactPath(pDC
->GetSafeHdc(), m_columnbuf
, cWidth
);
1163 pDC
->SelectObject(pFont
);
1171 pDispInfo
->item
.pszText
= m_columnbuf
;
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())
1206 const NotificationData
* data
= m_arData
[pLVCD
->nmcd
.dwItemSpec
];
1207 ASSERT(data
!= NULL
);
1211 // Store the color back in the NMLVCUSTOMDRAW struct.
1212 pLVCD
->clrText
= data
->color
;
1216 void CGitProgressDlg::OnNMDblclkSvnprogress(NMHDR
* /*pNMHDR*/, LRESULT
* /*pResult*/)
1219 LPNMLISTVIEW pNMLV
= reinterpret_cast<LPNMLISTVIEW
>(pNMHDR
);
1221 if (pNMLV
->iItem
< 0)
1223 if (m_options
& ProgOptDryRun
)
1224 return; //don't do anything in a dry-run.
1226 const NotificationData
* data
= m_arData
[pNMLV
->iItem
];
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
)
1252 CString cmd
= _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
1253 cmd
+= data
->path
.GetWinPathString() + _T(" ");
1254 CAppUtils::LaunchApplication(cmd
, NULL
, false);
1260 void CGitProgressDlg::OnHdnItemclickSvnprogress(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1262 LPNMHEADER phdr
= reinterpret_cast<LPNMHEADER
>(pNMHDR
);
1263 if (m_bThreadRunning
)
1265 if (m_nSortedColumn
== phdr
->iItem
)
1266 m_bAscending
= !m_bAscending
;
1268 m_bAscending
= TRUE
;
1269 m_nSortedColumn
= phdr
->iItem
;
1273 m_ProgList
.SetRedraw(FALSE
);
1274 m_ProgList
.DeleteAllItems();
1275 m_ProgList
.SetItemCountEx (static_cast<int>(m_arData
.size()));
1277 m_ProgList
.SetRedraw(TRUE
);
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
;
1295 start
= GetCurrentTime();
1296 ds
= stat
->received_bytes
- m_TotalBytesTransferred
;
1297 speed
= ds
* 1000.0/dt
;
1298 m_TotalBytesTransferred
= stat
->received_bytes
;
1305 CProgressCtrl
* progControl
= (CProgressCtrl
*)GetDlgItem(IDC_PROGRESSBAR
);
1308 progress
= stat
->received_objects
+ stat
->indexed_objects
;
1310 if ((stat
->total_objects
> 1000) && (!progControl
->IsWindowVisible()))
1312 progControl
->ShowWindow(SW_SHOW
);
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
);
1323 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_NORMAL
);
1324 m_pTaskbarList
->SetProgressValue(m_hWnd
, progress
, stat
->total_objects
);
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);
1333 m_sTotalBytesTransferred
.Format(IDS_SVN_PROGRESS_TOTALMBTRANSFERRED
, (double)((double)stat
->received_bytes
/ 1024000.0));
1337 str
.Format(_T("%fB/s"), speed
);
1338 else if(speed
< 1024 * 1024)
1339 str
.Format(_T("%.2fKB/s"), speed
/ 1024);
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
);
1349 LRESULT
CGitProgressDlg::OnGitProgress(WPARAM
/*wParam*/, LPARAM
/*lParam*/)
1352 SVNProgress
* pProgressData
= (SVNProgress
*)lParam
;
1353 CProgressCtrl
* progControl
= (CProgressCtrl
*)GetDlgItem(IDC_PROGRESSBAR
);
1354 if ((pProgressData
->total
> 1000)&&(!progControl
->IsWindowVisible()))
1356 progControl
->ShowWindow(SW_SHOW
);
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
);
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
);
1375 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_NORMAL
);
1376 m_pTaskbarList
->SetProgressValue(m_hWnd
, pProgressData
->progress
, pProgressData
->total
);
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);
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
);
1392 void CGitProgressDlg::OnTimer(UINT_PTR nIDEvent
)
1394 if (nIDEvent
== TRANSFERTIMER
)
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)
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
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
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
)
1442 switch (m_nSortedColumn
)
1444 case 0: //action column
1445 result
= pData1
->sActionColumnText
.Compare(pData2
->sActionColumnText
);
1447 case 1: //path column
1448 // Compare happens after switch()
1454 // Sort by path if everything else is equal
1457 result
= CTGitPath::Compare(pData1
->path
, pData2
->path
);
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
));
1477 HCURSOR hCur
= LoadCursor(NULL
, MAKEINTRESOURCE(IDC_ARROW
));
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)
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();
1518 if (GetKeyState(VK_CONTROL
)&0x8000)
1520 //Ctrl-C -> copy to clipboard
1522 POSITION pos
= m_ProgList
.GetFirstSelectedItemPosition();
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*/)
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
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
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
);
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
);
1617 } // if ((data)&&(!data->path.IsDirectory()))
1618 if (m_ProgList
.GetSelectedCount() == 1)
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
);
1634 if (m_ProgList
.GetSelectedCount() > 0)
1637 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1638 popup
.AppendMenuIcon(ID_COPY
, IDS_LOG_POPUP_COPYTOCLIPBOARD
,IDI_COPYCLIP
);
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;
1653 POSITION pos
= m_ProgList
.GetFirstSelectedItemPosition();
1656 int nItem
= m_ProgList
.GetNextSelectedItem(pos
);
1657 NotificationData
* data
= m_arData
[nItem
];
1660 sLines
+= data
->sPathColumnText
;
1661 sLines
+= _T("\r\n");
1665 if (!sLines
.IsEmpty())
1667 CStringUtils::WriteAsciiStringToClipboard(sLines
, GetSafeHwnd());
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
);
1681 svn_revnum_t rev
= -1;
1682 StringRevMap::iterator it
= m_UpdateStartRevMap
.end();
1683 if (data
->basepath
.IsEmpty())
1684 it
= m_UpdateStartRevMap
.begin();
1686 it
= m_UpdateStartRevMap
.find(data
->basepath
.GetSVNApiPath(pool
));
1687 if (it
!= m_UpdateStartRevMap
.end())
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
);
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
);
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();
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);
1726 CTGitPath tempfile
= CTempFiles::Instance().GetTempFilePath(false, data
->path
, rev
);
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
);
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)));
1747 case ID_EDITCONFLICT
:
1749 CString sPath
= GetPathFromColumnText(data
->sPathColumnText
);
1750 SVNDiff::StartConflictEditor(CTGitPath(sPath
));
1753 case ID_CONFLICTUSETHEIRS
:
1754 case ID_CONFLICTUSEMINE
:
1755 case ID_CONFLICTRESOLVE
:
1757 svn_wc_conflict_choice_t result
= svn_wc_conflict_choose_merged
;
1760 case ID_CONFLICTUSETHEIRS
:
1761 result
= svn_wc_conflict_choose_theirs_full
;
1763 case ID_CONFLICTUSEMINE
:
1764 result
= svn_wc_conflict_choose_mine_full
;
1766 case ID_CONFLICTRESOLVE
:
1767 result
= svn_wc_conflict_choose_merged
;
1771 POSITION pos
= m_ProgList
.GetFirstSelectedItemPosition();
1772 CString sResolvedPaths
;
1775 int nItem
= m_ProgList
.GetNextSelectedItem(pos
);
1776 NotificationData
* data
= m_arData
[nItem
];
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
);
1789 data
->color
= ::GetSysColor(COLOR_WINDOWTEXT
);
1790 data
->action
= svn_wc_notify_resolved
;
1791 data
->sActionColumnText
.LoadString(IDS_SVNACTION_RESOLVE
);
1792 data
->bConflictedActionItem
= false;
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())
1817 msg
.Format(IDS_SVNPROGRESS_RESOLVED
, (LPCTSTR
)sResolvedPaths
);
1818 CMessageBox::Show(m_hWnd
, msg
, _T("TortoiseGit"), MB_OK
| MB_ICONINFORMATION
);
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())
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
1835 CString sPath
= GetPathFromColumnText(data
->sPathColumnText
);
1836 dlg
.SetParams(CTGitPath(sPath
), SVNRev(), SVNRev::REV_HEAD
, 1, -1, TRUE
);
1845 CString sWinPath
= GetPathFromColumnText(data
->sPathColumnText
);
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);
1865 void CGitProgressDlg::OnEnSetfocusInfotext()
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);
1877 int selIndex
= m_ProgList
.GetSelectionMark();
1881 CDropFiles dropFiles
; // class for creating DROPFILES struct
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();
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
)
1913 int count
= m_ProgList
.GetItemCount();
1915 m_ProgList
.EnsureVisible(count
-1, false);
1919 //////////////////////////////////////////////////////////////////////////
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
;
1935 CStringA gitdir
= CUnicodeUtils::GetMulti(CTGitPath(g_Git
.m_CurrentDir
).GetGitPathString(), CP_UTF8
);
1936 if (git_repository_open(&repo
, gitdir
.GetBuffer()))
1938 gitdir
.ReleaseBuffer();
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();
1952 git_config_free(config
);
1953 git_repository_free(repo
);
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();
1965 git_config_free(config
);
1966 git_repository_free(repo
);
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();
1979 git_config_free(config
);
1980 git_repository_free(repo
);
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();
1993 git_config_free(config
);
1994 git_repository_free(repo
);
1997 systemConfigA
.ReleaseBuffer();
2000 git_repository_set_config(repo
, config
);
2002 if (git_repository_index(&index
, repo
))
2005 git_repository_free(repo
);
2008 if (git_index_read(index
))
2011 git_index_free(index
);
2012 git_repository_free(repo
);
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()))
2021 git_index_free(index
);
2022 git_repository_free(repo
);
2025 Notify(m_targetPathList
[i
],git_wc_notify_add
);
2028 if (git_index_write(index
))
2031 git_index_free(index
);
2032 git_repository_free(repo
);
2036 git_index_free(index
);
2037 git_repository_free(repo
);
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
);
2052 bool CGitProgressDlg::CmdCopy(CString
& /*sWindowTitle*/, bool& /*localoperation*/)
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
);
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
))
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
))
2088 if (SVN::PathIsURL(m_url
))
2090 CString
sMsg(MAKEINTRESOURCE(IDS_PROGRS_COPY_WARNING
));
2091 ReportNotification(sMsg
);
2098 bool CGitProgressDlg::CmdExport(CString
& /*sWindowTitle*/, bool& /*localoperation*/)
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
);
2107 if (m_options
& ProgOptEolCRLF
)
2109 if (m_options
& ProgOptEolLF
)
2111 if (m_options
& ProgOptEolCR
)
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
))
2123 bool CGitProgressDlg::CmdRename(CString
& /*sWindowTitle*/, bool& /*localoperation*/)
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
))
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;
2164 CAppUtils::RemoveTempMergeFile((CTGitPath
&)m_targetPathList
[i
]);
2166 Notify(m_targetPathList
[i
],git_wc_notify_resolved
);
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)
2191 catch (CFileException
* pE
)
2193 TRACE(_T("CFileException in Resolve!\n"));
2194 TCHAR error
[10000] = {0};
2195 pE
->GetErrorMessage(error
, 10000);
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);
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);
2217 CShellUpdater::Instance().AddPathsForUpdate(m_targetPathList
);
2219 this->GetDlgItem(IDC_LOGBUTTON
)->SetWindowText(CString(MAKEINTRESOURCE(IDS_COMMITBUTTON
)));
2220 this->GetDlgItem(IDC_LOGBUTTON
)->ShowWindow(SW_SHOW
);
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
)
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;
2257 Notify(m_selectedPaths
[i
],git_wc_notify_revert
);
2260 CShellUpdater::Instance().AddPathsForUpdate(m_selectedPaths
);
2265 bool CGitProgressDlg::CmdSwitch(CString
& /*sWindowTitle*/, bool& /*localoperation*/)
2268 ASSERT(m_targetPathList
.GetCount() == 1);
2270 sWindowTitle
.LoadString(IDS_PROGRS_TITLE_SWITCH
);
2271 SetWindowText(sWindowTitle
); // needs to be updated, see TSVN rev. 21375
2272 SetBackgroundImage(IDI_SWITCH_BKG
);
2274 if (st
.GetStatus(m_targetPathList
[0]) != (-2))
2276 if (st
.status
->entry
!= NULL
)
2278 rev
= st
.status
->entry
->revision
;
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
))
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
);
2305 bool CGitProgressDlg::CmdClone(CString
& sWindowTitle
, bool& /*localoperation*/)
2307 if (!g_Git
.UsingLibGit2(CGit::GIT_CMD_CLONE
))
2309 // should never run to here
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)
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
;
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
);
2354 m_Animate
.ShowWindow(SW_HIDE
);
2356 git_remote_free(origin
);
2362 else if (cloned_repo
)
2363 git_repository_free(cloned_repo
);
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
);
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
)));
2393 if(this->m_SendMailFlags
&SENDMAIL_COMBINED
)
2397 Notify(path
,git_wc_notify_sendmail_start
);
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
);
2414 Notify(path
,git_wc_notify_sendmail_retry
,ret
,&err
);
2419 str
.LoadString(IDS_SVN_USERCANCELLED
);
2420 Notify(path
,git_wc_notify_sendmail_error
,ret
,&str
);
2425 Notify(path
,git_wc_notify_sendmail_done
,ret
);
2429 for (int i
= 0; ret
&& i
< m_targetPathList
.GetCount(); ++i
)
2432 Notify(m_targetPathList
[i
],git_wc_notify_sendmail_start
);
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
);
2451 Notify(m_targetPathList
[i
],git_wc_notify_sendmail_retry
,ret
,&patch
.m_LastError
);
2456 str
.LoadString(IDS_SVN_USERCANCELLED
);
2457 Notify(m_targetPathList
[i
],git_wc_notify_sendmail_error
,ret
,&str
);
2462 Notify(m_targetPathList
[i
],git_wc_notify_sendmail_done
,ret
);
2468 LRESULT
CGitProgressDlg::OnTaskbarBtnCreated(WPARAM
/*wParam*/, LPARAM
/*lParam*/)
2470 m_pTaskbarList
.Release();
2471 m_pTaskbarList
.CoCreateInstance(CLSID_TaskbarList
);
2475 HBRUSH
CGitProgressDlg::OnCtlColor(CDC
* pDC
, CWnd
* pWnd
, UINT nCtlColor
)
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();
2485 hbr
= CResizableStandAloneDialog::OnCtlColor(pDC
, pWnd
, nCtlColor
);
2487 // TODO: Return a different brush if the default is not desired
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();