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
110 CGitLogListBase::~CGitLogListBase()
\r
112 InterlockedExchange(&m_bNoDispUpdates, TRUE);
\r
114 DestroyIcon(m_hModifiedIcon);
\r
115 DestroyIcon(m_hReplacedIcon);
\r
116 DestroyIcon(m_hAddedIcon);
\r
117 DestroyIcon(m_hDeletedIcon);
\r
118 m_logEntries.ClearAll();
\r
121 DeleteObject(m_boldFont);
\r
123 if ( m_pStoreSelection )
\r
125 delete m_pStoreSelection;
\r
126 m_pStoreSelection = NULL;
\r
129 if(this->m_bThreadRunning)
\r
131 m_bExitThread=true;
\r
132 WaitForSingleObject(m_LoadingThread->m_hThread,1000);
\r
138 BEGIN_MESSAGE_MAP(CGitLogListBase, CHintListCtrl)
\r
139 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnNMCustomdrawLoglist)
\r
140 ON_NOTIFY_REFLECT(LVN_GETDISPINFO, OnLvnGetdispinfoLoglist)
\r
141 ON_WM_CONTEXTMENU()
\r
142 ON_NOTIFY_REFLECT(NM_DBLCLK, OnNMDblclkLoglist)
\r
143 ON_NOTIFY_REFLECT(LVN_ODFINDITEM,OnLvnOdfinditemLoglist)
\r
146 ON_MESSAGE(MSG_LOADED,OnLoad)
\r
149 int CGitLogListBase:: OnCreate(LPCREATESTRUCT lpCreateStruct)
\r
151 PreSubclassWindow();
\r
152 return CHintListCtrl::OnCreate(lpCreateStruct);
\r
155 void CGitLogListBase::PreSubclassWindow()
\r
157 SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_SUBITEMIMAGES);
\r
158 // load the icons for the action columns
\r
159 m_Theme.SetWindowTheme(GetSafeHwnd(), L"Explorer", NULL);
\r
160 CHintListCtrl::PreSubclassWindow();
\r
163 void CGitLogListBase::InsertGitColumn()
\r
167 int c = ((CHeaderCtrl*)(GetDlgItem(0)))->GetItemCount()-1;
\r
171 temp.LoadString(IDS_LOG_GRAPH);
\r
173 InsertColumn(this->LOGLIST_GRAPH, temp);
\r
176 // make the revision column right aligned
\r
178 Column.mask = LVCF_FMT;
\r
179 Column.fmt = LVCFMT_RIGHT;
\r
180 SetColumn(0, &Column);
\r
183 // g_Git.GetLog(log);
\r
185 if(m_IsIDReplaceAction)
\r
187 temp.LoadString(IDS_LOG_ID);
\r
188 InsertColumn(this->LOGLIST_ACTION, temp);
\r
192 temp.LoadString(IDS_LOG_ACTIONS);
\r
193 InsertColumn(this->LOGLIST_ACTION, temp);
\r
195 temp.LoadString(IDS_LOG_MESSAGE);
\r
196 InsertColumn(this->LOGLIST_MESSAGE, temp);
\r
198 temp.LoadString(IDS_LOG_AUTHOR);
\r
199 InsertColumn(this->LOGLIST_AUTHOR, temp);
\r
201 temp.LoadString(IDS_LOG_DATE);
\r
202 InsertColumn(this->LOGLIST_DATE, temp);
\r
205 if (m_bShowBugtraqColumn)
\r
207 // temp = m_ProjectProperties.sLabel;
\r
208 if (temp.IsEmpty())
\r
209 temp.LoadString(IDS_LOG_BUGIDS);
\r
210 InsertColumn(this->LOGLIST_BUG, temp);
\r
215 ResizeAllListCtrlCols();
\r
221 * Resizes all columns in a list control to values in registry.
\r
223 void CGitLogListBase::ResizeAllListCtrlCols()
\r
225 // column max and min widths to allow
\r
226 static const int nMinimumWidth = 10;
\r
227 static const int nMaximumWidth = 1000;
\r
228 CHeaderCtrl* pHdrCtrl = (CHeaderCtrl*)(GetDlgItem(0));
\r
231 int numcols = pHdrCtrl->GetItemCount();
\r
232 for (int col = 0; col < numcols; col++)
\r
234 // get width for this col last time from registry
\r
236 regentry.Format( _T("Software\\TortoiseGit\\log\\ColWidth%d"), col);
\r
237 CRegDWORD regwidth(regentry, 0);
\r
239 if (cx < nMinimumWidth)
\r
241 cx = nMinimumWidth;
\r
242 } else if (cx > nMaximumWidth)
\r
244 cx = nMaximumWidth;
\r
247 SetColumnWidth(col, cx);
\r
254 BOOL CGitLogListBase::GetShortName(CString ref, CString &shortname,CString prefix)
\r
256 TRACE(_T("%s %s\r\n"),ref,prefix);
\r
257 if(ref.Left(prefix.GetLength()) == prefix)
\r
259 shortname = ref.Right(ref.GetLength()-prefix.GetLength());
\r
260 if(shortname.Right(3)==_T("^{}"))
\r
261 shortname=shortname.Left(shortname.GetLength()-3);
\r
266 void CGitLogListBase::FillBackGround(HDC hdc, int Index,CRect &rect)
\r
270 SecureZeroMemory(&rItem, sizeof(LVITEM));
\r
271 rItem.mask = LVIF_STATE;
\r
272 rItem.iItem = Index;
\r
273 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
\r
276 if (m_Theme.IsAppThemed() && m_bVista)
\r
278 m_Theme.Open(m_hWnd, L"Explorer");
\r
279 int state = LISS_NORMAL;
\r
280 if (rItem.state & LVIS_SELECTED)
\r
282 if (::GetFocus() == m_hWnd)
\r
283 state |= LISS_SELECTED;
\r
285 state |= LISS_SELECTEDNOTFOCUS;
\r
290 if (pLogEntry->bCopiedSelf)
\r
292 // unfortunately, the pLVCD->nmcd.uItemState does not contain valid
\r
293 // information at this drawing stage. But we can check the whether the
\r
294 // previous stage changed the background color of the item
\r
295 if (pLVCD->clrTextBk == GetSysColor(COLOR_MENU))
\r
298 brush = ::CreateSolidBrush(::GetSysColor(COLOR_MENU));
\r
301 ::FillRect(pLVCD->nmcd.hdc, &rect, brush);
\r
302 ::DeleteObject(brush);
\r
309 if (m_Theme.IsBackgroundPartiallyTransparent(LVP_LISTDETAIL, state))
\r
310 m_Theme.DrawParentBackground(m_hWnd, hdc, &rect);
\r
312 m_Theme.DrawBackground(hdc, LVP_LISTDETAIL, state, &rect, NULL);
\r
317 if (rItem.state & LVIS_SELECTED)
\r
319 if (::GetFocus() == m_hWnd)
\r
320 brush = ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT));
\r
322 brush = ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE));
\r
326 //if (pLogEntry->bCopiedSelf)
\r
327 // brush = ::CreateSolidBrush(::GetSysColor(COLOR_MENU));
\r
329 brush = ::CreateSolidBrush(::GetSysColor(COLOR_WINDOW));
\r
334 ::FillRect(hdc, &rect, brush);
\r
335 ::DeleteObject(brush);
\r
340 void CGitLogListBase::DrawTagBranch(HDC hdc,CRect &rect,INT_PTR index)
\r
342 GitRev* data = (GitRev*)m_arShownList.GetAt(index);
\r
345 SecureZeroMemory(&rItem, sizeof(LVITEM));
\r
346 rItem.mask = LVIF_STATE;
\r
347 rItem.iItem = index;
\r
348 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
\r
351 for(unsigned int i=0;i<m_HashMap[data->m_CommitHash].size();i++)
\r
354 str=m_HashMap[data->m_CommitHash][i];
\r
359 if(GetShortName(str,shortname,_T("refs/heads/")))
\r
361 if( shortname == m_CurrentBranch )
\r
362 brush = ::CreateSolidBrush(m_Colors.GetColor(CColors::CurrentBranch));
\r
364 brush = ::CreateSolidBrush(m_Colors.GetColor(CColors::LocalBranch));
\r
366 }else if(GetShortName(str,shortname,_T("refs/remotes/")))
\r
368 brush = ::CreateSolidBrush(m_Colors.GetColor(CColors::RemoteBranch));
\r
370 else if(GetShortName(str,shortname,_T("refs/tags/")))
\r
372 brush = ::CreateSolidBrush(m_Colors.GetColor(CColors::Tag));
\r
375 if(!shortname.IsEmpty())
\r
378 memset(&size,0,sizeof(SIZE));
\r
379 GetTextExtentPoint32(hdc, shortname,shortname.GetLength(),&size);
\r
381 rt.SetRect(rt.left,rt.top,rt.left+size.cx,rt.bottom);
\r
383 ::FillRect(hdc, &rt, brush);
\r
384 if (rItem.state & LVIS_SELECTED)
\r
386 COLORREF clrOld = ::SetTextColor(hdc,::GetSysColor(COLOR_HIGHLIGHTTEXT));
\r
387 ::DrawText(hdc,shortname,shortname.GetLength(),&rt,DT_CENTER);
\r
388 ::SetTextColor(hdc,clrOld);
\r
391 ::DrawText(hdc,shortname,shortname.GetLength(),&rt,DT_CENTER);
\r
395 ::MoveToEx(hdc,rt.left,rt.top,NULL);
\r
396 ::LineTo(hdc,rt.right,rt.top);
\r
397 ::LineTo(hdc,rt.right,rt.bottom);
\r
398 ::LineTo(hdc,rt.left,rt.bottom);
\r
399 ::LineTo(hdc,rt.left,rt.top);
\r
401 rt.left=rt.right+3;
\r
404 ::DeleteObject(brush);
\r
406 rt.right=rect.right;
\r
408 if (rItem.state & LVIS_SELECTED)
\r
410 COLORREF clrOld = ::SetTextColor(hdc,::GetSysColor(COLOR_HIGHLIGHTTEXT));
\r
411 ::DrawText(hdc,data->m_Subject,data->m_Subject.GetLength(),&rt,DT_LEFT);
\r
412 ::SetTextColor(hdc,clrOld);
\r
415 ::DrawText(hdc,data->m_Subject,data->m_Subject.GetLength(),&rt,DT_LEFT);
\r
420 void CGitLogListBase::paintGraphLane(HDC hdc, int laneHeight,int type, int x1, int x2,
\r
421 const COLORREF& col,int top
\r
424 int h = laneHeight / 2;
\r
425 int m = (x1 + x2) / 2;
\r
426 int r = (x2 - x1) / 3;
\r
429 #define P_CENTER m , h+top
\r
430 #define P_0 x2, h+top
\r
431 #define P_90 m , 0+top
\r
432 #define P_180 x1, h+top
\r
433 #define P_270 m , 2 * h+top
\r
434 #define R_CENTER m - r, h - r+top, m - r+d, h - r+top+d
\r
436 //static QPen myPen(Qt::black, 2); // fast path here
\r
438 pen.CreatePen(PS_SOLID,2,col);
\r
439 //myPen.setColor(col);
\r
440 HPEN oldpen=(HPEN)::SelectObject(hdc,(HPEN)pen);
\r
442 //p->setPen(myPen);
\r
446 case Lanes::ACTIVE:
\r
447 case Lanes::NOT_ACTIVE:
\r
448 case Lanes::MERGE_FORK:
\r
449 case Lanes::MERGE_FORK_R:
\r
450 case Lanes::MERGE_FORK_L:
\r
452 case Lanes::JOIN_R:
\r
453 case Lanes::JOIN_L:
\r
454 DrawLine(hdc,P_90,P_270);
\r
455 //p->drawLine(P_90, P_270);
\r
458 case Lanes::HEAD_R:
\r
459 case Lanes::HEAD_L:
\r
460 case Lanes::BRANCH:
\r
461 DrawLine(hdc,P_CENTER,P_270);
\r
462 //p->drawLine(P_CENTER, P_270);
\r
465 case Lanes::TAIL_R:
\r
466 case Lanes::TAIL_L:
\r
467 case Lanes::INITIAL:
\r
468 case Lanes::BOUNDARY:
\r
469 case Lanes::BOUNDARY_C:
\r
470 case Lanes::BOUNDARY_R:
\r
471 case Lanes::BOUNDARY_L:
\r
472 DrawLine(hdc,P_90, P_CENTER);
\r
473 //p->drawLine(P_90, P_CENTER);
\r
481 case Lanes::MERGE_FORK:
\r
486 case Lanes::CROSS_EMPTY:
\r
487 case Lanes::BOUNDARY_C:
\r
488 DrawLine(hdc,P_180,P_0);
\r
489 //p->drawLine(P_180, P_0);
\r
491 case Lanes::MERGE_FORK_R:
\r
492 case Lanes::JOIN_R:
\r
493 case Lanes::HEAD_R:
\r
494 case Lanes::TAIL_R:
\r
495 case Lanes::BOUNDARY_R:
\r
496 DrawLine(hdc,P_180,P_CENTER);
\r
497 //p->drawLine(P_180, P_CENTER);
\r
499 case Lanes::MERGE_FORK_L:
\r
500 case Lanes::JOIN_L:
\r
501 case Lanes::HEAD_L:
\r
502 case Lanes::TAIL_L:
\r
503 case Lanes::BOUNDARY_L:
\r
504 DrawLine(hdc,P_CENTER,P_0);
\r
505 //p->drawLine(P_CENTER, P_0);
\r
512 brush.CreateSolidBrush(col);
\r
513 HBRUSH oldbrush=(HBRUSH)::SelectObject(hdc,(HBRUSH)brush);
\r
514 // center symbol, e.g. rect or ellipse
\r
516 case Lanes::ACTIVE:
\r
517 case Lanes::INITIAL:
\r
518 case Lanes::BRANCH:
\r
520 //p->setPen(Qt::NoPen);
\r
521 //p->setBrush(col);
\r
522 ::Ellipse(hdc, R_CENTER);
\r
523 //p->drawEllipse(R_CENTER);
\r
525 case Lanes::MERGE_FORK:
\r
526 case Lanes::MERGE_FORK_R:
\r
527 case Lanes::MERGE_FORK_L:
\r
528 //p->setPen(Qt::NoPen);
\r
529 //p->setBrush(col);
\r
530 //p->drawRect(R_CENTER);
\r
531 Rectangle(hdc,R_CENTER);
\r
533 case Lanes::UNAPPLIED:
\r
535 //p->setPen(Qt::NoPen);
\r
536 //p->setBrush(Qt::red);
\r
537 //p->drawRect(m - r, h - 1, d, 2);
\r
538 ::Rectangle(hdc,m-r,h-1,d,2);
\r
540 case Lanes::APPLIED:
\r
542 //p->setPen(Qt::NoPen);
\r
543 //p->setBrush(DARK_GREEN);
\r
544 //p->drawRect(m - r, h - 1, d, 2);
\r
545 //p->drawRect(m - 1, h - r, 2, d);
\r
546 ::Rectangle(hdc,m-r,h-1,d,2);
\r
547 ::Rectangle(hdc,m-1,h-r,2,d);
\r
549 case Lanes::BOUNDARY:
\r
550 //p->setBrush(back);
\r
551 //p->drawEllipse(R_CENTER);
\r
552 ::Ellipse(hdc, R_CENTER);
\r
554 case Lanes::BOUNDARY_C:
\r
555 case Lanes::BOUNDARY_R:
\r
556 case Lanes::BOUNDARY_L:
\r
557 //p->setBrush(back);
\r
558 //p->drawRect(R_CENTER);
\r
559 ::Rectangle(hdc,R_CENTER);
\r
565 ::SelectObject(hdc,oldpen);
\r
566 ::SelectObject(hdc,oldbrush);
\r
575 void CGitLogListBase::DrawGraph(HDC hdc,CRect &rect,INT_PTR index)
\r
579 GitRev* data = (GitRev*)m_arShownList.GetAt(index);
\r
582 SecureZeroMemory(&rItem, sizeof(LVITEM));
\r
583 rItem.mask = LVIF_STATE;
\r
584 rItem.iItem = index;
\r
585 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
\r
589 // p->translate(QPoint(opt.rect.left(), opt.rect.top()));
\r
593 if (data->m_Lanes.size() == 0)
\r
594 m_logEntries.setLane(data->m_CommitHash);
\r
596 std::vector<int>& lanes=data->m_Lanes;
\r
597 UINT laneNum = lanes.size();
\r
598 UINT mergeLane = 0;
\r
599 for (UINT i = 0; i < laneNum; i++)
\r
600 if (Lanes::isMerge(lanes[i])) {
\r
605 int x1 = 0, x2 = 0;
\r
606 int maxWidth = rect.Width();
\r
607 int lw = 3 * rect.Height() / 4; //laneWidth()
\r
608 for (UINT i = 0; i < laneNum && x2 < maxWidth; i++) {
\r
614 if (ln == Lanes::EMPTY)
\r
617 UINT col = ( Lanes:: isHead(ln) ||Lanes:: isTail(ln) || Lanes::isJoin(ln)
\r
618 || ln ==Lanes:: CROSS_EMPTY) ? mergeLane : i;
\r
620 if (ln == Lanes::CROSS) {
\r
621 paintGraphLane(hdc, rect.Height(),Lanes::NOT_ACTIVE, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
\r
622 paintGraphLane(hdc, rect.Height(),Lanes::CROSS, x1, x2, m_LineColors[mergeLane % Lanes::COLORS_NUM],rect.top);
\r
624 paintGraphLane(hdc, rect.Height(),ln, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
\r
627 TRACE(_T("index %d %d\r\n"),index,data->m_Lanes.size());
\r
630 void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR *pNMHDR, LRESULT *pResult)
\r
633 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
\r
634 // Take the default processing unless we set this to something else below.
\r
635 *pResult = CDRF_DODEFAULT;
\r
637 if (m_bNoDispUpdates)
\r
642 switch (pLVCD->nmcd.dwDrawStage)
\r
644 case CDDS_PREPAINT:
\r
646 *pResult = CDRF_NOTIFYITEMDRAW;
\r
650 case CDDS_ITEMPREPAINT:
\r
652 // This is the prepaint stage for an item. Here's where we set the
\r
653 // item's text color.
\r
655 // Tell Windows to send draw notifications for each subitem.
\r
656 *pResult = CDRF_NOTIFYSUBITEMDRAW;
\r
658 COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);
\r
660 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
\r
662 GitRev* data = (GitRev*)m_arShownList.GetAt(pLVCD->nmcd.dwItemSpec);
\r
666 if (data->bCopiedSelf)
\r
668 // only change the background color if the item is not 'hot' (on vista with m_Themes enabled)
\r
669 if (!m_Theme.IsAppm_Themed() || !m_bVista || ((pLVCD->nmcd.uItemState & CDIS_HOT)==0))
\r
670 pLVCD->clrTextBk = GetSysColor(COLOR_MENU);
\r
674 crText = m_Colors.GetColor(CColors::Modified);
\r
676 // if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))
\r
677 // crText = GetSysColor(COLOR_GRAYTEXT);
\r
678 // if (data->Rev == m_wcRev)
\r
680 // SelectObject(pLVCD->nmcd.hdc, m_boldFont);
\r
681 // We changed the font, so we're returning CDRF_NEWFONT. This
\r
682 // tells the control to recalculate the extent of the text.
\r
683 // *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
\r
687 if (m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec)
\r
689 if (m_bStrictStopped)
\r
690 crText = GetSysColor(COLOR_GRAYTEXT);
\r
692 // Store the color back in the NMLVCUSTOMDRAW struct.
\r
693 pLVCD->clrText = crText;
\r
697 case CDDS_ITEMPREPAINT|CDDS_ITEM|CDDS_SUBITEM:
\r
699 if ((m_bStrictStopped)&&(m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec))
\r
701 pLVCD->nmcd.uItemState &= ~(CDIS_SELECTED|CDIS_FOCUS);
\r
704 if (pLVCD->iSubItem == LOGLIST_GRAPH)
\r
706 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
\r
709 GetSubItemRect(pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
\r
711 FillBackGround(pLVCD->nmcd.hdc, (INT_PTR)pLVCD->nmcd.dwItemSpec,rect);
\r
712 DrawGraph(pLVCD->nmcd.hdc,rect,pLVCD->nmcd.dwItemSpec);
\r
714 *pResult = CDRF_SKIPDEFAULT;
\r
720 if (pLVCD->iSubItem == LOGLIST_MESSAGE)
\r
722 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
\r
724 GitRev* data = (GitRev*)m_arShownList.GetAt(pLVCD->nmcd.dwItemSpec);
\r
725 //if(!data->m_IsFull)
\r
727 //if(data->SafeFetchFullInfo(&g_Git))
\r
728 // this->Invalidate();
\r
729 //TRACE(_T("Update ... %d\r\n"),pLVCD->nmcd.dwItemSpec);
\r
732 if(m_HashMap[data->m_CommitHash].size()!=0)
\r
736 GetSubItemRect(pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
\r
738 FillBackGround(pLVCD->nmcd.hdc, (INT_PTR)pLVCD->nmcd.dwItemSpec,rect);
\r
739 DrawTagBranch(pLVCD->nmcd.hdc,rect,pLVCD->nmcd.dwItemSpec);
\r
741 *pResult = CDRF_SKIPDEFAULT;
\r
748 if (pLVCD->iSubItem == 1)
\r
750 if(this->m_IsIDReplaceAction)
\r
752 *pResult = CDRF_DODEFAULT;
\r
755 *pResult = CDRF_DODEFAULT;
\r
757 if (m_arShownList.GetCount() <= (INT_PTR)pLVCD->nmcd.dwItemSpec)
\r
761 int iconwidth = ::GetSystemMetrics(SM_CXSMICON);
\r
762 int iconheight = ::GetSystemMetrics(SM_CYSMICON);
\r
764 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_arShownList.GetAt(pLVCD->nmcd.dwItemSpec));
\r
766 GetSubItemRect(pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
\r
767 // Get the selected state of the
\r
768 // item being drawn.
\r
770 // Fill the background
\r
771 FillBackGround(pLVCD->nmcd.hdc, (INT_PTR)pLVCD->nmcd.dwItemSpec,rect);
\r
773 // Draw the icon(s) into the compatible DC
\r
774 if (pLogEntry->m_Action & CTGitPath::LOGACTIONS_MODIFIED)
\r
775 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hModifiedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
\r
778 if (pLogEntry->m_Action & CTGitPath::LOGACTIONS_ADDED)
\r
779 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hAddedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
\r
782 if (pLogEntry->m_Action & CTGitPath::LOGACTIONS_DELETED)
\r
783 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hDeletedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
\r
786 if (pLogEntry->m_Action & CTGitPath::LOGACTIONS_REPLACED)
\r
787 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hReplacedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
\r
789 *pResult = CDRF_SKIPDEFAULT;
\r
795 *pResult = CDRF_DODEFAULT;
\r
799 // CGitLogListBase message handlers
\r
801 void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR *pNMHDR, LRESULT *pResult)
\r
803 NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
\r
805 // Create a pointer to the item
\r
806 LV_ITEM* pItem = &(pDispInfo)->item;
\r
808 // Do the list need text information?
\r
809 if (!(pItem->mask & LVIF_TEXT))
\r
812 // By default, clear text buffer.
\r
813 lstrcpyn(pItem->pszText, _T(""), pItem->cchTextMax);
\r
815 bool bOutOfRange = pItem->iItem >= ShownCountWithStopped();
\r
818 if (m_bNoDispUpdates || bOutOfRange)
\r
821 // Which item number?
\r
822 int itemid = pItem->iItem;
\r
823 GitRev * pLogEntry = NULL;
\r
824 if (itemid < m_arShownList.GetCount())
\r
825 pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.GetAt(pItem->iItem));
\r
828 temp.Format(_T("%d"),m_arShownList.GetCount()-pItem->iItem);
\r
831 switch (pItem->iSubItem)
\r
833 case this->LOGLIST_GRAPH: //Graphic
\r
838 case this->LOGLIST_ACTION: //action -- no text in the column
\r
839 if(this->m_IsIDReplaceAction)
\r
840 lstrcpyn(pItem->pszText, temp, pItem->cchTextMax);
\r
842 case this->LOGLIST_MESSAGE: //Message
\r
844 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->m_Subject, pItem->cchTextMax);
\r
846 case this->LOGLIST_AUTHOR: //Author
\r
848 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->m_AuthorName, pItem->cchTextMax);
\r
850 case this->LOGLIST_DATE: //Date
\r
852 lstrcpyn(pItem->pszText,
\r
853 CAppUtils::FormatDateAndTime( pLogEntry->m_AuthorDate, m_DateFormat ),
\r
854 pItem->cchTextMax);
\r
865 void CGitLogListBase::OnContextMenu(CWnd* pWnd, CPoint point)
\r
868 int selIndex = GetSelectionMark();
\r
870 return; // nothing selected, nothing to do with a context menu
\r
872 // if the user selected the info text telling about not all revisions shown due to
\r
873 // the "stop on copy/rename" option, we also don't show the context menu
\r
874 if ((m_bStrictStopped)&&(selIndex == m_arShownList.GetCount()))
\r
877 // if the context menu is invoked through the keyboard, we have to use
\r
878 // a calculated position on where to anchor the menu on
\r
879 if ((point.x == -1) && (point.y == -1))
\r
882 GetItemRect(selIndex, &rect, LVIR_LABEL);
\r
883 ClientToScreen(&rect);
\r
884 point = rect.CenterPoint();
\r
886 m_nSearchIndex = selIndex;
\r
887 m_bCancelled = FALSE;
\r
889 // calculate some information the context menu commands can use
\r
890 // CString pathURL = GetURLFromPath(m_path);
\r
892 POSITION pos = GetFirstSelectedItemPosition();
\r
893 int indexNext = GetNextSelectedItem(pos);
\r
897 GitRev* pSelLogEntry = reinterpret_cast<GitRev*>(m_arShownList.GetAt(indexNext));
\r
899 GitRev revSelected = pSelLogEntry->Rev;
\r
900 GitRev revPrevious = git_revnum_t(revSelected)-1;
\r
901 if ((pSelLogEntry->pArChangedPaths)&&(pSelLogEntry->pArChangedPaths->GetCount() <= 2))
\r
903 for (int i=0; i<pSelLogEntry->pArChangedPaths->GetCount(); ++i)
\r
905 LogChangedPath * changedpath = (LogChangedPath *)pSelLogEntry->pArChangedPaths->GetAt(i);
\r
906 if (changedpath->lCopyFromRev)
\r
907 revPrevious = changedpath->lCopyFromRev;
\r
910 GitRev revSelected2;
\r
913 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(GetNextSelectedItem(pos)));
\r
914 revSelected2 = pLogEntry->Rev;
\r
916 bool bAllFromTheSameAuthor = true;
\r
917 CString firstAuthor;
\r
918 CLogDataVector selEntries;
\r
919 GitRev revLowest, revHighest;
\r
920 GitRevRangeArray revisionRanges;
\r
922 POSITION pos = GetFirstSelectedItemPosition();
\r
923 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(GetNextSelectedItem(pos)));
\r
924 revisionRanges.AddRevision(pLogEntry->Rev);
\r
925 selEntries.push_back(pLogEntry);
\r
926 firstAuthor = pLogEntry->sAuthor;
\r
927 revLowest = pLogEntry->Rev;
\r
928 revHighest = pLogEntry->Rev;
\r
931 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(GetNextSelectedItem(pos)));
\r
932 revisionRanges.AddRevision(pLogEntry->Rev);
\r
933 selEntries.push_back(pLogEntry);
\r
934 if (firstAuthor.Compare(pLogEntry->sAuthor))
\r
935 bAllFromTheSameAuthor = false;
\r
936 revLowest = (git_revnum_t(pLogEntry->Rev) > git_revnum_t(revLowest) ? revLowest : pLogEntry->Rev);
\r
937 revHighest = (git_revnum_t(pLogEntry->Rev) < git_revnum_t(revHighest) ? revHighest : pLogEntry->Rev);
\r
943 int FirstSelect=-1, LastSelect=-1;
\r
944 pos = GetFirstSelectedItemPosition();
\r
945 FirstSelect = GetNextSelectedItem(pos);
\r
948 LastSelect = GetNextSelectedItem(pos);
\r
950 //entry is selected, now show the popup menu
\r
952 if (popup.CreatePopupMenu())
\r
954 if (GetSelectedCount() == 1)
\r
957 if (!m_path.IsDirectory())
\r
961 popup.AppendMenuIcon(ID_COMPARE, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
\r
962 popup.AppendMenuIcon(ID_BLAMECOMPARE, IDS_LOG_POPUP_BLAMECOMPARE, IDI_BLAME);
\r
964 popup.AppendMenuIcon(ID_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF_CH, IDI_DIFF);
\r
965 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF);
\r
966 popup.AppendMenu(MF_SEPARATOR, NULL);
\r
967 popup.AppendMenuIcon(ID_SAVEAS, IDS_LOG_POPUP_SAVE, IDI_SAVEAS);
\r
968 popup.AppendMenuIcon(ID_OPEN, IDS_LOG_POPUP_OPEN, IDI_OPEN);
\r
969 popup.AppendMenuIcon(ID_OPENWITH, IDS_LOG_POPUP_OPENWITH, IDI_OPEN);
\r
970 popup.AppendMenuIcon(ID_BLAME, IDS_LOG_POPUP_BLAME, IDI_BLAME);
\r
971 popup.AppendMenu(MF_SEPARATOR, NULL);
\r
978 popup.AppendMenuIcon(ID_COMPARE, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
\r
980 // TortoiseMerge could be improved to take a /blame switch
\r
981 // and then not 'cat' the files from a unified diff but
\r
983 // But until that's implemented, the context menu entry for
\r
984 // this feature is commented out.
\r
985 //popup.AppendMenu(ID_BLAMECOMPARE, IDS_LOG_POPUP_BLAMECOMPARE, IDI_BLAME);
\r
987 popup.AppendMenuIcon(ID_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF_CH, IDI_DIFF);
\r
988 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF);
\r
989 //popup.AppendMenuIcon(ID_BLAMEWITHPREVIOUS, IDS_LOG_POPUP_BLAMEWITHPREVIOUS, IDI_BLAME);
\r
990 popup.AppendMenu(MF_SEPARATOR, NULL);
\r
993 // if (!m_ProjectProperties.sWebViewerRev.IsEmpty())
\r
995 // popup.AppendMenuIcon(ID_VIEWREV, IDS_LOG_POPUP_VIEWREV);
\r
997 // if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
\r
999 // popup.AppendMenuIcon(ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
\r
1001 // if ((!m_ProjectProperties.sWebViewerPathRev.IsEmpty())||
\r
1002 // (!m_ProjectProperties.sWebViewerRev.IsEmpty()))
\r
1004 // popup.AppendMenu(MF_SEPARATOR, NULL);
\r
1008 // popup.AppendMenuIcon(ID_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
\r
1010 // popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT);
\r
1012 // popup.AppendMenuIcon(ID_MERGEREV, IDS_LOG_POPUP_MERGEREV, IDI_MERGE);
\r
1015 str.Format(_T("Reset %s to this"),g_Git.GetCurrentBranch());
\r
1016 popup.AppendMenuIcon(ID_RESET,str,IDI_REVERT);
\r
1017 popup.AppendMenuIcon(ID_SWITCHTOREV, _T("Switch/Checkout to this") , IDI_SWITCH);
\r
1018 popup.AppendMenuIcon(ID_CREATE_BRANCH, _T("Create Branch at this version") , IDI_COPY);
\r
1019 popup.AppendMenuIcon(ID_CREATE_TAG, _T("Create Tag at this version"), IDI_COPY);
\r
1020 popup.AppendMenuIcon(ID_CHERRY_PICK, _T("Cherry Pick this version"), IDI_EXPORT);
\r
1021 popup.AppendMenuIcon(ID_EXPORT, _T("Export this version"), IDI_EXPORT);
\r
1024 popup.AppendMenu(MF_SEPARATOR, NULL);
\r
1026 else if (GetSelectedCount() >= 2)
\r
1028 bool bAddSeparator = false;
\r
1029 if (IsSelectionContinuous() || (GetSelectedCount() == 2))
\r
1031 popup.AppendMenuIcon(ID_COMPARETWO, IDS_LOG_POPUP_COMPARETWO, IDI_DIFF);
\r
1033 if (GetSelectedCount() == 2)
\r
1035 //popup.AppendMenuIcon(ID_BLAMETWO, IDS_LOG_POPUP_BLAMEREVS, IDI_BLAME);
\r
1036 popup.AppendMenuIcon(ID_GNUDIFF2, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
\r
1037 bAddSeparator = true;
\r
1041 //popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREVS, IDI_REVERT);
\r
1043 // popup.AppendMenuIcon(ID_MERGEREV, IDS_LOG_POPUP_MERGEREVS, IDI_MERGE);
\r
1044 bAddSeparator = true;
\r
1046 if (bAddSeparator)
\r
1047 popup.AppendMenu(MF_SEPARATOR, NULL);
\r
1050 // if ((selEntries.size() > 0)&&(bAllFromTheSameAuthor))
\r
1052 // popup.AppendMenuIcon(ID_EDITAUTHOR, IDS_LOG_POPUP_EDITAUTHOR);
\r
1054 // if (GetSelectedCount() == 1)
\r
1056 // popup.AppendMenuIcon(ID_EDITLOG, IDS_LOG_POPUP_EDITLOG);
\r
1057 // popup.AppendMenuIcon(ID_REVPROPS, IDS_REPOBROWSE_SHOWREVPROP, IDI_PROPERTIES); // "Show Revision Properties"
\r
1058 // popup.AppendMenu(MF_SEPARATOR, NULL);
\r
1063 if (GetSelectedCount() == 1)
\r
1065 popup.AppendMenuIcon(ID_COPYHASH, _T("Copy Commit Hash"));
\r
1067 if (GetSelectedCount() != 0)
\r
1069 popup.AppendMenuIcon(ID_COPYCLIPBOARD, IDS_LOG_POPUP_COPYTOCLIPBOARD);
\r
1071 popup.AppendMenuIcon(ID_FINDENTRY, IDS_LOG_POPUP_FIND);
\r
1073 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
\r
1074 // DialogEnableWindow(IDOK, FALSE);
\r
1075 // SetPromptApp(&theApp);
\r
1077 this->ContextMenuAction(cmd, FirstSelect, LastSelect);
\r
1079 // EnableOKButton();
\r
1080 } // if (popup.CreatePopupMenu())
\r
1084 bool CGitLogListBase::IsSelectionContinuous()
\r
1086 if ( GetSelectedCount()==1 )
\r
1088 // if only one revision is selected, the selection is of course
\r
1093 POSITION pos = GetFirstSelectedItemPosition();
\r
1094 bool bContinuous = (m_arShownList.GetCount() == (INT_PTR)m_logEntries.size());
\r
1097 int itemindex = GetNextSelectedItem(pos);
\r
1100 int nextindex = GetNextSelectedItem(pos);
\r
1101 if (nextindex - itemindex > 1)
\r
1103 bContinuous = false;
\r
1106 itemindex = nextindex;
\r
1109 return bContinuous;
\r
1112 void CGitLogListBase::CopySelectionToClipBoard(bool HashOnly)
\r
1115 CString sClipdata;
\r
1116 POSITION pos = GetFirstSelectedItemPosition();
\r
1120 sRev.LoadString(IDS_LOG_REVISION);
\r
1122 sAuthor.LoadString(IDS_LOG_AUTHOR);
\r
1124 sDate.LoadString(IDS_LOG_DATE);
\r
1126 sMessage.LoadString(IDS_LOG_MESSAGE);
\r
1129 CString sLogCopyText;
\r
1131 GitRev * pLogEntry = reinterpret_cast<GitRev *>(m_arShownList.GetAt(GetNextSelectedItem(pos)));
\r
1135 //pLogEntry->m_Files
\r
1136 //LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
\r
1138 for (int cpPathIndex = 0; cpPathIndex<pLogEntry->m_Files.GetCount(); ++cpPathIndex)
\r
1140 sPaths += ((CTGitPath&)pLogEntry->m_Files[cpPathIndex]).GetActionName() + _T(" : ") + pLogEntry->m_Files[cpPathIndex].GetGitPathString();
\r
1141 sPaths += _T("\r\n");
\r
1144 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
1145 (LPCTSTR)sRev, pLogEntry->m_CommitHash,
\r
1146 (LPCTSTR)sAuthor, (LPCTSTR)pLogEntry->m_AuthorName,
\r
1147 (LPCTSTR)sDate, (LPCTSTR)CAppUtils::FormatDateAndTime( pLogEntry->m_AuthorDate, m_DateFormat ),
\r
1148 (LPCTSTR)sMessage, pLogEntry->m_Subject+_T("\r\n")+pLogEntry->m_Body,
\r
1150 sClipdata += sLogCopyText;
\r
1153 sClipdata += pLogEntry->m_CommitHash;
\r
1158 CStringUtils::WriteAsciiStringToClipboard(sClipdata, GetSafeHwnd());
\r
1163 void CGitLogListBase::DiffSelectedRevWithPrevious()
\r
1166 if (m_bThreadRunning)
\r
1168 UpdateLogInfoLabel();
\r
1169 int selIndex = m_LogList.GetSelectionMark();
\r
1172 int selCount = m_LogList.GetSelectedCount();
\r
1173 if (selCount != 1)
\r
1176 // Find selected entry in the log list
\r
1177 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
\r
1178 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(m_LogList.GetNextSelectedItem(pos)));
\r
1179 long rev1 = pLogEntry->Rev;
\r
1180 long rev2 = rev1-1;
\r
1181 CTGitPath path = m_path;
\r
1183 // See how many files under the relative root were changed in selected revision
\r
1185 LogChangedPath * changed = NULL;
\r
1186 for (INT_PTR c = 0; c < pLogEntry->pArChangedPaths->GetCount(); ++c)
\r
1188 LogChangedPath * cpath = pLogEntry->pArChangedPaths->GetAt(c);
\r
1189 if (cpath && cpath -> sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
\r
1196 if (m_path.IsDirectory() && nChanged == 1)
\r
1198 // We're looking at the log for a directory and only one file under dir was changed in the revision
\r
1199 // Do diff on that file instead of whole directory
\r
1200 path.AppendPathString(changed->sPath.Mid(m_sRelativeRoot.GetLength()));
\r
1203 m_bCancelled = FALSE;
\r
1204 DialogEnableWindow(IDOK, FALSE);
\r
1205 SetPromptApp(&theApp);
\r
1206 theApp.DoWaitCursor(1);
\r
1208 if (PromptShown())
\r
1210 GitDiff diff(this, m_hWnd, true);
\r
1211 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
\r
1212 diff.SetHEADPeg(m_LogRevision);
\r
1213 diff.ShowCompare(path, rev2, path, rev1);
\r
1217 CAppUtils::StartShowCompare(m_hWnd, path, rev2, path, rev1, GitRev(), m_LogRevision, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
\r
1220 theApp.DoWaitCursor(-1);
\r
1225 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR *pNMHDR, LRESULT *pResult)
\r
1227 LPNMLVFINDITEM pFindInfo = reinterpret_cast<LPNMLVFINDITEM>(pNMHDR);
\r
1230 if (pFindInfo->lvfi.flags & LVFI_PARAM)
\r
1232 if ((pFindInfo->iStart < 0)||(pFindInfo->iStart >= m_arShownList.GetCount()))
\r
1234 if (pFindInfo->lvfi.psz == 0)
\r
1237 CString sCmp = pFindInfo->lvfi.psz;
\r
1239 for (int i=pFindInfo->iStart; i<m_arShownList.GetCount(); ++i)
\r
1241 GitRev * pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.GetAt(i));
\r
1242 sRev.Format(_T("%ld"), pLogEntry->Rev);
\r
1243 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
\r
1245 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
\r
1253 if (sCmp.Compare(sRev)==0)
\r
1260 if (pFindInfo->lvfi.flags & LVFI_WRAP)
\r
1262 for (int i=0; i<pFindInfo->iStart; ++i)
\r
1264 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(i));
\r
1265 sRev.Format(_T("%ld"), pLogEntry->Rev);
\r
1266 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
\r
1268 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
\r
1276 if (sCmp.Compare(sRev)==0)
\r
1288 int CGitLogListBase::FillGitLog(CTGitPath *path,int info)
\r
1292 this->m_logEntries.ClearAll();
\r
1293 this->m_logEntries.ParserFromLog(path,-1,info);
\r
1295 //this->m_logEntries.ParserFromLog();
\r
1296 SetItemCountEx(this->m_logEntries.size());
\r
1298 this->m_arShownList.RemoveAll();
\r
1300 for(unsigned int i=0;i<m_logEntries.size();i++)
\r
1302 m_logEntries[i].m_IsFull=TRUE;
\r
1303 this->m_arShownList.Add(&m_logEntries[i]);
\r
1312 int CGitLogListBase::FillGitShortLog()
\r
1316 this->m_logEntries.ClearAll();
\r
1318 m_LogCache.FetchCacheIndex(g_Git.m_CurrentDir);
\r
1321 if(this->m_Path.IsEmpty())
\r
1324 path=&this->m_Path;
\r
1328 mask = CGit::LOG_INFO_ONLY_HASH | CGit::LOG_INFO_BOUNDARY;
\r
1329 // if(this->m_bAllBranch)
\r
1330 mask |= m_ShowMask;
\r
1332 this->m_logEntries.ParserShortLog(path,hash,-1,mask);
\r
1335 //this->m_logEntries.ParserFromLog();
\r
1336 if(IsInWorkingThread())
\r
1337 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL);
\r
1339 SetItemCountEx(this->m_logEntries.size());
\r
1341 this->m_arShownList.RemoveAll();
\r
1343 for(unsigned int i=0;i<m_logEntries.size();i++)
\r
1344 this->m_arShownList.Add(&m_logEntries[i]);
\r
1349 BOOL CGitLogListBase::PreTranslateMessage(MSG* pMsg)
\r
1351 // Skip Ctrl-C when copying text out of the log message or search filter
\r
1352 BOOL bSkipAccelerator = ( pMsg->message == WM_KEYDOWN && pMsg->wParam=='C' && (GetFocus()==GetDlgItem(IDC_MSGVIEW) || GetFocus()==GetDlgItem(IDC_SEARCHEDIT) ) && GetKeyState(VK_CONTROL)&0x8000 );
\r
1353 if (pMsg->message == WM_KEYDOWN && pMsg->wParam=='\r')
\r
1355 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))
\r
1357 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
\r
1359 DiffSelectedRevWithPrevious();
\r
1364 if (GetFocus()==GetDlgItem(IDC_LOGMSG))
\r
1366 DiffSelectedFile();
\r
1373 if (m_hAccel && !bSkipAccelerator)
\r
1375 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
\r
1381 //m_tooltips.RelayEvent(pMsg);
\r
1382 return __super::PreTranslateMessage(pMsg);
\r
1385 void CGitLogListBase::OnNMDblclkLoglist(NMHDR * /*pNMHDR*/, LRESULT *pResult)
\r
1387 // a double click on an entry in the revision list has happened
\r
1390 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
\r
1391 DiffSelectedRevWithPrevious();
\r
1394 int CGitLogListBase::FetchLogAsync(void * data)
\r
1397 m_bExitThread=FALSE;
\r
1398 InterlockedExchange(&m_bThreadRunning, TRUE);
\r
1399 InterlockedExchange(&m_bNoDispUpdates, TRUE);
\r
1400 m_LoadingThread = AfxBeginThread(LogThreadEntry, this);
\r
1401 if (m_LoadingThread ==NULL)
\r
1403 InterlockedExchange(&m_bThreadRunning, FALSE);
\r
1404 InterlockedExchange(&m_bNoDispUpdates, FALSE);
\r
1405 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
\r
1411 //this is the thread function which calls the subversion function
\r
1412 UINT CGitLogListBase::LogThreadEntry(LPVOID pVoid)
\r
1414 return ((CGitLogListBase*)pVoid)->LogThread();
\r
1417 void CGitLogListBase::GetTimeRange(CTime &oldest, CTime &latest)
\r
1420 oldest=CTime::GetCurrentTime();
\r
1421 latest=CTime(1971,1,2,0,0,0);
\r
1422 for(unsigned int i=0;i<m_logEntries.size();i++)
\r
1424 if(m_logEntries[i].m_AuthorDate.GetTime() < oldest.GetTime())
\r
1425 oldest = m_logEntries[i].m_AuthorDate.GetTime();
\r
1427 if(m_logEntries[i].m_AuthorDate.GetTime() > latest.GetTime())
\r
1428 latest = m_logEntries[i].m_AuthorDate.GetTime();
\r
1433 UINT CGitLogListBase::LogThread()
\r
1436 // if(m_ProcCallBack)
\r
1437 // m_ProcCallBack(m_ProcData,GITLOG_START);
\r
1438 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_START,0);
\r
1440 InterlockedExchange(&m_bThreadRunning, TRUE);
\r
1441 InterlockedExchange(&m_bNoDispUpdates, TRUE);
\r
1443 //does the user force the cache to refresh (shift or control key down)?
\r
1444 bool refresh = (GetKeyState (VK_CONTROL) < 0)
\r
1445 || (GetKeyState (VK_SHIFT) < 0);
\r
1447 //disable the "Get All" button while we're receiving
\r
1450 FillGitShortLog();
\r
1452 if(this->m_bExitThread)
\r
1455 RedrawItems(0, m_arShownList.GetCount());
\r
1456 // SetRedraw(false);
\r
1457 // ResizeAllListCtrlCols();
\r
1458 // SetRedraw(true);
\r
1460 if ( m_pStoreSelection )
\r
1462 // Deleting the instance will restore the
\r
1463 // selection of the CLogDlg.
\r
1464 delete m_pStoreSelection;
\r
1465 m_pStoreSelection = NULL;
\r
1469 // If no selection has been set then this must be the first time
\r
1470 // the revisions are shown. Let's preselect the topmost revision.
\r
1471 if ( GetItemCount()>0 )
\r
1473 SetSelectionMark(0);
\r
1474 SetItemState(0, LVIS_SELECTED, LVIS_SELECTED);
\r
1478 InterlockedExchange(&m_bNoDispUpdates, FALSE);
\r
1481 unsigned int updated=0;
\r
1486 for(unsigned int i=0;i<m_logEntries.size();i++)
\r
1488 if(m_LogCache.GetCacheData(m_logEntries[i]))
\r
1490 if(!m_logEntries.FetchFullInfo(i))
\r
1494 m_LogCache.AddCacheEntry(m_logEntries[i]);
\r
1499 InterlockedExchange(&m_logEntries[i].m_IsUpdateing,FALSE);
\r
1500 InterlockedExchange(&m_logEntries[i].m_IsFull,TRUE);
\r
1503 ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)i,0);
\r
1508 percent=updated*98/m_logEntries.size() + GITLOG_START+1;
\r
1509 if(percent == GITLOG_END)
\r
1510 percent = GITLOG_END -1;
\r
1512 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) percent,0);
\r
1516 if(updated==m_logEntries.size())
\r
1520 //RefreshCursor();
\r
1521 // make sure the filter is applied (if any) now, after we refreshed/fetched
\r
1522 // the log messages
\r
1524 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_END,0);
\r
1526 InterlockedExchange(&m_bThreadRunning, FALSE);
\r
1531 void CGitLogListBase::Refresh()
\r
1533 if(!m_bThreadRunning)
\r
1535 this->SetItemCountEx(0);
\r
1536 m_logEntries.clear();
\r
1537 InterlockedExchange(&m_bThreadRunning, TRUE);
\r
1538 InterlockedExchange(&m_bNoDispUpdates, TRUE);
\r
1539 if (AfxBeginThread(LogThreadEntry, this)==NULL)
\r
1541 InterlockedExchange(&m_bThreadRunning, FALSE);
\r
1542 InterlockedExchange(&m_bNoDispUpdates, FALSE);
\r
1543 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
\r
1545 m_sFilterText.Empty();
\r
1546 m_From=CTime(1970,1,2,0,0,0);
\r
1547 m_To=CTime::GetCurrentTime();
\r
1550 bool CGitLogListBase::ValidateRegexp(LPCTSTR regexp_str, tr1::wregex& pat, bool bMatchCase /* = false */)
\r
1554 tr1::regex_constants::syntax_option_type type = tr1::regex_constants::ECMAScript;
\r
1556 type |= tr1::regex_constants::icase;
\r
1557 pat = tr1::wregex(regexp_str, type);
\r
1560 catch (exception) {}
\r
1564 void CGitLogListBase::RecalculateShownList(CPtrArray * pShownlist)
\r
1567 pShownlist->RemoveAll();
\r
1568 tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
\r
1569 bool bRegex = false;
\r
1570 if (m_bFilterWithRegex)
\r
1571 bRegex = ValidateRegexp(m_sFilterText, pat, false);
\r
1573 tr1::regex_constants::match_flag_type flags = tr1::regex_constants::match_any;
\r
1575 for (DWORD i=0; i<m_logEntries.size(); ++i)
\r
1577 if ((bRegex)&&(m_bFilterWithRegex))
\r
1580 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
\r
1582 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR)m_logEntries[i]->sBugIDs);
\r
1583 if (regex_search(wstring((LPCTSTR)m_logEntries[i]->sBugIDs), pat, flags)&&IsEntryInDateRange(i))
\r
1585 pShownlist->Add(m_logEntries[i]);
\r
1590 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_MESSAGES))
\r
1592 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries[i].m_Subject);
\r
1593 if (regex_search(wstring((LPCTSTR)m_logEntries[i].m_Subject), pat, flags)&&IsEntryInDateRange(i))
\r
1595 pShownlist->Add(&m_logEntries[i]);
\r
1599 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries[i].m_Body);
\r
1600 if (regex_search(wstring((LPCTSTR)m_logEntries[i].m_Body), pat, flags)&&IsEntryInDateRange(i))
\r
1602 pShownlist->Add(&m_logEntries[i]);
\r
1607 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_PATHS))
\r
1609 LogChangedPathArray * cpatharray = m_logEntries[i]->pArChangedPaths;
\r
1611 bool bGoing = true;
\r
1612 for (INT_PTR cpPathIndex = 0; cpPathIndex<cpatharray->GetCount() && bGoing; ++cpPathIndex)
\r
1614 LogChangedPath * cpath = cpatharray->GetAt(cpPathIndex);
\r
1615 if (regex_search(wstring((LPCTSTR)cpath->sCopyFromPath), pat, flags)&&IsEntryInDateRange(i))
\r
1617 pShownlist->Add(m_logEntries[i]);
\r
1621 if (regex_search(wstring((LPCTSTR)cpath->sPath), pat, flags)&&IsEntryInDateRange(i))
\r
1623 pShownlist->Add(m_logEntries[i]);
\r
1627 if (regex_search(wstring((LPCTSTR)cpath->GetAction()), pat, flags)&&IsEntryInDateRange(i))
\r
1629 pShownlist->Add(m_logEntries[i]);
\r
1638 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_AUTHORS))
\r
1640 if (regex_search(wstring((LPCTSTR)m_logEntries[i].m_AuthorName), pat, flags)&&IsEntryInDateRange(i))
\r
1642 pShownlist->Add(&m_logEntries[i]);
\r
1646 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_REVS))
\r
1648 sRev.Format(_T("%ld"), m_logEntries[i].m_CommitHash);
\r
1649 if (regex_search(wstring((LPCTSTR)sRev), pat, flags)&&IsEntryInDateRange(i))
\r
1651 pShownlist->Add(&m_logEntries[i]);
\r
1658 CString find = m_sFilterText;
\r
1661 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
\r
1663 CString sBugIDs = m_logEntries[i]->sBugIDs;
\r
1665 sBugIDs = sBugIDs.MakeLower();
\r
1666 if ((sBugIDs.Find(find) >= 0)&&(IsEntryInDateRange(i)))
\r
1668 pShownlist->Add(m_logEntries[i]);
\r
1673 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_MESSAGES))
\r
1675 CString msg = m_logEntries[i].m_Subject;
\r
1677 msg = msg.MakeLower();
\r
1678 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
\r
1680 pShownlist->Add(&m_logEntries[i]);
\r
1683 msg = m_logEntries[i].m_Body;
\r
1685 msg = msg.MakeLower();
\r
1686 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
\r
1688 pShownlist->Add(&m_logEntries[i]);
\r
1693 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_PATHS))
\r
1695 LogChangedPathArray * cpatharray = m_logEntries[i]->pArChangedPaths;
\r
1697 bool bGoing = true;
\r
1698 for (INT_PTR cpPathIndex = 0; cpPathIndex<cpatharray->GetCount() && bGoing; ++cpPathIndex)
\r
1700 LogChangedPath * cpath = cpatharray->GetAt(cpPathIndex);
\r
1701 CString path = cpath->sCopyFromPath;
\r
1703 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
\r
1705 pShownlist->Add(m_logEntries[i]);
\r
1709 path = cpath->sPath;
\r
1711 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
\r
1713 pShownlist->Add(m_logEntries[i]);
\r
1717 path = cpath->GetAction();
\r
1719 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
\r
1721 pShownlist->Add(m_logEntries[i]);
\r
1728 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_AUTHORS))
\r
1730 CString msg = m_logEntries[i].m_AuthorName;
\r
1731 msg = msg.MakeLower();
\r
1732 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
\r
1734 pShownlist->Add(&m_logEntries[i]);
\r
1738 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_REVS))
\r
1740 sRev.Format(_T("%ld"), m_logEntries[i].m_CommitHash);
\r
1741 if ((sRev.Find(find) >= 0)&&(IsEntryInDateRange(i)))
\r
1743 pShownlist->Add(&m_logEntries[i]);
\r
1747 } // else (from if (bRegex))
\r
1748 } // for (DWORD i=0; i<m_logEntries.size(); ++i)
\r
1752 BOOL CGitLogListBase::IsEntryInDateRange(int i)
\r
1754 __time64_t time = m_logEntries[i].m_AuthorDate.GetTime();
\r
1755 if ((time >= m_From.GetTime())&&(time <= m_To.GetTime()))
\r
1762 void CGitLogListBase::StartFilter()
\r
1764 InterlockedExchange(&m_bNoDispUpdates, TRUE);
\r
1765 RecalculateShownList(&m_arShownList);
\r
1766 InterlockedExchange(&m_bNoDispUpdates, FALSE);
\r
1770 SetItemCountEx(ShownCountWithStopped());
\r
1771 RedrawItems(0, ShownCountWithStopped());
\r
1773 //ResizeAllListCtrlCols();
\r
1778 void CGitLogListBase::RemoveFilter()
\r
1781 InterlockedExchange(&m_bNoDispUpdates, TRUE);
\r
1783 m_arShownList.RemoveAll();
\r
1785 // reset the time filter too
\r
1787 m_timFrom = (__time64_t(m_tFrom));
\r
1788 m_timTo = (__time64_t(m_tTo));
\r
1789 m_DateFrom.SetTime(&m_timFrom);
\r
1790 m_DateTo.SetTime(&m_timTo);
\r
1791 m_DateFrom.SetRange(&m_timFrom, &m_timTo);
\r
1792 m_DateTo.SetRange(&m_timFrom, &m_timTo);
\r
1795 for (DWORD i=0; i<m_logEntries.size(); ++i)
\r
1797 m_arShownList.Add(&m_logEntries[i]);
\r
1799 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
\r
1801 SetItemCountEx(ShownCountWithStopped());
\r
1802 RedrawItems(0, ShownCountWithStopped());
\r
1803 // SetRedraw(false);
\r
1804 // ResizeAllListCtrlCols();
\r
1805 // SetRedraw(true);
\r
1807 InterlockedExchange(&m_bNoDispUpdates, FALSE);
\r
1810 void CGitLogListBase::Clear()
\r
1812 m_arShownList.RemoveAll();
\r
1813 m_logEntries.clear();
\r
1814 m_logEntries.m_HashMap.clear();
\r
1816 m_logEntries.m_Lns.clear();
\r
1818 m_logEntries.m_FirstFreeLane=0;
\r
1819 m_logEntries.m_Lns.clear();
\r
1823 void CGitLogListBase::OnDestroy()
\r
1825 // save the column widths to the registry
\r
1826 SaveColumnWidths();
\r
1828 if(this->m_bThreadRunning)
\r
1830 this->m_bExitThread=true;
\r
1831 DWORD ret =::WaitForSingleObject(m_LoadingThread->m_hThread,20000);
\r
1832 if(ret == WAIT_TIMEOUT)
\r
1833 TerminateThread();
\r
1835 while(m_LogCache.SaveCache())
\r
1837 if(CMessageBox::Show(NULL,_T("Cannot Save Log Cache to Disk,click yes for retry, click no for give up"),_T("TortoiseGit"),
\r
1838 MB_YESNO) == IDNO)
\r
1841 CHintListCtrl::OnDestroy();
\r
1844 LRESULT CGitLogListBase::OnLoad(WPARAM wParam,LPARAM lParam)
\r
1847 int i=(int)wParam;
\r
1848 this->GetItemRect(i,&rect,LVIR_BOUNDS);
\r
1849 this->InvalidateRect(rect);
\r
1854 * Save column widths to the registry
\r
1856 void CGitLogListBase::SaveColumnWidths()
\r
1858 CHeaderCtrl* pHdrCtrl = (CHeaderCtrl*)(GetDlgItem(0));
\r
1861 int numcols = pHdrCtrl->GetItemCount();
\r
1862 for (int col = 0; col < numcols; col++)
\r
1864 int width = GetColumnWidth( col );
\r
1866 regentry.Format( _T("Software\\TortoiseGit\\log\\ColWidth%d"), col);
\r
1867 CRegDWORD regwidth(regentry, 0);
\r
1868 regwidth = width; // this writes it to reg
\r