Remember "subfolder" as correctly spelled
[TortoiseGit.git] / src / TortoiseGitBlame / TortoiseGitBlameView.cpp
blob64e302220d79a6d22f2393bccdf6259b0fc8e980
1 // TortoiseGitBlame - a Viewer for Git Blames
3 // Copyright (C) 2008-2024 - TortoiseGit
4 // Copyright (C) 2003-2008, 2014 - TortoiseSVN
6 // Copyright (C)2003 Don HO <donho@altern.org>
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License
10 // as published by the Free Software Foundation; either version 2
11 // of the License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software Foundation,
20 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 // CTortoiseGitBlameView.cpp : implementation of the CTortoiseGitBlameView class
25 #include "stdafx.h"
26 #include "TortoiseGitBlame.h"
27 #include "CommonAppUtils.h"
28 #include "TortoiseGitBlameDoc.h"
29 #include "TortoiseGitBlameView.h"
30 #include "MainFrm.h"
31 #include "EditGotoDlg.h"
32 #include "LoglistUtils.h"
33 #include "FileTextLines.h"
34 #include "UnicodeUtils.h"
35 #include "MenuEncode.h"
36 #include "gitdll.h"
37 #include "StringUtils.h"
38 #include "BlameIndexColors.h"
39 #include "BlameDetectMovedOrCopiedLines.h"
40 #include "TGitPath.h"
41 #include "IconMenu.h"
42 #include "DPIAware.h"
43 #include "Theme.h"
44 #include "DarkModeHelper.h"
45 #include "Lexilla.h"
46 #include "AutoCloakWindow.h"
48 #ifdef _DEBUG
49 #define new DEBUG_NEW
50 #endif
52 UINT CTortoiseGitBlameView::m_FindDialogMessage;
54 // CTortoiseGitBlameView
55 IMPLEMENT_DYNAMIC(CSciEditBlame,CSciEdit)
57 IMPLEMENT_DYNCREATE(CTortoiseGitBlameView, CView)
59 BEGIN_MESSAGE_MAP(CTortoiseGitBlameView, CView)
60 // Standard printing commands
61 ON_COMMAND(ID_EDIT_FIND,OnEditFind)
62 ON_COMMAND(ID_EDIT_GOTO,OnEditGoto)
63 ON_COMMAND(ID_EDIT_COPY, CopyToClipboard)
64 ON_UPDATE_COMMAND_UI(ID_EDIT_COPY, OnUpdateViewCopyToClipboard)
65 ON_COMMAND(ID_VIEW_NEXT,OnViewNext)
66 ON_COMMAND(ID_VIEW_PREV,OnViewPrev)
67 ON_COMMAND(ID_FIND_NEXT, OnFindNext)
68 ON_COMMAND(ID_FIND_PREV, OnFindPrev)
69 ON_COMMAND(ID_VIEW_SHOWLOGID, OnViewToggleLogID)
70 ON_UPDATE_COMMAND_UI(ID_VIEW_SHOWLOGID, OnUpdateViewToggleLogID)
71 ON_COMMAND(ID_VIEW_SHOWAUTHOR, OnViewToggleAuthor)
72 ON_UPDATE_COMMAND_UI(ID_VIEW_SHOWAUTHOR, OnUpdateViewToggleAuthor)
73 ON_COMMAND(ID_VIEW_SHOWDATE, OnViewToggleDate)
74 ON_UPDATE_COMMAND_UI(ID_VIEW_SHOWDATE, OnUpdateViewToggleDate)
75 ON_COMMAND(ID_VIEW_SHOWFILENAME, OnViewToggleShowFilename)
76 ON_UPDATE_COMMAND_UI(ID_VIEW_SHOWFILENAME, OnUpdateViewToggleShowFilename)
77 ON_COMMAND(ID_VIEW_SHOWORIGINALLINENUMBER, OnViewToggleShowOriginalLineNumber)
78 ON_UPDATE_COMMAND_UI(ID_VIEW_SHOWORIGINALLINENUMBER, OnUpdateViewToggleShowOriginalLineNumber)
79 ON_COMMAND(ID_VIEW_DETECT_MOVED_OR_COPIED_LINES_DISABLED, OnViewDetectMovedOrCopiedLinesToggleDisabled)
80 ON_UPDATE_COMMAND_UI(ID_VIEW_DETECT_MOVED_OR_COPIED_LINES_DISABLED, OnUpdateViewDetectMovedOrCopiedLinesToggleDisabled)
81 ON_COMMAND(ID_VIEW_DETECT_MOVED_OR_COPIED_LINES_WITHIN_FILE, OnViewDetectMovedOrCopiedLinesToggleWithinFile)
82 ON_UPDATE_COMMAND_UI(ID_VIEW_DETECT_MOVED_OR_COPIED_LINES_WITHIN_FILE, OnUpdateViewDetectMovedOrCopiedLinesToggleWithinFile)
83 ON_COMMAND(ID_VIEW_DETECT_MOVED_OR_COPIED_LINES_FROM_MODIFIED_FILES, OnViewDetectMovedOrCopiedLinesToggleFromModifiedFiles)
84 ON_UPDATE_COMMAND_UI(ID_VIEW_DETECT_MOVED_OR_COPIED_LINES_FROM_MODIFIED_FILES, OnUpdateViewDetectMovedOrCopiedLinesToggleFromModifiedFiles)
85 ON_COMMAND(ID_VIEW_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES_AT_FILE_CREATION, OnViewDetectMovedOrCopiedLinesToggleFromExistingFilesAtFileCreation)
86 ON_UPDATE_COMMAND_UI(ID_VIEW_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES_AT_FILE_CREATION, OnUpdateViewDetectMovedOrCopiedLinesToggleFromExistingFilesAtFileCreation)
87 ON_COMMAND(ID_VIEW_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES, OnViewDetectMovedOrCopiedLinesToggleFromExistingFiles)
88 ON_UPDATE_COMMAND_UI(ID_VIEW_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES, OnUpdateViewDetectMovedOrCopiedLinesToggleFromExistingFiles)
89 ON_COMMAND(ID_VIEW_IGNORE_WHITESPACE, OnViewToggleIgnoreWhitespace)
90 ON_UPDATE_COMMAND_UI(ID_VIEW_IGNORE_WHITESPACE, OnUpdateViewToggleIgnoreWhitespace)
91 ON_COMMAND(ID_VIEW_SHOWCOMPLETELOG, OnViewToggleShowCompleteLog)
92 ON_UPDATE_COMMAND_UI(ID_VIEW_SHOWCOMPLETELOG, OnUpdateViewToggleShowCompleteLog)
93 ON_COMMAND(ID_VIEW_ONLYCONSIDERFIRSTPARENTS, OnViewToggleOnlyFirstParent)
94 ON_UPDATE_COMMAND_UI(ID_VIEW_ONLYCONSIDERFIRSTPARENTS, OnUpdateViewToggleOnlyFirstParent)
95 ON_COMMAND(ID_VIEW_FOLLOWRENAMES, OnViewToggleFollowRenames)
96 ON_UPDATE_COMMAND_UI(ID_VIEW_FOLLOWRENAMES, OnUpdateViewToggleFollowRenames)
97 ON_COMMAND(ID_VIEW_COLORBYAGE, OnViewToggleColorByAge)
98 ON_UPDATE_COMMAND_UI(ID_VIEW_COLORBYAGE, OnUpdateViewToggleColorByAge)
99 ON_COMMAND(ID_VIEW_ENABLELEXER, OnViewToggleLexer)
100 ON_UPDATE_COMMAND_UI(ID_VIEW_ENABLELEXER, OnUpdateViewToggleLexer)
101 ON_COMMAND(ID_VIEW_DARKMODE, OnViewToggleDarkMode)
102 ON_UPDATE_COMMAND_UI(ID_VIEW_DARKMODE, OnUpdateViewToggleDarkMode)
103 ON_COMMAND(ID_VIEW_WRAPLONGLINES, OnViewWrapLongLines)
104 ON_UPDATE_COMMAND_UI(ID_VIEW_WRAPLONGLINES, OnUpdateViewWrapLongLines)
105 ON_COMMAND_RANGE(IDM_FORMAT_ENCODE, IDM_FORMAT_ENCODE_END, OnChangeEncode)
106 ON_WM_CREATE()
107 ON_WM_SIZE()
108 ON_WM_MOUSEMOVE()
109 ON_WM_MOUSEHOVER()
110 ON_WM_MOUSELEAVE()
111 ON_WM_LBUTTONDOWN()
112 ON_WM_RBUTTONDOWN()
113 ON_WM_RBUTTONUP()
114 ON_WM_SYSCOLORCHANGE()
115 ON_WM_DESTROY()
116 ON_WM_ERASEBKGND()
117 ON_NOTIFY(SCN_PAINTED, IDC_SCINTILLA, OnSciPainted)
118 ON_NOTIFY(SCN_GETBKCOLOR, IDC_SCINTILLA, OnSciGetBkColor)
119 ON_NOTIFY(SCN_ZOOM, IDC_SCINTILLA, OnSciZoom)
120 ON_REGISTERED_MESSAGE(m_FindDialogMessage, OnFindDialogMessage)
121 END_MESSAGE_MAP()
124 // CTortoiseGitBlameView construction/destruction
126 CTortoiseGitBlameView::CTortoiseGitBlameView()
128 m_colorage = !!theApp.GetInt(L"ColorAge", !CTheme::Instance().IsHighContrastMode());
129 m_bLexer = !!theApp.GetInt(L"EnableLexer", !CTheme::Instance().IsHighContrastMode());
131 m_bShowLogID = (theApp.GetInt(L"ShowLogID", 0) == 1);
132 m_bShowAuthor = (theApp.GetInt(L"ShowAuthor", 1) == 1);
133 m_bShowDate = (theApp.GetInt(L"ShowDate", 0) == 1);
134 m_bShowFilename = (theApp.GetInt(L"ShowFilename", 0) == 1);
135 m_bShowOriginalLineNumber = (theApp.GetInt(L"ShowOriginalLineNumber", 0) == 1);
136 m_dwDetectMovedOrCopiedLines = theApp.GetInt(L"DetectMovedOrCopiedLines", 0);
137 m_bIgnoreWhitespace = (theApp.GetInt(L"IgnoreWhitespace", 0) == 1);
138 m_bShowCompleteLog = (theApp.GetInt(L"ShowCompleteLog", 1) == 1);
139 m_bOnlyFirstParent = (theApp.GetInt(L"OnlyFirstParent", 0) == 1);
140 m_bFollowRenames = (theApp.GetInt(L"FollowRenames", 0) == 1);
141 m_bBlameOutputContainsOtherFilenames = FALSE;
142 m_bWrapLongLines = !!theApp.GetInt(L"WrapLongLines", 0);
143 m_sFindText = theApp.GetString(L"FindString");
145 m_FindDialogMessage = ::RegisterWindowMessage(FINDMSGSTRING);
146 // get short/long datetime setting from registry
147 DWORD RegUseShortDateFormat = CRegDWORD(L"Software\\TortoiseGit\\LogDateFormat", TRUE);
148 if ( RegUseShortDateFormat )
150 m_DateFormat = DATE_SHORTDATE;
152 else
154 m_DateFormat = DATE_LONGDATE;
156 // get relative time display setting from registry
157 DWORD regRelativeTimes = CRegDWORD(L"Software\\TortoiseGit\\RelativeTimes", FALSE);
158 m_bRelativeTimes = (regRelativeTimes != 0);
160 m_sRev.LoadString(IDS_LOG_REVISION);
161 m_sFileName.LoadString(IDS_FILENAME);
162 m_sAuthor.LoadString(IDS_LOG_AUTHOR);
163 m_sDate.LoadString(IDS_LOG_DATE);
164 m_sMessage.LoadString(IDS_LOG_MESSAGE);
167 CTortoiseGitBlameView::~CTortoiseGitBlameView()
169 #ifdef USE_TEMPFILENAME
170 delete m_Buffer;
171 m_Buffer = nullptr;
172 #endif
174 struct EncodingUnit
176 int id;
177 const char* name;
180 static EncodingUnit encodings[] = {
181 {1250, "windows-1250"}, //IDM_FORMAT_WIN_1250
182 {1251, "windows-1251"}, //IDM_FORMAT_WIN_1251
183 {1252, "windows-1252"}, //IDM_FORMAT_WIN_1252
184 {1253, "windows-1253"}, //IDM_FORMAT_WIN_1253
185 {1254, "windows-1254"}, //IDM_FORMAT_WIN_1254
186 {1255, "windows-1255"}, //IDM_FORMAT_WIN_1255
187 {1256, "windows-1256"}, //IDM_FORMAT_WIN_1256
188 {1257, "windows-1257"}, //IDM_FORMAT_WIN_1257
189 {1258, "windows-1258"}, //IDM_FORMAT_WIN_1258
190 {28591, "latin1 ISO_8859-1 ISO-8859-1 CP819 IBM819 csISOLatin1 iso-ir-100 l1"}, //IDM_FORMAT_ISO_8859_1
191 {28592, "latin2 ISO_8859-2 ISO-8859-2 csISOLatin2 iso-ir-101 l2"}, //IDM_FORMAT_ISO_8859_2
192 {28593, "latin3 ISO_8859-3 ISO-8859-3 csISOLatin3 iso-ir-109 l3"}, //IDM_FORMAT_ISO_8859_3
193 {28594, "latin4 ISO_8859-4 ISO-8859-4 csISOLatin4 iso-ir-110 l4"}, //IDM_FORMAT_ISO_8859_4
194 {28595, "cyrillic ISO_8859-5 ISO-8859-5 csISOLatinCyrillic iso-ir-144"}, //IDM_FORMAT_ISO_8859_5
195 {28596, "arabic ISO_8859-6 ISO-8859-6 csISOLatinArabic iso-ir-127 ASMO-708 ECMA-114"}, //IDM_FORMAT_ISO_8859_6
196 {28597, "greek ISO_8859-7 ISO-8859-7 csISOLatinGreek greek8 iso-ir-126 ELOT_928 ECMA-118"}, //IDM_FORMAT_ISO_8859_7
197 {28598, "hebrew ISO_8859-8 ISO-8859-8 csISOLatinHebrew iso-ir-138"}, //IDM_FORMAT_ISO_8859_8
198 {28599, "latin5 ISO_8859-9 ISO-8859-9 csISOLatin5 iso-ir-148 l5"}, //IDM_FORMAT_ISO_8859_9
199 {28600, "latin6 ISO_8859-10 ISO-8859-10 csISOLatin6 iso-ir-157 l6"}, //IDM_FORMAT_ISO_8859_10
200 {28601, "ISO_8859-11 ISO-8859-11"}, //IDM_FORMAT_ISO_8859_11
201 {28603, "ISO_8859-13 ISO-8859-13"}, //IDM_FORMAT_ISO_8859_13
202 {28604, "iso-celtic latin8 ISO_8859-14 ISO-8859-14 18 iso-ir-199"}, //IDM_FORMAT_ISO_8859_14
203 {28605, "Latin-9 ISO_8859-15 ISO-8859-15"}, //IDM_FORMAT_ISO_8859_15
204 {28606, "latin10 ISO_8859-16 ISO-8859-16 110 iso-ir-226"}, //IDM_FORMAT_ISO_8859_16
205 {437, "IBM437 cp437 437 csPC8CodePage437"}, //IDM_FORMAT_DOS_437
206 {720, "IBM720 cp720 oem720 720"}, //IDM_FORMAT_DOS_720
207 {737, "IBM737 cp737 oem737 737"}, //IDM_FORMAT_DOS_737
208 {775, "IBM775 cp775 oem775 775"}, //IDM_FORMAT_DOS_775
209 {850, "IBM850 cp850 oem850 850"}, //IDM_FORMAT_DOS_850
210 {852, "IBM852 cp852 oem852 852"}, //IDM_FORMAT_DOS_852
211 {855, "IBM855 cp855 oem855 855 csIBM855"}, //IDM_FORMAT_DOS_855
212 {857, "IBM857 cp857 oem857 857"}, //IDM_FORMAT_DOS_857
213 {858, "IBM858 cp858 oem858 858"}, //IDM_FORMAT_DOS_858
214 {860, "IBM860 cp860 oem860 860"}, //IDM_FORMAT_DOS_860
215 {861, "IBM861 cp861 oem861 861"}, //IDM_FORMAT_DOS_861
216 {862, "IBM862 cp862 oem862 862"}, //IDM_FORMAT_DOS_862
217 {863, "IBM863 cp863 oem863 863"}, //IDM_FORMAT_DOS_863
218 {865, "IBM865 cp865 oem865 865"}, //IDM_FORMAT_DOS_865
219 {866, "IBM866 cp866 oem866 866"}, //IDM_FORMAT_DOS_866
220 {869, "IBM869 cp869 oem869 869"}, //IDM_FORMAT_DOS_869
221 {950, "big5 csBig5"}, //IDM_FORMAT_BIG5
222 {936, "gb2312 gbk csGB2312"}, //IDM_FORMAT_GB2312
223 {932, "Shift_JIS MS_Kanji csShiftJIS csWindows31J"}, //IDM_FORMAT_SHIFT_JIS
224 {949, "windows-949 korean"}, //IDM_FORMAT_KOREAN_WIN
225 {51949, "euc-kr csEUCKR"}, //IDM_FORMAT_EUC_KR
226 {874, "tis-620"}, //IDM_FORMAT_TIS_620
227 {10007, "x-mac-cyrillic xmaccyrillic"}, //IDM_FORMAT_MAC_CYRILLIC
228 {21866, "koi8_u"}, //IDM_FORMAT_KOI8U_CYRILLIC
229 {20866, "koi8_r csKOI8R"}, //IDM_FORMAT_KOI8R_CYRILLIC
230 {65001, "UTF-8"}, //IDM_FORMAT_UTF8
231 {1200, "UTF-16 LE"}, //IDM_FORMAT_UTF16LE
232 {1201, "UTF-16 BE"}, //IDM_FORMAT_UTF16BE
234 void CTortoiseGitBlameView::OnChangeEncode(UINT nId)
236 if(nId >= IDM_FORMAT_ENCODE && nId <= IDM_FORMAT_ENCODE_END)
237 this->UpdateInfo(encodings[nId - IDM_FORMAT_ENCODE].id);
239 int CTortoiseGitBlameView::OnCreate(LPCREATESTRUCT lpcs)
241 CRect rect,rect1;
242 this->GetWindowRect(&rect1);
243 rect.left = m_blamewidth + CDPIAware::Instance().ScaleX(GetSafeHwnd(), LOCATOR_WIDTH);
244 rect.right=rect.Width();
245 rect.top=0;
246 rect.bottom=rect.Height();
247 if (!m_TextView.Create(L"Scintilla", L"source", 0, rect, this, IDC_SCINTILLA, 0))
249 TRACE0("Failed to create view\n");
250 return -1; // fail to create
252 m_TextView.Init(-1);
253 m_TextView.m_bNoAutomaticStyling = true;
254 m_TextView.ShowWindow( SW_SHOW);
255 CreateFont();
256 m_TextView.SetReadOnly(true);
257 m_ToolTip.Create(this->GetParent());
259 m_themeCallbackId = CTheme::Instance().RegisterThemeChangeCallback([this]() { SetTheme(CTheme::Instance().IsDarkTheme()); });
260 SetTheme(CTheme::Instance().IsDarkTheme());
261 ::AfxGetApp()->GetMainWnd();
262 return CView::OnCreate(lpcs);
265 void CTortoiseGitBlameView::OnSize(UINT /*nType*/, int cx, int cy)
267 CRect rect;
268 rect.left=m_blamewidth;
269 rect.right=cx;
270 rect.top=0;
271 rect.bottom=cy;
273 m_TextView.MoveWindow(&rect);
275 BOOL CTortoiseGitBlameView::PreCreateWindow(CREATESTRUCT& cs)
277 return CView::PreCreateWindow(cs);
280 // CTortoiseGitBlameView drawing
282 BOOL CTortoiseGitBlameView::OnEraseBkgnd(CDC* /*pDC*/)
284 return TRUE;
287 void CTortoiseGitBlameView::OnDraw(CDC* pDC)
289 CTortoiseGitBlameDoc* pDoc = GetDocument();
290 ASSERT_VALID(pDoc);
291 if (!pDoc)
292 return;
294 CMemDC myDC(*pDC, this);
295 RECT rc;
296 GetClientRect(&rc);
297 myDC.GetDC().FillSolidRect(&rc, m_windowcolor);
298 DrawBlame(myDC.GetDC());
299 DrawLocatorBar(myDC.GetDC());
302 int CTortoiseGitBlameView::GetLineUnderCursor(CPoint point)
304 auto firstvisibleline = static_cast<int>(SendEditor(SCI_GETFIRSTVISIBLELINE));
305 auto line = static_cast<int>(SendEditor(SCI_DOCLINEFROMVISIBLE, firstvisibleline));
306 auto linesonscreen = static_cast<int>(SendEditor(SCI_LINESONSCREEN)) + 1;
307 auto height = static_cast<int>(SendEditor(SCI_TEXTHEIGHT));
309 int i = 0, y = 0;
310 for (i = line; y <= point.y && i < (line + linesonscreen); ++i)
312 auto wrapcount = static_cast<int>(SendEditor(SCI_WRAPCOUNT, i));
313 if (wrapcount > 1)
315 if (i == line)
316 wrapcount -= static_cast<int>(SendEditor(SCI_DOCLINEFROMVISIBLE, firstvisibleline + wrapcount - 1)) - static_cast<int>(SendEditor(SCI_DOCLINEFROMVISIBLE, firstvisibleline));
317 linesonscreen -= wrapcount - 1;
319 y += height * wrapcount;
321 return i - 1;
324 void CTortoiseGitBlameView::OnRButtonUp(UINT /*nFlags*/, CPoint point)
326 int line = GetLineUnderCursor(point);
327 if (m_data.IsValidLine(line))
329 m_MouseLine = line;
330 ClientToScreen(&point);
332 CGitHash hash = m_data.GetHash(line);
333 CString hashStr = hash.ToString();
335 GitRevLoglist* pRev = nullptr;
336 int logIndex = m_lineToLogIndex[line];
337 if (logIndex >= 0)
338 pRev = &GetLogData()->GetGitRevAt(logIndex);
339 else
341 pRev = m_data.GetRev(line, GetLogData()->m_pLogCache->m_HashMap);
342 if (pRev && pRev->m_ParentHash.empty())
344 if (pRev->GetParentFromHash(pRev->m_CommitHash))
345 MessageBox(pRev->GetLastErr(), L"TortoiseGit", MB_ICONERROR);
349 if (!pRev)
350 return;
352 CIconMenu popup;
353 CIconMenu blamemenu, diffmenu;
355 if (!popup.CreatePopupMenu())
356 return;
358 // Now find the relevant parent commits, they must contain the file which is blamed to be the source of the selected line,
359 // otherwise there is no previous file to compare to (only another previous revision).
361 GIT_REV_LIST parentHashWithFile;
362 std::vector<CString> parentFilename;
365 CTGitPath path(m_data.GetFilename(line));
366 auto files = pRev->GetFiles(nullptr);
367 for (int j = 0, j_size = files.GetCount(); j < j_size; ++j)
369 const CTGitPath &file = files[j];
370 if (file.IsEquivalentTo(path))
372 if (!(file.m_ParentNo & MERGE_MASK))
374 int action = file.m_Action;
375 // ignore (action & CTGitPath::LOGACTIONS_ADDED), as then there is nothing to blame/diff
376 // ignore (action & CTGitPath::LOGACTIONS_DELETED), should never happen as the file must exist
377 if (action & (CTGitPath::LOGACTIONS_MODIFIED | CTGitPath::LOGACTIONS_REPLACED))
379 int parentNo = file.m_ParentNo & PARENT_MASK;
380 if (parentNo >= 0 && static_cast<size_t>(parentNo) < pRev->m_ParentHash.size())
382 parentHashWithFile.push_back(pRev->m_ParentHash[parentNo]);
383 parentFilename.push_back((action & CTGitPath::LOGACTIONS_REPLACED) ? file.GetGitOldPathString() : file.GetGitPathString());
390 catch (const char* msg)
392 MessageBox(L"Could not get files of parents.\nlibgit reports:\n" + CUnicodeUtils::GetUnicode(msg), L"TortoiseGit", MB_ICONERROR);
395 // blame previous
396 if (!parentHashWithFile.empty())
398 if (parentHashWithFile.size() == 1)
400 popup.AppendMenuIcon(ID_BLAMEPREVIOUS, IDS_BLAME_POPUP_BLAME, IDI_BLAME_POPUP_BLAME);
402 else
404 blamemenu.CreatePopupMenu();
405 popup.AppendMenuIcon(ID_BLAMEPREVIOUS, IDS_BLAME_POPUP_BLAME, IDI_BLAME_POPUP_BLAME, blamemenu.m_hMenu);
407 for (size_t i = 0; i < parentHashWithFile.size(); ++i)
409 CString str;
410 str.Format(IDS_PARENT, i + 1);
411 blamemenu.AppendMenuIcon(ID_BLAMEPREVIOUS + ((i + 1) << 16), str);
416 // compare with previous
417 if (!parentHashWithFile.empty())
419 if (parentHashWithFile.size() == 1)
421 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_BLAME_POPUP_COMPARE, IDI_BLAME_POPUP_COMPARE);
422 if (CRegDWORD(L"Software\\TortoiseGit\\DiffByDoubleClickInLog", FALSE))
423 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
425 else
427 diffmenu.CreatePopupMenu();
428 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_BLAME_POPUP_COMPARE, IDI_BLAME_POPUP_COMPARE, diffmenu.m_hMenu);
429 for (size_t i = 0; i < parentHashWithFile.size(); ++i)
431 CString str;
432 str.Format(IDS_BLAME_POPUP_PARENT, i + 1);
433 diffmenu.AppendMenuIcon(static_cast<UINT>(ID_COMPAREWITHPREVIOUS + ((i + 1) << 16)),str);
434 if (i == 0 && CRegDWORD(L"Software\\TortoiseGit\\DiffByDoubleClickInLog", FALSE))
436 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
437 diffmenu.SetDefaultItem(static_cast<UINT>(ID_COMPAREWITHPREVIOUS + ((i + 1) << 16)), FALSE);
443 popup.AppendMenuIcon(ID_SHOWLOG, IDS_BLAME_POPUP_LOG, IDI_BLAME_POPUP_LOG);
444 popup.AppendMenu(MF_SEPARATOR, NULL);
445 popup.AppendMenuIcon(ID_COPYHASHTOCLIPBOARD, IDS_BLAME_POPUP_COPYHASHTOCLIPBOARD, IDI_BLAME_POPUP_COPY);
446 popup.AppendMenuIcon(ID_COPYLOGTOCLIPBOARD, IDS_BLAME_POPUP_COPYLOGTOCLIPBOARD, IDI_BLAME_POPUP_COPY);
448 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this);
449 if (!cmd)
450 return;
451 this->ContextMenuAction(cmd, pRev, parentHashWithFile, parentFilename, line);
455 void CTortoiseGitBlameView::ContextMenuAction(int cmd, GitRev *pRev, GIT_REV_LIST& parentHashWithFile, const std::vector<CString>& parentFilename, int selectedLine)
457 switch (cmd & 0xFFFF)
459 case ID_BLAMEPREVIOUS:
461 int index = (cmd>>16) & 0xFFFF;
462 if (index > 0)
463 index -= 1;
465 CString path = ResolveCommitFile(parentFilename[index]);
466 CString endrev = parentHashWithFile[index].ToString();
467 int line = m_data.GetOriginalLineNumber(selectedLine);
469 CString procCmd = L"/path:\"" + path + L"\" ";
470 procCmd += L" /command:blame";
471 procCmd += L" /endrev:" + endrev;
472 procCmd += L" /line:";
473 procCmd.AppendFormat(L"%d", line);
475 CCommonAppUtils::RunTortoiseGitProc(procCmd);
477 break;
479 case ID_COMPAREWITHPREVIOUS:
481 int index = (cmd >> 16) & 0xFFFF;
482 if (index > 0)
483 index -= 1;
485 CString path = ResolveCommitFile(parentFilename[index]);
486 CString startrev = parentHashWithFile[index].ToString();
487 CString endrev = pRev->m_CommitHash.ToString();
489 CString procCmd = L"/path:\"" + path + L"\" ";
490 procCmd += L" /command:diff";
491 procCmd += L" /startrev:" + startrev;
492 procCmd += L" /endrev:" + endrev;
493 if (!!(GetAsyncKeyState(VK_SHIFT) & 0x8000))
494 procCmd += L" /alternative";
496 CCommonAppUtils::RunTortoiseGitProc(procCmd);
498 break;
500 case ID_SHOWLOG:
502 CString path = ResolveCommitFile(selectedLine);
503 CString rev = m_data.GetHash(selectedLine).ToString();
505 CString procCmd = L"/path:\"" + path + L"\" ";
506 procCmd += L" /command:log";
507 procCmd += L" /rev:" + rev;
508 procCmd += L" /endrev:" + rev;
510 CCommonAppUtils::RunTortoiseGitProc(procCmd);
512 break;
514 case ID_COPYHASHTOCLIPBOARD:
515 this->GetLogList()->CopySelectionToClipBoard(CGitLogListBase::ID_COPYCLIPBOARDHASH);
516 break;
518 case ID_COPYLOGTOCLIPBOARD:
519 this->GetLogList()->CopySelectionToClipBoard(CGitLogListBase::ID_COPYCLIPBOARDFULL);
520 break;
524 // CTortoiseGitBlameView diagnostics
526 #ifdef _DEBUG
527 void CTortoiseGitBlameView::AssertValid() const
529 CView::AssertValid();
532 void CTortoiseGitBlameView::Dump(CDumpContext& dc) const
534 CView::Dump(dc);
537 CTortoiseGitBlameDoc* CTortoiseGitBlameView::GetDocument() const // non-debug version is inline
539 ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTortoiseGitBlameDoc)));
540 return static_cast<CTortoiseGitBlameDoc*>(m_pDocument);
542 #endif //_DEBUG
545 // Return a color which is interpolated between c1 and c2.
546 // Slider controls the relative proportions as a percentage:
547 // Slider = 0 represents pure c1
548 // Slider = 50 represents equal mixture
549 // Slider = 100 represents pure c2
550 COLORREF CTortoiseGitBlameView::InterColor(COLORREF c1, COLORREF c2, int Slider)
552 int r, g, b;
554 // Limit Slider to 0..100% range
555 if (Slider < 0)
556 Slider = 0;
557 if (Slider > 100)
558 Slider = 100;
560 // The color components have to be treated individually.
561 r = (GetRValue(c2) * Slider + GetRValue(c1) * (100 - Slider)) / 100;
562 g = (GetGValue(c2) * Slider + GetGValue(c1) * (100 - Slider)) / 100;
563 b = (GetBValue(c2) * Slider + GetBValue(c1) * (100 - Slider)) / 100;
565 return RGB(r, g, b);
568 LRESULT CTortoiseGitBlameView::SendEditor(UINT Msg, WPARAM wParam, LPARAM lParam)
570 return m_TextView.Call(Msg, wParam, lParam);
573 void CTortoiseGitBlameView::SetAStyle(int style, COLORREF fore, COLORREF back, int size, const char *face)
575 if (fore == back && fore == m_windowcolor)
576 fore = m_textcolor;
577 else if (CTheme::Instance().IsDarkTheme())
578 fore = CTheme::Instance().GetThemeColor(fore);
579 m_TextView.SetAStyle(style, fore, back, size, face);
582 void CTortoiseGitBlameView::InitialiseEditor()
584 SendEditor(SCI_SETTABWIDTH, static_cast<DWORD>(CRegStdDWORD(L"Software\\TortoiseGit\\BlameTabSize", 4)));
585 OnSciZoom(nullptr, nullptr);
588 m_regOldLinesColor = CRegStdDWORD(L"Software\\TortoiseGit\\BlameOldColor", BLAMEOLDCOLOR);
589 m_regNewLinesColor = CRegStdDWORD(L"Software\\TortoiseGit\\BlameNewColor", BLAMENEWCOLOR);
590 m_regDarkOldLinesColor = CRegStdDWORD(L"Software\\TortoiseGit\\BlameOldColorDark", DARKBLAMEOLDCOLOR);
591 m_regDarkNewLinesColor = CRegStdDWORD(L"Software\\TortoiseGit\\BlameNewColorDark", DARKBLAMENEWCOLOR);
592 if (CRegStdDWORD(L"Software\\TortoiseGit\\ScintillaDirect2D", FALSE) != FALSE)
594 SendEditor(SCI_SETTECHNOLOGY, SC_TECHNOLOGY_DIRECTWRITERETAIN);
595 SendEditor(SCI_SETBUFFEREDDRAW, 0);
598 if (m_bWrapLongLines)
599 SendEditor(SCI_SETWRAPMODE, SC_WRAP_WORD);
600 else
601 SendEditor(SCI_SETWRAPMODE, SC_WRAP_NONE);
603 if (CTheme::Instance().IsDarkTheme())
605 SendEditor(SCI_SETSELFORE, TRUE, CTheme::Instance().GetThemeColor(RGB(0, 0, 0)));
606 SendEditor(SCI_SETSELBACK, TRUE, CTheme::Instance().GetThemeColor(RGB(51, 153, 255)));
607 SendEditor(SCI_STYLESETFORE, STYLE_DEFAULT, BlameTextColorDark);
608 SendEditor(SCI_STYLESETBACK, STYLE_DEFAULT, BlameBackColorDark);
609 SendEditor(SCI_STYLECLEARALL);
610 SendEditor(SCI_SETCARETFORE, BlameTextColorDark);
611 SendEditor(SCI_SETWHITESPACEFORE, true, RGB(180, 180, 180));
613 else
615 SendEditor(SCI_SETSELFORE, TRUE, ::GetSysColor(COLOR_HIGHLIGHTTEXT));
616 SendEditor(SCI_SETSELBACK, TRUE, ::GetSysColor(COLOR_HIGHLIGHT));
617 SendEditor(SCI_STYLESETFORE, STYLE_DEFAULT, ::GetSysColor(COLOR_WINDOWTEXT));
618 SendEditor(SCI_STYLESETBACK, STYLE_DEFAULT, ::GetSysColor(COLOR_WINDOW));
619 SendEditor(SCI_STYLECLEARALL);
620 SendEditor(SCI_SETCARETFORE, ::GetSysColor(COLOR_WINDOWTEXT));
621 SendEditor(SCI_SETWHITESPACEFORE, true, ::GetSysColor(COLOR_3DSHADOW));
622 SendEditor(SCI_SETFOLDMARGINCOLOUR, true, RGB(240, 240, 240));
623 SendEditor(SCI_SETFOLDMARGINHICOLOUR, true, RGB(255, 255, 255));
624 SendEditor(SCI_STYLESETFORE, STYLE_LINENUMBER, RGB(109, 109, 109));
625 SendEditor(SCI_STYLESETBACK, STYLE_LINENUMBER, RGB(230, 230, 230));
627 SendEditor(SCI_STYLESETFORE, STYLE_BRACELIGHT, RGB(0, 150, 0));
628 SendEditor(SCI_STYLESETBOLD, STYLE_BRACELIGHT, 1);
629 SendEditor(SCI_STYLESETFORE, STYLE_BRACEBAD, RGB(255, 0, 0));
630 SendEditor(SCI_STYLESETBOLD, STYLE_BRACEBAD, 1);
632 if (CTheme::Instance().IsDarkTheme() || CTheme::Instance().IsHighContrastModeDark())
634 SendEditor(SCI_STYLESETFORE, STYLE_LINENUMBER, RGB(140, 140, 140));
635 SendEditor(SCI_STYLESETBACK, STYLE_LINENUMBER, BlameBackColorDark);
636 SendEditor(SCI_SETFOLDMARGINCOLOUR, true, BlameTextColorDark);
637 SendEditor(SCI_SETFOLDMARGINHICOLOUR, true, RGB(0, 0, 0));
639 if (m_bLexer)
640 SetupLexer(m_sLastFilename);
643 bool CTortoiseGitBlameView::DoSearch(CTortoiseGitBlameData::SearchDirection direction)
645 auto pos = static_cast<Sci_Position>(SendEditor(SCI_GETCURRENTPOS));
646 auto line = static_cast<int>(SendEditor(SCI_LINEFROMPOSITION, pos));
648 int i = m_data.FindFirstLineWrapAround(direction, m_sFindText, line, m_bMatchCase, [hWnd = m_pFindDialog->GetSafeHwnd()]{ FLASHWINFO flags = { sizeof(FLASHWINFO), hWnd, FLASHW_ALL, 2, 100 }; ::FlashWindowEx(&flags); });
649 if (i >= 0)
651 GotoLine(i + 1);
652 auto selstart = static_cast<int>(static_cast<Sci_Position>(SendEditor(SCI_GETCURRENTPOS)));
653 auto selend = static_cast<int>(static_cast<Sci_Position>(SendEditor(SCI_POSITIONFROMLINE, i + 1)));
654 SendEditor(SCI_SETSELECTIONSTART, selstart);
655 SendEditor(SCI_SETSELECTIONEND, selend);
656 m_SelectedLine = i;
658 else
659 ::MessageBox(m_pFindDialog && m_pFindDialog->GetSafeHwnd() ? m_pFindDialog->GetSafeHwnd() : GetSafeHwnd(), L"\"" + m_sFindText + L"\" " + CString(MAKEINTRESOURCE(IDS_NOTFOUND)), L"TortoiseGitBlame", MB_ICONINFORMATION);
661 return true;
664 void CTortoiseGitBlameView::OnFindPrev()
666 if (m_sFindText.IsEmpty())
667 return;
668 DoSearch(CTortoiseGitBlameData::SearchPrevious);
671 void CTortoiseGitBlameView::OnFindNext()
673 if (m_sFindText.IsEmpty())
674 return;
675 DoSearch(CTortoiseGitBlameData::SearchNext);
678 bool CTortoiseGitBlameView::GotoLine(int line)
680 --line;
681 const int numberOfLines = static_cast<int>(m_data.GetNumberOfLines());
682 if (line < 0 || numberOfLines == 0)
683 return false;
684 if (line >= numberOfLines)
686 line = numberOfLines - 1;
689 auto nCurrentPos = static_cast<Sci_Position>(SendEditor(SCI_GETCURRENTPOS));
690 int nCurrentLine = static_cast<int>(SendEditor(SCI_LINEFROMPOSITION, nCurrentPos));
691 int nFirstVisibleLine = static_cast<int>(SendEditor(SCI_GETFIRSTVISIBLELINE));
692 int nLinesOnScreen = static_cast<int>(SendEditor(SCI_LINESONSCREEN));
694 if ( line>=nFirstVisibleLine && line<=nFirstVisibleLine+nLinesOnScreen)
696 // no need to scroll
697 SendEditor(SCI_GOTOLINE, line);
699 else
701 // Place the requested line one third from the top
702 if ( line > nCurrentLine )
704 SendEditor(SCI_GOTOLINE, static_cast<WPARAM>(line + nLinesOnScreen * (2 / 3.0)));
706 else
708 SendEditor(SCI_GOTOLINE, static_cast<WPARAM>(line - nLinesOnScreen * (1 / 3.0)));
712 // Highlight the line
713 int nPosStart = static_cast<int>(SendEditor(SCI_POSITIONFROMLINE, line));
714 int nPosEnd = static_cast<int>(SendEditor(SCI_GETLINEENDPOSITION, line));
715 SendEditor(SCI_SETSEL,nPosEnd,nPosStart);
717 return true;
720 bool CTortoiseGitBlameView::ScrollToLine(long line)
722 if (line < 0)
723 return false;
725 int nCurrentLine = static_cast<int>(SendEditor(SCI_GETFIRSTVISIBLELINE));
727 int scrolldelta = line - nCurrentLine;
728 SendEditor(SCI_LINESCROLL, 0, scrolldelta);
730 return true;
733 void CTortoiseGitBlameView::CopyToClipboard()
735 CWnd * wnd = GetFocus();
736 if (wnd == this->GetLogList())
737 GetLogList()->CopySelectionToClipBoard();
738 else if (wnd)
740 if (CString(wnd->GetRuntimeClass()->m_lpszClassName) == L"CMFCPropertyGridCtrl")
742 auto grid = static_cast<CMFCPropertyGridCtrl*>(wnd);
743 if (grid->GetCurSel() && !grid->GetCurSel()->IsGroup())
744 CStringUtils::WriteAsciiStringToClipboard(grid->GetCurSel()->GetValue(), GetSafeHwnd());
746 else
747 m_TextView.Call(SCI_COPY);
751 void CTortoiseGitBlameView::SetTheme(bool bDark)
753 DarkModeHelper::Instance().AllowDarkModeForWindow(GetSafeHwnd(), bDark);
754 SetupColoring();
755 InitialiseEditor();
757 CMFCVisualManager::GetInstance()->OnUpdateSystemColors();
758 CMFCVisualManager::RedrawAll();
760 ::RedrawWindow(GetSafeHwnd(), nullptr, nullptr, RDW_FRAME | RDW_INVALIDATE | RDW_ERASE | RDW_INTERNALPAINT | RDW_ALLCHILDREN | RDW_UPDATENOW);
763 LONG CTortoiseGitBlameView::GetBlameWidth()
765 LONG blamewidth = CDPIAware::Instance().ScaleX(GetSafeHwnd(), LOCATOR_WIDTH) + CDPIAware::Instance().ScaleX(GetSafeHwnd(), BLAMESPACE);
766 SIZE width;
767 CreateFont();
768 HDC hDC = this->GetDC()->m_hDC;
769 HFONT oldfont = static_cast<HFONT>(::SelectObject(hDC, m_font.GetSafeHandle()));
771 if (!m_bShowLogID)
773 CString shortHash('f', g_Git.GetShortHASHLength());
774 ::GetTextExtentPoint32(hDC, shortHash, g_Git.GetShortHASHLength(), &width);
775 m_revwidth = width.cx + CDPIAware::Instance().ScaleX(GetSafeHwnd(), BLAMESPACE);
776 blamewidth += m_revwidth;
778 else
780 const auto length = static_cast<int>(std::ceil(std::log10(GetLogList()->GetItemCount() + 1)));
781 m_sLogIDFormat.Format(L"%%%dd", length);
782 ::GetTextExtentPoint32(hDC, CString(L'8', length), length, &width);
783 m_logidwidth = width.cx + CDPIAware::Instance().ScaleX(GetSafeHwnd(), BLAMESPACE);
784 blamewidth += m_logidwidth;
786 if (m_bShowDate)
788 SIZE maxwidth = {0};
790 const auto numberOfLines = m_data.GetNumberOfLines();
791 for (size_t i = 0; i < numberOfLines; ++i)
793 ::GetTextExtentPoint32(hDC, m_data.GetDate(i), m_data.GetDate(i).GetLength(), &width);
794 if (width.cx > maxwidth.cx)
795 maxwidth = width;
797 m_datewidth = maxwidth.cx + CDPIAware::Instance().ScaleX(GetSafeHwnd(), BLAMESPACE);
798 blamewidth += m_datewidth;
800 if ( m_bShowAuthor)
802 SIZE maxwidth = {0};
804 const size_t numberOfLines = m_data.GetNumberOfLines();
805 for (size_t i = 0; i < numberOfLines; ++i)
807 ::GetTextExtentPoint32(hDC,m_data.GetAuthor(i) , m_data.GetAuthor(i).GetLength(), &width);
808 if (width.cx > maxwidth.cx)
809 maxwidth = width;
811 m_authorwidth = maxwidth.cx + CDPIAware::Instance().ScaleX(GetSafeHwnd(), BLAMESPACE);
812 blamewidth += m_authorwidth;
814 if (m_bShowFilename)
816 SIZE maxwidth = {0};
818 const size_t numberOfLines = m_data.GetNumberOfLines();
819 for (size_t i = 0; i < numberOfLines; ++i)
821 ::GetTextExtentPoint32(hDC, m_data.GetFilename(i), m_data.GetFilename(i).GetLength(), &width);
822 if (width.cx > maxwidth.cx)
823 maxwidth = width;
825 m_filenameWidth = maxwidth.cx + CDPIAware::Instance().ScaleX(GetSafeHwnd(), BLAMESPACE);
826 blamewidth += m_filenameWidth;
828 if (m_bShowOriginalLineNumber)
830 SIZE maxwidth = {0};
832 const size_t numberOfLines = m_data.GetNumberOfLines();
833 CString str;
834 for (size_t i = 0; i < numberOfLines; ++i)
836 str.Format(L"%5d", m_data.GetOriginalLineNumber(i));
837 ::GetTextExtentPoint32(hDC, str, str.GetLength(), &width);
838 if (width.cx > maxwidth.cx)
839 maxwidth = width;
841 m_originalLineNumberWidth = maxwidth.cx + CDPIAware::Instance().ScaleX(GetSafeHwnd(), BLAMESPACE);
842 blamewidth += m_originalLineNumberWidth;
844 ::SelectObject(hDC, oldfont);
845 POINT pt = {blamewidth, 0};
846 LPtoDP(hDC, &pt, 1);
847 m_blamewidth = pt.x;
848 //::ReleaseDC(wBlame, hDC);
849 return blamewidth;
852 void CTortoiseGitBlameView::CreateFont()
854 if (m_font.GetSafeHandle())
855 return;
857 CreateNewFont(false);
860 void CTortoiseGitBlameView::CreateNewFont(bool resize)
862 m_font.DeleteObject();
863 LOGFONT lf = { 0 };
864 lf.lfWeight = 400;
865 lf.lfHeight = -CDPIAware::Instance().PointsToPixelsY(GetSafeHwnd(), static_cast<DWORD>(CRegStdDWORD(L"Software\\TortoiseGit\\BlameFontSize", 10))) - static_cast<int>(SendEditor(SCI_GETZOOM));
866 lf.lfCharSet = DEFAULT_CHARSET;
867 CRegStdString fontname = CRegStdString(L"Software\\TortoiseGit\\BlameFontName", L"Consolas");
868 wcsncpy_s(lf.lfFaceName, static_cast<std::wstring>(fontname).c_str(), _TRUNCATE);
869 m_font.CreateFontIndirect(&lf);
871 lf.lfItalic = TRUE;
872 m_italicfont.DeleteObject();
873 m_italicfont.CreateFontIndirect(&lf);
875 if (!resize || !m_pDocument)
876 return;
878 CRect rect;
879 this->GetClientRect(&rect);
880 rect.left = GetBlameWidth();
881 m_TextView.MoveWindow(&rect);
884 void CTortoiseGitBlameView::DrawBlame(HDC hDC)
886 if (!hDC || m_data.GetNumberOfLines() == 0)
887 return;
888 if (!m_font.GetSafeHandle())
889 return;
891 HFONT oldfont = nullptr;
892 int firstvisibleline = static_cast<int>(SendEditor(SCI_GETFIRSTVISIBLELINE));
893 int line = static_cast<int>(SendEditor(SCI_DOCLINEFROMVISIBLE, firstvisibleline));
894 int linesonscreen = static_cast<int>(SendEditor(SCI_LINESONSCREEN)) + 1;
895 int height = static_cast<int>(SendEditor(SCI_TEXTHEIGHT));
896 int Y = 0;
897 wchar_t buf[MAX_PATH] = { 0 };
898 std::fill_n(buf, _countof(buf) - 1, L' ');
899 CGitHash oldHash;
900 CString oldFile;
902 for (int i = line; i < (line + linesonscreen) && static_cast<size_t>(i) < m_data.GetNumberOfLines(); ++i)
904 auto wrapcount = static_cast<int>(SendEditor(SCI_WRAPCOUNT, i));
905 if (wrapcount > 1)
907 if (i == line)
908 wrapcount -= static_cast<int>(SendEditor(SCI_DOCLINEFROMVISIBLE, firstvisibleline + wrapcount - 1)) - static_cast<int>(SendEditor(SCI_DOCLINEFROMVISIBLE, firstvisibleline));
909 linesonscreen -= wrapcount - 1;
911 CGitHash hash(m_data.GetHash(i));
912 oldfont = static_cast<HFONT>(::SelectObject(hDC, m_font.GetSafeHandle()));
913 ::SetBkColor(hDC, m_windowcolor);
914 ::SetTextColor(hDC, m_textcolor);
915 bool hashMatches = !hash.IsEmpty() && m_selectedHashes.contains(hash);
916 if (hashMatches)
918 ::SetBkColor(hDC, m_selectedauthorcolor);
919 ::SetTextColor(hDC, m_texthighlightcolor);
922 if (m_MouseLine == i)
923 ::SetBkColor(hDC, m_mouserevcolor);
925 if (hashMatches || m_MouseLine == i)
927 auto old = ::GetTextColor(hDC);
928 ::SetTextColor(hDC, ::GetBkColor(hDC));
929 RECT rc2 = { CDPIAware::Instance().ScaleX(GetSafeHwnd(), LOCATOR_WIDTH), Y, m_blamewidth + CDPIAware::Instance().ScaleX(GetSafeHwnd(), LOCATOR_WIDTH), Y + (wrapcount * height) };
930 for (int j = 0; j < wrapcount; ++j)
931 ::ExtTextOut(hDC, 0, Y + (j * height), ETO_CLIPPED, &rc2, buf, _countof(buf) - 1, 0);
932 ::SetTextColor(hDC, old);
935 CString file = m_data.GetFilename(i);
936 if (oldHash != hash || (m_bShowFilename && oldFile != file) || m_bShowOriginalLineNumber)
938 RECT rc;
939 rc.top = static_cast<LONG>(Y);
940 rc.left = CDPIAware::Instance().ScaleX(GetSafeHwnd(), LOCATOR_WIDTH) + CDPIAware::Instance().ScaleX(GetSafeHwnd(), BLAMESPACE);
941 rc.bottom = static_cast<LONG>(Y + height);
942 rc.right = m_blamewidth;
944 if (!m_bShowLogID)
946 if (oldHash != hash)
948 CString shortHashStr = hash.ToString(g_Git.GetShortHASHLength());
949 ::ExtTextOut(hDC, rc.left, rc.top, ETO_CLIPPED, &rc, shortHashStr, shortHashStr.GetLength(), 0);
951 rc.left += m_revwidth;
953 else
955 if (oldHash != hash)
957 CString str;
958 str.Format(m_sLogIDFormat, GetLogList()->GetItemCount() - m_lineToLogIndex[i]);
959 if (m_lineToLogIndex[i] < 0)
960 str = "0";
961 ::ExtTextOut(hDC, rc.left, rc.top, ETO_CLIPPED, &rc, str, str.GetLength(), 0);
963 rc.left += m_logidwidth;
965 if (m_bShowAuthor)
967 if (oldHash != hash)
968 ::DrawText(hDC, m_data.GetAuthor(i), m_data.GetAuthor(i).GetLength(), &rc, DT_HIDEPREFIX | DT_NOPREFIX | DT_SINGLELINE);
969 rc.left += m_authorwidth;
971 if (m_bShowDate)
973 if (oldHash != hash)
974 ::DrawText(hDC, m_data.GetDate(i), m_data.GetDate(i).GetLength(), &rc, DT_HIDEPREFIX | DT_NOPREFIX | DT_SINGLELINE);
975 rc.left += m_datewidth;
977 if (m_bShowFilename)
979 if (oldFile != file)
980 ::DrawText(hDC, m_data.GetFilename(i), m_data.GetFilename(i).GetLength(), &rc, DT_HIDEPREFIX | DT_NOPREFIX | DT_SINGLELINE);
981 rc.left += m_filenameWidth;
983 if (m_bShowOriginalLineNumber)
985 CString str;
986 str.Format(L"%5d", m_data.GetOriginalLineNumber(i));
987 ::ExtTextOut(hDC, rc.left, rc.top, ETO_CLIPPED, &rc, str, str.GetLength(), 0);
988 rc.left += m_originalLineNumberWidth;
990 oldHash = hash;
991 oldFile = file;
993 if (i == m_SelectedLine && m_pFindDialog)
995 LOGBRUSH brush;
996 brush.lbColor = m_textcolor;
997 brush.lbHatch = 0;
998 brush.lbStyle = BS_SOLID;
999 HPEN pen = ExtCreatePen(PS_SOLID | PS_GEOMETRIC, 2, &brush, 0, nullptr);
1000 HGDIOBJ hPenOld = SelectObject(hDC, pen);
1001 RECT rc2 = { CDPIAware::Instance().ScaleX(GetSafeHwnd(), LOCATOR_WIDTH), Y + 1, m_blamewidth, Y + (wrapcount * height) - 1 };
1002 ::MoveToEx(hDC, rc2.left, rc2.top, nullptr);
1003 ::LineTo(hDC, rc2.right, rc2.top);
1004 ::LineTo(hDC, rc2.right, rc2.bottom);
1005 ::LineTo(hDC, rc2.left, rc2.bottom);
1006 ::LineTo(hDC, rc2.left, rc2.top);
1007 SelectObject(hDC, hPenOld);
1008 DeleteObject(pen);
1010 Y += wrapcount * height;
1011 ::SelectObject(hDC, oldfont);
1015 void CTortoiseGitBlameView::DrawLocatorBar(HDC hDC)
1017 if (!hDC)
1018 return;
1020 int line = static_cast<int>(SendEditor(SCI_GETFIRSTVISIBLELINE));
1021 int linesonscreen = static_cast<int>(SendEditor(SCI_LINESONSCREEN));
1022 int Y = 0;
1023 COLORREF blackColor = CTheme::Instance().GetThemeColor(GetSysColor(COLOR_WINDOWTEXT));
1025 RECT rc;
1026 this->GetClientRect(&rc);
1028 rc.right = CDPIAware::Instance().ScaleX(GetSafeHwnd(), LOCATOR_WIDTH);
1030 RECT lineRect = rc;
1031 LONG height = rc.bottom-rc.top;
1033 const auto numberOfLines = static_cast<int>(m_data.GetNumberOfLines());
1034 // draw the colored bar
1035 for (int currentLine = 0; currentLine < numberOfLines; ++currentLine)
1037 COLORREF cr = GetLineColor(currentLine);
1038 // get the line color
1039 if ((currentLine >= line)&&(currentLine < (line + linesonscreen)))
1041 cr = InterColor(cr, blackColor, 10);
1043 SetBkColor(hDC, cr);
1044 lineRect.top = static_cast<LONG>(Y);
1045 lineRect.bottom = ((currentLine + 1) * height / numberOfLines);
1046 ::ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &lineRect, nullptr, 0, nullptr);
1047 Y = lineRect.bottom;
1050 if (numberOfLines > 0)
1052 // now draw two lines indicating the scroll position of the source view
1053 SetBkColor(hDC, blackColor);
1054 lineRect.top = static_cast<LONG>(line) * height / numberOfLines;
1055 lineRect.bottom = lineRect.top+1;
1056 ::ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &lineRect, nullptr, 0, nullptr);
1057 lineRect.top = static_cast<LONG>(line + linesonscreen) * height / numberOfLines;
1058 lineRect.bottom = lineRect.top+1;
1059 ::ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &lineRect, nullptr, 0, nullptr);
1063 void CTortoiseGitBlameView::SetupLexer(CString filename)
1065 int start = filename.ReverseFind(L'.');
1066 SendEditor(SCI_SETILEXER, 0, reinterpret_cast<sptr_t>(nullptr));
1067 if (!m_bLexer)
1068 return;
1069 if (start > 0)
1071 //wcscpy_s(line, 20, lineptr+1);
1072 //_wcslwr_s(line, 20);
1073 CString ext=filename.Right(filename.GetLength()-start-1);
1074 const wchar_t* line = ext;
1076 if ((wcscmp(line, L"py") == 0) ||
1077 (wcscmp(line, L"pyw") == 0))
1079 SendEditor(SCI_SETILEXER, 0, reinterpret_cast<sptr_t>(CreateLexer("python")));
1080 SendEditor(SCI_SETKEYWORDS, 0, reinterpret_cast<LPARAM>(m_TextView.StringForControl(L"and assert break class continue def del elif \
1081 else except exec finally for from global if import in is lambda None \
1082 not or pass print raise return try while yield").GetBuffer()));
1083 SetAStyle(SCE_P_DEFAULT, black);
1084 SetAStyle(SCE_P_COMMENTLINE, darkGreen);
1085 SetAStyle(SCE_P_NUMBER, RGB(0, 0x80, 0x80));
1086 SetAStyle(SCE_P_STRING, RGB(0, 0, 0x80));
1087 SetAStyle(SCE_P_CHARACTER, RGB(0, 0, 0x80));
1088 SetAStyle(SCE_P_WORD, RGB(0x80, 0, 0x80));
1089 SetAStyle(SCE_P_TRIPLE, black);
1090 SetAStyle(SCE_P_TRIPLEDOUBLE, black);
1091 SetAStyle(SCE_P_CLASSNAME, darkBlue);
1092 SetAStyle(SCE_P_DEFNAME, darkBlue);
1093 SetAStyle(SCE_P_OPERATOR, darkBlue);
1094 SetAStyle(SCE_P_IDENTIFIER, darkBlue);
1095 SetAStyle(SCE_P_COMMENTBLOCK, darkGreen);
1096 SetAStyle(SCE_P_STRINGEOL, red);
1098 if ((wcscmp(line, L"c") == 0) ||
1099 (wcscmp(line, L"cc") == 0) ||
1100 (wcscmp(line, L"cpp") == 0) ||
1101 (wcscmp(line, L"cxx") == 0) ||
1102 (wcscmp(line, L"h") == 0) ||
1103 (wcscmp(line, L"hh") == 0) ||
1104 (wcscmp(line, L"hpp") == 0) ||
1105 (wcscmp(line, L"hxx") == 0) ||
1106 (wcscmp(line, L"dlg") == 0) ||
1107 (wcscmp(line, L"mak") == 0))
1109 SendEditor(SCI_SETILEXER, 0, reinterpret_cast<sptr_t>(CreateLexer("cpp")));
1110 SendEditor(SCI_SETKEYWORDS, 0, reinterpret_cast<LPARAM>(m_TextView.StringForControl(L"and and_eq asm auto bitand bitor bool break \
1111 case catch char class compl const const_cast continue \
1112 default delete do double dynamic_cast else enum explicit export extern false float for \
1113 friend goto if inline int long mutable namespace new not not_eq \
1114 operator or or_eq private protected public \
1115 register reinterpret_cast return short signed sizeof static static_cast struct switch \
1116 template this throw true try typedef typeid typename union unsigned using \
1117 virtual void volatile wchar_t while xor xor_eq").GetBuffer()));
1118 SendEditor(SCI_SETKEYWORDS, 3, reinterpret_cast<LPARAM>(m_TextView.StringForControl(L"a addindex addtogroup anchor arg attention \
1119 author b brief bug c class code date def defgroup deprecated dontinclude \
1120 e em endcode endhtmlonly endif endlatexonly endlink endverbatim enum example exception \
1121 f$ f[ f] file fn hideinitializer htmlinclude htmlonly \
1122 if image include ingroup internal invariant interface latexonly li line link \
1123 mainpage name namespace nosubgrouping note overload \
1124 p page par param post pre ref relates remarks return retval \
1125 sa section see showinitializer since skip skipline struct subsection \
1126 test throw todo typedef union until \
1127 var verbatim verbinclude version warning weakgroup $ @ \\ & < > # { }").GetBuffer()));
1128 SetupCppLexer();
1130 if (wcscmp(line, L"cs") == 0)
1132 SendEditor(SCI_SETILEXER, 0, reinterpret_cast<sptr_t>(CreateLexer("cpp")));
1133 SendEditor(SCI_SETKEYWORDS, 0, reinterpret_cast<LPARAM>(m_TextView.StringForControl(L"abstract as base bool break byte case catch char checked class \
1134 const continue decimal default delegate do double else enum \
1135 event explicit extern false finally fixed float for foreach goto if \
1136 implicit in int interface internal is lock long namespace new null \
1137 object operator out override params private protected public \
1138 readonly ref return sbyte sealed short sizeof stackalloc static \
1139 string struct switch this throw true try typeof uint ulong \
1140 unchecked unsafe ushort using virtual void while").GetBuffer()));
1141 SetupCppLexer();
1143 if ((wcscmp(line, L"rc") == 0) ||
1144 (wcscmp(line, L"rc2") == 0))
1146 SendEditor(SCI_SETILEXER, 0, reinterpret_cast<sptr_t>(CreateLexer("cpp")));
1147 SendEditor(SCI_SETKEYWORDS, 0, reinterpret_cast<LPARAM>(m_TextView.StringForControl(L"ACCELERATORS ALT AUTO3STATE AUTOCHECKBOX AUTORADIOBUTTON \
1148 BEGIN BITMAP BLOCK BUTTON CAPTION CHARACTERISTICS CHECKBOX CLASS \
1149 COMBOBOX CONTROL CTEXT CURSOR DEFPUSHBUTTON DIALOG DIALOGEX DISCARDABLE \
1150 EDITTEXT END EXSTYLE FONT GROUPBOX ICON LANGUAGE LISTBOX LTEXT \
1151 MENU MENUEX MENUITEM MESSAGETABLE POPUP \
1152 PUSHBUTTON RADIOBUTTON RCDATA RTEXT SCROLLBAR SEPARATOR SHIFT STATE3 \
1153 STRINGTABLE STYLE TEXTINCLUDE VALUE VERSION VERSIONINFO VIRTKEY").GetBuffer()));
1154 SetupCppLexer();
1156 if ((wcscmp(line, L"idl") == 0) ||
1157 (wcscmp(line, L"odl") == 0))
1159 SendEditor(SCI_SETILEXER, 0, reinterpret_cast<sptr_t>(CreateLexer("cpp")));
1160 SendEditor(SCI_SETKEYWORDS, 0, reinterpret_cast<LPARAM>(m_TextView.StringForControl(L"aggregatable allocate appobject arrays async async_uuid \
1161 auto_handle \
1162 bindable boolean broadcast byte byte_count \
1163 call_as callback char coclass code comm_status \
1164 const context_handle context_handle_noserialize \
1165 context_handle_serialize control cpp_quote custom \
1166 decode default defaultbind defaultcollelem \
1167 defaultvalue defaultvtable dispinterface displaybind dllname \
1168 double dual \
1169 enable_allocate encode endpoint entry enum error_status_t \
1170 explicit_handle \
1171 fault_status first_is float \
1172 handle_t heap helpcontext helpfile helpstring \
1173 helpstringcontext helpstringdll hidden hyper \
1174 id idempotent ignore iid_as iid_is immediatebind implicit_handle \
1175 import importlib in include in_line int __int64 __int3264 interface \
1176 last_is lcid length_is library licensed local long \
1177 max_is maybe message methods midl_pragma \
1178 midl_user_allocate midl_user_free min_is module ms_union \
1179 ncacn_at_dsp ncacn_dnet_nsp ncacn_http ncacn_ip_tcp \
1180 ncacn_nb_ipx ncacn_nb_nb ncacn_nb_tcp ncacn_np \
1181 ncacn_spx ncacn_vns_spp ncadg_ip_udp ncadg_ipx ncadg_mq \
1182 ncalrpc nocode nonbrowsable noncreatable nonextensible notify \
1183 object odl oleautomation optimize optional out out_of_line \
1184 pipe pointer_default pragma properties propget propput propputref \
1185 ptr public \
1186 range readonly ref represent_as requestedit restricted retval \
1187 shape short signed size_is small source strict_context_handle \
1188 string struct switch switch_is switch_type \
1189 transmit_as typedef \
1190 uidefault union unique unsigned user_marshal usesgetlasterror uuid \
1191 v1_enum vararg version void wchar_t wire_marshal").GetBuffer()));
1192 SetupCppLexer();
1194 if (wcscmp(line, L"java") == 0)
1196 SendEditor(SCI_SETILEXER, 0, reinterpret_cast<sptr_t>(CreateLexer("cpp")));
1197 SendEditor(SCI_SETKEYWORDS, 0, reinterpret_cast<LPARAM>(m_TextView.StringForControl(L"abstract assert boolean break byte case catch char class \
1198 const continue default do double else extends final finally float for future \
1199 generic goto if implements import inner instanceof int interface long \
1200 native new null outer package private protected public rest \
1201 return short static super switch synchronized this throw throws \
1202 transient try var void volatile while").GetBuffer()));
1203 SetupCppLexer();
1205 if (wcscmp(line, L"js") == 0)
1207 SendEditor(SCI_SETILEXER, 0, reinterpret_cast<sptr_t>(CreateLexer("cpp")));
1208 SendEditor(SCI_SETKEYWORDS, 0, reinterpret_cast<LPARAM>(m_TextView.StringForControl(L"abstract boolean break byte case catch char class \
1209 const continue debugger default delete do double else enum export extends \
1210 final finally float for function goto if implements import in instanceof \
1211 int interface long native new package private protected public \
1212 return short static super switch synchronized this throw throws \
1213 transient try typeof var void volatile while with").GetBuffer()));
1214 SetupCppLexer();
1216 if ((wcscmp(line, L"pas") == 0) ||
1217 (wcscmp(line, L"dpr") == 0) ||
1218 (wcscmp(line, L"pp") == 0))
1220 SendEditor(SCI_SETILEXER, 0, reinterpret_cast<sptr_t>(CreateLexer("pascal")));
1221 SendEditor(SCI_SETKEYWORDS, 0, reinterpret_cast<LPARAM>(m_TextView.StringForControl(L"and array as begin case class const constructor \
1222 destructor div do downto else end except file finally \
1223 for function goto if implementation in inherited \
1224 interface is mod not object of on or packed \
1225 procedure program property raise record repeat \
1226 set shl shr then threadvar to try type unit \
1227 until uses var while with xor").GetBuffer()));
1228 SetupCppLexer();
1230 if ((wcscmp(line, L"as") == 0) ||
1231 (wcscmp(line, L"asc") == 0) ||
1232 (wcscmp(line, L"jsfl") == 0))
1234 SendEditor(SCI_SETILEXER, 0, reinterpret_cast<sptr_t>(CreateLexer("cpp")));
1235 SendEditor(SCI_SETKEYWORDS, 0, reinterpret_cast<LPARAM>(m_TextView.StringForControl(L"add and break case catch class continue default delete do \
1236 dynamic else eq extends false finally for function ge get gt if implements import in \
1237 instanceof interface intrinsic le lt ne new not null or private public return \
1238 set static super switch this throw true try typeof undefined var void while with").GetBuffer()));
1239 SendEditor(SCI_SETKEYWORDS, 1, reinterpret_cast<LPARAM>(m_TextView.StringForControl(L"Array Arguments Accessibility Boolean Button Camera Color \
1240 ContextMenu ContextMenuItem Date Error Function Key LoadVars LocalConnection Math \
1241 Microphone Mouse MovieClip MovieClipLoader NetConnection NetStream Number Object \
1242 PrintJob Selection SharedObject Sound Stage String StyleSheet System TextField \
1243 TextFormat TextSnapshot Video Void XML XMLNode XMLSocket \
1244 _accProps _focusrect _global _highquality _parent _quality _root _soundbuftime \
1245 arguments asfunction call capabilities chr clearInterval duplicateMovieClip \
1246 escape eval fscommand getProperty getTimer getURL getVersion gotoAndPlay gotoAndStop \
1247 ifFrameLoaded Infinity -Infinity int isFinite isNaN length loadMovie loadMovieNum \
1248 loadVariables loadVariablesNum maxscroll mbchr mblength mbord mbsubstring MMExecute \
1249 NaN newline nextFrame nextScene on onClipEvent onUpdate ord parseFloat parseInt play \
1250 prevFrame prevScene print printAsBitmap printAsBitmapNum printNum random removeMovieClip \
1251 scroll set setInterval setProperty startDrag stop stopAllSounds stopDrag substring \
1252 targetPath tellTarget toggleHighQuality trace unescape unloadMovie unLoadMovieNum updateAfterEvent").GetBuffer()));
1253 SetupCppLexer();
1255 if ((wcscmp(line, L"html") == 0) ||
1256 (wcscmp(line, L"htm") == 0) ||
1257 (wcscmp(line, L"shtml") == 0) ||
1258 (wcscmp(line, L"htt") == 0) ||
1259 (wcscmp(line, L"xml") == 0) ||
1260 (wcscmp(line, L"asp") == 0) ||
1261 (wcscmp(line, L"xsl") == 0) ||
1262 (wcscmp(line, L"php") == 0) ||
1263 (wcscmp(line, L"xhtml") == 0) ||
1264 (wcscmp(line, L"phtml") == 0) ||
1265 (wcscmp(line, L"cfm") == 0) ||
1266 (wcscmp(line, L"tpl") == 0) ||
1267 (wcscmp(line, L"dtd") == 0) ||
1268 (wcscmp(line, L"hta") == 0) ||
1269 (wcscmp(line, L"htd") == 0) ||
1270 (wcscmp(line, L"wxs") == 0))
1272 SendEditor(SCI_SETILEXER, 0, reinterpret_cast<sptr_t>(CreateLexer("hypertext")));
1273 SendEditor(SCI_SETKEYWORDS, 0, reinterpret_cast<LPARAM>(m_TextView.StringForControl(L"a abbr acronym address applet area b base basefont \
1274 bdo big blockquote body br button caption center \
1275 cite code col colgroup dd del dfn dir div dl dt em \
1276 fieldset font form frame frameset h1 h2 h3 h4 h5 h6 \
1277 head hr html i iframe img input ins isindex kbd label \
1278 legend li link map menu meta noframes noscript \
1279 object ol optgroup option p param pre q s samp \
1280 script select small span strike strong style sub sup \
1281 table tbody td textarea tfoot th thead title tr tt u ul \
1282 var xml xmlns abbr accept-charset accept accesskey action align alink \
1283 alt archive axis background bgcolor border \
1284 cellpadding cellspacing char charoff charset checked cite \
1285 class classid clear codebase codetype color cols colspan \
1286 compact content coords \
1287 data datafld dataformatas datapagesize datasrc datetime \
1288 declare defer dir disabled enctype event \
1289 face for frame frameborder \
1290 headers height href hreflang hspace http-equiv \
1291 id ismap label lang language leftmargin link longdesc \
1292 marginwidth marginheight maxlength media method multiple \
1293 name nohref noresize noshade nowrap \
1294 object onblur onchange onclick ondblclick onfocus \
1295 onkeydown onkeypress onkeyup onload onmousedown \
1296 onmousemove onmouseover onmouseout onmouseup \
1297 onreset onselect onsubmit onunload \
1298 profile prompt readonly rel rev rows rowspan rules \
1299 scheme scope selected shape size span src standby start style \
1300 summary tabindex target text title topmargin type usemap \
1301 valign value valuetype version vlink vspace width \
1302 text password checkbox radio submit reset \
1303 file hidden image").GetBuffer()));
1304 SendEditor(SCI_SETKEYWORDS, 1, reinterpret_cast<LPARAM>(m_TextView.StringForControl(L"assign audio block break catch choice clear disconnect else elseif \
1305 emphasis enumerate error exit field filled form goto grammar help \
1306 if initial link log menu meta noinput nomatch object option p paragraph \
1307 param phoneme prompt property prosody record reprompt return s say-as \
1308 script sentence subdialog submit throw transfer value var voice vxml").GetBuffer()));
1309 SendEditor(SCI_SETKEYWORDS, 2, reinterpret_cast<LPARAM>(m_TextView.StringForControl(L"accept age alphabet anchor application base beep bridge category charset \
1310 classid cond connecttimeout content contour count dest destexpr dtmf dtmfterm \
1311 duration enctype event eventexpr expr expritem fetchtimeout finalsilence \
1312 gender http-equiv id level maxage maxstale maxtime message messageexpr \
1313 method mime modal mode name namelist next nextitem ph pitch range rate \
1314 scope size sizeexpr skiplist slot src srcexpr sub time timeexpr timeout \
1315 transferaudio type value variant version volume xml:lang").GetBuffer()));
1316 SendEditor(SCI_SETKEYWORDS, 3, reinterpret_cast<LPARAM>(m_TextView.StringForControl(L"and assert break class continue def del elif \
1317 else except exec finally for from global if import in is lambda None \
1318 not or pass print raise return try while yield").GetBuffer()));
1319 SendEditor(SCI_SETKEYWORDS, 4, reinterpret_cast<LPARAM>(m_TextView.StringForControl(L"and argv as argc break case cfunction class continue declare default do \
1320 die echo else elseif empty enddeclare endfor endforeach endif endswitch \
1321 endwhile e_all e_parse e_error e_warning eval exit extends false for \
1322 foreach function global http_cookie_vars http_get_vars http_post_vars \
1323 http_post_files http_env_vars http_server_vars if include include_once \
1324 list new not null old_function or parent php_os php_self php_version \
1325 print require require_once return static switch stdclass this true var \
1326 xor virtual while __file__ __line__ __sleep __wakeup").GetBuffer()));
1328 SetAStyle(SCE_H_TAG, darkBlue);
1329 SetAStyle(SCE_H_TAGUNKNOWN, red);
1330 SetAStyle(SCE_H_ATTRIBUTE, darkBlue);
1331 SetAStyle(SCE_H_ATTRIBUTEUNKNOWN, red);
1332 SetAStyle(SCE_H_NUMBER, RGB(0x80,0,0x80));
1333 SetAStyle(SCE_H_DOUBLESTRING, RGB(0,0x80,0));
1334 SetAStyle(SCE_H_SINGLESTRING, RGB(0,0x80,0));
1335 SetAStyle(SCE_H_OTHER, RGB(0x80,0,0x80));
1336 SetAStyle(SCE_H_COMMENT, RGB(0x80,0x80,0));
1337 SetAStyle(SCE_H_ENTITY, RGB(0x80,0,0x80));
1339 SetAStyle(SCE_H_TAGEND, darkBlue);
1340 SetAStyle(SCE_H_XMLSTART, darkBlue); // <?
1341 SetAStyle(SCE_H_QUESTION, darkBlue); // <?
1342 SetAStyle(SCE_H_XMLEND, darkBlue); // ?>
1343 SetAStyle(SCE_H_SCRIPT, darkBlue); // <script
1344 SetAStyle(SCE_H_ASP, RGB(0x4F, 0x4F, 0), RGB(0xFF, 0xFF, 0)); // <% ... %>
1345 SetAStyle(SCE_H_ASPAT, RGB(0x4F, 0x4F, 0), RGB(0xFF, 0xFF, 0)); // <%@ ... %>
1347 SetAStyle(SCE_HB_DEFAULT, black);
1348 SetAStyle(SCE_HB_COMMENTLINE, darkGreen);
1349 SetAStyle(SCE_HB_NUMBER, RGB(0,0x80,0x80));
1350 SetAStyle(SCE_HB_WORD, darkBlue);
1351 SendEditor(SCI_STYLESETBOLD, SCE_HB_WORD, 1);
1352 SetAStyle(SCE_HB_STRING, RGB(0x80,0,0x80));
1353 SetAStyle(SCE_HB_IDENTIFIER, black);
1355 // This light blue is found in the windows system palette so is safe to use even in 256 colour modes.
1356 // Show the whole section of VBScript with light blue background
1357 for (int bstyle = SCE_HB_DEFAULT; bstyle <= SCE_HB_STRINGEOL; ++bstyle) {
1358 SendEditor(SCI_STYLESETFONT, bstyle,
1359 reinterpret_cast<LPARAM>(m_TextView.StringForControl(L"Lucida Console").GetBuffer()));
1360 SendEditor(SCI_STYLESETBACK, bstyle, lightBlue);
1361 // This call extends the backround colour of the last style on the line to the edge of the window
1362 SendEditor(SCI_STYLESETEOLFILLED, bstyle, 1);
1364 SendEditor(SCI_STYLESETBACK, SCE_HB_STRINGEOL, RGB(0x7F,0x7F,0xFF));
1365 SendEditor(SCI_STYLESETFONT, SCE_HB_COMMENTLINE,
1366 reinterpret_cast<LPARAM>(m_TextView.StringForControl(L"Lucida Console").GetBuffer()));
1368 SetAStyle(SCE_HBA_DEFAULT, black);
1369 SetAStyle(SCE_HBA_COMMENTLINE, darkGreen);
1370 SetAStyle(SCE_HBA_NUMBER, RGB(0,0x80,0x80));
1371 SetAStyle(SCE_HBA_WORD, darkBlue);
1372 SendEditor(SCI_STYLESETBOLD, SCE_HBA_WORD, 1);
1373 SetAStyle(SCE_HBA_STRING, RGB(0x80,0,0x80));
1374 SetAStyle(SCE_HBA_IDENTIFIER, black);
1376 // Show the whole section of ASP VBScript with bright yellow background
1377 for (int bastyle = SCE_HBA_DEFAULT; bastyle <= SCE_HBA_STRINGEOL; ++bastyle) {
1378 SendEditor(SCI_STYLESETFONT, bastyle,
1379 reinterpret_cast<LPARAM>(m_TextView.StringForControl(L"Lucida Console").GetBuffer()));
1380 SendEditor(SCI_STYLESETBACK, bastyle, RGB(0xFF, 0xFF, 0));
1381 // This call extends the backround colour of the last style on the line to the edge of the window
1382 SendEditor(SCI_STYLESETEOLFILLED, bastyle, 1);
1384 SendEditor(SCI_STYLESETBACK, SCE_HBA_STRINGEOL, RGB(0xCF,0xCF,0x7F));
1385 SendEditor(SCI_STYLESETFONT, SCE_HBA_COMMENTLINE,
1386 reinterpret_cast<LPARAM>(m_TextView.StringForControl(L"Lucida Console").GetBuffer()));
1388 // If there is no need to support embedded Javascript, the following code can be dropped.
1389 // Javascript will still be correctly processed but will be displayed in just the default style.
1391 SetAStyle(SCE_HJ_START, RGB(0x80,0x80,0));
1392 SetAStyle(SCE_HJ_DEFAULT, black);
1393 SetAStyle(SCE_HJ_COMMENT, darkGreen);
1394 SetAStyle(SCE_HJ_COMMENTLINE, darkGreen);
1395 SetAStyle(SCE_HJ_COMMENTDOC, darkGreen);
1396 SetAStyle(SCE_HJ_NUMBER, RGB(0,0x80,0x80));
1397 SetAStyle(SCE_HJ_WORD, black);
1398 SetAStyle(SCE_HJ_KEYWORD, darkBlue);
1399 SetAStyle(SCE_HJ_DOUBLESTRING, RGB(0x80,0,0x80));
1400 SetAStyle(SCE_HJ_SINGLESTRING, RGB(0x80,0,0x80));
1401 SetAStyle(SCE_HJ_SYMBOLS, black);
1403 SetAStyle(SCE_HJA_START, RGB(0x80,0x80,0));
1404 SetAStyle(SCE_HJA_DEFAULT, black);
1405 SetAStyle(SCE_HJA_COMMENT, darkGreen);
1406 SetAStyle(SCE_HJA_COMMENTLINE, darkGreen);
1407 SetAStyle(SCE_HJA_COMMENTDOC, darkGreen);
1408 SetAStyle(SCE_HJA_NUMBER, RGB(0,0x80,0x80));
1409 SetAStyle(SCE_HJA_WORD, black);
1410 SetAStyle(SCE_HJA_KEYWORD, darkBlue);
1411 SetAStyle(SCE_HJA_DOUBLESTRING, RGB(0x80,0,0x80));
1412 SetAStyle(SCE_HJA_SINGLESTRING, RGB(0x80,0,0x80));
1413 SetAStyle(SCE_HJA_SYMBOLS, black);
1415 SetAStyle(SCE_HPHP_DEFAULT, black);
1416 SetAStyle(SCE_HPHP_HSTRING, RGB(0x80,0,0x80));
1417 SetAStyle(SCE_HPHP_SIMPLESTRING, RGB(0x80,0,0x80));
1418 SetAStyle(SCE_HPHP_WORD, darkBlue);
1419 SetAStyle(SCE_HPHP_NUMBER, RGB(0,0x80,0x80));
1420 SetAStyle(SCE_HPHP_VARIABLE, red);
1421 SetAStyle(SCE_HPHP_HSTRING_VARIABLE, red);
1422 SetAStyle(SCE_HPHP_COMPLEX_VARIABLE, red);
1423 SetAStyle(SCE_HPHP_COMMENT, darkGreen);
1424 SetAStyle(SCE_HPHP_COMMENTLINE, darkGreen);
1425 SetAStyle(SCE_HPHP_OPERATOR, darkBlue);
1427 // Show the whole section of Javascript with off white background
1428 for (int jstyle = SCE_HJ_DEFAULT; jstyle <= SCE_HJ_SYMBOLS; ++jstyle) {
1429 SendEditor(SCI_STYLESETFONT, jstyle,
1430 reinterpret_cast<LPARAM>(m_TextView.StringForControl(L"Lucida Console").GetBuffer()));
1431 SendEditor(SCI_STYLESETBACK, jstyle, offWhite);
1432 SendEditor(SCI_STYLESETEOLFILLED, jstyle, 1);
1434 SendEditor(SCI_STYLESETBACK, SCE_HJ_STRINGEOL, RGB(0xDF, 0xDF, 0x7F));
1435 SendEditor(SCI_STYLESETEOLFILLED, SCE_HJ_STRINGEOL, 1);
1437 // Show the whole section of Javascript with brown background
1438 for (int jastyle = SCE_HJA_DEFAULT; jastyle <= SCE_HJA_SYMBOLS; ++jastyle) {
1439 SendEditor(SCI_STYLESETFONT, jastyle,
1440 reinterpret_cast<LPARAM>(m_TextView.StringForControl(L"Lucida Console").GetBuffer()));
1441 SendEditor(SCI_STYLESETBACK, jastyle, RGB(0xDF, 0xDF, 0x7F));
1442 SendEditor(SCI_STYLESETEOLFILLED, jastyle, 1);
1444 SendEditor(SCI_STYLESETBACK, SCE_HJA_STRINGEOL, RGB(0x0,0xAF,0x5F));
1445 SendEditor(SCI_STYLESETEOLFILLED, SCE_HJA_STRINGEOL, 1);
1448 else
1450 SendEditor(SCI_SETILEXER, 0, reinterpret_cast<sptr_t>(CreateLexer("cpp")));
1451 SetupCppLexer();
1453 SendEditor(SCI_COLOURISE, 0, -1);
1456 void CTortoiseGitBlameView::SetupCppLexer()
1458 SetAStyle(SCE_C_DEFAULT, RGB(0, 0, 0));
1459 SetAStyle(SCE_C_COMMENT, RGB(0, 0x80, 0));
1460 SetAStyle(SCE_C_COMMENTLINE, RGB(0, 0x80, 0));
1461 SetAStyle(SCE_C_COMMENTDOC, RGB(0, 0x80, 0));
1462 SetAStyle(SCE_C_COMMENTLINEDOC, RGB(0, 0x80, 0));
1463 SetAStyle(SCE_C_COMMENTDOCKEYWORD, RGB(0, 0x80, 0));
1464 SetAStyle(SCE_C_COMMENTDOCKEYWORDERROR, RGB(0, 0x80, 0));
1465 SetAStyle(SCE_C_NUMBER, RGB(0, 0x80, 0x80));
1466 SetAStyle(SCE_C_WORD, RGB(0, 0, 0x80));
1467 SendEditor(SCE_C_WORD, 1);
1468 SetAStyle(SCE_C_STRING, RGB(0x80, 0, 0x80));
1469 SetAStyle(SCE_C_IDENTIFIER, RGB(0, 0, 0));
1470 SetAStyle(SCE_C_PREPROCESSOR, RGB(0x80, 0, 0));
1471 SetAStyle(SCE_C_OPERATOR, RGB(0x80, 0x80, 0));
1472 SendEditor(SCI_SETPROPERTY, reinterpret_cast<WPARAM>("lexer.cpp.track.preprocessor"), reinterpret_cast<LPARAM>("0"));
1475 int CTortoiseGitBlameView::GetEncode(unsigned char *buff, int size, int *bomoffset)
1477 CFileTextLines textlines;
1478 CFileTextLines::UnicodeType type = textlines.CheckUnicodeType(buff, size);
1480 if (type == CFileTextLines::UnicodeType::UTF8BOM)
1482 *bomoffset = 3;
1483 return CP_UTF8;
1485 if (type == CFileTextLines::UnicodeType::UTF8)
1486 return CP_UTF8;
1488 if (type == CFileTextLines::UnicodeType::UTF16_LE)
1489 return 1200;
1490 if (type == CFileTextLines::UnicodeType::UTF16_LEBOM)
1492 *bomoffset = 2;
1493 return 1200;
1496 if (type == CFileTextLines::UnicodeType::UTF16_BE)
1497 return 1201;
1498 if (type == CFileTextLines::UnicodeType::UTF16_BEBOM)
1500 *bomoffset = 2;
1501 return 1201;
1504 return GetACP();
1507 void CTortoiseGitBlameView::ParseBlame()
1509 m_data.ParseBlameOutput(GetDocument()->m_BlameData, GetLogData()->m_pLogCache->m_HashMap, m_DateFormat, m_bRelativeTimes);
1510 CString filename = GetDocument()->m_GitPath.GetGitPathString();
1511 m_bBlameOutputContainsOtherFilenames = m_data.ContainsOnlyFilename(filename) ? FALSE : TRUE;
1514 void CTortoiseGitBlameView::MapLineToLogIndex()
1516 std::vector<int> lineToLogIndex;
1519 const size_t numberOfLines = m_data.GetNumberOfLines();
1520 lineToLogIndex.reserve(numberOfLines);
1521 const size_t logSize = this->GetLogData()->size();
1522 for (size_t j = 0; j < numberOfLines; ++j)
1524 CGitHash& hash = m_data.GetHash(j);
1526 int index = -2;
1527 for (size_t i = 0; i < logSize; ++i)
1529 if (hash == (*GetLogData())[i])
1531 index = static_cast<int>(i);
1532 break;
1535 lineToLogIndex.push_back(index);
1537 this->m_lineToLogIndex.swap(lineToLogIndex);
1540 void CTortoiseGitBlameView::UpdateInfo(int Encode)
1542 CreateFont();
1544 // Set up the global default style. These attributes are used wherever no explicit choices are made.
1545 std::string fontName = CUnicodeUtils::StdGetUTF8(CRegStdString(L"Software\\TortoiseGit\\BlameFontName", L"Consolas"));
1546 SendEditor(SCI_STYLESETSIZE, STYLE_DEFAULT, (DWORD)CRegStdDWORD(L"Software\\TortoiseGit\\BlameFontSize", 10));
1547 SendEditor(SCI_STYLESETFONT, STYLE_DEFAULT, reinterpret_cast<LPARAM>(fontName.c_str()));
1548 SendEditor(SCI_STYLECLEARALL);
1550 InitialiseEditor();
1551 m_TextView.SetReadOnly(false);
1552 SendEditor(SCI_CLEARALL);
1553 SendEditor(SCI_EMPTYUNDOBUFFER);
1554 SendEditor(SCI_SETSAVEPOINT);
1555 SendEditor(SCI_CANCEL);
1556 SendEditor(SCI_SETUNDOCOLLECTION, 0);
1558 SendEditor(SCI_SETCODEPAGE, SC_CP_UTF8);
1560 int encoding = m_data.UpdateEncoding(Encode);
1562 const auto numberOfLines = static_cast<int>(m_data.GetNumberOfLines());
1563 int longestLine = 0;
1564 int longestLineLen = 0;
1565 if (numberOfLines > 0)
1567 CStringA text;
1568 for (int i = 0; i < numberOfLines; ++i)
1570 const auto lineLen = m_data.GetUtf8Line(i).GetLength();
1571 if (longestLineLen < lineLen)
1573 longestLineLen = lineLen;
1574 longestLine = i;
1576 text += m_data.GetUtf8Line(i);
1577 text += '\n';
1579 text.TrimRight("\r\n");
1580 SendEditor(SCI_REPLACESEL, 0, reinterpret_cast<LPARAM>(static_cast<LPCSTR>(text)));
1584 UINT nID;
1585 UINT nStyle;
1586 int cxWidth;
1587 int nIndex = static_cast<CMainFrame*>(::AfxGetApp()->GetMainWnd())->m_wndStatusBar.CommandToIndex(ID_INDICATOR_ENCODING);
1588 static_cast<CMainFrame*>(::AfxGetApp()->GetMainWnd())->m_wndStatusBar.GetPaneInfo(nIndex, nID, nStyle, cxWidth);
1589 CString sBarText;
1590 for (int i = 0; i < _countof(encodings); ++i)
1592 if (encodings[i].id == encoding)
1594 sBarText = CString(encodings[i].name);
1595 break;
1598 //calculate the width of the text
1599 auto pDC = static_cast<CMainFrame*>(::AfxGetApp()->GetMainWnd())->m_wndStatusBar.GetDC();
1600 if (pDC)
1602 CSize size = pDC->GetTextExtent(sBarText);
1603 static_cast<CMainFrame*>(::AfxGetApp()->GetMainWnd())->m_wndStatusBar.SetPaneInfo(nIndex, nID, nStyle, size.cx + 2);
1604 ReleaseDC(pDC);
1606 static_cast<CMainFrame*>(::AfxGetApp()->GetMainWnd())->m_wndStatusBar.SetPaneText(nIndex, sBarText);
1609 #ifdef USE_TEMPFILENAME
1610 delete m_Buffer;
1611 m_Buffer = nullptr;
1613 CFile file;
1614 file.Open(this->GetDocument()->m_TempFileName,CFile::modeRead);
1616 m_Buffer = new char[file.GetLength()+4];
1617 m_Buffer[file.GetLength()] =0;
1618 m_Buffer[file.GetLength()+1] =0;
1619 m_Buffer[file.GetLength()+2] =0;
1620 m_Buffer[file.GetLength()+3] =0;
1622 file.Read(m_Buffer, file.GetLength());
1624 int bomoffset =0;
1625 int encoding = GetEncode( (unsigned char *)m_Buffer, file.GetLength(), &bomoffset);
1627 file.Close();
1628 //SendEditor(SCI_SETCODEPAGE, encoding);
1630 //SendEditor(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)(m_Buffer + bomoffset));
1631 #endif
1632 m_sLastFilename = GetDocument()->m_CurrentFileName;
1633 SetupLexer(m_sLastFilename);
1635 SendEditor(SCI_GOTOPOS, 0);
1636 // set max scroll width, based on textwidth of longest line (heuristic, only works for monospace font)
1637 if (longestLine > 0)
1638 SendEditor(SCI_SETSCROLLWIDTH, static_cast<int>(SendEditor(SCI_TEXTWIDTH, STYLE_DEFAULT, reinterpret_cast<LPARAM>(static_cast<const char*>(m_data.GetUtf8Line(longestLine))))));
1639 else
1640 SendEditor(SCI_SETSCROLLWIDTH, 1);
1641 SendEditor(SCI_SETSCROLLWIDTHTRACKING, TRUE);
1642 m_TextView.SetReadOnly(true);
1644 GetBlameWidth();
1645 CRect rect;
1646 this->GetClientRect(rect);
1647 //this->m_TextView.GetWindowRect(rect);
1648 //this->m_TextView.ScreenToClient(rect);
1649 rect.left=this->m_blamewidth;
1650 this->m_TextView.MoveWindow(rect);
1652 this->Invalidate();
1655 CString CTortoiseGitBlameView::ResolveCommitFile(int line)
1657 return ResolveCommitFile(m_data.GetFilename(line));
1660 CString CTortoiseGitBlameView::ResolveCommitFile(const CString& path)
1662 if (path.IsEmpty())
1664 return static_cast<CMainFrame*>(::AfxGetApp()->GetMainWnd())->GetActiveView()->GetDocument()->GetPathName();
1666 else
1668 return g_Git.CombinePath(path);
1672 COLORREF CTortoiseGitBlameView::GetLineColor(size_t line)
1674 if (m_colorage && line < m_lineToLogIndex.size())
1676 int logIndex = m_lineToLogIndex[line];
1677 if (logIndex >= 0)
1679 int slider = static_cast<int>((GetLogData()->size() - logIndex) * 100 / (GetLogData()->size() + 1));
1680 COLORREF newCol = (CTheme::Instance().IsDarkTheme() || CTheme::Instance().IsHighContrastModeDark()) ? DWORD(m_regDarkNewLinesColor) : DWORD(m_regNewLinesColor);
1681 COLORREF oldCol = (CTheme::Instance().IsDarkTheme() || CTheme::Instance().IsHighContrastModeDark()) ? DWORD(m_regDarkOldLinesColor) : DWORD(m_regOldLinesColor);
1682 return InterColor(oldCol, newCol, slider);
1685 return m_windowcolor;
1688 void CTortoiseGitBlameView::SetupColoring()
1690 if (CTheme::Instance().IsDarkTheme())
1692 m_windowcolor = CTheme::darkBkColor;
1693 m_textcolor = CTheme::darkTextColor;
1694 m_texthighlightcolor = m_textcolor;
1695 m_selectedrevcolor = RGB(0, 30, 80);
1696 m_selectedauthorcolor = InterColor(m_selectedrevcolor, m_texthighlightcolor, 15);
1698 else
1700 m_windowcolor = GetSysColor(COLOR_WINDOW);
1701 m_textcolor = GetSysColor(COLOR_WINDOWTEXT);
1702 m_texthighlightcolor = GetSysColor(COLOR_HIGHLIGHTTEXT);
1703 m_selectedrevcolor = GetSysColor(COLOR_HIGHLIGHT);
1704 m_selectedauthorcolor = InterColor(m_selectedrevcolor, m_texthighlightcolor, 35);
1707 m_mouserevcolor = InterColor(m_windowcolor, m_textcolor, 20);
1708 m_mouseauthorcolor = InterColor(m_windowcolor, m_textcolor, 10);
1711 CGitBlameLogList *CTortoiseGitBlameView::GetLogList()
1713 return &(GetDocument()->GetMainFrame()->m_wndOutput.m_LogList);
1717 CLogDataVector * CTortoiseGitBlameView::GetLogData()
1719 return &(GetDocument()->GetMainFrame()->m_wndOutput.m_LogList.m_logEntries);
1722 void CTortoiseGitBlameView::OnSciPainted(NMHDR *,LRESULT *)
1724 this->Invalidate();
1727 void CTortoiseGitBlameView::OnLButtonDown(UINT nFlags,CPoint point)
1729 const int line = GetLineUnderCursor(point);
1730 if (static_cast<size_t>(line) < m_data.GetNumberOfLines())
1732 SetSelectedLine(line);
1733 bool found = m_selectedHashes.contains(m_data.GetHash(line));
1734 if (nFlags == 9)
1736 if (!found)
1737 m_selectedHashes.insert(m_data.GetHash(line));
1738 else
1739 m_selectedHashes.erase(m_data.GetHash(line));
1741 else if (!found || m_selectedHashes.size() > 1)
1743 m_selectedHashes.clear();
1744 m_selectedHashes.insert(m_data.GetHash(line));
1746 else
1747 m_selectedHashes.clear();
1749 if (m_selectedHashes.size() != 1)
1750 GetDocument()->GetMainFrame()->m_wndProperties.UpdateProperties(nullptr);
1751 else if (!m_selectedHashes.empty())
1753 auto pRev = m_data.GetRev(line, GetLogData()->m_pLogCache->m_HashMap);
1754 GetDocument()->GetMainFrame()->m_wndProperties.UpdateProperties(pRev);
1756 m_bBlockUpdates = true;
1758 const int logSize = static_cast<int>(GetLogData()->size());
1759 for (int i = 0; i < logSize; ++i)
1761 if (!m_selectedHashes.contains((*GetLogData())[i]))
1762 GetLogList()->SetItemState(i, 0, LVIS_SELECTED);
1763 else
1764 GetLogList()->SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
1766 if (int logIndex = m_lineToLogIndex[line]; logIndex >= 0)
1767 GetLogList()->EnsureVisible(logIndex, FALSE);
1769 m_bBlockUpdates = false;
1771 this->Invalidate();
1772 this->m_TextView.Invalidate();
1774 else
1776 SetSelectedLine(-1);
1779 CView::OnLButtonDown(nFlags,point);
1782 void CTortoiseGitBlameView::OnSciZoom(NMHDR* /*hdr*/, LRESULT* /*result*/)
1784 auto numberOfLines = m_data.GetNumberOfLines();
1785 int numDigits = 2;
1786 while (numberOfLines)
1788 numberOfLines /= 10;
1789 ++numDigits;
1791 if (m_bShowLine)
1792 SendEditor(SCI_SETMARGINWIDTHN, 0, numDigits * static_cast<int>(SendEditor(SCI_TEXTWIDTH, STYLE_LINENUMBER, reinterpret_cast<LPARAM>("8"))));
1793 else
1794 SendEditor(SCI_SETMARGINWIDTHN, 0);
1795 SendEditor(SCI_SETMARGINWIDTHN, 1);
1796 SendEditor(SCI_SETMARGINWIDTHN, 2);
1798 CreateNewFont(true);
1800 Invalidate();
1803 void CTortoiseGitBlameView::OnSciGetBkColor(NMHDR* hdr, LRESULT* /*result*/)
1805 auto notification = reinterpret_cast<SCNotification*>(hdr);
1807 if (notification->line < static_cast<Sci_Position>(m_data.GetNumberOfLines()))
1809 if (m_selectedHashes.contains(m_data.GetHash(notification->line)))
1810 notification->lParam = m_selectedauthorcolor;
1811 else
1812 notification->lParam = GetLineColor(notification->line);
1816 void CTortoiseGitBlameView::FocusOn(std::unordered_set<CGitHash>&& pRevs, GitRevLoglist* selected)
1818 if (m_bBlockUpdates)
1819 return;
1821 SendEditor(SCI_SETEMPTYSELECTION, SendEditor(SCI_GETCURRENTPOS));
1822 if (selected && !m_selectedHashes.contains(selected->m_CommitHash))
1824 if (int line = m_data.FindFirstLine(selected->m_CommitHash, 0); line >= 0)
1825 GotoLine(line + 1);
1828 m_selectedHashes.swap(pRevs);
1830 if (m_selectedHashes.size() != 1)
1831 GetDocument()->GetMainFrame()->m_wndProperties.UpdateProperties(nullptr);
1832 else if (selected && !m_selectedHashes.empty())
1833 GetDocument()->GetMainFrame()->m_wndProperties.UpdateProperties(selected);
1835 m_TextView.Invalidate();
1836 this->Invalidate();
1839 void CTortoiseGitBlameView::OnMouseHover(UINT /*nFlags*/, CPoint point)
1841 int line = GetLineUnderCursor(point);
1842 if (m_data.IsValidLine(line))
1844 if (line != m_MouseLine)
1846 m_MouseLine = line;
1847 GitRev *pRev = nullptr;
1848 int logIndex = m_lineToLogIndex[line];
1849 if (logIndex >= 0)
1850 pRev = &GetLogData()->GetGitRevAt(logIndex);
1851 else
1852 pRev = m_data.GetRev(line, GetLogData()->m_pLogCache->m_HashMap);
1854 if (!pRev)
1855 return;
1857 CString body = pRev->GetBody();
1858 int maxLine = 15;
1859 int iline = 0;
1860 int pos = 0;
1861 while (iline++ < maxLine)
1863 int pos2 = body.Find(L'\n', pos);
1864 if (pos2 < 0)
1865 break;
1866 int lineLength = pos2 - pos - 1;
1867 pos = pos2 + 1;
1868 iline += lineLength / 70;
1871 CString filename;
1872 if ((m_bShowCompleteLog && m_bFollowRenames && !m_bOnlyFirstParent) || !BlameIsLimitedToOneFilename(m_dwDetectMovedOrCopiedLines) || m_bBlameOutputContainsOtherFilenames)
1873 filename.Format(L"%s: %s\n", static_cast<LPCWSTR>(m_sFileName), static_cast<LPCWSTR>(m_data.GetFilename(line)));
1875 CString str;
1876 str.Format(L"%s: %s\n%s%s: %s <%s>\n%s: %s\n%s:\n%s\n%s", static_cast<LPCWSTR>(m_sRev), static_cast<LPCWSTR>(pRev->m_CommitHash.ToString()), static_cast<LPCWSTR>(filename),
1877 static_cast<LPCWSTR>(m_sAuthor), static_cast<LPCWSTR>(pRev->GetAuthorName()), static_cast<LPCWSTR>(pRev->GetAuthorEmail()),
1878 static_cast<LPCWSTR>(m_sDate), static_cast<LPCWSTR>(CLoglistUtils::FormatDateAndTime(pRev->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes)),
1879 static_cast<LPCWSTR>(m_sMessage), static_cast<LPCWSTR>(pRev->GetSubject()),
1880 iline <= maxLine ? static_cast<LPCWSTR>(body) : static_cast<LPCWSTR>((body.Left(pos) + L"\n...")));
1882 if (str.GetLength() > 8000)
1884 str.Truncate(8000);
1885 str += L"...";
1888 m_ToolTip.Pop();
1889 m_ToolTip.AddTool(this, str);
1891 Invalidate();
1896 void CTortoiseGitBlameView::OnMouseMove(UINT /*nFlags*/, CPoint /*point*/)
1898 TRACKMOUSEEVENT tme;
1899 tme.cbSize=sizeof(TRACKMOUSEEVENT);
1900 tme.dwFlags=TME_HOVER|TME_LEAVE;
1901 tme.hwndTrack=this->m_hWnd;
1902 tme.dwHoverTime=1;
1903 TrackMouseEvent(&tme);
1904 Invalidate();
1907 void CTortoiseGitBlameView::OnMouseLeave()
1909 if (m_MouseLine == -1)
1910 return;
1912 m_MouseLine = -1;
1913 Invalidate();
1916 BOOL CTortoiseGitBlameView::PreTranslateMessage(MSG* pMsg)
1918 if (m_ToolTip.GetSafeHwnd())
1919 m_ToolTip.RelayEvent(pMsg);
1920 if (pMsg->message == WM_MOUSEWHEEL)
1921 pMsg->hwnd = m_TextView.GetSafeHwnd();
1922 return CView::PreTranslateMessage(pMsg);
1925 void CTortoiseGitBlameView::OnEditFind()
1927 if (m_pFindDialog)
1929 m_pFindDialog->SetFocus();
1930 return;
1933 m_pFindDialog=new CFindReplaceDialog();
1935 CString oneline = m_sFindText;
1936 if (auto selstart = static_cast<Sci_Position>(m_TextView.Call(SCI_GETSELECTIONSTART)), selend = static_cast<Sci_Position>(m_TextView.Call(SCI_GETSELECTIONEND)); selstart != selend && selend - selstart < INT_MAX)
1938 CStringA selText;
1939 Sci_TextRangeFull range = { selstart, selend, selText.GetBuffer(SafeSizeToInt(selend - selstart)) };
1940 selText.ReleaseBufferSetLength(SafeSizeToInt(m_TextView.Call(SCI_GETTEXTRANGEFULL, 0, reinterpret_cast<LPARAM>(&range))));
1941 if (!selText.IsEmpty())
1942 oneline = m_TextView.StringFromControl(selText);
1945 DWORD flags = FR_DOWN | FR_HIDEWHOLEWORD;
1946 if (theApp.GetInt(L"FindMatchCase"))
1947 flags |= FR_MATCHCASE;
1949 m_pFindDialog->Create(TRUE, oneline, nullptr, flags, this);
1950 CAutoCloakWindow window_cloaker{ m_pFindDialog->GetSafeHwnd() };
1951 CTheme::Instance().SetThemeForDialog(m_pFindDialog->GetSafeHwnd(), CTheme::Instance().IsDarkTheme());
1954 void CTortoiseGitBlameView::OnEditGoto()
1956 CEditGotoDlg dlg;
1957 if(dlg.DoModal()==IDOK)
1959 this->GotoLine(dlg.m_LineNumber);
1963 LRESULT CTortoiseGitBlameView::OnFindDialogMessage(WPARAM /*wParam*/, LPARAM /*lParam*/)
1965 ASSERT(m_pFindDialog);
1967 // If the FR_DIALOGTERM flag is set,
1968 // invalidate the handle identifying the dialog box.
1969 if (m_pFindDialog->IsTerminating())
1971 m_pFindDialog = nullptr;
1972 return 0;
1975 // If the FR_FINDNEXT flag is set,
1976 // call the application-defined search routine
1977 // to search for the requested string.
1978 if(m_pFindDialog->FindNext())
1980 m_bMatchCase = !!(m_pFindDialog->MatchCase());
1981 m_sFindText = m_pFindDialog->GetFindString();
1983 theApp.WriteInt(L"FindMatchCase", m_bMatchCase ? 1 : 0);
1984 theApp.WriteString(L"FindString", m_sFindText);
1986 DoSearch(m_pFindDialog->SearchDown() ? CTortoiseGitBlameData::SearchNext : CTortoiseGitBlameData::SearchPrevious);
1989 return 0;
1992 void CTortoiseGitBlameView::OnViewNext()
1994 int startline = static_cast<int>(SendEditor(SCI_GETFIRSTVISIBLELINE));
1995 int line = m_data.FindNextLine(m_selectedHashes, startline, false);
1996 if(line >= 0)
1997 SendEditor(SCI_LINESCROLL, 0, line - startline);
1999 void CTortoiseGitBlameView::OnViewPrev()
2001 int startline = static_cast<int>(SendEditor(SCI_GETFIRSTVISIBLELINE));
2002 int line = m_data.FindNextLine(m_selectedHashes, startline, true);
2003 if(line >= 0)
2004 SendEditor(SCI_LINESCROLL, 0, line - startline + 1);
2007 void CTortoiseGitBlameView::OnViewToggleLogID()
2009 m_bShowLogID = !m_bShowLogID;
2011 theApp.WriteInt(L"ShowLogID", m_bShowLogID);
2013 CRect rect;
2014 this->GetClientRect(&rect);
2015 rect.left = GetBlameWidth();
2017 m_TextView.MoveWindow(&rect);
2020 void CTortoiseGitBlameView::OnUpdateViewToggleLogID(CCmdUI* pCmdUI)
2022 pCmdUI->SetCheck(m_bShowLogID);
2025 void CTortoiseGitBlameView::OnViewToggleAuthor()
2027 m_bShowAuthor = ! m_bShowAuthor;
2029 theApp.WriteInt(L"ShowAuthor", m_bShowAuthor);
2031 CRect rect;
2032 this->GetClientRect(&rect);
2033 rect.left=GetBlameWidth();
2035 m_TextView.MoveWindow(&rect);
2038 void CTortoiseGitBlameView::OnUpdateViewToggleAuthor(CCmdUI *pCmdUI)
2040 pCmdUI->SetCheck(m_bShowAuthor);
2043 void CTortoiseGitBlameView::OnViewToggleDate()
2045 m_bShowDate = ! m_bShowDate;
2047 theApp.WriteInt(L"ShowDate", m_bShowDate);
2049 CRect rect;
2050 this->GetClientRect(&rect);
2051 rect.left=GetBlameWidth();
2053 m_TextView.MoveWindow(&rect);
2056 void CTortoiseGitBlameView::OnUpdateViewToggleDate(CCmdUI *pCmdUI)
2058 pCmdUI->SetCheck(m_bShowDate);
2061 void CTortoiseGitBlameView::OnViewToggleShowFilename()
2063 m_bShowFilename = ! m_bShowFilename;
2065 theApp.WriteInt(L"ShowFilename", m_bShowFilename);
2067 CRect rect;
2068 this->GetClientRect(&rect);
2069 rect.left = GetBlameWidth();
2071 m_TextView.MoveWindow(&rect);
2074 void CTortoiseGitBlameView::OnUpdateViewToggleShowFilename(CCmdUI *pCmdUI)
2076 pCmdUI->SetCheck(m_bShowFilename);
2079 void CTortoiseGitBlameView::OnViewToggleShowOriginalLineNumber()
2081 m_bShowOriginalLineNumber = ! m_bShowOriginalLineNumber;
2083 theApp.WriteInt(L"ShowOriginalLineNumber", m_bShowOriginalLineNumber);
2085 CRect rect;
2086 this->GetClientRect(&rect);
2087 rect.left = GetBlameWidth();
2089 m_TextView.MoveWindow(&rect);
2092 void CTortoiseGitBlameView::OnUpdateViewToggleShowOriginalLineNumber(CCmdUI *pCmdUI)
2094 pCmdUI->SetCheck(m_bShowOriginalLineNumber);
2097 void CTortoiseGitBlameView::OnViewDetectMovedOrCopiedLines(DWORD dwDetectMovedOrCopiedLines)
2099 m_dwDetectMovedOrCopiedLines = dwDetectMovedOrCopiedLines;
2101 theApp.DoWaitCursor(1);
2103 theApp.WriteInt(L"DetectMovedOrCopiedLines", m_dwDetectMovedOrCopiedLines);
2105 auto document = static_cast<CTortoiseGitBlameDoc*>(m_pDocument);
2106 if (!document->m_CurrentFileName.IsEmpty())
2108 document->m_lLine = static_cast<int>(SendEditor(SCI_GETFIRSTVISIBLELINE)) + 1;
2109 theApp.m_pDocManager->OnFileNew();
2110 document->OnOpenDocument(document->m_CurrentFileName, document->m_Rev);
2112 theApp.DoWaitCursor(-1);
2115 void CTortoiseGitBlameView::OnViewDetectMovedOrCopiedLinesToggleDisabled()
2117 OnViewDetectMovedOrCopiedLines(BLAME_DETECT_MOVED_OR_COPIED_LINES_DISABLED);
2120 void CTortoiseGitBlameView::OnUpdateViewDetectMovedOrCopiedLinesToggleDisabled(CCmdUI *pCmdUI)
2122 pCmdUI->SetRadio(m_dwDetectMovedOrCopiedLines == BLAME_DETECT_MOVED_OR_COPIED_LINES_DISABLED);
2125 void CTortoiseGitBlameView::OnViewDetectMovedOrCopiedLinesToggleWithinFile()
2127 OnViewDetectMovedOrCopiedLines(BLAME_DETECT_MOVED_OR_COPIED_LINES_WITHIN_FILE);
2130 void CTortoiseGitBlameView::OnUpdateViewDetectMovedOrCopiedLinesToggleWithinFile(CCmdUI *pCmdUI)
2132 pCmdUI->SetRadio(m_dwDetectMovedOrCopiedLines == BLAME_DETECT_MOVED_OR_COPIED_LINES_WITHIN_FILE);
2135 void CTortoiseGitBlameView::OnViewDetectMovedOrCopiedLinesToggleFromModifiedFiles()
2137 OnViewDetectMovedOrCopiedLines(BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_MODIFIED_FILES);
2140 void CTortoiseGitBlameView::OnUpdateViewDetectMovedOrCopiedLinesToggleFromModifiedFiles(CCmdUI *pCmdUI)
2142 pCmdUI->SetRadio(m_dwDetectMovedOrCopiedLines == BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_MODIFIED_FILES);
2145 void CTortoiseGitBlameView::OnViewDetectMovedOrCopiedLinesToggleFromExistingFilesAtFileCreation()
2147 OnViewDetectMovedOrCopiedLines(BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES_AT_FILE_CREATION);
2150 void CTortoiseGitBlameView::OnUpdateViewDetectMovedOrCopiedLinesToggleFromExistingFilesAtFileCreation(CCmdUI *pCmdUI)
2152 pCmdUI->SetRadio(m_dwDetectMovedOrCopiedLines == BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES_AT_FILE_CREATION);
2155 void CTortoiseGitBlameView::OnViewDetectMovedOrCopiedLinesToggleFromExistingFiles()
2157 OnViewDetectMovedOrCopiedLines(BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES);
2160 void CTortoiseGitBlameView::OnUpdateViewDetectMovedOrCopiedLinesToggleFromExistingFiles(CCmdUI *pCmdUI)
2162 pCmdUI->SetRadio(m_dwDetectMovedOrCopiedLines == BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES);
2165 void CTortoiseGitBlameView::ReloadDocument()
2167 theApp.DoWaitCursor(1);
2168 auto document = static_cast<CTortoiseGitBlameDoc*>(m_pDocument);
2169 if (!document->m_CurrentFileName.IsEmpty())
2171 document->m_lLine = static_cast<int>(SendEditor(SCI_GETFIRSTVISIBLELINE)) + 1;
2172 theApp.m_pDocManager->OnFileNew();
2173 document->OnOpenDocument(document->m_CurrentFileName, document->m_Rev);
2175 theApp.DoWaitCursor(-1);
2178 void CTortoiseGitBlameView::OnViewToggleIgnoreWhitespace()
2180 m_bIgnoreWhitespace = ! m_bIgnoreWhitespace;
2182 theApp.WriteInt(L"IgnoreWhitespace", m_bIgnoreWhitespace ? 1 : 0);
2184 ReloadDocument();
2187 void CTortoiseGitBlameView::OnUpdateViewToggleIgnoreWhitespace(CCmdUI *pCmdUI)
2189 pCmdUI->SetCheck(m_bIgnoreWhitespace);
2192 void CTortoiseGitBlameView::OnViewToggleShowCompleteLog()
2194 m_bShowCompleteLog = ! m_bShowCompleteLog;
2196 theApp.WriteInt(L"ShowCompleteLog", m_bShowCompleteLog ? 1 : 0);
2198 ReloadDocument();
2201 void CTortoiseGitBlameView::OnUpdateViewToggleOnlyFirstParent(CCmdUI* pCmdUI)
2203 pCmdUI->SetCheck(m_bOnlyFirstParent);
2206 void CTortoiseGitBlameView::OnViewToggleOnlyFirstParent()
2208 m_bOnlyFirstParent = !m_bOnlyFirstParent;
2210 theApp.WriteInt(L"OnlyFirstParent", m_bOnlyFirstParent ? 1 : 0);
2212 ReloadDocument();
2215 void CTortoiseGitBlameView::OnUpdateViewToggleShowCompleteLog(CCmdUI *pCmdUI)
2217 pCmdUI->Enable(BlameIsLimitedToOneFilename(m_dwDetectMovedOrCopiedLines) && !m_bOnlyFirstParent);
2218 pCmdUI->SetCheck(m_bShowCompleteLog && BlameIsLimitedToOneFilename(m_dwDetectMovedOrCopiedLines) && !m_bOnlyFirstParent);
2221 void CTortoiseGitBlameView::OnViewToggleFollowRenames()
2223 m_bFollowRenames = ! m_bFollowRenames;
2225 theApp.WriteInt(L"FollowRenames", m_bFollowRenames ? 1 : 0);
2227 ReloadDocument();
2230 void CTortoiseGitBlameView::OnUpdateViewToggleFollowRenames(CCmdUI *pCmdUI)
2232 pCmdUI->Enable(m_bShowCompleteLog && BlameIsLimitedToOneFilename(m_dwDetectMovedOrCopiedLines) && !m_bOnlyFirstParent);
2233 pCmdUI->SetCheck(m_bFollowRenames && m_bShowCompleteLog && BlameIsLimitedToOneFilename(m_dwDetectMovedOrCopiedLines) && !m_bOnlyFirstParent);
2236 void CTortoiseGitBlameView::OnViewToggleColorByAge()
2238 m_colorage = ! m_colorage;
2240 theApp.WriteInt(L"ColorAge", m_colorage);
2242 m_TextView.Invalidate();
2245 void CTortoiseGitBlameView::OnUpdateViewToggleColorByAge(CCmdUI *pCmdUI)
2247 pCmdUI->SetCheck(m_colorage);
2250 void CTortoiseGitBlameView::OnViewToggleLexer()
2252 m_bLexer = !m_bLexer;
2254 theApp.WriteInt(L"EnableLexer", m_bLexer);
2256 SendEditor(SCI_CLEARDOCUMENTSTYLE, 0, 0);
2257 SetupLexer(GetDocument()->m_CurrentFileName);
2260 void CTortoiseGitBlameView::OnUpdateViewToggleLexer(CCmdUI *pCmdUI)
2262 pCmdUI->SetCheck(m_bLexer);
2265 void CTortoiseGitBlameView::OnViewToggleDarkMode()
2267 CTheme::Instance().SetDarkTheme(!CTheme::Instance().IsDarkTheme());
2268 theApp.WriteInt(L"DarkMode", CTheme::Instance().IsDarkTheme());
2271 void CTortoiseGitBlameView::OnUpdateViewToggleDarkMode(CCmdUI* pCmdUI)
2273 pCmdUI->Enable(CTheme::Instance().IsDarkModeAllowed());
2274 pCmdUI->SetCheck(CTheme::Instance().IsDarkTheme());
2277 void CTortoiseGitBlameView::OnViewWrapLongLines()
2279 m_bWrapLongLines = !m_bWrapLongLines;
2281 theApp.WriteInt(L"WrapLongLines", m_bWrapLongLines);
2283 if (m_bWrapLongLines)
2284 SendEditor(SCI_SETWRAPMODE, SC_WRAP_WORD);
2285 else
2286 SendEditor(SCI_SETWRAPMODE, SC_WRAP_NONE);
2289 void CTortoiseGitBlameView::OnUpdateViewWrapLongLines(CCmdUI* pCmdUI)
2291 pCmdUI->SetCheck(m_bWrapLongLines);
2294 void CTortoiseGitBlameView::OnUpdateViewCopyToClipboard(CCmdUI *pCmdUI)
2296 CWnd * wnd = GetFocus();
2297 if (wnd == GetLogList())
2298 pCmdUI->Enable(GetLogList()->GetSelectedCount() > 0);
2299 else if (wnd)
2301 if (CString(wnd->GetRuntimeClass()->m_lpszClassName) == L"CMFCPropertyGridCtrl")
2303 auto grid = static_cast<CMFCPropertyGridCtrl*>(wnd);
2304 pCmdUI->Enable(grid->GetCurSel() && !grid->GetCurSel()->IsGroup() && !CString(grid->GetCurSel()->GetValue()).IsEmpty());
2306 else
2307 pCmdUI->Enable(m_TextView.Call(SCI_GETSELECTIONSTART) != m_TextView.Call(SCI_GETSELECTIONEND));
2309 else
2310 pCmdUI->Enable(FALSE);
2313 void CTortoiseGitBlameView::OnDestroy()
2315 CTheme::Instance().SetThemeForDialog(GetSafeHwnd(), false);
2316 __super::OnDestroy();
2317 CTheme::Instance().RemoveRegisteredCallback(m_themeCallbackId);
2320 void CTortoiseGitBlameView::OnSysColorChange()
2322 __super::OnSysColorChange();
2323 CTheme::Instance().OnSysColorChanged();
2324 SetTheme(CTheme::Instance().IsDarkTheme());
2327 ULONG CTortoiseGitBlameView::GetGestureStatus(CPoint ptTouch)
2329 int line = GetLineUnderCursor(ptTouch);
2330 if (m_data.IsValidLine(line))
2331 return 0;
2332 return __super::GetGestureStatus(ptTouch);