ignore closeonend for GitProgressDlg until we fully support it
[TortoiseGit.git] / src / TortoiseProc / GitProgressDlg.cpp
blob888c16a1d34c74bc3efc96878a8b19386c7a40b3
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 "git2.h"
47 static UINT WM_GITPROGRESS = RegisterWindowMessage(_T("TORTOISEGIT_GITPROGRESS_MSG"));
49 BOOL CGitProgressDlg::m_bAscending = FALSE;
50 int CGitProgressDlg::m_nSortedColumn = -1;
52 #define TRANSFERTIMER 100
53 #define VISIBLETIMER 101
55 enum GITProgressDlgContextMenuCommands
57 // needs to start with 1, since 0 is the return value if *nothing* is clicked on in the context menu
58 ID_COMPARE = 1,
59 ID_EDITCONFLICT,
60 ID_CONFLICTRESOLVE,
61 ID_CONFLICTUSETHEIRS,
62 ID_CONFLICTUSEMINE,
63 ID_LOG,
64 ID_OPEN,
65 ID_OPENWITH,
66 ID_EXPLORE,
67 ID_COPY
70 IMPLEMENT_DYNAMIC(CGitProgressDlg, CResizableStandAloneDialog)
71 CGitProgressDlg::CGitProgressDlg(CWnd* pParent /*=NULL*/)
72 : CResizableStandAloneDialog(CGitProgressDlg::IDD, pParent)
73 , m_bCancelled(FALSE)
74 , m_pThread(NULL)
75 #if 0
76 , m_Revision(_T("HEAD"))
77 //, m_RevisionEnd(0)
78 , m_bLockWarning(false)
79 , m_bLockExists(false)
80 , m_bThreadRunning(FALSE)
81 , m_nConflicts(0)
82 , m_bErrorsOccurred(FALSE)
83 , m_bMergesAddsDeletesOccurred(FALSE)
85 , m_options(ProgOptNone)
86 , m_dwCloseOnEnd((DWORD)-1)
87 , m_bFinishedItemAdded(false)
88 , m_bLastVisible(false)
89 // , m_depth(svn_depth_unknown)
90 , m_itemCount(-1)
91 , m_itemCountTotal(-1)
92 , m_AlwaysConflicted(false)
93 , m_BugTraqProvider(NULL)
94 , sIgnoredIncluded(MAKEINTRESOURCE(IDS_PROGRS_IGNOREDINCLUDED))
95 , sExtExcluded(MAKEINTRESOURCE(IDS_PROGRS_EXTERNALSEXCLUDED))
96 , sExtIncluded(MAKEINTRESOURCE(IDS_PROGRS_EXTERNALSINCLUDED))
97 , sIgnoreAncestry(MAKEINTRESOURCE(IDS_PROGRS_IGNOREANCESTRY))
98 , sRespectAncestry(MAKEINTRESOURCE(IDS_PROGRS_RESPECTANCESTRY))
99 , sDryRun(MAKEINTRESOURCE(IDS_PROGRS_DRYRUN))
100 , sRecordOnly(MAKEINTRESOURCE(IDS_MERGE_RECORDONLY))
101 #endif
105 CGitProgressDlg::~CGitProgressDlg()
107 for (size_t i=0; i<m_arData.size(); i++)
109 delete m_arData[i];
111 if(m_pThread != NULL)
113 delete m_pThread;
117 void CGitProgressDlg::DoDataExchange(CDataExchange* pDX)
119 CResizableStandAloneDialog::DoDataExchange(pDX);
120 DDX_Control(pDX, IDC_SVNPROGRESS, m_ProgList);
123 BEGIN_MESSAGE_MAP(CGitProgressDlg, CResizableStandAloneDialog)
124 ON_BN_CLICKED(IDC_LOGBUTTON, OnBnClickedLogbutton)
125 ON_NOTIFY(NM_CUSTOMDRAW, IDC_SVNPROGRESS, OnNMCustomdrawSvnprogress)
126 ON_WM_CLOSE()
127 ON_NOTIFY(NM_DBLCLK, IDC_SVNPROGRESS, OnNMDblclkSvnprogress)
128 ON_NOTIFY(HDN_ITEMCLICK, 0, OnHdnItemclickSvnprogress)
129 ON_WM_SETCURSOR()
130 ON_WM_CONTEXTMENU()
131 ON_REGISTERED_MESSAGE(WM_GITPROGRESS, OnGitProgress)
132 ON_WM_TIMER()
133 ON_EN_SETFOCUS(IDC_INFOTEXT, &CGitProgressDlg::OnEnSetfocusInfotext)
134 ON_NOTIFY(LVN_BEGINDRAG, IDC_SVNPROGRESS, &CGitProgressDlg::OnLvnBegindragSvnprogress)
135 ON_WM_SIZE()
136 ON_NOTIFY(LVN_GETDISPINFO, IDC_SVNPROGRESS, &CGitProgressDlg::OnLvnGetdispinfoSvnprogress)
137 ON_BN_CLICKED(IDC_NONINTERACTIVE, &CGitProgressDlg::OnBnClickedNoninteractive)
138 ON_MESSAGE(WM_SHOWCONFLICTRESOLVER, OnShowConflictResolver)
139 ON_REGISTERED_MESSAGE(WM_TASKBARBTNCREATED, OnTaskbarBtnCreated)
140 END_MESSAGE_MAP()
142 BOOL CGitProgressDlg::Cancel()
144 return m_bCancelled;
147 LRESULT CGitProgressDlg::OnShowConflictResolver(WPARAM /*wParam*/, LPARAM /*lParam*/)
149 #if 0
150 CConflictResolveDlg dlg(this);
151 const svn_wc_conflict_description_t *description = (svn_wc_conflict_description_t *)lParam;
152 if (description)
154 dlg.SetConflictDescription(description);
155 if (m_pTaskbarList)
157 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_PAUSED);
159 if (dlg.DoModal() == IDOK)
161 if (dlg.GetResult() == svn_wc_conflict_choose_postpone)
163 // if the result is conflicted and the dialog returned IDOK,
164 // that means we should not ask again in case of a conflict
165 m_AlwaysConflicted = true;
166 ::SendMessage(GetDlgItem(IDC_NONINTERACTIVE)->GetSafeHwnd(), BM_SETCHECK, BST_CHECKED, 0);
169 m_mergedfile = dlg.GetMergedFile();
170 m_bCancelled = dlg.IsCancelled();
171 if (m_pTaskbarList)
172 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_INDETERMINATE);
173 return dlg.GetResult();
176 return svn_wc_conflict_choose_postpone;
177 #endif
178 return 0;
180 #if 0
181 svn_wc_conflict_choice_t CGitProgressDlg::ConflictResolveCallback(const svn_wc_conflict_description_t *description, CString& mergedfile)
183 // we only bother the user when merging
184 if (((m_Command == GitProgress_Merge)||(m_Command == GitProgress_MergeAll)||(m_Command == GitProgress_MergeReintegrate))&&(!m_AlwaysConflicted)&&(description))
186 // we're in a worker thread here. That means we must not show a dialog from the thread
187 // but let the UI thread do it.
188 // To do that, we send a message to the UI thread and let it show the conflict resolver dialog.
189 LRESULT dlgResult = ::SendMessage(GetSafeHwnd(), WM_SHOWCONFLICTRESOLVER, 0, (LPARAM)description);
190 mergedfile = m_mergedfile;
191 return (svn_wc_conflict_choice_t)dlgResult;
194 return svn_wc_conflict_choose_postpone;
196 #endif
197 void CGitProgressDlg::AddItemToList()
199 int totalcount = m_ProgList.GetItemCount();
201 m_ProgList.SetItemCountEx(totalcount+1, LVSICF_NOSCROLL|LVSICF_NOINVALIDATEALL);
202 // make columns width fit
203 if (iFirstResized < 30)
205 // only resize the columns for the first 30 or so entries.
206 // after that, don't resize them anymore because that's an
207 // expensive function call and the columns will be sized
208 // close enough already.
209 ResizeColumns();
210 iFirstResized++;
213 // Make sure the item is *entirely* visible even if the horizontal
214 // scroll bar is visible.
215 int count = m_ProgList.GetCountPerPage();
216 if (totalcount <= (m_ProgList.GetTopIndex() + count + nEnsureVisibleCount + 2))
218 nEnsureVisibleCount++;
219 m_bLastVisible = true;
221 else
223 nEnsureVisibleCount = 0;
224 if (IsIconic() == 0)
225 m_bLastVisible = false;
230 BOOL CGitProgressDlg::Notify(const CTGitPath& path, git_wc_notify_action_t action,
231 int /*status*/ ,
232 CString *strErr
234 svn_node_kind_t kind, const CString& mime_type,
235 svn_wc_notify_state_t content_state,
236 svn_wc_notify_state_t prop_state, LONG rev,
237 const svn_lock_t * lock, svn_wc_notify_lock_state_t lock_state,
238 const CString& changelistname,
239 svn_merge_range_t * range,
240 svn_error_t * err, apr_pool_t * pool
243 bool bNoNotify = false;
244 bool bDoAddData = true;
245 NotificationData * data = new NotificationData();
246 data->path = path;
247 data->action = action;
248 data->sPathColumnText=path.GetGitPathString();
249 data->bAuxItem = false;
250 #if 0
251 data->kind = kind;
252 data->mime_type = mime_type;
253 data->content_state = content_state;
254 data->prop_state = prop_state;
255 data->rev = rev;
256 data->lock_state = lock_state;
257 data->changelistname = changelistname;
258 if ((lock)&&(lock->owner))
259 data->owner = CUnicodeUtils::GetUnicode(lock->owner);
260 data->sPathColumnText = path.GetUIPathString();
261 if (!m_basePath.IsEmpty())
262 data->basepath = m_basePath;
263 if (range)
264 data->merge_range = *range;
265 #endif
266 switch (data->action)
268 case git_wc_notify_add:
269 //case svn_wc_notify_update_add:
270 // if ((data->content_state == svn_wc_notify_state_conflicted) || (data->prop_state == svn_wc_notify_state_conflicted))
271 // {
272 // data->color = m_Colors.GetColor(CColors::Conflict);
273 // data->bConflictedActionItem = true;
274 // data->sActionColumnText.LoadString(IDS_SVNACTION_CONFLICTED);
275 // m_nConflicts++;
276 // }
277 // else
278 // {
279 // m_bMergesAddsDeletesOccurred = true;
280 data->sActionColumnText.LoadString(IDS_SVNACTION_ADD);
281 data->color = m_Colors.GetColor(CColors::Added);
282 // }
283 break;
284 case git_wc_notify_sendmail_start:
285 data->bAuxItem = true;
286 data->sActionColumnText.LoadString(IDS_SVNACTION_SENDMAIL_START);
287 data->color = m_Colors.GetColor(CColors::Modified);
288 break;
290 case git_wc_notify_sendmail_error:
291 data->bAuxItem = true;
292 data->sActionColumnText.LoadString(IDS_SVNACTION_SENDMAIL_ERROR);
293 if(strErr)
294 data->sPathColumnText = *strErr;
295 else
296 data->sPathColumnText.Empty();
297 data->color = m_Colors.GetColor(CColors::Modified);
298 break;
300 case git_wc_notify_sendmail_done:
302 data->sActionColumnText.LoadString(IDS_SVNACTION_SENDMAIL_DONE);
303 data->sPathColumnText.Empty();
304 data->color = m_Colors.GetColor(CColors::Modified);
305 break;
307 case git_wc_notify_sendmail_retry:
308 data->sActionColumnText.LoadString(IDS_SVNACTION_SENDMAIL_RETRY);
309 data->sPathColumnText.Empty();
310 data->color = m_Colors.GetColor(CColors::Modified);
311 break;
314 case git_wc_notify_resolved:
315 data->sActionColumnText.LoadString(IDS_SVNACTION_RESOLVE);
316 break;
318 case git_wc_notify_revert:
319 data->sActionColumnText.LoadString(IDS_SVNACTION_REVERT);
320 break;
322 #if 0
323 case svn_wc_notify_commit_added:
324 data->sActionColumnText.LoadString(IDS_SVNACTION_ADDING);
325 data->color = m_Colors.GetColor(CColors::Added);
326 break;
327 case svn_wc_notify_copy:
328 data->sActionColumnText.LoadString(IDS_SVNACTION_COPY);
329 break;
330 case svn_wc_notify_commit_modified:
331 data->sActionColumnText.LoadString(IDS_SVNACTION_MODIFIED);
332 data->color = m_Colors.GetColor(CColors::Modified);
333 break;
334 case svn_wc_notify_delete:
335 case svn_wc_notify_update_delete:
336 data->sActionColumnText.LoadString(IDS_SVNACTION_DELETE);
337 m_bMergesAddsDeletesOccurred = true;
338 data->color = m_Colors.GetColor(CColors::Deleted);
339 break;
340 case svn_wc_notify_commit_deleted:
341 data->sActionColumnText.LoadString(IDS_SVNACTION_DELETING);
342 data->color = m_Colors.GetColor(CColors::Deleted);
343 break;
344 case svn_wc_notify_restore:
345 data->sActionColumnText.LoadString(IDS_SVNACTION_RESTORE);
346 break;
348 case svn_wc_notify_update_replace:
349 case svn_wc_notify_commit_replaced:
350 data->sActionColumnText.LoadString(IDS_SVNACTION_REPLACED);
351 data->color = m_Colors.GetColor(CColors::Deleted);
352 break;
353 case svn_wc_notify_exists:
354 if ((data->content_state == svn_wc_notify_state_conflicted) || (data->prop_state == svn_wc_notify_state_conflicted))
356 data->color = m_Colors.GetColor(CColors::Conflict);
357 data->bConflictedActionItem = true;
358 m_nConflicts++;
359 data->sActionColumnText.LoadString(IDS_SVNACTION_CONFLICTED);
361 else if ((data->content_state == svn_wc_notify_state_merged) || (data->prop_state == svn_wc_notify_state_merged))
363 data->color = m_Colors.GetColor(CColors::Merged);
364 m_bMergesAddsDeletesOccurred = true;
365 data->sActionColumnText.LoadString(IDS_SVNACTION_MERGED);
367 else
368 data->sActionColumnText.LoadString(IDS_SVNACTION_EXISTS);
369 break;
370 case svn_wc_notify_update_update:
371 // if this is an inoperative dir change, don't show the notification.
372 // an inoperative dir change is when a directory gets updated without
373 // any real change in either text or properties.
374 if ((kind == svn_node_dir)
375 && ((prop_state == svn_wc_notify_state_inapplicable)
376 || (prop_state == svn_wc_notify_state_unknown)
377 || (prop_state == svn_wc_notify_state_unchanged)))
379 bNoNotify = true;
380 break;
382 if ((data->content_state == svn_wc_notify_state_conflicted) || (data->prop_state == svn_wc_notify_state_conflicted))
384 data->color = m_Colors.GetColor(CColors::Conflict);
385 data->bConflictedActionItem = true;
386 m_nConflicts++;
387 data->sActionColumnText.LoadString(IDS_SVNACTION_CONFLICTED);
389 else if ((data->content_state == svn_wc_notify_state_merged) || (data->prop_state == svn_wc_notify_state_merged))
391 data->color = m_Colors.GetColor(CColors::Merged);
392 m_bMergesAddsDeletesOccurred = true;
393 data->sActionColumnText.LoadString(IDS_SVNACTION_MERGED);
395 else if (((data->content_state != svn_wc_notify_state_unchanged)&&(data->content_state != svn_wc_notify_state_unknown)) ||
396 ((data->prop_state != svn_wc_notify_state_unchanged)&&(data->prop_state != svn_wc_notify_state_unknown)))
398 data->sActionColumnText.LoadString(IDS_SVNACTION_UPDATE);
400 else
402 bNoNotify = true;
403 break;
405 if (lock_state == svn_wc_notify_lock_state_unlocked)
407 CString temp(MAKEINTRESOURCE(IDS_SVNACTION_UNLOCKED));
408 data->sActionColumnText += _T(", ") + temp;
410 break;
412 case svn_wc_notify_update_external:
413 // For some reason we build a list of externals...
414 m_ExtStack.AddHead(path.GetUIPathString());
415 data->sActionColumnText.LoadString(IDS_SVNACTION_EXTERNAL);
416 data->bAuxItem = true;
417 break;
419 case svn_wc_notify_update_completed:
421 data->sActionColumnText.LoadString(IDS_SVNACTION_COMPLETED);
422 data->bAuxItem = true;
423 bool bEmpty = !!m_ExtStack.IsEmpty();
424 if (!bEmpty)
425 data->sPathColumnText.Format(IDS_PROGRS_PATHATREV, (LPCTSTR)m_ExtStack.RemoveHead(), rev);
426 else
427 data->sPathColumnText.Format(IDS_PROGRS_ATREV, rev);
429 if ((m_nConflicts>0)&&(bEmpty))
431 // We're going to add another aux item - let's shove this current onto the list first
432 // I don't really like this, but it will do for the moment.
433 m_arData.push_back(data);
434 AddItemToList();
436 data = new NotificationData();
437 data->bAuxItem = true;
438 data->sActionColumnText.LoadString(IDS_PROGRS_CONFLICTSOCCURED_WARNING);
439 data->sPathColumnText.LoadString(IDS_PROGRS_CONFLICTSOCCURED);
440 data->color = m_Colors.GetColor(CColors::Conflict);
441 CSoundUtils::PlayTSVNWarning();
442 // This item will now be added after the switch statement
444 if (!m_basePath.IsEmpty())
445 m_FinishedRevMap[m_basePath.GetSVNApiPath(pool)] = rev;
446 m_RevisionEnd = rev;
447 m_bFinishedItemAdded = true;
449 break;
450 case svn_wc_notify_commit_postfix_txdelta:
451 data->sActionColumnText.LoadString(IDS_SVNACTION_POSTFIX);
452 break;
453 case svn_wc_notify_failed_revert:
454 data->sActionColumnText.LoadString(IDS_SVNACTION_FAILEDREVERT);
455 break;
456 case svn_wc_notify_status_completed:
457 case svn_wc_notify_status_external:
458 data->sActionColumnText.LoadString(IDS_SVNACTION_STATUS);
459 break;
460 case svn_wc_notify_skip:
461 if ((content_state == svn_wc_notify_state_missing)||(content_state == svn_wc_notify_state_obstructed)||(content_state == svn_wc_notify_state_conflicted))
463 data->sActionColumnText.LoadString(IDS_SVNACTION_SKIPMISSING);
465 // The color settings dialog describes the red color with
466 // "possible or real conflict / obstructed" which also applies to
467 // skipped targets during a merge. So we just use the same color.
468 data->color = m_Colors.GetColor(CColors::Conflict);
470 else
471 data->sActionColumnText.LoadString(IDS_SVNACTION_SKIP);
472 break;
473 case svn_wc_notify_locked:
474 if ((lock)&&(lock->owner))
475 data->sActionColumnText.Format(IDS_SVNACTION_LOCKEDBY, (LPCTSTR)CUnicodeUtils::GetUnicode(lock->owner));
476 break;
477 case svn_wc_notify_unlocked:
478 data->sActionColumnText.LoadString(IDS_SVNACTION_UNLOCKED);
479 break;
480 case svn_wc_notify_failed_lock:
481 data->sActionColumnText.LoadString(IDS_SVNACTION_FAILEDLOCK);
482 m_arData.push_back(data);
483 AddItemToList();
484 ReportError(SVN::GetErrorString(err));
485 bDoAddData = false;
486 if (err->apr_err == SVN_ERR_FS_OUT_OF_DATE)
487 m_bLockWarning = true;
488 if (err->apr_err == SVN_ERR_FS_PATH_ALREADY_LOCKED)
489 m_bLockExists = true;
490 break;
491 case svn_wc_notify_failed_unlock:
492 data->sActionColumnText.LoadString(IDS_SVNACTION_FAILEDUNLOCK);
493 m_arData.push_back(data);
494 AddItemToList();
495 ReportError(SVN::GetErrorString(err));
496 bDoAddData = false;
497 if (err->apr_err == SVN_ERR_FS_OUT_OF_DATE)
498 m_bLockWarning = true;
499 break;
500 case svn_wc_notify_changelist_set:
501 data->sActionColumnText.Format(IDS_SVNACTION_CHANGELISTSET, (LPCTSTR)data->changelistname);
502 break;
503 case svn_wc_notify_changelist_clear:
504 data->sActionColumnText.LoadString(IDS_SVNACTION_CHANGELISTCLEAR);
505 break;
506 case svn_wc_notify_changelist_moved:
507 data->sActionColumnText.Format(IDS_SVNACTION_CHANGELISTMOVED, (LPCTSTR)data->changelistname);
508 break;
509 case svn_wc_notify_foreign_merge_begin:
510 case svn_wc_notify_merge_begin:
511 if (range == NULL)
512 data->sActionColumnText.LoadString(IDS_SVNACTION_MERGEBEGINNONE);
513 else if ((data->merge_range.start == data->merge_range.end) || (data->merge_range.start == data->merge_range.end - 1))
514 data->sActionColumnText.Format(IDS_SVNACTION_MERGEBEGINSINGLE, data->merge_range.end);
515 else if (data->merge_range.start - 1 == data->merge_range.end)
516 data->sActionColumnText.Format(IDS_SVNACTION_MERGEBEGINSINGLEREVERSE, data->merge_range.start);
517 else if (data->merge_range.start < data->merge_range.end)
518 data->sActionColumnText.Format(IDS_SVNACTION_MERGEBEGINMULTIPLE, data->merge_range.start + 1, data->merge_range.end);
519 else
520 data->sActionColumnText.Format(IDS_SVNACTION_MERGEBEGINMULTIPLEREVERSE, data->merge_range.start, data->merge_range.end + 1);
521 data->bAuxItem = true;
522 break;
523 #endif
524 default:
525 break;
526 } // switch (data->action)
528 if (bNoNotify)
529 delete data;
530 else
532 if (bDoAddData)
534 m_arData.push_back(data);
535 AddItemToList();
536 if ((!data->bAuxItem) && (m_itemCount > 0))
538 m_itemCount--;
540 CProgressCtrl * progControl = (CProgressCtrl *)GetDlgItem(IDC_PROGRESSBAR);
541 progControl->ShowWindow(SW_SHOW);
542 progControl->SetPos(m_itemCountTotal - m_itemCount);
543 progControl->SetRange32(0, m_itemCountTotal);
544 if (m_pTaskbarList)
546 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
547 m_pTaskbarList->SetProgressValue(m_hWnd, m_itemCountTotal-m_itemCount, m_itemCountTotal);
551 //if ((action == svn_wc_notify_commit_postfix_txdelta)&&(bSecondResized == FALSE))
553 // ResizeColumns();
554 // bSecondResized = TRUE;
558 return TRUE;
562 CString CGitProgressDlg::BuildInfoString()
564 CString infotext;
565 if(this->m_Command == GitProgress_Resolve)
566 infotext = _T("You need commit your change after resolve conflict");
567 #if 0
569 CString temp;
570 int added = 0;
571 int copied = 0;
572 int deleted = 0;
573 int restored = 0;
574 int reverted = 0;
575 int resolved = 0;
576 int conflicted = 0;
577 int updated = 0;
578 int merged = 0;
579 int modified = 0;
580 int skipped = 0;
581 int replaced = 0;
583 for (size_t i=0; i<m_arData.size(); ++i)
585 const NotificationData * dat = m_arData[i];
586 switch (dat->action)
588 case svn_wc_notify_add:
589 case svn_wc_notify_update_add:
590 case svn_wc_notify_commit_added:
591 if (dat->bConflictedActionItem)
592 conflicted++;
593 else
594 added++;
595 break;
596 case svn_wc_notify_copy:
597 copied++;
598 break;
599 case svn_wc_notify_delete:
600 case svn_wc_notify_update_delete:
601 case svn_wc_notify_commit_deleted:
602 deleted++;
603 break;
604 case svn_wc_notify_restore:
605 restored++;
606 break;
607 case svn_wc_notify_revert:
608 reverted++;
609 break;
610 case svn_wc_notify_resolved:
611 resolved++;
612 break;
613 case svn_wc_notify_update_update:
614 if (dat->bConflictedActionItem)
615 conflicted++;
616 else if ((dat->content_state == svn_wc_notify_state_merged) || (dat->prop_state == svn_wc_notify_state_merged))
617 merged++;
618 else
619 updated++;
620 break;
621 case svn_wc_notify_commit_modified:
622 modified++;
623 break;
624 case svn_wc_notify_skip:
625 skipped++;
626 break;
627 case svn_wc_notify_commit_replaced:
628 replaced++;
629 break;
632 if (conflicted)
634 temp.LoadString(IDS_SVNACTION_CONFLICTED);
635 infotext += temp;
636 temp.Format(_T(":%d "), conflicted);
637 infotext += temp;
639 if (skipped)
641 temp.LoadString(IDS_SVNACTION_SKIP);
642 infotext += temp;
643 infotext.AppendFormat(_T(":%d "), skipped);
645 if (merged)
647 temp.LoadString(IDS_SVNACTION_MERGED);
648 infotext += temp;
649 infotext.AppendFormat(_T(":%d "), merged);
651 if (added)
653 temp.LoadString(IDS_SVNACTION_ADD);
654 infotext += temp;
655 infotext.AppendFormat(_T(":%d "), added);
657 if (deleted)
659 temp.LoadString(IDS_SVNACTION_DELETE);
660 infotext += temp;
661 infotext.AppendFormat(_T(":%d "), deleted);
663 if (modified)
665 temp.LoadString(IDS_SVNACTION_MODIFIED);
666 infotext += temp;
667 infotext.AppendFormat(_T(":%d "), modified);
669 if (copied)
671 temp.LoadString(IDS_SVNACTION_COPY);
672 infotext += temp;
673 infotext.AppendFormat(_T(":%d "), copied);
675 if (replaced)
677 temp.LoadString(IDS_SVNACTION_REPLACED);
678 infotext += temp;
679 infotext.AppendFormat(_T(":%d "), replaced);
681 if (updated)
683 temp.LoadString(IDS_SVNACTION_UPDATE);
684 infotext += temp;
685 infotext.AppendFormat(_T(":%d "), updated);
687 if (restored)
689 temp.LoadString(IDS_SVNACTION_RESTORE);
690 infotext += temp;
691 infotext.AppendFormat(_T(":%d "), restored);
693 if (reverted)
695 temp.LoadString(IDS_SVNACTION_REVERT);
696 infotext += temp;
697 infotext.AppendFormat(_T(":%d "), reverted);
699 if (resolved)
701 temp.LoadString(IDS_SVNACTION_RESOLVE);
702 infotext += temp;
703 infotext.AppendFormat(_T(":%d "), resolved);
705 #endif
706 return infotext;
709 void CGitProgressDlg::SetSelectedList(const CTGitPathList& selPaths)
711 m_selectedPaths = selPaths;
714 void CGitProgressDlg::ResizeColumns()
716 m_ProgList.SetRedraw(FALSE);
718 TCHAR textbuf[MAX_PATH];
720 int maxcol = ((CHeaderCtrl*)(m_ProgList.GetDlgItem(0)))->GetItemCount()-1;
721 for (int col = 0; col <= maxcol; col++)
723 // find the longest width of all items
724 int count = m_ProgList.GetItemCount();
725 HDITEM hdi = {0};
726 hdi.mask = HDI_TEXT;
727 hdi.pszText = textbuf;
728 hdi.cchTextMax = sizeof(textbuf);
729 ((CHeaderCtrl*)(m_ProgList.GetDlgItem(0)))->GetItem(col, &hdi);
730 int cx = m_ProgList.GetStringWidth(hdi.pszText)+20; // 20 pixels for col separator and margin
732 for (int index = 0; index<count; ++index)
734 // get the width of the string and add 12 pixels for the column separator and margins
735 int linewidth = cx;
736 switch (col)
738 case 0:
739 linewidth = m_ProgList.GetStringWidth(m_arData[index]->sActionColumnText) + 12;
740 break;
741 case 1:
742 linewidth = m_ProgList.GetStringWidth(m_arData[index]->sPathColumnText) + 12;
743 break;
744 case 2:
745 linewidth = m_ProgList.GetStringWidth(m_arData[index]->mime_type) + 12;
746 break;
748 if (cx < linewidth)
749 cx = linewidth;
751 m_ProgList.SetColumnWidth(col, cx);
754 m_ProgList.SetRedraw(TRUE);
757 BOOL CGitProgressDlg::OnInitDialog()
759 __super::OnInitDialog();
761 // Let the TaskbarButtonCreated message through the UIPI filter. If we don't
762 // do this, Explorer would be unable to send that message to our window if we
763 // were running elevated. It's OK to make the call all the time, since if we're
764 // not elevated, this is a no-op.
765 CHANGEFILTERSTRUCT cfs = { sizeof(CHANGEFILTERSTRUCT) };
766 typedef BOOL STDAPICALLTYPE ChangeWindowMessageFilterExDFN(HWND hWnd, UINT message, DWORD action, PCHANGEFILTERSTRUCT pChangeFilterStruct);
767 HMODULE hUser = ::LoadLibrary(_T("user32.dll"));
768 if (hUser)
770 ChangeWindowMessageFilterExDFN *pfnChangeWindowMessageFilterEx = (ChangeWindowMessageFilterExDFN*)GetProcAddress(hUser, "ChangeWindowMessageFilterEx");
771 if (pfnChangeWindowMessageFilterEx)
773 pfnChangeWindowMessageFilterEx(m_hWnd, WM_TASKBARBTNCREATED, MSGFLT_ALLOW, &cfs);
775 FreeLibrary(hUser);
777 m_pTaskbarList.Release();
778 m_pTaskbarList.CoCreateInstance(CLSID_TaskbarList);
780 m_ProgList.SetExtendedStyle (LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER);
782 m_ProgList.DeleteAllItems();
783 int c = ((CHeaderCtrl*)(m_ProgList.GetDlgItem(0)))->GetItemCount()-1;
784 while (c>=0)
785 m_ProgList.DeleteColumn(c--);
786 CString temp;
787 temp.LoadString(IDS_PROGRS_ACTION);
788 m_ProgList.InsertColumn(0, temp);
789 temp.LoadString(IDS_PROGRS_PATH);
790 m_ProgList.InsertColumn(1, temp);
791 temp.LoadString(IDS_PROGRS_MIMETYPE);
792 m_ProgList.InsertColumn(2, temp);
794 m_pThread = AfxBeginThread(ProgressThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
795 if (m_pThread==NULL)
797 ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
799 else
801 m_pThread->m_bAutoDelete = FALSE;
802 m_pThread->ResumeThread();
805 UpdateData(FALSE);
807 // Call this early so that the column headings aren't hidden before any
808 // text gets added.
809 ResizeColumns();
811 SetTimer(VISIBLETIMER, 300, NULL);
813 AddAnchor(IDC_SVNPROGRESS, TOP_LEFT, BOTTOM_RIGHT);
814 AddAnchor(IDC_PROGRESSLABEL, BOTTOM_LEFT, BOTTOM_CENTER);
815 AddAnchor(IDC_PROGRESSBAR, BOTTOM_CENTER, BOTTOM_RIGHT);
816 AddAnchor(IDC_INFOTEXT, BOTTOM_LEFT, BOTTOM_RIGHT);
817 AddAnchor(IDC_NONINTERACTIVE, BOTTOM_LEFT, BOTTOM_RIGHT);
818 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
819 AddAnchor(IDOK, BOTTOM_RIGHT);
820 AddAnchor(IDC_LOGBUTTON, BOTTOM_RIGHT);
821 //SetPromptParentWindow(this->m_hWnd);
822 if (hWndExplorer)
823 CenterWindow(CWnd::FromHandle(hWndExplorer));
824 EnableSaveRestore(_T("GITProgressDlg"));
825 return TRUE;
828 bool CGitProgressDlg::SetBackgroundImage(UINT nID)
830 return CAppUtils::SetListCtrlBackgroundImage(m_ProgList.GetSafeHwnd(), nID);
833 void CGitProgressDlg::ReportGitError()
835 ReportError(CString(git_lasterror()));
838 void CGitProgressDlg::ReportError(const CString& sError)
840 CSoundUtils::PlayTGitError();
841 ReportString(sError, CString(MAKEINTRESOURCE(IDS_ERR_ERROR)), m_Colors.GetColor(CColors::Conflict));
842 m_bErrorsOccurred = true;
845 void CGitProgressDlg::ReportWarning(const CString& sWarning)
847 CSoundUtils::PlayTGitWarning();
848 ReportString(sWarning, CString(MAKEINTRESOURCE(IDS_WARN_WARNING)), m_Colors.GetColor(CColors::Conflict));
851 void CGitProgressDlg::ReportNotification(const CString& sNotification)
853 CSoundUtils::PlayTGitNotification();
854 ReportString(sNotification, CString(MAKEINTRESOURCE(IDS_WARN_NOTE)));
857 void CGitProgressDlg::ReportCmd(const CString& sCmd)
859 ReportString(sCmd, CString(MAKEINTRESOURCE(IDS_PROGRS_CMDINFO)), m_Colors.GetColor(CColors::Cmd));
862 void CGitProgressDlg::ReportString(CString sMessage, const CString& sMsgKind, COLORREF color)
864 // instead of showing a dialog box with the error message or notification,
865 // just insert the error text into the list control.
866 // that way the user isn't 'interrupted' by a dialog box popping up!
868 // the message may be split up into different lines
869 // so add a new entry for each line of the message
870 while (!sMessage.IsEmpty())
872 NotificationData * data = new NotificationData();
873 data->bAuxItem = true;
874 data->sActionColumnText = sMsgKind;
875 if (sMessage.Find('\n')>=0)
876 data->sPathColumnText = sMessage.Left(sMessage.Find('\n'));
877 else
878 data->sPathColumnText = sMessage;
879 data->sPathColumnText.Trim(_T("\n\r"));
880 data->color = color;
881 if (sMessage.Find('\n')>=0)
883 sMessage = sMessage.Mid(sMessage.Find('\n'));
884 sMessage.Trim(_T("\n\r"));
886 else
887 sMessage.Empty();
888 m_arData.push_back(data);
889 AddItemToList();
893 UINT CGitProgressDlg::ProgressThreadEntry(LPVOID pVoid)
895 return ((CGitProgressDlg*)pVoid)->ProgressThread();
898 UINT CGitProgressDlg::ProgressThread()
900 // The SetParams function should have loaded something for us
902 CString temp;
903 CString sWindowTitle;
904 bool localoperation = false;
905 bool bSuccess = false;
906 m_AlwaysConflicted = false;
908 DialogEnableWindow(IDOK, FALSE);
909 DialogEnableWindow(IDCANCEL, TRUE);
910 // SetAndClearProgressInfo(m_hWnd);
911 m_itemCount = m_itemCountTotal;
913 InterlockedExchange(&m_bThreadRunning, TRUE);
914 iFirstResized = 0;
915 bSecondResized = FALSE;
916 m_bFinishedItemAdded = false;
917 CTime startTime = CTime::GetCurrentTime();
919 if (m_pTaskbarList)
920 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_INDETERMINATE);
922 switch (m_Command)
924 case GitProgress_Add:
925 bSuccess = CmdAdd(sWindowTitle, localoperation);
926 break;
927 case GitProgress_Copy:
928 bSuccess = CmdCopy(sWindowTitle, localoperation);
929 break;
930 case GitProgress_Export:
931 bSuccess = CmdExport(sWindowTitle, localoperation);
932 break;
933 case GitProgress_Rename:
934 bSuccess = CmdRename(sWindowTitle, localoperation);
935 break;
936 case GitProgress_Resolve:
937 bSuccess = CmdResolve(sWindowTitle, localoperation);
938 break;
939 case GitProgress_Revert:
940 bSuccess = CmdRevert(sWindowTitle, localoperation);
941 break;
942 case GitProgress_Switch:
943 bSuccess = CmdSwitch(sWindowTitle, localoperation);
944 break;
945 case GitProgress_SendMail:
946 bSuccess = CmdSendMail(sWindowTitle, localoperation);
947 break;
949 if (!bSuccess)
950 temp.LoadString(IDS_PROGRS_TITLEFAILED);
951 else
952 temp.LoadString(IDS_PROGRS_TITLEFIN);
953 sWindowTitle = sWindowTitle + _T(" ") + temp;
954 SetWindowText(sWindowTitle);
956 KillTimer(TRANSFERTIMER);
957 KillTimer(VISIBLETIMER);
959 if (m_pTaskbarList)
961 if (DidErrorsOccur())
963 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_ERROR);
964 m_pTaskbarList->SetProgressValue(m_hWnd, 100, 100);
966 else
967 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NOPROGRESS);
970 DialogEnableWindow(IDCANCEL, FALSE);
971 DialogEnableWindow(IDOK, TRUE);
973 CString info = BuildInfoString();
974 if (!bSuccess)
975 info.LoadString(IDS_PROGRS_INFOFAILED);
976 SetDlgItemText(IDC_INFOTEXT, info);
977 ResizeColumns();
978 SendMessage(DM_SETDEFID, IDOK);
979 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;
1059 cmd = CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe");
1060 cmd += _T(" /command:commit");
1062 cmd += _T(" /path:\"")+g_Git.m_CurrentDir+_T("\"");
1064 CAppUtils::LaunchApplication(cmd,NULL,false);
1065 this->EndDialog(IDOK);
1066 break;
1069 #if 0
1070 if (m_targetPathList.GetCount() != 1)
1071 return;
1072 StringRevMap::iterator it = m_UpdateStartRevMap.begin();
1073 svn_revnum_t rev = -1;
1074 if (it != m_UpdateStartRevMap.end())
1076 rev = it->second;
1078 CLogDlg dlg;
1079 dlg.SetParams(m_targetPathList[0], m_RevisionEnd, m_RevisionEnd, rev, 0, TRUE);
1080 dlg.DoModal();
1081 #endif
1085 void CGitProgressDlg::OnClose()
1087 if (m_bCancelled)
1089 TerminateThread(m_pThread->m_hThread, (DWORD)-1);
1090 InterlockedExchange(&m_bThreadRunning, FALSE);
1092 else
1094 m_bCancelled = TRUE;
1095 return;
1097 DialogEnableWindow(IDCANCEL, TRUE);
1098 __super::OnClose();
1101 void CGitProgressDlg::OnOK()
1103 if ((m_bCancelled)&&(!m_bThreadRunning))
1105 // I have made this wait a sensible amount of time (10 seconds) for the thread to finish
1106 // You must be careful in the thread that after posting the WM_COMMAND/IDOK message, you
1107 // don't do any more operations on the window which might require message passing
1108 // If you try to send windows messages once we're waiting here, then the thread can't finished
1109 // because the Window's message loop is blocked at this wait
1110 WaitForSingleObject(m_pThread->m_hThread, 10000);
1111 __super::OnOK();
1113 m_bCancelled = TRUE;
1116 void CGitProgressDlg::OnCancel()
1118 if ((m_bCancelled)&&(!m_bThreadRunning))
1119 __super::OnCancel();
1120 m_bCancelled = TRUE;
1123 void CGitProgressDlg::OnLvnGetdispinfoSvnprogress(NMHDR *pNMHDR, LRESULT *pResult)
1125 NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
1127 if (pDispInfo)
1129 if (pDispInfo->item.mask & LVIF_TEXT)
1131 if (pDispInfo->item.iItem < (int)m_arData.size())
1133 const NotificationData * data = m_arData[pDispInfo->item.iItem];
1134 switch (pDispInfo->item.iSubItem)
1136 case 0:
1137 lstrcpyn(m_columnbuf, data->sActionColumnText, MAX_PATH);
1138 break;
1139 case 1:
1140 lstrcpyn(m_columnbuf, data->sPathColumnText, pDispInfo->item.cchTextMax);
1141 if (!data->bAuxItem)
1143 int cWidth = m_ProgList.GetColumnWidth(1);
1144 cWidth = max(12, cWidth-12);
1145 CDC * pDC = m_ProgList.GetDC();
1146 if (pDC != NULL)
1148 CFont * pFont = pDC->SelectObject(m_ProgList.GetFont());
1149 PathCompactPath(pDC->GetSafeHdc(), m_columnbuf, cWidth);
1150 pDC->SelectObject(pFont);
1151 ReleaseDC(pDC);
1154 break;
1155 case 2:
1156 lstrcpyn(m_columnbuf, data->mime_type, MAX_PATH);
1157 break;
1158 default:
1159 m_columnbuf[0] = 0;
1161 pDispInfo->item.pszText = m_columnbuf;
1165 *pResult = 0;
1168 void CGitProgressDlg::OnNMCustomdrawSvnprogress(NMHDR *pNMHDR, LRESULT *pResult)
1170 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
1172 // Take the default processing unless we set this to something else below.
1173 *pResult = CDRF_DODEFAULT;
1175 // First thing - check the draw stage. If it's the control's prepaint
1176 // stage, then tell Windows we want messages for every item.
1178 if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )
1180 *pResult = CDRF_NOTIFYITEMDRAW;
1182 else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )
1184 // This is the prepaint stage for an item. Here's where we set the
1185 // item's text color. Our return value will tell Windows to draw the
1186 // item itself, but it will use the new color we set here.
1188 // Tell Windows to paint the control itself.
1189 *pResult = CDRF_DODEFAULT;
1191 ASSERT(pLVCD->nmcd.dwItemSpec < m_arData.size());
1192 if(pLVCD->nmcd.dwItemSpec >= m_arData.size())
1194 return;
1196 const NotificationData * data = m_arData[pLVCD->nmcd.dwItemSpec];
1197 ASSERT(data != NULL);
1198 if (data == NULL)
1199 return;
1201 // Store the color back in the NMLVCUSTOMDRAW struct.
1202 pLVCD->clrText = data->color;
1206 void CGitProgressDlg::OnNMDblclkSvnprogress(NMHDR * /*pNMHDR*/, LRESULT * /*pResult*/)
1208 #if 0
1209 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1210 *pResult = 0;
1211 if (pNMLV->iItem < 0)
1212 return;
1213 if (m_options & ProgOptDryRun)
1214 return; //don't do anything in a dry-run.
1216 const NotificationData * data = m_arData[pNMLV->iItem];
1217 if (data == NULL)
1218 return;
1220 if (data->bConflictedActionItem)
1222 // We've double-clicked on a conflicted item - do a three-way merge on it
1223 SVNDiff::StartConflictEditor(data->path);
1225 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))
1227 // This is a modified file which has been merged on update. Diff it against base
1228 CTGitPath temporaryFile;
1229 SVNDiff diff(this, this->m_hWnd, true);
1230 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
1231 svn_revnum_t baseRev = 0;
1232 diff.DiffFileAgainstBase(data->path, baseRev);
1234 else if ((!data->bAuxItem)&&(data->path.Exists())&&(!data->path.IsDirectory()))
1236 bool bOpenWith = false;
1237 int ret = (int)ShellExecute(m_hWnd, NULL, data->path.GetWinPath(), NULL, NULL, SW_SHOWNORMAL);
1238 if (ret <= HINSTANCE_ERROR)
1239 bOpenWith = true;
1240 if (bOpenWith)
1242 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
1243 cmd += data->path.GetWinPathString() + _T(" ");
1244 CAppUtils::LaunchApplication(cmd, NULL, false);
1247 #endif
1250 void CGitProgressDlg::OnHdnItemclickSvnprogress(NMHDR *pNMHDR, LRESULT *pResult)
1252 LPNMHEADER phdr = reinterpret_cast<LPNMHEADER>(pNMHDR);
1253 if (m_bThreadRunning)
1254 return;
1255 if (m_nSortedColumn == phdr->iItem)
1256 m_bAscending = !m_bAscending;
1257 else
1258 m_bAscending = TRUE;
1259 m_nSortedColumn = phdr->iItem;
1260 Sort();
1262 CString temp;
1263 m_ProgList.SetRedraw(FALSE);
1264 m_ProgList.DeleteAllItems();
1265 m_ProgList.SetItemCountEx (static_cast<int>(m_arData.size()));
1267 m_ProgList.SetRedraw(TRUE);
1269 *pResult = 0;
1272 bool CGitProgressDlg::NotificationDataIsAux(const NotificationData* pData)
1274 return pData->bAuxItem;
1277 LRESULT CGitProgressDlg::OnGitProgress(WPARAM /*wParam*/, LPARAM /*lParam*/)
1279 #if 0
1280 SVNProgress * pProgressData = (SVNProgress *)lParam;
1281 CProgressCtrl * progControl = (CProgressCtrl *)GetDlgItem(IDC_PROGRESSBAR);
1282 if ((pProgressData->total > 1000)&&(!progControl->IsWindowVisible()))
1284 progControl->ShowWindow(SW_SHOW);
1285 if (m_pTaskbarList)
1286 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
1288 if (((pProgressData->total < 0)&&(pProgressData->progress > 1000)&&(progControl->IsWindowVisible()))&&(m_itemCountTotal<0))
1290 progControl->ShowWindow(SW_HIDE);
1291 if (m_pTaskbarList)
1292 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_INDETERMINATE);
1294 if (!GetDlgItem(IDC_PROGRESSLABEL)->IsWindowVisible())
1295 GetDlgItem(IDC_PROGRESSLABEL)->ShowWindow(SW_SHOW);
1296 SetTimer(TRANSFERTIMER, 2000, NULL);
1297 if ((pProgressData->total > 0)&&(pProgressData->progress > 1000))
1299 progControl->SetPos((int)pProgressData->progress);
1300 progControl->SetRange32(0, (int)pProgressData->total);
1301 if (m_pTaskbarList)
1303 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
1304 m_pTaskbarList->SetProgressValue(m_hWnd, pProgressData->progress, pProgressData->total);
1307 CString progText;
1308 if (pProgressData->overall_total < 1024)
1309 m_sTotalBytesTransferred.Format(IDS_SVN_PROGRESS_TOTALBYTESTRANSFERRED, pProgressData->overall_total);
1310 else if (pProgressData->overall_total < 1200000)
1311 m_sTotalBytesTransferred.Format(IDS_SVN_PROGRESS_TOTALTRANSFERRED, pProgressData->overall_total / 1024);
1312 else
1313 m_sTotalBytesTransferred.Format(IDS_SVN_PROGRESS_TOTALMBTRANSFERRED, (double)((double)pProgressData->overall_total / 1024000.0));
1314 progText.Format(IDS_SVN_PROGRESS_TOTALANDSPEED, (LPCTSTR)m_sTotalBytesTransferred, (LPCTSTR)pProgressData->SpeedString);
1315 SetDlgItemText(IDC_PROGRESSLABEL, progText);
1316 #endif
1317 return 0;
1320 void CGitProgressDlg::OnTimer(UINT_PTR nIDEvent)
1322 if (nIDEvent == TRANSFERTIMER)
1324 CString progText;
1325 CString progSpeed;
1326 progSpeed.Format(IDS_SVN_PROGRESS_BYTES_SEC, 0);
1327 progText.Format(IDS_SVN_PROGRESS_TOTALANDSPEED, (LPCTSTR)m_sTotalBytesTransferred, (LPCTSTR)progSpeed);
1328 SetDlgItemText(IDC_PROGRESSLABEL, progText);
1329 KillTimer(TRANSFERTIMER);
1331 if (nIDEvent == VISIBLETIMER)
1333 if (nEnsureVisibleCount)
1334 m_ProgList.EnsureVisible(m_ProgList.GetItemCount()-1, false);
1335 nEnsureVisibleCount = 0;
1339 void CGitProgressDlg::Sort()
1341 if(m_arData.size() < 2)
1343 return;
1346 // We need to sort the blocks which lie between the auxiliary entries
1347 // This is so that any aux data stays where it was
1348 NotificationDataVect::iterator actionBlockBegin;
1349 NotificationDataVect::iterator actionBlockEnd = m_arData.begin(); // We start searching from here
1351 for(;;)
1353 // Search to the start of the non-aux entry in the next block
1354 actionBlockBegin = std::find_if(actionBlockEnd, m_arData.end(), std::not1(std::ptr_fun(&CGitProgressDlg::NotificationDataIsAux)));
1355 if(actionBlockBegin == m_arData.end())
1357 // There are no more actions
1358 break;
1360 // Now search to find the end of the block
1361 actionBlockEnd = std::find_if(actionBlockBegin+1, m_arData.end(), std::ptr_fun(&CGitProgressDlg::NotificationDataIsAux));
1362 // Now sort the block
1363 std::sort(actionBlockBegin, actionBlockEnd, &CGitProgressDlg::SortCompare);
1367 bool CGitProgressDlg::SortCompare(const NotificationData * pData1, const NotificationData * pData2)
1369 int result = 0;
1370 switch (m_nSortedColumn)
1372 case 0: //action column
1373 result = pData1->sActionColumnText.Compare(pData2->sActionColumnText);
1374 break;
1375 case 1: //path column
1376 // Compare happens after switch()
1377 break;
1378 case 2: //mime-type column
1379 result = pData1->mime_type.Compare(pData2->mime_type);
1380 break;
1381 default:
1382 break;
1385 // Sort by path if everything else is equal
1386 if (result == 0)
1388 result = CTGitPath::Compare(pData1->path, pData2->path);
1391 if (!m_bAscending)
1392 result = -result;
1393 return result < 0;
1396 BOOL CGitProgressDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
1398 if (!GetDlgItem(IDOK)->IsWindowEnabled())
1400 // only show the wait cursor over the list control
1401 if ((pWnd)&&(pWnd == GetDlgItem(IDC_SVNPROGRESS)))
1403 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT));
1404 SetCursor(hCur);
1405 return TRUE;
1408 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));
1409 SetCursor(hCur);
1410 return CResizableStandAloneDialog::OnSetCursor(pWnd, nHitTest, message);
1413 BOOL CGitProgressDlg::PreTranslateMessage(MSG* pMsg)
1415 if (pMsg->message == WM_KEYDOWN)
1417 if (pMsg->wParam == VK_ESCAPE)
1419 // pressing the ESC key should close the dialog. But since we disabled the escape
1420 // key (so the user doesn't get the idea that he could simply undo an e.g. update)
1421 // this won't work.
1422 // So if the user presses the ESC key, change it to VK_RETURN so the dialog gets
1423 // the impression that the OK button was pressed.
1424 if ((!m_bThreadRunning)&&(!GetDlgItem(IDCANCEL)->IsWindowEnabled())
1425 &&(GetDlgItem(IDOK)->IsWindowEnabled())&&(GetDlgItem(IDOK)->IsWindowVisible()))
1427 // since we convert ESC to RETURN, make sure the OK button has the focus.
1428 GetDlgItem(IDOK)->SetFocus();
1429 pMsg->wParam = VK_RETURN;
1432 if (pMsg->wParam == 'A')
1434 if (GetKeyState(VK_CONTROL)&0x8000)
1436 // Ctrl-A -> select all
1437 m_ProgList.SetSelectionMark(0);
1438 for (int i=0; i<m_ProgList.GetItemCount(); ++i)
1440 m_ProgList.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
1444 if ((pMsg->wParam == 'C')||(pMsg->wParam == VK_INSERT))
1446 int selIndex = m_ProgList.GetSelectionMark();
1447 if (selIndex >= 0)
1449 if (GetKeyState(VK_CONTROL)&0x8000)
1451 //Ctrl-C -> copy to clipboard
1452 CString sClipdata;
1453 POSITION pos = m_ProgList.GetFirstSelectedItemPosition();
1454 if (pos != NULL)
1456 while (pos)
1458 int nItem = m_ProgList.GetNextSelectedItem(pos);
1459 CString sAction = m_ProgList.GetItemText(nItem, 0);
1460 CString sPath = m_ProgList.GetItemText(nItem, 1);
1461 CString sMime = m_ProgList.GetItemText(nItem, 2);
1462 CString sLogCopyText;
1463 sLogCopyText.Format(_T("%s: %s %s\r\n"),
1464 (LPCTSTR)sAction, (LPCTSTR)sPath, (LPCTSTR)sMime);
1465 sClipdata += sLogCopyText;
1467 CStringUtils::WriteAsciiStringToClipboard(sClipdata);
1472 } // if (pMsg->message == WM_KEYDOWN)
1473 return __super::PreTranslateMessage(pMsg);
1476 void CGitProgressDlg::OnContextMenu(CWnd* /*pWnd*/, CPoint /*point*/)
1478 #if 0
1479 if (m_options & ProgOptDryRun)
1480 return; // don't do anything in a dry-run.
1482 if (pWnd == &m_ProgList)
1484 int selIndex = m_ProgList.GetSelectionMark();
1485 if ((point.x == -1) && (point.y == -1))
1487 // Menu was invoked from the keyboard rather than by right-clicking
1488 CRect rect;
1489 m_ProgList.GetItemRect(selIndex, &rect, LVIR_LABEL);
1490 m_ProgList.ClientToScreen(&rect);
1491 point = rect.CenterPoint();
1494 if ((selIndex >= 0)&&(!m_bThreadRunning))
1496 // entry is selected, thread has finished with updating so show the popup menu
1497 CIconMenu popup;
1498 if (popup.CreatePopupMenu())
1500 bool bAdded = false;
1501 NotificationData * data = m_arData[selIndex];
1502 if ((data)&&(!data->path.IsDirectory()))
1504 if (data->action == svn_wc_notify_update_update || data->action == svn_wc_notify_resolved)
1506 if (m_ProgList.GetSelectedCount() == 1)
1508 popup.AppendMenuIcon(ID_COMPARE, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1509 bAdded = true;
1512 if (data->bConflictedActionItem)
1514 if (m_ProgList.GetSelectedCount() == 1)
1516 popup.AppendMenuIcon(ID_EDITCONFLICT, IDS_MENUCONFLICT,IDI_CONFLICT);
1517 popup.SetDefaultItem(ID_EDITCONFLICT, FALSE);
1518 popup.AppendMenuIcon(ID_CONFLICTRESOLVE, IDS_SVNPROGRESS_MENUMARKASRESOLVED,IDI_RESOLVE);
1520 popup.AppendMenuIcon(ID_CONFLICTUSETHEIRS, IDS_SVNPROGRESS_MENUUSETHEIRS,IDI_RESOLVE);
1521 popup.AppendMenuIcon(ID_CONFLICTUSEMINE, IDS_SVNPROGRESS_MENUUSEMINE,IDI_RESOLVE);
1523 else if ((data->content_state == svn_wc_notify_state_merged)||(GitProgress_Merge == m_Command)||(data->action == svn_wc_notify_resolved))
1524 popup.SetDefaultItem(ID_COMPARE, FALSE);
1526 if (m_ProgList.GetSelectedCount() == 1)
1528 if ((data->action == svn_wc_notify_add)||
1529 (data->action == svn_wc_notify_update_add)||
1530 (data->action == svn_wc_notify_commit_added)||
1531 (data->action == svn_wc_notify_commit_modified)||
1532 (data->action == svn_wc_notify_restore)||
1533 (data->action == svn_wc_notify_revert)||
1534 (data->action == svn_wc_notify_resolved)||
1535 (data->action == svn_wc_notify_commit_replaced)||
1536 (data->action == svn_wc_notify_commit_modified)||
1537 (data->action == svn_wc_notify_commit_postfix_txdelta)||
1538 (data->action == svn_wc_notify_update_update))
1540 popup.AppendMenuIcon(ID_LOG, IDS_MENULOG,IDI_LOG);
1541 if (data->action == svn_wc_notify_update_update)
1542 popup.AppendMenu(MF_SEPARATOR, NULL);
1543 popup.AppendMenuIcon(ID_OPEN, IDS_LOG_POPUP_OPEN, IDI_OPEN);
1544 popup.AppendMenuIcon(ID_OPENWITH, IDS_LOG_POPUP_OPENWITH, IDI_OPEN);
1545 bAdded = true;
1548 } // if ((data)&&(!data->path.IsDirectory()))
1549 if (m_ProgList.GetSelectedCount() == 1)
1551 if (data)
1553 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1554 if ((!sPath.IsEmpty())&&(!SVN::PathIsURL(CTGitPath(sPath))))
1556 CTGitPath path = CTGitPath(sPath);
1557 if (path.GetDirectory().Exists())
1559 popup.AppendMenuIcon(ID_EXPLORE, IDS_SVNPROGRESS_MENUOPENPARENT, IDI_EXPLORER);
1560 bAdded = true;
1565 if (m_ProgList.GetSelectedCount() > 0)
1567 if (bAdded)
1568 popup.AppendMenu(MF_SEPARATOR, NULL);
1569 popup.AppendMenuIcon(ID_COPY, IDS_LOG_POPUP_COPYTOCLIPBOARD,IDI_COPYCLIP);
1570 bAdded = true;
1572 if (bAdded)
1574 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
1575 DialogEnableWindow(IDOK, FALSE);
1576 this->SetPromptApp(&theApp);
1577 theApp.DoWaitCursor(1);
1578 bool bOpenWith = false;
1579 switch (cmd)
1581 case ID_COPY:
1583 CString sLines;
1584 POSITION pos = m_ProgList.GetFirstSelectedItemPosition();
1585 while (pos)
1587 int nItem = m_ProgList.GetNextSelectedItem(pos);
1588 NotificationData * data = m_arData[nItem];
1589 if (data)
1591 sLines += data->sPathColumnText;
1592 sLines += _T("\r\n");
1595 sLines.TrimRight();
1596 if (!sLines.IsEmpty())
1598 CStringUtils::WriteAsciiStringToClipboard(sLines, GetSafeHwnd());
1601 break;
1602 case ID_EXPLORE:
1604 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1606 CTGitPath path = CTGitPath(sPath);
1607 ShellExecute(m_hWnd, _T("explore"), path.GetDirectory().GetWinPath(), NULL, path.GetDirectory().GetWinPath(), SW_SHOW);
1609 break;
1610 case ID_COMPARE:
1612 svn_revnum_t rev = -1;
1613 StringRevMap::iterator it = m_UpdateStartRevMap.end();
1614 if (data->basepath.IsEmpty())
1615 it = m_UpdateStartRevMap.begin();
1616 else
1617 it = m_UpdateStartRevMap.find(data->basepath.GetSVNApiPath(pool));
1618 if (it != m_UpdateStartRevMap.end())
1619 rev = it->second;
1620 // if the file was merged during update, do a three way diff between OLD, MINE, THEIRS
1621 if (data->content_state == svn_wc_notify_state_merged)
1623 CTGitPath basefile = CTempFiles::Instance().GetTempFilePath(false, data->path, rev);
1624 CTGitPath newfile = CTempFiles::Instance().GetTempFilePath(false, data->path, SVNRev::REV_HEAD);
1625 SVN svn;
1626 if (!svn.Cat(data->path, SVNRev(SVNRev::REV_WC), rev, basefile))
1628 CMessageBox::Show(m_hWnd, svn.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1629 DialogEnableWindow(IDOK, TRUE);
1630 break;
1632 // If necessary, convert the line-endings on the file before diffing
1633 if ((DWORD)CRegDWORD(_T("Software\\TortoiseGit\\ConvertBase"), TRUE))
1635 CTGitPath temporaryFile = CTempFiles::Instance().GetTempFilePath(false, data->path, SVNRev::REV_BASE);
1636 if (!svn.Cat(data->path, SVNRev(SVNRev::REV_BASE), SVNRev(SVNRev::REV_BASE), temporaryFile))
1638 temporaryFile.Reset();
1639 break;
1641 else
1643 newfile = temporaryFile;
1647 SetFileAttributes(newfile.GetWinPath(), FILE_ATTRIBUTE_READONLY);
1648 SetFileAttributes(basefile.GetWinPath(), FILE_ATTRIBUTE_READONLY);
1649 CString revname, wcname, basename;
1650 revname.Format(_T("%s Revision %ld"), (LPCTSTR)data->path.GetUIFileOrDirectoryName(), rev);
1651 wcname.Format(IDS_DIFF_WCNAME, (LPCTSTR)data->path.GetUIFileOrDirectoryName());
1652 basename.Format(IDS_DIFF_BASENAME, (LPCTSTR)data->path.GetUIFileOrDirectoryName());
1653 CAppUtils::StartExtMerge(basefile, newfile, data->path, data->path, basename, revname, wcname, CString(), true);
1655 else
1657 CTGitPath tempfile = CTempFiles::Instance().GetTempFilePath(false, data->path, rev);
1658 SVN svn;
1659 if (!svn.Cat(data->path, SVNRev(SVNRev::REV_WC), rev, tempfile))
1661 CMessageBox::Show(m_hWnd, svn.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1662 DialogEnableWindow(IDOK, TRUE);
1663 break;
1665 else
1667 SetFileAttributes(tempfile.GetWinPath(), FILE_ATTRIBUTE_READONLY);
1668 CString revname, wcname;
1669 revname.Format(_T("%s Revision %ld"), (LPCTSTR)data->path.GetUIFileOrDirectoryName(), rev);
1670 wcname.Format(IDS_DIFF_WCNAME, (LPCTSTR)data->path.GetUIFileOrDirectoryName());
1671 CAppUtils::StartExtDiff(
1672 tempfile, data->path, revname, wcname,
1673 CAppUtils::DiffFlags().AlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000)));
1677 break;
1678 case ID_EDITCONFLICT:
1680 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1681 SVNDiff::StartConflictEditor(CTGitPath(sPath));
1683 break;
1684 case ID_CONFLICTUSETHEIRS:
1685 case ID_CONFLICTUSEMINE:
1686 case ID_CONFLICTRESOLVE:
1688 svn_wc_conflict_choice_t result = svn_wc_conflict_choose_merged;
1689 switch (cmd)
1691 case ID_CONFLICTUSETHEIRS:
1692 result = svn_wc_conflict_choose_theirs_full;
1693 break;
1694 case ID_CONFLICTUSEMINE:
1695 result = svn_wc_conflict_choose_mine_full;
1696 break;
1697 case ID_CONFLICTRESOLVE:
1698 result = svn_wc_conflict_choose_merged;
1699 break;
1701 SVN svn;
1702 POSITION pos = m_ProgList.GetFirstSelectedItemPosition();
1703 CString sResolvedPaths;
1704 while (pos)
1706 int nItem = m_ProgList.GetNextSelectedItem(pos);
1707 NotificationData * data = m_arData[nItem];
1708 if (data)
1710 if (data->bConflictedActionItem)
1712 if (!svn.Resolve(data->path, result, FALSE))
1714 CMessageBox::Show(m_hWnd, svn.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1715 DialogEnableWindow(IDOK, TRUE);
1716 break;
1718 else
1720 data->color = ::GetSysColor(COLOR_WINDOWTEXT);
1721 data->action = svn_wc_notify_resolved;
1722 data->sActionColumnText.LoadString(IDS_SVNACTION_RESOLVE);
1723 data->bConflictedActionItem = false;
1724 m_nConflicts--;
1726 if (m_nConflicts==0)
1728 // When the last conflict is resolved we remove
1729 // the warning which we assume is in the last line.
1730 int nIndex = m_ProgList.GetItemCount()-1;
1731 VERIFY(m_ProgList.DeleteItem(nIndex));
1733 delete m_arData[nIndex];
1734 m_arData.pop_back();
1736 sResolvedPaths += data->path.GetWinPathString() + _T("\n");
1741 m_ProgList.Invalidate();
1742 CString info = BuildInfoString();
1743 SetDlgItemText(IDC_INFOTEXT, info);
1745 if (!sResolvedPaths.IsEmpty())
1747 CString msg;
1748 msg.Format(IDS_SVNPROGRESS_RESOLVED, (LPCTSTR)sResolvedPaths);
1749 CMessageBox::Show(m_hWnd, msg, _T("TortoiseGit"), MB_OK | MB_ICONINFORMATION);
1752 break;
1753 case ID_LOG:
1755 svn_revnum_t rev = m_RevisionEnd;
1756 if (!data->basepath.IsEmpty())
1758 StringRevMap::iterator it = m_FinishedRevMap.find(data->basepath.GetSVNApiPath(pool));
1759 if (it != m_FinishedRevMap.end())
1760 rev = it->second;
1762 CLogDlg dlg;
1763 // fetch the log from HEAD, not the revision we updated to:
1764 // the path might be inside an external folder which has its own
1765 // revisions.
1766 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1767 dlg.SetParams(CTGitPath(sPath), SVNRev(), SVNRev::REV_HEAD, 1, -1, TRUE);
1768 dlg.DoModal();
1770 break;
1771 case ID_OPENWITH:
1772 bOpenWith = true;
1773 case ID_OPEN:
1775 int ret = 0;
1776 CString sWinPath = GetPathFromColumnText(data->sPathColumnText);
1777 if (!bOpenWith)
1778 ret = (int)ShellExecute(this->m_hWnd, NULL, (LPCTSTR)sWinPath, NULL, NULL, SW_SHOWNORMAL);
1779 if ((ret <= HINSTANCE_ERROR)||bOpenWith)
1781 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
1782 cmd += sWinPath + _T(" ");
1783 CAppUtils::LaunchApplication(cmd, NULL, false);
1787 DialogEnableWindow(IDOK, TRUE);
1788 theApp.DoWaitCursor(-1);
1789 } // if (bAdded)
1793 #endif
1796 void CGitProgressDlg::OnEnSetfocusInfotext()
1798 CString sTemp;
1799 GetDlgItemText(IDC_INFOTEXT, sTemp);
1800 if (sTemp.IsEmpty())
1801 GetDlgItem(IDC_INFOTEXT)->HideCaret();
1804 void CGitProgressDlg::OnLvnBegindragSvnprogress(NMHDR* , LRESULT *pResult)
1806 //LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1807 #if 0
1808 int selIndex = m_ProgList.GetSelectionMark();
1809 if (selIndex < 0)
1810 return;
1812 CDropFiles dropFiles; // class for creating DROPFILES struct
1814 int index;
1815 POSITION pos = m_ProgList.GetFirstSelectedItemPosition();
1816 while ( (index = m_ProgList.GetNextSelectedItem(pos)) >= 0 )
1818 NotificationData * data = m_arData[index];
1820 if ( data->kind==svn_node_file || data->kind==svn_node_dir )
1822 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1824 dropFiles.AddFile( sPath );
1828 if ( dropFiles.GetCount()>0 )
1830 dropFiles.CreateStructure();
1832 #endif
1833 *pResult = 0;
1836 void CGitProgressDlg::OnSize(UINT nType, int cx, int cy)
1838 CResizableStandAloneDialog::OnSize(nType, cx, cy);
1839 if ((nType == SIZE_RESTORED)&&(m_bLastVisible))
1841 if(!m_ProgList.m_hWnd)
1842 return;
1844 int count = m_ProgList.GetItemCount();
1845 if (count > 0)
1846 m_ProgList.EnsureVisible(count-1, false);
1850 //////////////////////////////////////////////////////////////////////////
1851 /// commands
1852 //////////////////////////////////////////////////////////////////////////
1853 bool CGitProgressDlg::CmdAdd(CString& sWindowTitle, bool& localoperation)
1855 localoperation = true;
1856 sWindowTitle.LoadString(IDS_PROGRS_TITLE_ADD);
1857 CAppUtils::SetWindowTitle(m_hWnd, m_targetPathList.GetCommonRoot().GetUIPathString(), sWindowTitle);
1858 SetBackgroundImage(IDI_ADD_BKG);
1859 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_ADD)));
1861 // HACK for separate-git-dir, libgit2 doesn't support it atm
1862 if (CTGitPath(g_Git.m_CurrentDir + _T("/.git")).IsDirectory())
1864 git_repository *repo = NULL;
1865 git_index *index;
1867 CStringA gitdir = CUnicodeUtils::GetMulti(CTGitPath(g_Git.m_CurrentDir).GetGitPathString() + _T("/.git"), CP_ACP);
1868 if (git_repository_open(&repo, gitdir.GetBuffer()))
1870 ReportGitError();
1871 return false;
1873 if (git_repository_index(&index, repo))
1875 ReportGitError();
1876 git_repository_free(repo);
1877 return false;
1879 if (git_index_read(index))
1881 ReportGitError();
1882 git_index_free(index);
1883 git_repository_free(repo);
1884 return false;
1887 for(int i=0;i<m_targetPathList.GetCount();i++)
1889 if (git_index_add(index, CStringA(CUnicodeUtils::GetMulti(m_targetPathList[i].GetGitPathString(), CP_ACP)).GetBuffer(), 0))
1891 ReportGitError();
1892 git_index_free(index);
1893 git_repository_free(repo);
1894 return false;
1896 Notify(m_targetPathList[i],git_wc_notify_add);
1899 if (git_index_write(index))
1901 ReportGitError();
1902 git_index_free(index);
1903 git_repository_free(repo);
1904 return false;
1907 git_index_free(index);
1908 git_repository_free(repo);
1910 else
1912 for(int i = 0; i < m_targetPathList.GetCount(); i++)
1914 CString cmd, out;
1915 cmd.Format(_T("git.exe add -f -- \"%s\""),m_targetPathList[i].GetGitPathString());
1916 if(g_Git.Run(cmd, &out, CP_ACP))
1918 MessageBox(out, _T("TortoiseGit"), MB_OK|MB_ICONERROR);
1919 m_bErrorsOccurred = true;
1920 return false;
1922 Notify(m_targetPathList[i], git_wc_notify_add);
1926 CShellUpdater::Instance().AddPathsForUpdate(m_targetPathList);
1927 m_bErrorsOccurred=false;
1929 this->GetDlgItem(IDC_LOGBUTTON)->SetWindowText(_T("Commit ..."));
1930 this->GetDlgItem(IDC_LOGBUTTON)->ShowWindow(SW_SHOW);
1931 return true;
1934 bool CGitProgressDlg::CmdCopy(CString& /*sWindowTitle*/, bool& /*localoperation*/)
1936 #if 0
1937 ASSERT(m_targetPathList.GetCount() == 1);
1938 sWindowTitle.LoadString(IDS_PROGRS_TITLE_COPY);
1939 SetWindowText(sWindowTitle); // needs to be updated, see TSVN rev. 21375
1940 SetBackgroundImage(IDI_COPY_BKG);
1942 CString sCmdInfo;
1943 sCmdInfo.Format(IDS_PROGRS_CMD_COPY,
1944 m_targetPathList[0].IsUrl() ? (LPCTSTR)m_targetPathList[0].GetSVNPathString() : m_targetPathList[0].GetWinPath(),
1945 (LPCTSTR)m_url.GetSVNPathString(), (LPCTSTR)m_Revision.ToString());
1946 ReportCmd(sCmdInfo);
1948 if (!Copy(m_targetPathList, m_url, m_Revision, m_pegRev, m_sMessage))
1950 ReportSVNError();
1951 return false;
1953 if (m_options & ProgOptSwitchAfterCopy)
1955 sCmdInfo.Format(IDS_PROGRS_CMD_SWITCH,
1956 m_targetPathList[0].GetWinPath(),
1957 (LPCTSTR)m_url.GetSVNPathString(), (LPCTSTR)m_Revision.ToString());
1958 ReportCmd(sCmdInfo);
1959 if (!Switch(m_targetPathList[0], m_url, SVNRev::REV_HEAD, SVNRev::REV_HEAD, m_depth, TRUE, m_options & ProgOptIgnoreExternals))
1961 if (!Switch(m_targetPathList[0], m_url, SVNRev::REV_HEAD, m_Revision, m_depth, TRUE, m_options & ProgOptIgnoreExternals))
1963 ReportSVNError();
1964 return false;
1968 else
1970 if (SVN::PathIsURL(m_url))
1972 CString sMsg(MAKEINTRESOURCE(IDS_PROGRS_COPY_WARNING));
1973 ReportNotification(sMsg);
1976 #endif
1977 return true;
1980 bool CGitProgressDlg::CmdExport(CString& /*sWindowTitle*/, bool& /*localoperation*/)
1982 #if 0
1983 ASSERT(m_targetPathList.GetCount() == 1);
1984 sWindowTitle.LoadString(IDS_PROGRS_TITLE_EXPORT);
1985 sWindowTitle = m_url.GetUIFileOrDirectoryName()+_T(" - ")+sWindowTitle;
1986 SetWindowText(sWindowTitle); // needs to be updated, see TSVN rev. 21375
1987 SetBackgroundImage(IDI_EXPORT_BKG);
1988 CString eol;
1989 if (m_options & ProgOptEolCRLF)
1990 eol = _T("CRLF");
1991 if (m_options & ProgOptEolLF)
1992 eol = _T("LF");
1993 if (m_options & ProgOptEolCR)
1994 eol = _T("CR");
1995 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_EXPORT)));
1996 if (!Export(m_url, m_targetPathList[0], m_Revision, m_Revision, TRUE, m_options & ProgOptIgnoreExternals, m_depth, NULL, FALSE, eol))
1998 ReportSVNError();
1999 return false;
2001 #endif
2002 return true;
2005 bool CGitProgressDlg::CmdRename(CString& /*sWindowTitle*/, bool& /*localoperation*/)
2007 #if 0
2008 ASSERT(m_targetPathList.GetCount() == 1);
2009 if ((!m_targetPathList[0].IsUrl())&&(!m_url.IsUrl()))
2010 localoperation = true;
2011 sWindowTitle.LoadString(IDS_PROGRS_TITLE_RENAME);
2012 SetWindowText(sWindowTitle); // needs to be updated, see TSVN rev. 21375
2013 SetBackgroundImage(IDI_RENAME_BKG);
2014 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RENAME)));
2015 if (!Move(m_targetPathList, m_url, m_Revision, m_sMessage))
2017 ReportSVNError();
2018 return false;
2020 #endif
2021 return true;
2024 bool CGitProgressDlg::CmdResolve(CString& sWindowTitle, bool& localoperation)
2027 localoperation = true;
2028 ASSERT(m_targetPathList.GetCount() == 1);
2029 sWindowTitle.LoadString(IDS_PROGRS_TITLE_RESOLVE);
2030 CAppUtils::SetWindowTitle(m_hWnd, m_targetPathList.GetCommonRoot().GetUIPathString(), sWindowTitle);
2031 SetBackgroundImage(IDI_RESOLVE_BKG);
2032 // check if the file may still have conflict markers in it.
2033 //BOOL bMarkers = FALSE;
2035 for(int i=0;i<m_targetPathList.GetCount();i++)
2037 CString cmd,out,tempmergefile;
2038 cmd.Format(_T("git.exe add -f -- \"%s\""),m_targetPathList[i].GetGitPathString());
2039 if(g_Git.Run(cmd,&out,CP_ACP))
2041 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
2042 m_bErrorsOccurred=true;
2043 return false;
2046 CAppUtils::RemoveTempMergeFile((CTGitPath &)m_targetPathList[i]);
2048 Notify(m_targetPathList[i],git_wc_notify_resolved);
2050 #if 0
2051 if ((m_options & ProgOptSkipConflictCheck) == 0)
2055 for (INT_PTR fileindex=0; (fileindex<m_targetPathList.GetCount()) && (bMarkers==FALSE); ++fileindex)
2057 if (!m_targetPathList[fileindex].IsDirectory())
2059 CStdioFile file(m_targetPathList[fileindex].GetWinPath(), CFile::typeBinary | CFile::modeRead);
2060 CString strLine = _T("");
2061 while (file.ReadString(strLine))
2063 if (strLine.Find(_T("<<<<<<<"))==0)
2065 bMarkers = TRUE;
2066 break;
2069 file.Close();
2073 catch (CFileException* pE)
2075 TRACE(_T("CFileException in Resolve!\n"));
2076 TCHAR error[10000] = {0};
2077 pE->GetErrorMessage(error, 10000);
2078 ReportError(error);
2079 pE->Delete();
2080 return false;
2083 if (bMarkers)
2085 if (CMessageBox::Show(m_hWnd, IDS_PROGRS_REVERTMARKERS, IDS_APPNAME, MB_YESNO | MB_ICONQUESTION)==IDYES)
2087 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RESOLVE)));
2088 for (INT_PTR fileindex=0; fileindex<m_targetPathList.GetCount(); ++fileindex)
2089 Resolve(m_targetPathList[fileindex], svn_wc_conflict_choose_merged, true);
2092 else
2094 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RESOLVE)));
2095 for (INT_PTR fileindex=0; fileindex<m_targetPathList.GetCount(); ++fileindex)
2096 Resolve(m_targetPathList[fileindex], svn_wc_conflict_choose_merged, true);
2098 #endif
2099 CShellUpdater::Instance().AddPathsForUpdate(m_targetPathList);
2101 this->GetDlgItem(IDC_LOGBUTTON)->SetWindowText(_T("Commit ..."));
2102 this->GetDlgItem(IDC_LOGBUTTON)->ShowWindow(SW_SHOW);
2104 return true;
2107 bool CGitProgressDlg::CmdRevert(CString& sWindowTitle, bool& localoperation)
2110 localoperation = true;
2111 sWindowTitle.LoadString(IDS_PROGRS_TITLE_REVERT);
2112 CAppUtils::SetWindowTitle(m_hWnd, m_targetPathList.GetCommonRoot().GetUIPathString(), sWindowTitle);
2113 SetBackgroundImage(IDI_REVERT_BKG);
2115 CTGitPathList delList;
2116 for(int i=0;i<m_selectedPaths.GetCount();i++)
2118 CTGitPath path;
2119 int action;
2120 path.SetFromWin(g_Git.m_CurrentDir+_T("\\")+m_selectedPaths[i].GetWinPath());
2121 action = m_selectedPaths[i].m_Action;
2122 /* rename file can't delete because it needs original file*/
2123 if((!(action & CTGitPath::LOGACTIONS_ADDED)) &&
2124 (!(action & CTGitPath::LOGACTIONS_REPLACED)))
2125 delList.AddPath(path);
2127 if (DWORD(CRegDWORD(_T("Software\\TortoiseGit\\RevertWithRecycleBin"), TRUE)))
2128 delList.DeleteAllFiles(true);
2130 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_REVERT)));
2131 for(int i=0;i<m_selectedPaths.GetCount();i++)
2133 if(g_Git.Revert(_T("HEAD"), (CTGitPath&)m_selectedPaths[i]))
2135 CMessageBox::Show(NULL,_T("Revert Fail"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
2136 m_bErrorsOccurred=true;
2137 return false;
2139 Notify(m_selectedPaths[i],git_wc_notify_revert);
2142 CShellUpdater::Instance().AddPathsForUpdate(m_selectedPaths);
2144 return true;
2147 bool CGitProgressDlg::CmdSwitch(CString& /*sWindowTitle*/, bool& /*localoperation*/)
2149 #if 0
2150 ASSERT(m_targetPathList.GetCount() == 1);
2151 SVNStatus st;
2152 sWindowTitle.LoadString(IDS_PROGRS_TITLE_SWITCH);
2153 SetWindowText(sWindowTitle); // needs to be updated, see TSVN rev. 21375
2154 SetBackgroundImage(IDI_SWITCH_BKG);
2155 LONG rev = 0;
2156 if (st.GetStatus(m_targetPathList[0]) != (-2))
2158 if (st.status->entry != NULL)
2160 rev = st.status->entry->revision;
2164 CString sCmdInfo;
2165 sCmdInfo.Format(IDS_PROGRS_CMD_SWITCH,
2166 m_targetPathList[0].GetWinPath(), (LPCTSTR)m_url.GetSVNPathString(),
2167 (LPCTSTR)m_Revision.ToString());
2168 ReportCmd(sCmdInfo);
2170 bool depthIsSticky = true;
2171 if (m_depth == svn_depth_unknown)
2172 depthIsSticky = false;
2173 if (!Switch(m_targetPathList[0], m_url, m_Revision, m_Revision, m_depth, depthIsSticky, m_options & ProgOptIgnoreExternals))
2175 ReportSVNError();
2176 return false;
2178 m_UpdateStartRevMap[m_targetPathList[0].GetSVNApiPath(pool)] = rev;
2179 if ((m_RevisionEnd >= 0)&&(rev >= 0)
2180 &&((LONG)m_RevisionEnd > (LONG)rev))
2182 GetDlgItem(IDC_LOGBUTTON)->ShowWindow(SW_SHOW);
2184 #endif
2185 return true;
2188 void CGitProgressDlg::OnBnClickedNoninteractive()
2190 LRESULT res = ::SendMessage(GetDlgItem(IDC_NONINTERACTIVE)->GetSafeHwnd(), BM_GETCHECK, 0, 0);
2191 m_AlwaysConflicted = (res == BST_CHECKED);
2192 CRegDWORD nonint = CRegDWORD(_T("Software\\TortoiseGit\\MergeNonInteractive"), FALSE);
2193 nonint = m_AlwaysConflicted;
2196 CString CGitProgressDlg::GetPathFromColumnText(const CString& sColumnText)
2198 CString sPath = CPathUtils::ParsePathInString(sColumnText);
2199 if (sPath.Find(':')<0)
2201 // the path is not absolute: add the common root of all paths to it
2202 sPath = m_targetPathList.GetCommonRoot().GetDirectory().GetWinPathString() + _T("\\") + CPathUtils::ParsePathInString(sColumnText);
2204 return sPath;
2207 bool CGitProgressDlg::CmdSendMail(CString& sWindowTitle, bool& /*localoperation*/)
2209 sWindowTitle.LoadString(IDS_PROGRS_TITLE_SENDMAIL);
2210 CAppUtils::SetWindowTitle(m_hWnd, m_targetPathList.GetCommonRoot().GetUIPathString(), sWindowTitle);
2211 //SetBackgroundImage(IDI_ADD_BKG);
2212 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_SENDMAIL)));
2213 bool ret=true;
2214 if(this->m_SendMailFlags&SENDMAIL_COMBINED)
2216 CString error;
2217 CTGitPath path;
2218 Notify(path,git_wc_notify_sendmail_start);
2219 CString err;
2220 int retry=0;
2221 while(retry <3)
2223 if(!!CPatch::SendPatchesCombined(m_targetPathList,m_SendMailTO,m_SendMailCC,m_SendMailSubject,!!(this->m_SendMailFlags&SENDMAIL_ATTACHMENT),!!(this->m_SendMailFlags&SENDMAIL_MAPI),&err))
2225 Notify(path,git_wc_notify_sendmail_error,ret,&err);
2226 ret = false;
2228 else
2230 break;
2233 retry++;
2234 if (retry < 3)
2235 Notify(path,git_wc_notify_sendmail_retry,ret,&err);
2236 Sleep(2000);
2237 if(m_bCancelled)
2239 CString str(_T("User Canceled"));
2240 Notify(path,git_wc_notify_sendmail_error,ret,&str);
2241 return false;
2244 if (ret)
2245 Notify(path,git_wc_notify_sendmail_done,ret);
2247 else
2249 for(int i=0;ret && i<m_targetPathList.GetCount();i++)
2251 CPatch patch;
2252 Notify(m_targetPathList[i],git_wc_notify_sendmail_start);
2254 int retry=0;
2255 while(retry<3)
2257 if(!!patch.Send((CString&)m_targetPathList[i].GetWinPathString(),this->m_SendMailTO,
2258 this->m_SendMailCC,!!(this->m_SendMailFlags&SENDMAIL_ATTACHMENT),!!(this->m_SendMailFlags&SENDMAIL_MAPI)))
2260 Notify(m_targetPathList[i],git_wc_notify_sendmail_error,ret,&patch.m_LastError);
2261 ret = false;
2264 else
2266 ret = true;
2267 break;
2269 retry++;
2270 if (retry < 3)
2271 Notify(m_targetPathList[i],git_wc_notify_sendmail_retry,ret,&patch.m_LastError);
2272 Sleep(2000);
2273 if(m_bCancelled)
2275 CString str(_T("User Canceled"));
2276 Notify(m_targetPathList[i],git_wc_notify_sendmail_error,ret,&str);
2277 return false;
2280 if (ret)
2281 Notify(m_targetPathList[i],git_wc_notify_sendmail_done,ret);
2284 return ret;
2287 LRESULT CGitProgressDlg::OnTaskbarBtnCreated(WPARAM /*wParam*/, LPARAM /*lParam*/)
2289 m_pTaskbarList.Release();
2290 m_pTaskbarList.CoCreateInstance(CLSID_TaskbarList);
2291 return 0;