Adjust for Scintilla 4.0.3 and fix warnings
[TortoiseGit.git] / src / TortoiseGitBlame / TortoiseGitBlameView.cpp
blob0178e4ee7df097d8bcc6fec3e226218ea5744096
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"
43 #ifdef _DEBUG
44 #define new DEBUG_NEW
45 #endif
47 UINT CTortoiseGitBlameView::m_FindDialogMessage;
49 // CTortoiseGitBlameView
50 IMPLEMENT_DYNAMIC(CSciEditBlame,CSciEdit)
52 IMPLEMENT_DYNCREATE(CTortoiseGitBlameView, CView)
54 BEGIN_MESSAGE_MAP(CTortoiseGitBlameView, CView)
55 // Standard printing commands
56 ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)
57 ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
58 ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CTortoiseGitBlameView::OnFilePrintPreview)
59 ON_COMMAND(ID_EDIT_FIND,OnEditFind)
60 ON_COMMAND(ID_EDIT_GOTO,OnEditGoto)
61 ON_COMMAND(ID_EDIT_COPY, CopyToClipboard)
62 ON_UPDATE_COMMAND_UI(ID_EDIT_COPY, OnUpdateViewCopyToClipboard)
63 ON_COMMAND(ID_VIEW_NEXT,OnViewNext)
64 ON_COMMAND(ID_VIEW_PREV,OnViewPrev)
65 ON_COMMAND(ID_FIND_NEXT, OnFindNext)
66 ON_COMMAND(ID_FIND_PREV, OnFindPrev)
67 ON_COMMAND(ID_VIEW_SHOWAUTHOR, OnViewToggleAuthor)
68 ON_UPDATE_COMMAND_UI(ID_VIEW_SHOWAUTHOR, OnUpdateViewToggleAuthor)
69 ON_COMMAND(ID_VIEW_SHOWDATE, OnViewToggleDate)
70 ON_UPDATE_COMMAND_UI(ID_VIEW_SHOWDATE, OnUpdateViewToggleDate)
71 ON_COMMAND(ID_VIEW_SHOWFILENAME, OnViewToggleShowFilename)
72 ON_UPDATE_COMMAND_UI(ID_VIEW_SHOWFILENAME, OnUpdateViewToggleShowFilename)
73 ON_COMMAND(ID_VIEW_SHOWORIGINALLINENUMBER, OnViewToggleShowOriginalLineNumber)
74 ON_UPDATE_COMMAND_UI(ID_VIEW_SHOWORIGINALLINENUMBER, OnUpdateViewToggleShowOriginalLineNumber)
75 ON_COMMAND(ID_VIEW_DETECT_MOVED_OR_COPIED_LINES_DISABLED, OnViewDetectMovedOrCopiedLinesToggleDisabled)
76 ON_UPDATE_COMMAND_UI(ID_VIEW_DETECT_MOVED_OR_COPIED_LINES_DISABLED, OnUpdateViewDetectMovedOrCopiedLinesToggleDisabled)
77 ON_COMMAND(ID_VIEW_DETECT_MOVED_OR_COPIED_LINES_WITHIN_FILE, OnViewDetectMovedOrCopiedLinesToggleWithinFile)
78 ON_UPDATE_COMMAND_UI(ID_VIEW_DETECT_MOVED_OR_COPIED_LINES_WITHIN_FILE, OnUpdateViewDetectMovedOrCopiedLinesToggleWithinFile)
79 ON_COMMAND(ID_VIEW_DETECT_MOVED_OR_COPIED_LINES_FROM_MODIFIED_FILES, OnViewDetectMovedOrCopiedLinesToggleFromModifiedFiles)
80 ON_UPDATE_COMMAND_UI(ID_VIEW_DETECT_MOVED_OR_COPIED_LINES_FROM_MODIFIED_FILES, OnUpdateViewDetectMovedOrCopiedLinesToggleFromModifiedFiles)
81 ON_COMMAND(ID_VIEW_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES_AT_FILE_CREATION, OnViewDetectMovedOrCopiedLinesToggleFromExistingFilesAtFileCreation)
82 ON_UPDATE_COMMAND_UI(ID_VIEW_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES_AT_FILE_CREATION, OnUpdateViewDetectMovedOrCopiedLinesToggleFromExistingFilesAtFileCreation)
83 ON_COMMAND(ID_VIEW_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES, OnViewDetectMovedOrCopiedLinesToggleFromExistingFiles)
84 ON_UPDATE_COMMAND_UI(ID_VIEW_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES, OnUpdateViewDetectMovedOrCopiedLinesToggleFromExistingFiles)
85 ON_COMMAND(ID_VIEW_IGNORE_WHITESPACE, OnViewToggleIgnoreWhitespace)
86 ON_UPDATE_COMMAND_UI(ID_VIEW_IGNORE_WHITESPACE, OnUpdateViewToggleIgnoreWhitespace)
87 ON_COMMAND(ID_VIEW_SHOWCOMPLETELOG, OnViewToggleShowCompleteLog)
88 ON_UPDATE_COMMAND_UI(ID_VIEW_SHOWCOMPLETELOG, OnUpdateViewToggleShowCompleteLog)
89 ON_COMMAND(ID_VIEW_ONLYCONSIDERFIRSTPARENTS, OnViewToggleOnlyFirstParent)
90 ON_UPDATE_COMMAND_UI(ID_VIEW_ONLYCONSIDERFIRSTPARENTS, OnUpdateViewToggleOnlyFirstParent)
91 ON_COMMAND(ID_VIEW_FOLLOWRENAMES, OnViewToggleFollowRenames)
92 ON_UPDATE_COMMAND_UI(ID_VIEW_FOLLOWRENAMES, OnUpdateViewToggleFollowRenames)
93 ON_COMMAND(ID_VIEW_COLORBYAGE, OnViewToggleColorByAge)
94 ON_UPDATE_COMMAND_UI(ID_VIEW_COLORBYAGE, OnUpdateViewToggleColorByAge)
95 ON_COMMAND(ID_VIEW_ENABLELEXER, OnViewToggleLexer)
96 ON_UPDATE_COMMAND_UI(ID_VIEW_ENABLELEXER, OnUpdateViewToggleLexer)
97 ON_COMMAND(ID_VIEW_WRAPLONGLINES, OnViewWrapLongLines)
98 ON_UPDATE_COMMAND_UI(ID_VIEW_WRAPLONGLINES, OnUpdateViewWrapLongLines)
99 ON_COMMAND_RANGE(IDM_FORMAT_ENCODE, IDM_FORMAT_ENCODE_END, OnChangeEncode)
100 ON_WM_CREATE()
101 ON_WM_SIZE()
102 ON_WM_MOUSEMOVE()
103 ON_WM_MOUSEHOVER()
104 ON_WM_MOUSELEAVE()
105 ON_WM_LBUTTONDOWN()
106 ON_WM_RBUTTONDOWN()
107 ON_WM_RBUTTONUP()
108 ON_WM_SYSCOLORCHANGE()
109 ON_WM_ERASEBKGND()
110 ON_NOTIFY(SCN_PAINTED, IDC_SCINTILLA, OnSciPainted)
111 ON_NOTIFY(SCN_GETBKCOLOR, IDC_SCINTILLA, OnSciGetBkColor)
112 ON_REGISTERED_MESSAGE(m_FindDialogMessage, OnFindDialogMessage)
113 END_MESSAGE_MAP()
116 // CTortoiseGitBlameView construction/destruction
118 CTortoiseGitBlameView::CTortoiseGitBlameView()
119 : wBlame(0)
120 , wHeader(0)
121 , hwndTT(0)
122 , bIgnoreEOL(false)
123 , bIgnoreSpaces(false)
124 , bIgnoreAllSpaces(false)
125 , m_MouseLine(-1)
126 , m_bMatchCase(false)
127 , hInstance(nullptr)
128 , hResource(nullptr)
129 , currentDialog(nullptr)
130 , wMain(nullptr)
131 , wLocator(nullptr)
132 , m_blamewidth(0)
133 , m_revwidth(0)
134 , m_datewidth(0)
135 , m_authorwidth(0)
136 , m_filenameWidth(0)
137 , m_originalLineNumberWidth(0)
138 , m_linewidth(0)
139 , m_SelectedLine(-1)
140 , m_bShowLine(true)
141 , m_pFindDialog(nullptr)
142 #ifdef USE_TEMPFILENAME
143 , m_Buffer(nullptr)
144 #endif
146 m_windowcolor = ::GetSysColor(COLOR_WINDOW);
147 m_textcolor = ::GetSysColor(COLOR_WINDOWTEXT);
148 m_texthighlightcolor = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
149 m_mouserevcolor = InterColor(m_windowcolor, m_textcolor, 20);
150 m_mouseauthorcolor = InterColor(m_windowcolor, m_textcolor, 10);
151 m_selectedrevcolor = ::GetSysColor(COLOR_HIGHLIGHT);
152 m_selectedauthorcolor = InterColor(m_selectedrevcolor, m_texthighlightcolor, 35);
154 HIGHCONTRAST highContrast = { 0 };
155 highContrast.cbSize = sizeof(HIGHCONTRAST);
156 BOOL highContrastModeEnabled = SystemParametersInfo(SPI_GETHIGHCONTRAST, 0, &highContrast, 0) == TRUE && (highContrast.dwFlags & HCF_HIGHCONTRASTON);
157 m_colorage = !!theApp.GetInt(L"ColorAge", !highContrastModeEnabled);
158 m_bLexer = !!theApp.GetInt(L"EnableLexer", !highContrastModeEnabled);
160 m_bShowAuthor = (theApp.GetInt(L"ShowAuthor", 1) == 1);
161 m_bShowDate = (theApp.GetInt(L"ShowDate", 0) == 1);
162 m_bShowFilename = (theApp.GetInt(L"ShowFilename", 0) == 1);
163 m_bShowOriginalLineNumber = (theApp.GetInt(L"ShowOriginalLineNumber", 0) == 1);
164 m_dwDetectMovedOrCopiedLines = theApp.GetInt(L"DetectMovedOrCopiedLines", 0);
165 m_bIgnoreWhitespace = (theApp.GetInt(L"IgnoreWhitespace", 0) == 1);
166 m_bShowCompleteLog = (theApp.GetInt(L"ShowCompleteLog", 1) == 1);
167 m_bOnlyFirstParent = (theApp.GetInt(L"OnlyFirstParent", 0) == 1);
168 m_bFollowRenames = (theApp.GetInt(L"FollowRenames", 0) == 1);
169 m_bBlameOutputContainsOtherFilenames = FALSE;
170 m_bWrapLongLines = !!theApp.GetInt(L"WrapLongLines", 0);
171 m_sFindText = theApp.GetString(L"FindString");
173 m_FindDialogMessage = ::RegisterWindowMessage(FINDMSGSTRING);
174 // get short/long datetime setting from registry
175 DWORD RegUseShortDateFormat = CRegDWORD(L"Software\\TortoiseGit\\LogDateFormat", TRUE);
176 if ( RegUseShortDateFormat )
178 m_DateFormat = DATE_SHORTDATE;
180 else
182 m_DateFormat = DATE_LONGDATE;
184 // get relative time display setting from registry
185 DWORD regRelativeTimes = CRegDWORD(L"Software\\TortoiseGit\\RelativeTimes", FALSE);
186 m_bRelativeTimes = (regRelativeTimes != 0);
188 m_sRev.LoadString(IDS_LOG_REVISION);
189 m_sFileName.LoadString(IDS_FILENAME);
190 m_sAuthor.LoadString(IDS_LOG_AUTHOR);
191 m_sDate.LoadString(IDS_LOG_DATE);
192 m_sMessage.LoadString(IDS_LOG_MESSAGE);
195 CTortoiseGitBlameView::~CTortoiseGitBlameView()
197 #ifdef USE_TEMPFILENAME
198 delete m_Buffer;
199 m_Buffer = nullptr;
200 #endif
202 struct EncodingUnit
204 int id;
205 char *name;
208 static EncodingUnit encodings[] = {
209 {1250, "windows-1250"}, //IDM_FORMAT_WIN_1250
210 {1251, "windows-1251"}, //IDM_FORMAT_WIN_1251
211 {1252, "windows-1252"}, //IDM_FORMAT_WIN_1252
212 {1253, "windows-1253"}, //IDM_FORMAT_WIN_1253
213 {1254, "windows-1254"}, //IDM_FORMAT_WIN_1254
214 {1255, "windows-1255"}, //IDM_FORMAT_WIN_1255
215 {1256, "windows-1256"}, //IDM_FORMAT_WIN_1256
216 {1257, "windows-1257"}, //IDM_FORMAT_WIN_1257
217 {1258, "windows-1258"}, //IDM_FORMAT_WIN_1258
218 {28591, "latin1 ISO_8859-1 ISO-8859-1 CP819 IBM819 csISOLatin1 iso-ir-100 l1"}, //IDM_FORMAT_ISO_8859_1
219 {28592, "latin2 ISO_8859-2 ISO-8859-2 csISOLatin2 iso-ir-101 l2"}, //IDM_FORMAT_ISO_8859_2
220 {28593, "latin3 ISO_8859-3 ISO-8859-3 csISOLatin3 iso-ir-109 l3"}, //IDM_FORMAT_ISO_8859_3
221 {28594, "latin4 ISO_8859-4 ISO-8859-4 csISOLatin4 iso-ir-110 l4"}, //IDM_FORMAT_ISO_8859_4
222 {28595, "cyrillic ISO_8859-5 ISO-8859-5 csISOLatinCyrillic iso-ir-144"}, //IDM_FORMAT_ISO_8859_5
223 {28596, "arabic ISO_8859-6 ISO-8859-6 csISOLatinArabic iso-ir-127 ASMO-708 ECMA-114"}, //IDM_FORMAT_ISO_8859_6
224 {28597, "greek ISO_8859-7 ISO-8859-7 csISOLatinGreek greek8 iso-ir-126 ELOT_928 ECMA-118"}, //IDM_FORMAT_ISO_8859_7
225 {28598, "hebrew ISO_8859-8 ISO-8859-8 csISOLatinHebrew iso-ir-138"}, //IDM_FORMAT_ISO_8859_8
226 {28599, "latin5 ISO_8859-9 ISO-8859-9 csISOLatin5 iso-ir-148 l5"}, //IDM_FORMAT_ISO_8859_9
227 {28600, "latin6 ISO_8859-10 ISO-8859-10 csISOLatin6 iso-ir-157 l6"}, //IDM_FORMAT_ISO_8859_10
228 {28601, "ISO_8859-11 ISO-8859-11"}, //IDM_FORMAT_ISO_8859_11
229 {28603, "ISO_8859-13 ISO-8859-13"}, //IDM_FORMAT_ISO_8859_13
230 {28604, "iso-celtic latin8 ISO_8859-14 ISO-8859-14 18 iso-ir-199"}, //IDM_FORMAT_ISO_8859_14
231 {28605, "Latin-9 ISO_8859-15 ISO-8859-15"}, //IDM_FORMAT_ISO_8859_15
232 {28606, "latin10 ISO_8859-16 ISO-8859-16 110 iso-ir-226"}, //IDM_FORMAT_ISO_8859_16
233 {437, "IBM437 cp437 437 csPC8CodePage437"}, //IDM_FORMAT_DOS_437
234 {720, "IBM720 cp720 oem720 720"}, //IDM_FORMAT_DOS_720
235 {737, "IBM737 cp737 oem737 737"}, //IDM_FORMAT_DOS_737
236 {775, "IBM775 cp775 oem775 775"}, //IDM_FORMAT_DOS_775
237 {850, "IBM850 cp850 oem850 850"}, //IDM_FORMAT_DOS_850
238 {852, "IBM852 cp852 oem852 852"}, //IDM_FORMAT_DOS_852
239 {855, "IBM855 cp855 oem855 855 csIBM855"}, //IDM_FORMAT_DOS_855
240 {857, "IBM857 cp857 oem857 857"}, //IDM_FORMAT_DOS_857
241 {858, "IBM858 cp858 oem858 858"}, //IDM_FORMAT_DOS_858
242 {860, "IBM860 cp860 oem860 860"}, //IDM_FORMAT_DOS_860
243 {861, "IBM861 cp861 oem861 861"}, //IDM_FORMAT_DOS_861
244 {862, "IBM862 cp862 oem862 862"}, //IDM_FORMAT_DOS_862
245 {863, "IBM863 cp863 oem863 863"}, //IDM_FORMAT_DOS_863
246 {865, "IBM865 cp865 oem865 865"}, //IDM_FORMAT_DOS_865
247 {866, "IBM866 cp866 oem866 866"}, //IDM_FORMAT_DOS_866
248 {869, "IBM869 cp869 oem869 869"}, //IDM_FORMAT_DOS_869
249 {950, "big5 csBig5"}, //IDM_FORMAT_BIG5
250 {936, "gb2312 gbk csGB2312"}, //IDM_FORMAT_GB2312
251 {932, "Shift_JIS MS_Kanji csShiftJIS csWindows31J"}, //IDM_FORMAT_SHIFT_JIS
252 {949, "windows-949 korean"}, //IDM_FORMAT_KOREAN_WIN
253 {51949, "euc-kr csEUCKR"}, //IDM_FORMAT_EUC_KR
254 {874, "tis-620"}, //IDM_FORMAT_TIS_620
255 {10007, "x-mac-cyrillic xmaccyrillic"}, //IDM_FORMAT_MAC_CYRILLIC
256 {21866, "koi8_u"}, //IDM_FORMAT_KOI8U_CYRILLIC
257 {20866, "koi8_r csKOI8R"}, //IDM_FORMAT_KOI8R_CYRILLIC
258 {65001, "UTF-8"}, //IDM_FORMAT_UTF8
259 {1200, "UTF-16 LE"}, //IDM_FORMAT_UTF16LE
260 {1201, "UTF-16 BE"}, //IDM_FORMAT_UTF16BE
262 void CTortoiseGitBlameView::OnChangeEncode(UINT nId)
264 if(nId >= IDM_FORMAT_ENCODE && nId <= IDM_FORMAT_ENCODE_END)
265 this->UpdateInfo(encodings[nId - IDM_FORMAT_ENCODE].id);
267 int CTortoiseGitBlameView::OnCreate(LPCREATESTRUCT lpcs)
269 CRect rect,rect1;
270 this->GetWindowRect(&rect1);
271 rect.left=m_blamewidth+LOCATOR_WIDTH;
272 rect.right=rect.Width();
273 rect.top=0;
274 rect.bottom=rect.Height();
275 if (!m_TextView.Create(L"Scintilla", L"source", 0, rect, this, IDC_SCINTILLA, 0))
277 TRACE0("Failed to create view\n");
278 return -1; // fail to create
280 m_TextView.Init(-1);
281 m_TextView.ShowWindow( SW_SHOW);
282 CreateFont();
283 SendEditor(SCI_SETREADONLY, TRUE);
284 m_ToolTip.Create(this->GetParent());
286 ::AfxGetApp()->GetMainWnd();
287 return CView::OnCreate(lpcs);
290 void CTortoiseGitBlameView::OnSize(UINT /*nType*/, int cx, int cy)
292 CRect rect;
293 rect.left=m_blamewidth;
294 rect.right=cx;
295 rect.top=0;
296 rect.bottom=cy;
298 m_TextView.MoveWindow(&rect);
300 BOOL CTortoiseGitBlameView::PreCreateWindow(CREATESTRUCT& cs)
302 return CView::PreCreateWindow(cs);
305 // CTortoiseGitBlameView drawing
307 BOOL CTortoiseGitBlameView::OnEraseBkgnd(CDC* /*pDC*/)
309 return TRUE;
312 void CTortoiseGitBlameView::OnDraw(CDC* pDC)
314 CTortoiseGitBlameDoc* pDoc = GetDocument();
315 ASSERT_VALID(pDoc);
316 if (!pDoc)
317 return;
319 CMemDC myDC(*pDC, this);
320 RECT rc;
321 GetClientRect(&rc);
322 myDC.GetDC().FillSolidRect(&rc, m_windowcolor);
323 DrawBlame(myDC.GetDC());
324 DrawLocatorBar(myDC.GetDC());
328 // CTortoiseGitBlameView printing
331 void CTortoiseGitBlameView::OnFilePrintPreview()
333 AFXPrintPreview(this);
336 BOOL CTortoiseGitBlameView::OnPreparePrinting(CPrintInfo* pInfo)
338 // default preparation
339 return DoPreparePrinting(pInfo);
342 void CTortoiseGitBlameView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
344 // TODO: add extra initialization before printing
347 void CTortoiseGitBlameView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
349 // TODO: add cleanup after printing
352 int CTortoiseGitBlameView::GetLineUnderCursor(CPoint point)
354 auto firstvisibleline = (int)SendEditor(SCI_GETFIRSTVISIBLELINE);
355 auto line = (int)SendEditor(SCI_DOCLINEFROMVISIBLE, firstvisibleline);
356 auto linesonscreen = (int)SendEditor(SCI_LINESONSCREEN) + 1;
357 auto height = (int)SendEditor(SCI_TEXTHEIGHT);
359 int i = 0, y = 0;
360 for (i = line; y <= point.y && i < (line + linesonscreen); ++i)
362 auto wrapcount = (int)SendEditor(SCI_WRAPCOUNT, i);
363 if (wrapcount > 1)
365 if (i == line)
366 wrapcount -= (int)SendEditor(SCI_DOCLINEFROMVISIBLE, firstvisibleline + wrapcount - 1) - (int)SendEditor(SCI_DOCLINEFROMVISIBLE, firstvisibleline);
367 linesonscreen -= wrapcount - 1;
369 y += height * wrapcount;
371 return i - 1;
374 void CTortoiseGitBlameView::OnRButtonUp(UINT /*nFlags*/, CPoint point)
376 int line = GetLineUnderCursor(point);
377 if (m_data.IsValidLine(line))
379 m_MouseLine = line;
380 ClientToScreen(&point);
382 CGitHash hash = m_data.GetHash(line);
383 CString hashStr = hash.ToString();
385 GitRevLoglist* pRev = nullptr;
386 int logIndex = m_lineToLogIndex[line];
387 if (logIndex >= 0)
388 pRev = &GetLogData()->GetGitRevAt(logIndex);
389 else
391 pRev = m_data.GetRev(line, GetLogData()->m_pLogCache->m_HashMap);
392 if (pRev && pRev->m_ParentHash.empty())
394 if (pRev->GetParentFromHash(pRev->m_CommitHash))
395 MessageBox(pRev->GetLastErr(), L"TortoiseGit", MB_ICONERROR);
399 if (!pRev)
400 return;
402 CIconMenu popup;
403 CIconMenu blamemenu, diffmenu;
405 if (!popup.CreatePopupMenu())
406 return;
408 // Now find the relevant parent commits, they must contain the file which is blamed to be the source of the selected line,
409 // otherwise there is no previous file to compare to (only another previous revision).
411 GIT_REV_LIST parentHashWithFile;
412 std::vector<CString> parentFilename;
415 CTGitPath path(m_data.GetFilename(line));
416 const CTGitPathList& files = pRev->GetFiles(nullptr);
417 for (int j = 0, j_size = files.GetCount(); j < j_size; ++j)
419 const CTGitPath &file = files[j];
420 if (file.IsEquivalentTo(path))
422 if (!(file.m_ParentNo & MERGE_MASK))
424 int action = file.m_Action;
425 // ignore (action & CTGitPath::LOGACTIONS_ADDED), as then there is nothing to blame/diff
426 // ignore (action & CTGitPath::LOGACTIONS_DELETED), should never happen as the file must exist
427 if (action & (CTGitPath::LOGACTIONS_MODIFIED | CTGitPath::LOGACTIONS_REPLACED))
429 int parentNo = file.m_ParentNo & PARENT_MASK;
430 if (parentNo >= 0 && (size_t)parentNo < pRev->m_ParentHash.size())
432 parentHashWithFile.push_back(pRev->m_ParentHash[parentNo]);
433 parentFilename.push_back((action & CTGitPath::LOGACTIONS_REPLACED) ? file.GetGitOldPathString() : file.GetGitPathString());
440 catch (const char* msg)
442 MessageBox(L"Could not get files of parents.\nlibgit reports:\n" + CString(msg), L"TortoiseGit", MB_ICONERROR);
445 // blame previous
446 if (!parentHashWithFile.empty())
448 if (parentHashWithFile.size() == 1)
450 popup.AppendMenuIcon(ID_BLAMEPREVIOUS, IDS_BLAME_POPUP_BLAME, IDI_BLAME_POPUP_BLAME);
452 else
454 blamemenu.CreatePopupMenu();
455 popup.AppendMenuIcon(ID_BLAMEPREVIOUS, IDS_BLAME_POPUP_BLAME, IDI_BLAME_POPUP_BLAME, blamemenu.m_hMenu);
457 for (size_t i = 0; i < parentHashWithFile.size(); ++i)
459 CString str;
460 str.Format(IDS_PARENT, i + 1);
461 blamemenu.AppendMenuIcon(ID_BLAMEPREVIOUS + ((i + 1) << 16), str);
466 // compare with previous
467 if (!parentHashWithFile.empty())
469 if (parentHashWithFile.size() == 1)
471 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_BLAME_POPUP_COMPARE, IDI_BLAME_POPUP_COMPARE);
472 if (CRegDWORD(L"Software\\TortoiseGit\\DiffByDoubleClickInLog", FALSE))
473 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
475 else
477 diffmenu.CreatePopupMenu();
478 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_BLAME_POPUP_COMPARE, IDI_BLAME_POPUP_COMPARE, diffmenu.m_hMenu);
479 for (size_t i = 0; i < parentHashWithFile.size(); ++i)
481 CString str;
482 str.Format(IDS_BLAME_POPUP_PARENT, i + 1);
483 diffmenu.AppendMenuIcon((UINT)(ID_COMPAREWITHPREVIOUS + ((i + 1) << 16)),str);
484 if (i == 0 && CRegDWORD(L"Software\\TortoiseGit\\DiffByDoubleClickInLog", FALSE))
486 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
487 diffmenu.SetDefaultItem((UINT)(ID_COMPAREWITHPREVIOUS + ((i + 1) << 16)), FALSE);
493 popup.AppendMenuIcon(ID_SHOWLOG, IDS_BLAME_POPUP_LOG, IDI_BLAME_POPUP_LOG);
494 popup.AppendMenu(MF_SEPARATOR, NULL);
495 popup.AppendMenuIcon(ID_COPYHASHTOCLIPBOARD, IDS_BLAME_POPUP_COPYHASHTOCLIPBOARD, IDI_BLAME_POPUP_COPY);
496 popup.AppendMenuIcon(ID_COPYLOGTOCLIPBOARD, IDS_BLAME_POPUP_COPYLOGTOCLIPBOARD, IDI_BLAME_POPUP_COPY);
498 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this);
499 if (!cmd)
500 return;
501 this->ContextMenuAction(cmd, pRev, parentHashWithFile, parentFilename, line);
505 void CTortoiseGitBlameView::ContextMenuAction(int cmd, GitRev *pRev, GIT_REV_LIST& parentHashWithFile, const std::vector<CString>& parentFilename, int selectedLine)
507 switch (cmd & 0xFFFF)
509 case ID_BLAMEPREVIOUS:
511 int index = (cmd>>16) & 0xFFFF;
512 if (index > 0)
513 index -= 1;
515 CString path = ResolveCommitFile(parentFilename[index]);
516 CString endrev = parentHashWithFile[index].ToString();
517 int line = m_data.GetOriginalLineNumber(selectedLine);
519 CString procCmd = L"/path:\"" + path + L"\" ";
520 procCmd += L" /command:blame";
521 procCmd += L" /endrev:" + endrev;
522 procCmd += L" /line:";
523 procCmd.AppendFormat(L"%d", line);
525 CCommonAppUtils::RunTortoiseGitProc(procCmd);
527 break;
529 case ID_COMPAREWITHPREVIOUS:
531 int index = (cmd >> 16) & 0xFFFF;
532 if (index > 0)
533 index -= 1;
535 CString path = ResolveCommitFile(parentFilename[index]);
536 CString startrev = parentHashWithFile[index].ToString();
537 CString endrev = pRev->m_CommitHash.ToString();
539 CString procCmd = L"/path:\"" + path + L"\" ";
540 procCmd += L" /command:diff";
541 procCmd += L" /startrev:" + startrev;
542 procCmd += L" /endrev:" + endrev;
543 if (!!(GetAsyncKeyState(VK_SHIFT) & 0x8000))
544 procCmd += L" /alternative";
546 CCommonAppUtils::RunTortoiseGitProc(procCmd);
548 break;
550 case ID_SHOWLOG:
552 CString path = ResolveCommitFile(selectedLine);
553 CString rev = m_data.GetHash(selectedLine).ToString();
555 CString procCmd = L"/path:\"" + path + L"\" ";
556 procCmd += L" /command:log";
557 procCmd += L" /rev:" + rev;
558 procCmd += L" /endrev:" + rev;
560 CCommonAppUtils::RunTortoiseGitProc(procCmd);
562 break;
564 case ID_COPYHASHTOCLIPBOARD:
565 this->GetLogList()->CopySelectionToClipBoard(CGitLogListBase::ID_COPYCLIPBOARDHASH);
566 break;
568 case ID_COPYLOGTOCLIPBOARD:
569 this->GetLogList()->CopySelectionToClipBoard(CGitLogListBase::ID_COPYCLIPBOARDFULL);
570 break;
574 // CTortoiseGitBlameView diagnostics
576 #ifdef _DEBUG
577 void CTortoiseGitBlameView::AssertValid() const
579 CView::AssertValid();
582 void CTortoiseGitBlameView::Dump(CDumpContext& dc) const
584 CView::Dump(dc);
587 CTortoiseGitBlameDoc* CTortoiseGitBlameView::GetDocument() const // non-debug version is inline
589 ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTortoiseGitBlameDoc)));
590 return (CTortoiseGitBlameDoc*)m_pDocument;
592 #endif //_DEBUG
595 // Return a color which is interpolated between c1 and c2.
596 // Slider controls the relative proportions as a percentage:
597 // Slider = 0 represents pure c1
598 // Slider = 50 represents equal mixture
599 // Slider = 100 represents pure c2
600 COLORREF CTortoiseGitBlameView::InterColor(COLORREF c1, COLORREF c2, int Slider)
602 int r, g, b;
604 // Limit Slider to 0..100% range
605 if (Slider < 0)
606 Slider = 0;
607 if (Slider > 100)
608 Slider = 100;
610 // The color components have to be treated individually.
611 r = (GetRValue(c2) * Slider + GetRValue(c1) * (100 - Slider)) / 100;
612 g = (GetGValue(c2) * Slider + GetGValue(c1) * (100 - Slider)) / 100;
613 b = (GetBValue(c2) * Slider + GetBValue(c1) * (100 - Slider)) / 100;
615 return RGB(r, g, b);
618 LRESULT CTortoiseGitBlameView::SendEditor(UINT Msg, WPARAM wParam, LPARAM lParam)
620 return m_TextView.Call(Msg, wParam, lParam);
623 void CTortoiseGitBlameView::SetAStyle(int style, COLORREF fore, COLORREF back, int size, const char *face)
625 if (fore == back && fore == m_windowcolor)
626 fore = m_textcolor;
627 m_TextView.SetAStyle(style, fore, back, size, face);
630 void CTortoiseGitBlameView::InitialiseEditor()
632 SendEditor(SCI_STYLERESETDEFAULT);
633 // Set up the global default style. These attributes are used wherever no explicit choices are made.
634 std::string fontName = CUnicodeUtils::StdGetUTF8((std::wstring)CRegStdString(L"Software\\TortoiseGit\\BlameFontName", L"Consolas"));
635 SetAStyle(STYLE_DEFAULT,
636 ::GetSysColor(COLOR_WINDOWTEXT),
637 ::GetSysColor(COLOR_WINDOW),
638 (DWORD)CRegStdDWORD(L"Software\\TortoiseGit\\BlameFontSize", 10),
639 fontName.c_str()
641 SendEditor(SCI_SETTABWIDTH, (DWORD)CRegStdDWORD(L"Software\\TortoiseGit\\BlameTabSize", 4));
642 SendEditor(SCI_SETREADONLY, TRUE);
643 auto numberOfLines = m_data.GetNumberOfLines();
644 int numDigits = 2;
645 while (numberOfLines)
647 numberOfLines /= 10;
648 ++numDigits;
650 if (m_bShowLine)
651 SendEditor(SCI_SETMARGINWIDTHN, 0, numDigits * (int)SendEditor(SCI_TEXTWIDTH, STYLE_LINENUMBER, (LPARAM)"8"));
652 else
653 SendEditor(SCI_SETMARGINWIDTHN, 0);
654 SendEditor(SCI_SETMARGINWIDTHN, 1);
655 SendEditor(SCI_SETMARGINWIDTHN, 2);
656 //Set the default windows colors for edit controls
657 SendEditor(SCI_SETSELFORE, TRUE, ::GetSysColor(COLOR_HIGHLIGHTTEXT));
658 SendEditor(SCI_SETSELBACK, TRUE, ::GetSysColor(COLOR_HIGHLIGHT));
659 SendEditor(SCI_SETCARETFORE, ::GetSysColor(COLOR_WINDOWTEXT));
660 m_regOldLinesColor = CRegStdDWORD(L"Software\\TortoiseGit\\BlameOldColor", BLAMEOLDCOLOR);
661 m_regNewLinesColor = CRegStdDWORD(L"Software\\TortoiseGit\\BlameNewColor", BLAMENEWCOLOR);
662 if (CRegStdDWORD(L"Software\\TortoiseGit\\ScintillaDirect2D", FALSE) != FALSE)
664 SendEditor(SCI_SETTECHNOLOGY, SC_TECHNOLOGY_DIRECTWRITERETAIN);
665 SendEditor(SCI_SETBUFFEREDDRAW, 0);
668 if (m_bWrapLongLines)
669 SendEditor(SCI_SETWRAPMODE, SC_WRAP_WORD);
670 else
671 SendEditor(SCI_SETWRAPMODE, SC_WRAP_NONE);
672 SendEditor(SCI_STYLECLEARALL);
675 bool CTortoiseGitBlameView::DoSearch(CTortoiseGitBlameData::SearchDirection direction)
677 auto pos = (Sci_Position)SendEditor(SCI_GETCURRENTPOS);
678 auto line = (int)SendEditor(SCI_LINEFROMPOSITION, pos);
680 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); });
681 if (i >= 0)
683 GotoLine(i + 1);
684 auto selstart = (int)(Sci_Position)SendEditor(SCI_GETCURRENTPOS);
685 auto selend = (int)(Sci_Position)SendEditor(SCI_POSITIONFROMLINE, i + 1);
686 SendEditor(SCI_SETSELECTIONSTART, selstart);
687 SendEditor(SCI_SETSELECTIONEND, selend);
688 m_SelectedLine = i;
690 else
691 ::MessageBox(m_pFindDialog && m_pFindDialog->GetSafeHwnd() ? m_pFindDialog->GetSafeHwnd() : wMain, L"\"" + m_sFindText + L"\" " + CString(MAKEINTRESOURCE(IDS_NOTFOUND)), L"TortoiseGitBlame", MB_ICONINFORMATION);
693 return true;
696 void CTortoiseGitBlameView::OnFindPrev()
698 if (m_sFindText.IsEmpty())
699 return;
700 DoSearch(CTortoiseGitBlameData::SearchPrevious);
703 void CTortoiseGitBlameView::OnFindNext()
705 if (m_sFindText.IsEmpty())
706 return;
707 DoSearch(CTortoiseGitBlameData::SearchNext);
710 bool CTortoiseGitBlameView::GotoLine(int line)
712 --line;
713 int numberOfLines = (int)m_data.GetNumberOfLines();
714 if (line < 0 || numberOfLines == 0)
715 return false;
716 if (line >= numberOfLines)
718 line = numberOfLines - 1;
721 auto nCurrentPos = (Sci_Position)SendEditor(SCI_GETCURRENTPOS);
722 int nCurrentLine = (int)SendEditor(SCI_LINEFROMPOSITION,nCurrentPos);
723 int nFirstVisibleLine = (int)SendEditor(SCI_GETFIRSTVISIBLELINE);
724 int nLinesOnScreen = (int)SendEditor(SCI_LINESONSCREEN);
726 if ( line>=nFirstVisibleLine && line<=nFirstVisibleLine+nLinesOnScreen)
728 // no need to scroll
729 SendEditor(SCI_GOTOLINE, line);
731 else
733 // Place the requested line one third from the top
734 if ( line > nCurrentLine )
736 SendEditor(SCI_GOTOLINE, (WPARAM)(line+(int)nLinesOnScreen*(2/3.0)));
738 else
740 SendEditor(SCI_GOTOLINE, (WPARAM)(line-(int)nLinesOnScreen*(1/3.0)));
744 // Highlight the line
745 int nPosStart = (int)SendEditor(SCI_POSITIONFROMLINE,line);
746 int nPosEnd = (int)SendEditor(SCI_GETLINEENDPOSITION,line);
747 SendEditor(SCI_SETSEL,nPosEnd,nPosStart);
749 return true;
752 bool CTortoiseGitBlameView::ScrollToLine(long line)
754 if (line < 0)
755 return false;
757 int nCurrentLine = (int)SendEditor(SCI_GETFIRSTVISIBLELINE);
759 int scrolldelta = line - nCurrentLine;
760 SendEditor(SCI_LINESCROLL, 0, scrolldelta);
762 return true;
765 void CTortoiseGitBlameView::CopyToClipboard()
767 CWnd * wnd = GetFocus();
768 if (wnd == this->GetLogList())
769 GetLogList()->CopySelectionToClipBoard();
770 else if (wnd)
772 if (CString(wnd->GetRuntimeClass()->m_lpszClassName) == L"CMFCPropertyGridCtrl")
774 CMFCPropertyGridCtrl *grid = (CMFCPropertyGridCtrl *)wnd;
775 if (grid->GetCurSel() && !grid->GetCurSel()->IsGroup())
776 CStringUtils::WriteAsciiStringToClipboard(grid->GetCurSel()->GetValue(), GetSafeHwnd());
778 else
779 m_TextView.Call(SCI_COPY);
783 LONG CTortoiseGitBlameView::GetBlameWidth()
785 LONG blamewidth = 0;
786 SIZE width;
787 CreateFont();
788 HDC hDC = this->GetDC()->m_hDC;
789 HFONT oldfont = (HFONT)::SelectObject(hDC, m_font.GetSafeHandle());
791 CString shortHash('f', g_Git.GetShortHASHLength() + 1);
792 ::GetTextExtentPoint32(hDC, shortHash, g_Git.GetShortHASHLength() + 1, &width);
793 m_revwidth = width.cx + BLAMESPACE;
794 blamewidth += m_revwidth;
796 if (m_bShowDate)
798 SIZE maxwidth = {0};
800 auto numberOfLines = m_data.GetNumberOfLines();
801 for (size_t i = 0; i < numberOfLines; ++i)
803 ::GetTextExtentPoint32(hDC, m_data.GetDate(i), m_data.GetDate(i).GetLength(), &width);
804 if (width.cx > maxwidth.cx)
805 maxwidth = width;
807 m_datewidth = maxwidth.cx + BLAMESPACE;
808 blamewidth += m_datewidth;
810 if ( m_bShowAuthor)
812 SIZE maxwidth = {0};
814 size_t numberOfLines = m_data.GetNumberOfLines();
815 for (size_t i = 0; i < numberOfLines; ++i)
817 ::GetTextExtentPoint32(hDC,m_data.GetAuthor(i) , m_data.GetAuthor(i).GetLength(), &width);
818 if (width.cx > maxwidth.cx)
819 maxwidth = width;
821 m_authorwidth = maxwidth.cx + BLAMESPACE;
822 blamewidth += m_authorwidth;
824 if (m_bShowFilename)
826 SIZE maxwidth = {0};
828 size_t numberOfLines = m_data.GetNumberOfLines();
829 for (size_t i = 0; i < numberOfLines; ++i)
831 ::GetTextExtentPoint32(hDC, m_data.GetFilename(i), m_data.GetFilename(i).GetLength(), &width);
832 if (width.cx > maxwidth.cx)
833 maxwidth = width;
835 m_filenameWidth = maxwidth.cx + BLAMESPACE;
836 blamewidth += m_filenameWidth;
838 if (m_bShowOriginalLineNumber)
840 SIZE maxwidth = {0};
842 size_t numberOfLines = m_data.GetNumberOfLines();
843 CString str;
844 for (size_t i = 0; i < numberOfLines; ++i)
846 str.Format(L"%5d", m_data.GetOriginalLineNumber(i));
847 ::GetTextExtentPoint32(hDC, str, str.GetLength(), &width);
848 if (width.cx > maxwidth.cx)
849 maxwidth = width;
851 m_originalLineNumberWidth = maxwidth.cx + BLAMESPACE;
852 blamewidth += m_originalLineNumberWidth;
854 ::SelectObject(hDC, oldfont);
855 POINT pt = {blamewidth, 0};
856 LPtoDP(hDC, &pt, 1);
857 m_blamewidth = pt.x;
858 //::ReleaseDC(wBlame, hDC);
859 return blamewidth;
862 void CTortoiseGitBlameView::CreateFont()
864 if (m_font.GetSafeHandle())
865 return;
866 LOGFONT lf = {0};
867 lf.lfWeight = 400;
868 HDC hDC = ::GetDC(wBlame);
869 lf.lfHeight = -MulDiv((DWORD)CRegStdDWORD(L"Software\\TortoiseGit\\BlameFontSize", 10), GetDeviceCaps(hDC, LOGPIXELSY), 72);
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);
878 ::ReleaseDC(wBlame, hDC);
881 void CTortoiseGitBlameView::DrawBlame(HDC hDC)
883 if (!hDC || m_data.GetNumberOfLines() == 0)
884 return;
885 if (!m_font.GetSafeHandle())
886 return;
888 HFONT oldfont = nullptr;
889 int firstvisibleline = (int)SendEditor(SCI_GETFIRSTVISIBLELINE);
890 int line = (int)SendEditor(SCI_DOCLINEFROMVISIBLE, firstvisibleline);
891 int linesonscreen = (int)SendEditor(SCI_LINESONSCREEN) + 1;
892 int height = (int)SendEditor(SCI_TEXTHEIGHT);
893 int Y = 0;
894 TCHAR buf[MAX_PATH] = {0};
895 std::fill_n(buf, _countof(buf) - 1, L' ');
896 RECT rc;
897 CGitHash oldHash;
898 CString oldFile;
900 for (int i = line; i < (line + linesonscreen) && (size_t)i < m_data.GetNumberOfLines(); ++i)
902 auto wrapcount = (int)SendEditor(SCI_WRAPCOUNT, i);
903 if (wrapcount > 1)
905 if (i == line)
906 wrapcount -= (int)SendEditor(SCI_DOCLINEFROMVISIBLE, firstvisibleline + wrapcount - 1) - (int)SendEditor(SCI_DOCLINEFROMVISIBLE, firstvisibleline);
907 linesonscreen -= wrapcount - 1;
909 CGitHash hash(m_data.GetHash(i));
910 oldfont = (HFONT)::SelectObject(hDC, m_font.GetSafeHandle());
911 ::SetBkColor(hDC, m_windowcolor);
912 ::SetTextColor(hDC, m_textcolor);
913 if (!hash.IsEmpty() && hash == m_SelectedHash)
915 ::SetBkColor(hDC, m_selectedauthorcolor);
916 ::SetTextColor(hDC, m_texthighlightcolor);
919 if (m_MouseLine == i)
920 ::SetBkColor(hDC, m_mouserevcolor);
922 if ((!hash.IsEmpty() && hash == m_SelectedHash) || m_MouseLine == i)
924 auto old = ::GetTextColor(hDC);
925 ::SetTextColor(hDC, ::GetBkColor(hDC));
926 RECT rc2 = { LOCATOR_WIDTH, Y, m_blamewidth + LOCATOR_WIDTH, Y + (wrapcount * height) };
927 for (int j = 0; j < wrapcount; ++j)
928 ::ExtTextOut(hDC, 0, Y + (j * height), ETO_CLIPPED, &rc2, buf, _countof(buf) - 1, 0);
929 ::SetTextColor(hDC, old);
932 CString file = m_data.GetFilename(i);
933 if (oldHash != hash || (m_bShowFilename && oldFile != file) || m_bShowOriginalLineNumber)
935 rc.top = (LONG)Y;
936 rc.left = LOCATOR_WIDTH;
937 rc.bottom = (LONG)(Y + height);
938 rc.right = rc.left + m_blamewidth;
939 if (oldHash != hash)
941 CString shortHashStr = hash.ToString().Left(g_Git.GetShortHASHLength());
942 ::ExtTextOut(hDC, LOCATOR_WIDTH, Y, ETO_CLIPPED, &rc, shortHashStr, shortHashStr.GetLength(), 0);
944 int Left = m_revwidth;
946 if (m_bShowAuthor)
948 rc.right = rc.left + Left + m_authorwidth;
949 if (oldHash != hash)
950 ::ExtTextOut(hDC, Left, Y, ETO_CLIPPED, &rc, m_data.GetAuthor(i), m_data.GetAuthor(i).GetLength(), 0);
951 Left += m_authorwidth;
953 if (m_bShowDate)
955 rc.right = rc.left + Left + m_datewidth;
956 if (oldHash != hash)
957 ::ExtTextOut(hDC, Left, Y, ETO_CLIPPED, &rc, m_data.GetDate(i), m_data.GetDate(i).GetLength(), 0);
958 Left += m_datewidth;
960 if (m_bShowFilename)
962 rc.right = rc.left + Left + m_filenameWidth;
963 if (oldFile != file)
964 ::ExtTextOut(hDC, Left, Y, ETO_CLIPPED, &rc, m_data.GetFilename(i), m_data.GetFilename(i).GetLength(), 0);
965 Left += m_filenameWidth;
967 if (m_bShowOriginalLineNumber)
969 rc.right = rc.left + Left + m_originalLineNumberWidth;
970 CString str;
971 str.Format(L"%5d", m_data.GetOriginalLineNumber(i));
972 ::ExtTextOut(hDC, Left, Y, ETO_CLIPPED, &rc, str, str.GetLength(), 0);
973 Left += m_originalLineNumberWidth;
975 oldHash = hash;
976 oldFile = file;
978 if (i == m_SelectedLine && m_pFindDialog)
980 LOGBRUSH brush;
981 brush.lbColor = m_textcolor;
982 brush.lbHatch = 0;
983 brush.lbStyle = BS_SOLID;
984 HPEN pen = ExtCreatePen(PS_SOLID | PS_GEOMETRIC, 2, &brush, 0, nullptr);
985 HGDIOBJ hPenOld = SelectObject(hDC, pen);
986 RECT rc2 = { LOCATOR_WIDTH, Y + 1, m_blamewidth, Y + (wrapcount * height) - 1};
987 ::MoveToEx(hDC, rc2.left, rc2.top, nullptr);
988 ::LineTo(hDC, rc2.right, rc2.top);
989 ::LineTo(hDC, rc2.right, rc2.bottom);
990 ::LineTo(hDC, rc2.left, rc2.bottom);
991 ::LineTo(hDC, rc2.left, rc2.top);
992 SelectObject(hDC, hPenOld);
993 DeleteObject(pen);
995 Y += wrapcount * height;
996 ::SelectObject(hDC, oldfont);
1000 void CTortoiseGitBlameView::DrawLocatorBar(HDC hDC)
1002 if (!hDC)
1003 return;
1005 int line = (int)SendEditor(SCI_GETFIRSTVISIBLELINE);
1006 int linesonscreen = (int)SendEditor(SCI_LINESONSCREEN);
1007 int Y = 0;
1008 COLORREF blackColor = GetSysColor(COLOR_WINDOWTEXT);
1010 RECT rc;
1011 //::GetClientRect(wLocator, &rc);
1012 this->GetClientRect(&rc);
1014 rc.right=LOCATOR_WIDTH;
1016 RECT lineRect = rc;
1017 LONG height = rc.bottom-rc.top;
1019 auto numberOfLines = (int)m_data.GetNumberOfLines();
1020 // draw the colored bar
1021 for (int currentLine = 0; currentLine < numberOfLines; ++currentLine)
1023 COLORREF cr = GetLineColor(currentLine);
1024 // get the line color
1025 if ((currentLine >= line)&&(currentLine < (line + linesonscreen)))
1027 cr = InterColor(cr, blackColor, 10);
1029 SetBkColor(hDC, cr);
1030 lineRect.top = (LONG)Y;
1031 lineRect.bottom = (((int)currentLine + 1) * height / (int)numberOfLines);
1032 ::ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &lineRect, nullptr, 0, nullptr);
1033 Y = lineRect.bottom;
1036 if (numberOfLines > 0)
1038 // now draw two lines indicating the scroll position of the source view
1039 SetBkColor(hDC, blackColor);
1040 lineRect.top = (LONG)line * height / (int)numberOfLines;
1041 lineRect.bottom = lineRect.top+1;
1042 ::ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &lineRect, nullptr, 0, nullptr);
1043 lineRect.top = (LONG)(line + linesonscreen) * height / (int)numberOfLines;
1044 lineRect.bottom = lineRect.top+1;
1045 ::ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &lineRect, nullptr, 0, nullptr);
1049 void CTortoiseGitBlameView::SetupLexer(CString filename)
1051 int start = filename.ReverseFind(L'.');
1052 SendEditor(SCI_SETLEXER, SCLEX_NULL);
1053 if (!m_bLexer)
1054 return;
1055 if (start > 0)
1057 //wcscpy_s(line, 20, lineptr+1);
1058 //_wcslwr_s(line, 20);
1059 CString ext=filename.Right(filename.GetLength()-start-1);
1060 const TCHAR* line = ext;
1062 if ((wcscmp(line, L"py") == 0) ||
1063 (wcscmp(line, L"pyw") == 0))
1065 SendEditor(SCI_SETLEXER, SCLEX_PYTHON);
1066 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(L"and assert break class continue def del elif \
1067 else except exec finally for from global if import in is lambda None \
1068 not or pass print raise return try while yield").GetBuffer()));
1069 SetAStyle(SCE_P_DEFAULT, black);
1070 SetAStyle(SCE_P_COMMENTLINE, darkGreen);
1071 SetAStyle(SCE_P_NUMBER, RGB(0, 0x80, 0x80));
1072 SetAStyle(SCE_P_STRING, RGB(0, 0, 0x80));
1073 SetAStyle(SCE_P_CHARACTER, RGB(0, 0, 0x80));
1074 SetAStyle(SCE_P_WORD, RGB(0x80, 0, 0x80));
1075 SetAStyle(SCE_P_TRIPLE, black);
1076 SetAStyle(SCE_P_TRIPLEDOUBLE, black);
1077 SetAStyle(SCE_P_CLASSNAME, darkBlue);
1078 SetAStyle(SCE_P_DEFNAME, darkBlue);
1079 SetAStyle(SCE_P_OPERATOR, darkBlue);
1080 SetAStyle(SCE_P_IDENTIFIER, darkBlue);
1081 SetAStyle(SCE_P_COMMENTBLOCK, darkGreen);
1082 SetAStyle(SCE_P_STRINGEOL, red);
1084 if ((wcscmp(line, L"c") == 0) ||
1085 (wcscmp(line, L"cc") == 0) ||
1086 (wcscmp(line, L"cpp") == 0) ||
1087 (wcscmp(line, L"cxx") == 0) ||
1088 (wcscmp(line, L"h") == 0) ||
1089 (wcscmp(line, L"hh") == 0) ||
1090 (wcscmp(line, L"hpp") == 0) ||
1091 (wcscmp(line, L"hxx") == 0) ||
1092 (wcscmp(line, L"dlg") == 0) ||
1093 (wcscmp(line, L"mak") == 0))
1095 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1096 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(L"and and_eq asm auto bitand bitor bool break \
1097 case catch char class compl const const_cast continue \
1098 default delete do double dynamic_cast else enum explicit export extern false float for \
1099 friend goto if inline int long mutable namespace new not not_eq \
1100 operator or or_eq private protected public \
1101 register reinterpret_cast return short signed sizeof static static_cast struct switch \
1102 template this throw true try typedef typeid typename union unsigned using \
1103 virtual void volatile wchar_t while xor xor_eq").GetBuffer()));
1104 SendEditor(SCI_SETKEYWORDS, 3, (LPARAM)(m_TextView.StringForControl(L"a addindex addtogroup anchor arg attention \
1105 author b brief bug c class code date def defgroup deprecated dontinclude \
1106 e em endcode endhtmlonly endif endlatexonly endlink endverbatim enum example exception \
1107 f$ f[ f] file fn hideinitializer htmlinclude htmlonly \
1108 if image include ingroup internal invariant interface latexonly li line link \
1109 mainpage name namespace nosubgrouping note overload \
1110 p page par param post pre ref relates remarks return retval \
1111 sa section see showinitializer since skip skipline struct subsection \
1112 test throw todo typedef union until \
1113 var verbatim verbinclude version warning weakgroup $ @ \\ & < > # { }").GetBuffer()));
1114 SetupCppLexer();
1116 if (wcscmp(line, L"cs") == 0)
1118 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1119 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(L"abstract as base bool break byte case catch char checked class \
1120 const continue decimal default delegate do double else enum \
1121 event explicit extern false finally fixed float for foreach goto if \
1122 implicit in int interface internal is lock long namespace new null \
1123 object operator out override params private protected public \
1124 readonly ref return sbyte sealed short sizeof stackalloc static \
1125 string struct switch this throw true try typeof uint ulong \
1126 unchecked unsafe ushort using virtual void while").GetBuffer()));
1127 SetupCppLexer();
1129 if ((wcscmp(line, L"rc") == 0) ||
1130 (wcscmp(line, L"rc2") == 0))
1132 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1133 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(L"ACCELERATORS ALT AUTO3STATE AUTOCHECKBOX AUTORADIOBUTTON \
1134 BEGIN BITMAP BLOCK BUTTON CAPTION CHARACTERISTICS CHECKBOX CLASS \
1135 COMBOBOX CONTROL CTEXT CURSOR DEFPUSHBUTTON DIALOG DIALOGEX DISCARDABLE \
1136 EDITTEXT END EXSTYLE FONT GROUPBOX ICON LANGUAGE LISTBOX LTEXT \
1137 MENU MENUEX MENUITEM MESSAGETABLE POPUP \
1138 PUSHBUTTON RADIOBUTTON RCDATA RTEXT SCROLLBAR SEPARATOR SHIFT STATE3 \
1139 STRINGTABLE STYLE TEXTINCLUDE VALUE VERSION VERSIONINFO VIRTKEY").GetBuffer()));
1140 SetupCppLexer();
1142 if ((wcscmp(line, L"idl") == 0) ||
1143 (wcscmp(line, L"odl") == 0))
1145 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1146 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(L"aggregatable allocate appobject arrays async async_uuid \
1147 auto_handle \
1148 bindable boolean broadcast byte byte_count \
1149 call_as callback char coclass code comm_status \
1150 const context_handle context_handle_noserialize \
1151 context_handle_serialize control cpp_quote custom \
1152 decode default defaultbind defaultcollelem \
1153 defaultvalue defaultvtable dispinterface displaybind dllname \
1154 double dual \
1155 enable_allocate encode endpoint entry enum error_status_t \
1156 explicit_handle \
1157 fault_status first_is float \
1158 handle_t heap helpcontext helpfile helpstring \
1159 helpstringcontext helpstringdll hidden hyper \
1160 id idempotent ignore iid_as iid_is immediatebind implicit_handle \
1161 import importlib in include in_line int __int64 __int3264 interface \
1162 last_is lcid length_is library licensed local long \
1163 max_is maybe message methods midl_pragma \
1164 midl_user_allocate midl_user_free min_is module ms_union \
1165 ncacn_at_dsp ncacn_dnet_nsp ncacn_http ncacn_ip_tcp \
1166 ncacn_nb_ipx ncacn_nb_nb ncacn_nb_tcp ncacn_np \
1167 ncacn_spx ncacn_vns_spp ncadg_ip_udp ncadg_ipx ncadg_mq \
1168 ncalrpc nocode nonbrowsable noncreatable nonextensible notify \
1169 object odl oleautomation optimize optional out out_of_line \
1170 pipe pointer_default pragma properties propget propput propputref \
1171 ptr public \
1172 range readonly ref represent_as requestedit restricted retval \
1173 shape short signed size_is small source strict_context_handle \
1174 string struct switch switch_is switch_type \
1175 transmit_as typedef \
1176 uidefault union unique unsigned user_marshal usesgetlasterror uuid \
1177 v1_enum vararg version void wchar_t wire_marshal").GetBuffer()));
1178 SetupCppLexer();
1180 if (wcscmp(line, L"java") == 0)
1182 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1183 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(L"abstract assert boolean break byte case catch char class \
1184 const continue default do double else extends final finally float for future \
1185 generic goto if implements import inner instanceof int interface long \
1186 native new null outer package private protected public rest \
1187 return short static super switch synchronized this throw throws \
1188 transient try var void volatile while").GetBuffer()));
1189 SetupCppLexer();
1191 if (wcscmp(line, L"js") == 0)
1193 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1194 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(L"abstract boolean break byte case catch char class \
1195 const continue debugger default delete do double else enum export extends \
1196 final finally float for function goto if implements import in instanceof \
1197 int interface long native new package private protected public \
1198 return short static super switch synchronized this throw throws \
1199 transient try typeof var void volatile while with").GetBuffer()));
1200 SetupCppLexer();
1202 if ((wcscmp(line, L"pas") == 0) ||
1203 (wcscmp(line, L"dpr") == 0) ||
1204 (wcscmp(line, L"pp") == 0))
1206 SendEditor(SCI_SETLEXER, SCLEX_PASCAL);
1207 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(L"and array as begin case class const constructor \
1208 destructor div do downto else end except file finally \
1209 for function goto if implementation in inherited \
1210 interface is mod not object of on or packed \
1211 procedure program property raise record repeat \
1212 set shl shr then threadvar to try type unit \
1213 until uses var while with xor").GetBuffer()));
1214 SetupCppLexer();
1216 if ((wcscmp(line, L"as") == 0) ||
1217 (wcscmp(line, L"asc") == 0) ||
1218 (wcscmp(line, L"jsfl") == 0))
1220 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1221 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(L"add and break case catch class continue default delete do \
1222 dynamic else eq extends false finally for function ge get gt if implements import in \
1223 instanceof interface intrinsic le lt ne new not null or private public return \
1224 set static super switch this throw true try typeof undefined var void while with").GetBuffer()));
1225 SendEditor(SCI_SETKEYWORDS, 1, (LPARAM)(m_TextView.StringForControl(L"Array Arguments Accessibility Boolean Button Camera Color \
1226 ContextMenu ContextMenuItem Date Error Function Key LoadVars LocalConnection Math \
1227 Microphone Mouse MovieClip MovieClipLoader NetConnection NetStream Number Object \
1228 PrintJob Selection SharedObject Sound Stage String StyleSheet System TextField \
1229 TextFormat TextSnapshot Video Void XML XMLNode XMLSocket \
1230 _accProps _focusrect _global _highquality _parent _quality _root _soundbuftime \
1231 arguments asfunction call capabilities chr clearInterval duplicateMovieClip \
1232 escape eval fscommand getProperty getTimer getURL getVersion gotoAndPlay gotoAndStop \
1233 ifFrameLoaded Infinity -Infinity int isFinite isNaN length loadMovie loadMovieNum \
1234 loadVariables loadVariablesNum maxscroll mbchr mblength mbord mbsubstring MMExecute \
1235 NaN newline nextFrame nextScene on onClipEvent onUpdate ord parseFloat parseInt play \
1236 prevFrame prevScene print printAsBitmap printAsBitmapNum printNum random removeMovieClip \
1237 scroll set setInterval setProperty startDrag stop stopAllSounds stopDrag substring \
1238 targetPath tellTarget toggleHighQuality trace unescape unloadMovie unLoadMovieNum updateAfterEvent").GetBuffer()));
1239 SetupCppLexer();
1241 if ((wcscmp(line, L"html") == 0) ||
1242 (wcscmp(line, L"htm") == 0) ||
1243 (wcscmp(line, L"shtml") == 0) ||
1244 (wcscmp(line, L"htt") == 0) ||
1245 (wcscmp(line, L"xml") == 0) ||
1246 (wcscmp(line, L"asp") == 0) ||
1247 (wcscmp(line, L"xsl") == 0) ||
1248 (wcscmp(line, L"php") == 0) ||
1249 (wcscmp(line, L"xhtml") == 0) ||
1250 (wcscmp(line, L"phtml") == 0) ||
1251 (wcscmp(line, L"cfm") == 0) ||
1252 (wcscmp(line, L"tpl") == 0) ||
1253 (wcscmp(line, L"dtd") == 0) ||
1254 (wcscmp(line, L"hta") == 0) ||
1255 (wcscmp(line, L"htd") == 0) ||
1256 (wcscmp(line, L"wxs") == 0))
1258 SendEditor(SCI_SETLEXER, SCLEX_HTML);
1259 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(L"a abbr acronym address applet area b base basefont \
1260 bdo big blockquote body br button caption center \
1261 cite code col colgroup dd del dfn dir div dl dt em \
1262 fieldset font form frame frameset h1 h2 h3 h4 h5 h6 \
1263 head hr html i iframe img input ins isindex kbd label \
1264 legend li link map menu meta noframes noscript \
1265 object ol optgroup option p param pre q s samp \
1266 script select small span strike strong style sub sup \
1267 table tbody td textarea tfoot th thead title tr tt u ul \
1268 var xml xmlns abbr accept-charset accept accesskey action align alink \
1269 alt archive axis background bgcolor border \
1270 cellpadding cellspacing char charoff charset checked cite \
1271 class classid clear codebase codetype color cols colspan \
1272 compact content coords \
1273 data datafld dataformatas datapagesize datasrc datetime \
1274 declare defer dir disabled enctype event \
1275 face for frame frameborder \
1276 headers height href hreflang hspace http-equiv \
1277 id ismap label lang language leftmargin link longdesc \
1278 marginwidth marginheight maxlength media method multiple \
1279 name nohref noresize noshade nowrap \
1280 object onblur onchange onclick ondblclick onfocus \
1281 onkeydown onkeypress onkeyup onload onmousedown \
1282 onmousemove onmouseover onmouseout onmouseup \
1283 onreset onselect onsubmit onunload \
1284 profile prompt readonly rel rev rows rowspan rules \
1285 scheme scope selected shape size span src standby start style \
1286 summary tabindex target text title topmargin type usemap \
1287 valign value valuetype version vlink vspace width \
1288 text password checkbox radio submit reset \
1289 file hidden image").GetBuffer()));
1290 SendEditor(SCI_SETKEYWORDS, 1, (LPARAM)(m_TextView.StringForControl(L"assign audio block break catch choice clear disconnect else elseif \
1291 emphasis enumerate error exit field filled form goto grammar help \
1292 if initial link log menu meta noinput nomatch object option p paragraph \
1293 param phoneme prompt property prosody record reprompt return s say-as \
1294 script sentence subdialog submit throw transfer value var voice vxml").GetBuffer()));
1295 SendEditor(SCI_SETKEYWORDS, 2, (LPARAM)(m_TextView.StringForControl(L"accept age alphabet anchor application base beep bridge category charset \
1296 classid cond connecttimeout content contour count dest destexpr dtmf dtmfterm \
1297 duration enctype event eventexpr expr expritem fetchtimeout finalsilence \
1298 gender http-equiv id level maxage maxstale maxtime message messageexpr \
1299 method mime modal mode name namelist next nextitem ph pitch range rate \
1300 scope size sizeexpr skiplist slot src srcexpr sub time timeexpr timeout \
1301 transferaudio type value variant version volume xml:lang").GetBuffer()));
1302 SendEditor(SCI_SETKEYWORDS, 3, (LPARAM)(m_TextView.StringForControl(L"and assert break class continue def del elif \
1303 else except exec finally for from global if import in is lambda None \
1304 not or pass print raise return try while yield").GetBuffer()));
1305 SendEditor(SCI_SETKEYWORDS, 4, (LPARAM)(m_TextView.StringForControl(L"and argv as argc break case cfunction class continue declare default do \
1306 die echo else elseif empty enddeclare endfor endforeach endif endswitch \
1307 endwhile e_all e_parse e_error e_warning eval exit extends false for \
1308 foreach function global http_cookie_vars http_get_vars http_post_vars \
1309 http_post_files http_env_vars http_server_vars if include include_once \
1310 list new not null old_function or parent php_os php_self php_version \
1311 print require require_once return static switch stdclass this true var \
1312 xor virtual while __file__ __line__ __sleep __wakeup").GetBuffer()));
1314 SetAStyle(SCE_H_TAG, darkBlue);
1315 SetAStyle(SCE_H_TAGUNKNOWN, red);
1316 SetAStyle(SCE_H_ATTRIBUTE, darkBlue);
1317 SetAStyle(SCE_H_ATTRIBUTEUNKNOWN, red);
1318 SetAStyle(SCE_H_NUMBER, RGB(0x80,0,0x80));
1319 SetAStyle(SCE_H_DOUBLESTRING, RGB(0,0x80,0));
1320 SetAStyle(SCE_H_SINGLESTRING, RGB(0,0x80,0));
1321 SetAStyle(SCE_H_OTHER, RGB(0x80,0,0x80));
1322 SetAStyle(SCE_H_COMMENT, RGB(0x80,0x80,0));
1323 SetAStyle(SCE_H_ENTITY, RGB(0x80,0,0x80));
1325 SetAStyle(SCE_H_TAGEND, darkBlue);
1326 SetAStyle(SCE_H_XMLSTART, darkBlue); // <?
1327 SetAStyle(SCE_H_QUESTION, darkBlue); // <?
1328 SetAStyle(SCE_H_XMLEND, darkBlue); // ?>
1329 SetAStyle(SCE_H_SCRIPT, darkBlue); // <script
1330 SetAStyle(SCE_H_ASP, RGB(0x4F, 0x4F, 0), RGB(0xFF, 0xFF, 0)); // <% ... %>
1331 SetAStyle(SCE_H_ASPAT, RGB(0x4F, 0x4F, 0), RGB(0xFF, 0xFF, 0)); // <%@ ... %>
1333 SetAStyle(SCE_HB_DEFAULT, black);
1334 SetAStyle(SCE_HB_COMMENTLINE, darkGreen);
1335 SetAStyle(SCE_HB_NUMBER, RGB(0,0x80,0x80));
1336 SetAStyle(SCE_HB_WORD, darkBlue);
1337 SendEditor(SCI_STYLESETBOLD, SCE_HB_WORD, 1);
1338 SetAStyle(SCE_HB_STRING, RGB(0x80,0,0x80));
1339 SetAStyle(SCE_HB_IDENTIFIER, black);
1341 // This light blue is found in the windows system palette so is safe to use even in 256 colour modes.
1342 // Show the whole section of VBScript with light blue background
1343 for (int bstyle = SCE_HB_DEFAULT; bstyle <= SCE_HB_STRINGEOL; ++bstyle) {
1344 SendEditor(SCI_STYLESETFONT, bstyle,
1345 reinterpret_cast<LPARAM>(m_TextView.StringForControl(L"Lucida Console").GetBuffer()));
1346 SendEditor(SCI_STYLESETBACK, bstyle, lightBlue);
1347 // This call extends the backround colour of the last style on the line to the edge of the window
1348 SendEditor(SCI_STYLESETEOLFILLED, bstyle, 1);
1350 SendEditor(SCI_STYLESETBACK, SCE_HB_STRINGEOL, RGB(0x7F,0x7F,0xFF));
1351 SendEditor(SCI_STYLESETFONT, SCE_HB_COMMENTLINE,
1352 reinterpret_cast<LPARAM>(m_TextView.StringForControl(L"Lucida Console").GetBuffer()));
1354 SetAStyle(SCE_HBA_DEFAULT, black);
1355 SetAStyle(SCE_HBA_COMMENTLINE, darkGreen);
1356 SetAStyle(SCE_HBA_NUMBER, RGB(0,0x80,0x80));
1357 SetAStyle(SCE_HBA_WORD, darkBlue);
1358 SendEditor(SCI_STYLESETBOLD, SCE_HBA_WORD, 1);
1359 SetAStyle(SCE_HBA_STRING, RGB(0x80,0,0x80));
1360 SetAStyle(SCE_HBA_IDENTIFIER, black);
1362 // Show the whole section of ASP VBScript with bright yellow background
1363 for (int bastyle = SCE_HBA_DEFAULT; bastyle <= SCE_HBA_STRINGEOL; ++bastyle) {
1364 SendEditor(SCI_STYLESETFONT, bastyle,
1365 reinterpret_cast<LPARAM>(m_TextView.StringForControl(L"Lucida Console").GetBuffer()));
1366 SendEditor(SCI_STYLESETBACK, bastyle, RGB(0xFF, 0xFF, 0));
1367 // This call extends the backround colour of the last style on the line to the edge of the window
1368 SendEditor(SCI_STYLESETEOLFILLED, bastyle, 1);
1370 SendEditor(SCI_STYLESETBACK, SCE_HBA_STRINGEOL, RGB(0xCF,0xCF,0x7F));
1371 SendEditor(SCI_STYLESETFONT, SCE_HBA_COMMENTLINE,
1372 reinterpret_cast<LPARAM>(m_TextView.StringForControl(L"Lucida Console").GetBuffer()));
1374 // If there is no need to support embedded Javascript, the following code can be dropped.
1375 // Javascript will still be correctly processed but will be displayed in just the default style.
1377 SetAStyle(SCE_HJ_START, RGB(0x80,0x80,0));
1378 SetAStyle(SCE_HJ_DEFAULT, black);
1379 SetAStyle(SCE_HJ_COMMENT, darkGreen);
1380 SetAStyle(SCE_HJ_COMMENTLINE, darkGreen);
1381 SetAStyle(SCE_HJ_COMMENTDOC, darkGreen);
1382 SetAStyle(SCE_HJ_NUMBER, RGB(0,0x80,0x80));
1383 SetAStyle(SCE_HJ_WORD, black);
1384 SetAStyle(SCE_HJ_KEYWORD, darkBlue);
1385 SetAStyle(SCE_HJ_DOUBLESTRING, RGB(0x80,0,0x80));
1386 SetAStyle(SCE_HJ_SINGLESTRING, RGB(0x80,0,0x80));
1387 SetAStyle(SCE_HJ_SYMBOLS, black);
1389 SetAStyle(SCE_HJA_START, RGB(0x80,0x80,0));
1390 SetAStyle(SCE_HJA_DEFAULT, black);
1391 SetAStyle(SCE_HJA_COMMENT, darkGreen);
1392 SetAStyle(SCE_HJA_COMMENTLINE, darkGreen);
1393 SetAStyle(SCE_HJA_COMMENTDOC, darkGreen);
1394 SetAStyle(SCE_HJA_NUMBER, RGB(0,0x80,0x80));
1395 SetAStyle(SCE_HJA_WORD, black);
1396 SetAStyle(SCE_HJA_KEYWORD, darkBlue);
1397 SetAStyle(SCE_HJA_DOUBLESTRING, RGB(0x80,0,0x80));
1398 SetAStyle(SCE_HJA_SINGLESTRING, RGB(0x80,0,0x80));
1399 SetAStyle(SCE_HJA_SYMBOLS, black);
1401 SetAStyle(SCE_HPHP_DEFAULT, black);
1402 SetAStyle(SCE_HPHP_HSTRING, RGB(0x80,0,0x80));
1403 SetAStyle(SCE_HPHP_SIMPLESTRING, RGB(0x80,0,0x80));
1404 SetAStyle(SCE_HPHP_WORD, darkBlue);
1405 SetAStyle(SCE_HPHP_NUMBER, RGB(0,0x80,0x80));
1406 SetAStyle(SCE_HPHP_VARIABLE, red);
1407 SetAStyle(SCE_HPHP_HSTRING_VARIABLE, red);
1408 SetAStyle(SCE_HPHP_COMPLEX_VARIABLE, red);
1409 SetAStyle(SCE_HPHP_COMMENT, darkGreen);
1410 SetAStyle(SCE_HPHP_COMMENTLINE, darkGreen);
1411 SetAStyle(SCE_HPHP_OPERATOR, darkBlue);
1413 // Show the whole section of Javascript with off white background
1414 for (int jstyle = SCE_HJ_DEFAULT; jstyle <= SCE_HJ_SYMBOLS; ++jstyle) {
1415 SendEditor(SCI_STYLESETFONT, jstyle,
1416 reinterpret_cast<LPARAM>(m_TextView.StringForControl(L"Lucida Console").GetBuffer()));
1417 SendEditor(SCI_STYLESETBACK, jstyle, offWhite);
1418 SendEditor(SCI_STYLESETEOLFILLED, jstyle, 1);
1420 SendEditor(SCI_STYLESETBACK, SCE_HJ_STRINGEOL, RGB(0xDF, 0xDF, 0x7F));
1421 SendEditor(SCI_STYLESETEOLFILLED, SCE_HJ_STRINGEOL, 1);
1423 // Show the whole section of Javascript with brown background
1424 for (int jastyle = SCE_HJA_DEFAULT; jastyle <= SCE_HJA_SYMBOLS; ++jastyle) {
1425 SendEditor(SCI_STYLESETFONT, jastyle,
1426 reinterpret_cast<LPARAM>(m_TextView.StringForControl(L"Lucida Console").GetBuffer()));
1427 SendEditor(SCI_STYLESETBACK, jastyle, RGB(0xDF, 0xDF, 0x7F));
1428 SendEditor(SCI_STYLESETEOLFILLED, jastyle, 1);
1430 SendEditor(SCI_STYLESETBACK, SCE_HJA_STRINGEOL, RGB(0x0,0xAF,0x5F));
1431 SendEditor(SCI_STYLESETEOLFILLED, SCE_HJA_STRINGEOL, 1);
1434 else
1436 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1437 SetupCppLexer();
1439 SendEditor(SCI_COLOURISE, 0, -1);
1442 void CTortoiseGitBlameView::SetupCppLexer()
1444 SetAStyle(SCE_C_DEFAULT, RGB(0, 0, 0));
1445 SetAStyle(SCE_C_COMMENT, RGB(0, 0x80, 0));
1446 SetAStyle(SCE_C_COMMENTLINE, RGB(0, 0x80, 0));
1447 SetAStyle(SCE_C_COMMENTDOC, RGB(0, 0x80, 0));
1448 SetAStyle(SCE_C_COMMENTLINEDOC, RGB(0, 0x80, 0));
1449 SetAStyle(SCE_C_COMMENTDOCKEYWORD, RGB(0, 0x80, 0));
1450 SetAStyle(SCE_C_COMMENTDOCKEYWORDERROR, RGB(0, 0x80, 0));
1451 SetAStyle(SCE_C_NUMBER, RGB(0, 0x80, 0x80));
1452 SetAStyle(SCE_C_WORD, RGB(0, 0, 0x80));
1453 SendEditor(SCE_C_WORD, 1);
1454 SetAStyle(SCE_C_STRING, RGB(0x80, 0, 0x80));
1455 SetAStyle(SCE_C_IDENTIFIER, RGB(0, 0, 0));
1456 SetAStyle(SCE_C_PREPROCESSOR, RGB(0x80, 0, 0));
1457 SetAStyle(SCE_C_OPERATOR, RGB(0x80, 0x80, 0));
1458 SendEditor(SCI_SETPROPERTY, (WPARAM)"lexer.cpp.track.preprocessor", (LPARAM)"0");
1461 int CTortoiseGitBlameView::GetEncode(unsigned char *buff, int size, int *bomoffset)
1463 CFileTextLines textlines;
1464 CFileTextLines::UnicodeType type = textlines.CheckUnicodeType(buff, size);
1466 if(type == CFileTextLines::UTF8BOM)
1468 *bomoffset = 3;
1469 return CP_UTF8;
1471 if(type == CFileTextLines::UTF8)
1472 return CP_UTF8;
1474 if(type == CFileTextLines::UTF16_LE)
1475 return 1200;
1476 if (type == CFileTextLines::UTF16_LEBOM)
1478 *bomoffset = 2;
1479 return 1200;
1482 if(type == CFileTextLines::UTF16_BE)
1483 return 1201;
1484 if (type == CFileTextLines::UTF16_BEBOM)
1486 *bomoffset = 2;
1487 return 1201;
1490 return GetACP();
1493 void CTortoiseGitBlameView::ParseBlame()
1495 m_data.ParseBlameOutput(GetDocument()->m_BlameData, GetLogData()->m_pLogCache->m_HashMap, m_DateFormat, m_bRelativeTimes);
1496 CString filename = GetDocument()->m_GitPath.GetGitPathString();
1497 m_bBlameOutputContainsOtherFilenames = m_data.ContainsOnlyFilename(filename) ? FALSE : TRUE;
1500 void CTortoiseGitBlameView::MapLineToLogIndex()
1502 std::vector<int> lineToLogIndex;
1505 size_t numberOfLines = m_data.GetNumberOfLines();
1506 lineToLogIndex.reserve(numberOfLines);
1507 size_t logSize = this->GetLogData()->size();
1508 for (size_t j = 0; j < numberOfLines; ++j)
1510 CGitHash& hash = m_data.GetHash(j);
1512 int index = -2;
1513 for (size_t i = 0; i < logSize; ++i)
1515 if (hash == (*GetLogData())[i])
1517 index = (int)i;
1518 break;
1521 lineToLogIndex.push_back(index);
1523 this->m_lineToLogIndex.swap(lineToLogIndex);
1526 void CTortoiseGitBlameView::UpdateInfo(int Encode)
1528 CreateFont();
1530 InitialiseEditor();
1531 SendEditor(SCI_SETREADONLY, FALSE);
1532 SendEditor(SCI_CLEARALL);
1533 SendEditor(EM_EMPTYUNDOBUFFER);
1534 SendEditor(SCI_SETSAVEPOINT);
1535 SendEditor(SCI_CANCEL);
1536 SendEditor(SCI_SETUNDOCOLLECTION, 0);
1538 SendEditor(SCI_SETCODEPAGE, SC_CP_UTF8);
1540 int encoding = m_data.UpdateEncoding(Encode);
1542 auto numberOfLines = (int)m_data.GetNumberOfLines();
1543 if (numberOfLines > 0)
1545 CStringA text;
1546 for (int i = 0; i < numberOfLines; ++i)
1548 text += m_data.GetUtf8Line(i);
1549 text += '\n';
1551 text.TrimRight("\r\n");
1552 SendEditor(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)text);
1556 UINT nID;
1557 UINT nStyle;
1558 int cxWidth;
1559 int nIndex = ((CMainFrame *)::AfxGetApp()->GetMainWnd())->m_wndStatusBar.CommandToIndex(ID_INDICATOR_ENCODING);
1560 ((CMainFrame *)::AfxGetApp()->GetMainWnd())->m_wndStatusBar.GetPaneInfo(nIndex, nID, nStyle, cxWidth);
1561 CString sBarText;
1562 for (int i = 0; i < _countof(encodings); ++i)
1564 if (encodings[i].id == encoding)
1566 sBarText = CString(encodings[i].name);
1567 break;
1570 //calculate the width of the text
1571 CDC * pDC = ((CMainFrame *)::AfxGetApp()->GetMainWnd())->m_wndStatusBar.GetDC();
1572 if (pDC)
1574 CSize size = pDC->GetTextExtent(sBarText);
1575 ((CMainFrame *)::AfxGetApp()->GetMainWnd())->m_wndStatusBar.SetPaneInfo(nIndex, nID, nStyle, size.cx+2);
1576 ReleaseDC(pDC);
1578 ((CMainFrame *)::AfxGetApp()->GetMainWnd())->m_wndStatusBar.SetPaneText(nIndex, sBarText);
1581 #ifdef USE_TEMPFILENAME
1582 delete m_Buffer;
1583 m_Buffer = nullptr;
1585 CFile file;
1586 file.Open(this->GetDocument()->m_TempFileName,CFile::modeRead);
1588 m_Buffer = new char[file.GetLength()+4];
1589 m_Buffer[file.GetLength()] =0;
1590 m_Buffer[file.GetLength()+1] =0;
1591 m_Buffer[file.GetLength()+2] =0;
1592 m_Buffer[file.GetLength()+3] =0;
1594 file.Read(m_Buffer, file.GetLength());
1596 int bomoffset =0;
1597 int encoding = GetEncode( (unsigned char *)m_Buffer, file.GetLength(), &bomoffset);
1599 file.Close();
1600 //SendEditor(SCI_SETCODEPAGE, encoding);
1602 //SendEditor(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)(m_Buffer + bomoffset));
1603 #endif
1604 SetupLexer(GetDocument()->m_CurrentFileName);
1606 SendEditor(SCI_SETUNDOCOLLECTION, 1);
1607 SendEditor(EM_EMPTYUNDOBUFFER);
1608 SendEditor(SCI_SETSAVEPOINT);
1609 SendEditor(SCI_GOTOPOS, 0);
1610 SendEditor(SCI_SETSCROLLWIDTHTRACKING, TRUE);
1611 SendEditor(SCI_SETREADONLY, TRUE);
1613 GetBlameWidth();
1614 CRect rect;
1615 this->GetClientRect(rect);
1616 //this->m_TextView.GetWindowRect(rect);
1617 //this->m_TextView.ScreenToClient(rect);
1618 rect.left=this->m_blamewidth;
1619 this->m_TextView.MoveWindow(rect);
1621 this->Invalidate();
1624 CString CTortoiseGitBlameView::ResolveCommitFile(int line)
1626 return ResolveCommitFile(m_data.GetFilename(line));
1629 CString CTortoiseGitBlameView::ResolveCommitFile(const CString& path)
1631 if (path.IsEmpty())
1633 return ((CMainFrame*)::AfxGetApp()->GetMainWnd())->GetActiveView()->GetDocument()->GetPathName();
1635 else
1637 return g_Git.CombinePath(path);
1641 COLORREF CTortoiseGitBlameView::GetLineColor(size_t line)
1643 if (m_colorage && line < m_lineToLogIndex.size())
1645 int logIndex = m_lineToLogIndex[line];
1646 if (logIndex >= 0)
1648 int slider = (int)((GetLogData()->size() - logIndex) * 100 / (GetLogData()->size() + 1));
1649 return InterColor(DWORD(m_regOldLinesColor), DWORD(m_regNewLinesColor), slider);
1652 return m_windowcolor;
1655 CGitBlameLogList * CTortoiseGitBlameView::GetLogList()
1657 return &(GetDocument()->GetMainFrame()->m_wndOutput.m_LogList);
1661 CLogDataVector * CTortoiseGitBlameView::GetLogData()
1663 return &(GetDocument()->GetMainFrame()->m_wndOutput.m_LogList.m_logEntries);
1666 void CTortoiseGitBlameView::OnSciPainted(NMHDR *,LRESULT *)
1668 this->Invalidate();
1671 void CTortoiseGitBlameView::OnLButtonDown(UINT nFlags,CPoint point)
1673 int line = GetLineUnderCursor(point);
1674 if ((size_t)line < m_data.GetNumberOfLines())
1676 SetSelectedLine(line);
1677 if (m_data.GetHash(line) != m_SelectedHash)
1679 m_SelectedHash = m_data.GetHash(line);
1681 int logIndex = m_lineToLogIndex[line];
1682 if (logIndex >= 0)
1684 this->GetLogList()->SetItemState(logIndex, LVIS_SELECTED, LVIS_SELECTED);
1685 this->GetLogList()->EnsureVisible(logIndex, FALSE);
1687 else
1689 GitRevLoglist* pRev = m_data.GetRev(line, GetLogData()->m_pLogCache->m_HashMap);
1690 this->GetDocument()->GetMainFrame()->m_wndProperties.UpdateProperties(pRev);
1693 else
1695 m_SelectedHash.Empty();
1697 this->Invalidate();
1698 this->m_TextView.Invalidate();
1701 else
1703 SetSelectedLine(-1);
1706 CView::OnLButtonDown(nFlags,point);
1709 void CTortoiseGitBlameView::OnSciGetBkColor(NMHDR* hdr, LRESULT* /*result*/)
1711 SCNotification *notification=reinterpret_cast<SCNotification *>(hdr);
1713 if (notification->line < (Sci_Position)m_data.GetNumberOfLines())
1715 if (m_data.GetHash(notification->line) == this->m_SelectedHash)
1716 notification->lParam = m_selectedauthorcolor;
1717 else
1718 notification->lParam = GetLineColor(notification->line);
1722 void CTortoiseGitBlameView::FocusOn(GitRevLoglist* pRev)
1724 this->GetDocument()->GetMainFrame()->m_wndProperties.UpdateProperties(pRev);
1726 this->Invalidate();
1728 if (m_SelectedHash != pRev->m_CommitHash) {
1729 m_SelectedHash = pRev->m_CommitHash;
1730 int line = m_data.FindFirstLine(m_SelectedHash, 0);
1731 if (line >= 0)
1733 GotoLine(line + 1);
1734 m_TextView.Invalidate();
1735 return;
1737 SendEditor(SCI_SETSEL, INT_MAX, -1);
1741 void CTortoiseGitBlameView::OnMouseHover(UINT /*nFlags*/, CPoint point)
1743 int line = GetLineUnderCursor(point);
1744 if (m_data.IsValidLine(line))
1746 if (line != m_MouseLine)
1748 m_MouseLine = line;
1749 GitRev *pRev = nullptr;
1750 int logIndex = m_lineToLogIndex[line];
1751 if (logIndex >= 0)
1752 pRev = &GetLogData()->GetGitRevAt(logIndex);
1753 else
1754 pRev = m_data.GetRev(line, GetLogData()->m_pLogCache->m_HashMap);
1756 if (!pRev)
1757 return;
1759 CString body = pRev->GetBody();
1760 int maxLine = 15;
1761 int iline = 0;
1762 int pos = 0;
1763 while (iline++ < maxLine)
1765 int pos2 = body.Find(L'\n', pos);
1766 if (pos2 < 0)
1767 break;
1768 int lineLength = pos2 - pos - 1;
1769 pos = pos2 + 1;
1770 iline += lineLength / 70;
1773 CString filename;
1774 if ((m_bShowCompleteLog && m_bFollowRenames && !m_bOnlyFirstParent) || !BlameIsLimitedToOneFilename(m_dwDetectMovedOrCopiedLines) || m_bBlameOutputContainsOtherFilenames)
1775 filename.Format(L"%s: %s\n", (LPCTSTR)m_sFileName, (LPCTSTR)m_data.GetFilename(line));
1777 CString str;
1778 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,
1779 (LPCTSTR)m_sAuthor, (LPCTSTR)pRev->GetAuthorName(), (LPCTSTR)pRev->GetAuthorEmail(),
1780 (LPCTSTR)m_sDate, (LPCTSTR)CLoglistUtils::FormatDateAndTime(pRev->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
1781 (LPCTSTR)m_sMessage, (LPCTSTR)pRev->GetSubject(),
1782 iline <= maxLine ? (LPCTSTR)body : (body.Left(pos) + L"\n...................."));
1784 m_ToolTip.Pop();
1785 m_ToolTip.AddTool(this, str);
1787 Invalidate();
1792 void CTortoiseGitBlameView::OnMouseMove(UINT /*nFlags*/, CPoint /*point*/)
1794 TRACKMOUSEEVENT tme;
1795 tme.cbSize=sizeof(TRACKMOUSEEVENT);
1796 tme.dwFlags=TME_HOVER|TME_LEAVE;
1797 tme.hwndTrack=this->m_hWnd;
1798 tme.dwHoverTime=1;
1799 TrackMouseEvent(&tme);
1800 Invalidate();
1803 void CTortoiseGitBlameView::OnMouseLeave()
1805 if (m_MouseLine == -1)
1806 return;
1808 m_MouseLine = -1;
1809 Invalidate();
1812 BOOL CTortoiseGitBlameView::PreTranslateMessage(MSG* pMsg)
1814 if (m_ToolTip.GetSafeHwnd())
1815 m_ToolTip.RelayEvent(pMsg);
1816 return CView::PreTranslateMessage(pMsg);
1819 void CTortoiseGitBlameView::OnEditFind()
1821 if (m_pFindDialog)
1822 return;
1824 m_pFindDialog=new CFindReplaceDialog();
1826 CString oneline = m_sFindText;
1827 if (m_TextView.Call(SCI_GETSELECTIONSTART) != m_TextView.Call(SCI_GETSELECTIONEND))
1829 LRESULT bufsize = m_TextView.Call(SCI_GETSELECTIONEND) - m_TextView.Call(SCI_GETSELECTIONSTART);
1830 auto linebuf = std::make_unique<char[]>(bufsize + 1);
1831 SecureZeroMemory(linebuf.get(), bufsize + 1);
1832 SendEditor(SCI_GETSELTEXT, 0, (LPARAM)linebuf.get());
1833 oneline = m_TextView.StringFromControl(linebuf.get());
1836 DWORD flags = FR_DOWN | FR_HIDEWHOLEWORD;
1837 if (theApp.GetInt(L"FindMatchCase"))
1838 flags |= FR_MATCHCASE;
1840 m_pFindDialog->Create(TRUE, oneline, nullptr, flags, this);
1843 void CTortoiseGitBlameView::OnEditGoto()
1845 CEditGotoDlg dlg;
1846 if(dlg.DoModal()==IDOK)
1848 this->GotoLine(dlg.m_LineNumber);
1852 LRESULT CTortoiseGitBlameView::OnFindDialogMessage(WPARAM /*wParam*/, LPARAM /*lParam*/)
1854 ASSERT(m_pFindDialog);
1856 // If the FR_DIALOGTERM flag is set,
1857 // invalidate the handle identifying the dialog box.
1858 if (m_pFindDialog->IsTerminating())
1860 m_pFindDialog = nullptr;
1861 return 0;
1864 // If the FR_FINDNEXT flag is set,
1865 // call the application-defined search routine
1866 // to search for the requested string.
1867 if(m_pFindDialog->FindNext())
1869 m_bMatchCase = !!(m_pFindDialog->MatchCase());
1870 m_sFindText = m_pFindDialog->GetFindString();
1872 theApp.WriteInt(L"FindMatchCase", m_bMatchCase ? 1 : 0);
1873 theApp.WriteString(L"FindString", m_sFindText);
1875 DoSearch(m_pFindDialog->SearchDown() ? CTortoiseGitBlameData::SearchNext : CTortoiseGitBlameData::SearchPrevious);
1878 return 0;
1881 void CTortoiseGitBlameView::OnViewNext()
1883 int startline = (int)SendEditor(SCI_GETFIRSTVISIBLELINE);
1884 int line = m_data.FindNextLine(this->m_SelectedHash, (int)SendEditor(SCI_GETFIRSTVISIBLELINE), false);
1885 if(line >= 0)
1886 SendEditor(SCI_LINESCROLL, 0, line - startline - 2);
1888 void CTortoiseGitBlameView::OnViewPrev()
1890 int startline = (int)SendEditor(SCI_GETFIRSTVISIBLELINE);
1891 int line = m_data.FindNextLine(this->m_SelectedHash, (int)SendEditor(SCI_GETFIRSTVISIBLELINE), true);
1892 if(line >= 0)
1893 SendEditor(SCI_LINESCROLL, 0, line - startline - 2);
1896 void CTortoiseGitBlameView::OnViewToggleAuthor()
1898 m_bShowAuthor = ! m_bShowAuthor;
1900 theApp.WriteInt(L"ShowAuthor", m_bShowAuthor);
1902 CRect rect;
1903 this->GetClientRect(&rect);
1904 rect.left=GetBlameWidth();
1906 m_TextView.MoveWindow(&rect);
1909 void CTortoiseGitBlameView::OnUpdateViewToggleAuthor(CCmdUI *pCmdUI)
1911 pCmdUI->SetCheck(m_bShowAuthor);
1914 void CTortoiseGitBlameView::OnViewToggleDate()
1916 m_bShowDate = ! m_bShowDate;
1918 theApp.WriteInt(L"ShowDate", m_bShowDate);
1920 CRect rect;
1921 this->GetClientRect(&rect);
1922 rect.left=GetBlameWidth();
1924 m_TextView.MoveWindow(&rect);
1927 void CTortoiseGitBlameView::OnUpdateViewToggleDate(CCmdUI *pCmdUI)
1929 pCmdUI->SetCheck(m_bShowDate);
1932 void CTortoiseGitBlameView::OnViewToggleShowFilename()
1934 m_bShowFilename = ! m_bShowFilename;
1936 theApp.WriteInt(L"ShowFilename", m_bShowFilename);
1938 CRect rect;
1939 this->GetClientRect(&rect);
1940 rect.left = GetBlameWidth();
1942 m_TextView.MoveWindow(&rect);
1945 void CTortoiseGitBlameView::OnUpdateViewToggleShowFilename(CCmdUI *pCmdUI)
1947 pCmdUI->SetCheck(m_bShowFilename);
1950 void CTortoiseGitBlameView::OnViewToggleShowOriginalLineNumber()
1952 m_bShowOriginalLineNumber = ! m_bShowOriginalLineNumber;
1954 theApp.WriteInt(L"ShowOriginalLineNumber", m_bShowOriginalLineNumber);
1956 CRect rect;
1957 this->GetClientRect(&rect);
1958 rect.left = GetBlameWidth();
1960 m_TextView.MoveWindow(&rect);
1963 void CTortoiseGitBlameView::OnUpdateViewToggleShowOriginalLineNumber(CCmdUI *pCmdUI)
1965 pCmdUI->SetCheck(m_bShowOriginalLineNumber);
1968 void CTortoiseGitBlameView::OnViewDetectMovedOrCopiedLines(DWORD dwDetectMovedOrCopiedLines)
1970 m_dwDetectMovedOrCopiedLines = dwDetectMovedOrCopiedLines;
1972 theApp.DoWaitCursor(1);
1974 theApp.WriteInt(L"DetectMovedOrCopiedLines", m_dwDetectMovedOrCopiedLines);
1976 auto document = static_cast<CTortoiseGitBlameDoc*>(m_pDocument);
1977 if (!document->m_CurrentFileName.IsEmpty())
1979 document->m_lLine = (int)SendEditor(SCI_GETFIRSTVISIBLELINE) + 1;
1980 theApp.m_pDocManager->OnFileNew();
1981 document->OnOpenDocument(document->m_CurrentFileName, document->m_Rev);
1983 theApp.DoWaitCursor(-1);
1986 void CTortoiseGitBlameView::OnViewDetectMovedOrCopiedLinesToggleDisabled()
1988 OnViewDetectMovedOrCopiedLines(BLAME_DETECT_MOVED_OR_COPIED_LINES_DISABLED);
1991 void CTortoiseGitBlameView::OnUpdateViewDetectMovedOrCopiedLinesToggleDisabled(CCmdUI *pCmdUI)
1993 pCmdUI->SetRadio(m_dwDetectMovedOrCopiedLines == BLAME_DETECT_MOVED_OR_COPIED_LINES_DISABLED);
1996 void CTortoiseGitBlameView::OnViewDetectMovedOrCopiedLinesToggleWithinFile()
1998 OnViewDetectMovedOrCopiedLines(BLAME_DETECT_MOVED_OR_COPIED_LINES_WITHIN_FILE);
2001 void CTortoiseGitBlameView::OnUpdateViewDetectMovedOrCopiedLinesToggleWithinFile(CCmdUI *pCmdUI)
2003 pCmdUI->SetRadio(m_dwDetectMovedOrCopiedLines == BLAME_DETECT_MOVED_OR_COPIED_LINES_WITHIN_FILE);
2006 void CTortoiseGitBlameView::OnViewDetectMovedOrCopiedLinesToggleFromModifiedFiles()
2008 OnViewDetectMovedOrCopiedLines(BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_MODIFIED_FILES);
2011 void CTortoiseGitBlameView::OnUpdateViewDetectMovedOrCopiedLinesToggleFromModifiedFiles(CCmdUI *pCmdUI)
2013 pCmdUI->SetRadio(m_dwDetectMovedOrCopiedLines == BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_MODIFIED_FILES);
2016 void CTortoiseGitBlameView::OnViewDetectMovedOrCopiedLinesToggleFromExistingFilesAtFileCreation()
2018 OnViewDetectMovedOrCopiedLines(BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES_AT_FILE_CREATION);
2021 void CTortoiseGitBlameView::OnUpdateViewDetectMovedOrCopiedLinesToggleFromExistingFilesAtFileCreation(CCmdUI *pCmdUI)
2023 pCmdUI->SetRadio(m_dwDetectMovedOrCopiedLines == BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES_AT_FILE_CREATION);
2026 void CTortoiseGitBlameView::OnViewDetectMovedOrCopiedLinesToggleFromExistingFiles()
2028 OnViewDetectMovedOrCopiedLines(BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES);
2031 void CTortoiseGitBlameView::OnUpdateViewDetectMovedOrCopiedLinesToggleFromExistingFiles(CCmdUI *pCmdUI)
2033 pCmdUI->SetRadio(m_dwDetectMovedOrCopiedLines == BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES);
2036 void CTortoiseGitBlameView::ReloadDocument()
2038 theApp.DoWaitCursor(1);
2039 auto document = static_cast<CTortoiseGitBlameDoc*>(m_pDocument);
2040 if (!document->m_CurrentFileName.IsEmpty())
2042 document->m_lLine = (int)SendEditor(SCI_GETFIRSTVISIBLELINE) + 1;
2043 theApp.m_pDocManager->OnFileNew();
2044 document->OnOpenDocument(document->m_CurrentFileName, document->m_Rev);
2046 theApp.DoWaitCursor(-1);
2049 void CTortoiseGitBlameView::OnViewToggleIgnoreWhitespace()
2051 m_bIgnoreWhitespace = ! m_bIgnoreWhitespace;
2053 theApp.WriteInt(L"IgnoreWhitespace", m_bIgnoreWhitespace ? 1 : 0);
2055 ReloadDocument();
2058 void CTortoiseGitBlameView::OnUpdateViewToggleIgnoreWhitespace(CCmdUI *pCmdUI)
2060 pCmdUI->SetCheck(m_bIgnoreWhitespace);
2063 void CTortoiseGitBlameView::OnViewToggleShowCompleteLog()
2065 m_bShowCompleteLog = ! m_bShowCompleteLog;
2067 theApp.WriteInt(L"ShowCompleteLog", m_bShowCompleteLog ? 1 : 0);
2069 ReloadDocument();
2072 void CTortoiseGitBlameView::OnUpdateViewToggleOnlyFirstParent(CCmdUI* pCmdUI)
2074 pCmdUI->SetCheck(m_bOnlyFirstParent);
2077 void CTortoiseGitBlameView::OnViewToggleOnlyFirstParent()
2079 m_bOnlyFirstParent = !m_bOnlyFirstParent;
2081 theApp.WriteInt(L"OnlyFirstParent", m_bOnlyFirstParent ? 1 : 0);
2083 ReloadDocument();
2086 void CTortoiseGitBlameView::OnUpdateViewToggleShowCompleteLog(CCmdUI *pCmdUI)
2088 pCmdUI->Enable(BlameIsLimitedToOneFilename(m_dwDetectMovedOrCopiedLines) && !m_bOnlyFirstParent);
2089 pCmdUI->SetCheck(m_bShowCompleteLog && BlameIsLimitedToOneFilename(m_dwDetectMovedOrCopiedLines) && !m_bOnlyFirstParent);
2092 void CTortoiseGitBlameView::OnViewToggleFollowRenames()
2094 m_bFollowRenames = ! m_bFollowRenames;
2096 theApp.WriteInt(L"FollowRenames", m_bFollowRenames ? 1 : 0);
2098 ReloadDocument();
2101 void CTortoiseGitBlameView::OnUpdateViewToggleFollowRenames(CCmdUI *pCmdUI)
2103 pCmdUI->Enable(m_bShowCompleteLog && BlameIsLimitedToOneFilename(m_dwDetectMovedOrCopiedLines) && !m_bOnlyFirstParent);
2104 pCmdUI->SetCheck(m_bFollowRenames && m_bShowCompleteLog && BlameIsLimitedToOneFilename(m_dwDetectMovedOrCopiedLines) && !m_bOnlyFirstParent);
2107 void CTortoiseGitBlameView::OnViewToggleColorByAge()
2109 m_colorage = ! m_colorage;
2111 theApp.WriteInt(L"ColorAge", m_colorage);
2113 m_TextView.Invalidate();
2116 void CTortoiseGitBlameView::OnUpdateViewToggleColorByAge(CCmdUI *pCmdUI)
2118 pCmdUI->SetCheck(m_colorage);
2121 void CTortoiseGitBlameView::OnViewToggleLexer()
2123 m_bLexer = !m_bLexer;
2125 theApp.WriteInt(L"EnableLexer", m_bLexer);
2127 InitialiseEditor();
2128 SetupLexer(GetDocument()->m_CurrentFileName);
2129 this->Invalidate();
2132 void CTortoiseGitBlameView::OnUpdateViewToggleLexer(CCmdUI *pCmdUI)
2134 pCmdUI->SetCheck(m_bLexer);
2137 void CTortoiseGitBlameView::OnViewWrapLongLines()
2139 m_bWrapLongLines = !m_bWrapLongLines;
2141 theApp.WriteInt(L"WrapLongLines", m_bWrapLongLines);
2143 if (m_bWrapLongLines)
2144 SendEditor(SCI_SETWRAPMODE, SC_WRAP_WORD);
2145 else
2146 SendEditor(SCI_SETWRAPMODE, SC_WRAP_NONE);
2149 void CTortoiseGitBlameView::OnUpdateViewWrapLongLines(CCmdUI* pCmdUI)
2151 pCmdUI->SetCheck(m_bWrapLongLines);
2154 void CTortoiseGitBlameView::OnUpdateViewCopyToClipboard(CCmdUI *pCmdUI)
2156 CWnd * wnd = GetFocus();
2157 if (wnd == GetLogList())
2158 pCmdUI->Enable(GetLogList()->GetSelectedCount() > 0);
2159 else if (wnd)
2161 if (CString(wnd->GetRuntimeClass()->m_lpszClassName) == L"CMFCPropertyGridCtrl")
2163 CMFCPropertyGridCtrl *grid = (CMFCPropertyGridCtrl *)wnd;
2164 pCmdUI->Enable(grid->GetCurSel() && !grid->GetCurSel()->IsGroup() && !CString(grid->GetCurSel()->GetValue()).IsEmpty());
2166 else
2167 pCmdUI->Enable(m_TextView.Call(SCI_GETSELECTIONSTART) != m_TextView.Call(SCI_GETSELECTIONEND));
2169 else
2170 pCmdUI->Enable(FALSE);
2173 void CTortoiseGitBlameView::OnSysColorChange()
2175 __super::OnSysColorChange();
2176 m_windowcolor = ::GetSysColor(COLOR_WINDOW);
2177 m_textcolor = ::GetSysColor(COLOR_WINDOWTEXT);
2178 m_texthighlightcolor = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
2179 m_mouserevcolor = InterColor(m_windowcolor, m_textcolor, 20);
2180 m_mouseauthorcolor = InterColor(m_windowcolor, m_textcolor, 10);
2181 m_selectedrevcolor = ::GetSysColor(COLOR_HIGHLIGHT);
2182 m_selectedauthorcolor = InterColor(m_selectedrevcolor, m_texthighlightcolor, 35);
2183 InitialiseEditor();
2184 SetupLexer(GetDocument()->m_CurrentFileName);
2187 ULONG CTortoiseGitBlameView::GetGestureStatus(CPoint ptTouch)
2189 int line = GetLineUnderCursor(ptTouch);
2190 if (m_data.IsValidLine(line))
2191 return 0;
2192 return __super::GetGestureStatus(ptTouch);