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