Fixed issue #1470: Log Dialog: Selected item not remembered after refresh if item...
[TortoiseGit.git] / src / TortoiseProc / GitLogListBase.cpp
blob200a1e6b9200c1f36b3ed3c4fd242b650bc94b82
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);
64 const UINT CGitLogListBase::m_ScrollToMessage = RegisterWindowMessage(_T("TORTOISEGIT_LOG_SCROLLTO"));
66 IMPLEMENT_DYNAMIC(CGitLogListBase, CHintListCtrl)
68 CGitLogListBase::CGitLogListBase():CHintListCtrl()
69 ,m_regMaxBugIDColWidth(_T("Software\\TortoiseGit\\MaxBugIDColWidth"), 200)
70 ,m_nSearchIndex(0)
71 ,m_bNoDispUpdates(FALSE)
72 , m_bThreadRunning(FALSE)
73 , m_bStrictStopped(false)
74 , m_pStoreSelection(NULL)
75 , m_SelectedFilters(LOGFILTER_ALL)
76 , m_bShowWC(false)
77 , m_logEntries(&m_LogCache)
78 , m_pFindDialog(NULL)
79 , m_ColumnManager(this)
80 , m_dwDefaultColumns(0)
81 , m_arShownList(&m_critSec)
82 , m_hasWC(true)
83 , m_bNoHightlightHead(FALSE)
85 // use the default GUI font, create a copy of it and
86 // change the copy to BOLD (leave the rest of the font
87 // the same)
88 HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
89 LOGFONT lf = {0};
90 GetObject(hFont, sizeof(LOGFONT), &lf);
91 lf.lfWeight = FW_BOLD;
92 m_boldFont = CreateFontIndirect(&lf);
94 m_bShowBugtraqColumn=false;
96 m_IsIDReplaceAction=FALSE;
98 this->m_critSec.Init();
99 m_wcRev.m_CommitHash.Empty();
100 m_wcRev.GetSubject() = CString(MAKEINTRESOURCE(IDS_LOG_WORKINGDIRCHANGES));
101 m_wcRev.m_ParentHash.clear();
102 m_wcRev.m_Mark=_T('-');
103 m_wcRev.m_IsUpdateing=FALSE;
104 m_wcRev.m_IsFull = TRUE;
106 m_hModifiedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONMODIFIED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
107 m_hReplacedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONREPLACED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
108 m_hAddedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONADDED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
109 m_hDeletedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONDELETED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
110 m_hFetchIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONFETCHING), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
112 m_bFilterWithRegex = !!CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), TRUE);
114 g_Git.GetMapHashToFriendName(m_HashMap);
115 if (CTGitPath(g_Git.m_CurrentDir).HasAdminDir())
117 m_CurrentBranch=g_Git.GetCurrentBranch();
118 try {
119 m_HeadHash=g_Git.GetHash(_T("HEAD"));
121 catch (char* msg)
123 CString err(msg);
124 MessageBox(_T("Could not get HEAD hash. Quitting...\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
125 ExitProcess(1);
129 m_From = -1;
130 m_To = -1;
132 m_ShowMask = 0;
133 m_LoadingThread = NULL;
135 InterlockedExchange(&m_bExitThread,FALSE);
136 m_IsOldFirst = FALSE;
137 m_IsRebaseReplaceGraph = FALSE;
140 for(int i=0;i<Lanes::COLORS_NUM;i++)
142 m_LineColors[i] = m_Colors.GetColor((CColors::Colors)(CColors::BranchLine1+i));
144 // get short/long datetime setting from registry
145 DWORD RegUseShortDateFormat = CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE);
146 if ( RegUseShortDateFormat )
148 m_DateFormat = DATE_SHORTDATE;
150 else
152 m_DateFormat = DATE_LONGDATE;
154 // get relative time display setting from registry
155 DWORD regRelativeTimes = CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE);
156 m_bRelativeTimes = (regRelativeTimes != 0);
157 m_ContextMenuMask = 0xFFFFFFFFFFFFFFFF;
159 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_PICK);
160 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_SQUASH);
161 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_EDIT);
162 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_SKIP);
163 m_ContextMenuMask &= ~GetContextMenuBit(ID_LOG);
164 m_ContextMenuMask &= ~GetContextMenuBit(ID_BLAME);
166 m_ColumnRegKey=_T("log");
168 m_AsyncThreadExit = FALSE;
169 m_AsyncDiffEvent = ::CreateEvent(NULL,FALSE,TRUE,NULL);
170 m_AsynDiffListLock.Init();
172 m_DiffingThread = AfxBeginThread(AsyncThread, this, THREAD_PRIORITY_BELOW_NORMAL);
173 if (m_DiffingThread ==NULL)
175 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
176 return;
181 int CGitLogListBase::AsyncDiffThread()
183 m_AsyncThreadExited = false;
184 while(!m_AsyncThreadExit)
186 ::WaitForSingleObject(m_AsyncDiffEvent, INFINITE);
188 GitRev *pRev = NULL;
189 while(!m_AsyncThreadExit && !m_AsynDiffList.empty())
191 m_AsynDiffListLock.Lock();
192 pRev = m_AsynDiffList.back();
193 m_AsynDiffList.pop_back();
194 m_AsynDiffListLock.Unlock();
196 if( pRev->m_CommitHash.IsEmpty() )
198 if(pRev->m_IsDiffFiles)
199 continue;
201 pRev->GetFiles(this).Clear();
202 pRev->m_ParentHash.clear();
203 pRev->m_ParentHash.push_back(m_HeadHash);
204 if(g_Git.IsInitRepos())
206 g_Git.GetInitAddList(pRev->GetFiles(this));
209 else
211 g_Git.GetCommitDiffList(pRev->m_CommitHash.ToString(),this->m_HeadHash.ToString(), pRev->GetFiles(this));
213 pRev->GetAction(this) = 0;
215 for(int j=0;j< pRev->GetFiles(this).GetCount();j++)
216 pRev->GetAction(this) |= pRev->GetFiles(this)[j].m_Action;
218 InterlockedExchange(&pRev->m_IsDiffFiles, TRUE);
219 InterlockedExchange(&pRev->m_IsFull, TRUE);
221 pRev->GetBody().Format(IDS_FILESCHANGES, pRev->GetFiles(this).GetCount());
222 ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)0,0);
223 this->GetParent()->PostMessage(WM_COMMAND, MSG_FETCHED_DIFF, 0);
226 if(!pRev->CheckAndDiff())
227 { // fetch change file list
228 for(int i=GetTopIndex(); !m_AsyncThreadExit && i <= GetTopIndex()+GetCountPerPage(); i++)
230 if(i < m_arShownList.GetCount())
232 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(i);
233 if(data->m_CommitHash == pRev->m_CommitHash)
235 ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)i,0);
236 break;
241 if(!m_AsyncThreadExit && GetSelectedCount() == 1)
243 POSITION pos = GetFirstSelectedItemPosition();
244 int nItem = GetNextSelectedItem(pos);
246 if(nItem>=0)
248 GitRev* data = (GitRev*)m_arShownList[nItem];
249 if(data)
250 if(data->m_CommitHash == pRev->m_CommitHash)
252 this->GetParent()->PostMessage(WM_COMMAND, MSG_FETCHED_DIFF, 0);
259 m_AsyncThreadExited = true;
260 return 0;
262 void CGitLogListBase::hideFromContextMenu(unsigned __int64 hideMask, bool exclusivelyShow)
264 if (exclusivelyShow)
266 m_ContextMenuMask &= hideMask;
268 else
270 m_ContextMenuMask &= ~hideMask;
274 CGitLogListBase::~CGitLogListBase()
276 InterlockedExchange(&m_bNoDispUpdates, TRUE);
277 this->m_arShownList.SafeRemoveAll();
279 DestroyIcon(m_hModifiedIcon);
280 DestroyIcon(m_hReplacedIcon);
281 DestroyIcon(m_hAddedIcon);
282 DestroyIcon(m_hDeletedIcon);
283 m_logEntries.ClearAll();
285 if (m_boldFont)
286 DeleteObject(m_boldFont);
288 if ( m_pStoreSelection )
290 delete m_pStoreSelection;
291 m_pStoreSelection = NULL;
294 SafeTerminateThread();
295 SafeTerminateAsyncDiffThread();
297 if(m_AsyncDiffEvent)
298 CloseHandle(m_AsyncDiffEvent);
302 BEGIN_MESSAGE_MAP(CGitLogListBase, CHintListCtrl)
303 ON_REGISTERED_MESSAGE(m_FindDialogMessage, OnFindDialogMessage)
304 ON_REGISTERED_MESSAGE(m_ScrollToMessage, OnScrollToMessage)
305 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnNMCustomdrawLoglist)
306 ON_NOTIFY_REFLECT(LVN_GETDISPINFO, OnLvnGetdispinfoLoglist)
307 ON_WM_CONTEXTMENU()
308 ON_NOTIFY_REFLECT(NM_DBLCLK, OnNMDblclkLoglist)
309 ON_NOTIFY_REFLECT(LVN_ODFINDITEM,OnLvnOdfinditemLoglist)
310 ON_WM_CREATE()
311 ON_WM_DESTROY()
312 ON_MESSAGE(MSG_LOADED,OnLoad)
313 ON_WM_MEASUREITEM()
314 ON_WM_MEASUREITEM_REFLECT()
315 ON_NOTIFY(HDN_BEGINTRACKA, 0, OnHdnBegintrack)
316 ON_NOTIFY(HDN_BEGINTRACKW, 0, OnHdnBegintrack)
317 ON_NOTIFY(HDN_ITEMCHANGINGA, 0, OnHdnItemchanging)
318 ON_NOTIFY(HDN_ITEMCHANGINGW, 0, OnHdnItemchanging)
319 ON_NOTIFY(HDN_ENDTRACK, 0, OnColumnResized)
320 ON_NOTIFY(HDN_ENDDRAG, 0, OnColumnMoved)
321 END_MESSAGE_MAP()
323 void CGitLogListBase::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
325 //if (m_nRowHeight>0)
327 lpMeasureItemStruct->itemHeight = 50;
331 int CGitLogListBase:: OnCreate(LPCREATESTRUCT lpCreateStruct)
333 PreSubclassWindow();
334 return CHintListCtrl::OnCreate(lpCreateStruct);
337 void CGitLogListBase::PreSubclassWindow()
339 SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_SUBITEMIMAGES);
340 // load the icons for the action columns
341 // m_Theme.Open(m_hWnd, L"ListView");
342 SetWindowTheme(m_hWnd, L"Explorer", NULL);
343 CHintListCtrl::PreSubclassWindow();
346 void CGitLogListBase::InsertGitColumn()
348 CString temp;
350 CRegDWORD regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE);
351 DWORD exStyle = LVS_EX_HEADERDRAGDROP | LVS_EX_DOUBLEBUFFER | LVS_EX_INFOTIP | LVS_EX_SUBITEMIMAGES;
352 if (DWORD(regFullRowSelect))
353 exStyle |= LVS_EX_FULLROWSELECT;
354 SetExtendedStyle(exStyle);
356 UpdateProjectProperties();
358 static UINT normal[] =
360 IDS_LOG_GRAPH,
361 IDS_LOG_REBASE,
362 IDS_LOG_ID,
363 IDS_LOG_HASH,
364 IDS_LOG_ACTIONS,
365 IDS_LOG_MESSAGE,
366 IDS_LOG_AUTHOR,
367 IDS_LOG_DATE,
368 IDS_LOG_EMAIL,
369 IDS_LOG_COMMIT_NAME,
370 IDS_LOG_COMMIT_EMAIL,
371 IDS_LOG_COMMIT_DATE,
372 IDS_LOG_BUGIDS,
375 static int with[] =
377 ICONITEMBORDER+16*4,
378 ICONITEMBORDER+16*4,
379 ICONITEMBORDER+16*4,
380 ICONITEMBORDER+16*4,
381 ICONITEMBORDER+16*4,
382 LOGLIST_MESSAGE_MIN,
383 ICONITEMBORDER+16*4,
384 ICONITEMBORDER+16*4,
385 ICONITEMBORDER+16*4,
386 ICONITEMBORDER+16*4,
387 ICONITEMBORDER+16*4,
388 ICONITEMBORDER+16*4,
389 ICONITEMBORDER+16*4,
391 m_dwDefaultColumns = GIT_LOG_GRAPH|GIT_LOG_ACTIONS|GIT_LOG_MESSAGE|GIT_LOG_AUTHOR|GIT_LOG_DATE;
393 DWORD hideColumns = 0;
394 if(this->m_IsRebaseReplaceGraph)
396 hideColumns |= GIT_LOG_GRAPH;
397 m_dwDefaultColumns |= GIT_LOG_REBASE;
399 else
401 hideColumns |= GIT_LOG_REBASE;
404 if(this->m_IsIDReplaceAction)
406 hideColumns |= GIT_LOG_ACTIONS;
407 m_dwDefaultColumns |= GIT_LOG_ID;
408 m_dwDefaultColumns |= GIT_LOG_HASH;
410 else
412 hideColumns |= GIT_LOG_ID;
414 if(this->m_bShowBugtraqColumn)
416 m_dwDefaultColumns |= GIT_LOGLIST_BUG;
418 else
420 hideColumns |= GIT_LOGLIST_BUG;
422 SetRedraw(false);
424 m_ColumnManager.SetNames(normal, _countof(normal));
425 m_ColumnManager.ReadSettings(m_dwDefaultColumns, hideColumns, m_ColumnRegKey+_T("loglist"), _countof(normal), with);
427 SetRedraw(true);
432 * Resizes all columns in a list control to values in registry.
434 void CGitLogListBase::ResizeAllListCtrlCols()
436 // column max and min widths to allow
437 static const int nMinimumWidth = 10;
438 static const int nMaximumWidth = 1000;
439 CHeaderCtrl* pHdrCtrl = (CHeaderCtrl*)(GetDlgItem(0));
440 if (pHdrCtrl)
442 int numcols = pHdrCtrl->GetItemCount();
443 for (int col = 0; col < numcols; col++)
445 // get width for this col last time from registry
446 CString regentry;
447 regentry.Format( _T("Software\\TortoiseGit\\%s\\ColWidth%d"),m_ColumnRegKey, col);
448 CRegDWORD regwidth(regentry, 0);
449 int cx = regwidth;
450 if ( cx == 0 )
452 // no saved value, setup sensible defaults
453 if (col == this->LOGLIST_MESSAGE)
455 cx = LOGLIST_MESSAGE_MIN;
457 else
459 cx = ICONITEMBORDER+16*4;
462 if (cx < nMinimumWidth)
464 cx = nMinimumWidth;
466 else if (cx > nMaximumWidth)
468 cx = nMaximumWidth;
471 SetColumnWidth(col, cx);
478 BOOL CGitLogListBase::GetShortName(CString ref, CString &shortname,CString prefix)
480 //TRACE(_T("%s %s\r\n"),ref,prefix);
481 if(ref.Left(prefix.GetLength()) == prefix)
483 shortname = ref.Right(ref.GetLength()-prefix.GetLength());
484 if(shortname.Right(3)==_T("^{}"))
485 shortname=shortname.Left(shortname.GetLength()-3);
486 return TRUE;
488 return FALSE;
491 void CGitLogListBase::FillBackGround(HDC hdc, DWORD_PTR Index, CRect &rect)
493 LVITEM rItem;
494 SecureZeroMemory(&rItem, sizeof(LVITEM));
495 rItem.mask = LVIF_STATE;
496 rItem.iItem = (int)Index;
497 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
498 GetItem(&rItem);
500 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(Index);
501 HBRUSH brush = NULL;
503 if (!(rItem.state & LVIS_SELECTED))
505 if(pLogEntry->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_SQUASH)
506 brush = ::CreateSolidBrush(RGB(156,156,156));
507 else if(pLogEntry->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_EDIT)
508 brush = ::CreateSolidBrush(RGB(200,200,128));
510 else if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
512 if (rItem.state & LVIS_SELECTED)
514 if (::GetFocus() == m_hWnd)
515 brush = ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT));
516 else
517 brush = ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE));
521 if (brush != NULL)
523 ::FillRect(hdc, &rect, brush);
524 ::DeleteObject(brush);
528 void CGitLogListBase::DrawTagBranch(HDC hdc,CRect &rect,INT_PTR index)
530 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(index);
531 CRect rt=rect;
532 LVITEM rItem;
533 SecureZeroMemory(&rItem, sizeof(LVITEM));
534 rItem.mask = LVIF_STATE;
535 rItem.iItem = (int)index;
536 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
537 GetItem(&rItem);
539 CDC W_Dc;
540 W_Dc.Attach(hdc);
542 HTHEME hTheme = NULL;
543 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
544 hTheme = OpenThemeData(m_hWnd, L"Explorer::ListView;ListView");
546 for(unsigned int i=0;i<m_HashMap[data->m_CommitHash].size();i++)
548 CString str;
549 str=m_HashMap[data->m_CommitHash][i];
551 CString shortname;
552 HBRUSH brush = 0;
553 shortname = _T("");
554 COLORREF colRef = 0;
556 //Determine label color
557 if(GetShortName(str,shortname,_T("refs/heads/")))
559 if( shortname == m_CurrentBranch )
560 colRef = m_Colors.GetColor(CColors::CurrentBranch);
561 else
562 colRef = m_Colors.GetColor(CColors::LocalBranch);
565 else if(GetShortName(str,shortname,_T("refs/remotes/")))
567 colRef = m_Colors.GetColor(CColors::RemoteBranch);
569 else if(GetShortName(str,shortname,_T("refs/tags/")))
571 colRef = m_Colors.GetColor(CColors::Tag);
573 else if(GetShortName(str,shortname,_T("refs/stash")))
575 colRef = m_Colors.GetColor(CColors::Stash);
576 shortname=_T("stash");
578 else if(GetShortName(str,shortname,_T("refs/bisect/")))
580 if(shortname.Find(_T("good")) == 0)
582 colRef = m_Colors.GetColor(CColors::BisectGood);
583 shortname = _T("good");
586 if(shortname.Find(_T("bad")) == 0)
588 colRef = m_Colors.GetColor(CColors::BisectBad);
589 shortname = _T("bad");
593 //When row selected, ajust label color
594 if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
595 if (rItem.state & LVIS_SELECTED)
596 colRef = CColors::MixColors(colRef, ::GetSysColor(COLOR_HIGHLIGHT), 150);
598 brush = ::CreateSolidBrush(colRef);
600 if(!shortname.IsEmpty() && (rt.left<rect.right) )
602 SIZE size;
603 memset(&size,0,sizeof(SIZE));
604 GetTextExtentPoint32(hdc, shortname,shortname.GetLength(),&size);
606 rt.SetRect(rt.left,rt.top,rt.left+size.cx,rt.bottom);
607 rt.right+=8;
609 int textpos = DT_CENTER;
611 if(rt.right > rect.right)
613 rt.right = rect.right;
614 textpos =0;
617 //Fill interior of ref label
618 ::FillRect(hdc, &rt, brush);
620 //Draw edge of label
622 CRect rectEdge = rt;
624 W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef,100), m_Colors.Darken(colRef,100));
625 rectEdge.DeflateRect(1,1);
626 W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef,50), m_Colors.Darken(colRef,50));
628 //Draw text inside label
629 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
631 int txtState = LISS_NORMAL;
632 if (rItem.state & LVIS_SELECTED)
633 txtState = LISS_SELECTED;
635 DrawThemeText(hTheme,hdc, LVP_LISTITEM, txtState, shortname, -1, textpos | DT_SINGLELINE | DT_VCENTER, 0, &rt);
637 else
639 W_Dc.SetBkMode(TRANSPARENT);
640 if (rItem.state & LVIS_SELECTED)
642 COLORREF clrNew = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
643 COLORREF clrOld = ::SetTextColor(hdc,clrNew);
644 ::DrawText(hdc,shortname,shortname.GetLength(),&rt,textpos | DT_SINGLELINE | DT_VCENTER);
645 ::SetTextColor(hdc,clrOld);
647 else
649 ::DrawText(hdc,shortname,shortname.GetLength(),&rt,textpos | DT_SINGLELINE | DT_VCENTER);
653 //::MoveToEx(hdc,rt.left,rt.top,NULL);
654 //::LineTo(hdc,rt.right,rt.top);
655 //::LineTo(hdc,rt.right,rt.bottom);
656 //::LineTo(hdc,rt.left,rt.bottom);
657 //::LineTo(hdc,rt.left,rt.top);
659 rt.left=rt.right+1;
661 if(brush)
662 ::DeleteObject(brush);
664 rt.right=rect.right;
666 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
668 int txtState = LISS_NORMAL;
669 if (rItem.state & LVIS_SELECTED)
670 txtState = LISS_SELECTED;
672 DrawThemeText(hTheme,hdc, LVP_LISTITEM, txtState, data->GetSubject(), -1, DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS, 0, &rt);
674 else
676 if (rItem.state & LVIS_SELECTED)
678 COLORREF clrOld = ::SetTextColor(hdc,::GetSysColor(COLOR_HIGHLIGHTTEXT));
679 ::DrawText(hdc,data->GetSubject(),data->GetSubject().GetLength(),&rt,DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS);
680 ::SetTextColor(hdc,clrOld);
682 else
684 ::DrawText(hdc,data->GetSubject(),data->GetSubject().GetLength(),&rt,DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS);
688 if (hTheme)
689 CloseThemeData(hTheme);
691 W_Dc.Detach();
694 static COLORREF blend(const COLORREF& col1, const COLORREF& col2, int amount = 128) {
696 // Returns ((256 - amount)*col1 + amount*col2) / 256;
697 return RGB(((256 - amount)*GetRValue(col1) + amount*GetRValue(col2) ) / 256,
698 ((256 - amount)*GetGValue(col1) + amount*GetGValue(col2) ) / 256,
699 ((256 - amount)*GetBValue(col1) + amount*GetBValue(col2) ) / 256);
702 Gdiplus::Color GetGdiColor(COLORREF col)
704 return Gdiplus::Color(GetRValue(col),GetGValue(col),GetBValue(col));
706 void CGitLogListBase::paintGraphLane(HDC hdc, int laneHeight,int type, int x1, int x2,
707 const COLORREF& col,const COLORREF& activeColor, int top
710 int h = laneHeight / 2;
711 int m = (x1 + x2) / 2;
712 int r = (x2 - x1) / 3;
713 int d = 2 * r;
715 #define P_CENTER m , h+top
716 #define P_0 x2, h+top
717 #define P_90 m , 0+top-1
718 #define P_180 x1, h+top
719 #define P_270 m , 2 * h+top +1
720 #define R_CENTER m - r, h - r+top, d, d
723 #define DELTA_UR_B 2*(x1 - m), 2*h +top
724 #define DELTA_UR_E 0*16, 90*16 +top // -,
726 #define DELTA_DR_B 2*(x1 - m), 2*-h +top
727 #define DELTA_DR_E 270*16, 90*16 +top // -'
729 #define DELTA_UL_B 2*(x2 - m), 2*h +top
730 #define DELTA_UL_E 90*16, 90*16 +top // ,-
732 #define DELTA_DL_B 2*(x2 - m),2*-h +top
733 #define DELTA_DL_E 180*16, 90*16 // '-
735 #define CENTER_UR x1, 2*h, 225
736 #define CENTER_DR x1, 0 , 135
737 #define CENTER_UL x2, 2*h, 315
738 #define CENTER_DL x2, 0 , 45
741 Gdiplus::Graphics graphics( hdc );
743 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
745 // arc
746 switch (type) {
747 case Lanes::JOIN:
748 case Lanes::JOIN_R:
749 case Lanes::HEAD:
750 case Lanes::HEAD_R:
752 Gdiplus::LinearGradientBrush gradient(
753 Gdiplus::Point(x1-2, h+top-2),
754 Gdiplus::Point(P_270),
755 GetGdiColor(activeColor),GetGdiColor(col));
758 Gdiplus::Pen mypen(&gradient,2);
759 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
761 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
762 graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top+h-1, x2-x1,laneHeight,270,90);
763 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
765 break;
767 case Lanes::JOIN_L:
770 Gdiplus::LinearGradientBrush gradient(
771 Gdiplus::Point(P_270),
772 Gdiplus::Point(x2+1, h+top-1),
773 GetGdiColor(col),GetGdiColor(activeColor));
776 Gdiplus::Pen mypen(&gradient,2);
777 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
779 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
780 graphics.DrawArc(&mypen,x1+(x2-x1)/2,top+h-1, x2-x1,laneHeight,180,90);
781 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
784 break;
786 case Lanes::TAIL:
787 case Lanes::TAIL_R:
790 Gdiplus::LinearGradientBrush gradient(
791 Gdiplus::Point(x1-2, h+top-2),
792 Gdiplus::Point(P_90),
793 GetGdiColor(activeColor),GetGdiColor(col));
795 Gdiplus::Pen mypen(&gradient,2);
797 graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top-h-1, x2-x1,laneHeight,0,90);
799 #if 0
800 QConicalGradient gradient(CENTER_DR);
801 gradient.setColorAt(0.375, activeCol);
802 gradient.setColorAt(0.625, col);
803 myPen.setBrush(gradient);
804 p->setPen(myPen);
805 p->drawArc(P_CENTER, DELTA_DR);
806 #endif
807 break;
809 default:
810 break;
814 //static QPen myPen(Qt::black, 2); // fast path here
815 CPen pen;
816 pen.CreatePen(PS_SOLID,2,col);
817 //myPen.setColor(col);
818 HPEN oldpen=(HPEN)::SelectObject(hdc,(HPEN)pen);
820 Gdiplus::Pen myPen(GetGdiColor(col),2);
822 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
824 //p->setPen(myPen);
826 // vertical line
827 switch (type) {
828 case Lanes::ACTIVE:
829 case Lanes::NOT_ACTIVE:
830 case Lanes::MERGE_FORK:
831 case Lanes::MERGE_FORK_R:
832 case Lanes::MERGE_FORK_L:
833 case Lanes::JOIN:
834 case Lanes::JOIN_R:
835 case Lanes::JOIN_L:
836 case Lanes::CROSS:
837 //DrawLine(hdc,P_90,P_270);
838 graphics.DrawLine(&myPen,P_90,P_270);
839 //p->drawLine(P_90, P_270);
840 break;
841 case Lanes::HEAD_L:
842 case Lanes::BRANCH:
843 //DrawLine(hdc,P_CENTER,P_270);
844 graphics.DrawLine(&myPen,P_CENTER,P_270);
845 //p->drawLine(P_CENTER, P_270);
846 break;
847 case Lanes::TAIL_L:
848 case Lanes::INITIAL:
849 case Lanes::BOUNDARY:
850 case Lanes::BOUNDARY_C:
851 case Lanes::BOUNDARY_R:
852 case Lanes::BOUNDARY_L:
853 //DrawLine(hdc,P_90, P_CENTER);
854 graphics.DrawLine(&myPen,P_90,P_CENTER);
855 //p->drawLine(P_90, P_CENTER);
856 break;
857 default:
858 break;
861 myPen.SetColor(GetGdiColor(activeColor));
863 // horizontal line
864 switch (type) {
865 case Lanes::MERGE_FORK:
866 case Lanes::JOIN:
867 case Lanes::HEAD:
868 case Lanes::TAIL:
869 case Lanes::CROSS:
870 case Lanes::CROSS_EMPTY:
871 case Lanes::BOUNDARY_C:
872 //DrawLine(hdc,P_180,P_0);
873 graphics.DrawLine(&myPen,P_180,P_0);
874 //p->drawLine(P_180, P_0);
875 break;
876 case Lanes::MERGE_FORK_R:
877 case Lanes::BOUNDARY_R:
878 //DrawLine(hdc,P_180,P_CENTER);
879 graphics.DrawLine(&myPen,P_180,P_CENTER);
880 //p->drawLine(P_180, P_CENTER);
881 break;
882 case Lanes::MERGE_FORK_L:
883 case Lanes::HEAD_L:
884 case Lanes::TAIL_L:
885 case Lanes::BOUNDARY_L:
886 //DrawLine(hdc,P_CENTER,P_0);
887 graphics.DrawLine(&myPen,P_CENTER,P_0);
888 //p->drawLine(P_CENTER, P_0);
889 break;
890 default:
891 break;
894 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
896 CBrush brush;
897 brush.CreateSolidBrush(col);
898 HBRUSH oldbrush=(HBRUSH)::SelectObject(hdc,(HBRUSH)brush);
900 Gdiplus::SolidBrush myBrush(GetGdiColor(col));
901 // center symbol, e.g. rect or ellipse
902 switch (type) {
903 case Lanes::ACTIVE:
904 case Lanes::INITIAL:
905 case Lanes::BRANCH:
907 //p->setPen(Qt::NoPen);
908 //p->setBrush(col);
909 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
910 graphics.FillEllipse(&myBrush, R_CENTER);
911 //p->drawEllipse(R_CENTER);
912 break;
913 case Lanes::MERGE_FORK:
914 case Lanes::MERGE_FORK_R:
915 case Lanes::MERGE_FORK_L:
916 //p->setPen(Qt::NoPen);
917 //p->setBrush(col);
918 //p->drawRect(R_CENTER);
919 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
920 graphics.FillRectangle(&myBrush, R_CENTER);
921 break;
922 case Lanes::UNAPPLIED:
923 // Red minus sign
924 //p->setPen(Qt::NoPen);
925 //p->setBrush(Qt::red);
926 //p->drawRect(m - r, h - 1, d, 2);
927 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
928 graphics.FillRectangle(&myBrush,m-r,h-1,d,2);
929 break;
930 case Lanes::APPLIED:
931 // Green plus sign
932 //p->setPen(Qt::NoPen);
933 //p->setBrush(DARK_GREEN);
934 //p->drawRect(m - r, h - 1, d, 2);
935 //p->drawRect(m - 1, h - r, 2, d);
936 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
937 graphics.FillRectangle(&myBrush,m-r,h-1,d,2);
938 graphics.FillRectangle(&myBrush,m-1,h-r,2,d);
939 break;
940 case Lanes::BOUNDARY:
941 //p->setBrush(back);
942 //p->drawEllipse(R_CENTER);
943 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
944 graphics.DrawEllipse(&myPen, R_CENTER);
945 break;
946 case Lanes::BOUNDARY_C:
947 case Lanes::BOUNDARY_R:
948 case Lanes::BOUNDARY_L:
949 //p->setBrush(back);
950 //p->drawRect(R_CENTER);
951 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
952 graphics.FillRectangle(&myBrush,R_CENTER);
953 break;
954 default:
955 break;
958 ::SelectObject(hdc,oldpen);
959 ::SelectObject(hdc,oldbrush);
960 #undef P_CENTER
961 #undef P_0
962 #undef P_90
963 #undef P_180
964 #undef P_270
965 #undef R_CENTER
968 void CGitLogListBase::DrawGraph(HDC hdc,CRect &rect,INT_PTR index)
970 // TODO: unfinished
971 // return;
972 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(index);
973 if(data->m_CommitHash.IsEmpty())
974 return;
976 CRect rt=rect;
977 LVITEM rItem;
978 SecureZeroMemory(&rItem, sizeof(LVITEM));
979 rItem.mask = LVIF_STATE;
980 rItem.iItem = (int)index;
981 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
982 GetItem(&rItem);
984 // p->translate(QPoint(opt.rect.left(), opt.rect.top()));
986 if (data->m_Lanes.empty())
987 m_logEntries.setLane(data->m_CommitHash);
989 std::vector<int>& lanes=data->m_Lanes;
990 size_t laneNum = lanes.size();
991 UINT activeLane = 0;
992 for (UINT i = 0; i < laneNum; i++)
993 if (Lanes::isMerge(lanes[i])) {
994 activeLane = i;
995 break;
998 int x1 = 0, x2 = 0;
999 int maxWidth = rect.Width();
1000 int lw = 3 * rect.Height() / 4; //laneWidth()
1002 COLORREF activeColor = m_LineColors[activeLane % Lanes::COLORS_NUM];
1003 //if (opt.state & QStyle::State_Selected)
1004 // activeColor = blend(activeColor, opt.palette.highlightedText().color(), 208);
1006 for (unsigned int i = 0; i < laneNum && x2 < maxWidth; i++)
1009 x1 = x2;
1010 x2 += lw;
1012 int ln = lanes[i];
1013 if (ln == Lanes::EMPTY)
1014 continue;
1016 COLORREF color = i == activeLane ? activeColor : m_LineColors[i % Lanes::COLORS_NUM];
1017 paintGraphLane(hdc, rect.Height(),ln, x1+rect.left, x2+rect.left, color,activeColor, rect.top);
1020 #if 0
1021 for (UINT i = 0; i < laneNum && x2 < maxWidth; i++) {
1023 x1 = x2;
1024 x2 += lw;
1026 int ln = lanes[i];
1027 if (ln == Lanes::EMPTY)
1028 continue;
1030 UINT col = ( Lanes:: isHead(ln) ||Lanes:: isTail(ln) || Lanes::isJoin(ln)
1031 || ln ==Lanes:: CROSS_EMPTY) ? activeLane : i;
1033 if (ln == Lanes::CROSS)
1035 paintGraphLane(hdc, rect.Height(),Lanes::NOT_ACTIVE, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
1036 paintGraphLane(hdc, rect.Height(),Lanes::CROSS, x1, x2, m_LineColors[activeLane % Lanes::COLORS_NUM],rect.top);
1038 else
1039 paintGraphLane(hdc, rect.Height(),ln, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
1041 #endif
1045 void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1048 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
1049 // Take the default processing unless we set this to something else below.
1050 *pResult = CDRF_DODEFAULT;
1052 if (m_bNoDispUpdates)
1053 return;
1055 switch (pLVCD->nmcd.dwDrawStage)
1057 case CDDS_PREPAINT:
1059 *pResult = CDRF_NOTIFYITEMDRAW;
1060 return;
1062 break;
1063 case CDDS_ITEMPREPAINT:
1065 // This is the prepaint stage for an item. Here's where we set the
1066 // item's text color.
1068 // Tell Windows to send draw notifications for each subitem.
1069 *pResult = CDRF_NOTIFYSUBITEMDRAW;
1071 COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);
1073 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
1075 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1076 if (data)
1078 if (data->GetAction(this)& (CTGitPath::LOGACTIONS_REBASE_DONE| CTGitPath::LOGACTIONS_REBASE_SKIP) )
1079 crText = RGB(128,128,128);
1081 if(data->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_SQUASH)
1082 pLVCD->clrTextBk = RGB(156,156,156);
1083 else if(data->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_EDIT)
1084 pLVCD->clrTextBk = RGB(200,200,128);
1085 else
1086 pLVCD->clrTextBk = ::GetSysColor(COLOR_WINDOW);
1088 if(data->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_CURRENT)
1090 SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1091 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1094 if (data->m_CommitHash == m_HeadHash && m_bNoHightlightHead == FALSE)
1096 SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1097 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1100 // if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))
1101 // crText = GetSysColor(COLOR_GRAYTEXT);
1103 if (data->m_CommitHash.IsEmpty())
1105 //crText = GetSysColor(RGB(200,200,0));
1106 //SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1107 // We changed the font, so we're returning CDRF_NEWFONT. This
1108 // tells the control to recalculate the extent of the text.
1109 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1113 if (m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec)
1115 if (m_bStrictStopped)
1116 crText = GetSysColor(COLOR_GRAYTEXT);
1118 // Store the color back in the NMLVCUSTOMDRAW struct.
1119 pLVCD->clrText = crText;
1120 return;
1122 break;
1123 case CDDS_ITEMPREPAINT|CDDS_ITEM|CDDS_SUBITEM:
1125 if ((m_bStrictStopped)&&(m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec))
1127 pLVCD->nmcd.uItemState &= ~(CDIS_SELECTED|CDIS_FOCUS);
1130 if (pLVCD->iSubItem == LOGLIST_GRAPH && m_sFilterText.IsEmpty())
1132 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec && (!this->m_IsRebaseReplaceGraph) )
1134 CRect rect;
1135 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_LABEL, rect);
1137 //TRACE(_T("A Graphic left %d right %d\r\n"),rect.left,rect.right);
1138 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec,rect);
1140 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1141 if( !data ->m_CommitHash.IsEmpty())
1142 DrawGraph(pLVCD->nmcd.hdc,rect,pLVCD->nmcd.dwItemSpec);
1144 *pResult = CDRF_SKIPDEFAULT;
1145 return;
1149 if (pLVCD->iSubItem == LOGLIST_MESSAGE)
1151 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
1153 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1154 //if(!data->m_IsFull)
1156 //if(data->SafeFetchFullInfo(&g_Git))
1157 // this->Invalidate();
1158 //TRACE(_T("Update ... %d\r\n"),pLVCD->nmcd.dwItemSpec);
1161 if (!m_HashMap[data->m_CommitHash].empty())
1163 CRect rect;
1165 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
1167 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec,rect);
1168 DrawTagBranch(pLVCD->nmcd.hdc,rect,pLVCD->nmcd.dwItemSpec);
1170 *pResult = CDRF_SKIPDEFAULT;
1171 return;
1178 if (pLVCD->iSubItem == LOGLIST_ACTION)
1180 if(this->m_IsIDReplaceAction)
1182 *pResult = CDRF_DODEFAULT;
1183 return;
1185 *pResult = CDRF_DODEFAULT;
1187 if (m_arShownList.GetCount() <= (INT_PTR)pLVCD->nmcd.dwItemSpec)
1188 return;
1190 int nIcons = 0;
1191 int iconwidth = ::GetSystemMetrics(SM_CXSMICON);
1192 int iconheight = ::GetSystemMetrics(SM_CYSMICON);
1194 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec));
1195 CRect rect;
1196 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
1197 //TRACE(_T("Action left %d right %d\r\n"),rect.left,rect.right);
1198 // Get the selected state of the
1199 // item being drawn.
1201 // Fill the background if necessary
1202 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec, rect);
1204 // Draw the icon(s) into the compatible DC
1205 pLogEntry->GetAction(this);
1207 if (!pLogEntry->m_IsDiffFiles)
1208 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hFetchIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1210 if (pLogEntry->GetAction(this) & CTGitPath::LOGACTIONS_MODIFIED)
1211 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hModifiedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1212 nIcons++;
1214 if (pLogEntry->GetAction(this) & (CTGitPath::LOGACTIONS_ADDED|CTGitPath::LOGACTIONS_COPY) )
1215 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hAddedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1216 nIcons++;
1218 if (pLogEntry->GetAction(this) & CTGitPath::LOGACTIONS_DELETED)
1219 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hDeletedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1220 nIcons++;
1222 if (pLogEntry->GetAction(this) & CTGitPath::LOGACTIONS_REPLACED)
1223 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hReplacedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1224 nIcons++;
1225 *pResult = CDRF_SKIPDEFAULT;
1226 return;
1229 break;
1231 *pResult = CDRF_DODEFAULT;
1234 // CGitLogListBase message handlers
1236 void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1238 NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
1240 // Create a pointer to the item
1241 LV_ITEM* pItem = &(pDispInfo)->item;
1243 // Do the list need text information?
1244 if (!(pItem->mask & LVIF_TEXT))
1245 return;
1247 // By default, clear text buffer.
1248 lstrcpyn(pItem->pszText, _T(""), pItem->cchTextMax);
1250 bool bOutOfRange = pItem->iItem >= ShownCountWithStopped();
1252 *pResult = 0;
1253 if (m_bNoDispUpdates || bOutOfRange)
1254 return;
1256 // Which item number?
1257 int itemid = pItem->iItem;
1258 GitRev * pLogEntry = NULL;
1259 if (itemid < m_arShownList.GetCount())
1260 pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(pItem->iItem));
1262 CString temp;
1263 if(m_IsOldFirst)
1265 temp.Format(_T("%d"),pItem->iItem+1);
1268 else
1270 temp.Format(_T("%d"),m_arShownList.GetCount()-pItem->iItem);
1273 // Which column?
1274 switch (pItem->iSubItem)
1276 case this->LOGLIST_GRAPH: //Graphic
1277 break;
1278 case this->LOGLIST_REBASE:
1280 if(this->m_IsRebaseReplaceGraph)
1282 CTGitPath path;
1283 path.m_Action=pLogEntry->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_MODE_MASK;
1284 lstrcpyn(pItem->pszText,path.GetActionName(), pItem->cchTextMax);
1287 break;
1288 case this->LOGLIST_ACTION: //action -- no text in the column
1289 break;
1290 case this->LOGLIST_HASH:
1291 if(pLogEntry)
1292 lstrcpyn(pItem->pszText, pLogEntry->m_CommitHash.ToString(), pItem->cchTextMax);
1293 break;
1294 case this->LOGLIST_ID:
1295 if(this->m_IsIDReplaceAction)
1296 lstrcpyn(pItem->pszText, temp, pItem->cchTextMax);
1297 break;
1298 case this->LOGLIST_MESSAGE: //Message
1299 if (pLogEntry)
1300 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetSubject(), pItem->cchTextMax);
1301 break;
1302 case this->LOGLIST_AUTHOR: //Author
1303 if (pLogEntry)
1304 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetAuthorName(), pItem->cchTextMax);
1305 break;
1306 case this->LOGLIST_DATE: //Date
1307 if ( pLogEntry && (!pLogEntry->m_CommitHash.IsEmpty()) )
1308 lstrcpyn(pItem->pszText,
1309 CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
1310 pItem->cchTextMax);
1311 break;
1313 case this->LOGLIST_EMAIL:
1314 if (pLogEntry)
1315 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetAuthorEmail(), pItem->cchTextMax);
1316 break;
1318 case this->LOGLIST_COMMIT_NAME: //Commit
1319 if (pLogEntry)
1320 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetCommitterName(), pItem->cchTextMax);
1321 break;
1323 case this->LOGLIST_COMMIT_EMAIL: //Commit Email
1324 if (pLogEntry)
1325 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetCommitterEmail(), pItem->cchTextMax);
1326 break;
1328 case this->LOGLIST_COMMIT_DATE: //Commit Date
1329 if (pLogEntry && (!pLogEntry->m_CommitHash.IsEmpty()))
1330 lstrcpyn(pItem->pszText,
1331 CLoglistUtils::FormatDateAndTime(pLogEntry->GetCommitterDate(), m_DateFormat, true, m_bRelativeTimes),
1332 pItem->cchTextMax);
1333 break;
1334 case this->LOGLIST_BUG: //Bug ID
1335 if(pLogEntry)
1336 lstrcpyn(pItem->pszText, (LPCTSTR)this->m_ProjectProperties.FindBugID(pLogEntry->GetSubject() + _T("\r\n\r\n") + pLogEntry->GetBody()), pItem->cchTextMax);
1337 break;
1339 default:
1340 ASSERT(false);
1344 void CGitLogListBase::OnContextMenu(CWnd* pWnd, CPoint point)
1347 if (pWnd == GetHeaderCtrl())
1349 return m_ColumnManager.OnContextMenuHeader(pWnd,point,!!IsGroupViewEnabled());
1352 int selIndex = GetSelectionMark();
1353 if (selIndex < 0)
1354 return; // nothing selected, nothing to do with a context menu
1356 // if the user selected the info text telling about not all revisions shown due to
1357 // the "stop on copy/rename" option, we also don't show the context menu
1358 if ((m_bStrictStopped)&&(selIndex == m_arShownList.GetCount()))
1359 return;
1361 // if the context menu is invoked through the keyboard, we have to use
1362 // a calculated position on where to anchor the menu on
1363 if ((point.x == -1) && (point.y == -1))
1365 CRect rect;
1366 GetItemRect(selIndex, &rect, LVIR_LABEL);
1367 ClientToScreen(&rect);
1368 point = rect.CenterPoint();
1370 m_nSearchIndex = selIndex;
1371 m_bCancelled = FALSE;
1373 // calculate some information the context menu commands can use
1374 // CString pathURL = GetURLFromPath(m_path);
1376 POSITION pos = GetFirstSelectedItemPosition();
1377 int indexNext = GetNextSelectedItem(pos);
1378 if (indexNext < 0)
1379 return;
1381 GitRev* pSelLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(indexNext));
1382 #if 0
1383 GitRev revSelected = pSelLogEntry->Rev;
1384 GitRev revPrevious = git_revnum_t(revSelected)-1;
1385 if ((pSelLogEntry->pArChangedPaths)&&(pSelLogEntry->pArChangedPaths->GetCount() <= 2))
1387 for (int i=0; i<pSelLogEntry->pArChangedPaths->GetCount(); ++i)
1389 LogChangedPath * changedpath = (LogChangedPath *)pSelLogEntry->pArChangedPaths->SafeGetAt(i);
1390 if (changedpath->lCopyFromRev)
1391 revPrevious = changedpath->lCopyFromRev;
1394 GitRev revSelected2;
1395 if (pos)
1397 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1398 revSelected2 = pLogEntry->Rev;
1400 bool bAllFromTheSameAuthor = true;
1401 CString firstAuthor;
1402 CLogDataVector selEntries;
1403 GitRev revLowest, revHighest;
1404 GitRevRangeArray revisionRanges;
1406 POSITION pos = GetFirstSelectedItemPosition();
1407 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1408 revisionRanges.AddRevision(pLogEntry->Rev);
1409 selEntries.push_back(pLogEntry);
1410 firstAuthor = pLogEntry->sAuthor;
1411 revLowest = pLogEntry->Rev;
1412 revHighest = pLogEntry->Rev;
1413 while (pos)
1415 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1416 revisionRanges.AddRevision(pLogEntry->Rev);
1417 selEntries.push_back(pLogEntry);
1418 if (firstAuthor.Compare(pLogEntry->sAuthor))
1419 bAllFromTheSameAuthor = false;
1420 revLowest = (git_revnum_t(pLogEntry->Rev) > git_revnum_t(revLowest) ? revLowest : pLogEntry->Rev);
1421 revHighest = (git_revnum_t(pLogEntry->Rev) < git_revnum_t(revHighest) ? revHighest : pLogEntry->Rev);
1425 #endif
1427 int FirstSelect=-1, LastSelect=-1;
1428 pos = GetFirstSelectedItemPosition();
1429 FirstSelect = GetNextSelectedItem(pos);
1430 while(pos)
1432 LastSelect = GetNextSelectedItem(pos);
1434 //entry is selected, now show the popup menu
1435 CIconMenu popup;
1436 CIconMenu subbranchmenu, submenu, gnudiffmenu, diffmenu, revertmenu;
1438 if (popup.CreatePopupMenu())
1440 bool isHeadCommit = (pSelLogEntry->m_CommitHash == m_HeadHash);
1441 CString currentBranch = _T("refs/heads/") + g_Git.GetCurrentBranch();
1443 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_PICK))
1444 popup.AppendMenuIcon(ID_REBASE_PICK, IDS_REBASE_PICK, IDI_PICK);
1446 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_SQUASH))
1447 popup.AppendMenuIcon(ID_REBASE_SQUASH, IDS_REBASE_SQUASH, IDI_SQUASH);
1449 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_EDIT))
1450 popup.AppendMenuIcon(ID_REBASE_EDIT, IDS_REBASE_EDIT, IDI_EDIT);
1452 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_SKIP))
1453 popup.AppendMenuIcon(ID_REBASE_SKIP, IDS_REBASE_SKIP, IDI_SKIP);
1455 if(m_ContextMenuMask&(GetContextMenuBit(ID_REBASE_SKIP)|GetContextMenuBit(ID_REBASE_EDIT)|
1456 GetContextMenuBit(ID_REBASE_SQUASH)|GetContextMenuBit(ID_REBASE_PICK)))
1457 popup.AppendMenu(MF_SEPARATOR, NULL);
1459 if (GetSelectedCount() == 1)
1463 if( !pSelLogEntry->m_CommitHash.IsEmpty())
1465 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARE) && m_hasWC) // compare revision with WC
1466 popup.AppendMenuIcon(ID_COMPARE, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1468 else
1470 if(m_ContextMenuMask&GetContextMenuBit(ID_COMMIT))
1471 popup.AppendMenuIcon(ID_COMMIT, IDS_LOG_POPUP_COMMIT, IDI_COMMIT);
1473 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF1) && m_hasWC) // compare with WC, unified
1475 GitRev *pRev=pSelLogEntry;
1476 if (pSelLogEntry->m_ParentHash.empty())
1478 pRev->GetParentFromHash(pRev->m_CommitHash);
1480 if(pRev->m_ParentHash.size()<=1)
1482 popup.AppendMenuIcon(ID_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF_CH, IDI_DIFF);
1485 else
1487 gnudiffmenu.CreatePopupMenu();
1488 popup.AppendMenuIcon(ID_GNUDIFF1,IDS_LOG_POPUP_GNUDIFF_PARENT, IDI_DIFF, gnudiffmenu.m_hMenu);
1490 gnudiffmenu.AppendMenuIcon((UINT_PTR)(ID_GNUDIFF1 + (0xFFFF << 16)), CString(MAKEINTRESOURCE(IDS_ALLPARENTS)));
1491 gnudiffmenu.AppendMenuIcon((UINT_PTR)(ID_GNUDIFF1 + (0xFFFE << 16)), CString(MAKEINTRESOURCE(IDS_ONLYMERGEDFILES)));
1493 for(int i=0;i<pRev->m_ParentHash.size();i++)
1495 CString str;
1496 str.Format(IDS_PARENT, i + 1);
1497 gnudiffmenu.AppendMenuIcon(ID_GNUDIFF1+((i+1)<<16),str);
1502 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPAREWITHPREVIOUS))
1505 GitRev *pRev=pSelLogEntry;
1506 if (pSelLogEntry->m_ParentHash.empty())
1508 pRev->GetParentFromHash(pRev->m_CommitHash);
1510 if(pRev->m_ParentHash.size()<=1)
1512 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF);
1513 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1514 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
1516 else
1518 diffmenu.CreatePopupMenu();
1519 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF, diffmenu.m_hMenu);
1520 for(int i=0;i<pRev->m_ParentHash.size();i++)
1522 CString str;
1523 str.Format(IDS_PARENT, i + 1);
1524 diffmenu.AppendMenuIcon(ID_COMPAREWITHPREVIOUS +((i+1)<<16),str);
1525 if (i == 0 && CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1527 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
1528 diffmenu.SetDefaultItem(ID_COMPAREWITHPREVIOUS +((i+1)<<16), FALSE);
1534 if(m_ContextMenuMask&GetContextMenuBit(ID_BLAME))
1535 popup.AppendMenuIcon(ID_BLAME, IDS_LOG_POPUP_BLAME, IDI_BLAME);
1537 //popup.AppendMenuIcon(ID_BLAMEWITHPREVIOUS, IDS_LOG_POPUP_BLAMEWITHPREVIOUS, IDI_BLAME);
1538 popup.AppendMenu(MF_SEPARATOR, NULL);
1540 if (pSelLogEntry->m_CommitHash.IsEmpty())
1542 if(m_ContextMenuMask&GetContextMenuBit(ID_STASH_SAVE))
1543 popup.AppendMenuIcon(ID_STASH_SAVE, IDS_MENUSTASHSAVE, IDI_COMMIT);
1546 bool isStash = false;
1547 for (int i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); i++)
1549 if (m_HashMap[pSelLogEntry->m_CommitHash][i] == _T("refs/stash"))
1551 isStash = true;
1552 break;
1556 if (CTGitPath(g_Git.m_CurrentDir).HasStashDir() && (pSelLogEntry->m_CommitHash.IsEmpty() || isStash))
1558 if (m_ContextMenuMask&GetContextMenuBit(ID_STASH_POP))
1559 popup.AppendMenuIcon(ID_STASH_POP, IDS_MENUSTASHPOP, IDI_RELOCATE);
1561 if (m_ContextMenuMask&GetContextMenuBit(ID_STASH_LIST))
1562 popup.AppendMenuIcon(ID_STASH_LIST, IDS_MENUSTASHLIST, IDI_LOG);
1564 popup.AppendMenu(MF_SEPARATOR, NULL);
1567 if (pSelLogEntry->m_CommitHash.IsEmpty())
1569 if(m_ContextMenuMask&GetContextMenuBit(ID_FETCH))
1570 popup.AppendMenuIcon(ID_FETCH, IDS_MENUFETCH, IDI_PULL);
1572 popup.AppendMenu(MF_SEPARATOR, NULL);
1576 // if (!m_ProjectProperties.sWebViewerRev.IsEmpty())
1577 // {
1578 // popup.AppendMenuIcon(ID_VIEWREV, IDS_LOG_POPUP_VIEWREV);
1579 // }
1580 // if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
1581 // {
1582 // popup.AppendMenuIcon(ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
1583 // }
1584 // if ((!m_ProjectProperties.sWebViewerPathRev.IsEmpty())||
1585 // (!m_ProjectProperties.sWebViewerRev.IsEmpty()))
1586 // {
1587 // popup.AppendMenu(MF_SEPARATOR, NULL);
1588 // }
1590 CString str,format;
1591 //if (m_hasWC)
1592 // popup.AppendMenuIcon(ID_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
1594 if(!pSelLogEntry->m_CommitHash.IsEmpty())
1596 if((m_ContextMenuMask&GetContextMenuBit(ID_LOG)) &&
1597 GetSelectedCount() == 1)
1598 popup.AppendMenuIcon(ID_LOG, IDS_LOG_POPUP_LOG, IDI_LOG);
1600 if (m_ContextMenuMask&GetContextMenuBit(ID_REPOBROWSE))
1601 popup.AppendMenuIcon(ID_REPOBROWSE, IDS_LOG_BROWSEREPO, IDI_REPOBROWSE);
1603 format.LoadString(IDS_LOG_POPUP_MERGEREV);
1604 str.Format(format,g_Git.GetCurrentBranch());
1606 if (m_ContextMenuMask&GetContextMenuBit(ID_MERGEREV) && !isHeadCommit && m_hasWC)
1607 popup.AppendMenuIcon(ID_MERGEREV, str, IDI_MERGE);
1609 format.LoadString(IDS_RESET_TO_THIS_FORMAT);
1610 str.Format(format,g_Git.GetCurrentBranch());
1612 if(m_ContextMenuMask&GetContextMenuBit(ID_RESET) && m_hasWC)
1613 popup.AppendMenuIcon(ID_RESET,str,IDI_REVERT);
1616 // Add Switch Branch express Menu
1617 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end()
1618 && (m_ContextMenuMask&GetContextMenuBit(ID_SWITCHBRANCH) && m_hasWC)
1621 std::vector<CString *> branchs;
1622 for(int i=0;i<m_HashMap[pSelLogEntry->m_CommitHash].size();i++)
1624 CString ref = m_HashMap[pSelLogEntry->m_CommitHash][i];
1625 if(ref.Find(_T("refs/heads/")) == 0 && ref != currentBranch)
1627 branchs.push_back(&m_HashMap[pSelLogEntry->m_CommitHash][i]);
1631 CString str;
1632 str.LoadString(IDS_SWITCH_BRANCH);
1634 if(branchs.size() == 1)
1636 str+=_T(" ");
1637 str+= _T('"') + branchs[0]->Mid(11) + _T('"');
1638 popup.AppendMenuIcon(ID_SWITCHBRANCH,str,IDI_SWITCH);
1640 popup.SetMenuItemData(ID_SWITCHBRANCH,(ULONG_PTR)branchs[0]);
1643 else if(branchs.size() > 1)
1645 subbranchmenu.CreatePopupMenu();
1646 for(int i=0;i<branchs.size();i++)
1648 if (*branchs[i] != currentBranch)
1650 subbranchmenu.AppendMenuIcon(ID_SWITCHBRANCH+(i<<16), branchs[i]->Mid(11));
1651 subbranchmenu.SetMenuItemData(ID_SWITCHBRANCH+(i<<16), (ULONG_PTR) branchs[i]);
1655 popup.AppendMenuIcon(ID_SWITCHBRANCH, str, IDI_SWITCH, subbranchmenu.m_hMenu);
1659 if(m_ContextMenuMask&GetContextMenuBit(ID_SWITCHTOREV) && !isHeadCommit && m_hasWC)
1660 popup.AppendMenuIcon(ID_SWITCHTOREV, IDS_SWITCH_TO_THIS , IDI_SWITCH);
1662 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_BRANCH))
1663 popup.AppendMenuIcon(ID_CREATE_BRANCH, IDS_CREATE_BRANCH_AT_THIS , IDI_COPY);
1665 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_TAG))
1666 popup.AppendMenuIcon(ID_CREATE_TAG,IDS_CREATE_TAG_AT_THIS , IDI_TAG);
1668 format.LoadString(IDS_REBASE_THIS_FORMAT);
1669 str.Format(format,g_Git.GetCurrentBranch());
1671 if(pSelLogEntry->m_CommitHash != m_HeadHash && m_hasWC)
1672 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_TO_VERSION))
1673 popup.AppendMenuIcon(ID_REBASE_TO_VERSION, str , IDI_REBASE);
1675 if(m_ContextMenuMask&GetContextMenuBit(ID_EXPORT))
1676 popup.AppendMenuIcon(ID_EXPORT,IDS_EXPORT_TO_THIS, IDI_EXPORT);
1678 if (m_ContextMenuMask&GetContextMenuBit(ID_REVERTREV) && m_hasWC)
1680 GitRev *pRev = pSelLogEntry;
1681 if (pSelLogEntry->m_ParentHash.empty())
1683 pRev->GetParentFromHash(pRev->m_CommitHash);
1685 if (pRev->m_ParentHash.size() == 1)
1687 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT);
1689 else
1691 revertmenu.CreatePopupMenu();
1692 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT, revertmenu.m_hMenu);
1694 for (int i = 0; i < pRev->m_ParentHash.size(); i++)
1696 CString str;
1697 str.Format(IDS_PARENT, i + 1);
1698 revertmenu.AppendMenuIcon(ID_REVERTREV + ((i + 1) << 16), str);
1703 if (m_ContextMenuMask&GetContextMenuBit(ID_EDITNOTE))
1704 popup.AppendMenuIcon(ID_EDITNOTE, IDS_EDIT_NOTES, IDI_EDIT);
1706 popup.AppendMenu(MF_SEPARATOR, NULL);
1711 if(!pSelLogEntry->m_Ref.IsEmpty())
1713 popup.AppendMenuIcon(ID_REFLOG_DEL, IDS_REFLOG_DEL, IDI_DELETE);
1714 if (GetSelectedCount() == 1 && pSelLogEntry->m_Ref.Find(_T("refs/stash")) == 0)
1715 popup.AppendMenuIcon(ID_REFLOG_STASH_APPLY, IDS_MENUSTASHAPPLY, IDI_RELOCATE);
1716 popup.AppendMenu(MF_SEPARATOR, NULL);
1719 if (GetSelectedCount() >= 2)
1721 bool bAddSeparator = false;
1722 if (IsSelectionContinuous() || (GetSelectedCount() == 2))
1724 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARETWO)) // compare two revisions
1725 popup.AppendMenuIcon(ID_COMPARETWO, IDS_LOG_POPUP_COMPARETWO, IDI_DIFF);
1728 if (GetSelectedCount() == 2)
1730 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF2) && m_hasWC) // compare two revisions, unified
1731 popup.AppendMenuIcon(ID_GNUDIFF2, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
1732 bAddSeparator = true;
1735 if (m_hasWC)
1737 bAddSeparator = true;
1740 if (m_ContextMenuMask&GetContextMenuBit(ID_REVERTREV) && m_hasWC)
1741 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREVS, IDI_REVERT);
1743 if (bAddSeparator)
1744 popup.AppendMenu(MF_SEPARATOR, NULL);
1747 if ( GetSelectedCount() >0 && (!pSelLogEntry->m_CommitHash.IsEmpty()))
1749 bool bAddSeparator = false;
1750 if ( IsSelectionContinuous() && GetSelectedCount() >= 2 )
1752 if(m_ContextMenuMask&GetContextMenuBit(ID_COMBINE_COMMIT) && m_hasWC)
1754 CString head;
1755 int headindex;
1756 headindex = this->GetHeadIndex();
1757 if(headindex>=0)
1759 head.Format(_T("HEAD~%d"),LastSelect-headindex);
1760 CGitHash hash=g_Git.GetHash(head);
1761 GitRev* pLastEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(LastSelect));
1762 if(pLastEntry->m_CommitHash == hash) {
1763 popup.AppendMenuIcon(ID_COMBINE_COMMIT,IDS_COMBINE_TO_ONE,IDI_COMBINE);
1764 bAddSeparator = true;
1769 if(m_ContextMenuMask&GetContextMenuBit(ID_CHERRY_PICK) && !isHeadCommit && m_hasWC) {
1770 if (GetSelectedCount() >= 2)
1771 popup.AppendMenuIcon(ID_CHERRY_PICK, IDS_CHERRY_PICK_VERSIONS, IDI_EXPORT);
1772 else
1773 popup.AppendMenuIcon(ID_CHERRY_PICK, IDS_CHERRY_PICK_VERSION, IDI_EXPORT);
1774 bAddSeparator = true;
1777 if(GetSelectedCount()<=2 || (IsSelectionContinuous() && GetSelectedCount() > 0))
1778 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_PATCH)) {
1779 popup.AppendMenuIcon(ID_CREATE_PATCH, IDS_CREATE_PATCH, IDI_PATCH);
1780 bAddSeparator = true;
1783 if (bAddSeparator)
1784 popup.AppendMenu(MF_SEPARATOR, NULL);
1787 if (m_hasWC && (m_ContextMenuMask & GetContextMenuBit(ID_BISECTSTART)) && GetSelectedCount() == 2 && !reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(FirstSelect))->m_CommitHash.IsEmpty() && !CTGitPath(g_Git.m_CurrentDir).IsBisectActive())
1789 popup.AppendMenuIcon(ID_BISECTSTART, IDS_MENUBISECTSTART);
1790 popup.AppendMenu(MF_SEPARATOR, NULL);
1793 if (GetSelectedCount() == 1)
1795 bool bAddSeparator = false;
1796 if(m_ContextMenuMask&GetContextMenuBit(ID_PUSH) && !m_HashMap[pSelLogEntry->m_CommitHash].empty())
1798 // show the push-option only if the log entry has an associated local branch
1799 bool isLocal = false;
1800 for(int i=0; isLocal == false && i < m_HashMap[pSelLogEntry->m_CommitHash].size(); i++)
1802 if (m_HashMap[pSelLogEntry->m_CommitHash][i].Find(_T("refs/heads/")) == 0)
1803 isLocal = true;
1805 if (isLocal)
1807 popup.AppendMenuIcon(ID_PUSH, IDS_LOG_PUSH, IDI_PUSH);
1808 bAddSeparator = true;
1812 if(m_ContextMenuMask &GetContextMenuBit(ID_DELETE))
1814 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end() )
1816 std::vector<CString *> branchs;
1817 for (int i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); i++)
1819 if(m_HashMap[pSelLogEntry->m_CommitHash][i] != currentBranch)
1820 branchs.push_back(&m_HashMap[pSelLogEntry->m_CommitHash][i]);
1822 CString str;
1823 if (branchs.size() == 1)
1825 str.LoadString(IDS_DELETE_BRANCHTAG_SHORT);
1826 str+=_T(" ");
1827 str += *branchs[0];
1828 popup.AppendMenuIcon(ID_DELETE, str, IDI_DELETE);
1829 popup.SetMenuItemData(ID_DELETE, (ULONG_PTR)branchs[0]);
1830 bAddSeparator = true;
1832 else if (branchs.size() > 1)
1834 str.LoadString(IDS_DELETE_BRANCHTAG);
1835 submenu.CreatePopupMenu();
1836 for (int i = 0; i < branchs.size(); i++)
1838 submenu.AppendMenuIcon(ID_DELETE + (i << 16), *branchs[i]);
1839 submenu.SetMenuItemData(ID_DELETE + (i << 16), (ULONG_PTR)branchs[i]);
1842 popup.AppendMenuIcon(ID_DELETE,str, IDI_DELETE, submenu.m_hMenu);
1843 bAddSeparator = true;
1846 } // m_ContextMenuMask &GetContextMenuBit(ID_DELETE)
1847 if (bAddSeparator)
1848 popup.AppendMenu(MF_SEPARATOR, NULL);
1849 } // GetSelectedCount() == 1
1851 if (GetSelectedCount() != 0)
1853 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYHASH))
1854 popup.AppendMenuIcon(ID_COPYHASH, IDS_COPY_COMMIT_HASH, IDI_COPYCLIP);
1855 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYCLIPBOARD))
1856 popup.AppendMenuIcon(ID_COPYCLIPBOARD, IDS_LOG_POPUP_COPYTOCLIPBOARD, IDI_COPYCLIP);
1857 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYCLIPBOARDMESSAGES))
1858 popup.AppendMenuIcon(ID_COPYCLIPBOARDMESSAGES, IDS_LOG_POPUP_COPYTOCLIPBOARDMESSAGES, IDI_COPYCLIP);
1861 if(m_ContextMenuMask&GetContextMenuBit(ID_FINDENTRY))
1862 popup.AppendMenuIcon(ID_FINDENTRY, IDS_LOG_POPUP_FIND, IDI_FILTEREDIT);
1864 if (GetSelectedCount() == 1 && m_ContextMenuMask & GetContextMenuBit(ID_SHOWBRANCHES) && !pSelLogEntry->m_CommitHash.IsEmpty())
1865 popup.AppendMenuIcon(ID_SHOWBRANCHES, IDS_LOG_POPUP_SHOWBRANCHES, IDI_SHOWBRANCHES);
1867 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
1868 // DialogEnableWindow(IDOK, FALSE);
1869 // SetPromptApp(&theApp);
1871 this->ContextMenuAction(cmd, FirstSelect, LastSelect, &popup);
1873 // EnableOKButton();
1874 } // if (popup.CreatePopupMenu())
1878 bool CGitLogListBase::IsSelectionContinuous()
1880 if ( GetSelectedCount()==1 )
1882 // if only one revision is selected, the selection is of course
1883 // continuous
1884 return true;
1887 POSITION pos = GetFirstSelectedItemPosition();
1888 bool bContinuous = (m_arShownList.GetCount() == (INT_PTR)m_logEntries.size());
1889 if (bContinuous)
1891 int itemindex = GetNextSelectedItem(pos);
1892 while (pos)
1894 int nextindex = GetNextSelectedItem(pos);
1895 if (nextindex - itemindex > 1)
1897 bContinuous = false;
1898 break;
1900 itemindex = nextindex;
1903 return bContinuous;
1906 void CGitLogListBase::CopySelectionToClipBoard(int toCopy)
1909 CString sClipdata;
1910 POSITION pos = GetFirstSelectedItemPosition();
1911 if (pos != NULL)
1913 CString sRev;
1914 sRev.LoadString(IDS_LOG_REVISION);
1915 CString sAuthor;
1916 sAuthor.LoadString(IDS_LOG_AUTHOR);
1917 CString sDate;
1918 sDate.LoadString(IDS_LOG_DATE);
1919 CString sMessage;
1920 sMessage.LoadString(IDS_LOG_MESSAGE);
1921 bool first = true;
1922 while (pos)
1924 CString sLogCopyText;
1925 CString sPaths;
1926 GitRev * pLogEntry = reinterpret_cast<GitRev *>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1928 if (toCopy == ID_COPY_ALL)
1930 //pLogEntry->GetFiles(this)
1931 //LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
1933 CString from(MAKEINTRESOURCE(IDS_STATUSLIST_FROM));
1934 for (int cpPathIndex = 0; cpPathIndex<pLogEntry->GetFiles(this).GetCount(); ++cpPathIndex)
1936 sPaths += ((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetActionName() + _T(": ") + pLogEntry->GetFiles(this)[cpPathIndex].GetGitPathString();
1937 if (((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).m_Action & (CTGitPath::LOGACTIONS_REPLACED|CTGitPath::LOGACTIONS_COPY) && !((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetGitOldPathString().IsEmpty())
1939 CString rename;
1940 rename.Format(from, ((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetGitOldPathString());
1941 sPaths += _T(" ") + rename;
1943 sPaths += _T("\r\n");
1945 sPaths.Trim();
1946 CString body = pLogEntry->GetBody();
1947 body.Replace(_T("\n"), _T("\r\n"));
1948 sLogCopyText.Format(_T("%s: %s\r\n%s: %s <%s>\r\n%s: %s\r\n%s:\r\n%s\r\n----\r\n%s\r\n\r\n"),
1949 (LPCTSTR)sRev, pLogEntry->m_CommitHash.ToString(),
1950 (LPCTSTR)sAuthor, (LPCTSTR)pLogEntry->GetAuthorName(), (LPCTSTR)pLogEntry->GetAuthorEmail(),
1951 (LPCTSTR)sDate,
1952 (LPCTSTR)CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
1953 (LPCTSTR)sMessage, (pLogEntry->GetSubject().Trim() + _T("\r\n\r\n") + body.Trim()).Trim(),
1954 (LPCTSTR)sPaths);
1955 sClipdata += sLogCopyText;
1957 else if (toCopy == ID_COPY_MESSAGE)
1959 CString body = pLogEntry->GetBody();
1960 body.Replace(_T("\n"), _T("\r\n"));
1961 sClipdata += _T("* ") + (pLogEntry->GetSubject().Trim() + _T("\r\n\r\n") + body.Trim()).Trim() + _T("\r\n\r\n");
1963 else if (toCopy == ID_COPY_SUBJECT)
1965 sClipdata += _T("* ") + pLogEntry->GetSubject().Trim() + _T("\r\n\r\n");
1967 else
1969 if (!first)
1970 sClipdata += _T("\r\n");
1971 sClipdata += pLogEntry->m_CommitHash;
1974 first = false;
1976 CStringUtils::WriteAsciiStringToClipboard(sClipdata, GetSafeHwnd());
1981 void CGitLogListBase::DiffSelectedRevWithPrevious()
1983 if (m_bThreadRunning)
1984 return;
1986 int FirstSelect=-1, LastSelect=-1;
1987 POSITION pos = GetFirstSelectedItemPosition();
1988 FirstSelect = GetNextSelectedItem(pos);
1989 while(pos)
1991 LastSelect = GetNextSelectedItem(pos);
1994 ContextMenuAction(ID_COMPAREWITHPREVIOUS,FirstSelect,LastSelect, NULL);
1996 #if 0
1997 UpdateLogInfoLabel();
1998 int selIndex = m_LogList.GetSelectionMark();
1999 if (selIndex < 0)
2000 return;
2001 int selCount = m_LogList.GetSelectedCount();
2002 if (selCount != 1)
2003 return;
2005 // Find selected entry in the log list
2006 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2007 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
2008 long rev1 = pLogEntry->Rev;
2009 long rev2 = rev1-1;
2010 CTGitPath path = m_path;
2012 // See how many files under the relative root were changed in selected revision
2013 int nChanged = 0;
2014 LogChangedPath * changed = NULL;
2015 for (INT_PTR c = 0; c < pLogEntry->pArChangedPaths->GetCount(); ++c)
2017 LogChangedPath * cpath = pLogEntry->pArChangedPaths->SafeGetAt(c);
2018 if (cpath && cpath -> sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
2020 ++nChanged;
2021 changed = cpath;
2025 if (m_path.IsDirectory() && nChanged == 1)
2027 // We're looking at the log for a directory and only one file under dir was changed in the revision
2028 // Do diff on that file instead of whole directory
2029 path.AppendPathString(changed->sPath.Mid(m_sRelativeRoot.GetLength()));
2032 m_bCancelled = FALSE;
2033 DialogEnableWindow(IDOK, FALSE);
2034 SetPromptApp(&theApp);
2035 theApp.DoWaitCursor(1);
2037 if (PromptShown())
2039 GitDiff diff(this, m_hWnd, true);
2040 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
2041 diff.SetHEADPeg(m_LogRevision);
2042 diff.ShowCompare(path, rev2, path, rev1);
2044 else
2046 CAppUtils::StartShowCompare(m_hWnd, path, rev2, path, rev1, GitRev(), m_LogRevision, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
2049 theApp.DoWaitCursor(-1);
2050 EnableOKButton();
2051 #endif
2054 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR *pNMHDR, LRESULT *pResult)
2056 LPNMLVFINDITEM pFindInfo = reinterpret_cast<LPNMLVFINDITEM>(pNMHDR);
2057 *pResult = -1;
2059 if (pFindInfo->lvfi.flags & LVFI_PARAM)
2060 return;
2061 if ((pFindInfo->iStart < 0)||(pFindInfo->iStart >= m_arShownList.GetCount()))
2062 return;
2063 if (pFindInfo->lvfi.psz == 0)
2064 return;
2065 #if 0
2066 CString sCmp = pFindInfo->lvfi.psz;
2067 CString sRev;
2068 for (int i=pFindInfo->iStart; i<m_arShownList.GetCount(); ++i)
2070 GitRev * pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(i));
2071 sRev.Format(_T("%ld"), pLogEntry->Rev);
2072 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
2074 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
2076 *pResult = i;
2077 return;
2080 else
2082 if (sCmp.Compare(sRev)==0)
2084 *pResult = i;
2085 return;
2089 if (pFindInfo->lvfi.flags & LVFI_WRAP)
2091 for (int i=0; i<pFindInfo->iStart; ++i)
2093 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(i));
2094 sRev.Format(_T("%ld"), pLogEntry->Rev);
2095 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
2097 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
2099 *pResult = i;
2100 return;
2103 else
2105 if (sCmp.Compare(sRev)==0)
2107 *pResult = i;
2108 return;
2113 #endif
2114 *pResult = -1;
2117 int CGitLogListBase::FillGitLog(CTGitPath *path,int info,CString *from,CString *to)
2119 ClearText();
2121 this->m_arShownList.SafeRemoveAll();
2123 this->m_logEntries.ClearAll();
2124 if (this->m_logEntries.ParserFromLog(path,-1,info,from,to))
2125 return -1;
2127 //this->m_logEntries.ParserFromLog();
2128 SetItemCountEx((int)m_logEntries.size());
2130 for(unsigned int i=0;i<m_logEntries.size();i++)
2132 if(m_IsOldFirst)
2134 m_logEntries.GetGitRevAt(m_logEntries.size()-i-1).m_IsFull=TRUE;
2135 this->m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size()-i-1));
2138 else
2140 m_logEntries.GetGitRevAt(i).m_IsFull=TRUE;
2141 this->m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
2145 ReloadHashMap();
2147 if(path)
2148 m_Path=*path;
2149 return 0;
2153 int CGitLogListBase::BeginFetchLog()
2155 ClearText();
2157 this->m_arShownList.SafeRemoveAll();
2159 this->m_logEntries.ClearAll();
2161 this->m_LogCache.ClearAllParent();
2163 m_LogCache.FetchCacheIndex(g_Git.m_CurrentDir);
2165 CTGitPath *path;
2166 if(this->m_Path.IsEmpty())
2167 path=NULL;
2168 else
2169 path=&this->m_Path;
2171 CString hash;
2172 int mask;
2173 mask = CGit::LOG_INFO_ONLY_HASH | CGit::LOG_INFO_BOUNDARY;
2174 // if(this->m_bAllBranch)
2175 mask |= m_ShowMask ;
2177 if(m_bShowWC)
2179 this->m_logEntries.insert(m_logEntries.begin(),this->m_wcRev.m_CommitHash);
2180 ResetWcRev();
2181 this->m_LogCache.m_HashMap[m_wcRev.m_CommitHash]=m_wcRev;
2184 CString *pFrom, *pTo;
2185 pFrom = pTo = NULL;
2186 CString head(_T("HEAD"));
2187 if(!this->m_startrev.IsEmpty())
2189 pFrom = &this->m_startrev;
2190 if(!this->m_endrev.IsEmpty())
2191 pTo = &this->m_endrev;
2192 else
2193 pTo = &head;
2196 CFilterData data;
2197 data.m_From = m_From;
2198 data.m_To =m_To;
2200 #if 0 /* use tortoiegit filter */
2201 if(this->m_nSelectedFilter == LOGFILTER_ALL || m_nSelectedFilter == LOGFILTER_AUTHORS)
2202 data.m_Author = this->m_sFilterText;
2204 if(this->m_nSelectedFilter == LOGFILTER_ALL || m_nSelectedFilter == LOGFILTER_MESSAGES)
2205 data.m_MessageFilter = this->m_sFilterText;
2207 data.m_IsRegex = m_bFilterWithRegex;
2208 #endif
2210 // follow does not work for directories
2211 if (!path || path->IsDirectory())
2212 mask &= ~CGit::LOG_INFO_FOLLOW;
2213 // follow does not work with all branches 8at least in TGit)
2214 if (mask & CGit::LOG_INFO_FOLLOW)
2215 mask &= ~CGit::LOG_INFO_ALL_BRANCH;
2217 CString cmd=g_Git.GetLogCmd(m_StartRef,path,-1,mask,pFrom,pTo,true,&data);
2219 //this->m_logEntries.ParserFromLog();
2220 if(IsInWorkingThread())
2222 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL);
2224 else
2226 SetItemCountEx((int)m_logEntries.size());
2231 git_init();
2233 catch (char* msg)
2235 CString err(msg);
2236 MessageBox(_T("Could not initialize libgit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2237 return -1;
2240 if (g_Git.IsOrphanBranch(m_StartRef))
2241 return 0;
2243 try {
2244 if (git_open_log(&m_DllGitLog, CUnicodeUtils::GetMulti(cmd, CP_UTF8).GetBuffer()))
2246 return -1;
2249 catch (char* msg)
2251 CString err(msg);
2252 MessageBox(_T("Could not open log.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2253 return -1;
2256 return 0;
2259 BOOL CGitLogListBase::PreTranslateMessage(MSG* pMsg)
2261 if (pMsg->message == WM_KEYDOWN && pMsg->wParam=='\r')
2263 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))
2265 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
2267 DiffSelectedRevWithPrevious();
2268 return TRUE;
2271 #if 0
2272 if (GetFocus()==GetDlgItem(IDC_LOGMSG))
2274 DiffSelectedFile();
2275 return TRUE;
2277 #endif
2279 else if (pMsg->message == WM_KEYDOWN && pMsg->wParam == 'A' && GetAsyncKeyState(VK_CONTROL)&0x8000)
2281 // select all entries
2282 for (int i=0; i<GetItemCount(); ++i)
2284 SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
2286 return TRUE;
2289 #if 0
2290 if (m_hAccel && !bSkipAccelerator)
2292 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
2293 if (ret)
2294 return TRUE;
2297 #endif
2298 //m_tooltips.RelayEvent(pMsg);
2299 return __super::PreTranslateMessage(pMsg);
2302 void CGitLogListBase::OnNMDblclkLoglist(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2304 // a double click on an entry in the revision list has happened
2305 *pResult = 0;
2307 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
2308 DiffSelectedRevWithPrevious();
2311 int CGitLogListBase::FetchLogAsync(void * data)
2313 m_ProcData=data;
2314 m_bExitThread=FALSE;
2315 InterlockedExchange(&m_bThreadRunning, TRUE);
2316 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2317 m_LoadingThread = AfxBeginThread(LogThreadEntry, this, THREAD_PRIORITY_LOWEST);
2318 if (m_LoadingThread ==NULL)
2320 InterlockedExchange(&m_bThreadRunning, FALSE);
2321 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2322 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
2323 return -1;
2325 return 0;
2328 //this is the thread function which calls the subversion function
2329 UINT CGitLogListBase::LogThreadEntry(LPVOID pVoid)
2331 return ((CGitLogListBase*)pVoid)->LogThread();
2334 void CGitLogListBase::GetTimeRange(CTime &oldest, CTime &latest)
2336 //CTime time;
2337 oldest=CTime::GetCurrentTime();
2338 latest=CTime(1971,1,2,0,0,0);
2339 for(unsigned int i=0;i<m_logEntries.size();i++)
2341 if(m_logEntries[i].IsEmpty())
2342 continue;
2344 if(m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime() < oldest.GetTime())
2345 oldest = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
2347 if(m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime() > latest.GetTime())
2348 latest = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
2352 if(latest<oldest)
2353 latest=oldest;
2356 UINT CGitLogListBase::LogThread()
2358 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_START,0);
2360 InterlockedExchange(&m_bThreadRunning, TRUE);
2361 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2363 ULONGLONG t1,t2;
2365 if(BeginFetchLog())
2367 InterlockedExchange(&m_bThreadRunning, FALSE);
2368 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2370 return 1;
2373 tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
2374 bool bRegex = false;
2375 if (m_bFilterWithRegex)
2376 bRegex = ValidateRegexp(m_sFilterText, pat, false);
2378 TRACE(_T("\n===Begin===\n"));
2379 //Update work copy item;
2381 if (!m_logEntries.empty())
2383 GitRev *pRev = &m_logEntries.GetGitRevAt(0);
2385 m_arShownList.SafeAdd(pRev);
2389 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2391 // store commit number of the last selected commit/line before the refresh or -1
2392 int lastSelectedHashNItem = -1;
2393 int ret = 0;
2395 if (!g_Git.IsOrphanBranch(m_StartRef))
2397 g_Git.m_critGitDllSec.Lock();
2398 int total = 0;
2401 git_get_log_firstcommit(m_DllGitLog);
2402 total = git_get_log_estimate_commit_count(m_DllGitLog);
2404 catch (char* msg)
2406 CString err(msg);
2407 MessageBox(_T("Could not get first commit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2408 ret = -1;
2410 g_Git.m_critGitDllSec.Unlock();
2412 GIT_COMMIT commit;
2413 t2=t1=GetTickCount();
2414 int oldprecentage = 0;
2415 size_t oldsize = m_logEntries.size();
2416 while (ret== 0 && !m_bExitThread)
2418 g_Git.m_critGitDllSec.Lock();
2421 ret = git_get_log_nextcommit(this->m_DllGitLog, &commit, m_ShowMask & CGit::LOG_INFO_FOLLOW);
2423 catch (char* msg)
2425 g_Git.m_critGitDllSec.Unlock();
2426 CString err(msg);
2427 MessageBox(_T("Could not get next commit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2428 break;
2430 g_Git.m_critGitDllSec.Unlock();
2432 if(ret)
2433 break;
2435 if (commit.m_ignore == 1)
2437 git_free_commit(&commit);
2438 continue;
2441 //printf("%s\r\n",commit.GetSubject());
2442 if(m_bExitThread)
2443 break;
2445 CGitHash hash = (char*)commit.m_hash ;
2447 GitRev *pRev = m_LogCache.GetCacheData(hash);
2448 pRev->m_GitCommit = commit;
2449 InterlockedExchange(&pRev->m_IsCommitParsed, FALSE);
2451 char *note=NULL;
2452 g_Git.m_critGitDllSec.Lock();
2453 git_get_notes(commit.m_hash,&note);
2454 g_Git.m_critGitDllSec.Unlock();
2456 if(note)
2458 pRev->m_Notes.Empty();
2459 g_Git.StringAppend(&pRev->m_Notes,(BYTE*)note);
2462 if(!pRev->m_IsDiffFiles)
2464 pRev->m_CallDiffAsync = DiffAsync;
2467 pRev->ParserParentFromCommit(&commit);
2469 #ifdef DEBUG
2470 pRev->DbgPrint();
2471 TRACE(_T("\n"));
2472 #endif
2474 if(!m_sFilterText.IsEmpty())
2476 if(!IsMatchFilter(bRegex,pRev,pat))
2477 continue;
2479 this->m_critSec.Lock();
2480 m_logEntries.push_back(hash);
2481 m_arShownList.SafeAdd(pRev);
2482 this->m_critSec.Unlock();
2484 if (lastSelectedHashNItem == -1 && hash == m_lastSelectedHash)
2485 lastSelectedHashNItem = (int)m_arShownList.GetCount() - 1;
2487 t2=GetTickCount();
2489 if(t2-t1>500 || (m_logEntries.size()-oldsize >100))
2491 //update UI
2492 int percent = (int)m_logEntries.size() * 100 / total + GITLOG_START + 1;
2493 if(percent > 99)
2494 percent =99;
2495 if(percent < GITLOG_START)
2496 percent = GITLOG_START +1;
2498 oldsize = m_logEntries.size();
2499 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
2501 //if( percent > oldprecentage )
2503 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) percent,0);
2504 oldprecentage = percent;
2506 t1 = t2;
2509 g_Git.m_critGitDllSec.Lock();
2510 git_close_log(m_DllGitLog);
2511 g_Git.m_critGitDllSec.Unlock();
2515 if (m_bExitThread)
2517 InterlockedExchange(&m_bThreadRunning, FALSE);
2518 return 0;
2521 //Update UI;
2522 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
2524 if (lastSelectedHashNItem >= 0)
2525 PostMessage(m_ScrollToMessage, lastSelectedHashNItem);
2527 if (this->m_hWnd)
2528 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_END,0);
2530 InterlockedExchange(&m_bThreadRunning, FALSE);
2532 return 0;
2535 void CGitLogListBase::Refresh(BOOL IsCleanFilter)
2537 SafeTerminateThread();
2539 this->SetItemCountEx(0);
2540 this->Clear();
2542 ResetWcRev();
2544 // HACK to hide graph column
2545 if (m_ShowMask & CGit::LOG_INFO_FOLLOW)
2546 SetColumnWidth(0, 0);
2547 else
2548 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
2550 //Update branch and Tag info
2551 ReloadHashMap();
2552 //Assume Thread have exited
2553 //if(!m_bThreadRunning)
2555 m_logEntries.clear();
2557 if(IsCleanFilter)
2559 m_sFilterText.Empty();
2560 m_From=-1;
2561 m_To=-1;
2564 InterlockedExchange(&m_bExitThread,FALSE);
2566 InterlockedExchange(&m_bThreadRunning, TRUE);
2567 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2568 if ( (m_LoadingThread=AfxBeginThread(LogThreadEntry, this)) ==NULL)
2570 InterlockedExchange(&m_bThreadRunning, FALSE);
2571 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2572 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
2576 bool CGitLogListBase::ValidateRegexp(LPCTSTR regexp_str, tr1::wregex& pat, bool bMatchCase /* = false */)
2580 tr1::regex_constants::syntax_option_type type = tr1::regex_constants::ECMAScript;
2581 if (!bMatchCase)
2582 type |= tr1::regex_constants::icase;
2583 pat = tr1::wregex(regexp_str, type);
2584 return true;
2586 catch (exception) {}
2587 return false;
2589 BOOL CGitLogListBase::IsMatchFilter(bool bRegex, GitRev *pRev, tr1::wregex &pat)
2592 tr1::regex_constants::match_flag_type flags = tr1::regex_constants::match_any;
2593 CString sRev;
2595 if ((bRegex)&&(m_bFilterWithRegex))
2597 if (m_SelectedFilters & LOGFILTER_BUGID)
2599 if(this->m_bShowBugtraqColumn)
2601 CString sBugIds = m_ProjectProperties.FindBugID(pRev->GetSubject() + _T("\r\n\r\n") + pRev->GetBody());
2603 ATLTRACE(_T("bugID = \"%s\"\n"), sBugIds);
2604 if (regex_search(wstring(sBugIds), pat, flags))
2606 return TRUE;
2611 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
2613 ATLTRACE(_T("messge = \"%s\"\n"), pRev->GetSubject());
2614 if (regex_search(wstring((LPCTSTR)pRev->GetSubject()), pat, flags))
2616 return TRUE;
2620 if (m_SelectedFilters & LOGFILTER_MESSAGES)
2622 ATLTRACE(_T("messge = \"%s\"\n"),pRev->GetBody());
2623 if (regex_search(wstring((LPCTSTR)pRev->GetBody()), pat, flags))
2625 return TRUE;
2629 if (m_SelectedFilters & LOGFILTER_AUTHORS)
2631 if (regex_search(wstring(pRev->GetAuthorName()), pat, flags))
2633 return TRUE;
2636 if (regex_search(wstring(pRev->GetCommitterName()), pat, flags))
2638 return TRUE;
2642 if (m_SelectedFilters & LOGFILTER_REVS)
2644 sRev.Format(_T("%s"), pRev->m_CommitHash.ToString());
2645 if (regex_search(wstring((LPCTSTR)sRev), pat, flags))
2647 return TRUE;
2651 if (m_SelectedFilters & LOGFILTER_PATHS)
2653 CTGitPathList *pathList=NULL;
2654 if( pRev->m_IsDiffFiles)
2655 pathList = &pRev->GetFiles(this);
2656 else
2658 if(!pRev->m_IsSimpleListReady)
2659 pRev->SafeGetSimpleList(&g_Git);
2662 if(pathList)
2663 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList->GetCount(); ++cpPathIndex)
2665 if (regex_search(wstring((LPCTSTR)pathList->m_paths.at(cpPathIndex).GetGitOldPathString()), pat, flags))
2667 return true;
2669 if (regex_search(wstring((LPCTSTR)pathList->m_paths.at(cpPathIndex).GetGitPathString()), pat, flags))
2671 return true;
2675 for(size_t i = 0; i < pRev->m_SimpleFileList.size(); i++)
2677 if (regex_search(wstring((LPCTSTR)pRev->m_SimpleFileList[i]), pat, flags))
2679 return true;
2684 else
2686 CString find = m_sFilterText;
2687 find.MakeLower();
2689 if (m_SelectedFilters & LOGFILTER_BUGID)
2691 if(this->m_bShowBugtraqColumn)
2693 CString sBugIds = m_ProjectProperties.FindBugID(pRev->GetSubject() + _T("\r\n\r\n") + pRev->GetBody());
2695 sBugIds.MakeLower();
2696 if ((sBugIds.Find(find) >= 0))
2698 return TRUE;
2703 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
2705 CString msg = pRev->GetSubject();
2707 msg = msg.MakeLower();
2708 if ((msg.Find(find) >= 0))
2710 return TRUE;
2714 if (m_SelectedFilters & LOGFILTER_MESSAGES)
2716 CString msg = pRev->GetBody();
2718 msg = msg.MakeLower();
2719 if ((msg.Find(find) >= 0))
2721 return TRUE;
2725 if (m_SelectedFilters & LOGFILTER_AUTHORS)
2727 CString msg = pRev->GetAuthorName();
2728 msg = msg.MakeLower();
2729 if ((msg.Find(find) >= 0))
2731 return TRUE;
2735 if (m_SelectedFilters & LOGFILTER_REVS)
2737 sRev.Format(_T("%s"), pRev->m_CommitHash.ToString());
2738 if ((sRev.Find(find) >= 0))
2740 return TRUE;
2744 if (m_SelectedFilters & LOGFILTER_PATHS)
2746 CTGitPathList *pathList=NULL;
2747 if( pRev->m_IsDiffFiles)
2748 pathList = &pRev->GetFiles(this);
2749 else
2751 if(!pRev->m_IsSimpleListReady)
2752 pRev->SafeGetSimpleList(&g_Git);
2754 if(pathList)
2755 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList->GetCount() ; ++cpPathIndex)
2757 CTGitPath *cpath = &pathList->m_paths.at(cpPathIndex);
2758 CString path = cpath->GetGitOldPathString();
2759 path.MakeLower();
2760 if ((path.Find(find)>=0))
2762 return true;
2764 path = cpath->GetGitPathString();
2765 path.MakeLower();
2766 if ((path.Find(find)>=0))
2768 return true;
2772 for (size_t i = 0; i < pRev->m_SimpleFileList.size(); i++)
2774 CString path = pRev->m_SimpleFileList[i];
2775 path.MakeLower();
2776 if ((path.Find(find)>=0))
2778 return true;
2782 } // else (from if (bRegex))
2783 return FALSE;
2787 void CGitLogListBase::RecalculateShownList(CThreadSafePtrArray * pShownlist)
2790 pShownlist->SafeRemoveAll();
2792 tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
2793 bool bRegex = false;
2794 if (m_bFilterWithRegex)
2795 bRegex = ValidateRegexp(m_sFilterText, pat, false);
2797 tr1::regex_constants::match_flag_type flags = tr1::regex_constants::match_any;
2798 CString sRev;
2799 for (DWORD i=0; i<m_logEntries.size(); ++i)
2801 if ((bRegex)&&(m_bFilterWithRegex))
2803 #if 0
2804 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
2806 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR)m_logEntries[i]->sBugIDs);
2807 if (regex_search(wstring((LPCTSTR)m_logEntries[i]->sBugIDs), pat, flags)&&IsEntryInDateRange(i))
2809 pShownlist->SafeAdd(m_logEntries[i]);
2810 continue;
2813 #endif
2814 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
2816 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).GetSubject());
2817 if (regex_search(wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetSubject()), pat, flags)&&IsEntryInDateRange(i))
2819 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2820 continue;
2823 if (m_SelectedFilters & LOGFILTER_MESSAGES)
2825 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).GetBody());
2826 if (regex_search(wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetBody()), pat, flags)&&IsEntryInDateRange(i))
2828 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2829 continue;
2832 if (m_SelectedFilters & LOGFILTER_PATHS)
2834 CTGitPathList pathList = m_logEntries.GetGitRevAt(i).GetFiles(this);
2836 bool bGoing = true;
2837 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList.GetCount() && bGoing; ++cpPathIndex)
2839 CTGitPath cpath = pathList[cpPathIndex];
2840 if (regex_search(wstring((LPCTSTR)cpath.GetGitOldPathString()), pat, flags)&&IsEntryInDateRange(i))
2842 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2843 bGoing = false;
2844 continue;
2846 if (regex_search(wstring((LPCTSTR)cpath.GetGitPathString()), pat, flags)&&IsEntryInDateRange(i))
2848 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2849 bGoing = false;
2850 continue;
2852 if (regex_search(wstring((LPCTSTR)cpath.GetActionName()), pat, flags)&&IsEntryInDateRange(i))
2854 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2855 bGoing = false;
2856 continue;
2860 if (m_SelectedFilters & LOGFILTER_AUTHORS)
2862 if (regex_search(wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetAuthorName()), pat, flags)&&IsEntryInDateRange(i))
2864 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2865 continue;
2868 if (m_SelectedFilters & LOGFILTER_REVS)
2870 sRev.Format(_T("%s"), m_logEntries.GetGitRevAt(i).m_CommitHash.ToString());
2871 if (regex_search(wstring((LPCTSTR)sRev), pat, flags)&&IsEntryInDateRange(i))
2873 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2874 continue;
2877 } // if (bRegex)
2878 else
2880 CString find = m_sFilterText;
2881 find.MakeLower();
2882 #if 0
2883 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
2885 CString sBugIDs = m_logEntries[i]->sBugIDs;
2887 sBugIDs = sBugIDs.MakeLower();
2888 if ((sBugIDs.Find(find) >= 0)&&(IsEntryInDateRange(i)))
2890 pShownlist->SafeAdd(m_logEntries[i]);
2891 continue;
2894 #endif
2895 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
2897 CString msg = m_logEntries.GetGitRevAt(i).GetSubject();
2899 msg = msg.MakeLower();
2900 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
2902 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2903 continue;
2906 if (m_SelectedFilters & LOGFILTER_MESSAGES)
2908 CString msg = m_logEntries.GetGitRevAt(i).GetBody();
2910 msg = msg.MakeLower();
2911 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
2913 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2914 continue;
2917 if (m_SelectedFilters & LOGFILTER_PATHS)
2919 CTGitPathList pathList = m_logEntries.GetGitRevAt(i).GetFiles(this);
2921 bool bGoing = true;
2922 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList.GetCount() && bGoing; ++cpPathIndex)
2924 CTGitPath cpath = pathList[cpPathIndex];
2925 CString path = cpath.GetGitOldPathString();
2926 path.MakeLower();
2927 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
2929 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2930 bGoing = false;
2931 continue;
2933 path = cpath.GetGitPathString();
2934 path.MakeLower();
2935 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
2937 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2938 bGoing = false;
2939 continue;
2941 path = cpath.GetActionName();
2942 path.MakeLower();
2943 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
2945 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2946 bGoing = false;
2947 continue;
2951 if (m_SelectedFilters & LOGFILTER_AUTHORS)
2953 CString msg = m_logEntries.GetGitRevAt(i).GetAuthorName();
2954 msg = msg.MakeLower();
2955 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
2957 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2958 continue;
2961 if (m_SelectedFilters & LOGFILTER_REVS)
2963 sRev.Format(_T("%s"), m_logEntries.GetGitRevAt(i).m_CommitHash.ToString());
2964 if ((sRev.Find(find) >= 0)&&(IsEntryInDateRange(i)))
2966 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2967 continue;
2970 } // else (from if (bRegex))
2971 } // for (DWORD i=0; i<m_logEntries.size(); ++i)
2975 BOOL CGitLogListBase::IsEntryInDateRange(int /*i*/)
2978 __time64_t time = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
2980 if(m_From == -1)
2981 if(m_To == -1)
2982 return true;
2983 else
2984 return time <= m_To;
2985 else
2986 if(m_To == -1)
2987 return time >= m_From;
2988 else
2989 return ((time >= m_From)&&(time <= m_To));
2991 return TRUE; /* git dll will filter time range */
2993 // return TRUE;
2995 void CGitLogListBase::StartFilter()
2997 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2998 RecalculateShownList(&m_arShownList);
2999 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3002 DeleteAllItems();
3003 SetItemCountEx(ShownCountWithStopped());
3004 RedrawItems(0, ShownCountWithStopped());
3005 Invalidate();
3008 void CGitLogListBase::RemoveFilter()
3011 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3013 m_arShownList.SafeRemoveAll();
3015 // reset the time filter too
3016 #if 0
3017 m_timFrom = (__time64_t(m_tFrom));
3018 m_timTo = (__time64_t(m_tTo));
3019 m_DateFrom.SetTime(&m_timFrom);
3020 m_DateTo.SetTime(&m_timTo);
3021 m_DateFrom.SetRange(&m_timFrom, &m_timTo);
3022 m_DateTo.SetRange(&m_timFrom, &m_timTo);
3023 #endif
3025 for (DWORD i=0; i<m_logEntries.size(); ++i)
3027 if(this->m_IsOldFirst)
3029 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size()-i-1));
3031 else
3033 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
3036 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
3037 DeleteAllItems();
3038 SetItemCountEx(ShownCountWithStopped());
3039 RedrawItems(0, ShownCountWithStopped());
3041 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3044 void CGitLogListBase::Clear()
3046 m_arShownList.SafeRemoveAll();
3047 DeleteAllItems();
3049 m_logEntries.ClearAll();
3053 void CGitLogListBase::OnDestroy()
3055 // save the column widths to the registry
3056 SaveColumnWidths();
3058 SafeTerminateThread();
3059 SafeTerminateAsyncDiffThread();
3061 int retry = 0;
3062 while(m_LogCache.SaveCache())
3064 if(retry > 5)
3065 break;
3066 Sleep(1000);
3068 retry++;
3070 //if(CMessageBox::Show(NULL,_T("Cannot Save Log Cache to Disk. To retry click yes. To give up click no."),_T("TortoiseGit"),
3071 // MB_YESNO) == IDNO)
3072 // break;
3075 CHintListCtrl::OnDestroy();
3078 LRESULT CGitLogListBase::OnLoad(WPARAM wParam,LPARAM lParam)
3080 UNREFERENCED_PARAMETER(lParam);
3081 CRect rect;
3082 int i=(int)wParam;
3083 this->GetItemRect(i,&rect,LVIR_BOUNDS);
3084 this->InvalidateRect(rect);
3086 return 0;
3090 * Save column widths to the registry
3092 void CGitLogListBase::SaveColumnWidths()
3094 int maxcol = m_ColumnManager.GetColumnCount();
3096 // HACK that graph column is always shown
3097 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
3099 for (int col = 0; col < maxcol; col++)
3100 if (m_ColumnManager.IsVisible (col))
3101 m_ColumnManager.ColumnResized (col);
3103 m_ColumnManager.WriteSettings();
3106 int CGitLogListBase::GetHeadIndex()
3108 if(m_HeadHash.IsEmpty())
3109 return -1;
3111 for(int i=0;i<m_arShownList.GetCount();i++)
3113 GitRev *pRev = (GitRev*)m_arShownList[i];
3114 if(pRev)
3116 if(pRev->m_CommitHash.ToString() == m_HeadHash )
3117 return i;
3120 return -1;
3122 void CGitLogListBase::OnFind()
3124 if (!m_pFindDialog)
3126 m_pFindDialog = new CFindDlg(this);
3127 m_pFindDialog->Create(this);
3130 void CGitLogListBase::OnHdnBegintrack(NMHDR *pNMHDR, LRESULT *pResult)
3132 m_ColumnManager.OnHdnBegintrack(pNMHDR, pResult);
3134 void CGitLogListBase::OnHdnItemchanging(NMHDR *pNMHDR, LRESULT *pResult)
3136 if(!m_ColumnManager.OnHdnItemchanging(pNMHDR, pResult))
3137 Default();
3139 LRESULT CGitLogListBase::OnScrollToMessage(WPARAM itemToSelect, LPARAM /*lParam*/)
3141 SetItemState((int)itemToSelect, LVIS_SELECTED, LVIS_SELECTED);
3142 EnsureVisible((int)itemToSelect, FALSE);
3143 return 0;
3145 LRESULT CGitLogListBase::OnFindDialogMessage(WPARAM /*wParam*/, LPARAM /*lParam*/)
3148 ASSERT(m_pFindDialog != NULL);
3149 bool bFound = false;
3150 int i=0;
3152 if (m_pFindDialog->IsTerminating())
3154 // invalidate the handle identifying the dialog box.
3155 m_pFindDialog = NULL;
3156 return 0;
3159 if(m_pFindDialog->IsRef())
3161 CString str;
3162 str=m_pFindDialog->GetFindString();
3164 CGitHash hash;
3166 if(!str.IsEmpty())
3167 hash = g_Git.GetHash(str + _T("^{}")); // add ^{} in order to get the correct SHA-1 (especially for signed tags)
3169 if(!hash.IsEmpty())
3171 for (i = 0; i<m_arShownList.GetCount(); i++)
3173 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(i);
3174 if(pLogEntry && pLogEntry->m_CommitHash == hash)
3176 bFound = true;
3177 break;
3184 if(m_pFindDialog->FindNext())
3186 //read data from dialog
3187 CString FindText = m_pFindDialog->GetFindString();
3188 bool bMatchCase = (m_pFindDialog->MatchCase() == TRUE);
3190 tr1::wregex pat;
3191 bool bRegex = ValidateRegexp(FindText, pat, bMatchCase);
3193 tr1::regex_constants::match_flag_type flags = tr1::regex_constants::match_not_null;
3196 for (i = this->m_nSearchIndex; i<m_arShownList.GetCount()&&!bFound; i++)
3198 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(i);
3200 CString str;
3201 str+=pLogEntry->m_CommitHash.ToString();
3202 str+=_T("\n");
3204 for(int j=0;j<this->m_HashMap[pLogEntry->m_CommitHash].size();j++)
3206 str+=m_HashMap[pLogEntry->m_CommitHash][j];
3207 str+=_T("\n");
3210 str+=pLogEntry->GetAuthorEmail();
3211 str+=_T("\n");
3212 str+=pLogEntry->GetAuthorName();
3213 str+=_T("\n");
3214 str+=pLogEntry->GetBody();
3215 str+=_T("\n");
3216 str+=pLogEntry->GetCommitterEmail();
3217 str+=_T("\n");
3218 str+=pLogEntry->GetCommitterName();
3219 str+=_T("\n");
3220 str+=pLogEntry->GetSubject();
3221 str+=_T("\n");
3224 /*Because changed files list is loaded on demand when gui show,
3225 files will empty when files have not fetched.
3227 we can add it back by using one-way diff(with outnumber changed and rename detect.
3228 here just need changed filename list. one-way is much quicker.
3230 if(pLogEntry->m_IsFull)
3232 for(int i=0;i<pLogEntry->GetFiles(this).GetCount();i++)
3234 str+=pLogEntry->GetFiles(this)[i].GetWinPath();
3235 str+=_T("\n");
3236 str+=pLogEntry->GetFiles(this)[i].GetGitOldPathString();
3237 str+=_T("\n");
3240 else
3242 if(!pLogEntry->m_IsSimpleListReady)
3243 pLogEntry->SafeGetSimpleList(&g_Git);
3245 for(int i=0;i<pLogEntry->m_SimpleFileList.size();i++)
3247 str+=pLogEntry->m_SimpleFileList[i];
3248 str+=_T("\n");
3254 if (bRegex)
3256 if (regex_search(wstring(str), pat, flags))
3258 bFound = true;
3259 break;
3262 else
3264 if (bMatchCase)
3266 if (str.Find(FindText) >= 0)
3268 bFound = true;
3269 break;
3273 else
3275 CString msg = str;
3276 msg = msg.MakeLower();
3277 CString find = FindText.MakeLower();
3278 if (msg.Find(find) >= 0)
3280 bFound = TRUE;
3281 break;
3285 } // for (i = this->m_nSearchIndex; i<m_arShownList.GetItemCount()&&!bFound; i++)
3287 } // if(m_pFindDialog->FindNext())
3288 //UpdateLogInfoLabel();
3290 if (bFound)
3292 this->m_nSearchIndex = i;
3293 EnsureVisible(i, FALSE);
3294 SetItemState(GetSelectionMark(), 0, LVIS_SELECTED);
3295 SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
3296 SetSelectionMark(i);
3297 //FillLogMessageCtrl();
3298 UpdateData(FALSE);
3299 m_nSearchIndex++;
3300 if (m_nSearchIndex >= m_arShownList.GetCount())
3301 m_nSearchIndex = (int)m_arShownList.GetCount()-1;
3304 return 0;
3307 void CGitLogListBase::OnColumnResized(NMHDR *pNMHDR, LRESULT *pResult)
3309 m_ColumnManager.OnColumnResized(pNMHDR,pResult);
3311 *pResult = FALSE;
3314 void CGitLogListBase::OnColumnMoved(NMHDR *pNMHDR, LRESULT *pResult)
3316 m_ColumnManager.OnColumnMoved(pNMHDR, pResult);
3318 Invalidate(FALSE);