use gitdll gethash and clean up some warning
[TortoiseGit.git] / src / TortoiseProc / GitLogListBase.cpp
blob4b014269959d2e8ff7014bc62be803e8a343af72
1 // GitLogList.cpp : implementation file
2 //
3 /*
4 Description: qgit revision list view
6 Author: Marco Costalba (C) 2005-2007
8 Copyright: See COPYING file that comes with this distribution
11 #include "stdafx.h"
12 #include "resource.h"
13 #include "GitLogListBase.h"
14 #include "GitRev.h"
15 //#include "VssStyle.h"
16 #include "IconMenu.h"
17 // CGitLogListBase
18 #include "cursor.h"
19 #include "InputDlg.h"
20 #include "PropDlg.h"
21 #include "SVNProgressDlg.h"
22 #include "ProgressDlg.h"
23 //#include "RepositoryBrowser.h"
24 //#include "CopyDlg.h"
25 //#include "StatGraphDlg.h"
26 #include "Logdlg.h"
27 #include "MessageBox.h"
28 #include "Registry.h"
29 #include "AppUtils.h"
30 #include "PathUtils.h"
31 #include "StringUtils.h"
32 #include "UnicodeUtils.h"
33 #include "TempFile.h"
34 //#include "GitInfo.h"
35 //#include "GitDiff.h"
36 #include "IconMenu.h"
37 //#include "RevisionRangeDlg.h"
38 //#include "BrowseFolder.h"
39 //#include "BlameDlg.h"
40 //#include "Blame.h"
41 //#include "GitHelpers.h"
42 #include "GitStatus.h"
43 //#include "LogDlgHelper.h"
44 //#include "CachedLogInfo.h"
45 //#include "RepositoryInfo.h"
46 //#include "EditPropertiesDlg.h"
47 #include "FileDiffDlg.h"
48 #include "..\\TortoiseShell\\Resource.h"
49 #include "FindDlg.h"
51 const UINT CGitLogListBase::m_FindDialogMessage = RegisterWindowMessage(FINDMSGSTRING);
53 IMPLEMENT_DYNAMIC(CGitLogListBase, CHintListCtrl)
55 CGitLogListBase::CGitLogListBase():CHintListCtrl()
56 ,m_regMaxBugIDColWidth(_T("Software\\TortoiseGit\\MaxBugIDColWidth"), 200)
57 ,m_nSearchIndex(0)
58 ,m_bNoDispUpdates(FALSE)
59 , m_bThreadRunning(FALSE)
60 , m_bStrictStopped(false)
61 , m_pStoreSelection(NULL)
62 , m_nSelectedFilter(LOGFILTER_ALL)
63 , m_bVista(false)
64 , m_bShowWC(false)
65 , m_logEntries(&m_LogCache)
66 , m_pFindDialog(NULL)
67 , m_ColumnManager(this)
68 , m_dwDefaultColumns(0)
69 , m_arShownList(&m_critSec)
71 // use the default GUI font, create a copy of it and
72 // change the copy to BOLD (leave the rest of the font
73 // the same)
74 HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
75 LOGFONT lf = {0};
76 GetObject(hFont, sizeof(LOGFONT), &lf);
77 lf.lfWeight = FW_BOLD;
78 m_boldFont = CreateFontIndirect(&lf);
80 m_bShowBugtraqColumn=false;
82 m_IsIDReplaceAction=FALSE;
84 this->m_critSec.Init();
85 m_wcRev.m_CommitHash.Empty();
86 m_wcRev.GetSubject()=_T("Working dir changes");
87 m_wcRev.m_ParentHash.clear();
88 m_wcRev.m_Mark=_T('-');
89 m_wcRev.m_IsUpdateing=FALSE;
90 m_wcRev.m_IsFull = TRUE;
92 m_hModifiedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONMODIFIED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
93 m_hReplacedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONREPLACED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
94 m_hAddedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONADDED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
95 m_hDeletedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONDELETED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
96 m_hFetchIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONFETCHING), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
98 m_bFilterWithRegex = !!CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), TRUE);
100 g_Git.GetMapHashToFriendName(m_HashMap);
101 m_CurrentBranch=g_Git.GetCurrentBranch();
102 this->m_HeadHash=g_Git.GetHash(_T("HEAD"));
104 m_From=-1;;
105 m_To=-1;
107 m_ShowMask = 0;
108 m_LoadingThread = NULL;
110 InterlockedExchange(&m_bExitThread,FALSE);
111 m_IsOldFirst = FALSE;
112 m_IsRebaseReplaceGraph = FALSE;
115 for(int i=0;i<Lanes::COLORS_NUM;i++)
117 m_LineColors[i] = m_Colors.GetColor((CColors::Colors)(CColors::BranchLine1+i));
119 // get short/long datetime setting from registry
120 DWORD RegUseShortDateFormat = CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE);
121 if ( RegUseShortDateFormat )
123 m_DateFormat = DATE_SHORTDATE;
125 else
127 m_DateFormat = DATE_LONGDATE;
129 // get relative time display setting from registry
130 DWORD regRelativeTimes = CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE);
131 m_bRelativeTimes = (regRelativeTimes != 0);
132 m_ContextMenuMask = 0xFFFFFFFFFFFFFFFF;
134 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_PICK);
135 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_SQUASH);
136 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_EDIT);
137 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_SKIP);
138 m_ContextMenuMask &= ~GetContextMenuBit(ID_LOG);
139 m_ContextMenuMask &= ~GetContextMenuBit(ID_BLAME);
141 OSVERSIONINFOEX inf;
142 SecureZeroMemory(&inf, sizeof(OSVERSIONINFOEX));
143 inf.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
144 GetVersionEx((OSVERSIONINFO *)&inf);
145 WORD fullver = MAKEWORD(inf.dwMinorVersion, inf.dwMajorVersion);
146 m_bVista = (fullver >= 0x0600);
148 m_ColumnRegKey=_T("log");
150 m_AsyncThreadExit = FALSE;
151 m_AsyncDiffEvent = ::CreateEvent(NULL,FALSE,TRUE,NULL);
152 m_AysnDiffListLock.Init();
154 m_DiffingThread = AfxBeginThread(AsyncThread, this, THREAD_PRIORITY_BELOW_NORMAL);
155 if (m_DiffingThread ==NULL)
157 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
158 return;
163 int CGitLogListBase::AsyncDiffThread()
165 while(1)
167 ::WaitForSingleObject(m_AsyncDiffEvent, INFINITE);
168 if(m_AsyncThreadExit)
169 break;
171 GitRev *pRev = NULL;
172 while(1)
174 if(m_AsynDiffList.size() == 0)
175 break;
177 if(m_AsyncThreadExit)
178 break;
180 m_AysnDiffListLock.Lock();
181 pRev = m_AsynDiffList.back();
182 m_AsynDiffList.pop_back();
183 m_AysnDiffListLock.Unlock();
185 if( pRev->m_CommitHash.IsEmpty() )
187 if(pRev->m_IsDiffFiles)
188 continue;
190 pRev->GetFiles(this).Clear();
191 pRev->m_ParentHash.clear();
192 pRev->m_ParentHash.push_back(m_HeadHash);
193 if(g_Git.IsInitRepos())
195 g_Git.GetInitAddList(pRev->GetFiles(this));
197 }else
199 g_Git.GetCommitDiffList(pRev->m_CommitHash.ToString(),this->m_HeadHash.ToString(), pRev->GetFiles(this));
201 pRev->GetAction(this) = 0;
203 for(int j=0;j< pRev->GetFiles(this).GetCount();j++)
204 pRev->GetAction(this) |= pRev->GetFiles(this)[j].m_Action;
206 InterlockedExchange(&pRev->m_IsDiffFiles, TRUE);
207 InterlockedExchange(&pRev->m_IsFull, TRUE);
209 pRev->GetBody().Format(_T("%d files changed"),m_logEntries.GetGitRevAt(0).GetFiles(this).GetCount());
210 ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)0,0);
211 this->GetParent()->PostMessage(WM_COMMAND, MSG_FETCHED_DIFF, 0);
214 if(!pRev->CheckAndDiff())
215 { // fetch change file list
216 for(int i=GetTopIndex(); !m_AsyncThreadExit && i <= GetTopIndex()+GetCountPerPage(); i++)
218 if(i < m_arShownList.GetCount())
220 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(i);
221 if(data->m_CommitHash == pRev->m_CommitHash)
223 ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)i,0);
224 break;
229 if(!m_AsyncThreadExit && GetSelectedCount() == 1)
231 POSITION pos = GetFirstSelectedItemPosition();
232 int nItem = GetNextSelectedItem(pos);
234 if(nItem>=0)
236 GitRev* data = (GitRev*)m_arShownList[nItem];
237 if(data)
238 if(data->m_CommitHash == pRev->m_CommitHash)
240 this->GetParent()->PostMessage(WM_COMMAND, MSG_FETCHED_DIFF, 0);
247 return 0;
249 void CGitLogListBase::hideFromContextMenu(unsigned __int64 hideMask, bool exclusivelyShow)
251 if (exclusivelyShow) {
252 m_ContextMenuMask &= hideMask;
253 } else {
254 m_ContextMenuMask &= ~hideMask;
258 CGitLogListBase::~CGitLogListBase()
260 InterlockedExchange(&m_bNoDispUpdates, TRUE);
261 this->m_arShownList.SafeRemoveAll();
263 DestroyIcon(m_hModifiedIcon);
264 DestroyIcon(m_hReplacedIcon);
265 DestroyIcon(m_hAddedIcon);
266 DestroyIcon(m_hDeletedIcon);
267 m_logEntries.ClearAll();
269 if (m_boldFont)
270 DeleteObject(m_boldFont);
272 if ( m_pStoreSelection )
274 delete m_pStoreSelection;
275 m_pStoreSelection = NULL;
278 SafeTerminateThread();
279 SafeTerminateAsyncDiffThread();
281 if(m_AsyncDiffEvent)
282 CloseHandle(m_AsyncDiffEvent);
286 BEGIN_MESSAGE_MAP(CGitLogListBase, CHintListCtrl)
287 ON_REGISTERED_MESSAGE(m_FindDialogMessage, OnFindDialogMessage)
288 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnNMCustomdrawLoglist)
289 ON_NOTIFY_REFLECT(LVN_GETDISPINFO, OnLvnGetdispinfoLoglist)
290 ON_WM_CONTEXTMENU()
291 ON_NOTIFY_REFLECT(NM_DBLCLK, OnNMDblclkLoglist)
292 ON_NOTIFY_REFLECT(LVN_ODFINDITEM,OnLvnOdfinditemLoglist)
293 ON_WM_CREATE()
294 ON_WM_DESTROY()
295 ON_MESSAGE(MSG_LOADED,OnLoad)
296 ON_WM_MEASUREITEM()
297 ON_WM_MEASUREITEM_REFLECT()
298 ON_NOTIFY(HDN_BEGINTRACKA, 0, OnHdnBegintrack)
299 ON_NOTIFY(HDN_BEGINTRACKW, 0, OnHdnBegintrack)
300 ON_NOTIFY(HDN_ITEMCHANGINGA, 0, OnHdnItemchanging)
301 ON_NOTIFY(HDN_ITEMCHANGINGW, 0, OnHdnItemchanging)
302 ON_NOTIFY(HDN_ENDTRACK, 0, OnColumnResized)
303 ON_NOTIFY(HDN_ENDDRAG, 0, OnColumnMoved)
304 END_MESSAGE_MAP()
306 void CGitLogListBase::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
308 //if (m_nRowHeight>0)
310 lpMeasureItemStruct->itemHeight = 50;
314 int CGitLogListBase:: OnCreate(LPCREATESTRUCT lpCreateStruct)
316 PreSubclassWindow();
317 return CHintListCtrl::OnCreate(lpCreateStruct);
320 void CGitLogListBase::PreSubclassWindow()
322 SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_SUBITEMIMAGES);
323 // load the icons for the action columns
324 // m_Theme.Open(m_hWnd, L"ListView");
325 m_Theme.Open(m_hWnd, L"Explorer::ListView;ListView");
326 m_Theme.SetWindowTheme(m_hWnd, L"Explorer", NULL);
327 CHintListCtrl::PreSubclassWindow();
330 void CGitLogListBase::InsertGitColumn()
332 CString temp;
334 CRegDWORD regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE);
335 DWORD exStyle = LVS_EX_HEADERDRAGDROP | LVS_EX_DOUBLEBUFFER | LVS_EX_INFOTIP | LVS_EX_SUBITEMIMAGES;
336 if (DWORD(regFullRowSelect))
337 exStyle |= LVS_EX_FULLROWSELECT;
338 SetExtendedStyle(exStyle);
340 UpdateProjectProperties();
342 static UINT normal[] =
344 IDS_LOG_GRAPH,
345 IDS_LOG_REBASE,
346 IDS_LOG_ID,
347 IDS_LOG_HASH,
348 IDS_LOG_ACTIONS,
349 IDS_LOG_MESSAGE,
350 IDS_LOG_AUTHOR,
351 IDS_LOG_DATE,
352 IDS_LOG_EMAIL,
353 IDS_LOG_COMMIT_NAME,
354 IDS_LOG_COMMIT_EMAIL,
355 IDS_LOG_COMMIT_DATE,
356 IDS_LOG_BUGIDS,
359 static int with[] =
361 ICONITEMBORDER+16*4,
362 ICONITEMBORDER+16*4,
363 ICONITEMBORDER+16*4,
364 ICONITEMBORDER+16*4,
365 ICONITEMBORDER+16*4,
366 LOGLIST_MESSAGE_MIN,
367 ICONITEMBORDER+16*4,
368 ICONITEMBORDER+16*4,
369 ICONITEMBORDER+16*4,
370 ICONITEMBORDER+16*4,
371 ICONITEMBORDER+16*4,
372 ICONITEMBORDER+16*4,
373 ICONITEMBORDER+16*4,
375 m_dwDefaultColumns = GIT_LOG_GRAPH|GIT_LOG_ACTIONS|GIT_LOG_MESSAGE|GIT_LOG_AUTHOR|GIT_LOG_DATE;
377 DWORD hideColumns = 0;
378 if(this->m_IsRebaseReplaceGraph)
380 hideColumns |= GIT_LOG_GRAPH;
381 m_dwDefaultColumns |= GIT_LOG_REBASE;
382 } else {
383 hideColumns |= GIT_LOG_REBASE;
386 if(this->m_IsIDReplaceAction)
388 hideColumns |= GIT_LOG_ACTIONS;
389 m_dwDefaultColumns |= GIT_LOG_ID;
390 m_dwDefaultColumns |= GIT_LOG_HASH;
391 } else {
392 hideColumns |= GIT_LOG_ID;
394 if(this->m_bShowBugtraqColumn)
396 m_dwDefaultColumns |= GIT_LOGLIST_BUG;
397 } else {
398 hideColumns |= GIT_LOGLIST_BUG;
400 SetRedraw(false);
402 m_ColumnManager.SetNames(normal, sizeof(normal)/sizeof(UINT));
403 m_ColumnManager.ReadSettings(m_dwDefaultColumns, hideColumns, m_ColumnRegKey+_T("loglist"), sizeof(normal)/sizeof(UINT), with);
405 SetRedraw(true);
410 * Resizes all columns in a list control to values in registry.
412 void CGitLogListBase::ResizeAllListCtrlCols()
414 // column max and min widths to allow
415 static const int nMinimumWidth = 10;
416 static const int nMaximumWidth = 1000;
417 CHeaderCtrl* pHdrCtrl = (CHeaderCtrl*)(GetDlgItem(0));
418 if (pHdrCtrl)
420 int numcols = pHdrCtrl->GetItemCount();
421 for (int col = 0; col < numcols; col++)
423 // get width for this col last time from registry
424 CString regentry;
425 regentry.Format( _T("Software\\TortoiseGit\\%s\\ColWidth%d"),m_ColumnRegKey, col);
426 CRegDWORD regwidth(regentry, 0);
427 int cx = regwidth;
428 if ( cx == 0 )
430 // no saved value, setup sensible defaults
431 if (col == this->LOGLIST_MESSAGE)
433 cx = LOGLIST_MESSAGE_MIN;
435 else
437 cx = ICONITEMBORDER+16*4;
440 if (cx < nMinimumWidth)
442 cx = nMinimumWidth;
443 } else if (cx > nMaximumWidth)
445 cx = nMaximumWidth;
448 SetColumnWidth(col, cx);
455 BOOL CGitLogListBase::GetShortName(CString ref, CString &shortname,CString prefix)
457 //TRACE(_T("%s %s\r\n"),ref,prefix);
458 if(ref.Left(prefix.GetLength()) == prefix)
460 shortname = ref.Right(ref.GetLength()-prefix.GetLength());
461 if(shortname.Right(3)==_T("^{}"))
462 shortname=shortname.Left(shortname.GetLength()-3);
463 return TRUE;
465 return FALSE;
468 void CGitLogListBase::FillBackGround(HDC hdc, int Index,CRect &rect)
470 // HBRUSH brush;
471 LVITEM rItem;
472 SecureZeroMemory(&rItem, sizeof(LVITEM));
473 rItem.mask = LVIF_STATE;
474 rItem.iItem = Index;
475 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
476 GetItem(&rItem);
478 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(Index);
479 HBRUSH brush = NULL;
481 if (m_Theme.IsAppThemed() && m_bVista)
483 int state = LISS_NORMAL;
484 if (rItem.state & LVIS_SELECTED)
486 if (::GetFocus() == m_hWnd)
487 state |= LISS_SELECTED;
488 else
489 state |= LISS_SELECTEDNOTFOCUS;
491 else
493 if(pLogEntry->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_SQUASH)
494 brush = ::CreateSolidBrush(RGB(156,156,156));
495 else if(pLogEntry->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_EDIT)
496 brush = ::CreateSolidBrush(RGB(200,200,128));
499 if (brush != NULL)
501 ::FillRect(hdc, &rect, brush);
502 ::DeleteObject(brush);
504 else
506 if (m_Theme.IsBackgroundPartiallyTransparent(LVP_LISTITEM, state))
507 m_Theme.DrawParentBackground(m_hWnd, hdc, &rect);
509 CRect rectDraw = rect;
510 if(rItem.state & LVIS_SELECTED)
511 rectDraw.InflateRect(1,0);
512 else
513 rectDraw.InflateRect(1,1);
515 m_Theme.DrawBackground(hdc, LVP_LISTITEM, state, rectDraw, &rect);
518 else
520 if (rItem.state & LVIS_SELECTED)
522 if (::GetFocus() == m_hWnd)
523 brush = ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT));
524 else
525 brush = ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE));
527 else
529 //if (pLogEntry->bCopiedSelf)
530 // brush = ::CreateSolidBrush(::GetSysColor(COLOR_MENU));
531 //else
532 if(pLogEntry->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_SQUASH)
533 brush = ::CreateSolidBrush(RGB(156,156,156));
534 else if(pLogEntry->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_EDIT)
535 brush = ::CreateSolidBrush(RGB(200,200,128));
536 else
537 brush = ::CreateSolidBrush(::GetSysColor(COLOR_WINDOW));
539 if (brush == NULL)
540 return;
542 ::FillRect(hdc, &rect, brush);
543 ::DeleteObject(brush);
547 void CGitLogListBase::DrawTagBranch(HDC hdc,CRect &rect,INT_PTR index)
549 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(index);
550 CRect rt=rect;
551 LVITEM rItem;
552 SecureZeroMemory(&rItem, sizeof(LVITEM));
553 rItem.mask = LVIF_STATE;
554 rItem.iItem = index;
555 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
556 GetItem(&rItem);
558 CDC W_Dc;
559 W_Dc.Attach(hdc);
561 for(unsigned int i=0;i<m_HashMap[data->m_CommitHash].size();i++)
563 CString str;
564 str=m_HashMap[data->m_CommitHash][i];
566 CString shortname;
567 HBRUSH brush = 0;
568 shortname = _T("");
569 COLORREF colRef = 0;
571 //Determine label color
572 if(GetShortName(str,shortname,_T("refs/heads/")))
574 if( shortname == m_CurrentBranch )
575 colRef = m_Colors.GetColor(CColors::CurrentBranch);
576 else
577 colRef = m_Colors.GetColor(CColors::LocalBranch);
579 }else if(GetShortName(str,shortname,_T("refs/remotes/")))
581 colRef = m_Colors.GetColor(CColors::RemoteBranch);
583 else if(GetShortName(str,shortname,_T("refs/tags/")))
585 colRef = m_Colors.GetColor(CColors::Tag);
587 else if(GetShortName(str,shortname,_T("refs/stash")))
589 colRef = m_Colors.GetColor(CColors::Stash);
590 shortname=_T("stash");
591 }else if(GetShortName(str,shortname,_T("refs/bisect/")))
593 if(shortname.Find(_T("good")) == 0)
595 colRef = m_Colors.GetColor(CColors::BisectGood);
596 shortname = _T("good");
599 if(shortname.Find(_T("bad")) == 0)
601 colRef = m_Colors.GetColor(CColors::BisectBad);
602 shortname = _T("bad");
606 //When row selected, ajust label color
607 if (!(m_Theme.IsAppThemed() && m_bVista))
608 if (rItem.state & LVIS_SELECTED)
609 colRef = CColors::MixColors(colRef, ::GetSysColor(COLOR_HIGHLIGHT), 150);
611 brush = ::CreateSolidBrush(colRef);
613 if(!shortname.IsEmpty() && (rt.left<rect.right) )
615 SIZE size;
616 memset(&size,0,sizeof(SIZE));
617 GetTextExtentPoint32(hdc, shortname,shortname.GetLength(),&size);
619 rt.SetRect(rt.left,rt.top,rt.left+size.cx,rt.bottom);
620 rt.right+=8;
622 int textpos = DT_CENTER;
624 if(rt.right > rect.right)
626 rt.right = rect.right;
627 textpos =0;
630 //Fill interior of ref label
631 ::FillRect(hdc, &rt, brush);
633 //Draw edge of label
635 CRect rectEdge = rt;
637 W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef,100), m_Colors.Darken(colRef,100));
638 rectEdge.DeflateRect(1,1);
639 W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef,50), m_Colors.Darken(colRef,50));
641 //Draw text inside label
642 if (m_Theme.IsAppThemed() && m_bVista)
644 int txtState = LISS_NORMAL;
645 if (rItem.state & LVIS_SELECTED)
646 txtState = LISS_SELECTED;
648 m_Theme.DrawText(hdc, LVP_LISTITEM, txtState, shortname, -1, textpos | DT_SINGLELINE | DT_VCENTER, 0, &rt);
650 else
652 W_Dc.SetBkMode(TRANSPARENT);
653 if (rItem.state & LVIS_SELECTED)
655 COLORREF clrNew = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
656 COLORREF clrOld = ::SetTextColor(hdc,clrNew);
657 ::DrawText(hdc,shortname,shortname.GetLength(),&rt,textpos | DT_SINGLELINE | DT_VCENTER);
658 ::SetTextColor(hdc,clrOld);
659 }else
661 ::DrawText(hdc,shortname,shortname.GetLength(),&rt,textpos | DT_SINGLELINE | DT_VCENTER);
665 //::MoveToEx(hdc,rt.left,rt.top,NULL);
666 //::LineTo(hdc,rt.right,rt.top);
667 //::LineTo(hdc,rt.right,rt.bottom);
668 //::LineTo(hdc,rt.left,rt.bottom);
669 //::LineTo(hdc,rt.left,rt.top);
671 rt.left=rt.right+1;
673 if(brush)
674 ::DeleteObject(brush);
676 rt.right=rect.right;
678 if (m_Theme.IsAppThemed() && m_bVista)
680 int txtState = LISS_NORMAL;
681 if (rItem.state & LVIS_SELECTED)
682 txtState = LISS_SELECTED;
684 m_Theme.DrawText(hdc, LVP_LISTITEM, txtState, data->GetSubject(), -1, DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER, 0, &rt);
686 else
688 if (rItem.state & LVIS_SELECTED)
690 COLORREF clrOld = ::SetTextColor(hdc,::GetSysColor(COLOR_HIGHLIGHTTEXT));
691 ::DrawText(hdc,data->GetSubject(),data->GetSubject().GetLength(),&rt,DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER);
692 ::SetTextColor(hdc,clrOld);
693 }else
695 ::DrawText(hdc,data->GetSubject(),data->GetSubject().GetLength(),&rt,DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER);
699 W_Dc.Detach();
702 static COLORREF blend(const COLORREF& col1, const COLORREF& col2, int amount = 128) {
704 // Returns ((256 - amount)*col1 + amount*col2) / 256;
705 return RGB(((256 - amount)*GetRValue(col1) + amount*GetRValue(col2) ) / 256,
706 ((256 - amount)*GetGValue(col1) + amount*GetGValue(col2) ) / 256,
707 ((256 - amount)*GetBValue(col1) + amount*GetBValue(col2) ) / 256);
710 Gdiplus::Color GetGdiColor(COLORREF col)
712 return Gdiplus::Color(GetRValue(col),GetGValue(col),GetBValue(col));
714 void CGitLogListBase::paintGraphLane(HDC hdc, int laneHeight,int type, int x1, int x2,
715 const COLORREF& col,const COLORREF& activeColor, int top
718 int h = laneHeight / 2;
719 int m = (x1 + x2) / 2;
720 int r = (x2 - x1) / 3;
721 int d = 2 * r;
723 #define P_CENTER m , h+top
724 #define P_0 x2, h+top
725 #define P_90 m , 0+top-1
726 #define P_180 x1, h+top
727 #define P_270 m , 2 * h+top +1
728 #define R_CENTER m - r, h - r+top, d, d
731 #define DELTA_UR_B 2*(x1 - m), 2*h +top
732 #define DELTA_UR_E 0*16, 90*16 +top // -,
734 #define DELTA_DR_B 2*(x1 - m), 2*-h +top
735 #define DELTA_DR_E 270*16, 90*16 +top // -'
737 #define DELTA_UL_B 2*(x2 - m), 2*h +top
738 #define DELTA_UL_E 90*16, 90*16 +top // ,-
740 #define DELTA_DL_B 2*(x2 - m),2*-h +top
741 #define DELTA_DL_E 180*16, 90*16 // '-
743 #define CENTER_UR x1, 2*h, 225
744 #define CENTER_DR x1, 0 , 135
745 #define CENTER_UL x2, 2*h, 315
746 #define CENTER_DL x2, 0 , 45
749 Gdiplus::Graphics graphics( hdc );
751 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
753 // arc
754 switch (type) {
755 case Lanes::JOIN:
756 case Lanes::JOIN_R:
757 case Lanes::HEAD:
758 case Lanes::HEAD_R:
760 Gdiplus::LinearGradientBrush gradient(
761 Gdiplus::Point(x1-2, h+top-2),
762 Gdiplus::Point(P_270),
763 GetGdiColor(activeColor),GetGdiColor(col));
766 Gdiplus::Pen mypen(&gradient,2);
767 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
769 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
770 graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top+h-1, x2-x1,laneHeight,270,90);
771 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
773 break;
775 case Lanes::JOIN_L:
778 Gdiplus::LinearGradientBrush gradient(
779 Gdiplus::Point(P_270),
780 Gdiplus::Point(x2+1, h+top-1),
781 GetGdiColor(col),GetGdiColor(activeColor));
784 Gdiplus::Pen mypen(&gradient,2);
785 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
787 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
788 graphics.DrawArc(&mypen,x1+(x2-x1)/2,top+h-1, x2-x1,laneHeight,180,90);
789 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
792 break;
794 case Lanes::TAIL:
795 case Lanes::TAIL_R:
798 Gdiplus::LinearGradientBrush gradient(
799 Gdiplus::Point(x1-2, h+top-2),
800 Gdiplus::Point(P_90),
801 GetGdiColor(activeColor),GetGdiColor(col));
803 Gdiplus::Pen mypen(&gradient,2);
805 graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top-h-1, x2-x1,laneHeight,0,90);
807 #if 0
808 QConicalGradient gradient(CENTER_DR);
809 gradient.setColorAt(0.375, activeCol);
810 gradient.setColorAt(0.625, col);
811 myPen.setBrush(gradient);
812 p->setPen(myPen);
813 p->drawArc(P_CENTER, DELTA_DR);
814 #endif
815 break;
817 default:
818 break;
822 //static QPen myPen(Qt::black, 2); // fast path here
823 CPen pen;
824 pen.CreatePen(PS_SOLID,2,col);
825 //myPen.setColor(col);
826 HPEN oldpen=(HPEN)::SelectObject(hdc,(HPEN)pen);
828 Gdiplus::Pen myPen(GetGdiColor(col),2);
830 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
832 //p->setPen(myPen);
834 // vertical line
835 switch (type) {
836 case Lanes::ACTIVE:
837 case Lanes::NOT_ACTIVE:
838 case Lanes::MERGE_FORK:
839 case Lanes::MERGE_FORK_R:
840 case Lanes::MERGE_FORK_L:
841 case Lanes::JOIN:
842 case Lanes::JOIN_R:
843 case Lanes::JOIN_L:
844 case Lanes::CROSS:
845 //DrawLine(hdc,P_90,P_270);
846 graphics.DrawLine(&myPen,P_90,P_270);
847 //p->drawLine(P_90, P_270);
848 break;
849 case Lanes::HEAD_L:
850 case Lanes::BRANCH:
851 //DrawLine(hdc,P_CENTER,P_270);
852 graphics.DrawLine(&myPen,P_CENTER,P_270);
853 //p->drawLine(P_CENTER, P_270);
854 break;
855 case Lanes::TAIL_L:
856 case Lanes::INITIAL:
857 case Lanes::BOUNDARY:
858 case Lanes::BOUNDARY_C:
859 case Lanes::BOUNDARY_R:
860 case Lanes::BOUNDARY_L:
861 //DrawLine(hdc,P_90, P_CENTER);
862 graphics.DrawLine(&myPen,P_90,P_CENTER);
863 //p->drawLine(P_90, P_CENTER);
864 break;
865 default:
866 break;
869 myPen.SetColor(GetGdiColor(activeColor));
871 // horizontal line
872 switch (type) {
873 case Lanes::MERGE_FORK:
874 case Lanes::JOIN:
875 case Lanes::HEAD:
876 case Lanes::TAIL:
877 case Lanes::CROSS:
878 case Lanes::CROSS_EMPTY:
879 case Lanes::BOUNDARY_C:
880 //DrawLine(hdc,P_180,P_0);
881 graphics.DrawLine(&myPen,P_180,P_0);
882 //p->drawLine(P_180, P_0);
883 break;
884 case Lanes::MERGE_FORK_R:
885 case Lanes::BOUNDARY_R:
886 //DrawLine(hdc,P_180,P_CENTER);
887 graphics.DrawLine(&myPen,P_180,P_CENTER);
888 //p->drawLine(P_180, P_CENTER);
889 break;
890 case Lanes::MERGE_FORK_L:
891 case Lanes::HEAD_L:
892 case Lanes::TAIL_L:
893 case Lanes::BOUNDARY_L:
894 //DrawLine(hdc,P_CENTER,P_0);
895 graphics.DrawLine(&myPen,P_CENTER,P_0);
896 //p->drawLine(P_CENTER, P_0);
897 break;
898 default:
899 break;
902 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
904 CBrush brush;
905 brush.CreateSolidBrush(col);
906 HBRUSH oldbrush=(HBRUSH)::SelectObject(hdc,(HBRUSH)brush);
908 Gdiplus::SolidBrush myBrush(GetGdiColor(col));
909 // center symbol, e.g. rect or ellipse
910 switch (type) {
911 case Lanes::ACTIVE:
912 case Lanes::INITIAL:
913 case Lanes::BRANCH:
915 //p->setPen(Qt::NoPen);
916 //p->setBrush(col);
917 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
918 graphics.FillEllipse(&myBrush, R_CENTER);
919 //p->drawEllipse(R_CENTER);
920 break;
921 case Lanes::MERGE_FORK:
922 case Lanes::MERGE_FORK_R:
923 case Lanes::MERGE_FORK_L:
924 //p->setPen(Qt::NoPen);
925 //p->setBrush(col);
926 //p->drawRect(R_CENTER);
927 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
928 graphics.FillRectangle(&myBrush, R_CENTER);
929 break;
930 case Lanes::UNAPPLIED:
931 // Red minus sign
932 //p->setPen(Qt::NoPen);
933 //p->setBrush(Qt::red);
934 //p->drawRect(m - r, h - 1, d, 2);
935 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
936 graphics.FillRectangle(&myBrush,m-r,h-1,d,2);
937 break;
938 case Lanes::APPLIED:
939 // Green plus sign
940 //p->setPen(Qt::NoPen);
941 //p->setBrush(DARK_GREEN);
942 //p->drawRect(m - r, h - 1, d, 2);
943 //p->drawRect(m - 1, h - r, 2, d);
944 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
945 graphics.FillRectangle(&myBrush,m-r,h-1,d,2);
946 graphics.FillRectangle(&myBrush,m-1,h-r,2,d);
947 break;
948 case Lanes::BOUNDARY:
949 //p->setBrush(back);
950 //p->drawEllipse(R_CENTER);
951 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
952 graphics.DrawEllipse(&myPen, R_CENTER);
953 break;
954 case Lanes::BOUNDARY_C:
955 case Lanes::BOUNDARY_R:
956 case Lanes::BOUNDARY_L:
957 //p->setBrush(back);
958 //p->drawRect(R_CENTER);
959 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
960 graphics.FillRectangle(&myBrush,R_CENTER);
961 break;
962 default:
963 break;
966 ::SelectObject(hdc,oldpen);
967 ::SelectObject(hdc,oldbrush);
968 #undef P_CENTER
969 #undef P_0
970 #undef P_90
971 #undef P_180
972 #undef P_270
973 #undef R_CENTER
976 void CGitLogListBase::DrawGraph(HDC hdc,CRect &rect,INT_PTR index)
978 // TODO: unfinished
979 // return;
980 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(index);
981 if(data->m_CommitHash.IsEmpty())
982 return;
984 CRect rt=rect;
985 LVITEM rItem;
986 SecureZeroMemory(&rItem, sizeof(LVITEM));
987 rItem.mask = LVIF_STATE;
988 rItem.iItem = index;
989 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
990 GetItem(&rItem);
992 // p->translate(QPoint(opt.rect.left(), opt.rect.top()));
994 if (data->m_Lanes.size() == 0)
995 m_logEntries.setLane(data->m_CommitHash);
997 std::vector<int>& lanes=data->m_Lanes;
998 UINT laneNum = lanes.size();
999 UINT activeLane = 0;
1000 for (UINT i = 0; i < laneNum; i++)
1001 if (Lanes::isMerge(lanes[i])) {
1002 activeLane = i;
1003 break;
1006 int x1 = 0, x2 = 0;
1007 int maxWidth = rect.Width();
1008 int lw = 3 * rect.Height() / 4; //laneWidth()
1010 COLORREF activeColor = m_LineColors[activeLane % Lanes::COLORS_NUM];
1011 //if (opt.state & QStyle::State_Selected)
1012 // activeColor = blend(activeColor, opt.palette.highlightedText().color(), 208);
1014 for (unsigned int i = 0; i < laneNum && x2 < maxWidth; i++)
1017 x1 = x2;
1018 x2 += lw;
1020 int ln = lanes[i];
1021 if (ln == Lanes::EMPTY)
1022 continue;
1024 COLORREF color = i == activeLane ? activeColor : m_LineColors[i % Lanes::COLORS_NUM];
1025 paintGraphLane(hdc, rect.Height(),ln, x1+rect.left, x2+rect.left, color,activeColor, rect.top);
1028 #if 0
1029 for (UINT i = 0; i < laneNum && x2 < maxWidth; i++) {
1031 x1 = x2;
1032 x2 += lw;
1034 int ln = lanes[i];
1035 if (ln == Lanes::EMPTY)
1036 continue;
1038 UINT col = ( Lanes:: isHead(ln) ||Lanes:: isTail(ln) || Lanes::isJoin(ln)
1039 || ln ==Lanes:: CROSS_EMPTY) ? activeLane : i;
1041 if (ln == Lanes::CROSS) {
1042 paintGraphLane(hdc, rect.Height(),Lanes::NOT_ACTIVE, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
1043 paintGraphLane(hdc, rect.Height(),Lanes::CROSS, x1, x2, m_LineColors[activeLane % Lanes::COLORS_NUM],rect.top);
1044 } else
1045 paintGraphLane(hdc, rect.Height(),ln, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
1047 #endif
1051 void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1054 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
1055 // Take the default processing unless we set this to something else below.
1056 *pResult = CDRF_DODEFAULT;
1058 if (m_bNoDispUpdates)
1059 return;
1063 switch (pLVCD->nmcd.dwDrawStage)
1065 case CDDS_PREPAINT:
1067 *pResult = CDRF_NOTIFYITEMDRAW;
1068 return;
1070 break;
1071 case CDDS_ITEMPREPAINT:
1073 // This is the prepaint stage for an item. Here's where we set the
1074 // item's text color.
1076 // Tell Windows to send draw notifications for each subitem.
1077 *pResult = CDRF_NOTIFYSUBITEMDRAW;
1079 COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);
1081 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
1083 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1084 if (data)
1086 #if 0
1087 if (data->bCopiedSelf)
1089 // only change the background color if the item is not 'hot' (on vista with m_Themes enabled)
1090 if (!m_Theme.IsAppm_Themed() || !m_bVista || ((pLVCD->nmcd.uItemState & CDIS_HOT)==0))
1091 pLVCD->clrTextBk = GetSysColor(COLOR_MENU);
1094 if (data->bCopies)
1095 crText = m_Colors.GetColor(CColors::Modified);
1096 #endif
1097 if (data->GetAction(this)& (CTGitPath::LOGACTIONS_REBASE_DONE| CTGitPath::LOGACTIONS_REBASE_SKIP) )
1098 crText = RGB(128,128,128);
1100 if(data->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_SQUASH)
1101 pLVCD->clrTextBk = RGB(156,156,156);
1102 else if(data->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_EDIT)
1103 pLVCD->clrTextBk = RGB(200,200,128);
1104 else
1105 pLVCD->clrTextBk = ::GetSysColor(COLOR_WINDOW);
1107 if(data->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_CURRENT)
1109 SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1110 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1113 if(data->m_CommitHash.ToString() == m_HeadHash)
1115 SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1116 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1119 // if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))
1120 // crText = GetSysColor(COLOR_GRAYTEXT);
1122 if (data->m_CommitHash.IsEmpty())
1124 //crText = GetSysColor(RGB(200,200,0));
1125 //SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1126 // We changed the font, so we're returning CDRF_NEWFONT. This
1127 // tells the control to recalculate the extent of the text.
1128 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1132 if (m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec)
1134 if (m_bStrictStopped)
1135 crText = GetSysColor(COLOR_GRAYTEXT);
1137 // Store the color back in the NMLVCUSTOMDRAW struct.
1138 pLVCD->clrText = crText;
1139 return;
1141 break;
1142 case CDDS_ITEMPREPAINT|CDDS_ITEM|CDDS_SUBITEM:
1144 if ((m_bStrictStopped)&&(m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec))
1146 pLVCD->nmcd.uItemState &= ~(CDIS_SELECTED|CDIS_FOCUS);
1149 if (pLVCD->iSubItem == LOGLIST_GRAPH)
1151 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec && (!this->m_IsRebaseReplaceGraph) )
1153 CRect rect;
1154 GetSubItemRect(pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_LABEL, rect);
1156 //TRACE(_T("A Graphic left %d right %d\r\n"),rect.left,rect.right);
1157 FillBackGround(pLVCD->nmcd.hdc, (INT_PTR)pLVCD->nmcd.dwItemSpec,rect);
1159 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1160 if( !data ->m_CommitHash.IsEmpty())
1161 DrawGraph(pLVCD->nmcd.hdc,rect,pLVCD->nmcd.dwItemSpec);
1163 *pResult = CDRF_SKIPDEFAULT;
1164 return;
1168 if (pLVCD->iSubItem == LOGLIST_MESSAGE)
1170 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
1172 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1173 //if(!data->m_IsFull)
1175 //if(data->SafeFetchFullInfo(&g_Git))
1176 // this->Invalidate();
1177 //TRACE(_T("Update ... %d\r\n"),pLVCD->nmcd.dwItemSpec);
1180 if(m_HashMap[data->m_CommitHash].size()!=0)
1182 CRect rect;
1184 GetSubItemRect(pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
1186 FillBackGround(pLVCD->nmcd.hdc, (INT_PTR)pLVCD->nmcd.dwItemSpec,rect);
1187 DrawTagBranch(pLVCD->nmcd.hdc,rect,pLVCD->nmcd.dwItemSpec);
1189 *pResult = CDRF_SKIPDEFAULT;
1190 return;
1197 if (pLVCD->iSubItem == LOGLIST_ACTION)
1199 if(this->m_IsIDReplaceAction)
1201 *pResult = CDRF_DODEFAULT;
1202 return;
1204 *pResult = CDRF_DODEFAULT;
1206 if (m_arShownList.GetCount() <= (INT_PTR)pLVCD->nmcd.dwItemSpec)
1207 return;
1209 int nIcons = 0;
1210 int iconwidth = ::GetSystemMetrics(SM_CXSMICON);
1211 int iconheight = ::GetSystemMetrics(SM_CYSMICON);
1213 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec));
1214 CRect rect;
1215 GetSubItemRect(pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
1216 //TRACE(_T("Action left %d right %d\r\n"),rect.left,rect.right);
1217 // Get the selected state of the
1218 // item being drawn.
1220 // Fill the background
1221 FillBackGround(pLVCD->nmcd.hdc, (INT_PTR)pLVCD->nmcd.dwItemSpec,rect);
1223 // Draw the icon(s) into the compatible DC
1224 pLogEntry->GetAction(this);
1226 if (!pLogEntry->m_IsDiffFiles)
1227 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hFetchIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1229 if (pLogEntry->GetAction(this) & CTGitPath::LOGACTIONS_MODIFIED)
1230 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hModifiedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1231 nIcons++;
1233 if (pLogEntry->GetAction(this) & (CTGitPath::LOGACTIONS_ADDED|CTGitPath::LOGACTIONS_COPY) )
1234 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hAddedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1235 nIcons++;
1237 if (pLogEntry->GetAction(this) & CTGitPath::LOGACTIONS_DELETED)
1238 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hDeletedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1239 nIcons++;
1241 if (pLogEntry->GetAction(this) & CTGitPath::LOGACTIONS_REPLACED)
1242 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hReplacedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1243 nIcons++;
1244 *pResult = CDRF_SKIPDEFAULT;
1245 return;
1248 break;
1250 *pResult = CDRF_DODEFAULT;
1253 // CGitLogListBase message handlers
1255 void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1257 NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
1259 // Create a pointer to the item
1260 LV_ITEM* pItem = &(pDispInfo)->item;
1262 // Do the list need text information?
1263 if (!(pItem->mask & LVIF_TEXT))
1264 return;
1266 // By default, clear text buffer.
1267 lstrcpyn(pItem->pszText, _T(""), pItem->cchTextMax);
1269 bool bOutOfRange = pItem->iItem >= ShownCountWithStopped();
1271 *pResult = 0;
1272 if (m_bNoDispUpdates || bOutOfRange)
1273 return;
1275 // Which item number?
1276 int itemid = pItem->iItem;
1277 GitRev * pLogEntry = NULL;
1278 if (itemid < m_arShownList.GetCount())
1279 pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(pItem->iItem));
1281 CString temp;
1282 if(m_IsOldFirst)
1284 temp.Format(_T("%d"),pItem->iItem+1);
1286 }else
1288 temp.Format(_T("%d"),m_arShownList.GetCount()-pItem->iItem);
1291 // Which column?
1292 switch (pItem->iSubItem)
1294 case this->LOGLIST_GRAPH: //Graphic
1295 break;
1296 case this->LOGLIST_REBASE:
1298 if(this->m_IsRebaseReplaceGraph)
1300 CTGitPath path;
1301 path.m_Action=pLogEntry->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_MODE_MASK;
1302 lstrcpyn(pItem->pszText,path.GetActionName(), pItem->cchTextMax);
1305 break;
1306 case this->LOGLIST_ACTION: //action -- no text in the column
1307 break;
1308 case this->LOGLIST_HASH:
1309 if(pLogEntry)
1310 lstrcpyn(pItem->pszText, pLogEntry->m_CommitHash.ToString(), pItem->cchTextMax);
1311 break;
1312 case this->LOGLIST_ID:
1313 if(this->m_IsIDReplaceAction)
1314 lstrcpyn(pItem->pszText, temp, pItem->cchTextMax);
1315 break;
1316 case this->LOGLIST_MESSAGE: //Message
1317 if (pLogEntry)
1318 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetSubject(), pItem->cchTextMax);
1319 break;
1320 case this->LOGLIST_AUTHOR: //Author
1321 if (pLogEntry)
1322 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetAuthorName(), pItem->cchTextMax);
1323 break;
1324 case this->LOGLIST_DATE: //Date
1325 if ( pLogEntry && (!pLogEntry->m_CommitHash.IsEmpty()) )
1326 lstrcpyn(pItem->pszText,
1327 CAppUtils::FormatDateAndTime( pLogEntry->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes ),
1328 pItem->cchTextMax);
1329 break;
1331 case this->LOGLIST_EMAIL:
1332 if (pLogEntry)
1333 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetAuthorEmail(), pItem->cchTextMax);
1334 break;
1336 case this->LOGLIST_COMMIT_NAME: //Commit
1337 if (pLogEntry)
1338 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetCommitterName(), pItem->cchTextMax);
1339 break;
1341 case this->LOGLIST_COMMIT_EMAIL: //Commit Email
1342 if (pLogEntry)
1343 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetCommitterEmail(), pItem->cchTextMax);
1344 break;
1346 case this->LOGLIST_COMMIT_DATE: //Commit Date
1347 if (pLogEntry)
1348 lstrcpyn(pItem->pszText,
1349 CAppUtils::FormatDateAndTime( pLogEntry->GetCommitterDate(), m_DateFormat, true, m_bRelativeTimes ),
1350 pItem->cchTextMax);
1351 break;
1352 case this->LOGLIST_BUG: //Bug ID
1353 if(pLogEntry)
1354 lstrcpyn(pItem->pszText, (LPCTSTR)this->m_ProjectProperties.FindBugID(pLogEntry->GetSubject()), pItem->cchTextMax);
1355 break;
1357 default:
1358 ASSERT(false);
1362 void CGitLogListBase::OnContextMenu(CWnd* pWnd, CPoint point)
1365 if (pWnd == GetHeaderCtrl())
1367 return m_ColumnManager.OnContextMenuHeader(pWnd,point,!!IsGroupViewEnabled());
1370 int selIndex = GetSelectionMark();
1371 if (selIndex < 0)
1372 return; // nothing selected, nothing to do with a context menu
1374 // if the user selected the info text telling about not all revisions shown due to
1375 // the "stop on copy/rename" option, we also don't show the context menu
1376 if ((m_bStrictStopped)&&(selIndex == m_arShownList.GetCount()))
1377 return;
1379 // if the context menu is invoked through the keyboard, we have to use
1380 // a calculated position on where to anchor the menu on
1381 if ((point.x == -1) && (point.y == -1))
1383 CRect rect;
1384 GetItemRect(selIndex, &rect, LVIR_LABEL);
1385 ClientToScreen(&rect);
1386 point = rect.CenterPoint();
1388 m_nSearchIndex = selIndex;
1389 m_bCancelled = FALSE;
1391 // calculate some information the context menu commands can use
1392 // CString pathURL = GetURLFromPath(m_path);
1394 POSITION pos = GetFirstSelectedItemPosition();
1395 int indexNext = GetNextSelectedItem(pos);
1396 if (indexNext < 0)
1397 return;
1399 GitRev* pSelLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(indexNext));
1400 #if 0
1401 GitRev revSelected = pSelLogEntry->Rev;
1402 GitRev revPrevious = git_revnum_t(revSelected)-1;
1403 if ((pSelLogEntry->pArChangedPaths)&&(pSelLogEntry->pArChangedPaths->GetCount() <= 2))
1405 for (int i=0; i<pSelLogEntry->pArChangedPaths->GetCount(); ++i)
1407 LogChangedPath * changedpath = (LogChangedPath *)pSelLogEntry->pArChangedPaths->SafeGetAt(i);
1408 if (changedpath->lCopyFromRev)
1409 revPrevious = changedpath->lCopyFromRev;
1412 GitRev revSelected2;
1413 if (pos)
1415 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1416 revSelected2 = pLogEntry->Rev;
1418 bool bAllFromTheSameAuthor = true;
1419 CString firstAuthor;
1420 CLogDataVector selEntries;
1421 GitRev revLowest, revHighest;
1422 GitRevRangeArray revisionRanges;
1424 POSITION pos = GetFirstSelectedItemPosition();
1425 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1426 revisionRanges.AddRevision(pLogEntry->Rev);
1427 selEntries.push_back(pLogEntry);
1428 firstAuthor = pLogEntry->sAuthor;
1429 revLowest = pLogEntry->Rev;
1430 revHighest = pLogEntry->Rev;
1431 while (pos)
1433 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1434 revisionRanges.AddRevision(pLogEntry->Rev);
1435 selEntries.push_back(pLogEntry);
1436 if (firstAuthor.Compare(pLogEntry->sAuthor))
1437 bAllFromTheSameAuthor = false;
1438 revLowest = (git_revnum_t(pLogEntry->Rev) > git_revnum_t(revLowest) ? revLowest : pLogEntry->Rev);
1439 revHighest = (git_revnum_t(pLogEntry->Rev) < git_revnum_t(revHighest) ? revHighest : pLogEntry->Rev);
1443 #endif
1445 int FirstSelect=-1, LastSelect=-1;
1446 pos = GetFirstSelectedItemPosition();
1447 FirstSelect = GetNextSelectedItem(pos);
1448 while(pos)
1450 LastSelect = GetNextSelectedItem(pos);
1452 //entry is selected, now show the popup menu
1453 CIconMenu popup;
1454 CIconMenu subbranchmenu, submenu, gnudiffmenu,diffmenu;
1456 if (popup.CreatePopupMenu())
1459 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_PICK))
1460 popup.AppendMenuIcon(ID_REBASE_PICK, IDS_REBASE_PICK, IDI_PICK);
1462 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_SQUASH))
1463 popup.AppendMenuIcon(ID_REBASE_SQUASH, IDS_REBASE_SQUASH, IDI_SQUASH);
1465 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_EDIT))
1466 popup.AppendMenuIcon(ID_REBASE_EDIT, IDS_REBASE_EDIT, IDI_EDIT);
1468 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_SKIP))
1469 popup.AppendMenuIcon(ID_REBASE_SKIP, IDS_REBASE_SKIP, IDI_SKIP);
1471 if(m_ContextMenuMask&(GetContextMenuBit(ID_REBASE_SKIP)|GetContextMenuBit(ID_REBASE_EDIT)|
1472 GetContextMenuBit(ID_REBASE_SQUASH)|GetContextMenuBit(ID_REBASE_PICK)))
1473 popup.AppendMenu(MF_SEPARATOR, NULL);
1475 if (GetSelectedCount() == 1)
1479 if( !pSelLogEntry->m_CommitHash.IsEmpty())
1481 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARE))
1482 popup.AppendMenuIcon(ID_COMPARE, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1483 // TODO:
1484 // TortoiseMerge could be improved to take a /blame switch
1485 // and then not 'cat' the files from a unified diff but
1486 // blame then.
1487 // But until that's implemented, the context menu entry for
1488 // this feature is commented out.
1489 //popup.AppendMenu(ID_BLAMECOMPARE, IDS_LOG_POPUP_BLAMECOMPARE, IDI_BLAME);
1490 }else
1492 if(m_ContextMenuMask&GetContextMenuBit(ID_COMMIT))
1493 popup.AppendMenuIcon(ID_COMMIT, IDS_LOG_POPUP_COMMIT, IDI_COMMIT);
1495 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF1))
1497 GitRev *pRev=pSelLogEntry;
1498 if(pSelLogEntry->m_ParentHash.size()==0)
1500 pRev->GetParentFromHash(pRev->m_CommitHash);
1502 if(pRev->m_ParentHash.size()<=1)
1504 popup.AppendMenuIcon(ID_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF_CH, IDI_DIFF);
1506 }else
1508 gnudiffmenu.CreatePopupMenu();
1509 popup.AppendMenuIcon(ID_GNUDIFF1,IDS_LOG_POPUP_GNUDIFF_PARENT, IDI_DIFF, gnudiffmenu.m_hMenu);
1511 gnudiffmenu.AppendMenuIcon(ID_GNUDIFF1+(0xFFFF<<16),_T("All Parents"));
1512 gnudiffmenu.AppendMenuIcon(ID_GNUDIFF1+(0xFFFE<<16),_T("Only Merged Files"));
1514 for(int i=0;i<pRev->m_ParentHash.size();i++)
1516 CString str;
1517 str.Format(_T("%d parent"), i+1);
1518 gnudiffmenu.AppendMenuIcon(ID_GNUDIFF1+((i+1)<<16),str);
1523 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPAREWITHPREVIOUS))
1526 GitRev *pRev=pSelLogEntry;
1527 if(pSelLogEntry->m_ParentHash.size()==0)
1529 pRev->GetParentFromHash(pRev->m_CommitHash);
1531 if(pRev->m_ParentHash.size()<=1)
1533 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF);
1536 else
1538 diffmenu.CreatePopupMenu();
1539 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF, diffmenu.m_hMenu);
1540 for(int i=0;i<pRev->m_ParentHash.size();i++)
1542 CString str;
1543 str.Format(_T("%d Parent"), i+1);
1544 diffmenu.AppendMenuIcon(ID_COMPAREWITHPREVIOUS +((i+1)<<16),str);
1549 if(m_ContextMenuMask&GetContextMenuBit(ID_BLAME))
1550 popup.AppendMenuIcon(ID_BLAME, IDS_LOG_POPUP_BLAME, IDI_BLAME);
1552 //popup.AppendMenuIcon(ID_BLAMEWITHPREVIOUS, IDS_LOG_POPUP_BLAMEWITHPREVIOUS, IDI_BLAME);
1553 popup.AppendMenu(MF_SEPARATOR, NULL);
1556 // if (!m_ProjectProperties.sWebViewerRev.IsEmpty())
1557 // {
1558 // popup.AppendMenuIcon(ID_VIEWREV, IDS_LOG_POPUP_VIEWREV);
1559 // }
1560 // if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
1561 // {
1562 // popup.AppendMenuIcon(ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
1563 // }
1564 // if ((!m_ProjectProperties.sWebViewerPathRev.IsEmpty())||
1565 // (!m_ProjectProperties.sWebViewerRev.IsEmpty()))
1566 // {
1567 // popup.AppendMenu(MF_SEPARATOR, NULL);
1568 // }
1570 CString str,format;
1571 //if (m_hasWC)
1572 // popup.AppendMenuIcon(ID_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
1574 if(!pSelLogEntry->m_CommitHash.IsEmpty())
1576 if((m_ContextMenuMask&GetContextMenuBit(ID_LOG)) &&
1577 GetSelectedCount() == 1)
1578 popup.AppendMenuIcon(ID_LOG, IDS_LOG_POPUP_LOG, IDI_LOG);
1580 format.LoadString(IDS_LOG_POPUP_MERGEREV);
1581 str.Format(format,g_Git.GetCurrentBranch());
1583 if (m_ContextMenuMask&GetContextMenuBit(ID_MERGEREV))
1584 popup.AppendMenuIcon(ID_MERGEREV, str, IDI_MERGE);
1586 format.LoadString(IDS_RESET_TO_THIS_FORMAT);
1587 str.Format(format,g_Git.GetCurrentBranch());
1589 if(m_ContextMenuMask&GetContextMenuBit(ID_RESET))
1590 popup.AppendMenuIcon(ID_RESET,str,IDI_REVERT);
1593 // Add Switch Branch express Menu
1594 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end()
1595 && (m_ContextMenuMask&GetContextMenuBit(ID_SWITCHBRANCH))
1598 std::vector<CString *> branchs;
1599 CString ref;
1601 for(int i=0;i<m_HashMap[pSelLogEntry->m_CommitHash].size();i++)
1603 ref = m_HashMap[pSelLogEntry->m_CommitHash][i];
1604 if(ref.Find(_T("refs/heads/")) == 0)
1606 branchs.push_back(&m_HashMap[pSelLogEntry->m_CommitHash][i]);
1610 CString str;
1611 str.LoadString(IDS_SWITCH_BRANCH);
1613 if(branchs.size() == 1)
1615 str+=_T(" ");
1616 str+= branchs[0]->Mid(11);
1617 popup.AppendMenuIcon(ID_SWITCHBRANCH,str,IDI_SWITCH);
1619 popup.SetMenuItemData(ID_SWITCHBRANCH,(ULONG_PTR)branchs[0]);
1622 else if( branchs.size() > 1 )
1624 subbranchmenu.CreatePopupMenu();
1625 for(int i=0;i<branchs.size();i++)
1627 subbranchmenu.AppendMenuIcon(ID_SWITCHBRANCH+(i<<16), branchs[i]->Mid(11));
1628 subbranchmenu.SetMenuItemData(ID_SWITCHBRANCH+(i<<16), (ULONG_PTR) branchs[i]);
1631 popup.AppendMenuIcon(ID_SWITCHBRANCH, str, IDI_SWITCH, subbranchmenu.m_hMenu);
1635 if(m_ContextMenuMask&GetContextMenuBit(ID_SWITCHTOREV))
1636 popup.AppendMenuIcon(ID_SWITCHTOREV, IDS_SWITCH_TO_THIS , IDI_SWITCH);
1638 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_BRANCH))
1639 popup.AppendMenuIcon(ID_CREATE_BRANCH, IDS_CREATE_BRANCH_AT_THIS , IDI_COPY);
1641 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_TAG))
1642 popup.AppendMenuIcon(ID_CREATE_TAG,IDS_CREATE_TAG_AT_THIS , IDI_TAG);
1644 format.LoadString(IDS_REBASE_THIS_FORMAT);
1645 str.Format(format,g_Git.GetCurrentBranch());
1647 if(pSelLogEntry->m_CommitHash != m_HeadHash)
1648 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_TO_VERSION))
1649 popup.AppendMenuIcon(ID_REBASE_TO_VERSION, str , IDI_REBASE);
1651 if(m_ContextMenuMask&GetContextMenuBit(ID_EXPORT))
1652 popup.AppendMenuIcon(ID_EXPORT,IDS_EXPORT_TO_THIS, IDI_EXPORT);
1654 if (m_ContextMenuMask&GetContextMenuBit(ID_REVERTREV))
1655 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT);
1657 if (m_ContextMenuMask&GetContextMenuBit(ID_EDITNOTE))
1658 popup.AppendMenuIcon(ID_EDITNOTE, IDS_EDIT_NOTES, IDI_EDIT);
1660 popup.AppendMenu(MF_SEPARATOR, NULL);
1665 if(!pSelLogEntry->m_Ref.IsEmpty() && GetSelectedCount() == 1)
1667 popup.AppendMenuIcon(ID_REFLOG_DEL, IDS_REFLOG_DEL, IDI_DELETE);
1668 popup.AppendMenuIcon(ID_STASH_APPLY, IDS_MENUSTASHAPPLY, IDI_RELOCATE);
1669 popup.AppendMenu(MF_SEPARATOR, NULL);
1672 if (GetSelectedCount() >= 2)
1674 bool bAddSeparator = false;
1675 if (IsSelectionContinuous() || (GetSelectedCount() == 2))
1677 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARETWO))
1678 popup.AppendMenuIcon(ID_COMPARETWO, IDS_LOG_POPUP_COMPARETWO, IDI_DIFF);
1681 if (GetSelectedCount() == 2)
1683 //popup.AppendMenuIcon(ID_BLAMETWO, IDS_LOG_POPUP_BLAMEREVS, IDI_BLAME);
1684 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF2))
1685 popup.AppendMenuIcon(ID_GNUDIFF2, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
1686 bAddSeparator = true;
1689 if (m_hasWC)
1691 //popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREVS, IDI_REVERT);
1692 // if (m_hasWC)
1693 // popup.AppendMenuIcon(ID_MERGEREV, IDS_LOG_POPUP_MERGEREVS, IDI_MERGE);
1694 bAddSeparator = true;
1697 if (m_ContextMenuMask&GetContextMenuBit(ID_REVERTREV))
1698 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREVS, IDI_REVERT);
1700 if (bAddSeparator)
1701 popup.AppendMenu(MF_SEPARATOR, NULL);
1704 if ( GetSelectedCount() >0 && (!pSelLogEntry->m_CommitHash.IsEmpty()))
1706 bool bAddSeparator = false;
1707 if ( IsSelectionContinuous() && GetSelectedCount() >= 2 )
1709 if(m_ContextMenuMask&GetContextMenuBit(ID_COMBINE_COMMIT))
1711 CString head;
1712 int headindex;
1713 headindex = this->GetHeadIndex();
1714 if(headindex>=0)
1716 head.Format(_T("HEAD~%d"),LastSelect-headindex);
1717 CGitHash hash=g_Git.GetHash(head);
1718 GitRev* pLastEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(LastSelect));
1719 if(pLastEntry->m_CommitHash == hash) {
1720 popup.AppendMenuIcon(ID_COMBINE_COMMIT,IDS_COMBINE_TO_ONE,IDI_COMBINE);
1721 bAddSeparator = true;
1726 if(m_ContextMenuMask&GetContextMenuBit(ID_CHERRY_PICK)) {
1727 popup.AppendMenuIcon(ID_CHERRY_PICK, IDS_CHERRY_PICK_VERSION, IDI_EXPORT);
1728 bAddSeparator = true;
1731 if(GetSelectedCount()<=2 || (IsSelectionContinuous() && GetSelectedCount() > 0))
1732 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_PATCH)) {
1733 popup.AppendMenuIcon(ID_CREATE_PATCH, IDS_CREATE_PATCH, IDI_PATCH);
1734 bAddSeparator = true;
1737 if (bAddSeparator)
1738 popup.AppendMenu(MF_SEPARATOR, NULL);
1741 #if 0
1742 // if ((selEntries.size() > 0)&&(bAllFromTheSameAuthor))
1743 // {
1744 // popup.AppendMenuIcon(ID_EDITAUTHOR, IDS_LOG_POPUP_EDITAUTHOR);
1745 // }
1746 // if (GetSelectedCount() == 1)
1747 // {
1748 // popup.AppendMenuIcon(ID_EDITLOG, IDS_LOG_POPUP_EDITLOG);
1749 // popup.AppendMenuIcon(ID_REVPROPS, IDS_REPOBROWSE_SHOWREVPROP, IDI_PROPERTIES); // "Show Revision Properties"
1750 // popup.AppendMenu(MF_SEPARATOR, NULL);
1751 // }
1752 #endif
1754 if (GetSelectedCount() == 1)
1756 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYHASH))
1757 popup.AppendMenuIcon(ID_COPYHASH, IDS_COPY_COMMIT_HASH);
1759 if (GetSelectedCount() != 0)
1761 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYCLIPBOARD))
1762 popup.AppendMenuIcon(ID_COPYCLIPBOARD, IDS_LOG_POPUP_COPYTOCLIPBOARD);
1765 if(m_ContextMenuMask&GetContextMenuBit(ID_FINDENTRY))
1766 popup.AppendMenuIcon(ID_FINDENTRY, IDS_LOG_POPUP_FIND);
1768 if (GetSelectedCount() == 1)
1770 if(m_ContextMenuMask &GetContextMenuBit(ID_DELETE))
1772 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end() )
1774 CString str;
1775 str.LoadString(IDS_DELETE_BRANCHTAG);
1776 if( m_HashMap[pSelLogEntry->m_CommitHash].size() == 1 )
1778 str+=_T(" ");
1779 str+=m_HashMap[pSelLogEntry->m_CommitHash].at(0);
1780 popup.AppendMenuIcon(ID_DELETE,str+_T("..."),IDI_DELETE);
1782 else if( m_HashMap[pSelLogEntry->m_CommitHash].size() > 1 )
1785 submenu.CreatePopupMenu();
1786 for(int i=0;i<m_HashMap[pSelLogEntry->m_CommitHash].size();i++)
1788 submenu.AppendMenuIcon(ID_DELETE+(i<<16),m_HashMap[pSelLogEntry->m_CommitHash][i]+_T("..."));
1791 popup.AppendMenuIcon(ID_DELETE,str, IDI_DELETE, submenu.m_hMenu);
1795 } // m_ContextMenuMask &GetContextMenuBit(ID_DELETE)
1796 } // GetSelectedCount() == 1
1798 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
1799 // DialogEnableWindow(IDOK, FALSE);
1800 // SetPromptApp(&theApp);
1802 this->ContextMenuAction(cmd, FirstSelect, LastSelect, &popup);
1804 // EnableOKButton();
1805 } // if (popup.CreatePopupMenu())
1809 bool CGitLogListBase::IsSelectionContinuous()
1811 if ( GetSelectedCount()==1 )
1813 // if only one revision is selected, the selection is of course
1814 // continuous
1815 return true;
1818 POSITION pos = GetFirstSelectedItemPosition();
1819 bool bContinuous = (m_arShownList.GetCount() == (INT_PTR)m_logEntries.size());
1820 if (bContinuous)
1822 int itemindex = GetNextSelectedItem(pos);
1823 while (pos)
1825 int nextindex = GetNextSelectedItem(pos);
1826 if (nextindex - itemindex > 1)
1828 bContinuous = false;
1829 break;
1831 itemindex = nextindex;
1834 return bContinuous;
1837 void CGitLogListBase::CopySelectionToClipBoard(bool HashOnly)
1840 CString sClipdata;
1841 POSITION pos = GetFirstSelectedItemPosition();
1842 if (pos != NULL)
1844 CString sRev;
1845 sRev.LoadString(IDS_LOG_REVISION);
1846 CString sAuthor;
1847 sAuthor.LoadString(IDS_LOG_AUTHOR);
1848 CString sDate;
1849 sDate.LoadString(IDS_LOG_DATE);
1850 CString sMessage;
1851 sMessage.LoadString(IDS_LOG_MESSAGE);
1852 while (pos)
1854 CString sLogCopyText;
1855 CString sPaths;
1856 GitRev * pLogEntry = reinterpret_cast<GitRev *>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1858 if(!HashOnly)
1860 //pLogEntry->GetFiles(this)
1861 //LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
1863 for (int cpPathIndex = 0; cpPathIndex<pLogEntry->GetFiles(this).GetCount(); ++cpPathIndex)
1865 sPaths += ((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetActionName() + _T(" : ") + pLogEntry->GetFiles(this)[cpPathIndex].GetGitPathString();
1866 sPaths += _T("\r\n");
1868 sPaths.Trim();
1869 CString body = pLogEntry->GetBody();
1870 body.Replace(_T("\n"), _T("\r\n"));
1871 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"),
1872 (LPCTSTR)sRev, pLogEntry->m_CommitHash.ToString(),
1873 (LPCTSTR)sAuthor, (LPCTSTR)pLogEntry->GetAuthorName(),
1874 (LPCTSTR)sDate,
1875 (LPCTSTR)CAppUtils::FormatDateAndTime( pLogEntry->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes ),
1876 (LPCTSTR)sMessage, pLogEntry->GetSubject().Trim() + _T("\r\n\r\n") + body.Trim(),
1877 (LPCTSTR)sPaths);
1878 sClipdata += sLogCopyText;
1879 }else
1881 sClipdata += pLogEntry->m_CommitHash;
1882 break;
1886 CStringUtils::WriteAsciiStringToClipboard(sClipdata, GetSafeHwnd());
1891 void CGitLogListBase::DiffSelectedRevWithPrevious()
1893 if (m_bThreadRunning)
1894 return;
1896 int FirstSelect=-1, LastSelect=-1;
1897 POSITION pos = GetFirstSelectedItemPosition();
1898 FirstSelect = GetNextSelectedItem(pos);
1899 while(pos)
1901 LastSelect = GetNextSelectedItem(pos);
1904 ContextMenuAction(ID_COMPAREWITHPREVIOUS,FirstSelect,LastSelect, NULL);
1906 #if 0
1907 UpdateLogInfoLabel();
1908 int selIndex = m_LogList.GetSelectionMark();
1909 if (selIndex < 0)
1910 return;
1911 int selCount = m_LogList.GetSelectedCount();
1912 if (selCount != 1)
1913 return;
1915 // Find selected entry in the log list
1916 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
1917 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
1918 long rev1 = pLogEntry->Rev;
1919 long rev2 = rev1-1;
1920 CTGitPath path = m_path;
1922 // See how many files under the relative root were changed in selected revision
1923 int nChanged = 0;
1924 LogChangedPath * changed = NULL;
1925 for (INT_PTR c = 0; c < pLogEntry->pArChangedPaths->GetCount(); ++c)
1927 LogChangedPath * cpath = pLogEntry->pArChangedPaths->SafeGetAt(c);
1928 if (cpath && cpath -> sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
1930 ++nChanged;
1931 changed = cpath;
1935 if (m_path.IsDirectory() && nChanged == 1)
1937 // We're looking at the log for a directory and only one file under dir was changed in the revision
1938 // Do diff on that file instead of whole directory
1939 path.AppendPathString(changed->sPath.Mid(m_sRelativeRoot.GetLength()));
1942 m_bCancelled = FALSE;
1943 DialogEnableWindow(IDOK, FALSE);
1944 SetPromptApp(&theApp);
1945 theApp.DoWaitCursor(1);
1947 if (PromptShown())
1949 GitDiff diff(this, m_hWnd, true);
1950 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
1951 diff.SetHEADPeg(m_LogRevision);
1952 diff.ShowCompare(path, rev2, path, rev1);
1954 else
1956 CAppUtils::StartShowCompare(m_hWnd, path, rev2, path, rev1, GitRev(), m_LogRevision, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
1959 theApp.DoWaitCursor(-1);
1960 EnableOKButton();
1961 #endif
1964 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1966 LPNMLVFINDITEM pFindInfo = reinterpret_cast<LPNMLVFINDITEM>(pNMHDR);
1967 *pResult = -1;
1969 if (pFindInfo->lvfi.flags & LVFI_PARAM)
1970 return;
1971 if ((pFindInfo->iStart < 0)||(pFindInfo->iStart >= m_arShownList.GetCount()))
1972 return;
1973 if (pFindInfo->lvfi.psz == 0)
1974 return;
1975 #if 0
1976 CString sCmp = pFindInfo->lvfi.psz;
1977 CString sRev;
1978 for (int i=pFindInfo->iStart; i<m_arShownList.GetCount(); ++i)
1980 GitRev * pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(i));
1981 sRev.Format(_T("%ld"), pLogEntry->Rev);
1982 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
1984 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
1986 *pResult = i;
1987 return;
1990 else
1992 if (sCmp.Compare(sRev)==0)
1994 *pResult = i;
1995 return;
1999 if (pFindInfo->lvfi.flags & LVFI_WRAP)
2001 for (int i=0; i<pFindInfo->iStart; ++i)
2003 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(i));
2004 sRev.Format(_T("%ld"), pLogEntry->Rev);
2005 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
2007 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
2009 *pResult = i;
2010 return;
2013 else
2015 if (sCmp.Compare(sRev)==0)
2017 *pResult = i;
2018 return;
2023 #endif
2024 *pResult = -1;
2027 int CGitLogListBase::FillGitLog(CTGitPath *path,int info,CString *from,CString *to)
2029 ClearText();
2032 this->m_arShownList.SafeRemoveAll();
2034 this->m_logEntries.ClearAll();
2035 this->m_logEntries.ParserFromLog(path,-1,info,from,to);
2037 //this->m_logEntries.ParserFromLog();
2038 SetItemCountEx(this->m_logEntries.size());
2040 for(unsigned int i=0;i<m_logEntries.size();i++)
2042 if(m_IsOldFirst)
2044 m_logEntries.GetGitRevAt(m_logEntries.size()-i-1).m_IsFull=TRUE;
2045 this->m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size()-i-1));
2047 }else
2049 m_logEntries.GetGitRevAt(i).m_IsFull=TRUE;
2050 this->m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
2054 if(path)
2055 m_Path=*path;
2056 return 0;
2060 int CGitLogListBase::BeginFetchLog()
2062 ClearText();
2064 this->m_arShownList.SafeRemoveAll();
2066 this->m_logEntries.ClearAll();
2067 git_init();
2069 this->m_LogCache.ClearAllParent();
2071 m_LogCache.FetchCacheIndex(g_Git.m_CurrentDir);
2073 CTGitPath *path;
2074 if(this->m_Path.IsEmpty())
2075 path=NULL;
2076 else
2077 path=&this->m_Path;
2079 CString hash;
2080 int mask;
2081 mask = CGit::LOG_INFO_ONLY_HASH | CGit::LOG_INFO_BOUNDARY;
2082 // if(this->m_bAllBranch)
2083 mask |= m_ShowMask ;
2085 if(m_bShowWC)
2087 this->m_logEntries.insert(m_logEntries.begin(),this->m_wcRev.m_CommitHash);
2088 ResetWcRev();
2089 this->m_LogCache.m_HashMap[m_wcRev.m_CommitHash]=m_wcRev;
2092 CString *pFrom, *pTo;
2093 pFrom = pTo = NULL;
2094 if(!this->m_startrev.IsEmpty())
2096 pFrom = &this->m_startrev;
2097 if(!this->m_endrev.IsEmpty())
2098 pTo = &this->m_endrev;
2099 else
2100 pTo = &CString(_T("HEAD"));
2103 CFilterData data;
2104 data.m_From = m_From;
2105 data.m_To =m_To;
2107 if(this->m_nSelectedFilter == LOGFILTER_ALL || m_nSelectedFilter == LOGFILTER_AUTHORS)
2108 data.m_Author = this->m_sFilterText;
2110 if(this->m_nSelectedFilter == LOGFILTER_ALL || m_nSelectedFilter == LOGFILTER_MESSAGES)
2111 data.m_MessageFilter = this->m_sFilterText;
2113 data.m_IsRegex = m_bFilterWithRegex;
2115 CString cmd=g_Git.GetLogCmd(m_StartRef,path,-1,mask,pFrom,pTo,true,&data);
2117 //this->m_logEntries.ParserFromLog();
2118 if(IsInWorkingThread())
2120 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL);
2122 else
2124 SetItemCountEx(this->m_logEntries.size());
2127 git_init();
2129 if(g_Git.IsInitRepos())
2130 return 0;
2132 if(git_open_log(&m_DllGitLog,CUnicodeUtils::GetMulti(cmd,CP_ACP).GetBuffer()))
2134 return -1;
2137 return 0;
2140 BOOL CGitLogListBase::PreTranslateMessage(MSG* pMsg)
2142 if (pMsg->message == WM_KEYDOWN && pMsg->wParam=='\r')
2144 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))
2146 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
2148 DiffSelectedRevWithPrevious();
2149 return TRUE;
2152 #if 0
2153 if (GetFocus()==GetDlgItem(IDC_LOGMSG))
2155 DiffSelectedFile();
2156 return TRUE;
2158 #endif
2161 #if 0
2162 if (m_hAccel && !bSkipAccelerator)
2164 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
2165 if (ret)
2166 return TRUE;
2169 #endif
2170 //m_tooltips.RelayEvent(pMsg);
2171 return __super::PreTranslateMessage(pMsg);
2174 void CGitLogListBase::OnNMDblclkLoglist(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2176 // a double click on an entry in the revision list has happened
2177 *pResult = 0;
2179 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
2180 DiffSelectedRevWithPrevious();
2183 int CGitLogListBase::FetchLogAsync(void * data)
2185 m_ProcData=data;
2186 m_bExitThread=FALSE;
2187 InterlockedExchange(&m_bThreadRunning, TRUE);
2188 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2189 m_LoadingThread = AfxBeginThread(LogThreadEntry, this, THREAD_PRIORITY_LOWEST);
2190 if (m_LoadingThread ==NULL)
2192 InterlockedExchange(&m_bThreadRunning, FALSE);
2193 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2194 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
2195 return -1;
2197 return 0;
2200 //this is the thread function which calls the subversion function
2201 UINT CGitLogListBase::LogThreadEntry(LPVOID pVoid)
2203 return ((CGitLogListBase*)pVoid)->LogThread();
2206 void CGitLogListBase::GetTimeRange(CTime &oldest, CTime &latest)
2208 //CTime time;
2209 oldest=CTime::GetCurrentTime();
2210 latest=CTime(1971,1,2,0,0,0);
2211 for(unsigned int i=0;i<m_logEntries.size();i++)
2213 if(m_logEntries[i].IsEmpty())
2214 continue;
2216 if(m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime() < oldest.GetTime())
2217 oldest = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
2219 if(m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime() > latest.GetTime())
2220 latest = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
2224 if(latest<oldest)
2225 latest=oldest;
2228 UINT CGitLogListBase::LogThread()
2230 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_START,0);
2232 InterlockedExchange(&m_bThreadRunning, TRUE);
2233 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2235 ULONGLONG t1,t2;
2237 if(BeginFetchLog())
2239 InterlockedExchange(&m_bThreadRunning, FALSE);
2240 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2242 return -1;
2244 TRACE(_T("\n===Begin===\n"));
2245 //Update work copy item;
2247 if( m_logEntries.size() > 0)
2249 GitRev *pRev = &m_logEntries.GetGitRevAt(0);
2251 m_arShownList.SafeAdd(pRev);
2255 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2257 if(!g_Git.IsInitRepos())
2259 g_Git.m_critGitDllSec.Lock();
2260 git_get_log_firstcommit(m_DllGitLog);
2261 int total = git_get_log_estimate_commit_count(m_DllGitLog);
2262 g_Git.m_critGitDllSec.Unlock();
2264 GIT_COMMIT commit;
2265 t2=t1=GetTickCount();
2266 int oldprecentage = 0;
2267 int oldsize=m_logEntries.size();
2268 int ret=0;
2269 while( ret== 0)
2271 g_Git.m_critGitDllSec.Lock();
2272 ret=git_get_log_nextcommit(this->m_DllGitLog,&commit);
2273 g_Git.m_critGitDllSec.Unlock();
2275 if(ret)
2276 break;
2278 //printf("%s\r\n",commit.GetSubject());
2279 if(m_bExitThread)
2280 break;
2282 CGitHash hash = (char*)commit.m_hash ;
2284 GitRev *pRev = m_LogCache.GetCacheData(hash);
2285 pRev->m_GitCommit = commit;
2286 InterlockedExchange(&pRev->m_IsCommitParsed, FALSE);
2288 char *note=NULL;
2289 g_Git.m_critGitDllSec.Lock();
2290 git_get_notes(commit.m_hash,&note);
2291 g_Git.m_critGitDllSec.Unlock();
2293 if(note)
2295 pRev->m_Notes.Empty();
2296 g_Git.StringAppend(&pRev->m_Notes,(BYTE*)note);
2299 if(!pRev->m_IsDiffFiles)
2301 pRev->m_CallDiffAsync = DiffAsync;
2304 pRev->ParserParentFromCommit(&commit);
2306 #ifdef DEBUG
2307 pRev->DbgPrint();
2308 TRACE(_T("\n"));
2309 #endif
2311 this->m_critSec.Lock();
2312 m_logEntries.push_back(hash);
2313 m_arShownList.SafeAdd(pRev);
2314 this->m_critSec.Unlock();
2316 t2=GetTickCount();
2318 if(t2-t1>500 || (m_logEntries.size()-oldsize >100))
2320 //update UI
2321 int percent=m_logEntries.size()*100/total + GITLOG_START+1;
2322 if(percent > 99)
2323 percent =99;
2324 if(percent < GITLOG_START)
2325 percent = GITLOG_START +1;
2327 oldsize = m_logEntries.size();
2328 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
2330 //if( percent > oldprecentage )
2332 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) percent,0);
2333 oldprecentage = percent;
2335 t1 = t2;
2338 g_Git.m_critGitDllSec.Lock();
2339 git_close_log(m_DllGitLog);
2340 g_Git.m_critGitDllSec.Unlock();
2343 //Update UI;
2344 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
2345 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_END,0);
2347 InterlockedExchange(&m_bThreadRunning, FALSE);
2349 return 0;
2352 void CGitLogListBase::Refresh(BOOL IsCleanFilter)
2354 SafeTerminateThread();
2356 this->SetItemCountEx(0);
2357 this->Clear();
2359 ResetWcRev();
2361 //Update branch and Tag info
2362 ReloadHashMap();
2363 //Assume Thread have exited
2364 //if(!m_bThreadRunning)
2366 m_logEntries.clear();
2368 if(IsCleanFilter)
2370 m_sFilterText.Empty();
2371 m_From=-1;
2372 m_To=-1;
2375 InterlockedExchange(&m_bExitThread,FALSE);
2377 InterlockedExchange(&m_bThreadRunning, TRUE);
2378 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2379 if ( (m_LoadingThread=AfxBeginThread(LogThreadEntry, this)) ==NULL)
2381 InterlockedExchange(&m_bThreadRunning, FALSE);
2382 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2383 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
2387 bool CGitLogListBase::ValidateRegexp(LPCTSTR regexp_str, tr1::wregex& pat, bool bMatchCase /* = false */)
2391 tr1::regex_constants::syntax_option_type type = tr1::regex_constants::ECMAScript;
2392 if (!bMatchCase)
2393 type |= tr1::regex_constants::icase;
2394 pat = tr1::wregex(regexp_str, type);
2395 return true;
2397 catch (exception) {}
2398 return false;
2401 void CGitLogListBase::RecalculateShownList(CThreadSafePtrArray * pShownlist)
2404 pShownlist->SafeRemoveAll();
2406 tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
2407 bool bRegex = false;
2408 if (m_bFilterWithRegex)
2409 bRegex = ValidateRegexp(m_sFilterText, pat, false);
2411 tr1::regex_constants::match_flag_type flags = tr1::regex_constants::match_any;
2412 CString sRev;
2413 for (DWORD i=0; i<m_logEntries.size(); ++i)
2415 if ((bRegex)&&(m_bFilterWithRegex))
2417 #if 0
2418 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
2420 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR)m_logEntries[i]->sBugIDs);
2421 if (regex_search(wstring((LPCTSTR)m_logEntries[i]->sBugIDs), pat, flags)&&IsEntryInDateRange(i))
2423 pShownlist->SafeAdd(m_logEntries[i]);
2424 continue;
2427 #endif
2428 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_MESSAGES))
2430 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).GetSubject());
2431 if (regex_search(wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetSubject()), pat, flags)&&IsEntryInDateRange(i))
2433 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2434 continue;
2437 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).GetBody());
2438 if (regex_search(wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetBody()), pat, flags)&&IsEntryInDateRange(i))
2440 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2441 continue;
2444 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_PATHS))
2446 CTGitPathList pathList = m_logEntries.GetGitRevAt(i).GetFiles(this);
2448 bool bGoing = true;
2449 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList.GetCount() && bGoing; ++cpPathIndex)
2451 CTGitPath cpath = pathList[cpPathIndex];
2452 if (regex_search(wstring((LPCTSTR)cpath.GetGitOldPathString()), pat, flags)&&IsEntryInDateRange(i))
2454 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2455 bGoing = false;
2456 continue;
2458 if (regex_search(wstring((LPCTSTR)cpath.GetGitPathString()), pat, flags)&&IsEntryInDateRange(i))
2460 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2461 bGoing = false;
2462 continue;
2464 if (regex_search(wstring((LPCTSTR)cpath.GetActionName()), pat, flags)&&IsEntryInDateRange(i))
2466 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2467 bGoing = false;
2468 continue;
2472 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_AUTHORS))
2474 if (regex_search(wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetAuthorName()), pat, flags)&&IsEntryInDateRange(i))
2476 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2477 continue;
2480 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_REVS))
2482 sRev.Format(_T("%s"), m_logEntries.GetGitRevAt(i).m_CommitHash.ToString());
2483 if (regex_search(wstring((LPCTSTR)sRev), pat, flags)&&IsEntryInDateRange(i))
2485 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2486 continue;
2489 } // if (bRegex)
2490 else
2492 CString find = m_sFilterText;
2493 find.MakeLower();
2494 #if 0
2495 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
2497 CString sBugIDs = m_logEntries[i]->sBugIDs;
2499 sBugIDs = sBugIDs.MakeLower();
2500 if ((sBugIDs.Find(find) >= 0)&&(IsEntryInDateRange(i)))
2502 pShownlist->SafeAdd(m_logEntries[i]);
2503 continue;
2506 #endif
2507 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_MESSAGES))
2509 CString msg = m_logEntries.GetGitRevAt(i).GetSubject();
2511 msg = msg.MakeLower();
2512 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
2514 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2515 continue;
2517 msg = m_logEntries.GetGitRevAt(i).GetBody();
2519 msg = msg.MakeLower();
2520 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
2522 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2523 continue;
2526 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_PATHS))
2528 CTGitPathList pathList = m_logEntries.GetGitRevAt(i).GetFiles(this);
2530 bool bGoing = true;
2531 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList.GetCount() && bGoing; ++cpPathIndex)
2533 CTGitPath cpath = pathList[cpPathIndex];
2534 CString path = cpath.GetGitOldPathString();
2535 path.MakeLower();
2536 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
2538 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2539 bGoing = false;
2540 continue;
2542 path = cpath.GetGitPathString();
2543 path.MakeLower();
2544 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
2546 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2547 bGoing = false;
2548 continue;
2550 path = cpath.GetActionName();
2551 path.MakeLower();
2552 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
2554 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2555 bGoing = false;
2556 continue;
2560 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_AUTHORS))
2562 CString msg = m_logEntries.GetGitRevAt(i).GetAuthorName();
2563 msg = msg.MakeLower();
2564 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
2566 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2567 continue;
2570 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_REVS))
2572 sRev.Format(_T("%s"), m_logEntries.GetGitRevAt(i).m_CommitHash.ToString());
2573 if ((sRev.Find(find) >= 0)&&(IsEntryInDateRange(i)))
2575 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2576 continue;
2579 } // else (from if (bRegex))
2580 } // for (DWORD i=0; i<m_logEntries.size(); ++i)
2584 BOOL CGitLogListBase::IsEntryInDateRange(int i)
2587 __time64_t time = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
2589 if(m_From == -1)
2590 if(m_To == -1)
2591 return true;
2592 else
2593 return time <= m_To;
2594 else
2595 if(m_To == -1)
2596 return time >= m_From;
2597 else
2598 return ((time >= m_From)&&(time <= m_To));
2600 return TRUE; /* git dll will filter time range */
2602 // return TRUE;
2604 void CGitLogListBase::StartFilter()
2606 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2607 RecalculateShownList(&m_arShownList);
2608 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2611 DeleteAllItems();
2612 SetItemCountEx(ShownCountWithStopped());
2613 RedrawItems(0, ShownCountWithStopped());
2614 Invalidate();
2617 void CGitLogListBase::RemoveFilter()
2620 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2622 m_arShownList.SafeRemoveAll();
2624 // reset the time filter too
2625 #if 0
2626 m_timFrom = (__time64_t(m_tFrom));
2627 m_timTo = (__time64_t(m_tTo));
2628 m_DateFrom.SetTime(&m_timFrom);
2629 m_DateTo.SetTime(&m_timTo);
2630 m_DateFrom.SetRange(&m_timFrom, &m_timTo);
2631 m_DateTo.SetRange(&m_timFrom, &m_timTo);
2632 #endif
2634 for (DWORD i=0; i<m_logEntries.size(); ++i)
2636 if(this->m_IsOldFirst)
2638 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size()-i-1));
2639 }else
2641 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
2644 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
2645 DeleteAllItems();
2646 SetItemCountEx(ShownCountWithStopped());
2647 RedrawItems(0, ShownCountWithStopped());
2649 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2652 void CGitLogListBase::Clear()
2654 m_arShownList.SafeRemoveAll();
2655 DeleteAllItems();
2657 m_logEntries.ClearAll();
2661 void CGitLogListBase::OnDestroy()
2663 // save the column widths to the registry
2664 SaveColumnWidths();
2666 SafeTerminateThread();
2667 SafeTerminateAsyncDiffThread();
2669 int retry = 0;
2670 while(m_LogCache.SaveCache())
2672 if(retry > 5)
2673 break;
2674 Sleep(1000);
2676 retry++;
2678 //if(CMessageBox::Show(NULL,_T("Cannot Save Log Cache to Disk. To retry click yes. To give up click no."),_T("TortoiseGit"),
2679 // MB_YESNO) == IDNO)
2680 // break;
2683 CHintListCtrl::OnDestroy();
2686 LRESULT CGitLogListBase::OnLoad(WPARAM wParam,LPARAM lParam)
2688 UNREFERENCED_PARAMETER(lParam);
2689 CRect rect;
2690 int i=(int)wParam;
2691 this->GetItemRect(i,&rect,LVIR_BOUNDS);
2692 this->InvalidateRect(rect);
2694 return 0;
2698 * Save column widths to the registry
2700 void CGitLogListBase::SaveColumnWidths()
2702 int maxcol = m_ColumnManager.GetColumnCount();
2704 for (int col = 0; col < maxcol; col++)
2705 if (m_ColumnManager.IsVisible (col))
2706 m_ColumnManager.ColumnResized (col);
2708 m_ColumnManager.WriteSettings();
2711 int CGitLogListBase::GetHeadIndex()
2713 if(m_HeadHash.IsEmpty())
2714 return -1;
2716 for(int i=0;i<m_arShownList.GetCount();i++)
2718 GitRev *pRev = (GitRev*)m_arShownList[i];
2719 if(pRev)
2721 if(pRev->m_CommitHash.ToString() == m_HeadHash )
2722 return i;
2725 return -1;
2727 void CGitLogListBase::OnFind()
2729 if (!m_pFindDialog)
2731 m_pFindDialog = new CFindDlg(this);
2732 m_pFindDialog->Create(this);
2735 void CGitLogListBase::OnHdnBegintrack(NMHDR *pNMHDR, LRESULT *pResult)
2737 m_ColumnManager.OnHdnBegintrack(pNMHDR, pResult);
2739 void CGitLogListBase::OnHdnItemchanging(NMHDR *pNMHDR, LRESULT *pResult)
2741 if(!m_ColumnManager.OnHdnItemchanging(pNMHDR, pResult))
2742 Default();
2744 LRESULT CGitLogListBase::OnFindDialogMessage(WPARAM /*wParam*/, LPARAM /*lParam*/)
2747 ASSERT(m_pFindDialog != NULL);
2748 bool bFound = false;
2749 int i;
2751 if (m_pFindDialog->IsTerminating())
2753 // invalidate the handle identifying the dialog box.
2754 m_pFindDialog = NULL;
2755 return 0;
2758 if(m_pFindDialog->IsRef())
2760 CString str;
2761 str=m_pFindDialog->GetFindString();
2763 CGitHash hash;
2765 if(!str.IsEmpty())
2766 hash = g_Git.GetHash(str);
2768 if(!hash.IsEmpty())
2770 for (i = 0; i<m_arShownList.GetCount(); i++)
2772 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(i);
2773 if(pLogEntry && pLogEntry->m_CommitHash == hash)
2775 bFound = true;
2776 break;
2783 if(m_pFindDialog->FindNext())
2785 //read data from dialog
2786 CString FindText = m_pFindDialog->GetFindString();
2787 bool bMatchCase = (m_pFindDialog->MatchCase() == TRUE);
2789 tr1::wregex pat;
2790 bool bRegex = ValidateRegexp(FindText, pat, bMatchCase);
2792 tr1::regex_constants::match_flag_type flags = tr1::regex_constants::match_not_null;
2795 for (i = this->m_nSearchIndex; i<m_arShownList.GetCount()&&!bFound; i++)
2797 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(i);
2799 CString str;
2800 str+=pLogEntry->m_CommitHash.ToString();
2801 str+=_T("\n");
2803 for(int j=0;j<this->m_HashMap[pLogEntry->m_CommitHash].size();j++)
2805 str+=m_HashMap[pLogEntry->m_CommitHash][j];
2806 str+=_T("\n");
2809 str+=pLogEntry->GetAuthorEmail();
2810 str+=_T("\n");
2811 str+=pLogEntry->GetAuthorName();
2812 str+=_T("\n");
2813 str+=pLogEntry->GetBody();
2814 str+=_T("\n");
2815 str+=pLogEntry->GetCommitterEmail();
2816 str+=_T("\n");
2817 str+=pLogEntry->GetCommitterName();
2818 str+=_T("\n");
2819 str+=pLogEntry->GetSubject();
2820 str+=_T("\n");
2822 #if 0
2823 /*Because changed files list is loaded on demand when gui show,
2824 files will empty when files have not fetched.
2826 we can add it back by using one-way diff(with outnumber changed and rename detect.
2827 here just need changed filename list. one-way is much quicker.
2829 for(int i=0;i<pLogEntry->GetFiles(this).GetCount();i++)
2831 str+=pLogEntry->GetFiles(this)[i].GetWinPath();
2832 str+=_T("\n");
2833 str+=pLogEntry->GetFiles(this)[i].GetGitOldPathString();
2834 str+=_T("\n");
2836 #endif
2838 if (bRegex)
2840 if (regex_search(wstring(str), pat, flags))
2842 bFound = true;
2843 break;
2846 else
2848 if (bMatchCase)
2850 if (str.Find(FindText) >= 0)
2852 bFound = true;
2853 break;
2857 else
2859 CString msg = str;
2860 msg = msg.MakeLower();
2861 CString find = FindText.MakeLower();
2862 if (msg.Find(find) >= 0)
2864 bFound = TRUE;
2865 break;
2869 } // for (i = this->m_nSearchIndex; i<m_arShownList.GetItemCount()&&!bFound; i++)
2871 } // if(m_pFindDialog->FindNext())
2872 //UpdateLogInfoLabel();
2874 if (bFound)
2876 this->m_nSearchIndex = i;
2877 EnsureVisible(i, FALSE);
2878 SetItemState(GetSelectionMark(), 0, LVIS_SELECTED);
2879 SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
2880 SetSelectionMark(i);
2881 //FillLogMessageCtrl();
2882 UpdateData(FALSE);
2883 m_nSearchIndex++;
2884 if (m_nSearchIndex >= m_arShownList.GetCount())
2885 m_nSearchIndex = (int)m_arShownList.GetCount()-1;
2888 return 0;
2891 void CGitLogListBase::OnColumnResized(NMHDR *pNMHDR, LRESULT *pResult)
2893 m_ColumnManager.OnColumnResized(pNMHDR,pResult);
2895 *pResult = FALSE;
2898 void CGitLogListBase::OnColumnMoved(NMHDR *pNMHDR, LRESULT *pResult)
2900 m_ColumnManager.OnColumnMoved(pNMHDR, pResult);
2902 Invalidate(FALSE);