Keep the font size of 8 for the explorer property page
[TortoiseGit.git] / src / TortoiseGitBlame / TortoiseGitBlameView.cpp
blobe0837b7f8aa08f344efcf3f450298ca0dba178a4
1 // TortoiseGitBlame - a Viewer for Git Blames
3 // Copyright (C) 2008-2018 - 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"
44 #ifdef _DEBUG
45 #define new DEBUG_NEW
46 #endif
48 UINT CTortoiseGitBlameView::m_FindDialogMessage;
50 // CTortoiseGitBlameView
51 IMPLEMENT_DYNAMIC(CSciEditBlame,CSciEdit)
53 IMPLEMENT_DYNCREATE(CTortoiseGitBlameView, CView)
55 BEGIN_MESSAGE_MAP(CTortoiseGitBlameView, CView)
56 // Standard printing commands
57 ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)
58 ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
59 ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CTortoiseGitBlameView::OnFilePrintPreview)
60 ON_COMMAND(ID_EDIT_FIND,OnEditFind)
61 ON_COMMAND(ID_EDIT_GOTO,OnEditGoto)
62 ON_COMMAND(ID_EDIT_COPY, CopyToClipboard)
63 ON_UPDATE_COMMAND_UI(ID_EDIT_COPY, OnUpdateViewCopyToClipboard)
64 ON_COMMAND(ID_VIEW_NEXT,OnViewNext)
65 ON_COMMAND(ID_VIEW_PREV,OnViewPrev)
66 ON_COMMAND(ID_FIND_NEXT, OnFindNext)
67 ON_COMMAND(ID_FIND_PREV, OnFindPrev)
68 ON_COMMAND(ID_VIEW_SHOWAUTHOR, OnViewToggleAuthor)
69 ON_UPDATE_COMMAND_UI(ID_VIEW_SHOWAUTHOR, OnUpdateViewToggleAuthor)
70 ON_COMMAND(ID_VIEW_SHOWDATE, OnViewToggleDate)
71 ON_UPDATE_COMMAND_UI(ID_VIEW_SHOWDATE, OnUpdateViewToggleDate)
72 ON_COMMAND(ID_VIEW_SHOWFILENAME, OnViewToggleShowFilename)
73 ON_UPDATE_COMMAND_UI(ID_VIEW_SHOWFILENAME, OnUpdateViewToggleShowFilename)
74 ON_COMMAND(ID_VIEW_SHOWORIGINALLINENUMBER, OnViewToggleShowOriginalLineNumber)
75 ON_UPDATE_COMMAND_UI(ID_VIEW_SHOWORIGINALLINENUMBER, OnUpdateViewToggleShowOriginalLineNumber)
76 ON_COMMAND(ID_VIEW_DETECT_MOVED_OR_COPIED_LINES_DISABLED, OnViewDetectMovedOrCopiedLinesToggleDisabled)
77 ON_UPDATE_COMMAND_UI(ID_VIEW_DETECT_MOVED_OR_COPIED_LINES_DISABLED, OnUpdateViewDetectMovedOrCopiedLinesToggleDisabled)
78 ON_COMMAND(ID_VIEW_DETECT_MOVED_OR_COPIED_LINES_WITHIN_FILE, OnViewDetectMovedOrCopiedLinesToggleWithinFile)
79 ON_UPDATE_COMMAND_UI(ID_VIEW_DETECT_MOVED_OR_COPIED_LINES_WITHIN_FILE, OnUpdateViewDetectMovedOrCopiedLinesToggleWithinFile)
80 ON_COMMAND(ID_VIEW_DETECT_MOVED_OR_COPIED_LINES_FROM_MODIFIED_FILES, OnViewDetectMovedOrCopiedLinesToggleFromModifiedFiles)
81 ON_UPDATE_COMMAND_UI(ID_VIEW_DETECT_MOVED_OR_COPIED_LINES_FROM_MODIFIED_FILES, OnUpdateViewDetectMovedOrCopiedLinesToggleFromModifiedFiles)
82 ON_COMMAND(ID_VIEW_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES_AT_FILE_CREATION, OnViewDetectMovedOrCopiedLinesToggleFromExistingFilesAtFileCreation)
83 ON_UPDATE_COMMAND_UI(ID_VIEW_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES_AT_FILE_CREATION, OnUpdateViewDetectMovedOrCopiedLinesToggleFromExistingFilesAtFileCreation)
84 ON_COMMAND(ID_VIEW_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES, OnViewDetectMovedOrCopiedLinesToggleFromExistingFiles)
85 ON_UPDATE_COMMAND_UI(ID_VIEW_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES, OnUpdateViewDetectMovedOrCopiedLinesToggleFromExistingFiles)
86 ON_COMMAND(ID_VIEW_IGNORE_WHITESPACE, OnViewToggleIgnoreWhitespace)
87 ON_UPDATE_COMMAND_UI(ID_VIEW_IGNORE_WHITESPACE, OnUpdateViewToggleIgnoreWhitespace)
88 ON_COMMAND(ID_VIEW_SHOWCOMPLETELOG, OnViewToggleShowCompleteLog)
89 ON_UPDATE_COMMAND_UI(ID_VIEW_SHOWCOMPLETELOG, OnUpdateViewToggleShowCompleteLog)
90 ON_COMMAND(ID_VIEW_ONLYCONSIDERFIRSTPARENTS, OnViewToggleOnlyFirstParent)
91 ON_UPDATE_COMMAND_UI(ID_VIEW_ONLYCONSIDERFIRSTPARENTS, OnUpdateViewToggleOnlyFirstParent)
92 ON_COMMAND(ID_VIEW_FOLLOWRENAMES, OnViewToggleFollowRenames)
93 ON_UPDATE_COMMAND_UI(ID_VIEW_FOLLOWRENAMES, OnUpdateViewToggleFollowRenames)
94 ON_COMMAND(ID_VIEW_COLORBYAGE, OnViewToggleColorByAge)
95 ON_UPDATE_COMMAND_UI(ID_VIEW_COLORBYAGE, OnUpdateViewToggleColorByAge)
96 ON_COMMAND(ID_VIEW_ENABLELEXER, OnViewToggleLexer)
97 ON_UPDATE_COMMAND_UI(ID_VIEW_ENABLELEXER, OnUpdateViewToggleLexer)
98 ON_COMMAND(ID_VIEW_WRAPLONGLINES, OnViewWrapLongLines)
99 ON_UPDATE_COMMAND_UI(ID_VIEW_WRAPLONGLINES, OnUpdateViewWrapLongLines)
100 ON_COMMAND_RANGE(IDM_FORMAT_ENCODE, IDM_FORMAT_ENCODE_END, OnChangeEncode)
101 ON_WM_CREATE()
102 ON_WM_SIZE()
103 ON_WM_MOUSEMOVE()
104 ON_WM_MOUSEHOVER()
105 ON_WM_MOUSELEAVE()
106 ON_WM_LBUTTONDOWN()
107 ON_WM_RBUTTONDOWN()
108 ON_WM_RBUTTONUP()
109 ON_WM_SYSCOLORCHANGE()
110 ON_WM_ERASEBKGND()
111 ON_NOTIFY(SCN_PAINTED, IDC_SCINTILLA, OnSciPainted)
112 ON_NOTIFY(SCN_GETBKCOLOR, IDC_SCINTILLA, OnSciGetBkColor)
113 ON_REGISTERED_MESSAGE(m_FindDialogMessage, OnFindDialogMessage)
114 END_MESSAGE_MAP()
117 // CTortoiseGitBlameView construction/destruction
119 CTortoiseGitBlameView::CTortoiseGitBlameView()
120 : wBlame(0)
121 , wHeader(0)
122 , hwndTT(0)
123 , bIgnoreEOL(false)
124 , bIgnoreSpaces(false)
125 , bIgnoreAllSpaces(false)
126 , m_MouseLine(-1)
127 , m_bMatchCase(false)
128 , hInstance(nullptr)
129 , hResource(nullptr)
130 , currentDialog(nullptr)
131 , wMain(nullptr)
132 , wLocator(nullptr)
133 , m_blamewidth(0)
134 , m_revwidth(0)
135 , m_datewidth(0)
136 , m_authorwidth(0)
137 , m_filenameWidth(0)
138 , m_originalLineNumberWidth(0)
139 , m_linewidth(0)
140 , m_SelectedLine(-1)
141 , m_bShowLine(true)
142 , m_pFindDialog(nullptr)
143 #ifdef USE_TEMPFILENAME
144 , m_Buffer(nullptr)
145 #endif
147 m_windowcolor = ::GetSysColor(COLOR_WINDOW);
148 m_textcolor = ::GetSysColor(COLOR_WINDOWTEXT);
149 m_texthighlightcolor = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
150 m_mouserevcolor = InterColor(m_windowcolor, m_textcolor, 20);
151 m_mouseauthorcolor = InterColor(m_windowcolor, m_textcolor, 10);
152 m_selectedrevcolor = ::GetSysColor(COLOR_HIGHLIGHT);
153 m_selectedauthorcolor = InterColor(m_selectedrevcolor, m_texthighlightcolor, 35);
155 HIGHCONTRAST highContrast = { 0 };
156 highContrast.cbSize = sizeof(HIGHCONTRAST);
157 BOOL highContrastModeEnabled = SystemParametersInfo(SPI_GETHIGHCONTRAST, 0, &highContrast, 0) == TRUE && (highContrast.dwFlags & HCF_HIGHCONTRASTON);
158 m_colorage = !!theApp.GetInt(L"ColorAge", !highContrastModeEnabled);
159 m_bLexer = !!theApp.GetInt(L"EnableLexer", !highContrastModeEnabled);
161 m_bShowAuthor = (theApp.GetInt(L"ShowAuthor", 1) == 1);
162 m_bShowDate = (theApp.GetInt(L"ShowDate", 0) == 1);
163 m_bShowFilename = (theApp.GetInt(L"ShowFilename", 0) == 1);
164 m_bShowOriginalLineNumber = (theApp.GetInt(L"ShowOriginalLineNumber", 0) == 1);
165 m_dwDetectMovedOrCopiedLines = theApp.GetInt(L"DetectMovedOrCopiedLines", 0);
166 m_bIgnoreWhitespace = (theApp.GetInt(L"IgnoreWhitespace", 0) == 1);
167 m_bShowCompleteLog = (theApp.GetInt(L"ShowCompleteLog", 1) == 1);
168 m_bOnlyFirstParent = (theApp.GetInt(L"OnlyFirstParent", 0) == 1);
169 m_bFollowRenames = (theApp.GetInt(L"FollowRenames", 0) == 1);
170 m_bBlameOutputContainsOtherFilenames = FALSE;
171 m_bWrapLongLines = !!theApp.GetInt(L"WrapLongLines", 0);
172 m_sFindText = theApp.GetString(L"FindString");
174 m_FindDialogMessage = ::RegisterWindowMessage(FINDMSGSTRING);
175 // get short/long datetime setting from registry
176 DWORD RegUseShortDateFormat = CRegDWORD(L"Software\\TortoiseGit\\LogDateFormat", TRUE);
177 if ( RegUseShortDateFormat )
179 m_DateFormat = DATE_SHORTDATE;
181 else
183 m_DateFormat = DATE_LONGDATE;
185 // get relative time display setting from registry
186 DWORD regRelativeTimes = CRegDWORD(L"Software\\TortoiseGit\\RelativeTimes", FALSE);
187 m_bRelativeTimes = (regRelativeTimes != 0);
189 m_sRev.LoadString(IDS_LOG_REVISION);
190 m_sFileName.LoadString(IDS_FILENAME);
191 m_sAuthor.LoadString(IDS_LOG_AUTHOR);
192 m_sDate.LoadString(IDS_LOG_DATE);
193 m_sMessage.LoadString(IDS_LOG_MESSAGE);
196 CTortoiseGitBlameView::~CTortoiseGitBlameView()
198 #ifdef USE_TEMPFILENAME
199 delete m_Buffer;
200 m_Buffer = nullptr;
201 #endif
203 struct EncodingUnit
205 int id;
206 char *name;
209 static EncodingUnit encodings[] = {
210 {1250, "windows-1250"}, //IDM_FORMAT_WIN_1250
211 {1251, "windows-1251"}, //IDM_FORMAT_WIN_1251
212 {1252, "windows-1252"}, //IDM_FORMAT_WIN_1252
213 {1253, "windows-1253"}, //IDM_FORMAT_WIN_1253
214 {1254, "windows-1254"}, //IDM_FORMAT_WIN_1254
215 {1255, "windows-1255"}, //IDM_FORMAT_WIN_1255
216 {1256, "windows-1256"}, //IDM_FORMAT_WIN_1256
217 {1257, "windows-1257"}, //IDM_FORMAT_WIN_1257
218 {1258, "windows-1258"}, //IDM_FORMAT_WIN_1258
219 {28591, "latin1 ISO_8859-1 ISO-8859-1 CP819 IBM819 csISOLatin1 iso-ir-100 l1"}, //IDM_FORMAT_ISO_8859_1
220 {28592, "latin2 ISO_8859-2 ISO-8859-2 csISOLatin2 iso-ir-101 l2"}, //IDM_FORMAT_ISO_8859_2
221 {28593, "latin3 ISO_8859-3 ISO-8859-3 csISOLatin3 iso-ir-109 l3"}, //IDM_FORMAT_ISO_8859_3
222 {28594, "latin4 ISO_8859-4 ISO-8859-4 csISOLatin4 iso-ir-110 l4"}, //IDM_FORMAT_ISO_8859_4
223 {28595, "cyrillic ISO_8859-5 ISO-8859-5 csISOLatinCyrillic iso-ir-144"}, //IDM_FORMAT_ISO_8859_5
224 {28596, "arabic ISO_8859-6 ISO-8859-6 csISOLatinArabic iso-ir-127 ASMO-708 ECMA-114"}, //IDM_FORMAT_ISO_8859_6
225 {28597, "greek ISO_8859-7 ISO-8859-7 csISOLatinGreek greek8 iso-ir-126 ELOT_928 ECMA-118"}, //IDM_FORMAT_ISO_8859_7
226 {28598, "hebrew ISO_8859-8 ISO-8859-8 csISOLatinHebrew iso-ir-138"}, //IDM_FORMAT_ISO_8859_8
227 {28599, "latin5 ISO_8859-9 ISO-8859-9 csISOLatin5 iso-ir-148 l5"}, //IDM_FORMAT_ISO_8859_9
228 {28600, "latin6 ISO_8859-10 ISO-8859-10 csISOLatin6 iso-ir-157 l6"}, //IDM_FORMAT_ISO_8859_10
229 {28601, "ISO_8859-11 ISO-8859-11"}, //IDM_FORMAT_ISO_8859_11
230 {28603, "ISO_8859-13 ISO-8859-13"}, //IDM_FORMAT_ISO_8859_13
231 {28604, "iso-celtic latin8 ISO_8859-14 ISO-8859-14 18 iso-ir-199"}, //IDM_FORMAT_ISO_8859_14
232 {28605, "Latin-9 ISO_8859-15 ISO-8859-15"}, //IDM_FORMAT_ISO_8859_15
233 {28606, "latin10 ISO_8859-16 ISO-8859-16 110 iso-ir-226"}, //IDM_FORMAT_ISO_8859_16
234 {437, "IBM437 cp437 437 csPC8CodePage437"}, //IDM_FORMAT_DOS_437
235 {720, "IBM720 cp720 oem720 720"}, //IDM_FORMAT_DOS_720
236 {737, "IBM737 cp737 oem737 737"}, //IDM_FORMAT_DOS_737
237 {775, "IBM775 cp775 oem775 775"}, //IDM_FORMAT_DOS_775
238 {850, "IBM850 cp850 oem850 850"}, //IDM_FORMAT_DOS_850
239 {852, "IBM852 cp852 oem852 852"}, //IDM_FORMAT_DOS_852
240 {855, "IBM855 cp855 oem855 855 csIBM855"}, //IDM_FORMAT_DOS_855
241 {857, "IBM857 cp857 oem857 857"}, //IDM_FORMAT_DOS_857
242 {858, "IBM858 cp858 oem858 858"}, //IDM_FORMAT_DOS_858
243 {860, "IBM860 cp860 oem860 860"}, //IDM_FORMAT_DOS_860
244 {861, "IBM861 cp861 oem861 861"}, //IDM_FORMAT_DOS_861
245 {862, "IBM862 cp862 oem862 862"}, //IDM_FORMAT_DOS_862
246 {863, "IBM863 cp863 oem863 863"}, //IDM_FORMAT_DOS_863
247 {865, "IBM865 cp865 oem865 865"}, //IDM_FORMAT_DOS_865
248 {866, "IBM866 cp866 oem866 866"}, //IDM_FORMAT_DOS_866
249 {869, "IBM869 cp869 oem869 869"}, //IDM_FORMAT_DOS_869
250 {950, "big5 csBig5"}, //IDM_FORMAT_BIG5
251 {936, "gb2312 gbk csGB2312"}, //IDM_FORMAT_GB2312
252 {932, "Shift_JIS MS_Kanji csShiftJIS csWindows31J"}, //IDM_FORMAT_SHIFT_JIS
253 {949, "windows-949 korean"}, //IDM_FORMAT_KOREAN_WIN
254 {51949, "euc-kr csEUCKR"}, //IDM_FORMAT_EUC_KR
255 {874, "tis-620"}, //IDM_FORMAT_TIS_620
256 {10007, "x-mac-cyrillic xmaccyrillic"}, //IDM_FORMAT_MAC_CYRILLIC
257 {21866, "koi8_u"}, //IDM_FORMAT_KOI8U_CYRILLIC
258 {20866, "koi8_r csKOI8R"}, //IDM_FORMAT_KOI8R_CYRILLIC
259 {65001, "UTF-8"}, //IDM_FORMAT_UTF8
260 {1200, "UTF-16 LE"}, //IDM_FORMAT_UTF16LE
261 {1201, "UTF-16 BE"}, //IDM_FORMAT_UTF16BE
263 void CTortoiseGitBlameView::OnChangeEncode(UINT nId)
265 if(nId >= IDM_FORMAT_ENCODE && nId <= IDM_FORMAT_ENCODE_END)
266 this->UpdateInfo(encodings[nId - IDM_FORMAT_ENCODE].id);
268 int CTortoiseGitBlameView::OnCreate(LPCREATESTRUCT lpcs)
270 CRect rect,rect1;
271 this->GetWindowRect(&rect1);
272 rect.left = m_blamewidth + CDPIAware::Instance().ScaleX(LOCATOR_WIDTH);
273 rect.right=rect.Width();
274 rect.top=0;
275 rect.bottom=rect.Height();
276 if (!m_TextView.Create(L"Scintilla", L"source", 0, rect, this, IDC_SCINTILLA, 0))
278 TRACE0("Failed to create view\n");
279 return -1; // fail to create
281 m_TextView.Init(-1);
282 m_TextView.ShowWindow( SW_SHOW);
283 CreateFont();
284 SendEditor(SCI_SETREADONLY, TRUE);
285 m_ToolTip.Create(this->GetParent());
287 ::AfxGetApp()->GetMainWnd();
288 return CView::OnCreate(lpcs);
291 void CTortoiseGitBlameView::OnSize(UINT /*nType*/, int cx, int cy)
293 CRect rect;
294 rect.left=m_blamewidth;
295 rect.right=cx;
296 rect.top=0;
297 rect.bottom=cy;
299 m_TextView.MoveWindow(&rect);
301 BOOL CTortoiseGitBlameView::PreCreateWindow(CREATESTRUCT& cs)
303 return CView::PreCreateWindow(cs);
306 // CTortoiseGitBlameView drawing
308 BOOL CTortoiseGitBlameView::OnEraseBkgnd(CDC* /*pDC*/)
310 return TRUE;
313 void CTortoiseGitBlameView::OnDraw(CDC* pDC)
315 CTortoiseGitBlameDoc* pDoc = GetDocument();
316 ASSERT_VALID(pDoc);
317 if (!pDoc)
318 return;
320 CMemDC myDC(*pDC, this);
321 RECT rc;
322 GetClientRect(&rc);
323 myDC.GetDC().FillSolidRect(&rc, m_windowcolor);
324 DrawBlame(myDC.GetDC());
325 DrawLocatorBar(myDC.GetDC());
329 // CTortoiseGitBlameView printing
332 void CTortoiseGitBlameView::OnFilePrintPreview()
334 AFXPrintPreview(this);
337 BOOL CTortoiseGitBlameView::OnPreparePrinting(CPrintInfo* pInfo)
339 // default preparation
340 return DoPreparePrinting(pInfo);
343 void CTortoiseGitBlameView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
345 // TODO: add extra initialization before printing
348 void CTortoiseGitBlameView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
350 // TODO: add cleanup after printing
353 int CTortoiseGitBlameView::GetLineUnderCursor(CPoint point)
355 auto firstvisibleline = (int)SendEditor(SCI_GETFIRSTVISIBLELINE);
356 auto line = (int)SendEditor(SCI_DOCLINEFROMVISIBLE, firstvisibleline);
357 auto linesonscreen = (int)SendEditor(SCI_LINESONSCREEN) + 1;
358 auto height = (int)SendEditor(SCI_TEXTHEIGHT);
360 int i = 0, y = 0;
361 for (i = line; y <= point.y && i < (line + linesonscreen); ++i)
363 auto wrapcount = (int)SendEditor(SCI_WRAPCOUNT, i);
364 if (wrapcount > 1)
366 if (i == line)
367 wrapcount -= (int)SendEditor(SCI_DOCLINEFROMVISIBLE, firstvisibleline + wrapcount - 1) - (int)SendEditor(SCI_DOCLINEFROMVISIBLE, firstvisibleline);
368 linesonscreen -= wrapcount - 1;
370 y += height * wrapcount;
372 return i - 1;
375 void CTortoiseGitBlameView::OnRButtonUp(UINT /*nFlags*/, CPoint point)
377 int line = GetLineUnderCursor(point);
378 if (m_data.IsValidLine(line))
380 m_MouseLine = line;
381 ClientToScreen(&point);
383 CGitHash hash = m_data.GetHash(line);
384 CString hashStr = hash.ToString();
386 GitRevLoglist* pRev = nullptr;
387 int logIndex = m_lineToLogIndex[line];
388 if (logIndex >= 0)
389 pRev = &GetLogData()->GetGitRevAt(logIndex);
390 else
392 pRev = m_data.GetRev(line, GetLogData()->m_pLogCache->m_HashMap);
393 if (pRev && pRev->m_ParentHash.empty())
395 if (pRev->GetParentFromHash(pRev->m_CommitHash))
396 MessageBox(pRev->GetLastErr(), L"TortoiseGit", MB_ICONERROR);
400 if (!pRev)
401 return;
403 CIconMenu popup;
404 CIconMenu blamemenu, diffmenu;
406 if (!popup.CreatePopupMenu())
407 return;
409 // Now find the relevant parent commits, they must contain the file which is blamed to be the source of the selected line,
410 // otherwise there is no previous file to compare to (only another previous revision).
412 GIT_REV_LIST parentHashWithFile;
413 std::vector<CString> parentFilename;
416 CTGitPath path(m_data.GetFilename(line));
417 const CTGitPathList& files = pRev->GetFiles(nullptr);
418 for (int j = 0, j_size = files.GetCount(); j < j_size; ++j)
420 const CTGitPath &file = files[j];
421 if (file.IsEquivalentTo(path))
423 if (!(file.m_ParentNo & MERGE_MASK))
425 int action = file.m_Action;
426 // ignore (action & CTGitPath::LOGACTIONS_ADDED), as then there is nothing to blame/diff
427 // ignore (action & CTGitPath::LOGACTIONS_DELETED), should never happen as the file must exist
428 if (action & (CTGitPath::LOGACTIONS_MODIFIED | CTGitPath::LOGACTIONS_REPLACED))
430 int parentNo = file.m_ParentNo & PARENT_MASK;
431 if (parentNo >= 0 && (size_t)parentNo < pRev->m_ParentHash.size())
433 parentHashWithFile.push_back(pRev->m_ParentHash[parentNo]);
434 parentFilename.push_back((action & CTGitPath::LOGACTIONS_REPLACED) ? file.GetGitOldPathString() : file.GetGitPathString());
441 catch (const char* msg)
443 MessageBox(L"Could not get files of parents.\nlibgit reports:\n" + CString(msg), L"TortoiseGit", MB_ICONERROR);
446 // blame previous
447 if (!parentHashWithFile.empty())
449 if (parentHashWithFile.size() == 1)
451 popup.AppendMenuIcon(ID_BLAMEPREVIOUS, IDS_BLAME_POPUP_BLAME, IDI_BLAME_POPUP_BLAME);
453 else
455 blamemenu.CreatePopupMenu();
456 popup.AppendMenuIcon(ID_BLAMEPREVIOUS, IDS_BLAME_POPUP_BLAME, IDI_BLAME_POPUP_BLAME, blamemenu.m_hMenu);
458 for (size_t i = 0; i < parentHashWithFile.size(); ++i)
460 CString str;
461 str.Format(IDS_PARENT, i + 1);
462 blamemenu.AppendMenuIcon(ID_BLAMEPREVIOUS + ((i + 1) << 16), str);
467 // compare with previous
468 if (!parentHashWithFile.empty())
470 if (parentHashWithFile.size() == 1)
472 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_BLAME_POPUP_COMPARE, IDI_BLAME_POPUP_COMPARE);
473 if (CRegDWORD(L"Software\\TortoiseGit\\DiffByDoubleClickInLog", FALSE))
474 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
476 else
478 diffmenu.CreatePopupMenu();
479 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_BLAME_POPUP_COMPARE, IDI_BLAME_POPUP_COMPARE, diffmenu.m_hMenu);
480 for (size_t i = 0; i < parentHashWithFile.size(); ++i)
482 CString str;
483 str.Format(IDS_BLAME_POPUP_PARENT, i + 1);
484 diffmenu.AppendMenuIcon((UINT)(ID_COMPAREWITHPREVIOUS + ((i + 1) << 16)),str);
485 if (i == 0 && CRegDWORD(L"Software\\TortoiseGit\\DiffByDoubleClickInLog", FALSE))
487 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
488 diffmenu.SetDefaultItem((UINT)(ID_COMPAREWITHPREVIOUS + ((i + 1) << 16)), FALSE);
494 popup.AppendMenuIcon(ID_SHOWLOG, IDS_BLAME_POPUP_LOG, IDI_BLAME_POPUP_LOG);
495 popup.AppendMenu(MF_SEPARATOR, NULL);
496 popup.AppendMenuIcon(ID_COPYHASHTOCLIPBOARD, IDS_BLAME_POPUP_COPYHASHTOCLIPBOARD, IDI_BLAME_POPUP_COPY);
497 popup.AppendMenuIcon(ID_COPYLOGTOCLIPBOARD, IDS_BLAME_POPUP_COPYLOGTOCLIPBOARD, IDI_BLAME_POPUP_COPY);
499 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this);
500 if (!cmd)
501 return;
502 this->ContextMenuAction(cmd, pRev, parentHashWithFile, parentFilename, line);
506 void CTortoiseGitBlameView::ContextMenuAction(int cmd, GitRev *pRev, GIT_REV_LIST& parentHashWithFile, const std::vector<CString>& parentFilename, int selectedLine)
508 switch (cmd & 0xFFFF)
510 case ID_BLAMEPREVIOUS:
512 int index = (cmd>>16) & 0xFFFF;
513 if (index > 0)
514 index -= 1;
516 CString path = ResolveCommitFile(parentFilename[index]);
517 CString endrev = parentHashWithFile[index].ToString();
518 int line = m_data.GetOriginalLineNumber(selectedLine);
520 CString procCmd = L"/path:\"" + path + L"\" ";
521 procCmd += L" /command:blame";
522 procCmd += L" /endrev:" + endrev;
523 procCmd += L" /line:";
524 procCmd.AppendFormat(L"%d", line);
526 CCommonAppUtils::RunTortoiseGitProc(procCmd);
528 break;
530 case ID_COMPAREWITHPREVIOUS:
532 int index = (cmd >> 16) & 0xFFFF;
533 if (index > 0)
534 index -= 1;
536 CString path = ResolveCommitFile(parentFilename[index]);
537 CString startrev = parentHashWithFile[index].ToString();
538 CString endrev = pRev->m_CommitHash.ToString();
540 CString procCmd = L"/path:\"" + path + L"\" ";
541 procCmd += L" /command:diff";
542 procCmd += L" /startrev:" + startrev;
543 procCmd += L" /endrev:" + endrev;
544 if (!!(GetAsyncKeyState(VK_SHIFT) & 0x8000))
545 procCmd += L" /alternative";
547 CCommonAppUtils::RunTortoiseGitProc(procCmd);
549 break;
551 case ID_SHOWLOG:
553 CString path = ResolveCommitFile(selectedLine);
554 CString rev = m_data.GetHash(selectedLine).ToString();
556 CString procCmd = L"/path:\"" + path + L"\" ";
557 procCmd += L" /command:log";
558 procCmd += L" /rev:" + rev;
559 procCmd += L" /endrev:" + rev;
561 CCommonAppUtils::RunTortoiseGitProc(procCmd);
563 break;
565 case ID_COPYHASHTOCLIPBOARD:
566 this->GetLogList()->CopySelectionToClipBoard(CGitLogListBase::ID_COPYCLIPBOARDHASH);
567 break;
569 case ID_COPYLOGTOCLIPBOARD:
570 this->GetLogList()->CopySelectionToClipBoard(CGitLogListBase::ID_COPYCLIPBOARDFULL);
571 break;
575 // CTortoiseGitBlameView diagnostics
577 #ifdef _DEBUG
578 void CTortoiseGitBlameView::AssertValid() const
580 CView::AssertValid();
583 void CTortoiseGitBlameView::Dump(CDumpContext& dc) const
585 CView::Dump(dc);
588 CTortoiseGitBlameDoc* CTortoiseGitBlameView::GetDocument() const // non-debug version is inline
590 ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTortoiseGitBlameDoc)));
591 return (CTortoiseGitBlameDoc*)m_pDocument;
593 #endif //_DEBUG
596 // Return a color which is interpolated between c1 and c2.
597 // Slider controls the relative proportions as a percentage:
598 // Slider = 0 represents pure c1
599 // Slider = 50 represents equal mixture
600 // Slider = 100 represents pure c2
601 COLORREF CTortoiseGitBlameView::InterColor(COLORREF c1, COLORREF c2, int Slider)
603 int r, g, b;
605 // Limit Slider to 0..100% range
606 if (Slider < 0)
607 Slider = 0;
608 if (Slider > 100)
609 Slider = 100;
611 // The color components have to be treated individually.
612 r = (GetRValue(c2) * Slider + GetRValue(c1) * (100 - Slider)) / 100;
613 g = (GetGValue(c2) * Slider + GetGValue(c1) * (100 - Slider)) / 100;
614 b = (GetBValue(c2) * Slider + GetBValue(c1) * (100 - Slider)) / 100;
616 return RGB(r, g, b);
619 LRESULT CTortoiseGitBlameView::SendEditor(UINT Msg, WPARAM wParam, LPARAM lParam)
621 return m_TextView.Call(Msg, wParam, lParam);
624 void CTortoiseGitBlameView::SetAStyle(int style, COLORREF fore, COLORREF back, int size, const char *face)
626 if (fore == back && fore == m_windowcolor)
627 fore = m_textcolor;
628 m_TextView.SetAStyle(style, fore, back, size, face);
631 void CTortoiseGitBlameView::InitialiseEditor()
633 SendEditor(SCI_STYLERESETDEFAULT);
634 // Set up the global default style. These attributes are used wherever no explicit choices are made.
635 std::string fontName = CUnicodeUtils::StdGetUTF8((std::wstring)CRegStdString(L"Software\\TortoiseGit\\BlameFontName", L"Consolas"));
636 SetAStyle(STYLE_DEFAULT,
637 ::GetSysColor(COLOR_WINDOWTEXT),
638 ::GetSysColor(COLOR_WINDOW),
639 (DWORD)CRegStdDWORD(L"Software\\TortoiseGit\\BlameFontSize", 10),
640 fontName.c_str()
642 SendEditor(SCI_SETTABWIDTH, (DWORD)CRegStdDWORD(L"Software\\TortoiseGit\\BlameTabSize", 4));
643 SendEditor(SCI_SETREADONLY, TRUE);
644 auto numberOfLines = m_data.GetNumberOfLines();
645 int numDigits = 2;
646 while (numberOfLines)
648 numberOfLines /= 10;
649 ++numDigits;
651 if (m_bShowLine)
652 SendEditor(SCI_SETMARGINWIDTHN, 0, numDigits * (int)SendEditor(SCI_TEXTWIDTH, STYLE_LINENUMBER, (LPARAM)"8"));
653 else
654 SendEditor(SCI_SETMARGINWIDTHN, 0);
655 SendEditor(SCI_SETMARGINWIDTHN, 1);
656 SendEditor(SCI_SETMARGINWIDTHN, 2);
657 //Set the default windows colors for edit controls
658 SendEditor(SCI_SETSELFORE, TRUE, ::GetSysColor(COLOR_HIGHLIGHTTEXT));
659 SendEditor(SCI_SETSELBACK, TRUE, ::GetSysColor(COLOR_HIGHLIGHT));
660 SendEditor(SCI_SETCARETFORE, ::GetSysColor(COLOR_WINDOWTEXT));
661 m_regOldLinesColor = CRegStdDWORD(L"Software\\TortoiseGit\\BlameOldColor", BLAMEOLDCOLOR);
662 m_regNewLinesColor = CRegStdDWORD(L"Software\\TortoiseGit\\BlameNewColor", BLAMENEWCOLOR);
663 if (CRegStdDWORD(L"Software\\TortoiseGit\\ScintillaDirect2D", FALSE) != FALSE)
665 SendEditor(SCI_SETTECHNOLOGY, SC_TECHNOLOGY_DIRECTWRITERETAIN);
666 SendEditor(SCI_SETBUFFEREDDRAW, 0);
669 if (m_bWrapLongLines)
670 SendEditor(SCI_SETWRAPMODE, SC_WRAP_WORD);
671 else
672 SendEditor(SCI_SETWRAPMODE, SC_WRAP_NONE);
673 SendEditor(SCI_STYLECLEARALL);
676 bool CTortoiseGitBlameView::DoSearch(CTortoiseGitBlameData::SearchDirection direction)
678 auto pos = (Sci_Position)SendEditor(SCI_GETCURRENTPOS);
679 auto line = (int)SendEditor(SCI_LINEFROMPOSITION, pos);
681 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); });
682 if (i >= 0)
684 GotoLine(i + 1);
685 auto selstart = (int)(Sci_Position)SendEditor(SCI_GETCURRENTPOS);
686 auto selend = (int)(Sci_Position)SendEditor(SCI_POSITIONFROMLINE, i + 1);
687 SendEditor(SCI_SETSELECTIONSTART, selstart);
688 SendEditor(SCI_SETSELECTIONEND, selend);
689 m_SelectedLine = i;
691 else
692 ::MessageBox(m_pFindDialog && m_pFindDialog->GetSafeHwnd() ? m_pFindDialog->GetSafeHwnd() : wMain, L"\"" + m_sFindText + L"\" " + CString(MAKEINTRESOURCE(IDS_NOTFOUND)), L"TortoiseGitBlame", MB_ICONINFORMATION);
694 return true;
697 void CTortoiseGitBlameView::OnFindPrev()
699 if (m_sFindText.IsEmpty())
700 return;
701 DoSearch(CTortoiseGitBlameData::SearchPrevious);
704 void CTortoiseGitBlameView::OnFindNext()
706 if (m_sFindText.IsEmpty())
707 return;
708 DoSearch(CTortoiseGitBlameData::SearchNext);
711 bool CTortoiseGitBlameView::GotoLine(int line)
713 --line;
714 int numberOfLines = (int)m_data.GetNumberOfLines();
715 if (line < 0 || numberOfLines == 0)
716 return false;
717 if (line >= numberOfLines)
719 line = numberOfLines - 1;
722 auto nCurrentPos = (Sci_Position)SendEditor(SCI_GETCURRENTPOS);
723 int nCurrentLine = (int)SendEditor(SCI_LINEFROMPOSITION,nCurrentPos);
724 int nFirstVisibleLine = (int)SendEditor(SCI_GETFIRSTVISIBLELINE);
725 int nLinesOnScreen = (int)SendEditor(SCI_LINESONSCREEN);
727 if ( line>=nFirstVisibleLine && line<=nFirstVisibleLine+nLinesOnScreen)
729 // no need to scroll
730 SendEditor(SCI_GOTOLINE, line);
732 else
734 // Place the requested line one third from the top
735 if ( line > nCurrentLine )
737 SendEditor(SCI_GOTOLINE, (WPARAM)(line+(int)nLinesOnScreen*(2/3.0)));
739 else
741 SendEditor(SCI_GOTOLINE, (WPARAM)(line-(int)nLinesOnScreen*(1/3.0)));
745 // Highlight the line
746 int nPosStart = (int)SendEditor(SCI_POSITIONFROMLINE,line);
747 int nPosEnd = (int)SendEditor(SCI_GETLINEENDPOSITION,line);
748 SendEditor(SCI_SETSEL,nPosEnd,nPosStart);
750 return true;
753 bool CTortoiseGitBlameView::ScrollToLine(long line)
755 if (line < 0)
756 return false;
758 int nCurrentLine = (int)SendEditor(SCI_GETFIRSTVISIBLELINE);
760 int scrolldelta = line - nCurrentLine;
761 SendEditor(SCI_LINESCROLL, 0, scrolldelta);
763 return true;
766 void CTortoiseGitBlameView::CopyToClipboard()
768 CWnd * wnd = GetFocus();
769 if (wnd == this->GetLogList())
770 GetLogList()->CopySelectionToClipBoard();
771 else if (wnd)
773 if (CString(wnd->GetRuntimeClass()->m_lpszClassName) == L"CMFCPropertyGridCtrl")
775 CMFCPropertyGridCtrl *grid = (CMFCPropertyGridCtrl *)wnd;
776 if (grid->GetCurSel() && !grid->GetCurSel()->IsGroup())
777 CStringUtils::WriteAsciiStringToClipboard(grid->GetCurSel()->GetValue(), GetSafeHwnd());
779 else
780 m_TextView.Call(SCI_COPY);
784 LONG CTortoiseGitBlameView::GetBlameWidth()
786 LONG blamewidth = 0;
787 SIZE width;
788 CreateFont();
789 HDC hDC = this->GetDC()->m_hDC;
790 HFONT oldfont = (HFONT)::SelectObject(hDC, m_font.GetSafeHandle());
792 CString shortHash('f', g_Git.GetShortHASHLength() + 1);
793 ::GetTextExtentPoint32(hDC, shortHash, g_Git.GetShortHASHLength() + 1, &width);
794 m_revwidth = width.cx + CDPIAware::Instance().ScaleX(BLAMESPACE);
795 blamewidth += m_revwidth;
797 if (m_bShowDate)
799 SIZE maxwidth = {0};
801 auto numberOfLines = m_data.GetNumberOfLines();
802 for (size_t i = 0; i < numberOfLines; ++i)
804 ::GetTextExtentPoint32(hDC, m_data.GetDate(i), m_data.GetDate(i).GetLength(), &width);
805 if (width.cx > maxwidth.cx)
806 maxwidth = width;
808 m_datewidth = maxwidth.cx + CDPIAware::Instance().ScaleX(BLAMESPACE);
809 blamewidth += m_datewidth;
811 if ( m_bShowAuthor)
813 SIZE maxwidth = {0};
815 size_t numberOfLines = m_data.GetNumberOfLines();
816 for (size_t i = 0; i < numberOfLines; ++i)
818 ::GetTextExtentPoint32(hDC,m_data.GetAuthor(i) , m_data.GetAuthor(i).GetLength(), &width);
819 if (width.cx > maxwidth.cx)
820 maxwidth = width;
822 m_authorwidth = maxwidth.cx + CDPIAware::Instance().ScaleX(BLAMESPACE);
823 blamewidth += m_authorwidth;
825 if (m_bShowFilename)
827 SIZE maxwidth = {0};
829 size_t numberOfLines = m_data.GetNumberOfLines();
830 for (size_t i = 0; i < numberOfLines; ++i)
832 ::GetTextExtentPoint32(hDC, m_data.GetFilename(i), m_data.GetFilename(i).GetLength(), &width);
833 if (width.cx > maxwidth.cx)
834 maxwidth = width;
836 m_filenameWidth = maxwidth.cx + CDPIAware::Instance().ScaleX(BLAMESPACE);
837 blamewidth += m_filenameWidth;
839 if (m_bShowOriginalLineNumber)
841 SIZE maxwidth = {0};
843 size_t numberOfLines = m_data.GetNumberOfLines();
844 CString str;
845 for (size_t i = 0; i < numberOfLines; ++i)
847 str.Format(L"%5d", m_data.GetOriginalLineNumber(i));
848 ::GetTextExtentPoint32(hDC, str, str.GetLength(), &width);
849 if (width.cx > maxwidth.cx)
850 maxwidth = width;
852 m_originalLineNumberWidth = maxwidth.cx + CDPIAware::Instance().ScaleX(BLAMESPACE);
853 blamewidth += m_originalLineNumberWidth;
855 ::SelectObject(hDC, oldfont);
856 POINT pt = {blamewidth, 0};
857 LPtoDP(hDC, &pt, 1);
858 m_blamewidth = pt.x;
859 //::ReleaseDC(wBlame, hDC);
860 return blamewidth;
863 void CTortoiseGitBlameView::CreateFont()
865 if (m_font.GetSafeHandle())
866 return;
867 LOGFONT lf = {0};
868 lf.lfWeight = 400;
869 lf.lfHeight = -CDPIAware::Instance().PointsToPixelsY((DWORD)CRegStdDWORD(L"Software\\TortoiseGit\\BlameFontSize", 10));
870 lf.lfCharSet = DEFAULT_CHARSET;
871 CRegStdString fontname = CRegStdString(L"Software\\TortoiseGit\\BlameFontName", L"Consolas");
872 wcscpy_s(lf.lfFaceName, 32, ((std::wstring)fontname).c_str());
873 m_font.CreateFontIndirect(&lf);
875 lf.lfItalic = TRUE;
876 m_italicfont.CreateFontIndirect(&lf);
879 void CTortoiseGitBlameView::DrawBlame(HDC hDC)
881 if (!hDC || m_data.GetNumberOfLines() == 0)
882 return;
883 if (!m_font.GetSafeHandle())
884 return;
886 HFONT oldfont = nullptr;
887 int firstvisibleline = (int)SendEditor(SCI_GETFIRSTVISIBLELINE);
888 int line = (int)SendEditor(SCI_DOCLINEFROMVISIBLE, firstvisibleline);
889 int linesonscreen = (int)SendEditor(SCI_LINESONSCREEN) + 1;
890 int height = (int)SendEditor(SCI_TEXTHEIGHT);
891 int Y = 0;
892 TCHAR buf[MAX_PATH] = {0};
893 std::fill_n(buf, _countof(buf) - 1, L' ');
894 RECT rc;
895 CGitHash oldHash;
896 CString oldFile;
898 for (int i = line; i < (line + linesonscreen) && (size_t)i < m_data.GetNumberOfLines(); ++i)
900 auto wrapcount = (int)SendEditor(SCI_WRAPCOUNT, i);
901 if (wrapcount > 1)
903 if (i == line)
904 wrapcount -= (int)SendEditor(SCI_DOCLINEFROMVISIBLE, firstvisibleline + wrapcount - 1) - (int)SendEditor(SCI_DOCLINEFROMVISIBLE, firstvisibleline);
905 linesonscreen -= wrapcount - 1;
907 CGitHash hash(m_data.GetHash(i));
908 oldfont = (HFONT)::SelectObject(hDC, m_font.GetSafeHandle());
909 ::SetBkColor(hDC, m_windowcolor);
910 ::SetTextColor(hDC, m_textcolor);
911 if (!hash.IsEmpty() && hash == m_SelectedHash)
913 ::SetBkColor(hDC, m_selectedauthorcolor);
914 ::SetTextColor(hDC, m_texthighlightcolor);
917 if (m_MouseLine == i)
918 ::SetBkColor(hDC, m_mouserevcolor);
920 if ((!hash.IsEmpty() && hash == m_SelectedHash) || m_MouseLine == i)
922 auto old = ::GetTextColor(hDC);
923 ::SetTextColor(hDC, ::GetBkColor(hDC));
924 RECT rc2 = { CDPIAware::Instance().ScaleX(LOCATOR_WIDTH), Y, m_blamewidth + CDPIAware::Instance().ScaleX(LOCATOR_WIDTH), Y + (wrapcount * height) };
925 for (int j = 0; j < wrapcount; ++j)
926 ::ExtTextOut(hDC, 0, Y + (j * height), ETO_CLIPPED, &rc2, buf, _countof(buf) - 1, 0);
927 ::SetTextColor(hDC, old);
930 CString file = m_data.GetFilename(i);
931 if (oldHash != hash || (m_bShowFilename && oldFile != file) || m_bShowOriginalLineNumber)
933 rc.top = (LONG)Y;
934 rc.left = CDPIAware::Instance().ScaleX(LOCATOR_WIDTH);
935 rc.bottom = (LONG)(Y + height);
936 rc.right = rc.left + m_blamewidth;
937 if (oldHash != hash)
939 CString shortHashStr = hash.ToString().Left(g_Git.GetShortHASHLength());
940 ::ExtTextOut(hDC, CDPIAware::Instance().ScaleX(LOCATOR_WIDTH), Y, ETO_CLIPPED, &rc, shortHashStr, shortHashStr.GetLength(), 0);
942 int Left = m_revwidth;
944 if (m_bShowAuthor)
946 rc.right = rc.left + Left + m_authorwidth;
947 if (oldHash != hash)
948 ::ExtTextOut(hDC, Left, Y, ETO_CLIPPED, &rc, m_data.GetAuthor(i), m_data.GetAuthor(i).GetLength(), 0);
949 Left += m_authorwidth;
951 if (m_bShowDate)
953 rc.right = rc.left + Left + m_datewidth;
954 if (oldHash != hash)
955 ::ExtTextOut(hDC, Left, Y, ETO_CLIPPED, &rc, m_data.GetDate(i), m_data.GetDate(i).GetLength(), 0);
956 Left += m_datewidth;
958 if (m_bShowFilename)
960 rc.right = rc.left + Left + m_filenameWidth;
961 if (oldFile != file)
962 ::ExtTextOut(hDC, Left, Y, ETO_CLIPPED, &rc, m_data.GetFilename(i), m_data.GetFilename(i).GetLength(), 0);
963 Left += m_filenameWidth;
965 if (m_bShowOriginalLineNumber)
967 rc.right = rc.left + Left + m_originalLineNumberWidth;
968 CString str;
969 str.Format(L"%5d", m_data.GetOriginalLineNumber(i));
970 ::ExtTextOut(hDC, Left, Y, ETO_CLIPPED, &rc, str, str.GetLength(), 0);
971 Left += m_originalLineNumberWidth;
973 oldHash = hash;
974 oldFile = file;
976 if (i == m_SelectedLine && m_pFindDialog)
978 LOGBRUSH brush;
979 brush.lbColor = m_textcolor;
980 brush.lbHatch = 0;
981 brush.lbStyle = BS_SOLID;
982 HPEN pen = ExtCreatePen(PS_SOLID | PS_GEOMETRIC, 2, &brush, 0, nullptr);
983 HGDIOBJ hPenOld = SelectObject(hDC, pen);
984 RECT rc2 = { CDPIAware::Instance().ScaleX(LOCATOR_WIDTH), Y + 1, m_blamewidth, Y + (wrapcount * height) - 1};
985 ::MoveToEx(hDC, rc2.left, rc2.top, nullptr);
986 ::LineTo(hDC, rc2.right, rc2.top);
987 ::LineTo(hDC, rc2.right, rc2.bottom);
988 ::LineTo(hDC, rc2.left, rc2.bottom);
989 ::LineTo(hDC, rc2.left, rc2.top);
990 SelectObject(hDC, hPenOld);
991 DeleteObject(pen);
993 Y += wrapcount * height;
994 ::SelectObject(hDC, oldfont);
998 void CTortoiseGitBlameView::DrawLocatorBar(HDC hDC)
1000 if (!hDC)
1001 return;
1003 int line = (int)SendEditor(SCI_GETFIRSTVISIBLELINE);
1004 int linesonscreen = (int)SendEditor(SCI_LINESONSCREEN);
1005 int Y = 0;
1006 COLORREF blackColor = GetSysColor(COLOR_WINDOWTEXT);
1008 RECT rc;
1009 //::GetClientRect(wLocator, &rc);
1010 this->GetClientRect(&rc);
1012 rc.right = CDPIAware::Instance().ScaleX(LOCATOR_WIDTH);
1014 RECT lineRect = rc;
1015 LONG height = rc.bottom-rc.top;
1017 auto numberOfLines = (int)m_data.GetNumberOfLines();
1018 // draw the colored bar
1019 for (int currentLine = 0; currentLine < numberOfLines; ++currentLine)
1021 COLORREF cr = GetLineColor(currentLine);
1022 // get the line color
1023 if ((currentLine >= line)&&(currentLine < (line + linesonscreen)))
1025 cr = InterColor(cr, blackColor, 10);
1027 SetBkColor(hDC, cr);
1028 lineRect.top = (LONG)Y;
1029 lineRect.bottom = (((int)currentLine + 1) * height / (int)numberOfLines);
1030 ::ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &lineRect, nullptr, 0, nullptr);
1031 Y = lineRect.bottom;
1034 if (numberOfLines > 0)
1036 // now draw two lines indicating the scroll position of the source view
1037 SetBkColor(hDC, blackColor);
1038 lineRect.top = (LONG)line * height / (int)numberOfLines;
1039 lineRect.bottom = lineRect.top+1;
1040 ::ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &lineRect, nullptr, 0, nullptr);
1041 lineRect.top = (LONG)(line + linesonscreen) * height / (int)numberOfLines;
1042 lineRect.bottom = lineRect.top+1;
1043 ::ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &lineRect, nullptr, 0, nullptr);
1047 void CTortoiseGitBlameView::SetupLexer(CString filename)
1049 int start = filename.ReverseFind(L'.');
1050 SendEditor(SCI_SETLEXER, SCLEX_NULL);
1051 if (!m_bLexer)
1052 return;
1053 if (start > 0)
1055 //wcscpy_s(line, 20, lineptr+1);
1056 //_wcslwr_s(line, 20);
1057 CString ext=filename.Right(filename.GetLength()-start-1);
1058 const TCHAR* line = ext;
1060 if ((wcscmp(line, L"py") == 0) ||
1061 (wcscmp(line, L"pyw") == 0))
1063 SendEditor(SCI_SETLEXER, SCLEX_PYTHON);
1064 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(L"and assert break class continue def del elif \
1065 else except exec finally for from global if import in is lambda None \
1066 not or pass print raise return try while yield").GetBuffer()));
1067 SetAStyle(SCE_P_DEFAULT, black);
1068 SetAStyle(SCE_P_COMMENTLINE, darkGreen);
1069 SetAStyle(SCE_P_NUMBER, RGB(0, 0x80, 0x80));
1070 SetAStyle(SCE_P_STRING, RGB(0, 0, 0x80));
1071 SetAStyle(SCE_P_CHARACTER, RGB(0, 0, 0x80));
1072 SetAStyle(SCE_P_WORD, RGB(0x80, 0, 0x80));
1073 SetAStyle(SCE_P_TRIPLE, black);
1074 SetAStyle(SCE_P_TRIPLEDOUBLE, black);
1075 SetAStyle(SCE_P_CLASSNAME, darkBlue);
1076 SetAStyle(SCE_P_DEFNAME, darkBlue);
1077 SetAStyle(SCE_P_OPERATOR, darkBlue);
1078 SetAStyle(SCE_P_IDENTIFIER, darkBlue);
1079 SetAStyle(SCE_P_COMMENTBLOCK, darkGreen);
1080 SetAStyle(SCE_P_STRINGEOL, red);
1082 if ((wcscmp(line, L"c") == 0) ||
1083 (wcscmp(line, L"cc") == 0) ||
1084 (wcscmp(line, L"cpp") == 0) ||
1085 (wcscmp(line, L"cxx") == 0) ||
1086 (wcscmp(line, L"h") == 0) ||
1087 (wcscmp(line, L"hh") == 0) ||
1088 (wcscmp(line, L"hpp") == 0) ||
1089 (wcscmp(line, L"hxx") == 0) ||
1090 (wcscmp(line, L"dlg") == 0) ||
1091 (wcscmp(line, L"mak") == 0))
1093 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1094 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(L"and and_eq asm auto bitand bitor bool break \
1095 case catch char class compl const const_cast continue \
1096 default delete do double dynamic_cast else enum explicit export extern false float for \
1097 friend goto if inline int long mutable namespace new not not_eq \
1098 operator or or_eq private protected public \
1099 register reinterpret_cast return short signed sizeof static static_cast struct switch \
1100 template this throw true try typedef typeid typename union unsigned using \
1101 virtual void volatile wchar_t while xor xor_eq").GetBuffer()));
1102 SendEditor(SCI_SETKEYWORDS, 3, (LPARAM)(m_TextView.StringForControl(L"a addindex addtogroup anchor arg attention \
1103 author b brief bug c class code date def defgroup deprecated dontinclude \
1104 e em endcode endhtmlonly endif endlatexonly endlink endverbatim enum example exception \
1105 f$ f[ f] file fn hideinitializer htmlinclude htmlonly \
1106 if image include ingroup internal invariant interface latexonly li line link \
1107 mainpage name namespace nosubgrouping note overload \
1108 p page par param post pre ref relates remarks return retval \
1109 sa section see showinitializer since skip skipline struct subsection \
1110 test throw todo typedef union until \
1111 var verbatim verbinclude version warning weakgroup $ @ \\ & < > # { }").GetBuffer()));
1112 SetupCppLexer();
1114 if (wcscmp(line, L"cs") == 0)
1116 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1117 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(L"abstract as base bool break byte case catch char checked class \
1118 const continue decimal default delegate do double else enum \
1119 event explicit extern false finally fixed float for foreach goto if \
1120 implicit in int interface internal is lock long namespace new null \
1121 object operator out override params private protected public \
1122 readonly ref return sbyte sealed short sizeof stackalloc static \
1123 string struct switch this throw true try typeof uint ulong \
1124 unchecked unsafe ushort using virtual void while").GetBuffer()));
1125 SetupCppLexer();
1127 if ((wcscmp(line, L"rc") == 0) ||
1128 (wcscmp(line, L"rc2") == 0))
1130 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1131 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(L"ACCELERATORS ALT AUTO3STATE AUTOCHECKBOX AUTORADIOBUTTON \
1132 BEGIN BITMAP BLOCK BUTTON CAPTION CHARACTERISTICS CHECKBOX CLASS \
1133 COMBOBOX CONTROL CTEXT CURSOR DEFPUSHBUTTON DIALOG DIALOGEX DISCARDABLE \
1134 EDITTEXT END EXSTYLE FONT GROUPBOX ICON LANGUAGE LISTBOX LTEXT \
1135 MENU MENUEX MENUITEM MESSAGETABLE POPUP \
1136 PUSHBUTTON RADIOBUTTON RCDATA RTEXT SCROLLBAR SEPARATOR SHIFT STATE3 \
1137 STRINGTABLE STYLE TEXTINCLUDE VALUE VERSION VERSIONINFO VIRTKEY").GetBuffer()));
1138 SetupCppLexer();
1140 if ((wcscmp(line, L"idl") == 0) ||
1141 (wcscmp(line, L"odl") == 0))
1143 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1144 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(L"aggregatable allocate appobject arrays async async_uuid \
1145 auto_handle \
1146 bindable boolean broadcast byte byte_count \
1147 call_as callback char coclass code comm_status \
1148 const context_handle context_handle_noserialize \
1149 context_handle_serialize control cpp_quote custom \
1150 decode default defaultbind defaultcollelem \
1151 defaultvalue defaultvtable dispinterface displaybind dllname \
1152 double dual \
1153 enable_allocate encode endpoint entry enum error_status_t \
1154 explicit_handle \
1155 fault_status first_is float \
1156 handle_t heap helpcontext helpfile helpstring \
1157 helpstringcontext helpstringdll hidden hyper \
1158 id idempotent ignore iid_as iid_is immediatebind implicit_handle \
1159 import importlib in include in_line int __int64 __int3264 interface \
1160 last_is lcid length_is library licensed local long \
1161 max_is maybe message methods midl_pragma \
1162 midl_user_allocate midl_user_free min_is module ms_union \
1163 ncacn_at_dsp ncacn_dnet_nsp ncacn_http ncacn_ip_tcp \
1164 ncacn_nb_ipx ncacn_nb_nb ncacn_nb_tcp ncacn_np \
1165 ncacn_spx ncacn_vns_spp ncadg_ip_udp ncadg_ipx ncadg_mq \
1166 ncalrpc nocode nonbrowsable noncreatable nonextensible notify \
1167 object odl oleautomation optimize optional out out_of_line \
1168 pipe pointer_default pragma properties propget propput propputref \
1169 ptr public \
1170 range readonly ref represent_as requestedit restricted retval \
1171 shape short signed size_is small source strict_context_handle \
1172 string struct switch switch_is switch_type \
1173 transmit_as typedef \
1174 uidefault union unique unsigned user_marshal usesgetlasterror uuid \
1175 v1_enum vararg version void wchar_t wire_marshal").GetBuffer()));
1176 SetupCppLexer();
1178 if (wcscmp(line, L"java") == 0)
1180 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1181 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(L"abstract assert boolean break byte case catch char class \
1182 const continue default do double else extends final finally float for future \
1183 generic goto if implements import inner instanceof int interface long \
1184 native new null outer package private protected public rest \
1185 return short static super switch synchronized this throw throws \
1186 transient try var void volatile while").GetBuffer()));
1187 SetupCppLexer();
1189 if (wcscmp(line, L"js") == 0)
1191 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1192 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(L"abstract boolean break byte case catch char class \
1193 const continue debugger default delete do double else enum export extends \
1194 final finally float for function goto if implements import in instanceof \
1195 int interface long native new package private protected public \
1196 return short static super switch synchronized this throw throws \
1197 transient try typeof var void volatile while with").GetBuffer()));
1198 SetupCppLexer();
1200 if ((wcscmp(line, L"pas") == 0) ||
1201 (wcscmp(line, L"dpr") == 0) ||
1202 (wcscmp(line, L"pp") == 0))
1204 SendEditor(SCI_SETLEXER, SCLEX_PASCAL);
1205 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(L"and array as begin case class const constructor \
1206 destructor div do downto else end except file finally \
1207 for function goto if implementation in inherited \
1208 interface is mod not object of on or packed \
1209 procedure program property raise record repeat \
1210 set shl shr then threadvar to try type unit \
1211 until uses var while with xor").GetBuffer()));
1212 SetupCppLexer();
1214 if ((wcscmp(line, L"as") == 0) ||
1215 (wcscmp(line, L"asc") == 0) ||
1216 (wcscmp(line, L"jsfl") == 0))
1218 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1219 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(L"add and break case catch class continue default delete do \
1220 dynamic else eq extends false finally for function ge get gt if implements import in \
1221 instanceof interface intrinsic le lt ne new not null or private public return \
1222 set static super switch this throw true try typeof undefined var void while with").GetBuffer()));
1223 SendEditor(SCI_SETKEYWORDS, 1, (LPARAM)(m_TextView.StringForControl(L"Array Arguments Accessibility Boolean Button Camera Color \
1224 ContextMenu ContextMenuItem Date Error Function Key LoadVars LocalConnection Math \
1225 Microphone Mouse MovieClip MovieClipLoader NetConnection NetStream Number Object \
1226 PrintJob Selection SharedObject Sound Stage String StyleSheet System TextField \
1227 TextFormat TextSnapshot Video Void XML XMLNode XMLSocket \
1228 _accProps _focusrect _global _highquality _parent _quality _root _soundbuftime \
1229 arguments asfunction call capabilities chr clearInterval duplicateMovieClip \
1230 escape eval fscommand getProperty getTimer getURL getVersion gotoAndPlay gotoAndStop \
1231 ifFrameLoaded Infinity -Infinity int isFinite isNaN length loadMovie loadMovieNum \
1232 loadVariables loadVariablesNum maxscroll mbchr mblength mbord mbsubstring MMExecute \
1233 NaN newline nextFrame nextScene on onClipEvent onUpdate ord parseFloat parseInt play \
1234 prevFrame prevScene print printAsBitmap printAsBitmapNum printNum random removeMovieClip \
1235 scroll set setInterval setProperty startDrag stop stopAllSounds stopDrag substring \
1236 targetPath tellTarget toggleHighQuality trace unescape unloadMovie unLoadMovieNum updateAfterEvent").GetBuffer()));
1237 SetupCppLexer();
1239 if ((wcscmp(line, L"html") == 0) ||
1240 (wcscmp(line, L"htm") == 0) ||
1241 (wcscmp(line, L"shtml") == 0) ||
1242 (wcscmp(line, L"htt") == 0) ||
1243 (wcscmp(line, L"xml") == 0) ||
1244 (wcscmp(line, L"asp") == 0) ||
1245 (wcscmp(line, L"xsl") == 0) ||
1246 (wcscmp(line, L"php") == 0) ||
1247 (wcscmp(line, L"xhtml") == 0) ||
1248 (wcscmp(line, L"phtml") == 0) ||
1249 (wcscmp(line, L"cfm") == 0) ||
1250 (wcscmp(line, L"tpl") == 0) ||
1251 (wcscmp(line, L"dtd") == 0) ||
1252 (wcscmp(line, L"hta") == 0) ||
1253 (wcscmp(line, L"htd") == 0) ||
1254 (wcscmp(line, L"wxs") == 0))
1256 SendEditor(SCI_SETLEXER, SCLEX_HTML);
1257 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(L"a abbr acronym address applet area b base basefont \
1258 bdo big blockquote body br button caption center \
1259 cite code col colgroup dd del dfn dir div dl dt em \
1260 fieldset font form frame frameset h1 h2 h3 h4 h5 h6 \
1261 head hr html i iframe img input ins isindex kbd label \
1262 legend li link map menu meta noframes noscript \
1263 object ol optgroup option p param pre q s samp \
1264 script select small span strike strong style sub sup \
1265 table tbody td textarea tfoot th thead title tr tt u ul \
1266 var xml xmlns abbr accept-charset accept accesskey action align alink \
1267 alt archive axis background bgcolor border \
1268 cellpadding cellspacing char charoff charset checked cite \
1269 class classid clear codebase codetype color cols colspan \
1270 compact content coords \
1271 data datafld dataformatas datapagesize datasrc datetime \
1272 declare defer dir disabled enctype event \
1273 face for frame frameborder \
1274 headers height href hreflang hspace http-equiv \
1275 id ismap label lang language leftmargin link longdesc \
1276 marginwidth marginheight maxlength media method multiple \
1277 name nohref noresize noshade nowrap \
1278 object onblur onchange onclick ondblclick onfocus \
1279 onkeydown onkeypress onkeyup onload onmousedown \
1280 onmousemove onmouseover onmouseout onmouseup \
1281 onreset onselect onsubmit onunload \
1282 profile prompt readonly rel rev rows rowspan rules \
1283 scheme scope selected shape size span src standby start style \
1284 summary tabindex target text title topmargin type usemap \
1285 valign value valuetype version vlink vspace width \
1286 text password checkbox radio submit reset \
1287 file hidden image").GetBuffer()));
1288 SendEditor(SCI_SETKEYWORDS, 1, (LPARAM)(m_TextView.StringForControl(L"assign audio block break catch choice clear disconnect else elseif \
1289 emphasis enumerate error exit field filled form goto grammar help \
1290 if initial link log menu meta noinput nomatch object option p paragraph \
1291 param phoneme prompt property prosody record reprompt return s say-as \
1292 script sentence subdialog submit throw transfer value var voice vxml").GetBuffer()));
1293 SendEditor(SCI_SETKEYWORDS, 2, (LPARAM)(m_TextView.StringForControl(L"accept age alphabet anchor application base beep bridge category charset \
1294 classid cond connecttimeout content contour count dest destexpr dtmf dtmfterm \
1295 duration enctype event eventexpr expr expritem fetchtimeout finalsilence \
1296 gender http-equiv id level maxage maxstale maxtime message messageexpr \
1297 method mime modal mode name namelist next nextitem ph pitch range rate \
1298 scope size sizeexpr skiplist slot src srcexpr sub time timeexpr timeout \
1299 transferaudio type value variant version volume xml:lang").GetBuffer()));
1300 SendEditor(SCI_SETKEYWORDS, 3, (LPARAM)(m_TextView.StringForControl(L"and assert break class continue def del elif \
1301 else except exec finally for from global if import in is lambda None \
1302 not or pass print raise return try while yield").GetBuffer()));
1303 SendEditor(SCI_SETKEYWORDS, 4, (LPARAM)(m_TextView.StringForControl(L"and argv as argc break case cfunction class continue declare default do \
1304 die echo else elseif empty enddeclare endfor endforeach endif endswitch \
1305 endwhile e_all e_parse e_error e_warning eval exit extends false for \
1306 foreach function global http_cookie_vars http_get_vars http_post_vars \
1307 http_post_files http_env_vars http_server_vars if include include_once \
1308 list new not null old_function or parent php_os php_self php_version \
1309 print require require_once return static switch stdclass this true var \
1310 xor virtual while __file__ __line__ __sleep __wakeup").GetBuffer()));
1312 SetAStyle(SCE_H_TAG, darkBlue);
1313 SetAStyle(SCE_H_TAGUNKNOWN, red);
1314 SetAStyle(SCE_H_ATTRIBUTE, darkBlue);
1315 SetAStyle(SCE_H_ATTRIBUTEUNKNOWN, red);
1316 SetAStyle(SCE_H_NUMBER, RGB(0x80,0,0x80));
1317 SetAStyle(SCE_H_DOUBLESTRING, RGB(0,0x80,0));
1318 SetAStyle(SCE_H_SINGLESTRING, RGB(0,0x80,0));
1319 SetAStyle(SCE_H_OTHER, RGB(0x80,0,0x80));
1320 SetAStyle(SCE_H_COMMENT, RGB(0x80,0x80,0));
1321 SetAStyle(SCE_H_ENTITY, RGB(0x80,0,0x80));
1323 SetAStyle(SCE_H_TAGEND, darkBlue);
1324 SetAStyle(SCE_H_XMLSTART, darkBlue); // <?
1325 SetAStyle(SCE_H_QUESTION, darkBlue); // <?
1326 SetAStyle(SCE_H_XMLEND, darkBlue); // ?>
1327 SetAStyle(SCE_H_SCRIPT, darkBlue); // <script
1328 SetAStyle(SCE_H_ASP, RGB(0x4F, 0x4F, 0), RGB(0xFF, 0xFF, 0)); // <% ... %>
1329 SetAStyle(SCE_H_ASPAT, RGB(0x4F, 0x4F, 0), RGB(0xFF, 0xFF, 0)); // <%@ ... %>
1331 SetAStyle(SCE_HB_DEFAULT, black);
1332 SetAStyle(SCE_HB_COMMENTLINE, darkGreen);
1333 SetAStyle(SCE_HB_NUMBER, RGB(0,0x80,0x80));
1334 SetAStyle(SCE_HB_WORD, darkBlue);
1335 SendEditor(SCI_STYLESETBOLD, SCE_HB_WORD, 1);
1336 SetAStyle(SCE_HB_STRING, RGB(0x80,0,0x80));
1337 SetAStyle(SCE_HB_IDENTIFIER, black);
1339 // This light blue is found in the windows system palette so is safe to use even in 256 colour modes.
1340 // Show the whole section of VBScript with light blue background
1341 for (int bstyle = SCE_HB_DEFAULT; bstyle <= SCE_HB_STRINGEOL; ++bstyle) {
1342 SendEditor(SCI_STYLESETFONT, bstyle,
1343 reinterpret_cast<LPARAM>(m_TextView.StringForControl(L"Lucida Console").GetBuffer()));
1344 SendEditor(SCI_STYLESETBACK, bstyle, lightBlue);
1345 // This call extends the backround colour of the last style on the line to the edge of the window
1346 SendEditor(SCI_STYLESETEOLFILLED, bstyle, 1);
1348 SendEditor(SCI_STYLESETBACK, SCE_HB_STRINGEOL, RGB(0x7F,0x7F,0xFF));
1349 SendEditor(SCI_STYLESETFONT, SCE_HB_COMMENTLINE,
1350 reinterpret_cast<LPARAM>(m_TextView.StringForControl(L"Lucida Console").GetBuffer()));
1352 SetAStyle(SCE_HBA_DEFAULT, black);
1353 SetAStyle(SCE_HBA_COMMENTLINE, darkGreen);
1354 SetAStyle(SCE_HBA_NUMBER, RGB(0,0x80,0x80));
1355 SetAStyle(SCE_HBA_WORD, darkBlue);
1356 SendEditor(SCI_STYLESETBOLD, SCE_HBA_WORD, 1);
1357 SetAStyle(SCE_HBA_STRING, RGB(0x80,0,0x80));
1358 SetAStyle(SCE_HBA_IDENTIFIER, black);
1360 // Show the whole section of ASP VBScript with bright yellow background
1361 for (int bastyle = SCE_HBA_DEFAULT; bastyle <= SCE_HBA_STRINGEOL; ++bastyle) {
1362 SendEditor(SCI_STYLESETFONT, bastyle,
1363 reinterpret_cast<LPARAM>(m_TextView.StringForControl(L"Lucida Console").GetBuffer()));
1364 SendEditor(SCI_STYLESETBACK, bastyle, RGB(0xFF, 0xFF, 0));
1365 // This call extends the backround colour of the last style on the line to the edge of the window
1366 SendEditor(SCI_STYLESETEOLFILLED, bastyle, 1);
1368 SendEditor(SCI_STYLESETBACK, SCE_HBA_STRINGEOL, RGB(0xCF,0xCF,0x7F));
1369 SendEditor(SCI_STYLESETFONT, SCE_HBA_COMMENTLINE,
1370 reinterpret_cast<LPARAM>(m_TextView.StringForControl(L"Lucida Console").GetBuffer()));
1372 // If there is no need to support embedded Javascript, the following code can be dropped.
1373 // Javascript will still be correctly processed but will be displayed in just the default style.
1375 SetAStyle(SCE_HJ_START, RGB(0x80,0x80,0));
1376 SetAStyle(SCE_HJ_DEFAULT, black);
1377 SetAStyle(SCE_HJ_COMMENT, darkGreen);
1378 SetAStyle(SCE_HJ_COMMENTLINE, darkGreen);
1379 SetAStyle(SCE_HJ_COMMENTDOC, darkGreen);
1380 SetAStyle(SCE_HJ_NUMBER, RGB(0,0x80,0x80));
1381 SetAStyle(SCE_HJ_WORD, black);
1382 SetAStyle(SCE_HJ_KEYWORD, darkBlue);
1383 SetAStyle(SCE_HJ_DOUBLESTRING, RGB(0x80,0,0x80));
1384 SetAStyle(SCE_HJ_SINGLESTRING, RGB(0x80,0,0x80));
1385 SetAStyle(SCE_HJ_SYMBOLS, black);
1387 SetAStyle(SCE_HJA_START, RGB(0x80,0x80,0));
1388 SetAStyle(SCE_HJA_DEFAULT, black);
1389 SetAStyle(SCE_HJA_COMMENT, darkGreen);
1390 SetAStyle(SCE_HJA_COMMENTLINE, darkGreen);
1391 SetAStyle(SCE_HJA_COMMENTDOC, darkGreen);
1392 SetAStyle(SCE_HJA_NUMBER, RGB(0,0x80,0x80));
1393 SetAStyle(SCE_HJA_WORD, black);
1394 SetAStyle(SCE_HJA_KEYWORD, darkBlue);
1395 SetAStyle(SCE_HJA_DOUBLESTRING, RGB(0x80,0,0x80));
1396 SetAStyle(SCE_HJA_SINGLESTRING, RGB(0x80,0,0x80));
1397 SetAStyle(SCE_HJA_SYMBOLS, black);
1399 SetAStyle(SCE_HPHP_DEFAULT, black);
1400 SetAStyle(SCE_HPHP_HSTRING, RGB(0x80,0,0x80));
1401 SetAStyle(SCE_HPHP_SIMPLESTRING, RGB(0x80,0,0x80));
1402 SetAStyle(SCE_HPHP_WORD, darkBlue);
1403 SetAStyle(SCE_HPHP_NUMBER, RGB(0,0x80,0x80));
1404 SetAStyle(SCE_HPHP_VARIABLE, red);
1405 SetAStyle(SCE_HPHP_HSTRING_VARIABLE, red);
1406 SetAStyle(SCE_HPHP_COMPLEX_VARIABLE, red);
1407 SetAStyle(SCE_HPHP_COMMENT, darkGreen);
1408 SetAStyle(SCE_HPHP_COMMENTLINE, darkGreen);
1409 SetAStyle(SCE_HPHP_OPERATOR, darkBlue);
1411 // Show the whole section of Javascript with off white background
1412 for (int jstyle = SCE_HJ_DEFAULT; jstyle <= SCE_HJ_SYMBOLS; ++jstyle) {
1413 SendEditor(SCI_STYLESETFONT, jstyle,
1414 reinterpret_cast<LPARAM>(m_TextView.StringForControl(L"Lucida Console").GetBuffer()));
1415 SendEditor(SCI_STYLESETBACK, jstyle, offWhite);
1416 SendEditor(SCI_STYLESETEOLFILLED, jstyle, 1);
1418 SendEditor(SCI_STYLESETBACK, SCE_HJ_STRINGEOL, RGB(0xDF, 0xDF, 0x7F));
1419 SendEditor(SCI_STYLESETEOLFILLED, SCE_HJ_STRINGEOL, 1);
1421 // Show the whole section of Javascript with brown background
1422 for (int jastyle = SCE_HJA_DEFAULT; jastyle <= SCE_HJA_SYMBOLS; ++jastyle) {
1423 SendEditor(SCI_STYLESETFONT, jastyle,
1424 reinterpret_cast<LPARAM>(m_TextView.StringForControl(L"Lucida Console").GetBuffer()));
1425 SendEditor(SCI_STYLESETBACK, jastyle, RGB(0xDF, 0xDF, 0x7F));
1426 SendEditor(SCI_STYLESETEOLFILLED, jastyle, 1);
1428 SendEditor(SCI_STYLESETBACK, SCE_HJA_STRINGEOL, RGB(0x0,0xAF,0x5F));
1429 SendEditor(SCI_STYLESETEOLFILLED, SCE_HJA_STRINGEOL, 1);
1432 else
1434 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1435 SetupCppLexer();
1437 SendEditor(SCI_COLOURISE, 0, -1);
1440 void CTortoiseGitBlameView::SetupCppLexer()
1442 SetAStyle(SCE_C_DEFAULT, RGB(0, 0, 0));
1443 SetAStyle(SCE_C_COMMENT, RGB(0, 0x80, 0));
1444 SetAStyle(SCE_C_COMMENTLINE, RGB(0, 0x80, 0));
1445 SetAStyle(SCE_C_COMMENTDOC, RGB(0, 0x80, 0));
1446 SetAStyle(SCE_C_COMMENTLINEDOC, RGB(0, 0x80, 0));
1447 SetAStyle(SCE_C_COMMENTDOCKEYWORD, RGB(0, 0x80, 0));
1448 SetAStyle(SCE_C_COMMENTDOCKEYWORDERROR, RGB(0, 0x80, 0));
1449 SetAStyle(SCE_C_NUMBER, RGB(0, 0x80, 0x80));
1450 SetAStyle(SCE_C_WORD, RGB(0, 0, 0x80));
1451 SendEditor(SCE_C_WORD, 1);
1452 SetAStyle(SCE_C_STRING, RGB(0x80, 0, 0x80));
1453 SetAStyle(SCE_C_IDENTIFIER, RGB(0, 0, 0));
1454 SetAStyle(SCE_C_PREPROCESSOR, RGB(0x80, 0, 0));
1455 SetAStyle(SCE_C_OPERATOR, RGB(0x80, 0x80, 0));
1456 SendEditor(SCI_SETPROPERTY, (WPARAM)"lexer.cpp.track.preprocessor", (LPARAM)"0");
1459 int CTortoiseGitBlameView::GetEncode(unsigned char *buff, int size, int *bomoffset)
1461 CFileTextLines textlines;
1462 CFileTextLines::UnicodeType type = textlines.CheckUnicodeType(buff, size);
1464 if(type == CFileTextLines::UTF8BOM)
1466 *bomoffset = 3;
1467 return CP_UTF8;
1469 if(type == CFileTextLines::UTF8)
1470 return CP_UTF8;
1472 if(type == CFileTextLines::UTF16_LE)
1473 return 1200;
1474 if (type == CFileTextLines::UTF16_LEBOM)
1476 *bomoffset = 2;
1477 return 1200;
1480 if(type == CFileTextLines::UTF16_BE)
1481 return 1201;
1482 if (type == CFileTextLines::UTF16_BEBOM)
1484 *bomoffset = 2;
1485 return 1201;
1488 return GetACP();
1491 void CTortoiseGitBlameView::ParseBlame()
1493 m_data.ParseBlameOutput(GetDocument()->m_BlameData, GetLogData()->m_pLogCache->m_HashMap, m_DateFormat, m_bRelativeTimes);
1494 CString filename = GetDocument()->m_GitPath.GetGitPathString();
1495 m_bBlameOutputContainsOtherFilenames = m_data.ContainsOnlyFilename(filename) ? FALSE : TRUE;
1498 void CTortoiseGitBlameView::MapLineToLogIndex()
1500 std::vector<int> lineToLogIndex;
1503 size_t numberOfLines = m_data.GetNumberOfLines();
1504 lineToLogIndex.reserve(numberOfLines);
1505 size_t logSize = this->GetLogData()->size();
1506 for (size_t j = 0; j < numberOfLines; ++j)
1508 CGitHash& hash = m_data.GetHash(j);
1510 int index = -2;
1511 for (size_t i = 0; i < logSize; ++i)
1513 if (hash == (*GetLogData())[i])
1515 index = (int)i;
1516 break;
1519 lineToLogIndex.push_back(index);
1521 this->m_lineToLogIndex.swap(lineToLogIndex);
1524 void CTortoiseGitBlameView::UpdateInfo(int Encode)
1526 CreateFont();
1528 InitialiseEditor();
1529 SendEditor(SCI_SETREADONLY, FALSE);
1530 SendEditor(SCI_CLEARALL);
1531 SendEditor(EM_EMPTYUNDOBUFFER);
1532 SendEditor(SCI_SETSAVEPOINT);
1533 SendEditor(SCI_CANCEL);
1534 SendEditor(SCI_SETUNDOCOLLECTION, 0);
1536 SendEditor(SCI_SETCODEPAGE, SC_CP_UTF8);
1538 int encoding = m_data.UpdateEncoding(Encode);
1540 auto numberOfLines = (int)m_data.GetNumberOfLines();
1541 if (numberOfLines > 0)
1543 CStringA text;
1544 for (int i = 0; i < numberOfLines; ++i)
1546 text += m_data.GetUtf8Line(i);
1547 text += '\n';
1549 text.TrimRight("\r\n");
1550 SendEditor(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)text);
1554 UINT nID;
1555 UINT nStyle;
1556 int cxWidth;
1557 int nIndex = ((CMainFrame *)::AfxGetApp()->GetMainWnd())->m_wndStatusBar.CommandToIndex(ID_INDICATOR_ENCODING);
1558 ((CMainFrame *)::AfxGetApp()->GetMainWnd())->m_wndStatusBar.GetPaneInfo(nIndex, nID, nStyle, cxWidth);
1559 CString sBarText;
1560 for (int i = 0; i < _countof(encodings); ++i)
1562 if (encodings[i].id == encoding)
1564 sBarText = CString(encodings[i].name);
1565 break;
1568 //calculate the width of the text
1569 CDC * pDC = ((CMainFrame *)::AfxGetApp()->GetMainWnd())->m_wndStatusBar.GetDC();
1570 if (pDC)
1572 CSize size = pDC->GetTextExtent(sBarText);
1573 ((CMainFrame *)::AfxGetApp()->GetMainWnd())->m_wndStatusBar.SetPaneInfo(nIndex, nID, nStyle, size.cx+2);
1574 ReleaseDC(pDC);
1576 ((CMainFrame *)::AfxGetApp()->GetMainWnd())->m_wndStatusBar.SetPaneText(nIndex, sBarText);
1579 #ifdef USE_TEMPFILENAME
1580 delete m_Buffer;
1581 m_Buffer = nullptr;
1583 CFile file;
1584 file.Open(this->GetDocument()->m_TempFileName,CFile::modeRead);
1586 m_Buffer = new char[file.GetLength()+4];
1587 m_Buffer[file.GetLength()] =0;
1588 m_Buffer[file.GetLength()+1] =0;
1589 m_Buffer[file.GetLength()+2] =0;
1590 m_Buffer[file.GetLength()+3] =0;
1592 file.Read(m_Buffer, file.GetLength());
1594 int bomoffset =0;
1595 int encoding = GetEncode( (unsigned char *)m_Buffer, file.GetLength(), &bomoffset);
1597 file.Close();
1598 //SendEditor(SCI_SETCODEPAGE, encoding);
1600 //SendEditor(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)(m_Buffer + bomoffset));
1601 #endif
1602 SetupLexer(GetDocument()->m_CurrentFileName);
1604 SendEditor(SCI_SETUNDOCOLLECTION, 1);
1605 SendEditor(EM_EMPTYUNDOBUFFER);
1606 SendEditor(SCI_SETSAVEPOINT);
1607 SendEditor(SCI_GOTOPOS, 0);
1608 SendEditor(SCI_SETSCROLLWIDTHTRACKING, TRUE);
1609 SendEditor(SCI_SETREADONLY, TRUE);
1611 GetBlameWidth();
1612 CRect rect;
1613 this->GetClientRect(rect);
1614 //this->m_TextView.GetWindowRect(rect);
1615 //this->m_TextView.ScreenToClient(rect);
1616 rect.left=this->m_blamewidth;
1617 this->m_TextView.MoveWindow(rect);
1619 this->Invalidate();
1622 CString CTortoiseGitBlameView::ResolveCommitFile(int line)
1624 return ResolveCommitFile(m_data.GetFilename(line));
1627 CString CTortoiseGitBlameView::ResolveCommitFile(const CString& path)
1629 if (path.IsEmpty())
1631 return ((CMainFrame*)::AfxGetApp()->GetMainWnd())->GetActiveView()->GetDocument()->GetPathName();
1633 else
1635 return g_Git.CombinePath(path);
1639 COLORREF CTortoiseGitBlameView::GetLineColor(size_t line)
1641 if (m_colorage && line < m_lineToLogIndex.size())
1643 int logIndex = m_lineToLogIndex[line];
1644 if (logIndex >= 0)
1646 int slider = (int)((GetLogData()->size() - logIndex) * 100 / (GetLogData()->size() + 1));
1647 return InterColor(DWORD(m_regOldLinesColor), DWORD(m_regNewLinesColor), slider);
1650 return m_windowcolor;
1653 CGitBlameLogList * CTortoiseGitBlameView::GetLogList()
1655 return &(GetDocument()->GetMainFrame()->m_wndOutput.m_LogList);
1659 CLogDataVector * CTortoiseGitBlameView::GetLogData()
1661 return &(GetDocument()->GetMainFrame()->m_wndOutput.m_LogList.m_logEntries);
1664 void CTortoiseGitBlameView::OnSciPainted(NMHDR *,LRESULT *)
1666 this->Invalidate();
1669 void CTortoiseGitBlameView::OnLButtonDown(UINT nFlags,CPoint point)
1671 int line = GetLineUnderCursor(point);
1672 if ((size_t)line < m_data.GetNumberOfLines())
1674 SetSelectedLine(line);
1675 if (m_data.GetHash(line) != m_SelectedHash)
1677 m_SelectedHash = m_data.GetHash(line);
1679 int logIndex = m_lineToLogIndex[line];
1680 if (logIndex >= 0)
1682 this->GetLogList()->SetItemState(logIndex, LVIS_SELECTED, LVIS_SELECTED);
1683 this->GetLogList()->EnsureVisible(logIndex, FALSE);
1685 else
1687 GitRevLoglist* pRev = m_data.GetRev(line, GetLogData()->m_pLogCache->m_HashMap);
1688 this->GetDocument()->GetMainFrame()->m_wndProperties.UpdateProperties(pRev);
1691 else
1693 m_SelectedHash.Empty();
1695 this->Invalidate();
1696 this->m_TextView.Invalidate();
1699 else
1701 SetSelectedLine(-1);
1704 CView::OnLButtonDown(nFlags,point);
1707 void CTortoiseGitBlameView::OnSciGetBkColor(NMHDR* hdr, LRESULT* /*result*/)
1709 SCNotification *notification=reinterpret_cast<SCNotification *>(hdr);
1711 if (notification->line < (Sci_Position)m_data.GetNumberOfLines())
1713 if (m_data.GetHash(notification->line) == this->m_SelectedHash)
1714 notification->lParam = m_selectedauthorcolor;
1715 else
1716 notification->lParam = GetLineColor(notification->line);
1720 void CTortoiseGitBlameView::FocusOn(GitRevLoglist* pRev)
1722 this->GetDocument()->GetMainFrame()->m_wndProperties.UpdateProperties(pRev);
1724 this->Invalidate();
1726 if (m_SelectedHash != pRev->m_CommitHash) {
1727 m_SelectedHash = pRev->m_CommitHash;
1728 int line = m_data.FindFirstLine(m_SelectedHash, 0);
1729 if (line >= 0)
1731 GotoLine(line + 1);
1732 m_TextView.Invalidate();
1733 return;
1735 SendEditor(SCI_SETSEL, INT_MAX, -1);
1739 void CTortoiseGitBlameView::OnMouseHover(UINT /*nFlags*/, CPoint point)
1741 int line = GetLineUnderCursor(point);
1742 if (m_data.IsValidLine(line))
1744 if (line != m_MouseLine)
1746 m_MouseLine = line;
1747 GitRev *pRev = nullptr;
1748 int logIndex = m_lineToLogIndex[line];
1749 if (logIndex >= 0)
1750 pRev = &GetLogData()->GetGitRevAt(logIndex);
1751 else
1752 pRev = m_data.GetRev(line, GetLogData()->m_pLogCache->m_HashMap);
1754 if (!pRev)
1755 return;
1757 CString body = pRev->GetBody();
1758 int maxLine = 15;
1759 int iline = 0;
1760 int pos = 0;
1761 while (iline++ < maxLine)
1763 int pos2 = body.Find(L'\n', pos);
1764 if (pos2 < 0)
1765 break;
1766 int lineLength = pos2 - pos - 1;
1767 pos = pos2 + 1;
1768 iline += lineLength / 70;
1771 CString filename;
1772 if ((m_bShowCompleteLog && m_bFollowRenames && !m_bOnlyFirstParent) || !BlameIsLimitedToOneFilename(m_dwDetectMovedOrCopiedLines) || m_bBlameOutputContainsOtherFilenames)
1773 filename.Format(L"%s: %s\n", (LPCTSTR)m_sFileName, (LPCTSTR)m_data.GetFilename(line));
1775 CString str;
1776 str.Format(L"%s: %s\n%s%s: %s <%s>\n%s: %s\n%s:\n%s\n%s", (LPCTSTR)m_sRev, (LPCTSTR)pRev->m_CommitHash.ToString(), (LPCTSTR)filename,
1777 (LPCTSTR)m_sAuthor, (LPCTSTR)pRev->GetAuthorName(), (LPCTSTR)pRev->GetAuthorEmail(),
1778 (LPCTSTR)m_sDate, (LPCTSTR)CLoglistUtils::FormatDateAndTime(pRev->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
1779 (LPCTSTR)m_sMessage, (LPCTSTR)pRev->GetSubject(),
1780 iline <= maxLine ? (LPCTSTR)body : (body.Left(pos) + L"\n...................."));
1782 m_ToolTip.Pop();
1783 m_ToolTip.AddTool(this, str);
1785 Invalidate();
1790 void CTortoiseGitBlameView::OnMouseMove(UINT /*nFlags*/, CPoint /*point*/)
1792 TRACKMOUSEEVENT tme;
1793 tme.cbSize=sizeof(TRACKMOUSEEVENT);
1794 tme.dwFlags=TME_HOVER|TME_LEAVE;
1795 tme.hwndTrack=this->m_hWnd;
1796 tme.dwHoverTime=1;
1797 TrackMouseEvent(&tme);
1798 Invalidate();
1801 void CTortoiseGitBlameView::OnMouseLeave()
1803 if (m_MouseLine == -1)
1804 return;
1806 m_MouseLine = -1;
1807 Invalidate();
1810 BOOL CTortoiseGitBlameView::PreTranslateMessage(MSG* pMsg)
1812 if (m_ToolTip.GetSafeHwnd())
1813 m_ToolTip.RelayEvent(pMsg);
1814 return CView::PreTranslateMessage(pMsg);
1817 void CTortoiseGitBlameView::OnEditFind()
1819 if (m_pFindDialog)
1820 return;
1822 m_pFindDialog=new CFindReplaceDialog();
1824 CString oneline = m_sFindText;
1825 if (m_TextView.Call(SCI_GETSELECTIONSTART) != m_TextView.Call(SCI_GETSELECTIONEND))
1827 LRESULT bufsize = m_TextView.Call(SCI_GETSELECTIONEND) - m_TextView.Call(SCI_GETSELECTIONSTART);
1828 auto linebuf = std::make_unique<char[]>(bufsize + 1);
1829 SecureZeroMemory(linebuf.get(), bufsize + 1);
1830 SendEditor(SCI_GETSELTEXT, 0, (LPARAM)linebuf.get());
1831 oneline = m_TextView.StringFromControl(linebuf.get());
1834 DWORD flags = FR_DOWN | FR_HIDEWHOLEWORD;
1835 if (theApp.GetInt(L"FindMatchCase"))
1836 flags |= FR_MATCHCASE;
1838 m_pFindDialog->Create(TRUE, oneline, nullptr, flags, this);
1841 void CTortoiseGitBlameView::OnEditGoto()
1843 CEditGotoDlg dlg;
1844 if(dlg.DoModal()==IDOK)
1846 this->GotoLine(dlg.m_LineNumber);
1850 LRESULT CTortoiseGitBlameView::OnFindDialogMessage(WPARAM /*wParam*/, LPARAM /*lParam*/)
1852 ASSERT(m_pFindDialog);
1854 // If the FR_DIALOGTERM flag is set,
1855 // invalidate the handle identifying the dialog box.
1856 if (m_pFindDialog->IsTerminating())
1858 m_pFindDialog = nullptr;
1859 return 0;
1862 // If the FR_FINDNEXT flag is set,
1863 // call the application-defined search routine
1864 // to search for the requested string.
1865 if(m_pFindDialog->FindNext())
1867 m_bMatchCase = !!(m_pFindDialog->MatchCase());
1868 m_sFindText = m_pFindDialog->GetFindString();
1870 theApp.WriteInt(L"FindMatchCase", m_bMatchCase ? 1 : 0);
1871 theApp.WriteString(L"FindString", m_sFindText);
1873 DoSearch(m_pFindDialog->SearchDown() ? CTortoiseGitBlameData::SearchNext : CTortoiseGitBlameData::SearchPrevious);
1876 return 0;
1879 void CTortoiseGitBlameView::OnViewNext()
1881 int startline = (int)SendEditor(SCI_GETFIRSTVISIBLELINE);
1882 int line = m_data.FindNextLine(this->m_SelectedHash, (int)SendEditor(SCI_GETFIRSTVISIBLELINE), false);
1883 if(line >= 0)
1884 SendEditor(SCI_LINESCROLL, 0, line - startline - 2);
1886 void CTortoiseGitBlameView::OnViewPrev()
1888 int startline = (int)SendEditor(SCI_GETFIRSTVISIBLELINE);
1889 int line = m_data.FindNextLine(this->m_SelectedHash, (int)SendEditor(SCI_GETFIRSTVISIBLELINE), true);
1890 if(line >= 0)
1891 SendEditor(SCI_LINESCROLL, 0, line - startline - 2);
1894 void CTortoiseGitBlameView::OnViewToggleAuthor()
1896 m_bShowAuthor = ! m_bShowAuthor;
1898 theApp.WriteInt(L"ShowAuthor", m_bShowAuthor);
1900 CRect rect;
1901 this->GetClientRect(&rect);
1902 rect.left=GetBlameWidth();
1904 m_TextView.MoveWindow(&rect);
1907 void CTortoiseGitBlameView::OnUpdateViewToggleAuthor(CCmdUI *pCmdUI)
1909 pCmdUI->SetCheck(m_bShowAuthor);
1912 void CTortoiseGitBlameView::OnViewToggleDate()
1914 m_bShowDate = ! m_bShowDate;
1916 theApp.WriteInt(L"ShowDate", m_bShowDate);
1918 CRect rect;
1919 this->GetClientRect(&rect);
1920 rect.left=GetBlameWidth();
1922 m_TextView.MoveWindow(&rect);
1925 void CTortoiseGitBlameView::OnUpdateViewToggleDate(CCmdUI *pCmdUI)
1927 pCmdUI->SetCheck(m_bShowDate);
1930 void CTortoiseGitBlameView::OnViewToggleShowFilename()
1932 m_bShowFilename = ! m_bShowFilename;
1934 theApp.WriteInt(L"ShowFilename", m_bShowFilename);
1936 CRect rect;
1937 this->GetClientRect(&rect);
1938 rect.left = GetBlameWidth();
1940 m_TextView.MoveWindow(&rect);
1943 void CTortoiseGitBlameView::OnUpdateViewToggleShowFilename(CCmdUI *pCmdUI)
1945 pCmdUI->SetCheck(m_bShowFilename);
1948 void CTortoiseGitBlameView::OnViewToggleShowOriginalLineNumber()
1950 m_bShowOriginalLineNumber = ! m_bShowOriginalLineNumber;
1952 theApp.WriteInt(L"ShowOriginalLineNumber", m_bShowOriginalLineNumber);
1954 CRect rect;
1955 this->GetClientRect(&rect);
1956 rect.left = GetBlameWidth();
1958 m_TextView.MoveWindow(&rect);
1961 void CTortoiseGitBlameView::OnUpdateViewToggleShowOriginalLineNumber(CCmdUI *pCmdUI)
1963 pCmdUI->SetCheck(m_bShowOriginalLineNumber);
1966 void CTortoiseGitBlameView::OnViewDetectMovedOrCopiedLines(DWORD dwDetectMovedOrCopiedLines)
1968 m_dwDetectMovedOrCopiedLines = dwDetectMovedOrCopiedLines;
1970 theApp.DoWaitCursor(1);
1972 theApp.WriteInt(L"DetectMovedOrCopiedLines", m_dwDetectMovedOrCopiedLines);
1974 auto document = static_cast<CTortoiseGitBlameDoc*>(m_pDocument);
1975 if (!document->m_CurrentFileName.IsEmpty())
1977 document->m_lLine = (int)SendEditor(SCI_GETFIRSTVISIBLELINE) + 1;
1978 theApp.m_pDocManager->OnFileNew();
1979 document->OnOpenDocument(document->m_CurrentFileName, document->m_Rev);
1981 theApp.DoWaitCursor(-1);
1984 void CTortoiseGitBlameView::OnViewDetectMovedOrCopiedLinesToggleDisabled()
1986 OnViewDetectMovedOrCopiedLines(BLAME_DETECT_MOVED_OR_COPIED_LINES_DISABLED);
1989 void CTortoiseGitBlameView::OnUpdateViewDetectMovedOrCopiedLinesToggleDisabled(CCmdUI *pCmdUI)
1991 pCmdUI->SetRadio(m_dwDetectMovedOrCopiedLines == BLAME_DETECT_MOVED_OR_COPIED_LINES_DISABLED);
1994 void CTortoiseGitBlameView::OnViewDetectMovedOrCopiedLinesToggleWithinFile()
1996 OnViewDetectMovedOrCopiedLines(BLAME_DETECT_MOVED_OR_COPIED_LINES_WITHIN_FILE);
1999 void CTortoiseGitBlameView::OnUpdateViewDetectMovedOrCopiedLinesToggleWithinFile(CCmdUI *pCmdUI)
2001 pCmdUI->SetRadio(m_dwDetectMovedOrCopiedLines == BLAME_DETECT_MOVED_OR_COPIED_LINES_WITHIN_FILE);
2004 void CTortoiseGitBlameView::OnViewDetectMovedOrCopiedLinesToggleFromModifiedFiles()
2006 OnViewDetectMovedOrCopiedLines(BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_MODIFIED_FILES);
2009 void CTortoiseGitBlameView::OnUpdateViewDetectMovedOrCopiedLinesToggleFromModifiedFiles(CCmdUI *pCmdUI)
2011 pCmdUI->SetRadio(m_dwDetectMovedOrCopiedLines == BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_MODIFIED_FILES);
2014 void CTortoiseGitBlameView::OnViewDetectMovedOrCopiedLinesToggleFromExistingFilesAtFileCreation()
2016 OnViewDetectMovedOrCopiedLines(BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES_AT_FILE_CREATION);
2019 void CTortoiseGitBlameView::OnUpdateViewDetectMovedOrCopiedLinesToggleFromExistingFilesAtFileCreation(CCmdUI *pCmdUI)
2021 pCmdUI->SetRadio(m_dwDetectMovedOrCopiedLines == BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES_AT_FILE_CREATION);
2024 void CTortoiseGitBlameView::OnViewDetectMovedOrCopiedLinesToggleFromExistingFiles()
2026 OnViewDetectMovedOrCopiedLines(BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES);
2029 void CTortoiseGitBlameView::OnUpdateViewDetectMovedOrCopiedLinesToggleFromExistingFiles(CCmdUI *pCmdUI)
2031 pCmdUI->SetRadio(m_dwDetectMovedOrCopiedLines == BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES);
2034 void CTortoiseGitBlameView::ReloadDocument()
2036 theApp.DoWaitCursor(1);
2037 auto document = static_cast<CTortoiseGitBlameDoc*>(m_pDocument);
2038 if (!document->m_CurrentFileName.IsEmpty())
2040 document->m_lLine = (int)SendEditor(SCI_GETFIRSTVISIBLELINE) + 1;
2041 theApp.m_pDocManager->OnFileNew();
2042 document->OnOpenDocument(document->m_CurrentFileName, document->m_Rev);
2044 theApp.DoWaitCursor(-1);
2047 void CTortoiseGitBlameView::OnViewToggleIgnoreWhitespace()
2049 m_bIgnoreWhitespace = ! m_bIgnoreWhitespace;
2051 theApp.WriteInt(L"IgnoreWhitespace", m_bIgnoreWhitespace ? 1 : 0);
2053 ReloadDocument();
2056 void CTortoiseGitBlameView::OnUpdateViewToggleIgnoreWhitespace(CCmdUI *pCmdUI)
2058 pCmdUI->SetCheck(m_bIgnoreWhitespace);
2061 void CTortoiseGitBlameView::OnViewToggleShowCompleteLog()
2063 m_bShowCompleteLog = ! m_bShowCompleteLog;
2065 theApp.WriteInt(L"ShowCompleteLog", m_bShowCompleteLog ? 1 : 0);
2067 ReloadDocument();
2070 void CTortoiseGitBlameView::OnUpdateViewToggleOnlyFirstParent(CCmdUI* pCmdUI)
2072 pCmdUI->SetCheck(m_bOnlyFirstParent);
2075 void CTortoiseGitBlameView::OnViewToggleOnlyFirstParent()
2077 m_bOnlyFirstParent = !m_bOnlyFirstParent;
2079 theApp.WriteInt(L"OnlyFirstParent", m_bOnlyFirstParent ? 1 : 0);
2081 ReloadDocument();
2084 void CTortoiseGitBlameView::OnUpdateViewToggleShowCompleteLog(CCmdUI *pCmdUI)
2086 pCmdUI->Enable(BlameIsLimitedToOneFilename(m_dwDetectMovedOrCopiedLines) && !m_bOnlyFirstParent);
2087 pCmdUI->SetCheck(m_bShowCompleteLog && BlameIsLimitedToOneFilename(m_dwDetectMovedOrCopiedLines) && !m_bOnlyFirstParent);
2090 void CTortoiseGitBlameView::OnViewToggleFollowRenames()
2092 m_bFollowRenames = ! m_bFollowRenames;
2094 theApp.WriteInt(L"FollowRenames", m_bFollowRenames ? 1 : 0);
2096 ReloadDocument();
2099 void CTortoiseGitBlameView::OnUpdateViewToggleFollowRenames(CCmdUI *pCmdUI)
2101 pCmdUI->Enable(m_bShowCompleteLog && BlameIsLimitedToOneFilename(m_dwDetectMovedOrCopiedLines) && !m_bOnlyFirstParent);
2102 pCmdUI->SetCheck(m_bFollowRenames && m_bShowCompleteLog && BlameIsLimitedToOneFilename(m_dwDetectMovedOrCopiedLines) && !m_bOnlyFirstParent);
2105 void CTortoiseGitBlameView::OnViewToggleColorByAge()
2107 m_colorage = ! m_colorage;
2109 theApp.WriteInt(L"ColorAge", m_colorage);
2111 m_TextView.Invalidate();
2114 void CTortoiseGitBlameView::OnUpdateViewToggleColorByAge(CCmdUI *pCmdUI)
2116 pCmdUI->SetCheck(m_colorage);
2119 void CTortoiseGitBlameView::OnViewToggleLexer()
2121 m_bLexer = !m_bLexer;
2123 theApp.WriteInt(L"EnableLexer", m_bLexer);
2125 InitialiseEditor();
2126 SetupLexer(GetDocument()->m_CurrentFileName);
2127 this->Invalidate();
2130 void CTortoiseGitBlameView::OnUpdateViewToggleLexer(CCmdUI *pCmdUI)
2132 pCmdUI->SetCheck(m_bLexer);
2135 void CTortoiseGitBlameView::OnViewWrapLongLines()
2137 m_bWrapLongLines = !m_bWrapLongLines;
2139 theApp.WriteInt(L"WrapLongLines", m_bWrapLongLines);
2141 if (m_bWrapLongLines)
2142 SendEditor(SCI_SETWRAPMODE, SC_WRAP_WORD);
2143 else
2144 SendEditor(SCI_SETWRAPMODE, SC_WRAP_NONE);
2147 void CTortoiseGitBlameView::OnUpdateViewWrapLongLines(CCmdUI* pCmdUI)
2149 pCmdUI->SetCheck(m_bWrapLongLines);
2152 void CTortoiseGitBlameView::OnUpdateViewCopyToClipboard(CCmdUI *pCmdUI)
2154 CWnd * wnd = GetFocus();
2155 if (wnd == GetLogList())
2156 pCmdUI->Enable(GetLogList()->GetSelectedCount() > 0);
2157 else if (wnd)
2159 if (CString(wnd->GetRuntimeClass()->m_lpszClassName) == L"CMFCPropertyGridCtrl")
2161 CMFCPropertyGridCtrl *grid = (CMFCPropertyGridCtrl *)wnd;
2162 pCmdUI->Enable(grid->GetCurSel() && !grid->GetCurSel()->IsGroup() && !CString(grid->GetCurSel()->GetValue()).IsEmpty());
2164 else
2165 pCmdUI->Enable(m_TextView.Call(SCI_GETSELECTIONSTART) != m_TextView.Call(SCI_GETSELECTIONEND));
2167 else
2168 pCmdUI->Enable(FALSE);
2171 void CTortoiseGitBlameView::OnSysColorChange()
2173 __super::OnSysColorChange();
2174 m_windowcolor = ::GetSysColor(COLOR_WINDOW);
2175 m_textcolor = ::GetSysColor(COLOR_WINDOWTEXT);
2176 m_texthighlightcolor = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
2177 m_mouserevcolor = InterColor(m_windowcolor, m_textcolor, 20);
2178 m_mouseauthorcolor = InterColor(m_windowcolor, m_textcolor, 10);
2179 m_selectedrevcolor = ::GetSysColor(COLOR_HIGHLIGHT);
2180 m_selectedauthorcolor = InterColor(m_selectedrevcolor, m_texthighlightcolor, 35);
2181 InitialiseEditor();
2182 SetupLexer(GetDocument()->m_CurrentFileName);
2185 ULONG CTortoiseGitBlameView::GetGestureStatus(CPoint ptTouch)
2187 int line = GetLineUnderCursor(ptTouch);
2188 if (m_data.IsValidLine(line))
2189 return 0;
2190 return __super::GetGestureStatus(ptTouch);