1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2011 - TortoiseGit
4 // Copyright (C) 2005-2007 Marco Costalba
5 // Copyright (C) 2011 - Sven Strickroth <email@cs-ware.de>
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software Foundation,
19 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 // GitLogList.cpp : implementation file
25 #include "GitLogListBase.h"
27 //#include "VssStyle.h"
33 #include "SVNProgressDlg.h"
34 #include "ProgressDlg.h"
35 //#include "RepositoryBrowser.h"
36 //#include "CopyDlg.h"
37 //#include "StatGraphDlg.h"
39 #include "MessageBox.h"
42 #include "PathUtils.h"
43 #include "StringUtils.h"
44 #include "UnicodeUtils.h"
46 //#include "GitInfo.h"
47 //#include "GitDiff.h"
49 //#include "RevisionRangeDlg.h"
50 //#include "BrowseFolder.h"
51 //#include "BlameDlg.h"
53 //#include "GitHelpers.h"
54 #include "GitStatus.h"
55 //#include "LogDlgHelper.h"
56 //#include "CachedLogInfo.h"
57 //#include "RepositoryInfo.h"
58 //#include "EditPropertiesDlg.h"
59 #include "FileDiffDlg.h"
60 #include "..\\TortoiseShell\\Resource.h"
63 const UINT
CGitLogListBase::m_FindDialogMessage
= RegisterWindowMessage(FINDMSGSTRING
);
65 IMPLEMENT_DYNAMIC(CGitLogListBase
, CHintListCtrl
)
67 CGitLogListBase::CGitLogListBase():CHintListCtrl()
68 ,m_regMaxBugIDColWidth(_T("Software\\TortoiseGit\\MaxBugIDColWidth"), 200)
70 ,m_bNoDispUpdates(FALSE
)
71 , m_bThreadRunning(FALSE
)
72 , m_bStrictStopped(false)
73 , m_pStoreSelection(NULL
)
74 , m_nSelectedFilter(LOGFILTER_ALL
)
77 , m_logEntries(&m_LogCache
)
79 , m_ColumnManager(this)
80 , m_dwDefaultColumns(0)
81 , m_arShownList(&m_critSec
)
83 // use the default GUI font, create a copy of it and
84 // change the copy to BOLD (leave the rest of the font
86 HFONT hFont
= (HFONT
)GetStockObject(DEFAULT_GUI_FONT
);
88 GetObject(hFont
, sizeof(LOGFONT
), &lf
);
89 lf
.lfWeight
= FW_BOLD
;
90 m_boldFont
= CreateFontIndirect(&lf
);
92 m_bShowBugtraqColumn
=false;
94 m_IsIDReplaceAction
=FALSE
;
96 this->m_critSec
.Init();
97 m_wcRev
.m_CommitHash
.Empty();
98 m_wcRev
.GetSubject()=_T("Working dir changes");
99 m_wcRev
.m_ParentHash
.clear();
100 m_wcRev
.m_Mark
=_T('-');
101 m_wcRev
.m_IsUpdateing
=FALSE
;
102 m_wcRev
.m_IsFull
= TRUE
;
104 m_hModifiedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONMODIFIED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
105 m_hReplacedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONREPLACED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
106 m_hAddedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONADDED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
107 m_hDeletedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONDELETED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
108 m_hFetchIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONFETCHING
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
110 m_bFilterWithRegex
= !!CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), TRUE
);
112 g_Git
.GetMapHashToFriendName(m_HashMap
);
113 m_CurrentBranch
=g_Git
.GetCurrentBranch();
114 this->m_HeadHash
=g_Git
.GetHash(_T("HEAD"));
120 m_LoadingThread
= NULL
;
122 InterlockedExchange(&m_bExitThread
,FALSE
);
123 m_IsOldFirst
= FALSE
;
124 m_IsRebaseReplaceGraph
= FALSE
;
127 for(int i
=0;i
<Lanes::COLORS_NUM
;i
++)
129 m_LineColors
[i
] = m_Colors
.GetColor((CColors::Colors
)(CColors::BranchLine1
+i
));
131 // get short/long datetime setting from registry
132 DWORD RegUseShortDateFormat
= CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE
);
133 if ( RegUseShortDateFormat
)
135 m_DateFormat
= DATE_SHORTDATE
;
139 m_DateFormat
= DATE_LONGDATE
;
141 // get relative time display setting from registry
142 DWORD regRelativeTimes
= CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE
);
143 m_bRelativeTimes
= (regRelativeTimes
!= 0);
144 m_ContextMenuMask
= 0xFFFFFFFFFFFFFFFF;
146 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_PICK
);
147 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_SQUASH
);
148 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_EDIT
);
149 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_SKIP
);
150 m_ContextMenuMask
&= ~GetContextMenuBit(ID_LOG
);
151 m_ContextMenuMask
&= ~GetContextMenuBit(ID_BLAME
);
154 SecureZeroMemory(&inf
, sizeof(OSVERSIONINFOEX
));
155 inf
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEX
);
156 GetVersionEx((OSVERSIONINFO
*)&inf
);
157 WORD fullver
= MAKEWORD(inf
.dwMinorVersion
, inf
.dwMajorVersion
);
158 m_bVista
= (fullver
>= 0x0600);
160 m_ColumnRegKey
=_T("log");
162 m_AsyncThreadExit
= FALSE
;
163 m_AsyncDiffEvent
= ::CreateEvent(NULL
,FALSE
,TRUE
,NULL
);
164 m_AsynDiffListLock
.Init();
166 m_DiffingThread
= AfxBeginThread(AsyncThread
, this, THREAD_PRIORITY_BELOW_NORMAL
);
167 if (m_DiffingThread
==NULL
)
169 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
175 int CGitLogListBase::AsyncDiffThread()
177 m_AsyncThreadExited
= false;
178 while(!m_AsyncThreadExit
)
180 ::WaitForSingleObject(m_AsyncDiffEvent
, INFINITE
);
183 while(!m_AsyncThreadExit
&& m_AsynDiffList
.size() > 0)
185 m_AsynDiffListLock
.Lock();
186 pRev
= m_AsynDiffList
.back();
187 m_AsynDiffList
.pop_back();
188 m_AsynDiffListLock
.Unlock();
190 if( pRev
->m_CommitHash
.IsEmpty() )
192 if(pRev
->m_IsDiffFiles
)
195 pRev
->GetFiles(this).Clear();
196 pRev
->m_ParentHash
.clear();
197 pRev
->m_ParentHash
.push_back(m_HeadHash
);
198 if(g_Git
.IsInitRepos())
200 g_Git
.GetInitAddList(pRev
->GetFiles(this));
204 g_Git
.GetCommitDiffList(pRev
->m_CommitHash
.ToString(),this->m_HeadHash
.ToString(), pRev
->GetFiles(this));
206 pRev
->GetAction(this) = 0;
208 for(int j
=0;j
< pRev
->GetFiles(this).GetCount();j
++)
209 pRev
->GetAction(this) |= pRev
->GetFiles(this)[j
].m_Action
;
211 InterlockedExchange(&pRev
->m_IsDiffFiles
, TRUE
);
212 InterlockedExchange(&pRev
->m_IsFull
, TRUE
);
214 pRev
->GetBody().Format(_T("%d files changed"),pRev
->GetFiles(this).GetCount());
215 ::PostMessage(m_hWnd
,MSG_LOADED
,(WPARAM
)0,0);
216 this->GetParent()->PostMessage(WM_COMMAND
, MSG_FETCHED_DIFF
, 0);
219 if(!pRev
->CheckAndDiff())
220 { // fetch change file list
221 for(int i
=GetTopIndex(); !m_AsyncThreadExit
&& i
<= GetTopIndex()+GetCountPerPage(); i
++)
223 if(i
< m_arShownList
.GetCount())
225 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
226 if(data
->m_CommitHash
== pRev
->m_CommitHash
)
228 ::PostMessage(m_hWnd
,MSG_LOADED
,(WPARAM
)i
,0);
234 if(!m_AsyncThreadExit
&& GetSelectedCount() == 1)
236 POSITION pos
= GetFirstSelectedItemPosition();
237 int nItem
= GetNextSelectedItem(pos
);
241 GitRev
* data
= (GitRev
*)m_arShownList
[nItem
];
243 if(data
->m_CommitHash
== pRev
->m_CommitHash
)
245 this->GetParent()->PostMessage(WM_COMMAND
, MSG_FETCHED_DIFF
, 0);
252 m_AsyncThreadExited
= true;
255 void CGitLogListBase::hideFromContextMenu(unsigned __int64 hideMask
, bool exclusivelyShow
)
257 if (exclusivelyShow
) {
258 m_ContextMenuMask
&= hideMask
;
260 m_ContextMenuMask
&= ~hideMask
;
264 CGitLogListBase::~CGitLogListBase()
266 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
267 this->m_arShownList
.SafeRemoveAll();
269 DestroyIcon(m_hModifiedIcon
);
270 DestroyIcon(m_hReplacedIcon
);
271 DestroyIcon(m_hAddedIcon
);
272 DestroyIcon(m_hDeletedIcon
);
273 m_logEntries
.ClearAll();
276 DeleteObject(m_boldFont
);
278 if ( m_pStoreSelection
)
280 delete m_pStoreSelection
;
281 m_pStoreSelection
= NULL
;
284 SafeTerminateThread();
285 SafeTerminateAsyncDiffThread();
288 CloseHandle(m_AsyncDiffEvent
);
292 BEGIN_MESSAGE_MAP(CGitLogListBase
, CHintListCtrl
)
293 ON_REGISTERED_MESSAGE(m_FindDialogMessage
, OnFindDialogMessage
)
294 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW
, OnNMCustomdrawLoglist
)
295 ON_NOTIFY_REFLECT(LVN_GETDISPINFO
, OnLvnGetdispinfoLoglist
)
297 ON_NOTIFY_REFLECT(NM_DBLCLK
, OnNMDblclkLoglist
)
298 ON_NOTIFY_REFLECT(LVN_ODFINDITEM
,OnLvnOdfinditemLoglist
)
301 ON_MESSAGE(MSG_LOADED
,OnLoad
)
303 ON_WM_MEASUREITEM_REFLECT()
304 ON_NOTIFY(HDN_BEGINTRACKA
, 0, OnHdnBegintrack
)
305 ON_NOTIFY(HDN_BEGINTRACKW
, 0, OnHdnBegintrack
)
306 ON_NOTIFY(HDN_ITEMCHANGINGA
, 0, OnHdnItemchanging
)
307 ON_NOTIFY(HDN_ITEMCHANGINGW
, 0, OnHdnItemchanging
)
308 ON_NOTIFY(HDN_ENDTRACK
, 0, OnColumnResized
)
309 ON_NOTIFY(HDN_ENDDRAG
, 0, OnColumnMoved
)
312 void CGitLogListBase::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct
)
314 //if (m_nRowHeight>0)
316 lpMeasureItemStruct
->itemHeight
= 50;
320 int CGitLogListBase:: OnCreate(LPCREATESTRUCT lpCreateStruct
)
323 return CHintListCtrl::OnCreate(lpCreateStruct
);
326 void CGitLogListBase::PreSubclassWindow()
328 SetExtendedStyle(LVS_EX_FULLROWSELECT
| LVS_EX_SUBITEMIMAGES
);
329 // load the icons for the action columns
330 // m_Theme.Open(m_hWnd, L"ListView");
331 m_Theme
.Open(m_hWnd
, L
"Explorer::ListView;ListView");
332 m_Theme
.SetWindowTheme(m_hWnd
, L
"Explorer", NULL
);
333 CHintListCtrl::PreSubclassWindow();
336 void CGitLogListBase::InsertGitColumn()
340 CRegDWORD
regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE
);
341 DWORD exStyle
= LVS_EX_HEADERDRAGDROP
| LVS_EX_DOUBLEBUFFER
| LVS_EX_INFOTIP
| LVS_EX_SUBITEMIMAGES
;
342 if (DWORD(regFullRowSelect
))
343 exStyle
|= LVS_EX_FULLROWSELECT
;
344 SetExtendedStyle(exStyle
);
346 UpdateProjectProperties();
348 static UINT normal
[] =
360 IDS_LOG_COMMIT_EMAIL
,
381 m_dwDefaultColumns
= GIT_LOG_GRAPH
|GIT_LOG_ACTIONS
|GIT_LOG_MESSAGE
|GIT_LOG_AUTHOR
|GIT_LOG_DATE
;
383 DWORD hideColumns
= 0;
384 if(this->m_IsRebaseReplaceGraph
)
386 hideColumns
|= GIT_LOG_GRAPH
;
387 m_dwDefaultColumns
|= GIT_LOG_REBASE
;
389 hideColumns
|= GIT_LOG_REBASE
;
392 if(this->m_IsIDReplaceAction
)
394 hideColumns
|= GIT_LOG_ACTIONS
;
395 m_dwDefaultColumns
|= GIT_LOG_ID
;
396 m_dwDefaultColumns
|= GIT_LOG_HASH
;
398 hideColumns
|= GIT_LOG_ID
;
400 if(this->m_bShowBugtraqColumn
)
402 m_dwDefaultColumns
|= GIT_LOGLIST_BUG
;
404 hideColumns
|= GIT_LOGLIST_BUG
;
408 m_ColumnManager
.SetNames(normal
, sizeof(normal
)/sizeof(UINT
));
409 m_ColumnManager
.ReadSettings(m_dwDefaultColumns
, hideColumns
, m_ColumnRegKey
+_T("loglist"), sizeof(normal
)/sizeof(UINT
), with
);
416 * Resizes all columns in a list control to values in registry.
418 void CGitLogListBase::ResizeAllListCtrlCols()
420 // column max and min widths to allow
421 static const int nMinimumWidth
= 10;
422 static const int nMaximumWidth
= 1000;
423 CHeaderCtrl
* pHdrCtrl
= (CHeaderCtrl
*)(GetDlgItem(0));
426 int numcols
= pHdrCtrl
->GetItemCount();
427 for (int col
= 0; col
< numcols
; col
++)
429 // get width for this col last time from registry
431 regentry
.Format( _T("Software\\TortoiseGit\\%s\\ColWidth%d"),m_ColumnRegKey
, col
);
432 CRegDWORD
regwidth(regentry
, 0);
436 // no saved value, setup sensible defaults
437 if (col
== this->LOGLIST_MESSAGE
)
439 cx
= LOGLIST_MESSAGE_MIN
;
443 cx
= ICONITEMBORDER
+16*4;
446 if (cx
< nMinimumWidth
)
449 } else if (cx
> nMaximumWidth
)
454 SetColumnWidth(col
, cx
);
461 BOOL
CGitLogListBase::GetShortName(CString ref
, CString
&shortname
,CString prefix
)
463 //TRACE(_T("%s %s\r\n"),ref,prefix);
464 if(ref
.Left(prefix
.GetLength()) == prefix
)
466 shortname
= ref
.Right(ref
.GetLength()-prefix
.GetLength());
467 if(shortname
.Right(3)==_T("^{}"))
468 shortname
=shortname
.Left(shortname
.GetLength()-3);
474 void CGitLogListBase::FillBackGround(HDC hdc
, int Index
,CRect
&rect
)
478 SecureZeroMemory(&rItem
, sizeof(LVITEM
));
479 rItem
.mask
= LVIF_STATE
;
481 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
484 GitRev
* pLogEntry
= (GitRev
*)m_arShownList
.SafeGetAt(Index
);
487 if (m_Theme
.IsAppThemed() && m_bVista
)
489 int state
= LISS_NORMAL
;
490 if (rItem
.state
& LVIS_SELECTED
)
492 if (::GetFocus() == m_hWnd
)
493 state
|= LISS_SELECTED
;
495 state
|= LISS_SELECTEDNOTFOCUS
;
499 if(pLogEntry
->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_SQUASH
)
500 brush
= ::CreateSolidBrush(RGB(156,156,156));
501 else if(pLogEntry
->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_EDIT
)
502 brush
= ::CreateSolidBrush(RGB(200,200,128));
507 ::FillRect(hdc
, &rect
, brush
);
508 ::DeleteObject(brush
);
512 if (m_Theme
.IsBackgroundPartiallyTransparent(LVP_LISTITEM
, state
))
513 m_Theme
.DrawParentBackground(m_hWnd
, hdc
, &rect
);
515 CRect rectDraw
= rect
;
516 if(rItem
.state
& LVIS_SELECTED
)
517 rectDraw
.InflateRect(1,0);
519 rectDraw
.InflateRect(1,1);
521 m_Theme
.DrawBackground(hdc
, LVP_LISTITEM
, state
, rectDraw
, &rect
);
526 if (rItem
.state
& LVIS_SELECTED
)
528 if (::GetFocus() == m_hWnd
)
529 brush
= ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT
));
531 brush
= ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE
));
535 //if (pLogEntry->bCopiedSelf)
536 // brush = ::CreateSolidBrush(::GetSysColor(COLOR_MENU));
538 if(pLogEntry
->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_SQUASH
)
539 brush
= ::CreateSolidBrush(RGB(156,156,156));
540 else if(pLogEntry
->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_EDIT
)
541 brush
= ::CreateSolidBrush(RGB(200,200,128));
543 brush
= ::CreateSolidBrush(::GetSysColor(COLOR_WINDOW
));
548 ::FillRect(hdc
, &rect
, brush
);
549 ::DeleteObject(brush
);
553 void CGitLogListBase::DrawTagBranch(HDC hdc
,CRect
&rect
,INT_PTR index
)
555 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(index
);
558 SecureZeroMemory(&rItem
, sizeof(LVITEM
));
559 rItem
.mask
= LVIF_STATE
;
561 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
567 for(unsigned int i
=0;i
<m_HashMap
[data
->m_CommitHash
].size();i
++)
570 str
=m_HashMap
[data
->m_CommitHash
][i
];
577 //Determine label color
578 if(GetShortName(str
,shortname
,_T("refs/heads/")))
580 if( shortname
== m_CurrentBranch
)
581 colRef
= m_Colors
.GetColor(CColors::CurrentBranch
);
583 colRef
= m_Colors
.GetColor(CColors::LocalBranch
);
585 }else if(GetShortName(str
,shortname
,_T("refs/remotes/")))
587 colRef
= m_Colors
.GetColor(CColors::RemoteBranch
);
589 else if(GetShortName(str
,shortname
,_T("refs/tags/")))
591 colRef
= m_Colors
.GetColor(CColors::Tag
);
593 else if(GetShortName(str
,shortname
,_T("refs/stash")))
595 colRef
= m_Colors
.GetColor(CColors::Stash
);
596 shortname
=_T("stash");
597 }else if(GetShortName(str
,shortname
,_T("refs/bisect/")))
599 if(shortname
.Find(_T("good")) == 0)
601 colRef
= m_Colors
.GetColor(CColors::BisectGood
);
602 shortname
= _T("good");
605 if(shortname
.Find(_T("bad")) == 0)
607 colRef
= m_Colors
.GetColor(CColors::BisectBad
);
608 shortname
= _T("bad");
612 //When row selected, ajust label color
613 if (!(m_Theme
.IsAppThemed() && m_bVista
))
614 if (rItem
.state
& LVIS_SELECTED
)
615 colRef
= CColors::MixColors(colRef
, ::GetSysColor(COLOR_HIGHLIGHT
), 150);
617 brush
= ::CreateSolidBrush(colRef
);
619 if(!shortname
.IsEmpty() && (rt
.left
<rect
.right
) )
622 memset(&size
,0,sizeof(SIZE
));
623 GetTextExtentPoint32(hdc
, shortname
,shortname
.GetLength(),&size
);
625 rt
.SetRect(rt
.left
,rt
.top
,rt
.left
+size
.cx
,rt
.bottom
);
628 int textpos
= DT_CENTER
;
630 if(rt
.right
> rect
.right
)
632 rt
.right
= rect
.right
;
636 //Fill interior of ref label
637 ::FillRect(hdc
, &rt
, brush
);
643 W_Dc
.Draw3dRect(rectEdge
, m_Colors
.Lighten(colRef
,100), m_Colors
.Darken(colRef
,100));
644 rectEdge
.DeflateRect(1,1);
645 W_Dc
.Draw3dRect(rectEdge
, m_Colors
.Lighten(colRef
,50), m_Colors
.Darken(colRef
,50));
647 //Draw text inside label
648 if (m_Theme
.IsAppThemed() && m_bVista
)
650 int txtState
= LISS_NORMAL
;
651 if (rItem
.state
& LVIS_SELECTED
)
652 txtState
= LISS_SELECTED
;
654 m_Theme
.DrawText(hdc
, LVP_LISTITEM
, txtState
, shortname
, -1, textpos
| DT_SINGLELINE
| DT_VCENTER
, 0, &rt
);
658 W_Dc
.SetBkMode(TRANSPARENT
);
659 if (rItem
.state
& LVIS_SELECTED
)
661 COLORREF clrNew
= ::GetSysColor(COLOR_HIGHLIGHTTEXT
);
662 COLORREF clrOld
= ::SetTextColor(hdc
,clrNew
);
663 ::DrawText(hdc
,shortname
,shortname
.GetLength(),&rt
,textpos
| DT_SINGLELINE
| DT_VCENTER
);
664 ::SetTextColor(hdc
,clrOld
);
667 ::DrawText(hdc
,shortname
,shortname
.GetLength(),&rt
,textpos
| DT_SINGLELINE
| DT_VCENTER
);
671 //::MoveToEx(hdc,rt.left,rt.top,NULL);
672 //::LineTo(hdc,rt.right,rt.top);
673 //::LineTo(hdc,rt.right,rt.bottom);
674 //::LineTo(hdc,rt.left,rt.bottom);
675 //::LineTo(hdc,rt.left,rt.top);
680 ::DeleteObject(brush
);
684 if (m_Theme
.IsAppThemed() && m_bVista
)
686 int txtState
= LISS_NORMAL
;
687 if (rItem
.state
& LVIS_SELECTED
)
688 txtState
= LISS_SELECTED
;
690 m_Theme
.DrawText(hdc
, LVP_LISTITEM
, txtState
, data
->GetSubject(), -1, DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
, 0, &rt
);
694 if (rItem
.state
& LVIS_SELECTED
)
696 COLORREF clrOld
= ::SetTextColor(hdc
,::GetSysColor(COLOR_HIGHLIGHTTEXT
));
697 ::DrawText(hdc
,data
->GetSubject(),data
->GetSubject().GetLength(),&rt
,DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
);
698 ::SetTextColor(hdc
,clrOld
);
701 ::DrawText(hdc
,data
->GetSubject(),data
->GetSubject().GetLength(),&rt
,DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
);
708 static COLORREF
blend(const COLORREF
& col1
, const COLORREF
& col2
, int amount
= 128) {
710 // Returns ((256 - amount)*col1 + amount*col2) / 256;
711 return RGB(((256 - amount
)*GetRValue(col1
) + amount
*GetRValue(col2
) ) / 256,
712 ((256 - amount
)*GetGValue(col1
) + amount
*GetGValue(col2
) ) / 256,
713 ((256 - amount
)*GetBValue(col1
) + amount
*GetBValue(col2
) ) / 256);
716 Gdiplus::Color
GetGdiColor(COLORREF col
)
718 return Gdiplus::Color(GetRValue(col
),GetGValue(col
),GetBValue(col
));
720 void CGitLogListBase::paintGraphLane(HDC hdc
, int laneHeight
,int type
, int x1
, int x2
,
721 const COLORREF
& col
,const COLORREF
& activeColor
, int top
724 int h
= laneHeight
/ 2;
725 int m
= (x1
+ x2
) / 2;
726 int r
= (x2
- x1
) / 3;
729 #define P_CENTER m , h+top
730 #define P_0 x2, h+top
731 #define P_90 m , 0+top-1
732 #define P_180 x1, h+top
733 #define P_270 m , 2 * h+top +1
734 #define R_CENTER m - r, h - r+top, d, d
737 #define DELTA_UR_B 2*(x1 - m), 2*h +top
738 #define DELTA_UR_E 0*16, 90*16 +top // -,
740 #define DELTA_DR_B 2*(x1 - m), 2*-h +top
741 #define DELTA_DR_E 270*16, 90*16 +top // -'
743 #define DELTA_UL_B 2*(x2 - m), 2*h +top
744 #define DELTA_UL_E 90*16, 90*16 +top // ,-
746 #define DELTA_DL_B 2*(x2 - m),2*-h +top
747 #define DELTA_DL_E 180*16, 90*16 // '-
749 #define CENTER_UR x1, 2*h, 225
750 #define CENTER_DR x1, 0 , 135
751 #define CENTER_UL x2, 2*h, 315
752 #define CENTER_DL x2, 0 , 45
755 Gdiplus::Graphics
graphics( hdc
);
757 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
766 Gdiplus::LinearGradientBrush
gradient(
767 Gdiplus::Point(x1
-2, h
+top
-2),
768 Gdiplus::Point(P_270
),
769 GetGdiColor(activeColor
),GetGdiColor(col
));
772 Gdiplus::Pen
mypen(&gradient
,2);
773 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
775 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
776 graphics
.DrawArc(&mypen
,x1
-(x2
-x1
)/2-1,top
+h
-1, x2
-x1
,laneHeight
,270,90);
777 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
784 Gdiplus::LinearGradientBrush
gradient(
785 Gdiplus::Point(P_270
),
786 Gdiplus::Point(x2
+1, h
+top
-1),
787 GetGdiColor(col
),GetGdiColor(activeColor
));
790 Gdiplus::Pen
mypen(&gradient
,2);
791 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
793 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
794 graphics
.DrawArc(&mypen
,x1
+(x2
-x1
)/2,top
+h
-1, x2
-x1
,laneHeight
,180,90);
795 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
804 Gdiplus::LinearGradientBrush
gradient(
805 Gdiplus::Point(x1
-2, h
+top
-2),
806 Gdiplus::Point(P_90
),
807 GetGdiColor(activeColor
),GetGdiColor(col
));
809 Gdiplus::Pen
mypen(&gradient
,2);
811 graphics
.DrawArc(&mypen
,x1
-(x2
-x1
)/2-1,top
-h
-1, x2
-x1
,laneHeight
,0,90);
814 QConicalGradient
gradient(CENTER_DR
);
815 gradient
.setColorAt(0.375, activeCol
);
816 gradient
.setColorAt(0.625, col
);
817 myPen
.setBrush(gradient
);
819 p
->drawArc(P_CENTER
, DELTA_DR
);
828 //static QPen myPen(Qt::black, 2); // fast path here
830 pen
.CreatePen(PS_SOLID
,2,col
);
831 //myPen.setColor(col);
832 HPEN oldpen
=(HPEN
)::SelectObject(hdc
,(HPEN
)pen
);
834 Gdiplus::Pen
myPen(GetGdiColor(col
),2);
836 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
843 case Lanes::NOT_ACTIVE
:
844 case Lanes::MERGE_FORK
:
845 case Lanes::MERGE_FORK_R
:
846 case Lanes::MERGE_FORK_L
:
851 //DrawLine(hdc,P_90,P_270);
852 graphics
.DrawLine(&myPen
,P_90
,P_270
);
853 //p->drawLine(P_90, P_270);
857 //DrawLine(hdc,P_CENTER,P_270);
858 graphics
.DrawLine(&myPen
,P_CENTER
,P_270
);
859 //p->drawLine(P_CENTER, P_270);
863 case Lanes::BOUNDARY
:
864 case Lanes::BOUNDARY_C
:
865 case Lanes::BOUNDARY_R
:
866 case Lanes::BOUNDARY_L
:
867 //DrawLine(hdc,P_90, P_CENTER);
868 graphics
.DrawLine(&myPen
,P_90
,P_CENTER
);
869 //p->drawLine(P_90, P_CENTER);
875 myPen
.SetColor(GetGdiColor(activeColor
));
879 case Lanes::MERGE_FORK
:
884 case Lanes::CROSS_EMPTY
:
885 case Lanes::BOUNDARY_C
:
886 //DrawLine(hdc,P_180,P_0);
887 graphics
.DrawLine(&myPen
,P_180
,P_0
);
888 //p->drawLine(P_180, P_0);
890 case Lanes::MERGE_FORK_R
:
891 case Lanes::BOUNDARY_R
:
892 //DrawLine(hdc,P_180,P_CENTER);
893 graphics
.DrawLine(&myPen
,P_180
,P_CENTER
);
894 //p->drawLine(P_180, P_CENTER);
896 case Lanes::MERGE_FORK_L
:
899 case Lanes::BOUNDARY_L
:
900 //DrawLine(hdc,P_CENTER,P_0);
901 graphics
.DrawLine(&myPen
,P_CENTER
,P_0
);
902 //p->drawLine(P_CENTER, P_0);
908 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
911 brush
.CreateSolidBrush(col
);
912 HBRUSH oldbrush
=(HBRUSH
)::SelectObject(hdc
,(HBRUSH
)brush
);
914 Gdiplus::SolidBrush
myBrush(GetGdiColor(col
));
915 // center symbol, e.g. rect or ellipse
921 //p->setPen(Qt::NoPen);
923 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
924 graphics
.FillEllipse(&myBrush
, R_CENTER
);
925 //p->drawEllipse(R_CENTER);
927 case Lanes::MERGE_FORK
:
928 case Lanes::MERGE_FORK_R
:
929 case Lanes::MERGE_FORK_L
:
930 //p->setPen(Qt::NoPen);
932 //p->drawRect(R_CENTER);
933 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
934 graphics
.FillRectangle(&myBrush
, R_CENTER
);
936 case Lanes::UNAPPLIED
:
938 //p->setPen(Qt::NoPen);
939 //p->setBrush(Qt::red);
940 //p->drawRect(m - r, h - 1, d, 2);
941 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
942 graphics
.FillRectangle(&myBrush
,m
-r
,h
-1,d
,2);
946 //p->setPen(Qt::NoPen);
947 //p->setBrush(DARK_GREEN);
948 //p->drawRect(m - r, h - 1, d, 2);
949 //p->drawRect(m - 1, h - r, 2, d);
950 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
951 graphics
.FillRectangle(&myBrush
,m
-r
,h
-1,d
,2);
952 graphics
.FillRectangle(&myBrush
,m
-1,h
-r
,2,d
);
954 case Lanes::BOUNDARY
:
956 //p->drawEllipse(R_CENTER);
957 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
958 graphics
.DrawEllipse(&myPen
, R_CENTER
);
960 case Lanes::BOUNDARY_C
:
961 case Lanes::BOUNDARY_R
:
962 case Lanes::BOUNDARY_L
:
964 //p->drawRect(R_CENTER);
965 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
966 graphics
.FillRectangle(&myBrush
,R_CENTER
);
972 ::SelectObject(hdc
,oldpen
);
973 ::SelectObject(hdc
,oldbrush
);
982 void CGitLogListBase::DrawGraph(HDC hdc
,CRect
&rect
,INT_PTR index
)
986 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(index
);
987 if(data
->m_CommitHash
.IsEmpty())
992 SecureZeroMemory(&rItem
, sizeof(LVITEM
));
993 rItem
.mask
= LVIF_STATE
;
995 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
998 // p->translate(QPoint(opt.rect.left(), opt.rect.top()));
1000 if (data
->m_Lanes
.size() == 0)
1001 m_logEntries
.setLane(data
->m_CommitHash
);
1003 std::vector
<int>& lanes
=data
->m_Lanes
;
1004 UINT laneNum
= lanes
.size();
1005 UINT activeLane
= 0;
1006 for (UINT i
= 0; i
< laneNum
; i
++)
1007 if (Lanes::isMerge(lanes
[i
])) {
1013 int maxWidth
= rect
.Width();
1014 int lw
= 3 * rect
.Height() / 4; //laneWidth()
1016 COLORREF activeColor
= m_LineColors
[activeLane
% Lanes::COLORS_NUM
];
1017 //if (opt.state & QStyle::State_Selected)
1018 // activeColor = blend(activeColor, opt.palette.highlightedText().color(), 208);
1020 for (unsigned int i
= 0; i
< laneNum
&& x2
< maxWidth
; i
++)
1027 if (ln
== Lanes::EMPTY
)
1030 COLORREF color
= i
== activeLane
? activeColor
: m_LineColors
[i
% Lanes::COLORS_NUM
];
1031 paintGraphLane(hdc
, rect
.Height(),ln
, x1
+rect
.left
, x2
+rect
.left
, color
,activeColor
, rect
.top
);
1035 for (UINT i
= 0; i
< laneNum
&& x2
< maxWidth
; i
++) {
1041 if (ln
== Lanes::EMPTY
)
1044 UINT col
= ( Lanes:: isHead(ln
) ||Lanes:: isTail(ln
) || Lanes::isJoin(ln
)
1045 || ln
==Lanes:: CROSS_EMPTY
) ? activeLane
: i
;
1047 if (ln
== Lanes::CROSS
) {
1048 paintGraphLane(hdc
, rect
.Height(),Lanes::NOT_ACTIVE
, x1
, x2
, m_LineColors
[col
% Lanes::COLORS_NUM
],rect
.top
);
1049 paintGraphLane(hdc
, rect
.Height(),Lanes::CROSS
, x1
, x2
, m_LineColors
[activeLane
% Lanes::COLORS_NUM
],rect
.top
);
1051 paintGraphLane(hdc
, rect
.Height(),ln
, x1
, x2
, m_LineColors
[col
% Lanes::COLORS_NUM
],rect
.top
);
1057 void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1060 NMLVCUSTOMDRAW
* pLVCD
= reinterpret_cast<NMLVCUSTOMDRAW
*>( pNMHDR
);
1061 // Take the default processing unless we set this to something else below.
1062 *pResult
= CDRF_DODEFAULT
;
1064 if (m_bNoDispUpdates
)
1069 switch (pLVCD
->nmcd
.dwDrawStage
)
1073 *pResult
= CDRF_NOTIFYITEMDRAW
;
1077 case CDDS_ITEMPREPAINT
:
1079 // This is the prepaint stage for an item. Here's where we set the
1080 // item's text color.
1082 // Tell Windows to send draw notifications for each subitem.
1083 *pResult
= CDRF_NOTIFYSUBITEMDRAW
;
1085 COLORREF crText
= GetSysColor(COLOR_WINDOWTEXT
);
1087 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1089 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1093 if (data
->bCopiedSelf
)
1095 // only change the background color if the item is not 'hot' (on vista with m_Themes enabled)
1096 if (!m_Theme
.IsAppm_Themed() || !m_bVista
|| ((pLVCD
->nmcd
.uItemState
& CDIS_HOT
)==0))
1097 pLVCD
->clrTextBk
= GetSysColor(COLOR_MENU
);
1101 crText
= m_Colors
.GetColor(CColors::Modified
);
1103 if (data
->GetAction(this)& (CTGitPath::LOGACTIONS_REBASE_DONE
| CTGitPath::LOGACTIONS_REBASE_SKIP
) )
1104 crText
= RGB(128,128,128);
1106 if(data
->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_SQUASH
)
1107 pLVCD
->clrTextBk
= RGB(156,156,156);
1108 else if(data
->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_EDIT
)
1109 pLVCD
->clrTextBk
= RGB(200,200,128);
1111 pLVCD
->clrTextBk
= ::GetSysColor(COLOR_WINDOW
);
1113 if(data
->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_CURRENT
)
1115 SelectObject(pLVCD
->nmcd
.hdc
, m_boldFont
);
1116 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
1119 if(data
->m_CommitHash
.ToString() == m_HeadHash
)
1121 SelectObject(pLVCD
->nmcd
.hdc
, m_boldFont
);
1122 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
1125 // if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))
1126 // crText = GetSysColor(COLOR_GRAYTEXT);
1128 if (data
->m_CommitHash
.IsEmpty())
1130 //crText = GetSysColor(RGB(200,200,0));
1131 //SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1132 // We changed the font, so we're returning CDRF_NEWFONT. This
1133 // tells the control to recalculate the extent of the text.
1134 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
1138 if (m_arShownList
.GetCount() == (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1140 if (m_bStrictStopped
)
1141 crText
= GetSysColor(COLOR_GRAYTEXT
);
1143 // Store the color back in the NMLVCUSTOMDRAW struct.
1144 pLVCD
->clrText
= crText
;
1148 case CDDS_ITEMPREPAINT
|CDDS_ITEM
|CDDS_SUBITEM
:
1150 if ((m_bStrictStopped
)&&(m_arShownList
.GetCount() == (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
))
1152 pLVCD
->nmcd
.uItemState
&= ~(CDIS_SELECTED
|CDIS_FOCUS
);
1155 if (pLVCD
->iSubItem
== LOGLIST_GRAPH
)
1157 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
&& (!this->m_IsRebaseReplaceGraph
) )
1160 GetSubItemRect(pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_LABEL
, rect
);
1162 //TRACE(_T("A Graphic left %d right %d\r\n"),rect.left,rect.right);
1163 FillBackGround(pLVCD
->nmcd
.hdc
, (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
,rect
);
1165 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1166 if( !data
->m_CommitHash
.IsEmpty())
1167 DrawGraph(pLVCD
->nmcd
.hdc
,rect
,pLVCD
->nmcd
.dwItemSpec
);
1169 *pResult
= CDRF_SKIPDEFAULT
;
1174 if (pLVCD
->iSubItem
== LOGLIST_MESSAGE
)
1176 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1178 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1179 //if(!data->m_IsFull)
1181 //if(data->SafeFetchFullInfo(&g_Git))
1182 // this->Invalidate();
1183 //TRACE(_T("Update ... %d\r\n"),pLVCD->nmcd.dwItemSpec);
1186 if(m_HashMap
[data
->m_CommitHash
].size()!=0)
1190 GetSubItemRect(pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_BOUNDS
, rect
);
1192 FillBackGround(pLVCD
->nmcd
.hdc
, (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
,rect
);
1193 DrawTagBranch(pLVCD
->nmcd
.hdc
,rect
,pLVCD
->nmcd
.dwItemSpec
);
1195 *pResult
= CDRF_SKIPDEFAULT
;
1203 if (pLVCD
->iSubItem
== LOGLIST_ACTION
)
1205 if(this->m_IsIDReplaceAction
)
1207 *pResult
= CDRF_DODEFAULT
;
1210 *pResult
= CDRF_DODEFAULT
;
1212 if (m_arShownList
.GetCount() <= (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1216 int iconwidth
= ::GetSystemMetrics(SM_CXSMICON
);
1217 int iconheight
= ::GetSystemMetrics(SM_CYSMICON
);
1219 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
));
1221 GetSubItemRect(pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_BOUNDS
, rect
);
1222 //TRACE(_T("Action left %d right %d\r\n"),rect.left,rect.right);
1223 // Get the selected state of the
1224 // item being drawn.
1226 // Fill the background
1227 FillBackGround(pLVCD
->nmcd
.hdc
, (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
,rect
);
1229 // Draw the icon(s) into the compatible DC
1230 pLogEntry
->GetAction(this);
1232 if (!pLogEntry
->m_IsDiffFiles
)
1233 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+ ICONITEMBORDER
, rect
.top
, m_hFetchIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1235 if (pLogEntry
->GetAction(this) & CTGitPath::LOGACTIONS_MODIFIED
)
1236 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+ ICONITEMBORDER
, rect
.top
, m_hModifiedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1239 if (pLogEntry
->GetAction(this) & (CTGitPath::LOGACTIONS_ADDED
|CTGitPath::LOGACTIONS_COPY
) )
1240 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hAddedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1243 if (pLogEntry
->GetAction(this) & CTGitPath::LOGACTIONS_DELETED
)
1244 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hDeletedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1247 if (pLogEntry
->GetAction(this) & CTGitPath::LOGACTIONS_REPLACED
)
1248 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hReplacedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1250 *pResult
= CDRF_SKIPDEFAULT
;
1256 *pResult
= CDRF_DODEFAULT
;
1259 // CGitLogListBase message handlers
1261 void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1263 NMLVDISPINFO
*pDispInfo
= reinterpret_cast<NMLVDISPINFO
*>(pNMHDR
);
1265 // Create a pointer to the item
1266 LV_ITEM
* pItem
= &(pDispInfo
)->item
;
1268 // Do the list need text information?
1269 if (!(pItem
->mask
& LVIF_TEXT
))
1272 // By default, clear text buffer.
1273 lstrcpyn(pItem
->pszText
, _T(""), pItem
->cchTextMax
);
1275 bool bOutOfRange
= pItem
->iItem
>= ShownCountWithStopped();
1278 if (m_bNoDispUpdates
|| bOutOfRange
)
1281 // Which item number?
1282 int itemid
= pItem
->iItem
;
1283 GitRev
* pLogEntry
= NULL
;
1284 if (itemid
< m_arShownList
.GetCount())
1285 pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(pItem
->iItem
));
1290 temp
.Format(_T("%d"),pItem
->iItem
+1);
1294 temp
.Format(_T("%d"),m_arShownList
.GetCount()-pItem
->iItem
);
1298 switch (pItem
->iSubItem
)
1300 case this->LOGLIST_GRAPH
: //Graphic
1302 case this->LOGLIST_REBASE
:
1304 if(this->m_IsRebaseReplaceGraph
)
1307 path
.m_Action
=pLogEntry
->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_MODE_MASK
;
1308 lstrcpyn(pItem
->pszText
,path
.GetActionName(), pItem
->cchTextMax
);
1312 case this->LOGLIST_ACTION
: //action -- no text in the column
1314 case this->LOGLIST_HASH
:
1316 lstrcpyn(pItem
->pszText
, pLogEntry
->m_CommitHash
.ToString(), pItem
->cchTextMax
);
1318 case this->LOGLIST_ID
:
1319 if(this->m_IsIDReplaceAction
)
1320 lstrcpyn(pItem
->pszText
, temp
, pItem
->cchTextMax
);
1322 case this->LOGLIST_MESSAGE
: //Message
1324 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetSubject(), pItem
->cchTextMax
);
1326 case this->LOGLIST_AUTHOR
: //Author
1328 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetAuthorName(), pItem
->cchTextMax
);
1330 case this->LOGLIST_DATE
: //Date
1331 if ( pLogEntry
&& (!pLogEntry
->m_CommitHash
.IsEmpty()) )
1332 lstrcpyn(pItem
->pszText
,
1333 CAppUtils::FormatDateAndTime( pLogEntry
->GetAuthorDate(), m_DateFormat
, true, m_bRelativeTimes
),
1337 case this->LOGLIST_EMAIL
:
1339 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetAuthorEmail(), pItem
->cchTextMax
);
1342 case this->LOGLIST_COMMIT_NAME
: //Commit
1344 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetCommitterName(), pItem
->cchTextMax
);
1347 case this->LOGLIST_COMMIT_EMAIL
: //Commit Email
1349 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetCommitterEmail(), pItem
->cchTextMax
);
1352 case this->LOGLIST_COMMIT_DATE
: //Commit Date
1354 lstrcpyn(pItem
->pszText
,
1355 CAppUtils::FormatDateAndTime( pLogEntry
->GetCommitterDate(), m_DateFormat
, true, m_bRelativeTimes
),
1358 case this->LOGLIST_BUG
: //Bug ID
1360 lstrcpyn(pItem
->pszText
, (LPCTSTR
)this->m_ProjectProperties
.FindBugID(pLogEntry
->GetSubject()), pItem
->cchTextMax
);
1368 void CGitLogListBase::OnContextMenu(CWnd
* pWnd
, CPoint point
)
1371 if (pWnd
== GetHeaderCtrl())
1373 return m_ColumnManager
.OnContextMenuHeader(pWnd
,point
,!!IsGroupViewEnabled());
1376 int selIndex
= GetSelectionMark();
1378 return; // nothing selected, nothing to do with a context menu
1380 // if the user selected the info text telling about not all revisions shown due to
1381 // the "stop on copy/rename" option, we also don't show the context menu
1382 if ((m_bStrictStopped
)&&(selIndex
== m_arShownList
.GetCount()))
1385 // if the context menu is invoked through the keyboard, we have to use
1386 // a calculated position on where to anchor the menu on
1387 if ((point
.x
== -1) && (point
.y
== -1))
1390 GetItemRect(selIndex
, &rect
, LVIR_LABEL
);
1391 ClientToScreen(&rect
);
1392 point
= rect
.CenterPoint();
1394 m_nSearchIndex
= selIndex
;
1395 m_bCancelled
= FALSE
;
1397 // calculate some information the context menu commands can use
1398 // CString pathURL = GetURLFromPath(m_path);
1400 POSITION pos
= GetFirstSelectedItemPosition();
1401 int indexNext
= GetNextSelectedItem(pos
);
1405 GitRev
* pSelLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(indexNext
));
1407 GitRev revSelected
= pSelLogEntry
->Rev
;
1408 GitRev revPrevious
= git_revnum_t(revSelected
)-1;
1409 if ((pSelLogEntry
->pArChangedPaths
)&&(pSelLogEntry
->pArChangedPaths
->GetCount() <= 2))
1411 for (int i
=0; i
<pSelLogEntry
->pArChangedPaths
->GetCount(); ++i
)
1413 LogChangedPath
* changedpath
= (LogChangedPath
*)pSelLogEntry
->pArChangedPaths
->SafeGetAt(i
);
1414 if (changedpath
->lCopyFromRev
)
1415 revPrevious
= changedpath
->lCopyFromRev
;
1418 GitRev revSelected2
;
1421 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1422 revSelected2
= pLogEntry
->Rev
;
1424 bool bAllFromTheSameAuthor
= true;
1425 CString firstAuthor
;
1426 CLogDataVector selEntries
;
1427 GitRev revLowest
, revHighest
;
1428 GitRevRangeArray revisionRanges
;
1430 POSITION pos
= GetFirstSelectedItemPosition();
1431 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1432 revisionRanges
.AddRevision(pLogEntry
->Rev
);
1433 selEntries
.push_back(pLogEntry
);
1434 firstAuthor
= pLogEntry
->sAuthor
;
1435 revLowest
= pLogEntry
->Rev
;
1436 revHighest
= pLogEntry
->Rev
;
1439 pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1440 revisionRanges
.AddRevision(pLogEntry
->Rev
);
1441 selEntries
.push_back(pLogEntry
);
1442 if (firstAuthor
.Compare(pLogEntry
->sAuthor
))
1443 bAllFromTheSameAuthor
= false;
1444 revLowest
= (git_revnum_t(pLogEntry
->Rev
) > git_revnum_t(revLowest
) ? revLowest
: pLogEntry
->Rev
);
1445 revHighest
= (git_revnum_t(pLogEntry
->Rev
) < git_revnum_t(revHighest
) ? revHighest
: pLogEntry
->Rev
);
1451 int FirstSelect
=-1, LastSelect
=-1;
1452 pos
= GetFirstSelectedItemPosition();
1453 FirstSelect
= GetNextSelectedItem(pos
);
1456 LastSelect
= GetNextSelectedItem(pos
);
1458 //entry is selected, now show the popup menu
1460 CIconMenu subbranchmenu
, submenu
, gnudiffmenu
,diffmenu
;
1462 if (popup
.CreatePopupMenu())
1465 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_PICK
))
1466 popup
.AppendMenuIcon(ID_REBASE_PICK
, IDS_REBASE_PICK
, IDI_PICK
);
1468 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_SQUASH
))
1469 popup
.AppendMenuIcon(ID_REBASE_SQUASH
, IDS_REBASE_SQUASH
, IDI_SQUASH
);
1471 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_EDIT
))
1472 popup
.AppendMenuIcon(ID_REBASE_EDIT
, IDS_REBASE_EDIT
, IDI_EDIT
);
1474 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_SKIP
))
1475 popup
.AppendMenuIcon(ID_REBASE_SKIP
, IDS_REBASE_SKIP
, IDI_SKIP
);
1477 if(m_ContextMenuMask
&(GetContextMenuBit(ID_REBASE_SKIP
)|GetContextMenuBit(ID_REBASE_EDIT
)|
1478 GetContextMenuBit(ID_REBASE_SQUASH
)|GetContextMenuBit(ID_REBASE_PICK
)))
1479 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1481 if (GetSelectedCount() == 1)
1485 if( !pSelLogEntry
->m_CommitHash
.IsEmpty())
1487 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPARE
))
1488 popup
.AppendMenuIcon(ID_COMPARE
, IDS_LOG_POPUP_COMPARE
, IDI_DIFF
);
1490 // TortoiseMerge could be improved to take a /blame switch
1491 // and then not 'cat' the files from a unified diff but
1493 // But until that's implemented, the context menu entry for
1494 // this feature is commented out.
1495 //popup.AppendMenu(ID_BLAMECOMPARE, IDS_LOG_POPUP_BLAMECOMPARE, IDI_BLAME);
1498 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMMIT
))
1499 popup
.AppendMenuIcon(ID_COMMIT
, IDS_LOG_POPUP_COMMIT
, IDI_COMMIT
);
1501 if(m_ContextMenuMask
&GetContextMenuBit(ID_GNUDIFF1
))
1503 GitRev
*pRev
=pSelLogEntry
;
1504 if(pSelLogEntry
->m_ParentHash
.size()==0)
1506 pRev
->GetParentFromHash(pRev
->m_CommitHash
);
1508 if(pRev
->m_ParentHash
.size()<=1)
1510 popup
.AppendMenuIcon(ID_GNUDIFF1
, IDS_LOG_POPUP_GNUDIFF_CH
, IDI_DIFF
);
1514 gnudiffmenu
.CreatePopupMenu();
1515 popup
.AppendMenuIcon(ID_GNUDIFF1
,IDS_LOG_POPUP_GNUDIFF_PARENT
, IDI_DIFF
, gnudiffmenu
.m_hMenu
);
1517 gnudiffmenu
.AppendMenuIcon(ID_GNUDIFF1
+(0xFFFF<<16),_T("All Parents"));
1518 gnudiffmenu
.AppendMenuIcon(ID_GNUDIFF1
+(0xFFFE<<16),_T("Only Merged Files"));
1520 for(int i
=0;i
<pRev
->m_ParentHash
.size();i
++)
1523 str
.Format(_T("%d parent"), i
+1);
1524 gnudiffmenu
.AppendMenuIcon(ID_GNUDIFF1
+((i
+1)<<16),str
);
1529 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPAREWITHPREVIOUS
))
1532 GitRev
*pRev
=pSelLogEntry
;
1533 if(pSelLogEntry
->m_ParentHash
.size()==0)
1535 pRev
->GetParentFromHash(pRev
->m_CommitHash
);
1537 if(pRev
->m_ParentHash
.size()<=1)
1539 popup
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
, IDS_LOG_POPUP_COMPAREWITHPREVIOUS
, IDI_DIFF
);
1544 diffmenu
.CreatePopupMenu();
1545 popup
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
, IDS_LOG_POPUP_COMPAREWITHPREVIOUS
, IDI_DIFF
, diffmenu
.m_hMenu
);
1546 for(int i
=0;i
<pRev
->m_ParentHash
.size();i
++)
1549 str
.Format(_T("%d Parent"), i
+1);
1550 diffmenu
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
+((i
+1)<<16),str
);
1555 if(m_ContextMenuMask
&GetContextMenuBit(ID_BLAME
))
1556 popup
.AppendMenuIcon(ID_BLAME
, IDS_LOG_POPUP_BLAME
, IDI_BLAME
);
1558 //popup.AppendMenuIcon(ID_BLAMEWITHPREVIOUS, IDS_LOG_POPUP_BLAMEWITHPREVIOUS, IDI_BLAME);
1559 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1562 // if (!m_ProjectProperties.sWebViewerRev.IsEmpty())
1564 // popup.AppendMenuIcon(ID_VIEWREV, IDS_LOG_POPUP_VIEWREV);
1566 // if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
1568 // popup.AppendMenuIcon(ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
1570 // if ((!m_ProjectProperties.sWebViewerPathRev.IsEmpty())||
1571 // (!m_ProjectProperties.sWebViewerRev.IsEmpty()))
1573 // popup.AppendMenu(MF_SEPARATOR, NULL);
1578 // popup.AppendMenuIcon(ID_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
1580 if(!pSelLogEntry
->m_CommitHash
.IsEmpty())
1582 if((m_ContextMenuMask
&GetContextMenuBit(ID_LOG
)) &&
1583 GetSelectedCount() == 1)
1584 popup
.AppendMenuIcon(ID_LOG
, IDS_LOG_POPUP_LOG
, IDI_LOG
);
1586 format
.LoadString(IDS_LOG_POPUP_MERGEREV
);
1587 str
.Format(format
,g_Git
.GetCurrentBranch());
1589 if (m_ContextMenuMask
&GetContextMenuBit(ID_MERGEREV
))
1590 popup
.AppendMenuIcon(ID_MERGEREV
, str
, IDI_MERGE
);
1592 format
.LoadString(IDS_RESET_TO_THIS_FORMAT
);
1593 str
.Format(format
,g_Git
.GetCurrentBranch());
1595 if(m_ContextMenuMask
&GetContextMenuBit(ID_RESET
))
1596 popup
.AppendMenuIcon(ID_RESET
,str
,IDI_REVERT
);
1599 // Add Switch Branch express Menu
1600 if( this->m_HashMap
.find(pSelLogEntry
->m_CommitHash
) != m_HashMap
.end()
1601 && (m_ContextMenuMask
&GetContextMenuBit(ID_SWITCHBRANCH
))
1604 std::vector
<CString
*> branchs
;
1607 for(int i
=0;i
<m_HashMap
[pSelLogEntry
->m_CommitHash
].size();i
++)
1609 ref
= m_HashMap
[pSelLogEntry
->m_CommitHash
][i
];
1610 if(ref
.Find(_T("refs/heads/")) == 0)
1612 branchs
.push_back(&m_HashMap
[pSelLogEntry
->m_CommitHash
][i
]);
1617 str
.LoadString(IDS_SWITCH_BRANCH
);
1619 if(branchs
.size() == 1)
1622 str
+= _T('"') + branchs
[0]->Mid(11) + _T('"');
1623 popup
.AppendMenuIcon(ID_SWITCHBRANCH
,str
,IDI_SWITCH
);
1625 popup
.SetMenuItemData(ID_SWITCHBRANCH
,(ULONG_PTR
)branchs
[0]);
1628 else if( branchs
.size() > 1 )
1630 subbranchmenu
.CreatePopupMenu();
1631 for(int i
=0;i
<branchs
.size();i
++)
1633 subbranchmenu
.AppendMenuIcon(ID_SWITCHBRANCH
+(i
<<16), branchs
[i
]->Mid(11));
1634 subbranchmenu
.SetMenuItemData(ID_SWITCHBRANCH
+(i
<<16), (ULONG_PTR
) branchs
[i
]);
1637 popup
.AppendMenuIcon(ID_SWITCHBRANCH
, str
, IDI_SWITCH
, subbranchmenu
.m_hMenu
);
1641 if(m_ContextMenuMask
&GetContextMenuBit(ID_SWITCHTOREV
))
1642 popup
.AppendMenuIcon(ID_SWITCHTOREV
, IDS_SWITCH_TO_THIS
, IDI_SWITCH
);
1644 if(m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_BRANCH
))
1645 popup
.AppendMenuIcon(ID_CREATE_BRANCH
, IDS_CREATE_BRANCH_AT_THIS
, IDI_COPY
);
1647 if(m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_TAG
))
1648 popup
.AppendMenuIcon(ID_CREATE_TAG
,IDS_CREATE_TAG_AT_THIS
, IDI_TAG
);
1650 format
.LoadString(IDS_REBASE_THIS_FORMAT
);
1651 str
.Format(format
,g_Git
.GetCurrentBranch());
1653 if(pSelLogEntry
->m_CommitHash
!= m_HeadHash
)
1654 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_TO_VERSION
))
1655 popup
.AppendMenuIcon(ID_REBASE_TO_VERSION
, str
, IDI_REBASE
);
1657 if(m_ContextMenuMask
&GetContextMenuBit(ID_EXPORT
))
1658 popup
.AppendMenuIcon(ID_EXPORT
,IDS_EXPORT_TO_THIS
, IDI_EXPORT
);
1660 if (m_ContextMenuMask
&GetContextMenuBit(ID_REVERTREV
))
1661 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREV
, IDI_REVERT
);
1663 if (m_ContextMenuMask
&GetContextMenuBit(ID_EDITNOTE
))
1664 popup
.AppendMenuIcon(ID_EDITNOTE
, IDS_EDIT_NOTES
, IDI_EDIT
);
1666 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1671 if(!pSelLogEntry
->m_Ref
.IsEmpty() && GetSelectedCount() == 1)
1673 popup
.AppendMenuIcon(ID_REFLOG_DEL
, IDS_REFLOG_DEL
, IDI_DELETE
);
1674 popup
.AppendMenuIcon(ID_STASH_APPLY
, IDS_MENUSTASHAPPLY
, IDI_RELOCATE
);
1675 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1678 if (GetSelectedCount() >= 2)
1680 bool bAddSeparator
= false;
1681 if (IsSelectionContinuous() || (GetSelectedCount() == 2))
1683 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPARETWO
))
1684 popup
.AppendMenuIcon(ID_COMPARETWO
, IDS_LOG_POPUP_COMPARETWO
, IDI_DIFF
);
1687 if (GetSelectedCount() == 2)
1689 //popup.AppendMenuIcon(ID_BLAMETWO, IDS_LOG_POPUP_BLAMEREVS, IDI_BLAME);
1690 if(m_ContextMenuMask
&GetContextMenuBit(ID_GNUDIFF2
))
1691 popup
.AppendMenuIcon(ID_GNUDIFF2
, IDS_LOG_POPUP_GNUDIFF
, IDI_DIFF
);
1692 bAddSeparator
= true;
1697 //popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREVS, IDI_REVERT);
1699 // popup.AppendMenuIcon(ID_MERGEREV, IDS_LOG_POPUP_MERGEREVS, IDI_MERGE);
1700 bAddSeparator
= true;
1703 if (m_ContextMenuMask
&GetContextMenuBit(ID_REVERTREV
))
1704 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREVS
, IDI_REVERT
);
1707 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1710 if ( GetSelectedCount() >0 && (!pSelLogEntry
->m_CommitHash
.IsEmpty()))
1712 bool bAddSeparator
= false;
1713 if ( IsSelectionContinuous() && GetSelectedCount() >= 2 )
1715 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMBINE_COMMIT
))
1719 headindex
= this->GetHeadIndex();
1722 head
.Format(_T("HEAD~%d"),LastSelect
-headindex
);
1723 CGitHash hash
=g_Git
.GetHash(head
);
1724 GitRev
* pLastEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(LastSelect
));
1725 if(pLastEntry
->m_CommitHash
== hash
) {
1726 popup
.AppendMenuIcon(ID_COMBINE_COMMIT
,IDS_COMBINE_TO_ONE
,IDI_COMBINE
);
1727 bAddSeparator
= true;
1732 if(m_ContextMenuMask
&GetContextMenuBit(ID_CHERRY_PICK
)) {
1733 popup
.AppendMenuIcon(ID_CHERRY_PICK
, IDS_CHERRY_PICK_VERSION
, IDI_EXPORT
);
1734 bAddSeparator
= true;
1737 if(GetSelectedCount()<=2 || (IsSelectionContinuous() && GetSelectedCount() > 0))
1738 if(m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_PATCH
)) {
1739 popup
.AppendMenuIcon(ID_CREATE_PATCH
, IDS_CREATE_PATCH
, IDI_PATCH
);
1740 bAddSeparator
= true;
1744 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1748 // if ((selEntries.size() > 0)&&(bAllFromTheSameAuthor))
1750 // popup.AppendMenuIcon(ID_EDITAUTHOR, IDS_LOG_POPUP_EDITAUTHOR);
1752 // if (GetSelectedCount() == 1)
1754 // popup.AppendMenuIcon(ID_EDITLOG, IDS_LOG_POPUP_EDITLOG);
1755 // popup.AppendMenuIcon(ID_REVPROPS, IDS_REPOBROWSE_SHOWREVPROP, IDI_PROPERTIES); // "Show Revision Properties"
1756 // popup.AppendMenu(MF_SEPARATOR, NULL);
1760 if (GetSelectedCount() == 1)
1762 bool bAddSeparator
= false;
1763 if(m_ContextMenuMask
&GetContextMenuBit(ID_PUSH
) && m_HashMap
[pSelLogEntry
->m_CommitHash
].size() >= 1)
1765 // show the push-option only if the log entry has an associated local branch
1766 bool isLocal
= false;
1767 for(int i
=0; isLocal
== false && i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); i
++)
1769 if (m_HashMap
[pSelLogEntry
->m_CommitHash
][i
].Find(_T("refs/heads/")) == 0)
1774 popup
.AppendMenuIcon(ID_PUSH
, IDS_LOG_PUSH
, IDI_PUSH
);
1775 bAddSeparator
= true;
1779 if(m_ContextMenuMask
&GetContextMenuBit(ID_DELETE
))
1781 if( this->m_HashMap
.find(pSelLogEntry
->m_CommitHash
) != m_HashMap
.end() )
1784 if( m_HashMap
[pSelLogEntry
->m_CommitHash
].size() == 1 )
1786 str
.LoadString(IDS_DELETE_BRANCHTAG_SHORT
);
1788 str
+=m_HashMap
[pSelLogEntry
->m_CommitHash
].at(0);
1789 popup
.AppendMenuIcon(ID_DELETE
, str
, IDI_DELETE
);
1790 bAddSeparator
= true;
1792 else if( m_HashMap
[pSelLogEntry
->m_CommitHash
].size() > 1 )
1794 str
.LoadString(IDS_DELETE_BRANCHTAG
);
1795 submenu
.CreatePopupMenu();
1796 for(int i
=0;i
<m_HashMap
[pSelLogEntry
->m_CommitHash
].size();i
++)
1798 submenu
.AppendMenuIcon(ID_DELETE
+(i
<<16),m_HashMap
[pSelLogEntry
->m_CommitHash
][i
]);
1801 popup
.AppendMenuIcon(ID_DELETE
,str
, IDI_DELETE
, submenu
.m_hMenu
);
1802 bAddSeparator
= true;
1805 } // m_ContextMenuMask &GetContextMenuBit(ID_DELETE)
1807 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1808 } // GetSelectedCount() == 1
1810 if (GetSelectedCount() == 1)
1812 if(m_ContextMenuMask
&GetContextMenuBit(ID_COPYHASH
))
1813 popup
.AppendMenuIcon(ID_COPYHASH
, IDS_COPY_COMMIT_HASH
, IDI_COPYCLIP
);
1815 if (GetSelectedCount() != 0)
1817 if(m_ContextMenuMask
&GetContextMenuBit(ID_COPYCLIPBOARD
))
1818 popup
.AppendMenuIcon(ID_COPYCLIPBOARD
, IDS_LOG_POPUP_COPYTOCLIPBOARD
, IDI_COPYCLIP
);
1821 if(m_ContextMenuMask
&GetContextMenuBit(ID_FINDENTRY
))
1822 popup
.AppendMenuIcon(ID_FINDENTRY
, IDS_LOG_POPUP_FIND
, IDI_FILTEREDIT
);
1824 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, this, 0);
1825 // DialogEnableWindow(IDOK, FALSE);
1826 // SetPromptApp(&theApp);
1828 this->ContextMenuAction(cmd
, FirstSelect
, LastSelect
, &popup
);
1830 // EnableOKButton();
1831 } // if (popup.CreatePopupMenu())
1835 bool CGitLogListBase::IsSelectionContinuous()
1837 if ( GetSelectedCount()==1 )
1839 // if only one revision is selected, the selection is of course
1844 POSITION pos
= GetFirstSelectedItemPosition();
1845 bool bContinuous
= (m_arShownList
.GetCount() == (INT_PTR
)m_logEntries
.size());
1848 int itemindex
= GetNextSelectedItem(pos
);
1851 int nextindex
= GetNextSelectedItem(pos
);
1852 if (nextindex
- itemindex
> 1)
1854 bContinuous
= false;
1857 itemindex
= nextindex
;
1863 void CGitLogListBase::CopySelectionToClipBoard(bool HashOnly
)
1867 POSITION pos
= GetFirstSelectedItemPosition();
1871 sRev
.LoadString(IDS_LOG_REVISION
);
1873 sAuthor
.LoadString(IDS_LOG_AUTHOR
);
1875 sDate
.LoadString(IDS_LOG_DATE
);
1877 sMessage
.LoadString(IDS_LOG_MESSAGE
);
1880 CString sLogCopyText
;
1882 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1886 //pLogEntry->GetFiles(this)
1887 //LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
1889 for (int cpPathIndex
= 0; cpPathIndex
<pLogEntry
->GetFiles(this).GetCount(); ++cpPathIndex
)
1891 sPaths
+= ((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).GetActionName() + _T(" : ") + pLogEntry
->GetFiles(this)[cpPathIndex
].GetGitPathString();
1892 sPaths
+= _T("\r\n");
1895 CString body
= pLogEntry
->GetBody();
1896 body
.Replace(_T("\n"), _T("\r\n"));
1897 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"),
1898 (LPCTSTR
)sRev
, pLogEntry
->m_CommitHash
.ToString(),
1899 (LPCTSTR
)sAuthor
, (LPCTSTR
)pLogEntry
->GetAuthorName(),
1901 (LPCTSTR
)CAppUtils::FormatDateAndTime( pLogEntry
->GetAuthorDate(), m_DateFormat
, true, m_bRelativeTimes
),
1902 (LPCTSTR
)sMessage
, pLogEntry
->GetSubject().Trim() + _T("\r\n\r\n") + body
.Trim(),
1904 sClipdata
+= sLogCopyText
;
1907 sClipdata
+= pLogEntry
->m_CommitHash
;
1912 CStringUtils::WriteAsciiStringToClipboard(sClipdata
, GetSafeHwnd());
1917 void CGitLogListBase::DiffSelectedRevWithPrevious()
1919 if (m_bThreadRunning
)
1922 int FirstSelect
=-1, LastSelect
=-1;
1923 POSITION pos
= GetFirstSelectedItemPosition();
1924 FirstSelect
= GetNextSelectedItem(pos
);
1927 LastSelect
= GetNextSelectedItem(pos
);
1930 ContextMenuAction(ID_COMPAREWITHPREVIOUS
,FirstSelect
,LastSelect
, NULL
);
1933 UpdateLogInfoLabel();
1934 int selIndex
= m_LogList
.GetSelectionMark();
1937 int selCount
= m_LogList
.GetSelectedCount();
1941 // Find selected entry in the log list
1942 POSITION pos
= m_LogList
.GetFirstSelectedItemPosition();
1943 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(m_LogList
.GetNextSelectedItem(pos
)));
1944 long rev1
= pLogEntry
->Rev
;
1946 CTGitPath path
= m_path
;
1948 // See how many files under the relative root were changed in selected revision
1950 LogChangedPath
* changed
= NULL
;
1951 for (INT_PTR c
= 0; c
< pLogEntry
->pArChangedPaths
->GetCount(); ++c
)
1953 LogChangedPath
* cpath
= pLogEntry
->pArChangedPaths
->SafeGetAt(c
);
1954 if (cpath
&& cpath
-> sPath
.Left(m_sRelativeRoot
.GetLength()).Compare(m_sRelativeRoot
)==0)
1961 if (m_path
.IsDirectory() && nChanged
== 1)
1963 // We're looking at the log for a directory and only one file under dir was changed in the revision
1964 // Do diff on that file instead of whole directory
1965 path
.AppendPathString(changed
->sPath
.Mid(m_sRelativeRoot
.GetLength()));
1968 m_bCancelled
= FALSE
;
1969 DialogEnableWindow(IDOK
, FALSE
);
1970 SetPromptApp(&theApp
);
1971 theApp
.DoWaitCursor(1);
1975 GitDiff
diff(this, m_hWnd
, true);
1976 diff
.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
1977 diff
.SetHEADPeg(m_LogRevision
);
1978 diff
.ShowCompare(path
, rev2
, path
, rev1
);
1982 CAppUtils::StartShowCompare(m_hWnd
, path
, rev2
, path
, rev1
, GitRev(), m_LogRevision
, !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
1985 theApp
.DoWaitCursor(-1);
1990 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1992 LPNMLVFINDITEM pFindInfo
= reinterpret_cast<LPNMLVFINDITEM
>(pNMHDR
);
1995 if (pFindInfo
->lvfi
.flags
& LVFI_PARAM
)
1997 if ((pFindInfo
->iStart
< 0)||(pFindInfo
->iStart
>= m_arShownList
.GetCount()))
1999 if (pFindInfo
->lvfi
.psz
== 0)
2002 CString sCmp
= pFindInfo
->lvfi
.psz
;
2004 for (int i
=pFindInfo
->iStart
; i
<m_arShownList
.GetCount(); ++i
)
2006 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(i
));
2007 sRev
.Format(_T("%ld"), pLogEntry
->Rev
);
2008 if (pFindInfo
->lvfi
.flags
& LVFI_PARTIAL
)
2010 if (sCmp
.Compare(sRev
.Left(sCmp
.GetLength()))==0)
2018 if (sCmp
.Compare(sRev
)==0)
2025 if (pFindInfo
->lvfi
.flags
& LVFI_WRAP
)
2027 for (int i
=0; i
<pFindInfo
->iStart
; ++i
)
2029 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(i
));
2030 sRev
.Format(_T("%ld"), pLogEntry
->Rev
);
2031 if (pFindInfo
->lvfi
.flags
& LVFI_PARTIAL
)
2033 if (sCmp
.Compare(sRev
.Left(sCmp
.GetLength()))==0)
2041 if (sCmp
.Compare(sRev
)==0)
2053 int CGitLogListBase::FillGitLog(CTGitPath
*path
,int info
,CString
*from
,CString
*to
)
2058 this->m_arShownList
.SafeRemoveAll();
2060 this->m_logEntries
.ClearAll();
2061 this->m_logEntries
.ParserFromLog(path
,-1,info
,from
,to
);
2063 //this->m_logEntries.ParserFromLog();
2064 SetItemCountEx(this->m_logEntries
.size());
2066 for(unsigned int i
=0;i
<m_logEntries
.size();i
++)
2070 m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1).m_IsFull
=TRUE
;
2071 this->m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1));
2075 m_logEntries
.GetGitRevAt(i
).m_IsFull
=TRUE
;
2076 this->m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2086 int CGitLogListBase::BeginFetchLog()
2090 this->m_arShownList
.SafeRemoveAll();
2092 this->m_logEntries
.ClearAll();
2095 this->m_LogCache
.ClearAllParent();
2097 m_LogCache
.FetchCacheIndex(g_Git
.m_CurrentDir
);
2100 if(this->m_Path
.IsEmpty())
2107 mask
= CGit::LOG_INFO_ONLY_HASH
| CGit::LOG_INFO_BOUNDARY
;
2108 // if(this->m_bAllBranch)
2109 mask
|= m_ShowMask
;
2113 this->m_logEntries
.insert(m_logEntries
.begin(),this->m_wcRev
.m_CommitHash
);
2115 this->m_LogCache
.m_HashMap
[m_wcRev
.m_CommitHash
]=m_wcRev
;
2118 CString
*pFrom
, *pTo
;
2120 CString
head(_T("HEAD"));
2121 if(!this->m_startrev
.IsEmpty())
2123 pFrom
= &this->m_startrev
;
2124 if(!this->m_endrev
.IsEmpty())
2125 pTo
= &this->m_endrev
;
2131 data
.m_From
= m_From
;
2134 #if 0 /* use tortoiegit filter */
2135 if(this->m_nSelectedFilter
== LOGFILTER_ALL
|| m_nSelectedFilter
== LOGFILTER_AUTHORS
)
2136 data
.m_Author
= this->m_sFilterText
;
2138 if(this->m_nSelectedFilter
== LOGFILTER_ALL
|| m_nSelectedFilter
== LOGFILTER_MESSAGES
)
2139 data
.m_MessageFilter
= this->m_sFilterText
;
2141 data
.m_IsRegex
= m_bFilterWithRegex
;
2144 CString cmd
=g_Git
.GetLogCmd(m_StartRef
,path
,-1,mask
,pFrom
,pTo
,true,&data
);
2146 //this->m_logEntries.ParserFromLog();
2147 if(IsInWorkingThread())
2149 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
);
2153 SetItemCountEx(this->m_logEntries
.size());
2158 if(g_Git
.IsInitRepos())
2161 if(git_open_log(&m_DllGitLog
,CUnicodeUtils::GetMulti(cmd
,CP_ACP
).GetBuffer()))
2169 BOOL
CGitLogListBase::PreTranslateMessage(MSG
* pMsg
)
2171 if (pMsg
->message
== WM_KEYDOWN
&& pMsg
->wParam
=='\r')
2173 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))
2175 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
2177 DiffSelectedRevWithPrevious();
2182 if (GetFocus()==GetDlgItem(IDC_LOGMSG
))
2191 if (m_hAccel
&& !bSkipAccelerator
)
2193 int ret
= TranslateAccelerator(m_hWnd
, m_hAccel
, pMsg
);
2199 //m_tooltips.RelayEvent(pMsg);
2200 return __super::PreTranslateMessage(pMsg
);
2203 void CGitLogListBase::OnNMDblclkLoglist(NMHDR
* /*pNMHDR*/, LRESULT
*pResult
)
2205 // a double click on an entry in the revision list has happened
2208 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
2209 DiffSelectedRevWithPrevious();
2212 int CGitLogListBase::FetchLogAsync(void * data
)
2215 m_bExitThread
=FALSE
;
2216 InterlockedExchange(&m_bThreadRunning
, TRUE
);
2217 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2218 m_LoadingThread
= AfxBeginThread(LogThreadEntry
, this, THREAD_PRIORITY_LOWEST
);
2219 if (m_LoadingThread
==NULL
)
2221 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2222 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2223 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2229 //this is the thread function which calls the subversion function
2230 UINT
CGitLogListBase::LogThreadEntry(LPVOID pVoid
)
2232 return ((CGitLogListBase
*)pVoid
)->LogThread();
2235 void CGitLogListBase::GetTimeRange(CTime
&oldest
, CTime
&latest
)
2238 oldest
=CTime::GetCurrentTime();
2239 latest
=CTime(1971,1,2,0,0,0);
2240 for(unsigned int i
=0;i
<m_logEntries
.size();i
++)
2242 if(m_logEntries
[i
].IsEmpty())
2245 if(m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime() < oldest
.GetTime())
2246 oldest
= m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime();
2248 if(m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime() > latest
.GetTime())
2249 latest
= m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime();
2257 UINT
CGitLogListBase::LogThread()
2259 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) GITLOG_START
,0);
2261 InterlockedExchange(&m_bThreadRunning
, TRUE
);
2262 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2268 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2269 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2274 tr1::wregex pat
;//(_T("Remove"), tr1::regex_constants::icase);
2275 bool bRegex
= false;
2276 if (m_bFilterWithRegex
)
2277 bRegex
= ValidateRegexp(m_sFilterText
, pat
, false);
2279 TRACE(_T("\n===Begin===\n"));
2280 //Update work copy item;
2282 if( m_logEntries
.size() > 0)
2284 GitRev
*pRev
= &m_logEntries
.GetGitRevAt(0);
2286 m_arShownList
.SafeAdd(pRev
);
2290 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2292 if(!g_Git
.IsInitRepos())
2294 g_Git
.m_critGitDllSec
.Lock();
2295 git_get_log_firstcommit(m_DllGitLog
);
2296 int total
= git_get_log_estimate_commit_count(m_DllGitLog
);
2297 g_Git
.m_critGitDllSec
.Unlock();
2300 t2
=t1
=GetTickCount();
2301 int oldprecentage
= 0;
2302 int oldsize
=m_logEntries
.size();
2306 g_Git
.m_critGitDllSec
.Lock();
2307 ret
=git_get_log_nextcommit(this->m_DllGitLog
,&commit
);
2308 g_Git
.m_critGitDllSec
.Unlock();
2313 //printf("%s\r\n",commit.GetSubject());
2317 CGitHash hash
= (char*)commit
.m_hash
;
2319 GitRev
*pRev
= m_LogCache
.GetCacheData(hash
);
2320 pRev
->m_GitCommit
= commit
;
2321 InterlockedExchange(&pRev
->m_IsCommitParsed
, FALSE
);
2324 g_Git
.m_critGitDllSec
.Lock();
2325 git_get_notes(commit
.m_hash
,¬e
);
2326 g_Git
.m_critGitDllSec
.Unlock();
2330 pRev
->m_Notes
.Empty();
2331 g_Git
.StringAppend(&pRev
->m_Notes
,(BYTE
*)note
);
2334 if(!pRev
->m_IsDiffFiles
)
2336 pRev
->m_CallDiffAsync
= DiffAsync
;
2339 pRev
->ParserParentFromCommit(&commit
);
2346 if(!m_sFilterText
.IsEmpty())
2348 if(!IsMatchFilter(bRegex
,pRev
,pat
))
2351 this->m_critSec
.Lock();
2352 m_logEntries
.push_back(hash
);
2353 m_arShownList
.SafeAdd(pRev
);
2354 this->m_critSec
.Unlock();
2358 if(t2
-t1
>500 || (m_logEntries
.size()-oldsize
>100))
2361 int percent
=m_logEntries
.size()*100/total
+ GITLOG_START
+1;
2364 if(percent
< GITLOG_START
)
2365 percent
= GITLOG_START
+1;
2367 oldsize
= m_logEntries
.size();
2368 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
|LVSICF_NOSCROLL
);
2370 //if( percent > oldprecentage )
2372 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) percent
,0);
2373 oldprecentage
= percent
;
2378 g_Git
.m_critGitDllSec
.Lock();
2379 git_close_log(m_DllGitLog
);
2380 g_Git
.m_critGitDllSec
.Unlock();
2384 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
|LVSICF_NOSCROLL
);
2385 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) GITLOG_END
,0);
2387 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2392 void CGitLogListBase::Refresh(BOOL IsCleanFilter
)
2394 SafeTerminateThread();
2396 this->SetItemCountEx(0);
2401 //Update branch and Tag info
2403 //Assume Thread have exited
2404 //if(!m_bThreadRunning)
2406 m_logEntries
.clear();
2410 m_sFilterText
.Empty();
2415 InterlockedExchange(&m_bExitThread
,FALSE
);
2417 InterlockedExchange(&m_bThreadRunning
, TRUE
);
2418 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2419 if ( (m_LoadingThread
=AfxBeginThread(LogThreadEntry
, this)) ==NULL
)
2421 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2422 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2423 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2427 bool CGitLogListBase::ValidateRegexp(LPCTSTR regexp_str
, tr1::wregex
& pat
, bool bMatchCase
/* = false */)
2431 tr1::regex_constants::syntax_option_type type
= tr1::regex_constants::ECMAScript
;
2433 type
|= tr1::regex_constants::icase
;
2434 pat
= tr1::wregex(regexp_str
, type
);
2437 catch (exception
) {}
2440 BOOL
CGitLogListBase::IsMatchFilter(bool bRegex
, GitRev
*pRev
, tr1::wregex
&pat
)
2443 tr1::regex_constants::match_flag_type flags
= tr1::regex_constants::match_any
;
2446 if ((bRegex
)&&(m_bFilterWithRegex
))
2448 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_BUGID
))
2450 if(this->m_bShowBugtraqColumn
)
2452 CString sBugIds
= m_ProjectProperties
.FindBugID(pRev
->GetSubject());
2454 ATLTRACE(_T("bugID = \"%s\"\n"), sBugIds
);
2455 if (regex_search(wstring(sBugIds
), pat
, flags
))
2462 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_MESSAGES
))
2464 ATLTRACE(_T("messge = \"%s\"\n"), pRev
->GetSubject());
2465 if (regex_search(wstring((LPCTSTR
)pRev
->GetSubject()), pat
, flags
))
2470 ATLTRACE(_T("messge = \"%s\"\n"),pRev
->GetBody());
2471 if (regex_search(wstring((LPCTSTR
)pRev
->GetBody()), pat
, flags
))
2477 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_AUTHORS
))
2479 if (regex_search(wstring(pRev
->GetAuthorName()), pat
, flags
))
2484 if (regex_search(wstring(pRev
->GetCommitterName()), pat
, flags
))
2490 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_REVS
))
2492 sRev
.Format(_T("%s"), pRev
->m_CommitHash
.ToString());
2493 if (regex_search(wstring((LPCTSTR
)sRev
), pat
, flags
))
2499 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_PATHS
))
2501 CTGitPathList
*pathList
=NULL
;
2502 if( pRev
->m_IsDiffFiles
)
2503 pathList
= &pRev
->GetFiles(this);
2506 if(!pRev
->m_IsSimpleListReady
)
2507 pRev
->SafeGetSimpleList(&g_Git
);
2511 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
->GetCount(); ++cpPathIndex
)
2513 if (regex_search(wstring((LPCTSTR
)pathList
->m_paths
.at(cpPathIndex
).GetGitOldPathString()), pat
, flags
))
2517 if (regex_search(wstring((LPCTSTR
)pathList
->m_paths
.at(cpPathIndex
).GetGitPathString()), pat
, flags
))
2523 for(INT_PTR i
=0;i
<pRev
->m_SimpleFileList
.size();i
++)
2525 if (regex_search(wstring((LPCTSTR
)pRev
->m_SimpleFileList
[i
]), pat
, flags
))
2534 CString find
= m_sFilterText
;
2537 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_BUGID
))
2539 if(this->m_bShowBugtraqColumn
)
2541 CString sBugIds
= m_ProjectProperties
.FindBugID(pRev
->GetSubject());
2543 sBugIds
.MakeLower();
2544 if ((sBugIds
.Find(find
) >= 0))
2551 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_MESSAGES
))
2553 CString msg
= pRev
->GetSubject();
2555 msg
= msg
.MakeLower();
2556 if ((msg
.Find(find
) >= 0))
2561 msg
= pRev
->GetBody();
2563 msg
= msg
.MakeLower();
2564 if ((msg
.Find(find
) >= 0))
2570 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_AUTHORS
))
2572 CString msg
= pRev
->GetAuthorName();
2573 msg
= msg
.MakeLower();
2574 if ((msg
.Find(find
) >= 0))
2580 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_REVS
))
2582 sRev
.Format(_T("%s"), pRev
->m_CommitHash
.ToString());
2583 if ((sRev
.Find(find
) >= 0))
2589 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_PATHS
))
2591 CTGitPathList
*pathList
=NULL
;
2592 if( pRev
->m_IsDiffFiles
)
2593 pathList
= &pRev
->GetFiles(this);
2596 if(!pRev
->m_IsSimpleListReady
)
2597 pRev
->SafeGetSimpleList(&g_Git
);
2600 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
->GetCount() ; ++cpPathIndex
)
2602 CTGitPath
*cpath
= &pathList
->m_paths
.at(cpPathIndex
);
2603 CString path
= cpath
->GetGitOldPathString();
2605 if ((path
.Find(find
)>=0))
2609 path
= cpath
->GetGitPathString();
2611 if ((path
.Find(find
)>=0))
2617 for (INT_PTR i
=0;i
<pRev
->m_SimpleFileList
.size();i
++)
2619 CString path
= pRev
->m_SimpleFileList
[i
];
2621 if ((path
.Find(find
)>=0))
2627 } // else (from if (bRegex))
2632 void CGitLogListBase::RecalculateShownList(CThreadSafePtrArray
* pShownlist
)
2635 pShownlist
->SafeRemoveAll();
2637 tr1::wregex pat
;//(_T("Remove"), tr1::regex_constants::icase);
2638 bool bRegex
= false;
2639 if (m_bFilterWithRegex
)
2640 bRegex
= ValidateRegexp(m_sFilterText
, pat
, false);
2642 tr1::regex_constants::match_flag_type flags
= tr1::regex_constants::match_any
;
2644 for (DWORD i
=0; i
<m_logEntries
.size(); ++i
)
2646 if ((bRegex
)&&(m_bFilterWithRegex
))
2649 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_BUGID
))
2651 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR
)m_logEntries
[i
]->sBugIDs
);
2652 if (regex_search(wstring((LPCTSTR
)m_logEntries
[i
]->sBugIDs
), pat
, flags
)&&IsEntryInDateRange(i
))
2654 pShownlist
->SafeAdd(m_logEntries
[i
]);
2659 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_MESSAGES
))
2661 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries
.GetGitRevAt(i
).GetSubject());
2662 if (regex_search(wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetSubject()), pat
, flags
)&&IsEntryInDateRange(i
))
2664 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2668 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries
.GetGitRevAt(i
).GetBody());
2669 if (regex_search(wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetBody()), pat
, flags
)&&IsEntryInDateRange(i
))
2671 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2675 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_PATHS
))
2677 CTGitPathList pathList
= m_logEntries
.GetGitRevAt(i
).GetFiles(this);
2680 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
.GetCount() && bGoing
; ++cpPathIndex
)
2682 CTGitPath cpath
= pathList
[cpPathIndex
];
2683 if (regex_search(wstring((LPCTSTR
)cpath
.GetGitOldPathString()), pat
, flags
)&&IsEntryInDateRange(i
))
2685 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2689 if (regex_search(wstring((LPCTSTR
)cpath
.GetGitPathString()), pat
, flags
)&&IsEntryInDateRange(i
))
2691 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2695 if (regex_search(wstring((LPCTSTR
)cpath
.GetActionName()), pat
, flags
)&&IsEntryInDateRange(i
))
2697 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2703 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_AUTHORS
))
2705 if (regex_search(wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetAuthorName()), pat
, flags
)&&IsEntryInDateRange(i
))
2707 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2711 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_REVS
))
2713 sRev
.Format(_T("%s"), m_logEntries
.GetGitRevAt(i
).m_CommitHash
.ToString());
2714 if (regex_search(wstring((LPCTSTR
)sRev
), pat
, flags
)&&IsEntryInDateRange(i
))
2716 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2723 CString find
= m_sFilterText
;
2726 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_BUGID
))
2728 CString sBugIDs
= m_logEntries
[i
]->sBugIDs
;
2730 sBugIDs
= sBugIDs
.MakeLower();
2731 if ((sBugIDs
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
2733 pShownlist
->SafeAdd(m_logEntries
[i
]);
2738 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_MESSAGES
))
2740 CString msg
= m_logEntries
.GetGitRevAt(i
).GetSubject();
2742 msg
= msg
.MakeLower();
2743 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
2745 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2748 msg
= m_logEntries
.GetGitRevAt(i
).GetBody();
2750 msg
= msg
.MakeLower();
2751 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
2753 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2757 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_PATHS
))
2759 CTGitPathList pathList
= m_logEntries
.GetGitRevAt(i
).GetFiles(this);
2762 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
.GetCount() && bGoing
; ++cpPathIndex
)
2764 CTGitPath cpath
= pathList
[cpPathIndex
];
2765 CString path
= cpath
.GetGitOldPathString();
2767 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
2769 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2773 path
= cpath
.GetGitPathString();
2775 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
2777 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2781 path
= cpath
.GetActionName();
2783 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
2785 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2791 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_AUTHORS
))
2793 CString msg
= m_logEntries
.GetGitRevAt(i
).GetAuthorName();
2794 msg
= msg
.MakeLower();
2795 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
2797 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2801 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_REVS
))
2803 sRev
.Format(_T("%s"), m_logEntries
.GetGitRevAt(i
).m_CommitHash
.ToString());
2804 if ((sRev
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
2806 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2810 } // else (from if (bRegex))
2811 } // for (DWORD i=0; i<m_logEntries.size(); ++i)
2815 BOOL
CGitLogListBase::IsEntryInDateRange(int /*i*/)
2818 __time64_t time = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
2824 return time <= m_To;
2827 return time >= m_From;
2829 return ((time >= m_From)&&(time <= m_To));
2831 return TRUE
; /* git dll will filter time range */
2835 void CGitLogListBase::StartFilter()
2837 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2838 RecalculateShownList(&m_arShownList
);
2839 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2843 SetItemCountEx(ShownCountWithStopped());
2844 RedrawItems(0, ShownCountWithStopped());
2848 void CGitLogListBase::RemoveFilter()
2851 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2853 m_arShownList
.SafeRemoveAll();
2855 // reset the time filter too
2857 m_timFrom
= (__time64_t(m_tFrom
));
2858 m_timTo
= (__time64_t(m_tTo
));
2859 m_DateFrom
.SetTime(&m_timFrom
);
2860 m_DateTo
.SetTime(&m_timTo
);
2861 m_DateFrom
.SetRange(&m_timFrom
, &m_timTo
);
2862 m_DateTo
.SetRange(&m_timFrom
, &m_timTo
);
2865 for (DWORD i
=0; i
<m_logEntries
.size(); ++i
)
2867 if(this->m_IsOldFirst
)
2869 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1));
2872 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2875 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
2877 SetItemCountEx(ShownCountWithStopped());
2878 RedrawItems(0, ShownCountWithStopped());
2880 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2883 void CGitLogListBase::Clear()
2885 m_arShownList
.SafeRemoveAll();
2888 m_logEntries
.ClearAll();
2892 void CGitLogListBase::OnDestroy()
2894 // save the column widths to the registry
2897 SafeTerminateThread();
2898 SafeTerminateAsyncDiffThread();
2901 while(m_LogCache
.SaveCache())
2909 //if(CMessageBox::Show(NULL,_T("Cannot Save Log Cache to Disk. To retry click yes. To give up click no."),_T("TortoiseGit"),
2910 // MB_YESNO) == IDNO)
2914 CHintListCtrl::OnDestroy();
2917 LRESULT
CGitLogListBase::OnLoad(WPARAM wParam
,LPARAM lParam
)
2919 UNREFERENCED_PARAMETER(lParam
);
2922 this->GetItemRect(i
,&rect
,LVIR_BOUNDS
);
2923 this->InvalidateRect(rect
);
2929 * Save column widths to the registry
2931 void CGitLogListBase::SaveColumnWidths()
2933 int maxcol
= m_ColumnManager
.GetColumnCount();
2935 for (int col
= 0; col
< maxcol
; col
++)
2936 if (m_ColumnManager
.IsVisible (col
))
2937 m_ColumnManager
.ColumnResized (col
);
2939 m_ColumnManager
.WriteSettings();
2942 int CGitLogListBase::GetHeadIndex()
2944 if(m_HeadHash
.IsEmpty())
2947 for(int i
=0;i
<m_arShownList
.GetCount();i
++)
2949 GitRev
*pRev
= (GitRev
*)m_arShownList
[i
];
2952 if(pRev
->m_CommitHash
.ToString() == m_HeadHash
)
2958 void CGitLogListBase::OnFind()
2962 m_pFindDialog
= new CFindDlg(this);
2963 m_pFindDialog
->Create(this);
2966 void CGitLogListBase::OnHdnBegintrack(NMHDR
*pNMHDR
, LRESULT
*pResult
)
2968 m_ColumnManager
.OnHdnBegintrack(pNMHDR
, pResult
);
2970 void CGitLogListBase::OnHdnItemchanging(NMHDR
*pNMHDR
, LRESULT
*pResult
)
2972 if(!m_ColumnManager
.OnHdnItemchanging(pNMHDR
, pResult
))
2975 LRESULT
CGitLogListBase::OnFindDialogMessage(WPARAM
/*wParam*/, LPARAM
/*lParam*/)
2978 ASSERT(m_pFindDialog
!= NULL
);
2979 bool bFound
= false;
2982 if (m_pFindDialog
->IsTerminating())
2984 // invalidate the handle identifying the dialog box.
2985 m_pFindDialog
= NULL
;
2989 if(m_pFindDialog
->IsRef())
2992 str
=m_pFindDialog
->GetFindString();
2997 hash
= g_Git
.GetHash(str
);
3001 for (i
= 0; i
<m_arShownList
.GetCount(); i
++)
3003 GitRev
* pLogEntry
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
3004 if(pLogEntry
&& pLogEntry
->m_CommitHash
== hash
)
3014 if(m_pFindDialog
->FindNext())
3016 //read data from dialog
3017 CString FindText
= m_pFindDialog
->GetFindString();
3018 bool bMatchCase
= (m_pFindDialog
->MatchCase() == TRUE
);
3021 bool bRegex
= ValidateRegexp(FindText
, pat
, bMatchCase
);
3023 tr1::regex_constants::match_flag_type flags
= tr1::regex_constants::match_not_null
;
3026 for (i
= this->m_nSearchIndex
; i
<m_arShownList
.GetCount()&&!bFound
; i
++)
3028 GitRev
* pLogEntry
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
3031 str
+=pLogEntry
->m_CommitHash
.ToString();
3034 for(int j
=0;j
<this->m_HashMap
[pLogEntry
->m_CommitHash
].size();j
++)
3036 str
+=m_HashMap
[pLogEntry
->m_CommitHash
][j
];
3040 str
+=pLogEntry
->GetAuthorEmail();
3042 str
+=pLogEntry
->GetAuthorName();
3044 str
+=pLogEntry
->GetBody();
3046 str
+=pLogEntry
->GetCommitterEmail();
3048 str
+=pLogEntry
->GetCommitterName();
3050 str
+=pLogEntry
->GetSubject();
3054 /*Because changed files list is loaded on demand when gui show,
3055 files will empty when files have not fetched.
3057 we can add it back by using one-way diff(with outnumber changed and rename detect.
3058 here just need changed filename list. one-way is much quicker.
3060 if(pLogEntry
->m_IsFull
)
3062 for(int i
=0;i
<pLogEntry
->GetFiles(this).GetCount();i
++)
3064 str
+=pLogEntry
->GetFiles(this)[i
].GetWinPath();
3066 str
+=pLogEntry
->GetFiles(this)[i
].GetGitOldPathString();
3071 if(!pLogEntry
->m_IsSimpleListReady
)
3072 pLogEntry
->SafeGetSimpleList(&g_Git
);
3074 for(int i
=0;i
<pLogEntry
->m_SimpleFileList
.size();i
++)
3076 str
+=pLogEntry
->m_SimpleFileList
[i
];
3085 if (regex_search(wstring(str
), pat
, flags
))
3095 if (str
.Find(FindText
) >= 0)
3105 msg
= msg
.MakeLower();
3106 CString find
= FindText
.MakeLower();
3107 if (msg
.Find(find
) >= 0)
3114 } // for (i = this->m_nSearchIndex; i<m_arShownList.GetItemCount()&&!bFound; i++)
3116 } // if(m_pFindDialog->FindNext())
3117 //UpdateLogInfoLabel();
3121 this->m_nSearchIndex
= i
;
3122 EnsureVisible(i
, FALSE
);
3123 SetItemState(GetSelectionMark(), 0, LVIS_SELECTED
);
3124 SetItemState(i
, LVIS_SELECTED
, LVIS_SELECTED
);
3125 SetSelectionMark(i
);
3126 //FillLogMessageCtrl();
3129 if (m_nSearchIndex
>= m_arShownList
.GetCount())
3130 m_nSearchIndex
= (int)m_arShownList
.GetCount()-1;
3136 void CGitLogListBase::OnColumnResized(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3138 m_ColumnManager
.OnColumnResized(pNMHDR
,pResult
);
3143 void CGitLogListBase::OnColumnMoved(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3145 m_ColumnManager
.OnColumnMoved(pNMHDR
, pResult
);