Fixed issue #1499: Allow to show log if current HEAD and selected ref is orphan branc...
[TortoiseGit.git] / src / TortoiseProc / GitProgressDlg.cpp
blobf77d423874400cc100a02d1907b84d22c300edfa
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 , m_bErrorsOccurred(false)
78 #if 0
79 , m_Revision(_T("HEAD"))
80 //, m_RevisionEnd(0)
81 , m_bLockWarning(false)
82 , m_bLockExists(false)
83 , m_bThreadRunning(FALSE)
84 , m_nConflicts(0)
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 , sDryRun(MAKEINTRESOURCE(IDS_PROGRS_DRYRUN))
97 , sRecordOnly(MAKEINTRESOURCE(IDS_MERGE_RECORDONLY))
98 #endif
102 CGitProgressDlg::~CGitProgressDlg()
104 for (size_t i=0; i<m_arData.size(); i++)
106 delete m_arData[i];
108 if(m_pThread != NULL)
110 delete m_pThread;
114 void CGitProgressDlg::DoDataExchange(CDataExchange* pDX)
116 CResizableStandAloneDialog::DoDataExchange(pDX);
117 DDX_Control(pDX, IDC_SVNPROGRESS, m_ProgList);
120 BEGIN_MESSAGE_MAP(CGitProgressDlg, CResizableStandAloneDialog)
121 ON_BN_CLICKED(IDC_LOGBUTTON, OnBnClickedLogbutton)
122 ON_NOTIFY(NM_CUSTOMDRAW, IDC_SVNPROGRESS, OnNMCustomdrawSvnprogress)
123 ON_WM_CLOSE()
124 ON_NOTIFY(NM_DBLCLK, IDC_SVNPROGRESS, OnNMDblclkSvnprogress)
125 ON_NOTIFY(HDN_ITEMCLICK, 0, OnHdnItemclickSvnprogress)
126 ON_WM_SETCURSOR()
127 ON_WM_CONTEXTMENU()
128 ON_REGISTERED_MESSAGE(WM_GITPROGRESS, OnGitProgress)
129 ON_WM_TIMER()
130 ON_EN_SETFOCUS(IDC_INFOTEXT, &CGitProgressDlg::OnEnSetfocusInfotext)
131 ON_NOTIFY(LVN_BEGINDRAG, IDC_SVNPROGRESS, &CGitProgressDlg::OnLvnBegindragSvnprogress)
132 ON_WM_SIZE()
133 ON_NOTIFY(LVN_GETDISPINFO, IDC_SVNPROGRESS, &CGitProgressDlg::OnLvnGetdispinfoSvnprogress)
134 ON_BN_CLICKED(IDC_NONINTERACTIVE, &CGitProgressDlg::OnBnClickedNoninteractive)
135 ON_MESSAGE(WM_SHOWCONFLICTRESOLVER, OnShowConflictResolver)
136 ON_REGISTERED_MESSAGE(WM_TASKBARBTNCREATED, OnTaskbarBtnCreated)
137 END_MESSAGE_MAP()
139 BOOL CGitProgressDlg::Cancel()
141 return m_bCancelled;
144 LRESULT CGitProgressDlg::OnShowConflictResolver(WPARAM /*wParam*/, LPARAM /*lParam*/)
146 #if 0
147 CConflictResolveDlg dlg(this);
148 const svn_wc_conflict_description_t *description = (svn_wc_conflict_description_t *)lParam;
149 if (description)
151 dlg.SetConflictDescription(description);
152 if (m_pTaskbarList)
154 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_PAUSED);
156 if (dlg.DoModal() == IDOK)
158 if (dlg.GetResult() == svn_wc_conflict_choose_postpone)
160 // if the result is conflicted and the dialog returned IDOK,
161 // that means we should not ask again in case of a conflict
162 m_AlwaysConflicted = true;
163 ::SendMessage(GetDlgItem(IDC_NONINTERACTIVE)->GetSafeHwnd(), BM_SETCHECK, BST_CHECKED, 0);
166 m_mergedfile = dlg.GetMergedFile();
167 m_bCancelled = dlg.IsCancelled();
168 if (m_pTaskbarList)
169 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_INDETERMINATE);
170 return dlg.GetResult();
173 return svn_wc_conflict_choose_postpone;
174 #endif
175 return 0;
177 #if 0
178 svn_wc_conflict_choice_t CGitProgressDlg::ConflictResolveCallback(const svn_wc_conflict_description_t *description, CString& mergedfile)
180 // we only bother the user when merging
181 if (((m_Command == GitProgress_Merge)||(m_Command == GitProgress_MergeAll)||(m_Command == GitProgress_MergeReintegrate))&&(!m_AlwaysConflicted)&&(description))
183 // we're in a worker thread here. That means we must not show a dialog from the thread
184 // but let the UI thread do it.
185 // To do that, we send a message to the UI thread and let it show the conflict resolver dialog.
186 LRESULT dlgResult = ::SendMessage(GetSafeHwnd(), WM_SHOWCONFLICTRESOLVER, 0, (LPARAM)description);
187 mergedfile = m_mergedfile;
188 return (svn_wc_conflict_choice_t)dlgResult;
191 return svn_wc_conflict_choose_postpone;
193 #endif
194 void CGitProgressDlg::AddItemToList()
196 int totalcount = m_ProgList.GetItemCount();
198 m_ProgList.SetItemCountEx(totalcount+1, LVSICF_NOSCROLL|LVSICF_NOINVALIDATEALL);
199 // make columns width fit
200 if (iFirstResized < 30)
202 // only resize the columns for the first 30 or so entries.
203 // after that, don't resize them anymore because that's an
204 // expensive function call and the columns will be sized
205 // close enough already.
206 ResizeColumns();
207 iFirstResized++;
210 // Make sure the item is *entirely* visible even if the horizontal
211 // scroll bar is visible.
212 int count = m_ProgList.GetCountPerPage();
213 if (totalcount <= (m_ProgList.GetTopIndex() + count + nEnsureVisibleCount + 2))
215 nEnsureVisibleCount++;
216 m_bLastVisible = true;
218 else
220 nEnsureVisibleCount = 0;
221 if (IsIconic() == 0)
222 m_bLastVisible = false;
227 BOOL CGitProgressDlg::Notify(const CTGitPath& path, git_wc_notify_action_t action,
228 int /*status*/ ,
229 CString *strErr
231 svn_node_kind_t kind, const CString& mime_type,
232 svn_wc_notify_state_t content_state,
233 svn_wc_notify_state_t prop_state, LONG rev,
234 const svn_lock_t * lock, svn_wc_notify_lock_state_t lock_state,
235 const CString& changelistname,
236 svn_merge_range_t * range,
237 svn_error_t * err, apr_pool_t * pool
240 bool bNoNotify = false;
241 bool bDoAddData = true;
242 NotificationData * data = new NotificationData();
243 data->path = path;
244 data->action = action;
245 data->sPathColumnText=path.GetGitPathString();
246 data->bAuxItem = false;
247 #if 0
248 data->kind = kind;
249 data->mime_type = mime_type;
250 data->content_state = content_state;
251 data->prop_state = prop_state;
252 data->rev = rev;
253 data->lock_state = lock_state;
254 data->changelistname = changelistname;
255 if ((lock)&&(lock->owner))
256 data->owner = CUnicodeUtils::GetUnicode(lock->owner);
257 data->sPathColumnText = path.GetUIPathString();
258 if (!m_basePath.IsEmpty())
259 data->basepath = m_basePath;
260 if (range)
261 data->merge_range = *range;
262 #endif
263 switch (data->action)
265 case git_wc_notify_add:
266 //case svn_wc_notify_update_add:
267 // if ((data->content_state == svn_wc_notify_state_conflicted) || (data->prop_state == svn_wc_notify_state_conflicted))
268 // {
269 // data->color = m_Colors.GetColor(CColors::Conflict);
270 // data->bConflictedActionItem = true;
271 // data->sActionColumnText.LoadString(IDS_SVNACTION_CONFLICTED);
272 // m_nConflicts++;
273 // }
274 // else
275 // {
276 // m_bMergesAddsDeletesOccurred = true;
277 data->sActionColumnText.LoadString(IDS_SVNACTION_ADD);
278 data->color = m_Colors.GetColor(CColors::Added);
279 // }
280 break;
281 case git_wc_notify_sendmail_start:
282 data->bAuxItem = true;
283 data->sActionColumnText.LoadString(IDS_SVNACTION_SENDMAIL_START);
284 data->color = m_Colors.GetColor(CColors::Modified);
285 break;
287 case git_wc_notify_sendmail_error:
288 data->bAuxItem = true;
289 data->sActionColumnText.LoadString(IDS_SVNACTION_SENDMAIL_ERROR);
290 if(strErr)
291 data->sPathColumnText = *strErr;
292 else
293 data->sPathColumnText.Empty();
294 data->color = m_Colors.GetColor(CColors::Modified);
295 break;
297 case git_wc_notify_sendmail_done:
299 data->sActionColumnText.LoadString(IDS_SVNACTION_SENDMAIL_DONE);
300 data->sPathColumnText.Empty();
301 data->color = m_Colors.GetColor(CColors::Modified);
302 break;
304 case git_wc_notify_sendmail_retry:
305 data->sActionColumnText.LoadString(IDS_SVNACTION_SENDMAIL_RETRY);
306 data->sPathColumnText.Empty();
307 data->color = m_Colors.GetColor(CColors::Modified);
308 break;
311 case git_wc_notify_resolved:
312 data->sActionColumnText.LoadString(IDS_SVNACTION_RESOLVE);
313 break;
315 case git_wc_notify_revert:
316 data->sActionColumnText.LoadString(IDS_SVNACTION_REVERT);
317 break;
319 #if 0
320 case svn_wc_notify_commit_added:
321 data->sActionColumnText.LoadString(IDS_SVNACTION_ADDING);
322 data->color = m_Colors.GetColor(CColors::Added);
323 break;
324 case svn_wc_notify_copy:
325 data->sActionColumnText.LoadString(IDS_SVNACTION_COPY);
326 break;
327 case svn_wc_notify_commit_modified:
328 data->sActionColumnText.LoadString(IDS_SVNACTION_MODIFIED);
329 data->color = m_Colors.GetColor(CColors::Modified);
330 break;
331 case svn_wc_notify_delete:
332 case svn_wc_notify_update_delete:
333 data->sActionColumnText.LoadString(IDS_SVNACTION_DELETE);
334 m_bMergesAddsDeletesOccurred = true;
335 data->color = m_Colors.GetColor(CColors::Deleted);
336 break;
337 case svn_wc_notify_commit_deleted:
338 data->sActionColumnText.LoadString(IDS_SVNACTION_DELETING);
339 data->color = m_Colors.GetColor(CColors::Deleted);
340 break;
341 case svn_wc_notify_restore:
342 data->sActionColumnText.LoadString(IDS_SVNACTION_RESTORE);
343 break;
345 case svn_wc_notify_update_replace:
346 case svn_wc_notify_commit_replaced:
347 data->sActionColumnText.LoadString(IDS_SVNACTION_REPLACED);
348 data->color = m_Colors.GetColor(CColors::Deleted);
349 break;
350 case svn_wc_notify_exists:
351 if ((data->content_state == svn_wc_notify_state_conflicted) || (data->prop_state == svn_wc_notify_state_conflicted))
353 data->color = m_Colors.GetColor(CColors::Conflict);
354 data->bConflictedActionItem = true;
355 m_nConflicts++;
356 data->sActionColumnText.LoadString(IDS_SVNACTION_CONFLICTED);
358 else if ((data->content_state == svn_wc_notify_state_merged) || (data->prop_state == svn_wc_notify_state_merged))
360 data->color = m_Colors.GetColor(CColors::Merged);
361 m_bMergesAddsDeletesOccurred = true;
362 data->sActionColumnText.LoadString(IDS_SVNACTION_MERGED);
364 else
365 data->sActionColumnText.LoadString(IDS_SVNACTION_EXISTS);
366 break;
367 case svn_wc_notify_update_update:
368 // if this is an inoperative dir change, don't show the notification.
369 // an inoperative dir change is when a directory gets updated without
370 // any real change in either text or properties.
371 if ((kind == svn_node_dir)
372 && ((prop_state == svn_wc_notify_state_inapplicable)
373 || (prop_state == svn_wc_notify_state_unknown)
374 || (prop_state == svn_wc_notify_state_unchanged)))
376 bNoNotify = true;
377 break;
379 if ((data->content_state == svn_wc_notify_state_conflicted) || (data->prop_state == svn_wc_notify_state_conflicted))
381 data->color = m_Colors.GetColor(CColors::Conflict);
382 data->bConflictedActionItem = true;
383 m_nConflicts++;
384 data->sActionColumnText.LoadString(IDS_SVNACTION_CONFLICTED);
386 else if ((data->content_state == svn_wc_notify_state_merged) || (data->prop_state == svn_wc_notify_state_merged))
388 data->color = m_Colors.GetColor(CColors::Merged);
389 m_bMergesAddsDeletesOccurred = true;
390 data->sActionColumnText.LoadString(IDS_SVNACTION_MERGED);
392 else if (((data->content_state != svn_wc_notify_state_unchanged)&&(data->content_state != svn_wc_notify_state_unknown)) ||
393 ((data->prop_state != svn_wc_notify_state_unchanged)&&(data->prop_state != svn_wc_notify_state_unknown)))
395 data->sActionColumnText.LoadString(IDS_SVNACTION_UPDATE);
397 else
399 bNoNotify = true;
400 break;
402 if (lock_state == svn_wc_notify_lock_state_unlocked)
404 CString temp(MAKEINTRESOURCE(IDS_SVNACTION_UNLOCKED));
405 data->sActionColumnText += _T(", ") + temp;
407 break;
409 case svn_wc_notify_update_external:
410 // For some reason we build a list of externals...
411 m_ExtStack.AddHead(path.GetUIPathString());
412 data->sActionColumnText.LoadString(IDS_SVNACTION_EXTERNAL);
413 data->bAuxItem = true;
414 break;
416 case svn_wc_notify_update_completed:
418 data->sActionColumnText.LoadString(IDS_SVNACTION_COMPLETED);
419 data->bAuxItem = true;
420 bool bEmpty = !!m_ExtStack.IsEmpty();
421 if (!bEmpty)
422 data->sPathColumnText.Format(IDS_PROGRS_PATHATREV, (LPCTSTR)m_ExtStack.RemoveHead(), rev);
423 else
424 data->sPathColumnText.Format(IDS_PROGRS_ATREV, rev);
426 if ((m_nConflicts>0)&&(bEmpty))
428 // We're going to add another aux item - let's shove this current onto the list first
429 // I don't really like this, but it will do for the moment.
430 m_arData.push_back(data);
431 AddItemToList();
433 data = new NotificationData();
434 data->bAuxItem = true;
435 data->sActionColumnText.LoadString(IDS_PROGRS_CONFLICTSOCCURED_WARNING);
436 data->sPathColumnText.LoadString(IDS_PROGRS_CONFLICTSOCCURED);
437 data->color = m_Colors.GetColor(CColors::Conflict);
438 CSoundUtils::PlayTSVNWarning();
439 // This item will now be added after the switch statement
441 if (!m_basePath.IsEmpty())
442 m_FinishedRevMap[m_basePath.GetSVNApiPath(pool)] = rev;
443 m_RevisionEnd = rev;
444 m_bFinishedItemAdded = true;
446 break;
447 case svn_wc_notify_commit_postfix_txdelta:
448 data->sActionColumnText.LoadString(IDS_SVNACTION_POSTFIX);
449 break;
450 case svn_wc_notify_failed_revert:
451 data->sActionColumnText.LoadString(IDS_SVNACTION_FAILEDREVERT);
452 break;
453 case svn_wc_notify_status_completed:
454 case svn_wc_notify_status_external:
455 data->sActionColumnText.LoadString(IDS_SVNACTION_STATUS);
456 break;
457 case svn_wc_notify_skip:
458 if ((content_state == svn_wc_notify_state_missing)||(content_state == svn_wc_notify_state_obstructed)||(content_state == svn_wc_notify_state_conflicted))
460 data->sActionColumnText.LoadString(IDS_SVNACTION_SKIPMISSING);
462 // The color settings dialog describes the red color with
463 // "possible or real conflict / obstructed" which also applies to
464 // skipped targets during a merge. So we just use the same color.
465 data->color = m_Colors.GetColor(CColors::Conflict);
467 else
468 data->sActionColumnText.LoadString(IDS_SVNACTION_SKIP);
469 break;
470 case svn_wc_notify_locked:
471 if ((lock)&&(lock->owner))
472 data->sActionColumnText.Format(IDS_SVNACTION_LOCKEDBY, (LPCTSTR)CUnicodeUtils::GetUnicode(lock->owner));
473 break;
474 case svn_wc_notify_unlocked:
475 data->sActionColumnText.LoadString(IDS_SVNACTION_UNLOCKED);
476 break;
477 case svn_wc_notify_failed_lock:
478 data->sActionColumnText.LoadString(IDS_SVNACTION_FAILEDLOCK);
479 m_arData.push_back(data);
480 AddItemToList();
481 ReportError(SVN::GetErrorString(err));
482 bDoAddData = false;
483 if (err->apr_err == SVN_ERR_FS_OUT_OF_DATE)
484 m_bLockWarning = true;
485 if (err->apr_err == SVN_ERR_FS_PATH_ALREADY_LOCKED)
486 m_bLockExists = true;
487 break;
488 case svn_wc_notify_failed_unlock:
489 data->sActionColumnText.LoadString(IDS_SVNACTION_FAILEDUNLOCK);
490 m_arData.push_back(data);
491 AddItemToList();
492 ReportError(SVN::GetErrorString(err));
493 bDoAddData = false;
494 if (err->apr_err == SVN_ERR_FS_OUT_OF_DATE)
495 m_bLockWarning = true;
496 break;
497 case svn_wc_notify_changelist_set:
498 data->sActionColumnText.Format(IDS_SVNACTION_CHANGELISTSET, (LPCTSTR)data->changelistname);
499 break;
500 case svn_wc_notify_changelist_clear:
501 data->sActionColumnText.LoadString(IDS_SVNACTION_CHANGELISTCLEAR);
502 break;
503 case svn_wc_notify_changelist_moved:
504 data->sActionColumnText.Format(IDS_SVNACTION_CHANGELISTMOVED, (LPCTSTR)data->changelistname);
505 break;
506 case svn_wc_notify_foreign_merge_begin:
507 case svn_wc_notify_merge_begin:
508 if (range == NULL)
509 data->sActionColumnText.LoadString(IDS_SVNACTION_MERGEBEGINNONE);
510 else if ((data->merge_range.start == data->merge_range.end) || (data->merge_range.start == data->merge_range.end - 1))
511 data->sActionColumnText.Format(IDS_SVNACTION_MERGEBEGINSINGLE, data->merge_range.end);
512 else if (data->merge_range.start - 1 == data->merge_range.end)
513 data->sActionColumnText.Format(IDS_SVNACTION_MERGEBEGINSINGLEREVERSE, data->merge_range.start);
514 else if (data->merge_range.start < data->merge_range.end)
515 data->sActionColumnText.Format(IDS_SVNACTION_MERGEBEGINMULTIPLE, data->merge_range.start + 1, data->merge_range.end);
516 else
517 data->sActionColumnText.Format(IDS_SVNACTION_MERGEBEGINMULTIPLEREVERSE, data->merge_range.start, data->merge_range.end + 1);
518 data->bAuxItem = true;
519 break;
520 #endif
521 default:
522 break;
523 } // switch (data->action)
525 if (bNoNotify)
526 delete data;
527 else
529 if (bDoAddData)
531 m_arData.push_back(data);
532 AddItemToList();
533 if ((!data->bAuxItem) && (m_itemCount > 0))
535 m_itemCount--;
537 CProgressCtrl * progControl = (CProgressCtrl *)GetDlgItem(IDC_PROGRESSBAR);
538 progControl->ShowWindow(SW_SHOW);
539 progControl->SetPos(m_itemCountTotal - m_itemCount);
540 progControl->SetRange32(0, m_itemCountTotal);
541 if (m_pTaskbarList)
543 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
544 m_pTaskbarList->SetProgressValue(m_hWnd, m_itemCountTotal-m_itemCount, m_itemCountTotal);
548 //if ((action == svn_wc_notify_commit_postfix_txdelta)&&(bSecondResized == FALSE))
550 // ResizeColumns();
551 // bSecondResized = TRUE;
555 return TRUE;
559 CString CGitProgressDlg::BuildInfoString()
561 CString infotext;
562 if(this->m_Command == GitProgress_Resolve)
563 infotext = _T("You need commit your change after resolve conflict");
564 #if 0
566 CString temp;
567 int added = 0;
568 int copied = 0;
569 int deleted = 0;
570 int restored = 0;
571 int reverted = 0;
572 int resolved = 0;
573 int conflicted = 0;
574 int updated = 0;
575 int merged = 0;
576 int modified = 0;
577 int skipped = 0;
578 int replaced = 0;
580 for (size_t i=0; i<m_arData.size(); ++i)
582 const NotificationData * dat = m_arData[i];
583 switch (dat->action)
585 case svn_wc_notify_add:
586 case svn_wc_notify_update_add:
587 case svn_wc_notify_commit_added:
588 if (dat->bConflictedActionItem)
589 conflicted++;
590 else
591 added++;
592 break;
593 case svn_wc_notify_copy:
594 copied++;
595 break;
596 case svn_wc_notify_delete:
597 case svn_wc_notify_update_delete:
598 case svn_wc_notify_commit_deleted:
599 deleted++;
600 break;
601 case svn_wc_notify_restore:
602 restored++;
603 break;
604 case svn_wc_notify_revert:
605 reverted++;
606 break;
607 case svn_wc_notify_resolved:
608 resolved++;
609 break;
610 case svn_wc_notify_update_update:
611 if (dat->bConflictedActionItem)
612 conflicted++;
613 else if ((dat->content_state == svn_wc_notify_state_merged) || (dat->prop_state == svn_wc_notify_state_merged))
614 merged++;
615 else
616 updated++;
617 break;
618 case svn_wc_notify_commit_modified:
619 modified++;
620 break;
621 case svn_wc_notify_skip:
622 skipped++;
623 break;
624 case svn_wc_notify_commit_replaced:
625 replaced++;
626 break;
629 if (conflicted)
631 temp.LoadString(IDS_SVNACTION_CONFLICTED);
632 infotext += temp;
633 temp.Format(_T(":%d "), conflicted);
634 infotext += temp;
636 if (skipped)
638 temp.LoadString(IDS_SVNACTION_SKIP);
639 infotext += temp;
640 infotext.AppendFormat(_T(":%d "), skipped);
642 if (merged)
644 temp.LoadString(IDS_SVNACTION_MERGED);
645 infotext += temp;
646 infotext.AppendFormat(_T(":%d "), merged);
648 if (added)
650 temp.LoadString(IDS_SVNACTION_ADD);
651 infotext += temp;
652 infotext.AppendFormat(_T(":%d "), added);
654 if (deleted)
656 temp.LoadString(IDS_SVNACTION_DELETE);
657 infotext += temp;
658 infotext.AppendFormat(_T(":%d "), deleted);
660 if (modified)
662 temp.LoadString(IDS_SVNACTION_MODIFIED);
663 infotext += temp;
664 infotext.AppendFormat(_T(":%d "), modified);
666 if (copied)
668 temp.LoadString(IDS_SVNACTION_COPY);
669 infotext += temp;
670 infotext.AppendFormat(_T(":%d "), copied);
672 if (replaced)
674 temp.LoadString(IDS_SVNACTION_REPLACED);
675 infotext += temp;
676 infotext.AppendFormat(_T(":%d "), replaced);
678 if (updated)
680 temp.LoadString(IDS_SVNACTION_UPDATE);
681 infotext += temp;
682 infotext.AppendFormat(_T(":%d "), updated);
684 if (restored)
686 temp.LoadString(IDS_SVNACTION_RESTORE);
687 infotext += temp;
688 infotext.AppendFormat(_T(":%d "), restored);
690 if (reverted)
692 temp.LoadString(IDS_SVNACTION_REVERT);
693 infotext += temp;
694 infotext.AppendFormat(_T(":%d "), reverted);
696 if (resolved)
698 temp.LoadString(IDS_SVNACTION_RESOLVE);
699 infotext += temp;
700 infotext.AppendFormat(_T(":%d "), resolved);
702 #endif
703 return infotext;
706 void CGitProgressDlg::SetSelectedList(const CTGitPathList& selPaths)
708 m_selectedPaths = selPaths;
711 void CGitProgressDlg::ResizeColumns()
713 m_ProgList.SetRedraw(FALSE);
715 TCHAR textbuf[MAX_PATH];
717 int maxcol = ((CHeaderCtrl*)(m_ProgList.GetDlgItem(0)))->GetItemCount()-1;
718 for (int col = 0; col <= maxcol; col++)
720 // find the longest width of all items
721 int count = m_ProgList.GetItemCount();
722 HDITEM hdi = {0};
723 hdi.mask = HDI_TEXT;
724 hdi.pszText = textbuf;
725 hdi.cchTextMax = sizeof(textbuf);
726 ((CHeaderCtrl*)(m_ProgList.GetDlgItem(0)))->GetItem(col, &hdi);
727 int cx = m_ProgList.GetStringWidth(hdi.pszText)+20; // 20 pixels for col separator and margin
729 for (int index = 0; index<count; ++index)
731 // get the width of the string and add 12 pixels for the column separator and margins
732 int linewidth = cx;
733 switch (col)
735 case 0:
736 linewidth = m_ProgList.GetStringWidth(m_arData[index]->sActionColumnText) + 12;
737 break;
738 case 1:
739 linewidth = m_ProgList.GetStringWidth(m_arData[index]->sPathColumnText) + 12;
740 break;
742 if (cx < linewidth)
743 cx = linewidth;
745 m_ProgList.SetColumnWidth(col, cx);
748 m_ProgList.SetRedraw(TRUE);
751 BOOL CGitProgressDlg::OnInitDialog()
753 __super::OnInitDialog();
755 // Let the TaskbarButtonCreated message through the UIPI filter. If we don't
756 // do this, Explorer would be unable to send that message to our window if we
757 // were running elevated. It's OK to make the call all the time, since if we're
758 // not elevated, this is a no-op.
759 CHANGEFILTERSTRUCT cfs = { sizeof(CHANGEFILTERSTRUCT) };
760 typedef BOOL STDAPICALLTYPE ChangeWindowMessageFilterExDFN(HWND hWnd, UINT message, DWORD action, PCHANGEFILTERSTRUCT pChangeFilterStruct);
761 CAutoLibrary hUser = ::LoadLibrary(_T("user32.dll"));
762 if (hUser)
764 ChangeWindowMessageFilterExDFN *pfnChangeWindowMessageFilterEx = (ChangeWindowMessageFilterExDFN*)GetProcAddress(hUser, "ChangeWindowMessageFilterEx");
765 if (pfnChangeWindowMessageFilterEx)
767 pfnChangeWindowMessageFilterEx(m_hWnd, WM_TASKBARBTNCREATED, MSGFLT_ALLOW, &cfs);
770 m_pTaskbarList.Release();
771 m_pTaskbarList.CoCreateInstance(CLSID_TaskbarList);
773 m_ProgList.SetExtendedStyle (LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER);
775 m_ProgList.DeleteAllItems();
776 int c = ((CHeaderCtrl*)(m_ProgList.GetDlgItem(0)))->GetItemCount()-1;
777 while (c>=0)
778 m_ProgList.DeleteColumn(c--);
779 CString temp;
780 temp.LoadString(IDS_PROGRS_ACTION);
781 m_ProgList.InsertColumn(0, temp);
782 temp.LoadString(IDS_PROGRS_PATH);
783 m_ProgList.InsertColumn(1, temp);
785 m_pThread = AfxBeginThread(ProgressThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
786 if (m_pThread==NULL)
788 ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
790 else
792 m_pThread->m_bAutoDelete = FALSE;
793 m_pThread->ResumeThread();
796 UpdateData(FALSE);
798 // Call this early so that the column headings aren't hidden before any
799 // text gets added.
800 ResizeColumns();
802 SetTimer(VISIBLETIMER, 300, NULL);
804 AddAnchor(IDC_SVNPROGRESS, TOP_LEFT, BOTTOM_RIGHT);
805 AddAnchor(IDC_PROGRESSLABEL, BOTTOM_LEFT, BOTTOM_CENTER);
806 AddAnchor(IDC_PROGRESSBAR, BOTTOM_CENTER, BOTTOM_RIGHT);
807 AddAnchor(IDC_INFOTEXT, BOTTOM_LEFT, BOTTOM_RIGHT);
808 AddAnchor(IDC_NONINTERACTIVE, BOTTOM_LEFT, BOTTOM_RIGHT);
809 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
810 AddAnchor(IDOK, BOTTOM_RIGHT);
811 AddAnchor(IDC_LOGBUTTON, BOTTOM_RIGHT);
812 //SetPromptParentWindow(this->m_hWnd);
813 if (hWndExplorer)
814 CenterWindow(CWnd::FromHandle(hWndExplorer));
815 EnableSaveRestore(_T("GITProgressDlg"));
816 return TRUE;
819 bool CGitProgressDlg::SetBackgroundImage(UINT nID)
821 return CAppUtils::SetListCtrlBackgroundImage(m_ProgList.GetSafeHwnd(), nID);
824 void CGitProgressDlg::ReportGitError()
826 ReportError(CString(giterr_last()->message));
829 void CGitProgressDlg::ReportError(const CString& sError)
831 CSoundUtils::PlayTGitError();
832 ReportString(sError, CString(MAKEINTRESOURCE(IDS_ERR_ERROR)), m_Colors.GetColor(CColors::Conflict));
833 m_bErrorsOccurred = true;
836 void CGitProgressDlg::ReportWarning(const CString& sWarning)
838 CSoundUtils::PlayTGitWarning();
839 ReportString(sWarning, CString(MAKEINTRESOURCE(IDS_WARN_WARNING)), m_Colors.GetColor(CColors::Conflict));
842 void CGitProgressDlg::ReportNotification(const CString& sNotification)
844 CSoundUtils::PlayTGitNotification();
845 ReportString(sNotification, CString(MAKEINTRESOURCE(IDS_WARN_NOTE)));
848 void CGitProgressDlg::ReportCmd(const CString& sCmd)
850 ReportString(sCmd, CString(MAKEINTRESOURCE(IDS_PROGRS_CMDINFO)), m_Colors.GetColor(CColors::Cmd));
853 void CGitProgressDlg::ReportString(CString sMessage, const CString& sMsgKind, COLORREF color)
855 // instead of showing a dialog box with the error message or notification,
856 // just insert the error text into the list control.
857 // that way the user isn't 'interrupted' by a dialog box popping up!
859 // the message may be split up into different lines
860 // so add a new entry for each line of the message
861 while (!sMessage.IsEmpty())
863 NotificationData * data = new NotificationData();
864 data->bAuxItem = true;
865 data->sActionColumnText = sMsgKind;
866 if (sMessage.Find('\n')>=0)
867 data->sPathColumnText = sMessage.Left(sMessage.Find('\n'));
868 else
869 data->sPathColumnText = sMessage;
870 data->sPathColumnText.Trim(_T("\n\r"));
871 data->color = color;
872 if (sMessage.Find('\n')>=0)
874 sMessage = sMessage.Mid(sMessage.Find('\n'));
875 sMessage.Trim(_T("\n\r"));
877 else
878 sMessage.Empty();
879 m_arData.push_back(data);
880 AddItemToList();
884 UINT CGitProgressDlg::ProgressThreadEntry(LPVOID pVoid)
886 return ((CGitProgressDlg*)pVoid)->ProgressThread();
889 UINT CGitProgressDlg::ProgressThread()
891 // The SetParams function should have loaded something for us
893 CString temp;
894 CString sWindowTitle;
895 bool localoperation = false;
896 bool bSuccess = false;
897 m_AlwaysConflicted = false;
899 DialogEnableWindow(IDOK, FALSE);
900 DialogEnableWindow(IDCANCEL, TRUE);
901 // SetAndClearProgressInfo(m_hWnd);
902 m_itemCount = m_itemCountTotal;
904 InterlockedExchange(&m_bThreadRunning, TRUE);
905 iFirstResized = 0;
906 bSecondResized = FALSE;
907 m_bFinishedItemAdded = false;
908 CTime startTime = CTime::GetCurrentTime();
910 if (m_pTaskbarList)
911 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_INDETERMINATE);
913 switch (m_Command)
915 case GitProgress_Add:
916 bSuccess = CmdAdd(sWindowTitle, localoperation);
917 break;
918 case GitProgress_Copy:
919 bSuccess = CmdCopy(sWindowTitle, localoperation);
920 break;
921 case GitProgress_Export:
922 bSuccess = CmdExport(sWindowTitle, localoperation);
923 break;
924 case GitProgress_Rename:
925 bSuccess = CmdRename(sWindowTitle, localoperation);
926 break;
927 case GitProgress_Resolve:
928 bSuccess = CmdResolve(sWindowTitle, localoperation);
929 break;
930 case GitProgress_Revert:
931 bSuccess = CmdRevert(sWindowTitle, localoperation);
932 break;
933 case GitProgress_Switch:
934 bSuccess = CmdSwitch(sWindowTitle, localoperation);
935 break;
936 case GitProgress_SendMail:
937 bSuccess = CmdSendMail(sWindowTitle, localoperation);
938 break;
940 if (!bSuccess)
941 temp.LoadString(IDS_PROGRS_TITLEFAILED);
942 else
943 temp.LoadString(IDS_PROGRS_TITLEFIN);
944 sWindowTitle = sWindowTitle + _T(" ") + temp;
945 SetWindowText(sWindowTitle);
947 KillTimer(TRANSFERTIMER);
948 KillTimer(VISIBLETIMER);
950 if (m_pTaskbarList)
952 if (DidErrorsOccur())
954 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_ERROR);
955 m_pTaskbarList->SetProgressValue(m_hWnd, 100, 100);
957 else
958 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NOPROGRESS);
961 DialogEnableWindow(IDCANCEL, FALSE);
962 DialogEnableWindow(IDOK, TRUE);
964 CString info = BuildInfoString();
965 if (!bSuccess)
966 info.LoadString(IDS_PROGRS_INFOFAILED);
967 SetDlgItemText(IDC_INFOTEXT, info);
968 ResizeColumns();
969 CWnd * pWndOk = GetDlgItem(IDOK);
970 if (pWndOk && ::IsWindow(pWndOk->GetSafeHwnd()))
972 SendMessage(DM_SETDEFID, IDOK);
973 GetDlgItem(IDOK)->SetFocus();
976 CString sFinalInfo;
977 if (!m_sTotalBytesTransferred.IsEmpty())
979 CTimeSpan time = CTime::GetCurrentTime() - startTime;
980 temp.Format(IDS_PROGRS_TIME, (LONG)time.GetTotalMinutes(), (LONG)time.GetSeconds());
981 sFinalInfo.Format(IDS_PROGRS_FINALINFO, m_sTotalBytesTransferred, (LPCTSTR)temp);
982 SetDlgItemText(IDC_PROGRESSLABEL, sFinalInfo);
984 else
985 GetDlgItem(IDC_PROGRESSLABEL)->ShowWindow(SW_HIDE);
987 GetDlgItem(IDC_PROGRESSBAR)->ShowWindow(SW_HIDE);
989 if (!m_bFinishedItemAdded)
991 // there's no "finished: xxx" line at the end. We add one here to make
992 // sure the user sees that the command is actually finished.
993 NotificationData * data = new NotificationData();
994 data->bAuxItem = true;
995 data->sActionColumnText.LoadString(IDS_PROGRS_FINISHED);
996 m_arData.push_back(data);
997 AddItemToList();
1000 int count = m_ProgList.GetItemCount();
1001 if ((count > 0)&&(m_bLastVisible))
1002 m_ProgList.EnsureVisible(count-1, FALSE);
1004 CLogFile logfile;
1005 if (logfile.Open())
1007 logfile.AddTimeLine();
1008 for (size_t i=0; i<m_arData.size(); i++)
1010 NotificationData * data = m_arData[i];
1011 temp.Format(_T("%-20s : %s"), (LPCTSTR)data->sActionColumnText, (LPCTSTR)data->sPathColumnText);
1012 logfile.AddLine(temp);
1014 if (!sFinalInfo.IsEmpty())
1015 logfile.AddLine(sFinalInfo);
1016 logfile.Close();
1019 m_bCancelled = TRUE;
1020 InterlockedExchange(&m_bThreadRunning, FALSE);
1021 RefreshCursor();
1023 #if 0
1024 DWORD dwAutoClose = CRegStdDWORD(_T("Software\\TortoiseGit\\AutoClose"), CLOSE_MANUAL);
1025 if (m_options & ProgOptDryRun)
1026 dwAutoClose = 0; // dry run means progress dialog doesn't auto close at all
1027 if (!m_bLastVisible)
1028 dwAutoClose = 0;
1029 if (m_dwCloseOnEnd != (DWORD)-1)
1030 dwAutoClose = m_dwCloseOnEnd; // command line value has priority over setting value
1031 if ((dwAutoClose == CLOSE_NOERRORS)&&(!m_bErrorsOccurred))
1032 PostMessage(WM_COMMAND, 1, (LPARAM)GetDlgItem(IDOK)->m_hWnd);
1033 if ((dwAutoClose == CLOSE_NOCONFLICTS)&&(!m_bErrorsOccurred)&&(m_nConflicts==0))
1034 PostMessage(WM_COMMAND, 1, (LPARAM)GetDlgItem(IDOK)->m_hWnd);
1035 if ((dwAutoClose == CLOSE_NOMERGES)&&(!m_bErrorsOccurred)&&(m_nConflicts==0)&&(!m_bMergesAddsDeletesOccurred))
1036 PostMessage(WM_COMMAND, 1, (LPARAM)GetDlgItem(IDOK)->m_hWnd);
1037 if ((dwAutoClose == CLOSE_LOCAL)&&(!m_bErrorsOccurred)&&(m_nConflicts==0)&&(localoperation))
1038 PostMessage(WM_COMMAND, 1, (LPARAM)GetDlgItem(IDOK)->m_hWnd);
1039 #endif
1041 //Don't do anything here which might cause messages to be sent to the window
1042 //The window thread is probably now blocked in OnOK if we've done an auto close
1043 return 0;
1046 void CGitProgressDlg::OnBnClickedLogbutton()
1048 switch(this->m_Command)
1050 case GitProgress_Add:
1051 case GitProgress_Resolve:
1053 CString cmd = _T(" /command:commit");
1054 cmd += _T(" /path:\"")+g_Git.m_CurrentDir+_T("\"");
1056 CAppUtils::RunTortoiseProc(cmd);
1057 this->EndDialog(IDOK);
1058 break;
1061 #if 0
1062 if (m_targetPathList.GetCount() != 1)
1063 return;
1064 StringRevMap::iterator it = m_UpdateStartRevMap.begin();
1065 svn_revnum_t rev = -1;
1066 if (it != m_UpdateStartRevMap.end())
1068 rev = it->second;
1070 CLogDlg dlg;
1071 dlg.SetParams(m_targetPathList[0], m_RevisionEnd, m_RevisionEnd, rev, 0, TRUE);
1072 dlg.DoModal();
1073 #endif
1077 void CGitProgressDlg::OnClose()
1079 if (m_bCancelled)
1081 TerminateThread(m_pThread->m_hThread, (DWORD)-1);
1082 InterlockedExchange(&m_bThreadRunning, FALSE);
1084 else
1086 m_bCancelled = TRUE;
1087 return;
1089 DialogEnableWindow(IDCANCEL, TRUE);
1090 __super::OnClose();
1093 void CGitProgressDlg::OnOK()
1095 if ((m_bCancelled)&&(!m_bThreadRunning))
1097 // I have made this wait a sensible amount of time (10 seconds) for the thread to finish
1098 // You must be careful in the thread that after posting the WM_COMMAND/IDOK message, you
1099 // don't do any more operations on the window which might require message passing
1100 // If you try to send windows messages once we're waiting here, then the thread can't finished
1101 // because the Window's message loop is blocked at this wait
1102 WaitForSingleObject(m_pThread->m_hThread, 10000);
1103 __super::OnOK();
1105 m_bCancelled = TRUE;
1108 void CGitProgressDlg::OnCancel()
1110 if ((m_bCancelled)&&(!m_bThreadRunning))
1111 __super::OnCancel();
1112 m_bCancelled = TRUE;
1115 void CGitProgressDlg::OnLvnGetdispinfoSvnprogress(NMHDR *pNMHDR, LRESULT *pResult)
1117 NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
1119 if (pDispInfo)
1121 if (pDispInfo->item.mask & LVIF_TEXT)
1123 if (pDispInfo->item.iItem < (int)m_arData.size())
1125 const NotificationData * data = m_arData[pDispInfo->item.iItem];
1126 switch (pDispInfo->item.iSubItem)
1128 case 0:
1129 lstrcpyn(m_columnbuf, data->sActionColumnText, MAX_PATH);
1130 break;
1131 case 1:
1132 lstrcpyn(m_columnbuf, data->sPathColumnText, pDispInfo->item.cchTextMax);
1133 if (!data->bAuxItem)
1135 int cWidth = m_ProgList.GetColumnWidth(1);
1136 cWidth = max(12, cWidth-12);
1137 CDC * pDC = m_ProgList.GetDC();
1138 if (pDC != NULL)
1140 CFont * pFont = pDC->SelectObject(m_ProgList.GetFont());
1141 PathCompactPath(pDC->GetSafeHdc(), m_columnbuf, cWidth);
1142 pDC->SelectObject(pFont);
1143 ReleaseDC(pDC);
1146 break;
1147 default:
1148 m_columnbuf[0] = 0;
1150 pDispInfo->item.pszText = m_columnbuf;
1154 *pResult = 0;
1157 void CGitProgressDlg::OnNMCustomdrawSvnprogress(NMHDR *pNMHDR, LRESULT *pResult)
1159 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
1161 // Take the default processing unless we set this to something else below.
1162 *pResult = CDRF_DODEFAULT;
1164 // First thing - check the draw stage. If it's the control's prepaint
1165 // stage, then tell Windows we want messages for every item.
1167 if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )
1169 *pResult = CDRF_NOTIFYITEMDRAW;
1171 else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )
1173 // This is the prepaint stage for an item. Here's where we set the
1174 // item's text color. Our return value will tell Windows to draw the
1175 // item itself, but it will use the new color we set here.
1177 // Tell Windows to paint the control itself.
1178 *pResult = CDRF_DODEFAULT;
1180 ASSERT(pLVCD->nmcd.dwItemSpec < m_arData.size());
1181 if(pLVCD->nmcd.dwItemSpec >= m_arData.size())
1183 return;
1185 const NotificationData * data = m_arData[pLVCD->nmcd.dwItemSpec];
1186 ASSERT(data != NULL);
1187 if (data == NULL)
1188 return;
1190 // Store the color back in the NMLVCUSTOMDRAW struct.
1191 pLVCD->clrText = data->color;
1195 void CGitProgressDlg::OnNMDblclkSvnprogress(NMHDR * /*pNMHDR*/, LRESULT * /*pResult*/)
1197 #if 0
1198 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1199 *pResult = 0;
1200 if (pNMLV->iItem < 0)
1201 return;
1202 if (m_options & ProgOptDryRun)
1203 return; //don't do anything in a dry-run.
1205 const NotificationData * data = m_arData[pNMLV->iItem];
1206 if (data == NULL)
1207 return;
1209 if (data->bConflictedActionItem)
1211 // We've double-clicked on a conflicted item - do a three-way merge on it
1212 SVNDiff::StartConflictEditor(data->path);
1214 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))
1216 // This is a modified file which has been merged on update. Diff it against base
1217 CTGitPath temporaryFile;
1218 SVNDiff diff(this, this->m_hWnd, true);
1219 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
1220 svn_revnum_t baseRev = 0;
1221 diff.DiffFileAgainstBase(data->path, baseRev);
1223 else if ((!data->bAuxItem)&&(data->path.Exists())&&(!data->path.IsDirectory()))
1225 bool bOpenWith = false;
1226 int ret = (int)ShellExecute(m_hWnd, NULL, data->path.GetWinPath(), NULL, NULL, SW_SHOWNORMAL);
1227 if (ret <= HINSTANCE_ERROR)
1228 bOpenWith = true;
1229 if (bOpenWith)
1231 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
1232 cmd += data->path.GetWinPathString() + _T(" ");
1233 CAppUtils::LaunchApplication(cmd, NULL, false);
1236 #endif
1239 void CGitProgressDlg::OnHdnItemclickSvnprogress(NMHDR *pNMHDR, LRESULT *pResult)
1241 LPNMHEADER phdr = reinterpret_cast<LPNMHEADER>(pNMHDR);
1242 if (m_bThreadRunning)
1243 return;
1244 if (m_nSortedColumn == phdr->iItem)
1245 m_bAscending = !m_bAscending;
1246 else
1247 m_bAscending = TRUE;
1248 m_nSortedColumn = phdr->iItem;
1249 Sort();
1251 CString temp;
1252 m_ProgList.SetRedraw(FALSE);
1253 m_ProgList.DeleteAllItems();
1254 m_ProgList.SetItemCountEx (static_cast<int>(m_arData.size()));
1256 m_ProgList.SetRedraw(TRUE);
1258 *pResult = 0;
1261 bool CGitProgressDlg::NotificationDataIsAux(const NotificationData* pData)
1263 return pData->bAuxItem;
1266 LRESULT CGitProgressDlg::OnGitProgress(WPARAM /*wParam*/, LPARAM /*lParam*/)
1268 #if 0
1269 SVNProgress * pProgressData = (SVNProgress *)lParam;
1270 CProgressCtrl * progControl = (CProgressCtrl *)GetDlgItem(IDC_PROGRESSBAR);
1271 if ((pProgressData->total > 1000)&&(!progControl->IsWindowVisible()))
1273 progControl->ShowWindow(SW_SHOW);
1274 if (m_pTaskbarList)
1275 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
1277 if (((pProgressData->total < 0)&&(pProgressData->progress > 1000)&&(progControl->IsWindowVisible()))&&(m_itemCountTotal<0))
1279 progControl->ShowWindow(SW_HIDE);
1280 if (m_pTaskbarList)
1281 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_INDETERMINATE);
1283 if (!GetDlgItem(IDC_PROGRESSLABEL)->IsWindowVisible())
1284 GetDlgItem(IDC_PROGRESSLABEL)->ShowWindow(SW_SHOW);
1285 SetTimer(TRANSFERTIMER, 2000, NULL);
1286 if ((pProgressData->total > 0)&&(pProgressData->progress > 1000))
1288 progControl->SetPos((int)pProgressData->progress);
1289 progControl->SetRange32(0, (int)pProgressData->total);
1290 if (m_pTaskbarList)
1292 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
1293 m_pTaskbarList->SetProgressValue(m_hWnd, pProgressData->progress, pProgressData->total);
1296 CString progText;
1297 if (pProgressData->overall_total < 1024)
1298 m_sTotalBytesTransferred.Format(IDS_SVN_PROGRESS_TOTALBYTESTRANSFERRED, pProgressData->overall_total);
1299 else if (pProgressData->overall_total < 1200000)
1300 m_sTotalBytesTransferred.Format(IDS_SVN_PROGRESS_TOTALTRANSFERRED, pProgressData->overall_total / 1024);
1301 else
1302 m_sTotalBytesTransferred.Format(IDS_SVN_PROGRESS_TOTALMBTRANSFERRED, (double)((double)pProgressData->overall_total / 1024000.0));
1303 progText.Format(IDS_SVN_PROGRESS_TOTALANDSPEED, (LPCTSTR)m_sTotalBytesTransferred, (LPCTSTR)pProgressData->SpeedString);
1304 SetDlgItemText(IDC_PROGRESSLABEL, progText);
1305 #endif
1306 return 0;
1309 void CGitProgressDlg::OnTimer(UINT_PTR nIDEvent)
1311 if (nIDEvent == TRANSFERTIMER)
1313 CString progText;
1314 CString progSpeed;
1315 progSpeed.Format(IDS_SVN_PROGRESS_BYTES_SEC, 0);
1316 progText.Format(IDS_SVN_PROGRESS_TOTALANDSPEED, (LPCTSTR)m_sTotalBytesTransferred, (LPCTSTR)progSpeed);
1317 SetDlgItemText(IDC_PROGRESSLABEL, progText);
1318 KillTimer(TRANSFERTIMER);
1320 if (nIDEvent == VISIBLETIMER)
1322 if (nEnsureVisibleCount)
1323 m_ProgList.EnsureVisible(m_ProgList.GetItemCount()-1, false);
1324 nEnsureVisibleCount = 0;
1328 void CGitProgressDlg::Sort()
1330 if(m_arData.size() < 2)
1332 return;
1335 // We need to sort the blocks which lie between the auxiliary entries
1336 // This is so that any aux data stays where it was
1337 NotificationDataVect::iterator actionBlockBegin;
1338 NotificationDataVect::iterator actionBlockEnd = m_arData.begin(); // We start searching from here
1340 for(;;)
1342 // Search to the start of the non-aux entry in the next block
1343 actionBlockBegin = std::find_if(actionBlockEnd, m_arData.end(), std::not1(std::ptr_fun(&CGitProgressDlg::NotificationDataIsAux)));
1344 if(actionBlockBegin == m_arData.end())
1346 // There are no more actions
1347 break;
1349 // Now search to find the end of the block
1350 actionBlockEnd = std::find_if(actionBlockBegin+1, m_arData.end(), std::ptr_fun(&CGitProgressDlg::NotificationDataIsAux));
1351 // Now sort the block
1352 std::sort(actionBlockBegin, actionBlockEnd, &CGitProgressDlg::SortCompare);
1356 bool CGitProgressDlg::SortCompare(const NotificationData * pData1, const NotificationData * pData2)
1358 int result = 0;
1359 switch (m_nSortedColumn)
1361 case 0: //action column
1362 result = pData1->sActionColumnText.Compare(pData2->sActionColumnText);
1363 break;
1364 case 1: //path column
1365 // Compare happens after switch()
1366 break;
1367 default:
1368 break;
1371 // Sort by path if everything else is equal
1372 if (result == 0)
1374 result = CTGitPath::Compare(pData1->path, pData2->path);
1377 if (!m_bAscending)
1378 result = -result;
1379 return result < 0;
1382 BOOL CGitProgressDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
1384 if (!GetDlgItem(IDOK)->IsWindowEnabled())
1386 // only show the wait cursor over the list control
1387 if ((pWnd)&&(pWnd == GetDlgItem(IDC_SVNPROGRESS)))
1389 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT));
1390 SetCursor(hCur);
1391 return TRUE;
1394 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));
1395 SetCursor(hCur);
1396 return CResizableStandAloneDialog::OnSetCursor(pWnd, nHitTest, message);
1399 BOOL CGitProgressDlg::PreTranslateMessage(MSG* pMsg)
1401 if (pMsg->message == WM_KEYDOWN)
1403 if (pMsg->wParam == VK_ESCAPE)
1405 // pressing the ESC key should close the dialog. But since we disabled the escape
1406 // key (so the user doesn't get the idea that he could simply undo an e.g. update)
1407 // this won't work.
1408 // So if the user presses the ESC key, change it to VK_RETURN so the dialog gets
1409 // the impression that the OK button was pressed.
1410 if ((!m_bThreadRunning)&&(!GetDlgItem(IDCANCEL)->IsWindowEnabled())
1411 &&(GetDlgItem(IDOK)->IsWindowEnabled())&&(GetDlgItem(IDOK)->IsWindowVisible()))
1413 // since we convert ESC to RETURN, make sure the OK button has the focus.
1414 GetDlgItem(IDOK)->SetFocus();
1415 pMsg->wParam = VK_RETURN;
1418 if (pMsg->wParam == 'A')
1420 if (GetKeyState(VK_CONTROL)&0x8000)
1422 // Ctrl-A -> select all
1423 m_ProgList.SetSelectionMark(0);
1424 for (int i=0; i<m_ProgList.GetItemCount(); ++i)
1426 m_ProgList.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
1430 if ((pMsg->wParam == 'C')||(pMsg->wParam == VK_INSERT))
1432 int selIndex = m_ProgList.GetSelectionMark();
1433 if (selIndex >= 0)
1435 if (GetKeyState(VK_CONTROL)&0x8000)
1437 //Ctrl-C -> copy to clipboard
1438 CString sClipdata;
1439 POSITION pos = m_ProgList.GetFirstSelectedItemPosition();
1440 if (pos != NULL)
1442 while (pos)
1444 int nItem = m_ProgList.GetNextSelectedItem(pos);
1445 CString sAction = m_ProgList.GetItemText(nItem, 0);
1446 CString sPath = m_ProgList.GetItemText(nItem, 1);
1447 CString sMime = m_ProgList.GetItemText(nItem, 2);
1448 CString sLogCopyText;
1449 sLogCopyText.Format(_T("%s: %s %s\r\n"),
1450 (LPCTSTR)sAction, (LPCTSTR)sPath, (LPCTSTR)sMime);
1451 sClipdata += sLogCopyText;
1453 CStringUtils::WriteAsciiStringToClipboard(sClipdata);
1458 } // if (pMsg->message == WM_KEYDOWN)
1459 return __super::PreTranslateMessage(pMsg);
1462 void CGitProgressDlg::OnContextMenu(CWnd* /*pWnd*/, CPoint /*point*/)
1464 #if 0
1465 if (m_options & ProgOptDryRun)
1466 return; // don't do anything in a dry-run.
1468 if (pWnd == &m_ProgList)
1470 int selIndex = m_ProgList.GetSelectionMark();
1471 if ((point.x == -1) && (point.y == -1))
1473 // Menu was invoked from the keyboard rather than by right-clicking
1474 CRect rect;
1475 m_ProgList.GetItemRect(selIndex, &rect, LVIR_LABEL);
1476 m_ProgList.ClientToScreen(&rect);
1477 point = rect.CenterPoint();
1480 if ((selIndex >= 0)&&(!m_bThreadRunning))
1482 // entry is selected, thread has finished with updating so show the popup menu
1483 CIconMenu popup;
1484 if (popup.CreatePopupMenu())
1486 bool bAdded = false;
1487 NotificationData * data = m_arData[selIndex];
1488 if ((data)&&(!data->path.IsDirectory()))
1490 if (data->action == svn_wc_notify_update_update || data->action == svn_wc_notify_resolved)
1492 if (m_ProgList.GetSelectedCount() == 1)
1494 popup.AppendMenuIcon(ID_COMPARE, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1495 bAdded = true;
1498 if (data->bConflictedActionItem)
1500 if (m_ProgList.GetSelectedCount() == 1)
1502 popup.AppendMenuIcon(ID_EDITCONFLICT, IDS_MENUCONFLICT,IDI_CONFLICT);
1503 popup.SetDefaultItem(ID_EDITCONFLICT, FALSE);
1504 popup.AppendMenuIcon(ID_CONFLICTRESOLVE, IDS_SVNPROGRESS_MENUMARKASRESOLVED,IDI_RESOLVE);
1506 popup.AppendMenuIcon(ID_CONFLICTUSETHEIRS, IDS_SVNPROGRESS_MENUUSETHEIRS,IDI_RESOLVE);
1507 popup.AppendMenuIcon(ID_CONFLICTUSEMINE, IDS_SVNPROGRESS_MENUUSEMINE,IDI_RESOLVE);
1509 else if ((data->content_state == svn_wc_notify_state_merged)||(GitProgress_Merge == m_Command)||(data->action == svn_wc_notify_resolved))
1510 popup.SetDefaultItem(ID_COMPARE, FALSE);
1512 if (m_ProgList.GetSelectedCount() == 1)
1514 if ((data->action == svn_wc_notify_add)||
1515 (data->action == svn_wc_notify_update_add)||
1516 (data->action == svn_wc_notify_commit_added)||
1517 (data->action == svn_wc_notify_commit_modified)||
1518 (data->action == svn_wc_notify_restore)||
1519 (data->action == svn_wc_notify_revert)||
1520 (data->action == svn_wc_notify_resolved)||
1521 (data->action == svn_wc_notify_commit_replaced)||
1522 (data->action == svn_wc_notify_commit_modified)||
1523 (data->action == svn_wc_notify_commit_postfix_txdelta)||
1524 (data->action == svn_wc_notify_update_update))
1526 popup.AppendMenuIcon(ID_LOG, IDS_MENULOG,IDI_LOG);
1527 if (data->action == svn_wc_notify_update_update)
1528 popup.AppendMenu(MF_SEPARATOR, NULL);
1529 popup.AppendMenuIcon(ID_OPEN, IDS_LOG_POPUP_OPEN, IDI_OPEN);
1530 popup.AppendMenuIcon(ID_OPENWITH, IDS_LOG_POPUP_OPENWITH, IDI_OPEN);
1531 bAdded = true;
1534 } // if ((data)&&(!data->path.IsDirectory()))
1535 if (m_ProgList.GetSelectedCount() == 1)
1537 if (data)
1539 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1540 if ((!sPath.IsEmpty())&&(!SVN::PathIsURL(CTGitPath(sPath))))
1542 CTGitPath path = CTGitPath(sPath);
1543 if (path.GetDirectory().Exists())
1545 popup.AppendMenuIcon(ID_EXPLORE, IDS_SVNPROGRESS_MENUOPENPARENT, IDI_EXPLORER);
1546 bAdded = true;
1551 if (m_ProgList.GetSelectedCount() > 0)
1553 if (bAdded)
1554 popup.AppendMenu(MF_SEPARATOR, NULL);
1555 popup.AppendMenuIcon(ID_COPY, IDS_LOG_POPUP_COPYTOCLIPBOARD,IDI_COPYCLIP);
1556 bAdded = true;
1558 if (bAdded)
1560 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
1561 DialogEnableWindow(IDOK, FALSE);
1562 this->SetPromptApp(&theApp);
1563 theApp.DoWaitCursor(1);
1564 bool bOpenWith = false;
1565 switch (cmd)
1567 case ID_COPY:
1569 CString sLines;
1570 POSITION pos = m_ProgList.GetFirstSelectedItemPosition();
1571 while (pos)
1573 int nItem = m_ProgList.GetNextSelectedItem(pos);
1574 NotificationData * data = m_arData[nItem];
1575 if (data)
1577 sLines += data->sPathColumnText;
1578 sLines += _T("\r\n");
1581 sLines.TrimRight();
1582 if (!sLines.IsEmpty())
1584 CStringUtils::WriteAsciiStringToClipboard(sLines, GetSafeHwnd());
1587 break;
1588 case ID_EXPLORE:
1590 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1592 CTGitPath path = CTGitPath(sPath);
1593 ShellExecute(m_hWnd, _T("explore"), path.GetDirectory().GetWinPath(), NULL, path.GetDirectory().GetWinPath(), SW_SHOW);
1595 break;
1596 case ID_COMPARE:
1598 svn_revnum_t rev = -1;
1599 StringRevMap::iterator it = m_UpdateStartRevMap.end();
1600 if (data->basepath.IsEmpty())
1601 it = m_UpdateStartRevMap.begin();
1602 else
1603 it = m_UpdateStartRevMap.find(data->basepath.GetSVNApiPath(pool));
1604 if (it != m_UpdateStartRevMap.end())
1605 rev = it->second;
1606 // if the file was merged during update, do a three way diff between OLD, MINE, THEIRS
1607 if (data->content_state == svn_wc_notify_state_merged)
1609 CTGitPath basefile = CTempFiles::Instance().GetTempFilePath(false, data->path, rev);
1610 CTGitPath newfile = CTempFiles::Instance().GetTempFilePath(false, data->path, SVNRev::REV_HEAD);
1611 SVN svn;
1612 if (!svn.Cat(data->path, SVNRev(SVNRev::REV_WC), rev, basefile))
1614 CMessageBox::Show(m_hWnd, svn.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1615 DialogEnableWindow(IDOK, TRUE);
1616 break;
1618 // If necessary, convert the line-endings on the file before diffing
1619 if ((DWORD)CRegDWORD(_T("Software\\TortoiseGit\\ConvertBase"), TRUE))
1621 CTGitPath temporaryFile = CTempFiles::Instance().GetTempFilePath(false, data->path, SVNRev::REV_BASE);
1622 if (!svn.Cat(data->path, SVNRev(SVNRev::REV_BASE), SVNRev(SVNRev::REV_BASE), temporaryFile))
1624 temporaryFile.Reset();
1625 break;
1627 else
1629 newfile = temporaryFile;
1633 SetFileAttributes(newfile.GetWinPath(), FILE_ATTRIBUTE_READONLY);
1634 SetFileAttributes(basefile.GetWinPath(), FILE_ATTRIBUTE_READONLY);
1635 CString revname, wcname, basename;
1636 revname.Format(_T("%s Revision %ld"), (LPCTSTR)data->path.GetUIFileOrDirectoryName(), rev);
1637 wcname.Format(IDS_DIFF_WCNAME, (LPCTSTR)data->path.GetUIFileOrDirectoryName());
1638 basename.Format(IDS_DIFF_BASENAME, (LPCTSTR)data->path.GetUIFileOrDirectoryName());
1639 CAppUtils::StartExtMerge(basefile, newfile, data->path, data->path, basename, revname, wcname, CString(), true);
1641 else
1643 CTGitPath tempfile = CTempFiles::Instance().GetTempFilePath(false, data->path, rev);
1644 SVN svn;
1645 if (!svn.Cat(data->path, SVNRev(SVNRev::REV_WC), rev, tempfile))
1647 CMessageBox::Show(m_hWnd, svn.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1648 DialogEnableWindow(IDOK, TRUE);
1649 break;
1651 else
1653 SetFileAttributes(tempfile.GetWinPath(), FILE_ATTRIBUTE_READONLY);
1654 CString revname, wcname;
1655 revname.Format(_T("%s Revision %ld"), (LPCTSTR)data->path.GetUIFileOrDirectoryName(), rev);
1656 wcname.Format(IDS_DIFF_WCNAME, (LPCTSTR)data->path.GetUIFileOrDirectoryName());
1657 CAppUtils::StartExtDiff(
1658 tempfile, data->path, revname, wcname,
1659 CAppUtils::DiffFlags().AlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000)));
1663 break;
1664 case ID_EDITCONFLICT:
1666 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1667 SVNDiff::StartConflictEditor(CTGitPath(sPath));
1669 break;
1670 case ID_CONFLICTUSETHEIRS:
1671 case ID_CONFLICTUSEMINE:
1672 case ID_CONFLICTRESOLVE:
1674 svn_wc_conflict_choice_t result = svn_wc_conflict_choose_merged;
1675 switch (cmd)
1677 case ID_CONFLICTUSETHEIRS:
1678 result = svn_wc_conflict_choose_theirs_full;
1679 break;
1680 case ID_CONFLICTUSEMINE:
1681 result = svn_wc_conflict_choose_mine_full;
1682 break;
1683 case ID_CONFLICTRESOLVE:
1684 result = svn_wc_conflict_choose_merged;
1685 break;
1687 SVN svn;
1688 POSITION pos = m_ProgList.GetFirstSelectedItemPosition();
1689 CString sResolvedPaths;
1690 while (pos)
1692 int nItem = m_ProgList.GetNextSelectedItem(pos);
1693 NotificationData * data = m_arData[nItem];
1694 if (data)
1696 if (data->bConflictedActionItem)
1698 if (!svn.Resolve(data->path, result, FALSE))
1700 CMessageBox::Show(m_hWnd, svn.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1701 DialogEnableWindow(IDOK, TRUE);
1702 break;
1704 else
1706 data->color = ::GetSysColor(COLOR_WINDOWTEXT);
1707 data->action = svn_wc_notify_resolved;
1708 data->sActionColumnText.LoadString(IDS_SVNACTION_RESOLVE);
1709 data->bConflictedActionItem = false;
1710 m_nConflicts--;
1712 if (m_nConflicts==0)
1714 // When the last conflict is resolved we remove
1715 // the warning which we assume is in the last line.
1716 int nIndex = m_ProgList.GetItemCount()-1;
1717 VERIFY(m_ProgList.DeleteItem(nIndex));
1719 delete m_arData[nIndex];
1720 m_arData.pop_back();
1722 sResolvedPaths += data->path.GetWinPathString() + _T("\n");
1727 m_ProgList.Invalidate();
1728 CString info = BuildInfoString();
1729 SetDlgItemText(IDC_INFOTEXT, info);
1731 if (!sResolvedPaths.IsEmpty())
1733 CString msg;
1734 msg.Format(IDS_SVNPROGRESS_RESOLVED, (LPCTSTR)sResolvedPaths);
1735 CMessageBox::Show(m_hWnd, msg, _T("TortoiseGit"), MB_OK | MB_ICONINFORMATION);
1738 break;
1739 case ID_LOG:
1741 svn_revnum_t rev = m_RevisionEnd;
1742 if (!data->basepath.IsEmpty())
1744 StringRevMap::iterator it = m_FinishedRevMap.find(data->basepath.GetSVNApiPath(pool));
1745 if (it != m_FinishedRevMap.end())
1746 rev = it->second;
1748 CLogDlg dlg;
1749 // fetch the log from HEAD, not the revision we updated to:
1750 // the path might be inside an external folder which has its own
1751 // revisions.
1752 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1753 dlg.SetParams(CTGitPath(sPath), SVNRev(), SVNRev::REV_HEAD, 1, -1, TRUE);
1754 dlg.DoModal();
1756 break;
1757 case ID_OPENWITH:
1758 bOpenWith = true;
1759 case ID_OPEN:
1761 int ret = 0;
1762 CString sWinPath = GetPathFromColumnText(data->sPathColumnText);
1763 if (!bOpenWith)
1764 ret = (int)ShellExecute(this->m_hWnd, NULL, (LPCTSTR)sWinPath, NULL, NULL, SW_SHOWNORMAL);
1765 if ((ret <= HINSTANCE_ERROR)||bOpenWith)
1767 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
1768 cmd += sWinPath + _T(" ");
1769 CAppUtils::LaunchApplication(cmd, NULL, false);
1773 DialogEnableWindow(IDOK, TRUE);
1774 theApp.DoWaitCursor(-1);
1775 } // if (bAdded)
1779 #endif
1782 void CGitProgressDlg::OnEnSetfocusInfotext()
1784 CString sTemp;
1785 GetDlgItemText(IDC_INFOTEXT, sTemp);
1786 if (sTemp.IsEmpty())
1787 GetDlgItem(IDC_INFOTEXT)->HideCaret();
1790 void CGitProgressDlg::OnLvnBegindragSvnprogress(NMHDR* , LRESULT *pResult)
1792 //LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1793 #if 0
1794 int selIndex = m_ProgList.GetSelectionMark();
1795 if (selIndex < 0)
1796 return;
1798 CDropFiles dropFiles; // class for creating DROPFILES struct
1800 int index;
1801 POSITION pos = m_ProgList.GetFirstSelectedItemPosition();
1802 while ( (index = m_ProgList.GetNextSelectedItem(pos)) >= 0 )
1804 NotificationData * data = m_arData[index];
1806 if ( data->kind==svn_node_file || data->kind==svn_node_dir )
1808 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1810 dropFiles.AddFile( sPath );
1814 if ( dropFiles.GetCount()>0 )
1816 dropFiles.CreateStructure();
1818 #endif
1819 *pResult = 0;
1822 void CGitProgressDlg::OnSize(UINT nType, int cx, int cy)
1824 CResizableStandAloneDialog::OnSize(nType, cx, cy);
1825 if ((nType == SIZE_RESTORED)&&(m_bLastVisible))
1827 if(!m_ProgList.m_hWnd)
1828 return;
1830 int count = m_ProgList.GetItemCount();
1831 if (count > 0)
1832 m_ProgList.EnsureVisible(count-1, false);
1836 //////////////////////////////////////////////////////////////////////////
1837 /// commands
1838 //////////////////////////////////////////////////////////////////////////
1839 bool CGitProgressDlg::CmdAdd(CString& sWindowTitle, bool& localoperation)
1841 localoperation = true;
1842 sWindowTitle.LoadString(IDS_PROGRS_TITLE_ADD);
1843 CAppUtils::SetWindowTitle(m_hWnd, m_targetPathList.GetCommonRoot().GetUIPathString(), sWindowTitle);
1844 SetBackgroundImage(IDI_ADD_BKG);
1845 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_ADD)));
1847 if (CRegDWORD(_T("Software\\TortoiseGit\\UseLibgit2"), TRUE) == TRUE)
1849 git_repository *repo = NULL;
1850 git_index *index;
1852 CStringA gitdir = CUnicodeUtils::GetMulti(CTGitPath(g_Git.m_CurrentDir).GetGitPathString(), CP_UTF8);
1853 if (git_repository_open(&repo, gitdir.GetBuffer()))
1855 gitdir.ReleaseBuffer();
1856 ReportGitError();
1857 return false;
1859 gitdir.ReleaseBuffer();
1861 git_config * config;
1862 git_config_new(&config);
1864 CString adminDir;
1865 g_GitAdminDir.GetAdminDirPath(g_Git.m_CurrentDir, adminDir);
1866 CStringA projectConfigA = CUnicodeUtils::GetMulti(adminDir + _T("config"), CP_UTF8);
1867 if (git_config_add_file_ondisk(config, projectConfigA.GetBuffer(), 3))
1869 projectConfigA.ReleaseBuffer();
1870 ReportGitError();
1871 git_config_free(config);
1872 git_repository_free(repo);
1873 return false;
1875 projectConfigA.ReleaseBuffer();
1876 CString globalConfig = g_Git.GetHomeDirectory() + _T("\\.gitconfig");
1877 if (PathFileExists(globalConfig))
1879 CStringA globalConfigA = CUnicodeUtils::GetMulti(globalConfig, CP_UTF8);
1880 if (git_config_add_file_ondisk(config, globalConfigA.GetBuffer(), 2))
1882 globalConfigA.ReleaseBuffer();
1883 ReportGitError();
1884 git_config_free(config);
1885 git_repository_free(repo);
1886 return false;
1888 globalConfigA.ReleaseBuffer();
1890 CString msysGitBinPath(CRegString(REG_MSYSGIT_PATH, _T(""), FALSE));
1891 if (!msysGitBinPath.IsEmpty())
1893 CStringA systemConfigA = CUnicodeUtils::GetMulti(msysGitBinPath + _T("\\..\\etc\\gitconfig"), CP_UTF8);
1894 if (git_config_add_file_ondisk(config, systemConfigA.GetBuffer(), 1))
1896 systemConfigA.ReleaseBuffer();
1897 ReportGitError();
1898 git_config_free(config);
1899 git_repository_free(repo);
1900 return false;
1902 systemConfigA.ReleaseBuffer();
1905 git_repository_set_config(repo, config);
1907 if (git_repository_index(&index, repo))
1909 ReportGitError();
1910 git_repository_free(repo);
1911 return false;
1913 if (git_index_read(index))
1915 ReportGitError();
1916 git_index_free(index);
1917 git_repository_free(repo);
1918 return false;
1921 for(int i=0;i<m_targetPathList.GetCount();i++)
1923 if (git_index_add(index, CStringA(CUnicodeUtils::GetMulti(m_targetPathList[i].GetGitPathString(), CP_UTF8)).GetBuffer(), 0))
1925 ReportGitError();
1926 git_index_free(index);
1927 git_repository_free(repo);
1928 return false;
1930 Notify(m_targetPathList[i],git_wc_notify_add);
1933 if (git_index_write(index))
1935 ReportGitError();
1936 git_index_free(index);
1937 git_repository_free(repo);
1938 return false;
1941 git_index_free(index);
1942 git_repository_free(repo);
1944 else
1946 CMassiveGitTask mgt(L"add -f");
1947 mgt.ExecuteWithNotify(&m_targetPathList, m_bCancelled, git_wc_notify_add, this, &CGitProgressDlg::Notify);
1950 CShellUpdater::Instance().AddPathsForUpdate(m_targetPathList);
1952 this->GetDlgItem(IDC_LOGBUTTON)->SetWindowText(_T("Commit ..."));
1953 this->GetDlgItem(IDC_LOGBUTTON)->ShowWindow(SW_SHOW);
1954 return true;
1957 bool CGitProgressDlg::CmdCopy(CString& /*sWindowTitle*/, bool& /*localoperation*/)
1959 #if 0
1960 ASSERT(m_targetPathList.GetCount() == 1);
1961 sWindowTitle.LoadString(IDS_PROGRS_TITLE_COPY);
1962 SetWindowText(sWindowTitle); // needs to be updated, see TSVN rev. 21375
1963 SetBackgroundImage(IDI_COPY_BKG);
1965 CString sCmdInfo;
1966 sCmdInfo.Format(IDS_PROGRS_CMD_COPY,
1967 m_targetPathList[0].IsUrl() ? (LPCTSTR)m_targetPathList[0].GetSVNPathString() : m_targetPathList[0].GetWinPath(),
1968 (LPCTSTR)m_url.GetSVNPathString(), (LPCTSTR)m_Revision.ToString());
1969 ReportCmd(sCmdInfo);
1971 if (!Copy(m_targetPathList, m_url, m_Revision, m_pegRev, m_sMessage))
1973 ReportSVNError();
1974 return false;
1976 if (m_options & ProgOptSwitchAfterCopy)
1978 sCmdInfo.Format(IDS_PROGRS_CMD_SWITCH,
1979 m_targetPathList[0].GetWinPath(),
1980 (LPCTSTR)m_url.GetSVNPathString(), (LPCTSTR)m_Revision.ToString());
1981 ReportCmd(sCmdInfo);
1982 if (!Switch(m_targetPathList[0], m_url, SVNRev::REV_HEAD, SVNRev::REV_HEAD, m_depth, TRUE, m_options & ProgOptIgnoreExternals))
1984 if (!Switch(m_targetPathList[0], m_url, SVNRev::REV_HEAD, m_Revision, m_depth, TRUE, m_options & ProgOptIgnoreExternals))
1986 ReportSVNError();
1987 return false;
1991 else
1993 if (SVN::PathIsURL(m_url))
1995 CString sMsg(MAKEINTRESOURCE(IDS_PROGRS_COPY_WARNING));
1996 ReportNotification(sMsg);
1999 #endif
2000 return true;
2003 bool CGitProgressDlg::CmdExport(CString& /*sWindowTitle*/, bool& /*localoperation*/)
2005 #if 0
2006 ASSERT(m_targetPathList.GetCount() == 1);
2007 sWindowTitle.LoadString(IDS_PROGRS_TITLE_EXPORT);
2008 sWindowTitle = m_url.GetUIFileOrDirectoryName()+_T(" - ")+sWindowTitle;
2009 SetWindowText(sWindowTitle); // needs to be updated, see TSVN rev. 21375
2010 SetBackgroundImage(IDI_EXPORT_BKG);
2011 CString eol;
2012 if (m_options & ProgOptEolCRLF)
2013 eol = _T("CRLF");
2014 if (m_options & ProgOptEolLF)
2015 eol = _T("LF");
2016 if (m_options & ProgOptEolCR)
2017 eol = _T("CR");
2018 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_EXPORT)));
2019 if (!Export(m_url, m_targetPathList[0], m_Revision, m_Revision, TRUE, m_options & ProgOptIgnoreExternals, m_depth, NULL, FALSE, eol))
2021 ReportSVNError();
2022 return false;
2024 #endif
2025 return true;
2028 bool CGitProgressDlg::CmdRename(CString& /*sWindowTitle*/, bool& /*localoperation*/)
2030 #if 0
2031 ASSERT(m_targetPathList.GetCount() == 1);
2032 if ((!m_targetPathList[0].IsUrl())&&(!m_url.IsUrl()))
2033 localoperation = true;
2034 sWindowTitle.LoadString(IDS_PROGRS_TITLE_RENAME);
2035 SetWindowText(sWindowTitle); // needs to be updated, see TSVN rev. 21375
2036 SetBackgroundImage(IDI_RENAME_BKG);
2037 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RENAME)));
2038 if (!Move(m_targetPathList, m_url, m_Revision, m_sMessage))
2040 ReportSVNError();
2041 return false;
2043 #endif
2044 return true;
2047 bool CGitProgressDlg::CmdResolve(CString& sWindowTitle, bool& localoperation)
2050 localoperation = true;
2051 ASSERT(m_targetPathList.GetCount() == 1);
2052 sWindowTitle.LoadString(IDS_PROGRS_TITLE_RESOLVE);
2053 CAppUtils::SetWindowTitle(m_hWnd, m_targetPathList.GetCommonRoot().GetUIPathString(), sWindowTitle);
2054 SetBackgroundImage(IDI_RESOLVE_BKG);
2055 // check if the file may still have conflict markers in it.
2056 //BOOL bMarkers = FALSE;
2058 for(int i=0;i<m_targetPathList.GetCount();i++)
2060 CString cmd,out,tempmergefile;
2061 cmd.Format(_T("git.exe add -f -- \"%s\""),m_targetPathList[i].GetGitPathString());
2062 if (g_Git.Run(cmd, &out, CP_UTF8))
2064 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
2065 m_bErrorsOccurred=true;
2066 return false;
2069 CAppUtils::RemoveTempMergeFile((CTGitPath &)m_targetPathList[i]);
2071 Notify(m_targetPathList[i],git_wc_notify_resolved);
2073 #if 0
2074 if ((m_options & ProgOptSkipConflictCheck) == 0)
2078 for (INT_PTR fileindex=0; (fileindex<m_targetPathList.GetCount()) && (bMarkers==FALSE); ++fileindex)
2080 if (!m_targetPathList[fileindex].IsDirectory())
2082 CStdioFile file(m_targetPathList[fileindex].GetWinPath(), CFile::typeBinary | CFile::modeRead);
2083 CString strLine = _T("");
2084 while (file.ReadString(strLine))
2086 if (strLine.Find(_T("<<<<<<<"))==0)
2088 bMarkers = TRUE;
2089 break;
2092 file.Close();
2096 catch (CFileException* pE)
2098 TRACE(_T("CFileException in Resolve!\n"));
2099 TCHAR error[10000] = {0};
2100 pE->GetErrorMessage(error, 10000);
2101 ReportError(error);
2102 pE->Delete();
2103 return false;
2106 if (bMarkers)
2108 if (CMessageBox::Show(m_hWnd, IDS_PROGRS_REVERTMARKERS, IDS_APPNAME, MB_YESNO | MB_ICONQUESTION)==IDYES)
2110 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RESOLVE)));
2111 for (INT_PTR fileindex=0; fileindex<m_targetPathList.GetCount(); ++fileindex)
2112 Resolve(m_targetPathList[fileindex], svn_wc_conflict_choose_merged, true);
2115 else
2117 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RESOLVE)));
2118 for (INT_PTR fileindex=0; fileindex<m_targetPathList.GetCount(); ++fileindex)
2119 Resolve(m_targetPathList[fileindex], svn_wc_conflict_choose_merged, true);
2121 #endif
2122 CShellUpdater::Instance().AddPathsForUpdate(m_targetPathList);
2124 this->GetDlgItem(IDC_LOGBUTTON)->SetWindowText(_T("Commit ..."));
2125 this->GetDlgItem(IDC_LOGBUTTON)->ShowWindow(SW_SHOW);
2127 return true;
2130 bool CGitProgressDlg::CmdRevert(CString& sWindowTitle, bool& localoperation)
2133 localoperation = true;
2134 sWindowTitle.LoadString(IDS_PROGRS_TITLE_REVERT);
2135 CAppUtils::SetWindowTitle(m_hWnd, m_targetPathList.GetCommonRoot().GetUIPathString(), sWindowTitle);
2136 SetBackgroundImage(IDI_REVERT_BKG);
2138 CTGitPathList delList;
2139 for(int i=0;i<m_selectedPaths.GetCount();i++)
2141 CTGitPath path;
2142 int action;
2143 path.SetFromWin(g_Git.m_CurrentDir+_T("\\")+m_selectedPaths[i].GetWinPath());
2144 action = m_selectedPaths[i].m_Action;
2145 /* rename file can't delete because it needs original file*/
2146 if((!(action & CTGitPath::LOGACTIONS_ADDED)) &&
2147 (!(action & CTGitPath::LOGACTIONS_REPLACED)))
2148 delList.AddPath(path);
2150 if (DWORD(CRegDWORD(_T("Software\\TortoiseGit\\RevertWithRecycleBin"), TRUE)))
2151 delList.DeleteAllFiles(true);
2153 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_REVERT)));
2154 for(int i=0;i<m_selectedPaths.GetCount();i++)
2156 if(g_Git.Revert(_T("HEAD"), (CTGitPath&)m_selectedPaths[i]))
2158 CMessageBox::Show(NULL,_T("Revert Fail"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
2159 m_bErrorsOccurred=true;
2160 return false;
2162 Notify(m_selectedPaths[i],git_wc_notify_revert);
2165 CShellUpdater::Instance().AddPathsForUpdate(m_selectedPaths);
2167 return true;
2170 bool CGitProgressDlg::CmdSwitch(CString& /*sWindowTitle*/, bool& /*localoperation*/)
2172 #if 0
2173 ASSERT(m_targetPathList.GetCount() == 1);
2174 SVNStatus st;
2175 sWindowTitle.LoadString(IDS_PROGRS_TITLE_SWITCH);
2176 SetWindowText(sWindowTitle); // needs to be updated, see TSVN rev. 21375
2177 SetBackgroundImage(IDI_SWITCH_BKG);
2178 LONG rev = 0;
2179 if (st.GetStatus(m_targetPathList[0]) != (-2))
2181 if (st.status->entry != NULL)
2183 rev = st.status->entry->revision;
2187 CString sCmdInfo;
2188 sCmdInfo.Format(IDS_PROGRS_CMD_SWITCH,
2189 m_targetPathList[0].GetWinPath(), (LPCTSTR)m_url.GetSVNPathString(),
2190 (LPCTSTR)m_Revision.ToString());
2191 ReportCmd(sCmdInfo);
2193 bool depthIsSticky = true;
2194 if (m_depth == svn_depth_unknown)
2195 depthIsSticky = false;
2196 if (!Switch(m_targetPathList[0], m_url, m_Revision, m_Revision, m_depth, depthIsSticky, m_options & ProgOptIgnoreExternals))
2198 ReportSVNError();
2199 return false;
2201 m_UpdateStartRevMap[m_targetPathList[0].GetSVNApiPath(pool)] = rev;
2202 if ((m_RevisionEnd >= 0)&&(rev >= 0)
2203 &&((LONG)m_RevisionEnd > (LONG)rev))
2205 GetDlgItem(IDC_LOGBUTTON)->ShowWindow(SW_SHOW);
2207 #endif
2208 return true;
2211 void CGitProgressDlg::OnBnClickedNoninteractive()
2213 LRESULT res = ::SendMessage(GetDlgItem(IDC_NONINTERACTIVE)->GetSafeHwnd(), BM_GETCHECK, 0, 0);
2214 m_AlwaysConflicted = (res == BST_CHECKED);
2215 CRegDWORD nonint = CRegDWORD(_T("Software\\TortoiseGit\\MergeNonInteractive"), FALSE);
2216 nonint = m_AlwaysConflicted;
2219 CString CGitProgressDlg::GetPathFromColumnText(const CString& sColumnText)
2221 CString sPath = CPathUtils::ParsePathInString(sColumnText);
2222 if (sPath.Find(':')<0)
2224 // the path is not absolute: add the common root of all paths to it
2225 sPath = m_targetPathList.GetCommonRoot().GetDirectory().GetWinPathString() + _T("\\") + CPathUtils::ParsePathInString(sColumnText);
2227 return sPath;
2230 bool CGitProgressDlg::CmdSendMail(CString& sWindowTitle, bool& /*localoperation*/)
2232 sWindowTitle.LoadString(IDS_PROGRS_TITLE_SENDMAIL);
2233 CAppUtils::SetWindowTitle(m_hWnd, m_targetPathList.GetCommonRoot().GetUIPathString(), sWindowTitle);
2234 //SetBackgroundImage(IDI_ADD_BKG);
2235 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_SENDMAIL)));
2236 bool ret=true;
2237 if(this->m_SendMailFlags&SENDMAIL_COMBINED)
2239 CString error;
2240 CTGitPath path;
2241 Notify(path,git_wc_notify_sendmail_start);
2242 CString err;
2243 int retry=0;
2244 while(retry <3)
2246 if(!!CPatch::SendPatchesCombined(m_targetPathList,m_SendMailTO,m_SendMailCC,m_SendMailSubject,!!(this->m_SendMailFlags&SENDMAIL_ATTACHMENT),!!(this->m_SendMailFlags&SENDMAIL_MAPI),&err))
2248 Notify(path,git_wc_notify_sendmail_error,ret,&err);
2249 ret = false;
2251 else
2253 break;
2256 retry++;
2257 if (retry < 3)
2258 Notify(path,git_wc_notify_sendmail_retry,ret,&err);
2259 Sleep(2000);
2260 if(m_bCancelled)
2262 CString str(_T("User Canceled"));
2263 Notify(path,git_wc_notify_sendmail_error,ret,&str);
2264 return false;
2267 if (ret)
2268 Notify(path,git_wc_notify_sendmail_done,ret);
2270 else
2272 for(int i=0;ret && i<m_targetPathList.GetCount();i++)
2274 CPatch patch;
2275 Notify(m_targetPathList[i],git_wc_notify_sendmail_start);
2277 int retry=0;
2278 while(retry<3)
2280 if(!!patch.Send((CString&)m_targetPathList[i].GetWinPathString(),this->m_SendMailTO,
2281 this->m_SendMailCC,!!(this->m_SendMailFlags&SENDMAIL_ATTACHMENT),!!(this->m_SendMailFlags&SENDMAIL_MAPI)))
2283 Notify(m_targetPathList[i],git_wc_notify_sendmail_error,ret,&patch.m_LastError);
2284 ret = false;
2287 else
2289 ret = true;
2290 break;
2292 retry++;
2293 if (retry < 3)
2294 Notify(m_targetPathList[i],git_wc_notify_sendmail_retry,ret,&patch.m_LastError);
2295 Sleep(2000);
2296 if(m_bCancelled)
2298 CString str(_T("User Canceled"));
2299 Notify(m_targetPathList[i],git_wc_notify_sendmail_error,ret,&str);
2300 return false;
2303 if (ret)
2304 Notify(m_targetPathList[i],git_wc_notify_sendmail_done,ret);
2307 return ret;
2310 LRESULT CGitProgressDlg::OnTaskbarBtnCreated(WPARAM /*wParam*/, LPARAM /*lParam*/)
2312 m_pTaskbarList.Release();
2313 m_pTaskbarList.CoCreateInstance(CLSID_TaskbarList);
2314 return 0;