make bisect work (initial commit)
[TortoiseGit.git] / src / TortoiseProc / SVNProgressDlg.cpp
blob07bee3fbf6ec53b67ff5fdfc871879a8be332868
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2011 - 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 "SVNProgressDlg.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"
46 static UINT WM_GITPROGRESS = RegisterWindowMessage(_T("TORTOISEGIT_GITPROGRESS_MSG"));
48 BOOL CGitProgressDlg::m_bAscending = FALSE;
49 int CGitProgressDlg::m_nSortedColumn = -1;
51 #define TRANSFERTIMER 100
52 #define VISIBLETIMER 101
54 enum SVNProgressDlgContextMenuCommands
56 // needs to start with 1, since 0 is the return value if *nothing* is clicked on in the context menu
57 ID_COMPARE = 1,
58 ID_EDITCONFLICT,
59 ID_CONFLICTRESOLVE,
60 ID_CONFLICTUSETHEIRS,
61 ID_CONFLICTUSEMINE,
62 ID_LOG,
63 ID_OPEN,
64 ID_OPENWITH,
65 ID_EXPLORE,
66 ID_COPY
69 IMPLEMENT_DYNAMIC(CGitProgressDlg, CResizableStandAloneDialog)
70 CGitProgressDlg::CGitProgressDlg(CWnd* pParent /*=NULL*/)
71 : CResizableStandAloneDialog(CGitProgressDlg::IDD, pParent)
72 , m_bCancelled(FALSE)
73 , m_pThread(NULL)
74 #if 0
75 , m_Revision(_T("HEAD"))
76 //, m_RevisionEnd(0)
77 , m_bLockWarning(false)
78 , m_bLockExists(false)
79 , m_bThreadRunning(FALSE)
80 , m_nConflicts(0)
81 , m_bErrorsOccurred(FALSE)
82 , m_bMergesAddsDeletesOccurred(FALSE)
84 , m_options(ProgOptNone)
85 , m_dwCloseOnEnd((DWORD)-1)
86 , m_bFinishedItemAdded(false)
87 , m_bLastVisible(false)
88 // , m_depth(svn_depth_unknown)
89 , m_itemCount(-1)
90 , m_itemCountTotal(-1)
91 , m_AlwaysConflicted(false)
92 , m_BugTraqProvider(NULL)
93 , sIgnoredIncluded(MAKEINTRESOURCE(IDS_PROGRS_IGNOREDINCLUDED))
94 , sExtExcluded(MAKEINTRESOURCE(IDS_PROGRS_EXTERNALSEXCLUDED))
95 , sExtIncluded(MAKEINTRESOURCE(IDS_PROGRS_EXTERNALSINCLUDED))
96 , sIgnoreAncestry(MAKEINTRESOURCE(IDS_PROGRS_IGNOREANCESTRY))
97 , sRespectAncestry(MAKEINTRESOURCE(IDS_PROGRS_RESPECTANCESTRY))
98 , sDryRun(MAKEINTRESOURCE(IDS_PROGRS_DRYRUN))
99 , sRecordOnly(MAKEINTRESOURCE(IDS_MERGE_RECORDONLY))
100 #endif
104 CGitProgressDlg::~CGitProgressDlg()
106 for (size_t i=0; i<m_arData.size(); i++)
108 delete m_arData[i];
110 if(m_pThread != NULL)
112 delete m_pThread;
116 void CGitProgressDlg::DoDataExchange(CDataExchange* pDX)
118 CResizableStandAloneDialog::DoDataExchange(pDX);
119 DDX_Control(pDX, IDC_SVNPROGRESS, m_ProgList);
122 BEGIN_MESSAGE_MAP(CGitProgressDlg, CResizableStandAloneDialog)
123 ON_BN_CLICKED(IDC_LOGBUTTON, OnBnClickedLogbutton)
124 ON_NOTIFY(NM_CUSTOMDRAW, IDC_SVNPROGRESS, OnNMCustomdrawSvnprogress)
125 ON_WM_CLOSE()
126 ON_NOTIFY(NM_DBLCLK, IDC_SVNPROGRESS, OnNMDblclkSvnprogress)
127 ON_NOTIFY(HDN_ITEMCLICK, 0, OnHdnItemclickSvnprogress)
128 ON_WM_SETCURSOR()
129 ON_WM_CONTEXTMENU()
130 ON_REGISTERED_MESSAGE(WM_GITPROGRESS, OnGitProgress)
131 ON_WM_TIMER()
132 ON_EN_SETFOCUS(IDC_INFOTEXT, &CGitProgressDlg::OnEnSetfocusInfotext)
133 ON_NOTIFY(LVN_BEGINDRAG, IDC_SVNPROGRESS, &CGitProgressDlg::OnLvnBegindragSvnprogress)
134 ON_WM_SIZE()
135 ON_NOTIFY(LVN_GETDISPINFO, IDC_SVNPROGRESS, &CGitProgressDlg::OnLvnGetdispinfoSvnprogress)
136 ON_BN_CLICKED(IDC_NONINTERACTIVE, &CGitProgressDlg::OnBnClickedNoninteractive)
137 ON_MESSAGE(WM_SHOWCONFLICTRESOLVER, OnShowConflictResolver)
138 END_MESSAGE_MAP()
140 BOOL CGitProgressDlg::Cancel()
142 return m_bCancelled;
145 LRESULT CGitProgressDlg::OnShowConflictResolver(WPARAM /*wParam*/, LPARAM /*lParam*/)
147 #if 0
148 CConflictResolveDlg dlg(this);
149 const svn_wc_conflict_description_t *description = (svn_wc_conflict_description_t *)lParam;
150 if (description)
152 dlg.SetConflictDescription(description);
153 if (dlg.DoModal() == IDOK)
155 if (dlg.GetResult() == svn_wc_conflict_choose_postpone)
157 // if the result is conflicted and the dialog returned IDOK,
158 // that means we should not ask again in case of a conflict
159 m_AlwaysConflicted = true;
160 ::SendMessage(GetDlgItem(IDC_NONINTERACTIVE)->GetSafeHwnd(), BM_SETCHECK, BST_CHECKED, 0);
163 m_mergedfile = dlg.GetMergedFile();
164 m_bCancelled = dlg.IsCancelled();
165 return dlg.GetResult();
168 return svn_wc_conflict_choose_postpone;
169 #endif
170 return 0;
172 #if 0
173 svn_wc_conflict_choice_t CGitProgressDlg::ConflictResolveCallback(const svn_wc_conflict_description_t *description, CString& mergedfile)
175 // we only bother the user when merging
176 if (((m_Command == GitProgress_Merge)||(m_Command == GitProgress_MergeAll)||(m_Command == GitProgress_MergeReintegrate))&&(!m_AlwaysConflicted)&&(description))
178 // we're in a worker thread here. That means we must not show a dialog from the thread
179 // but let the UI thread do it.
180 // To do that, we send a message to the UI thread and let it show the conflict resolver dialog.
181 LRESULT dlgResult = ::SendMessage(GetSafeHwnd(), WM_SHOWCONFLICTRESOLVER, 0, (LPARAM)description);
182 mergedfile = m_mergedfile;
183 return (svn_wc_conflict_choice_t)dlgResult;
186 return svn_wc_conflict_choose_postpone;
188 #endif
189 void CGitProgressDlg::AddItemToList()
191 int totalcount = m_ProgList.GetItemCount();
193 m_ProgList.SetItemCountEx(totalcount+1, LVSICF_NOSCROLL|LVSICF_NOINVALIDATEALL);
194 // make columns width fit
195 if (iFirstResized < 30)
197 // only resize the columns for the first 30 or so entries.
198 // after that, don't resize them anymore because that's an
199 // expensive function call and the columns will be sized
200 // close enough already.
201 ResizeColumns();
202 iFirstResized++;
205 // Make sure the item is *entirely* visible even if the horizontal
206 // scroll bar is visible.
207 int count = m_ProgList.GetCountPerPage();
208 if (totalcount <= (m_ProgList.GetTopIndex() + count + nEnsureVisibleCount + 2))
210 nEnsureVisibleCount++;
211 m_bLastVisible = true;
213 else
215 nEnsureVisibleCount = 0;
216 if (IsIconic() == 0)
217 m_bLastVisible = false;
222 BOOL CGitProgressDlg::Notify(const CTGitPath& path, git_wc_notify_action_t action,
223 int /*status*/ ,
224 CString *strErr
226 svn_node_kind_t kind, const CString& mime_type,
227 svn_wc_notify_state_t content_state,
228 svn_wc_notify_state_t prop_state, LONG rev,
229 const svn_lock_t * lock, svn_wc_notify_lock_state_t lock_state,
230 const CString& changelistname,
231 svn_merge_range_t * range,
232 svn_error_t * err, apr_pool_t * pool
235 bool bNoNotify = false;
236 bool bDoAddData = true;
237 NotificationData * data = new NotificationData();
238 data->path = path;
239 data->action = action;
240 data->sPathColumnText=path.GetGitPathString();
241 data->bAuxItem = false;
242 #if 0
243 data->kind = kind;
244 data->mime_type = mime_type;
245 data->content_state = content_state;
246 data->prop_state = prop_state;
247 data->rev = rev;
248 data->lock_state = lock_state;
249 data->changelistname = changelistname;
250 if ((lock)&&(lock->owner))
251 data->owner = CUnicodeUtils::GetUnicode(lock->owner);
252 data->sPathColumnText = path.GetUIPathString();
253 if (!m_basePath.IsEmpty())
254 data->basepath = m_basePath;
255 if (range)
256 data->merge_range = *range;
257 #endif
258 switch (data->action)
260 case git_wc_notify_add:
261 //case svn_wc_notify_update_add:
262 // if ((data->content_state == svn_wc_notify_state_conflicted) || (data->prop_state == svn_wc_notify_state_conflicted))
263 // {
264 // data->color = m_Colors.GetColor(CColors::Conflict);
265 // data->bConflictedActionItem = true;
266 // data->sActionColumnText.LoadString(IDS_SVNACTION_CONFLICTED);
267 // m_nConflicts++;
268 // }
269 // else
270 // {
271 // m_bMergesAddsDeletesOccurred = true;
272 data->sActionColumnText.LoadString(IDS_SVNACTION_ADD);
273 data->color = m_Colors.GetColor(CColors::Added);
274 // }
275 break;
276 case git_wc_notify_sendmail_start:
277 data->bAuxItem = true;
278 data->sActionColumnText.LoadString(IDS_SVNACTION_SENDMAIL_START);
279 data->color = m_Colors.GetColor(CColors::Modified);
280 break;
282 case git_wc_notify_sendmail_error:
283 data->bAuxItem = true;
284 data->sActionColumnText.LoadString(IDS_SVNACTION_SENDMAIL_ERROR);
285 if(strErr)
286 data->sPathColumnText = *strErr;
287 else
288 data->sPathColumnText.Empty();
289 data->color = m_Colors.GetColor(CColors::Modified);
290 break;
292 case git_wc_notify_sendmail_done:
294 data->sActionColumnText.LoadString(IDS_SVNACTION_SENDMAIL_DONE);
295 data->sPathColumnText.Empty();
296 data->color = m_Colors.GetColor(CColors::Modified);
297 break;
299 case git_wc_notify_sendmail_retry:
300 data->sActionColumnText.LoadString(IDS_SVNACTION_SENDMAIL_RETRY);
301 data->sPathColumnText.Empty();
302 data->color = m_Colors.GetColor(CColors::Modified);
303 break;
306 case git_wc_notify_resolved:
307 data->sActionColumnText.LoadString(IDS_SVNACTION_RESOLVE);
308 break;
310 case git_wc_notify_revert:
311 data->sActionColumnText.LoadString(IDS_SVNACTION_REVERT);
312 break;
314 #if 0
315 case svn_wc_notify_commit_added:
316 data->sActionColumnText.LoadString(IDS_SVNACTION_ADDING);
317 data->color = m_Colors.GetColor(CColors::Added);
318 break;
319 case svn_wc_notify_copy:
320 data->sActionColumnText.LoadString(IDS_SVNACTION_COPY);
321 break;
322 case svn_wc_notify_commit_modified:
323 data->sActionColumnText.LoadString(IDS_SVNACTION_MODIFIED);
324 data->color = m_Colors.GetColor(CColors::Modified);
325 break;
326 case svn_wc_notify_delete:
327 case svn_wc_notify_update_delete:
328 data->sActionColumnText.LoadString(IDS_SVNACTION_DELETE);
329 m_bMergesAddsDeletesOccurred = true;
330 data->color = m_Colors.GetColor(CColors::Deleted);
331 break;
332 case svn_wc_notify_commit_deleted:
333 data->sActionColumnText.LoadString(IDS_SVNACTION_DELETING);
334 data->color = m_Colors.GetColor(CColors::Deleted);
335 break;
336 case svn_wc_notify_restore:
337 data->sActionColumnText.LoadString(IDS_SVNACTION_RESTORE);
338 break;
340 case svn_wc_notify_update_replace:
341 case svn_wc_notify_commit_replaced:
342 data->sActionColumnText.LoadString(IDS_SVNACTION_REPLACED);
343 data->color = m_Colors.GetColor(CColors::Deleted);
344 break;
345 case svn_wc_notify_exists:
346 if ((data->content_state == svn_wc_notify_state_conflicted) || (data->prop_state == svn_wc_notify_state_conflicted))
348 data->color = m_Colors.GetColor(CColors::Conflict);
349 data->bConflictedActionItem = true;
350 m_nConflicts++;
351 data->sActionColumnText.LoadString(IDS_SVNACTION_CONFLICTED);
353 else if ((data->content_state == svn_wc_notify_state_merged) || (data->prop_state == svn_wc_notify_state_merged))
355 data->color = m_Colors.GetColor(CColors::Merged);
356 m_bMergesAddsDeletesOccurred = true;
357 data->sActionColumnText.LoadString(IDS_SVNACTION_MERGED);
359 else
360 data->sActionColumnText.LoadString(IDS_SVNACTION_EXISTS);
361 break;
362 case svn_wc_notify_update_update:
363 // if this is an inoperative dir change, don't show the notification.
364 // an inoperative dir change is when a directory gets updated without
365 // any real change in either text or properties.
366 if ((kind == svn_node_dir)
367 && ((prop_state == svn_wc_notify_state_inapplicable)
368 || (prop_state == svn_wc_notify_state_unknown)
369 || (prop_state == svn_wc_notify_state_unchanged)))
371 bNoNotify = true;
372 break;
374 if ((data->content_state == svn_wc_notify_state_conflicted) || (data->prop_state == svn_wc_notify_state_conflicted))
376 data->color = m_Colors.GetColor(CColors::Conflict);
377 data->bConflictedActionItem = true;
378 m_nConflicts++;
379 data->sActionColumnText.LoadString(IDS_SVNACTION_CONFLICTED);
381 else if ((data->content_state == svn_wc_notify_state_merged) || (data->prop_state == svn_wc_notify_state_merged))
383 data->color = m_Colors.GetColor(CColors::Merged);
384 m_bMergesAddsDeletesOccurred = true;
385 data->sActionColumnText.LoadString(IDS_SVNACTION_MERGED);
387 else if (((data->content_state != svn_wc_notify_state_unchanged)&&(data->content_state != svn_wc_notify_state_unknown)) ||
388 ((data->prop_state != svn_wc_notify_state_unchanged)&&(data->prop_state != svn_wc_notify_state_unknown)))
390 data->sActionColumnText.LoadString(IDS_SVNACTION_UPDATE);
392 else
394 bNoNotify = true;
395 break;
397 if (lock_state == svn_wc_notify_lock_state_unlocked)
399 CString temp(MAKEINTRESOURCE(IDS_SVNACTION_UNLOCKED));
400 data->sActionColumnText += _T(", ") + temp;
402 break;
404 case svn_wc_notify_update_external:
405 // For some reason we build a list of externals...
406 m_ExtStack.AddHead(path.GetUIPathString());
407 data->sActionColumnText.LoadString(IDS_SVNACTION_EXTERNAL);
408 data->bAuxItem = true;
409 break;
411 case svn_wc_notify_update_completed:
413 data->sActionColumnText.LoadString(IDS_SVNACTION_COMPLETED);
414 data->bAuxItem = true;
415 bool bEmpty = !!m_ExtStack.IsEmpty();
416 if (!bEmpty)
417 data->sPathColumnText.Format(IDS_PROGRS_PATHATREV, (LPCTSTR)m_ExtStack.RemoveHead(), rev);
418 else
419 data->sPathColumnText.Format(IDS_PROGRS_ATREV, rev);
421 if ((m_nConflicts>0)&&(bEmpty))
423 // We're going to add another aux item - let's shove this current onto the list first
424 // I don't really like this, but it will do for the moment.
425 m_arData.push_back(data);
426 AddItemToList();
428 data = new NotificationData();
429 data->bAuxItem = true;
430 data->sActionColumnText.LoadString(IDS_PROGRS_CONFLICTSOCCURED_WARNING);
431 data->sPathColumnText.LoadString(IDS_PROGRS_CONFLICTSOCCURED);
432 data->color = m_Colors.GetColor(CColors::Conflict);
433 CSoundUtils::PlayTSVNWarning();
434 // This item will now be added after the switch statement
436 if (!m_basePath.IsEmpty())
437 m_FinishedRevMap[m_basePath.GetSVNApiPath(pool)] = rev;
438 m_RevisionEnd = rev;
439 m_bFinishedItemAdded = true;
441 break;
442 case svn_wc_notify_commit_postfix_txdelta:
443 data->sActionColumnText.LoadString(IDS_SVNACTION_POSTFIX);
444 break;
445 case svn_wc_notify_failed_revert:
446 data->sActionColumnText.LoadString(IDS_SVNACTION_FAILEDREVERT);
447 break;
448 case svn_wc_notify_status_completed:
449 case svn_wc_notify_status_external:
450 data->sActionColumnText.LoadString(IDS_SVNACTION_STATUS);
451 break;
452 case svn_wc_notify_skip:
453 if ((content_state == svn_wc_notify_state_missing)||(content_state == svn_wc_notify_state_obstructed)||(content_state == svn_wc_notify_state_conflicted))
455 data->sActionColumnText.LoadString(IDS_SVNACTION_SKIPMISSING);
457 // The color settings dialog describes the red color with
458 // "possible or real conflict / obstructed" which also applies to
459 // skipped targets during a merge. So we just use the same color.
460 data->color = m_Colors.GetColor(CColors::Conflict);
462 else
463 data->sActionColumnText.LoadString(IDS_SVNACTION_SKIP);
464 break;
465 case svn_wc_notify_locked:
466 if ((lock)&&(lock->owner))
467 data->sActionColumnText.Format(IDS_SVNACTION_LOCKEDBY, (LPCTSTR)CUnicodeUtils::GetUnicode(lock->owner));
468 break;
469 case svn_wc_notify_unlocked:
470 data->sActionColumnText.LoadString(IDS_SVNACTION_UNLOCKED);
471 break;
472 case svn_wc_notify_failed_lock:
473 data->sActionColumnText.LoadString(IDS_SVNACTION_FAILEDLOCK);
474 m_arData.push_back(data);
475 AddItemToList();
476 ReportError(SVN::GetErrorString(err));
477 bDoAddData = false;
478 if (err->apr_err == SVN_ERR_FS_OUT_OF_DATE)
479 m_bLockWarning = true;
480 if (err->apr_err == SVN_ERR_FS_PATH_ALREADY_LOCKED)
481 m_bLockExists = true;
482 break;
483 case svn_wc_notify_failed_unlock:
484 data->sActionColumnText.LoadString(IDS_SVNACTION_FAILEDUNLOCK);
485 m_arData.push_back(data);
486 AddItemToList();
487 ReportError(SVN::GetErrorString(err));
488 bDoAddData = false;
489 if (err->apr_err == SVN_ERR_FS_OUT_OF_DATE)
490 m_bLockWarning = true;
491 break;
492 case svn_wc_notify_changelist_set:
493 data->sActionColumnText.Format(IDS_SVNACTION_CHANGELISTSET, (LPCTSTR)data->changelistname);
494 break;
495 case svn_wc_notify_changelist_clear:
496 data->sActionColumnText.LoadString(IDS_SVNACTION_CHANGELISTCLEAR);
497 break;
498 case svn_wc_notify_changelist_moved:
499 data->sActionColumnText.Format(IDS_SVNACTION_CHANGELISTMOVED, (LPCTSTR)data->changelistname);
500 break;
501 case svn_wc_notify_foreign_merge_begin:
502 case svn_wc_notify_merge_begin:
503 if (range == NULL)
504 data->sActionColumnText.LoadString(IDS_SVNACTION_MERGEBEGINNONE);
505 else if ((data->merge_range.start == data->merge_range.end) || (data->merge_range.start == data->merge_range.end - 1))
506 data->sActionColumnText.Format(IDS_SVNACTION_MERGEBEGINSINGLE, data->merge_range.end);
507 else if (data->merge_range.start - 1 == data->merge_range.end)
508 data->sActionColumnText.Format(IDS_SVNACTION_MERGEBEGINSINGLEREVERSE, data->merge_range.start);
509 else if (data->merge_range.start < data->merge_range.end)
510 data->sActionColumnText.Format(IDS_SVNACTION_MERGEBEGINMULTIPLE, data->merge_range.start + 1, data->merge_range.end);
511 else
512 data->sActionColumnText.Format(IDS_SVNACTION_MERGEBEGINMULTIPLEREVERSE, data->merge_range.start, data->merge_range.end + 1);
513 data->bAuxItem = true;
514 break;
515 #endif
516 default:
517 break;
518 } // switch (data->action)
520 if (bNoNotify)
521 delete data;
522 else
524 if (bDoAddData)
526 m_arData.push_back(data);
527 AddItemToList();
528 if ((!data->bAuxItem) && (m_itemCount > 0))
530 m_itemCount--;
532 CProgressCtrl * progControl = (CProgressCtrl *)GetDlgItem(IDC_PROGRESSBAR);
533 progControl->ShowWindow(SW_SHOW);
534 progControl->SetPos(m_itemCountTotal - m_itemCount);
535 progControl->SetRange32(0, m_itemCountTotal);
538 //if ((action == svn_wc_notify_commit_postfix_txdelta)&&(bSecondResized == FALSE))
540 // ResizeColumns();
541 // bSecondResized = TRUE;
545 return TRUE;
549 CString CGitProgressDlg::BuildInfoString()
551 CString infotext;
552 if(this->m_Command == GitProgress_Resolve)
553 infotext = _T("You need commit your change after resolve conflict");
554 #if 0
556 CString temp;
557 int added = 0;
558 int copied = 0;
559 int deleted = 0;
560 int restored = 0;
561 int reverted = 0;
562 int resolved = 0;
563 int conflicted = 0;
564 int updated = 0;
565 int merged = 0;
566 int modified = 0;
567 int skipped = 0;
568 int replaced = 0;
570 for (size_t i=0; i<m_arData.size(); ++i)
572 const NotificationData * dat = m_arData[i];
573 switch (dat->action)
575 case svn_wc_notify_add:
576 case svn_wc_notify_update_add:
577 case svn_wc_notify_commit_added:
578 if (dat->bConflictedActionItem)
579 conflicted++;
580 else
581 added++;
582 break;
583 case svn_wc_notify_copy:
584 copied++;
585 break;
586 case svn_wc_notify_delete:
587 case svn_wc_notify_update_delete:
588 case svn_wc_notify_commit_deleted:
589 deleted++;
590 break;
591 case svn_wc_notify_restore:
592 restored++;
593 break;
594 case svn_wc_notify_revert:
595 reverted++;
596 break;
597 case svn_wc_notify_resolved:
598 resolved++;
599 break;
600 case svn_wc_notify_update_update:
601 if (dat->bConflictedActionItem)
602 conflicted++;
603 else if ((dat->content_state == svn_wc_notify_state_merged) || (dat->prop_state == svn_wc_notify_state_merged))
604 merged++;
605 else
606 updated++;
607 break;
608 case svn_wc_notify_commit_modified:
609 modified++;
610 break;
611 case svn_wc_notify_skip:
612 skipped++;
613 break;
614 case svn_wc_notify_commit_replaced:
615 replaced++;
616 break;
619 if (conflicted)
621 temp.LoadString(IDS_SVNACTION_CONFLICTED);
622 infotext += temp;
623 temp.Format(_T(":%d "), conflicted);
624 infotext += temp;
626 if (skipped)
628 temp.LoadString(IDS_SVNACTION_SKIP);
629 infotext += temp;
630 infotext.AppendFormat(_T(":%d "), skipped);
632 if (merged)
634 temp.LoadString(IDS_SVNACTION_MERGED);
635 infotext += temp;
636 infotext.AppendFormat(_T(":%d "), merged);
638 if (added)
640 temp.LoadString(IDS_SVNACTION_ADD);
641 infotext += temp;
642 infotext.AppendFormat(_T(":%d "), added);
644 if (deleted)
646 temp.LoadString(IDS_SVNACTION_DELETE);
647 infotext += temp;
648 infotext.AppendFormat(_T(":%d "), deleted);
650 if (modified)
652 temp.LoadString(IDS_SVNACTION_MODIFIED);
653 infotext += temp;
654 infotext.AppendFormat(_T(":%d "), modified);
656 if (copied)
658 temp.LoadString(IDS_SVNACTION_COPY);
659 infotext += temp;
660 infotext.AppendFormat(_T(":%d "), copied);
662 if (replaced)
664 temp.LoadString(IDS_SVNACTION_REPLACED);
665 infotext += temp;
666 infotext.AppendFormat(_T(":%d "), replaced);
668 if (updated)
670 temp.LoadString(IDS_SVNACTION_UPDATE);
671 infotext += temp;
672 infotext.AppendFormat(_T(":%d "), updated);
674 if (restored)
676 temp.LoadString(IDS_SVNACTION_RESTORE);
677 infotext += temp;
678 infotext.AppendFormat(_T(":%d "), restored);
680 if (reverted)
682 temp.LoadString(IDS_SVNACTION_REVERT);
683 infotext += temp;
684 infotext.AppendFormat(_T(":%d "), reverted);
686 if (resolved)
688 temp.LoadString(IDS_SVNACTION_RESOLVE);
689 infotext += temp;
690 infotext.AppendFormat(_T(":%d "), resolved);
692 #endif
693 return infotext;
696 void CGitProgressDlg::SetSelectedList(const CTGitPathList& selPaths)
698 m_selectedPaths = selPaths;
701 void CGitProgressDlg::ResizeColumns()
703 m_ProgList.SetRedraw(FALSE);
705 TCHAR textbuf[MAX_PATH];
707 int maxcol = ((CHeaderCtrl*)(m_ProgList.GetDlgItem(0)))->GetItemCount()-1;
708 for (int col = 0; col <= maxcol; col++)
710 // find the longest width of all items
711 int count = m_ProgList.GetItemCount();
712 HDITEM hdi = {0};
713 hdi.mask = HDI_TEXT;
714 hdi.pszText = textbuf;
715 hdi.cchTextMax = sizeof(textbuf);
716 ((CHeaderCtrl*)(m_ProgList.GetDlgItem(0)))->GetItem(col, &hdi);
717 int cx = m_ProgList.GetStringWidth(hdi.pszText)+20; // 20 pixels for col separator and margin
719 for (int index = 0; index<count; ++index)
721 // get the width of the string and add 12 pixels for the column separator and margins
722 int linewidth = cx;
723 switch (col)
725 case 0:
726 linewidth = m_ProgList.GetStringWidth(m_arData[index]->sActionColumnText) + 12;
727 break;
728 case 1:
729 linewidth = m_ProgList.GetStringWidth(m_arData[index]->sPathColumnText) + 12;
730 break;
731 case 2:
732 linewidth = m_ProgList.GetStringWidth(m_arData[index]->mime_type) + 12;
733 break;
735 if (cx < linewidth)
736 cx = linewidth;
738 m_ProgList.SetColumnWidth(col, cx);
741 m_ProgList.SetRedraw(TRUE);
744 BOOL CGitProgressDlg::OnInitDialog()
746 __super::OnInitDialog();
748 m_ProgList.SetExtendedStyle (LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER);
750 m_ProgList.DeleteAllItems();
751 int c = ((CHeaderCtrl*)(m_ProgList.GetDlgItem(0)))->GetItemCount()-1;
752 while (c>=0)
753 m_ProgList.DeleteColumn(c--);
754 CString temp;
755 temp.LoadString(IDS_PROGRS_ACTION);
756 m_ProgList.InsertColumn(0, temp);
757 temp.LoadString(IDS_PROGRS_PATH);
758 m_ProgList.InsertColumn(1, temp);
759 temp.LoadString(IDS_PROGRS_MIMETYPE);
760 m_ProgList.InsertColumn(2, temp);
762 m_pThread = AfxBeginThread(ProgressThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
763 if (m_pThread==NULL)
765 ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
767 else
769 m_pThread->m_bAutoDelete = FALSE;
770 m_pThread->ResumeThread();
773 UpdateData(FALSE);
775 // Call this early so that the column headings aren't hidden before any
776 // text gets added.
777 ResizeColumns();
779 SetTimer(VISIBLETIMER, 300, NULL);
781 AddAnchor(IDC_SVNPROGRESS, TOP_LEFT, BOTTOM_RIGHT);
782 AddAnchor(IDC_PROGRESSLABEL, BOTTOM_LEFT, BOTTOM_CENTER);
783 AddAnchor(IDC_PROGRESSBAR, BOTTOM_CENTER, BOTTOM_RIGHT);
784 AddAnchor(IDC_INFOTEXT, BOTTOM_LEFT, BOTTOM_RIGHT);
785 AddAnchor(IDC_NONINTERACTIVE, BOTTOM_LEFT, BOTTOM_RIGHT);
786 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
787 AddAnchor(IDOK, BOTTOM_RIGHT);
788 AddAnchor(IDC_LOGBUTTON, BOTTOM_RIGHT);
789 //SetPromptParentWindow(this->m_hWnd);
790 if (hWndExplorer)
791 CenterWindow(CWnd::FromHandle(hWndExplorer));
792 EnableSaveRestore(_T("SVNProgressDlg"));
793 return TRUE;
796 bool CGitProgressDlg::SetBackgroundImage(UINT nID)
798 return CAppUtils::SetListCtrlBackgroundImage(m_ProgList.GetSafeHwnd(), nID);
801 #if 0
802 void CGitProgressDlg::ReportSVNError()
804 ReportError(GetLastErrorMessage());
806 #endif
808 void CGitProgressDlg::ReportError(const CString& sError)
810 CSoundUtils::PlayTGitError();
811 ReportString(sError, CString(MAKEINTRESOURCE(IDS_ERR_ERROR)), m_Colors.GetColor(CColors::Conflict));
812 m_bErrorsOccurred = true;
815 void CGitProgressDlg::ReportWarning(const CString& sWarning)
817 CSoundUtils::PlayTGitWarning();
818 ReportString(sWarning, CString(MAKEINTRESOURCE(IDS_WARN_WARNING)), m_Colors.GetColor(CColors::Conflict));
821 void CGitProgressDlg::ReportNotification(const CString& sNotification)
823 CSoundUtils::PlayTGitNotification();
824 ReportString(sNotification, CString(MAKEINTRESOURCE(IDS_WARN_NOTE)));
827 void CGitProgressDlg::ReportCmd(const CString& sCmd)
829 ReportString(sCmd, CString(MAKEINTRESOURCE(IDS_PROGRS_CMDINFO)), m_Colors.GetColor(CColors::Cmd));
832 void CGitProgressDlg::ReportString(CString sMessage, const CString& sMsgKind, COLORREF color)
834 // instead of showing a dialog box with the error message or notification,
835 // just insert the error text into the list control.
836 // that way the user isn't 'interrupted' by a dialog box popping up!
838 // the message may be split up into different lines
839 // so add a new entry for each line of the message
840 while (!sMessage.IsEmpty())
842 NotificationData * data = new NotificationData();
843 data->bAuxItem = true;
844 data->sActionColumnText = sMsgKind;
845 if (sMessage.Find('\n')>=0)
846 data->sPathColumnText = sMessage.Left(sMessage.Find('\n'));
847 else
848 data->sPathColumnText = sMessage;
849 data->sPathColumnText.Trim(_T("\n\r"));
850 data->color = color;
851 if (sMessage.Find('\n')>=0)
853 sMessage = sMessage.Mid(sMessage.Find('\n'));
854 sMessage.Trim(_T("\n\r"));
856 else
857 sMessage.Empty();
858 m_arData.push_back(data);
859 AddItemToList();
863 UINT CGitProgressDlg::ProgressThreadEntry(LPVOID pVoid)
865 return ((CGitProgressDlg*)pVoid)->ProgressThread();
868 UINT CGitProgressDlg::ProgressThread()
870 // The SetParams function should have loaded something for us
872 CString temp;
873 CString sWindowTitle;
874 bool localoperation = false;
875 bool bSuccess = false;
876 m_AlwaysConflicted = false;
878 DialogEnableWindow(IDOK, FALSE);
879 DialogEnableWindow(IDCANCEL, TRUE);
880 // SetAndClearProgressInfo(m_hWnd);
881 m_itemCount = m_itemCountTotal;
883 InterlockedExchange(&m_bThreadRunning, TRUE);
884 iFirstResized = 0;
885 bSecondResized = FALSE;
886 m_bFinishedItemAdded = false;
887 CTime startTime = CTime::GetCurrentTime();
888 switch (m_Command)
890 case GitProgress_Add:
891 bSuccess = CmdAdd(sWindowTitle, localoperation);
892 break;
893 case GitProgress_Copy:
894 bSuccess = CmdCopy(sWindowTitle, localoperation);
895 break;
896 case GitProgress_Export:
897 bSuccess = CmdExport(sWindowTitle, localoperation);
898 break;
899 case GitProgress_Rename:
900 bSuccess = CmdRename(sWindowTitle, localoperation);
901 break;
902 case GitProgress_Resolve:
903 bSuccess = CmdResolve(sWindowTitle, localoperation);
904 break;
905 case GitProgress_Revert:
906 bSuccess = CmdRevert(sWindowTitle, localoperation);
907 break;
908 case GitProgress_Switch:
909 bSuccess = CmdSwitch(sWindowTitle, localoperation);
910 break;
911 case GitProgress_SendMail:
912 bSuccess = CmdSendMail(sWindowTitle, localoperation);
913 break;
915 if (!bSuccess)
916 temp.LoadString(IDS_PROGRS_TITLEFAILED);
917 else
918 temp.LoadString(IDS_PROGRS_TITLEFIN);
919 sWindowTitle = sWindowTitle + _T(" ") + temp;
920 SetWindowText(sWindowTitle);
922 KillTimer(TRANSFERTIMER);
923 KillTimer(VISIBLETIMER);
925 DialogEnableWindow(IDCANCEL, FALSE);
926 DialogEnableWindow(IDOK, TRUE);
928 CString info = BuildInfoString();
929 if (!bSuccess)
930 info.LoadString(IDS_PROGRS_INFOFAILED);
931 SetDlgItemText(IDC_INFOTEXT, info);
932 ResizeColumns();
933 SendMessage(DM_SETDEFID, IDOK);
934 GetDlgItem(IDOK)->SetFocus();
936 CString sFinalInfo;
937 if (!m_sTotalBytesTransferred.IsEmpty())
939 CTimeSpan time = CTime::GetCurrentTime() - startTime;
940 temp.Format(IDS_PROGRS_TIME, (LONG)time.GetTotalMinutes(), (LONG)time.GetSeconds());
941 sFinalInfo.Format(IDS_PROGRS_FINALINFO, m_sTotalBytesTransferred, (LPCTSTR)temp);
942 SetDlgItemText(IDC_PROGRESSLABEL, sFinalInfo);
944 else
945 GetDlgItem(IDC_PROGRESSLABEL)->ShowWindow(SW_HIDE);
947 GetDlgItem(IDC_PROGRESSBAR)->ShowWindow(SW_HIDE);
949 if (!m_bFinishedItemAdded)
951 // there's no "finished: xxx" line at the end. We add one here to make
952 // sure the user sees that the command is actually finished.
953 NotificationData * data = new NotificationData();
954 data->bAuxItem = true;
955 data->sActionColumnText.LoadString(IDS_PROGRS_FINISHED);
956 m_arData.push_back(data);
957 AddItemToList();
960 int count = m_ProgList.GetItemCount();
961 if ((count > 0)&&(m_bLastVisible))
962 m_ProgList.EnsureVisible(count-1, FALSE);
964 CLogFile logfile;
965 if (logfile.Open())
967 logfile.AddTimeLine();
968 for (size_t i=0; i<m_arData.size(); i++)
970 NotificationData * data = m_arData[i];
971 temp.Format(_T("%-20s : %s"), (LPCTSTR)data->sActionColumnText, (LPCTSTR)data->sPathColumnText);
972 logfile.AddLine(temp);
974 if (!sFinalInfo.IsEmpty())
975 logfile.AddLine(sFinalInfo);
976 logfile.Close();
979 m_bCancelled = TRUE;
980 InterlockedExchange(&m_bThreadRunning, FALSE);
981 RefreshCursor();
983 DWORD dwAutoClose = CRegStdDWORD(_T("Software\\TortoiseGit\\AutoClose"));
984 if (m_options & ProgOptDryRun)
985 dwAutoClose = 0; // dry run means progress dialog doesn't auto close at all
986 if (!m_bLastVisible)
987 dwAutoClose = 0;
988 if (m_dwCloseOnEnd != (DWORD)-1)
989 dwAutoClose = m_dwCloseOnEnd; // command line value has priority over setting value
990 if ((dwAutoClose == CLOSE_NOERRORS)&&(!m_bErrorsOccurred))
991 PostMessage(WM_COMMAND, 1, (LPARAM)GetDlgItem(IDOK)->m_hWnd);
992 if ((dwAutoClose == CLOSE_NOCONFLICTS)&&(!m_bErrorsOccurred)&&(m_nConflicts==0))
993 PostMessage(WM_COMMAND, 1, (LPARAM)GetDlgItem(IDOK)->m_hWnd);
994 if ((dwAutoClose == CLOSE_NOMERGES)&&(!m_bErrorsOccurred)&&(m_nConflicts==0)&&(!m_bMergesAddsDeletesOccurred))
995 PostMessage(WM_COMMAND, 1, (LPARAM)GetDlgItem(IDOK)->m_hWnd);
996 if ((dwAutoClose == CLOSE_LOCAL)&&(!m_bErrorsOccurred)&&(m_nConflicts==0)&&(localoperation))
997 PostMessage(WM_COMMAND, 1, (LPARAM)GetDlgItem(IDOK)->m_hWnd);
999 //Don't do anything here which might cause messages to be sent to the window
1000 //The window thread is probably now blocked in OnOK if we've done an auto close
1001 return 0;
1004 void CGitProgressDlg::OnBnClickedLogbutton()
1006 switch(this->m_Command)
1008 case GitProgress_Add:
1009 case GitProgress_Resolve:
1011 CString cmd;
1012 cmd = CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe");
1013 cmd += _T(" /command:commit");
1015 cmd += _T(" /path:\"")+g_Git.m_CurrentDir+_T("\"");
1017 CAppUtils::LaunchApplication(cmd,NULL,false);
1018 this->EndDialog(IDOK);
1019 break;
1022 #if 0
1023 if (m_targetPathList.GetCount() != 1)
1024 return;
1025 StringRevMap::iterator it = m_UpdateStartRevMap.begin();
1026 svn_revnum_t rev = -1;
1027 if (it != m_UpdateStartRevMap.end())
1029 rev = it->second;
1031 CLogDlg dlg;
1032 dlg.SetParams(m_targetPathList[0], m_RevisionEnd, m_RevisionEnd, rev, 0, TRUE);
1033 dlg.DoModal();
1034 #endif
1038 void CGitProgressDlg::OnClose()
1040 if (m_bCancelled)
1042 TerminateThread(m_pThread->m_hThread, (DWORD)-1);
1043 InterlockedExchange(&m_bThreadRunning, FALSE);
1045 else
1047 m_bCancelled = TRUE;
1048 return;
1050 DialogEnableWindow(IDCANCEL, TRUE);
1051 __super::OnClose();
1054 void CGitProgressDlg::OnOK()
1056 if ((m_bCancelled)&&(!m_bThreadRunning))
1058 // I have made this wait a sensible amount of time (10 seconds) for the thread to finish
1059 // You must be careful in the thread that after posting the WM_COMMAND/IDOK message, you
1060 // don't do any more operations on the window which might require message passing
1061 // If you try to send windows messages once we're waiting here, then the thread can't finished
1062 // because the Window's message loop is blocked at this wait
1063 WaitForSingleObject(m_pThread->m_hThread, 10000);
1064 __super::OnOK();
1066 m_bCancelled = TRUE;
1069 void CGitProgressDlg::OnCancel()
1071 if ((m_bCancelled)&&(!m_bThreadRunning))
1072 __super::OnCancel();
1073 m_bCancelled = TRUE;
1076 void CGitProgressDlg::OnLvnGetdispinfoSvnprogress(NMHDR *pNMHDR, LRESULT *pResult)
1078 NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
1080 if (pDispInfo)
1082 if (pDispInfo->item.mask & LVIF_TEXT)
1084 if (pDispInfo->item.iItem < (int)m_arData.size())
1086 const NotificationData * data = m_arData[pDispInfo->item.iItem];
1087 switch (pDispInfo->item.iSubItem)
1089 case 0:
1090 lstrcpyn(m_columnbuf, data->sActionColumnText, MAX_PATH);
1091 break;
1092 case 1:
1093 lstrcpyn(m_columnbuf, data->sPathColumnText, pDispInfo->item.cchTextMax);
1094 if (!data->bAuxItem)
1096 int cWidth = m_ProgList.GetColumnWidth(1);
1097 cWidth = max(12, cWidth-12);
1098 CDC * pDC = m_ProgList.GetDC();
1099 if (pDC != NULL)
1101 CFont * pFont = pDC->SelectObject(m_ProgList.GetFont());
1102 PathCompactPath(pDC->GetSafeHdc(), m_columnbuf, cWidth);
1103 pDC->SelectObject(pFont);
1104 ReleaseDC(pDC);
1107 break;
1108 case 2:
1109 lstrcpyn(m_columnbuf, data->mime_type, MAX_PATH);
1110 break;
1111 default:
1112 m_columnbuf[0] = 0;
1114 pDispInfo->item.pszText = m_columnbuf;
1118 *pResult = 0;
1121 void CGitProgressDlg::OnNMCustomdrawSvnprogress(NMHDR *pNMHDR, LRESULT *pResult)
1123 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
1125 // Take the default processing unless we set this to something else below.
1126 *pResult = CDRF_DODEFAULT;
1128 // First thing - check the draw stage. If it's the control's prepaint
1129 // stage, then tell Windows we want messages for every item.
1131 if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )
1133 *pResult = CDRF_NOTIFYITEMDRAW;
1135 else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )
1137 // This is the prepaint stage for an item. Here's where we set the
1138 // item's text color. Our return value will tell Windows to draw the
1139 // item itself, but it will use the new color we set here.
1141 // Tell Windows to paint the control itself.
1142 *pResult = CDRF_DODEFAULT;
1144 ASSERT(pLVCD->nmcd.dwItemSpec < m_arData.size());
1145 if(pLVCD->nmcd.dwItemSpec >= m_arData.size())
1147 return;
1149 const NotificationData * data = m_arData[pLVCD->nmcd.dwItemSpec];
1150 ASSERT(data != NULL);
1151 if (data == NULL)
1152 return;
1154 // Store the color back in the NMLVCUSTOMDRAW struct.
1155 pLVCD->clrText = data->color;
1159 void CGitProgressDlg::OnNMDblclkSvnprogress(NMHDR * /*pNMHDR*/, LRESULT * /*pResult*/)
1161 #if 0
1162 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1163 *pResult = 0;
1164 if (pNMLV->iItem < 0)
1165 return;
1166 if (m_options & ProgOptDryRun)
1167 return; //don't do anything in a dry-run.
1169 const NotificationData * data = m_arData[pNMLV->iItem];
1170 if (data == NULL)
1171 return;
1173 if (data->bConflictedActionItem)
1175 // We've double-clicked on a conflicted item - do a three-way merge on it
1176 SVNDiff::StartConflictEditor(data->path);
1178 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))
1180 // This is a modified file which has been merged on update. Diff it against base
1181 CTGitPath temporaryFile;
1182 SVNDiff diff(this, this->m_hWnd, true);
1183 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
1184 svn_revnum_t baseRev = 0;
1185 diff.DiffFileAgainstBase(data->path, baseRev);
1187 else if ((!data->bAuxItem)&&(data->path.Exists())&&(!data->path.IsDirectory()))
1189 bool bOpenWith = false;
1190 int ret = (int)ShellExecute(m_hWnd, NULL, data->path.GetWinPath(), NULL, NULL, SW_SHOWNORMAL);
1191 if (ret <= HINSTANCE_ERROR)
1192 bOpenWith = true;
1193 if (bOpenWith)
1195 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
1196 cmd += data->path.GetWinPathString() + _T(" ");
1197 CAppUtils::LaunchApplication(cmd, NULL, false);
1200 #endif
1203 void CGitProgressDlg::OnHdnItemclickSvnprogress(NMHDR *pNMHDR, LRESULT *pResult)
1205 LPNMHEADER phdr = reinterpret_cast<LPNMHEADER>(pNMHDR);
1206 if (m_bThreadRunning)
1207 return;
1208 if (m_nSortedColumn == phdr->iItem)
1209 m_bAscending = !m_bAscending;
1210 else
1211 m_bAscending = TRUE;
1212 m_nSortedColumn = phdr->iItem;
1213 Sort();
1215 CString temp;
1216 m_ProgList.SetRedraw(FALSE);
1217 m_ProgList.DeleteAllItems();
1218 m_ProgList.SetItemCountEx (static_cast<int>(m_arData.size()));
1220 m_ProgList.SetRedraw(TRUE);
1222 *pResult = 0;
1225 bool CGitProgressDlg::NotificationDataIsAux(const NotificationData* pData)
1227 return pData->bAuxItem;
1230 LRESULT CGitProgressDlg::OnGitProgress(WPARAM /*wParam*/, LPARAM /*lParam*/)
1232 #if 0
1233 SVNProgress * pProgressData = (SVNProgress *)lParam;
1234 CProgressCtrl * progControl = (CProgressCtrl *)GetDlgItem(IDC_PROGRESSBAR);
1235 if ((pProgressData->total > 1000)&&(!progControl->IsWindowVisible()))
1237 progControl->ShowWindow(SW_SHOW);
1239 if (((pProgressData->total < 0)&&(pProgressData->progress > 1000)&&(progControl->IsWindowVisible()))&&(m_itemCountTotal<0))
1241 progControl->ShowWindow(SW_HIDE);
1243 if (!GetDlgItem(IDC_PROGRESSLABEL)->IsWindowVisible())
1244 GetDlgItem(IDC_PROGRESSLABEL)->ShowWindow(SW_SHOW);
1245 SetTimer(TRANSFERTIMER, 2000, NULL);
1246 if ((pProgressData->total > 0)&&(pProgressData->progress > 1000))
1248 progControl->SetPos((int)pProgressData->progress);
1249 progControl->SetRange32(0, (int)pProgressData->total);
1251 CString progText;
1252 if (pProgressData->overall_total < 1024)
1253 m_sTotalBytesTransferred.Format(IDS_SVN_PROGRESS_TOTALBYTESTRANSFERRED, pProgressData->overall_total);
1254 else if (pProgressData->overall_total < 1200000)
1255 m_sTotalBytesTransferred.Format(IDS_SVN_PROGRESS_TOTALTRANSFERRED, pProgressData->overall_total / 1024);
1256 else
1257 m_sTotalBytesTransferred.Format(IDS_SVN_PROGRESS_TOTALMBTRANSFERRED, (double)((double)pProgressData->overall_total / 1024000.0));
1258 progText.Format(IDS_SVN_PROGRESS_TOTALANDSPEED, (LPCTSTR)m_sTotalBytesTransferred, (LPCTSTR)pProgressData->SpeedString);
1259 SetDlgItemText(IDC_PROGRESSLABEL, progText);
1260 #endif
1261 return 0;
1264 void CGitProgressDlg::OnTimer(UINT_PTR nIDEvent)
1266 if (nIDEvent == TRANSFERTIMER)
1268 CString progText;
1269 CString progSpeed;
1270 progSpeed.Format(IDS_SVN_PROGRESS_BYTES_SEC, 0);
1271 progText.Format(IDS_SVN_PROGRESS_TOTALANDSPEED, (LPCTSTR)m_sTotalBytesTransferred, (LPCTSTR)progSpeed);
1272 SetDlgItemText(IDC_PROGRESSLABEL, progText);
1273 KillTimer(TRANSFERTIMER);
1275 if (nIDEvent == VISIBLETIMER)
1277 if (nEnsureVisibleCount)
1278 m_ProgList.EnsureVisible(m_ProgList.GetItemCount()-1, false);
1279 nEnsureVisibleCount = 0;
1283 void CGitProgressDlg::Sort()
1285 if(m_arData.size() < 2)
1287 return;
1290 // We need to sort the blocks which lie between the auxiliary entries
1291 // This is so that any aux data stays where it was
1292 NotificationDataVect::iterator actionBlockBegin;
1293 NotificationDataVect::iterator actionBlockEnd = m_arData.begin(); // We start searching from here
1295 for(;;)
1297 // Search to the start of the non-aux entry in the next block
1298 actionBlockBegin = std::find_if(actionBlockEnd, m_arData.end(), std::not1(std::ptr_fun(&CGitProgressDlg::NotificationDataIsAux)));
1299 if(actionBlockBegin == m_arData.end())
1301 // There are no more actions
1302 break;
1304 // Now search to find the end of the block
1305 actionBlockEnd = std::find_if(actionBlockBegin+1, m_arData.end(), std::ptr_fun(&CGitProgressDlg::NotificationDataIsAux));
1306 // Now sort the block
1307 std::sort(actionBlockBegin, actionBlockEnd, &CGitProgressDlg::SortCompare);
1311 bool CGitProgressDlg::SortCompare(const NotificationData * pData1, const NotificationData * pData2)
1313 int result = 0;
1314 switch (m_nSortedColumn)
1316 case 0: //action column
1317 result = pData1->sActionColumnText.Compare(pData2->sActionColumnText);
1318 break;
1319 case 1: //path column
1320 // Compare happens after switch()
1321 break;
1322 case 2: //mime-type column
1323 result = pData1->mime_type.Compare(pData2->mime_type);
1324 break;
1325 default:
1326 break;
1329 // Sort by path if everything else is equal
1330 if (result == 0)
1332 result = CTGitPath::Compare(pData1->path, pData2->path);
1335 if (!m_bAscending)
1336 result = -result;
1337 return result < 0;
1340 BOOL CGitProgressDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
1342 if (!GetDlgItem(IDOK)->IsWindowEnabled())
1344 // only show the wait cursor over the list control
1345 if ((pWnd)&&(pWnd == GetDlgItem(IDC_SVNPROGRESS)))
1347 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT));
1348 SetCursor(hCur);
1349 return TRUE;
1352 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));
1353 SetCursor(hCur);
1354 return CResizableStandAloneDialog::OnSetCursor(pWnd, nHitTest, message);
1357 BOOL CGitProgressDlg::PreTranslateMessage(MSG* pMsg)
1359 if (pMsg->message == WM_KEYDOWN)
1361 if (pMsg->wParam == VK_ESCAPE)
1363 // pressing the ESC key should close the dialog. But since we disabled the escape
1364 // key (so the user doesn't get the idea that he could simply undo an e.g. update)
1365 // this won't work.
1366 // So if the user presses the ESC key, change it to VK_RETURN so the dialog gets
1367 // the impression that the OK button was pressed.
1368 if ((!m_bThreadRunning)&&(!GetDlgItem(IDCANCEL)->IsWindowEnabled())
1369 &&(GetDlgItem(IDOK)->IsWindowEnabled())&&(GetDlgItem(IDOK)->IsWindowVisible()))
1371 // since we convert ESC to RETURN, make sure the OK button has the focus.
1372 GetDlgItem(IDOK)->SetFocus();
1373 pMsg->wParam = VK_RETURN;
1376 if (pMsg->wParam == 'A')
1378 if (GetKeyState(VK_CONTROL)&0x8000)
1380 // Ctrl-A -> select all
1381 m_ProgList.SetSelectionMark(0);
1382 for (int i=0; i<m_ProgList.GetItemCount(); ++i)
1384 m_ProgList.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
1388 if ((pMsg->wParam == 'C')||(pMsg->wParam == VK_INSERT))
1390 int selIndex = m_ProgList.GetSelectionMark();
1391 if (selIndex >= 0)
1393 if (GetKeyState(VK_CONTROL)&0x8000)
1395 //Ctrl-C -> copy to clipboard
1396 CString sClipdata;
1397 POSITION pos = m_ProgList.GetFirstSelectedItemPosition();
1398 if (pos != NULL)
1400 while (pos)
1402 int nItem = m_ProgList.GetNextSelectedItem(pos);
1403 CString sAction = m_ProgList.GetItemText(nItem, 0);
1404 CString sPath = m_ProgList.GetItemText(nItem, 1);
1405 CString sMime = m_ProgList.GetItemText(nItem, 2);
1406 CString sLogCopyText;
1407 sLogCopyText.Format(_T("%s: %s %s\r\n"),
1408 (LPCTSTR)sAction, (LPCTSTR)sPath, (LPCTSTR)sMime);
1409 sClipdata += sLogCopyText;
1411 CStringUtils::WriteAsciiStringToClipboard(sClipdata);
1416 } // if (pMsg->message == WM_KEYDOWN)
1417 return __super::PreTranslateMessage(pMsg);
1420 void CGitProgressDlg::OnContextMenu(CWnd* /*pWnd*/, CPoint /*point*/)
1422 #if 0
1423 if (m_options & ProgOptDryRun)
1424 return; // don't do anything in a dry-run.
1426 if (pWnd == &m_ProgList)
1428 int selIndex = m_ProgList.GetSelectionMark();
1429 if ((point.x == -1) && (point.y == -1))
1431 // Menu was invoked from the keyboard rather than by right-clicking
1432 CRect rect;
1433 m_ProgList.GetItemRect(selIndex, &rect, LVIR_LABEL);
1434 m_ProgList.ClientToScreen(&rect);
1435 point = rect.CenterPoint();
1438 if ((selIndex >= 0)&&(!m_bThreadRunning))
1440 // entry is selected, thread has finished with updating so show the popup menu
1441 CIconMenu popup;
1442 if (popup.CreatePopupMenu())
1444 bool bAdded = false;
1445 NotificationData * data = m_arData[selIndex];
1446 if ((data)&&(!data->path.IsDirectory()))
1448 if (data->action == svn_wc_notify_update_update || data->action == svn_wc_notify_resolved)
1450 if (m_ProgList.GetSelectedCount() == 1)
1452 popup.AppendMenuIcon(ID_COMPARE, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1453 bAdded = true;
1456 if (data->bConflictedActionItem)
1458 if (m_ProgList.GetSelectedCount() == 1)
1460 popup.AppendMenuIcon(ID_EDITCONFLICT, IDS_MENUCONFLICT,IDI_CONFLICT);
1461 popup.SetDefaultItem(ID_EDITCONFLICT, FALSE);
1462 popup.AppendMenuIcon(ID_CONFLICTRESOLVE, IDS_SVNPROGRESS_MENUMARKASRESOLVED,IDI_RESOLVE);
1464 popup.AppendMenuIcon(ID_CONFLICTUSETHEIRS, IDS_SVNPROGRESS_MENUUSETHEIRS,IDI_RESOLVE);
1465 popup.AppendMenuIcon(ID_CONFLICTUSEMINE, IDS_SVNPROGRESS_MENUUSEMINE,IDI_RESOLVE);
1467 else if ((data->content_state == svn_wc_notify_state_merged)||(GitProgress_Merge == m_Command)||(data->action == svn_wc_notify_resolved))
1468 popup.SetDefaultItem(ID_COMPARE, FALSE);
1470 if (m_ProgList.GetSelectedCount() == 1)
1472 if ((data->action == svn_wc_notify_add)||
1473 (data->action == svn_wc_notify_update_add)||
1474 (data->action == svn_wc_notify_commit_added)||
1475 (data->action == svn_wc_notify_commit_modified)||
1476 (data->action == svn_wc_notify_restore)||
1477 (data->action == svn_wc_notify_revert)||
1478 (data->action == svn_wc_notify_resolved)||
1479 (data->action == svn_wc_notify_commit_replaced)||
1480 (data->action == svn_wc_notify_commit_modified)||
1481 (data->action == svn_wc_notify_commit_postfix_txdelta)||
1482 (data->action == svn_wc_notify_update_update))
1484 popup.AppendMenuIcon(ID_LOG, IDS_MENULOG,IDI_LOG);
1485 if (data->action == svn_wc_notify_update_update)
1486 popup.AppendMenu(MF_SEPARATOR, NULL);
1487 popup.AppendMenuIcon(ID_OPEN, IDS_LOG_POPUP_OPEN, IDI_OPEN);
1488 popup.AppendMenuIcon(ID_OPENWITH, IDS_LOG_POPUP_OPENWITH, IDI_OPEN);
1489 bAdded = true;
1492 } // if ((data)&&(!data->path.IsDirectory()))
1493 if (m_ProgList.GetSelectedCount() == 1)
1495 if (data)
1497 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1498 if ((!sPath.IsEmpty())&&(!SVN::PathIsURL(CTGitPath(sPath))))
1500 CTGitPath path = CTGitPath(sPath);
1501 if (path.GetDirectory().Exists())
1503 popup.AppendMenuIcon(ID_EXPLORE, IDS_SVNPROGRESS_MENUOPENPARENT, IDI_EXPLORER);
1504 bAdded = true;
1509 if (m_ProgList.GetSelectedCount() > 0)
1511 if (bAdded)
1512 popup.AppendMenu(MF_SEPARATOR, NULL);
1513 popup.AppendMenuIcon(ID_COPY, IDS_LOG_POPUP_COPYTOCLIPBOARD,IDI_COPYCLIP);
1514 bAdded = true;
1516 if (bAdded)
1518 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
1519 DialogEnableWindow(IDOK, FALSE);
1520 this->SetPromptApp(&theApp);
1521 theApp.DoWaitCursor(1);
1522 bool bOpenWith = false;
1523 switch (cmd)
1525 case ID_COPY:
1527 CString sLines;
1528 POSITION pos = m_ProgList.GetFirstSelectedItemPosition();
1529 while (pos)
1531 int nItem = m_ProgList.GetNextSelectedItem(pos);
1532 NotificationData * data = m_arData[nItem];
1533 if (data)
1535 sLines += data->sPathColumnText;
1536 sLines += _T("\r\n");
1539 sLines.TrimRight();
1540 if (!sLines.IsEmpty())
1542 CStringUtils::WriteAsciiStringToClipboard(sLines, GetSafeHwnd());
1545 break;
1546 case ID_EXPLORE:
1548 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1550 CTGitPath path = CTGitPath(sPath);
1551 ShellExecute(m_hWnd, _T("explore"), path.GetDirectory().GetWinPath(), NULL, path.GetDirectory().GetWinPath(), SW_SHOW);
1553 break;
1554 case ID_COMPARE:
1556 svn_revnum_t rev = -1;
1557 StringRevMap::iterator it = m_UpdateStartRevMap.end();
1558 if (data->basepath.IsEmpty())
1559 it = m_UpdateStartRevMap.begin();
1560 else
1561 it = m_UpdateStartRevMap.find(data->basepath.GetSVNApiPath(pool));
1562 if (it != m_UpdateStartRevMap.end())
1563 rev = it->second;
1564 // if the file was merged during update, do a three way diff between OLD, MINE, THEIRS
1565 if (data->content_state == svn_wc_notify_state_merged)
1567 CTGitPath basefile = CTempFiles::Instance().GetTempFilePath(false, data->path, rev);
1568 CTGitPath newfile = CTempFiles::Instance().GetTempFilePath(false, data->path, SVNRev::REV_HEAD);
1569 SVN svn;
1570 if (!svn.Cat(data->path, SVNRev(SVNRev::REV_WC), rev, basefile))
1572 CMessageBox::Show(m_hWnd, svn.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1573 DialogEnableWindow(IDOK, TRUE);
1574 break;
1576 // If necessary, convert the line-endings on the file before diffing
1577 if ((DWORD)CRegDWORD(_T("Software\\TortoiseGit\\ConvertBase"), TRUE))
1579 CTGitPath temporaryFile = CTempFiles::Instance().GetTempFilePath(false, data->path, SVNRev::REV_BASE);
1580 if (!svn.Cat(data->path, SVNRev(SVNRev::REV_BASE), SVNRev(SVNRev::REV_BASE), temporaryFile))
1582 temporaryFile.Reset();
1583 break;
1585 else
1587 newfile = temporaryFile;
1591 SetFileAttributes(newfile.GetWinPath(), FILE_ATTRIBUTE_READONLY);
1592 SetFileAttributes(basefile.GetWinPath(), FILE_ATTRIBUTE_READONLY);
1593 CString revname, wcname, basename;
1594 revname.Format(_T("%s Revision %ld"), (LPCTSTR)data->path.GetUIFileOrDirectoryName(), rev);
1595 wcname.Format(IDS_DIFF_WCNAME, (LPCTSTR)data->path.GetUIFileOrDirectoryName());
1596 basename.Format(IDS_DIFF_BASENAME, (LPCTSTR)data->path.GetUIFileOrDirectoryName());
1597 CAppUtils::StartExtMerge(basefile, newfile, data->path, data->path, basename, revname, wcname, CString(), true);
1599 else
1601 CTGitPath tempfile = CTempFiles::Instance().GetTempFilePath(false, data->path, rev);
1602 SVN svn;
1603 if (!svn.Cat(data->path, SVNRev(SVNRev::REV_WC), rev, tempfile))
1605 CMessageBox::Show(m_hWnd, svn.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1606 DialogEnableWindow(IDOK, TRUE);
1607 break;
1609 else
1611 SetFileAttributes(tempfile.GetWinPath(), FILE_ATTRIBUTE_READONLY);
1612 CString revname, wcname;
1613 revname.Format(_T("%s Revision %ld"), (LPCTSTR)data->path.GetUIFileOrDirectoryName(), rev);
1614 wcname.Format(IDS_DIFF_WCNAME, (LPCTSTR)data->path.GetUIFileOrDirectoryName());
1615 CAppUtils::StartExtDiff(
1616 tempfile, data->path, revname, wcname,
1617 CAppUtils::DiffFlags().AlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000)));
1621 break;
1622 case ID_EDITCONFLICT:
1624 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1625 SVNDiff::StartConflictEditor(CTGitPath(sPath));
1627 break;
1628 case ID_CONFLICTUSETHEIRS:
1629 case ID_CONFLICTUSEMINE:
1630 case ID_CONFLICTRESOLVE:
1632 svn_wc_conflict_choice_t result = svn_wc_conflict_choose_merged;
1633 switch (cmd)
1635 case ID_CONFLICTUSETHEIRS:
1636 result = svn_wc_conflict_choose_theirs_full;
1637 break;
1638 case ID_CONFLICTUSEMINE:
1639 result = svn_wc_conflict_choose_mine_full;
1640 break;
1641 case ID_CONFLICTRESOLVE:
1642 result = svn_wc_conflict_choose_merged;
1643 break;
1645 SVN svn;
1646 POSITION pos = m_ProgList.GetFirstSelectedItemPosition();
1647 CString sResolvedPaths;
1648 while (pos)
1650 int nItem = m_ProgList.GetNextSelectedItem(pos);
1651 NotificationData * data = m_arData[nItem];
1652 if (data)
1654 if (data->bConflictedActionItem)
1656 if (!svn.Resolve(data->path, result, FALSE))
1658 CMessageBox::Show(m_hWnd, svn.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1659 DialogEnableWindow(IDOK, TRUE);
1660 break;
1662 else
1664 data->color = ::GetSysColor(COLOR_WINDOWTEXT);
1665 data->action = svn_wc_notify_resolved;
1666 data->sActionColumnText.LoadString(IDS_SVNACTION_RESOLVE);
1667 data->bConflictedActionItem = false;
1668 m_nConflicts--;
1670 if (m_nConflicts==0)
1672 // When the last conflict is resolved we remove
1673 // the warning which we assume is in the last line.
1674 int nIndex = m_ProgList.GetItemCount()-1;
1675 VERIFY(m_ProgList.DeleteItem(nIndex));
1677 delete m_arData[nIndex];
1678 m_arData.pop_back();
1680 sResolvedPaths += data->path.GetWinPathString() + _T("\n");
1685 m_ProgList.Invalidate();
1686 CString info = BuildInfoString();
1687 SetDlgItemText(IDC_INFOTEXT, info);
1689 if (!sResolvedPaths.IsEmpty())
1691 CString msg;
1692 msg.Format(IDS_SVNPROGRESS_RESOLVED, (LPCTSTR)sResolvedPaths);
1693 CMessageBox::Show(m_hWnd, msg, _T("TortoiseGit"), MB_OK | MB_ICONINFORMATION);
1696 break;
1697 case ID_LOG:
1699 CRegDWORD reg = CRegDWORD(_T("Software\\TortoiseGit\\NumberOfLogs"), 100);
1700 int limit = (int)(DWORD)reg;
1701 svn_revnum_t rev = m_RevisionEnd;
1702 if (!data->basepath.IsEmpty())
1704 StringRevMap::iterator it = m_FinishedRevMap.find(data->basepath.GetSVNApiPath(pool));
1705 if (it != m_FinishedRevMap.end())
1706 rev = it->second;
1708 CLogDlg dlg;
1709 // fetch the log from HEAD, not the revision we updated to:
1710 // the path might be inside an external folder which has its own
1711 // revisions.
1712 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1713 dlg.SetParams(CTGitPath(sPath), SVNRev(), SVNRev::REV_HEAD, 1, limit, TRUE);
1714 dlg.DoModal();
1716 break;
1717 case ID_OPENWITH:
1718 bOpenWith = true;
1719 case ID_OPEN:
1721 int ret = 0;
1722 CString sWinPath = GetPathFromColumnText(data->sPathColumnText);
1723 if (!bOpenWith)
1724 ret = (int)ShellExecute(this->m_hWnd, NULL, (LPCTSTR)sWinPath, NULL, NULL, SW_SHOWNORMAL);
1725 if ((ret <= HINSTANCE_ERROR)||bOpenWith)
1727 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
1728 cmd += sWinPath + _T(" ");
1729 CAppUtils::LaunchApplication(cmd, NULL, false);
1733 DialogEnableWindow(IDOK, TRUE);
1734 theApp.DoWaitCursor(-1);
1735 } // if (bAdded)
1739 #endif
1742 void CGitProgressDlg::OnEnSetfocusInfotext()
1744 CString sTemp;
1745 GetDlgItemText(IDC_INFOTEXT, sTemp);
1746 if (sTemp.IsEmpty())
1747 GetDlgItem(IDC_INFOTEXT)->HideCaret();
1750 void CGitProgressDlg::OnLvnBegindragSvnprogress(NMHDR* , LRESULT *pResult)
1752 //LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1753 #if 0
1754 int selIndex = m_ProgList.GetSelectionMark();
1755 if (selIndex < 0)
1756 return;
1758 CDropFiles dropFiles; // class for creating DROPFILES struct
1760 int index;
1761 POSITION pos = m_ProgList.GetFirstSelectedItemPosition();
1762 while ( (index = m_ProgList.GetNextSelectedItem(pos)) >= 0 )
1764 NotificationData * data = m_arData[index];
1766 if ( data->kind==svn_node_file || data->kind==svn_node_dir )
1768 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1770 dropFiles.AddFile( sPath );
1774 if ( dropFiles.GetCount()>0 )
1776 dropFiles.CreateStructure();
1778 #endif
1779 *pResult = 0;
1782 void CGitProgressDlg::OnSize(UINT nType, int cx, int cy)
1784 CResizableStandAloneDialog::OnSize(nType, cx, cy);
1785 if ((nType == SIZE_RESTORED)&&(m_bLastVisible))
1787 if(!m_ProgList.m_hWnd)
1788 return;
1790 int count = m_ProgList.GetItemCount();
1791 if (count > 0)
1792 m_ProgList.EnsureVisible(count-1, false);
1796 //////////////////////////////////////////////////////////////////////////
1797 /// commands
1798 //////////////////////////////////////////////////////////////////////////
1799 bool CGitProgressDlg::CmdAdd(CString& sWindowTitle, bool& localoperation)
1801 localoperation = true;
1802 sWindowTitle.LoadString(IDS_PROGRS_TITLE_ADD);
1803 CAppUtils::SetWindowTitle(m_hWnd, m_targetPathList.GetCommonRoot().GetUIPathString(), sWindowTitle);
1804 SetBackgroundImage(IDI_ADD_BKG);
1805 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_ADD)));
1807 for(int i=0;i<m_targetPathList.GetCount();i++)
1809 CString cmd,out;
1810 cmd.Format(_T("git.exe add -f -- \"%s\""),m_targetPathList[i].GetGitPathString());
1811 if(g_Git.Run(cmd,&out,CP_ACP))
1813 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
1814 m_bErrorsOccurred=true;
1815 return false;
1817 Notify(m_targetPathList[i],git_wc_notify_add);
1819 #if 0
1820 if (!Add(m_targetPathList, &m_ProjectProperties, svn_depth_empty, FALSE, TRUE, TRUE))
1822 ReportSVNError();
1823 return false;
1825 #endif
1826 //CShellUpdater::Instance().AddPathsForUpdate(m_targetPathList);
1827 m_bErrorsOccurred=false;
1829 this->GetDlgItem(IDC_LOGBUTTON)->SetWindowText(_T("Commit ..."));
1830 this->GetDlgItem(IDC_LOGBUTTON)->ShowWindow(SW_SHOW);
1831 return true;
1834 bool CGitProgressDlg::CmdCopy(CString& /*sWindowTitle*/, bool& /*localoperation*/)
1836 #if 0
1837 ASSERT(m_targetPathList.GetCount() == 1);
1838 sWindowTitle.LoadString(IDS_PROGRS_TITLE_COPY);
1839 SetWindowText(sWindowTitle); // needs to be updated, see TSVN rev. 21375
1840 SetBackgroundImage(IDI_COPY_BKG);
1842 CString sCmdInfo;
1843 sCmdInfo.Format(IDS_PROGRS_CMD_COPY,
1844 m_targetPathList[0].IsUrl() ? (LPCTSTR)m_targetPathList[0].GetSVNPathString() : m_targetPathList[0].GetWinPath(),
1845 (LPCTSTR)m_url.GetSVNPathString(), (LPCTSTR)m_Revision.ToString());
1846 ReportCmd(sCmdInfo);
1848 if (!Copy(m_targetPathList, m_url, m_Revision, m_pegRev, m_sMessage))
1850 ReportSVNError();
1851 return false;
1853 if (m_options & ProgOptSwitchAfterCopy)
1855 sCmdInfo.Format(IDS_PROGRS_CMD_SWITCH,
1856 m_targetPathList[0].GetWinPath(),
1857 (LPCTSTR)m_url.GetSVNPathString(), (LPCTSTR)m_Revision.ToString());
1858 ReportCmd(sCmdInfo);
1859 if (!Switch(m_targetPathList[0], m_url, SVNRev::REV_HEAD, SVNRev::REV_HEAD, m_depth, TRUE, m_options & ProgOptIgnoreExternals))
1861 if (!Switch(m_targetPathList[0], m_url, SVNRev::REV_HEAD, m_Revision, m_depth, TRUE, m_options & ProgOptIgnoreExternals))
1863 ReportSVNError();
1864 return false;
1868 else
1870 if (SVN::PathIsURL(m_url))
1872 CString sMsg(MAKEINTRESOURCE(IDS_PROGRS_COPY_WARNING));
1873 ReportNotification(sMsg);
1876 #endif
1877 return true;
1880 bool CGitProgressDlg::CmdExport(CString& /*sWindowTitle*/, bool& /*localoperation*/)
1882 #if 0
1883 ASSERT(m_targetPathList.GetCount() == 1);
1884 sWindowTitle.LoadString(IDS_PROGRS_TITLE_EXPORT);
1885 sWindowTitle = m_url.GetUIFileOrDirectoryName()+_T(" - ")+sWindowTitle;
1886 SetWindowText(sWindowTitle); // needs to be updated, see TSVN rev. 21375
1887 SetBackgroundImage(IDI_EXPORT_BKG);
1888 CString eol;
1889 if (m_options & ProgOptEolCRLF)
1890 eol = _T("CRLF");
1891 if (m_options & ProgOptEolLF)
1892 eol = _T("LF");
1893 if (m_options & ProgOptEolCR)
1894 eol = _T("CR");
1895 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_EXPORT)));
1896 if (!Export(m_url, m_targetPathList[0], m_Revision, m_Revision, TRUE, m_options & ProgOptIgnoreExternals, m_depth, NULL, FALSE, eol))
1898 ReportSVNError();
1899 return false;
1901 #endif
1902 return true;
1905 bool CGitProgressDlg::CmdRename(CString& /*sWindowTitle*/, bool& /*localoperation*/)
1907 #if 0
1908 ASSERT(m_targetPathList.GetCount() == 1);
1909 if ((!m_targetPathList[0].IsUrl())&&(!m_url.IsUrl()))
1910 localoperation = true;
1911 sWindowTitle.LoadString(IDS_PROGRS_TITLE_RENAME);
1912 SetWindowText(sWindowTitle); // needs to be updated, see TSVN rev. 21375
1913 SetBackgroundImage(IDI_RENAME_BKG);
1914 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RENAME)));
1915 if (!Move(m_targetPathList, m_url, m_Revision, m_sMessage))
1917 ReportSVNError();
1918 return false;
1920 #endif
1921 return true;
1924 bool CGitProgressDlg::CmdResolve(CString& sWindowTitle, bool& localoperation)
1927 localoperation = true;
1928 ASSERT(m_targetPathList.GetCount() == 1);
1929 sWindowTitle.LoadString(IDS_PROGRS_TITLE_RESOLVE);
1930 CAppUtils::SetWindowTitle(m_hWnd, m_targetPathList.GetCommonRoot().GetUIPathString(), sWindowTitle);
1931 SetBackgroundImage(IDI_RESOLVE_BKG);
1932 // check if the file may still have conflict markers in it.
1933 //BOOL bMarkers = FALSE;
1935 for(int i=0;i<m_targetPathList.GetCount();i++)
1937 CString cmd,out,tempmergefile;
1938 cmd.Format(_T("git.exe add -f -- \"%s\""),m_targetPathList[i].GetGitPathString());
1939 if(g_Git.Run(cmd,&out,CP_ACP))
1941 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
1942 m_bErrorsOccurred=true;
1943 return false;
1946 CAppUtils::RemoveTempMergeFile((CTGitPath &)m_targetPathList[i]);
1948 Notify(m_targetPathList[i],git_wc_notify_resolved);
1950 #if 0
1951 if ((m_options & ProgOptSkipConflictCheck) == 0)
1955 for (INT_PTR fileindex=0; (fileindex<m_targetPathList.GetCount()) && (bMarkers==FALSE); ++fileindex)
1957 if (!m_targetPathList[fileindex].IsDirectory())
1959 CStdioFile file(m_targetPathList[fileindex].GetWinPath(), CFile::typeBinary | CFile::modeRead);
1960 CString strLine = _T("");
1961 while (file.ReadString(strLine))
1963 if (strLine.Find(_T("<<<<<<<"))==0)
1965 bMarkers = TRUE;
1966 break;
1969 file.Close();
1973 catch (CFileException* pE)
1975 TRACE(_T("CFileException in Resolve!\n"));
1976 TCHAR error[10000] = {0};
1977 pE->GetErrorMessage(error, 10000);
1978 ReportError(error);
1979 pE->Delete();
1980 return false;
1983 if (bMarkers)
1985 if (CMessageBox::Show(m_hWnd, IDS_PROGRS_REVERTMARKERS, IDS_APPNAME, MB_YESNO | MB_ICONQUESTION)==IDYES)
1987 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RESOLVE)));
1988 for (INT_PTR fileindex=0; fileindex<m_targetPathList.GetCount(); ++fileindex)
1989 Resolve(m_targetPathList[fileindex], svn_wc_conflict_choose_merged, true);
1992 else
1994 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RESOLVE)));
1995 for (INT_PTR fileindex=0; fileindex<m_targetPathList.GetCount(); ++fileindex)
1996 Resolve(m_targetPathList[fileindex], svn_wc_conflict_choose_merged, true);
1998 #endif
1999 CShellUpdater::Instance().AddPathsForUpdate(m_targetPathList);
2001 this->GetDlgItem(IDC_LOGBUTTON)->SetWindowText(_T("Commit ..."));
2002 this->GetDlgItem(IDC_LOGBUTTON)->ShowWindow(SW_SHOW);
2004 return true;
2007 bool CGitProgressDlg::CmdRevert(CString& sWindowTitle, bool& localoperation)
2010 localoperation = true;
2011 sWindowTitle.LoadString(IDS_PROGRS_TITLE_REVERT);
2012 CAppUtils::SetWindowTitle(m_hWnd, m_targetPathList.GetCommonRoot().GetUIPathString(), sWindowTitle);
2013 SetBackgroundImage(IDI_REVERT_BKG);
2015 CTGitPathList delList;
2016 for(int i=0;i<m_selectedPaths.GetCount();i++)
2018 CTGitPath path;
2019 int action;
2020 path.SetFromWin(g_Git.m_CurrentDir+_T("\\")+m_selectedPaths[i].GetWinPath());
2021 action = m_selectedPaths[i].m_Action;
2022 /* rename file can't delete because it needs original file*/
2023 if((!(action & CTGitPath::LOGACTIONS_ADDED)) &&
2024 (!(action & CTGitPath::LOGACTIONS_REPLACED)))
2025 delList.AddPath(path);
2027 if (DWORD(CRegDWORD(_T("Software\\TortoiseGit\\RevertWithRecycleBin"), TRUE)))
2028 delList.DeleteAllFiles(true);
2030 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_REVERT)));
2031 for(int i=0;i<m_selectedPaths.GetCount();i++)
2033 if(g_Git.Revert(_T("HEAD"), (CTGitPath&)m_selectedPaths[i]))
2035 CMessageBox::Show(NULL,_T("Revert Fail"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
2036 m_bErrorsOccurred=true;
2037 return false;
2039 Notify(m_selectedPaths[i],git_wc_notify_revert);
2042 CShellUpdater::Instance().AddPathsForUpdate(m_selectedPaths);
2044 return true;
2047 bool CGitProgressDlg::CmdSwitch(CString& /*sWindowTitle*/, bool& /*localoperation*/)
2049 #if 0
2050 ASSERT(m_targetPathList.GetCount() == 1);
2051 SVNStatus st;
2052 sWindowTitle.LoadString(IDS_PROGRS_TITLE_SWITCH);
2053 SetWindowText(sWindowTitle); // needs to be updated, see TSVN rev. 21375
2054 SetBackgroundImage(IDI_SWITCH_BKG);
2055 LONG rev = 0;
2056 if (st.GetStatus(m_targetPathList[0]) != (-2))
2058 if (st.status->entry != NULL)
2060 rev = st.status->entry->revision;
2064 CString sCmdInfo;
2065 sCmdInfo.Format(IDS_PROGRS_CMD_SWITCH,
2066 m_targetPathList[0].GetWinPath(), (LPCTSTR)m_url.GetSVNPathString(),
2067 (LPCTSTR)m_Revision.ToString());
2068 ReportCmd(sCmdInfo);
2070 bool depthIsSticky = true;
2071 if (m_depth == svn_depth_unknown)
2072 depthIsSticky = false;
2073 if (!Switch(m_targetPathList[0], m_url, m_Revision, m_Revision, m_depth, depthIsSticky, m_options & ProgOptIgnoreExternals))
2075 ReportSVNError();
2076 return false;
2078 m_UpdateStartRevMap[m_targetPathList[0].GetSVNApiPath(pool)] = rev;
2079 if ((m_RevisionEnd >= 0)&&(rev >= 0)
2080 &&((LONG)m_RevisionEnd > (LONG)rev))
2082 GetDlgItem(IDC_LOGBUTTON)->ShowWindow(SW_SHOW);
2084 #endif
2085 return true;
2088 void CGitProgressDlg::OnBnClickedNoninteractive()
2090 LRESULT res = ::SendMessage(GetDlgItem(IDC_NONINTERACTIVE)->GetSafeHwnd(), BM_GETCHECK, 0, 0);
2091 m_AlwaysConflicted = (res == BST_CHECKED);
2092 CRegDWORD nonint = CRegDWORD(_T("Software\\TortoiseGit\\MergeNonInteractive"), FALSE);
2093 nonint = m_AlwaysConflicted;
2096 CString CGitProgressDlg::GetPathFromColumnText(const CString& sColumnText)
2098 CString sPath = CPathUtils::ParsePathInString(sColumnText);
2099 if (sPath.Find(':')<0)
2101 // the path is not absolute: add the common root of all paths to it
2102 sPath = m_targetPathList.GetCommonRoot().GetDirectory().GetWinPathString() + _T("\\") + CPathUtils::ParsePathInString(sColumnText);
2104 return sPath;
2107 bool CGitProgressDlg::CmdSendMail(CString& sWindowTitle, bool& /*localoperation*/)
2109 sWindowTitle.LoadString(IDS_PROGRS_TITLE_SENDMAIL);
2110 CAppUtils::SetWindowTitle(m_hWnd, m_targetPathList.GetCommonRoot().GetUIPathString(), sWindowTitle);
2111 //SetBackgroundImage(IDI_ADD_BKG);
2112 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_SENDMAIL)));
2113 bool ret=true;
2114 if(this->m_SendMailFlags&SENDMAIL_COMBINED)
2116 CString error;
2117 CTGitPath path;
2118 Notify(path,git_wc_notify_sendmail_start);
2119 CString err;
2120 int retry=0;
2121 while(retry <3)
2123 if(!!CPatch::SendPatchesCombined(m_targetPathList,m_SendMailTO,m_SendMailCC,m_SendMailSubject,!!(this->m_SendMailFlags&SENDMAIL_ATTACHMENT),!!(this->m_SendMailFlags&SENDMAIL_MAPI),&err))
2125 Notify(path,git_wc_notify_sendmail_error,ret,&err);
2126 ret = false;
2128 else
2130 break;
2133 retry++;
2134 if (retry < 3)
2135 Notify(path,git_wc_notify_sendmail_retry,ret,&err);
2136 Sleep(2000);
2137 if(m_bCancelled)
2139 CString str(_T("User Canceled"));
2140 Notify(path,git_wc_notify_sendmail_error,ret,&str);
2141 return false;
2144 if (ret)
2145 Notify(path,git_wc_notify_sendmail_done,ret);
2147 else
2149 for(int i=0;ret && i<m_targetPathList.GetCount();i++)
2151 CPatch patch;
2152 Notify(m_targetPathList[i],git_wc_notify_sendmail_start);
2154 int retry=0;
2155 while(retry<3)
2157 if(!!patch.Send((CString&)m_targetPathList[i].GetWinPathString(),this->m_SendMailTO,
2158 this->m_SendMailCC,!!(this->m_SendMailFlags&SENDMAIL_ATTACHMENT),!!(this->m_SendMailFlags&SENDMAIL_MAPI)))
2160 Notify(m_targetPathList[i],git_wc_notify_sendmail_error,ret,&patch.m_LastError);
2161 ret = false;
2164 else
2166 ret = true;
2167 break;
2169 retry++;
2170 if (retry < 3)
2171 Notify(m_targetPathList[i],git_wc_notify_sendmail_retry,ret,&patch.m_LastError);
2172 Sleep(2000);
2173 if(m_bCancelled)
2175 CString str(_T("User Canceled"));
2176 Notify(m_targetPathList[i],git_wc_notify_sendmail_error,ret,&str);
2177 return false;
2180 if (ret)
2181 Notify(m_targetPathList[i],git_wc_notify_sendmail_done,ret);
2184 return ret;