renamed class name of MassiveGitTask to CMassiveGitTask
[TortoiseGit.git] / src / TortoiseProc / GitProgressDlg.cpp
blobed28978be5ebeaeaab82b61dec5676d2ced556bd
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2012 - TortoiseGit
4 // Copyright (C) 2003-2008 - TortoiseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "stdafx.h"
21 #include "TortoiseProc.h"
22 #include "messagebox.h"
23 #include "GITProgressDlg.h"
24 #include "LogDlg.h"
25 #include "TGitPath.h"
26 #include "Registry.h"
27 #include "GitStatus.h"
28 #include "AppUtils.h"
29 #include "PathUtils.h"
30 #include "StringUtils.h"
31 #include "TempFile.h"
32 #include "UnicodeUtils.h"
33 #include "SoundUtils.h"
34 #include "GitDiff.h"
35 #include "Hooks.h"
36 #include "DropFiles.h"
37 //#include "GitLogHelper.h"
38 #include "RegHistory.h"
39 //#include "ConflictResolveDlg.h"
40 #include "LogFile.h"
41 #include "ShellUpdater.h"
42 #include "IconMenu.h"
43 #include "BugTraqAssociations.h"
44 #include "patch.h"
45 #include "MassiveGitTask.h"
46 #include "git2.h"
47 #include "SmartHandle.h"
49 static UINT WM_GITPROGRESS = RegisterWindowMessage(_T("TORTOISEGIT_GITPROGRESS_MSG"));
51 BOOL CGitProgressDlg::m_bAscending = FALSE;
52 int CGitProgressDlg::m_nSortedColumn = -1;
54 #define TRANSFERTIMER 100
55 #define VISIBLETIMER 101
57 enum GITProgressDlgContextMenuCommands
59 // needs to start with 1, since 0 is the return value if *nothing* is clicked on in the context menu
60 ID_COMPARE = 1,
61 ID_EDITCONFLICT,
62 ID_CONFLICTRESOLVE,
63 ID_CONFLICTUSETHEIRS,
64 ID_CONFLICTUSEMINE,
65 ID_LOG,
66 ID_OPEN,
67 ID_OPENWITH,
68 ID_EXPLORE,
69 ID_COPY
72 IMPLEMENT_DYNAMIC(CGitProgressDlg, CResizableStandAloneDialog)
73 CGitProgressDlg::CGitProgressDlg(CWnd* pParent /*=NULL*/)
74 : CResizableStandAloneDialog(CGitProgressDlg::IDD, pParent)
75 , m_bCancelled(FALSE)
76 , m_pThread(NULL)
77 #if 0
78 , m_Revision(_T("HEAD"))
79 //, m_RevisionEnd(0)
80 , m_bLockWarning(false)
81 , m_bLockExists(false)
82 , m_bThreadRunning(FALSE)
83 , m_nConflicts(0)
84 , m_bErrorsOccurred(FALSE)
85 , m_bMergesAddsDeletesOccurred(FALSE)
87 , m_options(ProgOptNone)
88 , m_dwCloseOnEnd((DWORD)-1)
89 , m_bFinishedItemAdded(false)
90 , m_bLastVisible(false)
91 // , m_depth(svn_depth_unknown)
92 , m_itemCount(-1)
93 , m_itemCountTotal(-1)
94 , m_AlwaysConflicted(false)
95 , m_BugTraqProvider(NULL)
96 , sIgnoredIncluded(MAKEINTRESOURCE(IDS_PROGRS_IGNOREDINCLUDED))
97 , sExtExcluded(MAKEINTRESOURCE(IDS_PROGRS_EXTERNALSEXCLUDED))
98 , sExtIncluded(MAKEINTRESOURCE(IDS_PROGRS_EXTERNALSINCLUDED))
99 , sIgnoreAncestry(MAKEINTRESOURCE(IDS_PROGRS_IGNOREANCESTRY))
100 , sRespectAncestry(MAKEINTRESOURCE(IDS_PROGRS_RESPECTANCESTRY))
101 , sDryRun(MAKEINTRESOURCE(IDS_PROGRS_DRYRUN))
102 , sRecordOnly(MAKEINTRESOURCE(IDS_MERGE_RECORDONLY))
103 #endif
107 CGitProgressDlg::~CGitProgressDlg()
109 for (size_t i=0; i<m_arData.size(); i++)
111 delete m_arData[i];
113 if(m_pThread != NULL)
115 delete m_pThread;
119 void CGitProgressDlg::DoDataExchange(CDataExchange* pDX)
121 CResizableStandAloneDialog::DoDataExchange(pDX);
122 DDX_Control(pDX, IDC_SVNPROGRESS, m_ProgList);
125 BEGIN_MESSAGE_MAP(CGitProgressDlg, CResizableStandAloneDialog)
126 ON_BN_CLICKED(IDC_LOGBUTTON, OnBnClickedLogbutton)
127 ON_NOTIFY(NM_CUSTOMDRAW, IDC_SVNPROGRESS, OnNMCustomdrawSvnprogress)
128 ON_WM_CLOSE()
129 ON_NOTIFY(NM_DBLCLK, IDC_SVNPROGRESS, OnNMDblclkSvnprogress)
130 ON_NOTIFY(HDN_ITEMCLICK, 0, OnHdnItemclickSvnprogress)
131 ON_WM_SETCURSOR()
132 ON_WM_CONTEXTMENU()
133 ON_REGISTERED_MESSAGE(WM_GITPROGRESS, OnGitProgress)
134 ON_WM_TIMER()
135 ON_EN_SETFOCUS(IDC_INFOTEXT, &CGitProgressDlg::OnEnSetfocusInfotext)
136 ON_NOTIFY(LVN_BEGINDRAG, IDC_SVNPROGRESS, &CGitProgressDlg::OnLvnBegindragSvnprogress)
137 ON_WM_SIZE()
138 ON_NOTIFY(LVN_GETDISPINFO, IDC_SVNPROGRESS, &CGitProgressDlg::OnLvnGetdispinfoSvnprogress)
139 ON_BN_CLICKED(IDC_NONINTERACTIVE, &CGitProgressDlg::OnBnClickedNoninteractive)
140 ON_MESSAGE(WM_SHOWCONFLICTRESOLVER, OnShowConflictResolver)
141 ON_REGISTERED_MESSAGE(WM_TASKBARBTNCREATED, OnTaskbarBtnCreated)
142 END_MESSAGE_MAP()
144 BOOL CGitProgressDlg::Cancel()
146 return m_bCancelled;
149 LRESULT CGitProgressDlg::OnShowConflictResolver(WPARAM /*wParam*/, LPARAM /*lParam*/)
151 #if 0
152 CConflictResolveDlg dlg(this);
153 const svn_wc_conflict_description_t *description = (svn_wc_conflict_description_t *)lParam;
154 if (description)
156 dlg.SetConflictDescription(description);
157 if (m_pTaskbarList)
159 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_PAUSED);
161 if (dlg.DoModal() == IDOK)
163 if (dlg.GetResult() == svn_wc_conflict_choose_postpone)
165 // if the result is conflicted and the dialog returned IDOK,
166 // that means we should not ask again in case of a conflict
167 m_AlwaysConflicted = true;
168 ::SendMessage(GetDlgItem(IDC_NONINTERACTIVE)->GetSafeHwnd(), BM_SETCHECK, BST_CHECKED, 0);
171 m_mergedfile = dlg.GetMergedFile();
172 m_bCancelled = dlg.IsCancelled();
173 if (m_pTaskbarList)
174 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_INDETERMINATE);
175 return dlg.GetResult();
178 return svn_wc_conflict_choose_postpone;
179 #endif
180 return 0;
182 #if 0
183 svn_wc_conflict_choice_t CGitProgressDlg::ConflictResolveCallback(const svn_wc_conflict_description_t *description, CString& mergedfile)
185 // we only bother the user when merging
186 if (((m_Command == GitProgress_Merge)||(m_Command == GitProgress_MergeAll)||(m_Command == GitProgress_MergeReintegrate))&&(!m_AlwaysConflicted)&&(description))
188 // we're in a worker thread here. That means we must not show a dialog from the thread
189 // but let the UI thread do it.
190 // To do that, we send a message to the UI thread and let it show the conflict resolver dialog.
191 LRESULT dlgResult = ::SendMessage(GetSafeHwnd(), WM_SHOWCONFLICTRESOLVER, 0, (LPARAM)description);
192 mergedfile = m_mergedfile;
193 return (svn_wc_conflict_choice_t)dlgResult;
196 return svn_wc_conflict_choose_postpone;
198 #endif
199 void CGitProgressDlg::AddItemToList()
201 int totalcount = m_ProgList.GetItemCount();
203 m_ProgList.SetItemCountEx(totalcount+1, LVSICF_NOSCROLL|LVSICF_NOINVALIDATEALL);
204 // make columns width fit
205 if (iFirstResized < 30)
207 // only resize the columns for the first 30 or so entries.
208 // after that, don't resize them anymore because that's an
209 // expensive function call and the columns will be sized
210 // close enough already.
211 ResizeColumns();
212 iFirstResized++;
215 // Make sure the item is *entirely* visible even if the horizontal
216 // scroll bar is visible.
217 int count = m_ProgList.GetCountPerPage();
218 if (totalcount <= (m_ProgList.GetTopIndex() + count + nEnsureVisibleCount + 2))
220 nEnsureVisibleCount++;
221 m_bLastVisible = true;
223 else
225 nEnsureVisibleCount = 0;
226 if (IsIconic() == 0)
227 m_bLastVisible = false;
232 BOOL CGitProgressDlg::Notify(const CTGitPath& path, git_wc_notify_action_t action,
233 int /*status*/ ,
234 CString *strErr
236 svn_node_kind_t kind, const CString& mime_type,
237 svn_wc_notify_state_t content_state,
238 svn_wc_notify_state_t prop_state, LONG rev,
239 const svn_lock_t * lock, svn_wc_notify_lock_state_t lock_state,
240 const CString& changelistname,
241 svn_merge_range_t * range,
242 svn_error_t * err, apr_pool_t * pool
245 bool bNoNotify = false;
246 bool bDoAddData = true;
247 NotificationData * data = new NotificationData();
248 data->path = path;
249 data->action = action;
250 data->sPathColumnText=path.GetGitPathString();
251 data->bAuxItem = false;
252 #if 0
253 data->kind = kind;
254 data->mime_type = mime_type;
255 data->content_state = content_state;
256 data->prop_state = prop_state;
257 data->rev = rev;
258 data->lock_state = lock_state;
259 data->changelistname = changelistname;
260 if ((lock)&&(lock->owner))
261 data->owner = CUnicodeUtils::GetUnicode(lock->owner);
262 data->sPathColumnText = path.GetUIPathString();
263 if (!m_basePath.IsEmpty())
264 data->basepath = m_basePath;
265 if (range)
266 data->merge_range = *range;
267 #endif
268 switch (data->action)
270 case git_wc_notify_add:
271 //case svn_wc_notify_update_add:
272 // if ((data->content_state == svn_wc_notify_state_conflicted) || (data->prop_state == svn_wc_notify_state_conflicted))
273 // {
274 // data->color = m_Colors.GetColor(CColors::Conflict);
275 // data->bConflictedActionItem = true;
276 // data->sActionColumnText.LoadString(IDS_SVNACTION_CONFLICTED);
277 // m_nConflicts++;
278 // }
279 // else
280 // {
281 // m_bMergesAddsDeletesOccurred = true;
282 data->sActionColumnText.LoadString(IDS_SVNACTION_ADD);
283 data->color = m_Colors.GetColor(CColors::Added);
284 // }
285 break;
286 case git_wc_notify_sendmail_start:
287 data->bAuxItem = true;
288 data->sActionColumnText.LoadString(IDS_SVNACTION_SENDMAIL_START);
289 data->color = m_Colors.GetColor(CColors::Modified);
290 break;
292 case git_wc_notify_sendmail_error:
293 data->bAuxItem = true;
294 data->sActionColumnText.LoadString(IDS_SVNACTION_SENDMAIL_ERROR);
295 if(strErr)
296 data->sPathColumnText = *strErr;
297 else
298 data->sPathColumnText.Empty();
299 data->color = m_Colors.GetColor(CColors::Modified);
300 break;
302 case git_wc_notify_sendmail_done:
304 data->sActionColumnText.LoadString(IDS_SVNACTION_SENDMAIL_DONE);
305 data->sPathColumnText.Empty();
306 data->color = m_Colors.GetColor(CColors::Modified);
307 break;
309 case git_wc_notify_sendmail_retry:
310 data->sActionColumnText.LoadString(IDS_SVNACTION_SENDMAIL_RETRY);
311 data->sPathColumnText.Empty();
312 data->color = m_Colors.GetColor(CColors::Modified);
313 break;
316 case git_wc_notify_resolved:
317 data->sActionColumnText.LoadString(IDS_SVNACTION_RESOLVE);
318 break;
320 case git_wc_notify_revert:
321 data->sActionColumnText.LoadString(IDS_SVNACTION_REVERT);
322 break;
324 #if 0
325 case svn_wc_notify_commit_added:
326 data->sActionColumnText.LoadString(IDS_SVNACTION_ADDING);
327 data->color = m_Colors.GetColor(CColors::Added);
328 break;
329 case svn_wc_notify_copy:
330 data->sActionColumnText.LoadString(IDS_SVNACTION_COPY);
331 break;
332 case svn_wc_notify_commit_modified:
333 data->sActionColumnText.LoadString(IDS_SVNACTION_MODIFIED);
334 data->color = m_Colors.GetColor(CColors::Modified);
335 break;
336 case svn_wc_notify_delete:
337 case svn_wc_notify_update_delete:
338 data->sActionColumnText.LoadString(IDS_SVNACTION_DELETE);
339 m_bMergesAddsDeletesOccurred = true;
340 data->color = m_Colors.GetColor(CColors::Deleted);
341 break;
342 case svn_wc_notify_commit_deleted:
343 data->sActionColumnText.LoadString(IDS_SVNACTION_DELETING);
344 data->color = m_Colors.GetColor(CColors::Deleted);
345 break;
346 case svn_wc_notify_restore:
347 data->sActionColumnText.LoadString(IDS_SVNACTION_RESTORE);
348 break;
350 case svn_wc_notify_update_replace:
351 case svn_wc_notify_commit_replaced:
352 data->sActionColumnText.LoadString(IDS_SVNACTION_REPLACED);
353 data->color = m_Colors.GetColor(CColors::Deleted);
354 break;
355 case svn_wc_notify_exists:
356 if ((data->content_state == svn_wc_notify_state_conflicted) || (data->prop_state == svn_wc_notify_state_conflicted))
358 data->color = m_Colors.GetColor(CColors::Conflict);
359 data->bConflictedActionItem = true;
360 m_nConflicts++;
361 data->sActionColumnText.LoadString(IDS_SVNACTION_CONFLICTED);
363 else if ((data->content_state == svn_wc_notify_state_merged) || (data->prop_state == svn_wc_notify_state_merged))
365 data->color = m_Colors.GetColor(CColors::Merged);
366 m_bMergesAddsDeletesOccurred = true;
367 data->sActionColumnText.LoadString(IDS_SVNACTION_MERGED);
369 else
370 data->sActionColumnText.LoadString(IDS_SVNACTION_EXISTS);
371 break;
372 case svn_wc_notify_update_update:
373 // if this is an inoperative dir change, don't show the notification.
374 // an inoperative dir change is when a directory gets updated without
375 // any real change in either text or properties.
376 if ((kind == svn_node_dir)
377 && ((prop_state == svn_wc_notify_state_inapplicable)
378 || (prop_state == svn_wc_notify_state_unknown)
379 || (prop_state == svn_wc_notify_state_unchanged)))
381 bNoNotify = true;
382 break;
384 if ((data->content_state == svn_wc_notify_state_conflicted) || (data->prop_state == svn_wc_notify_state_conflicted))
386 data->color = m_Colors.GetColor(CColors::Conflict);
387 data->bConflictedActionItem = true;
388 m_nConflicts++;
389 data->sActionColumnText.LoadString(IDS_SVNACTION_CONFLICTED);
391 else if ((data->content_state == svn_wc_notify_state_merged) || (data->prop_state == svn_wc_notify_state_merged))
393 data->color = m_Colors.GetColor(CColors::Merged);
394 m_bMergesAddsDeletesOccurred = true;
395 data->sActionColumnText.LoadString(IDS_SVNACTION_MERGED);
397 else if (((data->content_state != svn_wc_notify_state_unchanged)&&(data->content_state != svn_wc_notify_state_unknown)) ||
398 ((data->prop_state != svn_wc_notify_state_unchanged)&&(data->prop_state != svn_wc_notify_state_unknown)))
400 data->sActionColumnText.LoadString(IDS_SVNACTION_UPDATE);
402 else
404 bNoNotify = true;
405 break;
407 if (lock_state == svn_wc_notify_lock_state_unlocked)
409 CString temp(MAKEINTRESOURCE(IDS_SVNACTION_UNLOCKED));
410 data->sActionColumnText += _T(", ") + temp;
412 break;
414 case svn_wc_notify_update_external:
415 // For some reason we build a list of externals...
416 m_ExtStack.AddHead(path.GetUIPathString());
417 data->sActionColumnText.LoadString(IDS_SVNACTION_EXTERNAL);
418 data->bAuxItem = true;
419 break;
421 case svn_wc_notify_update_completed:
423 data->sActionColumnText.LoadString(IDS_SVNACTION_COMPLETED);
424 data->bAuxItem = true;
425 bool bEmpty = !!m_ExtStack.IsEmpty();
426 if (!bEmpty)
427 data->sPathColumnText.Format(IDS_PROGRS_PATHATREV, (LPCTSTR)m_ExtStack.RemoveHead(), rev);
428 else
429 data->sPathColumnText.Format(IDS_PROGRS_ATREV, rev);
431 if ((m_nConflicts>0)&&(bEmpty))
433 // We're going to add another aux item - let's shove this current onto the list first
434 // I don't really like this, but it will do for the moment.
435 m_arData.push_back(data);
436 AddItemToList();
438 data = new NotificationData();
439 data->bAuxItem = true;
440 data->sActionColumnText.LoadString(IDS_PROGRS_CONFLICTSOCCURED_WARNING);
441 data->sPathColumnText.LoadString(IDS_PROGRS_CONFLICTSOCCURED);
442 data->color = m_Colors.GetColor(CColors::Conflict);
443 CSoundUtils::PlayTSVNWarning();
444 // This item will now be added after the switch statement
446 if (!m_basePath.IsEmpty())
447 m_FinishedRevMap[m_basePath.GetSVNApiPath(pool)] = rev;
448 m_RevisionEnd = rev;
449 m_bFinishedItemAdded = true;
451 break;
452 case svn_wc_notify_commit_postfix_txdelta:
453 data->sActionColumnText.LoadString(IDS_SVNACTION_POSTFIX);
454 break;
455 case svn_wc_notify_failed_revert:
456 data->sActionColumnText.LoadString(IDS_SVNACTION_FAILEDREVERT);
457 break;
458 case svn_wc_notify_status_completed:
459 case svn_wc_notify_status_external:
460 data->sActionColumnText.LoadString(IDS_SVNACTION_STATUS);
461 break;
462 case svn_wc_notify_skip:
463 if ((content_state == svn_wc_notify_state_missing)||(content_state == svn_wc_notify_state_obstructed)||(content_state == svn_wc_notify_state_conflicted))
465 data->sActionColumnText.LoadString(IDS_SVNACTION_SKIPMISSING);
467 // The color settings dialog describes the red color with
468 // "possible or real conflict / obstructed" which also applies to
469 // skipped targets during a merge. So we just use the same color.
470 data->color = m_Colors.GetColor(CColors::Conflict);
472 else
473 data->sActionColumnText.LoadString(IDS_SVNACTION_SKIP);
474 break;
475 case svn_wc_notify_locked:
476 if ((lock)&&(lock->owner))
477 data->sActionColumnText.Format(IDS_SVNACTION_LOCKEDBY, (LPCTSTR)CUnicodeUtils::GetUnicode(lock->owner));
478 break;
479 case svn_wc_notify_unlocked:
480 data->sActionColumnText.LoadString(IDS_SVNACTION_UNLOCKED);
481 break;
482 case svn_wc_notify_failed_lock:
483 data->sActionColumnText.LoadString(IDS_SVNACTION_FAILEDLOCK);
484 m_arData.push_back(data);
485 AddItemToList();
486 ReportError(SVN::GetErrorString(err));
487 bDoAddData = false;
488 if (err->apr_err == SVN_ERR_FS_OUT_OF_DATE)
489 m_bLockWarning = true;
490 if (err->apr_err == SVN_ERR_FS_PATH_ALREADY_LOCKED)
491 m_bLockExists = true;
492 break;
493 case svn_wc_notify_failed_unlock:
494 data->sActionColumnText.LoadString(IDS_SVNACTION_FAILEDUNLOCK);
495 m_arData.push_back(data);
496 AddItemToList();
497 ReportError(SVN::GetErrorString(err));
498 bDoAddData = false;
499 if (err->apr_err == SVN_ERR_FS_OUT_OF_DATE)
500 m_bLockWarning = true;
501 break;
502 case svn_wc_notify_changelist_set:
503 data->sActionColumnText.Format(IDS_SVNACTION_CHANGELISTSET, (LPCTSTR)data->changelistname);
504 break;
505 case svn_wc_notify_changelist_clear:
506 data->sActionColumnText.LoadString(IDS_SVNACTION_CHANGELISTCLEAR);
507 break;
508 case svn_wc_notify_changelist_moved:
509 data->sActionColumnText.Format(IDS_SVNACTION_CHANGELISTMOVED, (LPCTSTR)data->changelistname);
510 break;
511 case svn_wc_notify_foreign_merge_begin:
512 case svn_wc_notify_merge_begin:
513 if (range == NULL)
514 data->sActionColumnText.LoadString(IDS_SVNACTION_MERGEBEGINNONE);
515 else if ((data->merge_range.start == data->merge_range.end) || (data->merge_range.start == data->merge_range.end - 1))
516 data->sActionColumnText.Format(IDS_SVNACTION_MERGEBEGINSINGLE, data->merge_range.end);
517 else if (data->merge_range.start - 1 == data->merge_range.end)
518 data->sActionColumnText.Format(IDS_SVNACTION_MERGEBEGINSINGLEREVERSE, data->merge_range.start);
519 else if (data->merge_range.start < data->merge_range.end)
520 data->sActionColumnText.Format(IDS_SVNACTION_MERGEBEGINMULTIPLE, data->merge_range.start + 1, data->merge_range.end);
521 else
522 data->sActionColumnText.Format(IDS_SVNACTION_MERGEBEGINMULTIPLEREVERSE, data->merge_range.start, data->merge_range.end + 1);
523 data->bAuxItem = true;
524 break;
525 #endif
526 default:
527 break;
528 } // switch (data->action)
530 if (bNoNotify)
531 delete data;
532 else
534 if (bDoAddData)
536 m_arData.push_back(data);
537 AddItemToList();
538 if ((!data->bAuxItem) && (m_itemCount > 0))
540 m_itemCount--;
542 CProgressCtrl * progControl = (CProgressCtrl *)GetDlgItem(IDC_PROGRESSBAR);
543 progControl->ShowWindow(SW_SHOW);
544 progControl->SetPos(m_itemCountTotal - m_itemCount);
545 progControl->SetRange32(0, m_itemCountTotal);
546 if (m_pTaskbarList)
548 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
549 m_pTaskbarList->SetProgressValue(m_hWnd, m_itemCountTotal-m_itemCount, m_itemCountTotal);
553 //if ((action == svn_wc_notify_commit_postfix_txdelta)&&(bSecondResized == FALSE))
555 // ResizeColumns();
556 // bSecondResized = TRUE;
560 return TRUE;
564 CString CGitProgressDlg::BuildInfoString()
566 CString infotext;
567 if(this->m_Command == GitProgress_Resolve)
568 infotext = _T("You need commit your change after resolve conflict");
569 #if 0
571 CString temp;
572 int added = 0;
573 int copied = 0;
574 int deleted = 0;
575 int restored = 0;
576 int reverted = 0;
577 int resolved = 0;
578 int conflicted = 0;
579 int updated = 0;
580 int merged = 0;
581 int modified = 0;
582 int skipped = 0;
583 int replaced = 0;
585 for (size_t i=0; i<m_arData.size(); ++i)
587 const NotificationData * dat = m_arData[i];
588 switch (dat->action)
590 case svn_wc_notify_add:
591 case svn_wc_notify_update_add:
592 case svn_wc_notify_commit_added:
593 if (dat->bConflictedActionItem)
594 conflicted++;
595 else
596 added++;
597 break;
598 case svn_wc_notify_copy:
599 copied++;
600 break;
601 case svn_wc_notify_delete:
602 case svn_wc_notify_update_delete:
603 case svn_wc_notify_commit_deleted:
604 deleted++;
605 break;
606 case svn_wc_notify_restore:
607 restored++;
608 break;
609 case svn_wc_notify_revert:
610 reverted++;
611 break;
612 case svn_wc_notify_resolved:
613 resolved++;
614 break;
615 case svn_wc_notify_update_update:
616 if (dat->bConflictedActionItem)
617 conflicted++;
618 else if ((dat->content_state == svn_wc_notify_state_merged) || (dat->prop_state == svn_wc_notify_state_merged))
619 merged++;
620 else
621 updated++;
622 break;
623 case svn_wc_notify_commit_modified:
624 modified++;
625 break;
626 case svn_wc_notify_skip:
627 skipped++;
628 break;
629 case svn_wc_notify_commit_replaced:
630 replaced++;
631 break;
634 if (conflicted)
636 temp.LoadString(IDS_SVNACTION_CONFLICTED);
637 infotext += temp;
638 temp.Format(_T(":%d "), conflicted);
639 infotext += temp;
641 if (skipped)
643 temp.LoadString(IDS_SVNACTION_SKIP);
644 infotext += temp;
645 infotext.AppendFormat(_T(":%d "), skipped);
647 if (merged)
649 temp.LoadString(IDS_SVNACTION_MERGED);
650 infotext += temp;
651 infotext.AppendFormat(_T(":%d "), merged);
653 if (added)
655 temp.LoadString(IDS_SVNACTION_ADD);
656 infotext += temp;
657 infotext.AppendFormat(_T(":%d "), added);
659 if (deleted)
661 temp.LoadString(IDS_SVNACTION_DELETE);
662 infotext += temp;
663 infotext.AppendFormat(_T(":%d "), deleted);
665 if (modified)
667 temp.LoadString(IDS_SVNACTION_MODIFIED);
668 infotext += temp;
669 infotext.AppendFormat(_T(":%d "), modified);
671 if (copied)
673 temp.LoadString(IDS_SVNACTION_COPY);
674 infotext += temp;
675 infotext.AppendFormat(_T(":%d "), copied);
677 if (replaced)
679 temp.LoadString(IDS_SVNACTION_REPLACED);
680 infotext += temp;
681 infotext.AppendFormat(_T(":%d "), replaced);
683 if (updated)
685 temp.LoadString(IDS_SVNACTION_UPDATE);
686 infotext += temp;
687 infotext.AppendFormat(_T(":%d "), updated);
689 if (restored)
691 temp.LoadString(IDS_SVNACTION_RESTORE);
692 infotext += temp;
693 infotext.AppendFormat(_T(":%d "), restored);
695 if (reverted)
697 temp.LoadString(IDS_SVNACTION_REVERT);
698 infotext += temp;
699 infotext.AppendFormat(_T(":%d "), reverted);
701 if (resolved)
703 temp.LoadString(IDS_SVNACTION_RESOLVE);
704 infotext += temp;
705 infotext.AppendFormat(_T(":%d "), resolved);
707 #endif
708 return infotext;
711 void CGitProgressDlg::SetSelectedList(const CTGitPathList& selPaths)
713 m_selectedPaths = selPaths;
716 void CGitProgressDlg::ResizeColumns()
718 m_ProgList.SetRedraw(FALSE);
720 TCHAR textbuf[MAX_PATH];
722 int maxcol = ((CHeaderCtrl*)(m_ProgList.GetDlgItem(0)))->GetItemCount()-1;
723 for (int col = 0; col <= maxcol; col++)
725 // find the longest width of all items
726 int count = m_ProgList.GetItemCount();
727 HDITEM hdi = {0};
728 hdi.mask = HDI_TEXT;
729 hdi.pszText = textbuf;
730 hdi.cchTextMax = sizeof(textbuf);
731 ((CHeaderCtrl*)(m_ProgList.GetDlgItem(0)))->GetItem(col, &hdi);
732 int cx = m_ProgList.GetStringWidth(hdi.pszText)+20; // 20 pixels for col separator and margin
734 for (int index = 0; index<count; ++index)
736 // get the width of the string and add 12 pixels for the column separator and margins
737 int linewidth = cx;
738 switch (col)
740 case 0:
741 linewidth = m_ProgList.GetStringWidth(m_arData[index]->sActionColumnText) + 12;
742 break;
743 case 1:
744 linewidth = m_ProgList.GetStringWidth(m_arData[index]->sPathColumnText) + 12;
745 break;
746 case 2:
747 linewidth = m_ProgList.GetStringWidth(m_arData[index]->mime_type) + 12;
748 break;
750 if (cx < linewidth)
751 cx = linewidth;
753 m_ProgList.SetColumnWidth(col, cx);
756 m_ProgList.SetRedraw(TRUE);
759 BOOL CGitProgressDlg::OnInitDialog()
761 __super::OnInitDialog();
763 // Let the TaskbarButtonCreated message through the UIPI filter. If we don't
764 // do this, Explorer would be unable to send that message to our window if we
765 // were running elevated. It's OK to make the call all the time, since if we're
766 // not elevated, this is a no-op.
767 CHANGEFILTERSTRUCT cfs = { sizeof(CHANGEFILTERSTRUCT) };
768 typedef BOOL STDAPICALLTYPE ChangeWindowMessageFilterExDFN(HWND hWnd, UINT message, DWORD action, PCHANGEFILTERSTRUCT pChangeFilterStruct);
769 CAutoLibrary hUser = ::LoadLibrary(_T("user32.dll"));
770 if (hUser)
772 ChangeWindowMessageFilterExDFN *pfnChangeWindowMessageFilterEx = (ChangeWindowMessageFilterExDFN*)GetProcAddress(hUser, "ChangeWindowMessageFilterEx");
773 if (pfnChangeWindowMessageFilterEx)
775 pfnChangeWindowMessageFilterEx(m_hWnd, WM_TASKBARBTNCREATED, MSGFLT_ALLOW, &cfs);
778 m_pTaskbarList.Release();
779 m_pTaskbarList.CoCreateInstance(CLSID_TaskbarList);
781 m_ProgList.SetExtendedStyle (LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER);
783 m_ProgList.DeleteAllItems();
784 int c = ((CHeaderCtrl*)(m_ProgList.GetDlgItem(0)))->GetItemCount()-1;
785 while (c>=0)
786 m_ProgList.DeleteColumn(c--);
787 CString temp;
788 temp.LoadString(IDS_PROGRS_ACTION);
789 m_ProgList.InsertColumn(0, temp);
790 temp.LoadString(IDS_PROGRS_PATH);
791 m_ProgList.InsertColumn(1, temp);
792 temp.LoadString(IDS_PROGRS_MIMETYPE);
793 m_ProgList.InsertColumn(2, temp);
795 m_pThread = AfxBeginThread(ProgressThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
796 if (m_pThread==NULL)
798 ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
800 else
802 m_pThread->m_bAutoDelete = FALSE;
803 m_pThread->ResumeThread();
806 UpdateData(FALSE);
808 // Call this early so that the column headings aren't hidden before any
809 // text gets added.
810 ResizeColumns();
812 SetTimer(VISIBLETIMER, 300, NULL);
814 AddAnchor(IDC_SVNPROGRESS, TOP_LEFT, BOTTOM_RIGHT);
815 AddAnchor(IDC_PROGRESSLABEL, BOTTOM_LEFT, BOTTOM_CENTER);
816 AddAnchor(IDC_PROGRESSBAR, BOTTOM_CENTER, BOTTOM_RIGHT);
817 AddAnchor(IDC_INFOTEXT, BOTTOM_LEFT, BOTTOM_RIGHT);
818 AddAnchor(IDC_NONINTERACTIVE, BOTTOM_LEFT, BOTTOM_RIGHT);
819 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
820 AddAnchor(IDOK, BOTTOM_RIGHT);
821 AddAnchor(IDC_LOGBUTTON, BOTTOM_RIGHT);
822 //SetPromptParentWindow(this->m_hWnd);
823 if (hWndExplorer)
824 CenterWindow(CWnd::FromHandle(hWndExplorer));
825 EnableSaveRestore(_T("GITProgressDlg"));
826 return TRUE;
829 bool CGitProgressDlg::SetBackgroundImage(UINT nID)
831 return CAppUtils::SetListCtrlBackgroundImage(m_ProgList.GetSafeHwnd(), nID);
834 void CGitProgressDlg::ReportGitError()
836 ReportError(CString(git_lasterror()));
839 void CGitProgressDlg::ReportError(const CString& sError)
841 CSoundUtils::PlayTGitError();
842 ReportString(sError, CString(MAKEINTRESOURCE(IDS_ERR_ERROR)), m_Colors.GetColor(CColors::Conflict));
843 m_bErrorsOccurred = true;
846 void CGitProgressDlg::ReportWarning(const CString& sWarning)
848 CSoundUtils::PlayTGitWarning();
849 ReportString(sWarning, CString(MAKEINTRESOURCE(IDS_WARN_WARNING)), m_Colors.GetColor(CColors::Conflict));
852 void CGitProgressDlg::ReportNotification(const CString& sNotification)
854 CSoundUtils::PlayTGitNotification();
855 ReportString(sNotification, CString(MAKEINTRESOURCE(IDS_WARN_NOTE)));
858 void CGitProgressDlg::ReportCmd(const CString& sCmd)
860 ReportString(sCmd, CString(MAKEINTRESOURCE(IDS_PROGRS_CMDINFO)), m_Colors.GetColor(CColors::Cmd));
863 void CGitProgressDlg::ReportString(CString sMessage, const CString& sMsgKind, COLORREF color)
865 // instead of showing a dialog box with the error message or notification,
866 // just insert the error text into the list control.
867 // that way the user isn't 'interrupted' by a dialog box popping up!
869 // the message may be split up into different lines
870 // so add a new entry for each line of the message
871 while (!sMessage.IsEmpty())
873 NotificationData * data = new NotificationData();
874 data->bAuxItem = true;
875 data->sActionColumnText = sMsgKind;
876 if (sMessage.Find('\n')>=0)
877 data->sPathColumnText = sMessage.Left(sMessage.Find('\n'));
878 else
879 data->sPathColumnText = sMessage;
880 data->sPathColumnText.Trim(_T("\n\r"));
881 data->color = color;
882 if (sMessage.Find('\n')>=0)
884 sMessage = sMessage.Mid(sMessage.Find('\n'));
885 sMessage.Trim(_T("\n\r"));
887 else
888 sMessage.Empty();
889 m_arData.push_back(data);
890 AddItemToList();
894 UINT CGitProgressDlg::ProgressThreadEntry(LPVOID pVoid)
896 return ((CGitProgressDlg*)pVoid)->ProgressThread();
899 UINT CGitProgressDlg::ProgressThread()
901 // The SetParams function should have loaded something for us
903 CString temp;
904 CString sWindowTitle;
905 bool localoperation = false;
906 bool bSuccess = false;
907 m_AlwaysConflicted = false;
909 DialogEnableWindow(IDOK, FALSE);
910 DialogEnableWindow(IDCANCEL, TRUE);
911 // SetAndClearProgressInfo(m_hWnd);
912 m_itemCount = m_itemCountTotal;
914 InterlockedExchange(&m_bThreadRunning, TRUE);
915 iFirstResized = 0;
916 bSecondResized = FALSE;
917 m_bFinishedItemAdded = false;
918 CTime startTime = CTime::GetCurrentTime();
920 if (m_pTaskbarList)
921 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_INDETERMINATE);
923 switch (m_Command)
925 case GitProgress_Add:
926 bSuccess = CmdAdd(sWindowTitle, localoperation);
927 break;
928 case GitProgress_Copy:
929 bSuccess = CmdCopy(sWindowTitle, localoperation);
930 break;
931 case GitProgress_Export:
932 bSuccess = CmdExport(sWindowTitle, localoperation);
933 break;
934 case GitProgress_Rename:
935 bSuccess = CmdRename(sWindowTitle, localoperation);
936 break;
937 case GitProgress_Resolve:
938 bSuccess = CmdResolve(sWindowTitle, localoperation);
939 break;
940 case GitProgress_Revert:
941 bSuccess = CmdRevert(sWindowTitle, localoperation);
942 break;
943 case GitProgress_Switch:
944 bSuccess = CmdSwitch(sWindowTitle, localoperation);
945 break;
946 case GitProgress_SendMail:
947 bSuccess = CmdSendMail(sWindowTitle, localoperation);
948 break;
950 if (!bSuccess)
951 temp.LoadString(IDS_PROGRS_TITLEFAILED);
952 else
953 temp.LoadString(IDS_PROGRS_TITLEFIN);
954 sWindowTitle = sWindowTitle + _T(" ") + temp;
955 SetWindowText(sWindowTitle);
957 KillTimer(TRANSFERTIMER);
958 KillTimer(VISIBLETIMER);
960 if (m_pTaskbarList)
962 if (DidErrorsOccur())
964 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_ERROR);
965 m_pTaskbarList->SetProgressValue(m_hWnd, 100, 100);
967 else
968 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NOPROGRESS);
971 DialogEnableWindow(IDCANCEL, FALSE);
972 DialogEnableWindow(IDOK, TRUE);
974 CString info = BuildInfoString();
975 if (!bSuccess)
976 info.LoadString(IDS_PROGRS_INFOFAILED);
977 SetDlgItemText(IDC_INFOTEXT, info);
978 ResizeColumns();
979 SendMessage(DM_SETDEFID, IDOK);
980 GetDlgItem(IDOK)->SetFocus();
982 CString sFinalInfo;
983 if (!m_sTotalBytesTransferred.IsEmpty())
985 CTimeSpan time = CTime::GetCurrentTime() - startTime;
986 temp.Format(IDS_PROGRS_TIME, (LONG)time.GetTotalMinutes(), (LONG)time.GetSeconds());
987 sFinalInfo.Format(IDS_PROGRS_FINALINFO, m_sTotalBytesTransferred, (LPCTSTR)temp);
988 SetDlgItemText(IDC_PROGRESSLABEL, sFinalInfo);
990 else
991 GetDlgItem(IDC_PROGRESSLABEL)->ShowWindow(SW_HIDE);
993 GetDlgItem(IDC_PROGRESSBAR)->ShowWindow(SW_HIDE);
995 if (!m_bFinishedItemAdded)
997 // there's no "finished: xxx" line at the end. We add one here to make
998 // sure the user sees that the command is actually finished.
999 NotificationData * data = new NotificationData();
1000 data->bAuxItem = true;
1001 data->sActionColumnText.LoadString(IDS_PROGRS_FINISHED);
1002 m_arData.push_back(data);
1003 AddItemToList();
1006 int count = m_ProgList.GetItemCount();
1007 if ((count > 0)&&(m_bLastVisible))
1008 m_ProgList.EnsureVisible(count-1, FALSE);
1010 CLogFile logfile;
1011 if (logfile.Open())
1013 logfile.AddTimeLine();
1014 for (size_t i=0; i<m_arData.size(); i++)
1016 NotificationData * data = m_arData[i];
1017 temp.Format(_T("%-20s : %s"), (LPCTSTR)data->sActionColumnText, (LPCTSTR)data->sPathColumnText);
1018 logfile.AddLine(temp);
1020 if (!sFinalInfo.IsEmpty())
1021 logfile.AddLine(sFinalInfo);
1022 logfile.Close();
1025 m_bCancelled = TRUE;
1026 InterlockedExchange(&m_bThreadRunning, FALSE);
1027 RefreshCursor();
1029 #if 0
1030 DWORD dwAutoClose = CRegStdDWORD(_T("Software\\TortoiseGit\\AutoClose"), CLOSE_MANUAL);
1031 if (m_options & ProgOptDryRun)
1032 dwAutoClose = 0; // dry run means progress dialog doesn't auto close at all
1033 if (!m_bLastVisible)
1034 dwAutoClose = 0;
1035 if (m_dwCloseOnEnd != (DWORD)-1)
1036 dwAutoClose = m_dwCloseOnEnd; // command line value has priority over setting value
1037 if ((dwAutoClose == CLOSE_NOERRORS)&&(!m_bErrorsOccurred))
1038 PostMessage(WM_COMMAND, 1, (LPARAM)GetDlgItem(IDOK)->m_hWnd);
1039 if ((dwAutoClose == CLOSE_NOCONFLICTS)&&(!m_bErrorsOccurred)&&(m_nConflicts==0))
1040 PostMessage(WM_COMMAND, 1, (LPARAM)GetDlgItem(IDOK)->m_hWnd);
1041 if ((dwAutoClose == CLOSE_NOMERGES)&&(!m_bErrorsOccurred)&&(m_nConflicts==0)&&(!m_bMergesAddsDeletesOccurred))
1042 PostMessage(WM_COMMAND, 1, (LPARAM)GetDlgItem(IDOK)->m_hWnd);
1043 if ((dwAutoClose == CLOSE_LOCAL)&&(!m_bErrorsOccurred)&&(m_nConflicts==0)&&(localoperation))
1044 PostMessage(WM_COMMAND, 1, (LPARAM)GetDlgItem(IDOK)->m_hWnd);
1045 #endif
1047 //Don't do anything here which might cause messages to be sent to the window
1048 //The window thread is probably now blocked in OnOK if we've done an auto close
1049 return 0;
1052 void CGitProgressDlg::OnBnClickedLogbutton()
1054 switch(this->m_Command)
1056 case GitProgress_Add:
1057 case GitProgress_Resolve:
1059 CString cmd = _T(" /command:commit");
1060 cmd += _T(" /path:\"")+g_Git.m_CurrentDir+_T("\"");
1062 CAppUtils::RunTortoiseProc(cmd);
1063 this->EndDialog(IDOK);
1064 break;
1067 #if 0
1068 if (m_targetPathList.GetCount() != 1)
1069 return;
1070 StringRevMap::iterator it = m_UpdateStartRevMap.begin();
1071 svn_revnum_t rev = -1;
1072 if (it != m_UpdateStartRevMap.end())
1074 rev = it->second;
1076 CLogDlg dlg;
1077 dlg.SetParams(m_targetPathList[0], m_RevisionEnd, m_RevisionEnd, rev, 0, TRUE);
1078 dlg.DoModal();
1079 #endif
1083 void CGitProgressDlg::OnClose()
1085 if (m_bCancelled)
1087 TerminateThread(m_pThread->m_hThread, (DWORD)-1);
1088 InterlockedExchange(&m_bThreadRunning, FALSE);
1090 else
1092 m_bCancelled = TRUE;
1093 return;
1095 DialogEnableWindow(IDCANCEL, TRUE);
1096 __super::OnClose();
1099 void CGitProgressDlg::OnOK()
1101 if ((m_bCancelled)&&(!m_bThreadRunning))
1103 // I have made this wait a sensible amount of time (10 seconds) for the thread to finish
1104 // You must be careful in the thread that after posting the WM_COMMAND/IDOK message, you
1105 // don't do any more operations on the window which might require message passing
1106 // If you try to send windows messages once we're waiting here, then the thread can't finished
1107 // because the Window's message loop is blocked at this wait
1108 WaitForSingleObject(m_pThread->m_hThread, 10000);
1109 __super::OnOK();
1111 m_bCancelled = TRUE;
1114 void CGitProgressDlg::OnCancel()
1116 if ((m_bCancelled)&&(!m_bThreadRunning))
1117 __super::OnCancel();
1118 m_bCancelled = TRUE;
1121 void CGitProgressDlg::OnLvnGetdispinfoSvnprogress(NMHDR *pNMHDR, LRESULT *pResult)
1123 NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
1125 if (pDispInfo)
1127 if (pDispInfo->item.mask & LVIF_TEXT)
1129 if (pDispInfo->item.iItem < (int)m_arData.size())
1131 const NotificationData * data = m_arData[pDispInfo->item.iItem];
1132 switch (pDispInfo->item.iSubItem)
1134 case 0:
1135 lstrcpyn(m_columnbuf, data->sActionColumnText, MAX_PATH);
1136 break;
1137 case 1:
1138 lstrcpyn(m_columnbuf, data->sPathColumnText, pDispInfo->item.cchTextMax);
1139 if (!data->bAuxItem)
1141 int cWidth = m_ProgList.GetColumnWidth(1);
1142 cWidth = max(12, cWidth-12);
1143 CDC * pDC = m_ProgList.GetDC();
1144 if (pDC != NULL)
1146 CFont * pFont = pDC->SelectObject(m_ProgList.GetFont());
1147 PathCompactPath(pDC->GetSafeHdc(), m_columnbuf, cWidth);
1148 pDC->SelectObject(pFont);
1149 ReleaseDC(pDC);
1152 break;
1153 case 2:
1154 lstrcpyn(m_columnbuf, data->mime_type, MAX_PATH);
1155 break;
1156 default:
1157 m_columnbuf[0] = 0;
1159 pDispInfo->item.pszText = m_columnbuf;
1163 *pResult = 0;
1166 void CGitProgressDlg::OnNMCustomdrawSvnprogress(NMHDR *pNMHDR, LRESULT *pResult)
1168 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
1170 // Take the default processing unless we set this to something else below.
1171 *pResult = CDRF_DODEFAULT;
1173 // First thing - check the draw stage. If it's the control's prepaint
1174 // stage, then tell Windows we want messages for every item.
1176 if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )
1178 *pResult = CDRF_NOTIFYITEMDRAW;
1180 else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )
1182 // This is the prepaint stage for an item. Here's where we set the
1183 // item's text color. Our return value will tell Windows to draw the
1184 // item itself, but it will use the new color we set here.
1186 // Tell Windows to paint the control itself.
1187 *pResult = CDRF_DODEFAULT;
1189 ASSERT(pLVCD->nmcd.dwItemSpec < m_arData.size());
1190 if(pLVCD->nmcd.dwItemSpec >= m_arData.size())
1192 return;
1194 const NotificationData * data = m_arData[pLVCD->nmcd.dwItemSpec];
1195 ASSERT(data != NULL);
1196 if (data == NULL)
1197 return;
1199 // Store the color back in the NMLVCUSTOMDRAW struct.
1200 pLVCD->clrText = data->color;
1204 void CGitProgressDlg::OnNMDblclkSvnprogress(NMHDR * /*pNMHDR*/, LRESULT * /*pResult*/)
1206 #if 0
1207 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1208 *pResult = 0;
1209 if (pNMLV->iItem < 0)
1210 return;
1211 if (m_options & ProgOptDryRun)
1212 return; //don't do anything in a dry-run.
1214 const NotificationData * data = m_arData[pNMLV->iItem];
1215 if (data == NULL)
1216 return;
1218 if (data->bConflictedActionItem)
1220 // We've double-clicked on a conflicted item - do a three-way merge on it
1221 SVNDiff::StartConflictEditor(data->path);
1223 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))
1225 // This is a modified file which has been merged on update. Diff it against base
1226 CTGitPath temporaryFile;
1227 SVNDiff diff(this, this->m_hWnd, true);
1228 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
1229 svn_revnum_t baseRev = 0;
1230 diff.DiffFileAgainstBase(data->path, baseRev);
1232 else if ((!data->bAuxItem)&&(data->path.Exists())&&(!data->path.IsDirectory()))
1234 bool bOpenWith = false;
1235 int ret = (int)ShellExecute(m_hWnd, NULL, data->path.GetWinPath(), NULL, NULL, SW_SHOWNORMAL);
1236 if (ret <= HINSTANCE_ERROR)
1237 bOpenWith = true;
1238 if (bOpenWith)
1240 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
1241 cmd += data->path.GetWinPathString() + _T(" ");
1242 CAppUtils::LaunchApplication(cmd, NULL, false);
1245 #endif
1248 void CGitProgressDlg::OnHdnItemclickSvnprogress(NMHDR *pNMHDR, LRESULT *pResult)
1250 LPNMHEADER phdr = reinterpret_cast<LPNMHEADER>(pNMHDR);
1251 if (m_bThreadRunning)
1252 return;
1253 if (m_nSortedColumn == phdr->iItem)
1254 m_bAscending = !m_bAscending;
1255 else
1256 m_bAscending = TRUE;
1257 m_nSortedColumn = phdr->iItem;
1258 Sort();
1260 CString temp;
1261 m_ProgList.SetRedraw(FALSE);
1262 m_ProgList.DeleteAllItems();
1263 m_ProgList.SetItemCountEx (static_cast<int>(m_arData.size()));
1265 m_ProgList.SetRedraw(TRUE);
1267 *pResult = 0;
1270 bool CGitProgressDlg::NotificationDataIsAux(const NotificationData* pData)
1272 return pData->bAuxItem;
1275 LRESULT CGitProgressDlg::OnGitProgress(WPARAM /*wParam*/, LPARAM /*lParam*/)
1277 #if 0
1278 SVNProgress * pProgressData = (SVNProgress *)lParam;
1279 CProgressCtrl * progControl = (CProgressCtrl *)GetDlgItem(IDC_PROGRESSBAR);
1280 if ((pProgressData->total > 1000)&&(!progControl->IsWindowVisible()))
1282 progControl->ShowWindow(SW_SHOW);
1283 if (m_pTaskbarList)
1284 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
1286 if (((pProgressData->total < 0)&&(pProgressData->progress > 1000)&&(progControl->IsWindowVisible()))&&(m_itemCountTotal<0))
1288 progControl->ShowWindow(SW_HIDE);
1289 if (m_pTaskbarList)
1290 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_INDETERMINATE);
1292 if (!GetDlgItem(IDC_PROGRESSLABEL)->IsWindowVisible())
1293 GetDlgItem(IDC_PROGRESSLABEL)->ShowWindow(SW_SHOW);
1294 SetTimer(TRANSFERTIMER, 2000, NULL);
1295 if ((pProgressData->total > 0)&&(pProgressData->progress > 1000))
1297 progControl->SetPos((int)pProgressData->progress);
1298 progControl->SetRange32(0, (int)pProgressData->total);
1299 if (m_pTaskbarList)
1301 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
1302 m_pTaskbarList->SetProgressValue(m_hWnd, pProgressData->progress, pProgressData->total);
1305 CString progText;
1306 if (pProgressData->overall_total < 1024)
1307 m_sTotalBytesTransferred.Format(IDS_SVN_PROGRESS_TOTALBYTESTRANSFERRED, pProgressData->overall_total);
1308 else if (pProgressData->overall_total < 1200000)
1309 m_sTotalBytesTransferred.Format(IDS_SVN_PROGRESS_TOTALTRANSFERRED, pProgressData->overall_total / 1024);
1310 else
1311 m_sTotalBytesTransferred.Format(IDS_SVN_PROGRESS_TOTALMBTRANSFERRED, (double)((double)pProgressData->overall_total / 1024000.0));
1312 progText.Format(IDS_SVN_PROGRESS_TOTALANDSPEED, (LPCTSTR)m_sTotalBytesTransferred, (LPCTSTR)pProgressData->SpeedString);
1313 SetDlgItemText(IDC_PROGRESSLABEL, progText);
1314 #endif
1315 return 0;
1318 void CGitProgressDlg::OnTimer(UINT_PTR nIDEvent)
1320 if (nIDEvent == TRANSFERTIMER)
1322 CString progText;
1323 CString progSpeed;
1324 progSpeed.Format(IDS_SVN_PROGRESS_BYTES_SEC, 0);
1325 progText.Format(IDS_SVN_PROGRESS_TOTALANDSPEED, (LPCTSTR)m_sTotalBytesTransferred, (LPCTSTR)progSpeed);
1326 SetDlgItemText(IDC_PROGRESSLABEL, progText);
1327 KillTimer(TRANSFERTIMER);
1329 if (nIDEvent == VISIBLETIMER)
1331 if (nEnsureVisibleCount)
1332 m_ProgList.EnsureVisible(m_ProgList.GetItemCount()-1, false);
1333 nEnsureVisibleCount = 0;
1337 void CGitProgressDlg::Sort()
1339 if(m_arData.size() < 2)
1341 return;
1344 // We need to sort the blocks which lie between the auxiliary entries
1345 // This is so that any aux data stays where it was
1346 NotificationDataVect::iterator actionBlockBegin;
1347 NotificationDataVect::iterator actionBlockEnd = m_arData.begin(); // We start searching from here
1349 for(;;)
1351 // Search to the start of the non-aux entry in the next block
1352 actionBlockBegin = std::find_if(actionBlockEnd, m_arData.end(), std::not1(std::ptr_fun(&CGitProgressDlg::NotificationDataIsAux)));
1353 if(actionBlockBegin == m_arData.end())
1355 // There are no more actions
1356 break;
1358 // Now search to find the end of the block
1359 actionBlockEnd = std::find_if(actionBlockBegin+1, m_arData.end(), std::ptr_fun(&CGitProgressDlg::NotificationDataIsAux));
1360 // Now sort the block
1361 std::sort(actionBlockBegin, actionBlockEnd, &CGitProgressDlg::SortCompare);
1365 bool CGitProgressDlg::SortCompare(const NotificationData * pData1, const NotificationData * pData2)
1367 int result = 0;
1368 switch (m_nSortedColumn)
1370 case 0: //action column
1371 result = pData1->sActionColumnText.Compare(pData2->sActionColumnText);
1372 break;
1373 case 1: //path column
1374 // Compare happens after switch()
1375 break;
1376 case 2: //mime-type column
1377 result = pData1->mime_type.Compare(pData2->mime_type);
1378 break;
1379 default:
1380 break;
1383 // Sort by path if everything else is equal
1384 if (result == 0)
1386 result = CTGitPath::Compare(pData1->path, pData2->path);
1389 if (!m_bAscending)
1390 result = -result;
1391 return result < 0;
1394 BOOL CGitProgressDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
1396 if (!GetDlgItem(IDOK)->IsWindowEnabled())
1398 // only show the wait cursor over the list control
1399 if ((pWnd)&&(pWnd == GetDlgItem(IDC_SVNPROGRESS)))
1401 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT));
1402 SetCursor(hCur);
1403 return TRUE;
1406 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));
1407 SetCursor(hCur);
1408 return CResizableStandAloneDialog::OnSetCursor(pWnd, nHitTest, message);
1411 BOOL CGitProgressDlg::PreTranslateMessage(MSG* pMsg)
1413 if (pMsg->message == WM_KEYDOWN)
1415 if (pMsg->wParam == VK_ESCAPE)
1417 // pressing the ESC key should close the dialog. But since we disabled the escape
1418 // key (so the user doesn't get the idea that he could simply undo an e.g. update)
1419 // this won't work.
1420 // So if the user presses the ESC key, change it to VK_RETURN so the dialog gets
1421 // the impression that the OK button was pressed.
1422 if ((!m_bThreadRunning)&&(!GetDlgItem(IDCANCEL)->IsWindowEnabled())
1423 &&(GetDlgItem(IDOK)->IsWindowEnabled())&&(GetDlgItem(IDOK)->IsWindowVisible()))
1425 // since we convert ESC to RETURN, make sure the OK button has the focus.
1426 GetDlgItem(IDOK)->SetFocus();
1427 pMsg->wParam = VK_RETURN;
1430 if (pMsg->wParam == 'A')
1432 if (GetKeyState(VK_CONTROL)&0x8000)
1434 // Ctrl-A -> select all
1435 m_ProgList.SetSelectionMark(0);
1436 for (int i=0; i<m_ProgList.GetItemCount(); ++i)
1438 m_ProgList.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
1442 if ((pMsg->wParam == 'C')||(pMsg->wParam == VK_INSERT))
1444 int selIndex = m_ProgList.GetSelectionMark();
1445 if (selIndex >= 0)
1447 if (GetKeyState(VK_CONTROL)&0x8000)
1449 //Ctrl-C -> copy to clipboard
1450 CString sClipdata;
1451 POSITION pos = m_ProgList.GetFirstSelectedItemPosition();
1452 if (pos != NULL)
1454 while (pos)
1456 int nItem = m_ProgList.GetNextSelectedItem(pos);
1457 CString sAction = m_ProgList.GetItemText(nItem, 0);
1458 CString sPath = m_ProgList.GetItemText(nItem, 1);
1459 CString sMime = m_ProgList.GetItemText(nItem, 2);
1460 CString sLogCopyText;
1461 sLogCopyText.Format(_T("%s: %s %s\r\n"),
1462 (LPCTSTR)sAction, (LPCTSTR)sPath, (LPCTSTR)sMime);
1463 sClipdata += sLogCopyText;
1465 CStringUtils::WriteAsciiStringToClipboard(sClipdata);
1470 } // if (pMsg->message == WM_KEYDOWN)
1471 return __super::PreTranslateMessage(pMsg);
1474 void CGitProgressDlg::OnContextMenu(CWnd* /*pWnd*/, CPoint /*point*/)
1476 #if 0
1477 if (m_options & ProgOptDryRun)
1478 return; // don't do anything in a dry-run.
1480 if (pWnd == &m_ProgList)
1482 int selIndex = m_ProgList.GetSelectionMark();
1483 if ((point.x == -1) && (point.y == -1))
1485 // Menu was invoked from the keyboard rather than by right-clicking
1486 CRect rect;
1487 m_ProgList.GetItemRect(selIndex, &rect, LVIR_LABEL);
1488 m_ProgList.ClientToScreen(&rect);
1489 point = rect.CenterPoint();
1492 if ((selIndex >= 0)&&(!m_bThreadRunning))
1494 // entry is selected, thread has finished with updating so show the popup menu
1495 CIconMenu popup;
1496 if (popup.CreatePopupMenu())
1498 bool bAdded = false;
1499 NotificationData * data = m_arData[selIndex];
1500 if ((data)&&(!data->path.IsDirectory()))
1502 if (data->action == svn_wc_notify_update_update || data->action == svn_wc_notify_resolved)
1504 if (m_ProgList.GetSelectedCount() == 1)
1506 popup.AppendMenuIcon(ID_COMPARE, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1507 bAdded = true;
1510 if (data->bConflictedActionItem)
1512 if (m_ProgList.GetSelectedCount() == 1)
1514 popup.AppendMenuIcon(ID_EDITCONFLICT, IDS_MENUCONFLICT,IDI_CONFLICT);
1515 popup.SetDefaultItem(ID_EDITCONFLICT, FALSE);
1516 popup.AppendMenuIcon(ID_CONFLICTRESOLVE, IDS_SVNPROGRESS_MENUMARKASRESOLVED,IDI_RESOLVE);
1518 popup.AppendMenuIcon(ID_CONFLICTUSETHEIRS, IDS_SVNPROGRESS_MENUUSETHEIRS,IDI_RESOLVE);
1519 popup.AppendMenuIcon(ID_CONFLICTUSEMINE, IDS_SVNPROGRESS_MENUUSEMINE,IDI_RESOLVE);
1521 else if ((data->content_state == svn_wc_notify_state_merged)||(GitProgress_Merge == m_Command)||(data->action == svn_wc_notify_resolved))
1522 popup.SetDefaultItem(ID_COMPARE, FALSE);
1524 if (m_ProgList.GetSelectedCount() == 1)
1526 if ((data->action == svn_wc_notify_add)||
1527 (data->action == svn_wc_notify_update_add)||
1528 (data->action == svn_wc_notify_commit_added)||
1529 (data->action == svn_wc_notify_commit_modified)||
1530 (data->action == svn_wc_notify_restore)||
1531 (data->action == svn_wc_notify_revert)||
1532 (data->action == svn_wc_notify_resolved)||
1533 (data->action == svn_wc_notify_commit_replaced)||
1534 (data->action == svn_wc_notify_commit_modified)||
1535 (data->action == svn_wc_notify_commit_postfix_txdelta)||
1536 (data->action == svn_wc_notify_update_update))
1538 popup.AppendMenuIcon(ID_LOG, IDS_MENULOG,IDI_LOG);
1539 if (data->action == svn_wc_notify_update_update)
1540 popup.AppendMenu(MF_SEPARATOR, NULL);
1541 popup.AppendMenuIcon(ID_OPEN, IDS_LOG_POPUP_OPEN, IDI_OPEN);
1542 popup.AppendMenuIcon(ID_OPENWITH, IDS_LOG_POPUP_OPENWITH, IDI_OPEN);
1543 bAdded = true;
1546 } // if ((data)&&(!data->path.IsDirectory()))
1547 if (m_ProgList.GetSelectedCount() == 1)
1549 if (data)
1551 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1552 if ((!sPath.IsEmpty())&&(!SVN::PathIsURL(CTGitPath(sPath))))
1554 CTGitPath path = CTGitPath(sPath);
1555 if (path.GetDirectory().Exists())
1557 popup.AppendMenuIcon(ID_EXPLORE, IDS_SVNPROGRESS_MENUOPENPARENT, IDI_EXPLORER);
1558 bAdded = true;
1563 if (m_ProgList.GetSelectedCount() > 0)
1565 if (bAdded)
1566 popup.AppendMenu(MF_SEPARATOR, NULL);
1567 popup.AppendMenuIcon(ID_COPY, IDS_LOG_POPUP_COPYTOCLIPBOARD,IDI_COPYCLIP);
1568 bAdded = true;
1570 if (bAdded)
1572 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
1573 DialogEnableWindow(IDOK, FALSE);
1574 this->SetPromptApp(&theApp);
1575 theApp.DoWaitCursor(1);
1576 bool bOpenWith = false;
1577 switch (cmd)
1579 case ID_COPY:
1581 CString sLines;
1582 POSITION pos = m_ProgList.GetFirstSelectedItemPosition();
1583 while (pos)
1585 int nItem = m_ProgList.GetNextSelectedItem(pos);
1586 NotificationData * data = m_arData[nItem];
1587 if (data)
1589 sLines += data->sPathColumnText;
1590 sLines += _T("\r\n");
1593 sLines.TrimRight();
1594 if (!sLines.IsEmpty())
1596 CStringUtils::WriteAsciiStringToClipboard(sLines, GetSafeHwnd());
1599 break;
1600 case ID_EXPLORE:
1602 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1604 CTGitPath path = CTGitPath(sPath);
1605 ShellExecute(m_hWnd, _T("explore"), path.GetDirectory().GetWinPath(), NULL, path.GetDirectory().GetWinPath(), SW_SHOW);
1607 break;
1608 case ID_COMPARE:
1610 svn_revnum_t rev = -1;
1611 StringRevMap::iterator it = m_UpdateStartRevMap.end();
1612 if (data->basepath.IsEmpty())
1613 it = m_UpdateStartRevMap.begin();
1614 else
1615 it = m_UpdateStartRevMap.find(data->basepath.GetSVNApiPath(pool));
1616 if (it != m_UpdateStartRevMap.end())
1617 rev = it->second;
1618 // if the file was merged during update, do a three way diff between OLD, MINE, THEIRS
1619 if (data->content_state == svn_wc_notify_state_merged)
1621 CTGitPath basefile = CTempFiles::Instance().GetTempFilePath(false, data->path, rev);
1622 CTGitPath newfile = CTempFiles::Instance().GetTempFilePath(false, data->path, SVNRev::REV_HEAD);
1623 SVN svn;
1624 if (!svn.Cat(data->path, SVNRev(SVNRev::REV_WC), rev, basefile))
1626 CMessageBox::Show(m_hWnd, svn.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1627 DialogEnableWindow(IDOK, TRUE);
1628 break;
1630 // If necessary, convert the line-endings on the file before diffing
1631 if ((DWORD)CRegDWORD(_T("Software\\TortoiseGit\\ConvertBase"), TRUE))
1633 CTGitPath temporaryFile = CTempFiles::Instance().GetTempFilePath(false, data->path, SVNRev::REV_BASE);
1634 if (!svn.Cat(data->path, SVNRev(SVNRev::REV_BASE), SVNRev(SVNRev::REV_BASE), temporaryFile))
1636 temporaryFile.Reset();
1637 break;
1639 else
1641 newfile = temporaryFile;
1645 SetFileAttributes(newfile.GetWinPath(), FILE_ATTRIBUTE_READONLY);
1646 SetFileAttributes(basefile.GetWinPath(), FILE_ATTRIBUTE_READONLY);
1647 CString revname, wcname, basename;
1648 revname.Format(_T("%s Revision %ld"), (LPCTSTR)data->path.GetUIFileOrDirectoryName(), rev);
1649 wcname.Format(IDS_DIFF_WCNAME, (LPCTSTR)data->path.GetUIFileOrDirectoryName());
1650 basename.Format(IDS_DIFF_BASENAME, (LPCTSTR)data->path.GetUIFileOrDirectoryName());
1651 CAppUtils::StartExtMerge(basefile, newfile, data->path, data->path, basename, revname, wcname, CString(), true);
1653 else
1655 CTGitPath tempfile = CTempFiles::Instance().GetTempFilePath(false, data->path, rev);
1656 SVN svn;
1657 if (!svn.Cat(data->path, SVNRev(SVNRev::REV_WC), rev, tempfile))
1659 CMessageBox::Show(m_hWnd, svn.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1660 DialogEnableWindow(IDOK, TRUE);
1661 break;
1663 else
1665 SetFileAttributes(tempfile.GetWinPath(), FILE_ATTRIBUTE_READONLY);
1666 CString revname, wcname;
1667 revname.Format(_T("%s Revision %ld"), (LPCTSTR)data->path.GetUIFileOrDirectoryName(), rev);
1668 wcname.Format(IDS_DIFF_WCNAME, (LPCTSTR)data->path.GetUIFileOrDirectoryName());
1669 CAppUtils::StartExtDiff(
1670 tempfile, data->path, revname, wcname,
1671 CAppUtils::DiffFlags().AlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000)));
1675 break;
1676 case ID_EDITCONFLICT:
1678 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1679 SVNDiff::StartConflictEditor(CTGitPath(sPath));
1681 break;
1682 case ID_CONFLICTUSETHEIRS:
1683 case ID_CONFLICTUSEMINE:
1684 case ID_CONFLICTRESOLVE:
1686 svn_wc_conflict_choice_t result = svn_wc_conflict_choose_merged;
1687 switch (cmd)
1689 case ID_CONFLICTUSETHEIRS:
1690 result = svn_wc_conflict_choose_theirs_full;
1691 break;
1692 case ID_CONFLICTUSEMINE:
1693 result = svn_wc_conflict_choose_mine_full;
1694 break;
1695 case ID_CONFLICTRESOLVE:
1696 result = svn_wc_conflict_choose_merged;
1697 break;
1699 SVN svn;
1700 POSITION pos = m_ProgList.GetFirstSelectedItemPosition();
1701 CString sResolvedPaths;
1702 while (pos)
1704 int nItem = m_ProgList.GetNextSelectedItem(pos);
1705 NotificationData * data = m_arData[nItem];
1706 if (data)
1708 if (data->bConflictedActionItem)
1710 if (!svn.Resolve(data->path, result, FALSE))
1712 CMessageBox::Show(m_hWnd, svn.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1713 DialogEnableWindow(IDOK, TRUE);
1714 break;
1716 else
1718 data->color = ::GetSysColor(COLOR_WINDOWTEXT);
1719 data->action = svn_wc_notify_resolved;
1720 data->sActionColumnText.LoadString(IDS_SVNACTION_RESOLVE);
1721 data->bConflictedActionItem = false;
1722 m_nConflicts--;
1724 if (m_nConflicts==0)
1726 // When the last conflict is resolved we remove
1727 // the warning which we assume is in the last line.
1728 int nIndex = m_ProgList.GetItemCount()-1;
1729 VERIFY(m_ProgList.DeleteItem(nIndex));
1731 delete m_arData[nIndex];
1732 m_arData.pop_back();
1734 sResolvedPaths += data->path.GetWinPathString() + _T("\n");
1739 m_ProgList.Invalidate();
1740 CString info = BuildInfoString();
1741 SetDlgItemText(IDC_INFOTEXT, info);
1743 if (!sResolvedPaths.IsEmpty())
1745 CString msg;
1746 msg.Format(IDS_SVNPROGRESS_RESOLVED, (LPCTSTR)sResolvedPaths);
1747 CMessageBox::Show(m_hWnd, msg, _T("TortoiseGit"), MB_OK | MB_ICONINFORMATION);
1750 break;
1751 case ID_LOG:
1753 svn_revnum_t rev = m_RevisionEnd;
1754 if (!data->basepath.IsEmpty())
1756 StringRevMap::iterator it = m_FinishedRevMap.find(data->basepath.GetSVNApiPath(pool));
1757 if (it != m_FinishedRevMap.end())
1758 rev = it->second;
1760 CLogDlg dlg;
1761 // fetch the log from HEAD, not the revision we updated to:
1762 // the path might be inside an external folder which has its own
1763 // revisions.
1764 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1765 dlg.SetParams(CTGitPath(sPath), SVNRev(), SVNRev::REV_HEAD, 1, -1, TRUE);
1766 dlg.DoModal();
1768 break;
1769 case ID_OPENWITH:
1770 bOpenWith = true;
1771 case ID_OPEN:
1773 int ret = 0;
1774 CString sWinPath = GetPathFromColumnText(data->sPathColumnText);
1775 if (!bOpenWith)
1776 ret = (int)ShellExecute(this->m_hWnd, NULL, (LPCTSTR)sWinPath, NULL, NULL, SW_SHOWNORMAL);
1777 if ((ret <= HINSTANCE_ERROR)||bOpenWith)
1779 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
1780 cmd += sWinPath + _T(" ");
1781 CAppUtils::LaunchApplication(cmd, NULL, false);
1785 DialogEnableWindow(IDOK, TRUE);
1786 theApp.DoWaitCursor(-1);
1787 } // if (bAdded)
1791 #endif
1794 void CGitProgressDlg::OnEnSetfocusInfotext()
1796 CString sTemp;
1797 GetDlgItemText(IDC_INFOTEXT, sTemp);
1798 if (sTemp.IsEmpty())
1799 GetDlgItem(IDC_INFOTEXT)->HideCaret();
1802 void CGitProgressDlg::OnLvnBegindragSvnprogress(NMHDR* , LRESULT *pResult)
1804 //LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1805 #if 0
1806 int selIndex = m_ProgList.GetSelectionMark();
1807 if (selIndex < 0)
1808 return;
1810 CDropFiles dropFiles; // class for creating DROPFILES struct
1812 int index;
1813 POSITION pos = m_ProgList.GetFirstSelectedItemPosition();
1814 while ( (index = m_ProgList.GetNextSelectedItem(pos)) >= 0 )
1816 NotificationData * data = m_arData[index];
1818 if ( data->kind==svn_node_file || data->kind==svn_node_dir )
1820 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1822 dropFiles.AddFile( sPath );
1826 if ( dropFiles.GetCount()>0 )
1828 dropFiles.CreateStructure();
1830 #endif
1831 *pResult = 0;
1834 void CGitProgressDlg::OnSize(UINT nType, int cx, int cy)
1836 CResizableStandAloneDialog::OnSize(nType, cx, cy);
1837 if ((nType == SIZE_RESTORED)&&(m_bLastVisible))
1839 if(!m_ProgList.m_hWnd)
1840 return;
1842 int count = m_ProgList.GetItemCount();
1843 if (count > 0)
1844 m_ProgList.EnsureVisible(count-1, false);
1848 //////////////////////////////////////////////////////////////////////////
1849 /// commands
1850 //////////////////////////////////////////////////////////////////////////
1851 bool CGitProgressDlg::CmdAdd(CString& sWindowTitle, bool& localoperation)
1853 localoperation = true;
1854 sWindowTitle.LoadString(IDS_PROGRS_TITLE_ADD);
1855 CAppUtils::SetWindowTitle(m_hWnd, m_targetPathList.GetCommonRoot().GetUIPathString(), sWindowTitle);
1856 SetBackgroundImage(IDI_ADD_BKG);
1857 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_ADD)));
1859 // HACK for separate-git-dir, libgit2 doesn't support it atm
1860 if (CTGitPath(g_Git.m_CurrentDir + _T("/.git")).IsDirectory() && CRegDWORD(_T("Software\\TortoiseGit\\UseLibgit2"), FALSE) == TRUE)
1862 git_repository *repo = NULL;
1863 git_index *index;
1865 CStringA gitdir = CUnicodeUtils::GetMulti(CTGitPath(g_Git.m_CurrentDir).GetGitPathString() + _T("/.git"), CP_ACP);
1866 if (git_repository_open(&repo, gitdir.GetBuffer()))
1868 ReportGitError();
1869 return false;
1871 if (git_repository_index(&index, repo))
1873 ReportGitError();
1874 git_repository_free(repo);
1875 return false;
1877 if (git_index_read(index))
1879 ReportGitError();
1880 git_index_free(index);
1881 git_repository_free(repo);
1882 return false;
1885 for(int i=0;i<m_targetPathList.GetCount();i++)
1887 if (git_index_add(index, CStringA(CUnicodeUtils::GetMulti(m_targetPathList[i].GetGitPathString(), CP_ACP)).GetBuffer(), 0))
1889 ReportGitError();
1890 git_index_free(index);
1891 git_repository_free(repo);
1892 return false;
1894 Notify(m_targetPathList[i],git_wc_notify_add);
1897 if (git_index_write(index))
1899 ReportGitError();
1900 git_index_free(index);
1901 git_repository_free(repo);
1902 return false;
1905 git_index_free(index);
1906 git_repository_free(repo);
1908 else
1910 CMassiveGitTask mgt(L"add -f");
1911 mgt.ExecuteWithNotify(&m_targetPathList, m_bCancelled, git_wc_notify_add, this, &CGitProgressDlg::Notify);
1914 CShellUpdater::Instance().AddPathsForUpdate(m_targetPathList);
1915 m_bErrorsOccurred=false;
1917 this->GetDlgItem(IDC_LOGBUTTON)->SetWindowText(_T("Commit ..."));
1918 this->GetDlgItem(IDC_LOGBUTTON)->ShowWindow(SW_SHOW);
1919 return true;
1922 bool CGitProgressDlg::CmdCopy(CString& /*sWindowTitle*/, bool& /*localoperation*/)
1924 #if 0
1925 ASSERT(m_targetPathList.GetCount() == 1);
1926 sWindowTitle.LoadString(IDS_PROGRS_TITLE_COPY);
1927 SetWindowText(sWindowTitle); // needs to be updated, see TSVN rev. 21375
1928 SetBackgroundImage(IDI_COPY_BKG);
1930 CString sCmdInfo;
1931 sCmdInfo.Format(IDS_PROGRS_CMD_COPY,
1932 m_targetPathList[0].IsUrl() ? (LPCTSTR)m_targetPathList[0].GetSVNPathString() : m_targetPathList[0].GetWinPath(),
1933 (LPCTSTR)m_url.GetSVNPathString(), (LPCTSTR)m_Revision.ToString());
1934 ReportCmd(sCmdInfo);
1936 if (!Copy(m_targetPathList, m_url, m_Revision, m_pegRev, m_sMessage))
1938 ReportSVNError();
1939 return false;
1941 if (m_options & ProgOptSwitchAfterCopy)
1943 sCmdInfo.Format(IDS_PROGRS_CMD_SWITCH,
1944 m_targetPathList[0].GetWinPath(),
1945 (LPCTSTR)m_url.GetSVNPathString(), (LPCTSTR)m_Revision.ToString());
1946 ReportCmd(sCmdInfo);
1947 if (!Switch(m_targetPathList[0], m_url, SVNRev::REV_HEAD, SVNRev::REV_HEAD, m_depth, TRUE, m_options & ProgOptIgnoreExternals))
1949 if (!Switch(m_targetPathList[0], m_url, SVNRev::REV_HEAD, m_Revision, m_depth, TRUE, m_options & ProgOptIgnoreExternals))
1951 ReportSVNError();
1952 return false;
1956 else
1958 if (SVN::PathIsURL(m_url))
1960 CString sMsg(MAKEINTRESOURCE(IDS_PROGRS_COPY_WARNING));
1961 ReportNotification(sMsg);
1964 #endif
1965 return true;
1968 bool CGitProgressDlg::CmdExport(CString& /*sWindowTitle*/, bool& /*localoperation*/)
1970 #if 0
1971 ASSERT(m_targetPathList.GetCount() == 1);
1972 sWindowTitle.LoadString(IDS_PROGRS_TITLE_EXPORT);
1973 sWindowTitle = m_url.GetUIFileOrDirectoryName()+_T(" - ")+sWindowTitle;
1974 SetWindowText(sWindowTitle); // needs to be updated, see TSVN rev. 21375
1975 SetBackgroundImage(IDI_EXPORT_BKG);
1976 CString eol;
1977 if (m_options & ProgOptEolCRLF)
1978 eol = _T("CRLF");
1979 if (m_options & ProgOptEolLF)
1980 eol = _T("LF");
1981 if (m_options & ProgOptEolCR)
1982 eol = _T("CR");
1983 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_EXPORT)));
1984 if (!Export(m_url, m_targetPathList[0], m_Revision, m_Revision, TRUE, m_options & ProgOptIgnoreExternals, m_depth, NULL, FALSE, eol))
1986 ReportSVNError();
1987 return false;
1989 #endif
1990 return true;
1993 bool CGitProgressDlg::CmdRename(CString& /*sWindowTitle*/, bool& /*localoperation*/)
1995 #if 0
1996 ASSERT(m_targetPathList.GetCount() == 1);
1997 if ((!m_targetPathList[0].IsUrl())&&(!m_url.IsUrl()))
1998 localoperation = true;
1999 sWindowTitle.LoadString(IDS_PROGRS_TITLE_RENAME);
2000 SetWindowText(sWindowTitle); // needs to be updated, see TSVN rev. 21375
2001 SetBackgroundImage(IDI_RENAME_BKG);
2002 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RENAME)));
2003 if (!Move(m_targetPathList, m_url, m_Revision, m_sMessage))
2005 ReportSVNError();
2006 return false;
2008 #endif
2009 return true;
2012 bool CGitProgressDlg::CmdResolve(CString& sWindowTitle, bool& localoperation)
2015 localoperation = true;
2016 ASSERT(m_targetPathList.GetCount() == 1);
2017 sWindowTitle.LoadString(IDS_PROGRS_TITLE_RESOLVE);
2018 CAppUtils::SetWindowTitle(m_hWnd, m_targetPathList.GetCommonRoot().GetUIPathString(), sWindowTitle);
2019 SetBackgroundImage(IDI_RESOLVE_BKG);
2020 // check if the file may still have conflict markers in it.
2021 //BOOL bMarkers = FALSE;
2023 for(int i=0;i<m_targetPathList.GetCount();i++)
2025 CString cmd,out,tempmergefile;
2026 cmd.Format(_T("git.exe add -f -- \"%s\""),m_targetPathList[i].GetGitPathString());
2027 if(g_Git.Run(cmd,&out,CP_ACP))
2029 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
2030 m_bErrorsOccurred=true;
2031 return false;
2034 CAppUtils::RemoveTempMergeFile((CTGitPath &)m_targetPathList[i]);
2036 Notify(m_targetPathList[i],git_wc_notify_resolved);
2038 #if 0
2039 if ((m_options & ProgOptSkipConflictCheck) == 0)
2043 for (INT_PTR fileindex=0; (fileindex<m_targetPathList.GetCount()) && (bMarkers==FALSE); ++fileindex)
2045 if (!m_targetPathList[fileindex].IsDirectory())
2047 CStdioFile file(m_targetPathList[fileindex].GetWinPath(), CFile::typeBinary | CFile::modeRead);
2048 CString strLine = _T("");
2049 while (file.ReadString(strLine))
2051 if (strLine.Find(_T("<<<<<<<"))==0)
2053 bMarkers = TRUE;
2054 break;
2057 file.Close();
2061 catch (CFileException* pE)
2063 TRACE(_T("CFileException in Resolve!\n"));
2064 TCHAR error[10000] = {0};
2065 pE->GetErrorMessage(error, 10000);
2066 ReportError(error);
2067 pE->Delete();
2068 return false;
2071 if (bMarkers)
2073 if (CMessageBox::Show(m_hWnd, IDS_PROGRS_REVERTMARKERS, IDS_APPNAME, MB_YESNO | MB_ICONQUESTION)==IDYES)
2075 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RESOLVE)));
2076 for (INT_PTR fileindex=0; fileindex<m_targetPathList.GetCount(); ++fileindex)
2077 Resolve(m_targetPathList[fileindex], svn_wc_conflict_choose_merged, true);
2080 else
2082 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RESOLVE)));
2083 for (INT_PTR fileindex=0; fileindex<m_targetPathList.GetCount(); ++fileindex)
2084 Resolve(m_targetPathList[fileindex], svn_wc_conflict_choose_merged, true);
2086 #endif
2087 CShellUpdater::Instance().AddPathsForUpdate(m_targetPathList);
2089 this->GetDlgItem(IDC_LOGBUTTON)->SetWindowText(_T("Commit ..."));
2090 this->GetDlgItem(IDC_LOGBUTTON)->ShowWindow(SW_SHOW);
2092 return true;
2095 bool CGitProgressDlg::CmdRevert(CString& sWindowTitle, bool& localoperation)
2098 localoperation = true;
2099 sWindowTitle.LoadString(IDS_PROGRS_TITLE_REVERT);
2100 CAppUtils::SetWindowTitle(m_hWnd, m_targetPathList.GetCommonRoot().GetUIPathString(), sWindowTitle);
2101 SetBackgroundImage(IDI_REVERT_BKG);
2103 CTGitPathList delList;
2104 for(int i=0;i<m_selectedPaths.GetCount();i++)
2106 CTGitPath path;
2107 int action;
2108 path.SetFromWin(g_Git.m_CurrentDir+_T("\\")+m_selectedPaths[i].GetWinPath());
2109 action = m_selectedPaths[i].m_Action;
2110 /* rename file can't delete because it needs original file*/
2111 if((!(action & CTGitPath::LOGACTIONS_ADDED)) &&
2112 (!(action & CTGitPath::LOGACTIONS_REPLACED)))
2113 delList.AddPath(path);
2115 if (DWORD(CRegDWORD(_T("Software\\TortoiseGit\\RevertWithRecycleBin"), TRUE)))
2116 delList.DeleteAllFiles(true);
2118 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_REVERT)));
2119 for(int i=0;i<m_selectedPaths.GetCount();i++)
2121 if(g_Git.Revert(_T("HEAD"), (CTGitPath&)m_selectedPaths[i]))
2123 CMessageBox::Show(NULL,_T("Revert Fail"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
2124 m_bErrorsOccurred=true;
2125 return false;
2127 Notify(m_selectedPaths[i],git_wc_notify_revert);
2130 CShellUpdater::Instance().AddPathsForUpdate(m_selectedPaths);
2132 return true;
2135 bool CGitProgressDlg::CmdSwitch(CString& /*sWindowTitle*/, bool& /*localoperation*/)
2137 #if 0
2138 ASSERT(m_targetPathList.GetCount() == 1);
2139 SVNStatus st;
2140 sWindowTitle.LoadString(IDS_PROGRS_TITLE_SWITCH);
2141 SetWindowText(sWindowTitle); // needs to be updated, see TSVN rev. 21375
2142 SetBackgroundImage(IDI_SWITCH_BKG);
2143 LONG rev = 0;
2144 if (st.GetStatus(m_targetPathList[0]) != (-2))
2146 if (st.status->entry != NULL)
2148 rev = st.status->entry->revision;
2152 CString sCmdInfo;
2153 sCmdInfo.Format(IDS_PROGRS_CMD_SWITCH,
2154 m_targetPathList[0].GetWinPath(), (LPCTSTR)m_url.GetSVNPathString(),
2155 (LPCTSTR)m_Revision.ToString());
2156 ReportCmd(sCmdInfo);
2158 bool depthIsSticky = true;
2159 if (m_depth == svn_depth_unknown)
2160 depthIsSticky = false;
2161 if (!Switch(m_targetPathList[0], m_url, m_Revision, m_Revision, m_depth, depthIsSticky, m_options & ProgOptIgnoreExternals))
2163 ReportSVNError();
2164 return false;
2166 m_UpdateStartRevMap[m_targetPathList[0].GetSVNApiPath(pool)] = rev;
2167 if ((m_RevisionEnd >= 0)&&(rev >= 0)
2168 &&((LONG)m_RevisionEnd > (LONG)rev))
2170 GetDlgItem(IDC_LOGBUTTON)->ShowWindow(SW_SHOW);
2172 #endif
2173 return true;
2176 void CGitProgressDlg::OnBnClickedNoninteractive()
2178 LRESULT res = ::SendMessage(GetDlgItem(IDC_NONINTERACTIVE)->GetSafeHwnd(), BM_GETCHECK, 0, 0);
2179 m_AlwaysConflicted = (res == BST_CHECKED);
2180 CRegDWORD nonint = CRegDWORD(_T("Software\\TortoiseGit\\MergeNonInteractive"), FALSE);
2181 nonint = m_AlwaysConflicted;
2184 CString CGitProgressDlg::GetPathFromColumnText(const CString& sColumnText)
2186 CString sPath = CPathUtils::ParsePathInString(sColumnText);
2187 if (sPath.Find(':')<0)
2189 // the path is not absolute: add the common root of all paths to it
2190 sPath = m_targetPathList.GetCommonRoot().GetDirectory().GetWinPathString() + _T("\\") + CPathUtils::ParsePathInString(sColumnText);
2192 return sPath;
2195 bool CGitProgressDlg::CmdSendMail(CString& sWindowTitle, bool& /*localoperation*/)
2197 sWindowTitle.LoadString(IDS_PROGRS_TITLE_SENDMAIL);
2198 CAppUtils::SetWindowTitle(m_hWnd, m_targetPathList.GetCommonRoot().GetUIPathString(), sWindowTitle);
2199 //SetBackgroundImage(IDI_ADD_BKG);
2200 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_SENDMAIL)));
2201 bool ret=true;
2202 if(this->m_SendMailFlags&SENDMAIL_COMBINED)
2204 CString error;
2205 CTGitPath path;
2206 Notify(path,git_wc_notify_sendmail_start);
2207 CString err;
2208 int retry=0;
2209 while(retry <3)
2211 if(!!CPatch::SendPatchesCombined(m_targetPathList,m_SendMailTO,m_SendMailCC,m_SendMailSubject,!!(this->m_SendMailFlags&SENDMAIL_ATTACHMENT),!!(this->m_SendMailFlags&SENDMAIL_MAPI),&err))
2213 Notify(path,git_wc_notify_sendmail_error,ret,&err);
2214 ret = false;
2216 else
2218 break;
2221 retry++;
2222 if (retry < 3)
2223 Notify(path,git_wc_notify_sendmail_retry,ret,&err);
2224 Sleep(2000);
2225 if(m_bCancelled)
2227 CString str(_T("User Canceled"));
2228 Notify(path,git_wc_notify_sendmail_error,ret,&str);
2229 return false;
2232 if (ret)
2233 Notify(path,git_wc_notify_sendmail_done,ret);
2235 else
2237 for(int i=0;ret && i<m_targetPathList.GetCount();i++)
2239 CPatch patch;
2240 Notify(m_targetPathList[i],git_wc_notify_sendmail_start);
2242 int retry=0;
2243 while(retry<3)
2245 if(!!patch.Send((CString&)m_targetPathList[i].GetWinPathString(),this->m_SendMailTO,
2246 this->m_SendMailCC,!!(this->m_SendMailFlags&SENDMAIL_ATTACHMENT),!!(this->m_SendMailFlags&SENDMAIL_MAPI)))
2248 Notify(m_targetPathList[i],git_wc_notify_sendmail_error,ret,&patch.m_LastError);
2249 ret = false;
2252 else
2254 ret = true;
2255 break;
2257 retry++;
2258 if (retry < 3)
2259 Notify(m_targetPathList[i],git_wc_notify_sendmail_retry,ret,&patch.m_LastError);
2260 Sleep(2000);
2261 if(m_bCancelled)
2263 CString str(_T("User Canceled"));
2264 Notify(m_targetPathList[i],git_wc_notify_sendmail_error,ret,&str);
2265 return false;
2268 if (ret)
2269 Notify(m_targetPathList[i],git_wc_notify_sendmail_done,ret);
2272 return ret;
2275 LRESULT CGitProgressDlg::OnTaskbarBtnCreated(WPARAM /*wParam*/, LPARAM /*lParam*/)
2277 m_pTaskbarList.Release();
2278 m_pTaskbarList.CoCreateInstance(CLSID_TaskbarList);
2279 return 0;