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
26 #include "TortoiseGitBlame.h"
27 #include "CommonAppUtils.h"
28 #include "TortoiseGitBlameDoc.h"
29 #include "TortoiseGitBlameView.h"
31 #include "EditGotoDlg.h"
32 #include "LoglistUtils.h"
33 #include "FileTextLines.h"
34 #include "UnicodeUtils.h"
35 #include "MenuEncode.h"
37 #include "StringUtils.h"
38 #include "BlameIndexColors.h"
39 #include "BlameDetectMovedOrCopiedLines.h"
44 #include "DarkModeHelper.h"
46 #include "AutoCloakWindow.h"
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
)
114 ON_WM_SYSCOLORCHANGE()
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
)
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
;
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
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
)
242 this->GetWindowRect(&rect1
);
243 rect
.left
= m_blamewidth
+ CDPIAware::Instance().ScaleX(GetSafeHwnd(), LOCATOR_WIDTH
);
244 rect
.right
=rect
.Width();
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
253 m_TextView
.m_bNoAutomaticStyling
= true;
254 m_TextView
.ShowWindow( SW_SHOW
);
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
)
268 rect
.left
=m_blamewidth
;
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*/)
287 void CTortoiseGitBlameView::OnDraw(CDC
* pDC
)
289 CTortoiseGitBlameDoc
* pDoc
= GetDocument();
294 CMemDC
myDC(*pDC
, this);
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
));
310 for (i
= line
; y
<= point
.y
&& i
< (line
+ linesonscreen
); ++i
)
312 auto wrapcount
= static_cast<int>(SendEditor(SCI_WRAPCOUNT
, i
));
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
;
324 void CTortoiseGitBlameView::OnRButtonUp(UINT
/*nFlags*/, CPoint point
)
326 int line
= GetLineUnderCursor(point
);
327 if (m_data
.IsValidLine(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
];
338 pRev
= &GetLogData()->GetGitRevAt(logIndex
);
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
);
353 CIconMenu blamemenu
, diffmenu
;
355 if (!popup
.CreatePopupMenu())
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
);
396 if (!parentHashWithFile
.empty())
398 if (parentHashWithFile
.size() == 1)
400 popup
.AppendMenuIcon(ID_BLAMEPREVIOUS
, IDS_BLAME_POPUP_BLAME
, IDI_BLAME_POPUP_BLAME
);
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
)
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
);
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
)
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);
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;
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
);
479 case ID_COMPAREWITHPREVIOUS
:
481 int index
= (cmd
>> 16) & 0xFFFF;
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
);
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
);
514 case ID_COPYHASHTOCLIPBOARD
:
515 this->GetLogList()->CopySelectionToClipBoard(CGitLogListBase::ID_COPYCLIPBOARDHASH
);
518 case ID_COPYLOGTOCLIPBOARD
:
519 this->GetLogList()->CopySelectionToClipBoard(CGitLogListBase::ID_COPYCLIPBOARDFULL
);
524 // CTortoiseGitBlameView diagnostics
527 void CTortoiseGitBlameView::AssertValid() const
529 CView::AssertValid();
532 void CTortoiseGitBlameView::Dump(CDumpContext
& dc
) const
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
);
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
)
554 // Limit Slider to 0..100% range
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;
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
)
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
);
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));
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));
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
); });
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
);
659 ::MessageBox(m_pFindDialog
&& m_pFindDialog
->GetSafeHwnd() ? m_pFindDialog
->GetSafeHwnd() : GetSafeHwnd(), L
"\"" + m_sFindText
+ L
"\" " + CString(MAKEINTRESOURCE(IDS_NOTFOUND
)), L
"TortoiseGitBlame", MB_ICONINFORMATION
);
664 void CTortoiseGitBlameView::OnFindPrev()
666 if (m_sFindText
.IsEmpty())
668 DoSearch(CTortoiseGitBlameData::SearchPrevious
);
671 void CTortoiseGitBlameView::OnFindNext()
673 if (m_sFindText
.IsEmpty())
675 DoSearch(CTortoiseGitBlameData::SearchNext
);
678 bool CTortoiseGitBlameView::GotoLine(int line
)
681 const int numberOfLines
= static_cast<int>(m_data
.GetNumberOfLines());
682 if (line
< 0 || numberOfLines
== 0)
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
)
697 SendEditor(SCI_GOTOLINE
, line
);
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)));
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
);
720 bool CTortoiseGitBlameView::ScrollToLine(long line
)
725 int nCurrentLine
= static_cast<int>(SendEditor(SCI_GETFIRSTVISIBLELINE
));
727 int scrolldelta
= line
- nCurrentLine
;
728 SendEditor(SCI_LINESCROLL
, 0, scrolldelta
);
733 void CTortoiseGitBlameView::CopyToClipboard()
735 CWnd
* wnd
= GetFocus();
736 if (wnd
== this->GetLogList())
737 GetLogList()->CopySelectionToClipBoard();
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());
747 m_TextView
.Call(SCI_COPY
);
751 void CTortoiseGitBlameView::SetTheme(bool bDark
)
753 DarkModeHelper::Instance().AllowDarkModeForWindow(GetSafeHwnd(), bDark
);
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
);
768 HDC hDC
= this->GetDC()->m_hDC
;
769 HFONT oldfont
= static_cast<HFONT
>(::SelectObject(hDC
, m_font
.GetSafeHandle()));
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
;
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
;
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
)
797 m_datewidth
= maxwidth
.cx
+ CDPIAware::Instance().ScaleX(GetSafeHwnd(), BLAMESPACE
);
798 blamewidth
+= m_datewidth
;
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
)
811 m_authorwidth
= maxwidth
.cx
+ CDPIAware::Instance().ScaleX(GetSafeHwnd(), BLAMESPACE
);
812 blamewidth
+= m_authorwidth
;
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
)
825 m_filenameWidth
= maxwidth
.cx
+ CDPIAware::Instance().ScaleX(GetSafeHwnd(), BLAMESPACE
);
826 blamewidth
+= m_filenameWidth
;
828 if (m_bShowOriginalLineNumber
)
832 const size_t numberOfLines
= m_data
.GetNumberOfLines();
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
)
841 m_originalLineNumberWidth
= maxwidth
.cx
+ CDPIAware::Instance().ScaleX(GetSafeHwnd(), BLAMESPACE
);
842 blamewidth
+= m_originalLineNumberWidth
;
844 ::SelectObject(hDC
, oldfont
);
845 POINT pt
= {blamewidth
, 0};
848 //::ReleaseDC(wBlame, hDC);
852 void CTortoiseGitBlameView::CreateFont()
854 if (m_font
.GetSafeHandle())
857 CreateNewFont(false);
860 void CTortoiseGitBlameView::CreateNewFont(bool resize
)
862 m_font
.DeleteObject();
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
);
872 m_italicfont
.DeleteObject();
873 m_italicfont
.CreateFontIndirect(&lf
);
875 if (!resize
|| !m_pDocument
)
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)
888 if (!m_font
.GetSafeHandle())
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
));
897 wchar_t buf
[MAX_PATH
] = { 0 };
898 std::fill_n(buf
, _countof(buf
) - 1, L
' ');
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
));
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
);
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
)
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
;
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
;
958 str
.Format(m_sLogIDFormat
, GetLogList()->GetItemCount() - m_lineToLogIndex
[i
]);
959 if (m_lineToLogIndex
[i
] < 0)
961 ::ExtTextOut(hDC
, rc
.left
, rc
.top
, ETO_CLIPPED
, &rc
, str
, str
.GetLength(), 0);
963 rc
.left
+= m_logidwidth
;
968 ::DrawText(hDC
, m_data
.GetAuthor(i
), m_data
.GetAuthor(i
).GetLength(), &rc
, DT_HIDEPREFIX
| DT_NOPREFIX
| DT_SINGLELINE
);
969 rc
.left
+= m_authorwidth
;
974 ::DrawText(hDC
, m_data
.GetDate(i
), m_data
.GetDate(i
).GetLength(), &rc
, DT_HIDEPREFIX
| DT_NOPREFIX
| DT_SINGLELINE
);
975 rc
.left
+= m_datewidth
;
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
)
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
;
993 if (i
== m_SelectedLine
&& m_pFindDialog
)
996 brush
.lbColor
= m_textcolor
;
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
);
1010 Y
+= wrapcount
* height
;
1011 ::SelectObject(hDC
, oldfont
);
1015 void CTortoiseGitBlameView::DrawLocatorBar(HDC hDC
)
1020 int line
= static_cast<int>(SendEditor(SCI_GETFIRSTVISIBLELINE
));
1021 int linesonscreen
= static_cast<int>(SendEditor(SCI_LINESONSCREEN
));
1023 COLORREF blackColor
= CTheme::Instance().GetThemeColor(GetSysColor(COLOR_WINDOWTEXT
));
1026 this->GetClientRect(&rc
);
1028 rc
.right
= CDPIAware::Instance().ScaleX(GetSafeHwnd(), LOCATOR_WIDTH
);
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));
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()));
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()));
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()));
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 \
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 \
1169 enable_allocate encode endpoint entry enum error_status_t \
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 \
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()));
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()));
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()));
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()));
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()));
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);
1450 SendEditor(SCI_SETILEXER
, 0, reinterpret_cast<sptr_t
>(CreateLexer("cpp")));
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
)
1485 if (type
== CFileTextLines::UnicodeType::UTF8
)
1488 if (type
== CFileTextLines::UnicodeType::UTF16_LE
)
1490 if (type
== CFileTextLines::UnicodeType::UTF16_LEBOM
)
1496 if (type
== CFileTextLines::UnicodeType::UTF16_BE
)
1498 if (type
== CFileTextLines::UnicodeType::UTF16_BEBOM
)
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
);
1527 for (size_t i
= 0; i
< logSize
; ++i
)
1529 if (hash
== (*GetLogData())[i
])
1531 index
= static_cast<int>(i
);
1535 lineToLogIndex
.push_back(index
);
1537 this->m_lineToLogIndex
.swap(lineToLogIndex
);
1540 void CTortoiseGitBlameView::UpdateInfo(int Encode
)
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
);
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)
1568 for (int i
= 0; i
< numberOfLines
; ++i
)
1570 const auto lineLen
= m_data
.GetUtf8Line(i
).GetLength();
1571 if (longestLineLen
< lineLen
)
1573 longestLineLen
= lineLen
;
1576 text
+= m_data
.GetUtf8Line(i
);
1579 text
.TrimRight("\r\n");
1580 SendEditor(SCI_REPLACESEL
, 0, reinterpret_cast<LPARAM
>(static_cast<LPCSTR
>(text
)));
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
);
1590 for (int i
= 0; i
< _countof(encodings
); ++i
)
1592 if (encodings
[i
].id
== encoding
)
1594 sBarText
= CString(encodings
[i
].name
);
1598 //calculate the width of the text
1599 auto pDC
= static_cast<CMainFrame
*>(::AfxGetApp()->GetMainWnd())->m_wndStatusBar
.GetDC();
1602 CSize size
= pDC
->GetTextExtent(sBarText
);
1603 static_cast<CMainFrame
*>(::AfxGetApp()->GetMainWnd())->m_wndStatusBar
.SetPaneInfo(nIndex
, nID
, nStyle
, size
.cx
+ 2);
1606 static_cast<CMainFrame
*>(::AfxGetApp()->GetMainWnd())->m_wndStatusBar
.SetPaneText(nIndex
, sBarText
);
1609 #ifdef USE_TEMPFILENAME
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());
1625 int encoding
= GetEncode( (unsigned char *)m_Buffer
, file
.GetLength(), &bomoffset
);
1628 //SendEditor(SCI_SETCODEPAGE, encoding);
1630 //SendEditor(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)(m_Buffer + bomoffset));
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
))))));
1640 SendEditor(SCI_SETSCROLLWIDTH
, 1);
1641 SendEditor(SCI_SETSCROLLWIDTHTRACKING
, TRUE
);
1642 m_TextView
.SetReadOnly(true);
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
);
1655 CString
CTortoiseGitBlameView::ResolveCommitFile(int line
)
1657 return ResolveCommitFile(m_data
.GetFilename(line
));
1660 CString
CTortoiseGitBlameView::ResolveCommitFile(const CString
& path
)
1664 return static_cast<CMainFrame
*>(::AfxGetApp()->GetMainWnd())->GetActiveView()->GetDocument()->GetPathName();
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
];
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);
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
*)
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
));
1737 m_selectedHashes
.insert(m_data
.GetHash(line
));
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
));
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
);
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;
1772 this->m_TextView
.Invalidate();
1776 SetSelectedLine(-1);
1779 CView::OnLButtonDown(nFlags
,point
);
1782 void CTortoiseGitBlameView::OnSciZoom(NMHDR
* /*hdr*/, LRESULT
* /*result*/)
1784 auto numberOfLines
= m_data
.GetNumberOfLines();
1786 while (numberOfLines
)
1788 numberOfLines
/= 10;
1792 SendEditor(SCI_SETMARGINWIDTHN
, 0, numDigits
* static_cast<int>(SendEditor(SCI_TEXTWIDTH
, STYLE_LINENUMBER
, reinterpret_cast<LPARAM
>("8"))));
1794 SendEditor(SCI_SETMARGINWIDTHN
, 0);
1795 SendEditor(SCI_SETMARGINWIDTHN
, 1);
1796 SendEditor(SCI_SETMARGINWIDTHN
, 2);
1798 CreateNewFont(true);
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
;
1812 notification
->lParam
= GetLineColor(notification
->line
);
1816 void CTortoiseGitBlameView::FocusOn(std::unordered_set
<CGitHash
>&& pRevs
, GitRevLoglist
* selected
)
1818 if (m_bBlockUpdates
)
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)
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();
1839 void CTortoiseGitBlameView::OnMouseHover(UINT
/*nFlags*/, CPoint point
)
1841 int line
= GetLineUnderCursor(point
);
1842 if (m_data
.IsValidLine(line
))
1844 if (line
!= m_MouseLine
)
1847 GitRev
*pRev
= nullptr;
1848 int logIndex
= m_lineToLogIndex
[line
];
1850 pRev
= &GetLogData()->GetGitRevAt(logIndex
);
1852 pRev
= m_data
.GetRev(line
, GetLogData()->m_pLogCache
->m_HashMap
);
1857 CString body
= pRev
->GetBody();
1861 while (iline
++ < maxLine
)
1863 int pos2
= body
.Find(L
'\n', pos
);
1866 int lineLength
= pos2
- pos
- 1;
1868 iline
+= lineLength
/ 70;
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
)));
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)
1889 m_ToolTip
.AddTool(this, str
);
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
;
1903 TrackMouseEvent(&tme
);
1907 void CTortoiseGitBlameView::OnMouseLeave()
1909 if (m_MouseLine
== -1)
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()
1929 m_pFindDialog
->SetFocus();
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
)
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()
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;
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
);
1992 void CTortoiseGitBlameView::OnViewNext()
1994 int startline
= static_cast<int>(SendEditor(SCI_GETFIRSTVISIBLELINE
));
1995 int line
= m_data
.FindNextLine(m_selectedHashes
, startline
, false);
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);
2004 SendEditor(SCI_LINESCROLL
, 0, line
- startline
+ 1);
2007 void CTortoiseGitBlameView::OnViewToggleLogID()
2009 m_bShowLogID
= !m_bShowLogID
;
2011 theApp
.WriteInt(L
"ShowLogID", m_bShowLogID
);
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
);
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
);
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
);
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
);
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);
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);
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);
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);
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
);
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);
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());
2307 pCmdUI
->Enable(m_TextView
.Call(SCI_GETSELECTIONSTART
) != m_TextView
.Call(SCI_GETSELECTIONEND
));
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
))
2332 return __super::GetGestureStatus(ptTouch
);