Added CString wrapper for get_windows_home_directory()
[TortoiseGit.git] / src / TortoiseProc / GitProgressDlg.cpp
blob40ae5d409ad351089d9e573fa0043b53fe85a38e
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;
741 case 2:
742 linewidth = m_ProgList.GetStringWidth(m_arData[index]->mime_type) + 12;
743 break;
745 if (cx < linewidth)
746 cx = linewidth;
748 m_ProgList.SetColumnWidth(col, cx);
751 m_ProgList.SetRedraw(TRUE);
754 BOOL CGitProgressDlg::OnInitDialog()
756 __super::OnInitDialog();
758 // Let the TaskbarButtonCreated message through the UIPI filter. If we don't
759 // do this, Explorer would be unable to send that message to our window if we
760 // were running elevated. It's OK to make the call all the time, since if we're
761 // not elevated, this is a no-op.
762 CHANGEFILTERSTRUCT cfs = { sizeof(CHANGEFILTERSTRUCT) };
763 typedef BOOL STDAPICALLTYPE ChangeWindowMessageFilterExDFN(HWND hWnd, UINT message, DWORD action, PCHANGEFILTERSTRUCT pChangeFilterStruct);
764 CAutoLibrary hUser = ::LoadLibrary(_T("user32.dll"));
765 if (hUser)
767 ChangeWindowMessageFilterExDFN *pfnChangeWindowMessageFilterEx = (ChangeWindowMessageFilterExDFN*)GetProcAddress(hUser, "ChangeWindowMessageFilterEx");
768 if (pfnChangeWindowMessageFilterEx)
770 pfnChangeWindowMessageFilterEx(m_hWnd, WM_TASKBARBTNCREATED, MSGFLT_ALLOW, &cfs);
773 m_pTaskbarList.Release();
774 m_pTaskbarList.CoCreateInstance(CLSID_TaskbarList);
776 m_ProgList.SetExtendedStyle (LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER);
778 m_ProgList.DeleteAllItems();
779 int c = ((CHeaderCtrl*)(m_ProgList.GetDlgItem(0)))->GetItemCount()-1;
780 while (c>=0)
781 m_ProgList.DeleteColumn(c--);
782 CString temp;
783 temp.LoadString(IDS_PROGRS_ACTION);
784 m_ProgList.InsertColumn(0, temp);
785 temp.LoadString(IDS_PROGRS_PATH);
786 m_ProgList.InsertColumn(1, temp);
787 temp.LoadString(IDS_PROGRS_MIMETYPE);
788 m_ProgList.InsertColumn(2, temp);
790 m_pThread = AfxBeginThread(ProgressThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
791 if (m_pThread==NULL)
793 ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
795 else
797 m_pThread->m_bAutoDelete = FALSE;
798 m_pThread->ResumeThread();
801 UpdateData(FALSE);
803 // Call this early so that the column headings aren't hidden before any
804 // text gets added.
805 ResizeColumns();
807 SetTimer(VISIBLETIMER, 300, NULL);
809 AddAnchor(IDC_SVNPROGRESS, TOP_LEFT, BOTTOM_RIGHT);
810 AddAnchor(IDC_PROGRESSLABEL, BOTTOM_LEFT, BOTTOM_CENTER);
811 AddAnchor(IDC_PROGRESSBAR, BOTTOM_CENTER, BOTTOM_RIGHT);
812 AddAnchor(IDC_INFOTEXT, BOTTOM_LEFT, BOTTOM_RIGHT);
813 AddAnchor(IDC_NONINTERACTIVE, BOTTOM_LEFT, BOTTOM_RIGHT);
814 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
815 AddAnchor(IDOK, BOTTOM_RIGHT);
816 AddAnchor(IDC_LOGBUTTON, BOTTOM_RIGHT);
817 //SetPromptParentWindow(this->m_hWnd);
818 if (hWndExplorer)
819 CenterWindow(CWnd::FromHandle(hWndExplorer));
820 EnableSaveRestore(_T("GITProgressDlg"));
821 return TRUE;
824 bool CGitProgressDlg::SetBackgroundImage(UINT nID)
826 return CAppUtils::SetListCtrlBackgroundImage(m_ProgList.GetSafeHwnd(), nID);
829 void CGitProgressDlg::ReportGitError()
831 ReportError(CString(giterr_last()->message));
834 void CGitProgressDlg::ReportError(const CString& sError)
836 CSoundUtils::PlayTGitError();
837 ReportString(sError, CString(MAKEINTRESOURCE(IDS_ERR_ERROR)), m_Colors.GetColor(CColors::Conflict));
838 m_bErrorsOccurred = true;
841 void CGitProgressDlg::ReportWarning(const CString& sWarning)
843 CSoundUtils::PlayTGitWarning();
844 ReportString(sWarning, CString(MAKEINTRESOURCE(IDS_WARN_WARNING)), m_Colors.GetColor(CColors::Conflict));
847 void CGitProgressDlg::ReportNotification(const CString& sNotification)
849 CSoundUtils::PlayTGitNotification();
850 ReportString(sNotification, CString(MAKEINTRESOURCE(IDS_WARN_NOTE)));
853 void CGitProgressDlg::ReportCmd(const CString& sCmd)
855 ReportString(sCmd, CString(MAKEINTRESOURCE(IDS_PROGRS_CMDINFO)), m_Colors.GetColor(CColors::Cmd));
858 void CGitProgressDlg::ReportString(CString sMessage, const CString& sMsgKind, COLORREF color)
860 // instead of showing a dialog box with the error message or notification,
861 // just insert the error text into the list control.
862 // that way the user isn't 'interrupted' by a dialog box popping up!
864 // the message may be split up into different lines
865 // so add a new entry for each line of the message
866 while (!sMessage.IsEmpty())
868 NotificationData * data = new NotificationData();
869 data->bAuxItem = true;
870 data->sActionColumnText = sMsgKind;
871 if (sMessage.Find('\n')>=0)
872 data->sPathColumnText = sMessage.Left(sMessage.Find('\n'));
873 else
874 data->sPathColumnText = sMessage;
875 data->sPathColumnText.Trim(_T("\n\r"));
876 data->color = color;
877 if (sMessage.Find('\n')>=0)
879 sMessage = sMessage.Mid(sMessage.Find('\n'));
880 sMessage.Trim(_T("\n\r"));
882 else
883 sMessage.Empty();
884 m_arData.push_back(data);
885 AddItemToList();
889 UINT CGitProgressDlg::ProgressThreadEntry(LPVOID pVoid)
891 return ((CGitProgressDlg*)pVoid)->ProgressThread();
894 UINT CGitProgressDlg::ProgressThread()
896 // The SetParams function should have loaded something for us
898 CString temp;
899 CString sWindowTitle;
900 bool localoperation = false;
901 bool bSuccess = false;
902 m_AlwaysConflicted = false;
904 DialogEnableWindow(IDOK, FALSE);
905 DialogEnableWindow(IDCANCEL, TRUE);
906 // SetAndClearProgressInfo(m_hWnd);
907 m_itemCount = m_itemCountTotal;
909 InterlockedExchange(&m_bThreadRunning, TRUE);
910 iFirstResized = 0;
911 bSecondResized = FALSE;
912 m_bFinishedItemAdded = false;
913 CTime startTime = CTime::GetCurrentTime();
915 if (m_pTaskbarList)
916 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_INDETERMINATE);
918 switch (m_Command)
920 case GitProgress_Add:
921 bSuccess = CmdAdd(sWindowTitle, localoperation);
922 break;
923 case GitProgress_Copy:
924 bSuccess = CmdCopy(sWindowTitle, localoperation);
925 break;
926 case GitProgress_Export:
927 bSuccess = CmdExport(sWindowTitle, localoperation);
928 break;
929 case GitProgress_Rename:
930 bSuccess = CmdRename(sWindowTitle, localoperation);
931 break;
932 case GitProgress_Resolve:
933 bSuccess = CmdResolve(sWindowTitle, localoperation);
934 break;
935 case GitProgress_Revert:
936 bSuccess = CmdRevert(sWindowTitle, localoperation);
937 break;
938 case GitProgress_Switch:
939 bSuccess = CmdSwitch(sWindowTitle, localoperation);
940 break;
941 case GitProgress_SendMail:
942 bSuccess = CmdSendMail(sWindowTitle, localoperation);
943 break;
945 if (!bSuccess)
946 temp.LoadString(IDS_PROGRS_TITLEFAILED);
947 else
948 temp.LoadString(IDS_PROGRS_TITLEFIN);
949 sWindowTitle = sWindowTitle + _T(" ") + temp;
950 SetWindowText(sWindowTitle);
952 KillTimer(TRANSFERTIMER);
953 KillTimer(VISIBLETIMER);
955 if (m_pTaskbarList)
957 if (DidErrorsOccur())
959 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_ERROR);
960 m_pTaskbarList->SetProgressValue(m_hWnd, 100, 100);
962 else
963 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NOPROGRESS);
966 DialogEnableWindow(IDCANCEL, FALSE);
967 DialogEnableWindow(IDOK, TRUE);
969 CString info = BuildInfoString();
970 if (!bSuccess)
971 info.LoadString(IDS_PROGRS_INFOFAILED);
972 SetDlgItemText(IDC_INFOTEXT, info);
973 ResizeColumns();
974 CWnd * pWndOk = GetDlgItem(IDOK);
975 if (pWndOk && ::IsWindow(pWndOk->GetSafeHwnd()))
977 SendMessage(DM_SETDEFID, IDOK);
978 GetDlgItem(IDOK)->SetFocus();
981 CString sFinalInfo;
982 if (!m_sTotalBytesTransferred.IsEmpty())
984 CTimeSpan time = CTime::GetCurrentTime() - startTime;
985 temp.Format(IDS_PROGRS_TIME, (LONG)time.GetTotalMinutes(), (LONG)time.GetSeconds());
986 sFinalInfo.Format(IDS_PROGRS_FINALINFO, m_sTotalBytesTransferred, (LPCTSTR)temp);
987 SetDlgItemText(IDC_PROGRESSLABEL, sFinalInfo);
989 else
990 GetDlgItem(IDC_PROGRESSLABEL)->ShowWindow(SW_HIDE);
992 GetDlgItem(IDC_PROGRESSBAR)->ShowWindow(SW_HIDE);
994 if (!m_bFinishedItemAdded)
996 // there's no "finished: xxx" line at the end. We add one here to make
997 // sure the user sees that the command is actually finished.
998 NotificationData * data = new NotificationData();
999 data->bAuxItem = true;
1000 data->sActionColumnText.LoadString(IDS_PROGRS_FINISHED);
1001 m_arData.push_back(data);
1002 AddItemToList();
1005 int count = m_ProgList.GetItemCount();
1006 if ((count > 0)&&(m_bLastVisible))
1007 m_ProgList.EnsureVisible(count-1, FALSE);
1009 CLogFile logfile;
1010 if (logfile.Open())
1012 logfile.AddTimeLine();
1013 for (size_t i=0; i<m_arData.size(); i++)
1015 NotificationData * data = m_arData[i];
1016 temp.Format(_T("%-20s : %s"), (LPCTSTR)data->sActionColumnText, (LPCTSTR)data->sPathColumnText);
1017 logfile.AddLine(temp);
1019 if (!sFinalInfo.IsEmpty())
1020 logfile.AddLine(sFinalInfo);
1021 logfile.Close();
1024 m_bCancelled = TRUE;
1025 InterlockedExchange(&m_bThreadRunning, FALSE);
1026 RefreshCursor();
1028 #if 0
1029 DWORD dwAutoClose = CRegStdDWORD(_T("Software\\TortoiseGit\\AutoClose"), CLOSE_MANUAL);
1030 if (m_options & ProgOptDryRun)
1031 dwAutoClose = 0; // dry run means progress dialog doesn't auto close at all
1032 if (!m_bLastVisible)
1033 dwAutoClose = 0;
1034 if (m_dwCloseOnEnd != (DWORD)-1)
1035 dwAutoClose = m_dwCloseOnEnd; // command line value has priority over setting value
1036 if ((dwAutoClose == CLOSE_NOERRORS)&&(!m_bErrorsOccurred))
1037 PostMessage(WM_COMMAND, 1, (LPARAM)GetDlgItem(IDOK)->m_hWnd);
1038 if ((dwAutoClose == CLOSE_NOCONFLICTS)&&(!m_bErrorsOccurred)&&(m_nConflicts==0))
1039 PostMessage(WM_COMMAND, 1, (LPARAM)GetDlgItem(IDOK)->m_hWnd);
1040 if ((dwAutoClose == CLOSE_NOMERGES)&&(!m_bErrorsOccurred)&&(m_nConflicts==0)&&(!m_bMergesAddsDeletesOccurred))
1041 PostMessage(WM_COMMAND, 1, (LPARAM)GetDlgItem(IDOK)->m_hWnd);
1042 if ((dwAutoClose == CLOSE_LOCAL)&&(!m_bErrorsOccurred)&&(m_nConflicts==0)&&(localoperation))
1043 PostMessage(WM_COMMAND, 1, (LPARAM)GetDlgItem(IDOK)->m_hWnd);
1044 #endif
1046 //Don't do anything here which might cause messages to be sent to the window
1047 //The window thread is probably now blocked in OnOK if we've done an auto close
1048 return 0;
1051 void CGitProgressDlg::OnBnClickedLogbutton()
1053 switch(this->m_Command)
1055 case GitProgress_Add:
1056 case GitProgress_Resolve:
1058 CString cmd = _T(" /command:commit");
1059 cmd += _T(" /path:\"")+g_Git.m_CurrentDir+_T("\"");
1061 CAppUtils::RunTortoiseProc(cmd);
1062 this->EndDialog(IDOK);
1063 break;
1066 #if 0
1067 if (m_targetPathList.GetCount() != 1)
1068 return;
1069 StringRevMap::iterator it = m_UpdateStartRevMap.begin();
1070 svn_revnum_t rev = -1;
1071 if (it != m_UpdateStartRevMap.end())
1073 rev = it->second;
1075 CLogDlg dlg;
1076 dlg.SetParams(m_targetPathList[0], m_RevisionEnd, m_RevisionEnd, rev, 0, TRUE);
1077 dlg.DoModal();
1078 #endif
1082 void CGitProgressDlg::OnClose()
1084 if (m_bCancelled)
1086 TerminateThread(m_pThread->m_hThread, (DWORD)-1);
1087 InterlockedExchange(&m_bThreadRunning, FALSE);
1089 else
1091 m_bCancelled = TRUE;
1092 return;
1094 DialogEnableWindow(IDCANCEL, TRUE);
1095 __super::OnClose();
1098 void CGitProgressDlg::OnOK()
1100 if ((m_bCancelled)&&(!m_bThreadRunning))
1102 // I have made this wait a sensible amount of time (10 seconds) for the thread to finish
1103 // You must be careful in the thread that after posting the WM_COMMAND/IDOK message, you
1104 // don't do any more operations on the window which might require message passing
1105 // If you try to send windows messages once we're waiting here, then the thread can't finished
1106 // because the Window's message loop is blocked at this wait
1107 WaitForSingleObject(m_pThread->m_hThread, 10000);
1108 __super::OnOK();
1110 m_bCancelled = TRUE;
1113 void CGitProgressDlg::OnCancel()
1115 if ((m_bCancelled)&&(!m_bThreadRunning))
1116 __super::OnCancel();
1117 m_bCancelled = TRUE;
1120 void CGitProgressDlg::OnLvnGetdispinfoSvnprogress(NMHDR *pNMHDR, LRESULT *pResult)
1122 NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
1124 if (pDispInfo)
1126 if (pDispInfo->item.mask & LVIF_TEXT)
1128 if (pDispInfo->item.iItem < (int)m_arData.size())
1130 const NotificationData * data = m_arData[pDispInfo->item.iItem];
1131 switch (pDispInfo->item.iSubItem)
1133 case 0:
1134 lstrcpyn(m_columnbuf, data->sActionColumnText, MAX_PATH);
1135 break;
1136 case 1:
1137 lstrcpyn(m_columnbuf, data->sPathColumnText, pDispInfo->item.cchTextMax);
1138 if (!data->bAuxItem)
1140 int cWidth = m_ProgList.GetColumnWidth(1);
1141 cWidth = max(12, cWidth-12);
1142 CDC * pDC = m_ProgList.GetDC();
1143 if (pDC != NULL)
1145 CFont * pFont = pDC->SelectObject(m_ProgList.GetFont());
1146 PathCompactPath(pDC->GetSafeHdc(), m_columnbuf, cWidth);
1147 pDC->SelectObject(pFont);
1148 ReleaseDC(pDC);
1151 break;
1152 case 2:
1153 lstrcpyn(m_columnbuf, data->mime_type, MAX_PATH);
1154 break;
1155 default:
1156 m_columnbuf[0] = 0;
1158 pDispInfo->item.pszText = m_columnbuf;
1162 *pResult = 0;
1165 void CGitProgressDlg::OnNMCustomdrawSvnprogress(NMHDR *pNMHDR, LRESULT *pResult)
1167 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
1169 // Take the default processing unless we set this to something else below.
1170 *pResult = CDRF_DODEFAULT;
1172 // First thing - check the draw stage. If it's the control's prepaint
1173 // stage, then tell Windows we want messages for every item.
1175 if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )
1177 *pResult = CDRF_NOTIFYITEMDRAW;
1179 else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )
1181 // This is the prepaint stage for an item. Here's where we set the
1182 // item's text color. Our return value will tell Windows to draw the
1183 // item itself, but it will use the new color we set here.
1185 // Tell Windows to paint the control itself.
1186 *pResult = CDRF_DODEFAULT;
1188 ASSERT(pLVCD->nmcd.dwItemSpec < m_arData.size());
1189 if(pLVCD->nmcd.dwItemSpec >= m_arData.size())
1191 return;
1193 const NotificationData * data = m_arData[pLVCD->nmcd.dwItemSpec];
1194 ASSERT(data != NULL);
1195 if (data == NULL)
1196 return;
1198 // Store the color back in the NMLVCUSTOMDRAW struct.
1199 pLVCD->clrText = data->color;
1203 void CGitProgressDlg::OnNMDblclkSvnprogress(NMHDR * /*pNMHDR*/, LRESULT * /*pResult*/)
1205 #if 0
1206 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1207 *pResult = 0;
1208 if (pNMLV->iItem < 0)
1209 return;
1210 if (m_options & ProgOptDryRun)
1211 return; //don't do anything in a dry-run.
1213 const NotificationData * data = m_arData[pNMLV->iItem];
1214 if (data == NULL)
1215 return;
1217 if (data->bConflictedActionItem)
1219 // We've double-clicked on a conflicted item - do a three-way merge on it
1220 SVNDiff::StartConflictEditor(data->path);
1222 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))
1224 // This is a modified file which has been merged on update. Diff it against base
1225 CTGitPath temporaryFile;
1226 SVNDiff diff(this, this->m_hWnd, true);
1227 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
1228 svn_revnum_t baseRev = 0;
1229 diff.DiffFileAgainstBase(data->path, baseRev);
1231 else if ((!data->bAuxItem)&&(data->path.Exists())&&(!data->path.IsDirectory()))
1233 bool bOpenWith = false;
1234 int ret = (int)ShellExecute(m_hWnd, NULL, data->path.GetWinPath(), NULL, NULL, SW_SHOWNORMAL);
1235 if (ret <= HINSTANCE_ERROR)
1236 bOpenWith = true;
1237 if (bOpenWith)
1239 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
1240 cmd += data->path.GetWinPathString() + _T(" ");
1241 CAppUtils::LaunchApplication(cmd, NULL, false);
1244 #endif
1247 void CGitProgressDlg::OnHdnItemclickSvnprogress(NMHDR *pNMHDR, LRESULT *pResult)
1249 LPNMHEADER phdr = reinterpret_cast<LPNMHEADER>(pNMHDR);
1250 if (m_bThreadRunning)
1251 return;
1252 if (m_nSortedColumn == phdr->iItem)
1253 m_bAscending = !m_bAscending;
1254 else
1255 m_bAscending = TRUE;
1256 m_nSortedColumn = phdr->iItem;
1257 Sort();
1259 CString temp;
1260 m_ProgList.SetRedraw(FALSE);
1261 m_ProgList.DeleteAllItems();
1262 m_ProgList.SetItemCountEx (static_cast<int>(m_arData.size()));
1264 m_ProgList.SetRedraw(TRUE);
1266 *pResult = 0;
1269 bool CGitProgressDlg::NotificationDataIsAux(const NotificationData* pData)
1271 return pData->bAuxItem;
1274 LRESULT CGitProgressDlg::OnGitProgress(WPARAM /*wParam*/, LPARAM /*lParam*/)
1276 #if 0
1277 SVNProgress * pProgressData = (SVNProgress *)lParam;
1278 CProgressCtrl * progControl = (CProgressCtrl *)GetDlgItem(IDC_PROGRESSBAR);
1279 if ((pProgressData->total > 1000)&&(!progControl->IsWindowVisible()))
1281 progControl->ShowWindow(SW_SHOW);
1282 if (m_pTaskbarList)
1283 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
1285 if (((pProgressData->total < 0)&&(pProgressData->progress > 1000)&&(progControl->IsWindowVisible()))&&(m_itemCountTotal<0))
1287 progControl->ShowWindow(SW_HIDE);
1288 if (m_pTaskbarList)
1289 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_INDETERMINATE);
1291 if (!GetDlgItem(IDC_PROGRESSLABEL)->IsWindowVisible())
1292 GetDlgItem(IDC_PROGRESSLABEL)->ShowWindow(SW_SHOW);
1293 SetTimer(TRANSFERTIMER, 2000, NULL);
1294 if ((pProgressData->total > 0)&&(pProgressData->progress > 1000))
1296 progControl->SetPos((int)pProgressData->progress);
1297 progControl->SetRange32(0, (int)pProgressData->total);
1298 if (m_pTaskbarList)
1300 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
1301 m_pTaskbarList->SetProgressValue(m_hWnd, pProgressData->progress, pProgressData->total);
1304 CString progText;
1305 if (pProgressData->overall_total < 1024)
1306 m_sTotalBytesTransferred.Format(IDS_SVN_PROGRESS_TOTALBYTESTRANSFERRED, pProgressData->overall_total);
1307 else if (pProgressData->overall_total < 1200000)
1308 m_sTotalBytesTransferred.Format(IDS_SVN_PROGRESS_TOTALTRANSFERRED, pProgressData->overall_total / 1024);
1309 else
1310 m_sTotalBytesTransferred.Format(IDS_SVN_PROGRESS_TOTALMBTRANSFERRED, (double)((double)pProgressData->overall_total / 1024000.0));
1311 progText.Format(IDS_SVN_PROGRESS_TOTALANDSPEED, (LPCTSTR)m_sTotalBytesTransferred, (LPCTSTR)pProgressData->SpeedString);
1312 SetDlgItemText(IDC_PROGRESSLABEL, progText);
1313 #endif
1314 return 0;
1317 void CGitProgressDlg::OnTimer(UINT_PTR nIDEvent)
1319 if (nIDEvent == TRANSFERTIMER)
1321 CString progText;
1322 CString progSpeed;
1323 progSpeed.Format(IDS_SVN_PROGRESS_BYTES_SEC, 0);
1324 progText.Format(IDS_SVN_PROGRESS_TOTALANDSPEED, (LPCTSTR)m_sTotalBytesTransferred, (LPCTSTR)progSpeed);
1325 SetDlgItemText(IDC_PROGRESSLABEL, progText);
1326 KillTimer(TRANSFERTIMER);
1328 if (nIDEvent == VISIBLETIMER)
1330 if (nEnsureVisibleCount)
1331 m_ProgList.EnsureVisible(m_ProgList.GetItemCount()-1, false);
1332 nEnsureVisibleCount = 0;
1336 void CGitProgressDlg::Sort()
1338 if(m_arData.size() < 2)
1340 return;
1343 // We need to sort the blocks which lie between the auxiliary entries
1344 // This is so that any aux data stays where it was
1345 NotificationDataVect::iterator actionBlockBegin;
1346 NotificationDataVect::iterator actionBlockEnd = m_arData.begin(); // We start searching from here
1348 for(;;)
1350 // Search to the start of the non-aux entry in the next block
1351 actionBlockBegin = std::find_if(actionBlockEnd, m_arData.end(), std::not1(std::ptr_fun(&CGitProgressDlg::NotificationDataIsAux)));
1352 if(actionBlockBegin == m_arData.end())
1354 // There are no more actions
1355 break;
1357 // Now search to find the end of the block
1358 actionBlockEnd = std::find_if(actionBlockBegin+1, m_arData.end(), std::ptr_fun(&CGitProgressDlg::NotificationDataIsAux));
1359 // Now sort the block
1360 std::sort(actionBlockBegin, actionBlockEnd, &CGitProgressDlg::SortCompare);
1364 bool CGitProgressDlg::SortCompare(const NotificationData * pData1, const NotificationData * pData2)
1366 int result = 0;
1367 switch (m_nSortedColumn)
1369 case 0: //action column
1370 result = pData1->sActionColumnText.Compare(pData2->sActionColumnText);
1371 break;
1372 case 1: //path column
1373 // Compare happens after switch()
1374 break;
1375 case 2: //mime-type column
1376 result = pData1->mime_type.Compare(pData2->mime_type);
1377 break;
1378 default:
1379 break;
1382 // Sort by path if everything else is equal
1383 if (result == 0)
1385 result = CTGitPath::Compare(pData1->path, pData2->path);
1388 if (!m_bAscending)
1389 result = -result;
1390 return result < 0;
1393 BOOL CGitProgressDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
1395 if (!GetDlgItem(IDOK)->IsWindowEnabled())
1397 // only show the wait cursor over the list control
1398 if ((pWnd)&&(pWnd == GetDlgItem(IDC_SVNPROGRESS)))
1400 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT));
1401 SetCursor(hCur);
1402 return TRUE;
1405 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));
1406 SetCursor(hCur);
1407 return CResizableStandAloneDialog::OnSetCursor(pWnd, nHitTest, message);
1410 BOOL CGitProgressDlg::PreTranslateMessage(MSG* pMsg)
1412 if (pMsg->message == WM_KEYDOWN)
1414 if (pMsg->wParam == VK_ESCAPE)
1416 // pressing the ESC key should close the dialog. But since we disabled the escape
1417 // key (so the user doesn't get the idea that he could simply undo an e.g. update)
1418 // this won't work.
1419 // So if the user presses the ESC key, change it to VK_RETURN so the dialog gets
1420 // the impression that the OK button was pressed.
1421 if ((!m_bThreadRunning)&&(!GetDlgItem(IDCANCEL)->IsWindowEnabled())
1422 &&(GetDlgItem(IDOK)->IsWindowEnabled())&&(GetDlgItem(IDOK)->IsWindowVisible()))
1424 // since we convert ESC to RETURN, make sure the OK button has the focus.
1425 GetDlgItem(IDOK)->SetFocus();
1426 pMsg->wParam = VK_RETURN;
1429 if (pMsg->wParam == 'A')
1431 if (GetKeyState(VK_CONTROL)&0x8000)
1433 // Ctrl-A -> select all
1434 m_ProgList.SetSelectionMark(0);
1435 for (int i=0; i<m_ProgList.GetItemCount(); ++i)
1437 m_ProgList.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
1441 if ((pMsg->wParam == 'C')||(pMsg->wParam == VK_INSERT))
1443 int selIndex = m_ProgList.GetSelectionMark();
1444 if (selIndex >= 0)
1446 if (GetKeyState(VK_CONTROL)&0x8000)
1448 //Ctrl-C -> copy to clipboard
1449 CString sClipdata;
1450 POSITION pos = m_ProgList.GetFirstSelectedItemPosition();
1451 if (pos != NULL)
1453 while (pos)
1455 int nItem = m_ProgList.GetNextSelectedItem(pos);
1456 CString sAction = m_ProgList.GetItemText(nItem, 0);
1457 CString sPath = m_ProgList.GetItemText(nItem, 1);
1458 CString sMime = m_ProgList.GetItemText(nItem, 2);
1459 CString sLogCopyText;
1460 sLogCopyText.Format(_T("%s: %s %s\r\n"),
1461 (LPCTSTR)sAction, (LPCTSTR)sPath, (LPCTSTR)sMime);
1462 sClipdata += sLogCopyText;
1464 CStringUtils::WriteAsciiStringToClipboard(sClipdata);
1469 } // if (pMsg->message == WM_KEYDOWN)
1470 return __super::PreTranslateMessage(pMsg);
1473 void CGitProgressDlg::OnContextMenu(CWnd* /*pWnd*/, CPoint /*point*/)
1475 #if 0
1476 if (m_options & ProgOptDryRun)
1477 return; // don't do anything in a dry-run.
1479 if (pWnd == &m_ProgList)
1481 int selIndex = m_ProgList.GetSelectionMark();
1482 if ((point.x == -1) && (point.y == -1))
1484 // Menu was invoked from the keyboard rather than by right-clicking
1485 CRect rect;
1486 m_ProgList.GetItemRect(selIndex, &rect, LVIR_LABEL);
1487 m_ProgList.ClientToScreen(&rect);
1488 point = rect.CenterPoint();
1491 if ((selIndex >= 0)&&(!m_bThreadRunning))
1493 // entry is selected, thread has finished with updating so show the popup menu
1494 CIconMenu popup;
1495 if (popup.CreatePopupMenu())
1497 bool bAdded = false;
1498 NotificationData * data = m_arData[selIndex];
1499 if ((data)&&(!data->path.IsDirectory()))
1501 if (data->action == svn_wc_notify_update_update || data->action == svn_wc_notify_resolved)
1503 if (m_ProgList.GetSelectedCount() == 1)
1505 popup.AppendMenuIcon(ID_COMPARE, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1506 bAdded = true;
1509 if (data->bConflictedActionItem)
1511 if (m_ProgList.GetSelectedCount() == 1)
1513 popup.AppendMenuIcon(ID_EDITCONFLICT, IDS_MENUCONFLICT,IDI_CONFLICT);
1514 popup.SetDefaultItem(ID_EDITCONFLICT, FALSE);
1515 popup.AppendMenuIcon(ID_CONFLICTRESOLVE, IDS_SVNPROGRESS_MENUMARKASRESOLVED,IDI_RESOLVE);
1517 popup.AppendMenuIcon(ID_CONFLICTUSETHEIRS, IDS_SVNPROGRESS_MENUUSETHEIRS,IDI_RESOLVE);
1518 popup.AppendMenuIcon(ID_CONFLICTUSEMINE, IDS_SVNPROGRESS_MENUUSEMINE,IDI_RESOLVE);
1520 else if ((data->content_state == svn_wc_notify_state_merged)||(GitProgress_Merge == m_Command)||(data->action == svn_wc_notify_resolved))
1521 popup.SetDefaultItem(ID_COMPARE, FALSE);
1523 if (m_ProgList.GetSelectedCount() == 1)
1525 if ((data->action == svn_wc_notify_add)||
1526 (data->action == svn_wc_notify_update_add)||
1527 (data->action == svn_wc_notify_commit_added)||
1528 (data->action == svn_wc_notify_commit_modified)||
1529 (data->action == svn_wc_notify_restore)||
1530 (data->action == svn_wc_notify_revert)||
1531 (data->action == svn_wc_notify_resolved)||
1532 (data->action == svn_wc_notify_commit_replaced)||
1533 (data->action == svn_wc_notify_commit_modified)||
1534 (data->action == svn_wc_notify_commit_postfix_txdelta)||
1535 (data->action == svn_wc_notify_update_update))
1537 popup.AppendMenuIcon(ID_LOG, IDS_MENULOG,IDI_LOG);
1538 if (data->action == svn_wc_notify_update_update)
1539 popup.AppendMenu(MF_SEPARATOR, NULL);
1540 popup.AppendMenuIcon(ID_OPEN, IDS_LOG_POPUP_OPEN, IDI_OPEN);
1541 popup.AppendMenuIcon(ID_OPENWITH, IDS_LOG_POPUP_OPENWITH, IDI_OPEN);
1542 bAdded = true;
1545 } // if ((data)&&(!data->path.IsDirectory()))
1546 if (m_ProgList.GetSelectedCount() == 1)
1548 if (data)
1550 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1551 if ((!sPath.IsEmpty())&&(!SVN::PathIsURL(CTGitPath(sPath))))
1553 CTGitPath path = CTGitPath(sPath);
1554 if (path.GetDirectory().Exists())
1556 popup.AppendMenuIcon(ID_EXPLORE, IDS_SVNPROGRESS_MENUOPENPARENT, IDI_EXPLORER);
1557 bAdded = true;
1562 if (m_ProgList.GetSelectedCount() > 0)
1564 if (bAdded)
1565 popup.AppendMenu(MF_SEPARATOR, NULL);
1566 popup.AppendMenuIcon(ID_COPY, IDS_LOG_POPUP_COPYTOCLIPBOARD,IDI_COPYCLIP);
1567 bAdded = true;
1569 if (bAdded)
1571 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
1572 DialogEnableWindow(IDOK, FALSE);
1573 this->SetPromptApp(&theApp);
1574 theApp.DoWaitCursor(1);
1575 bool bOpenWith = false;
1576 switch (cmd)
1578 case ID_COPY:
1580 CString sLines;
1581 POSITION pos = m_ProgList.GetFirstSelectedItemPosition();
1582 while (pos)
1584 int nItem = m_ProgList.GetNextSelectedItem(pos);
1585 NotificationData * data = m_arData[nItem];
1586 if (data)
1588 sLines += data->sPathColumnText;
1589 sLines += _T("\r\n");
1592 sLines.TrimRight();
1593 if (!sLines.IsEmpty())
1595 CStringUtils::WriteAsciiStringToClipboard(sLines, GetSafeHwnd());
1598 break;
1599 case ID_EXPLORE:
1601 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1603 CTGitPath path = CTGitPath(sPath);
1604 ShellExecute(m_hWnd, _T("explore"), path.GetDirectory().GetWinPath(), NULL, path.GetDirectory().GetWinPath(), SW_SHOW);
1606 break;
1607 case ID_COMPARE:
1609 svn_revnum_t rev = -1;
1610 StringRevMap::iterator it = m_UpdateStartRevMap.end();
1611 if (data->basepath.IsEmpty())
1612 it = m_UpdateStartRevMap.begin();
1613 else
1614 it = m_UpdateStartRevMap.find(data->basepath.GetSVNApiPath(pool));
1615 if (it != m_UpdateStartRevMap.end())
1616 rev = it->second;
1617 // if the file was merged during update, do a three way diff between OLD, MINE, THEIRS
1618 if (data->content_state == svn_wc_notify_state_merged)
1620 CTGitPath basefile = CTempFiles::Instance().GetTempFilePath(false, data->path, rev);
1621 CTGitPath newfile = CTempFiles::Instance().GetTempFilePath(false, data->path, SVNRev::REV_HEAD);
1622 SVN svn;
1623 if (!svn.Cat(data->path, SVNRev(SVNRev::REV_WC), rev, basefile))
1625 CMessageBox::Show(m_hWnd, svn.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1626 DialogEnableWindow(IDOK, TRUE);
1627 break;
1629 // If necessary, convert the line-endings on the file before diffing
1630 if ((DWORD)CRegDWORD(_T("Software\\TortoiseGit\\ConvertBase"), TRUE))
1632 CTGitPath temporaryFile = CTempFiles::Instance().GetTempFilePath(false, data->path, SVNRev::REV_BASE);
1633 if (!svn.Cat(data->path, SVNRev(SVNRev::REV_BASE), SVNRev(SVNRev::REV_BASE), temporaryFile))
1635 temporaryFile.Reset();
1636 break;
1638 else
1640 newfile = temporaryFile;
1644 SetFileAttributes(newfile.GetWinPath(), FILE_ATTRIBUTE_READONLY);
1645 SetFileAttributes(basefile.GetWinPath(), FILE_ATTRIBUTE_READONLY);
1646 CString revname, wcname, basename;
1647 revname.Format(_T("%s Revision %ld"), (LPCTSTR)data->path.GetUIFileOrDirectoryName(), rev);
1648 wcname.Format(IDS_DIFF_WCNAME, (LPCTSTR)data->path.GetUIFileOrDirectoryName());
1649 basename.Format(IDS_DIFF_BASENAME, (LPCTSTR)data->path.GetUIFileOrDirectoryName());
1650 CAppUtils::StartExtMerge(basefile, newfile, data->path, data->path, basename, revname, wcname, CString(), true);
1652 else
1654 CTGitPath tempfile = CTempFiles::Instance().GetTempFilePath(false, data->path, rev);
1655 SVN svn;
1656 if (!svn.Cat(data->path, SVNRev(SVNRev::REV_WC), rev, tempfile))
1658 CMessageBox::Show(m_hWnd, svn.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1659 DialogEnableWindow(IDOK, TRUE);
1660 break;
1662 else
1664 SetFileAttributes(tempfile.GetWinPath(), FILE_ATTRIBUTE_READONLY);
1665 CString revname, wcname;
1666 revname.Format(_T("%s Revision %ld"), (LPCTSTR)data->path.GetUIFileOrDirectoryName(), rev);
1667 wcname.Format(IDS_DIFF_WCNAME, (LPCTSTR)data->path.GetUIFileOrDirectoryName());
1668 CAppUtils::StartExtDiff(
1669 tempfile, data->path, revname, wcname,
1670 CAppUtils::DiffFlags().AlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000)));
1674 break;
1675 case ID_EDITCONFLICT:
1677 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1678 SVNDiff::StartConflictEditor(CTGitPath(sPath));
1680 break;
1681 case ID_CONFLICTUSETHEIRS:
1682 case ID_CONFLICTUSEMINE:
1683 case ID_CONFLICTRESOLVE:
1685 svn_wc_conflict_choice_t result = svn_wc_conflict_choose_merged;
1686 switch (cmd)
1688 case ID_CONFLICTUSETHEIRS:
1689 result = svn_wc_conflict_choose_theirs_full;
1690 break;
1691 case ID_CONFLICTUSEMINE:
1692 result = svn_wc_conflict_choose_mine_full;
1693 break;
1694 case ID_CONFLICTRESOLVE:
1695 result = svn_wc_conflict_choose_merged;
1696 break;
1698 SVN svn;
1699 POSITION pos = m_ProgList.GetFirstSelectedItemPosition();
1700 CString sResolvedPaths;
1701 while (pos)
1703 int nItem = m_ProgList.GetNextSelectedItem(pos);
1704 NotificationData * data = m_arData[nItem];
1705 if (data)
1707 if (data->bConflictedActionItem)
1709 if (!svn.Resolve(data->path, result, FALSE))
1711 CMessageBox::Show(m_hWnd, svn.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1712 DialogEnableWindow(IDOK, TRUE);
1713 break;
1715 else
1717 data->color = ::GetSysColor(COLOR_WINDOWTEXT);
1718 data->action = svn_wc_notify_resolved;
1719 data->sActionColumnText.LoadString(IDS_SVNACTION_RESOLVE);
1720 data->bConflictedActionItem = false;
1721 m_nConflicts--;
1723 if (m_nConflicts==0)
1725 // When the last conflict is resolved we remove
1726 // the warning which we assume is in the last line.
1727 int nIndex = m_ProgList.GetItemCount()-1;
1728 VERIFY(m_ProgList.DeleteItem(nIndex));
1730 delete m_arData[nIndex];
1731 m_arData.pop_back();
1733 sResolvedPaths += data->path.GetWinPathString() + _T("\n");
1738 m_ProgList.Invalidate();
1739 CString info = BuildInfoString();
1740 SetDlgItemText(IDC_INFOTEXT, info);
1742 if (!sResolvedPaths.IsEmpty())
1744 CString msg;
1745 msg.Format(IDS_SVNPROGRESS_RESOLVED, (LPCTSTR)sResolvedPaths);
1746 CMessageBox::Show(m_hWnd, msg, _T("TortoiseGit"), MB_OK | MB_ICONINFORMATION);
1749 break;
1750 case ID_LOG:
1752 svn_revnum_t rev = m_RevisionEnd;
1753 if (!data->basepath.IsEmpty())
1755 StringRevMap::iterator it = m_FinishedRevMap.find(data->basepath.GetSVNApiPath(pool));
1756 if (it != m_FinishedRevMap.end())
1757 rev = it->second;
1759 CLogDlg dlg;
1760 // fetch the log from HEAD, not the revision we updated to:
1761 // the path might be inside an external folder which has its own
1762 // revisions.
1763 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1764 dlg.SetParams(CTGitPath(sPath), SVNRev(), SVNRev::REV_HEAD, 1, -1, TRUE);
1765 dlg.DoModal();
1767 break;
1768 case ID_OPENWITH:
1769 bOpenWith = true;
1770 case ID_OPEN:
1772 int ret = 0;
1773 CString sWinPath = GetPathFromColumnText(data->sPathColumnText);
1774 if (!bOpenWith)
1775 ret = (int)ShellExecute(this->m_hWnd, NULL, (LPCTSTR)sWinPath, NULL, NULL, SW_SHOWNORMAL);
1776 if ((ret <= HINSTANCE_ERROR)||bOpenWith)
1778 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
1779 cmd += sWinPath + _T(" ");
1780 CAppUtils::LaunchApplication(cmd, NULL, false);
1784 DialogEnableWindow(IDOK, TRUE);
1785 theApp.DoWaitCursor(-1);
1786 } // if (bAdded)
1790 #endif
1793 void CGitProgressDlg::OnEnSetfocusInfotext()
1795 CString sTemp;
1796 GetDlgItemText(IDC_INFOTEXT, sTemp);
1797 if (sTemp.IsEmpty())
1798 GetDlgItem(IDC_INFOTEXT)->HideCaret();
1801 void CGitProgressDlg::OnLvnBegindragSvnprogress(NMHDR* , LRESULT *pResult)
1803 //LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1804 #if 0
1805 int selIndex = m_ProgList.GetSelectionMark();
1806 if (selIndex < 0)
1807 return;
1809 CDropFiles dropFiles; // class for creating DROPFILES struct
1811 int index;
1812 POSITION pos = m_ProgList.GetFirstSelectedItemPosition();
1813 while ( (index = m_ProgList.GetNextSelectedItem(pos)) >= 0 )
1815 NotificationData * data = m_arData[index];
1817 if ( data->kind==svn_node_file || data->kind==svn_node_dir )
1819 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1821 dropFiles.AddFile( sPath );
1825 if ( dropFiles.GetCount()>0 )
1827 dropFiles.CreateStructure();
1829 #endif
1830 *pResult = 0;
1833 void CGitProgressDlg::OnSize(UINT nType, int cx, int cy)
1835 CResizableStandAloneDialog::OnSize(nType, cx, cy);
1836 if ((nType == SIZE_RESTORED)&&(m_bLastVisible))
1838 if(!m_ProgList.m_hWnd)
1839 return;
1841 int count = m_ProgList.GetItemCount();
1842 if (count > 0)
1843 m_ProgList.EnsureVisible(count-1, false);
1847 //////////////////////////////////////////////////////////////////////////
1848 /// commands
1849 //////////////////////////////////////////////////////////////////////////
1850 bool CGitProgressDlg::CmdAdd(CString& sWindowTitle, bool& localoperation)
1852 localoperation = true;
1853 sWindowTitle.LoadString(IDS_PROGRS_TITLE_ADD);
1854 CAppUtils::SetWindowTitle(m_hWnd, m_targetPathList.GetCommonRoot().GetUIPathString(), sWindowTitle);
1855 SetBackgroundImage(IDI_ADD_BKG);
1856 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_ADD)));
1858 if (CRegDWORD(_T("Software\\TortoiseGit\\UseLibgit2"), FALSE) == TRUE)
1860 git_repository *repo = NULL;
1861 git_index *index;
1863 CStringA gitdir = CUnicodeUtils::GetMulti(CTGitPath(g_Git.m_CurrentDir).GetGitPathString(), CP_UTF8);
1864 if (git_repository_open(&repo, gitdir.GetBuffer()))
1866 gitdir.ReleaseBuffer();
1867 ReportGitError();
1868 return false;
1870 gitdir.ReleaseBuffer();
1872 git_config * config;
1873 git_config_new(&config);
1875 CString adminDir;
1876 g_GitAdminDir.GetAdminDirPath(g_Git.m_CurrentDir, adminDir);
1877 CStringA projectConfigA = CUnicodeUtils::GetMulti(adminDir + _T("config"), CP_UTF8);
1878 if (git_config_add_file_ondisk(config, projectConfigA.GetBuffer(), 3))
1880 projectConfigA.ReleaseBuffer();
1881 ReportGitError();
1882 git_config_free(config);
1883 git_repository_free(repo);
1884 return false;
1886 projectConfigA.ReleaseBuffer();
1887 CString globalConfig = g_Git.GetHomeDirectory() + _T("\\.gitconfig");
1888 if (PathFileExists(globalConfig))
1890 CStringA globalConfigA = CUnicodeUtils::GetMulti(globalConfig, CP_UTF8);
1891 if (git_config_add_file_ondisk(config, globalConfigA.GetBuffer(), 2))
1893 globalConfigA.ReleaseBuffer();
1894 ReportGitError();
1895 git_config_free(config);
1896 git_repository_free(repo);
1897 return false;
1899 globalConfigA.ReleaseBuffer();
1901 CString msysGitBinPath(CRegString(REG_MSYSGIT_PATH, _T(""), FALSE));
1902 if (!msysGitBinPath.IsEmpty())
1904 CStringA systemConfigA = CUnicodeUtils::GetMulti(msysGitBinPath + _T("\\..\\etc\\gitconfig"), CP_UTF8);
1905 if (git_config_add_file_ondisk(config, systemConfigA.GetBuffer(), 1))
1907 systemConfigA.ReleaseBuffer();
1908 ReportGitError();
1909 git_config_free(config);
1910 git_repository_free(repo);
1911 return false;
1913 systemConfigA.ReleaseBuffer();
1916 git_repository_set_config(repo, config);
1918 if (git_repository_index(&index, repo))
1920 ReportGitError();
1921 git_repository_free(repo);
1922 return false;
1924 if (git_index_read(index))
1926 ReportGitError();
1927 git_index_free(index);
1928 git_repository_free(repo);
1929 return false;
1932 for(int i=0;i<m_targetPathList.GetCount();i++)
1934 if (git_index_add(index, CStringA(CUnicodeUtils::GetMulti(m_targetPathList[i].GetGitPathString(), CP_UTF8)).GetBuffer(), 0))
1936 ReportGitError();
1937 git_index_free(index);
1938 git_repository_free(repo);
1939 return false;
1941 Notify(m_targetPathList[i],git_wc_notify_add);
1944 if (git_index_write(index))
1946 ReportGitError();
1947 git_index_free(index);
1948 git_repository_free(repo);
1949 return false;
1952 git_index_free(index);
1953 git_repository_free(repo);
1955 else
1957 CMassiveGitTask mgt(L"add -f");
1958 mgt.ExecuteWithNotify(&m_targetPathList, m_bCancelled, git_wc_notify_add, this, &CGitProgressDlg::Notify);
1961 CShellUpdater::Instance().AddPathsForUpdate(m_targetPathList);
1963 this->GetDlgItem(IDC_LOGBUTTON)->SetWindowText(_T("Commit ..."));
1964 this->GetDlgItem(IDC_LOGBUTTON)->ShowWindow(SW_SHOW);
1965 return true;
1968 bool CGitProgressDlg::CmdCopy(CString& /*sWindowTitle*/, bool& /*localoperation*/)
1970 #if 0
1971 ASSERT(m_targetPathList.GetCount() == 1);
1972 sWindowTitle.LoadString(IDS_PROGRS_TITLE_COPY);
1973 SetWindowText(sWindowTitle); // needs to be updated, see TSVN rev. 21375
1974 SetBackgroundImage(IDI_COPY_BKG);
1976 CString sCmdInfo;
1977 sCmdInfo.Format(IDS_PROGRS_CMD_COPY,
1978 m_targetPathList[0].IsUrl() ? (LPCTSTR)m_targetPathList[0].GetSVNPathString() : m_targetPathList[0].GetWinPath(),
1979 (LPCTSTR)m_url.GetSVNPathString(), (LPCTSTR)m_Revision.ToString());
1980 ReportCmd(sCmdInfo);
1982 if (!Copy(m_targetPathList, m_url, m_Revision, m_pegRev, m_sMessage))
1984 ReportSVNError();
1985 return false;
1987 if (m_options & ProgOptSwitchAfterCopy)
1989 sCmdInfo.Format(IDS_PROGRS_CMD_SWITCH,
1990 m_targetPathList[0].GetWinPath(),
1991 (LPCTSTR)m_url.GetSVNPathString(), (LPCTSTR)m_Revision.ToString());
1992 ReportCmd(sCmdInfo);
1993 if (!Switch(m_targetPathList[0], m_url, SVNRev::REV_HEAD, SVNRev::REV_HEAD, m_depth, TRUE, m_options & ProgOptIgnoreExternals))
1995 if (!Switch(m_targetPathList[0], m_url, SVNRev::REV_HEAD, m_Revision, m_depth, TRUE, m_options & ProgOptIgnoreExternals))
1997 ReportSVNError();
1998 return false;
2002 else
2004 if (SVN::PathIsURL(m_url))
2006 CString sMsg(MAKEINTRESOURCE(IDS_PROGRS_COPY_WARNING));
2007 ReportNotification(sMsg);
2010 #endif
2011 return true;
2014 bool CGitProgressDlg::CmdExport(CString& /*sWindowTitle*/, bool& /*localoperation*/)
2016 #if 0
2017 ASSERT(m_targetPathList.GetCount() == 1);
2018 sWindowTitle.LoadString(IDS_PROGRS_TITLE_EXPORT);
2019 sWindowTitle = m_url.GetUIFileOrDirectoryName()+_T(" - ")+sWindowTitle;
2020 SetWindowText(sWindowTitle); // needs to be updated, see TSVN rev. 21375
2021 SetBackgroundImage(IDI_EXPORT_BKG);
2022 CString eol;
2023 if (m_options & ProgOptEolCRLF)
2024 eol = _T("CRLF");
2025 if (m_options & ProgOptEolLF)
2026 eol = _T("LF");
2027 if (m_options & ProgOptEolCR)
2028 eol = _T("CR");
2029 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_EXPORT)));
2030 if (!Export(m_url, m_targetPathList[0], m_Revision, m_Revision, TRUE, m_options & ProgOptIgnoreExternals, m_depth, NULL, FALSE, eol))
2032 ReportSVNError();
2033 return false;
2035 #endif
2036 return true;
2039 bool CGitProgressDlg::CmdRename(CString& /*sWindowTitle*/, bool& /*localoperation*/)
2041 #if 0
2042 ASSERT(m_targetPathList.GetCount() == 1);
2043 if ((!m_targetPathList[0].IsUrl())&&(!m_url.IsUrl()))
2044 localoperation = true;
2045 sWindowTitle.LoadString(IDS_PROGRS_TITLE_RENAME);
2046 SetWindowText(sWindowTitle); // needs to be updated, see TSVN rev. 21375
2047 SetBackgroundImage(IDI_RENAME_BKG);
2048 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RENAME)));
2049 if (!Move(m_targetPathList, m_url, m_Revision, m_sMessage))
2051 ReportSVNError();
2052 return false;
2054 #endif
2055 return true;
2058 bool CGitProgressDlg::CmdResolve(CString& sWindowTitle, bool& localoperation)
2061 localoperation = true;
2062 ASSERT(m_targetPathList.GetCount() == 1);
2063 sWindowTitle.LoadString(IDS_PROGRS_TITLE_RESOLVE);
2064 CAppUtils::SetWindowTitle(m_hWnd, m_targetPathList.GetCommonRoot().GetUIPathString(), sWindowTitle);
2065 SetBackgroundImage(IDI_RESOLVE_BKG);
2066 // check if the file may still have conflict markers in it.
2067 //BOOL bMarkers = FALSE;
2069 for(int i=0;i<m_targetPathList.GetCount();i++)
2071 CString cmd,out,tempmergefile;
2072 cmd.Format(_T("git.exe add -f -- \"%s\""),m_targetPathList[i].GetGitPathString());
2073 if (g_Git.Run(cmd, &out, CP_UTF8))
2075 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
2076 m_bErrorsOccurred=true;
2077 return false;
2080 CAppUtils::RemoveTempMergeFile((CTGitPath &)m_targetPathList[i]);
2082 Notify(m_targetPathList[i],git_wc_notify_resolved);
2084 #if 0
2085 if ((m_options & ProgOptSkipConflictCheck) == 0)
2089 for (INT_PTR fileindex=0; (fileindex<m_targetPathList.GetCount()) && (bMarkers==FALSE); ++fileindex)
2091 if (!m_targetPathList[fileindex].IsDirectory())
2093 CStdioFile file(m_targetPathList[fileindex].GetWinPath(), CFile::typeBinary | CFile::modeRead);
2094 CString strLine = _T("");
2095 while (file.ReadString(strLine))
2097 if (strLine.Find(_T("<<<<<<<"))==0)
2099 bMarkers = TRUE;
2100 break;
2103 file.Close();
2107 catch (CFileException* pE)
2109 TRACE(_T("CFileException in Resolve!\n"));
2110 TCHAR error[10000] = {0};
2111 pE->GetErrorMessage(error, 10000);
2112 ReportError(error);
2113 pE->Delete();
2114 return false;
2117 if (bMarkers)
2119 if (CMessageBox::Show(m_hWnd, IDS_PROGRS_REVERTMARKERS, IDS_APPNAME, MB_YESNO | MB_ICONQUESTION)==IDYES)
2121 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RESOLVE)));
2122 for (INT_PTR fileindex=0; fileindex<m_targetPathList.GetCount(); ++fileindex)
2123 Resolve(m_targetPathList[fileindex], svn_wc_conflict_choose_merged, true);
2126 else
2128 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RESOLVE)));
2129 for (INT_PTR fileindex=0; fileindex<m_targetPathList.GetCount(); ++fileindex)
2130 Resolve(m_targetPathList[fileindex], svn_wc_conflict_choose_merged, true);
2132 #endif
2133 CShellUpdater::Instance().AddPathsForUpdate(m_targetPathList);
2135 this->GetDlgItem(IDC_LOGBUTTON)->SetWindowText(_T("Commit ..."));
2136 this->GetDlgItem(IDC_LOGBUTTON)->ShowWindow(SW_SHOW);
2138 return true;
2141 bool CGitProgressDlg::CmdRevert(CString& sWindowTitle, bool& localoperation)
2144 localoperation = true;
2145 sWindowTitle.LoadString(IDS_PROGRS_TITLE_REVERT);
2146 CAppUtils::SetWindowTitle(m_hWnd, m_targetPathList.GetCommonRoot().GetUIPathString(), sWindowTitle);
2147 SetBackgroundImage(IDI_REVERT_BKG);
2149 CTGitPathList delList;
2150 for(int i=0;i<m_selectedPaths.GetCount();i++)
2152 CTGitPath path;
2153 int action;
2154 path.SetFromWin(g_Git.m_CurrentDir+_T("\\")+m_selectedPaths[i].GetWinPath());
2155 action = m_selectedPaths[i].m_Action;
2156 /* rename file can't delete because it needs original file*/
2157 if((!(action & CTGitPath::LOGACTIONS_ADDED)) &&
2158 (!(action & CTGitPath::LOGACTIONS_REPLACED)))
2159 delList.AddPath(path);
2161 if (DWORD(CRegDWORD(_T("Software\\TortoiseGit\\RevertWithRecycleBin"), TRUE)))
2162 delList.DeleteAllFiles(true);
2164 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_REVERT)));
2165 for(int i=0;i<m_selectedPaths.GetCount();i++)
2167 if(g_Git.Revert(_T("HEAD"), (CTGitPath&)m_selectedPaths[i]))
2169 CMessageBox::Show(NULL,_T("Revert Fail"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
2170 m_bErrorsOccurred=true;
2171 return false;
2173 Notify(m_selectedPaths[i],git_wc_notify_revert);
2176 CShellUpdater::Instance().AddPathsForUpdate(m_selectedPaths);
2178 return true;
2181 bool CGitProgressDlg::CmdSwitch(CString& /*sWindowTitle*/, bool& /*localoperation*/)
2183 #if 0
2184 ASSERT(m_targetPathList.GetCount() == 1);
2185 SVNStatus st;
2186 sWindowTitle.LoadString(IDS_PROGRS_TITLE_SWITCH);
2187 SetWindowText(sWindowTitle); // needs to be updated, see TSVN rev. 21375
2188 SetBackgroundImage(IDI_SWITCH_BKG);
2189 LONG rev = 0;
2190 if (st.GetStatus(m_targetPathList[0]) != (-2))
2192 if (st.status->entry != NULL)
2194 rev = st.status->entry->revision;
2198 CString sCmdInfo;
2199 sCmdInfo.Format(IDS_PROGRS_CMD_SWITCH,
2200 m_targetPathList[0].GetWinPath(), (LPCTSTR)m_url.GetSVNPathString(),
2201 (LPCTSTR)m_Revision.ToString());
2202 ReportCmd(sCmdInfo);
2204 bool depthIsSticky = true;
2205 if (m_depth == svn_depth_unknown)
2206 depthIsSticky = false;
2207 if (!Switch(m_targetPathList[0], m_url, m_Revision, m_Revision, m_depth, depthIsSticky, m_options & ProgOptIgnoreExternals))
2209 ReportSVNError();
2210 return false;
2212 m_UpdateStartRevMap[m_targetPathList[0].GetSVNApiPath(pool)] = rev;
2213 if ((m_RevisionEnd >= 0)&&(rev >= 0)
2214 &&((LONG)m_RevisionEnd > (LONG)rev))
2216 GetDlgItem(IDC_LOGBUTTON)->ShowWindow(SW_SHOW);
2218 #endif
2219 return true;
2222 void CGitProgressDlg::OnBnClickedNoninteractive()
2224 LRESULT res = ::SendMessage(GetDlgItem(IDC_NONINTERACTIVE)->GetSafeHwnd(), BM_GETCHECK, 0, 0);
2225 m_AlwaysConflicted = (res == BST_CHECKED);
2226 CRegDWORD nonint = CRegDWORD(_T("Software\\TortoiseGit\\MergeNonInteractive"), FALSE);
2227 nonint = m_AlwaysConflicted;
2230 CString CGitProgressDlg::GetPathFromColumnText(const CString& sColumnText)
2232 CString sPath = CPathUtils::ParsePathInString(sColumnText);
2233 if (sPath.Find(':')<0)
2235 // the path is not absolute: add the common root of all paths to it
2236 sPath = m_targetPathList.GetCommonRoot().GetDirectory().GetWinPathString() + _T("\\") + CPathUtils::ParsePathInString(sColumnText);
2238 return sPath;
2241 bool CGitProgressDlg::CmdSendMail(CString& sWindowTitle, bool& /*localoperation*/)
2243 sWindowTitle.LoadString(IDS_PROGRS_TITLE_SENDMAIL);
2244 CAppUtils::SetWindowTitle(m_hWnd, m_targetPathList.GetCommonRoot().GetUIPathString(), sWindowTitle);
2245 //SetBackgroundImage(IDI_ADD_BKG);
2246 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_SENDMAIL)));
2247 bool ret=true;
2248 if(this->m_SendMailFlags&SENDMAIL_COMBINED)
2250 CString error;
2251 CTGitPath path;
2252 Notify(path,git_wc_notify_sendmail_start);
2253 CString err;
2254 int retry=0;
2255 while(retry <3)
2257 if(!!CPatch::SendPatchesCombined(m_targetPathList,m_SendMailTO,m_SendMailCC,m_SendMailSubject,!!(this->m_SendMailFlags&SENDMAIL_ATTACHMENT),!!(this->m_SendMailFlags&SENDMAIL_MAPI),&err))
2259 Notify(path,git_wc_notify_sendmail_error,ret,&err);
2260 ret = false;
2262 else
2264 break;
2267 retry++;
2268 if (retry < 3)
2269 Notify(path,git_wc_notify_sendmail_retry,ret,&err);
2270 Sleep(2000);
2271 if(m_bCancelled)
2273 CString str(_T("User Canceled"));
2274 Notify(path,git_wc_notify_sendmail_error,ret,&str);
2275 return false;
2278 if (ret)
2279 Notify(path,git_wc_notify_sendmail_done,ret);
2281 else
2283 for(int i=0;ret && i<m_targetPathList.GetCount();i++)
2285 CPatch patch;
2286 Notify(m_targetPathList[i],git_wc_notify_sendmail_start);
2288 int retry=0;
2289 while(retry<3)
2291 if(!!patch.Send((CString&)m_targetPathList[i].GetWinPathString(),this->m_SendMailTO,
2292 this->m_SendMailCC,!!(this->m_SendMailFlags&SENDMAIL_ATTACHMENT),!!(this->m_SendMailFlags&SENDMAIL_MAPI)))
2294 Notify(m_targetPathList[i],git_wc_notify_sendmail_error,ret,&patch.m_LastError);
2295 ret = false;
2298 else
2300 ret = true;
2301 break;
2303 retry++;
2304 if (retry < 3)
2305 Notify(m_targetPathList[i],git_wc_notify_sendmail_retry,ret,&patch.m_LastError);
2306 Sleep(2000);
2307 if(m_bCancelled)
2309 CString str(_T("User Canceled"));
2310 Notify(m_targetPathList[i],git_wc_notify_sendmail_error,ret,&str);
2311 return false;
2314 if (ret)
2315 Notify(m_targetPathList[i],git_wc_notify_sendmail_done,ret);
2318 return ret;
2321 LRESULT CGitProgressDlg::OnTaskbarBtnCreated(WPARAM /*wParam*/, LPARAM /*lParam*/)
2323 m_pTaskbarList.Release();
2324 m_pTaskbarList.CoCreateInstance(CLSID_TaskbarList);
2325 return 0;