better check when to enable statistics button
[TortoiseGit.git] / src / TortoiseProc / GitLogListBase.cpp
blob16d9405624f45488c7af1c26c880bdfda4b36623
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2011 - TortoiseGit
4 // Copyright (C) 2005-2007 Marco Costalba
5 // Copyright (C) 2011 - Sven Strickroth <email@cs-ware.de>
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software Foundation,
19 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 // GitLogList.cpp : implementation file
23 #include "stdafx.h"
24 #include "resource.h"
25 #include "GitLogListBase.h"
26 #include "GitRev.h"
27 //#include "VssStyle.h"
28 #include "IconMenu.h"
29 // CGitLogListBase
30 #include "cursor.h"
31 #include "InputDlg.h"
32 #include "GITProgressDlg.h"
33 #include "ProgressDlg.h"
34 //#include "RepositoryBrowser.h"
35 //#include "CopyDlg.h"
36 //#include "StatGraphDlg.h"
37 #include "Logdlg.h"
38 #include "MessageBox.h"
39 #include "Registry.h"
40 #include "AppUtils.h"
41 #include "PathUtils.h"
42 #include "StringUtils.h"
43 #include "UnicodeUtils.h"
44 #include "TempFile.h"
45 //#include "GitInfo.h"
46 //#include "GitDiff.h"
47 #include "IconMenu.h"
48 //#include "RevisionRangeDlg.h"
49 //#include "BrowseFolder.h"
50 //#include "BlameDlg.h"
51 //#include "Blame.h"
52 //#include "GitHelpers.h"
53 #include "GitStatus.h"
54 //#include "LogDlgHelper.h"
55 //#include "CachedLogInfo.h"
56 //#include "RepositoryInfo.h"
57 //#include "EditPropertiesDlg.h"
58 #include "FileDiffDlg.h"
59 #include "..\\TortoiseShell\\Resource.h"
60 #include "FindDlg.h"
61 #include "SysInfo.h"
63 const UINT CGitLogListBase::m_FindDialogMessage = RegisterWindowMessage(FINDMSGSTRING);
65 IMPLEMENT_DYNAMIC(CGitLogListBase, CHintListCtrl)
67 CGitLogListBase::CGitLogListBase():CHintListCtrl()
68 ,m_regMaxBugIDColWidth(_T("Software\\TortoiseGit\\MaxBugIDColWidth"), 200)
69 ,m_nSearchIndex(0)
70 ,m_bNoDispUpdates(FALSE)
71 , m_bThreadRunning(FALSE)
72 , m_bStrictStopped(false)
73 , m_pStoreSelection(NULL)
74 , m_nSelectedFilter(LOGFILTER_ALL)
75 , m_bShowWC(false)
76 , m_logEntries(&m_LogCache)
77 , m_pFindDialog(NULL)
78 , m_ColumnManager(this)
79 , m_dwDefaultColumns(0)
80 , m_arShownList(&m_critSec)
82 // use the default GUI font, create a copy of it and
83 // change the copy to BOLD (leave the rest of the font
84 // the same)
85 HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
86 LOGFONT lf = {0};
87 GetObject(hFont, sizeof(LOGFONT), &lf);
88 lf.lfWeight = FW_BOLD;
89 m_boldFont = CreateFontIndirect(&lf);
91 m_bShowBugtraqColumn=false;
93 m_IsIDReplaceAction=FALSE;
95 this->m_critSec.Init();
96 m_wcRev.m_CommitHash.Empty();
97 m_wcRev.GetSubject()=_T("Working dir changes");
98 m_wcRev.m_ParentHash.clear();
99 m_wcRev.m_Mark=_T('-');
100 m_wcRev.m_IsUpdateing=FALSE;
101 m_wcRev.m_IsFull = TRUE;
103 m_hModifiedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONMODIFIED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
104 m_hReplacedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONREPLACED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
105 m_hAddedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONADDED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
106 m_hDeletedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONDELETED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
107 m_hFetchIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONFETCHING), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
109 m_bFilterWithRegex = !!CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), TRUE);
111 g_Git.GetMapHashToFriendName(m_HashMap);
112 m_CurrentBranch=g_Git.GetCurrentBranch();
113 this->m_HeadHash=g_Git.GetHash(_T("HEAD"));
115 m_From=-1;;
116 m_To=-1;
118 m_ShowMask = 0;
119 m_LoadingThread = NULL;
121 InterlockedExchange(&m_bExitThread,FALSE);
122 m_IsOldFirst = FALSE;
123 m_IsRebaseReplaceGraph = FALSE;
126 for(int i=0;i<Lanes::COLORS_NUM;i++)
128 m_LineColors[i] = m_Colors.GetColor((CColors::Colors)(CColors::BranchLine1+i));
130 // get short/long datetime setting from registry
131 DWORD RegUseShortDateFormat = CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE);
132 if ( RegUseShortDateFormat )
134 m_DateFormat = DATE_SHORTDATE;
136 else
138 m_DateFormat = DATE_LONGDATE;
140 // get relative time display setting from registry
141 DWORD regRelativeTimes = CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE);
142 m_bRelativeTimes = (regRelativeTimes != 0);
143 m_ContextMenuMask = 0xFFFFFFFFFFFFFFFF;
145 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_PICK);
146 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_SQUASH);
147 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_EDIT);
148 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_SKIP);
149 m_ContextMenuMask &= ~GetContextMenuBit(ID_LOG);
150 m_ContextMenuMask &= ~GetContextMenuBit(ID_BLAME);
152 m_ColumnRegKey=_T("log");
154 m_AsyncThreadExit = FALSE;
155 m_AsyncDiffEvent = ::CreateEvent(NULL,FALSE,TRUE,NULL);
156 m_AsynDiffListLock.Init();
158 m_DiffingThread = AfxBeginThread(AsyncThread, this, THREAD_PRIORITY_BELOW_NORMAL);
159 if (m_DiffingThread ==NULL)
161 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
162 return;
167 int CGitLogListBase::AsyncDiffThread()
169 m_AsyncThreadExited = false;
170 while(!m_AsyncThreadExit)
172 ::WaitForSingleObject(m_AsyncDiffEvent, INFINITE);
174 GitRev *pRev = NULL;
175 while(!m_AsyncThreadExit && m_AsynDiffList.size() > 0)
177 m_AsynDiffListLock.Lock();
178 pRev = m_AsynDiffList.back();
179 m_AsynDiffList.pop_back();
180 m_AsynDiffListLock.Unlock();
182 if( pRev->m_CommitHash.IsEmpty() )
184 if(pRev->m_IsDiffFiles)
185 continue;
187 pRev->GetFiles(this).Clear();
188 pRev->m_ParentHash.clear();
189 pRev->m_ParentHash.push_back(m_HeadHash);
190 if(g_Git.IsInitRepos())
192 g_Git.GetInitAddList(pRev->GetFiles(this));
195 else
197 g_Git.GetCommitDiffList(pRev->m_CommitHash.ToString(),this->m_HeadHash.ToString(), pRev->GetFiles(this));
199 pRev->GetAction(this) = 0;
201 for(int j=0;j< pRev->GetFiles(this).GetCount();j++)
202 pRev->GetAction(this) |= pRev->GetFiles(this)[j].m_Action;
204 InterlockedExchange(&pRev->m_IsDiffFiles, TRUE);
205 InterlockedExchange(&pRev->m_IsFull, TRUE);
207 pRev->GetBody().Format(_T("%d files changed"),pRev->GetFiles(this).GetCount());
208 ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)0,0);
209 this->GetParent()->PostMessage(WM_COMMAND, MSG_FETCHED_DIFF, 0);
212 if(!pRev->CheckAndDiff())
213 { // fetch change file list
214 for(int i=GetTopIndex(); !m_AsyncThreadExit && i <= GetTopIndex()+GetCountPerPage(); i++)
216 if(i < m_arShownList.GetCount())
218 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(i);
219 if(data->m_CommitHash == pRev->m_CommitHash)
221 ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)i,0);
222 break;
227 if(!m_AsyncThreadExit && GetSelectedCount() == 1)
229 POSITION pos = GetFirstSelectedItemPosition();
230 int nItem = GetNextSelectedItem(pos);
232 if(nItem>=0)
234 GitRev* data = (GitRev*)m_arShownList[nItem];
235 if(data)
236 if(data->m_CommitHash == pRev->m_CommitHash)
238 this->GetParent()->PostMessage(WM_COMMAND, MSG_FETCHED_DIFF, 0);
245 m_AsyncThreadExited = true;
246 return 0;
248 void CGitLogListBase::hideFromContextMenu(unsigned __int64 hideMask, bool exclusivelyShow)
250 if (exclusivelyShow)
252 m_ContextMenuMask &= hideMask;
254 else
256 m_ContextMenuMask &= ~hideMask;
260 CGitLogListBase::~CGitLogListBase()
262 InterlockedExchange(&m_bNoDispUpdates, TRUE);
263 this->m_arShownList.SafeRemoveAll();
265 DestroyIcon(m_hModifiedIcon);
266 DestroyIcon(m_hReplacedIcon);
267 DestroyIcon(m_hAddedIcon);
268 DestroyIcon(m_hDeletedIcon);
269 m_logEntries.ClearAll();
271 if (m_boldFont)
272 DeleteObject(m_boldFont);
274 if ( m_pStoreSelection )
276 delete m_pStoreSelection;
277 m_pStoreSelection = NULL;
280 SafeTerminateThread();
281 SafeTerminateAsyncDiffThread();
283 if(m_AsyncDiffEvent)
284 CloseHandle(m_AsyncDiffEvent);
288 BEGIN_MESSAGE_MAP(CGitLogListBase, CHintListCtrl)
289 ON_REGISTERED_MESSAGE(m_FindDialogMessage, OnFindDialogMessage)
290 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnNMCustomdrawLoglist)
291 ON_NOTIFY_REFLECT(LVN_GETDISPINFO, OnLvnGetdispinfoLoglist)
292 ON_WM_CONTEXTMENU()
293 ON_NOTIFY_REFLECT(NM_DBLCLK, OnNMDblclkLoglist)
294 ON_NOTIFY_REFLECT(LVN_ODFINDITEM,OnLvnOdfinditemLoglist)
295 ON_WM_CREATE()
296 ON_WM_DESTROY()
297 ON_MESSAGE(MSG_LOADED,OnLoad)
298 ON_WM_MEASUREITEM()
299 ON_WM_MEASUREITEM_REFLECT()
300 ON_NOTIFY(HDN_BEGINTRACKA, 0, OnHdnBegintrack)
301 ON_NOTIFY(HDN_BEGINTRACKW, 0, OnHdnBegintrack)
302 ON_NOTIFY(HDN_ITEMCHANGINGA, 0, OnHdnItemchanging)
303 ON_NOTIFY(HDN_ITEMCHANGINGW, 0, OnHdnItemchanging)
304 ON_NOTIFY(HDN_ENDTRACK, 0, OnColumnResized)
305 ON_NOTIFY(HDN_ENDDRAG, 0, OnColumnMoved)
306 END_MESSAGE_MAP()
308 void CGitLogListBase::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
310 //if (m_nRowHeight>0)
312 lpMeasureItemStruct->itemHeight = 50;
316 int CGitLogListBase:: OnCreate(LPCREATESTRUCT lpCreateStruct)
318 PreSubclassWindow();
319 return CHintListCtrl::OnCreate(lpCreateStruct);
322 void CGitLogListBase::PreSubclassWindow()
324 SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_SUBITEMIMAGES);
325 // load the icons for the action columns
326 // m_Theme.Open(m_hWnd, L"ListView");
327 SetWindowTheme(m_hWnd, L"Explorer", NULL);
328 CHintListCtrl::PreSubclassWindow();
331 void CGitLogListBase::InsertGitColumn()
333 CString temp;
335 CRegDWORD regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE);
336 DWORD exStyle = LVS_EX_HEADERDRAGDROP | LVS_EX_DOUBLEBUFFER | LVS_EX_INFOTIP | LVS_EX_SUBITEMIMAGES;
337 if (DWORD(regFullRowSelect))
338 exStyle |= LVS_EX_FULLROWSELECT;
339 SetExtendedStyle(exStyle);
341 UpdateProjectProperties();
343 static UINT normal[] =
345 IDS_LOG_GRAPH,
346 IDS_LOG_REBASE,
347 IDS_LOG_ID,
348 IDS_LOG_HASH,
349 IDS_LOG_ACTIONS,
350 IDS_LOG_MESSAGE,
351 IDS_LOG_AUTHOR,
352 IDS_LOG_DATE,
353 IDS_LOG_EMAIL,
354 IDS_LOG_COMMIT_NAME,
355 IDS_LOG_COMMIT_EMAIL,
356 IDS_LOG_COMMIT_DATE,
357 IDS_LOG_BUGIDS,
360 static int with[] =
362 ICONITEMBORDER+16*4,
363 ICONITEMBORDER+16*4,
364 ICONITEMBORDER+16*4,
365 ICONITEMBORDER+16*4,
366 ICONITEMBORDER+16*4,
367 LOGLIST_MESSAGE_MIN,
368 ICONITEMBORDER+16*4,
369 ICONITEMBORDER+16*4,
370 ICONITEMBORDER+16*4,
371 ICONITEMBORDER+16*4,
372 ICONITEMBORDER+16*4,
373 ICONITEMBORDER+16*4,
374 ICONITEMBORDER+16*4,
376 m_dwDefaultColumns = GIT_LOG_GRAPH|GIT_LOG_ACTIONS|GIT_LOG_MESSAGE|GIT_LOG_AUTHOR|GIT_LOG_DATE;
378 DWORD hideColumns = 0;
379 if(this->m_IsRebaseReplaceGraph)
381 hideColumns |= GIT_LOG_GRAPH;
382 m_dwDefaultColumns |= GIT_LOG_REBASE;
384 else
386 hideColumns |= GIT_LOG_REBASE;
389 if(this->m_IsIDReplaceAction)
391 hideColumns |= GIT_LOG_ACTIONS;
392 m_dwDefaultColumns |= GIT_LOG_ID;
393 m_dwDefaultColumns |= GIT_LOG_HASH;
395 else
397 hideColumns |= GIT_LOG_ID;
399 if(this->m_bShowBugtraqColumn)
401 m_dwDefaultColumns |= GIT_LOGLIST_BUG;
403 else
405 hideColumns |= GIT_LOGLIST_BUG;
407 SetRedraw(false);
409 m_ColumnManager.SetNames(normal, _countof(normal));
410 m_ColumnManager.ReadSettings(m_dwDefaultColumns, hideColumns, m_ColumnRegKey+_T("loglist"), _countof(normal), with);
412 SetRedraw(true);
417 * Resizes all columns in a list control to values in registry.
419 void CGitLogListBase::ResizeAllListCtrlCols()
421 // column max and min widths to allow
422 static const int nMinimumWidth = 10;
423 static const int nMaximumWidth = 1000;
424 CHeaderCtrl* pHdrCtrl = (CHeaderCtrl*)(GetDlgItem(0));
425 if (pHdrCtrl)
427 int numcols = pHdrCtrl->GetItemCount();
428 for (int col = 0; col < numcols; col++)
430 // get width for this col last time from registry
431 CString regentry;
432 regentry.Format( _T("Software\\TortoiseGit\\%s\\ColWidth%d"),m_ColumnRegKey, col);
433 CRegDWORD regwidth(regentry, 0);
434 int cx = regwidth;
435 if ( cx == 0 )
437 // no saved value, setup sensible defaults
438 if (col == this->LOGLIST_MESSAGE)
440 cx = LOGLIST_MESSAGE_MIN;
442 else
444 cx = ICONITEMBORDER+16*4;
447 if (cx < nMinimumWidth)
449 cx = nMinimumWidth;
451 else if (cx > nMaximumWidth)
453 cx = nMaximumWidth;
456 SetColumnWidth(col, cx);
463 BOOL CGitLogListBase::GetShortName(CString ref, CString &shortname,CString prefix)
465 //TRACE(_T("%s %s\r\n"),ref,prefix);
466 if(ref.Left(prefix.GetLength()) == prefix)
468 shortname = ref.Right(ref.GetLength()-prefix.GetLength());
469 if(shortname.Right(3)==_T("^{}"))
470 shortname=shortname.Left(shortname.GetLength()-3);
471 return TRUE;
473 return FALSE;
476 void CGitLogListBase::FillBackGround(HDC hdc, int Index,CRect &rect)
478 // HBRUSH brush;
479 LVITEM rItem;
480 SecureZeroMemory(&rItem, sizeof(LVITEM));
481 rItem.mask = LVIF_STATE;
482 rItem.iItem = Index;
483 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
484 GetItem(&rItem);
486 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(Index);
487 HBRUSH brush = NULL;
489 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
491 HTHEME hTheme = OpenThemeData(m_hWnd, L"Explorer::ListView;ListView");
492 int state = LISS_NORMAL;
493 if (rItem.state & LVIS_SELECTED)
495 if (::GetFocus() == m_hWnd)
496 state |= LISS_SELECTED;
497 else
498 state |= LISS_SELECTEDNOTFOCUS;
500 else
502 if(pLogEntry->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_SQUASH)
503 brush = ::CreateSolidBrush(RGB(156,156,156));
504 else if(pLogEntry->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_EDIT)
505 brush = ::CreateSolidBrush(RGB(200,200,128));
508 if (brush != NULL)
510 ::FillRect(hdc, &rect, brush);
511 ::DeleteObject(brush);
513 else
515 if (IsThemeBackgroundPartiallyTransparent(hTheme, LVP_LISTITEM, state))
516 DrawThemeParentBackground(m_hWnd, hdc, &rect);
518 CRect rectDraw = rect;
519 if(rItem.state & LVIS_SELECTED)
520 rectDraw.InflateRect(1,0);
521 else
522 rectDraw.InflateRect(1,1);
524 DrawThemeBackground(hTheme, hdc, LVP_LISTITEM, state, rectDraw, &rect);
526 CloseThemeData(hTheme);
528 else
530 if (rItem.state & LVIS_SELECTED)
532 if (::GetFocus() == m_hWnd)
533 brush = ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT));
534 else
535 brush = ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE));
537 else
539 //if (pLogEntry->bCopiedSelf)
540 // brush = ::CreateSolidBrush(::GetSysColor(COLOR_MENU));
541 //else
542 if(pLogEntry->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_SQUASH)
543 brush = ::CreateSolidBrush(RGB(156,156,156));
544 else if(pLogEntry->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_EDIT)
545 brush = ::CreateSolidBrush(RGB(200,200,128));
546 else
547 brush = ::CreateSolidBrush(::GetSysColor(COLOR_WINDOW));
549 if (brush == NULL)
550 return;
552 ::FillRect(hdc, &rect, brush);
553 ::DeleteObject(brush);
557 void CGitLogListBase::DrawTagBranch(HDC hdc,CRect &rect,INT_PTR index)
559 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(index);
560 CRect rt=rect;
561 LVITEM rItem;
562 SecureZeroMemory(&rItem, sizeof(LVITEM));
563 rItem.mask = LVIF_STATE;
564 rItem.iItem = index;
565 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
566 GetItem(&rItem);
568 CDC W_Dc;
569 W_Dc.Attach(hdc);
571 HTHEME hTheme = NULL;
572 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
573 hTheme = OpenThemeData(m_hWnd, L"Explorer::ListView;ListView");
575 for(unsigned int i=0;i<m_HashMap[data->m_CommitHash].size();i++)
577 CString str;
578 str=m_HashMap[data->m_CommitHash][i];
580 CString shortname;
581 HBRUSH brush = 0;
582 shortname = _T("");
583 COLORREF colRef = 0;
585 //Determine label color
586 if(GetShortName(str,shortname,_T("refs/heads/")))
588 if( shortname == m_CurrentBranch )
589 colRef = m_Colors.GetColor(CColors::CurrentBranch);
590 else
591 colRef = m_Colors.GetColor(CColors::LocalBranch);
594 else if(GetShortName(str,shortname,_T("refs/remotes/")))
596 colRef = m_Colors.GetColor(CColors::RemoteBranch);
598 else if(GetShortName(str,shortname,_T("refs/tags/")))
600 colRef = m_Colors.GetColor(CColors::Tag);
602 else if(GetShortName(str,shortname,_T("refs/stash")))
604 colRef = m_Colors.GetColor(CColors::Stash);
605 shortname=_T("stash");
607 else if(GetShortName(str,shortname,_T("refs/bisect/")))
609 if(shortname.Find(_T("good")) == 0)
611 colRef = m_Colors.GetColor(CColors::BisectGood);
612 shortname = _T("good");
615 if(shortname.Find(_T("bad")) == 0)
617 colRef = m_Colors.GetColor(CColors::BisectBad);
618 shortname = _T("bad");
622 //When row selected, ajust label color
623 if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
624 if (rItem.state & LVIS_SELECTED)
625 colRef = CColors::MixColors(colRef, ::GetSysColor(COLOR_HIGHLIGHT), 150);
627 brush = ::CreateSolidBrush(colRef);
629 if(!shortname.IsEmpty() && (rt.left<rect.right) )
631 SIZE size;
632 memset(&size,0,sizeof(SIZE));
633 GetTextExtentPoint32(hdc, shortname,shortname.GetLength(),&size);
635 rt.SetRect(rt.left,rt.top,rt.left+size.cx,rt.bottom);
636 rt.right+=8;
638 int textpos = DT_CENTER;
640 if(rt.right > rect.right)
642 rt.right = rect.right;
643 textpos =0;
646 //Fill interior of ref label
647 ::FillRect(hdc, &rt, brush);
649 //Draw edge of label
651 CRect rectEdge = rt;
653 W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef,100), m_Colors.Darken(colRef,100));
654 rectEdge.DeflateRect(1,1);
655 W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef,50), m_Colors.Darken(colRef,50));
657 //Draw text inside label
658 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
660 int txtState = LISS_NORMAL;
661 if (rItem.state & LVIS_SELECTED)
662 txtState = LISS_SELECTED;
664 DrawThemeText(hTheme,hdc, LVP_LISTITEM, txtState, shortname, -1, textpos | DT_SINGLELINE | DT_VCENTER, 0, &rt);
666 else
668 W_Dc.SetBkMode(TRANSPARENT);
669 if (rItem.state & LVIS_SELECTED)
671 COLORREF clrNew = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
672 COLORREF clrOld = ::SetTextColor(hdc,clrNew);
673 ::DrawText(hdc,shortname,shortname.GetLength(),&rt,textpos | DT_SINGLELINE | DT_VCENTER);
674 ::SetTextColor(hdc,clrOld);
676 else
678 ::DrawText(hdc,shortname,shortname.GetLength(),&rt,textpos | DT_SINGLELINE | DT_VCENTER);
682 //::MoveToEx(hdc,rt.left,rt.top,NULL);
683 //::LineTo(hdc,rt.right,rt.top);
684 //::LineTo(hdc,rt.right,rt.bottom);
685 //::LineTo(hdc,rt.left,rt.bottom);
686 //::LineTo(hdc,rt.left,rt.top);
688 rt.left=rt.right+1;
690 if(brush)
691 ::DeleteObject(brush);
693 rt.right=rect.right;
695 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
697 int txtState = LISS_NORMAL;
698 if (rItem.state & LVIS_SELECTED)
699 txtState = LISS_SELECTED;
701 DrawThemeText(hTheme,hdc, LVP_LISTITEM, txtState, data->GetSubject(), -1, DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER, 0, &rt);
703 else
705 if (rItem.state & LVIS_SELECTED)
707 COLORREF clrOld = ::SetTextColor(hdc,::GetSysColor(COLOR_HIGHLIGHTTEXT));
708 ::DrawText(hdc,data->GetSubject(),data->GetSubject().GetLength(),&rt,DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER);
709 ::SetTextColor(hdc,clrOld);
711 else
713 ::DrawText(hdc,data->GetSubject(),data->GetSubject().GetLength(),&rt,DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER);
717 if (hTheme)
718 CloseThemeData(hTheme);
720 W_Dc.Detach();
723 static COLORREF blend(const COLORREF& col1, const COLORREF& col2, int amount = 128) {
725 // Returns ((256 - amount)*col1 + amount*col2) / 256;
726 return RGB(((256 - amount)*GetRValue(col1) + amount*GetRValue(col2) ) / 256,
727 ((256 - amount)*GetGValue(col1) + amount*GetGValue(col2) ) / 256,
728 ((256 - amount)*GetBValue(col1) + amount*GetBValue(col2) ) / 256);
731 Gdiplus::Color GetGdiColor(COLORREF col)
733 return Gdiplus::Color(GetRValue(col),GetGValue(col),GetBValue(col));
735 void CGitLogListBase::paintGraphLane(HDC hdc, int laneHeight,int type, int x1, int x2,
736 const COLORREF& col,const COLORREF& activeColor, int top
739 int h = laneHeight / 2;
740 int m = (x1 + x2) / 2;
741 int r = (x2 - x1) / 3;
742 int d = 2 * r;
744 #define P_CENTER m , h+top
745 #define P_0 x2, h+top
746 #define P_90 m , 0+top-1
747 #define P_180 x1, h+top
748 #define P_270 m , 2 * h+top +1
749 #define R_CENTER m - r, h - r+top, d, d
752 #define DELTA_UR_B 2*(x1 - m), 2*h +top
753 #define DELTA_UR_E 0*16, 90*16 +top // -,
755 #define DELTA_DR_B 2*(x1 - m), 2*-h +top
756 #define DELTA_DR_E 270*16, 90*16 +top // -'
758 #define DELTA_UL_B 2*(x2 - m), 2*h +top
759 #define DELTA_UL_E 90*16, 90*16 +top // ,-
761 #define DELTA_DL_B 2*(x2 - m),2*-h +top
762 #define DELTA_DL_E 180*16, 90*16 // '-
764 #define CENTER_UR x1, 2*h, 225
765 #define CENTER_DR x1, 0 , 135
766 #define CENTER_UL x2, 2*h, 315
767 #define CENTER_DL x2, 0 , 45
770 Gdiplus::Graphics graphics( hdc );
772 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
774 // arc
775 switch (type) {
776 case Lanes::JOIN:
777 case Lanes::JOIN_R:
778 case Lanes::HEAD:
779 case Lanes::HEAD_R:
781 Gdiplus::LinearGradientBrush gradient(
782 Gdiplus::Point(x1-2, h+top-2),
783 Gdiplus::Point(P_270),
784 GetGdiColor(activeColor),GetGdiColor(col));
787 Gdiplus::Pen mypen(&gradient,2);
788 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
790 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
791 graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top+h-1, x2-x1,laneHeight,270,90);
792 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
794 break;
796 case Lanes::JOIN_L:
799 Gdiplus::LinearGradientBrush gradient(
800 Gdiplus::Point(P_270),
801 Gdiplus::Point(x2+1, h+top-1),
802 GetGdiColor(col),GetGdiColor(activeColor));
805 Gdiplus::Pen mypen(&gradient,2);
806 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
808 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
809 graphics.DrawArc(&mypen,x1+(x2-x1)/2,top+h-1, x2-x1,laneHeight,180,90);
810 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
813 break;
815 case Lanes::TAIL:
816 case Lanes::TAIL_R:
819 Gdiplus::LinearGradientBrush gradient(
820 Gdiplus::Point(x1-2, h+top-2),
821 Gdiplus::Point(P_90),
822 GetGdiColor(activeColor),GetGdiColor(col));
824 Gdiplus::Pen mypen(&gradient,2);
826 graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top-h-1, x2-x1,laneHeight,0,90);
828 #if 0
829 QConicalGradient gradient(CENTER_DR);
830 gradient.setColorAt(0.375, activeCol);
831 gradient.setColorAt(0.625, col);
832 myPen.setBrush(gradient);
833 p->setPen(myPen);
834 p->drawArc(P_CENTER, DELTA_DR);
835 #endif
836 break;
838 default:
839 break;
843 //static QPen myPen(Qt::black, 2); // fast path here
844 CPen pen;
845 pen.CreatePen(PS_SOLID,2,col);
846 //myPen.setColor(col);
847 HPEN oldpen=(HPEN)::SelectObject(hdc,(HPEN)pen);
849 Gdiplus::Pen myPen(GetGdiColor(col),2);
851 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
853 //p->setPen(myPen);
855 // vertical line
856 switch (type) {
857 case Lanes::ACTIVE:
858 case Lanes::NOT_ACTIVE:
859 case Lanes::MERGE_FORK:
860 case Lanes::MERGE_FORK_R:
861 case Lanes::MERGE_FORK_L:
862 case Lanes::JOIN:
863 case Lanes::JOIN_R:
864 case Lanes::JOIN_L:
865 case Lanes::CROSS:
866 //DrawLine(hdc,P_90,P_270);
867 graphics.DrawLine(&myPen,P_90,P_270);
868 //p->drawLine(P_90, P_270);
869 break;
870 case Lanes::HEAD_L:
871 case Lanes::BRANCH:
872 //DrawLine(hdc,P_CENTER,P_270);
873 graphics.DrawLine(&myPen,P_CENTER,P_270);
874 //p->drawLine(P_CENTER, P_270);
875 break;
876 case Lanes::TAIL_L:
877 case Lanes::INITIAL:
878 case Lanes::BOUNDARY:
879 case Lanes::BOUNDARY_C:
880 case Lanes::BOUNDARY_R:
881 case Lanes::BOUNDARY_L:
882 //DrawLine(hdc,P_90, P_CENTER);
883 graphics.DrawLine(&myPen,P_90,P_CENTER);
884 //p->drawLine(P_90, P_CENTER);
885 break;
886 default:
887 break;
890 myPen.SetColor(GetGdiColor(activeColor));
892 // horizontal line
893 switch (type) {
894 case Lanes::MERGE_FORK:
895 case Lanes::JOIN:
896 case Lanes::HEAD:
897 case Lanes::TAIL:
898 case Lanes::CROSS:
899 case Lanes::CROSS_EMPTY:
900 case Lanes::BOUNDARY_C:
901 //DrawLine(hdc,P_180,P_0);
902 graphics.DrawLine(&myPen,P_180,P_0);
903 //p->drawLine(P_180, P_0);
904 break;
905 case Lanes::MERGE_FORK_R:
906 case Lanes::BOUNDARY_R:
907 //DrawLine(hdc,P_180,P_CENTER);
908 graphics.DrawLine(&myPen,P_180,P_CENTER);
909 //p->drawLine(P_180, P_CENTER);
910 break;
911 case Lanes::MERGE_FORK_L:
912 case Lanes::HEAD_L:
913 case Lanes::TAIL_L:
914 case Lanes::BOUNDARY_L:
915 //DrawLine(hdc,P_CENTER,P_0);
916 graphics.DrawLine(&myPen,P_CENTER,P_0);
917 //p->drawLine(P_CENTER, P_0);
918 break;
919 default:
920 break;
923 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
925 CBrush brush;
926 brush.CreateSolidBrush(col);
927 HBRUSH oldbrush=(HBRUSH)::SelectObject(hdc,(HBRUSH)brush);
929 Gdiplus::SolidBrush myBrush(GetGdiColor(col));
930 // center symbol, e.g. rect or ellipse
931 switch (type) {
932 case Lanes::ACTIVE:
933 case Lanes::INITIAL:
934 case Lanes::BRANCH:
936 //p->setPen(Qt::NoPen);
937 //p->setBrush(col);
938 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
939 graphics.FillEllipse(&myBrush, R_CENTER);
940 //p->drawEllipse(R_CENTER);
941 break;
942 case Lanes::MERGE_FORK:
943 case Lanes::MERGE_FORK_R:
944 case Lanes::MERGE_FORK_L:
945 //p->setPen(Qt::NoPen);
946 //p->setBrush(col);
947 //p->drawRect(R_CENTER);
948 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
949 graphics.FillRectangle(&myBrush, R_CENTER);
950 break;
951 case Lanes::UNAPPLIED:
952 // Red minus sign
953 //p->setPen(Qt::NoPen);
954 //p->setBrush(Qt::red);
955 //p->drawRect(m - r, h - 1, d, 2);
956 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
957 graphics.FillRectangle(&myBrush,m-r,h-1,d,2);
958 break;
959 case Lanes::APPLIED:
960 // Green plus sign
961 //p->setPen(Qt::NoPen);
962 //p->setBrush(DARK_GREEN);
963 //p->drawRect(m - r, h - 1, d, 2);
964 //p->drawRect(m - 1, h - r, 2, d);
965 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
966 graphics.FillRectangle(&myBrush,m-r,h-1,d,2);
967 graphics.FillRectangle(&myBrush,m-1,h-r,2,d);
968 break;
969 case Lanes::BOUNDARY:
970 //p->setBrush(back);
971 //p->drawEllipse(R_CENTER);
972 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
973 graphics.DrawEllipse(&myPen, R_CENTER);
974 break;
975 case Lanes::BOUNDARY_C:
976 case Lanes::BOUNDARY_R:
977 case Lanes::BOUNDARY_L:
978 //p->setBrush(back);
979 //p->drawRect(R_CENTER);
980 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
981 graphics.FillRectangle(&myBrush,R_CENTER);
982 break;
983 default:
984 break;
987 ::SelectObject(hdc,oldpen);
988 ::SelectObject(hdc,oldbrush);
989 #undef P_CENTER
990 #undef P_0
991 #undef P_90
992 #undef P_180
993 #undef P_270
994 #undef R_CENTER
997 void CGitLogListBase::DrawGraph(HDC hdc,CRect &rect,INT_PTR index)
999 // TODO: unfinished
1000 // return;
1001 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(index);
1002 if(data->m_CommitHash.IsEmpty())
1003 return;
1005 CRect rt=rect;
1006 LVITEM rItem;
1007 SecureZeroMemory(&rItem, sizeof(LVITEM));
1008 rItem.mask = LVIF_STATE;
1009 rItem.iItem = index;
1010 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
1011 GetItem(&rItem);
1013 // p->translate(QPoint(opt.rect.left(), opt.rect.top()));
1015 if (data->m_Lanes.size() == 0)
1016 m_logEntries.setLane(data->m_CommitHash);
1018 std::vector<int>& lanes=data->m_Lanes;
1019 UINT laneNum = lanes.size();
1020 UINT activeLane = 0;
1021 for (UINT i = 0; i < laneNum; i++)
1022 if (Lanes::isMerge(lanes[i])) {
1023 activeLane = i;
1024 break;
1027 int x1 = 0, x2 = 0;
1028 int maxWidth = rect.Width();
1029 int lw = 3 * rect.Height() / 4; //laneWidth()
1031 COLORREF activeColor = m_LineColors[activeLane % Lanes::COLORS_NUM];
1032 //if (opt.state & QStyle::State_Selected)
1033 // activeColor = blend(activeColor, opt.palette.highlightedText().color(), 208);
1035 for (unsigned int i = 0; i < laneNum && x2 < maxWidth; i++)
1038 x1 = x2;
1039 x2 += lw;
1041 int ln = lanes[i];
1042 if (ln == Lanes::EMPTY)
1043 continue;
1045 COLORREF color = i == activeLane ? activeColor : m_LineColors[i % Lanes::COLORS_NUM];
1046 paintGraphLane(hdc, rect.Height(),ln, x1+rect.left, x2+rect.left, color,activeColor, rect.top);
1049 #if 0
1050 for (UINT i = 0; i < laneNum && x2 < maxWidth; i++) {
1052 x1 = x2;
1053 x2 += lw;
1055 int ln = lanes[i];
1056 if (ln == Lanes::EMPTY)
1057 continue;
1059 UINT col = ( Lanes:: isHead(ln) ||Lanes:: isTail(ln) || Lanes::isJoin(ln)
1060 || ln ==Lanes:: CROSS_EMPTY) ? activeLane : i;
1062 if (ln == Lanes::CROSS)
1064 paintGraphLane(hdc, rect.Height(),Lanes::NOT_ACTIVE, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
1065 paintGraphLane(hdc, rect.Height(),Lanes::CROSS, x1, x2, m_LineColors[activeLane % Lanes::COLORS_NUM],rect.top);
1067 else
1068 paintGraphLane(hdc, rect.Height(),ln, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
1070 #endif
1074 void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1077 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
1078 // Take the default processing unless we set this to something else below.
1079 *pResult = CDRF_DODEFAULT;
1081 if (m_bNoDispUpdates)
1082 return;
1086 switch (pLVCD->nmcd.dwDrawStage)
1088 case CDDS_PREPAINT:
1090 *pResult = CDRF_NOTIFYITEMDRAW;
1091 return;
1093 break;
1094 case CDDS_ITEMPREPAINT:
1096 // This is the prepaint stage for an item. Here's where we set the
1097 // item's text color.
1099 // Tell Windows to send draw notifications for each subitem.
1100 *pResult = CDRF_NOTIFYSUBITEMDRAW;
1102 COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);
1104 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
1106 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1107 if (data)
1109 #if 0
1110 if (data->bCopiedSelf)
1112 // only change the background color if the item is not 'hot' (on vista with m_Themes enabled)
1113 if (!IsAppThemed()) || !m_bVista || ((pLVCD->nmcd.uItemState & CDIS_HOT)==0))
1114 pLVCD->clrTextBk = GetSysColor(COLOR_MENU);
1117 if (data->bCopies)
1118 crText = m_Colors.GetColor(CColors::Modified);
1119 #endif
1120 if (data->GetAction(this)& (CTGitPath::LOGACTIONS_REBASE_DONE| CTGitPath::LOGACTIONS_REBASE_SKIP) )
1121 crText = RGB(128,128,128);
1123 if(data->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_SQUASH)
1124 pLVCD->clrTextBk = RGB(156,156,156);
1125 else if(data->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_EDIT)
1126 pLVCD->clrTextBk = RGB(200,200,128);
1127 else
1128 pLVCD->clrTextBk = ::GetSysColor(COLOR_WINDOW);
1130 if(data->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_CURRENT)
1132 SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1133 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1136 if(data->m_CommitHash.ToString() == m_HeadHash)
1138 SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1139 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1142 // if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))
1143 // crText = GetSysColor(COLOR_GRAYTEXT);
1145 if (data->m_CommitHash.IsEmpty())
1147 //crText = GetSysColor(RGB(200,200,0));
1148 //SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1149 // We changed the font, so we're returning CDRF_NEWFONT. This
1150 // tells the control to recalculate the extent of the text.
1151 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1155 if (m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec)
1157 if (m_bStrictStopped)
1158 crText = GetSysColor(COLOR_GRAYTEXT);
1160 // Store the color back in the NMLVCUSTOMDRAW struct.
1161 pLVCD->clrText = crText;
1162 return;
1164 break;
1165 case CDDS_ITEMPREPAINT|CDDS_ITEM|CDDS_SUBITEM:
1167 if ((m_bStrictStopped)&&(m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec))
1169 pLVCD->nmcd.uItemState &= ~(CDIS_SELECTED|CDIS_FOCUS);
1172 if (pLVCD->iSubItem == LOGLIST_GRAPH)
1174 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec && (!this->m_IsRebaseReplaceGraph) )
1176 CRect rect;
1177 GetSubItemRect(pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_LABEL, rect);
1179 //TRACE(_T("A Graphic left %d right %d\r\n"),rect.left,rect.right);
1180 FillBackGround(pLVCD->nmcd.hdc, (INT_PTR)pLVCD->nmcd.dwItemSpec,rect);
1182 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1183 if( !data ->m_CommitHash.IsEmpty())
1184 DrawGraph(pLVCD->nmcd.hdc,rect,pLVCD->nmcd.dwItemSpec);
1186 *pResult = CDRF_SKIPDEFAULT;
1187 return;
1191 if (pLVCD->iSubItem == LOGLIST_MESSAGE)
1193 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
1195 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1196 //if(!data->m_IsFull)
1198 //if(data->SafeFetchFullInfo(&g_Git))
1199 // this->Invalidate();
1200 //TRACE(_T("Update ... %d\r\n"),pLVCD->nmcd.dwItemSpec);
1203 if(m_HashMap[data->m_CommitHash].size()!=0)
1205 CRect rect;
1207 GetSubItemRect(pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
1209 FillBackGround(pLVCD->nmcd.hdc, (INT_PTR)pLVCD->nmcd.dwItemSpec,rect);
1210 DrawTagBranch(pLVCD->nmcd.hdc,rect,pLVCD->nmcd.dwItemSpec);
1212 *pResult = CDRF_SKIPDEFAULT;
1213 return;
1220 if (pLVCD->iSubItem == LOGLIST_ACTION)
1222 if(this->m_IsIDReplaceAction)
1224 *pResult = CDRF_DODEFAULT;
1225 return;
1227 *pResult = CDRF_DODEFAULT;
1229 if (m_arShownList.GetCount() <= (INT_PTR)pLVCD->nmcd.dwItemSpec)
1230 return;
1232 int nIcons = 0;
1233 int iconwidth = ::GetSystemMetrics(SM_CXSMICON);
1234 int iconheight = ::GetSystemMetrics(SM_CYSMICON);
1236 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec));
1237 CRect rect;
1238 GetSubItemRect(pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
1239 //TRACE(_T("Action left %d right %d\r\n"),rect.left,rect.right);
1240 // Get the selected state of the
1241 // item being drawn.
1243 // Fill the background
1244 FillBackGround(pLVCD->nmcd.hdc, (INT_PTR)pLVCD->nmcd.dwItemSpec,rect);
1246 // Draw the icon(s) into the compatible DC
1247 pLogEntry->GetAction(this);
1249 if (!pLogEntry->m_IsDiffFiles)
1250 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hFetchIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1252 if (pLogEntry->GetAction(this) & CTGitPath::LOGACTIONS_MODIFIED)
1253 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hModifiedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1254 nIcons++;
1256 if (pLogEntry->GetAction(this) & (CTGitPath::LOGACTIONS_ADDED|CTGitPath::LOGACTIONS_COPY) )
1257 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hAddedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1258 nIcons++;
1260 if (pLogEntry->GetAction(this) & CTGitPath::LOGACTIONS_DELETED)
1261 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hDeletedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1262 nIcons++;
1264 if (pLogEntry->GetAction(this) & CTGitPath::LOGACTIONS_REPLACED)
1265 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hReplacedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1266 nIcons++;
1267 *pResult = CDRF_SKIPDEFAULT;
1268 return;
1271 break;
1273 *pResult = CDRF_DODEFAULT;
1276 // CGitLogListBase message handlers
1278 void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1280 NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
1282 // Create a pointer to the item
1283 LV_ITEM* pItem = &(pDispInfo)->item;
1285 // Do the list need text information?
1286 if (!(pItem->mask & LVIF_TEXT))
1287 return;
1289 // By default, clear text buffer.
1290 lstrcpyn(pItem->pszText, _T(""), pItem->cchTextMax);
1292 bool bOutOfRange = pItem->iItem >= ShownCountWithStopped();
1294 *pResult = 0;
1295 if (m_bNoDispUpdates || bOutOfRange)
1296 return;
1298 // Which item number?
1299 int itemid = pItem->iItem;
1300 GitRev * pLogEntry = NULL;
1301 if (itemid < m_arShownList.GetCount())
1302 pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(pItem->iItem));
1304 CString temp;
1305 if(m_IsOldFirst)
1307 temp.Format(_T("%d"),pItem->iItem+1);
1310 else
1312 temp.Format(_T("%d"),m_arShownList.GetCount()-pItem->iItem);
1315 // Which column?
1316 switch (pItem->iSubItem)
1318 case this->LOGLIST_GRAPH: //Graphic
1319 break;
1320 case this->LOGLIST_REBASE:
1322 if(this->m_IsRebaseReplaceGraph)
1324 CTGitPath path;
1325 path.m_Action=pLogEntry->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_MODE_MASK;
1326 lstrcpyn(pItem->pszText,path.GetActionName(), pItem->cchTextMax);
1329 break;
1330 case this->LOGLIST_ACTION: //action -- no text in the column
1331 break;
1332 case this->LOGLIST_HASH:
1333 if(pLogEntry)
1334 lstrcpyn(pItem->pszText, pLogEntry->m_CommitHash.ToString(), pItem->cchTextMax);
1335 break;
1336 case this->LOGLIST_ID:
1337 if(this->m_IsIDReplaceAction)
1338 lstrcpyn(pItem->pszText, temp, pItem->cchTextMax);
1339 break;
1340 case this->LOGLIST_MESSAGE: //Message
1341 if (pLogEntry)
1342 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetSubject(), pItem->cchTextMax);
1343 break;
1344 case this->LOGLIST_AUTHOR: //Author
1345 if (pLogEntry)
1346 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetAuthorName(), pItem->cchTextMax);
1347 break;
1348 case this->LOGLIST_DATE: //Date
1349 if ( pLogEntry && (!pLogEntry->m_CommitHash.IsEmpty()) )
1350 lstrcpyn(pItem->pszText,
1351 CAppUtils::FormatDateAndTime( pLogEntry->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes ),
1352 pItem->cchTextMax);
1353 break;
1355 case this->LOGLIST_EMAIL:
1356 if (pLogEntry)
1357 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetAuthorEmail(), pItem->cchTextMax);
1358 break;
1360 case this->LOGLIST_COMMIT_NAME: //Commit
1361 if (pLogEntry)
1362 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetCommitterName(), pItem->cchTextMax);
1363 break;
1365 case this->LOGLIST_COMMIT_EMAIL: //Commit Email
1366 if (pLogEntry)
1367 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetCommitterEmail(), pItem->cchTextMax);
1368 break;
1370 case this->LOGLIST_COMMIT_DATE: //Commit Date
1371 if (pLogEntry)
1372 lstrcpyn(pItem->pszText,
1373 CAppUtils::FormatDateAndTime( pLogEntry->GetCommitterDate(), m_DateFormat, true, m_bRelativeTimes ),
1374 pItem->cchTextMax);
1375 break;
1376 case this->LOGLIST_BUG: //Bug ID
1377 if(pLogEntry)
1378 lstrcpyn(pItem->pszText, (LPCTSTR)this->m_ProjectProperties.FindBugID(pLogEntry->GetSubject()), pItem->cchTextMax);
1379 break;
1381 default:
1382 ASSERT(false);
1386 void CGitLogListBase::OnContextMenu(CWnd* pWnd, CPoint point)
1389 if (pWnd == GetHeaderCtrl())
1391 return m_ColumnManager.OnContextMenuHeader(pWnd,point,!!IsGroupViewEnabled());
1394 int selIndex = GetSelectionMark();
1395 if (selIndex < 0)
1396 return; // nothing selected, nothing to do with a context menu
1398 // if the user selected the info text telling about not all revisions shown due to
1399 // the "stop on copy/rename" option, we also don't show the context menu
1400 if ((m_bStrictStopped)&&(selIndex == m_arShownList.GetCount()))
1401 return;
1403 // if the context menu is invoked through the keyboard, we have to use
1404 // a calculated position on where to anchor the menu on
1405 if ((point.x == -1) && (point.y == -1))
1407 CRect rect;
1408 GetItemRect(selIndex, &rect, LVIR_LABEL);
1409 ClientToScreen(&rect);
1410 point = rect.CenterPoint();
1412 m_nSearchIndex = selIndex;
1413 m_bCancelled = FALSE;
1415 // calculate some information the context menu commands can use
1416 // CString pathURL = GetURLFromPath(m_path);
1418 POSITION pos = GetFirstSelectedItemPosition();
1419 int indexNext = GetNextSelectedItem(pos);
1420 if (indexNext < 0)
1421 return;
1423 GitRev* pSelLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(indexNext));
1424 #if 0
1425 GitRev revSelected = pSelLogEntry->Rev;
1426 GitRev revPrevious = git_revnum_t(revSelected)-1;
1427 if ((pSelLogEntry->pArChangedPaths)&&(pSelLogEntry->pArChangedPaths->GetCount() <= 2))
1429 for (int i=0; i<pSelLogEntry->pArChangedPaths->GetCount(); ++i)
1431 LogChangedPath * changedpath = (LogChangedPath *)pSelLogEntry->pArChangedPaths->SafeGetAt(i);
1432 if (changedpath->lCopyFromRev)
1433 revPrevious = changedpath->lCopyFromRev;
1436 GitRev revSelected2;
1437 if (pos)
1439 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1440 revSelected2 = pLogEntry->Rev;
1442 bool bAllFromTheSameAuthor = true;
1443 CString firstAuthor;
1444 CLogDataVector selEntries;
1445 GitRev revLowest, revHighest;
1446 GitRevRangeArray revisionRanges;
1448 POSITION pos = GetFirstSelectedItemPosition();
1449 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1450 revisionRanges.AddRevision(pLogEntry->Rev);
1451 selEntries.push_back(pLogEntry);
1452 firstAuthor = pLogEntry->sAuthor;
1453 revLowest = pLogEntry->Rev;
1454 revHighest = pLogEntry->Rev;
1455 while (pos)
1457 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1458 revisionRanges.AddRevision(pLogEntry->Rev);
1459 selEntries.push_back(pLogEntry);
1460 if (firstAuthor.Compare(pLogEntry->sAuthor))
1461 bAllFromTheSameAuthor = false;
1462 revLowest = (git_revnum_t(pLogEntry->Rev) > git_revnum_t(revLowest) ? revLowest : pLogEntry->Rev);
1463 revHighest = (git_revnum_t(pLogEntry->Rev) < git_revnum_t(revHighest) ? revHighest : pLogEntry->Rev);
1467 #endif
1469 int FirstSelect=-1, LastSelect=-1;
1470 pos = GetFirstSelectedItemPosition();
1471 FirstSelect = GetNextSelectedItem(pos);
1472 while(pos)
1474 LastSelect = GetNextSelectedItem(pos);
1476 //entry is selected, now show the popup menu
1477 CIconMenu popup;
1478 CIconMenu subbranchmenu, submenu, gnudiffmenu,diffmenu;
1480 if (popup.CreatePopupMenu())
1482 bool isHeadCommit = (pSelLogEntry->m_CommitHash == m_HeadHash);
1484 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_PICK))
1485 popup.AppendMenuIcon(ID_REBASE_PICK, IDS_REBASE_PICK, IDI_PICK);
1487 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_SQUASH))
1488 popup.AppendMenuIcon(ID_REBASE_SQUASH, IDS_REBASE_SQUASH, IDI_SQUASH);
1490 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_EDIT))
1491 popup.AppendMenuIcon(ID_REBASE_EDIT, IDS_REBASE_EDIT, IDI_EDIT);
1493 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_SKIP))
1494 popup.AppendMenuIcon(ID_REBASE_SKIP, IDS_REBASE_SKIP, IDI_SKIP);
1496 if(m_ContextMenuMask&(GetContextMenuBit(ID_REBASE_SKIP)|GetContextMenuBit(ID_REBASE_EDIT)|
1497 GetContextMenuBit(ID_REBASE_SQUASH)|GetContextMenuBit(ID_REBASE_PICK)))
1498 popup.AppendMenu(MF_SEPARATOR, NULL);
1500 if (GetSelectedCount() == 1)
1504 if( !pSelLogEntry->m_CommitHash.IsEmpty())
1506 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARE))
1507 popup.AppendMenuIcon(ID_COMPARE, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1508 // TODO:
1509 // TortoiseMerge could be improved to take a /blame switch
1510 // and then not 'cat' the files from a unified diff but
1511 // blame then.
1512 // But until that's implemented, the context menu entry for
1513 // this feature is commented out.
1514 //popup.AppendMenu(ID_BLAMECOMPARE, IDS_LOG_POPUP_BLAMECOMPARE, IDI_BLAME);
1516 else
1518 if(m_ContextMenuMask&GetContextMenuBit(ID_COMMIT))
1519 popup.AppendMenuIcon(ID_COMMIT, IDS_LOG_POPUP_COMMIT, IDI_COMMIT);
1521 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF1))
1523 GitRev *pRev=pSelLogEntry;
1524 if(pSelLogEntry->m_ParentHash.size()==0)
1526 pRev->GetParentFromHash(pRev->m_CommitHash);
1528 if(pRev->m_ParentHash.size()<=1)
1530 popup.AppendMenuIcon(ID_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF_CH, IDI_DIFF);
1533 else
1535 gnudiffmenu.CreatePopupMenu();
1536 popup.AppendMenuIcon(ID_GNUDIFF1,IDS_LOG_POPUP_GNUDIFF_PARENT, IDI_DIFF, gnudiffmenu.m_hMenu);
1538 gnudiffmenu.AppendMenuIcon(ID_GNUDIFF1+(0xFFFF<<16),_T("All Parents"));
1539 gnudiffmenu.AppendMenuIcon(ID_GNUDIFF1+(0xFFFE<<16),_T("Only Merged Files"));
1541 for(int i=0;i<pRev->m_ParentHash.size();i++)
1543 CString str;
1544 str.Format(_T("Parent %d"), i+1);
1545 gnudiffmenu.AppendMenuIcon(ID_GNUDIFF1+((i+1)<<16),str);
1550 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPAREWITHPREVIOUS))
1553 GitRev *pRev=pSelLogEntry;
1554 if(pSelLogEntry->m_ParentHash.size()==0)
1556 pRev->GetParentFromHash(pRev->m_CommitHash);
1558 if(pRev->m_ParentHash.size()<=1)
1560 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF);
1561 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1562 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
1564 else
1566 diffmenu.CreatePopupMenu();
1567 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF, diffmenu.m_hMenu);
1568 for(int i=0;i<pRev->m_ParentHash.size();i++)
1570 CString str;
1571 str.Format(_T("Parent %d"), i+1);
1572 diffmenu.AppendMenuIcon(ID_COMPAREWITHPREVIOUS +((i+1)<<16),str);
1573 if (i == 0 && CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1575 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
1576 diffmenu.SetDefaultItem(ID_COMPAREWITHPREVIOUS +((i+1)<<16), FALSE);
1582 if(m_ContextMenuMask&GetContextMenuBit(ID_BLAME))
1583 popup.AppendMenuIcon(ID_BLAME, IDS_LOG_POPUP_BLAME, IDI_BLAME);
1585 //popup.AppendMenuIcon(ID_BLAMEWITHPREVIOUS, IDS_LOG_POPUP_BLAMEWITHPREVIOUS, IDI_BLAME);
1586 popup.AppendMenu(MF_SEPARATOR, NULL);
1589 // if (!m_ProjectProperties.sWebViewerRev.IsEmpty())
1590 // {
1591 // popup.AppendMenuIcon(ID_VIEWREV, IDS_LOG_POPUP_VIEWREV);
1592 // }
1593 // if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
1594 // {
1595 // popup.AppendMenuIcon(ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
1596 // }
1597 // if ((!m_ProjectProperties.sWebViewerPathRev.IsEmpty())||
1598 // (!m_ProjectProperties.sWebViewerRev.IsEmpty()))
1599 // {
1600 // popup.AppendMenu(MF_SEPARATOR, NULL);
1601 // }
1603 CString str,format;
1604 //if (m_hasWC)
1605 // popup.AppendMenuIcon(ID_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
1607 if(!pSelLogEntry->m_CommitHash.IsEmpty())
1609 if((m_ContextMenuMask&GetContextMenuBit(ID_LOG)) &&
1610 GetSelectedCount() == 1)
1611 popup.AppendMenuIcon(ID_LOG, IDS_LOG_POPUP_LOG, IDI_LOG);
1613 format.LoadString(IDS_LOG_POPUP_MERGEREV);
1614 str.Format(format,g_Git.GetCurrentBranch());
1616 bool thisbranch = false;
1617 CString currentBranch = _T("refs/heads/")+g_Git.GetCurrentBranch();
1618 for(int i=0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); i++)
1620 if (m_HashMap[pSelLogEntry->m_CommitHash][i] == currentBranch)
1621 thisbranch = true;
1622 break;
1625 if (m_ContextMenuMask&GetContextMenuBit(ID_MERGEREV) && !isHeadCommit)
1626 popup.AppendMenuIcon(ID_MERGEREV, str, IDI_MERGE);
1628 format.LoadString(IDS_RESET_TO_THIS_FORMAT);
1629 str.Format(format,g_Git.GetCurrentBranch());
1631 if(m_ContextMenuMask&GetContextMenuBit(ID_RESET))
1632 popup.AppendMenuIcon(ID_RESET,str,IDI_REVERT);
1635 // Add Switch Branch express Menu
1636 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end()
1637 && (m_ContextMenuMask&GetContextMenuBit(ID_SWITCHBRANCH))
1640 std::vector<CString *> branchs;
1641 CString ref;
1643 for(int i=0;i<m_HashMap[pSelLogEntry->m_CommitHash].size();i++)
1645 ref = m_HashMap[pSelLogEntry->m_CommitHash][i];
1646 if(ref.Find(_T("refs/heads/")) == 0 && ref != currentBranch)
1648 branchs.push_back(&m_HashMap[pSelLogEntry->m_CommitHash][i]);
1652 CString str;
1653 str.LoadString(IDS_SWITCH_BRANCH);
1655 if(branchs.size() == 1)
1657 str+=_T(" ");
1658 str+= _T('"') + branchs[0]->Mid(11) + _T('"');
1659 popup.AppendMenuIcon(ID_SWITCHBRANCH,str,IDI_SWITCH);
1661 popup.SetMenuItemData(ID_SWITCHBRANCH,(ULONG_PTR)branchs[0]);
1664 else if(branchs.size() > 1)
1666 subbranchmenu.CreatePopupMenu();
1667 for(int i=0;i<branchs.size();i++)
1669 if (*branchs[i] != currentBranch)
1671 subbranchmenu.AppendMenuIcon(ID_SWITCHBRANCH+(i<<16), branchs[i]->Mid(11));
1672 subbranchmenu.SetMenuItemData(ID_SWITCHBRANCH+(i<<16), (ULONG_PTR) branchs[i]);
1676 popup.AppendMenuIcon(ID_SWITCHBRANCH, str, IDI_SWITCH, subbranchmenu.m_hMenu);
1680 if(m_ContextMenuMask&GetContextMenuBit(ID_SWITCHTOREV) && !isHeadCommit)
1681 popup.AppendMenuIcon(ID_SWITCHTOREV, IDS_SWITCH_TO_THIS , IDI_SWITCH);
1683 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_BRANCH))
1684 popup.AppendMenuIcon(ID_CREATE_BRANCH, IDS_CREATE_BRANCH_AT_THIS , IDI_COPY);
1686 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_TAG))
1687 popup.AppendMenuIcon(ID_CREATE_TAG,IDS_CREATE_TAG_AT_THIS , IDI_TAG);
1689 format.LoadString(IDS_REBASE_THIS_FORMAT);
1690 str.Format(format,g_Git.GetCurrentBranch());
1692 if(pSelLogEntry->m_CommitHash != m_HeadHash)
1693 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_TO_VERSION))
1694 popup.AppendMenuIcon(ID_REBASE_TO_VERSION, str , IDI_REBASE);
1696 if(m_ContextMenuMask&GetContextMenuBit(ID_EXPORT))
1697 popup.AppendMenuIcon(ID_EXPORT,IDS_EXPORT_TO_THIS, IDI_EXPORT);
1699 if (m_ContextMenuMask&GetContextMenuBit(ID_REVERTREV))
1700 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT);
1702 if (m_ContextMenuMask&GetContextMenuBit(ID_EDITNOTE))
1703 popup.AppendMenuIcon(ID_EDITNOTE, IDS_EDIT_NOTES, IDI_EDIT);
1705 popup.AppendMenu(MF_SEPARATOR, NULL);
1710 if(!pSelLogEntry->m_Ref.IsEmpty() && GetSelectedCount() == 1)
1712 popup.AppendMenuIcon(ID_REFLOG_DEL, IDS_REFLOG_DEL, IDI_DELETE);
1713 popup.AppendMenuIcon(ID_STASH_APPLY, IDS_MENUSTASHAPPLY, IDI_RELOCATE);
1714 popup.AppendMenu(MF_SEPARATOR, NULL);
1717 if (GetSelectedCount() >= 2)
1719 bool bAddSeparator = false;
1720 if (IsSelectionContinuous() || (GetSelectedCount() == 2))
1722 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARETWO))
1723 popup.AppendMenuIcon(ID_COMPARETWO, IDS_LOG_POPUP_COMPARETWO, IDI_DIFF);
1726 if (GetSelectedCount() == 2)
1728 //popup.AppendMenuIcon(ID_BLAMETWO, IDS_LOG_POPUP_BLAMEREVS, IDI_BLAME);
1729 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF2))
1730 popup.AppendMenuIcon(ID_GNUDIFF2, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
1731 bAddSeparator = true;
1734 if (m_hasWC)
1736 //popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREVS, IDI_REVERT);
1737 // if (m_hasWC)
1738 // popup.AppendMenuIcon(ID_MERGEREV, IDS_LOG_POPUP_MERGEREVS, IDI_MERGE);
1739 bAddSeparator = true;
1742 if (m_ContextMenuMask&GetContextMenuBit(ID_REVERTREV))
1743 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREVS, IDI_REVERT);
1745 if (bAddSeparator)
1746 popup.AppendMenu(MF_SEPARATOR, NULL);
1749 if ( GetSelectedCount() >0 && (!pSelLogEntry->m_CommitHash.IsEmpty()))
1751 bool bAddSeparator = false;
1752 if ( IsSelectionContinuous() && GetSelectedCount() >= 2 )
1754 if(m_ContextMenuMask&GetContextMenuBit(ID_COMBINE_COMMIT))
1756 CString head;
1757 int headindex;
1758 headindex = this->GetHeadIndex();
1759 if(headindex>=0)
1761 head.Format(_T("HEAD~%d"),LastSelect-headindex);
1762 CGitHash hash=g_Git.GetHash(head);
1763 GitRev* pLastEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(LastSelect));
1764 if(pLastEntry->m_CommitHash == hash) {
1765 popup.AppendMenuIcon(ID_COMBINE_COMMIT,IDS_COMBINE_TO_ONE,IDI_COMBINE);
1766 bAddSeparator = true;
1771 if(m_ContextMenuMask&GetContextMenuBit(ID_CHERRY_PICK) && !isHeadCommit) {
1772 if (GetSelectedCount() >= 2)
1773 popup.AppendMenuIcon(ID_CHERRY_PICK, IDS_CHERRY_PICK_VERSIONS, IDI_EXPORT);
1774 else
1775 popup.AppendMenuIcon(ID_CHERRY_PICK, IDS_CHERRY_PICK_VERSION, IDI_EXPORT);
1776 bAddSeparator = true;
1779 if(GetSelectedCount()<=2 || (IsSelectionContinuous() && GetSelectedCount() > 0))
1780 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_PATCH)) {
1781 popup.AppendMenuIcon(ID_CREATE_PATCH, IDS_CREATE_PATCH, IDI_PATCH);
1782 bAddSeparator = true;
1785 if (bAddSeparator)
1786 popup.AppendMenu(MF_SEPARATOR, NULL);
1789 #if 0
1790 // if ((selEntries.size() > 0)&&(bAllFromTheSameAuthor))
1791 // {
1792 // popup.AppendMenuIcon(ID_EDITAUTHOR, IDS_LOG_POPUP_EDITAUTHOR);
1793 // }
1794 // if (GetSelectedCount() == 1)
1795 // {
1796 // popup.AppendMenuIcon(ID_EDITLOG, IDS_LOG_POPUP_EDITLOG);
1797 // popup.AppendMenuIcon(ID_REVPROPS, IDS_REPOBROWSE_SHOWREVPROP, IDI_PROPERTIES); // "Show Revision Properties"
1798 // popup.AppendMenu(MF_SEPARATOR, NULL);
1799 // }
1800 #endif
1802 if (GetSelectedCount() == 1)
1804 bool bAddSeparator = false;
1805 if(m_ContextMenuMask&GetContextMenuBit(ID_PUSH) && m_HashMap[pSelLogEntry->m_CommitHash].size() >= 1)
1807 // show the push-option only if the log entry has an associated local branch
1808 bool isLocal = false;
1809 for(int i=0; isLocal == false && i < m_HashMap[pSelLogEntry->m_CommitHash].size(); i++)
1811 if (m_HashMap[pSelLogEntry->m_CommitHash][i].Find(_T("refs/heads/")) == 0)
1812 isLocal = true;
1814 if (isLocal)
1816 popup.AppendMenuIcon(ID_PUSH, IDS_LOG_PUSH, IDI_PUSH);
1817 bAddSeparator = true;
1821 if(m_ContextMenuMask &GetContextMenuBit(ID_DELETE))
1823 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end() )
1825 CString str;
1826 if( m_HashMap[pSelLogEntry->m_CommitHash].size() == 1 )
1828 str.LoadString(IDS_DELETE_BRANCHTAG_SHORT);
1829 str+=_T(" ");
1830 str+=m_HashMap[pSelLogEntry->m_CommitHash].at(0);
1831 popup.AppendMenuIcon(ID_DELETE, str, IDI_DELETE);
1832 bAddSeparator = true;
1834 else if( m_HashMap[pSelLogEntry->m_CommitHash].size() > 1 )
1836 str.LoadString(IDS_DELETE_BRANCHTAG);
1837 submenu.CreatePopupMenu();
1838 for(int i=0;i<m_HashMap[pSelLogEntry->m_CommitHash].size();i++)
1840 submenu.AppendMenuIcon(ID_DELETE+(i<<16),m_HashMap[pSelLogEntry->m_CommitHash][i]);
1843 popup.AppendMenuIcon(ID_DELETE,str, IDI_DELETE, submenu.m_hMenu);
1844 bAddSeparator = true;
1847 } // m_ContextMenuMask &GetContextMenuBit(ID_DELETE)
1848 if (bAddSeparator)
1849 popup.AppendMenu(MF_SEPARATOR, NULL);
1850 } // GetSelectedCount() == 1
1852 if (GetSelectedCount() == 1)
1854 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYHASH))
1855 popup.AppendMenuIcon(ID_COPYHASH, IDS_COPY_COMMIT_HASH, IDI_COPYCLIP);
1857 if (GetSelectedCount() != 0)
1859 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYCLIPBOARD))
1860 popup.AppendMenuIcon(ID_COPYCLIPBOARD, IDS_LOG_POPUP_COPYTOCLIPBOARD, IDI_COPYCLIP);
1863 if(m_ContextMenuMask&GetContextMenuBit(ID_FINDENTRY))
1864 popup.AppendMenuIcon(ID_FINDENTRY, IDS_LOG_POPUP_FIND, IDI_FILTEREDIT);
1866 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
1867 // DialogEnableWindow(IDOK, FALSE);
1868 // SetPromptApp(&theApp);
1870 this->ContextMenuAction(cmd, FirstSelect, LastSelect, &popup);
1872 // EnableOKButton();
1873 } // if (popup.CreatePopupMenu())
1877 bool CGitLogListBase::IsSelectionContinuous()
1879 if ( GetSelectedCount()==1 )
1881 // if only one revision is selected, the selection is of course
1882 // continuous
1883 return true;
1886 POSITION pos = GetFirstSelectedItemPosition();
1887 bool bContinuous = (m_arShownList.GetCount() == (INT_PTR)m_logEntries.size());
1888 if (bContinuous)
1890 int itemindex = GetNextSelectedItem(pos);
1891 while (pos)
1893 int nextindex = GetNextSelectedItem(pos);
1894 if (nextindex - itemindex > 1)
1896 bContinuous = false;
1897 break;
1899 itemindex = nextindex;
1902 return bContinuous;
1905 void CGitLogListBase::CopySelectionToClipBoard(bool HashOnly)
1908 CString sClipdata;
1909 POSITION pos = GetFirstSelectedItemPosition();
1910 if (pos != NULL)
1912 CString sRev;
1913 sRev.LoadString(IDS_LOG_REVISION);
1914 CString sAuthor;
1915 sAuthor.LoadString(IDS_LOG_AUTHOR);
1916 CString sDate;
1917 sDate.LoadString(IDS_LOG_DATE);
1918 CString sMessage;
1919 sMessage.LoadString(IDS_LOG_MESSAGE);
1920 while (pos)
1922 CString sLogCopyText;
1923 CString sPaths;
1924 GitRev * pLogEntry = reinterpret_cast<GitRev *>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1926 if(!HashOnly)
1928 //pLogEntry->GetFiles(this)
1929 //LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
1931 for (int cpPathIndex = 0; cpPathIndex<pLogEntry->GetFiles(this).GetCount(); ++cpPathIndex)
1933 sPaths += ((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetActionName() + _T(" : ") + pLogEntry->GetFiles(this)[cpPathIndex].GetGitPathString();
1934 sPaths += _T("\r\n");
1936 sPaths.Trim();
1937 CString body = pLogEntry->GetBody();
1938 body.Replace(_T("\n"), _T("\r\n"));
1939 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"),
1940 (LPCTSTR)sRev, pLogEntry->m_CommitHash.ToString(),
1941 (LPCTSTR)sAuthor, (LPCTSTR)pLogEntry->GetAuthorName(),
1942 (LPCTSTR)sDate,
1943 (LPCTSTR)CAppUtils::FormatDateAndTime( pLogEntry->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes ),
1944 (LPCTSTR)sMessage, pLogEntry->GetSubject().Trim() + _T("\r\n\r\n") + body.Trim(),
1945 (LPCTSTR)sPaths);
1946 sClipdata += sLogCopyText;
1948 else
1950 sClipdata += pLogEntry->m_CommitHash;
1951 break;
1955 CStringUtils::WriteAsciiStringToClipboard(sClipdata, GetSafeHwnd());
1960 void CGitLogListBase::DiffSelectedRevWithPrevious()
1962 if (m_bThreadRunning)
1963 return;
1965 int FirstSelect=-1, LastSelect=-1;
1966 POSITION pos = GetFirstSelectedItemPosition();
1967 FirstSelect = GetNextSelectedItem(pos);
1968 while(pos)
1970 LastSelect = GetNextSelectedItem(pos);
1973 ContextMenuAction(ID_COMPAREWITHPREVIOUS,FirstSelect,LastSelect, NULL);
1975 #if 0
1976 UpdateLogInfoLabel();
1977 int selIndex = m_LogList.GetSelectionMark();
1978 if (selIndex < 0)
1979 return;
1980 int selCount = m_LogList.GetSelectedCount();
1981 if (selCount != 1)
1982 return;
1984 // Find selected entry in the log list
1985 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
1986 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
1987 long rev1 = pLogEntry->Rev;
1988 long rev2 = rev1-1;
1989 CTGitPath path = m_path;
1991 // See how many files under the relative root were changed in selected revision
1992 int nChanged = 0;
1993 LogChangedPath * changed = NULL;
1994 for (INT_PTR c = 0; c < pLogEntry->pArChangedPaths->GetCount(); ++c)
1996 LogChangedPath * cpath = pLogEntry->pArChangedPaths->SafeGetAt(c);
1997 if (cpath && cpath -> sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
1999 ++nChanged;
2000 changed = cpath;
2004 if (m_path.IsDirectory() && nChanged == 1)
2006 // We're looking at the log for a directory and only one file under dir was changed in the revision
2007 // Do diff on that file instead of whole directory
2008 path.AppendPathString(changed->sPath.Mid(m_sRelativeRoot.GetLength()));
2011 m_bCancelled = FALSE;
2012 DialogEnableWindow(IDOK, FALSE);
2013 SetPromptApp(&theApp);
2014 theApp.DoWaitCursor(1);
2016 if (PromptShown())
2018 GitDiff diff(this, m_hWnd, true);
2019 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
2020 diff.SetHEADPeg(m_LogRevision);
2021 diff.ShowCompare(path, rev2, path, rev1);
2023 else
2025 CAppUtils::StartShowCompare(m_hWnd, path, rev2, path, rev1, GitRev(), m_LogRevision, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
2028 theApp.DoWaitCursor(-1);
2029 EnableOKButton();
2030 #endif
2033 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR *pNMHDR, LRESULT *pResult)
2035 LPNMLVFINDITEM pFindInfo = reinterpret_cast<LPNMLVFINDITEM>(pNMHDR);
2036 *pResult = -1;
2038 if (pFindInfo->lvfi.flags & LVFI_PARAM)
2039 return;
2040 if ((pFindInfo->iStart < 0)||(pFindInfo->iStart >= m_arShownList.GetCount()))
2041 return;
2042 if (pFindInfo->lvfi.psz == 0)
2043 return;
2044 #if 0
2045 CString sCmp = pFindInfo->lvfi.psz;
2046 CString sRev;
2047 for (int i=pFindInfo->iStart; i<m_arShownList.GetCount(); ++i)
2049 GitRev * pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(i));
2050 sRev.Format(_T("%ld"), pLogEntry->Rev);
2051 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
2053 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
2055 *pResult = i;
2056 return;
2059 else
2061 if (sCmp.Compare(sRev)==0)
2063 *pResult = i;
2064 return;
2068 if (pFindInfo->lvfi.flags & LVFI_WRAP)
2070 for (int i=0; i<pFindInfo->iStart; ++i)
2072 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(i));
2073 sRev.Format(_T("%ld"), pLogEntry->Rev);
2074 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
2076 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
2078 *pResult = i;
2079 return;
2082 else
2084 if (sCmp.Compare(sRev)==0)
2086 *pResult = i;
2087 return;
2092 #endif
2093 *pResult = -1;
2096 int CGitLogListBase::FillGitLog(CTGitPath *path,int info,CString *from,CString *to)
2098 ClearText();
2101 this->m_arShownList.SafeRemoveAll();
2103 this->m_logEntries.ClearAll();
2104 this->m_logEntries.ParserFromLog(path,-1,info,from,to);
2106 //this->m_logEntries.ParserFromLog();
2107 SetItemCountEx(this->m_logEntries.size());
2109 for(unsigned int i=0;i<m_logEntries.size();i++)
2111 if(m_IsOldFirst)
2113 m_logEntries.GetGitRevAt(m_logEntries.size()-i-1).m_IsFull=TRUE;
2114 this->m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size()-i-1));
2117 else
2119 m_logEntries.GetGitRevAt(i).m_IsFull=TRUE;
2120 this->m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
2124 if(path)
2125 m_Path=*path;
2126 return 0;
2130 int CGitLogListBase::BeginFetchLog()
2132 ClearText();
2134 this->m_arShownList.SafeRemoveAll();
2136 this->m_logEntries.ClearAll();
2137 git_init();
2139 this->m_LogCache.ClearAllParent();
2141 m_LogCache.FetchCacheIndex(g_Git.m_CurrentDir);
2143 CTGitPath *path;
2144 if(this->m_Path.IsEmpty())
2145 path=NULL;
2146 else
2147 path=&this->m_Path;
2149 CString hash;
2150 int mask;
2151 mask = CGit::LOG_INFO_ONLY_HASH | CGit::LOG_INFO_BOUNDARY;
2152 // if(this->m_bAllBranch)
2153 mask |= m_ShowMask ;
2155 if(m_bShowWC)
2157 this->m_logEntries.insert(m_logEntries.begin(),this->m_wcRev.m_CommitHash);
2158 ResetWcRev();
2159 this->m_LogCache.m_HashMap[m_wcRev.m_CommitHash]=m_wcRev;
2162 CString *pFrom, *pTo;
2163 pFrom = pTo = NULL;
2164 CString head(_T("HEAD"));
2165 if(!this->m_startrev.IsEmpty())
2167 pFrom = &this->m_startrev;
2168 if(!this->m_endrev.IsEmpty())
2169 pTo = &this->m_endrev;
2170 else
2171 pTo = &head;
2174 CFilterData data;
2175 data.m_From = m_From;
2176 data.m_To =m_To;
2178 #if 0 /* use tortoiegit filter */
2179 if(this->m_nSelectedFilter == LOGFILTER_ALL || m_nSelectedFilter == LOGFILTER_AUTHORS)
2180 data.m_Author = this->m_sFilterText;
2182 if(this->m_nSelectedFilter == LOGFILTER_ALL || m_nSelectedFilter == LOGFILTER_MESSAGES)
2183 data.m_MessageFilter = this->m_sFilterText;
2185 data.m_IsRegex = m_bFilterWithRegex;
2186 #endif
2188 CString cmd=g_Git.GetLogCmd(m_StartRef,path,-1,mask,pFrom,pTo,true,&data);
2190 //this->m_logEntries.ParserFromLog();
2191 if(IsInWorkingThread())
2193 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL);
2195 else
2197 SetItemCountEx(this->m_logEntries.size());
2200 git_init();
2202 if(g_Git.IsInitRepos())
2203 return 0;
2205 if(git_open_log(&m_DllGitLog,CUnicodeUtils::GetMulti(cmd,CP_ACP).GetBuffer()))
2207 return -1;
2210 return 0;
2213 BOOL CGitLogListBase::PreTranslateMessage(MSG* pMsg)
2215 if (pMsg->message == WM_KEYDOWN && pMsg->wParam=='\r')
2217 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))
2219 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
2221 DiffSelectedRevWithPrevious();
2222 return TRUE;
2225 #if 0
2226 if (GetFocus()==GetDlgItem(IDC_LOGMSG))
2228 DiffSelectedFile();
2229 return TRUE;
2231 #endif
2233 else if (pMsg->message == WM_KEYDOWN && pMsg->wParam == 'A' && GetAsyncKeyState(VK_CONTROL)&0x8000)
2235 // select all entries
2236 for (int i=0; i<GetItemCount(); ++i)
2238 SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
2240 return TRUE;
2243 #if 0
2244 if (m_hAccel && !bSkipAccelerator)
2246 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
2247 if (ret)
2248 return TRUE;
2251 #endif
2252 //m_tooltips.RelayEvent(pMsg);
2253 return __super::PreTranslateMessage(pMsg);
2256 void CGitLogListBase::OnNMDblclkLoglist(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2258 // a double click on an entry in the revision list has happened
2259 *pResult = 0;
2261 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
2262 DiffSelectedRevWithPrevious();
2265 int CGitLogListBase::FetchLogAsync(void * data)
2267 m_ProcData=data;
2268 m_bExitThread=FALSE;
2269 InterlockedExchange(&m_bThreadRunning, TRUE);
2270 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2271 m_LoadingThread = AfxBeginThread(LogThreadEntry, this, THREAD_PRIORITY_LOWEST);
2272 if (m_LoadingThread ==NULL)
2274 InterlockedExchange(&m_bThreadRunning, FALSE);
2275 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2276 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
2277 return -1;
2279 return 0;
2282 //this is the thread function which calls the subversion function
2283 UINT CGitLogListBase::LogThreadEntry(LPVOID pVoid)
2285 return ((CGitLogListBase*)pVoid)->LogThread();
2288 void CGitLogListBase::GetTimeRange(CTime &oldest, CTime &latest)
2290 //CTime time;
2291 oldest=CTime::GetCurrentTime();
2292 latest=CTime(1971,1,2,0,0,0);
2293 for(unsigned int i=0;i<m_logEntries.size();i++)
2295 if(m_logEntries[i].IsEmpty())
2296 continue;
2298 if(m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime() < oldest.GetTime())
2299 oldest = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
2301 if(m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime() > latest.GetTime())
2302 latest = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
2306 if(latest<oldest)
2307 latest=oldest;
2310 UINT CGitLogListBase::LogThread()
2312 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_START,0);
2314 InterlockedExchange(&m_bThreadRunning, TRUE);
2315 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2317 ULONGLONG t1,t2;
2319 if(BeginFetchLog())
2321 InterlockedExchange(&m_bThreadRunning, FALSE);
2322 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2324 return -1;
2327 tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
2328 bool bRegex = false;
2329 if (m_bFilterWithRegex)
2330 bRegex = ValidateRegexp(m_sFilterText, pat, false);
2332 TRACE(_T("\n===Begin===\n"));
2333 //Update work copy item;
2335 if( m_logEntries.size() > 0)
2337 GitRev *pRev = &m_logEntries.GetGitRevAt(0);
2339 m_arShownList.SafeAdd(pRev);
2343 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2345 // store commit number of the last selected commit/line before the refresh or -1
2346 int lastSelectedHashNItem = -1;
2348 if(!g_Git.IsInitRepos())
2350 g_Git.m_critGitDllSec.Lock();
2351 git_get_log_firstcommit(m_DllGitLog);
2352 int total = git_get_log_estimate_commit_count(m_DllGitLog);
2353 g_Git.m_critGitDllSec.Unlock();
2355 GIT_COMMIT commit;
2356 t2=t1=GetTickCount();
2357 int oldprecentage = 0;
2358 int oldsize=m_logEntries.size();
2359 int ret=0;
2360 while( ret== 0)
2362 g_Git.m_critGitDllSec.Lock();
2363 ret = git_get_log_nextcommit(this->m_DllGitLog, &commit, 0);
2364 g_Git.m_critGitDllSec.Unlock();
2366 if(ret)
2367 break;
2369 //printf("%s\r\n",commit.GetSubject());
2370 if(m_bExitThread)
2371 break;
2373 CGitHash hash = (char*)commit.m_hash ;
2375 GitRev *pRev = m_LogCache.GetCacheData(hash);
2376 pRev->m_GitCommit = commit;
2377 InterlockedExchange(&pRev->m_IsCommitParsed, FALSE);
2379 char *note=NULL;
2380 g_Git.m_critGitDllSec.Lock();
2381 git_get_notes(commit.m_hash,&note);
2382 g_Git.m_critGitDllSec.Unlock();
2384 if(note)
2386 pRev->m_Notes.Empty();
2387 g_Git.StringAppend(&pRev->m_Notes,(BYTE*)note);
2390 if(!pRev->m_IsDiffFiles)
2392 pRev->m_CallDiffAsync = DiffAsync;
2395 pRev->ParserParentFromCommit(&commit);
2397 #ifdef DEBUG
2398 pRev->DbgPrint();
2399 TRACE(_T("\n"));
2400 #endif
2402 if(!m_sFilterText.IsEmpty())
2404 if(!IsMatchFilter(bRegex,pRev,pat))
2405 continue;
2407 this->m_critSec.Lock();
2408 m_logEntries.push_back(hash);
2409 m_arShownList.SafeAdd(pRev);
2410 this->m_critSec.Unlock();
2412 if (lastSelectedHashNItem == -1 && hash == m_lastSelectedHash)
2413 lastSelectedHashNItem = m_arShownList.GetCount() - 1;
2415 t2=GetTickCount();
2417 if(t2-t1>500 || (m_logEntries.size()-oldsize >100))
2419 //update UI
2420 int percent=m_logEntries.size()*100/total + GITLOG_START+1;
2421 if(percent > 99)
2422 percent =99;
2423 if(percent < GITLOG_START)
2424 percent = GITLOG_START +1;
2426 oldsize = m_logEntries.size();
2427 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
2429 //if( percent > oldprecentage )
2431 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) percent,0);
2432 oldprecentage = percent;
2434 t1 = t2;
2437 g_Git.m_critGitDllSec.Lock();
2438 git_close_log(m_DllGitLog);
2439 g_Git.m_critGitDllSec.Unlock();
2443 // restore last selected item
2444 if (lastSelectedHashNItem >= 0)
2446 SetItemState(lastSelectedHashNItem, LVIS_SELECTED, LVIS_SELECTED);
2447 EnsureVisible(lastSelectedHashNItem, FALSE);
2450 //Update UI;
2451 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
2452 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_END,0);
2454 InterlockedExchange(&m_bThreadRunning, FALSE);
2456 return 0;
2459 void CGitLogListBase::Refresh(BOOL IsCleanFilter)
2461 SafeTerminateThread();
2463 this->SetItemCountEx(0);
2464 this->Clear();
2466 ResetWcRev();
2468 //Update branch and Tag info
2469 ReloadHashMap();
2470 //Assume Thread have exited
2471 //if(!m_bThreadRunning)
2473 m_logEntries.clear();
2475 if(IsCleanFilter)
2477 m_sFilterText.Empty();
2478 m_From=-1;
2479 m_To=-1;
2482 InterlockedExchange(&m_bExitThread,FALSE);
2484 InterlockedExchange(&m_bThreadRunning, TRUE);
2485 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2486 if ( (m_LoadingThread=AfxBeginThread(LogThreadEntry, this)) ==NULL)
2488 InterlockedExchange(&m_bThreadRunning, FALSE);
2489 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2490 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
2494 bool CGitLogListBase::ValidateRegexp(LPCTSTR regexp_str, tr1::wregex& pat, bool bMatchCase /* = false */)
2498 tr1::regex_constants::syntax_option_type type = tr1::regex_constants::ECMAScript;
2499 if (!bMatchCase)
2500 type |= tr1::regex_constants::icase;
2501 pat = tr1::wregex(regexp_str, type);
2502 return true;
2504 catch (exception) {}
2505 return false;
2507 BOOL CGitLogListBase::IsMatchFilter(bool bRegex, GitRev *pRev, tr1::wregex &pat)
2510 tr1::regex_constants::match_flag_type flags = tr1::regex_constants::match_any;
2511 CString sRev;
2513 if ((bRegex)&&(m_bFilterWithRegex))
2515 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
2517 if(this->m_bShowBugtraqColumn)
2519 CString sBugIds = m_ProjectProperties.FindBugID(pRev->GetSubject());
2521 ATLTRACE(_T("bugID = \"%s\"\n"), sBugIds);
2522 if (regex_search(wstring(sBugIds), pat, flags))
2524 return TRUE;
2529 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_SUBJECT)||(m_nSelectedFilter == LOGFILTER_MESSAGES))
2531 ATLTRACE(_T("messge = \"%s\"\n"), pRev->GetSubject());
2532 if (regex_search(wstring((LPCTSTR)pRev->GetSubject()), pat, flags))
2534 return TRUE;
2538 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_MESSAGES))
2540 ATLTRACE(_T("messge = \"%s\"\n"),pRev->GetBody());
2541 if (regex_search(wstring((LPCTSTR)pRev->GetBody()), pat, flags))
2543 return TRUE;
2547 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_AUTHORS))
2549 if (regex_search(wstring(pRev->GetAuthorName()), pat, flags))
2551 return TRUE;
2554 if (regex_search(wstring(pRev->GetCommitterName()), pat, flags))
2556 return TRUE;
2560 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_REVS))
2562 sRev.Format(_T("%s"), pRev->m_CommitHash.ToString());
2563 if (regex_search(wstring((LPCTSTR)sRev), pat, flags))
2565 return TRUE;
2569 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_PATHS))
2571 CTGitPathList *pathList=NULL;
2572 if( pRev->m_IsDiffFiles)
2573 pathList = &pRev->GetFiles(this);
2574 else
2576 if(!pRev->m_IsSimpleListReady)
2577 pRev->SafeGetSimpleList(&g_Git);
2580 if(pathList)
2581 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList->GetCount(); ++cpPathIndex)
2583 if (regex_search(wstring((LPCTSTR)pathList->m_paths.at(cpPathIndex).GetGitOldPathString()), pat, flags))
2585 return true;
2587 if (regex_search(wstring((LPCTSTR)pathList->m_paths.at(cpPathIndex).GetGitPathString()), pat, flags))
2589 return true;
2593 for(INT_PTR i=0;i<pRev->m_SimpleFileList.size();i++)
2595 if (regex_search(wstring((LPCTSTR)pRev->m_SimpleFileList[i]), pat, flags))
2597 return true;
2602 else
2604 CString find = m_sFilterText;
2605 find.MakeLower();
2607 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
2609 if(this->m_bShowBugtraqColumn)
2611 CString sBugIds = m_ProjectProperties.FindBugID(pRev->GetSubject());
2613 sBugIds.MakeLower();
2614 if ((sBugIds.Find(find) >= 0))
2616 return TRUE;
2621 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_SUBJECT)||(m_nSelectedFilter == LOGFILTER_MESSAGES))
2623 CString msg = pRev->GetSubject();
2625 msg = msg.MakeLower();
2626 if ((msg.Find(find) >= 0))
2628 return TRUE;
2632 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_MESSAGES))
2634 CString msg = pRev->GetBody();
2636 msg = msg.MakeLower();
2637 if ((msg.Find(find) >= 0))
2639 return TRUE;
2643 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_AUTHORS))
2645 CString msg = pRev->GetAuthorName();
2646 msg = msg.MakeLower();
2647 if ((msg.Find(find) >= 0))
2649 return TRUE;
2653 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_REVS))
2655 sRev.Format(_T("%s"), pRev->m_CommitHash.ToString());
2656 if ((sRev.Find(find) >= 0))
2658 return TRUE;
2662 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_PATHS))
2664 CTGitPathList *pathList=NULL;
2665 if( pRev->m_IsDiffFiles)
2666 pathList = &pRev->GetFiles(this);
2667 else
2669 if(!pRev->m_IsSimpleListReady)
2670 pRev->SafeGetSimpleList(&g_Git);
2672 if(pathList)
2673 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList->GetCount() ; ++cpPathIndex)
2675 CTGitPath *cpath = &pathList->m_paths.at(cpPathIndex);
2676 CString path = cpath->GetGitOldPathString();
2677 path.MakeLower();
2678 if ((path.Find(find)>=0))
2680 return true;
2682 path = cpath->GetGitPathString();
2683 path.MakeLower();
2684 if ((path.Find(find)>=0))
2686 return true;
2690 for (INT_PTR i=0;i<pRev->m_SimpleFileList.size();i++)
2692 CString path = pRev->m_SimpleFileList[i];
2693 path.MakeLower();
2694 if ((path.Find(find)>=0))
2696 return true;
2700 } // else (from if (bRegex))
2701 return FALSE;
2705 void CGitLogListBase::RecalculateShownList(CThreadSafePtrArray * pShownlist)
2708 pShownlist->SafeRemoveAll();
2710 tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
2711 bool bRegex = false;
2712 if (m_bFilterWithRegex)
2713 bRegex = ValidateRegexp(m_sFilterText, pat, false);
2715 tr1::regex_constants::match_flag_type flags = tr1::regex_constants::match_any;
2716 CString sRev;
2717 for (DWORD i=0; i<m_logEntries.size(); ++i)
2719 if ((bRegex)&&(m_bFilterWithRegex))
2721 #if 0
2722 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
2724 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR)m_logEntries[i]->sBugIDs);
2725 if (regex_search(wstring((LPCTSTR)m_logEntries[i]->sBugIDs), pat, flags)&&IsEntryInDateRange(i))
2727 pShownlist->SafeAdd(m_logEntries[i]);
2728 continue;
2731 #endif
2732 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_SUBJECT)||(m_nSelectedFilter == LOGFILTER_MESSAGES))
2734 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).GetSubject());
2735 if (regex_search(wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetSubject()), pat, flags)&&IsEntryInDateRange(i))
2737 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2738 continue;
2741 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_MESSAGES))
2743 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).GetBody());
2744 if (regex_search(wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetBody()), pat, flags)&&IsEntryInDateRange(i))
2746 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2747 continue;
2750 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_PATHS))
2752 CTGitPathList pathList = m_logEntries.GetGitRevAt(i).GetFiles(this);
2754 bool bGoing = true;
2755 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList.GetCount() && bGoing; ++cpPathIndex)
2757 CTGitPath cpath = pathList[cpPathIndex];
2758 if (regex_search(wstring((LPCTSTR)cpath.GetGitOldPathString()), pat, flags)&&IsEntryInDateRange(i))
2760 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2761 bGoing = false;
2762 continue;
2764 if (regex_search(wstring((LPCTSTR)cpath.GetGitPathString()), pat, flags)&&IsEntryInDateRange(i))
2766 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2767 bGoing = false;
2768 continue;
2770 if (regex_search(wstring((LPCTSTR)cpath.GetActionName()), pat, flags)&&IsEntryInDateRange(i))
2772 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2773 bGoing = false;
2774 continue;
2778 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_AUTHORS))
2780 if (regex_search(wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetAuthorName()), pat, flags)&&IsEntryInDateRange(i))
2782 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2783 continue;
2786 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_REVS))
2788 sRev.Format(_T("%s"), m_logEntries.GetGitRevAt(i).m_CommitHash.ToString());
2789 if (regex_search(wstring((LPCTSTR)sRev), pat, flags)&&IsEntryInDateRange(i))
2791 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2792 continue;
2795 } // if (bRegex)
2796 else
2798 CString find = m_sFilterText;
2799 find.MakeLower();
2800 #if 0
2801 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
2803 CString sBugIDs = m_logEntries[i]->sBugIDs;
2805 sBugIDs = sBugIDs.MakeLower();
2806 if ((sBugIDs.Find(find) >= 0)&&(IsEntryInDateRange(i)))
2808 pShownlist->SafeAdd(m_logEntries[i]);
2809 continue;
2812 #endif
2813 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_SUBJECT)||(m_nSelectedFilter == LOGFILTER_MESSAGES))
2815 CString msg = m_logEntries.GetGitRevAt(i).GetSubject();
2817 msg = msg.MakeLower();
2818 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
2820 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2821 continue;
2824 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_MESSAGES))
2826 CString msg = m_logEntries.GetGitRevAt(i).GetBody();
2828 msg = msg.MakeLower();
2829 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
2831 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2832 continue;
2835 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_PATHS))
2837 CTGitPathList pathList = m_logEntries.GetGitRevAt(i).GetFiles(this);
2839 bool bGoing = true;
2840 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList.GetCount() && bGoing; ++cpPathIndex)
2842 CTGitPath cpath = pathList[cpPathIndex];
2843 CString path = cpath.GetGitOldPathString();
2844 path.MakeLower();
2845 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
2847 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2848 bGoing = false;
2849 continue;
2851 path = cpath.GetGitPathString();
2852 path.MakeLower();
2853 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
2855 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2856 bGoing = false;
2857 continue;
2859 path = cpath.GetActionName();
2860 path.MakeLower();
2861 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
2863 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2864 bGoing = false;
2865 continue;
2869 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_AUTHORS))
2871 CString msg = m_logEntries.GetGitRevAt(i).GetAuthorName();
2872 msg = msg.MakeLower();
2873 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
2875 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2876 continue;
2879 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_REVS))
2881 sRev.Format(_T("%s"), m_logEntries.GetGitRevAt(i).m_CommitHash.ToString());
2882 if ((sRev.Find(find) >= 0)&&(IsEntryInDateRange(i)))
2884 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2885 continue;
2888 } // else (from if (bRegex))
2889 } // for (DWORD i=0; i<m_logEntries.size(); ++i)
2893 BOOL CGitLogListBase::IsEntryInDateRange(int /*i*/)
2896 __time64_t time = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
2898 if(m_From == -1)
2899 if(m_To == -1)
2900 return true;
2901 else
2902 return time <= m_To;
2903 else
2904 if(m_To == -1)
2905 return time >= m_From;
2906 else
2907 return ((time >= m_From)&&(time <= m_To));
2909 return TRUE; /* git dll will filter time range */
2911 // return TRUE;
2913 void CGitLogListBase::StartFilter()
2915 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2916 RecalculateShownList(&m_arShownList);
2917 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2920 DeleteAllItems();
2921 SetItemCountEx(ShownCountWithStopped());
2922 RedrawItems(0, ShownCountWithStopped());
2923 Invalidate();
2926 void CGitLogListBase::RemoveFilter()
2929 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2931 m_arShownList.SafeRemoveAll();
2933 // reset the time filter too
2934 #if 0
2935 m_timFrom = (__time64_t(m_tFrom));
2936 m_timTo = (__time64_t(m_tTo));
2937 m_DateFrom.SetTime(&m_timFrom);
2938 m_DateTo.SetTime(&m_timTo);
2939 m_DateFrom.SetRange(&m_timFrom, &m_timTo);
2940 m_DateTo.SetRange(&m_timFrom, &m_timTo);
2941 #endif
2943 for (DWORD i=0; i<m_logEntries.size(); ++i)
2945 if(this->m_IsOldFirst)
2947 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size()-i-1));
2949 else
2951 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
2954 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
2955 DeleteAllItems();
2956 SetItemCountEx(ShownCountWithStopped());
2957 RedrawItems(0, ShownCountWithStopped());
2959 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2962 void CGitLogListBase::Clear()
2964 m_arShownList.SafeRemoveAll();
2965 DeleteAllItems();
2967 m_logEntries.ClearAll();
2971 void CGitLogListBase::OnDestroy()
2973 // save the column widths to the registry
2974 SaveColumnWidths();
2976 SafeTerminateThread();
2977 SafeTerminateAsyncDiffThread();
2979 int retry = 0;
2980 while(m_LogCache.SaveCache())
2982 if(retry > 5)
2983 break;
2984 Sleep(1000);
2986 retry++;
2988 //if(CMessageBox::Show(NULL,_T("Cannot Save Log Cache to Disk. To retry click yes. To give up click no."),_T("TortoiseGit"),
2989 // MB_YESNO) == IDNO)
2990 // break;
2993 CHintListCtrl::OnDestroy();
2996 LRESULT CGitLogListBase::OnLoad(WPARAM wParam,LPARAM lParam)
2998 UNREFERENCED_PARAMETER(lParam);
2999 CRect rect;
3000 int i=(int)wParam;
3001 this->GetItemRect(i,&rect,LVIR_BOUNDS);
3002 this->InvalidateRect(rect);
3004 return 0;
3008 * Save column widths to the registry
3010 void CGitLogListBase::SaveColumnWidths()
3012 int maxcol = m_ColumnManager.GetColumnCount();
3014 for (int col = 0; col < maxcol; col++)
3015 if (m_ColumnManager.IsVisible (col))
3016 m_ColumnManager.ColumnResized (col);
3018 m_ColumnManager.WriteSettings();
3021 int CGitLogListBase::GetHeadIndex()
3023 if(m_HeadHash.IsEmpty())
3024 return -1;
3026 for(int i=0;i<m_arShownList.GetCount();i++)
3028 GitRev *pRev = (GitRev*)m_arShownList[i];
3029 if(pRev)
3031 if(pRev->m_CommitHash.ToString() == m_HeadHash )
3032 return i;
3035 return -1;
3037 void CGitLogListBase::OnFind()
3039 if (!m_pFindDialog)
3041 m_pFindDialog = new CFindDlg(this);
3042 m_pFindDialog->Create(this);
3045 void CGitLogListBase::OnHdnBegintrack(NMHDR *pNMHDR, LRESULT *pResult)
3047 m_ColumnManager.OnHdnBegintrack(pNMHDR, pResult);
3049 void CGitLogListBase::OnHdnItemchanging(NMHDR *pNMHDR, LRESULT *pResult)
3051 if(!m_ColumnManager.OnHdnItemchanging(pNMHDR, pResult))
3052 Default();
3054 LRESULT CGitLogListBase::OnFindDialogMessage(WPARAM /*wParam*/, LPARAM /*lParam*/)
3057 ASSERT(m_pFindDialog != NULL);
3058 bool bFound = false;
3059 int i=0;
3061 if (m_pFindDialog->IsTerminating())
3063 // invalidate the handle identifying the dialog box.
3064 m_pFindDialog = NULL;
3065 return 0;
3068 if(m_pFindDialog->IsRef())
3070 CString str;
3071 str=m_pFindDialog->GetFindString();
3073 CGitHash hash;
3075 if(!str.IsEmpty())
3076 hash = g_Git.GetHash(str);
3078 if(!hash.IsEmpty())
3080 for (i = 0; i<m_arShownList.GetCount(); i++)
3082 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(i);
3083 if(pLogEntry && pLogEntry->m_CommitHash == hash)
3085 bFound = true;
3086 break;
3093 if(m_pFindDialog->FindNext())
3095 //read data from dialog
3096 CString FindText = m_pFindDialog->GetFindString();
3097 bool bMatchCase = (m_pFindDialog->MatchCase() == TRUE);
3099 tr1::wregex pat;
3100 bool bRegex = ValidateRegexp(FindText, pat, bMatchCase);
3102 tr1::regex_constants::match_flag_type flags = tr1::regex_constants::match_not_null;
3105 for (i = this->m_nSearchIndex; i<m_arShownList.GetCount()&&!bFound; i++)
3107 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(i);
3109 CString str;
3110 str+=pLogEntry->m_CommitHash.ToString();
3111 str+=_T("\n");
3113 for(int j=0;j<this->m_HashMap[pLogEntry->m_CommitHash].size();j++)
3115 str+=m_HashMap[pLogEntry->m_CommitHash][j];
3116 str+=_T("\n");
3119 str+=pLogEntry->GetAuthorEmail();
3120 str+=_T("\n");
3121 str+=pLogEntry->GetAuthorName();
3122 str+=_T("\n");
3123 str+=pLogEntry->GetBody();
3124 str+=_T("\n");
3125 str+=pLogEntry->GetCommitterEmail();
3126 str+=_T("\n");
3127 str+=pLogEntry->GetCommitterName();
3128 str+=_T("\n");
3129 str+=pLogEntry->GetSubject();
3130 str+=_T("\n");
3133 /*Because changed files list is loaded on demand when gui show,
3134 files will empty when files have not fetched.
3136 we can add it back by using one-way diff(with outnumber changed and rename detect.
3137 here just need changed filename list. one-way is much quicker.
3139 if(pLogEntry->m_IsFull)
3141 for(int i=0;i<pLogEntry->GetFiles(this).GetCount();i++)
3143 str+=pLogEntry->GetFiles(this)[i].GetWinPath();
3144 str+=_T("\n");
3145 str+=pLogEntry->GetFiles(this)[i].GetGitOldPathString();
3146 str+=_T("\n");
3149 else
3151 if(!pLogEntry->m_IsSimpleListReady)
3152 pLogEntry->SafeGetSimpleList(&g_Git);
3154 for(int i=0;i<pLogEntry->m_SimpleFileList.size();i++)
3156 str+=pLogEntry->m_SimpleFileList[i];
3157 str+=_T("\n");
3163 if (bRegex)
3165 if (regex_search(wstring(str), pat, flags))
3167 bFound = true;
3168 break;
3171 else
3173 if (bMatchCase)
3175 if (str.Find(FindText) >= 0)
3177 bFound = true;
3178 break;
3182 else
3184 CString msg = str;
3185 msg = msg.MakeLower();
3186 CString find = FindText.MakeLower();
3187 if (msg.Find(find) >= 0)
3189 bFound = TRUE;
3190 break;
3194 } // for (i = this->m_nSearchIndex; i<m_arShownList.GetItemCount()&&!bFound; i++)
3196 } // if(m_pFindDialog->FindNext())
3197 //UpdateLogInfoLabel();
3199 if (bFound)
3201 this->m_nSearchIndex = i;
3202 EnsureVisible(i, FALSE);
3203 SetItemState(GetSelectionMark(), 0, LVIS_SELECTED);
3204 SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
3205 SetSelectionMark(i);
3206 //FillLogMessageCtrl();
3207 UpdateData(FALSE);
3208 m_nSearchIndex++;
3209 if (m_nSearchIndex >= m_arShownList.GetCount())
3210 m_nSearchIndex = (int)m_arShownList.GetCount()-1;
3213 return 0;
3216 void CGitLogListBase::OnColumnResized(NMHDR *pNMHDR, LRESULT *pResult)
3218 m_ColumnManager.OnColumnResized(pNMHDR,pResult);
3220 *pResult = FALSE;
3223 void CGitLogListBase::OnColumnMoved(NMHDR *pNMHDR, LRESULT *pResult)
3225 m_ColumnManager.OnColumnMoved(pNMHDR, pResult);
3227 Invalidate(FALSE);