1
// TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2021 - TortoiseGit
4 // Copyright (C) 2005-2007 Marco Costalba
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 // GitLogList.cpp : implementation file
23 #include "GitLogListBase.h"
25 #include "GitProgressDlg.h"
26 #include "ProgressDlg.h"
27 #include "MessageBox.h"
28 #include "LoglistUtils.h"
29 #include "StringUtils.h"
30 #include "UnicodeUtils.h"
31 #include "../TortoiseShell/Resource.h"
32 #include "CommonAppUtils.h"
35 const UINT
CGitLogListBase::m_FindDialogMessage
= RegisterWindowMessage(FINDMSGSTRING
);
36 const UINT
CGitLogListBase::m_ScrollToMessage
= RegisterWindowMessage(L
"TORTOISEGIT_LOG_SCROLLTO");
37 const UINT
CGitLogListBase::m_ScrollToRef
= RegisterWindowMessage(L
"TORTOISEGIT_LOG_SCROLLTOREF");
38 const UINT
CGitLogListBase::m_RebaseActionMessage
= RegisterWindowMessage(L
"TORTOISEGIT_LOG_REBASEACTION");
39 const UINT
CGitLogListBase::LOGLIST_RESET_WCREV
= RegisterWindowMessage(L
"TORTOISEGIT_LOG_RESET_WCREV");
41 long volatile CGitLogListBase::s_bThreadRunning
= FALSE
;
43 IMPLEMENT_DYNAMIC(CGitLogListBase
, CHintCtrl
<CResizableColumnsListCtrl
<CListCtrl
>>)
45 CGitLogListBase::CGitLogListBase() : CHintCtrl
<CResizableColumnsListCtrl
<CListCtrl
>>()
46 ,m_regMaxBugIDColWidth(L
"Software\\TortoiseGit\\MaxBugIDColWidth", 200)
48 ,m_bNoDispUpdates(FALSE
)
49 , m_ShowFilter(FILTERSHOW_ALL
)
51 , m_logEntries(&m_LogCache
)
52 , m_pFindDialog(nullptr)
53 , m_dwDefaultColumns(0)
54 , m_arShownList(&m_critSec
)
56 , m_bNoHightlightHead(FALSE
)
57 , m_ShowRefMask(LOGLIST_SHOWALLREFS
)
58 , m_bFullCommitMessageOnLogLine(false)
60 , m_AsyncThreadRunning(FALSE
)
61 , m_AsyncThreadExit(FALSE
)
62 , m_DiffingThread(nullptr)
63 , m_bIsCherryPick(false)
64 , m_bShowBugtraqColumn(false)
65 , m_IsIDReplaceAction(FALSE
)
67 , m_LoadingThread(nullptr)
68 , m_bExitThread(FALSE
)
70 , m_IsRebaseReplaceGraph(FALSE
)
71 , m_ContextMenuMask(0xFFFFFFFFFFFFFFFF)
72 , m_bDragndropEnabled(false)
75 , m_nDropMarkerLast(-1)
76 , m_nDropMarkerLastHot(-1)
77 , m_LogFilter(std::make_shared
<CLogDlgFilter
>())
78 , m_HashMap(std::make_shared
<MAP_HASH_NAME
>())
80 // use the default GUI font, create a copy of it and
81 // change the copy to BOLD (leave the rest of the font
86 int cx
= GetSystemMetrics(SM_CXSMICON
);
87 int cy
= GetSystemMetrics(SM_CYSMICON
);
88 m_hModifiedIcon
= CCommonAppUtils::LoadIconEx(IDI_ACTIONMODIFIED
, cx
, cy
);
89 m_hReplacedIcon
= CCommonAppUtils::LoadIconEx(IDI_ACTIONREPLACED
, cx
, cy
);
90 m_hConflictedIcon
= CCommonAppUtils::LoadIconEx(IDI_ACTIONCONFLICTED
, cx
, cy
);
91 m_hAddedIcon
= CCommonAppUtils::LoadIconEx(IDI_ACTIONADDED
, cx
, cy
);
92 m_hDeletedIcon
= CCommonAppUtils::LoadIconEx(IDI_ACTIONDELETED
, cx
, cy
);
93 m_hFetchIcon
= CCommonAppUtils::LoadIconEx(IDI_ACTIONFETCHING
, cx
, cy
);
95 m_Filter
.m_NumberOfLogsScale
= CRegDWORD(L
"Software\\TortoiseGit\\LogDialog\\NumberOfLogsScale", CFilterData::SHOW_NO_LIMIT
);
96 if (m_Filter
.m_NumberOfLogsScale
== CFilterData::SHOW_LAST_SEL_DATE
)
99 key
.Format(L
"Software\\TortoiseGit\\History\\LogDlg_Limits\\%s\\FromDate", static_cast<LPCWSTR
>(g_Git
.m_CurrentDir
));
100 key
.Replace(L
':', L
'_');
101 CString lastSelFromDate
= CRegString(key
);
102 if (lastSelFromDate
.GetLength() == 10)
104 CTime time
= CTime(_wtoi(static_cast<LPCWSTR
>(lastSelFromDate
.Left(4))), _wtoi(static_cast<LPCWSTR
>(lastSelFromDate
.Mid(5, 2))), _wtoi(static_cast<LPCWSTR
>(lastSelFromDate
.Mid(8, 2))), 0, 0, 0);
105 m_Filter
.m_From
= static_cast<DWORD
>(time
.GetTime());
108 m_Filter
.m_NumberOfLogs
= CRegDWORD(L
"Software\\TortoiseGit\\LogDialog\\NumberOfLogs", 1);
110 // get short/long datetime setting from registry
111 DWORD RegUseShortDateFormat
= CRegDWORD(L
"Software\\TortoiseGit\\LogDateFormat", TRUE
);
112 if ( RegUseShortDateFormat
)
114 m_DateFormat
= DATE_SHORTDATE
;
118 m_DateFormat
= DATE_LONGDATE
;
120 // get relative time display setting from registry
121 DWORD regRelativeTimes
= CRegDWORD(L
"Software\\TortoiseGit\\RelativeTimes", FALSE
);
122 m_bRelativeTimes
= (regRelativeTimes
!= 0);
124 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_PICK
);
125 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_SQUASH
);
126 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_EDIT
);
127 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_SKIP
);
128 m_ContextMenuMask
&= ~GetContextMenuBit(ID_LOG
);
129 m_ContextMenuMask
&= ~GetContextMenuBit(ID_BLAME
);
130 m_ContextMenuMask
&= ~GetContextMenuBit(ID_BLAMEPREVIOUS
);
132 m_ColumnRegKey
= L
"log";
134 m_bTagsBranchesOnRightSide
= !!CRegDWORD(L
"Software\\TortoiseGit\\DrawTagsBranchesOnRightSide", FALSE
);
135 m_bSymbolizeRefNames
= !!CRegDWORD(L
"Software\\TortoiseGit\\SymbolizeRefNames", FALSE
);
136 m_bIncludeBoundaryCommits
= !!CRegDWORD(L
"Software\\TortoiseGit\\LogIncludeBoundaryCommits", FALSE
);
137 m_bFullCommitMessageOnLogLine
= !!CRegDWORD(L
"Software\\TortoiseGit\\FullCommitMessageOnLogLine", FALSE
);
139 m_LineWidth
= max(1, static_cast<int>(CRegDWORD(L
"Software\\TortoiseGit\\TortoiseProc\\Graph\\LogLineWidth", 2)));
140 m_NodeSize
= max(1, static_cast<int>(CRegDWORD(L
"Software\\TortoiseGit\\TortoiseProc\\Graph\\LogNodeSize", 10)));
142 m_AsyncDiffEvent
= ::CreateEvent(nullptr, FALSE
, TRUE
, nullptr);
143 StartAsyncDiffThread();
146 HWND
CGitLogListBase::GetParentHWND()
148 auto owner
= GetSafeOwner();
150 return GetSafeHwnd();
151 return owner
->GetSafeHwnd();
154 int CGitLogListBase::AsyncDiffThread()
156 while(!m_AsyncThreadExit
)
158 ::WaitForSingleObject(m_AsyncDiffEvent
, INFINITE
);
160 GitRevLoglist
* pRev
= nullptr;
161 while(!m_AsyncThreadExit
&& !m_AsynDiffList
.empty())
163 m_AsynDiffListLock
.Lock();
164 pRev
= m_AsynDiffList
.back();
165 m_AsynDiffList
.pop_back();
166 m_AsynDiffListLock
.Unlock();
168 if( pRev
->m_CommitHash
.IsEmpty() )
170 if(pRev
->m_IsDiffFiles
)
173 auto filesWrapper
= pRev
->GetFilesWriter();
174 auto& files
= filesWrapper
.m_files
;
176 pRev
->m_ParentHash
.clear();
177 pRev
->m_ParentHash
.push_back(m_HeadHash
);
178 g_Git
.RefreshGitIndex();
179 g_Git
.GetWorkingTreeChanges(files
, false, nullptr, true); // filtering is done in LogDlg.cpp
180 auto& action
= pRev
->GetAction(this);
182 for (int j
= 0; j
< files
.GetCount(); ++j
)
183 action
|= files
[j
].m_Action
;
185 if (CString err
; pRev
->GetUnRevFiles().FillUnRev(CTGitPath::LOGACTIONS_UNVER
, nullptr, &err
))
187 MessageBox(L
"Failed to get UnRev file list\n" + err
, L
"TortoiseGit", MB_OK
| MB_ICONERROR
);
188 InterlockedExchange(&m_AsyncThreadRunning
, FALSE
);
192 InterlockedExchange(&pRev
->m_IsDiffFiles
, TRUE
);
194 CString body
= L
"\n";
195 body
.AppendFormat(IDS_FILESCHANGES
, files
.GetCount());
196 pRev
->GetBody() = body
;
197 ::PostMessage(m_hWnd
, MSG_LOADED
, 0, 0);
198 this->GetParent()->PostMessage(WM_COMMAND
, MSG_FETCHED_DIFF
, 0);
202 if (!pRev
->CheckAndDiff())
203 { // fetch change file list
204 for (int i
= GetTopIndex(); !m_AsyncThreadExit
&& i
<= GetTopIndex() + GetCountPerPage(); ++i
)
206 if (i
< static_cast<int>(m_arShownList
.size()))
208 GitRevLoglist
* data
= m_arShownList
.SafeGetAt(i
);
209 if(data
->m_CommitHash
== pRev
->m_CommitHash
)
211 ::PostMessage(m_hWnd
, MSG_LOADED
, i
, 0);
217 if(!m_AsyncThreadExit
&& GetSelectedCount() == 1)
219 POSITION pos
= GetFirstSelectedItemPosition();
220 int nItem
= GetNextSelectedItem(pos
);
224 GitRevLoglist
* data
= m_arShownList
.SafeGetAt(nItem
);
226 if(data
->m_CommitHash
== pRev
->m_CommitHash
)
227 this->GetParent()->PostMessage(WM_COMMAND
, MSG_FETCHED_DIFF
, 0);
233 InterlockedExchange(&m_AsyncThreadRunning
, FALSE
);
236 void CGitLogListBase::hideFromContextMenu(unsigned __int64 hideMask
, bool exclusivelyShow
)
239 m_ContextMenuMask
&= hideMask
;
241 m_ContextMenuMask
&= ~hideMask
;
244 CGitLogListBase::~CGitLogListBase()
246 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
247 this->m_arShownList
.SafeRemoveAll();
249 m_logEntries
.ClearAll();
251 SafeTerminateThread();
252 SafeTerminateAsyncDiffThread();
255 CloseHandle(m_AsyncDiffEvent
);
259 BEGIN_MESSAGE_MAP(CGitLogListBase
, CHintCtrl
<CResizableColumnsListCtrl
<CListCtrl
>>)
260 ON_REGISTERED_MESSAGE(m_FindDialogMessage
, OnFindDialogMessage
)
261 ON_REGISTERED_MESSAGE(m_ScrollToMessage
, OnScrollToMessage
)
262 ON_REGISTERED_MESSAGE(m_ScrollToRef
, OnScrollToRef
)
263 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW
, OnNMCustomdrawLoglist
)
264 ON_NOTIFY_REFLECT(LVN_GETDISPINFO
, OnLvnGetdispinfoLoglist
)
266 ON_NOTIFY_REFLECT(NM_DBLCLK
, OnNMDblclkLoglist
)
267 ON_NOTIFY_REFLECT(LVN_ODFINDITEM
,OnLvnOdfinditemLoglist
)
270 ON_MESSAGE(MSG_LOADED
,OnLoad
)
272 ON_WM_MEASUREITEM_REFLECT()
273 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW
, 0, 0xFFFF, &OnToolTipText
)
274 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA
, 0, 0xFFFF, &OnToolTipText
)
277 ON_NOTIFY_REFLECT(LVN_BEGINDRAG
, OnBeginDrag
)
280 void CGitLogListBase::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct
)
282 //if (m_nRowHeight>0)
283 lpMeasureItemStruct
->itemHeight
= CDPIAware::Instance().ScaleY(50);
286 int CGitLogListBase:: OnCreate(LPCREATESTRUCT lpCreateStruct
)
289 return __super::OnCreate(lpCreateStruct
);
292 void CGitLogListBase::SetStyle()
294 SetExtendedStyle(LVS_EX_INFOTIP
| LVS_EX_DOUBLEBUFFER
| LVS_EX_SUBITEMIMAGES
| LVS_EX_FULLROWSELECT
);
297 void CGitLogListBase::PreSubclassWindow()
300 // load the icons for the action columns
301 // m_Theme.Open(m_hWnd, L"ListView");
302 SetWindowTheme(m_hWnd
, L
"Explorer", nullptr);
303 __super::PreSubclassWindow();
306 CString
CGitLogListBase::GetRebaseActionName(int action
)
308 if (action
& LOGACTIONS_REBASE_EDIT
)
309 return MAKEINTRESOURCE(IDS_PATHACTIONS_EDIT
);
310 if (action
& LOGACTIONS_REBASE_SQUASH
)
311 return MAKEINTRESOURCE(IDS_PATHACTIONS_SQUASH
);
312 if (action
& LOGACTIONS_REBASE_PICK
)
313 return MAKEINTRESOURCE(IDS_PATHACTIONS_PICK
);
314 if (action
& LOGACTIONS_REBASE_SKIP
)
315 return MAKEINTRESOURCE(IDS_PATHACTIONS_SKIP
);
317 return MAKEINTRESOURCE(IDS_PATHACTIONS_UNKNOWN
);
320 void CGitLogListBase::InsertGitColumn()
325 if (CRegDWORD(L
"Software\\TortoiseGit\\LogFontForLogCtrl", FALSE
))
327 CCommonAppUtils::CreateFontForLogs(m_Font
);
331 // use the default font, create a copy of it and
332 // change the copy to BOLD (leave the rest of the font
335 GetFont()->GetLogFont(&lf
);
336 lf
.lfWeight
= FW_BOLD
;
337 m_boldFont
.CreateFontIndirect(&lf
);
338 lf
.lfWeight
= FW_DONTCARE
;
340 m_FontItalics
.CreateFontIndirect(&lf
);
341 lf
.lfWeight
= FW_BOLD
;
342 m_boldItalicsFont
.CreateFontIndirect(&lf
);
344 // only load properties if we have a repository
345 if (GitAdminDir::IsWorkingTreeOrBareRepo(g_Git
.m_CurrentDir
))
346 UpdateProjectProperties();
348 static UINT normal
[] =
360 IDS_LOG_COMMIT_EMAIL
,
366 auto iconItemBorder
= CDPIAware::Instance().ScaleX(ICONITEMBORDER
);
367 auto columnWidth
= CDPIAware::Instance().ScaleX(ICONITEMBORDER
+ 16 * 4);
374 2 * iconItemBorder
+ GetSystemMetrics(SM_CXSMICON
) * 5,
375 CDPIAware::Instance().ScaleX(LOGLIST_MESSAGE_MIN
),
385 m_dwDefaultColumns
= GIT_LOG_GRAPH
|GIT_LOG_ACTIONS
|GIT_LOG_MESSAGE
|GIT_LOG_AUTHOR
|GIT_LOG_DATE
;
387 DWORD hideColumns
= 0;
388 if(this->m_IsRebaseReplaceGraph
)
390 hideColumns
|= GIT_LOG_GRAPH
;
391 m_dwDefaultColumns
|= GIT_LOG_REBASE
;
394 hideColumns
|= GIT_LOG_REBASE
;
396 if(this->m_IsIDReplaceAction
)
398 hideColumns
|= GIT_LOG_ACTIONS
;
399 m_dwDefaultColumns
|= GIT_LOG_ID
;
400 m_dwDefaultColumns
|= GIT_LOG_HASH
;
403 hideColumns
|= GIT_LOG_ID
;
404 if(this->m_bShowBugtraqColumn
)
405 m_dwDefaultColumns
|= GIT_LOGLIST_BUG
;
407 hideColumns
|= GIT_LOGLIST_BUG
;
408 if (CTGitPath(g_Git
.m_CurrentDir
).HasGitSVNDir())
409 m_dwDefaultColumns
|= GIT_LOGLIST_SVNREV
;
411 hideColumns
|= GIT_LOGLIST_SVNREV
;
414 m_ColumnManager
.SetNames(normal
, _countof(normal
));
415 constexpr int columnVersion
= 6; // adjust when changing number/names/etc. of columns
416 m_ColumnManager
.ReadSettings(m_dwDefaultColumns
, hideColumns
, m_ColumnRegKey
+ L
"loglist", columnVersion
, _countof(normal
), with
);
417 m_ColumnManager
.SetRightAlign(LOGLIST_ID
);
419 if (!(hideColumns
& GIT_LOG_ACTIONS
))
421 // Configure fake a imagelist for LogList with 1px width and height = GetSystemMetrics(SM_CYSMICON)
422 // to set the minimum item height: we draw icons in the actions column, but on High-DPI the
423 // display's font height may be less than small icon height.
424 ASSERT((GetStyle() & LVS_SHAREIMAGELISTS
) == 0);
425 HIMAGELIST hImageList
= ImageList_Create(1, GetSystemMetrics(SM_CYSMICON
), 0, 1, 0);
426 ListView_SetImageList(GetSafeHwnd(), hImageList
, LVSIL_SMALL
);
432 void CGitLogListBase::FillBackGround(HDC hdc
, DWORD_PTR Index
, CRect
&rect
)
434 LVITEM rItem
= { 0 };
435 rItem
.mask
= LVIF_STATE
;
436 rItem
.iItem
= static_cast<int>(Index
);
437 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
440 GitRevLoglist
* pLogEntry
= m_arShownList
.SafeGetAt(Index
);
441 HBRUSH brush
= nullptr;
443 if (pLogEntry
&& !(rItem
.state
& LVIS_SELECTED
))
445 int action
= pLogEntry
->GetRebaseAction();
446 if (action
& LOGACTIONS_REBASE_SQUASH
)
447 brush
= ::CreateSolidBrush(RGB(156,156,156));
448 else if (action
& LOGACTIONS_REBASE_EDIT
)
449 brush
= ::CreateSolidBrush(RGB(200,200,128));
451 else if (!IsAppThemed())
453 if (rItem
.state
& LVIS_SELECTED
)
455 if (::GetFocus() == m_hWnd
)
456 brush
= ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT
));
458 brush
= ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE
));
463 ::FillRect(hdc
, &rect
, brush
);
464 ::DeleteObject(brush
);
468 void DrawTrackingRoundRect(HDC hdc
, CRect rect
, HBRUSH brush
, COLORREF darkColor
)
470 POINT point
= { 4, 4 };
472 rt2
.DeflateRect(1, 1);
473 rt2
.OffsetRect(2, 2);
475 HPEN nullPen
= ::CreatePen(PS_NULL
, 0, 0);
476 HPEN oldpen
= static_cast<HPEN
>(::SelectObject(hdc
, nullPen
));
477 HBRUSH darkBrush
= static_cast<HBRUSH
>(::CreateSolidBrush(darkColor
));
478 HBRUSH oldbrush
= static_cast<HBRUSH
>(::SelectObject(hdc
, darkBrush
));
479 ::RoundRect(hdc
, rt2
.left
, rt2
.top
, rt2
.right
, rt2
.bottom
, point
.x
, point
.y
);
481 ::SelectObject(hdc
, brush
);
482 rt2
.OffsetRect(-2, -2);
483 ::RoundRect(hdc
, rt2
.left
, rt2
.top
, rt2
.right
, rt2
.bottom
, point
.x
, point
.y
);
484 ::SelectObject(hdc
, oldbrush
);
485 ::SelectObject(hdc
, oldpen
);
486 ::DeleteObject(nullPen
);
487 ::DeleteObject(darkBrush
);
490 void DrawUpstream(HDC hdc
, CRect rect
, COLORREF color
, int bold
)
492 HPEN pen
= ::CreatePen(PS_SOLID
, bold
, color
);
493 HPEN oldpen
= static_cast<HPEN
>(::SelectObject(hdc
, pen
));
494 ::MoveToEx(hdc
, rect
.left
+ 2 + bold
, rect
.top
+ 2 - bold
, nullptr);
495 ::LineTo(hdc
, rect
.left
+ 2 + bold
, rect
.bottom
+ 1 - bold
);
496 ::MoveToEx(hdc
, rect
.left
+ 3, rect
.top
+ 1, nullptr);
497 ::LineTo(hdc
, rect
.left
, rect
.top
+ 4);
498 ::MoveToEx(hdc
, rect
.left
+ 2 + bold
, rect
.top
+ 1, nullptr);
499 ::LineTo(hdc
, rect
.right
+ 1 + bold
, rect
.top
+ 4);
500 ::MoveToEx(hdc
, rect
.left
+ 1, rect
.top
+ 2 + bold
, nullptr);
501 ::LineTo(hdc
, rect
.right
+ 1 + bold
, rect
.top
+ 2 + bold
);
502 ::SelectObject(hdc
, oldpen
);
506 void CGitLogListBase::DrawTagBranchMessage(NMLVCUSTOMDRAW
* pLVCD
, const CRect
& rect
, INT_PTR index
, const std::vector
<REFLABEL
>& refList
)
508 GitRevLoglist
* data
= m_arShownList
.SafeGetAt(index
);
510 LVITEM rItem
= { 0 };
511 rItem
.mask
= LVIF_STATE
;
512 rItem
.iItem
= static_cast<int>(index
);
513 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
517 W_Dc
.Attach(pLVCD
->nmcd
.hdc
);
519 CAutoThemeData hTheme
;
521 hTheme
= OpenThemeData(m_hWnd
, L
"Explorer::ListView;ListView");
523 if (m_bTagsBranchesOnRightSide
)
525 HFONT oldFont
= static_cast<HFONT
>(SelectObject(pLVCD
->nmcd
.hdc
, GetStockObject(DEFAULT_GUI_FONT
)));
527 GetTextExtentPoint32(pLVCD
->nmcd
.hdc
, L
" ", 1, &oneSpaceSize
);
530 GetThemeMetric(hTheme
, pLVCD
->nmcd
.hdc
, LVP_LISTITEM
, LISS_NORMAL
, TMT_BORDERSIZE
, &borderWidth
);
531 SelectObject(pLVCD
->nmcd
.hdc
, oldFont
);
532 rt
.left
+= borderWidth
+ oneSpaceSize
.cx
;
537 GetTextExtentPoint32(pLVCD
->nmcd
.hdc
, L
" ", 1, &oneSpaceSize
);
538 DrawTagBranch(pLVCD
->nmcd
.hdc
, W_Dc
, hTheme
, rect
, rt
, rItem
, data
, refList
);
539 rt
.left
+= oneSpaceSize
.cx
;
542 CString msg
= MessageDisplayStr(data
);
543 int action
= data
->GetRebaseAction();
544 bool skip
= !!(action
& (LOGACTIONS_REBASE_DONE
| LOGACTIONS_REBASE_SKIP
));
545 std::vector
<CHARRANGE
> ranges
;
546 auto filter
= m_LogFilter
;
547 if ((filter
->GetSelectedFilters() & (LOGFILTER_SUBJECT
| (m_bFullCommitMessageOnLogLine
? LOGFILTER_MESSAGES
: 0))) && filter
->IsFilterActive())
548 filter
->GetMatchRanges(ranges
, msg
, 0);
551 int txtState
= LISS_NORMAL
;
552 if (rItem
.state
& LVIS_SELECTED
)
553 txtState
= LISS_SELECTED
;
556 DrawListItemWithMatchesRect(pLVCD
, ranges
, rt
, msg
, m_Colors
, hTheme
, txtState
);
559 DTTOPTS opts
= { 0 };
560 opts
.dwSize
= sizeof(opts
);
561 opts
.crText
= skip
? RGB(128, 128, 128) : CTheme::Instance().IsDarkTheme() ? CTheme::darkTextColor
: GetSysColor(COLOR_WINDOWTEXT
);
562 opts
.dwFlags
= DTT_TEXTCOLOR
;
563 DrawThemeTextEx(hTheme
, pLVCD
->nmcd
.hdc
, LVP_LISTITEM
, txtState
, msg
, -1, DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
| DT_END_ELLIPSIS
, &rt
, &opts
);
568 if ((rItem
.state
& LVIS_SELECTED
) && ::GetFocus() == m_hWnd
)
569 pLVCD
->clrText
= skip
? RGB(128, 128, 128) : ::GetSysColor(COLOR_HIGHLIGHTTEXT
);
571 pLVCD
->clrText
= skip
? RGB(128, 128, 128) : CTheme::Instance().IsDarkTheme() ? CTheme::darkTextColor
: GetSysColor(COLOR_WINDOWTEXT
);
573 DrawListItemWithMatchesRect(pLVCD
, ranges
, rt
, msg
, m_Colors
);
576 COLORREF clrOld
= ::SetTextColor(pLVCD
->nmcd
.hdc
, pLVCD
->clrText
);
577 ::DrawText(pLVCD
->nmcd
.hdc
, msg
, msg
.GetLength(), &rt
, DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
| DT_END_ELLIPSIS
);
578 ::SetTextColor(pLVCD
->nmcd
.hdc
, clrOld
);
582 if (m_bTagsBranchesOnRightSide
)
585 GetTextExtentPoint32(pLVCD
->nmcd
.hdc
, L
" ", 1, &oneSpaceSize
);
588 GetTextExtentPoint32(pLVCD
->nmcd
.hdc
, msg
, msg
.GetLength(), &size
);
590 rt
.left
+= oneSpaceSize
.cx
+ size
.cx
;
592 DrawTagBranch(pLVCD
->nmcd
.hdc
, W_Dc
, hTheme
, rect
, rt
, rItem
, data
, refList
);
598 void CGitLogListBase::DrawTagBranch(HDC hdc
, CDC
& W_Dc
, HTHEME hTheme
, const CRect
& rect
, CRect
& rt
, LVITEM
& rItem
, GitRevLoglist
* data
, const std::vector
<REFLABEL
>& refList
)
600 for (unsigned int i
= 0; i
< refList
.size(); ++i
)
602 CString shortname
= !refList
[i
].simplifiedName
.IsEmpty() ? refList
[i
].simplifiedName
: refList
[i
].name
;
604 COLORREF colRef
= refList
[i
].color
;
605 bool singleRemote
= refList
[i
].singleRemote
;
606 bool hasTracking
= refList
[i
].hasTracking
;
607 CGit::REF_TYPE refType
= refList
[i
].refType
;
609 //When row selected, ajust label color
612 if (rItem
.state
& LVIS_SELECTED
)
613 colRef
= CColors::MixColors(colRef
, ::GetSysColor(COLOR_HIGHLIGHT
), 150);
616 brush
= ::CreateSolidBrush(colRef
);
618 if (!shortname
.IsEmpty() && (rt
.left
< rect
.right
))
621 GetTextExtentPoint32(hdc
, shortname
, shortname
.GetLength(), &size
);
623 rt
.SetRect(rt
.left
, rt
.top
, rt
.left
+ size
.cx
, rt
.bottom
);
626 int textpos
= DT_CENTER
;
628 if (rt
.right
> rect
.right
)
630 rt
.right
= rect
.right
;
639 textRect
.OffsetRect(5, 0);
643 DrawTrackingRoundRect(hdc
, rt
, brush
, m_Colors
.Darken(colRef
, 100));
646 //Fill interior of ref label
647 ::FillRect(hdc
, &rt
, brush
);
655 W_Dc
.Draw3dRect(rectEdge
, m_Colors
.Lighten(colRef
, 100), m_Colors
.Darken(colRef
, 100));
656 rectEdge
.DeflateRect(1, 1);
657 W_Dc
.Draw3dRect(rectEdge
, m_Colors
.Lighten(colRef
, 50), m_Colors
.Darken(colRef
, 50));
660 if (refType
== CGit::REF_TYPE::ANNOTATED_TAG
)
663 POINT trianglept
[3] = { { rt
.right
- 8, rt
.top
}, { rt
.right
, (rt
.top
+ rt
.bottom
) / 2 }, { rt
.right
- 8, rt
.bottom
} };
664 HRGN hrgn
= ::CreatePolygonRgn(trianglept
, 3, ALTERNATE
);
665 ::FillRgn(hdc
, hrgn
, brush
);
666 ::DeleteObject(hrgn
);
667 ::MoveToEx(hdc
, trianglept
[0].x
- 1, trianglept
[0].y
, nullptr);
669 HPEN oldpen
= static_cast<HPEN
>(SelectObject(hdc
, pen
= ::CreatePen(PS_SOLID
, 2, m_Colors
.Lighten(colRef
, 50))));
670 ::LineTo(hdc
, trianglept
[1].x
- 1, trianglept
[1].y
- 1);
672 SelectObject(hdc
, pen
= ::CreatePen(PS_SOLID
, 2, m_Colors
.Darken(colRef
, 50)));
673 ::LineTo(hdc
, trianglept
[2].x
- 1, trianglept
[2].y
- 1);
675 SelectObject(hdc
, pen
= ::CreatePen(PS_SOLID
, 2, colRef
));
676 ::MoveToEx(hdc
, trianglept
[0].x
- 1, trianglept
[2].y
- 3, nullptr);
677 ::LineTo(hdc
, trianglept
[0].x
- 1, trianglept
[0].y
);
679 SelectObject(hdc
, oldpen
);
682 //Draw text inside label
683 bool customColor
= (colRef
& 0xff) * 30 + ((colRef
>> 8) & 0xff) * 59 + ((colRef
>> 16) & 0xff) * 11 <= 12800; // check if dark background
684 if (!customColor
&& IsAppThemed())
686 int txtState
= LISS_NORMAL
;
687 if (rItem
.state
& LVIS_SELECTED
)
688 txtState
= LISS_SELECTED
;
690 DTTOPTS opts
= { 0 };
691 opts
.dwSize
= sizeof(opts
);
692 opts
.crText
= GetSysColor(COLOR_WINDOWTEXT
);
693 opts
.dwFlags
= DTT_TEXTCOLOR
;
694 DrawThemeTextEx(hTheme
, hdc
, LVP_LISTITEM
, txtState
, shortname
, -1, textpos
| DT_SINGLELINE
| DT_VCENTER
, &textRect
, &opts
);
698 W_Dc
.SetBkMode(TRANSPARENT
);
699 if (customColor
|| (rItem
.state
& LVIS_SELECTED
))
701 COLORREF clrNew
= ::GetSysColor(COLOR_HIGHLIGHTTEXT
);
702 COLORREF clrOld
= ::SetTextColor(hdc
,clrNew
);
703 ::DrawText(hdc
, shortname
, shortname
.GetLength(), &textRect
, textpos
| DT_SINGLELINE
| DT_VCENTER
);
704 ::SetTextColor(hdc
,clrOld
);
708 COLORREF clrOld
= ::SetTextColor(hdc
, CTheme::Instance().IsDarkTheme() ? CTheme::darkTextColor
: GetSysColor(COLOR_WINDOWTEXT
));
709 ::DrawText(hdc
, shortname
, shortname
.GetLength(), &textRect
, textpos
| DT_SINGLELINE
| DT_VCENTER
);
710 ::SetTextColor(hdc
, clrOld
);
716 COLORREF color
= ::GetSysColor(customColor
? COLOR_HIGHLIGHTTEXT
: COLOR_WINDOWTEXT
);
717 int bold
= data
->m_CommitHash
== m_HeadHash
? 2 : 1;
719 newRect
.SetRect(rt
.left
+ 2, rt
.top
+ 4, rt
.left
+ 6, rt
.bottom
- 4);
720 DrawUpstream(hdc
, newRect
, color
, bold
);
723 if (!refList
[i
].fullName
.IsEmpty())
724 m_RefLabelPosMap
[refList
[i
].fullName
] = rt
;
726 rt
.left
= rt
.right
+ 1;
729 ::DeleteObject(brush
);
731 rt
.right
= rect
.right
;
734 Gdiplus::Color
GetGdiColor(COLORREF col
)
736 return Gdiplus::Color(GetRValue(col
),GetGValue(col
),GetBValue(col
));
738 void CGitLogListBase::paintGraphLane(HDC hdc
, int laneHeight
,int type
, int x1
, int x2
,
739 const COLORREF
& col
,const COLORREF
& activeColor
, int top
742 int h
= laneHeight
/ 2;
743 int m
= (x1
+ x2
) / 2;
744 int r
= (x2
- x1
) * m_NodeSize
/ 30;
747 #define P_CENTER m , h+top
748 #define P_0 x2, h+top
749 #define P_90 m , 0+top-1
750 #define P_180 x1, h+top
751 #define P_270 m , 2 * h+top +1
752 #define R_CENTER m - r, h - r+top, d, d
755 #define DELTA_UR_B 2*(x1 - m), 2*h +top
756 #define DELTA_UR_E 0*16, 90*16 +top // -,
758 #define DELTA_DR_B 2*(x1 - m), 2*-h +top
759 #define DELTA_DR_E 270*16, 90*16 +top // -'
761 #define DELTA_UL_B 2*(x2 - m), 2*h +top
762 #define DELTA_UL_E 90*16, 90*16 +top // ,-
764 #define DELTA_DL_B 2*(x2 - m),2*-h +top
765 #define DELTA_DL_E 180*16, 90*16 // '-
767 #define CENTER_UR x1, 2*h, 225
768 #define CENTER_DR x1, 0 , 135
769 #define CENTER_UL x2, 2*h, 315
770 #define CENTER_DL x2, 0 , 45
773 Gdiplus::Graphics
graphics( hdc
);
775 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
784 Gdiplus::LinearGradientBrush
gradient(
785 Gdiplus::Point(x1
-2, h
+top
-2),
786 Gdiplus::Point(P_270
),
787 GetGdiColor(activeColor
),GetGdiColor(col
));
790 Gdiplus::Pen
mypen(&gradient
, static_cast<Gdiplus::REAL
>(m_LineWidth
));
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-1,top
+h
-1, x2
-x1
,laneHeight
,270,90);
795 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
801 Gdiplus::LinearGradientBrush
gradient(
802 Gdiplus::Point(P_270
),
803 Gdiplus::Point(x2
+1, h
+top
-1),
804 GetGdiColor(col
),GetGdiColor(activeColor
));
807 Gdiplus::Pen
mypen(&gradient
, static_cast<Gdiplus::REAL
>(m_LineWidth
));
808 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
810 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
811 graphics
.DrawArc(&mypen
,x1
+(x2
-x1
)/2,top
+h
-1, x2
-x1
,laneHeight
,180,90);
812 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
820 Gdiplus::LinearGradientBrush
gradient(
821 Gdiplus::Point(x1
-2, h
+top
-2),
822 Gdiplus::Point(P_90
),
823 GetGdiColor(activeColor
),GetGdiColor(col
));
825 Gdiplus::Pen
mypen(&gradient
, static_cast<Gdiplus::REAL
>(m_LineWidth
));
827 graphics
.DrawArc(&mypen
,x1
-(x2
-x1
)/2-1,top
-h
-1, x2
-x1
,laneHeight
,0,90);
830 QConicalGradient
gradient(CENTER_DR
);
831 gradient
.setColorAt(0.375, activeCol
);
832 gradient
.setColorAt(0.625, col
);
833 myPen
.setBrush(gradient
);
835 p
->drawArc(P_CENTER
, DELTA_DR
);
844 //static QPen myPen(Qt::black, 2); // fast path here
846 pen
.CreatePen(PS_SOLID
,2,col
);
847 //myPen.setColor(col);
848 HPEN oldpen
= static_cast<HPEN
>(::SelectObject(hdc
, pen
));
850 Gdiplus::Pen
myPen(GetGdiColor(col
), static_cast<Gdiplus::REAL
>(m_LineWidth
));
852 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
859 case Lanes::NOT_ACTIVE
:
860 case Lanes::MERGE_FORK
:
861 case Lanes::MERGE_FORK_R
:
862 case Lanes::MERGE_FORK_L
:
867 //DrawLine(hdc,P_90,P_270);
868 graphics
.DrawLine(&myPen
,P_90
,P_270
);
869 //p->drawLine(P_90, P_270);
873 //DrawLine(hdc,P_CENTER,P_270);
874 graphics
.DrawLine(&myPen
,P_CENTER
,P_270
);
875 //p->drawLine(P_CENTER, P_270);
879 case Lanes::MERGE_FORK_L_INITIAL
:
880 case Lanes::BOUNDARY
:
881 case Lanes::BOUNDARY_C
:
882 case Lanes::BOUNDARY_R
:
883 case Lanes::BOUNDARY_L
:
884 //DrawLine(hdc,P_90, P_CENTER);
885 graphics
.DrawLine(&myPen
,P_90
,P_CENTER
);
886 //p->drawLine(P_90, P_CENTER);
892 myPen
.SetColor(GetGdiColor(activeColor
));
896 case Lanes::MERGE_FORK
:
901 case Lanes::CROSS_EMPTY
:
902 case Lanes::BOUNDARY_C
:
903 //DrawLine(hdc,P_180,P_0);
904 graphics
.DrawLine(&myPen
,P_180
,P_0
);
905 //p->drawLine(P_180, P_0);
907 case Lanes::MERGE_FORK_R
:
908 case Lanes::BOUNDARY_R
:
909 //DrawLine(hdc,P_180,P_CENTER);
910 graphics
.DrawLine(&myPen
,P_180
,P_CENTER
);
911 //p->drawLine(P_180, P_CENTER);
913 case Lanes::MERGE_FORK_L
:
914 case Lanes::MERGE_FORK_L_INITIAL
:
917 case Lanes::BOUNDARY_L
:
918 //DrawLine(hdc,P_CENTER,P_0);
919 graphics
.DrawLine(&myPen
,P_CENTER
,P_0
);
920 //p->drawLine(P_CENTER, P_0);
926 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
929 brush
.CreateSolidBrush(col
);
930 HBRUSH oldbrush
= static_cast<HBRUSH
>(::SelectObject(hdc
, brush
));
932 Gdiplus::SolidBrush
myBrush(GetGdiColor(col
));
933 // center symbol, e.g. rect or ellipse
939 //p->setPen(Qt::NoPen);
941 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
942 graphics
.FillEllipse(&myBrush
, R_CENTER
);
943 //p->drawEllipse(R_CENTER);
945 case Lanes::MERGE_FORK
:
946 case Lanes::MERGE_FORK_R
:
947 case Lanes::MERGE_FORK_L
:
948 case Lanes::MERGE_FORK_L_INITIAL
:
949 //p->setPen(Qt::NoPen);
951 //p->drawRect(R_CENTER);
952 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
953 graphics
.FillRectangle(&myBrush
, R_CENTER
);
955 case Lanes::UNAPPLIED
:
957 //p->setPen(Qt::NoPen);
958 //p->setBrush(Qt::red);
959 //p->drawRect(m - r, h - 1, d, 2);
960 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
961 graphics
.FillRectangle(&myBrush
,m
-r
,h
-1,d
,2);
965 //p->setPen(Qt::NoPen);
966 //p->setBrush(DARK_GREEN);
967 //p->drawRect(m - r, h - 1, d, 2);
968 //p->drawRect(m - 1, h - r, 2, d);
969 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
970 graphics
.FillRectangle(&myBrush
,m
-r
,h
-1,d
,2);
971 graphics
.FillRectangle(&myBrush
,m
-1,h
-r
,2,d
);
973 case Lanes::BOUNDARY
:
975 //p->drawEllipse(R_CENTER);
976 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
977 graphics
.DrawEllipse(&myPen
, R_CENTER
);
979 case Lanes::BOUNDARY_C
:
980 case Lanes::BOUNDARY_R
:
981 case Lanes::BOUNDARY_L
:
983 //p->drawRect(R_CENTER);
984 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
985 graphics
.FillRectangle(&myBrush
,R_CENTER
);
991 ::SelectObject(hdc
,oldpen
);
992 ::SelectObject(hdc
,oldbrush
);
1001 void CGitLogListBase::DrawGraph(HDC hdc
,CRect
&rect
,INT_PTR index
)
1005 GitRevLoglist
* data
= m_arShownList
.SafeGetAt(index
);
1006 if(data
->m_CommitHash
.IsEmpty())
1010 LVITEM rItem
= { 0 };
1011 rItem
.mask
= LVIF_STATE
;
1012 rItem
.iItem
= static_cast<int>(index
);
1013 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
1016 // p->translate(QPoint(opt.rect.left(), opt.rect.top()));
1018 if (data
->m_Lanes
.empty())
1019 m_logEntries
.setLane(data
->m_CommitHash
);
1021 std::vector
<int>& lanes
=data
->m_Lanes
;
1022 size_t laneNum
= lanes
.size();
1023 UINT activeLane
= 0;
1024 for (UINT i
= 0; i
< laneNum
; ++i
)
1025 if (Lanes::isMerge(lanes
[i
])) {
1031 int maxWidth
= rect
.Width();
1032 int lw
= 3 * rect
.Height() / 4; //laneWidth()
1034 COLORREF activeColor
= CTheme::Instance().GetThemeColor(m_Colors
.GetColor((CColors::Colors
)(CColors::BranchLine1
+ (activeLane
% Lanes::COLORS_NUM
))), true);
1036 for (unsigned int i
= 0; i
< laneNum
&& x2
< maxWidth
; ++i
)
1042 if (ln
== Lanes::EMPTY
)
1045 COLORREF color
= i
== activeLane
? activeColor
: CTheme::Instance().GetThemeColor(m_Colors
.GetColor((CColors::Colors
)(CColors::BranchLine1
+ (i
% Lanes::COLORS_NUM
))), true);
1046 paintGraphLane(hdc
, rect
.Height(),ln
, x1
+rect
.left
, x2
+rect
.left
, color
,activeColor
, rect
.top
);
1050 for (UINT i
= 0; i
< laneNum
&& x2
< maxWidth
; ++i
) {
1055 if (ln
== Lanes::EMPTY
)
1058 UINT col
= ( Lanes:: isHead(ln
) ||Lanes:: isTail(ln
) || Lanes::isJoin(ln
)
1059 || ln
==Lanes:: CROSS_EMPTY
) ? activeLane
: i
;
1061 if (ln
== Lanes::CROSS
)
1063 paintGraphLane(hdc
, rect
.Height(),Lanes::NOT_ACTIVE
, x1
, x2
, m_LineColors
[col
% Lanes::COLORS_NUM
],rect
.top
);
1064 paintGraphLane(hdc
, rect
.Height(),Lanes::CROSS
, x1
, x2
, m_LineColors
[activeLane
% Lanes::COLORS_NUM
],rect
.top
);
1067 paintGraphLane(hdc
, rect
.Height(),ln
, x1
, x2
, m_LineColors
[col
% Lanes::COLORS_NUM
],rect
.top
);
1072 void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1074 NMLVCUSTOMDRAW
* pLVCD
= reinterpret_cast<NMLVCUSTOMDRAW
*>( pNMHDR
);
1075 // Take the default processing unless we set this to something else below.
1076 *pResult
= CDRF_DODEFAULT
;
1078 if (m_bNoDispUpdates
)
1081 switch (pLVCD
->nmcd
.dwDrawStage
)
1085 *pResult
= CDRF_NOTIFYITEMDRAW
;
1089 case CDDS_ITEMPREPAINT
:
1091 // This is the prepaint stage for an item. Here's where we set the
1092 // item's text color.
1094 // Tell Windows to send draw notifications for each subitem.
1095 *pResult
= CDRF_NOTIFYSUBITEMDRAW
;
1097 COLORREF crText
= CTheme::Instance().IsDarkTheme() ? CTheme::darkTextColor
: GetSysColor(COLOR_WINDOWTEXT
);
1099 if (m_arShownList
.size() > pLVCD
->nmcd
.dwItemSpec
)
1101 GitRevLoglist
* data
= m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1104 HGDIOBJ hGdiObj
= nullptr;
1105 int action
= data
->GetRebaseAction();
1106 if (action
& (LOGACTIONS_REBASE_DONE
| LOGACTIONS_REBASE_SKIP
))
1107 crText
= RGB(128, 128, 128);
1109 if (action
& LOGACTIONS_REBASE_SQUASH
)
1110 pLVCD
->clrTextBk
= RGB(156, 156, 156);
1111 else if (action
& LOGACTIONS_REBASE_EDIT
)
1112 pLVCD
->clrTextBk
= CTheme::Instance().GetThemeColor(RGB(200, 200, 128));
1114 pLVCD
->clrTextBk
= CTheme::Instance().IsDarkTheme() ? CTheme::darkBkColor
: GetSysColor(COLOR_WINDOW
);
1116 if (action
& LOGACTIONS_REBASE_CURRENT
)
1117 hGdiObj
= m_boldFont
.GetSafeHandle();
1119 BOOL isHeadHash
= data
->m_CommitHash
== m_HeadHash
&& m_bNoHightlightHead
== FALSE
;
1120 BOOL isHighlight
= data
->m_CommitHash
== m_highlight
&& !m_highlight
.IsEmpty();
1121 if (isHeadHash
&& isHighlight
)
1122 hGdiObj
= m_boldItalicsFont
.GetSafeHandle();
1123 else if (isHeadHash
)
1124 hGdiObj
= m_boldFont
.GetSafeHandle();
1125 else if (isHighlight
)
1126 hGdiObj
= m_FontItalics
.GetSafeHandle();
1130 SelectObject(pLVCD
->nmcd
.hdc
, hGdiObj
);
1131 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
1134 // if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))
1135 // crText = GetSysColor(COLOR_GRAYTEXT);
1137 if (data
->m_CommitHash
.IsEmpty())
1139 //crText = GetSysColor(RGB(200,200,0));
1140 //SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1141 // We changed the font, so we're returning CDRF_NEWFONT. This
1142 // tells the control to recalculate the extent of the text.
1143 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
1147 // Store the color back in the NMLVCUSTOMDRAW struct.
1148 pLVCD
->clrText
= crText
;
1153 case CDDS_ITEMPREPAINT
| CDDS_ITEM
| CDDS_SUBITEM
:
1155 switch (pLVCD
->iSubItem
)
1158 if ((m_ShowFilter
& FILTERSHOW_MERGEPOINTS
) && !m_LogFilter
->IsFilterActive())
1160 if (m_arShownList
.size() > pLVCD
->nmcd
.dwItemSpec
&& !this->m_IsRebaseReplaceGraph
)
1163 GetSubItemRect(static_cast<int>(pLVCD
->nmcd
.dwItemSpec
), pLVCD
->iSubItem
, LVIR_LABEL
, rect
);
1165 //TRACE(L"A Graphic left %d right %d\r\n", rect.left, rect.right);
1166 FillBackGround(pLVCD
->nmcd
.hdc
, pLVCD
->nmcd
.dwItemSpec
,rect
);
1168 GitRevLoglist
* data
= m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1169 if( !data
->m_CommitHash
.IsEmpty())
1170 DrawGraph(pLVCD
->nmcd
.hdc
,rect
,pLVCD
->nmcd
.dwItemSpec
);
1172 *pResult
= CDRF_SKIPDEFAULT
;
1178 case LOGLIST_MESSAGE
:
1179 // If the top index of list is changed, the position map of reference label is outdated.
1180 if (m_OldTopIndex
!= GetTopIndex())
1182 m_OldTopIndex
= GetTopIndex();
1183 m_RefLabelPosMap
.clear();
1186 if (m_arShownList
.size() > pLVCD
->nmcd
.dwItemSpec
)
1188 GitRevLoglist
* data
= m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1190 auto hashMapSharedPtr
= m_HashMap
;
1191 const auto& hashMap
= *hashMapSharedPtr
;
1192 if ((hashMap
.find(data
->m_CommitHash
) != hashMap
.cend() || (!m_superProjectHash
.IsEmpty() && data
->m_CommitHash
== m_superProjectHash
)) && !(data
->GetRebaseAction() & LOGACTIONS_REBASE_DONE
))
1195 GetSubItemRect(static_cast<int>(pLVCD
->nmcd
.dwItemSpec
), pLVCD
->iSubItem
, LVIR_BOUNDS
, rect
);
1197 // BEGIN: extended redraw, HACK for issue #1618 and #2014
1198 // not in FillBackGround method, because this only affected the message subitem
1199 if (0 != pLVCD
->iStateId
) // don't know why, but this helps against loosing the focus rect
1202 int index
= static_cast<int>(pLVCD
->nmcd
.dwItemSpec
);
1203 int state
= GetItemState(index
, LVIS_SELECTED
);
1204 int txtState
= LISS_NORMAL
;
1205 if (IsAppThemed() && GetHotItem() == static_cast<int>(index
))
1207 if (state
& LVIS_SELECTED
)
1208 txtState
= LISS_HOTSELECTED
;
1210 txtState
= LISS_HOT
;
1212 else if (state
& LVIS_SELECTED
)
1214 if (::GetFocus() == m_hWnd
)
1215 txtState
= LISS_SELECTED
;
1217 txtState
= LISS_SELECTEDNOTFOCUS
;
1220 CAutoThemeData hTheme
;
1223 hTheme
= OpenThemeData(m_hWnd
, L
"Explorer::ListView;ListView");
1225 // make sure the column separator/border is not overpainted
1226 int borderWidth
= 0;
1227 GetThemeMetric(hTheme
, pLVCD
->nmcd
.hdc
, LVP_LISTITEM
, LISS_NORMAL
, TMT_BORDERSIZE
, &borderWidth
);
1228 InflateRect(&rect
, -(2 * borderWidth
), 0);
1231 if (hTheme
&& IsThemeBackgroundPartiallyTransparent(hTheme
, LVP_LISTDETAIL
, txtState
))
1232 DrawThemeParentBackground(m_hWnd
, pLVCD
->nmcd
.hdc
, &rect
);
1235 HBRUSH brush
= ::CreateSolidBrush(pLVCD
->clrTextBk
);
1236 ::FillRect(pLVCD
->nmcd
.hdc
, rect
, brush
);
1237 ::DeleteObject(brush
);
1239 if (hTheme
&& txtState
!= LISS_NORMAL
)
1242 // get rect of whole line
1243 GetItemRect(index
, rt
, LVIR_BOUNDS
);
1246 // calculate background for rect of whole line, but limit redrawing to SubItem rect
1247 DrawThemeBackground(hTheme
, pLVCD
->nmcd
.hdc
, LVP_LISTITEM
, txtState
, rt
, rect2
);
1249 hTheme
.CloseHandle();
1250 // END: extended redraw
1252 FillBackGround(pLVCD
->nmcd
.hdc
, pLVCD
->nmcd
.dwItemSpec
, rect
);
1254 std::vector
<REFLABEL
> refsToShow
;
1255 STRING_VECTOR remoteTrackingList
;
1256 std::vector
<CString
>::const_iterator refListIt
;
1257 std::vector
<CString
>::const_iterator refListItEnd
;
1258 auto commitRefsIt
= hashMap
.find(data
->m_CommitHash
);
1259 if (commitRefsIt
!= hashMap
.cend())
1261 refListIt
= (*commitRefsIt
).second
.cbegin();
1262 refListItEnd
= (*commitRefsIt
).second
.cend();
1264 for (; refListIt
!= refListItEnd
; ++refListIt
)
1267 refLabel
.color
= RGB(255, 255, 255);
1268 refLabel
.singleRemote
= false;
1269 refLabel
.hasTracking
= false;
1270 refLabel
.sameName
= false;
1271 refLabel
.name
= CGit::GetShortName(*refListIt
, &refLabel
.refType
);
1272 refLabel
.fullName
= *refListIt
;
1274 switch (refLabel
.refType
)
1276 case CGit::REF_TYPE::LOCAL_BRANCH
:
1278 if (!(m_ShowRefMask
& LOGLIST_SHOWLOCALBRANCHES
))
1280 if (refLabel
.name
== m_CurrentBranch
)
1281 refLabel
.color
= CTheme::Instance().GetThemeColor(m_Colors
.GetColor(CColors::CurrentBranch
), true);
1283 refLabel
.color
= CTheme::Instance().GetThemeColor(m_Colors
.GetColor(CColors::LocalBranch
), true);
1285 std::pair
<CString
, CString
> trackingEntry
= m_TrackingMap
[refLabel
.name
];
1286 CString pullRemote
= trackingEntry
.first
;
1287 CString pullBranch
= trackingEntry
.second
;
1288 if (!pullRemote
.IsEmpty() && !pullBranch
.IsEmpty())
1290 CString defaultUpstream
;
1291 defaultUpstream
.Format(L
"refs/remotes/%s/%s", static_cast<LPCWSTR
>(pullRemote
), static_cast<LPCWSTR
>(pullBranch
));
1292 refLabel
.hasTracking
= true;
1293 if (m_ShowRefMask
& LOGLIST_SHOWREMOTEBRANCHES
)
1296 for (auto it2
= refListIt
+ 1; it2
!= refListItEnd
; ++it2
)
1298 if (*it2
== defaultUpstream
)
1307 bool sameName
= pullBranch
== refLabel
.name
;
1308 refsToShow
.push_back(refLabel
);
1309 CGit::GetShortName(defaultUpstream
, refLabel
.name
, L
"refs/remotes/");
1310 refLabel
.color
= CTheme::Instance().GetThemeColor(m_Colors
.GetColor(CColors::RemoteBranch
), true);
1311 if (m_bSymbolizeRefNames
)
1313 if (!m_SingleRemote
.IsEmpty() && m_SingleRemote
== pullRemote
)
1315 refLabel
.simplifiedName
= L
'/';
1317 refLabel
.simplifiedName
+= L
'≡';
1319 refLabel
.simplifiedName
+= pullBranch
;
1320 refLabel
.singleRemote
= true;
1323 refLabel
.simplifiedName
= pullRemote
+ L
"/≡";
1324 refLabel
.sameName
= sameName
;
1326 refLabel
.fullName
= defaultUpstream
;
1327 refsToShow
.push_back(refLabel
);
1328 remoteTrackingList
.push_back(defaultUpstream
);
1335 case CGit::REF_TYPE::REMOTE_BRANCH
:
1337 if (!(m_ShowRefMask
& LOGLIST_SHOWREMOTEBRANCHES
))
1340 for (size_t j
= 0; j
< remoteTrackingList
.size(); ++j
)
1342 if (remoteTrackingList
[j
] == *refListIt
)
1351 refLabel
.color
= CTheme::Instance().GetThemeColor(m_Colors
.GetColor(CColors::RemoteBranch
), true);
1352 if (m_bSymbolizeRefNames
)
1354 if (!m_SingleRemote
.IsEmpty() && CStringUtils::StartsWith(refLabel
.name
, m_SingleRemote
+ L
"/"))
1356 refLabel
.simplifiedName
= L
'/' + refLabel
.name
.Mid(m_SingleRemote
.GetLength() + 1);
1357 refLabel
.singleRemote
= true;
1362 case CGit::REF_TYPE::ANNOTATED_TAG
:
1364 case CGit::REF_TYPE::TAG
:
1365 if (!(m_ShowRefMask
& LOGLIST_SHOWTAGS
))
1367 refLabel
.color
= CTheme::Instance().GetThemeColor(m_Colors
.GetColor(CColors::Tag
), true);
1370 case CGit::REF_TYPE::STASH
:
1371 if (!(m_ShowRefMask
& LOGLIST_SHOWSTASH
))
1373 refLabel
.color
= CTheme::Instance().GetThemeColor(m_Colors
.GetColor(CColors::Stash
), true);
1376 case CGit::REF_TYPE::BISECT_GOOD
:
1378 case CGit::REF_TYPE::BISECT_BAD
:
1380 case CGit::REF_TYPE::BISECT_SKIP
:
1381 if (!(m_ShowRefMask
& LOGLIST_SHOWBISECT
))
1383 refLabel
.color
= CTheme::Instance().GetThemeColor((refLabel
.refType
== CGit::REF_TYPE::BISECT_GOOD
) ? m_Colors
.GetColor(CColors::BisectGood
) : ((refLabel
.refType
== CGit::REF_TYPE::BISECT_SKIP
) ? m_Colors
.GetColor(CColors::BisectSkip
) : m_Colors
.GetColor(CColors::BisectBad
)), true);
1386 case CGit::REF_TYPE::NOTES
:
1387 if (!(m_ShowRefMask
& LOGLIST_SHOWOTHERREFS
))
1389 refLabel
.color
= CTheme::Instance().GetThemeColor(m_Colors
.GetColor(CColors::NoteNode
), true);
1393 if (!(m_ShowRefMask
& LOGLIST_SHOWOTHERREFS
))
1395 refLabel
.color
= CTheme::Instance().GetThemeColor(m_Colors
.GetColor(CColors::OtherRef
), true);
1398 refsToShow
.push_back(refLabel
);
1400 if (!m_superProjectHash
.IsEmpty() && data
->m_CommitHash
== m_superProjectHash
)
1403 refLabel
.color
= CTheme::Instance().GetThemeColor(RGB(246, 153, 253), true);
1404 refLabel
.singleRemote
= false;
1405 refLabel
.hasTracking
= false;
1406 refLabel
.sameName
= false;
1407 refLabel
.name
= L
"super-project-pointer";
1408 refLabel
.fullName
= "";
1409 refsToShow
.push_back(refLabel
);
1412 if (refsToShow
.empty())
1414 *pResult
= CDRF_DODEFAULT
;
1418 DrawTagBranchMessage(pLVCD
, rect
, pLVCD
->nmcd
.dwItemSpec
, refsToShow
);
1420 *pResult
= CDRF_SKIPDEFAULT
;
1423 else if (DrawListItemWithMatchesIfEnabled(m_LogFilter
, LOGFILTER_SUBJECT
| LOGFILTER_MESSAGES
, pLVCD
, pResult
))//from here
1428 case LOGLIST_ACTION
:
1430 if (m_IsIDReplaceAction
|| !m_ColumnManager
.IsVisible(LOGLIST_ACTION
))
1432 *pResult
= CDRF_DODEFAULT
;
1435 *pResult
= CDRF_DODEFAULT
;
1437 if (m_arShownList
.size() <= pLVCD
->nmcd
.dwItemSpec
)
1441 int iconwidth
= ::GetSystemMetrics(SM_CXSMICON
);
1442 int iconheight
= ::GetSystemMetrics(SM_CYSMICON
);
1444 GitRevLoglist
* pLogEntry
= m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1446 GetSubItemRect(static_cast<int>(pLVCD
->nmcd
.dwItemSpec
), pLVCD
->iSubItem
, LVIR_BOUNDS
, rect
);
1447 //TRACE(L"Action left %d right %d\r\n", rect.left, rect.right);
1448 // Get the selected state of the
1449 // item being drawn.
1451 CMemDC
myDC(*CDC::FromHandle(pLVCD
->nmcd
.hdc
), rect
);
1452 BitBlt(myDC
.GetDC(), rect
.left
, rect
.top
, rect
.Width(), rect
.Height(), pLVCD
->nmcd
.hdc
, rect
.left
, rect
.top
, SRCCOPY
);
1454 // Fill the background if necessary
1455 FillBackGround(myDC
.GetDC(), pLVCD
->nmcd
.dwItemSpec
, rect
);
1457 // Draw the icon(s) into the compatible DC
1458 int action
= pLogEntry
->GetAction(this);
1459 auto iconItemBorder
= CDPIAware::Instance().ScaleX(ICONITEMBORDER
);
1460 if (!pLogEntry
->m_IsDiffFiles
)
1462 ::DrawIconEx(myDC
.GetDC(), rect
.left
+ iconItemBorder
, rect
.top
, m_hFetchIcon
, iconwidth
, iconheight
, 0, nullptr, DI_NORMAL
);
1463 *pResult
= CDRF_SKIPDEFAULT
;
1467 if (action
& CTGitPath::LOGACTIONS_MODIFIED
)
1468 ::DrawIconEx(myDC
.GetDC(), rect
.left
+ iconItemBorder
, rect
.top
, m_hModifiedIcon
, iconwidth
, iconheight
, 0, nullptr, DI_NORMAL
);
1471 if (action
& (CTGitPath::LOGACTIONS_ADDED
| CTGitPath::LOGACTIONS_COPY
))
1472 ::DrawIconEx(myDC
.GetDC(), rect
.left
+ nIcons
* iconwidth
+ iconItemBorder
, rect
.top
, m_hAddedIcon
, iconwidth
, iconheight
, 0, nullptr, DI_NORMAL
);
1475 if (action
& CTGitPath::LOGACTIONS_DELETED
)
1476 ::DrawIconEx(myDC
.GetDC(), rect
.left
+ nIcons
* iconwidth
+ iconItemBorder
, rect
.top
, m_hDeletedIcon
, iconwidth
, iconheight
, 0, nullptr, DI_NORMAL
);
1479 if (action
& CTGitPath::LOGACTIONS_REPLACED
)
1480 ::DrawIconEx(myDC
.GetDC(), rect
.left
+ nIcons
* iconwidth
+ iconItemBorder
, rect
.top
, m_hReplacedIcon
, iconwidth
, iconheight
, 0, nullptr, DI_NORMAL
);
1483 if (action
& CTGitPath::LOGACTIONS_UNMERGED
)
1484 ::DrawIconEx(myDC
.GetDC(), rect
.left
+ nIcons
* iconwidth
+ iconItemBorder
, rect
.top
, m_hConflictedIcon
, iconwidth
, iconheight
, 0, nullptr, DI_NORMAL
);
1487 *pResult
= CDRF_SKIPDEFAULT
;
1492 if (DrawListItemWithMatchesIfEnabled(m_LogFilter
, LOGFILTER_REVS
, pLVCD
, pResult
))
1496 case LOGLIST_AUTHOR
:
1497 case LOGLIST_COMMIT_NAME
:
1498 if (DrawListItemWithMatchesIfEnabled(m_LogFilter
, LOGFILTER_AUTHORS
, pLVCD
, pResult
))
1503 case LOGLIST_COMMIT_EMAIL
:
1504 if (DrawListItemWithMatchesIfEnabled(m_LogFilter
, LOGFILTER_EMAILS
, pLVCD
, pResult
))
1509 if (DrawListItemWithMatchesIfEnabled(m_LogFilter
, LOGFILTER_BUGID
, pLVCD
, pResult
))
1516 *pResult
= CDRF_DODEFAULT
;
1519 CString
FindSVNRev(const CString
& msg
)
1523 const std::wsregex_iterator end
;
1524 std::wstring s
{ static_cast<LPCWSTR
>(msg
) };
1525 std::wregex
regex1(L
"^\\s*git-svn-id:\\s+(.*)\\@(\\d+)\\s([a-f\\d\\-]+)$");
1526 for (std::wsregex_iterator
it(s
.cbegin(), s
.cend(), regex1
); it
!= end
; ++it
)
1528 const std::wsmatch match
= *it
;
1529 if (match
.size() == 4)
1531 ATLTRACE(L
"matched rev: %s\n", std::wstring(match
[2]).c_str());
1532 return std::wstring(match
[2]).c_str();
1535 std::wregex
regex2(L
"^\\s*git-svn-id:\\s(\\d+)\\@([a-f\\d\\-]+)$");
1536 for (std::wsregex_iterator
it(s
.cbegin(), s
.cend(), regex2
); it
!= end
; ++it
)
1538 const std::wsmatch match
= *it
;
1539 if (match
.size() == 3)
1541 ATLTRACE(L
"matched rev: %s\n", std::wstring(match
[1]).c_str());
1542 return std::wstring(match
[1]).c_str();
1546 catch (std::exception
&) {}
1551 CString
CGitLogListBase::MessageDisplayStr(GitRev
* pLogEntry
)
1553 if (!m_bFullCommitMessageOnLogLine
|| pLogEntry
->GetBody().IsEmpty())
1554 return pLogEntry
->GetSubject();
1556 CString
txt(pLogEntry
->GetSubject());
1558 txt
+= pLogEntry
->GetBody();
1561 txt
.Replace(L
'\n', L
' ');
1562 txt
.Replace(L
'\r', L
' ');
1567 // CGitLogListBase message handlers
1569 void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1571 NMLVDISPINFO
*pDispInfo
= reinterpret_cast<NMLVDISPINFO
*>(pNMHDR
);
1573 // Create a pointer to the item
1574 LV_ITEM
* pItem
= &(pDispInfo
)->item
;
1576 // Do the list need text information?
1577 if (!(pItem
->mask
& LVIF_TEXT
))
1580 // By default, clear text buffer.
1581 lstrcpyn(pItem
->pszText
, L
"", pItem
->cchTextMax
- 1);
1583 bool bOutOfRange
= pItem
->iItem
>= static_cast<int>(m_arShownList
.size());
1586 if (m_bNoDispUpdates
|| bOutOfRange
)
1589 // Which item number?
1590 GitRevLoglist
* pLogEntry
= m_arShownList
.SafeGetAt(pItem
->iItem
);
1594 temp
.Format(L
"%d", pItem
->iItem
+ 1);
1596 temp
.Format(L
"%zu", m_arShownList
.size() - pItem
->iItem
);
1602 switch (pItem
->iSubItem
)
1604 case LOGLIST_GRAPH
: //Graphic
1606 case LOGLIST_REBASE
:
1607 if (m_IsRebaseReplaceGraph
)
1608 lstrcpyn(pItem
->pszText
, GetRebaseActionName(pLogEntry
->GetRebaseAction() & LOGACTIONS_REBASE_MODE_MASK
), pItem
->cchTextMax
- 1);
1610 case LOGLIST_ACTION
: //action -- no text in the column
1613 lstrcpyn(pItem
->pszText
, pLogEntry
->m_CommitHash
.ToString(), pItem
->cchTextMax
- 1);
1616 if (this->m_IsIDReplaceAction
)
1617 lstrcpyn(pItem
->pszText
, temp
, pItem
->cchTextMax
- 1);
1619 case LOGLIST_MESSAGE
: //Message
1620 lstrcpyn(pItem
->pszText
, static_cast<LPCWSTR
>(MessageDisplayStr(pLogEntry
)), pItem
->cchTextMax
- 1);
1622 case LOGLIST_AUTHOR
: //Author
1623 lstrcpyn(pItem
->pszText
, static_cast<LPCWSTR
>(pLogEntry
->GetAuthorName()), pItem
->cchTextMax
- 1);
1625 case LOGLIST_DATE
: //Date
1626 if (!pLogEntry
->m_CommitHash
.IsEmpty())
1627 lstrcpyn(pItem
->pszText
,
1628 CLoglistUtils::FormatDateAndTime(pLogEntry
->GetAuthorDate(), m_DateFormat
, true, m_bRelativeTimes
),
1629 pItem
->cchTextMax
- 1);
1633 lstrcpyn(pItem
->pszText
, static_cast<LPCWSTR
>(pLogEntry
->GetAuthorEmail()), pItem
->cchTextMax
- 1);
1636 case LOGLIST_COMMIT_NAME
: //Commit
1637 lstrcpyn(pItem
->pszText
, static_cast<LPCWSTR
>(pLogEntry
->GetCommitterName()), pItem
->cchTextMax
- 1);
1640 case LOGLIST_COMMIT_EMAIL
: //Commit Email
1641 lstrcpyn(pItem
->pszText
, static_cast<LPCWSTR
>(pLogEntry
->GetCommitterEmail()), pItem
->cchTextMax
- 1);
1644 case LOGLIST_COMMIT_DATE
: //Commit Date
1645 if (!pLogEntry
->m_CommitHash
.IsEmpty())
1646 lstrcpyn(pItem
->pszText
,
1647 CLoglistUtils::FormatDateAndTime(pLogEntry
->GetCommitterDate(), m_DateFormat
, true, m_bRelativeTimes
),
1648 pItem
->cchTextMax
- 1);
1650 case LOGLIST_BUG
: //Bug ID
1651 lstrcpyn(pItem
->pszText
, static_cast<LPCWSTR
>(this->m_ProjectProperties
.FindBugID(pLogEntry
->GetSubjectBody())), pItem
->cchTextMax
- 1);
1653 case LOGLIST_SVNREV
: //SVN revision
1654 lstrcpyn(pItem
->pszText
, static_cast<LPCWSTR
>(FindSVNRev(pLogEntry
->GetSubjectBody())), pItem
->cchTextMax
- 1);
1662 bool CGitLogListBase::IsOnStash(int index
)
1664 GitRevLoglist
* rev
= m_arShownList
.SafeGetAt(index
);
1669 GitRevLoglist
* preRev
= m_arShownList
.SafeGetAt(index
- 1);
1670 if (IsStash(preRev
))
1671 return preRev
->m_ParentHash
.size() == 2 && preRev
->m_ParentHash
[1] == rev
->m_CommitHash
;
1676 bool CGitLogListBase::IsStash(const GitRev
* pSelLogEntry
)
1678 auto hashMap
= m_HashMap
;
1679 const auto refList
= hashMap
.get()->find(pSelLogEntry
->m_CommitHash
);
1680 if (refList
== hashMap
.get()->cend())
1682 return any_of((*refList
).second
, [](const auto& ref
) { return ref
== L
"refs/stash"; });
1685 bool CGitLogListBase::IsBisect(const GitRev
* pSelLogEntry
)
1687 auto hashMap
= m_HashMap
;
1688 const auto refList
= hashMap
->find(pSelLogEntry
->m_CommitHash
);
1689 if (refList
== hashMap
->cend())
1691 return any_of((*refList
).second
, [](const auto& ref
) { return CStringUtils::StartsWith(ref
, L
"refs/bisect/"); });
1694 void CGitLogListBase::GetParentHashes(GitRev
*pRev
, GIT_REV_LIST
&parentHash
)
1696 if (pRev
->m_ParentHash
.empty() && !pRev
->m_CommitHash
.IsEmpty())
1698 if (pRev
->GetParentFromHash(pRev
->m_CommitHash
))
1699 MessageBox(pRev
->GetLastErr(), L
"TortoiseGit", MB_ICONERROR
);
1701 parentHash
= pRev
->m_ParentHash
;
1704 void CGitLogListBase::OnContextMenu(CWnd
* pWnd
, CPoint point
)
1706 __super::OnContextMenu(pWnd
, point
);
1711 int selIndex
= GetSelectionMark();
1713 return; // nothing selected, nothing to do with a context menu
1715 // if the context menu is invoked through the keyboard, we have to use
1716 // a calculated position on where to anchor the menu on
1717 if ((point
.x
== -1) && (point
.y
== -1))
1720 GetItemRect(selIndex
, &rect
, LVIR_LABEL
);
1721 ClientToScreen(&rect
);
1722 point
= rect
.CenterPoint();
1724 m_nSearchIndex
= selIndex
;
1726 bool showExtendedMenu
= (GetAsyncKeyState(VK_SHIFT
) & 0x8000) != 0;
1728 POSITION pos
= GetFirstSelectedItemPosition();
1729 int FirstSelect
= GetNextSelectedItem(pos
);
1730 if (FirstSelect
< 0)
1733 GitRevLoglist
* pSelLogEntry
= m_arShownList
.SafeGetAt(FirstSelect
);
1734 if (pSelLogEntry
== nullptr)
1737 int LastSelect
= -1;
1738 UINT selectedCount
= 1;
1741 LastSelect
= GetNextSelectedItem(pos
);
1745 ASSERT(GetSelectedCount() == selectedCount
);
1747 //entry is selected, now show the popup menu
1749 CIconMenu subbranchmenu
, submenu
, gnudiffmenu
, diffmenu
, blamemenu
, revertmenu
;
1751 if (popup
.CreatePopupMenu())
1754 if (g_Git
.GetHash(headHash
, L
"HEAD"))
1756 MessageBox(g_Git
.GetGitLastErr(L
"Could not get HEAD hash."), L
"TortoiseGit", MB_ICONERROR
);
1759 auto hashMapSharedPtr
= m_HashMap
;
1760 const auto& hashMap
= *hashMapSharedPtr
;
1761 bool isHeadCommit
= (pSelLogEntry
->m_CommitHash
== headHash
);
1762 CString currentBranch
= L
"refs/heads/" + g_Git
.GetCurrentBranch();
1763 CTGitPath
workingTree(g_Git
.m_CurrentDir
);
1764 bool isMergeActive
= workingTree
.IsMergeActive();
1765 bool isBisectActive
= workingTree
.IsBisectActive();
1766 bool isStash
= IsOnStash(FirstSelect
);
1767 GIT_REV_LIST parentHash
;
1768 GetParentHashes(pSelLogEntry
, parentHash
);
1769 STRING_VECTOR parentInfo
;
1770 for (size_t i
= 0; i
< parentHash
.size(); ++i
)
1773 str
.Format(IDS_PARENT
, i
+ 1);
1775 if (rev
.GetCommit(parentHash
[i
].ToString()) == 0)
1777 CString commitTitle
= rev
.GetSubject();
1778 if (commitTitle
.GetLength() > 20)
1780 commitTitle
.Truncate(20);
1781 commitTitle
+= L
"...";
1783 commitTitle
.Replace(L
"&", L
"&&");
1784 str
.AppendFormat(L
": \"%s\" (%s)", static_cast<LPCWSTR
>(commitTitle
), static_cast<LPCWSTR
>(parentHash
[i
].ToString(g_Git
.GetShortHASHLength())));
1787 str
.AppendFormat(L
" (%s)", static_cast<LPCWSTR
>(parentHash
[i
].ToString(g_Git
.GetShortHASHLength())));
1788 parentInfo
.push_back(str
);
1791 if (m_ContextMenuMask
& GetContextMenuBit(ID_REBASE_PICK
) && !(pSelLogEntry
->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT
| LOGACTIONS_REBASE_DONE
)))
1792 popup
.AppendMenuIcon(ID_REBASE_PICK
, IDS_REBASE_PICK
, IDI_PICK
);
1794 if (m_ContextMenuMask
& GetContextMenuBit(ID_REBASE_SQUASH
) && !(pSelLogEntry
->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT
| LOGACTIONS_REBASE_DONE
)) && FirstSelect
!= GetItemCount() - 1 && LastSelect
!= GetItemCount() - 1 && (m_bIsCherryPick
|| pSelLogEntry
->ParentsCount() == 1))
1795 popup
.AppendMenuIcon(ID_REBASE_SQUASH
, IDS_REBASE_SQUASH
, IDI_SQUASH
);
1797 if (m_ContextMenuMask
& GetContextMenuBit(ID_REBASE_EDIT
) && !(pSelLogEntry
->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT
| LOGACTIONS_REBASE_DONE
)))
1798 popup
.AppendMenuIcon(ID_REBASE_EDIT
, IDS_REBASE_EDIT
, IDI_EDIT
);
1800 if (m_ContextMenuMask
& GetContextMenuBit(ID_REBASE_SKIP
) && !(pSelLogEntry
->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT
| LOGACTIONS_REBASE_DONE
)))
1801 popup
.AppendMenuIcon(ID_REBASE_SKIP
, IDS_REBASE_SKIP
, IDI_SKIP
);
1803 if (m_ContextMenuMask
& (GetContextMenuBit(ID_REBASE_SKIP
) | GetContextMenuBit(ID_REBASE_EDIT
) | GetContextMenuBit(ID_REBASE_SQUASH
) | GetContextMenuBit(ID_REBASE_PICK
)) && !(pSelLogEntry
->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT
| LOGACTIONS_REBASE_DONE
)))
1804 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1806 if (selectedCount
== 1)
1809 bool requiresSeparator
= false;
1810 if( !pSelLogEntry
->m_CommitHash
.IsEmpty())
1812 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPARE
) && m_hasWC
) // compare revision with WC
1814 popup
.AppendMenuIcon(ID_COMPARE
, IDS_LOG_POPUP_COMPARE
, IDI_DIFF
);
1815 requiresSeparator
= true;
1820 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMMIT
))
1822 popup
.AppendMenuIcon(ID_COMMIT
, IDS_LOG_POPUP_COMMIT
, IDI_COMMIT
);
1823 requiresSeparator
= true;
1825 if (isMergeActive
&& (m_ContextMenuMask
& GetContextMenuBit(ID_MERGE_ABORT
)))
1827 popup
.AppendMenuIcon(ID_MERGE_ABORT
, IDS_MENUMERGEABORT
, IDI_MERGEABORT
);
1828 requiresSeparator
= true;
1832 if (m_ContextMenuMask
& GetContextMenuBit(ID_BLAMEPREVIOUS
))
1834 if (parentHash
.size() == 1)
1836 popup
.AppendMenuIcon(ID_BLAMEPREVIOUS
, IDS_LOG_POPUP_BLAMEPREVIOUS
, IDI_BLAME
);
1837 requiresSeparator
= true;
1839 else if (parentHash
.size() > 1)
1841 blamemenu
.CreatePopupMenu();
1842 popup
.AppendMenuIcon(ID_BLAMEPREVIOUS
, IDS_LOG_POPUP_BLAMEPREVIOUS
, IDI_BLAME
, blamemenu
.m_hMenu
);
1843 for (size_t i
= 0; i
< parentInfo
.size(); ++i
)
1845 blamemenu
.AppendMenuIcon(ID_BLAMEPREVIOUS
+ ((i
+ 1) << 16), parentInfo
[i
]);
1847 requiresSeparator
= true;
1851 if(m_ContextMenuMask
&GetContextMenuBit(ID_GNUDIFF1
) && m_hasWC
) // compare with WC, unified
1853 if (parentHash
.size() == 1)
1855 popup
.AppendMenuIcon(ID_GNUDIFF1
, IDS_LOG_POPUP_GNUDIFF
, IDI_DIFF
);
1856 requiresSeparator
= true;
1858 else if (parentHash
.size() > 1)
1860 gnudiffmenu
.CreatePopupMenu();
1861 popup
.AppendMenuIcon(ID_GNUDIFF1
,IDS_LOG_POPUP_GNUDIFF_PARENT
, IDI_DIFF
, gnudiffmenu
.m_hMenu
);
1863 gnudiffmenu
.AppendMenuIcon(static_cast<UINT_PTR
>(ID_GNUDIFF1
+ (0xFFFF << 16)), CString(MAKEINTRESOURCE(IDS_ALLPARENTS
)));
1864 gnudiffmenu
.AppendMenuIcon(static_cast<UINT_PTR
>(ID_GNUDIFF1
+ (0xFFFE << 16)), CString(MAKEINTRESOURCE(IDS_ONLYMERGEDFILES
)));
1865 gnudiffmenu
.AppendMenuIcon(static_cast<UINT_PTR
>(ID_GNUDIFF1
+ (0xFFFD << 16)), CString(MAKEINTRESOURCE(IDS_DIFFWITHMERGE
)));
1867 for (size_t i
= 0; i
< parentInfo
.size(); ++i
)
1869 gnudiffmenu
.AppendMenuIcon(ID_GNUDIFF1
+ ((i
+ 1) << 16), parentInfo
[i
]);
1871 requiresSeparator
= true;
1875 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPAREWITHPREVIOUS
))
1877 if (parentHash
.size() == 1)
1879 popup
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
, IDS_LOG_POPUP_COMPAREWITHPREVIOUS
, IDI_DIFF
);
1880 if (CRegDWORD(L
"Software\\TortoiseGit\\DiffByDoubleClickInLog", FALSE
) && m_ColumnRegKey
!= L
"reflog")
1881 popup
.SetDefaultItem(ID_COMPAREWITHPREVIOUS
, FALSE
);
1882 requiresSeparator
= true;
1884 else if (parentHash
.size() > 1)
1886 diffmenu
.CreatePopupMenu();
1887 popup
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
, IDS_LOG_POPUP_COMPAREWITHPREVIOUS
, IDI_DIFF
, diffmenu
.m_hMenu
);
1888 for (size_t i
= 0; i
< parentInfo
.size(); ++i
)
1890 diffmenu
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
+ ((i
+ 1) << 16), parentInfo
[i
]);
1891 if (i
== 0 && CRegDWORD(L
"Software\\TortoiseGit\\DiffByDoubleClickInLog", FALSE
) && m_ColumnRegKey
!= L
"reflog")
1893 popup
.SetDefaultItem(ID_COMPAREWITHPREVIOUS
, FALSE
);
1894 diffmenu
.SetDefaultItem(static_cast<UINT
>(ID_COMPAREWITHPREVIOUS
+ ((i
+ 1) << 16)), FALSE
);
1897 requiresSeparator
= true;
1901 if(m_ContextMenuMask
&GetContextMenuBit(ID_BLAME
))
1903 popup
.AppendMenuIcon(ID_BLAME
, IDS_LOG_POPUP_BLAME
, IDI_BLAME
);
1904 requiresSeparator
= true;
1907 if (requiresSeparator
)
1909 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1910 requiresSeparator
= false;
1913 if (pSelLogEntry
->m_CommitHash
.IsEmpty() && !isMergeActive
)
1915 if(m_ContextMenuMask
&GetContextMenuBit(ID_STASH_SAVE
))
1917 popup
.AppendMenuIcon(ID_STASH_SAVE
, IDS_MENUSTASHSAVE
, IDI_SHELVE
);
1918 requiresSeparator
= true;
1922 if ((pSelLogEntry
->m_CommitHash
.IsEmpty() || isStash
) && workingTree
.HasStashDir())
1924 if (m_ContextMenuMask
&GetContextMenuBit(ID_STASH_POP
))
1926 popup
.AppendMenuIcon(ID_STASH_POP
, IDS_MENUSTASHPOP
, IDI_UNSHELVE
);
1927 requiresSeparator
= true;
1930 if (m_ContextMenuMask
&GetContextMenuBit(ID_STASH_LIST
))
1932 popup
.AppendMenuIcon(ID_STASH_LIST
, IDS_MENUSTASHLIST
, IDI_LOG
);
1933 requiresSeparator
= true;
1937 if (requiresSeparator
)
1939 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1940 requiresSeparator
= false;
1945 GitRevLoglist
* pFirstEntry
= m_arShownList
.SafeGetAt(FirstSelect
);
1946 if (m_ContextMenuMask
&GetContextMenuBit(ID_BISECTGOOD
) && !IsBisect(pFirstEntry
))
1948 popup
.AppendMenuIcon(ID_BISECTGOOD
, IDS_MENUBISECTGOOD
, IDI_THUMB_UP
);
1949 requiresSeparator
= true;
1952 if (m_ContextMenuMask
&GetContextMenuBit(ID_BISECTBAD
) && !IsBisect(pFirstEntry
))
1954 popup
.AppendMenuIcon(ID_BISECTBAD
, IDS_MENUBISECTBAD
, IDI_THUMB_DOWN
);
1955 requiresSeparator
= true;
1957 if (m_ContextMenuMask
&GetContextMenuBit(ID_BISECTSKIP
) && !IsBisect(pFirstEntry
))
1959 popup
.AppendMenuIcon(ID_BISECTSKIP
, IDS_MENUBISECTSKIP
, IDI_BISECT
);
1960 requiresSeparator
= true;
1964 if (pSelLogEntry
->m_CommitHash
.IsEmpty() && isBisectActive
)
1966 if (m_ContextMenuMask
&GetContextMenuBit(ID_BISECTRESET
))
1968 popup
.AppendMenuIcon(ID_BISECTRESET
, IDS_MENUBISECTRESET
, IDI_BISECT_RESET
);
1969 requiresSeparator
= true;
1973 if (requiresSeparator
)
1975 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1976 requiresSeparator
= false;
1979 if (pSelLogEntry
->m_CommitHash
.IsEmpty())
1981 if (m_ContextMenuMask
& GetContextMenuBit(ID_PULL
) && !isMergeActive
)
1982 popup
.AppendMenuIcon(ID_PULL
, IDS_MENUPULL
, IDI_PULL
);
1984 if(m_ContextMenuMask
&GetContextMenuBit(ID_FETCH
))
1985 popup
.AppendMenuIcon(ID_FETCH
, IDS_MENUFETCH
, IDI_UPDATE
);
1987 if ((m_ContextMenuMask
& GetContextMenuBit(ID_SUBMODULE_UPDATE
)) && workingTree
.HasSubmodules())
1988 popup
.AppendMenuIcon(ID_SUBMODULE_UPDATE
, IDS_PROC_SYNC_SUBKODULEUPDATE
, IDI_UPDATE
);
1990 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1992 if (m_ContextMenuMask
& GetContextMenuBit(ID_CLEANUP
))
1993 popup
.AppendMenuIcon(ID_CLEANUP
, IDS_MENUCLEANUP
, IDI_CLEANUP
);
1995 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1999 // if (!m_ProjectProperties.sWebViewerRev.IsEmpty())
2001 // popup.AppendMenuIcon(ID_VIEWREV, IDS_LOG_POPUP_VIEWREV);
2003 // if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
2005 // popup.AppendMenuIcon(ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
2007 // if ((!m_ProjectProperties.sWebViewerPathRev.IsEmpty())||
2008 // (!m_ProjectProperties.sWebViewerRev.IsEmpty()))
2010 // popup.AppendMenu(MF_SEPARATOR, NULL);
2015 // popup.AppendMenuIcon(ID_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
2017 if(!pSelLogEntry
->m_CommitHash
.IsEmpty())
2019 if (m_ContextMenuMask
& GetContextMenuBit(ID_LOG
))
2021 popup
.AppendMenuIcon(ID_LOG
, IDS_LOG_POPUP_LOG
, IDI_LOG
);
2022 if (m_ColumnRegKey
== L
"reflog")
2023 popup
.SetDefaultItem(ID_LOG
, FALSE
);
2026 if (m_ContextMenuMask
&GetContextMenuBit(ID_REPOBROWSE
))
2027 popup
.AppendMenuIcon(ID_REPOBROWSE
, IDS_LOG_BROWSEREPO
, IDI_REPOBROWSE
);
2029 str
.Format(IDS_LOG_POPUP_MERGEREV
, static_cast<LPCWSTR
>(g_Git
.GetCurrentBranch()));
2031 if (m_ContextMenuMask
&GetContextMenuBit(ID_MERGEREV
) && !isHeadCommit
&& m_hasWC
&& !isMergeActive
&& !isStash
)
2033 popup
.AppendMenuIcon(ID_MERGEREV
, str
, IDI_MERGE
);
2035 size_t index
= static_cast<size_t>(-1);
2036 CGit::REF_TYPE type
= CGit::REF_TYPE::UNKNOWN
;
2037 if (IsMouseOnRefLabelFromPopupMenu(pSelLogEntry
, point
, type
, hashMap
, nullptr, &index
))
2038 popup
.SetMenuItemData(ID_MERGEREV
, reinterpret_cast<LONG_PTR
>(&hashMap
.find(pSelLogEntry
->m_CommitHash
)->second
[index
]));
2041 str
.Format(IDS_RESET_TO_THIS_FORMAT
, static_cast<LPCWSTR
>(g_Git
.GetCurrentBranch()));
2043 if (m_ContextMenuMask
&GetContextMenuBit(ID_RESET
) && m_hasWC
&& !isStash
)
2044 popup
.AppendMenuIcon(ID_RESET
, str
, IDI_RESET
);
2047 // Add Switch Branch express Menu
2048 if (hashMap
.find(pSelLogEntry
->m_CommitHash
) != hashMap
.end()
2049 && (m_ContextMenuMask
&GetContextMenuBit(ID_SWITCHBRANCH
) && m_hasWC
&& !isStash
)
2052 std::vector
<const CString
*> branchs
;
2053 auto addCheck
= [&](const CString
& ref
)
2055 if (!CStringUtils::StartsWith(ref
, L
"refs/heads/") || ref
== currentBranch
)
2057 branchs
.push_back(&ref
);
2059 size_t index
= static_cast<size_t>(-1);
2060 CGit::REF_TYPE type
= CGit::REF_TYPE::UNKNOWN
;
2061 if (IsMouseOnRefLabelFromPopupMenu(pSelLogEntry
, point
, type
, hashMap
, nullptr, &index
))
2062 addCheck(hashMap
.find(pSelLogEntry
->m_CommitHash
)->second
[index
]);
2064 for_each(hashMap
.find(pSelLogEntry
->m_CommitHash
)->second
, addCheck
);
2067 str2
.LoadString(IDS_SWITCH_BRANCH
);
2069 if(branchs
.size() == 1)
2072 str2
+= L
'"' + branchs
[0]->Mid(static_cast<int>(wcslen(L
"refs/heads/"))) + L
'"';
2073 popup
.AppendMenuIcon(ID_SWITCHBRANCH
, str2
, IDI_SWITCH
);
2075 popup
.SetMenuItemData(ID_SWITCHBRANCH
, reinterpret_cast<LONG_PTR
>(branchs
[0]));
2078 else if(branchs
.size() > 1)
2080 subbranchmenu
.CreatePopupMenu();
2081 for (size_t i
= 0 ; i
< branchs
.size(); ++i
)
2083 if (*branchs
[i
] != currentBranch
)
2085 subbranchmenu
.AppendMenuIcon(ID_SWITCHBRANCH
+ (i
<< 16), branchs
[i
]->Mid(static_cast<int>(wcslen(L
"refs/heads/"))));
2086 subbranchmenu
.SetMenuItemData(ID_SWITCHBRANCH
+(i
<<16), reinterpret_cast<LONG_PTR
>(branchs
[i
]));
2090 popup
.AppendMenuIcon(ID_SWITCHBRANCH
, str2
, IDI_SWITCH
, subbranchmenu
.m_hMenu
);
2094 if (m_ContextMenuMask
&GetContextMenuBit(ID_SWITCHTOREV
) && !isHeadCommit
&& m_hasWC
&& !isStash
)
2096 popup
.AppendMenuIcon(ID_SWITCHTOREV
, IDS_SWITCH_TO_THIS
, IDI_SWITCH
);
2097 size_t index
= static_cast<size_t>(-1);
2098 CGit::REF_TYPE type
= CGit::REF_TYPE::UNKNOWN
;
2099 if (IsMouseOnRefLabelFromPopupMenu(pSelLogEntry
, point
, type
, hashMap
, nullptr, &index
))
2100 popup
.SetMenuItemData(ID_SWITCHTOREV
, reinterpret_cast<LONG_PTR
>(&hashMap
.find(pSelLogEntry
->m_CommitHash
)->second
[index
]));
2103 if (m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_BRANCH
) && !isStash
)
2105 popup
.AppendMenuIcon(ID_CREATE_BRANCH
, IDS_CREATE_BRANCH_AT_THIS
, IDI_COPY
);
2107 size_t index
= static_cast<size_t>(-1);
2108 CGit::REF_TYPE type
= CGit::REF_TYPE::REMOTE_BRANCH
;
2109 if (IsMouseOnRefLabelFromPopupMenu(pSelLogEntry
, point
, type
, hashMap
, nullptr, &index
))
2110 popup
.SetMenuItemData(ID_CREATE_BRANCH
, reinterpret_cast<LONG_PTR
>(&hashMap
.find(pSelLogEntry
->m_CommitHash
)->second
[index
]));
2113 if (m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_TAG
) && !isStash
)
2114 popup
.AppendMenuIcon(ID_CREATE_TAG
,IDS_CREATE_TAG_AT_THIS
, IDI_TAG
);
2116 str
.Format(IDS_REBASE_THIS_FORMAT
, static_cast<LPCWSTR
>(g_Git
.GetCurrentBranch()));
2118 if (pSelLogEntry
->m_CommitHash
!= headHash
&& m_hasWC
&& !isMergeActive
&& !isStash
)
2119 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_TO_VERSION
))
2120 popup
.AppendMenuIcon(ID_REBASE_TO_VERSION
, str
, IDI_REBASE
);
2122 if(m_ContextMenuMask
&GetContextMenuBit(ID_EXPORT
))
2123 popup
.AppendMenuIcon(ID_EXPORT
,IDS_EXPORT_TO_THIS
, IDI_EXPORT
);
2125 if (m_ContextMenuMask
&GetContextMenuBit(ID_REVERTREV
) && m_hasWC
&& !isMergeActive
&& !isStash
)
2127 if (parentHash
.size() == 1)
2128 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREV
, IDI_REVERT
);
2129 else if (parentHash
.size() > 1)
2131 revertmenu
.CreatePopupMenu();
2132 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREV
, IDI_REVERT
, revertmenu
.m_hMenu
);
2134 for (size_t i
= 0; i
< parentInfo
.size(); ++i
)
2136 revertmenu
.AppendMenuIcon(ID_REVERTREV
+ ((i
+ 1) << 16), parentInfo
[i
]);
2141 if (m_ContextMenuMask
&GetContextMenuBit(ID_EDITNOTE
) && !isStash
)
2142 popup
.AppendMenuIcon(ID_EDITNOTE
, IDS_EDIT_NOTES
, IDI_EDIT
);
2144 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2148 if(!pSelLogEntry
->m_Ref
.IsEmpty())
2150 popup
.AppendMenuIcon(ID_REFLOG_DEL
, IDS_REFLOG_DEL
, IDI_DELETE
);
2151 if (selectedCount
== 1 && CStringUtils::StartsWith(pSelLogEntry
->m_Ref
, L
"refs/stash"))
2152 popup
.AppendMenuIcon(ID_REFLOG_STASH_APPLY
, IDS_MENUSTASHAPPLY
, IDI_UNSHELVE
);
2153 if (selectedCount
<= 2)
2154 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2157 if (selectedCount
>= 2)
2159 bool bAddSeparator
= false;
2160 if ((selectedCount
== 2) || IsSelectionContinuous())
2162 if (m_ContextMenuMask
&GetContextMenuBit(ID_COMPARETWO
)) // compare two revisions
2164 popup
.AppendMenuIcon(ID_COMPARETWO
, IDS_LOG_POPUP_COMPARETWO
, IDI_DIFF
);
2165 bAddSeparator
= true;
2169 if (selectedCount
== 2)
2171 if (m_ContextMenuMask
&GetContextMenuBit(ID_GNUDIFF2
) && m_hasWC
) // compare two revisions, unified
2173 popup
.AppendMenuIcon(ID_GNUDIFF2
, IDS_LOG_POPUP_GNUDIFF
, IDI_DIFF
);
2174 bAddSeparator
= true;
2177 if (!pSelLogEntry
->m_CommitHash
.IsEmpty())
2179 CString firstSelHash
= pSelLogEntry
->m_CommitHash
.ToString(g_Git
.GetShortHASHLength());
2180 GitRevLoglist
* pLastEntry
= m_arShownList
.SafeGetAt(LastSelect
);
2181 CString lastSelHash
= pLastEntry
->m_CommitHash
.ToString(g_Git
.GetShortHASHLength());
2183 menu
.Format(IDS_SHOWLOG_OF
, static_cast<LPCWSTR
>(lastSelHash
+ L
".." + firstSelHash
));
2184 popup
.AppendMenuIcon(ID_LOG_VIEWRANGE
, menu
, IDI_LOG
);
2185 menu
.Format(IDS_SHOWLOG_OF
, static_cast<LPCWSTR
>(lastSelHash
+ L
"..." + firstSelHash
));
2186 popup
.AppendMenuIcon(ID_LOG_VIEWRANGE_REACHABLEFROMONLYONE
, menu
, IDI_LOG
);
2187 bAddSeparator
= true;
2191 if ((m_ContextMenuMask
& GetContextMenuBit(ID_COMPARETWOCOMMITCHANGES
)) && selectedCount
== 2)
2193 bAddSeparator
= true;
2194 popup
.AppendMenuIcon(ID_COMPARETWOCOMMITCHANGES
, IDS_LOG_POPUP_COMPARECHANGESET
, IDI_DIFF
);
2199 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2200 bAddSeparator
= false;
2203 if (m_ContextMenuMask
&GetContextMenuBit(ID_REVERTREV
) && m_hasWC
&& !isMergeActive
)
2204 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREVS
, IDI_REVERT
);
2207 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2210 if (selectedCount
> 1 && isBisectActive
&& (m_ContextMenuMask
& GetContextMenuBit(ID_BISECTSKIP
)) && !IsBisect(pSelLogEntry
))
2212 popup
.AppendMenuIcon(ID_BISECTSKIP
, IDS_MENUBISECTSKIP
, IDI_BISECT
);
2213 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2216 if (!pSelLogEntry
->m_CommitHash
.IsEmpty())
2218 bool bAddSeparator
= false;
2219 if (selectedCount
>= 2 && IsSelectionContinuous())
2221 if (m_ContextMenuMask
&GetContextMenuBit(ID_COMBINE_COMMIT
) && m_hasWC
&& !isMergeActive
)
2223 int headindex
= this->GetHeadIndex();
2224 if(headindex
>=0 && LastSelect
>= headindex
&& FirstSelect
>= headindex
)
2227 head
.Format(L
"HEAD~%d", FirstSelect
- headindex
);
2229 int ret
= g_Git
.GetHash(hashFirst
, head
);
2230 head
.Format(L
"HEAD~%d",LastSelect
-headindex
);
2232 ret
= ret
|| g_Git
.GetHash(hash
, head
);
2233 GitRevLoglist
* pFirstEntry
= m_arShownList
.SafeGetAt(FirstSelect
);
2234 GitRevLoglist
* pLastEntry
= m_arShownList
.SafeGetAt(LastSelect
);
2235 if (!ret
&& pFirstEntry
->m_CommitHash
== hashFirst
&& pLastEntry
->m_CommitHash
== hash
)
2237 popup
.AppendMenuIcon(ID_COMBINE_COMMIT
,IDS_COMBINE_TO_ONE
,IDI_COMBINE
);
2238 bAddSeparator
= true;
2243 if (m_ContextMenuMask
&GetContextMenuBit(ID_CHERRY_PICK
) && !isHeadCommit
&& m_hasWC
&& !isMergeActive
) {
2244 if (selectedCount
>= 2)
2245 popup
.AppendMenuIcon(ID_CHERRY_PICK
, IDS_CHERRY_PICK_VERSIONS
, IDI_CHERRYPICK
);
2247 popup
.AppendMenuIcon(ID_CHERRY_PICK
, IDS_CHERRY_PICK_VERSION
, IDI_CHERRYPICK
);
2248 bAddSeparator
= true;
2251 if (!isStash
&& (selectedCount
<= 2 || IsSelectionContinuous()))
2252 if(m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_PATCH
)) {
2253 popup
.AppendMenuIcon(ID_CREATE_PATCH
, IDS_CREATE_PATCH
, IDI_PATCH
);
2254 bAddSeparator
= true;
2258 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2261 if (m_hasWC
&& !isMergeActive
&& !isStash
&& (m_ContextMenuMask
& GetContextMenuBit(ID_BISECTSTART
)) && selectedCount
== 2 && !m_arShownList
.SafeGetAt(FirstSelect
)->m_CommitHash
.IsEmpty() && !isBisectActive
)
2263 popup
.AppendMenuIcon(ID_BISECTSTART
, IDS_MENUBISECTSTART
, IDI_BISECT
);
2264 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2267 if (selectedCount
== 1)
2269 bool bAddSeparator
= false;
2270 if ((m_ContextMenuMask
& GetContextMenuBit(ID_PUSH
)) && ((!isStash
&& hashMap
.find(pSelLogEntry
->m_CommitHash
) != hashMap
.cend()) || showExtendedMenu
))
2272 // show the push-option only if the log entry has an associated local branch
2273 bool isLocal
= hashMap
.find(pSelLogEntry
->m_CommitHash
) != hashMap
.cend() && any_of(hashMap
.find(pSelLogEntry
->m_CommitHash
)->second
, [](const CString
& ref
) { return CStringUtils::StartsWith(ref
, L
"refs/heads/") || CStringUtils::StartsWith(ref
, L
"refs/tags/"); });
2274 if (isLocal
|| showExtendedMenu
)
2277 str
.LoadString(IDS_MENUPUSH
);
2280 size_t index
= static_cast<size_t>(-1);
2281 CGit::REF_TYPE type
= CGit::REF_TYPE::UNKNOWN
;
2282 if (IsMouseOnRefLabelFromPopupMenu(pSelLogEntry
, point
, type
, hashMap
, &branch
, &index
))
2283 if (type
== CGit::REF_TYPE::LOCAL_BRANCH
|| type
== CGit::REF_TYPE::ANNOTATED_TAG
|| type
== CGit::REF_TYPE::TAG
)
2284 str
.Insert(str
.Find(L
'.'), L
" \"" + branch
+ L
'"');
2286 popup
.AppendMenuIcon(ID_PUSH
, str
, IDI_PUSH
);
2288 if (auto refList
= hashMap
.find(pSelLogEntry
->m_CommitHash
); index
!= static_cast<size_t>(-1) && index
< refList
->second
.size())
2289 popup
.SetMenuItemData(ID_PUSH
, reinterpret_cast<LONG_PTR
>(&refList
->second
[index
]));
2291 if (m_ContextMenuMask
& GetContextMenuBit(ID_SVNDCOMMIT
) && workingTree
.HasGitSVNDir())
2292 popup
.AppendMenuIcon(ID_SVNDCOMMIT
, IDS_MENUSVNDCOMMIT
, IDI_COMMIT
);
2294 bAddSeparator
= true;
2297 if (m_ContextMenuMask
& GetContextMenuBit(ID_PULL
) && isHeadCommit
&& !isMergeActive
&& m_hasWC
)
2299 popup
.AppendMenuIcon(ID_PULL
, IDS_MENUPULL
, IDI_PULL
);
2300 bAddSeparator
= true;
2304 if(m_ContextMenuMask
&GetContextMenuBit(ID_DELETE
))
2306 if (auto refList
= hashMap
.find(pSelLogEntry
->m_CommitHash
); refList
!= hashMap
.end() )
2308 std::vector
<const CString
*> branchs
;
2309 auto addCheck
= [&](const CString
& ref
)
2311 if (ref
== currentBranch
)
2313 branchs
.push_back(&ref
);
2315 size_t index
= static_cast<size_t>(-1);
2316 CGit::REF_TYPE type
= CGit::REF_TYPE::UNKNOWN
;
2317 if (IsMouseOnRefLabelFromPopupMenu(pSelLogEntry
, point
, type
, hashMap
, nullptr, &index
))
2318 addCheck(refList
->second
[index
]);
2320 for_each(refList
->second
, addCheck
);
2323 if (branchs
.size() == 1)
2325 str
.LoadString(IDS_DELETE_BRANCHTAG_SHORT
);
2328 popup
.AppendMenuIcon(ID_DELETE
, str
, IDI_DELETE
);
2329 popup
.SetMenuItemData(ID_DELETE
, reinterpret_cast<LONG_PTR
>(branchs
[0]));
2330 bAddSeparator
= true;
2332 else if (branchs
.size() > 1)
2334 str
.LoadString(IDS_DELETE_BRANCHTAG
);
2335 submenu
.CreatePopupMenu();
2336 for (size_t i
= 0; i
< branchs
.size(); ++i
)
2338 submenu
.AppendMenuIcon(ID_DELETE
+ (i
<< 16), *branchs
[i
]);
2339 submenu
.SetMenuItemData(ID_DELETE
+ (i
<< 16), reinterpret_cast<LONG_PTR
>(branchs
[i
]));
2341 submenu
.AppendMenuIcon(ID_DELETE
+ (branchs
.size() << 16), IDS_ALL
);
2342 submenu
.SetMenuItemData(ID_DELETE
+ (branchs
.size() << 16), reinterpret_cast<LONG_PTR
>(MAKEINTRESOURCE(IDS_ALL
)));
2344 popup
.AppendMenuIcon(ID_DELETE
,str
, IDI_DELETE
, submenu
.m_hMenu
);
2345 bAddSeparator
= true;
2348 } // m_ContextMenuMask &GetContextMenuBit(ID_DELETE)
2350 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2351 } // selectedCount == 1
2353 CIconMenu clipSubMenu
;
2354 if (!clipSubMenu
.CreatePopupMenu())
2356 if (m_ContextMenuMask
& GetContextMenuBit(ID_COPYCLIPBOARD
) && m_ColumnRegKey
!= L
"reflog")
2358 clipSubMenu
.AppendMenuIcon(ID_COPYCLIPBOARDFULL
, IDS_LOG_POPUP_CLIPBOARD_FULL
, IDI_COPYCLIP
);
2359 clipSubMenu
.AppendMenuIcon(ID_COPYCLIPBOARDFULLNOPATHS
, IDS_LOG_POPUP_CLIPBOARD_FULLNOPATHS
, IDI_COPYCLIP
);
2360 clipSubMenu
.AppendMenuIcon(ID_COPYCLIPBOARDHASH
, IDS_LOG_HASH
, IDI_COPYCLIP
);
2361 clipSubMenu
.AppendMenuIcon(ID_COPYCLIPBOARDAUTHORSFULL
, IDS_LOG_POPUP_CLIPBOARD_AUTHORSFULL
, IDI_COPYCLIP
);
2362 clipSubMenu
.AppendMenuIcon(ID_COPYCLIPBOARDAUTHORSNAME
, IDS_LOG_POPUP_CLIPBOARD_AUTHORSNAME
, IDI_COPYCLIP
);
2363 clipSubMenu
.AppendMenuIcon(ID_COPYCLIPBOARDAUTHORSEMAIL
, IDS_LOG_POPUP_CLIPBOARD_AUTHORSEMAIL
, IDI_COPYCLIP
);
2364 clipSubMenu
.AppendMenuIcon(ID_COPYCLIPBOARDSUBJECTS
, IDS_LOG_POPUP_CLIPBOARD_SUBJECTS
, IDI_COPYCLIP
);
2365 clipSubMenu
.AppendMenuIcon(ID_COPYCLIPBOARDMESSAGES
, IDS_LOG_POPUP_CLIPBOARD_MSGS
, IDI_COPYCLIP
);
2366 if (hashMap
.find(pSelLogEntry
->m_CommitHash
) != hashMap
.cend() && selectedCount
== 1)
2368 clipSubMenu
.AppendMenuIcon(ID_COPYCLIPBOARDBRANCHTAG
, IDS_LOG_POPUP_CLIPBOARD_TAGBRANCHES
, IDI_COPYCLIP
);
2369 size_t index
= static_cast<size_t>(-1);
2370 CGit::REF_TYPE type
= CGit::REF_TYPE::UNKNOWN
;
2371 if (IsMouseOnRefLabelFromPopupMenu(pSelLogEntry
, point
, type
, hashMap
, nullptr, &index
))
2372 clipSubMenu
.SetMenuItemData(ID_COPYCLIPBOARDBRANCHTAG
, reinterpret_cast<LONG_PTR
>(&hashMap
.find(pSelLogEntry
->m_CommitHash
)->second
[index
]));
2376 temp
.LoadString(IDS_LOG_POPUP_COPYTOCLIPBOARD
);
2377 popup
.InsertMenu(static_cast<UINT
>(-1), MF_BYPOSITION
| MF_POPUP
, reinterpret_cast<UINT_PTR
>(clipSubMenu
.m_hMenu
), temp
);
2379 else if (m_ContextMenuMask
& GetContextMenuBit(ID_COPYCLIPBOARD
) && m_ColumnRegKey
== L
"reflog")
2381 clipSubMenu
.AppendMenuIcon(ID_COPYCLIPBOARDFULL
, IDS_LOG_POPUP_CLIPBOARD_FULL
, IDI_COPYCLIP
);
2382 clipSubMenu
.AppendMenuIcon(ID_COPYCLIPBOARDHASH
, IDS_LOG_HASH
, IDI_COPYCLIP
);
2383 clipSubMenu
.AppendMenuIcon(ID_COPYCLIPBOARDMESSAGES
, IDS_LOG_POPUP_CLIPBOARD_MSGS
, IDI_COPYCLIP
);
2386 temp
.LoadString(IDS_LOG_POPUP_COPYTOCLIPBOARD
);
2387 popup
.InsertMenu(static_cast<UINT
>(-1), MF_BYPOSITION
| MF_POPUP
, reinterpret_cast<UINT_PTR
>(clipSubMenu
.m_hMenu
), temp
);
2390 if(m_ContextMenuMask
&GetContextMenuBit(ID_FINDENTRY
))
2391 popup
.AppendMenuIcon(ID_FINDENTRY
, IDS_LOG_POPUP_FIND
, IDI_FILTEREDIT
);
2393 if (selectedCount
== 1 && (m_ContextMenuMask
& GetContextMenuBit(ID_SHOWBRANCHES
)) && !pSelLogEntry
->m_CommitHash
.IsEmpty())
2394 popup
.AppendMenuIcon(ID_SHOWBRANCHES
, IDS_LOG_POPUP_SHOWBRANCHES
, IDI_SHOWBRANCHES
);
2396 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, this);
2397 // DialogEnableWindow(IDOK, FALSE);
2398 // SetPromptApp(&theApp);
2400 this->ContextMenuAction(cmd
, FirstSelect
, LastSelect
, &popup
, hashMap
);
2402 // EnableOKButton();
2403 } // if (popup.CreatePopupMenu())
2406 bool CGitLogListBase::IsSelectionContinuous()
2408 if ( GetSelectedCount()==1 )
2410 // if only one revision is selected, the selection is of course
2415 POSITION pos
= GetFirstSelectedItemPosition();
2416 bool bContinuous
= (m_arShownList
.size() == m_logEntries
.size());
2419 int itemindex
= GetNextSelectedItem(pos
);
2422 int nextindex
= GetNextSelectedItem(pos
);
2423 if (nextindex
- itemindex
> 1)
2425 bContinuous
= false;
2428 itemindex
= nextindex
;
2434 void CGitLogListBase::CopySelectionToClipBoard(int toCopy
)
2437 POSITION pos
= GetFirstSelectedItemPosition();
2441 sRev
.LoadString(IDS_LOG_REVISION
);
2443 sAuthor
.LoadString(IDS_LOG_AUTHOR
);
2445 sDate
.LoadString(IDS_LOG_DATE
);
2447 sMessage
.LoadString(IDS_LOG_MESSAGE
);
2448 CString
from(MAKEINTRESOURCE(IDS_STATUSLIST_FROM
));
2452 CString sLogCopyText
;
2454 GitRevLoglist
* pLogEntry
= m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
));
2456 if (toCopy
== ID_COPYCLIPBOARDFULL
)
2458 sPaths
= L
"----\r\n";
2459 auto files
= pLogEntry
->GetFiles(nullptr);
2460 for (int cpPathIndex
= 0; cpPathIndex
< files
.GetCount(); ++cpPathIndex
)
2462 auto& file
= files
[cpPathIndex
];
2463 sPaths
+= file
.GetActionName() + L
": " + file
.GetGitPathString();
2464 if (file
.m_Action
& (CTGitPath::LOGACTIONS_REPLACED
| CTGitPath::LOGACTIONS_COPY
) && !file
.GetGitOldPathString().IsEmpty())
2467 sPaths
.AppendFormat(from
, static_cast<LPCWSTR
>(file
.GetGitOldPathString()));
2475 if (toCopy
== ID_COPYCLIPBOARDFULL
|| toCopy
== ID_COPYCLIPBOARDFULLNOPATHS
)
2478 if (!pLogEntry
->m_Notes
.IsEmpty())
2480 sNotesTags
= L
"----\n" + CString(MAKEINTRESOURCE(IDS_NOTES
));
2481 sNotesTags
+= L
":\n";
2482 sNotesTags
+= pLogEntry
->m_Notes
;
2483 sNotesTags
.Replace(L
"\n", L
"\r\n");
2485 CString tagInfo
= GetTagInfo(pLogEntry
);
2486 if (!tagInfo
.IsEmpty())
2488 sNotesTags
+= L
"----\r\n" + CString(MAKEINTRESOURCE(IDS_PROC_LOG_TAGINFO
)) + L
":\r\n";
2489 tagInfo
.Replace(L
"\n", L
"\r\n");
2490 sNotesTags
+= tagInfo
;
2493 sLogCopyText
.Format(L
"%s: %s\r\n%s: %s <%s>\r\n%s: %s\r\n%s:\r\n%s\r\n%s%s\r\n",
2494 static_cast<LPCWSTR
>(sRev
), static_cast<LPCWSTR
>(pLogEntry
->m_CommitHash
.ToString()),
2495 static_cast<LPCWSTR
>(sAuthor
), static_cast<LPCWSTR
>(pLogEntry
->GetAuthorName()), static_cast<LPCWSTR
>(pLogEntry
->GetAuthorEmail()),
2496 static_cast<LPCWSTR
>(sDate
),
2497 static_cast<LPCWSTR
>(CLoglistUtils::FormatDateAndTime(pLogEntry
->GetAuthorDate(), m_DateFormat
, true, m_bRelativeTimes
)),
2498 static_cast<LPCWSTR
>(sMessage
), static_cast<LPCWSTR
>(pLogEntry
->GetSubjectBody(true)),
2499 static_cast<LPCWSTR
>(sNotesTags
),
2500 static_cast<LPCWSTR
>(sPaths
));
2501 sClipdata
+= sLogCopyText
;
2503 else if (toCopy
== ID_COPYCLIPBOARDAUTHORSFULL
)
2506 sClipdata
+= L
"\r\n";
2507 sClipdata
+= pLogEntry
->GetAuthorName();
2509 sClipdata
+= pLogEntry
->GetAuthorEmail();
2512 else if (toCopy
== ID_COPYCLIPBOARDAUTHORSNAME
)
2515 sClipdata
+= L
"\r\n";
2516 sClipdata
+= pLogEntry
->GetAuthorName();
2518 else if (toCopy
== ID_COPYCLIPBOARDAUTHORSEMAIL
)
2521 sClipdata
+= L
"\r\n";
2522 sClipdata
+= pLogEntry
->GetAuthorEmail();
2525 else if (toCopy
== ID_COPYCLIPBOARDMESSAGES
)
2528 sClipdata
+= pLogEntry
->GetSubjectBody(true);
2529 sClipdata
+= L
"\r\n\r\n";
2531 else if (toCopy
== ID_COPYCLIPBOARDSUBJECTS
)
2534 sClipdata
+= pLogEntry
->GetSubject().Trim();
2535 sClipdata
+= L
"\r\n\r\n";
2540 sClipdata
+= L
"\r\n";
2541 sClipdata
+= pLogEntry
->m_CommitHash
.ToString();
2546 CStringUtils::WriteAsciiStringToClipboard(sClipdata
, GetSafeHwnd());
2550 void CGitLogListBase::DiffSelectedRevWithPrevious()
2552 if (s_bThreadRunning
)
2555 POSITION pos
= GetFirstSelectedItemPosition();
2556 auto FirstSelect
= GetNextSelectedItem(pos
);
2557 int LastSelect
= -1;
2559 LastSelect
= GetNextSelectedItem(pos
);
2561 auto hashMap
= m_HashMap
;
2562 ContextMenuAction(ID_COMPAREWITHPREVIOUS
, FirstSelect
, LastSelect
, nullptr, *hashMap
.get());
2565 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
2567 LPNMLVFINDITEM pFindInfo
= reinterpret_cast<LPNMLVFINDITEM
>(pNMHDR
);
2570 if (pFindInfo
->lvfi
.flags
& LVFI_PARAM
)
2572 if (pFindInfo
->iStart
< 0 || pFindInfo
->iStart
>= static_cast<int>(m_arShownList
.size()))
2574 if (!pFindInfo
->lvfi
.psz
)
2577 CString sCmp
= pFindInfo
->lvfi
.psz
;
2579 for (int i
=pFindInfo
->iStart
; i
<m_arShownList
.GetCount(); ++i
)
2581 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(i
));
2582 sRev
.Format(L
"%ld", pLogEntry
->Rev
);
2583 if (pFindInfo
->lvfi
.flags
& LVFI_PARTIAL
)
2585 if (sCmp
.Compare(sRev
.Left(sCmp
.GetLength()))==0)
2593 if (sCmp
.Compare(sRev
)==0)
2600 if (pFindInfo
->lvfi
.flags
& LVFI_WRAP
)
2602 for (int i
=0; i
<pFindInfo
->iStart
; ++i
)
2604 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(i
));
2605 sRev
.Format(L
"%ld", pLogEntry
->Rev
);
2606 if (pFindInfo
->lvfi
.flags
& LVFI_PARTIAL
)
2608 if (sCmp
.Compare(sRev
.Left(sCmp
.GetLength()))==0)
2616 if (sCmp
.Compare(sRev
)==0)
2628 int CGitLogListBase::FillGitLog(CTGitPath
*path
, CString
*range
, int info
)
2632 this->m_arShownList
.SafeRemoveAll();
2634 this->m_logEntries
.ClearAll();
2635 if (this->m_logEntries
.ParserFromLog(path
, 0, info
, range
))
2638 SetItemCountEx(static_cast<int>(m_logEntries
.size()));
2640 for (unsigned int i
= 0; i
< m_logEntries
.size(); ++i
)
2643 this->m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1));
2645 this->m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2649 std::for_each(m_arShownList
.begin(), m_arShownList
.end(), [](auto entry
) { entry
->m_CallDiffAsync
= DiffAsync
; });
2659 int CGitLogListBase::FillGitLog(std::unordered_set
<CGitHash
>& hashes
)
2663 m_arShownList
.SafeRemoveAll();
2665 m_logEntries
.ClearAll();
2666 if (m_logEntries
.Fill(hashes
))
2669 SetItemCountEx(static_cast<int>(m_logEntries
.size()));
2671 for (unsigned int i
= 0; i
< m_logEntries
.size(); ++i
)
2674 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(m_logEntries
.size() - i
- 1));
2676 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2680 std::for_each(m_arShownList
.begin(), m_arShownList
.end(), [](auto entry
) { entry
->m_CallDiffAsync
= DiffAsync
; });
2688 int CGitLogListBase::BeginFetchLog()
2690 ATLASSERT(IsInWorkingThread());
2693 this->m_arShownList
.SafeRemoveAll();
2695 this->m_logEntries
.ClearAll();
2697 this->m_LogCache
.ClearAllParent();
2699 m_LogCache
.FetchCacheIndex(g_Git
.m_CurrentDir
);
2702 if(this->m_Path
.IsEmpty())
2707 int mask
= CGit::LOG_INFO_ONLY_HASH
;
2708 if (m_bIncludeBoundaryCommits
)
2709 mask
|= CGit::LOG_INFO_BOUNDARY
;
2710 // if(this->m_bAllBranch)
2711 mask
|= m_ShowMask
;
2715 this->m_logEntries
.insert(m_logEntries
.cbegin(), m_wcRev
.m_CommitHash
);
2717 this->m_LogCache
.m_HashMap
[m_wcRev
.m_CommitHash
]=m_wcRev
;
2722 Locker
lock(m_critSec
);
2725 if (range
.IsEmpty())
2728 // follow does not work for directories
2729 if (!path
|| path
->IsDirectory())
2730 mask
&= ~CGit::LOG_INFO_FOLLOW
;
2731 // follow does not work with all branches 8at least in TGit)
2732 if (mask
& CGit::LOG_INFO_FOLLOW
)
2733 mask
&= ~(CGit::LOG_INFO_ALL_BRANCH
| CGit::LOG_INFO_BASIC_REFS
| CGit::LOG_INFO_LOCAL_BRANCHES
);
2735 CString cmd
= g_Git
.GetLogCmd(range
, path
, mask
, &m_Filter
, CRegDWORD(L
"Software\\TortoiseGit\\LogOrderBy", CGit::LOG_ORDER_TOPOORDER
));
2737 PostMessage(LVM_SETITEMCOUNT
, m_logEntries
.size(), LVSICF_NOINVALIDATEALL
);
2741 CAutoLocker
lock(g_Git
.m_critGitDllSec
);
2742 g_Git
.CheckAndInitDll();
2747 MessageBox(L
"Could not initialize libgit.\nlibgit reports:\n" + err
, L
"TortoiseGit", MB_ICONERROR
);
2751 if (!g_Git
.CanParseRev(range
))
2753 if (!(mask
& CGit::LOG_INFO_ALL_BRANCH
) && !(mask
& CGit::LOG_INFO_BASIC_REFS
) && !(mask
& CGit::LOG_INFO_LOCAL_BRANCHES
))
2756 // if show all branches, pick any ref as dummy entry ref
2758 if (g_Git
.GetRefList(list
))
2759 MessageBox(g_Git
.GetGitLastErr(L
"Could not get all refs."), L
"TortoiseGit", MB_ICONERROR
);
2763 cmd
= g_Git
.GetLogCmd(list
[0], path
, mask
, &m_Filter
, CRegDWORD(L
"Software\\TortoiseGit\\LogOrderBy", CGit::LOG_ORDER_TOPOORDER
));
2766 g_Git
.m_critGitDllSec
.Lock();
2768 if (git_open_log(&m_DllGitLog
, CUnicodeUtils::GetUTF8(cmd
)))
2770 g_Git
.m_critGitDllSec
.Unlock();
2776 g_Git
.m_critGitDllSec
.Unlock();
2778 MessageBox(L
"Could not open log.\nlibgit reports:\n" + err
, L
"TortoiseGit", MB_ICONERROR
);
2781 g_Git
.m_critGitDllSec
.Unlock();
2786 BOOL
CGitLogListBase::PreTranslateMessage(MSG
* pMsg
)
2788 if (pMsg
->message
== WM_KEYDOWN
&& pMsg
->wParam
=='\r' && !(GetAsyncKeyState(VK_CONTROL
) & 0x8000))
2790 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))
2792 if (CRegDWORD(L
"Software\\TortoiseGit\\DiffByDoubleClickInLog", FALSE
))
2794 DiffSelectedRevWithPrevious();
2799 if (GetFocus()==GetDlgItem(IDC_LOGMSG
))
2806 else if (pMsg
->message
== WM_KEYDOWN
&& pMsg
->wParam
== 'A' && GetAsyncKeyState(VK_CONTROL
)&0x8000)
2808 // select all entries
2809 for (int i
=0; i
<GetItemCount(); ++i
)
2810 SetItemState(i
, LVIS_SELECTED
, LVIS_SELECTED
);
2815 if (m_hAccel
&& !bSkipAccelerator
)
2817 int ret
= TranslateAccelerator(m_hWnd
, m_hAccel
, pMsg
);
2823 //m_tooltips.RelayEvent(pMsg);
2824 return __super::PreTranslateMessage(pMsg
);
2827 void CGitLogListBase::OnNMDblclkLoglist(NMHDR
* /*pNMHDR*/, LRESULT
*pResult
)
2829 // a double click on an entry in the revision list has happened
2832 if (CRegDWORD(L
"Software\\TortoiseGit\\DiffByDoubleClickInLog", FALSE
))
2833 DiffSelectedRevWithPrevious();
2836 void CGitLogListBase::FetchLogAsync(void* data
)
2840 StartLoadingThread();
2843 UINT
CGitLogListBase::LogThreadEntry(LPVOID pVoid
)
2845 return static_cast<CGitLogListBase
*>(pVoid
)->LogThread();
2848 void CGitLogListBase::GetTimeRange(CTime
&oldest
, CTime
&latest
)
2851 oldest
=CTime::GetCurrentTime();
2852 latest
=CTime(1971,1,2,0,0,0);
2853 for (unsigned int i
= 0; i
< m_logEntries
.size(); ++i
)
2855 if(m_logEntries
[i
].IsEmpty())
2858 if (m_logEntries
.GetGitRevAt(i
).GetCommitterDate().GetTime() < oldest
.GetTime())
2859 oldest
= m_logEntries
.GetGitRevAt(i
).GetCommitterDate().GetTime();
2861 if (m_logEntries
.GetGitRevAt(i
).GetCommitterDate().GetTime() > latest
.GetTime())
2862 latest
= m_logEntries
.GetGitRevAt(i
).GetCommitterDate().GetTime();
2870 UINT
CGitLogListBase::LogThread()
2872 ::PostMessage(this->GetParent()->m_hWnd
, MSG_LOAD_PERCENTAGE
, GITLOG_START
, 0);
2878 InterlockedExchange(&s_bThreadRunning
, FALSE
);
2879 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2884 // create a copy we can safely work on in this thread
2885 auto shared_filter(m_LogFilter
);
2886 const auto& filter
= *shared_filter
;
2888 TRACE(L
"\n===Begin===\n");
2889 //Update work copy item;
2891 if (!m_logEntries
.empty())
2893 GitRevLoglist
* pRev
= &m_logEntries
.GetGitRevAt(0);
2895 m_arShownList
.SafeAdd(pRev
);
2899 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2901 // store commit number of the last selected commit/line before the refresh or -1
2902 int lastSelectedHashNItem
= -1;
2903 if (m_lastSelectedHash
.IsEmpty())
2904 lastSelectedHashNItem
= 0;
2908 bool shouldWalk
= true;
2911 Locker
lock(m_critSec
);
2914 if (!g_Git
.CanParseRev(range
))
2916 // walk revisions if show all branches and there exists any ref
2917 if (!(m_ShowMask
& CGit::LOG_INFO_ALL_BRANCH
) && !(m_ShowMask
& CGit::LOG_INFO_BASIC_REFS
) && !(m_ShowMask
& CGit::LOG_INFO_LOCAL_BRANCHES
))
2922 if (g_Git
.GetRefList(list
))
2923 MessageBox(g_Git
.GetGitLastErr(L
"Could not get all refs."), L
"TortoiseGit", MB_ICONERROR
);
2931 g_Git
.m_critGitDllSec
.Lock();
2934 MessageBox(L
"Opening log failed.", L
"TortoiseGit", MB_ICONERROR
);
2935 g_Git
.m_critGitDllSec
.Unlock();
2936 InterlockedExchange(&s_bThreadRunning
, FALSE
);
2937 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2943 [&] {git_get_log_firstcommit(m_DllGitLog
);}();
2944 total
= git_get_log_estimate_commit_count(m_DllGitLog
);
2949 MessageBox(L
"Could not get first commit.\nlibgit reports:\n" + err
, L
"TortoiseGit", MB_ICONERROR
);
2952 g_Git
.m_critGitDllSec
.Unlock();
2954 if (CGitMailmap::ShouldLoadMailmap())
2955 GitRevLoglist::s_Mailmap
= std::make_shared
<CGitMailmap
>();
2956 else if (GitRevLoglist::s_Mailmap
)
2957 GitRevLoglist::s_Mailmap
= nullptr;
2958 auto mailmap
= GitRevLoglist::s_Mailmap
;
2960 auto hashMapSharedPtr
= m_HashMap
;
2961 const auto& hashMap
= *hashMapSharedPtr
;
2964 t2
= t1
= GetTickCount64();
2965 int oldprecentage
= 0;
2966 size_t oldsize
= m_logEntries
.size();
2967 std::unordered_map
<CGitHash
, std::unordered_set
<CGitHash
>> commitChildren
;
2968 while (ret
== 0 && !m_bExitThread
)
2970 g_Git
.m_critGitDllSec
.Lock();
2973 [&] { ret
= git_get_log_nextcommit(this->m_DllGitLog
, &commit
, m_ShowMask
& CGit::LOG_INFO_FOLLOW
); } ();
2977 g_Git
.m_critGitDllSec
.Unlock();
2979 MessageBox(L
"Could not get next commit.\nlibgit reports:\n" + err
, L
"TortoiseGit", MB_ICONERROR
);
2985 g_Git
.m_critGitDllSec
.Unlock();
2986 if (ret
!= -2) // other than end of revision walking
2987 MessageBox((L
"Could not get next commit.\nlibgit returns:" + std::to_wstring(ret
)).c_str(), L
"TortoiseGit", MB_ICONERROR
);
2991 if (commit
.m_ignore
== 1)
2993 git_free_commit(&commit
);
2994 g_Git
.m_critGitDllSec
.Unlock();
2998 //printf("%s\r\n",commit.GetSubject());
3001 git_free_commit(&commit
);
3002 g_Git
.m_critGitDllSec
.Unlock();
3006 CGitHash hash
= CGitHash::FromRaw(commit
.m_hash
);
3008 GitRevLoglist
* pRev
= m_LogCache
.GetCacheData(hash
);
3009 pRev
->Parse(&commit
, mailmap
.get()); // better parse here than on GITLOG_END in LogDlg::OnLogListLoading for updating the DateSelectors
3011 char* note
= nullptr;
3014 git_get_notes(commit
.m_hash
, ¬e
);
3018 g_Git
.m_critGitDllSec
.Unlock();
3020 MessageBox(L
"Could not get commit notes.\nlibgit reports:\n" + err
, L
"TortoiseGit", MB_ICONERROR
);
3026 pRev
->m_Notes
= CUnicodeUtils::GetUnicode(note
);
3030 git_free_commit(&commit
);
3031 g_Git
.m_critGitDllSec
.Unlock();
3033 if(!pRev
->m_IsDiffFiles
)
3035 pRev
->m_CallDiffAsync
= DiffAsync
;
3038 if (m_ShowFilter
& FILTERSHOW_MERGEPOINTS
) // See also ShouldShowFilter()
3040 for (size_t i
= 0; i
< pRev
->m_ParentHash
.size(); ++i
)
3042 const CGitHash
&parentHash
= pRev
->m_ParentHash
[i
];
3043 auto it
= commitChildren
.find(parentHash
);
3044 if (it
== commitChildren
.end())
3045 it
= commitChildren
.insert(make_pair(parentHash
, std::unordered_set
<CGitHash
>())).first
;
3046 it
->second
.insert(pRev
->m_CommitHash
);
3054 bool visible
= filter(pRev
, this, hashMap
);
3055 if (visible
&& !ShouldShowFilter(pRev
, commitChildren
, hashMap
))
3057 this->m_critSec
.Lock();
3058 m_logEntries
.append(hash
, visible
);
3060 m_arShownList
.push_back(pRev
); // push_back is ok here, because we use the very same lock, otherwise use SafeAdd
3061 this->m_critSec
.Unlock();
3066 if (lastSelectedHashNItem
== -1 && hash
== m_lastSelectedHash
)
3067 lastSelectedHashNItem
= static_cast<int>(m_arShownList
.size()) - 1;
3069 t2
= GetTickCount64();
3071 if (t2
- t1
> 500UL || (m_logEntries
.size() - oldsize
> 100))
3074 int percent
= static_cast<int>(m_logEntries
.size() * 100 / (total
+ 1));
3077 if (percent
<= GITLOG_START
)
3078 percent
= GITLOG_START
+1;
3080 oldsize
= m_logEntries
.size();
3081 PostMessage(LVM_SETITEMCOUNT
, this->m_logEntries
.size(), LVSICF_NOINVALIDATEALL
|LVSICF_NOSCROLL
);
3083 if (percent
> oldprecentage
)
3085 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
, percent
, 0);
3086 oldprecentage
= percent
;
3089 if (lastSelectedHashNItem
>= 0)
3090 PostMessage(m_ScrollToMessage
, lastSelectedHashNItem
);
3095 g_Git
.m_critGitDllSec
.Lock();
3096 git_close_log(m_DllGitLog
);
3097 g_Git
.m_critGitDllSec
.Unlock();
3102 InterlockedExchange(&s_bThreadRunning
, FALSE
);
3107 PostMessage(LVM_SETITEMCOUNT
, this->m_logEntries
.size(), LVSICF_NOINVALIDATEALL
|LVSICF_NOSCROLL
);
3109 if (lastSelectedHashNItem
>= 0)
3110 PostMessage(m_ScrollToMessage
, lastSelectedHashNItem
);
3113 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
, GITLOG_END
, 0);
3115 InterlockedExchange(&s_bThreadRunning
, FALSE
);
3120 void CGitLogListBase::FetchRemoteList()
3122 STRING_VECTOR remoteList
;
3123 m_SingleRemote
.Empty();
3124 if (!g_Git
.GetRemoteList(remoteList
) && remoteList
.size() == 1)
3125 m_SingleRemote
= remoteList
[0];
3128 void CGitLogListBase::FetchTrackingBranchList()
3130 m_TrackingMap
.clear();
3131 auto hashMap
= m_HashMap
;
3132 for (auto it
= hashMap
->cbegin(); it
!= hashMap
->cend(); ++it
)
3134 for (const auto& ref
: it
->second
)
3137 if (CGit::GetShortName(ref
, branchName
, L
"refs/heads/"))
3139 CString pullRemote
, pullBranch
;
3140 g_Git
.GetRemoteTrackedBranch(branchName
, pullRemote
, pullBranch
);
3141 if (!pullRemote
.IsEmpty() && !pullBranch
.IsEmpty())
3142 m_TrackingMap
[branchName
] = std::make_pair(pullRemote
, pullBranch
);
3148 void CGitLogListBase::Refresh(BOOL IsCleanFilter
)
3150 SafeTerminateThread();
3152 this->SetItemCountEx(0);
3157 ShowGraphColumn((m_ShowMask
& CGit::LOG_INFO_FOLLOW
) ? false : true);
3159 //Update branch and Tag info
3162 m_pFindDialog
->RefreshList();
3163 //Assume Thread have exited
3164 //if(!s_bThreadRunning)
3166 m_logEntries
.clear();
3169 m_LogFilter
= std::make_shared
<CLogDlgFilter
>();
3171 SafeTerminateAsyncDiffThread();
3172 m_AsynDiffListLock
.Lock();
3173 m_AsynDiffList
.clear();
3174 m_AsynDiffListLock
.Unlock();
3175 StartAsyncDiffThread();
3177 StartLoadingThread();
3181 void CGitLogListBase::StartAsyncDiffThread()
3183 if (m_AsyncThreadExit
)
3185 if (InterlockedExchange(&m_AsyncThreadRunning
, TRUE
) != FALSE
)
3187 m_DiffingThread
= AfxBeginThread(AsyncThread
, this, THREAD_PRIORITY_BELOW_NORMAL
, 0, CREATE_SUSPENDED
);
3188 if (!m_DiffingThread
)
3190 InterlockedExchange(&m_AsyncThreadRunning
, FALSE
);
3191 CMessageBox::Show(GetSafeHwnd(), IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
3194 m_DiffingThread
->m_bAutoDelete
= FALSE
;
3195 m_DiffingThread
->ResumeThread();
3198 void CGitLogListBase::StartLoadingThread()
3200 if (InterlockedExchange(&s_bThreadRunning
, TRUE
) != FALSE
)
3202 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
3203 InterlockedExchange(&m_bExitThread
, FALSE
);
3204 m_LoadingThread
= AfxBeginThread(LogThreadEntry
, this, THREAD_PRIORITY_LOWEST
, 0, CREATE_SUSPENDED
);
3205 if (!m_LoadingThread
)
3207 InterlockedExchange(&s_bThreadRunning
, FALSE
);
3208 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
3209 CMessageBox::Show(GetSafeHwnd(), IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
3212 m_LoadingThread
->m_bAutoDelete
= FALSE
;
3213 m_LoadingThread
->ResumeThread();
3216 bool CGitLogListBase::ShouldShowFilter(GitRevLoglist
* pRev
, const std::unordered_map
<CGitHash
, std::unordered_set
<CGitHash
>>& commitChildren
, const MAP_HASH_NAME
& hashMap
)
3218 if (m_ShowFilter
& FILTERSHOW_ANYCOMMIT
)
3221 if ((m_ShowFilter
& FILTERSHOW_REFS
) && hashMap
.find(pRev
->m_CommitHash
) != hashMap
.cend())
3224 const auto& refList
= hashMap
.find(pRev
->m_CommitHash
)->second
;
3225 for (size_t i
= 0; i
< refList
.size(); ++i
)
3227 const CString
&str
= refList
[i
];
3228 if (CStringUtils::StartsWith(str
, L
"refs/heads/"))
3230 if (m_ShowRefMask
& LOGLIST_SHOWLOCALBRANCHES
)
3233 else if (CStringUtils::StartsWith(str
, L
"refs/remotes/"))
3235 if (m_ShowRefMask
& LOGLIST_SHOWREMOTEBRANCHES
)
3238 else if (CStringUtils::StartsWith(str
, L
"refs/tags/"))
3240 if (m_ShowRefMask
& LOGLIST_SHOWTAGS
)
3243 else if (CStringUtils::StartsWith(str
, L
"refs/stash"))
3245 if (m_ShowRefMask
& LOGLIST_SHOWSTASH
)
3248 else if (CStringUtils::StartsWith(str
, L
"refs/bisect/"))
3250 if (m_ShowRefMask
& LOGLIST_SHOWBISECT
)
3254 // Keep the head too.
3255 if (pRev
->m_CommitHash
== m_HeadHash
)
3259 if (m_ShowFilter
& FILTERSHOW_MERGEPOINTS
)
3261 if (pRev
->ParentsCount() > 1)
3263 auto childrenIt
= commitChildren
.find(pRev
->m_CommitHash
);
3264 if (childrenIt
!= commitChildren
.end())
3266 const std::unordered_set
<CGitHash
> &children
= childrenIt
->second
;
3267 if (children
.size() > 1)
3274 void CGitLogListBase::ShowGraphColumn(bool bShow
)
3276 // HACK to hide graph column
3278 SetColumnWidth(0, m_ColumnManager
.GetWidth(0, false));
3280 SetColumnWidth(0, 0);
3283 CString
CGitLogListBase::GetTagInfo(GitRev
* pLogEntry
) const
3285 auto hashMap
= m_HashMap
;
3286 auto refs
= hashMap
->find(pLogEntry
->m_CommitHash
);
3287 if (refs
== hashMap
->end())
3290 return GetTagInfo(refs
->second
);
3293 CString
CGitLogListBase::GetTagInfo(const STRING_VECTOR
& refs
) const
3296 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
3298 if (!CStringUtils::StartsWith((*it
), L
"refs/tags/"))
3300 if (!CStringUtils::EndsWith((*it
), L
"^{}"))
3304 cmd
.Format(L
"git.exe cat-file tag %s", static_cast<LPCWSTR
>((*it
).Left((*it
).GetLength() - static_cast<int>(wcslen(L
"^{}")))));
3306 if (g_Git
.Run(cmd
, &output
, nullptr, CP_UTF8
) != 0)
3312 // this assumes that in the header of the tag there is no ">" before the "tagger " header entry
3313 int pos1
= output
.Find(L
'>');
3317 if (output
[pos1
] == L
' ')
3319 int pos2
= output
.Find(L
'\n', pos1
);
3323 CString str
= output
.Mid(pos1
, pos2
- pos1
);
3324 wchar_t* pEnd
= nullptr;
3326 auto number
= wcstoumax(str
.GetBuffer(), &pEnd
, 10);
3327 if (str
.GetBuffer() == pEnd
)
3329 if (errno
== ERANGE
)
3332 output
.Delete(pos1
, pos2
- pos1
);
3333 output
.Insert(pos1
, static_cast<LPCWSTR
>(CLoglistUtils::FormatDateAndTime(CTime(number
), m_DateFormat
, true, m_bRelativeTimes
)));
3335 output
.Trim().AppendChar(L
'\n');
3341 void CGitLogListBase::Clear()
3343 m_arShownList
.SafeRemoveAll();
3346 m_logEntries
.ClearAll();
3349 void CGitLogListBase::OnDestroy()
3351 SafeTerminateThread();
3352 SafeTerminateAsyncDiffThread();
3355 while(m_LogCache
.SaveCache())
3363 //if(CMessageBox::Show(nullptr, L"Cannot Save Log Cache to Disk. To retry click yes. To give up click no.", L"TortoiseGit",
3364 // MB_YESNO) == IDNO)
3368 __super::OnDestroy();
3371 LRESULT
CGitLogListBase::OnLoad(WPARAM wParam
,LPARAM
/*lParam*/)
3374 int i
= static_cast<int>(wParam
);
3375 this->GetItemRect(i
,&rect
,LVIR_BOUNDS
);
3376 this->InvalidateRect(rect
);
3382 * Save column widths to the registry
3384 void CGitLogListBase::SaveColumnWidths()
3386 // HACK that graph column is always shown
3387 SetColumnWidth(0, m_ColumnManager
.GetWidth(0, false));
3389 __super::SaveColumnWidths();
3392 int CGitLogListBase::GetHeadIndex()
3394 if(m_HeadHash
.IsEmpty())
3397 for (size_t i
= 0; i
< m_arShownList
.size(); ++i
)
3399 GitRev
* pRev
= m_arShownList
.SafeGetAt(i
);
3402 if (pRev
->m_CommitHash
== m_HeadHash
)
3403 return static_cast<int>(i
);
3408 void CGitLogListBase::OnFind()
3412 m_pFindDialog
= new CFindDlg(this);
3413 m_pFindDialog
->Create(this);
3417 m_pFindDialog
->SetFocus();
3422 LRESULT
CGitLogListBase::OnScrollToMessage(WPARAM itemToSelect
, LPARAM
/*lParam*/)
3424 if (GetSelectedCount() != 0)
3427 CGitHash theSelectedHash
= m_lastSelectedHash
;
3428 SetItemState(static_cast<int>(itemToSelect
), LVIS_SELECTED
| LVIS_FOCUSED
, LVIS_SELECTED
| LVIS_FOCUSED
);
3429 m_lastSelectedHash
= theSelectedHash
;
3431 int countPerPage
= GetCountPerPage();
3432 EnsureVisible(max(0, static_cast<int>(itemToSelect
) - countPerPage
/ 2), FALSE
);
3433 EnsureVisible(min(GetItemCount(), static_cast<int>(itemToSelect
) + countPerPage
/ 2), FALSE
);
3434 EnsureVisible(static_cast<int>(itemToSelect
), FALSE
);
3438 LRESULT
CGitLogListBase::OnScrollToRef(WPARAM wParam
, LPARAM
/*lParam*/)
3440 CString
* ref
= reinterpret_cast<CString
*>(wParam
);
3441 if (!ref
|| ref
->IsEmpty())
3444 bool bShift
= (GetAsyncKeyState(VK_SHIFT
) & 0x8000) != 0;
3447 if (g_Git
.GetHash(hash
, *ref
+ L
"^{}")) // add ^{} in order to get the correct SHA-1 (especially for signed tags)
3448 MessageBox(g_Git
.GetGitLastErr(L
"Could not get hash of ref \"" + *ref
+ L
"^{}\"."), L
"TortoiseGit", MB_ICONERROR
);
3453 bool bFound
= false;
3454 int cnt
= static_cast<int>(m_arShownList
.size());
3456 for (i
= 0; i
< cnt
; ++i
)
3458 GitRev
* pLogEntry
= m_arShownList
.SafeGetAt(i
);
3459 if (pLogEntry
&& pLogEntry
->m_CommitHash
== hash
)
3468 EnsureVisible(i
, FALSE
);
3471 SetItemState(GetSelectionMark(), 0, LVIS_SELECTED
);
3472 SetItemState(i
, LVIS_SELECTED
| LVIS_FOCUSED
, LVIS_SELECTED
| LVIS_FOCUSED
);
3473 SetSelectionMark(i
);
3477 GitRev
* pLogEntry
= m_arShownList
.SafeGetAt(i
);
3479 m_highlight
= pLogEntry
->m_CommitHash
;
3487 LRESULT
CGitLogListBase::OnFindDialogMessage(WPARAM
/*wParam*/, LPARAM
/*lParam*/)
3489 ASSERT(m_pFindDialog
);
3490 bool bFound
= false;
3493 if (m_pFindDialog
->IsTerminating())
3495 // invalidate the handle identifying the dialog box.
3496 m_pFindDialog
= nullptr;
3500 int cnt
= static_cast<int>(m_arShownList
.size());
3501 bool bShift
= (GetAsyncKeyState(VK_SHIFT
) & 0x8000) != 0;
3503 if(m_pFindDialog
->IsRef())
3506 str
=m_pFindDialog
->GetFindString();
3512 if (g_Git
.GetHash(hash
, str
+ L
"^{}")) // add ^{} in order to get the correct SHA-1 (especially for signed tags)
3513 MessageBox(g_Git
.GetGitLastErr(L
"Could not get hash of ref \"" + str
+ L
"^{}\"."), L
"TortoiseGit", MB_ICONERROR
);
3518 for (i
= 0; i
< cnt
; ++i
)
3520 GitRev
* pLogEntry
= m_arShownList
.SafeGetAt(i
);
3521 if(pLogEntry
&& pLogEntry
->m_CommitHash
== hash
)
3530 m_pFindDialog
->FlashWindowEx(FLASHW_ALL
, 2, 100);
3535 if (m_pFindDialog
->FindNext() && !bFound
)
3537 //read data from dialog
3538 CLogDlgFilter filter
{ m_pFindDialog
->GetFindString(), m_pFindDialog
->Regex(), LOGFILTER_ALL
, m_pFindDialog
->MatchCase() == TRUE
};
3540 auto hashMapSharedPtr
= m_HashMap
;
3541 auto& hashMap
= *hashMapSharedPtr
;
3543 for (i
= m_nSearchIndex
+ 1; ; ++i
)
3548 m_pFindDialog
->FlashWindowEx(FLASHW_ALL
, 2, 100);
3550 if (m_nSearchIndex
>= 0)
3552 if (i
== m_nSearchIndex
)
3554 ::MessageBeep(0xFFFFFFFF);
3555 m_pFindDialog
->FlashWindowEx(FLASHW_ALL
, 3, 100);
3560 if (filter(m_arShownList
.SafeGetAt(i
), this, hashMap
))
3566 } // if(m_pFindDialog->FindNext())
3571 EnsureVisible(i
, FALSE
);
3574 SetItemState(GetSelectionMark(), 0, LVIS_SELECTED
);
3575 SetItemState(i
, LVIS_SELECTED
| LVIS_FOCUSED
, LVIS_SELECTED
| LVIS_FOCUSED
);
3576 SetSelectionMark(i
);
3580 GitRev
* pLogEntry
= m_arShownList
.SafeGetAt(i
);
3582 m_highlight
= pLogEntry
->m_CommitHash
;
3585 //FillLogMessageCtrl();
3592 INT_PTR
CGitLogListBase::OnToolHitTest(CPoint point
, TOOLINFO
* pTI
) const
3594 LVHITTESTINFO lvhitTestInfo
;
3596 lvhitTestInfo
.pt
= point
;
3598 int nItem
= ListView_SubItemHitTest(m_hWnd
, &lvhitTestInfo
);
3599 int nSubItem
= lvhitTestInfo
.iSubItem
;
3601 UINT nFlags
= lvhitTestInfo
.flags
;
3603 // nFlags is 0 if the SubItemHitTest fails
3604 // Therefore, 0 & <anything> will equal false
3605 if (nFlags
& LVHT_ONITEM
)
3607 // Get the client area occupied by this control
3609 GetClientRect(&rcClient
);
3611 // Fill in the TOOLINFO structure
3613 pTI
->uId
= static_cast<UINT
>((nItem
<< 10) + (nSubItem
& 0x3ff) + 1);
3614 pTI
->lpszText
= LPSTR_TEXTCALLBACK
;
3615 pTI
->rect
= rcClient
;
3617 return pTI
->uId
; // By returning a unique value per listItem,
3618 // we ensure that when the mouse moves over another list item,
3619 // the tooltip will change
3623 // Otherwise, we aren't interested, so let the message propagate
3628 BOOL
CGitLogListBase::OnToolTipText(UINT
/*id*/, NMHDR
* pNMHDR
, LRESULT
* pResult
)
3630 auto pTTTA
= reinterpret_cast<TOOLTIPTEXTA
*>(pNMHDR
);
3631 auto pTTTW
= reinterpret_cast<TOOLTIPTEXTW
*>(pNMHDR
);
3635 // Ignore messages from the built in tooltip, we are processing them internally
3636 if ((pNMHDR
->idFrom
== reinterpret_cast<UINT_PTR
>(m_hWnd
)) &&
3637 (((pNMHDR
->code
== TTN_NEEDTEXTA
) && (pTTTA
->uFlags
& TTF_IDISHWND
)) ||
3638 ((pNMHDR
->code
== TTN_NEEDTEXTW
) && (pTTTW
->uFlags
& TTF_IDISHWND
))))
3641 // Get the mouse position
3642 const MSG
* pMessage
= GetCurrentMessage();
3646 ScreenToClient(&pt
);
3648 // Check if the point falls onto a list item
3649 LVHITTESTINFO lvhitTestInfo
;
3650 lvhitTestInfo
.pt
= pt
;
3652 int nItem
= SubItemHitTest(&lvhitTestInfo
);
3654 if (lvhitTestInfo
.flags
& LVHT_ONITEM
)
3656 // Get branch description first
3658 if (lvhitTestInfo
.iSubItem
== LOGLIST_MESSAGE
)
3661 CGit::REF_TYPE type
= CGit::REF_TYPE::LOCAL_BRANCH
;
3662 auto hashMap
= m_HashMap
;
3663 if (IsMouseOnRefLabel(m_arShownList
.SafeGetAt(nItem
), lvhitTestInfo
.pt
, type
, *hashMap
.get(), &branch
))
3665 MAP_STRING_STRING descriptions
;
3666 g_Git
.GetBranchDescriptions(descriptions
);
3667 if (descriptions
.find(branch
) != descriptions
.cend())
3669 strTipText
.LoadString(IDS_DESCRIPTION
);
3670 strTipText
+= L
":\n";
3671 strTipText
+= descriptions
[branch
];
3676 bool followMousePos
= false;
3677 if (!strTipText
.IsEmpty())
3678 followMousePos
= true;
3680 strTipText
= GetToolTipText(nItem
, lvhitTestInfo
.iSubItem
);
3681 if (strTipText
.IsEmpty())
3684 // we want multiline tooltips
3685 ::SendMessage(pNMHDR
->hwndFrom
, TTM_SETMAXTIPWIDTH
, 0, SHRT_MAX
);
3687 if (strTipText
.GetLength() >= _countof(m_wszTip
))
3689 strTipText
.Truncate(_countof(m_wszTip
) - 1 - 3);
3690 strTipText
+= L
"...";
3692 wcsncpy_s(m_wszTip
, strTipText
, _TRUNCATE
);
3693 // handle Unicode as well as non-Unicode requests
3694 if (pNMHDR
->code
== TTN_NEEDTEXTA
)
3696 pTTTA
->hinst
= nullptr;
3697 pTTTA
->lpszText
= m_szTip
;
3698 ::WideCharToMultiByte(CP_ACP
, 0, m_wszTip
, -1, m_szTip
, 8192, nullptr, nullptr);
3702 pTTTW
->hinst
= nullptr;
3703 pTTTW
->lpszText
= m_wszTip
;
3707 GetSubItemRect(nItem
, lvhitTestInfo
.iSubItem
, LVIR_LABEL
, rect
);
3709 rect
.MoveToXY(pt
.x
, pt
.y
+ CDPIAware::Instance().ScaleY(18)); // 18: to act like a normal tooltip
3710 ClientToScreen(rect
);
3711 ::SetWindowPos(pNMHDR
->hwndFrom
, HWND_TOP
, rect
.left
, rect
.top
, 0, 0, SWP_NOACTIVATE
|SWP_NOSIZE
|SWP_NOOWNERZORDER
);
3713 return TRUE
; // We found a tool tip,
3714 // tell the framework this message has been handled
3717 return FALSE
; // We didn't handle the message,
3718 // let the framework continue propagating the message
3721 CString
CGitLogListBase::GetToolTipText(int nItem
, int nSubItem
)
3723 if (nSubItem
== LOGLIST_MESSAGE
&& !m_bTagsBranchesOnRightSide
)
3725 GitRevLoglist
* pLogEntry
= m_arShownList
.SafeGetAt(nItem
);
3726 if (pLogEntry
== nullptr)
3728 auto hashMap
= m_HashMap
;
3729 if (hashMap
->find(pLogEntry
->m_CommitHash
) == hashMap
->cend() && (m_superProjectHash
.IsEmpty() || pLogEntry
->m_CommitHash
!= m_superProjectHash
))
3731 return pLogEntry
->GetSubject();
3733 else if (nSubItem
== LOGLIST_DATE
&& m_bRelativeTimes
)
3735 GitRevLoglist
* pLogEntry
= m_arShownList
.SafeGetAt(nItem
);
3736 if (pLogEntry
== nullptr)
3738 return CLoglistUtils::FormatDateAndTime(pLogEntry
->GetAuthorDate(), m_DateFormat
, true, false);
3740 else if (nSubItem
== LOGLIST_COMMIT_DATE
&& m_bRelativeTimes
)
3742 GitRevLoglist
* pLogEntry
= m_arShownList
.SafeGetAt(nItem
);
3743 if (pLogEntry
== nullptr)
3745 return CLoglistUtils::FormatDateAndTime(pLogEntry
->GetCommitterDate(), m_DateFormat
, true, false);
3747 else if (nSubItem
== LOGLIST_ACTION
)
3749 GitRevLoglist
* pLogEntry
= m_arShownList
.SafeGetAt(nItem
);
3750 if (pLogEntry
== nullptr)
3753 int actions
= pLogEntry
->GetAction(this);
3754 if (!pLogEntry
->m_IsDiffFiles
)
3755 return CString(MAKEINTRESOURCE(IDS_PROC_LOG_FETCHINGFILES
));
3758 if (actions
& CTGitPath::LOGACTIONS_MODIFIED
)
3759 actionText
+= CTGitPath::GetActionName(CTGitPath::LOGACTIONS_MODIFIED
);
3761 if (actions
& CTGitPath::LOGACTIONS_ADDED
)
3763 if (!actionText
.IsEmpty())
3764 actionText
+= L
"\r\n";
3765 actionText
+= CTGitPath::GetActionName(CTGitPath::LOGACTIONS_ADDED
);
3768 if (actions
& CTGitPath::LOGACTIONS_DELETED
)
3770 if (!actionText
.IsEmpty())
3771 actionText
+= L
"\r\n";
3772 actionText
+= CTGitPath::GetActionName(CTGitPath::LOGACTIONS_DELETED
);
3775 if (actions
& CTGitPath::LOGACTIONS_REPLACED
)
3777 if (!actionText
.IsEmpty())
3778 actionText
+= L
"\r\n";
3779 actionText
+= CTGitPath::GetActionName(CTGitPath::LOGACTIONS_REPLACED
);
3782 if (actions
& CTGitPath::LOGACTIONS_UNMERGED
)
3784 if (!actionText
.IsEmpty())
3785 actionText
+= L
"\r\n";
3786 actionText
+= CTGitPath::GetActionName(CTGitPath::LOGACTIONS_UNMERGED
);
3789 if (!actionText
.IsEmpty())
3791 CString
sTitle(MAKEINTRESOURCE(IDS_LOG_ACTIONS
));
3792 return sTitle
+ L
":\r\n" + actionText
;
3798 bool CGitLogListBase::IsMouseOnRefLabelFromPopupMenu(const GitRevLoglist
* pLogEntry
, const CPoint
& point
, CGit::REF_TYPE
& type
, const MAP_HASH_NAME
& hashMap
, CString
* pShortname
/*nullptr*/, size_t* pIndex
/*nullptr*/)
3801 ScreenToClient(&pt
);
3802 return IsMouseOnRefLabel(pLogEntry
, pt
, type
, hashMap
, pShortname
, pIndex
);
3805 bool CGitLogListBase::IsMouseOnRefLabel(const GitRevLoglist
* pLogEntry
, const POINT
& pt
, CGit::REF_TYPE
& type
, const MAP_HASH_NAME
& hashMap
, CString
* pShortname
/*nullptr*/, size_t* pIndex
/*nullptr*/)
3810 auto refList
= hashMap
.find(pLogEntry
->m_CommitHash
);
3811 if (refList
== hashMap
.cend())
3814 for (size_t i
= 0; i
< refList
->second
.size(); ++i
)
3816 const auto labelpos
= m_RefLabelPosMap
.find(refList
->second
[i
]);
3817 if (labelpos
== m_RefLabelPosMap
.cend() || !labelpos
->second
.PtInRect(pt
))
3820 CGit::REF_TYPE foundType
;
3822 *pShortname
= CGit::GetShortName(refList
->second
[i
], &foundType
);
3824 CGit::GetShortName(refList
->second
[i
], &foundType
);
3825 if (foundType
!= type
&& type
!= CGit::REF_TYPE::UNKNOWN
)
3836 void CGitLogListBase::OnBeginDrag(NMHDR
* /*pnmhdr*/, LRESULT
* pResult
)
3840 if (!m_bDragndropEnabled
|| GetSelectedCount() == 0 || !IsSelectionContinuous())
3845 m_nDropMarkerLast
= -1;
3846 m_nDropMarkerLastHot
= GetHotItem();
3850 void CGitLogListBase::OnMouseMove(UINT nFlags
, CPoint point
)
3852 __super::OnMouseMove(nFlags
, point
);
3857 CPoint dropPoint
= point
;
3858 ClientToScreen(&dropPoint
);
3860 if (WindowFromPoint(dropPoint
) != this)
3862 SetCursor(LoadCursor(nullptr, IDC_NO
));
3864 DrawDropInsertMarker(m_nDropIndex
);
3868 SetCursor(LoadCursor(nullptr, IDC_ARROW
));
3869 ScreenToClient(&dropPoint
);
3872 m_nDropIndex
= HitTest(dropPoint
);
3874 if (m_nDropIndex
== -1) // might be last item, allow to move past last item
3877 m_nDropIndex
= HitTest(dropPoint
);
3878 if (m_nDropIndex
!= -1)
3879 m_nDropIndex
= GetItemCount();
3882 POSITION pos
= GetFirstSelectedItemPosition();
3883 int first
= GetNextSelectedItem(pos
);
3886 last
= GetNextSelectedItem(pos
);
3887 if (m_nDropIndex
== -1 || (m_nDropIndex
>= first
&& m_nDropIndex
- 1 <= last
))
3889 SetCursor(LoadCursor(nullptr, IDC_NO
));
3893 // handle auto scrolling
3894 int hotItem
= GetHotItem();
3895 int topindex
= GetTopIndex();
3896 if (hotItem
== topindex
&& hotItem
!= 0)
3897 EnsureVisible(hotItem
- 1, FALSE
);
3898 else if (hotItem
>= topindex
+ GetCountPerPage() - 1 && hotItem
+ 1 < GetItemCount())
3899 EnsureVisible(hotItem
+ 1, FALSE
);
3901 DrawDropInsertMarker(m_nDropIndex
);
3904 void CGitLogListBase::OnLButtonUp(UINT nFlags
, CPoint point
)
3909 SetCursor(LoadCursor(nullptr, IDC_HAND
));
3910 m_bDragging
= FALSE
;
3913 GetItemRect(m_nDropMarkerLast
, &rect
, 0);
3914 rect
.bottom
= rect
.top
+ 2;
3916 InvalidateRect(&rect
, 0);
3919 ClientToScreen(&pt
);
3920 if (WindowFromPoint(pt
) == this && m_nDropIndex
!= -1)
3921 GetParent()->PostMessage(MSG_COMMITS_REORDERED
, m_nDropIndex
, 0);
3924 __super::OnLButtonUp(nFlags
, point
);
3927 void CGitLogListBase::DrawDropInsertMarker(int nIndex
)
3929 if (m_nDropMarkerLast
!= nIndex
)
3932 if (GetItemRect(m_nDropMarkerLast
, &rect
, 0))
3934 rect
.bottom
= rect
.top
+ 2;
3936 InvalidateRect(&rect
, 0);
3938 else if (m_nDropMarkerLast
== GetItemCount())
3939 DrawDropInsertMarkerLine(m_nDropMarkerLast
); // double painting = removal
3940 m_nDropMarkerLast
= nIndex
;
3945 DrawDropInsertMarkerLine(m_nDropMarkerLast
);
3947 else if (m_nDropMarkerLastHot
!= GetHotItem())
3949 m_nDropMarkerLastHot
= GetHotItem();
3950 m_nDropMarkerLast
= -1;
3954 void CGitLogListBase::DrawDropInsertMarkerLine(int nIndex
)
3956 CBrush
* pBrush
= CDC::GetHalftoneBrush();
3960 if (nIndex
< GetItemCount())
3962 GetItemRect(nIndex
, &rect
, 0);
3963 rect
.bottom
= rect
.top
+ 2;
3968 GetItemRect(nIndex
- 1, &rect
, 0);
3969 rect
.top
= rect
.bottom
- 2;
3973 CBrush
* pBrushOld
= pDC
->SelectObject(pBrush
);
3974 pDC
->PatBlt(rect
.left
, rect
.top
, rect
.Width(), rect
.Height(), PATINVERT
);
3975 pDC
->SelectObject(pBrushOld
);
3980 ULONG
CGitLogListBase::GetGestureStatus(CPoint
/*ptTouch*/)
3985 void CGitLogListBase::DrawListItemWithMatchesRect(NMLVCUSTOMDRAW
* pLVCD
, const std::vector
<CHARRANGE
>& ranges
, CRect rect
, const CString
& text
, CColors
& colors
, HTHEME hTheme
/*= nullptr*/, int txtState
/*= 0*/)
3988 COLORREF textColor
= pLVCD
->clrText
;
3992 ::SetTextColor(pLVCD
->nmcd
.hdc
, textColor
);
3993 SetBkMode(pLVCD
->nmcd
.hdc
, TRANSPARENT
);
3995 DTTOPTS opts
= { 0 };
3996 opts
.dwSize
= sizeof(opts
);
3997 opts
.crText
= textColor
;
3998 opts
.dwFlags
= DTT_TEXTCOLOR
;
4000 for (auto it
= ranges
.cbegin(); it
!= ranges
.cend(); ++it
)
4003 if (it
->cpMin
- drawPos
)
4007 DrawText(pLVCD
->nmcd
.hdc
, text
.Mid(drawPos
), it
->cpMin
- drawPos
, &rc
, DT_SINGLELINE
| DT_VCENTER
| DT_NOPREFIX
| DT_END_ELLIPSIS
);
4008 DrawText(pLVCD
->nmcd
.hdc
, text
.Mid(drawPos
), it
->cpMin
- drawPos
, &rc
, DT_CALCRECT
| DT_SINGLELINE
| DT_VCENTER
| DT_NOPREFIX
| DT_END_ELLIPSIS
);
4012 DrawThemeTextEx(hTheme
, pLVCD
->nmcd
.hdc
, LVP_LISTITEM
, txtState
, text
.Mid(drawPos
), it
->cpMin
- drawPos
, DT_SINGLELINE
| DT_VCENTER
| DT_NOPREFIX
| DT_END_ELLIPSIS
, &rc
, &opts
);
4013 GetThemeTextExtent(hTheme
, pLVCD
->nmcd
.hdc
, LVP_LISTITEM
, txtState
, text
.Mid(drawPos
), it
->cpMin
- drawPos
, DT_CALCRECT
| DT_SINGLELINE
| DT_VCENTER
| DT_NOPREFIX
| DT_END_ELLIPSIS
, &rect
, &rc
);
4015 rect
.left
= rc
.right
;
4018 drawPos
= it
->cpMin
;
4019 if (it
->cpMax
- drawPos
)
4023 ::SetTextColor(pLVCD
->nmcd
.hdc
, CTheme::Instance().GetThemeColor(colors
.GetColor(CColors::FilterMatch
), true));
4024 DrawText(pLVCD
->nmcd
.hdc
, text
.Mid(drawPos
), it
->cpMax
- drawPos
, &rc
, DT_SINGLELINE
| DT_VCENTER
| DT_NOPREFIX
| DT_END_ELLIPSIS
);
4025 DrawText(pLVCD
->nmcd
.hdc
, text
.Mid(drawPos
), it
->cpMax
- drawPos
, &rc
, DT_CALCRECT
| DT_SINGLELINE
| DT_VCENTER
| DT_NOPREFIX
| DT_END_ELLIPSIS
);
4026 ::SetTextColor(pLVCD
->nmcd
.hdc
, textColor
);
4030 opts
.crText
= CTheme::Instance().GetThemeColor(colors
.GetColor(CColors::FilterMatch
), true);
4031 DrawThemeTextEx(hTheme
, pLVCD
->nmcd
.hdc
, LVP_LISTITEM
, txtState
, text
.Mid(drawPos
), it
->cpMax
- drawPos
, DT_SINGLELINE
| DT_VCENTER
| DT_NOPREFIX
| DT_END_ELLIPSIS
, &rc
, &opts
);
4032 GetThemeTextExtent(hTheme
, pLVCD
->nmcd
.hdc
, LVP_LISTITEM
, txtState
, text
.Mid(drawPos
), it
->cpMax
- drawPos
, DT_CALCRECT
| DT_SINGLELINE
| DT_VCENTER
| DT_NOPREFIX
| DT_END_ELLIPSIS
, &rect
, &rc
);
4033 opts
.crText
= textColor
;
4035 rect
.left
= rc
.right
;
4038 drawPos
= it
->cpMax
;
4041 DrawText(pLVCD
->nmcd
.hdc
, text
.Mid(drawPos
), -1, &rc
, DT_SINGLELINE
| DT_VCENTER
| DT_NOPREFIX
| DT_END_ELLIPSIS
);
4043 DrawThemeTextEx(hTheme
, pLVCD
->nmcd
.hdc
, LVP_LISTITEM
, txtState
, text
.Mid(drawPos
), -1, DT_SINGLELINE
| DT_VCENTER
| DT_NOPREFIX
| DT_END_ELLIPSIS
, &rc
, &opts
);
4046 bool CGitLogListBase::DrawListItemWithMatchesIfEnabled(std::shared_ptr
<CLogDlgFilter
> filter
, DWORD selectedFilter
, NMLVCUSTOMDRAW
* pLVCD
, LRESULT
* pResult
)
4048 if ((filter
->GetSelectedFilters() & selectedFilter
) && filter
->IsFilterActive())
4051 GetSubItemRect(static_cast<int>(pLVCD
->nmcd
.dwItemSpec
), pLVCD
->iSubItem
, LVIR_BOUNDS
, rect
);
4053 int index
= static_cast<int>(pLVCD
->nmcd
.dwItemSpec
);
4054 int state
= GetItemState(index
, LVIS_SELECTED
);
4055 int txtState
= LISS_NORMAL
;
4056 if (IsAppThemed() && GetHotItem() == static_cast<int>(index
))
4058 if (state
& LVIS_SELECTED
)
4059 txtState
= LISS_HOTSELECTED
;
4061 txtState
= LISS_HOT
;
4063 else if (state
& LVIS_SELECTED
)
4065 if (::GetFocus() == m_hWnd
)
4066 txtState
= LISS_SELECTED
;
4068 txtState
= LISS_SELECTEDNOTFOCUS
;
4071 CAutoThemeData hTheme
;
4074 hTheme
= OpenThemeData(m_hWnd
, L
"Explorer::ListView;ListView");
4076 // make sure the column separator/border is not overpainted
4077 int borderWidth
= 0;
4078 GetThemeMetric(hTheme
, pLVCD
->nmcd
.hdc
, LVP_LISTITEM
, LISS_NORMAL
, TMT_BORDERSIZE
, &borderWidth
);
4079 InflateRect(&rect
, -(2 * borderWidth
), 0);
4082 if (hTheme
&& IsThemeBackgroundPartiallyTransparent(hTheme
, LVP_LISTDETAIL
, txtState
))
4083 DrawThemeParentBackground(m_hWnd
, pLVCD
->nmcd
.hdc
, &rect
);
4086 HBRUSH brush
= ::CreateSolidBrush(pLVCD
->clrTextBk
);
4087 ::FillRect(pLVCD
->nmcd
.hdc
, rect
, brush
);
4088 ::DeleteObject(brush
);
4090 if (hTheme
&& txtState
!= LISS_NORMAL
)
4093 // get rect of whole line
4094 GetItemRect(index
, rt
, LVIR_BOUNDS
);
4097 // calculate background for rect of whole line, but limit redrawing to SubItem rect
4098 DrawThemeBackground(hTheme
, pLVCD
->nmcd
.hdc
, LVP_LISTITEM
, txtState
, rt
, rect2
);
4100 hTheme
.CloseHandle();
4101 // END: extended redraw
4103 FillBackGround(pLVCD
->nmcd
.hdc
, pLVCD
->nmcd
.dwItemSpec
, rect
);
4106 *pResult
= DrawListItemWithMatches(filter
.get(), *this, pLVCD
, m_Colors
);
4112 LRESULT
CGitLogListBase::DrawListItemWithMatches(CFilterHelper
* filter
, CListCtrl
& listCtrl
, NMLVCUSTOMDRAW
* pLVCD
, CColors
& colors
)
4114 CString text
= static_cast<LPCWSTR
>(listCtrl
.GetItemText(static_cast<int>(pLVCD
->nmcd
.dwItemSpec
), pLVCD
->iSubItem
));
4116 return CDRF_DODEFAULT
;
4118 std::vector
<CHARRANGE
> ranges
;
4119 filter
->GetMatchRanges(ranges
, text
, 0);
4121 return CDRF_DODEFAULT
;
4123 // even though we initialize the 'rect' here with nmcd.rc,
4124 // we must not use it but use the rects from GetItemRect()
4125 // and GetSubItemRect(). Because on XP, the nmcd.rc has
4126 // bogus data in it.
4127 CRect rect
= pLVCD
->nmcd
.rc
;
4129 // find the margin where the text label starts
4130 CRect labelRC
, boundsRC
, iconRC
;
4131 listCtrl
.GetItemRect(static_cast<int>(pLVCD
->nmcd
.dwItemSpec
), &labelRC
, LVIR_LABEL
);
4132 listCtrl
.GetItemRect(static_cast<int>(pLVCD
->nmcd
.dwItemSpec
), &iconRC
, LVIR_ICON
);
4133 listCtrl
.GetItemRect(static_cast<int>(pLVCD
->nmcd
.dwItemSpec
), &boundsRC
, LVIR_BOUNDS
);
4135 int leftmargin
= labelRC
.left
- boundsRC
.left
;
4136 if (pLVCD
->iSubItem
)
4137 leftmargin
-= iconRC
.Width();
4139 if (pLVCD
->iSubItem
!= 0)
4140 listCtrl
.GetSubItemRect(static_cast<int>(pLVCD
->nmcd
.dwItemSpec
), pLVCD
->iSubItem
, LVIR_BOUNDS
, rect
);
4142 int borderWidth
= 0;
4143 CAutoThemeData hTheme
;
4146 hTheme
= OpenThemeData(listCtrl
.m_hWnd
, L
"Explorer::ListView;ListView");
4147 GetThemeMetric(hTheme
, pLVCD
->nmcd
.hdc
, LVP_LISTITEM
, LISS_NORMAL
, TMT_BORDERSIZE
, &borderWidth
);
4150 borderWidth
= GetSystemMetrics(SM_CXBORDER
);
4152 if (listCtrl
.GetExtendedStyle() & LVS_EX_CHECKBOXES
)
4154 // I'm not very happy about this fixed margin here
4155 // but I haven't found a way to ask the system what
4156 // the margin really is.
4157 // At least it works on XP/Vista/win7/win8, and even with
4158 // increased font sizes
4162 LVITEM item
= { 0 };
4163 item
.iItem
= static_cast<int>(pLVCD
->nmcd
.dwItemSpec
);
4165 item
.mask
= LVIF_IMAGE
| LVIF_STATE
;
4166 item
.stateMask
= static_cast<UINT
>(-1);
4167 listCtrl
.GetItem(&item
);
4170 int txtState
= LISS_NORMAL
;
4173 HBRUSH brush
= nullptr;
4174 if (item
.state
& LVIS_SELECTED
)
4176 if (::GetFocus() == listCtrl
.GetSafeHwnd())
4178 brush
= ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT
));
4179 pLVCD
->clrText
= ::GetSysColor(COLOR_HIGHLIGHTTEXT
);
4183 brush
= ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE
));
4184 pLVCD
->clrText
= CTheme::Instance().IsDarkTheme() ? CTheme::darkTextColor
: GetSysColor(COLOR_WINDOWTEXT
);
4189 brush
= ::CreateSolidBrush(::GetSysColor(COLOR_WINDOW
));
4191 listCtrl
.GetSubItemRect(static_cast<int>(pLVCD
->nmcd
.dwItemSpec
), pLVCD
->iSubItem
, LVIR_LABEL
, my
);
4192 ::FillRect(pLVCD
->nmcd
.hdc
, my
, brush
);
4193 ::DeleteObject(brush
);
4197 if (listCtrl
.GetHotItem() == static_cast<int>(pLVCD
->nmcd
.dwItemSpec
))
4199 if (item
.state
& LVIS_SELECTED
)
4200 txtState
= LISS_HOTSELECTED
;
4202 txtState
= LISS_HOT
;
4204 else if (item
.state
& LVIS_SELECTED
)
4206 if (::GetFocus() == listCtrl
.GetSafeHwnd())
4207 txtState
= LISS_SELECTED
;
4209 txtState
= LISS_SELECTEDNOTFOCUS
;
4212 if (IsThemeBackgroundPartiallyTransparent(hTheme
, LVP_LISTDETAIL
, txtState
))
4213 DrawThemeParentBackground(listCtrl
.m_hWnd
, pLVCD
->nmcd
.hdc
, &rect
);
4216 HBRUSH brush
= ::CreateSolidBrush(pLVCD
->clrTextBk
);
4217 ::FillRect(pLVCD
->nmcd
.hdc
, rect
, brush
);
4218 ::DeleteObject(brush
);
4220 if (txtState
!= LISS_NORMAL
)
4223 listCtrl
.GetSubItemRect(static_cast<int>(pLVCD
->nmcd
.dwItemSpec
), pLVCD
->iSubItem
, LVIR_LABEL
, my
);
4224 if (pLVCD
->iSubItem
== 0)
4226 // also fill the icon part of the line
4231 // calculate background for rect of whole line, but limit redrawing to SubItem rect
4232 DrawThemeBackground(hTheme
, pLVCD
->nmcd
.hdc
, LVP_LISTITEM
, txtState
, boundsRC
, my
);
4236 // draw the icon for the first column
4237 if (pLVCD
->iSubItem
== 0)
4240 rect
.right
= rect
.left
+ listCtrl
.GetColumnWidth(0);
4241 rect
.left
= iconRC
.left
;
4243 if (item
.iImage
>= 0)
4249 dc
.Attach(pLVCD
->nmcd
.hdc
);
4250 int style
= ILD_TRANSPARENT
;
4253 auto whitebrush
= ::CreateSolidBrush(::GetSysColor(COLOR_WINDOW
));
4254 ::FillRect(dc
, iconRC
, whitebrush
);
4255 ::DeleteObject(whitebrush
);
4256 if (item
.state
& LVIS_SELECTED
)
4258 if (::GetFocus() == listCtrl
.GetSafeHwnd())
4259 style
= ILD_SELECTED
;
4264 listCtrl
.GetImageList(LVSIL_SMALL
)->Draw(&dc
, item
.iImage
, pt
, style
);
4266 leftmargin
-= iconRC
.left
;
4270 RECT irc
= boundsRC
;
4271 irc
.left
+= borderWidth
;
4272 irc
.right
= iconRC
.left
;
4275 if (item
.state
& LVIS_SELECTED
)
4277 if (listCtrl
.GetHotItem() == item
.iItem
)
4278 state
= CBS_CHECKEDHOT
;
4280 state
= CBS_CHECKEDNORMAL
;
4284 if (listCtrl
.GetHotItem() == item
.iItem
)
4285 state
= CBS_UNCHECKEDHOT
;
4287 if ((state
) && (listCtrl
.GetExtendedStyle() & LVS_EX_CHECKBOXES
))
4289 CAutoThemeData hTheme2
= OpenThemeData(listCtrl
.m_hWnd
, L
"BUTTON");
4290 DrawThemeBackground(hTheme2
, pLVCD
->nmcd
.hdc
, BP_CHECKBOX
, state
, &irc
, NULL
);
4294 InflateRect(&rect
, -(2 * borderWidth
), 0);
4296 rect
.left
+= leftmargin
;
4299 // is the column left- or right-aligned? (we don't handle centered (yet))
4301 Column
.mask
= LVCF_FMT
;
4302 listCtrl
.GetColumn(pLVCD
->iSubItem
, &Column
);
4303 if (Column
.fmt
& LVCFMT_RIGHT
)
4305 DrawText(pLVCD
->nmcd
.hdc
, text
, -1, &rc
, DT_CALCRECT
| DT_SINGLELINE
| DT_VCENTER
| DT_NOPREFIX
| DT_END_ELLIPSIS
);
4306 rect
.left
= rect
.right
- (rc
.right
- rc
.left
);
4309 rect
.left
+= 2 * borderWidth
;
4310 rect
.right
+= 2 * borderWidth
;
4314 DrawListItemWithMatchesRect(pLVCD
, ranges
, rect
, text
, colors
, hTheme
, txtState
);
4316 return CDRF_SKIPDEFAULT
;