Use CAutoGeneralHandle
[TortoiseGit.git] / src / TortoiseProc / GitLogListBase.cpp
blobf35f2321902510d9ee1dd00613824f60f3d51e33
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2012 - TortoiseGit
4 // Copyright (C) 2005-2007 Marco Costalba
5 // Copyright (C) 2011-2012 - 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 "LoglistUtils.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_SelectedFilters(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)
81 , m_hasWC(true)
83 // use the default GUI font, create a copy of it and
84 // change the copy to BOLD (leave the rest of the font
85 // the same)
86 HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
87 LOGFONT lf = {0};
88 GetObject(hFont, sizeof(LOGFONT), &lf);
89 lf.lfWeight = FW_BOLD;
90 m_boldFont = CreateFontIndirect(&lf);
92 m_bShowBugtraqColumn=false;
94 m_IsIDReplaceAction=FALSE;
96 this->m_critSec.Init();
97 m_wcRev.m_CommitHash.Empty();
98 m_wcRev.GetSubject() = CString(MAKEINTRESOURCE(IDS_LOG_WORKINGDIRCHANGES));
99 m_wcRev.m_ParentHash.clear();
100 m_wcRev.m_Mark=_T('-');
101 m_wcRev.m_IsUpdateing=FALSE;
102 m_wcRev.m_IsFull = TRUE;
104 m_hModifiedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONMODIFIED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
105 m_hReplacedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONREPLACED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
106 m_hAddedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONADDED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
107 m_hDeletedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONDELETED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
108 m_hFetchIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONFETCHING), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
110 m_bFilterWithRegex = !!CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), TRUE);
112 g_Git.GetMapHashToFriendName(m_HashMap);
113 if (CTGitPath(g_Git.m_CurrentDir).HasAdminDir())
115 m_CurrentBranch=g_Git.GetCurrentBranch();
116 try {
117 m_HeadHash=g_Git.GetHash(_T("HEAD"));
119 catch (char* msg)
121 CString err(msg);
122 MessageBox(_T("Could not get HEAD hash. Quitting...\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
123 ExitProcess(1);
127 m_From=-1;;
128 m_To=-1;
130 m_ShowMask = 0;
131 m_LoadingThread = NULL;
133 InterlockedExchange(&m_bExitThread,FALSE);
134 m_IsOldFirst = FALSE;
135 m_IsRebaseReplaceGraph = FALSE;
138 for(int i=0;i<Lanes::COLORS_NUM;i++)
140 m_LineColors[i] = m_Colors.GetColor((CColors::Colors)(CColors::BranchLine1+i));
142 // get short/long datetime setting from registry
143 DWORD RegUseShortDateFormat = CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE);
144 if ( RegUseShortDateFormat )
146 m_DateFormat = DATE_SHORTDATE;
148 else
150 m_DateFormat = DATE_LONGDATE;
152 // get relative time display setting from registry
153 DWORD regRelativeTimes = CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE);
154 m_bRelativeTimes = (regRelativeTimes != 0);
155 m_ContextMenuMask = 0xFFFFFFFFFFFFFFFF;
157 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_PICK);
158 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_SQUASH);
159 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_EDIT);
160 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_SKIP);
161 m_ContextMenuMask &= ~GetContextMenuBit(ID_LOG);
162 m_ContextMenuMask &= ~GetContextMenuBit(ID_BLAME);
164 m_ColumnRegKey=_T("log");
166 m_AsyncThreadExit = FALSE;
167 m_AsyncDiffEvent = ::CreateEvent(NULL,FALSE,TRUE,NULL);
168 m_AsynDiffListLock.Init();
170 m_DiffingThread = AfxBeginThread(AsyncThread, this, THREAD_PRIORITY_BELOW_NORMAL);
171 if (m_DiffingThread ==NULL)
173 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
174 return;
179 int CGitLogListBase::AsyncDiffThread()
181 m_AsyncThreadExited = false;
182 while(!m_AsyncThreadExit)
184 ::WaitForSingleObject(m_AsyncDiffEvent, INFINITE);
186 GitRev *pRev = NULL;
187 while(!m_AsyncThreadExit && m_AsynDiffList.size() > 0)
189 m_AsynDiffListLock.Lock();
190 pRev = m_AsynDiffList.back();
191 m_AsynDiffList.pop_back();
192 m_AsynDiffListLock.Unlock();
194 if( pRev->m_CommitHash.IsEmpty() )
196 if(pRev->m_IsDiffFiles)
197 continue;
199 pRev->GetFiles(this).Clear();
200 pRev->m_ParentHash.clear();
201 pRev->m_ParentHash.push_back(m_HeadHash);
202 if(g_Git.IsInitRepos())
204 g_Git.GetInitAddList(pRev->GetFiles(this));
207 else
209 g_Git.GetCommitDiffList(pRev->m_CommitHash.ToString(),this->m_HeadHash.ToString(), pRev->GetFiles(this));
211 pRev->GetAction(this) = 0;
213 for(int j=0;j< pRev->GetFiles(this).GetCount();j++)
214 pRev->GetAction(this) |= pRev->GetFiles(this)[j].m_Action;
216 InterlockedExchange(&pRev->m_IsDiffFiles, TRUE);
217 InterlockedExchange(&pRev->m_IsFull, TRUE);
219 pRev->GetBody().Format(IDS_FILESCHANGES, pRev->GetFiles(this).GetCount());
220 ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)0,0);
221 this->GetParent()->PostMessage(WM_COMMAND, MSG_FETCHED_DIFF, 0);
224 if(!pRev->CheckAndDiff())
225 { // fetch change file list
226 for(int i=GetTopIndex(); !m_AsyncThreadExit && i <= GetTopIndex()+GetCountPerPage(); i++)
228 if(i < m_arShownList.GetCount())
230 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(i);
231 if(data->m_CommitHash == pRev->m_CommitHash)
233 ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)i,0);
234 break;
239 if(!m_AsyncThreadExit && GetSelectedCount() == 1)
241 POSITION pos = GetFirstSelectedItemPosition();
242 int nItem = GetNextSelectedItem(pos);
244 if(nItem>=0)
246 GitRev* data = (GitRev*)m_arShownList[nItem];
247 if(data)
248 if(data->m_CommitHash == pRev->m_CommitHash)
250 this->GetParent()->PostMessage(WM_COMMAND, MSG_FETCHED_DIFF, 0);
257 m_AsyncThreadExited = true;
258 return 0;
260 void CGitLogListBase::hideFromContextMenu(unsigned __int64 hideMask, bool exclusivelyShow)
262 if (exclusivelyShow)
264 m_ContextMenuMask &= hideMask;
266 else
268 m_ContextMenuMask &= ~hideMask;
272 CGitLogListBase::~CGitLogListBase()
274 InterlockedExchange(&m_bNoDispUpdates, TRUE);
275 this->m_arShownList.SafeRemoveAll();
277 DestroyIcon(m_hModifiedIcon);
278 DestroyIcon(m_hReplacedIcon);
279 DestroyIcon(m_hAddedIcon);
280 DestroyIcon(m_hDeletedIcon);
281 m_logEntries.ClearAll();
283 if (m_boldFont)
284 DeleteObject(m_boldFont);
286 if ( m_pStoreSelection )
288 delete m_pStoreSelection;
289 m_pStoreSelection = NULL;
292 SafeTerminateThread();
293 SafeTerminateAsyncDiffThread();
295 if(m_AsyncDiffEvent)
296 CloseHandle(m_AsyncDiffEvent);
300 BEGIN_MESSAGE_MAP(CGitLogListBase, CHintListCtrl)
301 ON_REGISTERED_MESSAGE(m_FindDialogMessage, OnFindDialogMessage)
302 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnNMCustomdrawLoglist)
303 ON_NOTIFY_REFLECT(LVN_GETDISPINFO, OnLvnGetdispinfoLoglist)
304 ON_WM_CONTEXTMENU()
305 ON_NOTIFY_REFLECT(NM_DBLCLK, OnNMDblclkLoglist)
306 ON_NOTIFY_REFLECT(LVN_ODFINDITEM,OnLvnOdfinditemLoglist)
307 ON_WM_CREATE()
308 ON_WM_DESTROY()
309 ON_MESSAGE(MSG_LOADED,OnLoad)
310 ON_WM_MEASUREITEM()
311 ON_WM_MEASUREITEM_REFLECT()
312 ON_NOTIFY(HDN_BEGINTRACKA, 0, OnHdnBegintrack)
313 ON_NOTIFY(HDN_BEGINTRACKW, 0, OnHdnBegintrack)
314 ON_NOTIFY(HDN_ITEMCHANGINGA, 0, OnHdnItemchanging)
315 ON_NOTIFY(HDN_ITEMCHANGINGW, 0, OnHdnItemchanging)
316 ON_NOTIFY(HDN_ENDTRACK, 0, OnColumnResized)
317 ON_NOTIFY(HDN_ENDDRAG, 0, OnColumnMoved)
318 END_MESSAGE_MAP()
320 void CGitLogListBase::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
322 //if (m_nRowHeight>0)
324 lpMeasureItemStruct->itemHeight = 50;
328 int CGitLogListBase:: OnCreate(LPCREATESTRUCT lpCreateStruct)
330 PreSubclassWindow();
331 return CHintListCtrl::OnCreate(lpCreateStruct);
334 void CGitLogListBase::PreSubclassWindow()
336 SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_SUBITEMIMAGES);
337 // load the icons for the action columns
338 // m_Theme.Open(m_hWnd, L"ListView");
339 SetWindowTheme(m_hWnd, L"Explorer", NULL);
340 CHintListCtrl::PreSubclassWindow();
343 void CGitLogListBase::InsertGitColumn()
345 CString temp;
347 CRegDWORD regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE);
348 DWORD exStyle = LVS_EX_HEADERDRAGDROP | LVS_EX_DOUBLEBUFFER | LVS_EX_INFOTIP | LVS_EX_SUBITEMIMAGES;
349 if (DWORD(regFullRowSelect))
350 exStyle |= LVS_EX_FULLROWSELECT;
351 SetExtendedStyle(exStyle);
353 UpdateProjectProperties();
355 static UINT normal[] =
357 IDS_LOG_GRAPH,
358 IDS_LOG_REBASE,
359 IDS_LOG_ID,
360 IDS_LOG_HASH,
361 IDS_LOG_ACTIONS,
362 IDS_LOG_MESSAGE,
363 IDS_LOG_AUTHOR,
364 IDS_LOG_DATE,
365 IDS_LOG_EMAIL,
366 IDS_LOG_COMMIT_NAME,
367 IDS_LOG_COMMIT_EMAIL,
368 IDS_LOG_COMMIT_DATE,
369 IDS_LOG_BUGIDS,
372 static int with[] =
374 ICONITEMBORDER+16*4,
375 ICONITEMBORDER+16*4,
376 ICONITEMBORDER+16*4,
377 ICONITEMBORDER+16*4,
378 ICONITEMBORDER+16*4,
379 LOGLIST_MESSAGE_MIN,
380 ICONITEMBORDER+16*4,
381 ICONITEMBORDER+16*4,
382 ICONITEMBORDER+16*4,
383 ICONITEMBORDER+16*4,
384 ICONITEMBORDER+16*4,
385 ICONITEMBORDER+16*4,
386 ICONITEMBORDER+16*4,
388 m_dwDefaultColumns = GIT_LOG_GRAPH|GIT_LOG_ACTIONS|GIT_LOG_MESSAGE|GIT_LOG_AUTHOR|GIT_LOG_DATE;
390 DWORD hideColumns = 0;
391 if(this->m_IsRebaseReplaceGraph)
393 hideColumns |= GIT_LOG_GRAPH;
394 m_dwDefaultColumns |= GIT_LOG_REBASE;
396 else
398 hideColumns |= GIT_LOG_REBASE;
401 if(this->m_IsIDReplaceAction)
403 hideColumns |= GIT_LOG_ACTIONS;
404 m_dwDefaultColumns |= GIT_LOG_ID;
405 m_dwDefaultColumns |= GIT_LOG_HASH;
407 else
409 hideColumns |= GIT_LOG_ID;
411 if(this->m_bShowBugtraqColumn)
413 m_dwDefaultColumns |= GIT_LOGLIST_BUG;
415 else
417 hideColumns |= GIT_LOGLIST_BUG;
419 SetRedraw(false);
421 m_ColumnManager.SetNames(normal, _countof(normal));
422 m_ColumnManager.ReadSettings(m_dwDefaultColumns, hideColumns, m_ColumnRegKey+_T("loglist"), _countof(normal), with);
424 SetRedraw(true);
429 * Resizes all columns in a list control to values in registry.
431 void CGitLogListBase::ResizeAllListCtrlCols()
433 // column max and min widths to allow
434 static const int nMinimumWidth = 10;
435 static const int nMaximumWidth = 1000;
436 CHeaderCtrl* pHdrCtrl = (CHeaderCtrl*)(GetDlgItem(0));
437 if (pHdrCtrl)
439 int numcols = pHdrCtrl->GetItemCount();
440 for (int col = 0; col < numcols; col++)
442 // get width for this col last time from registry
443 CString regentry;
444 regentry.Format( _T("Software\\TortoiseGit\\%s\\ColWidth%d"),m_ColumnRegKey, col);
445 CRegDWORD regwidth(regentry, 0);
446 int cx = regwidth;
447 if ( cx == 0 )
449 // no saved value, setup sensible defaults
450 if (col == this->LOGLIST_MESSAGE)
452 cx = LOGLIST_MESSAGE_MIN;
454 else
456 cx = ICONITEMBORDER+16*4;
459 if (cx < nMinimumWidth)
461 cx = nMinimumWidth;
463 else if (cx > nMaximumWidth)
465 cx = nMaximumWidth;
468 SetColumnWidth(col, cx);
475 BOOL CGitLogListBase::GetShortName(CString ref, CString &shortname,CString prefix)
477 //TRACE(_T("%s %s\r\n"),ref,prefix);
478 if(ref.Left(prefix.GetLength()) == prefix)
480 shortname = ref.Right(ref.GetLength()-prefix.GetLength());
481 if(shortname.Right(3)==_T("^{}"))
482 shortname=shortname.Left(shortname.GetLength()-3);
483 return TRUE;
485 return FALSE;
488 void CGitLogListBase::FillBackGround(HDC hdc, int Index,CRect &rect)
490 LVITEM rItem;
491 SecureZeroMemory(&rItem, sizeof(LVITEM));
492 rItem.mask = LVIF_STATE;
493 rItem.iItem = Index;
494 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
495 GetItem(&rItem);
497 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(Index);
498 HBRUSH brush = NULL;
500 if (!(rItem.state & LVIS_SELECTED))
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));
507 else if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
509 if (rItem.state & LVIS_SELECTED)
511 if (::GetFocus() == m_hWnd)
512 brush = ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT));
513 else
514 brush = ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE));
518 if (brush != NULL)
520 ::FillRect(hdc, &rect, brush);
521 ::DeleteObject(brush);
525 void CGitLogListBase::DrawTagBranch(HDC hdc,CRect &rect,INT_PTR index)
527 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(index);
528 CRect rt=rect;
529 LVITEM rItem;
530 SecureZeroMemory(&rItem, sizeof(LVITEM));
531 rItem.mask = LVIF_STATE;
532 rItem.iItem = index;
533 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
534 GetItem(&rItem);
536 CDC W_Dc;
537 W_Dc.Attach(hdc);
539 HTHEME hTheme = NULL;
540 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
541 hTheme = OpenThemeData(m_hWnd, L"Explorer::ListView;ListView");
543 for(unsigned int i=0;i<m_HashMap[data->m_CommitHash].size();i++)
545 CString str;
546 str=m_HashMap[data->m_CommitHash][i];
548 CString shortname;
549 HBRUSH brush = 0;
550 shortname = _T("");
551 COLORREF colRef = 0;
553 //Determine label color
554 if(GetShortName(str,shortname,_T("refs/heads/")))
556 if( shortname == m_CurrentBranch )
557 colRef = m_Colors.GetColor(CColors::CurrentBranch);
558 else
559 colRef = m_Colors.GetColor(CColors::LocalBranch);
562 else if(GetShortName(str,shortname,_T("refs/remotes/")))
564 colRef = m_Colors.GetColor(CColors::RemoteBranch);
566 else if(GetShortName(str,shortname,_T("refs/tags/")))
568 colRef = m_Colors.GetColor(CColors::Tag);
570 else if(GetShortName(str,shortname,_T("refs/stash")))
572 colRef = m_Colors.GetColor(CColors::Stash);
573 shortname=_T("stash");
575 else if(GetShortName(str,shortname,_T("refs/bisect/")))
577 if(shortname.Find(_T("good")) == 0)
579 colRef = m_Colors.GetColor(CColors::BisectGood);
580 shortname = _T("good");
583 if(shortname.Find(_T("bad")) == 0)
585 colRef = m_Colors.GetColor(CColors::BisectBad);
586 shortname = _T("bad");
590 //When row selected, ajust label color
591 if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
592 if (rItem.state & LVIS_SELECTED)
593 colRef = CColors::MixColors(colRef, ::GetSysColor(COLOR_HIGHLIGHT), 150);
595 brush = ::CreateSolidBrush(colRef);
597 if(!shortname.IsEmpty() && (rt.left<rect.right) )
599 SIZE size;
600 memset(&size,0,sizeof(SIZE));
601 GetTextExtentPoint32(hdc, shortname,shortname.GetLength(),&size);
603 rt.SetRect(rt.left,rt.top,rt.left+size.cx,rt.bottom);
604 rt.right+=8;
606 int textpos = DT_CENTER;
608 if(rt.right > rect.right)
610 rt.right = rect.right;
611 textpos =0;
614 //Fill interior of ref label
615 ::FillRect(hdc, &rt, brush);
617 //Draw edge of label
619 CRect rectEdge = rt;
621 W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef,100), m_Colors.Darken(colRef,100));
622 rectEdge.DeflateRect(1,1);
623 W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef,50), m_Colors.Darken(colRef,50));
625 //Draw text inside label
626 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
628 int txtState = LISS_NORMAL;
629 if (rItem.state & LVIS_SELECTED)
630 txtState = LISS_SELECTED;
632 DrawThemeText(hTheme,hdc, LVP_LISTITEM, txtState, shortname, -1, textpos | DT_SINGLELINE | DT_VCENTER, 0, &rt);
634 else
636 W_Dc.SetBkMode(TRANSPARENT);
637 if (rItem.state & LVIS_SELECTED)
639 COLORREF clrNew = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
640 COLORREF clrOld = ::SetTextColor(hdc,clrNew);
641 ::DrawText(hdc,shortname,shortname.GetLength(),&rt,textpos | DT_SINGLELINE | DT_VCENTER);
642 ::SetTextColor(hdc,clrOld);
644 else
646 ::DrawText(hdc,shortname,shortname.GetLength(),&rt,textpos | DT_SINGLELINE | DT_VCENTER);
650 //::MoveToEx(hdc,rt.left,rt.top,NULL);
651 //::LineTo(hdc,rt.right,rt.top);
652 //::LineTo(hdc,rt.right,rt.bottom);
653 //::LineTo(hdc,rt.left,rt.bottom);
654 //::LineTo(hdc,rt.left,rt.top);
656 rt.left=rt.right+1;
658 if(brush)
659 ::DeleteObject(brush);
661 rt.right=rect.right;
663 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
665 int txtState = LISS_NORMAL;
666 if (rItem.state & LVIS_SELECTED)
667 txtState = LISS_SELECTED;
669 DrawThemeText(hTheme,hdc, LVP_LISTITEM, txtState, data->GetSubject(), -1, DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER, 0, &rt);
671 else
673 if (rItem.state & LVIS_SELECTED)
675 COLORREF clrOld = ::SetTextColor(hdc,::GetSysColor(COLOR_HIGHLIGHTTEXT));
676 ::DrawText(hdc,data->GetSubject(),data->GetSubject().GetLength(),&rt,DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER);
677 ::SetTextColor(hdc,clrOld);
679 else
681 ::DrawText(hdc,data->GetSubject(),data->GetSubject().GetLength(),&rt,DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER);
685 if (hTheme)
686 CloseThemeData(hTheme);
688 W_Dc.Detach();
691 static COLORREF blend(const COLORREF& col1, const COLORREF& col2, int amount = 128) {
693 // Returns ((256 - amount)*col1 + amount*col2) / 256;
694 return RGB(((256 - amount)*GetRValue(col1) + amount*GetRValue(col2) ) / 256,
695 ((256 - amount)*GetGValue(col1) + amount*GetGValue(col2) ) / 256,
696 ((256 - amount)*GetBValue(col1) + amount*GetBValue(col2) ) / 256);
699 Gdiplus::Color GetGdiColor(COLORREF col)
701 return Gdiplus::Color(GetRValue(col),GetGValue(col),GetBValue(col));
703 void CGitLogListBase::paintGraphLane(HDC hdc, int laneHeight,int type, int x1, int x2,
704 const COLORREF& col,const COLORREF& activeColor, int top
707 int h = laneHeight / 2;
708 int m = (x1 + x2) / 2;
709 int r = (x2 - x1) / 3;
710 int d = 2 * r;
712 #define P_CENTER m , h+top
713 #define P_0 x2, h+top
714 #define P_90 m , 0+top-1
715 #define P_180 x1, h+top
716 #define P_270 m , 2 * h+top +1
717 #define R_CENTER m - r, h - r+top, d, d
720 #define DELTA_UR_B 2*(x1 - m), 2*h +top
721 #define DELTA_UR_E 0*16, 90*16 +top // -,
723 #define DELTA_DR_B 2*(x1 - m), 2*-h +top
724 #define DELTA_DR_E 270*16, 90*16 +top // -'
726 #define DELTA_UL_B 2*(x2 - m), 2*h +top
727 #define DELTA_UL_E 90*16, 90*16 +top // ,-
729 #define DELTA_DL_B 2*(x2 - m),2*-h +top
730 #define DELTA_DL_E 180*16, 90*16 // '-
732 #define CENTER_UR x1, 2*h, 225
733 #define CENTER_DR x1, 0 , 135
734 #define CENTER_UL x2, 2*h, 315
735 #define CENTER_DL x2, 0 , 45
738 Gdiplus::Graphics graphics( hdc );
740 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
742 // arc
743 switch (type) {
744 case Lanes::JOIN:
745 case Lanes::JOIN_R:
746 case Lanes::HEAD:
747 case Lanes::HEAD_R:
749 Gdiplus::LinearGradientBrush gradient(
750 Gdiplus::Point(x1-2, h+top-2),
751 Gdiplus::Point(P_270),
752 GetGdiColor(activeColor),GetGdiColor(col));
755 Gdiplus::Pen mypen(&gradient,2);
756 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
758 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
759 graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top+h-1, x2-x1,laneHeight,270,90);
760 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
762 break;
764 case Lanes::JOIN_L:
767 Gdiplus::LinearGradientBrush gradient(
768 Gdiplus::Point(P_270),
769 Gdiplus::Point(x2+1, h+top-1),
770 GetGdiColor(col),GetGdiColor(activeColor));
773 Gdiplus::Pen mypen(&gradient,2);
774 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
776 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
777 graphics.DrawArc(&mypen,x1+(x2-x1)/2,top+h-1, x2-x1,laneHeight,180,90);
778 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
781 break;
783 case Lanes::TAIL:
784 case Lanes::TAIL_R:
787 Gdiplus::LinearGradientBrush gradient(
788 Gdiplus::Point(x1-2, h+top-2),
789 Gdiplus::Point(P_90),
790 GetGdiColor(activeColor),GetGdiColor(col));
792 Gdiplus::Pen mypen(&gradient,2);
794 graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top-h-1, x2-x1,laneHeight,0,90);
796 #if 0
797 QConicalGradient gradient(CENTER_DR);
798 gradient.setColorAt(0.375, activeCol);
799 gradient.setColorAt(0.625, col);
800 myPen.setBrush(gradient);
801 p->setPen(myPen);
802 p->drawArc(P_CENTER, DELTA_DR);
803 #endif
804 break;
806 default:
807 break;
811 //static QPen myPen(Qt::black, 2); // fast path here
812 CPen pen;
813 pen.CreatePen(PS_SOLID,2,col);
814 //myPen.setColor(col);
815 HPEN oldpen=(HPEN)::SelectObject(hdc,(HPEN)pen);
817 Gdiplus::Pen myPen(GetGdiColor(col),2);
819 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
821 //p->setPen(myPen);
823 // vertical line
824 switch (type) {
825 case Lanes::ACTIVE:
826 case Lanes::NOT_ACTIVE:
827 case Lanes::MERGE_FORK:
828 case Lanes::MERGE_FORK_R:
829 case Lanes::MERGE_FORK_L:
830 case Lanes::JOIN:
831 case Lanes::JOIN_R:
832 case Lanes::JOIN_L:
833 case Lanes::CROSS:
834 //DrawLine(hdc,P_90,P_270);
835 graphics.DrawLine(&myPen,P_90,P_270);
836 //p->drawLine(P_90, P_270);
837 break;
838 case Lanes::HEAD_L:
839 case Lanes::BRANCH:
840 //DrawLine(hdc,P_CENTER,P_270);
841 graphics.DrawLine(&myPen,P_CENTER,P_270);
842 //p->drawLine(P_CENTER, P_270);
843 break;
844 case Lanes::TAIL_L:
845 case Lanes::INITIAL:
846 case Lanes::BOUNDARY:
847 case Lanes::BOUNDARY_C:
848 case Lanes::BOUNDARY_R:
849 case Lanes::BOUNDARY_L:
850 //DrawLine(hdc,P_90, P_CENTER);
851 graphics.DrawLine(&myPen,P_90,P_CENTER);
852 //p->drawLine(P_90, P_CENTER);
853 break;
854 default:
855 break;
858 myPen.SetColor(GetGdiColor(activeColor));
860 // horizontal line
861 switch (type) {
862 case Lanes::MERGE_FORK:
863 case Lanes::JOIN:
864 case Lanes::HEAD:
865 case Lanes::TAIL:
866 case Lanes::CROSS:
867 case Lanes::CROSS_EMPTY:
868 case Lanes::BOUNDARY_C:
869 //DrawLine(hdc,P_180,P_0);
870 graphics.DrawLine(&myPen,P_180,P_0);
871 //p->drawLine(P_180, P_0);
872 break;
873 case Lanes::MERGE_FORK_R:
874 case Lanes::BOUNDARY_R:
875 //DrawLine(hdc,P_180,P_CENTER);
876 graphics.DrawLine(&myPen,P_180,P_CENTER);
877 //p->drawLine(P_180, P_CENTER);
878 break;
879 case Lanes::MERGE_FORK_L:
880 case Lanes::HEAD_L:
881 case Lanes::TAIL_L:
882 case Lanes::BOUNDARY_L:
883 //DrawLine(hdc,P_CENTER,P_0);
884 graphics.DrawLine(&myPen,P_CENTER,P_0);
885 //p->drawLine(P_CENTER, P_0);
886 break;
887 default:
888 break;
891 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
893 CBrush brush;
894 brush.CreateSolidBrush(col);
895 HBRUSH oldbrush=(HBRUSH)::SelectObject(hdc,(HBRUSH)brush);
897 Gdiplus::SolidBrush myBrush(GetGdiColor(col));
898 // center symbol, e.g. rect or ellipse
899 switch (type) {
900 case Lanes::ACTIVE:
901 case Lanes::INITIAL:
902 case Lanes::BRANCH:
904 //p->setPen(Qt::NoPen);
905 //p->setBrush(col);
906 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
907 graphics.FillEllipse(&myBrush, R_CENTER);
908 //p->drawEllipse(R_CENTER);
909 break;
910 case Lanes::MERGE_FORK:
911 case Lanes::MERGE_FORK_R:
912 case Lanes::MERGE_FORK_L:
913 //p->setPen(Qt::NoPen);
914 //p->setBrush(col);
915 //p->drawRect(R_CENTER);
916 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
917 graphics.FillRectangle(&myBrush, R_CENTER);
918 break;
919 case Lanes::UNAPPLIED:
920 // Red minus sign
921 //p->setPen(Qt::NoPen);
922 //p->setBrush(Qt::red);
923 //p->drawRect(m - r, h - 1, d, 2);
924 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
925 graphics.FillRectangle(&myBrush,m-r,h-1,d,2);
926 break;
927 case Lanes::APPLIED:
928 // Green plus sign
929 //p->setPen(Qt::NoPen);
930 //p->setBrush(DARK_GREEN);
931 //p->drawRect(m - r, h - 1, d, 2);
932 //p->drawRect(m - 1, h - r, 2, d);
933 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
934 graphics.FillRectangle(&myBrush,m-r,h-1,d,2);
935 graphics.FillRectangle(&myBrush,m-1,h-r,2,d);
936 break;
937 case Lanes::BOUNDARY:
938 //p->setBrush(back);
939 //p->drawEllipse(R_CENTER);
940 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
941 graphics.DrawEllipse(&myPen, R_CENTER);
942 break;
943 case Lanes::BOUNDARY_C:
944 case Lanes::BOUNDARY_R:
945 case Lanes::BOUNDARY_L:
946 //p->setBrush(back);
947 //p->drawRect(R_CENTER);
948 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
949 graphics.FillRectangle(&myBrush,R_CENTER);
950 break;
951 default:
952 break;
955 ::SelectObject(hdc,oldpen);
956 ::SelectObject(hdc,oldbrush);
957 #undef P_CENTER
958 #undef P_0
959 #undef P_90
960 #undef P_180
961 #undef P_270
962 #undef R_CENTER
965 void CGitLogListBase::DrawGraph(HDC hdc,CRect &rect,INT_PTR index)
967 // TODO: unfinished
968 // return;
969 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(index);
970 if(data->m_CommitHash.IsEmpty())
971 return;
973 CRect rt=rect;
974 LVITEM rItem;
975 SecureZeroMemory(&rItem, sizeof(LVITEM));
976 rItem.mask = LVIF_STATE;
977 rItem.iItem = index;
978 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
979 GetItem(&rItem);
981 // p->translate(QPoint(opt.rect.left(), opt.rect.top()));
983 if (data->m_Lanes.size() == 0)
984 m_logEntries.setLane(data->m_CommitHash);
986 std::vector<int>& lanes=data->m_Lanes;
987 UINT laneNum = lanes.size();
988 UINT activeLane = 0;
989 for (UINT i = 0; i < laneNum; i++)
990 if (Lanes::isMerge(lanes[i])) {
991 activeLane = i;
992 break;
995 int x1 = 0, x2 = 0;
996 int maxWidth = rect.Width();
997 int lw = 3 * rect.Height() / 4; //laneWidth()
999 COLORREF activeColor = m_LineColors[activeLane % Lanes::COLORS_NUM];
1000 //if (opt.state & QStyle::State_Selected)
1001 // activeColor = blend(activeColor, opt.palette.highlightedText().color(), 208);
1003 for (unsigned int i = 0; i < laneNum && x2 < maxWidth; i++)
1006 x1 = x2;
1007 x2 += lw;
1009 int ln = lanes[i];
1010 if (ln == Lanes::EMPTY)
1011 continue;
1013 COLORREF color = i == activeLane ? activeColor : m_LineColors[i % Lanes::COLORS_NUM];
1014 paintGraphLane(hdc, rect.Height(),ln, x1+rect.left, x2+rect.left, color,activeColor, rect.top);
1017 #if 0
1018 for (UINT i = 0; i < laneNum && x2 < maxWidth; i++) {
1020 x1 = x2;
1021 x2 += lw;
1023 int ln = lanes[i];
1024 if (ln == Lanes::EMPTY)
1025 continue;
1027 UINT col = ( Lanes:: isHead(ln) ||Lanes:: isTail(ln) || Lanes::isJoin(ln)
1028 || ln ==Lanes:: CROSS_EMPTY) ? activeLane : i;
1030 if (ln == Lanes::CROSS)
1032 paintGraphLane(hdc, rect.Height(),Lanes::NOT_ACTIVE, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
1033 paintGraphLane(hdc, rect.Height(),Lanes::CROSS, x1, x2, m_LineColors[activeLane % Lanes::COLORS_NUM],rect.top);
1035 else
1036 paintGraphLane(hdc, rect.Height(),ln, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
1038 #endif
1042 void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1045 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
1046 // Take the default processing unless we set this to something else below.
1047 *pResult = CDRF_DODEFAULT;
1049 if (m_bNoDispUpdates)
1050 return;
1052 switch (pLVCD->nmcd.dwDrawStage)
1054 case CDDS_PREPAINT:
1056 *pResult = CDRF_NOTIFYITEMDRAW;
1057 return;
1059 break;
1060 case CDDS_ITEMPREPAINT:
1062 // This is the prepaint stage for an item. Here's where we set the
1063 // item's text color.
1065 // Tell Windows to send draw notifications for each subitem.
1066 *pResult = CDRF_NOTIFYSUBITEMDRAW;
1068 COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);
1070 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
1072 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1073 if (data)
1075 if (data->GetAction(this)& (CTGitPath::LOGACTIONS_REBASE_DONE| CTGitPath::LOGACTIONS_REBASE_SKIP) )
1076 crText = RGB(128,128,128);
1078 if(data->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_SQUASH)
1079 pLVCD->clrTextBk = RGB(156,156,156);
1080 else if(data->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_EDIT)
1081 pLVCD->clrTextBk = RGB(200,200,128);
1082 else
1083 pLVCD->clrTextBk = ::GetSysColor(COLOR_WINDOW);
1085 if(data->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_CURRENT)
1087 SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1088 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1091 if(data->m_CommitHash.ToString() == m_HeadHash)
1093 SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1094 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1097 // if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))
1098 // crText = GetSysColor(COLOR_GRAYTEXT);
1100 if (data->m_CommitHash.IsEmpty())
1102 //crText = GetSysColor(RGB(200,200,0));
1103 //SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1104 // We changed the font, so we're returning CDRF_NEWFONT. This
1105 // tells the control to recalculate the extent of the text.
1106 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1110 if (m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec)
1112 if (m_bStrictStopped)
1113 crText = GetSysColor(COLOR_GRAYTEXT);
1115 // Store the color back in the NMLVCUSTOMDRAW struct.
1116 pLVCD->clrText = crText;
1117 return;
1119 break;
1120 case CDDS_ITEMPREPAINT|CDDS_ITEM|CDDS_SUBITEM:
1122 if ((m_bStrictStopped)&&(m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec))
1124 pLVCD->nmcd.uItemState &= ~(CDIS_SELECTED|CDIS_FOCUS);
1127 if (pLVCD->iSubItem == LOGLIST_GRAPH && m_sFilterText.IsEmpty())
1129 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec && (!this->m_IsRebaseReplaceGraph) )
1131 CRect rect;
1132 GetSubItemRect(pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_LABEL, rect);
1134 //TRACE(_T("A Graphic left %d right %d\r\n"),rect.left,rect.right);
1135 FillBackGround(pLVCD->nmcd.hdc, (INT_PTR)pLVCD->nmcd.dwItemSpec,rect);
1137 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1138 if( !data ->m_CommitHash.IsEmpty())
1139 DrawGraph(pLVCD->nmcd.hdc,rect,pLVCD->nmcd.dwItemSpec);
1141 *pResult = CDRF_SKIPDEFAULT;
1142 return;
1146 if (pLVCD->iSubItem == LOGLIST_MESSAGE)
1148 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
1150 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1151 //if(!data->m_IsFull)
1153 //if(data->SafeFetchFullInfo(&g_Git))
1154 // this->Invalidate();
1155 //TRACE(_T("Update ... %d\r\n"),pLVCD->nmcd.dwItemSpec);
1158 if(m_HashMap[data->m_CommitHash].size()!=0)
1160 CRect rect;
1162 GetSubItemRect(pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
1164 FillBackGround(pLVCD->nmcd.hdc, (INT_PTR)pLVCD->nmcd.dwItemSpec,rect);
1165 DrawTagBranch(pLVCD->nmcd.hdc,rect,pLVCD->nmcd.dwItemSpec);
1167 *pResult = CDRF_SKIPDEFAULT;
1168 return;
1175 if (pLVCD->iSubItem == LOGLIST_ACTION)
1177 if(this->m_IsIDReplaceAction)
1179 *pResult = CDRF_DODEFAULT;
1180 return;
1182 *pResult = CDRF_DODEFAULT;
1184 if (m_arShownList.GetCount() <= (INT_PTR)pLVCD->nmcd.dwItemSpec)
1185 return;
1187 int nIcons = 0;
1188 int iconwidth = ::GetSystemMetrics(SM_CXSMICON);
1189 int iconheight = ::GetSystemMetrics(SM_CYSMICON);
1191 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec));
1192 CRect rect;
1193 GetSubItemRect(pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
1194 //TRACE(_T("Action left %d right %d\r\n"),rect.left,rect.right);
1195 // Get the selected state of the
1196 // item being drawn.
1198 // Fill the background if necessary
1199 FillBackGround(pLVCD->nmcd.hdc, (INT_PTR)pLVCD->nmcd.dwItemSpec,rect);
1201 // Draw the icon(s) into the compatible DC
1202 pLogEntry->GetAction(this);
1204 if (!pLogEntry->m_IsDiffFiles)
1205 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hFetchIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1207 if (pLogEntry->GetAction(this) & CTGitPath::LOGACTIONS_MODIFIED)
1208 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hModifiedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1209 nIcons++;
1211 if (pLogEntry->GetAction(this) & (CTGitPath::LOGACTIONS_ADDED|CTGitPath::LOGACTIONS_COPY) )
1212 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hAddedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1213 nIcons++;
1215 if (pLogEntry->GetAction(this) & CTGitPath::LOGACTIONS_DELETED)
1216 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hDeletedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1217 nIcons++;
1219 if (pLogEntry->GetAction(this) & CTGitPath::LOGACTIONS_REPLACED)
1220 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hReplacedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1221 nIcons++;
1222 *pResult = CDRF_SKIPDEFAULT;
1223 return;
1226 break;
1228 *pResult = CDRF_DODEFAULT;
1231 // CGitLogListBase message handlers
1233 void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1235 NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
1237 // Create a pointer to the item
1238 LV_ITEM* pItem = &(pDispInfo)->item;
1240 // Do the list need text information?
1241 if (!(pItem->mask & LVIF_TEXT))
1242 return;
1244 // By default, clear text buffer.
1245 lstrcpyn(pItem->pszText, _T(""), pItem->cchTextMax);
1247 bool bOutOfRange = pItem->iItem >= ShownCountWithStopped();
1249 *pResult = 0;
1250 if (m_bNoDispUpdates || bOutOfRange)
1251 return;
1253 // Which item number?
1254 int itemid = pItem->iItem;
1255 GitRev * pLogEntry = NULL;
1256 if (itemid < m_arShownList.GetCount())
1257 pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(pItem->iItem));
1259 CString temp;
1260 if(m_IsOldFirst)
1262 temp.Format(_T("%d"),pItem->iItem+1);
1265 else
1267 temp.Format(_T("%d"),m_arShownList.GetCount()-pItem->iItem);
1270 // Which column?
1271 switch (pItem->iSubItem)
1273 case this->LOGLIST_GRAPH: //Graphic
1274 break;
1275 case this->LOGLIST_REBASE:
1277 if(this->m_IsRebaseReplaceGraph)
1279 CTGitPath path;
1280 path.m_Action=pLogEntry->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_MODE_MASK;
1281 lstrcpyn(pItem->pszText,path.GetActionName(), pItem->cchTextMax);
1284 break;
1285 case this->LOGLIST_ACTION: //action -- no text in the column
1286 break;
1287 case this->LOGLIST_HASH:
1288 if(pLogEntry)
1289 lstrcpyn(pItem->pszText, pLogEntry->m_CommitHash.ToString(), pItem->cchTextMax);
1290 break;
1291 case this->LOGLIST_ID:
1292 if(this->m_IsIDReplaceAction)
1293 lstrcpyn(pItem->pszText, temp, pItem->cchTextMax);
1294 break;
1295 case this->LOGLIST_MESSAGE: //Message
1296 if (pLogEntry)
1297 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetSubject(), pItem->cchTextMax);
1298 break;
1299 case this->LOGLIST_AUTHOR: //Author
1300 if (pLogEntry)
1301 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetAuthorName(), pItem->cchTextMax);
1302 break;
1303 case this->LOGLIST_DATE: //Date
1304 if ( pLogEntry && (!pLogEntry->m_CommitHash.IsEmpty()) )
1305 lstrcpyn(pItem->pszText,
1306 CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
1307 pItem->cchTextMax);
1308 break;
1310 case this->LOGLIST_EMAIL:
1311 if (pLogEntry)
1312 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetAuthorEmail(), pItem->cchTextMax);
1313 break;
1315 case this->LOGLIST_COMMIT_NAME: //Commit
1316 if (pLogEntry)
1317 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetCommitterName(), pItem->cchTextMax);
1318 break;
1320 case this->LOGLIST_COMMIT_EMAIL: //Commit Email
1321 if (pLogEntry)
1322 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetCommitterEmail(), pItem->cchTextMax);
1323 break;
1325 case this->LOGLIST_COMMIT_DATE: //Commit Date
1326 if (pLogEntry && (!pLogEntry->m_CommitHash.IsEmpty()))
1327 lstrcpyn(pItem->pszText,
1328 CLoglistUtils::FormatDateAndTime(pLogEntry->GetCommitterDate(), m_DateFormat, true, m_bRelativeTimes),
1329 pItem->cchTextMax);
1330 break;
1331 case this->LOGLIST_BUG: //Bug ID
1332 if(pLogEntry)
1333 lstrcpyn(pItem->pszText, (LPCTSTR)this->m_ProjectProperties.FindBugID(pLogEntry->GetSubject() + _T("\r\n\r\n") + pLogEntry->GetBody()), pItem->cchTextMax);
1334 break;
1336 default:
1337 ASSERT(false);
1341 void CGitLogListBase::OnContextMenu(CWnd* pWnd, CPoint point)
1344 if (pWnd == GetHeaderCtrl())
1346 return m_ColumnManager.OnContextMenuHeader(pWnd,point,!!IsGroupViewEnabled());
1349 int selIndex = GetSelectionMark();
1350 if (selIndex < 0)
1351 return; // nothing selected, nothing to do with a context menu
1353 // if the user selected the info text telling about not all revisions shown due to
1354 // the "stop on copy/rename" option, we also don't show the context menu
1355 if ((m_bStrictStopped)&&(selIndex == m_arShownList.GetCount()))
1356 return;
1358 // if the context menu is invoked through the keyboard, we have to use
1359 // a calculated position on where to anchor the menu on
1360 if ((point.x == -1) && (point.y == -1))
1362 CRect rect;
1363 GetItemRect(selIndex, &rect, LVIR_LABEL);
1364 ClientToScreen(&rect);
1365 point = rect.CenterPoint();
1367 m_nSearchIndex = selIndex;
1368 m_bCancelled = FALSE;
1370 // calculate some information the context menu commands can use
1371 // CString pathURL = GetURLFromPath(m_path);
1373 POSITION pos = GetFirstSelectedItemPosition();
1374 int indexNext = GetNextSelectedItem(pos);
1375 if (indexNext < 0)
1376 return;
1378 GitRev* pSelLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(indexNext));
1379 #if 0
1380 GitRev revSelected = pSelLogEntry->Rev;
1381 GitRev revPrevious = git_revnum_t(revSelected)-1;
1382 if ((pSelLogEntry->pArChangedPaths)&&(pSelLogEntry->pArChangedPaths->GetCount() <= 2))
1384 for (int i=0; i<pSelLogEntry->pArChangedPaths->GetCount(); ++i)
1386 LogChangedPath * changedpath = (LogChangedPath *)pSelLogEntry->pArChangedPaths->SafeGetAt(i);
1387 if (changedpath->lCopyFromRev)
1388 revPrevious = changedpath->lCopyFromRev;
1391 GitRev revSelected2;
1392 if (pos)
1394 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1395 revSelected2 = pLogEntry->Rev;
1397 bool bAllFromTheSameAuthor = true;
1398 CString firstAuthor;
1399 CLogDataVector selEntries;
1400 GitRev revLowest, revHighest;
1401 GitRevRangeArray revisionRanges;
1403 POSITION pos = GetFirstSelectedItemPosition();
1404 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1405 revisionRanges.AddRevision(pLogEntry->Rev);
1406 selEntries.push_back(pLogEntry);
1407 firstAuthor = pLogEntry->sAuthor;
1408 revLowest = pLogEntry->Rev;
1409 revHighest = pLogEntry->Rev;
1410 while (pos)
1412 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1413 revisionRanges.AddRevision(pLogEntry->Rev);
1414 selEntries.push_back(pLogEntry);
1415 if (firstAuthor.Compare(pLogEntry->sAuthor))
1416 bAllFromTheSameAuthor = false;
1417 revLowest = (git_revnum_t(pLogEntry->Rev) > git_revnum_t(revLowest) ? revLowest : pLogEntry->Rev);
1418 revHighest = (git_revnum_t(pLogEntry->Rev) < git_revnum_t(revHighest) ? revHighest : pLogEntry->Rev);
1422 #endif
1424 int FirstSelect=-1, LastSelect=-1;
1425 pos = GetFirstSelectedItemPosition();
1426 FirstSelect = GetNextSelectedItem(pos);
1427 while(pos)
1429 LastSelect = GetNextSelectedItem(pos);
1431 //entry is selected, now show the popup menu
1432 CIconMenu popup;
1433 CIconMenu subbranchmenu, submenu, gnudiffmenu,diffmenu;
1435 if (popup.CreatePopupMenu())
1437 bool isHeadCommit = (pSelLogEntry->m_CommitHash == m_HeadHash);
1438 CString currentBranch = _T("refs/heads/") + g_Git.GetCurrentBranch();
1440 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_PICK))
1441 popup.AppendMenuIcon(ID_REBASE_PICK, IDS_REBASE_PICK, IDI_PICK);
1443 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_SQUASH))
1444 popup.AppendMenuIcon(ID_REBASE_SQUASH, IDS_REBASE_SQUASH, IDI_SQUASH);
1446 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_EDIT))
1447 popup.AppendMenuIcon(ID_REBASE_EDIT, IDS_REBASE_EDIT, IDI_EDIT);
1449 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_SKIP))
1450 popup.AppendMenuIcon(ID_REBASE_SKIP, IDS_REBASE_SKIP, IDI_SKIP);
1452 if(m_ContextMenuMask&(GetContextMenuBit(ID_REBASE_SKIP)|GetContextMenuBit(ID_REBASE_EDIT)|
1453 GetContextMenuBit(ID_REBASE_SQUASH)|GetContextMenuBit(ID_REBASE_PICK)))
1454 popup.AppendMenu(MF_SEPARATOR, NULL);
1456 if (GetSelectedCount() == 1)
1460 if( !pSelLogEntry->m_CommitHash.IsEmpty())
1462 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARE) && m_hasWC) // compare revision with WC
1463 popup.AppendMenuIcon(ID_COMPARE, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1465 else
1467 if(m_ContextMenuMask&GetContextMenuBit(ID_COMMIT))
1468 popup.AppendMenuIcon(ID_COMMIT, IDS_LOG_POPUP_COMMIT, IDI_COMMIT);
1470 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF1) && m_hasWC) // compare with WC, unified
1472 GitRev *pRev=pSelLogEntry;
1473 if(pSelLogEntry->m_ParentHash.size()==0)
1475 pRev->GetParentFromHash(pRev->m_CommitHash);
1477 if(pRev->m_ParentHash.size()<=1)
1479 popup.AppendMenuIcon(ID_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF_CH, IDI_DIFF);
1482 else
1484 gnudiffmenu.CreatePopupMenu();
1485 popup.AppendMenuIcon(ID_GNUDIFF1,IDS_LOG_POPUP_GNUDIFF_PARENT, IDI_DIFF, gnudiffmenu.m_hMenu);
1487 gnudiffmenu.AppendMenuIcon(ID_GNUDIFF1 + (0xFFFF << 16), CString(MAKEINTRESOURCE(IDS_ALLPARENTS)));
1488 gnudiffmenu.AppendMenuIcon(ID_GNUDIFF1 + (0xFFFE << 16), CString(MAKEINTRESOURCE(IDS_ONLYMERGEDFILES)));
1490 for(int i=0;i<pRev->m_ParentHash.size();i++)
1492 CString str;
1493 str.Format(IDS_PARENT, i + 1);
1494 gnudiffmenu.AppendMenuIcon(ID_GNUDIFF1+((i+1)<<16),str);
1499 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPAREWITHPREVIOUS))
1502 GitRev *pRev=pSelLogEntry;
1503 if(pSelLogEntry->m_ParentHash.size()==0)
1505 pRev->GetParentFromHash(pRev->m_CommitHash);
1507 if(pRev->m_ParentHash.size()<=1)
1509 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF);
1510 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1511 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
1513 else
1515 diffmenu.CreatePopupMenu();
1516 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF, diffmenu.m_hMenu);
1517 for(int i=0;i<pRev->m_ParentHash.size();i++)
1519 CString str;
1520 str.Format(IDS_PARENT, i + 1);
1521 diffmenu.AppendMenuIcon(ID_COMPAREWITHPREVIOUS +((i+1)<<16),str);
1522 if (i == 0 && CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1524 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
1525 diffmenu.SetDefaultItem(ID_COMPAREWITHPREVIOUS +((i+1)<<16), FALSE);
1531 if(m_ContextMenuMask&GetContextMenuBit(ID_BLAME))
1532 popup.AppendMenuIcon(ID_BLAME, IDS_LOG_POPUP_BLAME, IDI_BLAME);
1534 //popup.AppendMenuIcon(ID_BLAMEWITHPREVIOUS, IDS_LOG_POPUP_BLAMEWITHPREVIOUS, IDI_BLAME);
1535 popup.AppendMenu(MF_SEPARATOR, NULL);
1537 if (pSelLogEntry->m_CommitHash.IsEmpty())
1539 if(m_ContextMenuMask&GetContextMenuBit(ID_STASH_SAVE))
1540 popup.AppendMenuIcon(ID_STASH_SAVE, IDS_MENUSTASHSAVE, IDI_COMMIT);
1543 bool isStash = false;
1544 for (int i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); i++)
1546 if (m_HashMap[pSelLogEntry->m_CommitHash][i] == _T("refs/stash"))
1548 isStash = true;
1549 break;
1553 if (CTGitPath(g_Git.m_CurrentDir).HasStashDir() && (pSelLogEntry->m_CommitHash.IsEmpty() || isStash))
1555 if (m_ContextMenuMask&GetContextMenuBit(ID_STASH_POP))
1556 popup.AppendMenuIcon(ID_STASH_POP, IDS_MENUSTASHPOP, IDI_RELOCATE);
1558 if (m_ContextMenuMask&GetContextMenuBit(ID_STASH_LIST))
1559 popup.AppendMenuIcon(ID_STASH_LIST, IDS_MENUSTASHLIST, IDI_LOG);
1561 popup.AppendMenu(MF_SEPARATOR, NULL);
1564 if (pSelLogEntry->m_CommitHash.IsEmpty())
1566 if(m_ContextMenuMask&GetContextMenuBit(ID_FETCH))
1567 popup.AppendMenuIcon(ID_FETCH, IDS_MENUFETCH, IDI_PULL);
1569 popup.AppendMenu(MF_SEPARATOR, NULL);
1573 // if (!m_ProjectProperties.sWebViewerRev.IsEmpty())
1574 // {
1575 // popup.AppendMenuIcon(ID_VIEWREV, IDS_LOG_POPUP_VIEWREV);
1576 // }
1577 // if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
1578 // {
1579 // popup.AppendMenuIcon(ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
1580 // }
1581 // if ((!m_ProjectProperties.sWebViewerPathRev.IsEmpty())||
1582 // (!m_ProjectProperties.sWebViewerRev.IsEmpty()))
1583 // {
1584 // popup.AppendMenu(MF_SEPARATOR, NULL);
1585 // }
1587 CString str,format;
1588 //if (m_hasWC)
1589 // popup.AppendMenuIcon(ID_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
1591 if(!pSelLogEntry->m_CommitHash.IsEmpty())
1593 if((m_ContextMenuMask&GetContextMenuBit(ID_LOG)) &&
1594 GetSelectedCount() == 1)
1595 popup.AppendMenuIcon(ID_LOG, IDS_LOG_POPUP_LOG, IDI_LOG);
1597 if (m_ContextMenuMask&GetContextMenuBit(ID_REPOBROWSE))
1598 popup.AppendMenuIcon(ID_REPOBROWSE, IDS_LOG_BROWSEREPO, IDI_REPOBROWSE);
1600 format.LoadString(IDS_LOG_POPUP_MERGEREV);
1601 str.Format(format,g_Git.GetCurrentBranch());
1603 if (m_ContextMenuMask&GetContextMenuBit(ID_MERGEREV) && !isHeadCommit && m_hasWC)
1604 popup.AppendMenuIcon(ID_MERGEREV, str, IDI_MERGE);
1606 format.LoadString(IDS_RESET_TO_THIS_FORMAT);
1607 str.Format(format,g_Git.GetCurrentBranch());
1609 if(m_ContextMenuMask&GetContextMenuBit(ID_RESET) && m_hasWC)
1610 popup.AppendMenuIcon(ID_RESET,str,IDI_REVERT);
1613 // Add Switch Branch express Menu
1614 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end()
1615 && (m_ContextMenuMask&GetContextMenuBit(ID_SWITCHBRANCH) && m_hasWC)
1618 std::vector<CString *> branchs;
1619 for(int i=0;i<m_HashMap[pSelLogEntry->m_CommitHash].size();i++)
1621 CString ref = m_HashMap[pSelLogEntry->m_CommitHash][i];
1622 if(ref.Find(_T("refs/heads/")) == 0 && ref != currentBranch)
1624 branchs.push_back(&m_HashMap[pSelLogEntry->m_CommitHash][i]);
1628 CString str;
1629 str.LoadString(IDS_SWITCH_BRANCH);
1631 if(branchs.size() == 1)
1633 str+=_T(" ");
1634 str+= _T('"') + branchs[0]->Mid(11) + _T('"');
1635 popup.AppendMenuIcon(ID_SWITCHBRANCH,str,IDI_SWITCH);
1637 popup.SetMenuItemData(ID_SWITCHBRANCH,(ULONG_PTR)branchs[0]);
1640 else if(branchs.size() > 1)
1642 subbranchmenu.CreatePopupMenu();
1643 for(int i=0;i<branchs.size();i++)
1645 if (*branchs[i] != currentBranch)
1647 subbranchmenu.AppendMenuIcon(ID_SWITCHBRANCH+(i<<16), branchs[i]->Mid(11));
1648 subbranchmenu.SetMenuItemData(ID_SWITCHBRANCH+(i<<16), (ULONG_PTR) branchs[i]);
1652 popup.AppendMenuIcon(ID_SWITCHBRANCH, str, IDI_SWITCH, subbranchmenu.m_hMenu);
1656 if(m_ContextMenuMask&GetContextMenuBit(ID_SWITCHTOREV) && !isHeadCommit && m_hasWC)
1657 popup.AppendMenuIcon(ID_SWITCHTOREV, IDS_SWITCH_TO_THIS , IDI_SWITCH);
1659 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_BRANCH))
1660 popup.AppendMenuIcon(ID_CREATE_BRANCH, IDS_CREATE_BRANCH_AT_THIS , IDI_COPY);
1662 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_TAG))
1663 popup.AppendMenuIcon(ID_CREATE_TAG,IDS_CREATE_TAG_AT_THIS , IDI_TAG);
1665 format.LoadString(IDS_REBASE_THIS_FORMAT);
1666 str.Format(format,g_Git.GetCurrentBranch());
1668 if(pSelLogEntry->m_CommitHash != m_HeadHash && m_hasWC)
1669 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_TO_VERSION))
1670 popup.AppendMenuIcon(ID_REBASE_TO_VERSION, str , IDI_REBASE);
1672 if(m_ContextMenuMask&GetContextMenuBit(ID_EXPORT))
1673 popup.AppendMenuIcon(ID_EXPORT,IDS_EXPORT_TO_THIS, IDI_EXPORT);
1675 if (m_ContextMenuMask&GetContextMenuBit(ID_REVERTREV) && m_hasWC)
1676 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT);
1678 if (m_ContextMenuMask&GetContextMenuBit(ID_EDITNOTE))
1679 popup.AppendMenuIcon(ID_EDITNOTE, IDS_EDIT_NOTES, IDI_EDIT);
1681 popup.AppendMenu(MF_SEPARATOR, NULL);
1686 if(!pSelLogEntry->m_Ref.IsEmpty())
1688 popup.AppendMenuIcon(ID_REFLOG_DEL, IDS_REFLOG_DEL, IDI_DELETE);
1689 if (GetSelectedCount() == 1 && pSelLogEntry->m_Ref.Find(_T("refs/stash")) == 0)
1690 popup.AppendMenuIcon(ID_REFLOG_STASH_APPLY, IDS_MENUSTASHAPPLY, IDI_RELOCATE);
1691 popup.AppendMenu(MF_SEPARATOR, NULL);
1694 if (GetSelectedCount() >= 2)
1696 bool bAddSeparator = false;
1697 if (IsSelectionContinuous() || (GetSelectedCount() == 2))
1699 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARETWO)) // compare two revisions
1700 popup.AppendMenuIcon(ID_COMPARETWO, IDS_LOG_POPUP_COMPARETWO, IDI_DIFF);
1703 if (GetSelectedCount() == 2)
1705 //popup.AppendMenuIcon(ID_BLAMETWO, IDS_LOG_POPUP_BLAMEREVS, IDI_BLAME);
1706 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF2) && m_hasWC) // compare two revisions, unified
1707 popup.AppendMenuIcon(ID_GNUDIFF2, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
1708 bAddSeparator = true;
1711 if (m_hasWC)
1713 //popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREVS, IDI_REVERT);
1714 // if (m_hasWC)
1715 // popup.AppendMenuIcon(ID_MERGEREV, IDS_LOG_POPUP_MERGEREVS, IDI_MERGE);
1716 bAddSeparator = true;
1719 if (m_ContextMenuMask&GetContextMenuBit(ID_REVERTREV) && m_hasWC)
1720 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREVS, IDI_REVERT);
1722 if (bAddSeparator)
1723 popup.AppendMenu(MF_SEPARATOR, NULL);
1726 if ( GetSelectedCount() >0 && (!pSelLogEntry->m_CommitHash.IsEmpty()))
1728 bool bAddSeparator = false;
1729 if ( IsSelectionContinuous() && GetSelectedCount() >= 2 )
1731 if(m_ContextMenuMask&GetContextMenuBit(ID_COMBINE_COMMIT) && m_hasWC)
1733 CString head;
1734 int headindex;
1735 headindex = this->GetHeadIndex();
1736 if(headindex>=0)
1738 head.Format(_T("HEAD~%d"),LastSelect-headindex);
1739 CGitHash hash=g_Git.GetHash(head);
1740 GitRev* pLastEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(LastSelect));
1741 if(pLastEntry->m_CommitHash == hash) {
1742 popup.AppendMenuIcon(ID_COMBINE_COMMIT,IDS_COMBINE_TO_ONE,IDI_COMBINE);
1743 bAddSeparator = true;
1748 if(m_ContextMenuMask&GetContextMenuBit(ID_CHERRY_PICK) && !isHeadCommit && m_hasWC) {
1749 if (GetSelectedCount() >= 2)
1750 popup.AppendMenuIcon(ID_CHERRY_PICK, IDS_CHERRY_PICK_VERSIONS, IDI_EXPORT);
1751 else
1752 popup.AppendMenuIcon(ID_CHERRY_PICK, IDS_CHERRY_PICK_VERSION, IDI_EXPORT);
1753 bAddSeparator = true;
1756 if(GetSelectedCount()<=2 || (IsSelectionContinuous() && GetSelectedCount() > 0))
1757 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_PATCH)) {
1758 popup.AppendMenuIcon(ID_CREATE_PATCH, IDS_CREATE_PATCH, IDI_PATCH);
1759 bAddSeparator = true;
1762 if (bAddSeparator)
1763 popup.AppendMenu(MF_SEPARATOR, NULL);
1766 #if 0
1767 // if ((selEntries.size() > 0)&&(bAllFromTheSameAuthor))
1768 // {
1769 // popup.AppendMenuIcon(ID_EDITAUTHOR, IDS_LOG_POPUP_EDITAUTHOR);
1770 // }
1771 // if (GetSelectedCount() == 1)
1772 // {
1773 // popup.AppendMenuIcon(ID_EDITLOG, IDS_LOG_POPUP_EDITLOG);
1774 // popup.AppendMenuIcon(ID_REVPROPS, IDS_REPOBROWSE_SHOWREVPROP, IDI_PROPERTIES); // "Show Revision Properties"
1775 // popup.AppendMenu(MF_SEPARATOR, NULL);
1776 // }
1777 #endif
1779 if (GetSelectedCount() == 1)
1781 bool bAddSeparator = false;
1782 if(m_ContextMenuMask&GetContextMenuBit(ID_PUSH) && m_HashMap[pSelLogEntry->m_CommitHash].size() >= 1)
1784 // show the push-option only if the log entry has an associated local branch
1785 bool isLocal = false;
1786 for(int i=0; isLocal == false && i < m_HashMap[pSelLogEntry->m_CommitHash].size(); i++)
1788 if (m_HashMap[pSelLogEntry->m_CommitHash][i].Find(_T("refs/heads/")) == 0)
1789 isLocal = true;
1791 if (isLocal)
1793 popup.AppendMenuIcon(ID_PUSH, IDS_LOG_PUSH, IDI_PUSH);
1794 bAddSeparator = true;
1798 if(m_ContextMenuMask &GetContextMenuBit(ID_DELETE))
1800 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end() )
1802 std::vector<CString *> branchs;
1803 for (int i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); i++)
1805 if(m_HashMap[pSelLogEntry->m_CommitHash][i] != currentBranch)
1806 branchs.push_back(&m_HashMap[pSelLogEntry->m_CommitHash][i]);
1808 CString str;
1809 if (branchs.size() == 1)
1811 str.LoadString(IDS_DELETE_BRANCHTAG_SHORT);
1812 str+=_T(" ");
1813 str += *branchs[0];
1814 popup.AppendMenuIcon(ID_DELETE, str, IDI_DELETE);
1815 popup.SetMenuItemData(ID_DELETE, (ULONG_PTR)branchs[0]);
1816 bAddSeparator = true;
1818 else if (branchs.size() > 1)
1820 str.LoadString(IDS_DELETE_BRANCHTAG);
1821 submenu.CreatePopupMenu();
1822 for (int i = 0; i < branchs.size(); i++)
1824 submenu.AppendMenuIcon(ID_DELETE + (i << 16), *branchs[i]);
1825 submenu.SetMenuItemData(ID_DELETE + (i << 16), (ULONG_PTR)branchs[i]);
1828 popup.AppendMenuIcon(ID_DELETE,str, IDI_DELETE, submenu.m_hMenu);
1829 bAddSeparator = true;
1832 } // m_ContextMenuMask &GetContextMenuBit(ID_DELETE)
1833 if (bAddSeparator)
1834 popup.AppendMenu(MF_SEPARATOR, NULL);
1835 } // GetSelectedCount() == 1
1837 if (GetSelectedCount() == 1)
1839 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYHASH))
1840 popup.AppendMenuIcon(ID_COPYHASH, IDS_COPY_COMMIT_HASH, IDI_COPYCLIP);
1842 if (GetSelectedCount() != 0)
1844 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYCLIPBOARD))
1845 popup.AppendMenuIcon(ID_COPYCLIPBOARD, IDS_LOG_POPUP_COPYTOCLIPBOARD, IDI_COPYCLIP);
1848 if(m_ContextMenuMask&GetContextMenuBit(ID_FINDENTRY))
1849 popup.AppendMenuIcon(ID_FINDENTRY, IDS_LOG_POPUP_FIND, IDI_FILTEREDIT);
1851 if (GetSelectedCount() == 1 && m_ContextMenuMask & GetContextMenuBit(ID_SHOWBRANCHES) && !pSelLogEntry->m_CommitHash.IsEmpty())
1852 popup.AppendMenuIcon(ID_SHOWBRANCHES, IDS_LOG_POPUP_SHOWBRANCHES, IDI_SHOWBRANCHES);
1854 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
1855 // DialogEnableWindow(IDOK, FALSE);
1856 // SetPromptApp(&theApp);
1858 this->ContextMenuAction(cmd, FirstSelect, LastSelect, &popup);
1860 // EnableOKButton();
1861 } // if (popup.CreatePopupMenu())
1865 bool CGitLogListBase::IsSelectionContinuous()
1867 if ( GetSelectedCount()==1 )
1869 // if only one revision is selected, the selection is of course
1870 // continuous
1871 return true;
1874 POSITION pos = GetFirstSelectedItemPosition();
1875 bool bContinuous = (m_arShownList.GetCount() == (INT_PTR)m_logEntries.size());
1876 if (bContinuous)
1878 int itemindex = GetNextSelectedItem(pos);
1879 while (pos)
1881 int nextindex = GetNextSelectedItem(pos);
1882 if (nextindex - itemindex > 1)
1884 bContinuous = false;
1885 break;
1887 itemindex = nextindex;
1890 return bContinuous;
1893 void CGitLogListBase::CopySelectionToClipBoard(bool HashOnly)
1896 CString sClipdata;
1897 POSITION pos = GetFirstSelectedItemPosition();
1898 if (pos != NULL)
1900 CString sRev;
1901 sRev.LoadString(IDS_LOG_REVISION);
1902 CString sAuthor;
1903 sAuthor.LoadString(IDS_LOG_AUTHOR);
1904 CString sDate;
1905 sDate.LoadString(IDS_LOG_DATE);
1906 CString sMessage;
1907 sMessage.LoadString(IDS_LOG_MESSAGE);
1908 while (pos)
1910 CString sLogCopyText;
1911 CString sPaths;
1912 GitRev * pLogEntry = reinterpret_cast<GitRev *>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1914 if(!HashOnly)
1916 //pLogEntry->GetFiles(this)
1917 //LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
1919 CString from(MAKEINTRESOURCE(IDS_STATUSLIST_FROM));
1920 for (int cpPathIndex = 0; cpPathIndex<pLogEntry->GetFiles(this).GetCount(); ++cpPathIndex)
1922 sPaths += ((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetActionName() + _T(": ") + pLogEntry->GetFiles(this)[cpPathIndex].GetGitPathString();
1923 if (((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).m_Action & (CTGitPath::LOGACTIONS_REPLACED|CTGitPath::LOGACTIONS_COPY) && !((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetGitOldPathString().IsEmpty())
1925 CString rename;
1926 rename.Format(from, ((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetGitOldPathString());
1927 sPaths += _T(" ") + rename;
1929 sPaths += _T("\r\n");
1931 sPaths.Trim();
1932 CString body = pLogEntry->GetBody();
1933 body.Replace(_T("\n"), _T("\r\n"));
1934 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"),
1935 (LPCTSTR)sRev, pLogEntry->m_CommitHash.ToString(),
1936 (LPCTSTR)sAuthor, (LPCTSTR)pLogEntry->GetAuthorName(),
1937 (LPCTSTR)sDate,
1938 (LPCTSTR)CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
1939 (LPCTSTR)sMessage, pLogEntry->GetSubject().Trim() + _T("\r\n\r\n") + body.Trim(),
1940 (LPCTSTR)sPaths);
1941 sClipdata += sLogCopyText;
1943 else
1945 sClipdata += pLogEntry->m_CommitHash;
1946 break;
1950 CStringUtils::WriteAsciiStringToClipboard(sClipdata, GetSafeHwnd());
1955 void CGitLogListBase::DiffSelectedRevWithPrevious()
1957 if (m_bThreadRunning)
1958 return;
1960 int FirstSelect=-1, LastSelect=-1;
1961 POSITION pos = GetFirstSelectedItemPosition();
1962 FirstSelect = GetNextSelectedItem(pos);
1963 while(pos)
1965 LastSelect = GetNextSelectedItem(pos);
1968 ContextMenuAction(ID_COMPAREWITHPREVIOUS,FirstSelect,LastSelect, NULL);
1970 #if 0
1971 UpdateLogInfoLabel();
1972 int selIndex = m_LogList.GetSelectionMark();
1973 if (selIndex < 0)
1974 return;
1975 int selCount = m_LogList.GetSelectedCount();
1976 if (selCount != 1)
1977 return;
1979 // Find selected entry in the log list
1980 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
1981 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
1982 long rev1 = pLogEntry->Rev;
1983 long rev2 = rev1-1;
1984 CTGitPath path = m_path;
1986 // See how many files under the relative root were changed in selected revision
1987 int nChanged = 0;
1988 LogChangedPath * changed = NULL;
1989 for (INT_PTR c = 0; c < pLogEntry->pArChangedPaths->GetCount(); ++c)
1991 LogChangedPath * cpath = pLogEntry->pArChangedPaths->SafeGetAt(c);
1992 if (cpath && cpath -> sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
1994 ++nChanged;
1995 changed = cpath;
1999 if (m_path.IsDirectory() && nChanged == 1)
2001 // We're looking at the log for a directory and only one file under dir was changed in the revision
2002 // Do diff on that file instead of whole directory
2003 path.AppendPathString(changed->sPath.Mid(m_sRelativeRoot.GetLength()));
2006 m_bCancelled = FALSE;
2007 DialogEnableWindow(IDOK, FALSE);
2008 SetPromptApp(&theApp);
2009 theApp.DoWaitCursor(1);
2011 if (PromptShown())
2013 GitDiff diff(this, m_hWnd, true);
2014 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
2015 diff.SetHEADPeg(m_LogRevision);
2016 diff.ShowCompare(path, rev2, path, rev1);
2018 else
2020 CAppUtils::StartShowCompare(m_hWnd, path, rev2, path, rev1, GitRev(), m_LogRevision, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
2023 theApp.DoWaitCursor(-1);
2024 EnableOKButton();
2025 #endif
2028 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR *pNMHDR, LRESULT *pResult)
2030 LPNMLVFINDITEM pFindInfo = reinterpret_cast<LPNMLVFINDITEM>(pNMHDR);
2031 *pResult = -1;
2033 if (pFindInfo->lvfi.flags & LVFI_PARAM)
2034 return;
2035 if ((pFindInfo->iStart < 0)||(pFindInfo->iStart >= m_arShownList.GetCount()))
2036 return;
2037 if (pFindInfo->lvfi.psz == 0)
2038 return;
2039 #if 0
2040 CString sCmp = pFindInfo->lvfi.psz;
2041 CString sRev;
2042 for (int i=pFindInfo->iStart; i<m_arShownList.GetCount(); ++i)
2044 GitRev * pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(i));
2045 sRev.Format(_T("%ld"), pLogEntry->Rev);
2046 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
2048 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
2050 *pResult = i;
2051 return;
2054 else
2056 if (sCmp.Compare(sRev)==0)
2058 *pResult = i;
2059 return;
2063 if (pFindInfo->lvfi.flags & LVFI_WRAP)
2065 for (int i=0; i<pFindInfo->iStart; ++i)
2067 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(i));
2068 sRev.Format(_T("%ld"), pLogEntry->Rev);
2069 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
2071 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
2073 *pResult = i;
2074 return;
2077 else
2079 if (sCmp.Compare(sRev)==0)
2081 *pResult = i;
2082 return;
2087 #endif
2088 *pResult = -1;
2091 int CGitLogListBase::FillGitLog(CTGitPath *path,int info,CString *from,CString *to)
2093 ClearText();
2095 this->m_arShownList.SafeRemoveAll();
2097 this->m_logEntries.ClearAll();
2098 if (this->m_logEntries.ParserFromLog(path,-1,info,from,to))
2099 return -1;
2101 //this->m_logEntries.ParserFromLog();
2102 SetItemCountEx(this->m_logEntries.size());
2104 for(unsigned int i=0;i<m_logEntries.size();i++)
2106 if(m_IsOldFirst)
2108 m_logEntries.GetGitRevAt(m_logEntries.size()-i-1).m_IsFull=TRUE;
2109 this->m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size()-i-1));
2112 else
2114 m_logEntries.GetGitRevAt(i).m_IsFull=TRUE;
2115 this->m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
2119 m_CurrentBranch = g_Git.GetCurrentBranch();
2120 m_HeadHash = g_Git.GetHash(_T("HEAD"));
2122 if(path)
2123 m_Path=*path;
2124 return 0;
2128 int CGitLogListBase::BeginFetchLog()
2130 ClearText();
2132 this->m_arShownList.SafeRemoveAll();
2134 this->m_logEntries.ClearAll();
2135 git_init();
2137 this->m_LogCache.ClearAllParent();
2139 m_LogCache.FetchCacheIndex(g_Git.m_CurrentDir);
2141 CTGitPath *path;
2142 if(this->m_Path.IsEmpty())
2143 path=NULL;
2144 else
2145 path=&this->m_Path;
2147 CString hash;
2148 int mask;
2149 mask = CGit::LOG_INFO_ONLY_HASH | CGit::LOG_INFO_BOUNDARY;
2150 // if(this->m_bAllBranch)
2151 mask |= m_ShowMask ;
2153 if(m_bShowWC)
2155 this->m_logEntries.insert(m_logEntries.begin(),this->m_wcRev.m_CommitHash);
2156 ResetWcRev();
2157 this->m_LogCache.m_HashMap[m_wcRev.m_CommitHash]=m_wcRev;
2160 CString *pFrom, *pTo;
2161 pFrom = pTo = NULL;
2162 CString head(_T("HEAD"));
2163 if(!this->m_startrev.IsEmpty())
2165 pFrom = &this->m_startrev;
2166 if(!this->m_endrev.IsEmpty())
2167 pTo = &this->m_endrev;
2168 else
2169 pTo = &head;
2172 CFilterData data;
2173 data.m_From = m_From;
2174 data.m_To =m_To;
2176 #if 0 /* use tortoiegit filter */
2177 if(this->m_nSelectedFilter == LOGFILTER_ALL || m_nSelectedFilter == LOGFILTER_AUTHORS)
2178 data.m_Author = this->m_sFilterText;
2180 if(this->m_nSelectedFilter == LOGFILTER_ALL || m_nSelectedFilter == LOGFILTER_MESSAGES)
2181 data.m_MessageFilter = this->m_sFilterText;
2183 data.m_IsRegex = m_bFilterWithRegex;
2184 #endif
2186 // follow does not work for directories
2187 if (!path || path->IsDirectory())
2188 mask &= ~CGit::LOG_INFO_FOLLOW;
2189 // follow does not work with all branches 8at least in TGit)
2190 if (mask & CGit::LOG_INFO_FOLLOW)
2191 mask &= ~CGit::LOG_INFO_ALL_BRANCH;
2193 CString cmd=g_Git.GetLogCmd(m_StartRef,path,-1,mask,pFrom,pTo,true,&data);
2195 //this->m_logEntries.ParserFromLog();
2196 if(IsInWorkingThread())
2198 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL);
2200 else
2202 SetItemCountEx(this->m_logEntries.size());
2207 git_init();
2209 catch (char* msg)
2211 CString err(msg);
2212 MessageBox(_T("Could not initialize libgit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2213 return -1;
2216 if(g_Git.IsInitRepos())
2217 return 0;
2219 try {
2220 if (git_open_log(&m_DllGitLog, CUnicodeUtils::GetMulti(cmd, CP_UTF8).GetBuffer()))
2222 return -1;
2225 catch (char* msg)
2227 CString err(msg);
2228 MessageBox(_T("Could not open log.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2229 return -1;
2232 return 0;
2235 BOOL CGitLogListBase::PreTranslateMessage(MSG* pMsg)
2237 if (pMsg->message == WM_KEYDOWN && pMsg->wParam=='\r')
2239 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))
2241 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
2243 DiffSelectedRevWithPrevious();
2244 return TRUE;
2247 #if 0
2248 if (GetFocus()==GetDlgItem(IDC_LOGMSG))
2250 DiffSelectedFile();
2251 return TRUE;
2253 #endif
2255 else if (pMsg->message == WM_KEYDOWN && pMsg->wParam == 'A' && GetAsyncKeyState(VK_CONTROL)&0x8000)
2257 // select all entries
2258 for (int i=0; i<GetItemCount(); ++i)
2260 SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
2262 return TRUE;
2265 #if 0
2266 if (m_hAccel && !bSkipAccelerator)
2268 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
2269 if (ret)
2270 return TRUE;
2273 #endif
2274 //m_tooltips.RelayEvent(pMsg);
2275 return __super::PreTranslateMessage(pMsg);
2278 void CGitLogListBase::OnNMDblclkLoglist(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2280 // a double click on an entry in the revision list has happened
2281 *pResult = 0;
2283 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
2284 DiffSelectedRevWithPrevious();
2287 int CGitLogListBase::FetchLogAsync(void * data)
2289 m_ProcData=data;
2290 m_bExitThread=FALSE;
2291 InterlockedExchange(&m_bThreadRunning, TRUE);
2292 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2293 m_LoadingThread = AfxBeginThread(LogThreadEntry, this, THREAD_PRIORITY_LOWEST);
2294 if (m_LoadingThread ==NULL)
2296 InterlockedExchange(&m_bThreadRunning, FALSE);
2297 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2298 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
2299 return -1;
2301 return 0;
2304 //this is the thread function which calls the subversion function
2305 UINT CGitLogListBase::LogThreadEntry(LPVOID pVoid)
2307 return ((CGitLogListBase*)pVoid)->LogThread();
2310 void CGitLogListBase::GetTimeRange(CTime &oldest, CTime &latest)
2312 //CTime time;
2313 oldest=CTime::GetCurrentTime();
2314 latest=CTime(1971,1,2,0,0,0);
2315 for(unsigned int i=0;i<m_logEntries.size();i++)
2317 if(m_logEntries[i].IsEmpty())
2318 continue;
2320 if(m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime() < oldest.GetTime())
2321 oldest = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
2323 if(m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime() > latest.GetTime())
2324 latest = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
2328 if(latest<oldest)
2329 latest=oldest;
2332 UINT CGitLogListBase::LogThread()
2334 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_START,0);
2336 InterlockedExchange(&m_bThreadRunning, TRUE);
2337 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2339 ULONGLONG t1,t2;
2341 if(BeginFetchLog())
2343 InterlockedExchange(&m_bThreadRunning, FALSE);
2344 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2346 return -1;
2349 tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
2350 bool bRegex = false;
2351 if (m_bFilterWithRegex)
2352 bRegex = ValidateRegexp(m_sFilterText, pat, false);
2354 TRACE(_T("\n===Begin===\n"));
2355 //Update work copy item;
2357 if( m_logEntries.size() > 0)
2359 GitRev *pRev = &m_logEntries.GetGitRevAt(0);
2361 m_arShownList.SafeAdd(pRev);
2365 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2367 // store commit number of the last selected commit/line before the refresh or -1
2368 int lastSelectedHashNItem = -1;
2369 int ret = 0;
2371 if(!g_Git.IsInitRepos())
2373 g_Git.m_critGitDllSec.Lock();
2374 int total = 0;
2377 git_get_log_firstcommit(m_DllGitLog);
2378 total = git_get_log_estimate_commit_count(m_DllGitLog);
2380 catch (char* msg)
2382 CString err(msg);
2383 MessageBox(_T("Could not get first commit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2384 ret = -1;
2386 g_Git.m_critGitDllSec.Unlock();
2388 GIT_COMMIT commit;
2389 t2=t1=GetTickCount();
2390 int oldprecentage = 0;
2391 int oldsize=m_logEntries.size();
2392 while( ret== 0)
2394 g_Git.m_critGitDllSec.Lock();
2397 ret = git_get_log_nextcommit(this->m_DllGitLog, &commit, m_ShowMask & CGit::LOG_INFO_FOLLOW);
2399 catch (char* msg)
2401 g_Git.m_critGitDllSec.Unlock();
2402 CString err(msg);
2403 MessageBox(_T("Could not get next commit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2404 break;
2406 g_Git.m_critGitDllSec.Unlock();
2408 if(ret)
2409 break;
2411 if (commit.m_ignore == 1)
2413 git_free_commit(&commit);
2414 continue;
2417 //printf("%s\r\n",commit.GetSubject());
2418 if(m_bExitThread)
2419 break;
2421 CGitHash hash = (char*)commit.m_hash ;
2423 GitRev *pRev = m_LogCache.GetCacheData(hash);
2424 pRev->m_GitCommit = commit;
2425 InterlockedExchange(&pRev->m_IsCommitParsed, FALSE);
2427 char *note=NULL;
2428 g_Git.m_critGitDllSec.Lock();
2429 git_get_notes(commit.m_hash,&note);
2430 g_Git.m_critGitDllSec.Unlock();
2432 if(note)
2434 pRev->m_Notes.Empty();
2435 g_Git.StringAppend(&pRev->m_Notes,(BYTE*)note);
2438 if(!pRev->m_IsDiffFiles)
2440 pRev->m_CallDiffAsync = DiffAsync;
2443 pRev->ParserParentFromCommit(&commit);
2445 #ifdef DEBUG
2446 pRev->DbgPrint();
2447 TRACE(_T("\n"));
2448 #endif
2450 if(!m_sFilterText.IsEmpty())
2452 if(!IsMatchFilter(bRegex,pRev,pat))
2453 continue;
2455 this->m_critSec.Lock();
2456 m_logEntries.push_back(hash);
2457 m_arShownList.SafeAdd(pRev);
2458 this->m_critSec.Unlock();
2460 if (lastSelectedHashNItem == -1 && hash == m_lastSelectedHash)
2461 lastSelectedHashNItem = m_arShownList.GetCount() - 1;
2463 t2=GetTickCount();
2465 if(t2-t1>500 || (m_logEntries.size()-oldsize >100))
2467 //update UI
2468 int percent=m_logEntries.size()*100/total + GITLOG_START+1;
2469 if(percent > 99)
2470 percent =99;
2471 if(percent < GITLOG_START)
2472 percent = GITLOG_START +1;
2474 oldsize = m_logEntries.size();
2475 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
2477 //if( percent > oldprecentage )
2479 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) percent,0);
2480 oldprecentage = percent;
2482 t1 = t2;
2485 g_Git.m_critGitDllSec.Lock();
2486 git_close_log(m_DllGitLog);
2487 g_Git.m_critGitDllSec.Unlock();
2491 // restore last selected item
2492 if (lastSelectedHashNItem >= 0)
2494 SetItemState(lastSelectedHashNItem, LVIS_SELECTED, LVIS_SELECTED);
2495 EnsureVisible(lastSelectedHashNItem, FALSE);
2498 //Update UI;
2499 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
2500 if (this->m_hWnd)
2501 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_END,0);
2503 InterlockedExchange(&m_bThreadRunning, FALSE);
2505 return 0;
2508 void CGitLogListBase::Refresh(BOOL IsCleanFilter)
2510 SafeTerminateThread();
2512 this->SetItemCountEx(0);
2513 this->Clear();
2515 ResetWcRev();
2517 // HACK to hide graph column
2518 if (m_ShowMask & CGit::LOG_INFO_FOLLOW)
2519 SetColumnWidth(0, 0);
2520 else
2521 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
2523 //Update branch and Tag info
2524 ReloadHashMap();
2525 //Assume Thread have exited
2526 //if(!m_bThreadRunning)
2528 m_logEntries.clear();
2530 if(IsCleanFilter)
2532 m_sFilterText.Empty();
2533 m_From=-1;
2534 m_To=-1;
2537 InterlockedExchange(&m_bExitThread,FALSE);
2539 InterlockedExchange(&m_bThreadRunning, TRUE);
2540 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2541 if ( (m_LoadingThread=AfxBeginThread(LogThreadEntry, this)) ==NULL)
2543 InterlockedExchange(&m_bThreadRunning, FALSE);
2544 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2545 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
2549 bool CGitLogListBase::ValidateRegexp(LPCTSTR regexp_str, tr1::wregex& pat, bool bMatchCase /* = false */)
2553 tr1::regex_constants::syntax_option_type type = tr1::regex_constants::ECMAScript;
2554 if (!bMatchCase)
2555 type |= tr1::regex_constants::icase;
2556 pat = tr1::wregex(regexp_str, type);
2557 return true;
2559 catch (exception) {}
2560 return false;
2562 BOOL CGitLogListBase::IsMatchFilter(bool bRegex, GitRev *pRev, tr1::wregex &pat)
2565 tr1::regex_constants::match_flag_type flags = tr1::regex_constants::match_any;
2566 CString sRev;
2568 if ((bRegex)&&(m_bFilterWithRegex))
2570 if (m_SelectedFilters & LOGFILTER_BUGID)
2572 if(this->m_bShowBugtraqColumn)
2574 CString sBugIds = m_ProjectProperties.FindBugID(pRev->GetSubject() + _T("\r\n\r\n") + pRev->GetBody());
2576 ATLTRACE(_T("bugID = \"%s\"\n"), sBugIds);
2577 if (regex_search(wstring(sBugIds), pat, flags))
2579 return TRUE;
2584 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
2586 ATLTRACE(_T("messge = \"%s\"\n"), pRev->GetSubject());
2587 if (regex_search(wstring((LPCTSTR)pRev->GetSubject()), pat, flags))
2589 return TRUE;
2593 if (m_SelectedFilters & LOGFILTER_MESSAGES)
2595 ATLTRACE(_T("messge = \"%s\"\n"),pRev->GetBody());
2596 if (regex_search(wstring((LPCTSTR)pRev->GetBody()), pat, flags))
2598 return TRUE;
2602 if (m_SelectedFilters & LOGFILTER_AUTHORS)
2604 if (regex_search(wstring(pRev->GetAuthorName()), pat, flags))
2606 return TRUE;
2609 if (regex_search(wstring(pRev->GetCommitterName()), pat, flags))
2611 return TRUE;
2615 if (m_SelectedFilters & LOGFILTER_REVS)
2617 sRev.Format(_T("%s"), pRev->m_CommitHash.ToString());
2618 if (regex_search(wstring((LPCTSTR)sRev), pat, flags))
2620 return TRUE;
2624 if (m_SelectedFilters & LOGFILTER_PATHS)
2626 CTGitPathList *pathList=NULL;
2627 if( pRev->m_IsDiffFiles)
2628 pathList = &pRev->GetFiles(this);
2629 else
2631 if(!pRev->m_IsSimpleListReady)
2632 pRev->SafeGetSimpleList(&g_Git);
2635 if(pathList)
2636 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList->GetCount(); ++cpPathIndex)
2638 if (regex_search(wstring((LPCTSTR)pathList->m_paths.at(cpPathIndex).GetGitOldPathString()), pat, flags))
2640 return true;
2642 if (regex_search(wstring((LPCTSTR)pathList->m_paths.at(cpPathIndex).GetGitPathString()), pat, flags))
2644 return true;
2648 for(INT_PTR i=0;i<pRev->m_SimpleFileList.size();i++)
2650 if (regex_search(wstring((LPCTSTR)pRev->m_SimpleFileList[i]), pat, flags))
2652 return true;
2657 else
2659 CString find = m_sFilterText;
2660 find.MakeLower();
2662 if (m_SelectedFilters & LOGFILTER_BUGID)
2664 if(this->m_bShowBugtraqColumn)
2666 CString sBugIds = m_ProjectProperties.FindBugID(pRev->GetSubject() + _T("\r\n\r\n") + pRev->GetBody());
2668 sBugIds.MakeLower();
2669 if ((sBugIds.Find(find) >= 0))
2671 return TRUE;
2676 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
2678 CString msg = pRev->GetSubject();
2680 msg = msg.MakeLower();
2681 if ((msg.Find(find) >= 0))
2683 return TRUE;
2687 if (m_SelectedFilters & LOGFILTER_MESSAGES)
2689 CString msg = pRev->GetBody();
2691 msg = msg.MakeLower();
2692 if ((msg.Find(find) >= 0))
2694 return TRUE;
2698 if (m_SelectedFilters & LOGFILTER_AUTHORS)
2700 CString msg = pRev->GetAuthorName();
2701 msg = msg.MakeLower();
2702 if ((msg.Find(find) >= 0))
2704 return TRUE;
2708 if (m_SelectedFilters & LOGFILTER_REVS)
2710 sRev.Format(_T("%s"), pRev->m_CommitHash.ToString());
2711 if ((sRev.Find(find) >= 0))
2713 return TRUE;
2717 if (m_SelectedFilters & LOGFILTER_PATHS)
2719 CTGitPathList *pathList=NULL;
2720 if( pRev->m_IsDiffFiles)
2721 pathList = &pRev->GetFiles(this);
2722 else
2724 if(!pRev->m_IsSimpleListReady)
2725 pRev->SafeGetSimpleList(&g_Git);
2727 if(pathList)
2728 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList->GetCount() ; ++cpPathIndex)
2730 CTGitPath *cpath = &pathList->m_paths.at(cpPathIndex);
2731 CString path = cpath->GetGitOldPathString();
2732 path.MakeLower();
2733 if ((path.Find(find)>=0))
2735 return true;
2737 path = cpath->GetGitPathString();
2738 path.MakeLower();
2739 if ((path.Find(find)>=0))
2741 return true;
2745 for (INT_PTR i=0;i<pRev->m_SimpleFileList.size();i++)
2747 CString path = pRev->m_SimpleFileList[i];
2748 path.MakeLower();
2749 if ((path.Find(find)>=0))
2751 return true;
2755 } // else (from if (bRegex))
2756 return FALSE;
2760 void CGitLogListBase::RecalculateShownList(CThreadSafePtrArray * pShownlist)
2763 pShownlist->SafeRemoveAll();
2765 tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
2766 bool bRegex = false;
2767 if (m_bFilterWithRegex)
2768 bRegex = ValidateRegexp(m_sFilterText, pat, false);
2770 tr1::regex_constants::match_flag_type flags = tr1::regex_constants::match_any;
2771 CString sRev;
2772 for (DWORD i=0; i<m_logEntries.size(); ++i)
2774 if ((bRegex)&&(m_bFilterWithRegex))
2776 #if 0
2777 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
2779 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR)m_logEntries[i]->sBugIDs);
2780 if (regex_search(wstring((LPCTSTR)m_logEntries[i]->sBugIDs), pat, flags)&&IsEntryInDateRange(i))
2782 pShownlist->SafeAdd(m_logEntries[i]);
2783 continue;
2786 #endif
2787 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
2789 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).GetSubject());
2790 if (regex_search(wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetSubject()), pat, flags)&&IsEntryInDateRange(i))
2792 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2793 continue;
2796 if (m_SelectedFilters & LOGFILTER_MESSAGES)
2798 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).GetBody());
2799 if (regex_search(wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetBody()), pat, flags)&&IsEntryInDateRange(i))
2801 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2802 continue;
2805 if (m_SelectedFilters & LOGFILTER_PATHS)
2807 CTGitPathList pathList = m_logEntries.GetGitRevAt(i).GetFiles(this);
2809 bool bGoing = true;
2810 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList.GetCount() && bGoing; ++cpPathIndex)
2812 CTGitPath cpath = pathList[cpPathIndex];
2813 if (regex_search(wstring((LPCTSTR)cpath.GetGitOldPathString()), pat, flags)&&IsEntryInDateRange(i))
2815 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2816 bGoing = false;
2817 continue;
2819 if (regex_search(wstring((LPCTSTR)cpath.GetGitPathString()), pat, flags)&&IsEntryInDateRange(i))
2821 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2822 bGoing = false;
2823 continue;
2825 if (regex_search(wstring((LPCTSTR)cpath.GetActionName()), pat, flags)&&IsEntryInDateRange(i))
2827 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2828 bGoing = false;
2829 continue;
2833 if (m_SelectedFilters & LOGFILTER_AUTHORS)
2835 if (regex_search(wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetAuthorName()), pat, flags)&&IsEntryInDateRange(i))
2837 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2838 continue;
2841 if (m_SelectedFilters & LOGFILTER_REVS)
2843 sRev.Format(_T("%s"), m_logEntries.GetGitRevAt(i).m_CommitHash.ToString());
2844 if (regex_search(wstring((LPCTSTR)sRev), pat, flags)&&IsEntryInDateRange(i))
2846 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2847 continue;
2850 } // if (bRegex)
2851 else
2853 CString find = m_sFilterText;
2854 find.MakeLower();
2855 #if 0
2856 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
2858 CString sBugIDs = m_logEntries[i]->sBugIDs;
2860 sBugIDs = sBugIDs.MakeLower();
2861 if ((sBugIDs.Find(find) >= 0)&&(IsEntryInDateRange(i)))
2863 pShownlist->SafeAdd(m_logEntries[i]);
2864 continue;
2867 #endif
2868 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
2870 CString msg = m_logEntries.GetGitRevAt(i).GetSubject();
2872 msg = msg.MakeLower();
2873 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
2875 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2876 continue;
2879 if (m_SelectedFilters & LOGFILTER_MESSAGES)
2881 CString msg = m_logEntries.GetGitRevAt(i).GetBody();
2883 msg = msg.MakeLower();
2884 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
2886 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2887 continue;
2890 if (m_SelectedFilters & LOGFILTER_PATHS)
2892 CTGitPathList pathList = m_logEntries.GetGitRevAt(i).GetFiles(this);
2894 bool bGoing = true;
2895 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList.GetCount() && bGoing; ++cpPathIndex)
2897 CTGitPath cpath = pathList[cpPathIndex];
2898 CString path = cpath.GetGitOldPathString();
2899 path.MakeLower();
2900 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
2902 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2903 bGoing = false;
2904 continue;
2906 path = cpath.GetGitPathString();
2907 path.MakeLower();
2908 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
2910 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2911 bGoing = false;
2912 continue;
2914 path = cpath.GetActionName();
2915 path.MakeLower();
2916 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
2918 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2919 bGoing = false;
2920 continue;
2924 if (m_SelectedFilters & LOGFILTER_AUTHORS)
2926 CString msg = m_logEntries.GetGitRevAt(i).GetAuthorName();
2927 msg = msg.MakeLower();
2928 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
2930 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2931 continue;
2934 if (m_SelectedFilters & LOGFILTER_REVS)
2936 sRev.Format(_T("%s"), m_logEntries.GetGitRevAt(i).m_CommitHash.ToString());
2937 if ((sRev.Find(find) >= 0)&&(IsEntryInDateRange(i)))
2939 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2940 continue;
2943 } // else (from if (bRegex))
2944 } // for (DWORD i=0; i<m_logEntries.size(); ++i)
2948 BOOL CGitLogListBase::IsEntryInDateRange(int /*i*/)
2951 __time64_t time = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
2953 if(m_From == -1)
2954 if(m_To == -1)
2955 return true;
2956 else
2957 return time <= m_To;
2958 else
2959 if(m_To == -1)
2960 return time >= m_From;
2961 else
2962 return ((time >= m_From)&&(time <= m_To));
2964 return TRUE; /* git dll will filter time range */
2966 // return TRUE;
2968 void CGitLogListBase::StartFilter()
2970 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2971 RecalculateShownList(&m_arShownList);
2972 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2975 DeleteAllItems();
2976 SetItemCountEx(ShownCountWithStopped());
2977 RedrawItems(0, ShownCountWithStopped());
2978 Invalidate();
2981 void CGitLogListBase::RemoveFilter()
2984 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2986 m_arShownList.SafeRemoveAll();
2988 // reset the time filter too
2989 #if 0
2990 m_timFrom = (__time64_t(m_tFrom));
2991 m_timTo = (__time64_t(m_tTo));
2992 m_DateFrom.SetTime(&m_timFrom);
2993 m_DateTo.SetTime(&m_timTo);
2994 m_DateFrom.SetRange(&m_timFrom, &m_timTo);
2995 m_DateTo.SetRange(&m_timFrom, &m_timTo);
2996 #endif
2998 for (DWORD i=0; i<m_logEntries.size(); ++i)
3000 if(this->m_IsOldFirst)
3002 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size()-i-1));
3004 else
3006 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
3009 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
3010 DeleteAllItems();
3011 SetItemCountEx(ShownCountWithStopped());
3012 RedrawItems(0, ShownCountWithStopped());
3014 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3017 void CGitLogListBase::Clear()
3019 m_arShownList.SafeRemoveAll();
3020 DeleteAllItems();
3022 m_logEntries.ClearAll();
3026 void CGitLogListBase::OnDestroy()
3028 // save the column widths to the registry
3029 SaveColumnWidths();
3031 SafeTerminateThread();
3032 SafeTerminateAsyncDiffThread();
3034 int retry = 0;
3035 while(m_LogCache.SaveCache())
3037 if(retry > 5)
3038 break;
3039 Sleep(1000);
3041 retry++;
3043 //if(CMessageBox::Show(NULL,_T("Cannot Save Log Cache to Disk. To retry click yes. To give up click no."),_T("TortoiseGit"),
3044 // MB_YESNO) == IDNO)
3045 // break;
3048 CHintListCtrl::OnDestroy();
3051 LRESULT CGitLogListBase::OnLoad(WPARAM wParam,LPARAM lParam)
3053 UNREFERENCED_PARAMETER(lParam);
3054 CRect rect;
3055 int i=(int)wParam;
3056 this->GetItemRect(i,&rect,LVIR_BOUNDS);
3057 this->InvalidateRect(rect);
3059 return 0;
3063 * Save column widths to the registry
3065 void CGitLogListBase::SaveColumnWidths()
3067 int maxcol = m_ColumnManager.GetColumnCount();
3069 // HACK that graph column is always shown
3070 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
3072 for (int col = 0; col < maxcol; col++)
3073 if (m_ColumnManager.IsVisible (col))
3074 m_ColumnManager.ColumnResized (col);
3076 m_ColumnManager.WriteSettings();
3079 int CGitLogListBase::GetHeadIndex()
3081 if(m_HeadHash.IsEmpty())
3082 return -1;
3084 for(int i=0;i<m_arShownList.GetCount();i++)
3086 GitRev *pRev = (GitRev*)m_arShownList[i];
3087 if(pRev)
3089 if(pRev->m_CommitHash.ToString() == m_HeadHash )
3090 return i;
3093 return -1;
3095 void CGitLogListBase::OnFind()
3097 if (!m_pFindDialog)
3099 m_pFindDialog = new CFindDlg(this);
3100 m_pFindDialog->Create(this);
3103 void CGitLogListBase::OnHdnBegintrack(NMHDR *pNMHDR, LRESULT *pResult)
3105 m_ColumnManager.OnHdnBegintrack(pNMHDR, pResult);
3107 void CGitLogListBase::OnHdnItemchanging(NMHDR *pNMHDR, LRESULT *pResult)
3109 if(!m_ColumnManager.OnHdnItemchanging(pNMHDR, pResult))
3110 Default();
3112 LRESULT CGitLogListBase::OnFindDialogMessage(WPARAM /*wParam*/, LPARAM /*lParam*/)
3115 ASSERT(m_pFindDialog != NULL);
3116 bool bFound = false;
3117 int i=0;
3119 if (m_pFindDialog->IsTerminating())
3121 // invalidate the handle identifying the dialog box.
3122 m_pFindDialog = NULL;
3123 return 0;
3126 if(m_pFindDialog->IsRef())
3128 CString str;
3129 str=m_pFindDialog->GetFindString();
3131 CGitHash hash;
3133 if(!str.IsEmpty())
3134 hash = g_Git.GetHash(str + _T("^{}")); // add ^{} in order to get the correct SHA-1 (especially for signed tags)
3136 if(!hash.IsEmpty())
3138 for (i = 0; i<m_arShownList.GetCount(); i++)
3140 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(i);
3141 if(pLogEntry && pLogEntry->m_CommitHash == hash)
3143 bFound = true;
3144 break;
3151 if(m_pFindDialog->FindNext())
3153 //read data from dialog
3154 CString FindText = m_pFindDialog->GetFindString();
3155 bool bMatchCase = (m_pFindDialog->MatchCase() == TRUE);
3157 tr1::wregex pat;
3158 bool bRegex = ValidateRegexp(FindText, pat, bMatchCase);
3160 tr1::regex_constants::match_flag_type flags = tr1::regex_constants::match_not_null;
3163 for (i = this->m_nSearchIndex; i<m_arShownList.GetCount()&&!bFound; i++)
3165 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(i);
3167 CString str;
3168 str+=pLogEntry->m_CommitHash.ToString();
3169 str+=_T("\n");
3171 for(int j=0;j<this->m_HashMap[pLogEntry->m_CommitHash].size();j++)
3173 str+=m_HashMap[pLogEntry->m_CommitHash][j];
3174 str+=_T("\n");
3177 str+=pLogEntry->GetAuthorEmail();
3178 str+=_T("\n");
3179 str+=pLogEntry->GetAuthorName();
3180 str+=_T("\n");
3181 str+=pLogEntry->GetBody();
3182 str+=_T("\n");
3183 str+=pLogEntry->GetCommitterEmail();
3184 str+=_T("\n");
3185 str+=pLogEntry->GetCommitterName();
3186 str+=_T("\n");
3187 str+=pLogEntry->GetSubject();
3188 str+=_T("\n");
3191 /*Because changed files list is loaded on demand when gui show,
3192 files will empty when files have not fetched.
3194 we can add it back by using one-way diff(with outnumber changed and rename detect.
3195 here just need changed filename list. one-way is much quicker.
3197 if(pLogEntry->m_IsFull)
3199 for(int i=0;i<pLogEntry->GetFiles(this).GetCount();i++)
3201 str+=pLogEntry->GetFiles(this)[i].GetWinPath();
3202 str+=_T("\n");
3203 str+=pLogEntry->GetFiles(this)[i].GetGitOldPathString();
3204 str+=_T("\n");
3207 else
3209 if(!pLogEntry->m_IsSimpleListReady)
3210 pLogEntry->SafeGetSimpleList(&g_Git);
3212 for(int i=0;i<pLogEntry->m_SimpleFileList.size();i++)
3214 str+=pLogEntry->m_SimpleFileList[i];
3215 str+=_T("\n");
3221 if (bRegex)
3223 if (regex_search(wstring(str), pat, flags))
3225 bFound = true;
3226 break;
3229 else
3231 if (bMatchCase)
3233 if (str.Find(FindText) >= 0)
3235 bFound = true;
3236 break;
3240 else
3242 CString msg = str;
3243 msg = msg.MakeLower();
3244 CString find = FindText.MakeLower();
3245 if (msg.Find(find) >= 0)
3247 bFound = TRUE;
3248 break;
3252 } // for (i = this->m_nSearchIndex; i<m_arShownList.GetItemCount()&&!bFound; i++)
3254 } // if(m_pFindDialog->FindNext())
3255 //UpdateLogInfoLabel();
3257 if (bFound)
3259 this->m_nSearchIndex = i;
3260 EnsureVisible(i, FALSE);
3261 SetItemState(GetSelectionMark(), 0, LVIS_SELECTED);
3262 SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
3263 SetSelectionMark(i);
3264 //FillLogMessageCtrl();
3265 UpdateData(FALSE);
3266 m_nSearchIndex++;
3267 if (m_nSearchIndex >= m_arShownList.GetCount())
3268 m_nSearchIndex = (int)m_arShownList.GetCount()-1;
3271 return 0;
3274 void CGitLogListBase::OnColumnResized(NMHDR *pNMHDR, LRESULT *pResult)
3276 m_ColumnManager.OnColumnResized(pNMHDR,pResult);
3278 *pResult = FALSE;
3281 void CGitLogListBase::OnColumnMoved(NMHDR *pNMHDR, LRESULT *pResult)
3283 m_ColumnManager.OnColumnMoved(pNMHDR, pResult);
3285 Invalidate(FALSE);