1
// TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2022 - 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
>())
79 , m_RollUpStates(std::make_shared
<RollUpStateMap
>())
81 // use the default GUI font, create a copy of it and
82 // change the copy to BOLD (leave the rest of the font
87 int cx
= GetSystemMetrics(SM_CXSMICON
);
88 int cy
= GetSystemMetrics(SM_CYSMICON
);
89 m_hModifiedIcon
= CCommonAppUtils::LoadIconEx(IDI_ACTIONMODIFIED
, cx
, cy
);
90 m_hReplacedIcon
= CCommonAppUtils::LoadIconEx(IDI_ACTIONREPLACED
, cx
, cy
);
91 m_hConflictedIcon
= CCommonAppUtils::LoadIconEx(IDI_ACTIONCONFLICTED
, cx
, cy
);
92 m_hAddedIcon
= CCommonAppUtils::LoadIconEx(IDI_ACTIONADDED
, cx
, cy
);
93 m_hDeletedIcon
= CCommonAppUtils::LoadIconEx(IDI_ACTIONDELETED
, cx
, cy
);
94 m_hFetchIcon
= CCommonAppUtils::LoadIconEx(IDI_ACTIONFETCHING
, cx
, cy
);
96 m_Filter
.m_NumberOfLogsScale
= CRegDWORD(L
"Software\\TortoiseGit\\LogDialog\\NumberOfLogsScale", CFilterData::SHOW_NO_LIMIT
);
97 if (m_Filter
.m_NumberOfLogsScale
== CFilterData::SHOW_LAST_SEL_DATE
)
100 key
.Format(L
"Software\\TortoiseGit\\History\\LogDlg_Limits\\%s\\FromDate", static_cast<LPCWSTR
>(g_Git
.m_CurrentDir
));
101 key
.Replace(L
':', L
'_');
102 CString lastSelFromDate
= CRegString(key
);
103 if (lastSelFromDate
.GetLength() == 10)
105 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);
106 m_Filter
.m_From
= static_cast<DWORD
>(time
.GetTime());
109 m_Filter
.m_NumberOfLogs
= CRegDWORD(L
"Software\\TortoiseGit\\LogDialog\\NumberOfLogs", 1);
111 // get short/long datetime setting from registry
112 DWORD RegUseShortDateFormat
= CRegDWORD(L
"Software\\TortoiseGit\\LogDateFormat", TRUE
);
113 if ( RegUseShortDateFormat
)
115 m_DateFormat
= DATE_SHORTDATE
;
119 m_DateFormat
= DATE_LONGDATE
;
121 // get relative time display setting from registry
122 DWORD regRelativeTimes
= CRegDWORD(L
"Software\\TortoiseGit\\RelativeTimes", FALSE
);
123 m_bRelativeTimes
= (regRelativeTimes
!= 0);
125 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_PICK
);
126 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_SQUASH
);
127 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_EDIT
);
128 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_SKIP
);
129 m_ContextMenuMask
&= ~GetContextMenuBit(ID_LOG
);
130 m_ContextMenuMask
&= ~GetContextMenuBit(ID_BLAME
);
131 m_ContextMenuMask
&= ~GetContextMenuBit(ID_BLAMEPREVIOUS
);
133 m_ColumnRegKey
= L
"log";
135 m_bTagsBranchesOnRightSide
= !!CRegDWORD(L
"Software\\TortoiseGit\\DrawTagsBranchesOnRightSide", FALSE
);
136 m_bSymbolizeRefNames
= !!CRegDWORD(L
"Software\\TortoiseGit\\SymbolizeRefNames", FALSE
);
137 m_bIncludeBoundaryCommits
= !!CRegDWORD(L
"Software\\TortoiseGit\\LogIncludeBoundaryCommits", FALSE
);
138 m_bFullCommitMessageOnLogLine
= !!CRegDWORD(L
"Software\\TortoiseGit\\FullCommitMessageOnLogLine", FALSE
);
140 m_LineWidth
= max(1, static_cast<int>(CRegDWORD(L
"Software\\TortoiseGit\\TortoiseProc\\Graph\\LogLineWidth", 2)));
141 m_NodeSize
= max(1, static_cast<int>(CRegDWORD(L
"Software\\TortoiseGit\\TortoiseProc\\Graph\\LogNodeSize", 10)));
143 m_AsyncDiffEvent
= ::CreateEvent(nullptr, FALSE
, TRUE
, nullptr);
144 StartAsyncDiffThread();
147 HWND
CGitLogListBase::GetParentHWND()
149 auto owner
= GetSafeOwner();
151 return GetSafeHwnd();
152 return owner
->GetSafeHwnd();
155 int CGitLogListBase::AsyncDiffThread()
157 while(!m_AsyncThreadExit
)
159 ::WaitForSingleObject(m_AsyncDiffEvent
, INFINITE
);
161 GitRevLoglist
* pRev
= nullptr;
162 while(!m_AsyncThreadExit
&& !m_AsynDiffList
.empty())
164 m_AsynDiffListLock
.Lock();
165 pRev
= m_AsynDiffList
.back();
166 m_AsynDiffList
.pop_back();
167 m_AsynDiffListLock
.Unlock();
169 if( pRev
->m_CommitHash
.IsEmpty() )
171 if(pRev
->m_IsDiffFiles
)
174 auto filesWrapper
= pRev
->GetFilesWriter();
175 auto& files
= filesWrapper
.m_files
;
177 pRev
->m_ParentHash
.clear();
178 pRev
->m_ParentHash
.push_back(m_HeadHash
);
179 g_Git
.RefreshGitIndex();
180 g_Git
.GetWorkingTreeChanges(files
, false, nullptr, true); // filtering is done in LogDlg.cpp
181 auto& action
= pRev
->GetAction(this);
183 for (int j
= 0; j
< files
.GetCount(); ++j
)
184 action
|= files
[j
].m_Action
;
186 if (CString err
; pRev
->GetUnRevFiles().FillUnRev(CTGitPath::LOGACTIONS_UNVER
, nullptr, &err
))
188 MessageBox(L
"Failed to get UnRev file list\n" + err
, L
"TortoiseGit", MB_OK
| MB_ICONERROR
);
189 InterlockedExchange(&m_AsyncThreadRunning
, FALSE
);
193 InterlockedExchange(&pRev
->m_IsDiffFiles
, TRUE
);
195 CString body
= L
"\n";
196 body
.AppendFormat(IDS_FILESCHANGES
, files
.GetCount());
197 pRev
->GetBody() = body
;
198 ::PostMessage(m_hWnd
, MSG_LOADED
, 0, 0);
199 this->GetParent()->PostMessage(WM_COMMAND
, MSG_FETCHED_DIFF
, 0);
203 if (!pRev
->CheckAndDiff())
204 { // fetch change file list
205 for (int i
= GetTopIndex(); !m_AsyncThreadExit
&& i
<= GetTopIndex() + GetCountPerPage(); ++i
)
207 if (i
< static_cast<int>(m_arShownList
.size()))
209 GitRevLoglist
* data
= m_arShownList
.SafeGetAt(i
);
210 if(data
->m_CommitHash
== pRev
->m_CommitHash
)
212 ::PostMessage(m_hWnd
, MSG_LOADED
, i
, 0);
218 if(!m_AsyncThreadExit
&& GetSelectedCount() == 1)
220 POSITION pos
= GetFirstSelectedItemPosition();
221 int nItem
= GetNextSelectedItem(pos
);
225 GitRevLoglist
* data
= m_arShownList
.SafeGetAt(nItem
);
227 if(data
->m_CommitHash
== pRev
->m_CommitHash
)
228 this->GetParent()->PostMessage(WM_COMMAND
, MSG_FETCHED_DIFF
, 0);
234 InterlockedExchange(&m_AsyncThreadRunning
, FALSE
);
237 void CGitLogListBase::hideFromContextMenu(unsigned __int64 hideMask
, bool exclusivelyShow
)
240 m_ContextMenuMask
&= hideMask
;
242 m_ContextMenuMask
&= ~hideMask
;
245 CGitLogListBase::~CGitLogListBase()
247 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
248 this->m_arShownList
.SafeRemoveAll();
250 m_logEntries
.ClearAll();
252 SafeTerminateThread();
253 SafeTerminateAsyncDiffThread();
256 CloseHandle(m_AsyncDiffEvent
);
260 BEGIN_MESSAGE_MAP(CGitLogListBase
, CHintCtrl
<CResizableColumnsListCtrl
<CListCtrl
>>)
261 ON_REGISTERED_MESSAGE(m_FindDialogMessage
, OnFindDialogMessage
)
262 ON_REGISTERED_MESSAGE(m_ScrollToMessage
, OnScrollToMessage
)
263 ON_REGISTERED_MESSAGE(m_ScrollToRef
, OnScrollToRef
)
264 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW
, OnNMCustomdrawLoglist
)
265 ON_NOTIFY_REFLECT(LVN_GETDISPINFO
, OnLvnGetdispinfoLoglist
)
267 ON_NOTIFY_REFLECT(NM_DBLCLK
, OnNMDblclkLoglist
)
268 ON_NOTIFY_REFLECT(LVN_ODFINDITEM
,OnLvnOdfinditemLoglist
)
271 ON_MESSAGE(MSG_LOADED
,OnLoad
)
273 ON_WM_MEASUREITEM_REFLECT()
274 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW
, 0, 0xFFFF, &OnToolTipText
)
275 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA
, 0, 0xFFFF, &OnToolTipText
)
278 ON_NOTIFY_REFLECT(LVN_BEGINDRAG
, OnBeginDrag
)
281 void CGitLogListBase::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct
)
283 //if (m_nRowHeight>0)
284 lpMeasureItemStruct
->itemHeight
= CDPIAware::Instance().ScaleY(50);
287 int CGitLogListBase:: OnCreate(LPCREATESTRUCT lpCreateStruct
)
290 return __super::OnCreate(lpCreateStruct
);
293 void CGitLogListBase::SetStyle()
295 SetExtendedStyle(LVS_EX_INFOTIP
| LVS_EX_DOUBLEBUFFER
| LVS_EX_SUBITEMIMAGES
| LVS_EX_FULLROWSELECT
);
298 void CGitLogListBase::PreSubclassWindow()
301 // load the icons for the action columns
302 // m_Theme.Open(m_hWnd, L"ListView");
303 SetWindowTheme(m_hWnd
, L
"Explorer", nullptr);
304 __super::PreSubclassWindow();
307 CString
CGitLogListBase::GetRebaseActionName(int action
)
309 if (action
& LOGACTIONS_REBASE_EDIT
)
310 return MAKEINTRESOURCE(IDS_PATHACTIONS_EDIT
);
311 if (action
& LOGACTIONS_REBASE_SQUASH
)
312 return MAKEINTRESOURCE(IDS_PATHACTIONS_SQUASH
);
313 if (action
& LOGACTIONS_REBASE_PICK
)
314 return MAKEINTRESOURCE(IDS_PATHACTIONS_PICK
);
315 if (action
& LOGACTIONS_REBASE_SKIP
)
316 return MAKEINTRESOURCE(IDS_PATHACTIONS_SKIP
);
318 return MAKEINTRESOURCE(IDS_PATHACTIONS_UNKNOWN
);
321 void CGitLogListBase::InsertGitColumn()
326 if (CRegDWORD(L
"Software\\TortoiseGit\\LogFontForLogCtrl", FALSE
))
328 CCommonAppUtils::CreateFontForLogs(m_Font
);
332 // use the default font, create a copy of it and
333 // change the copy to BOLD (leave the rest of the font
336 GetFont()->GetLogFont(&lf
);
337 lf
.lfWeight
= FW_BOLD
;
338 m_boldFont
.CreateFontIndirect(&lf
);
339 lf
.lfWeight
= FW_DONTCARE
;
341 m_FontItalics
.CreateFontIndirect(&lf
);
342 lf
.lfWeight
= FW_BOLD
;
343 m_boldItalicsFont
.CreateFontIndirect(&lf
);
345 // only load properties if we have a repository
346 if (GitAdminDir::IsWorkingTreeOrBareRepo(g_Git
.m_CurrentDir
))
347 UpdateProjectProperties();
349 static UINT normal
[] =
361 IDS_LOG_COMMIT_EMAIL
,
367 auto iconItemBorder
= CDPIAware::Instance().ScaleX(ICONITEMBORDER
);
368 auto columnWidth
= CDPIAware::Instance().ScaleX(ICONITEMBORDER
+ 16 * 4);
375 2 * iconItemBorder
+ GetSystemMetrics(SM_CXSMICON
) * 5,
376 CDPIAware::Instance().ScaleX(LOGLIST_MESSAGE_MIN
),
386 m_dwDefaultColumns
= GIT_LOG_GRAPH
|GIT_LOG_ACTIONS
|GIT_LOG_MESSAGE
|GIT_LOG_AUTHOR
|GIT_LOG_DATE
;
388 DWORD hideColumns
= 0;
389 if(this->m_IsRebaseReplaceGraph
)
391 hideColumns
|= GIT_LOG_GRAPH
;
392 m_dwDefaultColumns
|= GIT_LOG_REBASE
;
395 hideColumns
|= GIT_LOG_REBASE
;
397 if(this->m_IsIDReplaceAction
)
399 hideColumns
|= GIT_LOG_ACTIONS
;
400 m_dwDefaultColumns
|= GIT_LOG_ID
;
401 m_dwDefaultColumns
|= GIT_LOG_HASH
;
404 hideColumns
|= GIT_LOG_ID
;
405 if(this->m_bShowBugtraqColumn
)
406 m_dwDefaultColumns
|= GIT_LOGLIST_BUG
;
408 hideColumns
|= GIT_LOGLIST_BUG
;
409 if (CTGitPath(g_Git
.m_CurrentDir
).HasGitSVNDir())
410 m_dwDefaultColumns
|= GIT_LOGLIST_SVNREV
;
412 hideColumns
|= GIT_LOGLIST_SVNREV
;
415 m_ColumnManager
.SetNames(normal
, _countof(normal
));
416 constexpr int columnVersion
= 6; // adjust when changing number/names/etc. of columns
417 m_ColumnManager
.ReadSettings(m_dwDefaultColumns
, hideColumns
, m_ColumnRegKey
+ L
"loglist", columnVersion
, _countof(normal
), with
);
418 m_ColumnManager
.SetRightAlign(LOGLIST_ID
);
420 if (!(hideColumns
& GIT_LOG_ACTIONS
))
422 // Configure fake a imagelist for LogList with 1px width and height = GetSystemMetrics(SM_CYSMICON)
423 // to set the minimum item height: we draw icons in the actions column, but on High-DPI the
424 // display's font height may be less than small icon height.
425 ASSERT((GetStyle() & LVS_SHAREIMAGELISTS
) == 0);
426 HIMAGELIST hImageList
= ImageList_Create(1, GetSystemMetrics(SM_CYSMICON
), 0, 1, 0);
427 ListView_SetImageList(GetSafeHwnd(), hImageList
, LVSIL_SMALL
);
433 void CGitLogListBase::FillBackGround(HDC hdc
, DWORD_PTR Index
, CRect
&rect
)
435 LVITEM rItem
= { 0 };
436 rItem
.mask
= LVIF_STATE
;
437 rItem
.iItem
= static_cast<int>(Index
);
438 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
441 GitRevLoglist
* pLogEntry
= m_arShownList
.SafeGetAt(Index
);
442 HBRUSH brush
= nullptr;
444 if (pLogEntry
&& !(rItem
.state
& LVIS_SELECTED
))
446 int action
= pLogEntry
->GetRebaseAction();
447 if (action
& LOGACTIONS_REBASE_SQUASH
)
448 brush
= ::CreateSolidBrush(RGB(156,156,156));
449 else if (action
& LOGACTIONS_REBASE_EDIT
)
450 brush
= ::CreateSolidBrush(RGB(200,200,128));
452 else if (!IsAppThemed())
454 if (rItem
.state
& LVIS_SELECTED
)
456 if (::GetFocus() == m_hWnd
)
457 brush
= ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT
));
459 brush
= ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE
));
464 ::FillRect(hdc
, &rect
, brush
);
465 ::DeleteObject(brush
);
469 void DrawTrackingRoundRect(HDC hdc
, CRect rect
, HBRUSH brush
, COLORREF darkColor
)
471 POINT point
= { 4, 4 };
473 rt2
.DeflateRect(1, 1);
474 rt2
.OffsetRect(2, 2);
476 HPEN nullPen
= ::CreatePen(PS_NULL
, 0, 0);
477 HPEN oldpen
= static_cast<HPEN
>(::SelectObject(hdc
, nullPen
));
478 HBRUSH darkBrush
= static_cast<HBRUSH
>(::CreateSolidBrush(darkColor
));
479 HBRUSH oldbrush
= static_cast<HBRUSH
>(::SelectObject(hdc
, darkBrush
));
480 ::RoundRect(hdc
, rt2
.left
, rt2
.top
, rt2
.right
, rt2
.bottom
, point
.x
, point
.y
);
482 ::SelectObject(hdc
, brush
);
483 rt2
.OffsetRect(-2, -2);
484 ::RoundRect(hdc
, rt2
.left
, rt2
.top
, rt2
.right
, rt2
.bottom
, point
.x
, point
.y
);
485 ::SelectObject(hdc
, oldbrush
);
486 ::SelectObject(hdc
, oldpen
);
487 ::DeleteObject(nullPen
);
488 ::DeleteObject(darkBrush
);
491 void DrawUpstream(HDC hdc
, CRect rect
, COLORREF color
, int bold
)
493 HPEN pen
= ::CreatePen(PS_SOLID
, bold
, color
);
494 HPEN oldpen
= static_cast<HPEN
>(::SelectObject(hdc
, pen
));
495 ::MoveToEx(hdc
, rect
.left
+ 2 + bold
, rect
.top
+ 2 - bold
, nullptr);
496 ::LineTo(hdc
, rect
.left
+ 2 + bold
, rect
.bottom
+ 1 - bold
);
497 ::MoveToEx(hdc
, rect
.left
+ 3, rect
.top
+ 1, nullptr);
498 ::LineTo(hdc
, rect
.left
, rect
.top
+ 4);
499 ::MoveToEx(hdc
, rect
.left
+ 2 + bold
, rect
.top
+ 1, nullptr);
500 ::LineTo(hdc
, rect
.right
+ 1 + bold
, rect
.top
+ 4);
501 ::MoveToEx(hdc
, rect
.left
+ 1, rect
.top
+ 2 + bold
, nullptr);
502 ::LineTo(hdc
, rect
.right
+ 1 + bold
, rect
.top
+ 2 + bold
);
503 ::SelectObject(hdc
, oldpen
);
507 void CGitLogListBase::DrawTagBranchMessage(NMLVCUSTOMDRAW
* pLVCD
, const CRect
& rect
, INT_PTR index
, const std::vector
<REFLABEL
>& refList
)
509 GitRevLoglist
* data
= m_arShownList
.SafeGetAt(index
);
511 LVITEM rItem
= { 0 };
512 rItem
.mask
= LVIF_STATE
;
513 rItem
.iItem
= static_cast<int>(index
);
514 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
518 W_Dc
.Attach(pLVCD
->nmcd
.hdc
);
520 CAutoThemeData hTheme
;
522 hTheme
= OpenThemeData(m_hWnd
, L
"Explorer::ListView;ListView");
524 if (m_bTagsBranchesOnRightSide
)
526 HFONT oldFont
= static_cast<HFONT
>(SelectObject(pLVCD
->nmcd
.hdc
, GetStockObject(DEFAULT_GUI_FONT
)));
528 GetTextExtentPoint32(pLVCD
->nmcd
.hdc
, L
" ", 1, &oneSpaceSize
);
531 GetThemeMetric(hTheme
, pLVCD
->nmcd
.hdc
, LVP_LISTITEM
, LISS_NORMAL
, TMT_BORDERSIZE
, &borderWidth
);
532 SelectObject(pLVCD
->nmcd
.hdc
, oldFont
);
533 rt
.left
+= borderWidth
+ oneSpaceSize
.cx
;
538 GetTextExtentPoint32(pLVCD
->nmcd
.hdc
, L
" ", 1, &oneSpaceSize
);
539 DrawTagBranch(pLVCD
->nmcd
.hdc
, W_Dc
, hTheme
, rect
, rt
, rItem
, data
, refList
);
540 rt
.left
+= oneSpaceSize
.cx
;
543 CString msg
= MessageDisplayStr(data
);
544 int action
= data
->GetRebaseAction();
545 bool skip
= !!(action
& (LOGACTIONS_REBASE_DONE
| LOGACTIONS_REBASE_SKIP
));
546 std::vector
<CHARRANGE
> ranges
;
547 auto filter
= m_LogFilter
;
548 if ((filter
->GetSelectedFilters() & (LOGFILTER_SUBJECT
| (m_bFullCommitMessageOnLogLine
? LOGFILTER_MESSAGES
: 0))) && filter
->IsFilterActive())
549 filter
->GetMatchRanges(ranges
, msg
, 0);
552 int txtState
= LISS_NORMAL
;
553 if (rItem
.state
& LVIS_SELECTED
)
554 txtState
= LISS_SELECTED
;
557 DrawListItemWithMatchesRect(pLVCD
, ranges
, rt
, msg
, m_Colors
, hTheme
, txtState
);
560 DTTOPTS opts
= { 0 };
561 opts
.dwSize
= sizeof(opts
);
562 opts
.crText
= skip
? RGB(128, 128, 128) : CTheme::Instance().IsDarkTheme() ? CTheme::darkTextColor
: GetSysColor(COLOR_WINDOWTEXT
);
563 opts
.dwFlags
= DTT_TEXTCOLOR
;
564 DrawThemeTextEx(hTheme
, pLVCD
->nmcd
.hdc
, LVP_LISTITEM
, txtState
, msg
, -1, DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
| DT_END_ELLIPSIS
, &rt
, &opts
);
569 if ((rItem
.state
& LVIS_SELECTED
) && ::GetFocus() == m_hWnd
)
570 pLVCD
->clrText
= skip
? RGB(128, 128, 128) : ::GetSysColor(COLOR_HIGHLIGHTTEXT
);
572 pLVCD
->clrText
= skip
? RGB(128, 128, 128) : CTheme::Instance().IsDarkTheme() ? CTheme::darkTextColor
: GetSysColor(COLOR_WINDOWTEXT
);
574 DrawListItemWithMatchesRect(pLVCD
, ranges
, rt
, msg
, m_Colors
);
577 COLORREF clrOld
= ::SetTextColor(pLVCD
->nmcd
.hdc
, pLVCD
->clrText
);
578 ::DrawText(pLVCD
->nmcd
.hdc
, msg
, msg
.GetLength(), &rt
, DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
| DT_END_ELLIPSIS
);
579 ::SetTextColor(pLVCD
->nmcd
.hdc
, clrOld
);
583 if (m_bTagsBranchesOnRightSide
)
586 GetTextExtentPoint32(pLVCD
->nmcd
.hdc
, L
" ", 1, &oneSpaceSize
);
589 GetTextExtentPoint32(pLVCD
->nmcd
.hdc
, msg
, msg
.GetLength(), &size
);
591 rt
.left
+= oneSpaceSize
.cx
+ size
.cx
;
593 DrawTagBranch(pLVCD
->nmcd
.hdc
, W_Dc
, hTheme
, rect
, rt
, rItem
, data
, refList
);
599 void CGitLogListBase::DrawTagBranch(HDC hdc
, CDC
& W_Dc
, HTHEME hTheme
, const CRect
& rect
, CRect
& rt
, LVITEM
& rItem
, GitRevLoglist
* data
, const std::vector
<REFLABEL
>& refList
)
601 for (unsigned int i
= 0; i
< refList
.size(); ++i
)
603 CString shortname
= !refList
[i
].simplifiedName
.IsEmpty() ? refList
[i
].simplifiedName
: refList
[i
].name
;
605 COLORREF colRef
= refList
[i
].color
;
606 bool singleRemote
= refList
[i
].singleRemote
;
607 bool hasTracking
= refList
[i
].hasTracking
;
608 CGit::REF_TYPE refType
= refList
[i
].refType
;
610 //When row selected, ajust label color
613 if (rItem
.state
& LVIS_SELECTED
)
614 colRef
= CColors::MixColors(colRef
, ::GetSysColor(COLOR_HIGHLIGHT
), 150);
617 brush
= ::CreateSolidBrush(colRef
);
619 if (!shortname
.IsEmpty() && (rt
.left
< rect
.right
))
622 GetTextExtentPoint32(hdc
, shortname
, shortname
.GetLength(), &size
);
624 rt
.SetRect(rt
.left
, rt
.top
, rt
.left
+ size
.cx
, rt
.bottom
);
627 int textpos
= DT_CENTER
;
629 if (rt
.right
> rect
.right
)
631 rt
.right
= rect
.right
;
640 textRect
.OffsetRect(5, 0);
644 DrawTrackingRoundRect(hdc
, rt
, brush
, m_Colors
.Darken(colRef
, 100));
647 //Fill interior of ref label
648 ::FillRect(hdc
, &rt
, brush
);
656 W_Dc
.Draw3dRect(rectEdge
, m_Colors
.Lighten(colRef
, 100), m_Colors
.Darken(colRef
, 100));
657 rectEdge
.DeflateRect(1, 1);
658 W_Dc
.Draw3dRect(rectEdge
, m_Colors
.Lighten(colRef
, 50), m_Colors
.Darken(colRef
, 50));
661 if (refType
== CGit::REF_TYPE::ANNOTATED_TAG
)
664 POINT trianglept
[3] = { { rt
.right
- 8, rt
.top
}, { rt
.right
, (rt
.top
+ rt
.bottom
) / 2 }, { rt
.right
- 8, rt
.bottom
} };
665 HRGN hrgn
= ::CreatePolygonRgn(trianglept
, 3, ALTERNATE
);
666 ::FillRgn(hdc
, hrgn
, brush
);
667 ::DeleteObject(hrgn
);
668 ::MoveToEx(hdc
, trianglept
[0].x
- 1, trianglept
[0].y
, nullptr);
670 HPEN oldpen
= static_cast<HPEN
>(SelectObject(hdc
, pen
= ::CreatePen(PS_SOLID
, 2, m_Colors
.Lighten(colRef
, 50))));
671 ::LineTo(hdc
, trianglept
[1].x
- 1, trianglept
[1].y
- 1);
673 SelectObject(hdc
, pen
= ::CreatePen(PS_SOLID
, 2, m_Colors
.Darken(colRef
, 50)));
674 ::LineTo(hdc
, trianglept
[2].x
- 1, trianglept
[2].y
- 1);
676 SelectObject(hdc
, pen
= ::CreatePen(PS_SOLID
, 2, colRef
));
677 ::MoveToEx(hdc
, trianglept
[0].x
- 1, trianglept
[2].y
- 3, nullptr);
678 ::LineTo(hdc
, trianglept
[0].x
- 1, trianglept
[0].y
);
680 SelectObject(hdc
, oldpen
);
683 //Draw text inside label
684 bool customColor
= (colRef
& 0xff) * 30 + ((colRef
>> 8) & 0xff) * 59 + ((colRef
>> 16) & 0xff) * 11 <= 12800; // check if dark background
685 if (!customColor
&& IsAppThemed())
687 int txtState
= LISS_NORMAL
;
688 if (rItem
.state
& LVIS_SELECTED
)
689 txtState
= LISS_SELECTED
;
691 DTTOPTS opts
= { 0 };
692 opts
.dwSize
= sizeof(opts
);
693 opts
.crText
= GetSysColor(COLOR_WINDOWTEXT
);
694 opts
.dwFlags
= DTT_TEXTCOLOR
;
695 DrawThemeTextEx(hTheme
, hdc
, LVP_LISTITEM
, txtState
, shortname
, -1, textpos
| DT_NOPREFIX
| DT_SINGLELINE
| DT_VCENTER
, &textRect
, &opts
);
699 W_Dc
.SetBkMode(TRANSPARENT
);
700 if (customColor
|| (rItem
.state
& LVIS_SELECTED
))
702 COLORREF clrNew
= ::GetSysColor(COLOR_HIGHLIGHTTEXT
);
703 COLORREF clrOld
= ::SetTextColor(hdc
,clrNew
);
704 ::DrawText(hdc
, shortname
, shortname
.GetLength(), &textRect
, textpos
| DT_NOPREFIX
| DT_SINGLELINE
| DT_VCENTER
);
705 ::SetTextColor(hdc
,clrOld
);
709 COLORREF clrOld
= ::SetTextColor(hdc
, CTheme::Instance().IsDarkTheme() ? CTheme::darkTextColor
: GetSysColor(COLOR_WINDOWTEXT
));
710 ::DrawText(hdc
, shortname
, shortname
.GetLength(), &textRect
, textpos
| DT_NOPREFIX
| DT_SINGLELINE
| DT_VCENTER
);
711 ::SetTextColor(hdc
, clrOld
);
717 COLORREF color
= ::GetSysColor(customColor
? COLOR_HIGHLIGHTTEXT
: COLOR_WINDOWTEXT
);
718 int bold
= data
->m_CommitHash
== m_HeadHash
? 2 : 1;
720 newRect
.SetRect(rt
.left
+ 2, rt
.top
+ 4, rt
.left
+ 6, rt
.bottom
- 4);
721 DrawUpstream(hdc
, newRect
, color
, bold
);
724 if (!refList
[i
].fullName
.IsEmpty())
725 m_RefLabelPosMap
[refList
[i
].fullName
] = rt
;
727 rt
.left
= rt
.right
+ 1;
730 ::DeleteObject(brush
);
732 rt
.right
= rect
.right
;
735 Gdiplus::Color
GetGdiColor(COLORREF col
)
737 return Gdiplus::Color(GetRValue(col
),GetGValue(col
),GetBValue(col
));
739 void CGitLogListBase::paintGraphLane(HDC hdc
, int laneHeight
,int type
, bool rolledUp
, int x1
, int x2
,
740 const COLORREF
& col
,const COLORREF
& activeColor
, int top
743 int h
= laneHeight
/ 2;
744 int m
= (x1
+ x2
) / 2;
745 int r
= (x2
- x1
) * m_NodeSize
/ 30;
748 #define P_CENTER m , h+top
749 #define P_CENTER_0 m+r, h+top
750 #define P_CENTER_90 m, h-r+top
751 #define P_CENTER_180 m-r, h+top
752 #define P_CENTER_270 m, h+r+top
753 #define P_0 x2, h+top
754 #define P_90 m , 0+top-1
755 #define P_180 x1, h+top
756 #define P_270 m , 2 * h+top +1
757 #define R_CENTER m - r, h - r+top, d, d
760 #define DELTA_UR_B 2*(x1 - m), 2*h +top
761 #define DELTA_UR_E 0*16, 90*16 +top // -,
763 #define DELTA_DR_B 2*(x1 - m), 2*-h +top
764 #define DELTA_DR_E 270*16, 90*16 +top // -'
766 #define DELTA_UL_B 2*(x2 - m), 2*h +top
767 #define DELTA_UL_E 90*16, 90*16 +top // ,-
769 #define DELTA_DL_B 2*(x2 - m),2*-h +top
770 #define DELTA_DL_E 180*16, 90*16 // '-
772 #define CENTER_UR x1, 2*h, 225
773 #define CENTER_DR x1, 0 , 135
774 #define CENTER_UL x2, 2*h, 315
775 #define CENTER_DL x2, 0 , 45
778 Gdiplus::Graphics
graphics( hdc
);
780 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
789 Gdiplus::LinearGradientBrush
gradient(
790 Gdiplus::Point(x1
-2, h
+top
-2),
791 Gdiplus::Point(P_270
),
792 GetGdiColor(activeColor
),GetGdiColor(col
));
795 Gdiplus::Pen
mypen(&gradient
, static_cast<Gdiplus::REAL
>(m_LineWidth
));
796 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
798 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
799 graphics
.DrawArc(&mypen
,x1
-(x2
-x1
)/2-1,top
+h
-1, x2
-x1
,laneHeight
,270,90);
800 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
806 Gdiplus::LinearGradientBrush
gradient(
807 Gdiplus::Point(P_270
),
808 Gdiplus::Point(x2
+1, h
+top
-1),
809 GetGdiColor(col
),GetGdiColor(activeColor
));
812 Gdiplus::Pen
mypen(&gradient
, static_cast<Gdiplus::REAL
>(m_LineWidth
));
813 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
815 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
816 graphics
.DrawArc(&mypen
,x1
+(x2
-x1
)/2,top
+h
-1, x2
-x1
,laneHeight
,180,90);
817 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
825 Gdiplus::LinearGradientBrush
gradient(
826 Gdiplus::Point(x1
-2, h
+top
-2),
827 Gdiplus::Point(P_90
),
828 GetGdiColor(activeColor
),GetGdiColor(col
));
830 Gdiplus::Pen
mypen(&gradient
, static_cast<Gdiplus::REAL
>(m_LineWidth
));
832 graphics
.DrawArc(&mypen
,x1
-(x2
-x1
)/2-1,top
-h
-1, x2
-x1
,laneHeight
,0,90);
835 QConicalGradient
gradient(CENTER_DR
);
836 gradient
.setColorAt(0.375, activeCol
);
837 gradient
.setColorAt(0.625, col
);
838 myPen
.setBrush(gradient
);
840 p
->drawArc(P_CENTER
, DELTA_DR
);
849 //static QPen myPen(Qt::black, 2); // fast path here
851 pen
.CreatePen(PS_SOLID
,2,col
);
852 //myPen.setColor(col);
853 HPEN oldpen
= static_cast<HPEN
>(::SelectObject(hdc
, pen
));
855 Gdiplus::Pen
myPen(GetGdiColor(col
), static_cast<Gdiplus::REAL
>(m_LineWidth
));
857 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
864 case Lanes::MERGE_FORK
:
865 case Lanes::MERGE_FORK_R
:
866 case Lanes::MERGE_FORK_L
:
869 graphics
.DrawLine(&myPen
, P_90
, P_CENTER_90
);
870 graphics
.DrawLine(&myPen
, P_CENTER_270
, P_270
);
874 case Lanes::NOT_ACTIVE
:
879 //DrawLine(hdc,P_90,P_270);
880 graphics
.DrawLine(&myPen
,P_90
,P_270
);
881 //p->drawLine(P_90, P_270);
886 graphics
.DrawLine(&myPen
, P_CENTER_270
, P_270
);
891 //DrawLine(hdc,P_CENTER,P_270);
892 graphics
.DrawLine(&myPen
,P_CENTER
,P_270
);
893 //p->drawLine(P_CENTER, P_270);
896 case Lanes::MERGE_FORK_L_INITIAL
:
897 case Lanes::BOUNDARY
:
898 case Lanes::BOUNDARY_C
:
899 case Lanes::BOUNDARY_R
:
900 case Lanes::BOUNDARY_L
:
903 graphics
.DrawLine(&myPen
, P_90
, P_CENTER_90
);
908 //DrawLine(hdc,P_90, P_CENTER);
909 graphics
.DrawLine(&myPen
,P_90
,P_CENTER
);
910 //p->drawLine(P_90, P_CENTER);
916 myPen
.SetColor(GetGdiColor(activeColor
));
920 case Lanes::MERGE_FORK
:
921 case Lanes::BOUNDARY_C
:
924 graphics
.DrawLine(&myPen
, P_180
, P_CENTER_180
);
925 graphics
.DrawLine(&myPen
, P_CENTER_0
, P_0
);
933 case Lanes::CROSS_EMPTY
:
934 //DrawLine(hdc,P_180,P_0);
935 graphics
.DrawLine(&myPen
,P_180
,P_0
);
936 //p->drawLine(P_180, P_0);
938 case Lanes::MERGE_FORK_R
:
939 case Lanes::BOUNDARY_R
:
940 //DrawLine(hdc,P_180,P_CENTER);
942 graphics
.DrawLine(&myPen
, P_180
, P_CENTER_180
);
944 graphics
.DrawLine(&myPen
, P_180
, P_CENTER
);
945 //p->drawLine(P_180, P_CENTER);
947 case Lanes::MERGE_FORK_L
:
948 case Lanes::MERGE_FORK_L_INITIAL
:
949 case Lanes::BOUNDARY_L
:
952 graphics
.DrawLine(&myPen
, P_CENTER_0
, P_0
);
958 //DrawLine(hdc,P_CENTER,P_0);
959 graphics
.DrawLine(&myPen
,P_CENTER
,P_0
);
960 //p->drawLine(P_CENTER, P_0);
966 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
969 brush
.CreateSolidBrush(col
);
970 HBRUSH oldbrush
= static_cast<HBRUSH
>(::SelectObject(hdc
, brush
));
972 Gdiplus::SolidBrush
myBrush(GetGdiColor(col
));
973 Gdiplus::Pen
myPen1(GetGdiColor(col
), 1);
974 // center symbol, e.g. rect or ellipse
980 //p->setPen(Qt::NoPen);
982 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
984 graphics
.DrawEllipse(&myPen1
, R_CENTER
);
986 graphics
.FillEllipse(&myBrush
, R_CENTER
);
987 //p->drawEllipse(R_CENTER);
989 case Lanes::MERGE_FORK
:
990 case Lanes::MERGE_FORK_R
:
991 case Lanes::MERGE_FORK_L
:
992 case Lanes::MERGE_FORK_L_INITIAL
:
993 //p->setPen(Qt::NoPen);
995 //p->drawRect(R_CENTER);
996 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
998 graphics
.DrawRectangle(&myPen1
, R_CENTER
);
1000 graphics
.FillRectangle(&myBrush
, R_CENTER
);
1002 case Lanes::UNAPPLIED
:
1004 //p->setPen(Qt::NoPen);
1005 //p->setBrush(Qt::red);
1006 //p->drawRect(m - r, h - 1, d, 2);
1007 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
1008 graphics
.FillRectangle(&myBrush
,m
-r
,h
-1,d
,2);
1010 case Lanes::APPLIED
:
1012 //p->setPen(Qt::NoPen);
1013 //p->setBrush(DARK_GREEN);
1014 //p->drawRect(m - r, h - 1, d, 2);
1015 //p->drawRect(m - 1, h - r, 2, d);
1016 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
1017 graphics
.FillRectangle(&myBrush
,m
-r
,h
-1,d
,2);
1018 graphics
.FillRectangle(&myBrush
,m
-1,h
-r
,2,d
);
1020 case Lanes::BOUNDARY
:
1021 //p->setBrush(back);
1022 //p->drawEllipse(R_CENTER);
1023 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
1024 graphics
.DrawEllipse(&myPen
, R_CENTER
);
1026 case Lanes::BOUNDARY_C
:
1027 case Lanes::BOUNDARY_R
:
1028 case Lanes::BOUNDARY_L
:
1029 //p->setBrush(back);
1030 //p->drawRect(R_CENTER);
1031 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
1033 graphics
.DrawRectangle(&myPen1
, R_CENTER
);
1035 graphics
.FillRectangle(&myBrush
, R_CENTER
);
1041 ::SelectObject(hdc
,oldpen
);
1042 ::SelectObject(hdc
,oldbrush
);
1055 void CGitLogListBase::DrawGraph(HDC hdc
,CRect
&rect
,INT_PTR index
)
1059 GitRevLoglist
* data
= m_arShownList
.SafeGetAt(index
);
1060 if(data
->m_CommitHash
.IsEmpty())
1064 LVITEM rItem
= { 0 };
1065 rItem
.mask
= LVIF_STATE
;
1066 rItem
.iItem
= static_cast<int>(index
);
1067 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
1070 // p->translate(QPoint(opt.rect.left(), opt.rect.top()));
1072 if (data
->m_Lanes
.empty())
1073 m_logEntries
.setLane(data
->m_CommitHash
);
1075 std::vector
<int>& lanes
=data
->m_Lanes
;
1076 size_t laneNum
= lanes
.size();
1077 UINT activeLane
= 0;
1078 for (UINT i
= 0; i
< laneNum
; ++i
)
1079 if (Lanes::isMerge(lanes
[i
])) {
1085 int maxWidth
= rect
.Width();
1086 int lw
= 3 * rect
.Height() / 4; //laneWidth()
1088 COLORREF activeColor
= CTheme::Instance().GetThemeColor(m_Colors
.GetColor((CColors::Colors
)(CColors::BranchLine1
+ (activeLane
% Lanes::COLORS_NUM
))), true);
1090 for (unsigned int i
= 0; i
< laneNum
&& x2
< maxWidth
; ++i
)
1096 if (ln
== Lanes::EMPTY
)
1099 COLORREF color
= i
== activeLane
? activeColor
: CTheme::Instance().GetThemeColor(m_Colors
.GetColor((CColors::Colors
)(CColors::BranchLine1
+ (i
% Lanes::COLORS_NUM
))), true);
1100 paintGraphLane(hdc
, rect
.Height(), ln
, data
->m_RolledUp
, x1
+ rect
.left
, x2
+ rect
.left
, color
,activeColor
, rect
.top
);
1104 for (UINT i
= 0; i
< laneNum
&& x2
< maxWidth
; ++i
) {
1109 if (ln
== Lanes::EMPTY
)
1112 UINT col
= ( Lanes:: isHead(ln
) ||Lanes:: isTail(ln
) || Lanes::isJoin(ln
)
1113 || ln
==Lanes:: CROSS_EMPTY
) ? activeLane
: i
;
1115 if (ln
== Lanes::CROSS
)
1117 paintGraphLane(hdc
, rect
.Height(),Lanes::NOT_ACTIVE
, x1
, x2
, m_LineColors
[col
% Lanes::COLORS_NUM
],rect
.top
);
1118 paintGraphLane(hdc
, rect
.Height(),Lanes::CROSS
, x1
, x2
, m_LineColors
[activeLane
% Lanes::COLORS_NUM
],rect
.top
);
1121 paintGraphLane(hdc
, rect
.Height(),ln
, x1
, x2
, m_LineColors
[col
% Lanes::COLORS_NUM
],rect
.top
);
1126 void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1128 NMLVCUSTOMDRAW
* pLVCD
= reinterpret_cast<NMLVCUSTOMDRAW
*>( pNMHDR
);
1129 // Take the default processing unless we set this to something else below.
1130 *pResult
= CDRF_DODEFAULT
;
1132 if (m_bNoDispUpdates
)
1135 switch (pLVCD
->nmcd
.dwDrawStage
)
1139 *pResult
= CDRF_NOTIFYITEMDRAW
;
1143 case CDDS_ITEMPREPAINT
:
1145 // This is the prepaint stage for an item. Here's where we set the
1146 // item's text color.
1148 // Tell Windows to send draw notifications for each subitem.
1149 *pResult
= CDRF_NOTIFYSUBITEMDRAW
;
1151 COLORREF crText
= CTheme::Instance().IsDarkTheme() ? CTheme::darkTextColor
: GetSysColor(COLOR_WINDOWTEXT
);
1153 if (m_arShownList
.size() > pLVCD
->nmcd
.dwItemSpec
)
1155 GitRevLoglist
* data
= m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1158 HGDIOBJ hGdiObj
= nullptr;
1159 int action
= data
->GetRebaseAction();
1160 if (action
& (LOGACTIONS_REBASE_DONE
| LOGACTIONS_REBASE_SKIP
))
1161 crText
= RGB(128, 128, 128);
1163 if (action
& LOGACTIONS_REBASE_SQUASH
)
1164 pLVCD
->clrTextBk
= RGB(156, 156, 156);
1165 else if (action
& LOGACTIONS_REBASE_EDIT
)
1166 pLVCD
->clrTextBk
= CTheme::Instance().GetThemeColor(RGB(200, 200, 128));
1168 pLVCD
->clrTextBk
= CTheme::Instance().IsDarkTheme() ? CTheme::darkBkColor
: GetSysColor(COLOR_WINDOW
);
1170 if (action
& LOGACTIONS_REBASE_CURRENT
)
1171 hGdiObj
= m_boldFont
.GetSafeHandle();
1173 BOOL isHeadHash
= data
->m_CommitHash
== m_HeadHash
&& m_bNoHightlightHead
== FALSE
;
1174 BOOL isHighlight
= data
->m_CommitHash
== m_highlight
&& !m_highlight
.IsEmpty();
1175 if (isHeadHash
&& isHighlight
)
1176 hGdiObj
= m_boldItalicsFont
.GetSafeHandle();
1177 else if (isHeadHash
)
1178 hGdiObj
= m_boldFont
.GetSafeHandle();
1179 else if (isHighlight
)
1180 hGdiObj
= m_FontItalics
.GetSafeHandle();
1184 SelectObject(pLVCD
->nmcd
.hdc
, hGdiObj
);
1185 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
1188 // if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))
1189 // crText = GetSysColor(COLOR_GRAYTEXT);
1191 if (data
->m_CommitHash
.IsEmpty())
1193 //crText = GetSysColor(RGB(200,200,0));
1194 //SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1195 // We changed the font, so we're returning CDRF_NEWFONT. This
1196 // tells the control to recalculate the extent of the text.
1197 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
1201 // Store the color back in the NMLVCUSTOMDRAW struct.
1202 pLVCD
->clrText
= crText
;
1207 case CDDS_ITEMPREPAINT
| CDDS_ITEM
| CDDS_SUBITEM
:
1209 switch (pLVCD
->iSubItem
)
1212 if ((m_ShowFilter
& FILTERSHOW_MERGEPOINTS
) && !m_LogFilter
->IsFilterActive())
1214 if (m_arShownList
.size() > pLVCD
->nmcd
.dwItemSpec
&& !this->m_IsRebaseReplaceGraph
)
1217 GetSubItemRect(static_cast<int>(pLVCD
->nmcd
.dwItemSpec
), pLVCD
->iSubItem
, LVIR_LABEL
, rect
);
1219 //TRACE(L"A Graphic left %d right %d\r\n", rect.left, rect.right);
1220 FillBackGround(pLVCD
->nmcd
.hdc
, pLVCD
->nmcd
.dwItemSpec
,rect
);
1222 GitRevLoglist
* data
= m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1223 if( !data
->m_CommitHash
.IsEmpty())
1224 DrawGraph(pLVCD
->nmcd
.hdc
,rect
,pLVCD
->nmcd
.dwItemSpec
);
1226 *pResult
= CDRF_SKIPDEFAULT
;
1232 case LOGLIST_MESSAGE
:
1233 // If the top index of list is changed, the position map of reference label is outdated.
1234 if (m_OldTopIndex
!= GetTopIndex())
1236 m_OldTopIndex
= GetTopIndex();
1237 m_RefLabelPosMap
.clear();
1240 if (m_arShownList
.size() > pLVCD
->nmcd
.dwItemSpec
)
1242 GitRevLoglist
* data
= m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1244 auto hashMapSharedPtr
= m_HashMap
;
1245 const auto& hashMap
= *hashMapSharedPtr
;
1246 if ((hashMap
.find(data
->m_CommitHash
) != hashMap
.cend() || (!m_superProjectHash
.IsEmpty() && data
->m_CommitHash
== m_superProjectHash
)) && !(data
->GetRebaseAction() & LOGACTIONS_REBASE_DONE
))
1249 GetSubItemRect(static_cast<int>(pLVCD
->nmcd
.dwItemSpec
), pLVCD
->iSubItem
, LVIR_BOUNDS
, rect
);
1251 // BEGIN: extended redraw, HACK for issue #1618 and #2014
1252 // not in FillBackGround method, because this only affected the message subitem
1253 if (0 != pLVCD
->iStateId
) // don't know why, but this helps against loosing the focus rect
1256 int index
= static_cast<int>(pLVCD
->nmcd
.dwItemSpec
);
1257 int state
= GetItemState(index
, LVIS_SELECTED
);
1258 int txtState
= LISS_NORMAL
;
1259 if (IsAppThemed() && GetHotItem() == static_cast<int>(index
))
1261 if (state
& LVIS_SELECTED
)
1262 txtState
= LISS_HOTSELECTED
;
1264 txtState
= LISS_HOT
;
1266 else if (state
& LVIS_SELECTED
)
1268 if (::GetFocus() == m_hWnd
)
1269 txtState
= LISS_SELECTED
;
1271 txtState
= LISS_SELECTEDNOTFOCUS
;
1274 CAutoThemeData hTheme
;
1277 hTheme
= OpenThemeData(m_hWnd
, L
"Explorer::ListView;ListView");
1279 // make sure the column separator/border is not overpainted
1280 int borderWidth
= 0;
1281 GetThemeMetric(hTheme
, pLVCD
->nmcd
.hdc
, LVP_LISTITEM
, LISS_NORMAL
, TMT_BORDERSIZE
, &borderWidth
);
1282 InflateRect(&rect
, -(2 * borderWidth
), 0);
1285 if (hTheme
&& IsThemeBackgroundPartiallyTransparent(hTheme
, LVP_LISTDETAIL
, txtState
))
1286 DrawThemeParentBackground(m_hWnd
, pLVCD
->nmcd
.hdc
, &rect
);
1289 HBRUSH brush
= ::CreateSolidBrush(pLVCD
->clrTextBk
);
1290 ::FillRect(pLVCD
->nmcd
.hdc
, rect
, brush
);
1291 ::DeleteObject(brush
);
1293 if (hTheme
&& txtState
!= LISS_NORMAL
)
1296 // get rect of whole line
1297 GetItemRect(index
, rt
, LVIR_BOUNDS
);
1300 // calculate background for rect of whole line, but limit redrawing to SubItem rect
1301 DrawThemeBackground(hTheme
, pLVCD
->nmcd
.hdc
, LVP_LISTITEM
, txtState
, rt
, rect2
);
1303 hTheme
.CloseHandle();
1304 // END: extended redraw
1306 FillBackGround(pLVCD
->nmcd
.hdc
, pLVCD
->nmcd
.dwItemSpec
, rect
);
1308 std::vector
<REFLABEL
> refsToShow
;
1309 STRING_VECTOR remoteTrackingList
;
1310 std::vector
<CString
>::const_iterator refListIt
;
1311 std::vector
<CString
>::const_iterator refListItEnd
;
1312 auto commitRefsIt
= hashMap
.find(data
->m_CommitHash
);
1313 if (commitRefsIt
!= hashMap
.cend())
1315 refListIt
= (*commitRefsIt
).second
.cbegin();
1316 refListItEnd
= (*commitRefsIt
).second
.cend();
1318 for (; refListIt
!= refListItEnd
; ++refListIt
)
1321 refLabel
.color
= RGB(255, 255, 255);
1322 refLabel
.singleRemote
= false;
1323 refLabel
.hasTracking
= false;
1324 refLabel
.sameName
= false;
1325 refLabel
.name
= CGit::GetShortName(*refListIt
, &refLabel
.refType
);
1326 refLabel
.fullName
= *refListIt
;
1328 switch (refLabel
.refType
)
1330 case CGit::REF_TYPE::LOCAL_BRANCH
:
1332 if (!(m_ShowRefMask
& LOGLIST_SHOWLOCALBRANCHES
))
1334 if (refLabel
.name
== m_CurrentBranch
)
1335 refLabel
.color
= CTheme::Instance().GetThemeColor(m_Colors
.GetColor(CColors::CurrentBranch
), true);
1337 refLabel
.color
= CTheme::Instance().GetThemeColor(m_Colors
.GetColor(CColors::LocalBranch
), true);
1339 std::pair
<CString
, CString
> trackingEntry
= m_TrackingMap
[refLabel
.name
];
1340 CString pullRemote
= trackingEntry
.first
;
1341 CString pullBranch
= trackingEntry
.second
;
1342 if (!pullRemote
.IsEmpty() && !pullBranch
.IsEmpty())
1344 CString defaultUpstream
;
1345 defaultUpstream
.Format(L
"refs/remotes/%s/%s", static_cast<LPCWSTR
>(pullRemote
), static_cast<LPCWSTR
>(pullBranch
));
1346 refLabel
.hasTracking
= true;
1347 if (m_ShowRefMask
& LOGLIST_SHOWREMOTEBRANCHES
)
1350 for (auto it2
= refListIt
+ 1; it2
!= refListItEnd
; ++it2
)
1352 if (*it2
== defaultUpstream
)
1361 bool sameName
= pullBranch
== refLabel
.name
;
1362 refsToShow
.push_back(refLabel
);
1363 CGit::GetShortName(defaultUpstream
, refLabel
.name
, L
"refs/remotes/");
1364 refLabel
.color
= CTheme::Instance().GetThemeColor(m_Colors
.GetColor(CColors::RemoteBranch
), true);
1365 if (m_bSymbolizeRefNames
)
1367 if (!m_SingleRemote
.IsEmpty() && m_SingleRemote
== pullRemote
)
1369 refLabel
.simplifiedName
= L
'/';
1371 refLabel
.simplifiedName
+= L
'≡';
1373 refLabel
.simplifiedName
+= pullBranch
;
1374 refLabel
.singleRemote
= true;
1377 refLabel
.simplifiedName
= pullRemote
+ L
"/≡";
1378 refLabel
.sameName
= sameName
;
1380 refLabel
.fullName
= defaultUpstream
;
1381 refsToShow
.push_back(refLabel
);
1382 remoteTrackingList
.push_back(defaultUpstream
);
1389 case CGit::REF_TYPE::REMOTE_BRANCH
:
1391 if (!(m_ShowRefMask
& LOGLIST_SHOWREMOTEBRANCHES
))
1394 for (size_t j
= 0; j
< remoteTrackingList
.size(); ++j
)
1396 if (remoteTrackingList
[j
] == *refListIt
)
1405 refLabel
.color
= CTheme::Instance().GetThemeColor(m_Colors
.GetColor(CColors::RemoteBranch
), true);
1406 if (m_bSymbolizeRefNames
)
1408 if (!m_SingleRemote
.IsEmpty() && CStringUtils::StartsWith(refLabel
.name
, m_SingleRemote
+ L
"/"))
1410 refLabel
.simplifiedName
= L
'/' + refLabel
.name
.Mid(m_SingleRemote
.GetLength() + 1);
1411 refLabel
.singleRemote
= true;
1416 case CGit::REF_TYPE::ANNOTATED_TAG
:
1418 case CGit::REF_TYPE::TAG
:
1419 if (!(m_ShowRefMask
& LOGLIST_SHOWTAGS
))
1421 refLabel
.color
= CTheme::Instance().GetThemeColor(m_Colors
.GetColor(CColors::Tag
), true);
1424 case CGit::REF_TYPE::STASH
:
1425 if (!(m_ShowRefMask
& LOGLIST_SHOWSTASH
))
1427 refLabel
.color
= CTheme::Instance().GetThemeColor(m_Colors
.GetColor(CColors::Stash
), true);
1430 case CGit::REF_TYPE::BISECT_GOOD
:
1432 case CGit::REF_TYPE::BISECT_BAD
:
1434 case CGit::REF_TYPE::BISECT_SKIP
:
1435 if (!(m_ShowRefMask
& LOGLIST_SHOWBISECT
))
1437 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);
1440 case CGit::REF_TYPE::NOTES
:
1441 if (!(m_ShowRefMask
& LOGLIST_SHOWOTHERREFS
))
1443 refLabel
.color
= CTheme::Instance().GetThemeColor(m_Colors
.GetColor(CColors::NoteNode
), true);
1447 if (!(m_ShowRefMask
& LOGLIST_SHOWOTHERREFS
))
1449 refLabel
.color
= CTheme::Instance().GetThemeColor(m_Colors
.GetColor(CColors::OtherRef
), true);
1452 refsToShow
.push_back(refLabel
);
1454 if (!m_superProjectHash
.IsEmpty() && data
->m_CommitHash
== m_superProjectHash
)
1457 refLabel
.color
= CTheme::Instance().GetThemeColor(RGB(246, 153, 253), true);
1458 refLabel
.singleRemote
= false;
1459 refLabel
.hasTracking
= false;
1460 refLabel
.sameName
= false;
1461 refLabel
.name
= L
"super-project-pointer";
1462 refLabel
.fullName
= "";
1463 refsToShow
.push_back(refLabel
);
1466 if (refsToShow
.empty())
1468 *pResult
= CDRF_DODEFAULT
;
1472 DrawTagBranchMessage(pLVCD
, rect
, pLVCD
->nmcd
.dwItemSpec
, refsToShow
);
1474 *pResult
= CDRF_SKIPDEFAULT
;
1477 else if (DrawListItemWithMatchesIfEnabled(m_LogFilter
, LOGFILTER_SUBJECT
| LOGFILTER_MESSAGES
, pLVCD
, pResult
))//from here
1482 case LOGLIST_ACTION
:
1484 if (m_IsIDReplaceAction
|| !m_ColumnManager
.IsVisible(LOGLIST_ACTION
))
1486 *pResult
= CDRF_DODEFAULT
;
1489 *pResult
= CDRF_DODEFAULT
;
1491 if (m_arShownList
.size() <= pLVCD
->nmcd
.dwItemSpec
)
1495 int iconwidth
= ::GetSystemMetrics(SM_CXSMICON
);
1496 int iconheight
= ::GetSystemMetrics(SM_CYSMICON
);
1498 GitRevLoglist
* pLogEntry
= m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1500 GetSubItemRect(static_cast<int>(pLVCD
->nmcd
.dwItemSpec
), pLVCD
->iSubItem
, LVIR_BOUNDS
, rect
);
1501 //TRACE(L"Action left %d right %d\r\n", rect.left, rect.right);
1502 // Get the selected state of the
1503 // item being drawn.
1505 CMemDC
myDC(*CDC::FromHandle(pLVCD
->nmcd
.hdc
), rect
);
1506 BitBlt(myDC
.GetDC(), rect
.left
, rect
.top
, rect
.Width(), rect
.Height(), pLVCD
->nmcd
.hdc
, rect
.left
, rect
.top
, SRCCOPY
);
1508 // Fill the background if necessary
1509 FillBackGround(myDC
.GetDC(), pLVCD
->nmcd
.dwItemSpec
, rect
);
1511 // Draw the icon(s) into the compatible DC
1512 int action
= pLogEntry
->GetAction(this);
1513 auto iconItemBorder
= CDPIAware::Instance().ScaleX(ICONITEMBORDER
);
1514 if (!pLogEntry
->m_IsDiffFiles
)
1516 ::DrawIconEx(myDC
.GetDC(), rect
.left
+ iconItemBorder
, rect
.top
, m_hFetchIcon
, iconwidth
, iconheight
, 0, nullptr, DI_NORMAL
);
1517 *pResult
= CDRF_SKIPDEFAULT
;
1521 if (action
& CTGitPath::LOGACTIONS_MODIFIED
)
1522 ::DrawIconEx(myDC
.GetDC(), rect
.left
+ iconItemBorder
, rect
.top
, m_hModifiedIcon
, iconwidth
, iconheight
, 0, nullptr, DI_NORMAL
);
1525 if (action
& (CTGitPath::LOGACTIONS_ADDED
| CTGitPath::LOGACTIONS_COPY
))
1526 ::DrawIconEx(myDC
.GetDC(), rect
.left
+ nIcons
* iconwidth
+ iconItemBorder
, rect
.top
, m_hAddedIcon
, iconwidth
, iconheight
, 0, nullptr, DI_NORMAL
);
1529 if (action
& CTGitPath::LOGACTIONS_DELETED
)
1530 ::DrawIconEx(myDC
.GetDC(), rect
.left
+ nIcons
* iconwidth
+ iconItemBorder
, rect
.top
, m_hDeletedIcon
, iconwidth
, iconheight
, 0, nullptr, DI_NORMAL
);
1533 if (action
& CTGitPath::LOGACTIONS_REPLACED
)
1534 ::DrawIconEx(myDC
.GetDC(), rect
.left
+ nIcons
* iconwidth
+ iconItemBorder
, rect
.top
, m_hReplacedIcon
, iconwidth
, iconheight
, 0, nullptr, DI_NORMAL
);
1537 if (action
& CTGitPath::LOGACTIONS_UNMERGED
)
1538 ::DrawIconEx(myDC
.GetDC(), rect
.left
+ nIcons
* iconwidth
+ iconItemBorder
, rect
.top
, m_hConflictedIcon
, iconwidth
, iconheight
, 0, nullptr, DI_NORMAL
);
1541 *pResult
= CDRF_SKIPDEFAULT
;
1546 if (DrawListItemWithMatchesIfEnabled(m_LogFilter
, LOGFILTER_REVS
, pLVCD
, pResult
))
1550 case LOGLIST_AUTHOR
:
1551 case LOGLIST_COMMIT_NAME
:
1552 if (DrawListItemWithMatchesIfEnabled(m_LogFilter
, LOGFILTER_AUTHORS
, pLVCD
, pResult
))
1557 case LOGLIST_COMMIT_EMAIL
:
1558 if (DrawListItemWithMatchesIfEnabled(m_LogFilter
, LOGFILTER_EMAILS
, pLVCD
, pResult
))
1563 if (DrawListItemWithMatchesIfEnabled(m_LogFilter
, LOGFILTER_BUGID
, pLVCD
, pResult
))
1570 *pResult
= CDRF_DODEFAULT
;
1573 CString
FindSVNRev(const CString
& msg
)
1577 const std::wsregex_iterator end
;
1578 std::wstring s
{ static_cast<LPCWSTR
>(msg
) };
1579 std::wregex
regex1(L
"^\\s*git-svn-id:\\s+(.*)\\@(\\d+)\\s([a-f\\d\\-]+)$");
1580 for (std::wsregex_iterator
it(s
.cbegin(), s
.cend(), regex1
); it
!= end
; ++it
)
1582 const std::wsmatch match
= *it
;
1583 if (match
.size() == 4)
1585 ATLTRACE(L
"matched rev: %s\n", std::wstring(match
[2]).c_str());
1586 return std::wstring(match
[2]).c_str();
1589 std::wregex
regex2(L
"^\\s*git-svn-id:\\s(\\d+)\\@([a-f\\d\\-]+)$");
1590 for (std::wsregex_iterator
it(s
.cbegin(), s
.cend(), regex2
); it
!= end
; ++it
)
1592 const std::wsmatch match
= *it
;
1593 if (match
.size() == 3)
1595 ATLTRACE(L
"matched rev: %s\n", std::wstring(match
[1]).c_str());
1596 return std::wstring(match
[1]).c_str();
1600 catch (std::exception
&) {}
1605 CString
CGitLogListBase::MessageDisplayStr(GitRev
* pLogEntry
)
1607 if (!m_bFullCommitMessageOnLogLine
|| pLogEntry
->GetBody().IsEmpty())
1608 return pLogEntry
->GetSubject();
1610 CString
txt(pLogEntry
->GetSubject());
1612 txt
+= pLogEntry
->GetBody();
1615 txt
.Replace(L
'\n', L
' ');
1616 txt
.Replace(L
'\r', L
' ');
1621 // CGitLogListBase message handlers
1623 void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1625 NMLVDISPINFO
*pDispInfo
= reinterpret_cast<NMLVDISPINFO
*>(pNMHDR
);
1627 // Create a pointer to the item
1628 LV_ITEM
* pItem
= &(pDispInfo
)->item
;
1630 // Do the list need text information?
1631 if (!(pItem
->mask
& LVIF_TEXT
))
1634 // By default, clear text buffer.
1635 lstrcpyn(pItem
->pszText
, L
"", pItem
->cchTextMax
- 1);
1637 bool bOutOfRange
= pItem
->iItem
>= static_cast<int>(m_arShownList
.size());
1640 if (m_bNoDispUpdates
|| bOutOfRange
)
1643 // Which item number?
1644 GitRevLoglist
* pLogEntry
= m_arShownList
.SafeGetAt(pItem
->iItem
);
1648 temp
.Format(L
"%d", pItem
->iItem
+ 1);
1650 temp
.Format(L
"%zu", m_arShownList
.size() - pItem
->iItem
);
1656 switch (pItem
->iSubItem
)
1658 case LOGLIST_GRAPH
: //Graphic
1660 case LOGLIST_REBASE
:
1661 if (m_IsRebaseReplaceGraph
)
1662 lstrcpyn(pItem
->pszText
, GetRebaseActionName(pLogEntry
->GetRebaseAction() & LOGACTIONS_REBASE_MODE_MASK
), pItem
->cchTextMax
- 1);
1664 case LOGLIST_ACTION
: //action -- no text in the column
1667 lstrcpyn(pItem
->pszText
, pLogEntry
->m_CommitHash
.ToString(), pItem
->cchTextMax
- 1);
1670 if (this->m_IsIDReplaceAction
)
1671 lstrcpyn(pItem
->pszText
, temp
, pItem
->cchTextMax
- 1);
1673 case LOGLIST_MESSAGE
: //Message
1674 lstrcpyn(pItem
->pszText
, static_cast<LPCWSTR
>(MessageDisplayStr(pLogEntry
)), pItem
->cchTextMax
- 1);
1676 case LOGLIST_AUTHOR
: //Author
1677 lstrcpyn(pItem
->pszText
, static_cast<LPCWSTR
>(pLogEntry
->GetAuthorName()), pItem
->cchTextMax
- 1);
1679 case LOGLIST_DATE
: //Date
1680 if (!pLogEntry
->m_CommitHash
.IsEmpty())
1681 lstrcpyn(pItem
->pszText
,
1682 CLoglistUtils::FormatDateAndTime(pLogEntry
->GetAuthorDate(), m_DateFormat
, true, m_bRelativeTimes
),
1683 pItem
->cchTextMax
- 1);
1687 lstrcpyn(pItem
->pszText
, static_cast<LPCWSTR
>(pLogEntry
->GetAuthorEmail()), pItem
->cchTextMax
- 1);
1690 case LOGLIST_COMMIT_NAME
: //Commit
1691 lstrcpyn(pItem
->pszText
, static_cast<LPCWSTR
>(pLogEntry
->GetCommitterName()), pItem
->cchTextMax
- 1);
1694 case LOGLIST_COMMIT_EMAIL
: //Commit Email
1695 lstrcpyn(pItem
->pszText
, static_cast<LPCWSTR
>(pLogEntry
->GetCommitterEmail()), pItem
->cchTextMax
- 1);
1698 case LOGLIST_COMMIT_DATE
: //Commit Date
1699 if (!pLogEntry
->m_CommitHash
.IsEmpty())
1700 lstrcpyn(pItem
->pszText
,
1701 CLoglistUtils::FormatDateAndTime(pLogEntry
->GetCommitterDate(), m_DateFormat
, true, m_bRelativeTimes
),
1702 pItem
->cchTextMax
- 1);
1704 case LOGLIST_BUG
: //Bug ID
1705 lstrcpyn(pItem
->pszText
, static_cast<LPCWSTR
>(this->m_ProjectProperties
.FindBugID(pLogEntry
->GetSubjectBody())), pItem
->cchTextMax
- 1);
1707 case LOGLIST_SVNREV
: //SVN revision
1708 lstrcpyn(pItem
->pszText
, static_cast<LPCWSTR
>(FindSVNRev(pLogEntry
->GetSubjectBody())), pItem
->cchTextMax
- 1);
1716 bool CGitLogListBase::IsOnStash(int index
)
1718 GitRevLoglist
* rev
= m_arShownList
.SafeGetAt(index
);
1723 GitRevLoglist
* preRev
= m_arShownList
.SafeGetAt(index
- 1);
1724 if (IsStash(preRev
))
1725 return preRev
->m_ParentHash
.size() == 2 && preRev
->m_ParentHash
[1] == rev
->m_CommitHash
;
1730 bool CGitLogListBase::IsStash(const GitRev
* pSelLogEntry
)
1732 auto hashMap
= m_HashMap
;
1733 const auto refList
= hashMap
.get()->find(pSelLogEntry
->m_CommitHash
);
1734 if (refList
== hashMap
.get()->cend())
1736 return any_of((*refList
).second
, [](const auto& ref
) { return ref
== L
"refs/stash"; });
1739 bool CGitLogListBase::IsBisect(const GitRev
* pSelLogEntry
)
1741 auto hashMap
= m_HashMap
;
1742 const auto refList
= hashMap
->find(pSelLogEntry
->m_CommitHash
);
1743 if (refList
== hashMap
->cend())
1745 return any_of((*refList
).second
, [](const auto& ref
) { return CStringUtils::StartsWith(ref
, L
"refs/bisect/"); });
1748 void CGitLogListBase::GetParentHashes(GitRev
*pRev
, GIT_REV_LIST
&parentHash
)
1750 if (pRev
->m_ParentHash
.empty() && !pRev
->m_CommitHash
.IsEmpty())
1752 if (pRev
->GetParentFromHash(pRev
->m_CommitHash
))
1753 MessageBox(pRev
->GetLastErr(), L
"TortoiseGit", MB_ICONERROR
);
1755 parentHash
= pRev
->m_ParentHash
;
1758 void CGitLogListBase::OnContextMenu(CWnd
* pWnd
, CPoint point
)
1760 __super::OnContextMenu(pWnd
, point
);
1765 int selIndex
= GetSelectionMark();
1767 return; // nothing selected, nothing to do with a context menu
1769 // if the context menu is invoked through the keyboard, we have to use
1770 // a calculated position on where to anchor the menu on
1771 if ((point
.x
== -1) && (point
.y
== -1))
1774 GetItemRect(selIndex
, &rect
, LVIR_LABEL
);
1775 ClientToScreen(&rect
);
1776 point
= rect
.CenterPoint();
1778 m_nSearchIndex
= selIndex
;
1780 bool showExtendedMenu
= (GetAsyncKeyState(VK_SHIFT
) & 0x8000) != 0;
1782 POSITION pos
= GetFirstSelectedItemPosition();
1783 int FirstSelect
= GetNextSelectedItem(pos
);
1784 if (FirstSelect
< 0)
1787 GitRevLoglist
* pSelLogEntry
= m_arShownList
.SafeGetAt(FirstSelect
);
1788 if (pSelLogEntry
== nullptr)
1791 int LastSelect
= -1;
1792 UINT selectedCount
= 1;
1795 LastSelect
= GetNextSelectedItem(pos
);
1799 ASSERT(GetSelectedCount() == selectedCount
);
1801 //entry is selected, now show the popup menu
1803 CIconMenu subbranchmenu
, submenu
, gnudiffmenu
, diffmenu
, blamemenu
, revertmenu
;
1805 if (popup
.CreatePopupMenu())
1808 if (g_Git
.GetHash(headHash
, L
"HEAD"))
1810 MessageBox(g_Git
.GetGitLastErr(L
"Could not get HEAD hash."), L
"TortoiseGit", MB_ICONERROR
);
1813 auto hashMapSharedPtr
= m_HashMap
;
1814 const auto& hashMap
= *hashMapSharedPtr
;
1815 bool isHeadCommit
= (pSelLogEntry
->m_CommitHash
== headHash
);
1816 CString currentBranch
= L
"refs/heads/" + g_Git
.GetCurrentBranch();
1817 CTGitPath
workingTree(g_Git
.m_CurrentDir
);
1818 bool isMergeActive
= workingTree
.IsMergeActive();
1819 bool isBisectActive
= workingTree
.IsBisectActive();
1820 bool isStash
= IsOnStash(FirstSelect
);
1821 GIT_REV_LIST parentHash
;
1822 GetParentHashes(pSelLogEntry
, parentHash
);
1823 STRING_VECTOR parentInfo
;
1824 for (size_t i
= 0; i
< parentHash
.size(); ++i
)
1827 str
.Format(IDS_PARENT
, i
+ 1);
1829 if (rev
.GetCommit(parentHash
[i
].ToString()) == 0)
1831 CString commitTitle
= rev
.GetSubject();
1832 if (commitTitle
.GetLength() > 20)
1834 commitTitle
.Truncate(20);
1835 commitTitle
+= L
"...";
1837 commitTitle
.Replace(L
"&", L
"&&");
1838 str
.AppendFormat(L
": \"%s\" (%s)", static_cast<LPCWSTR
>(commitTitle
), static_cast<LPCWSTR
>(parentHash
[i
].ToString(g_Git
.GetShortHASHLength())));
1841 str
.AppendFormat(L
" (%s)", static_cast<LPCWSTR
>(parentHash
[i
].ToString(g_Git
.GetShortHASHLength())));
1842 parentInfo
.push_back(str
);
1845 if (m_ContextMenuMask
& GetContextMenuBit(ID_REBASE_PICK
) && !(pSelLogEntry
->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT
| LOGACTIONS_REBASE_DONE
)))
1846 popup
.AppendMenuIcon(ID_REBASE_PICK
, IDS_REBASE_PICK
, IDI_PICK
);
1848 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))
1849 popup
.AppendMenuIcon(ID_REBASE_SQUASH
, IDS_REBASE_SQUASH
, IDI_SQUASH
);
1851 if (m_ContextMenuMask
& GetContextMenuBit(ID_REBASE_EDIT
) && !(pSelLogEntry
->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT
| LOGACTIONS_REBASE_DONE
)))
1852 popup
.AppendMenuIcon(ID_REBASE_EDIT
, IDS_REBASE_EDIT
, IDI_EDIT
);
1854 if (m_ContextMenuMask
& GetContextMenuBit(ID_REBASE_SKIP
) && !(pSelLogEntry
->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT
| LOGACTIONS_REBASE_DONE
)))
1855 popup
.AppendMenuIcon(ID_REBASE_SKIP
, IDS_REBASE_SKIP
, IDI_SKIP
);
1857 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
)))
1858 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1860 if (selectedCount
== 1)
1863 bool requiresSeparator
= false;
1864 if( !pSelLogEntry
->m_CommitHash
.IsEmpty())
1866 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPARE
) && m_hasWC
) // compare revision with WC
1868 popup
.AppendMenuIcon(ID_COMPARE
, IDS_LOG_POPUP_COMPARE
, IDI_DIFF
);
1869 requiresSeparator
= true;
1874 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMMIT
))
1876 popup
.AppendMenuIcon(ID_COMMIT
, IDS_LOG_POPUP_COMMIT
, IDI_COMMIT
);
1877 requiresSeparator
= true;
1879 if (isMergeActive
&& (m_ContextMenuMask
& GetContextMenuBit(ID_MERGE_ABORT
)))
1881 popup
.AppendMenuIcon(ID_MERGE_ABORT
, IDS_MENUMERGEABORT
, IDI_MERGEABORT
);
1882 requiresSeparator
= true;
1886 if (m_ContextMenuMask
& GetContextMenuBit(ID_BLAMEPREVIOUS
))
1888 if (parentHash
.size() == 1)
1890 popup
.AppendMenuIcon(ID_BLAMEPREVIOUS
, IDS_LOG_POPUP_BLAMEPREVIOUS
, IDI_BLAME
);
1891 requiresSeparator
= true;
1893 else if (parentHash
.size() > 1)
1895 blamemenu
.CreatePopupMenu();
1896 popup
.AppendMenuIcon(ID_BLAMEPREVIOUS
, IDS_LOG_POPUP_BLAMEPREVIOUS
, IDI_BLAME
, blamemenu
.m_hMenu
);
1897 for (size_t i
= 0; i
< parentInfo
.size(); ++i
)
1899 blamemenu
.AppendMenuIcon(ID_BLAMEPREVIOUS
+ ((i
+ 1) << 16), parentInfo
[i
]);
1901 requiresSeparator
= true;
1905 if(m_ContextMenuMask
&GetContextMenuBit(ID_GNUDIFF1
) && m_hasWC
) // compare with WC, unified
1907 if (parentHash
.size() == 1)
1909 popup
.AppendMenuIcon(ID_GNUDIFF1
, IDS_LOG_POPUP_GNUDIFF
, IDI_DIFF
);
1910 requiresSeparator
= true;
1912 else if (parentHash
.size() > 1)
1914 gnudiffmenu
.CreatePopupMenu();
1915 popup
.AppendMenuIcon(ID_GNUDIFF1
,IDS_LOG_POPUP_GNUDIFF_PARENT
, IDI_DIFF
, gnudiffmenu
.m_hMenu
);
1917 gnudiffmenu
.AppendMenuIcon(static_cast<UINT_PTR
>(ID_GNUDIFF1
+ (0xFFFF << 16)), CString(MAKEINTRESOURCE(IDS_ALLPARENTS
)));
1918 gnudiffmenu
.AppendMenuIcon(static_cast<UINT_PTR
>(ID_GNUDIFF1
+ (0xFFFE << 16)), CString(MAKEINTRESOURCE(IDS_ONLYMERGEDFILES
)));
1919 gnudiffmenu
.AppendMenuIcon(static_cast<UINT_PTR
>(ID_GNUDIFF1
+ (0xFFFD << 16)), CString(MAKEINTRESOURCE(IDS_DIFFWITHMERGE
)));
1921 for (size_t i
= 0; i
< parentInfo
.size(); ++i
)
1923 gnudiffmenu
.AppendMenuIcon(ID_GNUDIFF1
+ ((i
+ 1) << 16), parentInfo
[i
]);
1925 requiresSeparator
= true;
1929 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPAREWITHPREVIOUS
))
1931 if (parentHash
.size() == 1)
1933 popup
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
, IDS_LOG_POPUP_COMPAREWITHPREVIOUS
, IDI_DIFF
);
1934 if (CRegDWORD(L
"Software\\TortoiseGit\\DiffByDoubleClickInLog", FALSE
) && m_ColumnRegKey
!= L
"reflog")
1935 popup
.SetDefaultItem(ID_COMPAREWITHPREVIOUS
, FALSE
);
1936 requiresSeparator
= true;
1938 else if (parentHash
.size() > 1)
1940 diffmenu
.CreatePopupMenu();
1941 popup
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
, IDS_LOG_POPUP_COMPAREWITHPREVIOUS
, IDI_DIFF
, diffmenu
.m_hMenu
);
1942 for (size_t i
= 0; i
< parentInfo
.size(); ++i
)
1944 diffmenu
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
+ ((i
+ 1) << 16), parentInfo
[i
]);
1945 if (i
== 0 && CRegDWORD(L
"Software\\TortoiseGit\\DiffByDoubleClickInLog", FALSE
) && m_ColumnRegKey
!= L
"reflog")
1947 popup
.SetDefaultItem(ID_COMPAREWITHPREVIOUS
, FALSE
);
1948 diffmenu
.SetDefaultItem(static_cast<UINT
>(ID_COMPAREWITHPREVIOUS
+ ((i
+ 1) << 16)), FALSE
);
1951 requiresSeparator
= true;
1955 if(m_ContextMenuMask
&GetContextMenuBit(ID_BLAME
))
1957 popup
.AppendMenuIcon(ID_BLAME
, IDS_LOG_POPUP_BLAME
, IDI_BLAME
);
1958 requiresSeparator
= true;
1961 if (requiresSeparator
)
1963 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1964 requiresSeparator
= false;
1967 if (pSelLogEntry
->m_CommitHash
.IsEmpty() && !isMergeActive
)
1969 if(m_ContextMenuMask
&GetContextMenuBit(ID_STASH_SAVE
))
1971 popup
.AppendMenuIcon(ID_STASH_SAVE
, IDS_MENUSTASHSAVE
, IDI_SHELVE
);
1972 requiresSeparator
= true;
1976 if ((pSelLogEntry
->m_CommitHash
.IsEmpty() || isStash
) && workingTree
.HasStashDir())
1978 if (m_ContextMenuMask
&GetContextMenuBit(ID_STASH_POP
))
1980 popup
.AppendMenuIcon(ID_STASH_POP
, IDS_MENUSTASHPOP
, IDI_UNSHELVE
);
1981 requiresSeparator
= true;
1984 if (m_ContextMenuMask
&GetContextMenuBit(ID_STASH_LIST
))
1986 popup
.AppendMenuIcon(ID_STASH_LIST
, IDS_MENUSTASHLIST
, IDI_LOG
);
1987 requiresSeparator
= true;
1991 if (requiresSeparator
)
1993 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1994 requiresSeparator
= false;
1999 GitRevLoglist
* pFirstEntry
= m_arShownList
.SafeGetAt(FirstSelect
);
2000 if (m_ContextMenuMask
&GetContextMenuBit(ID_BISECTGOOD
) && !IsBisect(pFirstEntry
))
2002 popup
.AppendMenuIcon(ID_BISECTGOOD
, IDS_MENUBISECTGOOD
, IDI_THUMB_UP
);
2003 requiresSeparator
= true;
2006 if (m_ContextMenuMask
&GetContextMenuBit(ID_BISECTBAD
) && !IsBisect(pFirstEntry
))
2008 popup
.AppendMenuIcon(ID_BISECTBAD
, IDS_MENUBISECTBAD
, IDI_THUMB_DOWN
);
2009 requiresSeparator
= true;
2011 if (m_ContextMenuMask
&GetContextMenuBit(ID_BISECTSKIP
) && !IsBisect(pFirstEntry
))
2013 popup
.AppendMenuIcon(ID_BISECTSKIP
, IDS_MENUBISECTSKIP
, IDI_BISECT
);
2014 requiresSeparator
= true;
2018 if (pSelLogEntry
->m_CommitHash
.IsEmpty() && isBisectActive
)
2020 if (m_ContextMenuMask
&GetContextMenuBit(ID_BISECTRESET
))
2022 popup
.AppendMenuIcon(ID_BISECTRESET
, IDS_MENUBISECTRESET
, IDI_BISECT_RESET
);
2023 requiresSeparator
= true;
2027 if (requiresSeparator
)
2029 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2030 requiresSeparator
= false;
2033 if (pSelLogEntry
->m_CommitHash
.IsEmpty())
2035 if (m_ContextMenuMask
& GetContextMenuBit(ID_PULL
) && !isMergeActive
)
2036 popup
.AppendMenuIcon(ID_PULL
, IDS_MENUPULL
, IDI_PULL
);
2038 if(m_ContextMenuMask
&GetContextMenuBit(ID_FETCH
))
2039 popup
.AppendMenuIcon(ID_FETCH
, IDS_MENUFETCH
, IDI_UPDATE
);
2041 if ((m_ContextMenuMask
& GetContextMenuBit(ID_SUBMODULE_UPDATE
)) && workingTree
.HasSubmodules())
2042 popup
.AppendMenuIcon(ID_SUBMODULE_UPDATE
, IDS_PROC_SYNC_SUBKODULEUPDATE
, IDI_UPDATE
);
2044 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2046 if (m_ContextMenuMask
& GetContextMenuBit(ID_CLEANUP
))
2047 popup
.AppendMenuIcon(ID_CLEANUP
, IDS_MENUCLEANUP
, IDI_CLEANUP
);
2049 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2053 // if (!m_ProjectProperties.sWebViewerRev.IsEmpty())
2055 // popup.AppendMenuIcon(ID_VIEWREV, IDS_LOG_POPUP_VIEWREV);
2057 // if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
2059 // popup.AppendMenuIcon(ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
2061 // if ((!m_ProjectProperties.sWebViewerPathRev.IsEmpty())||
2062 // (!m_ProjectProperties.sWebViewerRev.IsEmpty()))
2064 // popup.AppendMenu(MF_SEPARATOR, NULL);
2069 // popup.AppendMenuIcon(ID_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
2071 if(!pSelLogEntry
->m_CommitHash
.IsEmpty())
2073 if (m_ContextMenuMask
& GetContextMenuBit(ID_LOG
))
2075 popup
.AppendMenuIcon(ID_LOG
, IDS_LOG_POPUP_LOG
, IDI_LOG
);
2076 if (m_ColumnRegKey
== L
"reflog")
2077 popup
.SetDefaultItem(ID_LOG
, FALSE
);
2080 if (m_ContextMenuMask
&GetContextMenuBit(ID_REPOBROWSE
))
2081 popup
.AppendMenuIcon(ID_REPOBROWSE
, IDS_LOG_BROWSEREPO
, IDI_REPOBROWSE
);
2083 str
.Format(IDS_LOG_POPUP_MERGEREV
, static_cast<LPCWSTR
>(g_Git
.GetCurrentBranch()));
2085 if (m_ContextMenuMask
&GetContextMenuBit(ID_MERGEREV
) && !isHeadCommit
&& m_hasWC
&& !isMergeActive
&& !isStash
)
2087 popup
.AppendMenuIcon(ID_MERGEREV
, str
, IDI_MERGE
);
2089 size_t index
= static_cast<size_t>(-1);
2090 CGit::REF_TYPE type
= CGit::REF_TYPE::UNKNOWN
;
2091 if (IsMouseOnRefLabelFromPopupMenu(pSelLogEntry
, point
, type
, hashMap
, nullptr, &index
))
2092 popup
.SetMenuItemData(ID_MERGEREV
, reinterpret_cast<LONG_PTR
>(&hashMap
.find(pSelLogEntry
->m_CommitHash
)->second
[index
]));
2095 str
.Format(IDS_RESET_TO_THIS_FORMAT
, static_cast<LPCWSTR
>(g_Git
.GetCurrentBranch()));
2097 if (m_ContextMenuMask
&GetContextMenuBit(ID_RESET
) && m_hasWC
&& !isStash
)
2098 popup
.AppendMenuIcon(ID_RESET
, str
, IDI_RESET
);
2101 // Add Switch Branch express Menu
2102 if (hashMap
.find(pSelLogEntry
->m_CommitHash
) != hashMap
.end()
2103 && (m_ContextMenuMask
&GetContextMenuBit(ID_SWITCHBRANCH
) && m_hasWC
&& !isStash
)
2106 std::vector
<const CString
*> branchs
;
2107 auto addCheck
= [&](const CString
& ref
)
2109 if (!CStringUtils::StartsWith(ref
, L
"refs/heads/") || ref
== currentBranch
)
2111 branchs
.push_back(&ref
);
2113 size_t index
= static_cast<size_t>(-1);
2114 CGit::REF_TYPE type
= CGit::REF_TYPE::UNKNOWN
;
2115 if (IsMouseOnRefLabelFromPopupMenu(pSelLogEntry
, point
, type
, hashMap
, nullptr, &index
))
2116 addCheck(hashMap
.find(pSelLogEntry
->m_CommitHash
)->second
[index
]);
2118 for_each(hashMap
.find(pSelLogEntry
->m_CommitHash
)->second
, addCheck
);
2121 str2
.LoadString(IDS_SWITCH_BRANCH
);
2123 if(branchs
.size() == 1)
2126 str2
+= L
'"' + branchs
[0]->Mid(static_cast<int>(wcslen(L
"refs/heads/"))) + L
'"';
2127 popup
.AppendMenuIcon(ID_SWITCHBRANCH
, str2
, IDI_SWITCH
);
2129 popup
.SetMenuItemData(ID_SWITCHBRANCH
, reinterpret_cast<LONG_PTR
>(branchs
[0]));
2132 else if(branchs
.size() > 1)
2134 subbranchmenu
.CreatePopupMenu();
2135 for (size_t i
= 0 ; i
< branchs
.size(); ++i
)
2137 if (*branchs
[i
] != currentBranch
)
2139 subbranchmenu
.AppendMenuIcon(ID_SWITCHBRANCH
+ (i
<< 16), branchs
[i
]->Mid(static_cast<int>(wcslen(L
"refs/heads/"))));
2140 subbranchmenu
.SetMenuItemData(ID_SWITCHBRANCH
+(i
<<16), reinterpret_cast<LONG_PTR
>(branchs
[i
]));
2144 popup
.AppendMenuIcon(ID_SWITCHBRANCH
, str2
, IDI_SWITCH
, subbranchmenu
.m_hMenu
);
2148 if (m_ContextMenuMask
&GetContextMenuBit(ID_SWITCHTOREV
) && !isHeadCommit
&& m_hasWC
&& !isStash
)
2150 popup
.AppendMenuIcon(ID_SWITCHTOREV
, IDS_SWITCH_TO_THIS
, IDI_SWITCH
);
2151 size_t index
= static_cast<size_t>(-1);
2152 CGit::REF_TYPE type
= CGit::REF_TYPE::UNKNOWN
;
2153 if (IsMouseOnRefLabelFromPopupMenu(pSelLogEntry
, point
, type
, hashMap
, nullptr, &index
))
2154 popup
.SetMenuItemData(ID_SWITCHTOREV
, reinterpret_cast<LONG_PTR
>(&hashMap
.find(pSelLogEntry
->m_CommitHash
)->second
[index
]));
2157 if (m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_BRANCH
) && !isStash
)
2159 popup
.AppendMenuIcon(ID_CREATE_BRANCH
, IDS_CREATE_BRANCH_AT_THIS
, IDI_COPY
);
2161 size_t index
= static_cast<size_t>(-1);
2162 CGit::REF_TYPE type
= CGit::REF_TYPE::REMOTE_BRANCH
;
2163 if (IsMouseOnRefLabelFromPopupMenu(pSelLogEntry
, point
, type
, hashMap
, nullptr, &index
))
2164 popup
.SetMenuItemData(ID_CREATE_BRANCH
, reinterpret_cast<LONG_PTR
>(&hashMap
.find(pSelLogEntry
->m_CommitHash
)->second
[index
]));
2167 if (m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_TAG
) && !isStash
)
2168 popup
.AppendMenuIcon(ID_CREATE_TAG
,IDS_CREATE_TAG_AT_THIS
, IDI_TAG
);
2170 str
.Format(IDS_REBASE_THIS_FORMAT
, static_cast<LPCWSTR
>(g_Git
.GetCurrentBranch()));
2172 if (pSelLogEntry
->m_CommitHash
!= headHash
&& m_hasWC
&& !isMergeActive
&& !isStash
)
2173 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_TO_VERSION
))
2174 popup
.AppendMenuIcon(ID_REBASE_TO_VERSION
, str
, IDI_REBASE
);
2176 if(m_ContextMenuMask
&GetContextMenuBit(ID_EXPORT
))
2177 popup
.AppendMenuIcon(ID_EXPORT
,IDS_EXPORT_TO_THIS
, IDI_EXPORT
);
2179 if (m_ContextMenuMask
&GetContextMenuBit(ID_REVERTREV
) && m_hasWC
&& !isMergeActive
&& !isStash
)
2181 if (parentHash
.size() == 1)
2182 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREV
, IDI_REVERT
);
2183 else if (parentHash
.size() > 1)
2185 revertmenu
.CreatePopupMenu();
2186 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREV
, IDI_REVERT
, revertmenu
.m_hMenu
);
2188 for (size_t i
= 0; i
< parentInfo
.size(); ++i
)
2190 revertmenu
.AppendMenuIcon(ID_REVERTREV
+ ((i
+ 1) << 16), parentInfo
[i
]);
2195 if (m_ContextMenuMask
&GetContextMenuBit(ID_EDITNOTE
) && !isStash
)
2196 popup
.AppendMenuIcon(ID_EDITNOTE
, IDS_EDIT_NOTES
, IDI_EDIT
);
2198 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2202 if(!pSelLogEntry
->m_Ref
.IsEmpty())
2204 popup
.AppendMenuIcon(ID_REFLOG_DEL
, IDS_REFLOG_DEL
, IDI_DELETE
);
2205 if (selectedCount
== 1 && CStringUtils::StartsWith(pSelLogEntry
->m_Ref
, L
"refs/stash"))
2206 popup
.AppendMenuIcon(ID_REFLOG_STASH_APPLY
, IDS_MENUSTASHAPPLY
, IDI_UNSHELVE
);
2207 if (selectedCount
<= 2)
2208 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2211 if (selectedCount
>= 2)
2213 bool bAddSeparator
= false;
2214 if ((selectedCount
== 2) || IsSelectionContinuous())
2216 if (m_ContextMenuMask
&GetContextMenuBit(ID_COMPARETWO
)) // compare two revisions
2218 popup
.AppendMenuIcon(ID_COMPARETWO
, IDS_LOG_POPUP_COMPARETWO
, IDI_DIFF
);
2219 bAddSeparator
= true;
2223 if (selectedCount
== 2)
2225 if (m_ContextMenuMask
&GetContextMenuBit(ID_GNUDIFF2
) && m_hasWC
) // compare two revisions, unified
2227 popup
.AppendMenuIcon(ID_GNUDIFF2
, IDS_LOG_POPUP_GNUDIFF
, IDI_DIFF
);
2228 bAddSeparator
= true;
2231 if (!pSelLogEntry
->m_CommitHash
.IsEmpty())
2233 CString firstSelHash
= pSelLogEntry
->m_CommitHash
.ToString(g_Git
.GetShortHASHLength());
2234 GitRevLoglist
* pLastEntry
= m_arShownList
.SafeGetAt(LastSelect
);
2235 CString lastSelHash
= pLastEntry
->m_CommitHash
.ToString(g_Git
.GetShortHASHLength());
2237 menu
.Format(IDS_SHOWLOG_OF
, static_cast<LPCWSTR
>(lastSelHash
+ L
".." + firstSelHash
));
2238 popup
.AppendMenuIcon(ID_LOG_VIEWRANGE
, menu
, IDI_LOG
);
2239 menu
.Format(IDS_SHOWLOG_OF
, static_cast<LPCWSTR
>(lastSelHash
+ L
"..." + firstSelHash
));
2240 popup
.AppendMenuIcon(ID_LOG_VIEWRANGE_REACHABLEFROMONLYONE
, menu
, IDI_LOG
);
2241 bAddSeparator
= true;
2245 if ((m_ContextMenuMask
& GetContextMenuBit(ID_COMPARETWOCOMMITCHANGES
)) && selectedCount
== 2)
2247 bAddSeparator
= true;
2248 popup
.AppendMenuIcon(ID_COMPARETWOCOMMITCHANGES
, IDS_LOG_POPUP_COMPARECHANGESET
, IDI_DIFF
);
2253 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2254 bAddSeparator
= false;
2257 if (m_ContextMenuMask
&GetContextMenuBit(ID_REVERTREV
) && m_hasWC
&& !isMergeActive
)
2258 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREVS
, IDI_REVERT
);
2261 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2264 if (selectedCount
> 1 && isBisectActive
&& (m_ContextMenuMask
& GetContextMenuBit(ID_BISECTSKIP
)) && !IsBisect(pSelLogEntry
))
2266 popup
.AppendMenuIcon(ID_BISECTSKIP
, IDS_MENUBISECTSKIP
, IDI_BISECT
);
2267 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2270 if (!pSelLogEntry
->m_CommitHash
.IsEmpty())
2272 bool bAddSeparator
= false;
2273 if (selectedCount
>= 2 && IsSelectionContinuous())
2275 if (m_ContextMenuMask
&GetContextMenuBit(ID_COMBINE_COMMIT
) && m_hasWC
&& !isMergeActive
)
2277 int headindex
= this->GetHeadIndex();
2278 if(headindex
>=0 && LastSelect
>= headindex
&& FirstSelect
>= headindex
)
2281 head
.Format(L
"HEAD~%d", FirstSelect
- headindex
);
2283 int ret
= g_Git
.GetHash(hashFirst
, head
);
2284 head
.Format(L
"HEAD~%d",LastSelect
-headindex
);
2286 ret
= ret
|| g_Git
.GetHash(hash
, head
);
2287 GitRevLoglist
* pFirstEntry
= m_arShownList
.SafeGetAt(FirstSelect
);
2288 GitRevLoglist
* pLastEntry
= m_arShownList
.SafeGetAt(LastSelect
);
2289 if (!ret
&& pFirstEntry
->m_CommitHash
== hashFirst
&& pLastEntry
->m_CommitHash
== hash
)
2291 popup
.AppendMenuIcon(ID_COMBINE_COMMIT
,IDS_COMBINE_TO_ONE
,IDI_COMBINE
);
2292 bAddSeparator
= true;
2297 if (m_ContextMenuMask
&GetContextMenuBit(ID_CHERRY_PICK
) && !isHeadCommit
&& m_hasWC
&& !isMergeActive
) {
2298 if (selectedCount
>= 2)
2299 popup
.AppendMenuIcon(ID_CHERRY_PICK
, IDS_CHERRY_PICK_VERSIONS
, IDI_CHERRYPICK
);
2301 popup
.AppendMenuIcon(ID_CHERRY_PICK
, IDS_CHERRY_PICK_VERSION
, IDI_CHERRYPICK
);
2302 bAddSeparator
= true;
2305 if (!isStash
&& (selectedCount
<= 2 || IsSelectionContinuous()))
2306 if(m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_PATCH
)) {
2307 popup
.AppendMenuIcon(ID_CREATE_PATCH
, IDS_CREATE_PATCH
, IDI_PATCH
);
2308 bAddSeparator
= true;
2312 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2315 if (m_hasWC
&& !isMergeActive
&& !isStash
&& (m_ContextMenuMask
& GetContextMenuBit(ID_BISECTSTART
)) && selectedCount
== 2 && !m_arShownList
.SafeGetAt(FirstSelect
)->m_CommitHash
.IsEmpty() && !isBisectActive
)
2317 popup
.AppendMenuIcon(ID_BISECTSTART
, IDS_MENUBISECTSTART
, IDI_BISECT
);
2318 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2321 if (selectedCount
== 1)
2323 bool bAddSeparator
= false;
2324 if ((m_ContextMenuMask
& GetContextMenuBit(ID_PUSH
)) && ((!isStash
&& hashMap
.find(pSelLogEntry
->m_CommitHash
) != hashMap
.cend()) || showExtendedMenu
))
2326 // show the push-option only if the log entry has an associated local branch
2327 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/"); });
2328 if (isLocal
|| showExtendedMenu
)
2331 str
.LoadString(IDS_MENUPUSH
);
2334 size_t index
= static_cast<size_t>(-1);
2335 CGit::REF_TYPE type
= CGit::REF_TYPE::UNKNOWN
;
2336 if (IsMouseOnRefLabelFromPopupMenu(pSelLogEntry
, point
, type
, hashMap
, &branch
, &index
))
2337 if (type
== CGit::REF_TYPE::LOCAL_BRANCH
|| type
== CGit::REF_TYPE::ANNOTATED_TAG
|| type
== CGit::REF_TYPE::TAG
)
2338 str
.Insert(str
.Find(L
'.'), L
" \"" + branch
+ L
'"');
2340 popup
.AppendMenuIcon(ID_PUSH
, str
, IDI_PUSH
);
2342 if (auto refList
= hashMap
.find(pSelLogEntry
->m_CommitHash
); index
!= static_cast<size_t>(-1) && index
< refList
->second
.size())
2343 popup
.SetMenuItemData(ID_PUSH
, reinterpret_cast<LONG_PTR
>(&refList
->second
[index
]));
2345 if (m_ContextMenuMask
& GetContextMenuBit(ID_SVNDCOMMIT
) && workingTree
.HasGitSVNDir())
2346 popup
.AppendMenuIcon(ID_SVNDCOMMIT
, IDS_MENUSVNDCOMMIT
, IDI_COMMIT
);
2348 bAddSeparator
= true;
2351 if (m_ContextMenuMask
& GetContextMenuBit(ID_PULL
) && isHeadCommit
&& !isMergeActive
&& m_hasWC
)
2353 popup
.AppendMenuIcon(ID_PULL
, IDS_MENUPULL
, IDI_PULL
);
2354 bAddSeparator
= true;
2358 if(m_ContextMenuMask
&GetContextMenuBit(ID_DELETE
))
2360 if (auto refList
= hashMap
.find(pSelLogEntry
->m_CommitHash
); refList
!= hashMap
.end() )
2362 std::vector
<const CString
*> branchs
;
2363 auto addCheck
= [&](const CString
& ref
)
2365 if (ref
== currentBranch
)
2367 branchs
.push_back(&ref
);
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 addCheck(refList
->second
[index
]);
2374 for_each(refList
->second
, addCheck
);
2377 if (branchs
.size() == 1)
2379 str
.LoadString(IDS_DELETE_BRANCHTAG_SHORT
);
2382 popup
.AppendMenuIcon(ID_DELETE
, str
, IDI_DELETE
);
2383 popup
.SetMenuItemData(ID_DELETE
, reinterpret_cast<LONG_PTR
>(branchs
[0]));
2384 bAddSeparator
= true;
2386 else if (branchs
.size() > 1)
2388 str
.LoadString(IDS_DELETE_BRANCHTAG
);
2389 submenu
.CreatePopupMenu();
2390 for (size_t i
= 0; i
< branchs
.size(); ++i
)
2392 submenu
.AppendMenuIcon(ID_DELETE
+ (i
<< 16), *branchs
[i
]);
2393 submenu
.SetMenuItemData(ID_DELETE
+ (i
<< 16), reinterpret_cast<LONG_PTR
>(branchs
[i
]));
2395 submenu
.AppendMenuIcon(ID_DELETE
+ (branchs
.size() << 16), IDS_ALL
);
2396 submenu
.SetMenuItemData(ID_DELETE
+ (branchs
.size() << 16), reinterpret_cast<LONG_PTR
>(MAKEINTRESOURCE(IDS_ALL
)));
2398 popup
.AppendMenuIcon(ID_DELETE
,str
, IDI_DELETE
, submenu
.m_hMenu
);
2399 bAddSeparator
= true;
2402 } // m_ContextMenuMask &GetContextMenuBit(ID_DELETE)
2404 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2406 if ((m_ContextMenuMask
& GetContextMenuBit(ID_TOGGLE_ROLLUP
)) && (m_ShowFilter
& FILTERSHOW_MERGEPOINTS
) && !m_LogFilter
->IsFilterActive() && !pSelLogEntry
->m_CommitHash
.IsEmpty())
2408 popup
.AppendMenuIcon(ID_TOGGLE_ROLLUP
, pSelLogEntry
->m_RolledUp
? IDS_LOG_POPUP_EXPAND
: IDS_LOG_POPUP_COLLAPSE
);
2409 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2412 } // selectedCount == 1
2414 CIconMenu clipSubMenu
;
2415 if (!clipSubMenu
.CreatePopupMenu())
2417 if (m_ContextMenuMask
& GetContextMenuBit(ID_COPYCLIPBOARD
) && m_ColumnRegKey
!= L
"reflog")
2419 clipSubMenu
.AppendMenuIcon(ID_COPYCLIPBOARDFULL
, IDS_LOG_POPUP_CLIPBOARD_FULL
, IDI_COPYCLIP
);
2420 clipSubMenu
.AppendMenuIcon(ID_COPYCLIPBOARDFULLNOPATHS
, IDS_LOG_POPUP_CLIPBOARD_FULLNOPATHS
, IDI_COPYCLIP
);
2421 clipSubMenu
.AppendMenuIcon(ID_COPYCLIPBOARDHASH
, IDS_LOG_HASH
, IDI_COPYCLIP
);
2422 clipSubMenu
.AppendMenuIcon(ID_COPYCLIPBOARDAUTHORSFULL
, IDS_LOG_POPUP_CLIPBOARD_AUTHORSFULL
, IDI_COPYCLIP
);
2423 clipSubMenu
.AppendMenuIcon(ID_COPYCLIPBOARDAUTHORSNAME
, IDS_LOG_POPUP_CLIPBOARD_AUTHORSNAME
, IDI_COPYCLIP
);
2424 clipSubMenu
.AppendMenuIcon(ID_COPYCLIPBOARDAUTHORSEMAIL
, IDS_LOG_POPUP_CLIPBOARD_AUTHORSEMAIL
, IDI_COPYCLIP
);
2425 clipSubMenu
.AppendMenuIcon(ID_COPYCLIPBOARDSUBJECTS
, IDS_LOG_POPUP_CLIPBOARD_SUBJECTS
, IDI_COPYCLIP
);
2426 clipSubMenu
.AppendMenuIcon(ID_COPYCLIPBOARDMESSAGES
, IDS_LOG_POPUP_CLIPBOARD_MSGS
, IDI_COPYCLIP
);
2427 if (hashMap
.find(pSelLogEntry
->m_CommitHash
) != hashMap
.cend() && selectedCount
== 1)
2429 clipSubMenu
.AppendMenuIcon(ID_COPYCLIPBOARDBRANCHTAG
, IDS_LOG_POPUP_CLIPBOARD_TAGBRANCHES
, IDI_COPYCLIP
);
2430 size_t index
= static_cast<size_t>(-1);
2431 CGit::REF_TYPE type
= CGit::REF_TYPE::UNKNOWN
;
2432 if (IsMouseOnRefLabelFromPopupMenu(pSelLogEntry
, point
, type
, hashMap
, nullptr, &index
))
2433 clipSubMenu
.SetMenuItemData(ID_COPYCLIPBOARDBRANCHTAG
, reinterpret_cast<LONG_PTR
>(&hashMap
.find(pSelLogEntry
->m_CommitHash
)->second
[index
]));
2437 temp
.LoadString(IDS_LOG_POPUP_COPYTOCLIPBOARD
);
2438 popup
.InsertMenu(static_cast<UINT
>(-1), MF_BYPOSITION
| MF_POPUP
, reinterpret_cast<UINT_PTR
>(clipSubMenu
.m_hMenu
), temp
);
2440 else if (m_ContextMenuMask
& GetContextMenuBit(ID_COPYCLIPBOARD
) && m_ColumnRegKey
== L
"reflog")
2442 clipSubMenu
.AppendMenuIcon(ID_COPYCLIPBOARDFULL
, IDS_LOG_POPUP_CLIPBOARD_FULL
, IDI_COPYCLIP
);
2443 clipSubMenu
.AppendMenuIcon(ID_COPYCLIPBOARDHASH
, IDS_LOG_HASH
, IDI_COPYCLIP
);
2444 clipSubMenu
.AppendMenuIcon(ID_COPYCLIPBOARDMESSAGES
, IDS_LOG_POPUP_CLIPBOARD_MSGS
, IDI_COPYCLIP
);
2447 temp
.LoadString(IDS_LOG_POPUP_COPYTOCLIPBOARD
);
2448 popup
.InsertMenu(static_cast<UINT
>(-1), MF_BYPOSITION
| MF_POPUP
, reinterpret_cast<UINT_PTR
>(clipSubMenu
.m_hMenu
), temp
);
2451 if(m_ContextMenuMask
&GetContextMenuBit(ID_FINDENTRY
))
2452 popup
.AppendMenuIcon(ID_FINDENTRY
, IDS_LOG_POPUP_FIND
, IDI_FILTEREDIT
);
2454 if (selectedCount
== 1 && (m_ContextMenuMask
& GetContextMenuBit(ID_SHOWBRANCHES
)) && !pSelLogEntry
->m_CommitHash
.IsEmpty())
2455 popup
.AppendMenuIcon(ID_SHOWBRANCHES
, IDS_LOG_POPUP_SHOWBRANCHES
, IDI_SHOWBRANCHES
);
2457 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, this);
2458 // DialogEnableWindow(IDOK, FALSE);
2459 // SetPromptApp(&theApp);
2461 this->ContextMenuAction(cmd
, FirstSelect
, LastSelect
, &popup
, hashMap
);
2463 // EnableOKButton();
2464 } // if (popup.CreatePopupMenu())
2467 bool CGitLogListBase::IsSelectionContinuous()
2469 if ( GetSelectedCount()==1 )
2471 // if only one revision is selected, the selection is of course
2476 POSITION pos
= GetFirstSelectedItemPosition();
2477 bool bContinuous
= (m_arShownList
.size() == m_logEntries
.size());
2480 int itemindex
= GetNextSelectedItem(pos
);
2483 int nextindex
= GetNextSelectedItem(pos
);
2484 if (nextindex
- itemindex
> 1)
2486 bContinuous
= false;
2489 itemindex
= nextindex
;
2495 void CGitLogListBase::CopySelectionToClipBoard(int toCopy
)
2498 POSITION pos
= GetFirstSelectedItemPosition();
2502 sRev
.LoadString(IDS_LOG_REVISION
);
2504 sAuthor
.LoadString(IDS_LOG_AUTHOR
);
2506 sDate
.LoadString(IDS_LOG_DATE
);
2508 sMessage
.LoadString(IDS_LOG_MESSAGE
);
2509 CString
from(MAKEINTRESOURCE(IDS_STATUSLIST_FROM
));
2513 CString sLogCopyText
;
2515 GitRevLoglist
* pLogEntry
= m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
));
2517 if (toCopy
== ID_COPYCLIPBOARDFULL
)
2519 sPaths
= L
"----\r\n";
2520 auto files
= pLogEntry
->GetFiles(nullptr);
2521 for (int cpPathIndex
= 0; cpPathIndex
< files
.GetCount(); ++cpPathIndex
)
2523 auto& file
= files
[cpPathIndex
];
2524 sPaths
+= file
.GetActionName() + L
": " + file
.GetGitPathString();
2525 if (file
.m_Action
& (CTGitPath::LOGACTIONS_REPLACED
| CTGitPath::LOGACTIONS_COPY
) && !file
.GetGitOldPathString().IsEmpty())
2528 sPaths
.AppendFormat(from
, static_cast<LPCWSTR
>(file
.GetGitOldPathString()));
2536 if (toCopy
== ID_COPYCLIPBOARDFULL
|| toCopy
== ID_COPYCLIPBOARDFULLNOPATHS
)
2539 if (!pLogEntry
->m_Notes
.IsEmpty())
2541 sNotesTags
= L
"----\n" + CString(MAKEINTRESOURCE(IDS_NOTES
));
2542 sNotesTags
+= L
":\n";
2543 sNotesTags
+= pLogEntry
->m_Notes
;
2544 sNotesTags
.Replace(L
"\n", L
"\r\n");
2546 CString tagInfo
= GetTagInfo(pLogEntry
);
2547 if (!tagInfo
.IsEmpty())
2549 sNotesTags
+= L
"----\r\n" + CString(MAKEINTRESOURCE(IDS_PROC_LOG_TAGINFO
)) + L
":\r\n";
2550 tagInfo
.Replace(L
"\n", L
"\r\n");
2551 sNotesTags
+= tagInfo
;
2554 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",
2555 static_cast<LPCWSTR
>(sRev
), static_cast<LPCWSTR
>(pLogEntry
->m_CommitHash
.ToString()),
2556 static_cast<LPCWSTR
>(sAuthor
), static_cast<LPCWSTR
>(pLogEntry
->GetAuthorName()), static_cast<LPCWSTR
>(pLogEntry
->GetAuthorEmail()),
2557 static_cast<LPCWSTR
>(sDate
),
2558 static_cast<LPCWSTR
>(CLoglistUtils::FormatDateAndTime(pLogEntry
->GetAuthorDate(), m_DateFormat
, true, m_bRelativeTimes
)),
2559 static_cast<LPCWSTR
>(sMessage
), static_cast<LPCWSTR
>(pLogEntry
->GetSubjectBody(true)),
2560 static_cast<LPCWSTR
>(sNotesTags
),
2561 static_cast<LPCWSTR
>(sPaths
));
2562 sClipdata
+= sLogCopyText
;
2564 else if (toCopy
== ID_COPYCLIPBOARDAUTHORSFULL
)
2567 sClipdata
+= L
"\r\n";
2568 sClipdata
+= pLogEntry
->GetAuthorName();
2570 sClipdata
+= pLogEntry
->GetAuthorEmail();
2573 else if (toCopy
== ID_COPYCLIPBOARDAUTHORSNAME
)
2576 sClipdata
+= L
"\r\n";
2577 sClipdata
+= pLogEntry
->GetAuthorName();
2579 else if (toCopy
== ID_COPYCLIPBOARDAUTHORSEMAIL
)
2582 sClipdata
+= L
"\r\n";
2583 sClipdata
+= pLogEntry
->GetAuthorEmail();
2586 else if (toCopy
== ID_COPYCLIPBOARDMESSAGES
)
2589 sClipdata
+= pLogEntry
->GetSubjectBody(true);
2590 sClipdata
+= L
"\r\n\r\n";
2592 else if (toCopy
== ID_COPYCLIPBOARDSUBJECTS
)
2595 sClipdata
+= pLogEntry
->GetSubject().Trim();
2596 sClipdata
+= L
"\r\n\r\n";
2601 sClipdata
+= L
"\r\n";
2602 sClipdata
+= pLogEntry
->m_CommitHash
.ToString();
2607 CStringUtils::WriteAsciiStringToClipboard(sClipdata
, GetSafeHwnd());
2611 void CGitLogListBase::DiffSelectedRevWithPrevious()
2613 if (s_bThreadRunning
)
2616 POSITION pos
= GetFirstSelectedItemPosition();
2617 auto FirstSelect
= GetNextSelectedItem(pos
);
2618 int LastSelect
= -1;
2620 LastSelect
= GetNextSelectedItem(pos
);
2622 auto hashMap
= m_HashMap
;
2623 ContextMenuAction(ID_COMPAREWITHPREVIOUS
, FirstSelect
, LastSelect
, nullptr, *hashMap
.get());
2626 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
2628 LPNMLVFINDITEM pFindInfo
= reinterpret_cast<LPNMLVFINDITEM
>(pNMHDR
);
2631 if (pFindInfo
->lvfi
.flags
& LVFI_PARAM
)
2633 if (pFindInfo
->iStart
< 0 || pFindInfo
->iStart
>= static_cast<int>(m_arShownList
.size()))
2635 if (!pFindInfo
->lvfi
.psz
)
2638 CString sCmp
= pFindInfo
->lvfi
.psz
;
2640 for (int i
=pFindInfo
->iStart
; i
<m_arShownList
.GetCount(); ++i
)
2642 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(i
));
2643 sRev
.Format(L
"%ld", pLogEntry
->Rev
);
2644 if (pFindInfo
->lvfi
.flags
& LVFI_PARTIAL
)
2646 if (sCmp
.Compare(sRev
.Left(sCmp
.GetLength()))==0)
2654 if (sCmp
.Compare(sRev
)==0)
2661 if (pFindInfo
->lvfi
.flags
& LVFI_WRAP
)
2663 for (int i
=0; i
<pFindInfo
->iStart
; ++i
)
2665 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(i
));
2666 sRev
.Format(L
"%ld", pLogEntry
->Rev
);
2667 if (pFindInfo
->lvfi
.flags
& LVFI_PARTIAL
)
2669 if (sCmp
.Compare(sRev
.Left(sCmp
.GetLength()))==0)
2677 if (sCmp
.Compare(sRev
)==0)
2689 int CGitLogListBase::FillGitLog(CTGitPath
*path
, CString
*range
, int info
)
2693 this->m_arShownList
.SafeRemoveAll();
2695 this->m_logEntries
.ClearAll();
2696 if (this->m_logEntries
.ParserFromLog(path
, 0, info
, range
))
2699 SetItemCountEx(static_cast<int>(m_logEntries
.size()));
2701 for (unsigned int i
= 0; i
< m_logEntries
.size(); ++i
)
2704 this->m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1));
2706 this->m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2710 std::for_each(m_arShownList
.begin(), m_arShownList
.end(), [](auto entry
) { entry
->m_CallDiffAsync
= DiffAsync
; });
2720 int CGitLogListBase::FillGitLog(std::unordered_set
<CGitHash
>& hashes
)
2724 m_arShownList
.SafeRemoveAll();
2726 m_logEntries
.ClearAll();
2727 if (m_logEntries
.Fill(hashes
))
2730 SetItemCountEx(static_cast<int>(m_logEntries
.size()));
2732 for (unsigned int i
= 0; i
< m_logEntries
.size(); ++i
)
2735 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(m_logEntries
.size() - i
- 1));
2737 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2741 std::for_each(m_arShownList
.begin(), m_arShownList
.end(), [](auto entry
) { entry
->m_CallDiffAsync
= DiffAsync
; });
2749 int CGitLogListBase::BeginFetchLog()
2751 ATLASSERT(IsInWorkingThread());
2754 this->m_arShownList
.SafeRemoveAll();
2756 this->m_logEntries
.ClearAll();
2758 this->m_LogCache
.ClearAllParent();
2760 m_LogCache
.FetchCacheIndex(g_Git
.m_CurrentDir
);
2763 if(this->m_Path
.IsEmpty())
2768 int mask
= CGit::LOG_INFO_ONLY_HASH
;
2769 if (m_bIncludeBoundaryCommits
)
2770 mask
|= CGit::LOG_INFO_BOUNDARY
;
2771 // if(this->m_bAllBranch)
2772 mask
|= m_ShowMask
;
2776 this->m_logEntries
.insert(m_logEntries
.cbegin(), m_wcRev
.m_CommitHash
);
2778 this->m_LogCache
.m_HashMap
[m_wcRev
.m_CommitHash
]=m_wcRev
;
2783 Locker
lock(m_critSec
);
2786 if (range
.IsEmpty())
2789 // follow does not work for directories
2790 if (!path
|| path
->IsDirectory())
2791 mask
&= ~CGit::LOG_INFO_FOLLOW
;
2792 // follow does not work with all branches 8at least in TGit)
2793 if (mask
& CGit::LOG_INFO_FOLLOW
)
2794 mask
&= ~(CGit::LOG_INFO_ALL_BRANCH
| CGit::LOG_INFO_BASIC_REFS
| CGit::LOG_INFO_LOCAL_BRANCHES
);
2796 CString cmd
= g_Git
.GetLogCmd(range
, path
, mask
, &m_Filter
, CRegDWORD(L
"Software\\TortoiseGit\\LogOrderBy", CGit::LOG_ORDER_TOPOORDER
));
2798 PostMessage(LVM_SETITEMCOUNT
, m_logEntries
.size(), LVSICF_NOINVALIDATEALL
);
2802 CAutoLocker
lock(g_Git
.m_critGitDllSec
);
2803 g_Git
.CheckAndInitDll();
2808 MessageBox(L
"Could not initialize libgit.\nlibgit reports:\n" + err
, L
"TortoiseGit", MB_ICONERROR
);
2812 if (!g_Git
.CanParseRev(range
))
2814 if (!(mask
& CGit::LOG_INFO_ALL_BRANCH
) && !(mask
& CGit::LOG_INFO_BASIC_REFS
) && !(mask
& CGit::LOG_INFO_LOCAL_BRANCHES
))
2817 // if show all branches, pick any ref as dummy entry ref
2819 if (g_Git
.GetRefList(list
))
2820 MessageBox(g_Git
.GetGitLastErr(L
"Could not get all refs."), L
"TortoiseGit", MB_ICONERROR
);
2824 cmd
= g_Git
.GetLogCmd(list
[0], path
, mask
, &m_Filter
, CRegDWORD(L
"Software\\TortoiseGit\\LogOrderBy", CGit::LOG_ORDER_TOPOORDER
));
2827 g_Git
.m_critGitDllSec
.Lock();
2829 if (git_open_log(&m_DllGitLog
, CUnicodeUtils::GetUTF8(cmd
)))
2831 g_Git
.m_critGitDllSec
.Unlock();
2837 g_Git
.m_critGitDllSec
.Unlock();
2839 MessageBox(L
"Could not open log.\nlibgit reports:\n" + err
, L
"TortoiseGit", MB_ICONERROR
);
2842 g_Git
.m_critGitDllSec
.Unlock();
2847 BOOL
CGitLogListBase::PreTranslateMessage(MSG
* pMsg
)
2849 if (pMsg
->message
== WM_KEYDOWN
&& pMsg
->wParam
=='\r' && !(GetAsyncKeyState(VK_CONTROL
) & 0x8000))
2851 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))
2853 if (CRegDWORD(L
"Software\\TortoiseGit\\DiffByDoubleClickInLog", FALSE
))
2855 DiffSelectedRevWithPrevious();
2860 if (GetFocus()==GetDlgItem(IDC_LOGMSG
))
2867 else if (pMsg
->message
== WM_KEYDOWN
&& pMsg
->wParam
== 'A' && GetAsyncKeyState(VK_CONTROL
)&0x8000)
2869 // select all entries
2870 for (int i
=0; i
<GetItemCount(); ++i
)
2871 SetItemState(i
, LVIS_SELECTED
, LVIS_SELECTED
);
2876 if (m_hAccel
&& !bSkipAccelerator
)
2878 int ret
= TranslateAccelerator(m_hWnd
, m_hAccel
, pMsg
);
2884 //m_tooltips.RelayEvent(pMsg);
2885 return __super::PreTranslateMessage(pMsg
);
2888 void CGitLogListBase::OnNMDblclkLoglist(NMHDR
* /*pNMHDR*/, LRESULT
*pResult
)
2890 // a double click on an entry in the revision list has happened
2893 if (CRegDWORD(L
"Software\\TortoiseGit\\DiffByDoubleClickInLog", FALSE
))
2894 DiffSelectedRevWithPrevious();
2897 void CGitLogListBase::FetchLogAsync(void* data
)
2901 StartLoadingThread();
2904 UINT
CGitLogListBase::LogThreadEntry(LPVOID pVoid
)
2906 return static_cast<CGitLogListBase
*>(pVoid
)->LogThread();
2909 void CGitLogListBase::GetTimeRange(CTime
&oldest
, CTime
&latest
)
2912 oldest
=CTime::GetCurrentTime();
2913 latest
=CTime(1971,1,2,0,0,0);
2914 for (unsigned int i
= 0; i
< m_logEntries
.size(); ++i
)
2916 if(m_logEntries
[i
].IsEmpty())
2919 if (m_logEntries
.GetGitRevAt(i
).GetCommitterDate().GetTime() < oldest
.GetTime())
2920 oldest
= m_logEntries
.GetGitRevAt(i
).GetCommitterDate().GetTime();
2922 if (m_logEntries
.GetGitRevAt(i
).GetCommitterDate().GetTime() > latest
.GetTime())
2923 latest
= m_logEntries
.GetGitRevAt(i
).GetCommitterDate().GetTime();
2931 UINT
CGitLogListBase::LogThread()
2933 ::PostMessage(this->GetParent()->m_hWnd
, MSG_LOAD_PERCENTAGE
, GITLOG_START
, 0);
2939 InterlockedExchange(&s_bThreadRunning
, FALSE
);
2940 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2945 // create a copy we can safely work on in this thread
2946 auto shared_filter(m_LogFilter
);
2947 const auto& filter
= *shared_filter
;
2949 TRACE(L
"\n===Begin===\n");
2950 //Update work copy item;
2952 if (!m_logEntries
.empty())
2954 GitRevLoglist
* pRev
= &m_logEntries
.GetGitRevAt(0);
2956 m_arShownList
.SafeAdd(pRev
);
2960 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2962 // store commit number of the last selected commit/line before the refresh or -1
2963 int lastSelectedHashNItem
= -1;
2964 if (m_lastSelectedHash
.IsEmpty())
2965 lastSelectedHashNItem
= 0;
2969 bool shouldWalk
= true;
2972 Locker
lock(m_critSec
);
2975 if (!g_Git
.CanParseRev(range
))
2977 // walk revisions if show all branches and there exists any ref
2978 if (!(m_ShowMask
& CGit::LOG_INFO_ALL_BRANCH
) && !(m_ShowMask
& CGit::LOG_INFO_BASIC_REFS
) && !(m_ShowMask
& CGit::LOG_INFO_LOCAL_BRANCHES
))
2983 if (g_Git
.GetRefList(list
))
2984 MessageBox(g_Git
.GetGitLastErr(L
"Could not get all refs."), L
"TortoiseGit", MB_ICONERROR
);
2992 g_Git
.m_critGitDllSec
.Lock();
2995 MessageBox(L
"Opening log failed.", L
"TortoiseGit", MB_ICONERROR
);
2996 g_Git
.m_critGitDllSec
.Unlock();
2997 InterlockedExchange(&s_bThreadRunning
, FALSE
);
2998 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
3004 [&] {git_get_log_firstcommit(m_DllGitLog
);}();
3005 total
= git_get_log_estimate_commit_count(m_DllGitLog
);
3010 MessageBox(L
"Could not get first commit.\nlibgit reports:\n" + err
, L
"TortoiseGit", MB_ICONERROR
);
3013 g_Git
.m_critGitDllSec
.Unlock();
3015 if (CGitMailmap::ShouldLoadMailmap())
3016 GitRevLoglist::s_Mailmap
= std::make_shared
<CGitMailmap
>();
3017 else if (GitRevLoglist::s_Mailmap
)
3018 GitRevLoglist::s_Mailmap
= nullptr;
3019 auto mailmap
= GitRevLoglist::s_Mailmap
;
3021 auto hashMapSharedPtr
= m_HashMap
;
3022 const auto& hashMap
= *hashMapSharedPtr
;
3024 auto rollUpStatesSharedPtr
= m_RollUpStates
;
3025 const auto &rollUpStates
= *rollUpStatesSharedPtr
;
3026 std::unordered_set
<CGitHash
> collapsedNodes
, expandedNodes
;
3029 t2
= t1
= GetTickCount64();
3030 int oldprecentage
= 0;
3031 size_t oldsize
= m_logEntries
.size();
3032 std::unordered_map
<CGitHash
, std::unordered_set
<CGitHash
>> commitChildren
;
3033 while (ret
== 0 && !m_bExitThread
)
3035 g_Git
.m_critGitDllSec
.Lock();
3038 [&] { ret
= git_get_log_nextcommit(this->m_DllGitLog
, &commit
, m_ShowMask
& CGit::LOG_INFO_FOLLOW
); } ();
3042 g_Git
.m_critGitDllSec
.Unlock();
3044 MessageBox(L
"Could not get next commit.\nlibgit reports:\n" + err
, L
"TortoiseGit", MB_ICONERROR
);
3050 g_Git
.m_critGitDllSec
.Unlock();
3051 if (ret
!= -2) // other than end of revision walking
3052 MessageBox((L
"Could not get next commit.\nlibgit returns:" + std::to_wstring(ret
)).c_str(), L
"TortoiseGit", MB_ICONERROR
);
3056 if (commit
.m_ignore
== 1)
3058 git_free_commit(&commit
);
3059 g_Git
.m_critGitDllSec
.Unlock();
3063 //printf("%s\r\n",commit.GetSubject());
3066 git_free_commit(&commit
);
3067 g_Git
.m_critGitDllSec
.Unlock();
3071 CGitHash hash
= CGitHash::FromRaw(commit
.m_hash
);
3073 GitRevLoglist
* pRev
= m_LogCache
.GetCacheData(hash
);
3074 pRev
->Parse(&commit
, mailmap
.get()); // better parse here than on GITLOG_END in LogDlg::OnLogListLoading for updating the DateSelectors
3076 char* note
= nullptr;
3079 git_get_notes(commit
.m_hash
, ¬e
);
3083 g_Git
.m_critGitDllSec
.Unlock();
3085 MessageBox(L
"Could not get commit notes.\nlibgit reports:\n" + err
, L
"TortoiseGit", MB_ICONERROR
);
3091 pRev
->m_Notes
= CUnicodeUtils::GetUnicode(note
);
3095 git_free_commit(&commit
);
3096 g_Git
.m_critGitDllSec
.Unlock();
3098 if(!pRev
->m_IsDiffFiles
)
3100 pRev
->m_CallDiffAsync
= DiffAsync
;
3103 if (m_ShowFilter
& FILTERSHOW_MERGEPOINTS
) // See also ShouldShowFilter()
3105 for (size_t i
= 0; i
< pRev
->m_ParentHash
.size(); ++i
)
3107 const CGitHash
&parentHash
= pRev
->m_ParentHash
[i
];
3108 auto it
= commitChildren
.find(parentHash
);
3109 if (it
== commitChildren
.end())
3110 it
= commitChildren
.insert(make_pair(parentHash
, std::unordered_set
<CGitHash
>())).first
;
3111 it
->second
.insert(pRev
->m_CommitHash
);
3119 if (rollUpStates
.empty() || !(m_ShowFilter
& FILTERSHOW_MERGEPOINTS
))
3121 visible
= ShouldShowFilter(pRev
, commitChildren
, hashMap
);
3122 pRev
->m_RolledUp
= !ShouldShowAnyFilter();
3123 pRev
->m_RolledUpIsForced
= false;
3125 else // !(rollUpStates.empty())
3127 auto itChildren
= commitChildren
.find(pRev
->m_CommitHash
);
3128 bool hasChildren
= itChildren
!= commitChildren
.end();
3129 bool isFork
= hasChildren
&& (itChildren
->second
.size() > 1);
3130 bool isChildExpanded
= hasChildren
&& !isFork
&& expandedNodes
.count(*itChildren
->second
.begin());
3131 bool isChildCollapsed
= hasChildren
&& !isFork
&& !isChildExpanded
&& collapsedNodes
.count(*itChildren
->second
.begin());
3133 auto itForcedState
= rollUpStates
.find(pRev
->m_CommitHash
);
3134 bool hasForcedState
= itForcedState
!= rollUpStates
.end();
3135 bool forcedRollUp
= hasForcedState
&& (itForcedState
->second
== RollUpState::Collapse
);
3137 bool shouldShowAny
= ShouldShowAnyFilter();
3138 bool shouldShowSpecial
= ShouldShowRefsFilter(pRev
, hashMap
) || ShouldShowMergePointsFilter(pRev
, commitChildren
);
3140 bool isSpecial
= isFork
|| shouldShowSpecial
;
3141 bool isRegular
= !isSpecial
;
3143 visible
= isSpecial
|| isChildExpanded
|| (shouldShowAny
&& !isChildCollapsed
);
3145 bool rolledUpByDefault
= (isSpecial
&& !shouldShowAny
) || (isRegular
&& isChildCollapsed
);
3146 pRev
->m_RolledUp
= (visible
&& hasForcedState
) ? forcedRollUp
: rolledUpByDefault
;
3147 pRev
->m_RolledUpIsForced
= (pRev
->m_RolledUp
!= rolledUpByDefault
);
3149 if (pRev
->m_RolledUp
)
3150 collapsedNodes
.insert(pRev
->m_CommitHash
);
3152 expandedNodes
.insert(pRev
->m_CommitHash
);
3155 if (visible
&& !filter(pRev
, this, hashMap
))
3157 this->m_critSec
.Lock();
3158 m_logEntries
.append(hash
, visible
);
3160 m_arShownList
.push_back(pRev
); // push_back is ok here, because we use the very same lock, otherwise use SafeAdd
3161 this->m_critSec
.Unlock();
3166 if (lastSelectedHashNItem
== -1 && hash
== m_lastSelectedHash
)
3167 lastSelectedHashNItem
= static_cast<int>(m_arShownList
.size()) - 1;
3169 t2
= GetTickCount64();
3171 if (t2
- t1
> 500UL || (m_logEntries
.size() - oldsize
> 100))
3174 int percent
= static_cast<int>(m_logEntries
.size() * 100 / (total
+ 1));
3177 if (percent
<= GITLOG_START
)
3178 percent
= GITLOG_START
+1;
3180 oldsize
= m_logEntries
.size();
3181 PostMessage(LVM_SETITEMCOUNT
, this->m_logEntries
.size(), LVSICF_NOINVALIDATEALL
|LVSICF_NOSCROLL
);
3183 if (percent
> oldprecentage
)
3185 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
, percent
, 0);
3186 oldprecentage
= percent
;
3189 if (lastSelectedHashNItem
>= 0)
3190 PostMessage(m_ScrollToMessage
, lastSelectedHashNItem
);
3195 g_Git
.m_critGitDllSec
.Lock();
3196 git_close_log(m_DllGitLog
);
3197 g_Git
.m_critGitDllSec
.Unlock();
3202 InterlockedExchange(&s_bThreadRunning
, FALSE
);
3207 PostMessage(LVM_SETITEMCOUNT
, this->m_logEntries
.size(), LVSICF_NOINVALIDATEALL
|LVSICF_NOSCROLL
);
3209 if (lastSelectedHashNItem
>= 0)
3210 PostMessage(m_ScrollToMessage
, lastSelectedHashNItem
);
3213 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
, GITLOG_END
, 0);
3215 InterlockedExchange(&s_bThreadRunning
, FALSE
);
3220 void CGitLogListBase::FetchRemoteList()
3222 STRING_VECTOR remoteList
;
3223 m_SingleRemote
.Empty();
3224 if (!g_Git
.GetRemoteList(remoteList
) && remoteList
.size() == 1)
3225 m_SingleRemote
= remoteList
[0];
3228 void CGitLogListBase::FetchTrackingBranchList()
3230 m_TrackingMap
.clear();
3231 auto hashMap
= m_HashMap
;
3232 for (auto it
= hashMap
->cbegin(); it
!= hashMap
->cend(); ++it
)
3234 for (const auto& ref
: it
->second
)
3237 if (CGit::GetShortName(ref
, branchName
, L
"refs/heads/"))
3239 CString pullRemote
, pullBranch
;
3240 g_Git
.GetRemoteTrackedBranch(branchName
, pullRemote
, pullBranch
);
3241 if (!pullRemote
.IsEmpty() && !pullBranch
.IsEmpty())
3242 m_TrackingMap
[branchName
] = std::make_pair(pullRemote
, pullBranch
);
3248 void CGitLogListBase::Refresh(BOOL IsCleanFilter
)
3250 SafeTerminateThread();
3252 this->SetItemCountEx(0);
3257 ShowGraphColumn((m_ShowMask
& CGit::LOG_INFO_FOLLOW
) ? false : true);
3259 //Update branch and Tag info
3262 m_pFindDialog
->RefreshList();
3263 //Assume Thread have exited
3264 //if(!s_bThreadRunning)
3266 m_logEntries
.clear();
3269 m_LogFilter
= std::make_shared
<CLogDlgFilter
>();
3271 SafeTerminateAsyncDiffThread();
3272 m_AsynDiffListLock
.Lock();
3273 m_AsynDiffList
.clear();
3274 m_AsynDiffListLock
.Unlock();
3275 StartAsyncDiffThread();
3277 StartLoadingThread();
3281 void CGitLogListBase::StartAsyncDiffThread()
3283 if (m_AsyncThreadExit
)
3285 if (InterlockedExchange(&m_AsyncThreadRunning
, TRUE
) != FALSE
)
3287 m_DiffingThread
= AfxBeginThread(AsyncThread
, this, THREAD_PRIORITY_BELOW_NORMAL
, 0, CREATE_SUSPENDED
);
3288 if (!m_DiffingThread
)
3290 InterlockedExchange(&m_AsyncThreadRunning
, FALSE
);
3291 CMessageBox::Show(GetSafeHwnd(), IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
3294 m_DiffingThread
->m_bAutoDelete
= FALSE
;
3295 m_DiffingThread
->ResumeThread();
3298 void CGitLogListBase::StartLoadingThread()
3300 if (InterlockedExchange(&s_bThreadRunning
, TRUE
) != FALSE
)
3302 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
3303 InterlockedExchange(&m_bExitThread
, FALSE
);
3304 m_LoadingThread
= AfxBeginThread(LogThreadEntry
, this, THREAD_PRIORITY_LOWEST
, 0, CREATE_SUSPENDED
);
3305 if (!m_LoadingThread
)
3307 InterlockedExchange(&s_bThreadRunning
, FALSE
);
3308 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
3309 CMessageBox::Show(GetSafeHwnd(), IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
3312 m_LoadingThread
->m_bAutoDelete
= FALSE
;
3313 m_LoadingThread
->ResumeThread();
3316 bool CGitLogListBase::ShouldShowAnyFilter()
3318 return m_ShowFilter
& FILTERSHOW_ANYCOMMIT
;
3321 bool CGitLogListBase::ShouldShowRefsFilter(GitRevLoglist
* pRev
, const MAP_HASH_NAME
& hashMap
)
3323 if (!(m_ShowFilter
& FILTERSHOW_REFS
))
3327 if (pRev
->m_CommitHash
== m_HeadHash
)
3331 auto refsIt
= hashMap
.find(pRev
->m_CommitHash
);
3332 if (refsIt
== hashMap
.cend())
3334 const auto& refList
= refsIt
->second
;
3335 for (const CString
&str
: refList
)
3337 if (CStringUtils::StartsWith(str
, L
"refs/heads/"))
3339 if (m_ShowRefMask
& LOGLIST_SHOWLOCALBRANCHES
)
3342 else if (CStringUtils::StartsWith(str
, L
"refs/remotes/"))
3344 if (m_ShowRefMask
& LOGLIST_SHOWREMOTEBRANCHES
)
3347 else if (CStringUtils::StartsWith(str
, L
"refs/tags/"))
3349 if (m_ShowRefMask
& LOGLIST_SHOWTAGS
)
3352 else if (CStringUtils::StartsWith(str
, L
"refs/stash"))
3354 if (m_ShowRefMask
& LOGLIST_SHOWSTASH
)
3357 else if (CStringUtils::StartsWith(str
, L
"refs/bisect/"))
3359 if (m_ShowRefMask
& LOGLIST_SHOWBISECT
)
3366 bool CGitLogListBase::ShouldShowMergePointsFilter(GitRevLoglist
* pRev
, const std::unordered_map
<CGitHash
, std::unordered_set
<CGitHash
>>& commitChildren
)
3368 if (!(m_ShowFilter
& FILTERSHOW_MERGEPOINTS
))
3371 if (pRev
->ParentsCount() > 1)
3374 if (auto childrenIt
= commitChildren
.find(pRev
->m_CommitHash
); childrenIt
!= commitChildren
.end())
3376 const std::unordered_set
<CGitHash
> &children
= childrenIt
->second
;
3377 if (children
.size() > 1)
3383 bool CGitLogListBase::ShouldShowFilter(GitRevLoglist
* pRev
, const std::unordered_map
<CGitHash
, std::unordered_set
<CGitHash
>>& commitChildren
, const MAP_HASH_NAME
& hashMap
)
3385 return ShouldShowAnyFilter() || ShouldShowRefsFilter(pRev
, hashMap
) || ShouldShowMergePointsFilter(pRev
, commitChildren
);
3388 void CGitLogListBase::ShowGraphColumn(bool bShow
)
3390 // HACK to hide graph column
3392 SetColumnWidth(0, m_ColumnManager
.GetWidth(0, false));
3394 SetColumnWidth(0, 0);
3397 CString
CGitLogListBase::GetTagInfo(GitRev
* pLogEntry
) const
3399 auto hashMap
= m_HashMap
;
3400 auto refs
= hashMap
->find(pLogEntry
->m_CommitHash
);
3401 if (refs
== hashMap
->end())
3404 return GetTagInfo(refs
->second
);
3407 CString
CGitLogListBase::GetTagInfo(const STRING_VECTOR
& refs
) const
3410 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
3412 if (!CStringUtils::StartsWith((*it
), L
"refs/tags/"))
3414 if (!CStringUtils::EndsWith((*it
), L
"^{}"))
3418 cmd
.Format(L
"git.exe cat-file tag %s", static_cast<LPCWSTR
>((*it
).Left((*it
).GetLength() - static_cast<int>(wcslen(L
"^{}")))));
3420 if (g_Git
.Run(cmd
, &output
, nullptr, CP_UTF8
) != 0)
3426 // this assumes that in the header of the tag there is no ">" before the "tagger " header entry
3427 int pos1
= output
.Find(L
'>');
3431 if (output
[pos1
] == L
' ')
3433 int pos2
= output
.Find(L
'\n', pos1
);
3437 CString str
= output
.Mid(pos1
, pos2
- pos1
);
3438 wchar_t* pEnd
= nullptr;
3440 auto number
= wcstoumax(str
.GetBuffer(), &pEnd
, 10);
3441 if (str
.GetBuffer() == pEnd
)
3443 if (errno
== ERANGE
)
3446 output
.Delete(pos1
, pos2
- pos1
);
3447 output
.Insert(pos1
, static_cast<LPCWSTR
>(CLoglistUtils::FormatDateAndTime(CTime(number
), m_DateFormat
, true, m_bRelativeTimes
)));
3449 output
.Trim().AppendChar(L
'\n');
3455 void CGitLogListBase::Clear()
3457 m_arShownList
.SafeRemoveAll();
3460 m_logEntries
.ClearAll();
3463 void CGitLogListBase::OnDestroy()
3465 SafeTerminateThread();
3466 SafeTerminateAsyncDiffThread();
3469 while(m_LogCache
.SaveCache())
3477 //if(CMessageBox::Show(nullptr, L"Cannot Save Log Cache to Disk. To retry click yes. To give up click no.", L"TortoiseGit",
3478 // MB_YESNO) == IDNO)
3482 __super::OnDestroy();
3485 LRESULT
CGitLogListBase::OnLoad(WPARAM wParam
,LPARAM
/*lParam*/)
3488 int i
= static_cast<int>(wParam
);
3489 this->GetItemRect(i
,&rect
,LVIR_BOUNDS
);
3490 this->InvalidateRect(rect
);
3496 * Save column widths to the registry
3498 void CGitLogListBase::SaveColumnWidths()
3500 // HACK that graph column is always shown
3501 SetColumnWidth(0, m_ColumnManager
.GetWidth(0, false));
3503 __super::SaveColumnWidths();
3506 int CGitLogListBase::GetHeadIndex()
3508 if(m_HeadHash
.IsEmpty())
3511 for (size_t i
= 0; i
< m_arShownList
.size(); ++i
)
3513 GitRev
* pRev
= m_arShownList
.SafeGetAt(i
);
3516 if (pRev
->m_CommitHash
== m_HeadHash
)
3517 return static_cast<int>(i
);
3522 void CGitLogListBase::OnFind()
3526 m_pFindDialog
= new CFindDlg(this);
3527 m_pFindDialog
->Create(this);
3531 m_pFindDialog
->SetFocus();
3536 LRESULT
CGitLogListBase::OnScrollToMessage(WPARAM itemToSelect
, LPARAM
/*lParam*/)
3538 if (GetSelectedCount() != 0)
3541 CGitHash theSelectedHash
= m_lastSelectedHash
;
3542 SetItemState(static_cast<int>(itemToSelect
), LVIS_SELECTED
| LVIS_FOCUSED
, LVIS_SELECTED
| LVIS_FOCUSED
);
3543 m_lastSelectedHash
= theSelectedHash
;
3545 int countPerPage
= GetCountPerPage();
3546 EnsureVisible(max(0, static_cast<int>(itemToSelect
) - countPerPage
/ 2), FALSE
);
3547 EnsureVisible(min(GetItemCount(), static_cast<int>(itemToSelect
) + countPerPage
/ 2), FALSE
);
3548 EnsureVisible(static_cast<int>(itemToSelect
), FALSE
);
3552 LRESULT
CGitLogListBase::OnScrollToRef(WPARAM wParam
, LPARAM
/*lParam*/)
3554 CString
* ref
= reinterpret_cast<CString
*>(wParam
);
3555 if (!ref
|| ref
->IsEmpty())
3558 bool bShift
= (GetAsyncKeyState(VK_SHIFT
) & 0x8000) != 0;
3561 if (g_Git
.GetHash(hash
, *ref
+ L
"^{}")) // add ^{} in order to get the correct SHA-1 (especially for signed tags)
3562 MessageBox(g_Git
.GetGitLastErr(L
"Could not get hash of ref \"" + *ref
+ L
"^{}\"."), L
"TortoiseGit", MB_ICONERROR
);
3567 bool bFound
= false;
3568 int cnt
= static_cast<int>(m_arShownList
.size());
3570 for (i
= 0; i
< cnt
; ++i
)
3572 GitRev
* pLogEntry
= m_arShownList
.SafeGetAt(i
);
3573 if (pLogEntry
&& pLogEntry
->m_CommitHash
== hash
)
3582 EnsureVisible(i
, FALSE
);
3585 SetItemState(GetSelectionMark(), 0, LVIS_SELECTED
);
3586 SetItemState(i
, LVIS_SELECTED
| LVIS_FOCUSED
, LVIS_SELECTED
| LVIS_FOCUSED
);
3587 SetSelectionMark(i
);
3591 GitRev
* pLogEntry
= m_arShownList
.SafeGetAt(i
);
3593 m_highlight
= pLogEntry
->m_CommitHash
;
3601 LRESULT
CGitLogListBase::OnFindDialogMessage(WPARAM
/*wParam*/, LPARAM
/*lParam*/)
3603 ASSERT(m_pFindDialog
);
3604 bool bFound
= false;
3607 if (m_pFindDialog
->IsTerminating())
3609 // invalidate the handle identifying the dialog box.
3610 m_pFindDialog
= nullptr;
3614 int cnt
= static_cast<int>(m_arShownList
.size());
3615 bool bShift
= (GetAsyncKeyState(VK_SHIFT
) & 0x8000) != 0;
3617 if(m_pFindDialog
->IsRef())
3620 str
=m_pFindDialog
->GetFindString();
3626 if (g_Git
.GetHash(hash
, str
+ L
"^{}")) // add ^{} in order to get the correct SHA-1 (especially for signed tags)
3627 MessageBox(g_Git
.GetGitLastErr(L
"Could not get hash of ref \"" + str
+ L
"^{}\"."), L
"TortoiseGit", MB_ICONERROR
);
3632 for (i
= 0; i
< cnt
; ++i
)
3634 GitRev
* pLogEntry
= m_arShownList
.SafeGetAt(i
);
3635 if(pLogEntry
&& pLogEntry
->m_CommitHash
== hash
)
3644 m_pFindDialog
->FlashWindowEx(FLASHW_ALL
, 2, 100);
3649 if (m_pFindDialog
->FindNext() && !bFound
)
3651 //read data from dialog
3652 CLogDlgFilter filter
{ m_pFindDialog
->GetFindString(), m_pFindDialog
->Regex(), LOGFILTER_ALL
, m_pFindDialog
->MatchCase() == TRUE
};
3654 auto hashMapSharedPtr
= m_HashMap
;
3655 auto& hashMap
= *hashMapSharedPtr
;
3657 for (i
= m_nSearchIndex
+ 1; ; ++i
)
3662 m_pFindDialog
->FlashWindowEx(FLASHW_ALL
, 2, 100);
3664 if (m_nSearchIndex
>= 0)
3666 if (i
== m_nSearchIndex
)
3668 ::MessageBeep(0xFFFFFFFF);
3669 m_pFindDialog
->FlashWindowEx(FLASHW_ALL
, 3, 100);
3674 if (filter(m_arShownList
.SafeGetAt(i
), this, hashMap
))
3680 } // if(m_pFindDialog->FindNext())
3685 EnsureVisible(i
, FALSE
);
3688 SetItemState(GetSelectionMark(), 0, LVIS_SELECTED
);
3689 SetItemState(i
, LVIS_SELECTED
| LVIS_FOCUSED
, LVIS_SELECTED
| LVIS_FOCUSED
);
3690 SetSelectionMark(i
);
3694 GitRev
* pLogEntry
= m_arShownList
.SafeGetAt(i
);
3696 m_highlight
= pLogEntry
->m_CommitHash
;
3699 //FillLogMessageCtrl();
3706 INT_PTR
CGitLogListBase::OnToolHitTest(CPoint point
, TOOLINFO
* pTI
) const
3708 LVHITTESTINFO lvhitTestInfo
;
3710 lvhitTestInfo
.pt
= point
;
3712 int nItem
= ListView_SubItemHitTest(m_hWnd
, &lvhitTestInfo
);
3713 int nSubItem
= lvhitTestInfo
.iSubItem
;
3715 UINT nFlags
= lvhitTestInfo
.flags
;
3717 // nFlags is 0 if the SubItemHitTest fails
3718 // Therefore, 0 & <anything> will equal false
3719 if (nFlags
& LVHT_ONITEM
)
3721 // Get the client area occupied by this control
3723 GetClientRect(&rcClient
);
3725 // Fill in the TOOLINFO structure
3727 pTI
->uId
= static_cast<UINT
>((nItem
<< 10) + (nSubItem
& 0x3ff) + 1);
3728 pTI
->lpszText
= LPSTR_TEXTCALLBACK
;
3729 pTI
->rect
= rcClient
;
3731 return pTI
->uId
; // By returning a unique value per listItem,
3732 // we ensure that when the mouse moves over another list item,
3733 // the tooltip will change
3737 // Otherwise, we aren't interested, so let the message propagate
3742 BOOL
CGitLogListBase::OnToolTipText(UINT
/*id*/, NMHDR
* pNMHDR
, LRESULT
* pResult
)
3744 auto pTTTA
= reinterpret_cast<TOOLTIPTEXTA
*>(pNMHDR
);
3745 auto pTTTW
= reinterpret_cast<TOOLTIPTEXTW
*>(pNMHDR
);
3749 // Ignore messages from the built in tooltip, we are processing them internally
3750 if ((pNMHDR
->idFrom
== reinterpret_cast<UINT_PTR
>(m_hWnd
)) &&
3751 (((pNMHDR
->code
== TTN_NEEDTEXTA
) && (pTTTA
->uFlags
& TTF_IDISHWND
)) ||
3752 ((pNMHDR
->code
== TTN_NEEDTEXTW
) && (pTTTW
->uFlags
& TTF_IDISHWND
))))
3755 // Get the mouse position
3756 const MSG
* pMessage
= GetCurrentMessage();
3760 ScreenToClient(&pt
);
3762 // Check if the point falls onto a list item
3763 LVHITTESTINFO lvhitTestInfo
;
3764 lvhitTestInfo
.pt
= pt
;
3766 int nItem
= SubItemHitTest(&lvhitTestInfo
);
3768 if (lvhitTestInfo
.flags
& LVHT_ONITEM
)
3770 // Get branch description first
3772 if (lvhitTestInfo
.iSubItem
== LOGLIST_MESSAGE
)
3775 CGit::REF_TYPE type
= CGit::REF_TYPE::LOCAL_BRANCH
;
3776 auto hashMap
= m_HashMap
;
3777 if (IsMouseOnRefLabel(m_arShownList
.SafeGetAt(nItem
), lvhitTestInfo
.pt
, type
, *hashMap
.get(), &branch
))
3779 MAP_STRING_STRING descriptions
;
3780 g_Git
.GetBranchDescriptions(descriptions
);
3781 if (descriptions
.find(branch
) != descriptions
.cend())
3783 strTipText
.LoadString(IDS_DESCRIPTION
);
3784 strTipText
+= L
":\n";
3785 strTipText
+= descriptions
[branch
];
3790 bool followMousePos
= false;
3791 if (!strTipText
.IsEmpty())
3792 followMousePos
= true;
3794 strTipText
= GetToolTipText(nItem
, lvhitTestInfo
.iSubItem
);
3795 if (strTipText
.IsEmpty())
3798 // we want multiline tooltips
3799 ::SendMessage(pNMHDR
->hwndFrom
, TTM_SETMAXTIPWIDTH
, 0, SHRT_MAX
);
3801 if (strTipText
.GetLength() >= _countof(m_wszTip
))
3803 strTipText
.Truncate(_countof(m_wszTip
) - 1 - 3);
3804 strTipText
+= L
"...";
3806 wcsncpy_s(m_wszTip
, strTipText
, _TRUNCATE
);
3807 // handle Unicode as well as non-Unicode requests
3808 if (pNMHDR
->code
== TTN_NEEDTEXTA
)
3810 pTTTA
->hinst
= nullptr;
3811 pTTTA
->lpszText
= m_szTip
;
3812 ::WideCharToMultiByte(CP_ACP
, 0, m_wszTip
, -1, m_szTip
, 8192, nullptr, nullptr);
3816 pTTTW
->hinst
= nullptr;
3817 pTTTW
->lpszText
= m_wszTip
;
3821 GetSubItemRect(nItem
, lvhitTestInfo
.iSubItem
, LVIR_LABEL
, rect
);
3823 rect
.MoveToXY(pt
.x
, pt
.y
+ CDPIAware::Instance().ScaleY(18)); // 18: to act like a normal tooltip
3824 ClientToScreen(rect
);
3825 ::SetWindowPos(pNMHDR
->hwndFrom
, HWND_TOP
, rect
.left
, rect
.top
, 0, 0, SWP_NOACTIVATE
|SWP_NOSIZE
|SWP_NOOWNERZORDER
);
3827 return TRUE
; // We found a tool tip,
3828 // tell the framework this message has been handled
3831 return FALSE
; // We didn't handle the message,
3832 // let the framework continue propagating the message
3835 CString
CGitLogListBase::GetToolTipText(int nItem
, int nSubItem
)
3837 if (nSubItem
== LOGLIST_MESSAGE
&& !m_bTagsBranchesOnRightSide
)
3839 GitRevLoglist
* pLogEntry
= m_arShownList
.SafeGetAt(nItem
);
3840 if (pLogEntry
== nullptr)
3842 auto hashMap
= m_HashMap
;
3843 if (hashMap
->find(pLogEntry
->m_CommitHash
) == hashMap
->cend() && (m_superProjectHash
.IsEmpty() || pLogEntry
->m_CommitHash
!= m_superProjectHash
))
3845 return pLogEntry
->GetSubject();
3847 else if (nSubItem
== LOGLIST_DATE
&& m_bRelativeTimes
)
3849 GitRevLoglist
* pLogEntry
= m_arShownList
.SafeGetAt(nItem
);
3850 if (pLogEntry
== nullptr)
3852 return CLoglistUtils::FormatDateAndTime(pLogEntry
->GetAuthorDate(), m_DateFormat
, true, false);
3854 else if (nSubItem
== LOGLIST_COMMIT_DATE
&& m_bRelativeTimes
)
3856 GitRevLoglist
* pLogEntry
= m_arShownList
.SafeGetAt(nItem
);
3857 if (pLogEntry
== nullptr)
3859 return CLoglistUtils::FormatDateAndTime(pLogEntry
->GetCommitterDate(), m_DateFormat
, true, false);
3861 else if (nSubItem
== LOGLIST_ACTION
)
3863 GitRevLoglist
* pLogEntry
= m_arShownList
.SafeGetAt(nItem
);
3864 if (pLogEntry
== nullptr)
3867 int actions
= pLogEntry
->GetAction(this);
3868 if (!pLogEntry
->m_IsDiffFiles
)
3869 return CString(MAKEINTRESOURCE(IDS_PROC_LOG_FETCHINGFILES
));
3872 if (actions
& CTGitPath::LOGACTIONS_MODIFIED
)
3873 actionText
+= CTGitPath::GetActionName(CTGitPath::LOGACTIONS_MODIFIED
);
3875 if (actions
& CTGitPath::LOGACTIONS_ADDED
)
3877 if (!actionText
.IsEmpty())
3878 actionText
+= L
"\r\n";
3879 actionText
+= CTGitPath::GetActionName(CTGitPath::LOGACTIONS_ADDED
);
3882 if (actions
& CTGitPath::LOGACTIONS_DELETED
)
3884 if (!actionText
.IsEmpty())
3885 actionText
+= L
"\r\n";
3886 actionText
+= CTGitPath::GetActionName(CTGitPath::LOGACTIONS_DELETED
);
3889 if (actions
& CTGitPath::LOGACTIONS_REPLACED
)
3891 if (!actionText
.IsEmpty())
3892 actionText
+= L
"\r\n";
3893 actionText
+= CTGitPath::GetActionName(CTGitPath::LOGACTIONS_REPLACED
);
3896 if (actions
& CTGitPath::LOGACTIONS_UNMERGED
)
3898 if (!actionText
.IsEmpty())
3899 actionText
+= L
"\r\n";
3900 actionText
+= CTGitPath::GetActionName(CTGitPath::LOGACTIONS_UNMERGED
);
3903 if (!actionText
.IsEmpty())
3905 CString
sTitle(MAKEINTRESOURCE(IDS_LOG_ACTIONS
));
3906 return sTitle
+ L
":\r\n" + actionText
;
3912 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*/)
3915 ScreenToClient(&pt
);
3916 return IsMouseOnRefLabel(pLogEntry
, pt
, type
, hashMap
, pShortname
, pIndex
);
3919 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*/)
3924 auto refList
= hashMap
.find(pLogEntry
->m_CommitHash
);
3925 if (refList
== hashMap
.cend())
3928 for (size_t i
= 0; i
< refList
->second
.size(); ++i
)
3930 const auto labelpos
= m_RefLabelPosMap
.find(refList
->second
[i
]);
3931 if (labelpos
== m_RefLabelPosMap
.cend() || !labelpos
->second
.PtInRect(pt
))
3934 CGit::REF_TYPE foundType
;
3936 *pShortname
= CGit::GetShortName(refList
->second
[i
], &foundType
);
3938 CGit::GetShortName(refList
->second
[i
], &foundType
);
3939 if (foundType
!= type
&& type
!= CGit::REF_TYPE::UNKNOWN
)
3950 void CGitLogListBase::OnBeginDrag(NMHDR
* /*pnmhdr*/, LRESULT
* pResult
)
3954 if (!m_bDragndropEnabled
|| GetSelectedCount() == 0 || !IsSelectionContinuous())
3959 m_nDropMarkerLast
= -1;
3960 m_nDropMarkerLastHot
= GetHotItem();
3964 void CGitLogListBase::OnMouseMove(UINT nFlags
, CPoint point
)
3966 __super::OnMouseMove(nFlags
, point
);
3971 CPoint dropPoint
= point
;
3972 ClientToScreen(&dropPoint
);
3974 if (WindowFromPoint(dropPoint
) != this)
3976 SetCursor(LoadCursor(nullptr, IDC_NO
));
3978 DrawDropInsertMarker(m_nDropIndex
);
3982 SetCursor(LoadCursor(nullptr, IDC_ARROW
));
3983 ScreenToClient(&dropPoint
);
3986 m_nDropIndex
= HitTest(dropPoint
);
3988 if (m_nDropIndex
== -1) // might be last item, allow to move past last item
3991 m_nDropIndex
= HitTest(dropPoint
);
3992 if (m_nDropIndex
!= -1)
3993 m_nDropIndex
= GetItemCount();
3996 POSITION pos
= GetFirstSelectedItemPosition();
3997 int first
= GetNextSelectedItem(pos
);
4000 last
= GetNextSelectedItem(pos
);
4001 if (m_nDropIndex
== -1 || (m_nDropIndex
>= first
&& m_nDropIndex
- 1 <= last
))
4003 SetCursor(LoadCursor(nullptr, IDC_NO
));
4007 // handle auto scrolling
4008 int hotItem
= GetHotItem();
4009 int topindex
= GetTopIndex();
4010 if (hotItem
== topindex
&& hotItem
!= 0)
4011 EnsureVisible(hotItem
- 1, FALSE
);
4012 else if (hotItem
>= topindex
+ GetCountPerPage() - 1 && hotItem
+ 1 < GetItemCount())
4013 EnsureVisible(hotItem
+ 1, FALSE
);
4015 DrawDropInsertMarker(m_nDropIndex
);
4018 void CGitLogListBase::OnLButtonUp(UINT nFlags
, CPoint point
)
4023 SetCursor(LoadCursor(nullptr, IDC_HAND
));
4024 m_bDragging
= FALSE
;
4027 GetItemRect(m_nDropMarkerLast
, &rect
, 0);
4028 rect
.bottom
= rect
.top
+ 2;
4030 InvalidateRect(&rect
, 0);
4033 ClientToScreen(&pt
);
4034 if (WindowFromPoint(pt
) == this && m_nDropIndex
!= -1)
4035 GetParent()->PostMessage(MSG_COMMITS_REORDERED
, m_nDropIndex
, 0);
4038 __super::OnLButtonUp(nFlags
, point
);
4041 void CGitLogListBase::DrawDropInsertMarker(int nIndex
)
4043 if (m_nDropMarkerLast
!= nIndex
)
4046 if (GetItemRect(m_nDropMarkerLast
, &rect
, 0))
4048 rect
.bottom
= rect
.top
+ 2;
4050 InvalidateRect(&rect
, 0);
4052 else if (m_nDropMarkerLast
== GetItemCount())
4053 DrawDropInsertMarkerLine(m_nDropMarkerLast
); // double painting = removal
4054 m_nDropMarkerLast
= nIndex
;
4059 DrawDropInsertMarkerLine(m_nDropMarkerLast
);
4061 else if (m_nDropMarkerLastHot
!= GetHotItem())
4063 m_nDropMarkerLastHot
= GetHotItem();
4064 m_nDropMarkerLast
= -1;
4068 void CGitLogListBase::DrawDropInsertMarkerLine(int nIndex
)
4070 CBrush
* pBrush
= CDC::GetHalftoneBrush();
4074 if (nIndex
< GetItemCount())
4076 GetItemRect(nIndex
, &rect
, 0);
4077 rect
.bottom
= rect
.top
+ 2;
4082 GetItemRect(nIndex
- 1, &rect
, 0);
4083 rect
.top
= rect
.bottom
- 2;
4087 CBrush
* pBrushOld
= pDC
->SelectObject(pBrush
);
4088 pDC
->PatBlt(rect
.left
, rect
.top
, rect
.Width(), rect
.Height(), PATINVERT
);
4089 pDC
->SelectObject(pBrushOld
);
4094 ULONG
CGitLogListBase::GetGestureStatus(CPoint
/*ptTouch*/)
4099 void CGitLogListBase::DrawListItemWithMatchesRect(NMLVCUSTOMDRAW
* pLVCD
, const std::vector
<CHARRANGE
>& ranges
, CRect rect
, const CString
& text
, CColors
& colors
, HTHEME hTheme
/*= nullptr*/, int txtState
/*= 0*/)
4102 COLORREF textColor
= pLVCD
->clrText
;
4106 ::SetTextColor(pLVCD
->nmcd
.hdc
, textColor
);
4107 SetBkMode(pLVCD
->nmcd
.hdc
, TRANSPARENT
);
4109 DTTOPTS opts
= { 0 };
4110 opts
.dwSize
= sizeof(opts
);
4111 opts
.crText
= textColor
;
4112 opts
.dwFlags
= DTT_TEXTCOLOR
;
4114 for (auto it
= ranges
.cbegin(); it
!= ranges
.cend(); ++it
)
4117 if (it
->cpMin
- drawPos
)
4121 DrawText(pLVCD
->nmcd
.hdc
, text
.Mid(drawPos
), it
->cpMin
- drawPos
, &rc
, DT_SINGLELINE
| DT_VCENTER
| DT_NOPREFIX
| DT_END_ELLIPSIS
);
4122 DrawText(pLVCD
->nmcd
.hdc
, text
.Mid(drawPos
), it
->cpMin
- drawPos
, &rc
, DT_CALCRECT
| DT_SINGLELINE
| DT_VCENTER
| DT_NOPREFIX
| DT_END_ELLIPSIS
);
4126 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
);
4127 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
);
4129 rect
.left
= rc
.right
;
4132 drawPos
= it
->cpMin
;
4133 if (it
->cpMax
- drawPos
)
4137 ::SetTextColor(pLVCD
->nmcd
.hdc
, CTheme::Instance().GetThemeColor(colors
.GetColor(CColors::FilterMatch
), true));
4138 DrawText(pLVCD
->nmcd
.hdc
, text
.Mid(drawPos
), it
->cpMax
- drawPos
, &rc
, DT_SINGLELINE
| DT_VCENTER
| DT_NOPREFIX
| DT_END_ELLIPSIS
);
4139 DrawText(pLVCD
->nmcd
.hdc
, text
.Mid(drawPos
), it
->cpMax
- drawPos
, &rc
, DT_CALCRECT
| DT_SINGLELINE
| DT_VCENTER
| DT_NOPREFIX
| DT_END_ELLIPSIS
);
4140 ::SetTextColor(pLVCD
->nmcd
.hdc
, textColor
);
4144 opts
.crText
= CTheme::Instance().GetThemeColor(colors
.GetColor(CColors::FilterMatch
), true);
4145 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
);
4146 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
);
4147 opts
.crText
= textColor
;
4149 rect
.left
= rc
.right
;
4152 drawPos
= it
->cpMax
;
4155 DrawText(pLVCD
->nmcd
.hdc
, text
.Mid(drawPos
), -1, &rc
, DT_SINGLELINE
| DT_VCENTER
| DT_NOPREFIX
| DT_END_ELLIPSIS
);
4157 DrawThemeTextEx(hTheme
, pLVCD
->nmcd
.hdc
, LVP_LISTITEM
, txtState
, text
.Mid(drawPos
), -1, DT_SINGLELINE
| DT_VCENTER
| DT_NOPREFIX
| DT_END_ELLIPSIS
, &rc
, &opts
);
4160 bool CGitLogListBase::DrawListItemWithMatchesIfEnabled(std::shared_ptr
<CLogDlgFilter
> filter
, DWORD selectedFilter
, NMLVCUSTOMDRAW
* pLVCD
, LRESULT
* pResult
)
4162 if ((filter
->GetSelectedFilters() & selectedFilter
) && filter
->IsFilterActive())
4165 GetSubItemRect(static_cast<int>(pLVCD
->nmcd
.dwItemSpec
), pLVCD
->iSubItem
, LVIR_BOUNDS
, rect
);
4167 int index
= static_cast<int>(pLVCD
->nmcd
.dwItemSpec
);
4168 int state
= GetItemState(index
, LVIS_SELECTED
);
4169 int txtState
= LISS_NORMAL
;
4170 if (IsAppThemed() && GetHotItem() == static_cast<int>(index
))
4172 if (state
& LVIS_SELECTED
)
4173 txtState
= LISS_HOTSELECTED
;
4175 txtState
= LISS_HOT
;
4177 else if (state
& LVIS_SELECTED
)
4179 if (::GetFocus() == m_hWnd
)
4180 txtState
= LISS_SELECTED
;
4182 txtState
= LISS_SELECTEDNOTFOCUS
;
4185 CAutoThemeData hTheme
;
4188 hTheme
= OpenThemeData(m_hWnd
, L
"Explorer::ListView;ListView");
4190 // make sure the column separator/border is not overpainted
4191 int borderWidth
= 0;
4192 GetThemeMetric(hTheme
, pLVCD
->nmcd
.hdc
, LVP_LISTITEM
, LISS_NORMAL
, TMT_BORDERSIZE
, &borderWidth
);
4193 InflateRect(&rect
, -(2 * borderWidth
), 0);
4196 if (hTheme
&& IsThemeBackgroundPartiallyTransparent(hTheme
, LVP_LISTDETAIL
, txtState
))
4197 DrawThemeParentBackground(m_hWnd
, pLVCD
->nmcd
.hdc
, &rect
);
4200 HBRUSH brush
= ::CreateSolidBrush(pLVCD
->clrTextBk
);
4201 ::FillRect(pLVCD
->nmcd
.hdc
, rect
, brush
);
4202 ::DeleteObject(brush
);
4204 if (hTheme
&& txtState
!= LISS_NORMAL
)
4207 // get rect of whole line
4208 GetItemRect(index
, rt
, LVIR_BOUNDS
);
4211 // calculate background for rect of whole line, but limit redrawing to SubItem rect
4212 DrawThemeBackground(hTheme
, pLVCD
->nmcd
.hdc
, LVP_LISTITEM
, txtState
, rt
, rect2
);
4214 hTheme
.CloseHandle();
4215 // END: extended redraw
4217 FillBackGround(pLVCD
->nmcd
.hdc
, pLVCD
->nmcd
.dwItemSpec
, rect
);
4220 *pResult
= DrawListItemWithMatches(filter
.get(), *this, pLVCD
, m_Colors
);
4226 LRESULT
CGitLogListBase::DrawListItemWithMatches(CFilterHelper
* filter
, CListCtrl
& listCtrl
, NMLVCUSTOMDRAW
* pLVCD
, CColors
& colors
)
4228 CString text
= static_cast<LPCWSTR
>(listCtrl
.GetItemText(static_cast<int>(pLVCD
->nmcd
.dwItemSpec
), pLVCD
->iSubItem
));
4230 return CDRF_DODEFAULT
;
4232 std::vector
<CHARRANGE
> ranges
;
4233 filter
->GetMatchRanges(ranges
, text
, 0);
4235 return CDRF_DODEFAULT
;
4237 // even though we initialize the 'rect' here with nmcd.rc,
4238 // we must not use it but use the rects from GetItemRect()
4239 // and GetSubItemRect(). Because on XP, the nmcd.rc has
4240 // bogus data in it.
4241 CRect rect
= pLVCD
->nmcd
.rc
;
4243 // find the margin where the text label starts
4244 CRect labelRC
, boundsRC
, iconRC
;
4245 listCtrl
.GetItemRect(static_cast<int>(pLVCD
->nmcd
.dwItemSpec
), &labelRC
, LVIR_LABEL
);
4246 listCtrl
.GetItemRect(static_cast<int>(pLVCD
->nmcd
.dwItemSpec
), &iconRC
, LVIR_ICON
);
4247 listCtrl
.GetItemRect(static_cast<int>(pLVCD
->nmcd
.dwItemSpec
), &boundsRC
, LVIR_BOUNDS
);
4249 int leftmargin
= labelRC
.left
- boundsRC
.left
;
4250 if (pLVCD
->iSubItem
)
4251 leftmargin
-= iconRC
.Width();
4253 if (pLVCD
->iSubItem
!= 0)
4254 listCtrl
.GetSubItemRect(static_cast<int>(pLVCD
->nmcd
.dwItemSpec
), pLVCD
->iSubItem
, LVIR_BOUNDS
, rect
);
4256 int borderWidth
= 0;
4257 CAutoThemeData hTheme
;
4260 hTheme
= OpenThemeData(listCtrl
.m_hWnd
, L
"Explorer::ListView;ListView");
4261 GetThemeMetric(hTheme
, pLVCD
->nmcd
.hdc
, LVP_LISTITEM
, LISS_NORMAL
, TMT_BORDERSIZE
, &borderWidth
);
4264 borderWidth
= GetSystemMetrics(SM_CXBORDER
);
4266 if (listCtrl
.GetExtendedStyle() & LVS_EX_CHECKBOXES
)
4268 // I'm not very happy about this fixed margin here
4269 // but I haven't found a way to ask the system what
4270 // the margin really is.
4271 // At least it works on XP/Vista/win7/win8, and even with
4272 // increased font sizes
4276 LVITEM item
= { 0 };
4277 item
.iItem
= static_cast<int>(pLVCD
->nmcd
.dwItemSpec
);
4279 item
.mask
= LVIF_IMAGE
| LVIF_STATE
;
4280 item
.stateMask
= static_cast<UINT
>(-1);
4281 listCtrl
.GetItem(&item
);
4284 int txtState
= LISS_NORMAL
;
4287 HBRUSH brush
= nullptr;
4288 if (item
.state
& LVIS_SELECTED
)
4290 if (::GetFocus() == listCtrl
.GetSafeHwnd())
4292 brush
= ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT
));
4293 pLVCD
->clrText
= ::GetSysColor(COLOR_HIGHLIGHTTEXT
);
4297 brush
= ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE
));
4298 pLVCD
->clrText
= CTheme::Instance().IsDarkTheme() ? CTheme::darkTextColor
: GetSysColor(COLOR_WINDOWTEXT
);
4303 brush
= ::CreateSolidBrush(::GetSysColor(COLOR_WINDOW
));
4305 listCtrl
.GetSubItemRect(static_cast<int>(pLVCD
->nmcd
.dwItemSpec
), pLVCD
->iSubItem
, LVIR_LABEL
, my
);
4306 ::FillRect(pLVCD
->nmcd
.hdc
, my
, brush
);
4307 ::DeleteObject(brush
);
4311 if (listCtrl
.GetHotItem() == static_cast<int>(pLVCD
->nmcd
.dwItemSpec
))
4313 if (item
.state
& LVIS_SELECTED
)
4314 txtState
= LISS_HOTSELECTED
;
4316 txtState
= LISS_HOT
;
4318 else if (item
.state
& LVIS_SELECTED
)
4320 if (::GetFocus() == listCtrl
.GetSafeHwnd())
4321 txtState
= LISS_SELECTED
;
4323 txtState
= LISS_SELECTEDNOTFOCUS
;
4326 if (IsThemeBackgroundPartiallyTransparent(hTheme
, LVP_LISTDETAIL
, txtState
))
4327 DrawThemeParentBackground(listCtrl
.m_hWnd
, pLVCD
->nmcd
.hdc
, &rect
);
4330 HBRUSH brush
= ::CreateSolidBrush(pLVCD
->clrTextBk
);
4331 ::FillRect(pLVCD
->nmcd
.hdc
, rect
, brush
);
4332 ::DeleteObject(brush
);
4334 if (txtState
!= LISS_NORMAL
)
4337 listCtrl
.GetSubItemRect(static_cast<int>(pLVCD
->nmcd
.dwItemSpec
), pLVCD
->iSubItem
, LVIR_LABEL
, my
);
4338 if (pLVCD
->iSubItem
== 0)
4340 // also fill the icon part of the line
4345 // calculate background for rect of whole line, but limit redrawing to SubItem rect
4346 DrawThemeBackground(hTheme
, pLVCD
->nmcd
.hdc
, LVP_LISTITEM
, txtState
, boundsRC
, my
);
4350 // draw the icon for the first column
4351 if (pLVCD
->iSubItem
== 0)
4354 rect
.right
= rect
.left
+ listCtrl
.GetColumnWidth(0);
4355 rect
.left
= iconRC
.left
;
4357 if (item
.iImage
>= 0)
4363 dc
.Attach(pLVCD
->nmcd
.hdc
);
4364 int style
= ILD_TRANSPARENT
;
4367 auto whitebrush
= ::CreateSolidBrush(::GetSysColor(COLOR_WINDOW
));
4368 ::FillRect(dc
, iconRC
, whitebrush
);
4369 ::DeleteObject(whitebrush
);
4370 if (item
.state
& LVIS_SELECTED
)
4372 if (::GetFocus() == listCtrl
.GetSafeHwnd())
4373 style
= ILD_SELECTED
;
4378 listCtrl
.GetImageList(LVSIL_SMALL
)->Draw(&dc
, item
.iImage
, pt
, style
);
4380 leftmargin
-= iconRC
.left
;
4384 RECT irc
= boundsRC
;
4385 irc
.left
+= borderWidth
;
4386 irc
.right
= iconRC
.left
;
4389 if (item
.state
& LVIS_SELECTED
)
4391 if (listCtrl
.GetHotItem() == item
.iItem
)
4392 state
= CBS_CHECKEDHOT
;
4394 state
= CBS_CHECKEDNORMAL
;
4398 if (listCtrl
.GetHotItem() == item
.iItem
)
4399 state
= CBS_UNCHECKEDHOT
;
4401 if ((state
) && (listCtrl
.GetExtendedStyle() & LVS_EX_CHECKBOXES
))
4403 CAutoThemeData hTheme2
= OpenThemeData(listCtrl
.m_hWnd
, L
"BUTTON");
4404 DrawThemeBackground(hTheme2
, pLVCD
->nmcd
.hdc
, BP_CHECKBOX
, state
, &irc
, NULL
);
4408 InflateRect(&rect
, -(2 * borderWidth
), 0);
4410 rect
.left
+= leftmargin
;
4413 // is the column left- or right-aligned? (we don't handle centered (yet))
4415 Column
.mask
= LVCF_FMT
;
4416 listCtrl
.GetColumn(pLVCD
->iSubItem
, &Column
);
4417 if (Column
.fmt
& LVCFMT_RIGHT
)
4419 DrawText(pLVCD
->nmcd
.hdc
, text
, -1, &rc
, DT_CALCRECT
| DT_SINGLELINE
| DT_VCENTER
| DT_NOPREFIX
| DT_END_ELLIPSIS
);
4420 rect
.left
= rect
.right
- (rc
.right
- rc
.left
);
4423 rect
.left
+= 2 * borderWidth
;
4424 rect
.right
+= 2 * borderWidth
;
4428 DrawListItemWithMatchesRect(pLVCD
, ranges
, rect
, text
, colors
, hTheme
, txtState
);
4430 return CDRF_SKIPDEFAULT
;