1 // GitLogList.cpp : implementation file
\r
4 Description: qgit revision list view
\r
6 Author: Marco Costalba (C) 2005-2007
\r
8 Copyright: See COPYING file that comes with this distribution
\r
12 #include "GitLogListBase.h"
\r
14 //#include "VssStyle.h"
\r
15 #include "IconMenu.h"
\r
18 #include "InputDlg.h"
\r
19 #include "PropDlg.h"
\r
20 #include "SVNProgressDlg.h"
\r
21 #include "ProgressDlg.h"
\r
22 //#include "RepositoryBrowser.h"
\r
23 //#include "CopyDlg.h"
\r
24 //#include "StatGraphDlg.h"
\r
26 #include "MessageBox.h"
\r
27 #include "Registry.h"
\r
28 #include "AppUtils.h"
\r
29 #include "PathUtils.h"
\r
30 #include "StringUtils.h"
\r
31 #include "UnicodeUtils.h"
\r
32 #include "TempFile.h"
\r
33 //#include "GitInfo.h"
\r
34 //#include "GitDiff.h"
\r
35 #include "IconMenu.h"
\r
36 //#include "RevisionRangeDlg.h"
\r
37 //#include "BrowseFolder.h"
\r
38 //#include "BlameDlg.h"
\r
39 //#include "Blame.h"
\r
40 //#include "GitHelpers.h"
\r
41 #include "GitStatus.h"
\r
42 //#include "LogDlgHelper.h"
\r
43 //#include "CachedLogInfo.h"
\r
44 //#include "RepositoryInfo.h"
\r
45 //#include "EditPropertiesDlg.h"
\r
46 #include "FileDiffDlg.h"
\r
47 #include "..\\TortoiseShell\\Resource.h"
\r
50 IMPLEMENT_DYNAMIC(CGitLogListBase, CHintListCtrl)
\r
52 CGitLogListBase::CGitLogListBase():CHintListCtrl()
\r
53 ,m_regMaxBugIDColWidth(_T("Software\\TortoiseGit\\MaxBugIDColWidth"), 200)
\r
55 ,m_bNoDispUpdates(FALSE)
\r
56 , m_bThreadRunning(FALSE)
\r
57 , m_bStrictStopped(false)
\r
58 , m_pStoreSelection(NULL)
\r
59 , m_nSelectedFilter(LOGFILTER_ALL)
\r
61 // use the default GUI font, create a copy of it and
\r
62 // change the copy to BOLD (leave the rest of the font
\r
64 HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
\r
66 GetObject(hFont, sizeof(LOGFONT), &lf);
\r
67 lf.lfWeight = FW_BOLD;
\r
68 m_boldFont = CreateFontIndirect(&lf);
\r
70 m_bShowBugtraqColumn=0;
\r
72 m_IsIDReplaceAction=FALSE;
\r
74 m_wcRev.m_CommitHash=GIT_REV_ZERO;
\r
75 m_wcRev.m_Subject=_T("Working Copy");
\r
77 m_hModifiedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONMODIFIED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
\r
78 m_hReplacedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONREPLACED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
\r
79 m_hAddedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONADDED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
\r
80 m_hDeletedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONDELETED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
\r
82 m_bFilterWithRegex = !!CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), TRUE);
\r
84 g_Git.GetMapHashToFriendName(m_HashMap);
\r
85 m_CurrentBranch=g_Git.GetCurrentBranch();
\r
87 m_From=CTime(1970,1,2,0,0,0);
\r
88 m_To=CTime::GetCurrentTime();
\r
90 m_LoadingThread = NULL;
\r
92 m_bExitThread=FALSE;
\r
94 for(int i=0;i<Lanes::COLORS_NUM;i++)
\r
96 m_LineColors[i] = m_Colors.GetColor((CColors::Colors)(CColors::BranchLine1+i));
\r
98 // get short/long datetime setting from registry
\r
99 DWORD RegUseShortDateFormat = CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE);
\r
100 if ( RegUseShortDateFormat )
\r
102 m_DateFormat = DATE_SHORTDATE;
\r
106 m_DateFormat = DATE_LONGDATE;
\r
108 // get relative time display setting from registry
\r
109 DWORD regRelativeTimes = CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE);
\r
110 m_bRelativeTimes = (regRelativeTimes != 0);
\r
113 CGitLogListBase::~CGitLogListBase()
\r
115 InterlockedExchange(&m_bNoDispUpdates, TRUE);
\r
117 DestroyIcon(m_hModifiedIcon);
\r
118 DestroyIcon(m_hReplacedIcon);
\r
119 DestroyIcon(m_hAddedIcon);
\r
120 DestroyIcon(m_hDeletedIcon);
\r
121 m_logEntries.ClearAll();
\r
124 DeleteObject(m_boldFont);
\r
126 if ( m_pStoreSelection )
\r
128 delete m_pStoreSelection;
\r
129 m_pStoreSelection = NULL;
\r
132 if(this->m_bThreadRunning)
\r
134 m_bExitThread=true;
\r
135 WaitForSingleObject(m_LoadingThread->m_hThread,1000);
\r
141 BEGIN_MESSAGE_MAP(CGitLogListBase, CHintListCtrl)
\r
142 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnNMCustomdrawLoglist)
\r
143 ON_NOTIFY_REFLECT(LVN_GETDISPINFO, OnLvnGetdispinfoLoglist)
\r
144 ON_WM_CONTEXTMENU()
\r
145 ON_NOTIFY_REFLECT(NM_DBLCLK, OnNMDblclkLoglist)
\r
146 ON_NOTIFY_REFLECT(LVN_ODFINDITEM,OnLvnOdfinditemLoglist)
\r
149 ON_MESSAGE(MSG_LOADED,OnLoad)
\r
152 int CGitLogListBase:: OnCreate(LPCREATESTRUCT lpCreateStruct)
\r
154 PreSubclassWindow();
\r
155 return CHintListCtrl::OnCreate(lpCreateStruct);
\r
158 void CGitLogListBase::PreSubclassWindow()
\r
160 SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_SUBITEMIMAGES);
\r
161 // load the icons for the action columns
\r
162 m_Theme.SetWindowTheme(GetSafeHwnd(), L"Explorer", NULL);
\r
163 CHintListCtrl::PreSubclassWindow();
\r
166 void CGitLogListBase::InsertGitColumn()
\r
170 int c = ((CHeaderCtrl*)(GetDlgItem(0)))->GetItemCount()-1;
\r
174 temp.LoadString(IDS_LOG_GRAPH);
\r
176 InsertColumn(this->LOGLIST_GRAPH, temp);
\r
179 // make the revision column right aligned
\r
181 Column.mask = LVCF_FMT;
\r
182 Column.fmt = LVCFMT_RIGHT;
\r
183 SetColumn(0, &Column);
\r
186 // g_Git.GetLog(log);
\r
188 if(m_IsIDReplaceAction)
\r
190 temp.LoadString(IDS_LOG_ID);
\r
191 InsertColumn(this->LOGLIST_ACTION, temp);
\r
195 temp.LoadString(IDS_LOG_ACTIONS);
\r
196 InsertColumn(this->LOGLIST_ACTION, temp);
\r
198 temp.LoadString(IDS_LOG_MESSAGE);
\r
199 InsertColumn(this->LOGLIST_MESSAGE, temp);
\r
201 temp.LoadString(IDS_LOG_AUTHOR);
\r
202 InsertColumn(this->LOGLIST_AUTHOR, temp);
\r
204 temp.LoadString(IDS_LOG_DATE);
\r
205 InsertColumn(this->LOGLIST_DATE, temp);
\r
208 if (m_bShowBugtraqColumn)
\r
210 // temp = m_ProjectProperties.sLabel;
\r
211 if (temp.IsEmpty())
\r
212 temp.LoadString(IDS_LOG_BUGIDS);
\r
213 InsertColumn(this->LOGLIST_BUG, temp);
\r
218 ResizeAllListCtrlCols();
\r
224 * Resizes all columns in a list control to values in registry.
\r
226 void CGitLogListBase::ResizeAllListCtrlCols()
\r
228 // column max and min widths to allow
\r
229 static const int nMinimumWidth = 10;
\r
230 static const int nMaximumWidth = 1000;
\r
231 CHeaderCtrl* pHdrCtrl = (CHeaderCtrl*)(GetDlgItem(0));
\r
234 int numcols = pHdrCtrl->GetItemCount();
\r
235 for (int col = 0; col < numcols; col++)
\r
237 // get width for this col last time from registry
\r
239 regentry.Format( _T("Software\\TortoiseGit\\log\\ColWidth%d"), col);
\r
240 CRegDWORD regwidth(regentry, 0);
\r
244 // no saved value, setup sensible defaults
\r
245 if (col == this->LOGLIST_MESSAGE)
\r
247 cx = LOGLIST_MESSAGE_MIN;
\r
251 cx = ICONITEMBORDER+16*4;
\r
254 if (cx < nMinimumWidth)
\r
256 cx = nMinimumWidth;
\r
257 } else if (cx > nMaximumWidth)
\r
259 cx = nMaximumWidth;
\r
262 SetColumnWidth(col, cx);
\r
269 BOOL CGitLogListBase::GetShortName(CString ref, CString &shortname,CString prefix)
\r
271 TRACE(_T("%s %s\r\n"),ref,prefix);
\r
272 if(ref.Left(prefix.GetLength()) == prefix)
\r
274 shortname = ref.Right(ref.GetLength()-prefix.GetLength());
\r
275 if(shortname.Right(3)==_T("^{}"))
\r
276 shortname=shortname.Left(shortname.GetLength()-3);
\r
281 void CGitLogListBase::FillBackGround(HDC hdc, int Index,CRect &rect)
\r
285 SecureZeroMemory(&rItem, sizeof(LVITEM));
\r
286 rItem.mask = LVIF_STATE;
\r
287 rItem.iItem = Index;
\r
288 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
\r
291 if (m_Theme.IsAppThemed() && m_bVista)
\r
293 m_Theme.Open(m_hWnd, L"Explorer");
\r
294 int state = LISS_NORMAL;
\r
295 if (rItem.state & LVIS_SELECTED)
\r
297 if (::GetFocus() == m_hWnd)
\r
298 state |= LISS_SELECTED;
\r
300 state |= LISS_SELECTEDNOTFOCUS;
\r
305 if (pLogEntry->bCopiedSelf)
\r
307 // unfortunately, the pLVCD->nmcd.uItemState does not contain valid
\r
308 // information at this drawing stage. But we can check the whether the
\r
309 // previous stage changed the background color of the item
\r
310 if (pLVCD->clrTextBk == GetSysColor(COLOR_MENU))
\r
313 brush = ::CreateSolidBrush(::GetSysColor(COLOR_MENU));
\r
316 ::FillRect(pLVCD->nmcd.hdc, &rect, brush);
\r
317 ::DeleteObject(brush);
\r
324 if (m_Theme.IsBackgroundPartiallyTransparent(LVP_LISTDETAIL, state))
\r
325 m_Theme.DrawParentBackground(m_hWnd, hdc, &rect);
\r
327 m_Theme.DrawBackground(hdc, LVP_LISTDETAIL, state, &rect, NULL);
\r
332 if (rItem.state & LVIS_SELECTED)
\r
334 if (::GetFocus() == m_hWnd)
\r
335 brush = ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT));
\r
337 brush = ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE));
\r
341 //if (pLogEntry->bCopiedSelf)
\r
342 // brush = ::CreateSolidBrush(::GetSysColor(COLOR_MENU));
\r
344 brush = ::CreateSolidBrush(::GetSysColor(COLOR_WINDOW));
\r
349 ::FillRect(hdc, &rect, brush);
\r
350 ::DeleteObject(brush);
\r
355 void CGitLogListBase::DrawTagBranch(HDC hdc,CRect &rect,INT_PTR index)
\r
357 GitRev* data = (GitRev*)m_arShownList.GetAt(index);
\r
360 SecureZeroMemory(&rItem, sizeof(LVITEM));
\r
361 rItem.mask = LVIF_STATE;
\r
362 rItem.iItem = index;
\r
363 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
\r
366 for(unsigned int i=0;i<m_HashMap[data->m_CommitHash].size();i++)
\r
369 str=m_HashMap[data->m_CommitHash][i];
\r
374 if(GetShortName(str,shortname,_T("refs/heads/")))
\r
376 if( shortname == m_CurrentBranch )
\r
377 brush = ::CreateSolidBrush(m_Colors.GetColor(CColors::CurrentBranch));
\r
379 brush = ::CreateSolidBrush(m_Colors.GetColor(CColors::LocalBranch));
\r
381 }else if(GetShortName(str,shortname,_T("refs/remotes/")))
\r
383 brush = ::CreateSolidBrush(m_Colors.GetColor(CColors::RemoteBranch));
\r
385 else if(GetShortName(str,shortname,_T("refs/tags/")))
\r
387 brush = ::CreateSolidBrush(m_Colors.GetColor(CColors::Tag));
\r
390 if(!shortname.IsEmpty())
\r
393 memset(&size,0,sizeof(SIZE));
\r
394 GetTextExtentPoint32(hdc, shortname,shortname.GetLength(),&size);
\r
396 rt.SetRect(rt.left,rt.top,rt.left+size.cx,rt.bottom);
\r
398 ::FillRect(hdc, &rt, brush);
\r
399 if (rItem.state & LVIS_SELECTED)
\r
401 COLORREF clrOld = ::SetTextColor(hdc,::GetSysColor(COLOR_HIGHLIGHTTEXT));
\r
402 ::DrawText(hdc,shortname,shortname.GetLength(),&rt,DT_CENTER);
\r
403 ::SetTextColor(hdc,clrOld);
\r
406 ::DrawText(hdc,shortname,shortname.GetLength(),&rt,DT_CENTER);
\r
410 ::MoveToEx(hdc,rt.left,rt.top,NULL);
\r
411 ::LineTo(hdc,rt.right,rt.top);
\r
412 ::LineTo(hdc,rt.right,rt.bottom);
\r
413 ::LineTo(hdc,rt.left,rt.bottom);
\r
414 ::LineTo(hdc,rt.left,rt.top);
\r
416 rt.left=rt.right+3;
\r
419 ::DeleteObject(brush);
\r
421 rt.right=rect.right;
\r
423 if (rItem.state & LVIS_SELECTED)
\r
425 COLORREF clrOld = ::SetTextColor(hdc,::GetSysColor(COLOR_HIGHLIGHTTEXT));
\r
426 ::DrawText(hdc,data->m_Subject,data->m_Subject.GetLength(),&rt,DT_LEFT);
\r
427 ::SetTextColor(hdc,clrOld);
\r
430 ::DrawText(hdc,data->m_Subject,data->m_Subject.GetLength(),&rt,DT_LEFT);
\r
435 void CGitLogListBase::paintGraphLane(HDC hdc, int laneHeight,int type, int x1, int x2,
\r
436 const COLORREF& col,int top
\r
439 int h = laneHeight / 2;
\r
440 int m = (x1 + x2) / 2;
\r
441 int r = (x2 - x1) / 3;
\r
444 #define P_CENTER m , h+top
\r
445 #define P_0 x2, h+top
\r
446 #define P_90 m , 0+top
\r
447 #define P_180 x1, h+top
\r
448 #define P_270 m , 2 * h+top
\r
449 #define R_CENTER m - r, h - r+top, m - r+d, h - r+top+d
\r
451 //static QPen myPen(Qt::black, 2); // fast path here
\r
453 pen.CreatePen(PS_SOLID,2,col);
\r
454 //myPen.setColor(col);
\r
455 HPEN oldpen=(HPEN)::SelectObject(hdc,(HPEN)pen);
\r
457 //p->setPen(myPen);
\r
461 case Lanes::ACTIVE:
\r
462 case Lanes::NOT_ACTIVE:
\r
463 case Lanes::MERGE_FORK:
\r
464 case Lanes::MERGE_FORK_R:
\r
465 case Lanes::MERGE_FORK_L:
\r
467 case Lanes::JOIN_R:
\r
468 case Lanes::JOIN_L:
\r
469 DrawLine(hdc,P_90,P_270);
\r
470 //p->drawLine(P_90, P_270);
\r
473 case Lanes::HEAD_R:
\r
474 case Lanes::HEAD_L:
\r
475 case Lanes::BRANCH:
\r
476 DrawLine(hdc,P_CENTER,P_270);
\r
477 //p->drawLine(P_CENTER, P_270);
\r
480 case Lanes::TAIL_R:
\r
481 case Lanes::TAIL_L:
\r
482 case Lanes::INITIAL:
\r
483 case Lanes::BOUNDARY:
\r
484 case Lanes::BOUNDARY_C:
\r
485 case Lanes::BOUNDARY_R:
\r
486 case Lanes::BOUNDARY_L:
\r
487 DrawLine(hdc,P_90, P_CENTER);
\r
488 //p->drawLine(P_90, P_CENTER);
\r
496 case Lanes::MERGE_FORK:
\r
501 case Lanes::CROSS_EMPTY:
\r
502 case Lanes::BOUNDARY_C:
\r
503 DrawLine(hdc,P_180,P_0);
\r
504 //p->drawLine(P_180, P_0);
\r
506 case Lanes::MERGE_FORK_R:
\r
507 case Lanes::JOIN_R:
\r
508 case Lanes::HEAD_R:
\r
509 case Lanes::TAIL_R:
\r
510 case Lanes::BOUNDARY_R:
\r
511 DrawLine(hdc,P_180,P_CENTER);
\r
512 //p->drawLine(P_180, P_CENTER);
\r
514 case Lanes::MERGE_FORK_L:
\r
515 case Lanes::JOIN_L:
\r
516 case Lanes::HEAD_L:
\r
517 case Lanes::TAIL_L:
\r
518 case Lanes::BOUNDARY_L:
\r
519 DrawLine(hdc,P_CENTER,P_0);
\r
520 //p->drawLine(P_CENTER, P_0);
\r
527 brush.CreateSolidBrush(col);
\r
528 HBRUSH oldbrush=(HBRUSH)::SelectObject(hdc,(HBRUSH)brush);
\r
529 // center symbol, e.g. rect or ellipse
\r
531 case Lanes::ACTIVE:
\r
532 case Lanes::INITIAL:
\r
533 case Lanes::BRANCH:
\r
535 //p->setPen(Qt::NoPen);
\r
536 //p->setBrush(col);
\r
537 ::Ellipse(hdc, R_CENTER);
\r
538 //p->drawEllipse(R_CENTER);
\r
540 case Lanes::MERGE_FORK:
\r
541 case Lanes::MERGE_FORK_R:
\r
542 case Lanes::MERGE_FORK_L:
\r
543 //p->setPen(Qt::NoPen);
\r
544 //p->setBrush(col);
\r
545 //p->drawRect(R_CENTER);
\r
546 Rectangle(hdc,R_CENTER);
\r
548 case Lanes::UNAPPLIED:
\r
550 //p->setPen(Qt::NoPen);
\r
551 //p->setBrush(Qt::red);
\r
552 //p->drawRect(m - r, h - 1, d, 2);
\r
553 ::Rectangle(hdc,m-r,h-1,d,2);
\r
555 case Lanes::APPLIED:
\r
557 //p->setPen(Qt::NoPen);
\r
558 //p->setBrush(DARK_GREEN);
\r
559 //p->drawRect(m - r, h - 1, d, 2);
\r
560 //p->drawRect(m - 1, h - r, 2, d);
\r
561 ::Rectangle(hdc,m-r,h-1,d,2);
\r
562 ::Rectangle(hdc,m-1,h-r,2,d);
\r
564 case Lanes::BOUNDARY:
\r
565 //p->setBrush(back);
\r
566 //p->drawEllipse(R_CENTER);
\r
567 ::Ellipse(hdc, R_CENTER);
\r
569 case Lanes::BOUNDARY_C:
\r
570 case Lanes::BOUNDARY_R:
\r
571 case Lanes::BOUNDARY_L:
\r
572 //p->setBrush(back);
\r
573 //p->drawRect(R_CENTER);
\r
574 ::Rectangle(hdc,R_CENTER);
\r
580 ::SelectObject(hdc,oldpen);
\r
581 ::SelectObject(hdc,oldbrush);
\r
590 void CGitLogListBase::DrawGraph(HDC hdc,CRect &rect,INT_PTR index)
\r
594 GitRev* data = (GitRev*)m_arShownList.GetAt(index);
\r
597 SecureZeroMemory(&rItem, sizeof(LVITEM));
\r
598 rItem.mask = LVIF_STATE;
\r
599 rItem.iItem = index;
\r
600 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
\r
604 // p->translate(QPoint(opt.rect.left(), opt.rect.top()));
\r
608 if (data->m_Lanes.size() == 0)
\r
609 m_logEntries.setLane(data->m_CommitHash);
\r
611 std::vector<int>& lanes=data->m_Lanes;
\r
612 UINT laneNum = lanes.size();
\r
613 UINT mergeLane = 0;
\r
614 for (UINT i = 0; i < laneNum; i++)
\r
615 if (Lanes::isMerge(lanes[i])) {
\r
620 int x1 = 0, x2 = 0;
\r
621 int maxWidth = rect.Width();
\r
622 int lw = 3 * rect.Height() / 4; //laneWidth()
\r
623 for (UINT i = 0; i < laneNum && x2 < maxWidth; i++) {
\r
629 if (ln == Lanes::EMPTY)
\r
632 UINT col = ( Lanes:: isHead(ln) ||Lanes:: isTail(ln) || Lanes::isJoin(ln)
\r
633 || ln ==Lanes:: CROSS_EMPTY) ? mergeLane : i;
\r
635 if (ln == Lanes::CROSS) {
\r
636 paintGraphLane(hdc, rect.Height(),Lanes::NOT_ACTIVE, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
\r
637 paintGraphLane(hdc, rect.Height(),Lanes::CROSS, x1, x2, m_LineColors[mergeLane % Lanes::COLORS_NUM],rect.top);
\r
639 paintGraphLane(hdc, rect.Height(),ln, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
\r
642 TRACE(_T("index %d %d\r\n"),index,data->m_Lanes.size());
\r
645 void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR *pNMHDR, LRESULT *pResult)
\r
648 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
\r
649 // Take the default processing unless we set this to something else below.
\r
650 *pResult = CDRF_DODEFAULT;
\r
652 if (m_bNoDispUpdates)
\r
657 switch (pLVCD->nmcd.dwDrawStage)
\r
659 case CDDS_PREPAINT:
\r
661 *pResult = CDRF_NOTIFYITEMDRAW;
\r
665 case CDDS_ITEMPREPAINT:
\r
667 // This is the prepaint stage for an item. Here's where we set the
\r
668 // item's text color.
\r
670 // Tell Windows to send draw notifications for each subitem.
\r
671 *pResult = CDRF_NOTIFYSUBITEMDRAW;
\r
673 COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);
\r
675 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
\r
677 GitRev* data = (GitRev*)m_arShownList.GetAt(pLVCD->nmcd.dwItemSpec);
\r
681 if (data->bCopiedSelf)
\r
683 // only change the background color if the item is not 'hot' (on vista with m_Themes enabled)
\r
684 if (!m_Theme.IsAppm_Themed() || !m_bVista || ((pLVCD->nmcd.uItemState & CDIS_HOT)==0))
\r
685 pLVCD->clrTextBk = GetSysColor(COLOR_MENU);
\r
689 crText = m_Colors.GetColor(CColors::Modified);
\r
691 // if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))
\r
692 // crText = GetSysColor(COLOR_GRAYTEXT);
\r
693 // if (data->Rev == m_wcRev)
\r
695 // SelectObject(pLVCD->nmcd.hdc, m_boldFont);
\r
696 // We changed the font, so we're returning CDRF_NEWFONT. This
\r
697 // tells the control to recalculate the extent of the text.
\r
698 // *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
\r
702 if (m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec)
\r
704 if (m_bStrictStopped)
\r
705 crText = GetSysColor(COLOR_GRAYTEXT);
\r
707 // Store the color back in the NMLVCUSTOMDRAW struct.
\r
708 pLVCD->clrText = crText;
\r
712 case CDDS_ITEMPREPAINT|CDDS_ITEM|CDDS_SUBITEM:
\r
714 if ((m_bStrictStopped)&&(m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec))
\r
716 pLVCD->nmcd.uItemState &= ~(CDIS_SELECTED|CDIS_FOCUS);
\r
719 if (pLVCD->iSubItem == LOGLIST_GRAPH)
\r
721 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
\r
724 GetSubItemRect(pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
\r
726 FillBackGround(pLVCD->nmcd.hdc, (INT_PTR)pLVCD->nmcd.dwItemSpec,rect);
\r
727 DrawGraph(pLVCD->nmcd.hdc,rect,pLVCD->nmcd.dwItemSpec);
\r
729 *pResult = CDRF_SKIPDEFAULT;
\r
735 if (pLVCD->iSubItem == LOGLIST_MESSAGE)
\r
737 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
\r
739 GitRev* data = (GitRev*)m_arShownList.GetAt(pLVCD->nmcd.dwItemSpec);
\r
740 //if(!data->m_IsFull)
\r
742 //if(data->SafeFetchFullInfo(&g_Git))
\r
743 // this->Invalidate();
\r
744 //TRACE(_T("Update ... %d\r\n"),pLVCD->nmcd.dwItemSpec);
\r
747 if(m_HashMap[data->m_CommitHash].size()!=0)
\r
751 GetSubItemRect(pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
\r
753 FillBackGround(pLVCD->nmcd.hdc, (INT_PTR)pLVCD->nmcd.dwItemSpec,rect);
\r
754 DrawTagBranch(pLVCD->nmcd.hdc,rect,pLVCD->nmcd.dwItemSpec);
\r
756 *pResult = CDRF_SKIPDEFAULT;
\r
763 if (pLVCD->iSubItem == 1)
\r
765 if(this->m_IsIDReplaceAction)
\r
767 *pResult = CDRF_DODEFAULT;
\r
770 *pResult = CDRF_DODEFAULT;
\r
772 if (m_arShownList.GetCount() <= (INT_PTR)pLVCD->nmcd.dwItemSpec)
\r
776 int iconwidth = ::GetSystemMetrics(SM_CXSMICON);
\r
777 int iconheight = ::GetSystemMetrics(SM_CYSMICON);
\r
779 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_arShownList.GetAt(pLVCD->nmcd.dwItemSpec));
\r
781 GetSubItemRect(pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
\r
782 // Get the selected state of the
\r
783 // item being drawn.
\r
785 // Fill the background
\r
786 FillBackGround(pLVCD->nmcd.hdc, (INT_PTR)pLVCD->nmcd.dwItemSpec,rect);
\r
788 // Draw the icon(s) into the compatible DC
\r
789 if (pLogEntry->m_Action & CTGitPath::LOGACTIONS_MODIFIED)
\r
790 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hModifiedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
\r
793 if (pLogEntry->m_Action & CTGitPath::LOGACTIONS_ADDED)
\r
794 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hAddedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
\r
797 if (pLogEntry->m_Action & CTGitPath::LOGACTIONS_DELETED)
\r
798 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hDeletedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
\r
801 if (pLogEntry->m_Action & CTGitPath::LOGACTIONS_REPLACED)
\r
802 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hReplacedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
\r
804 *pResult = CDRF_SKIPDEFAULT;
\r
810 *pResult = CDRF_DODEFAULT;
\r
814 // CGitLogListBase message handlers
\r
816 void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR *pNMHDR, LRESULT *pResult)
\r
818 NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
\r
820 // Create a pointer to the item
\r
821 LV_ITEM* pItem = &(pDispInfo)->item;
\r
823 // Do the list need text information?
\r
824 if (!(pItem->mask & LVIF_TEXT))
\r
827 // By default, clear text buffer.
\r
828 lstrcpyn(pItem->pszText, _T(""), pItem->cchTextMax);
\r
830 bool bOutOfRange = pItem->iItem >= ShownCountWithStopped();
\r
833 if (m_bNoDispUpdates || bOutOfRange)
\r
836 // Which item number?
\r
837 int itemid = pItem->iItem;
\r
838 GitRev * pLogEntry = NULL;
\r
839 if (itemid < m_arShownList.GetCount())
\r
840 pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.GetAt(pItem->iItem));
\r
843 temp.Format(_T("%d"),m_arShownList.GetCount()-pItem->iItem);
\r
846 switch (pItem->iSubItem)
\r
848 case this->LOGLIST_GRAPH: //Graphic
\r
853 case this->LOGLIST_ACTION: //action -- no text in the column
\r
854 if(this->m_IsIDReplaceAction)
\r
855 lstrcpyn(pItem->pszText, temp, pItem->cchTextMax);
\r
857 case this->LOGLIST_MESSAGE: //Message
\r
859 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->m_Subject, pItem->cchTextMax);
\r
861 case this->LOGLIST_AUTHOR: //Author
\r
863 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->m_AuthorName, pItem->cchTextMax);
\r
865 case this->LOGLIST_DATE: //Date
\r
867 lstrcpyn(pItem->pszText,
\r
868 CAppUtils::FormatDateAndTime( pLogEntry->m_AuthorDate, m_DateFormat, true, m_bRelativeTimes ),
\r
869 pItem->cchTextMax);
\r
880 void CGitLogListBase::OnContextMenu(CWnd* pWnd, CPoint point)
\r
883 int selIndex = GetSelectionMark();
\r
885 return; // nothing selected, nothing to do with a context menu
\r
887 // if the user selected the info text telling about not all revisions shown due to
\r
888 // the "stop on copy/rename" option, we also don't show the context menu
\r
889 if ((m_bStrictStopped)&&(selIndex == m_arShownList.GetCount()))
\r
892 // if the context menu is invoked through the keyboard, we have to use
\r
893 // a calculated position on where to anchor the menu on
\r
894 if ((point.x == -1) && (point.y == -1))
\r
897 GetItemRect(selIndex, &rect, LVIR_LABEL);
\r
898 ClientToScreen(&rect);
\r
899 point = rect.CenterPoint();
\r
901 m_nSearchIndex = selIndex;
\r
902 m_bCancelled = FALSE;
\r
904 // calculate some information the context menu commands can use
\r
905 // CString pathURL = GetURLFromPath(m_path);
\r
907 POSITION pos = GetFirstSelectedItemPosition();
\r
908 int indexNext = GetNextSelectedItem(pos);
\r
912 GitRev* pSelLogEntry = reinterpret_cast<GitRev*>(m_arShownList.GetAt(indexNext));
\r
914 GitRev revSelected = pSelLogEntry->Rev;
\r
915 GitRev revPrevious = git_revnum_t(revSelected)-1;
\r
916 if ((pSelLogEntry->pArChangedPaths)&&(pSelLogEntry->pArChangedPaths->GetCount() <= 2))
\r
918 for (int i=0; i<pSelLogEntry->pArChangedPaths->GetCount(); ++i)
\r
920 LogChangedPath * changedpath = (LogChangedPath *)pSelLogEntry->pArChangedPaths->GetAt(i);
\r
921 if (changedpath->lCopyFromRev)
\r
922 revPrevious = changedpath->lCopyFromRev;
\r
925 GitRev revSelected2;
\r
928 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(GetNextSelectedItem(pos)));
\r
929 revSelected2 = pLogEntry->Rev;
\r
931 bool bAllFromTheSameAuthor = true;
\r
932 CString firstAuthor;
\r
933 CLogDataVector selEntries;
\r
934 GitRev revLowest, revHighest;
\r
935 GitRevRangeArray revisionRanges;
\r
937 POSITION pos = GetFirstSelectedItemPosition();
\r
938 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(GetNextSelectedItem(pos)));
\r
939 revisionRanges.AddRevision(pLogEntry->Rev);
\r
940 selEntries.push_back(pLogEntry);
\r
941 firstAuthor = pLogEntry->sAuthor;
\r
942 revLowest = pLogEntry->Rev;
\r
943 revHighest = pLogEntry->Rev;
\r
946 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(GetNextSelectedItem(pos)));
\r
947 revisionRanges.AddRevision(pLogEntry->Rev);
\r
948 selEntries.push_back(pLogEntry);
\r
949 if (firstAuthor.Compare(pLogEntry->sAuthor))
\r
950 bAllFromTheSameAuthor = false;
\r
951 revLowest = (git_revnum_t(pLogEntry->Rev) > git_revnum_t(revLowest) ? revLowest : pLogEntry->Rev);
\r
952 revHighest = (git_revnum_t(pLogEntry->Rev) < git_revnum_t(revHighest) ? revHighest : pLogEntry->Rev);
\r
958 int FirstSelect=-1, LastSelect=-1;
\r
959 pos = GetFirstSelectedItemPosition();
\r
960 FirstSelect = GetNextSelectedItem(pos);
\r
963 LastSelect = GetNextSelectedItem(pos);
\r
965 //entry is selected, now show the popup menu
\r
967 if (popup.CreatePopupMenu())
\r
969 if (GetSelectedCount() == 1)
\r
972 if (!m_path.IsDirectory())
\r
976 popup.AppendMenuIcon(ID_COMPARE, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
\r
977 popup.AppendMenuIcon(ID_BLAMECOMPARE, IDS_LOG_POPUP_BLAMECOMPARE, IDI_BLAME);
\r
979 popup.AppendMenuIcon(ID_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF_CH, IDI_DIFF);
\r
980 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF);
\r
981 popup.AppendMenu(MF_SEPARATOR, NULL);
\r
982 popup.AppendMenuIcon(ID_SAVEAS, IDS_LOG_POPUP_SAVE, IDI_SAVEAS);
\r
983 popup.AppendMenuIcon(ID_OPEN, IDS_LOG_POPUP_OPEN, IDI_OPEN);
\r
984 popup.AppendMenuIcon(ID_OPENWITH, IDS_LOG_POPUP_OPENWITH, IDI_OPEN);
\r
985 popup.AppendMenuIcon(ID_BLAME, IDS_LOG_POPUP_BLAME, IDI_BLAME);
\r
986 popup.AppendMenu(MF_SEPARATOR, NULL);
\r
993 popup.AppendMenuIcon(ID_COMPARE, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
\r
995 // TortoiseMerge could be improved to take a /blame switch
\r
996 // and then not 'cat' the files from a unified diff but
\r
998 // But until that's implemented, the context menu entry for
\r
999 // this feature is commented out.
\r
1000 //popup.AppendMenu(ID_BLAMECOMPARE, IDS_LOG_POPUP_BLAMECOMPARE, IDI_BLAME);
\r
1002 popup.AppendMenuIcon(ID_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF_CH, IDI_DIFF);
\r
1003 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF);
\r
1004 //popup.AppendMenuIcon(ID_BLAMEWITHPREVIOUS, IDS_LOG_POPUP_BLAMEWITHPREVIOUS, IDI_BLAME);
\r
1005 popup.AppendMenu(MF_SEPARATOR, NULL);
\r
1008 // if (!m_ProjectProperties.sWebViewerRev.IsEmpty())
\r
1010 // popup.AppendMenuIcon(ID_VIEWREV, IDS_LOG_POPUP_VIEWREV);
\r
1012 // if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
\r
1014 // popup.AppendMenuIcon(ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
\r
1016 // if ((!m_ProjectProperties.sWebViewerPathRev.IsEmpty())||
\r
1017 // (!m_ProjectProperties.sWebViewerRev.IsEmpty()))
\r
1019 // popup.AppendMenu(MF_SEPARATOR, NULL);
\r
1023 // popup.AppendMenuIcon(ID_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
\r
1025 // popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT);
\r
1027 // popup.AppendMenuIcon(ID_MERGEREV, IDS_LOG_POPUP_MERGEREV, IDI_MERGE);
\r
1030 str.Format(_T("Reset %s to this"),g_Git.GetCurrentBranch());
\r
1031 popup.AppendMenuIcon(ID_RESET,str,IDI_REVERT);
\r
1032 popup.AppendMenuIcon(ID_SWITCHTOREV, _T("Switch/Checkout to this") , IDI_SWITCH);
\r
1033 popup.AppendMenuIcon(ID_CREATE_BRANCH, _T("Create Branch at this version") , IDI_COPY);
\r
1034 popup.AppendMenuIcon(ID_CREATE_TAG, _T("Create Tag at this version"), IDI_COPY);
\r
1035 popup.AppendMenuIcon(ID_CHERRY_PICK, _T("Cherry Pick this version"), IDI_EXPORT);
\r
1036 popup.AppendMenuIcon(ID_EXPORT, _T("Export this version"), IDI_EXPORT);
\r
1039 popup.AppendMenu(MF_SEPARATOR, NULL);
\r
1041 else if (GetSelectedCount() >= 2)
\r
1043 bool bAddSeparator = false;
\r
1044 if (IsSelectionContinuous() || (GetSelectedCount() == 2))
\r
1046 popup.AppendMenuIcon(ID_COMPARETWO, IDS_LOG_POPUP_COMPARETWO, IDI_DIFF);
\r
1048 if (GetSelectedCount() == 2)
\r
1050 //popup.AppendMenuIcon(ID_BLAMETWO, IDS_LOG_POPUP_BLAMEREVS, IDI_BLAME);
\r
1051 popup.AppendMenuIcon(ID_GNUDIFF2, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
\r
1052 bAddSeparator = true;
\r
1056 //popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREVS, IDI_REVERT);
\r
1058 // popup.AppendMenuIcon(ID_MERGEREV, IDS_LOG_POPUP_MERGEREVS, IDI_MERGE);
\r
1059 bAddSeparator = true;
\r
1061 if (bAddSeparator)
\r
1062 popup.AppendMenu(MF_SEPARATOR, NULL);
\r
1065 // if ((selEntries.size() > 0)&&(bAllFromTheSameAuthor))
\r
1067 // popup.AppendMenuIcon(ID_EDITAUTHOR, IDS_LOG_POPUP_EDITAUTHOR);
\r
1069 // if (GetSelectedCount() == 1)
\r
1071 // popup.AppendMenuIcon(ID_EDITLOG, IDS_LOG_POPUP_EDITLOG);
\r
1072 // popup.AppendMenuIcon(ID_REVPROPS, IDS_REPOBROWSE_SHOWREVPROP, IDI_PROPERTIES); // "Show Revision Properties"
\r
1073 // popup.AppendMenu(MF_SEPARATOR, NULL);
\r
1078 if (GetSelectedCount() == 1)
\r
1080 popup.AppendMenuIcon(ID_COPYHASH, _T("Copy Commit Hash"));
\r
1082 if (GetSelectedCount() != 0)
\r
1084 popup.AppendMenuIcon(ID_COPYCLIPBOARD, IDS_LOG_POPUP_COPYTOCLIPBOARD);
\r
1086 popup.AppendMenuIcon(ID_FINDENTRY, IDS_LOG_POPUP_FIND);
\r
1088 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
\r
1089 // DialogEnableWindow(IDOK, FALSE);
\r
1090 // SetPromptApp(&theApp);
\r
1092 this->ContextMenuAction(cmd, FirstSelect, LastSelect);
\r
1094 // EnableOKButton();
\r
1095 } // if (popup.CreatePopupMenu())
\r
1099 bool CGitLogListBase::IsSelectionContinuous()
\r
1101 if ( GetSelectedCount()==1 )
\r
1103 // if only one revision is selected, the selection is of course
\r
1108 POSITION pos = GetFirstSelectedItemPosition();
\r
1109 bool bContinuous = (m_arShownList.GetCount() == (INT_PTR)m_logEntries.size());
\r
1112 int itemindex = GetNextSelectedItem(pos);
\r
1115 int nextindex = GetNextSelectedItem(pos);
\r
1116 if (nextindex - itemindex > 1)
\r
1118 bContinuous = false;
\r
1121 itemindex = nextindex;
\r
1124 return bContinuous;
\r
1127 void CGitLogListBase::CopySelectionToClipBoard(bool HashOnly)
\r
1130 CString sClipdata;
\r
1131 POSITION pos = GetFirstSelectedItemPosition();
\r
1135 sRev.LoadString(IDS_LOG_REVISION);
\r
1137 sAuthor.LoadString(IDS_LOG_AUTHOR);
\r
1139 sDate.LoadString(IDS_LOG_DATE);
\r
1141 sMessage.LoadString(IDS_LOG_MESSAGE);
\r
1144 CString sLogCopyText;
\r
1146 GitRev * pLogEntry = reinterpret_cast<GitRev *>(m_arShownList.GetAt(GetNextSelectedItem(pos)));
\r
1150 //pLogEntry->m_Files
\r
1151 //LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
\r
1153 for (int cpPathIndex = 0; cpPathIndex<pLogEntry->m_Files.GetCount(); ++cpPathIndex)
\r
1155 sPaths += ((CTGitPath&)pLogEntry->m_Files[cpPathIndex]).GetActionName() + _T(" : ") + pLogEntry->m_Files[cpPathIndex].GetGitPathString();
\r
1156 sPaths += _T("\r\n");
\r
1159 sLogCopyText.Format(_T("%s: %s\r\n%s: %s\r\n%s: %s\r\n%s:\r\n%s\r\n----\r\n%s\r\n\r\n"),
\r
1160 (LPCTSTR)sRev, pLogEntry->m_CommitHash,
\r
1161 (LPCTSTR)sAuthor, (LPCTSTR)pLogEntry->m_AuthorName,
\r
1163 (LPCTSTR)CAppUtils::FormatDateAndTime( pLogEntry->m_AuthorDate, m_DateFormat, true, m_bRelativeTimes ),
\r
1164 (LPCTSTR)sMessage, pLogEntry->m_Subject+_T("\r\n")+pLogEntry->m_Body,
\r
1166 sClipdata += sLogCopyText;
\r
1169 sClipdata += pLogEntry->m_CommitHash;
\r
1174 CStringUtils::WriteAsciiStringToClipboard(sClipdata, GetSafeHwnd());
\r
1179 void CGitLogListBase::DiffSelectedRevWithPrevious()
\r
1182 if (m_bThreadRunning)
\r
1184 UpdateLogInfoLabel();
\r
1185 int selIndex = m_LogList.GetSelectionMark();
\r
1188 int selCount = m_LogList.GetSelectedCount();
\r
1189 if (selCount != 1)
\r
1192 // Find selected entry in the log list
\r
1193 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
\r
1194 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(m_LogList.GetNextSelectedItem(pos)));
\r
1195 long rev1 = pLogEntry->Rev;
\r
1196 long rev2 = rev1-1;
\r
1197 CTGitPath path = m_path;
\r
1199 // See how many files under the relative root were changed in selected revision
\r
1201 LogChangedPath * changed = NULL;
\r
1202 for (INT_PTR c = 0; c < pLogEntry->pArChangedPaths->GetCount(); ++c)
\r
1204 LogChangedPath * cpath = pLogEntry->pArChangedPaths->GetAt(c);
\r
1205 if (cpath && cpath -> sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
\r
1212 if (m_path.IsDirectory() && nChanged == 1)
\r
1214 // We're looking at the log for a directory and only one file under dir was changed in the revision
\r
1215 // Do diff on that file instead of whole directory
\r
1216 path.AppendPathString(changed->sPath.Mid(m_sRelativeRoot.GetLength()));
\r
1219 m_bCancelled = FALSE;
\r
1220 DialogEnableWindow(IDOK, FALSE);
\r
1221 SetPromptApp(&theApp);
\r
1222 theApp.DoWaitCursor(1);
\r
1224 if (PromptShown())
\r
1226 GitDiff diff(this, m_hWnd, true);
\r
1227 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
\r
1228 diff.SetHEADPeg(m_LogRevision);
\r
1229 diff.ShowCompare(path, rev2, path, rev1);
\r
1233 CAppUtils::StartShowCompare(m_hWnd, path, rev2, path, rev1, GitRev(), m_LogRevision, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
\r
1236 theApp.DoWaitCursor(-1);
\r
1241 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR *pNMHDR, LRESULT *pResult)
\r
1243 LPNMLVFINDITEM pFindInfo = reinterpret_cast<LPNMLVFINDITEM>(pNMHDR);
\r
1246 if (pFindInfo->lvfi.flags & LVFI_PARAM)
\r
1248 if ((pFindInfo->iStart < 0)||(pFindInfo->iStart >= m_arShownList.GetCount()))
\r
1250 if (pFindInfo->lvfi.psz == 0)
\r
1253 CString sCmp = pFindInfo->lvfi.psz;
\r
1255 for (int i=pFindInfo->iStart; i<m_arShownList.GetCount(); ++i)
\r
1257 GitRev * pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.GetAt(i));
\r
1258 sRev.Format(_T("%ld"), pLogEntry->Rev);
\r
1259 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
\r
1261 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
\r
1269 if (sCmp.Compare(sRev)==0)
\r
1276 if (pFindInfo->lvfi.flags & LVFI_WRAP)
\r
1278 for (int i=0; i<pFindInfo->iStart; ++i)
\r
1280 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(i));
\r
1281 sRev.Format(_T("%ld"), pLogEntry->Rev);
\r
1282 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
\r
1284 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
\r
1292 if (sCmp.Compare(sRev)==0)
\r
1304 int CGitLogListBase::FillGitLog(CTGitPath *path,int info)
\r
1308 this->m_logEntries.ClearAll();
\r
1309 this->m_logEntries.ParserFromLog(path,-1,info);
\r
1311 //this->m_logEntries.ParserFromLog();
\r
1312 SetItemCountEx(this->m_logEntries.size());
\r
1314 this->m_arShownList.RemoveAll();
\r
1316 for(unsigned int i=0;i<m_logEntries.size();i++)
\r
1318 m_logEntries[i].m_IsFull=TRUE;
\r
1319 this->m_arShownList.Add(&m_logEntries[i]);
\r
1328 int CGitLogListBase::FillGitShortLog()
\r
1332 this->m_logEntries.ClearAll();
\r
1334 m_LogCache.FetchCacheIndex(g_Git.m_CurrentDir);
\r
1337 if(this->m_Path.IsEmpty())
\r
1340 path=&this->m_Path;
\r
1344 mask = CGit::LOG_INFO_ONLY_HASH | CGit::LOG_INFO_BOUNDARY;
\r
1345 // if(this->m_bAllBranch)
\r
1346 mask |= m_ShowMask;
\r
1348 this->m_logEntries.ParserShortLog(path,hash,-1,mask);
\r
1351 //this->m_logEntries.ParserFromLog();
\r
1352 if(IsInWorkingThread())
\r
1353 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL);
\r
1355 SetItemCountEx(this->m_logEntries.size());
\r
1357 this->m_arShownList.RemoveAll();
\r
1359 for(unsigned int i=0;i<m_logEntries.size();i++)
\r
1360 this->m_arShownList.Add(&m_logEntries[i]);
\r
1365 BOOL CGitLogListBase::PreTranslateMessage(MSG* pMsg)
\r
1367 // Skip Ctrl-C when copying text out of the log message or search filter
\r
1368 BOOL bSkipAccelerator = ( pMsg->message == WM_KEYDOWN && pMsg->wParam=='C' && (GetFocus()==GetDlgItem(IDC_MSGVIEW) || GetFocus()==GetDlgItem(IDC_SEARCHEDIT) ) && GetKeyState(VK_CONTROL)&0x8000 );
\r
1369 if (pMsg->message == WM_KEYDOWN && pMsg->wParam=='\r')
\r
1371 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))
\r
1373 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
\r
1375 DiffSelectedRevWithPrevious();
\r
1380 if (GetFocus()==GetDlgItem(IDC_LOGMSG))
\r
1382 DiffSelectedFile();
\r
1389 if (m_hAccel && !bSkipAccelerator)
\r
1391 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
\r
1397 //m_tooltips.RelayEvent(pMsg);
\r
1398 return __super::PreTranslateMessage(pMsg);
\r
1401 void CGitLogListBase::OnNMDblclkLoglist(NMHDR * /*pNMHDR*/, LRESULT *pResult)
\r
1403 // a double click on an entry in the revision list has happened
\r
1406 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
\r
1407 DiffSelectedRevWithPrevious();
\r
1410 int CGitLogListBase::FetchLogAsync(void * data)
\r
1413 m_bExitThread=FALSE;
\r
1414 InterlockedExchange(&m_bThreadRunning, TRUE);
\r
1415 InterlockedExchange(&m_bNoDispUpdates, TRUE);
\r
1416 m_LoadingThread = AfxBeginThread(LogThreadEntry, this);
\r
1417 if (m_LoadingThread ==NULL)
\r
1419 InterlockedExchange(&m_bThreadRunning, FALSE);
\r
1420 InterlockedExchange(&m_bNoDispUpdates, FALSE);
\r
1421 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
\r
1427 //this is the thread function which calls the subversion function
\r
1428 UINT CGitLogListBase::LogThreadEntry(LPVOID pVoid)
\r
1430 return ((CGitLogListBase*)pVoid)->LogThread();
\r
1433 void CGitLogListBase::GetTimeRange(CTime &oldest, CTime &latest)
\r
1436 oldest=CTime::GetCurrentTime();
\r
1437 latest=CTime(1971,1,2,0,0,0);
\r
1438 for(unsigned int i=0;i<m_logEntries.size();i++)
\r
1440 if(m_logEntries[i].m_AuthorDate.GetTime() < oldest.GetTime())
\r
1441 oldest = m_logEntries[i].m_AuthorDate.GetTime();
\r
1443 if(m_logEntries[i].m_AuthorDate.GetTime() > latest.GetTime())
\r
1444 latest = m_logEntries[i].m_AuthorDate.GetTime();
\r
1449 UINT CGitLogListBase::LogThread()
\r
1452 // if(m_ProcCallBack)
\r
1453 // m_ProcCallBack(m_ProcData,GITLOG_START);
\r
1454 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_START,0);
\r
1456 InterlockedExchange(&m_bThreadRunning, TRUE);
\r
1457 InterlockedExchange(&m_bNoDispUpdates, TRUE);
\r
1459 //does the user force the cache to refresh (shift or control key down)?
\r
1460 bool refresh = (GetKeyState (VK_CONTROL) < 0)
\r
1461 || (GetKeyState (VK_SHIFT) < 0);
\r
1463 //disable the "Get All" button while we're receiving
\r
1466 FillGitShortLog();
\r
1468 if(this->m_bExitThread)
\r
1471 RedrawItems(0, m_arShownList.GetCount());
\r
1472 // SetRedraw(false);
\r
1473 // ResizeAllListCtrlCols();
\r
1474 // SetRedraw(true);
\r
1476 if ( m_pStoreSelection )
\r
1478 // Deleting the instance will restore the
\r
1479 // selection of the CLogDlg.
\r
1480 delete m_pStoreSelection;
\r
1481 m_pStoreSelection = NULL;
\r
1485 // If no selection has been set then this must be the first time
\r
1486 // the revisions are shown. Let's preselect the topmost revision.
\r
1487 if ( GetItemCount()>0 )
\r
1489 SetSelectionMark(0);
\r
1490 SetItemState(0, LVIS_SELECTED, LVIS_SELECTED);
\r
1494 InterlockedExchange(&m_bNoDispUpdates, FALSE);
\r
1496 unsigned int updated=0;
\r
1501 for(unsigned int i=0;i<m_logEntries.size();i++)
\r
1503 if(m_LogCache.GetCacheData(m_logEntries[i]))
\r
1505 if(!m_logEntries.FetchFullInfo(i))
\r
1509 m_LogCache.AddCacheEntry(m_logEntries[i]);
\r
1514 InterlockedExchange(&m_logEntries[i].m_IsUpdateing,FALSE);
\r
1515 InterlockedExchange(&m_logEntries[i].m_IsFull,TRUE);
\r
1518 ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)i,0);
\r
1523 percent=updated*98/m_logEntries.size() + GITLOG_START+1;
\r
1524 if(percent == GITLOG_END)
\r
1525 percent = GITLOG_END -1;
\r
1527 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) percent,0);
\r
1531 if(updated==m_logEntries.size())
\r
1535 //RefreshCursor();
\r
1536 // make sure the filter is applied (if any) now, after we refreshed/fetched
\r
1537 // the log messages
\r
1539 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_END,0);
\r
1541 InterlockedExchange(&m_bThreadRunning, FALSE);
\r
1546 void CGitLogListBase::Refresh()
\r
1548 m_bExitThread=TRUE;
\r
1549 DWORD ret =::WaitForSingleObject(m_LoadingThread->m_hThread,20000);
\r
1550 if(ret == WAIT_TIMEOUT)
\r
1551 TerminateThread();
\r
1555 if(!m_bThreadRunning)
\r
1557 this->SetItemCountEx(0);
\r
1558 m_logEntries.clear();
\r
1559 m_bExitThread=FALSE;
\r
1560 InterlockedExchange(&m_bThreadRunning, TRUE);
\r
1561 InterlockedExchange(&m_bNoDispUpdates, TRUE);
\r
1562 if (AfxBeginThread(LogThreadEntry, this)==NULL)
\r
1564 InterlockedExchange(&m_bThreadRunning, FALSE);
\r
1565 InterlockedExchange(&m_bNoDispUpdates, FALSE);
\r
1566 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
\r
1568 m_sFilterText.Empty();
\r
1569 m_From=CTime(1970,1,2,0,0,0);
\r
1570 m_To=CTime::GetCurrentTime();
\r
1573 bool CGitLogListBase::ValidateRegexp(LPCTSTR regexp_str, tr1::wregex& pat, bool bMatchCase /* = false */)
\r
1577 tr1::regex_constants::syntax_option_type type = tr1::regex_constants::ECMAScript;
\r
1579 type |= tr1::regex_constants::icase;
\r
1580 pat = tr1::wregex(regexp_str, type);
\r
1583 catch (exception) {}
\r
1587 void CGitLogListBase::RecalculateShownList(CPtrArray * pShownlist)
\r
1590 pShownlist->RemoveAll();
\r
1591 tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
\r
1592 bool bRegex = false;
\r
1593 if (m_bFilterWithRegex)
\r
1594 bRegex = ValidateRegexp(m_sFilterText, pat, false);
\r
1596 tr1::regex_constants::match_flag_type flags = tr1::regex_constants::match_any;
\r
1598 for (DWORD i=0; i<m_logEntries.size(); ++i)
\r
1600 if ((bRegex)&&(m_bFilterWithRegex))
\r
1603 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
\r
1605 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR)m_logEntries[i]->sBugIDs);
\r
1606 if (regex_search(wstring((LPCTSTR)m_logEntries[i]->sBugIDs), pat, flags)&&IsEntryInDateRange(i))
\r
1608 pShownlist->Add(m_logEntries[i]);
\r
1613 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_MESSAGES))
\r
1615 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries[i].m_Subject);
\r
1616 if (regex_search(wstring((LPCTSTR)m_logEntries[i].m_Subject), pat, flags)&&IsEntryInDateRange(i))
\r
1618 pShownlist->Add(&m_logEntries[i]);
\r
1622 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries[i].m_Body);
\r
1623 if (regex_search(wstring((LPCTSTR)m_logEntries[i].m_Body), pat, flags)&&IsEntryInDateRange(i))
\r
1625 pShownlist->Add(&m_logEntries[i]);
\r
1630 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_PATHS))
\r
1632 LogChangedPathArray * cpatharray = m_logEntries[i]->pArChangedPaths;
\r
1634 bool bGoing = true;
\r
1635 for (INT_PTR cpPathIndex = 0; cpPathIndex<cpatharray->GetCount() && bGoing; ++cpPathIndex)
\r
1637 LogChangedPath * cpath = cpatharray->GetAt(cpPathIndex);
\r
1638 if (regex_search(wstring((LPCTSTR)cpath->sCopyFromPath), pat, flags)&&IsEntryInDateRange(i))
\r
1640 pShownlist->Add(m_logEntries[i]);
\r
1644 if (regex_search(wstring((LPCTSTR)cpath->sPath), pat, flags)&&IsEntryInDateRange(i))
\r
1646 pShownlist->Add(m_logEntries[i]);
\r
1650 if (regex_search(wstring((LPCTSTR)cpath->GetAction()), pat, flags)&&IsEntryInDateRange(i))
\r
1652 pShownlist->Add(m_logEntries[i]);
\r
1661 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_AUTHORS))
\r
1663 if (regex_search(wstring((LPCTSTR)m_logEntries[i].m_AuthorName), pat, flags)&&IsEntryInDateRange(i))
\r
1665 pShownlist->Add(&m_logEntries[i]);
\r
1669 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_REVS))
\r
1671 sRev.Format(_T("%ld"), m_logEntries[i].m_CommitHash);
\r
1672 if (regex_search(wstring((LPCTSTR)sRev), pat, flags)&&IsEntryInDateRange(i))
\r
1674 pShownlist->Add(&m_logEntries[i]);
\r
1681 CString find = m_sFilterText;
\r
1684 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
\r
1686 CString sBugIDs = m_logEntries[i]->sBugIDs;
\r
1688 sBugIDs = sBugIDs.MakeLower();
\r
1689 if ((sBugIDs.Find(find) >= 0)&&(IsEntryInDateRange(i)))
\r
1691 pShownlist->Add(m_logEntries[i]);
\r
1696 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_MESSAGES))
\r
1698 CString msg = m_logEntries[i].m_Subject;
\r
1700 msg = msg.MakeLower();
\r
1701 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
\r
1703 pShownlist->Add(&m_logEntries[i]);
\r
1706 msg = m_logEntries[i].m_Body;
\r
1708 msg = msg.MakeLower();
\r
1709 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
\r
1711 pShownlist->Add(&m_logEntries[i]);
\r
1716 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_PATHS))
\r
1718 LogChangedPathArray * cpatharray = m_logEntries[i]->pArChangedPaths;
\r
1720 bool bGoing = true;
\r
1721 for (INT_PTR cpPathIndex = 0; cpPathIndex<cpatharray->GetCount() && bGoing; ++cpPathIndex)
\r
1723 LogChangedPath * cpath = cpatharray->GetAt(cpPathIndex);
\r
1724 CString path = cpath->sCopyFromPath;
\r
1726 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
\r
1728 pShownlist->Add(m_logEntries[i]);
\r
1732 path = cpath->sPath;
\r
1734 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
\r
1736 pShownlist->Add(m_logEntries[i]);
\r
1740 path = cpath->GetAction();
\r
1742 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
\r
1744 pShownlist->Add(m_logEntries[i]);
\r
1751 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_AUTHORS))
\r
1753 CString msg = m_logEntries[i].m_AuthorName;
\r
1754 msg = msg.MakeLower();
\r
1755 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
\r
1757 pShownlist->Add(&m_logEntries[i]);
\r
1761 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_REVS))
\r
1763 sRev.Format(_T("%ld"), m_logEntries[i].m_CommitHash);
\r
1764 if ((sRev.Find(find) >= 0)&&(IsEntryInDateRange(i)))
\r
1766 pShownlist->Add(&m_logEntries[i]);
\r
1770 } // else (from if (bRegex))
\r
1771 } // for (DWORD i=0; i<m_logEntries.size(); ++i)
\r
1775 BOOL CGitLogListBase::IsEntryInDateRange(int i)
\r
1777 __time64_t time = m_logEntries[i].m_AuthorDate.GetTime();
\r
1778 if ((time >= m_From.GetTime())&&(time <= m_To.GetTime()))
\r
1785 void CGitLogListBase::StartFilter()
\r
1787 InterlockedExchange(&m_bNoDispUpdates, TRUE);
\r
1788 RecalculateShownList(&m_arShownList);
\r
1789 InterlockedExchange(&m_bNoDispUpdates, FALSE);
\r
1793 SetItemCountEx(ShownCountWithStopped());
\r
1794 RedrawItems(0, ShownCountWithStopped());
\r
1796 //ResizeAllListCtrlCols();
\r
1801 void CGitLogListBase::RemoveFilter()
\r
1804 InterlockedExchange(&m_bNoDispUpdates, TRUE);
\r
1806 m_arShownList.RemoveAll();
\r
1808 // reset the time filter too
\r
1810 m_timFrom = (__time64_t(m_tFrom));
\r
1811 m_timTo = (__time64_t(m_tTo));
\r
1812 m_DateFrom.SetTime(&m_timFrom);
\r
1813 m_DateTo.SetTime(&m_timTo);
\r
1814 m_DateFrom.SetRange(&m_timFrom, &m_timTo);
\r
1815 m_DateTo.SetRange(&m_timFrom, &m_timTo);
\r
1818 for (DWORD i=0; i<m_logEntries.size(); ++i)
\r
1820 m_arShownList.Add(&m_logEntries[i]);
\r
1822 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
\r
1824 SetItemCountEx(ShownCountWithStopped());
\r
1825 RedrawItems(0, ShownCountWithStopped());
\r
1826 // SetRedraw(false);
\r
1827 // ResizeAllListCtrlCols();
\r
1828 // SetRedraw(true);
\r
1830 InterlockedExchange(&m_bNoDispUpdates, FALSE);
\r
1833 void CGitLogListBase::Clear()
\r
1835 m_arShownList.RemoveAll();
\r
1836 m_logEntries.clear();
\r
1837 m_logEntries.m_HashMap.clear();
\r
1839 m_logEntries.m_Lns.clear();
\r
1841 m_logEntries.m_FirstFreeLane=0;
\r
1842 m_logEntries.m_Lns.clear();
\r
1846 void CGitLogListBase::OnDestroy()
\r
1848 // save the column widths to the registry
\r
1849 SaveColumnWidths();
\r
1851 if(this->m_bThreadRunning)
\r
1853 this->m_bExitThread=true;
\r
1854 DWORD ret =::WaitForSingleObject(m_LoadingThread->m_hThread,20000);
\r
1855 if(ret == WAIT_TIMEOUT)
\r
1856 TerminateThread();
\r
1858 while(m_LogCache.SaveCache())
\r
1860 if(CMessageBox::Show(NULL,_T("Cannot Save Log Cache to Disk. To retry click yes. To give up click no."),_T("TortoiseGit"),
\r
1861 MB_YESNO) == IDNO)
\r
1864 CHintListCtrl::OnDestroy();
\r
1867 LRESULT CGitLogListBase::OnLoad(WPARAM wParam,LPARAM lParam)
\r
1870 int i=(int)wParam;
\r
1871 this->GetItemRect(i,&rect,LVIR_BOUNDS);
\r
1872 this->InvalidateRect(rect);
\r
1877 * Save column widths to the registry
\r
1879 void CGitLogListBase::SaveColumnWidths()
\r
1881 CHeaderCtrl* pHdrCtrl = (CHeaderCtrl*)(GetDlgItem(0));
\r
1884 int numcols = pHdrCtrl->GetItemCount();
\r
1885 for (int col = 0; col < numcols; col++)
\r
1887 int width = GetColumnWidth( col );
\r
1889 regentry.Format( _T("Software\\TortoiseGit\\log\\ColWidth%d"), col);
\r
1890 CRegDWORD regwidth(regentry, 0);
\r
1891 regwidth = width; // this writes it to reg
\r