TGitBlame: Allow to search both directions
[TortoiseGit.git] / src / TortoiseGitBlame / TortoiseGitBlameView.cpp
blob1c7e4529f3b9ed21ce2a938546c5a060e9daeebf
1 // TortoiseGitBlame - a Viewer for Git Blames
3 // Copyright (C) 2008-2017 - 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_bBlameOuputContainsOtherFilenames = FALSE;
170 m_bWrapLongLines = !!theApp.GetInt(L"WrapLongLines", 0);
172 m_FindDialogMessage = ::RegisterWindowMessage(FINDMSGSTRING);
173 // get short/long datetime setting from registry
174 DWORD RegUseShortDateFormat = CRegDWORD(L"Software\\TortoiseGit\\LogDateFormat", TRUE);
175 if ( RegUseShortDateFormat )
177 m_DateFormat = DATE_SHORTDATE;
179 else
181 m_DateFormat = DATE_LONGDATE;
183 // get relative time display setting from registry
184 DWORD regRelativeTimes = CRegDWORD(L"Software\\TortoiseGit\\RelativeTimes", FALSE);
185 m_bRelativeTimes = (regRelativeTimes != 0);
187 m_sRev.LoadString(IDS_LOG_REVISION);
188 m_sFileName.LoadString(IDS_FILENAME);
189 m_sAuthor.LoadString(IDS_LOG_AUTHOR);
190 m_sDate.LoadString(IDS_LOG_DATE);
191 m_sMessage.LoadString(IDS_LOG_MESSAGE);
194 CTortoiseGitBlameView::~CTortoiseGitBlameView()
196 #ifdef USE_TEMPFILENAME
197 delete m_Buffer;
198 m_Buffer = nullptr;
199 #endif
201 struct EncodingUnit
203 int id;
204 char *name;
207 static EncodingUnit encodings[] = {
208 {1250, "windows-1250"}, //IDM_FORMAT_WIN_1250
209 {1251, "windows-1251"}, //IDM_FORMAT_WIN_1251
210 {1252, "windows-1252"}, //IDM_FORMAT_WIN_1252
211 {1253, "windows-1253"}, //IDM_FORMAT_WIN_1253
212 {1254, "windows-1254"}, //IDM_FORMAT_WIN_1254
213 {1255, "windows-1255"}, //IDM_FORMAT_WIN_1255
214 {1256, "windows-1256"}, //IDM_FORMAT_WIN_1256
215 {1257, "windows-1257"}, //IDM_FORMAT_WIN_1257
216 {1258, "windows-1258"}, //IDM_FORMAT_WIN_1258
217 {28591, "latin1 ISO_8859-1 ISO-8859-1 CP819 IBM819 csISOLatin1 iso-ir-100 l1"}, //IDM_FORMAT_ISO_8859_1
218 {28592, "latin2 ISO_8859-2 ISO-8859-2 csISOLatin2 iso-ir-101 l2"}, //IDM_FORMAT_ISO_8859_2
219 {28593, "latin3 ISO_8859-3 ISO-8859-3 csISOLatin3 iso-ir-109 l3"}, //IDM_FORMAT_ISO_8859_3
220 {28594, "latin4 ISO_8859-4 ISO-8859-4 csISOLatin4 iso-ir-110 l4"}, //IDM_FORMAT_ISO_8859_4
221 {28595, "cyrillic ISO_8859-5 ISO-8859-5 csISOLatinCyrillic iso-ir-144"}, //IDM_FORMAT_ISO_8859_5
222 {28596, "arabic ISO_8859-6 ISO-8859-6 csISOLatinArabic iso-ir-127 ASMO-708 ECMA-114"}, //IDM_FORMAT_ISO_8859_6
223 {28597, "greek ISO_8859-7 ISO-8859-7 csISOLatinGreek greek8 iso-ir-126 ELOT_928 ECMA-118"}, //IDM_FORMAT_ISO_8859_7
224 {28598, "hebrew ISO_8859-8 ISO-8859-8 csISOLatinHebrew iso-ir-138"}, //IDM_FORMAT_ISO_8859_8
225 {28599, "latin5 ISO_8859-9 ISO-8859-9 csISOLatin5 iso-ir-148 l5"}, //IDM_FORMAT_ISO_8859_9
226 {28600, "latin6 ISO_8859-10 ISO-8859-10 csISOLatin6 iso-ir-157 l6"}, //IDM_FORMAT_ISO_8859_10
227 {28601, "ISO_8859-11 ISO-8859-11"}, //IDM_FORMAT_ISO_8859_11
228 {28603, "ISO_8859-13 ISO-8859-13"}, //IDM_FORMAT_ISO_8859_13
229 {28604, "iso-celtic latin8 ISO_8859-14 ISO-8859-14 18 iso-ir-199"}, //IDM_FORMAT_ISO_8859_14
230 {28605, "Latin-9 ISO_8859-15 ISO-8859-15"}, //IDM_FORMAT_ISO_8859_15
231 {28606, "latin10 ISO_8859-16 ISO-8859-16 110 iso-ir-226"}, //IDM_FORMAT_ISO_8859_16
232 {437, "IBM437 cp437 437 csPC8CodePage437"}, //IDM_FORMAT_DOS_437
233 {720, "IBM720 cp720 oem720 720"}, //IDM_FORMAT_DOS_720
234 {737, "IBM737 cp737 oem737 737"}, //IDM_FORMAT_DOS_737
235 {775, "IBM775 cp775 oem775 775"}, //IDM_FORMAT_DOS_775
236 {850, "IBM850 cp850 oem850 850"}, //IDM_FORMAT_DOS_850
237 {852, "IBM852 cp852 oem852 852"}, //IDM_FORMAT_DOS_852
238 {855, "IBM855 cp855 oem855 855 csIBM855"}, //IDM_FORMAT_DOS_855
239 {857, "IBM857 cp857 oem857 857"}, //IDM_FORMAT_DOS_857
240 {858, "IBM858 cp858 oem858 858"}, //IDM_FORMAT_DOS_858
241 {860, "IBM860 cp860 oem860 860"}, //IDM_FORMAT_DOS_860
242 {861, "IBM861 cp861 oem861 861"}, //IDM_FORMAT_DOS_861
243 {862, "IBM862 cp862 oem862 862"}, //IDM_FORMAT_DOS_862
244 {863, "IBM863 cp863 oem863 863"}, //IDM_FORMAT_DOS_863
245 {865, "IBM865 cp865 oem865 865"}, //IDM_FORMAT_DOS_865
246 {866, "IBM866 cp866 oem866 866"}, //IDM_FORMAT_DOS_866
247 {869, "IBM869 cp869 oem869 869"}, //IDM_FORMAT_DOS_869
248 {950, "big5 csBig5"}, //IDM_FORMAT_BIG5
249 {936, "gb2312 gbk csGB2312"}, //IDM_FORMAT_GB2312
250 {932, "Shift_JIS MS_Kanji csShiftJIS csWindows31J"}, //IDM_FORMAT_SHIFT_JIS
251 {949, "windows-949 korean"}, //IDM_FORMAT_KOREAN_WIN
252 {51949, "euc-kr csEUCKR"}, //IDM_FORMAT_EUC_KR
253 {874, "tis-620"}, //IDM_FORMAT_TIS_620
254 {10007, "x-mac-cyrillic xmaccyrillic"}, //IDM_FORMAT_MAC_CYRILLIC
255 {21866, "koi8_u"}, //IDM_FORMAT_KOI8U_CYRILLIC
256 {20866, "koi8_r csKOI8R"}, //IDM_FORMAT_KOI8R_CYRILLIC
257 {65001, "UTF-8"}, //IDM_FORMAT_UTF8
258 {1200, "UTF-16 LE"}, //IDM_FORMAT_UTF16LE
259 {1201, "UTF-16 BE"}, //IDM_FORMAT_UTF16BE
261 void CTortoiseGitBlameView::OnChangeEncode(UINT nId)
263 if(nId >= IDM_FORMAT_ENCODE && nId <= IDM_FORMAT_ENCODE_END)
264 this->UpdateInfo(encodings[nId - IDM_FORMAT_ENCODE].id);
266 int CTortoiseGitBlameView::OnCreate(LPCREATESTRUCT lpcs)
268 CRect rect,rect1;
269 this->GetWindowRect(&rect1);
270 rect.left=m_blamewidth+LOCATOR_WIDTH;
271 rect.right=rect.Width();
272 rect.top=0;
273 rect.bottom=rect.Height();
274 if (!m_TextView.Create(L"Scintilla", L"source", 0, rect, this, IDC_SCINTILLA, 0))
276 TRACE0("Failed to create view\n");
277 return -1; // fail to create
279 m_TextView.Init(-1);
280 m_TextView.ShowWindow( SW_SHOW);
281 CreateFont();
282 SendEditor(SCI_SETREADONLY, TRUE);
283 m_ToolTip.Create(this->GetParent());
285 ::AfxGetApp()->GetMainWnd();
286 return CView::OnCreate(lpcs);
289 void CTortoiseGitBlameView::OnSize(UINT /*nType*/, int cx, int cy)
291 CRect rect;
292 rect.left=m_blamewidth;
293 rect.right=cx;
294 rect.top=0;
295 rect.bottom=cy;
297 m_TextView.MoveWindow(&rect);
299 BOOL CTortoiseGitBlameView::PreCreateWindow(CREATESTRUCT& cs)
301 return CView::PreCreateWindow(cs);
304 // CTortoiseGitBlameView drawing
306 BOOL CTortoiseGitBlameView::OnEraseBkgnd(CDC* /*pDC*/)
308 return TRUE;
311 void CTortoiseGitBlameView::OnDraw(CDC* pDC)
313 CTortoiseGitBlameDoc* pDoc = GetDocument();
314 ASSERT_VALID(pDoc);
315 if (!pDoc)
316 return;
318 CMemDC myDC(*pDC, this);
319 RECT rc;
320 GetClientRect(&rc);
321 myDC.GetDC().FillSolidRect(&rc, m_windowcolor);
322 DrawBlame(myDC.GetDC());
323 DrawLocatorBar(myDC.GetDC());
327 // CTortoiseGitBlameView printing
330 void CTortoiseGitBlameView::OnFilePrintPreview()
332 AFXPrintPreview(this);
335 BOOL CTortoiseGitBlameView::OnPreparePrinting(CPrintInfo* pInfo)
337 // default preparation
338 return DoPreparePrinting(pInfo);
341 void CTortoiseGitBlameView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
343 // TODO: add extra initialization before printing
346 void CTortoiseGitBlameView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
348 // TODO: add cleanup after printing
351 int CTortoiseGitBlameView::GetLineUnderCursor(CPoint point)
353 int firstvisibleline = (int)SendEditor(SCI_GETFIRSTVISIBLELINE);
354 int line = (int)SendEditor(SCI_DOCLINEFROMVISIBLE, firstvisibleline);
355 int linesonscreen = (int)SendEditor(SCI_LINESONSCREEN) + 1;
356 int height = (int)SendEditor(SCI_TEXTHEIGHT);
358 int i = 0, y = 0;
359 for (i = line; y <= point.y && i < (line + linesonscreen); ++i)
361 auto wrapcount = (int)SendEditor(SCI_WRAPCOUNT, i);
362 if (wrapcount > 1)
364 if (i == line)
365 wrapcount -= (int)SendEditor(SCI_DOCLINEFROMVISIBLE, firstvisibleline + wrapcount - 1) - (int)SendEditor(SCI_DOCLINEFROMVISIBLE, firstvisibleline);
366 linesonscreen -= wrapcount - 1;
368 y += height * wrapcount;
370 return i - 1;
373 void CTortoiseGitBlameView::OnRButtonUp(UINT /*nFlags*/, CPoint point)
375 int line = GetLineUnderCursor(point);
376 if (m_data.IsValidLine(line))
378 m_MouseLine = line;
379 ClientToScreen(&point);
381 CGitHash hash = m_data.GetHash(line);
382 CString hashStr = hash.ToString();
384 GitRevLoglist* pRev = nullptr;
385 int logIndex = m_lineToLogIndex[line];
386 if (logIndex >= 0)
387 pRev = &GetLogData()->GetGitRevAt(logIndex);
388 else
390 pRev = m_data.GetRev(line, GetLogData()->m_pLogCache->m_HashMap);
391 if (pRev && pRev->m_ParentHash.empty())
393 if (pRev->GetParentFromHash(pRev->m_CommitHash))
394 MessageBox(pRev->GetLastErr(), L"TortoiseGit", MB_ICONERROR);
398 if (!pRev)
399 return;
401 CIconMenu popup;
402 CIconMenu blamemenu, diffmenu;
404 if (!popup.CreatePopupMenu())
405 return;
407 // Now find the relevant parent commits, they must contain the file which is blamed to be the source of the selected line,
408 // otherwise there is no previous file to compare to (only another previous revision).
410 GIT_REV_LIST parentHashWithFile;
411 std::vector<CString> parentFilename;
414 CTGitPath path(m_data.GetFilename(line));
415 const CTGitPathList& files = pRev->GetFiles(nullptr);
416 for (int j = 0, j_size = files.GetCount(); j < j_size; ++j)
418 const CTGitPath &file = files[j];
419 if (file.IsEquivalentTo(path))
421 if (!(file.m_ParentNo & MERGE_MASK))
423 int action = file.m_Action;
424 // ignore (action & CTGitPath::LOGACTIONS_ADDED), as then there is nothing to blame/diff
425 // ignore (action & CTGitPath::LOGACTIONS_DELETED), should never happen as the file must exist
426 if (action & (CTGitPath::LOGACTIONS_MODIFIED | CTGitPath::LOGACTIONS_REPLACED))
428 int parentNo = file.m_ParentNo & PARENT_MASK;
429 if (parentNo >= 0 && (size_t)parentNo < pRev->m_ParentHash.size())
431 parentHashWithFile.push_back(pRev->m_ParentHash[parentNo]);
432 parentFilename.push_back((action & CTGitPath::LOGACTIONS_REPLACED) ? file.GetGitOldPathString() : file.GetGitPathString());
439 catch (const char* msg)
441 MessageBox(L"Could not get files of parents.\nlibgit reports:\n" + CString(msg), L"TortoiseGit", MB_ICONERROR);
444 // blame previous
445 if (!parentHashWithFile.empty())
447 if (parentHashWithFile.size() == 1)
449 popup.AppendMenuIcon(ID_BLAMEPREVIOUS, IDS_BLAME_POPUP_BLAME, IDI_BLAME_POPUP_BLAME);
451 else
453 blamemenu.CreatePopupMenu();
454 popup.AppendMenuIcon(ID_BLAMEPREVIOUS, IDS_BLAME_POPUP_BLAME, IDI_BLAME_POPUP_BLAME, blamemenu.m_hMenu);
456 for (size_t i = 0; i < parentHashWithFile.size(); ++i)
458 CString str;
459 str.Format(IDS_PARENT, i + 1);
460 blamemenu.AppendMenuIcon(ID_BLAMEPREVIOUS + ((i + 1) << 16), str);
465 // compare with previous
466 if (!parentHashWithFile.empty())
468 if (parentHashWithFile.size() == 1)
470 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_BLAME_POPUP_COMPARE, IDI_BLAME_POPUP_COMPARE);
471 if (CRegDWORD(L"Software\\TortoiseGit\\DiffByDoubleClickInLog", FALSE))
472 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
474 else
476 diffmenu.CreatePopupMenu();
477 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_BLAME_POPUP_COMPARE, IDI_BLAME_POPUP_COMPARE, diffmenu.m_hMenu);
478 for (size_t i = 0; i < parentHashWithFile.size(); ++i)
480 CString str;
481 str.Format(IDS_BLAME_POPUP_PARENT, i + 1);
482 diffmenu.AppendMenuIcon((UINT)(ID_COMPAREWITHPREVIOUS + ((i + 1) << 16)),str);
483 if (i == 0 && CRegDWORD(L"Software\\TortoiseGit\\DiffByDoubleClickInLog", FALSE))
485 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
486 diffmenu.SetDefaultItem((UINT)(ID_COMPAREWITHPREVIOUS + ((i + 1) << 16)), FALSE);
492 popup.AppendMenuIcon(ID_SHOWLOG, IDS_BLAME_POPUP_LOG, IDI_BLAME_POPUP_LOG);
493 popup.AppendMenu(MF_SEPARATOR, NULL);
494 popup.AppendMenuIcon(ID_COPYHASHTOCLIPBOARD, IDS_BLAME_POPUP_COPYHASHTOCLIPBOARD, IDI_BLAME_POPUP_COPY);
495 popup.AppendMenuIcon(ID_COPYLOGTOCLIPBOARD, IDS_BLAME_POPUP_COPYLOGTOCLIPBOARD, IDI_BLAME_POPUP_COPY);
497 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this);
498 this->ContextMenuAction(cmd, pRev, parentHashWithFile, parentFilename);
502 void CTortoiseGitBlameView::ContextMenuAction(int cmd, GitRev *pRev, GIT_REV_LIST& parentHashWithFile, const std::vector<CString>& parentFilename)
504 switch (cmd & 0xFFFF)
506 case ID_BLAMEPREVIOUS:
508 int index = (cmd>>16) & 0xFFFF;
509 if (index > 0)
510 index -= 1;
512 CString path = ResolveCommitFile(parentFilename[index]);
513 CString endrev = parentHashWithFile[index].ToString();
514 int line = m_data.GetOriginalLineNumber(m_MouseLine);
516 CString procCmd = L"/path:\"" + path + L"\" ";
517 procCmd += L" /command:blame";
518 procCmd += L" /endrev:" + endrev;
519 procCmd += L" /line:";
520 procCmd.AppendFormat(L"%d", line);
522 CCommonAppUtils::RunTortoiseGitProc(procCmd);
524 break;
526 case ID_COMPAREWITHPREVIOUS:
528 int index = (cmd >> 16) & 0xFFFF;
529 if (index > 0)
530 index -= 1;
532 CString path = ResolveCommitFile(parentFilename[index]);
533 CString startrev = pRev->m_CommitHash.ToString();
534 CString endrev = parentHashWithFile[index].ToString();
536 CString procCmd = L"/path:\"" + path + L"\" ";
537 procCmd += L" /command:diff";
538 procCmd += L" /startrev:" + startrev;
539 procCmd += L" /endrev:" + endrev;
540 if (!!(GetAsyncKeyState(VK_SHIFT) & 0x8000))
541 procCmd += L" /alternative";
543 CCommonAppUtils::RunTortoiseGitProc(procCmd);
545 break;
547 case ID_SHOWLOG:
549 CString path = ResolveCommitFile(m_MouseLine);
550 CString rev = m_data.GetHash(m_MouseLine).ToString();
552 CString procCmd = L"/path:\"" + path + L"\" ";
553 procCmd += L" /command:log";
554 procCmd += L" /rev:" + rev;
555 procCmd += L" /endrev:" + rev;
557 CCommonAppUtils::RunTortoiseGitProc(procCmd);
559 break;
561 case ID_COPYHASHTOCLIPBOARD:
562 this->GetLogList()->CopySelectionToClipBoard(CGitLogListBase::ID_COPYCLIPBOARDHASH);
563 break;
565 case ID_COPYLOGTOCLIPBOARD:
566 this->GetLogList()->CopySelectionToClipBoard(CGitLogListBase::ID_COPYCLIPBOARDFULL);
567 break;
571 // CTortoiseGitBlameView diagnostics
573 #ifdef _DEBUG
574 void CTortoiseGitBlameView::AssertValid() const
576 CView::AssertValid();
579 void CTortoiseGitBlameView::Dump(CDumpContext& dc) const
581 CView::Dump(dc);
584 CTortoiseGitBlameDoc* CTortoiseGitBlameView::GetDocument() const // non-debug version is inline
586 ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTortoiseGitBlameDoc)));
587 return (CTortoiseGitBlameDoc*)m_pDocument;
589 #endif //_DEBUG
592 // Return a color which is interpolated between c1 and c2.
593 // Slider controls the relative proportions as a percentage:
594 // Slider = 0 represents pure c1
595 // Slider = 50 represents equal mixture
596 // Slider = 100 represents pure c2
597 COLORREF CTortoiseGitBlameView::InterColor(COLORREF c1, COLORREF c2, int Slider)
599 int r, g, b;
601 // Limit Slider to 0..100% range
602 if (Slider < 0)
603 Slider = 0;
604 if (Slider > 100)
605 Slider = 100;
607 // The color components have to be treated individually.
608 r = (GetRValue(c2) * Slider + GetRValue(c1) * (100 - Slider)) / 100;
609 g = (GetGValue(c2) * Slider + GetGValue(c1) * (100 - Slider)) / 100;
610 b = (GetBValue(c2) * Slider + GetBValue(c1) * (100 - Slider)) / 100;
612 return RGB(r, g, b);
615 LRESULT CTortoiseGitBlameView::SendEditor(UINT Msg, WPARAM wParam, LPARAM lParam)
617 return m_TextView.Call(Msg, wParam, lParam);
620 void CTortoiseGitBlameView::SetAStyle(int style, COLORREF fore, COLORREF back, int size, const char *face)
622 if (fore == back && fore == m_windowcolor)
623 fore = m_textcolor;
624 m_TextView.SetAStyle(style, fore, back, size, face);
627 void CTortoiseGitBlameView::InitialiseEditor()
629 SendEditor(SCI_STYLERESETDEFAULT);
630 // Set up the global default style. These attributes are used wherever no explicit choices are made.
631 std::string fontName = CUnicodeUtils::StdGetUTF8((std::wstring)CRegStdString(L"Software\\TortoiseGit\\BlameFontName", L"Consolas"));
632 SetAStyle(STYLE_DEFAULT,
633 ::GetSysColor(COLOR_WINDOWTEXT),
634 ::GetSysColor(COLOR_WINDOW),
635 (DWORD)CRegStdDWORD(L"Software\\TortoiseGit\\BlameFontSize", 10),
636 fontName.c_str()
638 SendEditor(SCI_SETTABWIDTH, (DWORD)CRegStdDWORD(L"Software\\TortoiseGit\\BlameTabSize", 4));
639 SendEditor(SCI_SETREADONLY, TRUE);
640 LRESULT pix = SendEditor(SCI_TEXTWIDTH, STYLE_LINENUMBER, (LPARAM)this->m_TextView.StringForControl(L"_99999").GetBuffer());
641 if (m_bShowLine)
642 SendEditor(SCI_SETMARGINWIDTHN, 0, pix);
643 else
644 SendEditor(SCI_SETMARGINWIDTHN, 0);
645 SendEditor(SCI_SETMARGINWIDTHN, 1);
646 SendEditor(SCI_SETMARGINWIDTHN, 2);
647 //Set the default windows colors for edit controls
648 SendEditor(SCI_SETSELFORE, TRUE, ::GetSysColor(COLOR_HIGHLIGHTTEXT));
649 SendEditor(SCI_SETSELBACK, TRUE, ::GetSysColor(COLOR_HIGHLIGHT));
650 SendEditor(SCI_SETCARETFORE, ::GetSysColor(COLOR_WINDOWTEXT));
651 m_regOldLinesColor = CRegStdDWORD(L"Software\\TortoiseGit\\BlameOldColor", BLAMEOLDCOLOR);
652 m_regNewLinesColor = CRegStdDWORD(L"Software\\TortoiseGit\\BlameNewColor", BLAMENEWCOLOR);
653 if (CRegStdDWORD(L"Software\\TortoiseGit\\ScintillaDirect2D", FALSE) != FALSE)
655 SendEditor(SCI_SETTECHNOLOGY, SC_TECHNOLOGY_DIRECTWRITERETAIN);
656 SendEditor(SCI_SETBUFFEREDDRAW, 0);
659 if (m_bWrapLongLines)
660 SendEditor(SCI_SETWRAPMODE, SC_WRAP_WORD);
661 else
662 SendEditor(SCI_SETWRAPMODE, SC_WRAP_NONE);
663 SendEditor(SCI_STYLECLEARALL);
666 bool CTortoiseGitBlameView::DoSearch(CTortoiseGitBlameData::SearchDirection direction)
668 int pos = (int)SendEditor(SCI_GETCURRENTPOS);
669 int line = (int)SendEditor(SCI_LINEFROMPOSITION, pos);
671 int i = m_data.FindFirstLineWrapAround(direction, m_sFindText, line, m_bMatchCase);
672 if (i >= 0)
674 GotoLine(i + 1);
675 int selstart = (int)SendEditor(SCI_GETCURRENTPOS);
676 int selend = (int)SendEditor(SCI_POSITIONFROMLINE, i + 1);
677 SendEditor(SCI_SETSELECTIONSTART, selstart);
678 SendEditor(SCI_SETSELECTIONEND, selend);
679 m_SelectedLine = i;
681 else
682 ::MessageBox(m_pFindDialog && m_pFindDialog->GetSafeHwnd() ? m_pFindDialog->GetSafeHwnd() : wMain, L"\"" + m_sFindText + L"\" " + CString(MAKEINTRESOURCE(IDS_NOTFOUND)), L"TortoiseGitBlame", MB_ICONINFORMATION);
684 return true;
687 void CTortoiseGitBlameView::OnFindPrev()
689 if (m_sFindText.IsEmpty())
690 return;
691 DoSearch(CTortoiseGitBlameData::SearchPrevious);
694 void CTortoiseGitBlameView::OnFindNext()
696 if (m_sFindText.IsEmpty())
697 return;
698 DoSearch(CTortoiseGitBlameData::SearchNext);
701 bool CTortoiseGitBlameView::GotoLine(int line)
703 --line;
704 int numberOfLines = m_data.GetNumberOfLines();
705 if (line < 0 || numberOfLines == 0)
706 return false;
707 if (line >= numberOfLines)
709 line = numberOfLines - 1;
712 int nCurrentPos = (int)SendEditor(SCI_GETCURRENTPOS);
713 int nCurrentLine = (int)SendEditor(SCI_LINEFROMPOSITION,nCurrentPos);
714 int nFirstVisibleLine = (int)SendEditor(SCI_GETFIRSTVISIBLELINE);
715 int nLinesOnScreen = (int)SendEditor(SCI_LINESONSCREEN);
717 if ( line>=nFirstVisibleLine && line<=nFirstVisibleLine+nLinesOnScreen)
719 // no need to scroll
720 SendEditor(SCI_GOTOLINE, line);
722 else
724 // Place the requested line one third from the top
725 if ( line > nCurrentLine )
727 SendEditor(SCI_GOTOLINE, (WPARAM)(line+(int)nLinesOnScreen*(2/3.0)));
729 else
731 SendEditor(SCI_GOTOLINE, (WPARAM)(line-(int)nLinesOnScreen*(1/3.0)));
735 // Highlight the line
736 int nPosStart = (int)SendEditor(SCI_POSITIONFROMLINE,line);
737 int nPosEnd = (int)SendEditor(SCI_GETLINEENDPOSITION,line);
738 SendEditor(SCI_SETSEL,nPosEnd,nPosStart);
740 return true;
743 bool CTortoiseGitBlameView::ScrollToLine(long line)
745 if (line < 0)
746 return false;
748 int nCurrentLine = (int)SendEditor(SCI_GETFIRSTVISIBLELINE);
750 int scrolldelta = line - nCurrentLine;
751 SendEditor(SCI_LINESCROLL, 0, scrolldelta);
753 return true;
756 void CTortoiseGitBlameView::CopyToClipboard()
758 CWnd * wnd = GetFocus();
759 if (wnd == this->GetLogList())
760 GetLogList()->CopySelectionToClipBoard();
761 else if (wnd)
763 if (CString(wnd->GetRuntimeClass()->m_lpszClassName) == L"CMFCPropertyGridCtrl")
765 CMFCPropertyGridCtrl *grid = (CMFCPropertyGridCtrl *)wnd;
766 if (grid->GetCurSel() && !grid->GetCurSel()->IsGroup())
767 CStringUtils::WriteAsciiStringToClipboard(grid->GetCurSel()->GetValue(), GetSafeHwnd());
769 else
770 m_TextView.Call(SCI_COPY);
774 LONG CTortoiseGitBlameView::GetBlameWidth()
776 LONG blamewidth = 0;
777 SIZE width;
778 CreateFont();
779 HDC hDC = this->GetDC()->m_hDC;
780 HFONT oldfont = (HFONT)::SelectObject(hDC, m_font.GetSafeHandle());
782 CString shortHash('f', g_Git.GetShortHASHLength() + 1);
783 ::GetTextExtentPoint32(hDC, shortHash, g_Git.GetShortHASHLength() + 1, &width);
784 m_revwidth = width.cx + BLAMESPACE;
785 blamewidth += m_revwidth;
787 if (m_bShowDate)
789 SIZE maxwidth = {0};
791 int numberOfLines = m_data.GetNumberOfLines();
792 for (int i = 0; i < numberOfLines; ++i)
794 ::GetTextExtentPoint32(hDC, m_data.GetDate(i), m_data.GetDate(i).GetLength(), &width);
795 if (width.cx > maxwidth.cx)
796 maxwidth = width;
798 m_datewidth = maxwidth.cx + BLAMESPACE;
799 blamewidth += m_datewidth;
801 if ( m_bShowAuthor)
803 SIZE maxwidth = {0};
805 int numberOfLines = m_data.GetNumberOfLines();
806 for (int i = 0; i < numberOfLines; ++i)
808 ::GetTextExtentPoint32(hDC,m_data.GetAuthor(i) , m_data.GetAuthor(i).GetLength(), &width);
809 if (width.cx > maxwidth.cx)
810 maxwidth = width;
812 m_authorwidth = maxwidth.cx + BLAMESPACE;
813 blamewidth += m_authorwidth;
815 if (m_bShowFilename)
817 SIZE maxwidth = {0};
819 int numberOfLines = m_data.GetNumberOfLines();
820 for (int i = 0; i < numberOfLines; ++i)
822 ::GetTextExtentPoint32(hDC, m_data.GetFilename(i), m_data.GetFilename(i).GetLength(), &width);
823 if (width.cx > maxwidth.cx)
824 maxwidth = width;
826 m_filenameWidth = maxwidth.cx + BLAMESPACE;
827 blamewidth += m_filenameWidth;
829 if (m_bShowOriginalLineNumber)
831 SIZE maxwidth = {0};
833 int numberOfLines = m_data.GetNumberOfLines();
834 CString str;
835 for (int i = 0; i < numberOfLines; ++i)
837 str.Format(L"%5d", m_data.GetOriginalLineNumber(i));
838 ::GetTextExtentPoint32(hDC, str, str.GetLength(), &width);
839 if (width.cx > maxwidth.cx)
840 maxwidth = width;
842 m_originalLineNumberWidth = maxwidth.cx + BLAMESPACE;
843 blamewidth += m_originalLineNumberWidth;
845 ::SelectObject(hDC, oldfont);
846 POINT pt = {blamewidth, 0};
847 LPtoDP(hDC, &pt, 1);
848 m_blamewidth = pt.x;
849 //::ReleaseDC(wBlame, hDC);
850 return blamewidth;
853 void CTortoiseGitBlameView::CreateFont()
855 if (m_font.GetSafeHandle())
856 return;
857 LOGFONT lf = {0};
858 lf.lfWeight = 400;
859 HDC hDC = ::GetDC(wBlame);
860 lf.lfHeight = -MulDiv((DWORD)CRegStdDWORD(L"Software\\TortoiseGit\\BlameFontSize", 10), GetDeviceCaps(hDC, LOGPIXELSY), 72);
861 lf.lfCharSet = DEFAULT_CHARSET;
862 CRegStdString fontname = CRegStdString(L"Software\\TortoiseGit\\BlameFontName", L"Consolas");
863 wcscpy_s(lf.lfFaceName, 32, ((std::wstring)fontname).c_str());
864 m_font.CreateFontIndirect(&lf);
866 lf.lfItalic = TRUE;
867 m_italicfont.CreateFontIndirect(&lf);
869 ::ReleaseDC(wBlame, hDC);
872 void CTortoiseGitBlameView::DrawBlame(HDC hDC)
874 if (!hDC || m_data.GetNumberOfLines() == 0)
875 return;
876 if (!m_font.GetSafeHandle())
877 return;
879 HFONT oldfont = nullptr;
880 int firstvisibleline = (int)SendEditor(SCI_GETFIRSTVISIBLELINE);
881 int line = (int)SendEditor(SCI_DOCLINEFROMVISIBLE, firstvisibleline);
882 int linesonscreen = (int)SendEditor(SCI_LINESONSCREEN) + 1;
883 int height = (int)SendEditor(SCI_TEXTHEIGHT);
884 int Y = 0;
885 TCHAR buf[MAX_PATH] = {0};
886 std::fill_n(buf, _countof(buf) - 1, L' ');
887 RECT rc;
888 CGitHash oldHash;
889 CString oldFile;
891 for (int i = line; i < (line + linesonscreen) && i < m_data.GetNumberOfLines(); ++i)
893 auto wrapcount = (int)SendEditor(SCI_WRAPCOUNT, i);
894 if (wrapcount > 1)
896 if (i == line)
897 wrapcount -= (int)SendEditor(SCI_DOCLINEFROMVISIBLE, firstvisibleline + wrapcount - 1) - (int)SendEditor(SCI_DOCLINEFROMVISIBLE, firstvisibleline);
898 linesonscreen -= wrapcount - 1;
900 CGitHash hash(m_data.GetHash(i));
901 oldfont = (HFONT)::SelectObject(hDC, m_font.GetSafeHandle());
902 ::SetBkColor(hDC, m_windowcolor);
903 ::SetTextColor(hDC, m_textcolor);
904 if (!hash.IsEmpty() && hash == m_SelectedHash)
906 ::SetBkColor(hDC, m_selectedauthorcolor);
907 ::SetTextColor(hDC, m_texthighlightcolor);
910 if (m_MouseLine == i)
911 ::SetBkColor(hDC, m_mouserevcolor);
913 if ((!hash.IsEmpty() && hash == m_SelectedHash) || m_MouseLine == i)
915 auto old = ::GetTextColor(hDC);
916 ::SetTextColor(hDC, ::GetBkColor(hDC));
917 RECT rc2 = { LOCATOR_WIDTH, Y, m_blamewidth + LOCATOR_WIDTH, Y + (wrapcount * height) };
918 for (int j = 0; j < wrapcount; ++j)
919 ::ExtTextOut(hDC, 0, Y + (j * height), ETO_CLIPPED, &rc2, buf, _countof(buf) - 1, 0);
920 ::SetTextColor(hDC, old);
923 CString file = m_data.GetFilename(i);
924 if (oldHash != hash || (m_bShowFilename && oldFile != file) || m_bShowOriginalLineNumber)
926 rc.top = (LONG)Y;
927 rc.left = LOCATOR_WIDTH;
928 rc.bottom = (LONG)(Y + height);
929 rc.right = rc.left + m_blamewidth;
930 if (oldHash != hash)
932 CString shortHashStr = hash.ToString().Left(g_Git.GetShortHASHLength());
933 ::ExtTextOut(hDC, LOCATOR_WIDTH, Y, ETO_CLIPPED, &rc, shortHashStr, shortHashStr.GetLength(), 0);
935 int Left = m_revwidth;
937 if (m_bShowAuthor)
939 rc.right = rc.left + Left + m_authorwidth;
940 if (oldHash != hash)
941 ::ExtTextOut(hDC, Left, Y, ETO_CLIPPED, &rc, m_data.GetAuthor(i), m_data.GetAuthor(i).GetLength(), 0);
942 Left += m_authorwidth;
944 if (m_bShowDate)
946 rc.right = rc.left + Left + m_datewidth;
947 if (oldHash != hash)
948 ::ExtTextOut(hDC, Left, Y, ETO_CLIPPED, &rc, m_data.GetDate(i), m_data.GetDate(i).GetLength(), 0);
949 Left += m_datewidth;
951 if (m_bShowFilename)
953 rc.right = rc.left + Left + m_filenameWidth;
954 if (oldFile != file)
955 ::ExtTextOut(hDC, Left, Y, ETO_CLIPPED, &rc, m_data.GetFilename(i), m_data.GetFilename(i).GetLength(), 0);
956 Left += m_filenameWidth;
958 if (m_bShowOriginalLineNumber)
960 rc.right = rc.left + Left + m_originalLineNumberWidth;
961 CString str;
962 str.Format(L"%5d", m_data.GetOriginalLineNumber(i));
963 ::ExtTextOut(hDC, Left, Y, ETO_CLIPPED, &rc, str, str.GetLength(), 0);
964 Left += m_originalLineNumberWidth;
966 oldHash = hash;
967 oldFile = file;
969 if (i == m_SelectedLine && m_pFindDialog)
971 LOGBRUSH brush;
972 brush.lbColor = m_textcolor;
973 brush.lbHatch = 0;
974 brush.lbStyle = BS_SOLID;
975 HPEN pen = ExtCreatePen(PS_SOLID | PS_GEOMETRIC, 2, &brush, 0, nullptr);
976 HGDIOBJ hPenOld = SelectObject(hDC, pen);
977 RECT rc2 = { LOCATOR_WIDTH, Y + 1, m_blamewidth, Y + (wrapcount * height) - 1};
978 ::MoveToEx(hDC, rc2.left, rc2.top, nullptr);
979 ::LineTo(hDC, rc2.right, rc2.top);
980 ::LineTo(hDC, rc2.right, rc2.bottom);
981 ::LineTo(hDC, rc2.left, rc2.bottom);
982 ::LineTo(hDC, rc2.left, rc2.top);
983 SelectObject(hDC, hPenOld);
984 DeleteObject(pen);
986 Y += wrapcount * height;
987 ::SelectObject(hDC, oldfont);
991 void CTortoiseGitBlameView::DrawLocatorBar(HDC hDC)
993 if (!hDC)
994 return;
996 int line = (int)SendEditor(SCI_GETFIRSTVISIBLELINE);
997 int linesonscreen = (int)SendEditor(SCI_LINESONSCREEN);
998 int Y = 0;
999 COLORREF blackColor = GetSysColor(COLOR_WINDOWTEXT);
1001 RECT rc;
1002 //::GetClientRect(wLocator, &rc);
1003 this->GetClientRect(&rc);
1005 rc.right=LOCATOR_WIDTH;
1007 RECT lineRect = rc;
1008 LONG height = rc.bottom-rc.top;
1010 int numberOfLines = m_data.GetNumberOfLines();
1011 // draw the colored bar
1012 for (int currentLine = 0; currentLine<numberOfLines; ++currentLine)
1014 COLORREF cr = GetLineColor(currentLine);
1015 // get the line color
1016 if ((currentLine >= line)&&(currentLine < (line + linesonscreen)))
1018 cr = InterColor(cr, blackColor, 10);
1020 SetBkColor(hDC, cr);
1021 lineRect.top = (LONG)Y;
1022 lineRect.bottom = ((currentLine + 1) * height / numberOfLines);
1023 ::ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &lineRect, nullptr, 0, nullptr);
1024 Y = lineRect.bottom;
1027 if (numberOfLines > 0)
1029 // now draw two lines indicating the scroll position of the source view
1030 SetBkColor(hDC, blackColor);
1031 lineRect.top = (LONG)line * height / numberOfLines;
1032 lineRect.bottom = lineRect.top+1;
1033 ::ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &lineRect, nullptr, 0, nullptr);
1034 lineRect.top = (LONG)(line + linesonscreen) * height / numberOfLines;
1035 lineRect.bottom = lineRect.top+1;
1036 ::ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &lineRect, nullptr, 0, nullptr);
1040 void CTortoiseGitBlameView::SetupLexer(CString filename)
1042 int start = filename.ReverseFind(L'.');
1043 SendEditor(SCI_SETLEXER, SCLEX_NULL);
1044 if (!m_bLexer)
1045 return;
1046 if (start > 0)
1048 //wcscpy_s(line, 20, lineptr+1);
1049 //_wcslwr_s(line, 20);
1050 CString ext=filename.Right(filename.GetLength()-start-1);
1051 const TCHAR* line = ext;
1053 if ((wcscmp(line, L"py") == 0) ||
1054 (wcscmp(line, L"pyw") == 0))
1056 SendEditor(SCI_SETLEXER, SCLEX_PYTHON);
1057 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(L"and assert break class continue def del elif \
1058 else except exec finally for from global if import in is lambda None \
1059 not or pass print raise return try while yield").GetBuffer()));
1060 SetAStyle(SCE_P_DEFAULT, black);
1061 SetAStyle(SCE_P_COMMENTLINE, darkGreen);
1062 SetAStyle(SCE_P_NUMBER, RGB(0, 0x80, 0x80));
1063 SetAStyle(SCE_P_STRING, RGB(0, 0, 0x80));
1064 SetAStyle(SCE_P_CHARACTER, RGB(0, 0, 0x80));
1065 SetAStyle(SCE_P_WORD, RGB(0x80, 0, 0x80));
1066 SetAStyle(SCE_P_TRIPLE, black);
1067 SetAStyle(SCE_P_TRIPLEDOUBLE, black);
1068 SetAStyle(SCE_P_CLASSNAME, darkBlue);
1069 SetAStyle(SCE_P_DEFNAME, darkBlue);
1070 SetAStyle(SCE_P_OPERATOR, darkBlue);
1071 SetAStyle(SCE_P_IDENTIFIER, darkBlue);
1072 SetAStyle(SCE_P_COMMENTBLOCK, darkGreen);
1073 SetAStyle(SCE_P_STRINGEOL, red);
1075 if ((wcscmp(line, L"c") == 0) ||
1076 (wcscmp(line, L"cc") == 0) ||
1077 (wcscmp(line, L"cpp") == 0) ||
1078 (wcscmp(line, L"cxx") == 0) ||
1079 (wcscmp(line, L"h") == 0) ||
1080 (wcscmp(line, L"hh") == 0) ||
1081 (wcscmp(line, L"hpp") == 0) ||
1082 (wcscmp(line, L"hxx") == 0) ||
1083 (wcscmp(line, L"dlg") == 0) ||
1084 (wcscmp(line, L"mak") == 0))
1086 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1087 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(L"and and_eq asm auto bitand bitor bool break \
1088 case catch char class compl const const_cast continue \
1089 default delete do double dynamic_cast else enum explicit export extern false float for \
1090 friend goto if inline int long mutable namespace new not not_eq \
1091 operator or or_eq private protected public \
1092 register reinterpret_cast return short signed sizeof static static_cast struct switch \
1093 template this throw true try typedef typeid typename union unsigned using \
1094 virtual void volatile wchar_t while xor xor_eq").GetBuffer()));
1095 SendEditor(SCI_SETKEYWORDS, 3, (LPARAM)(m_TextView.StringForControl(L"a addindex addtogroup anchor arg attention \
1096 author b brief bug c class code date def defgroup deprecated dontinclude \
1097 e em endcode endhtmlonly endif endlatexonly endlink endverbatim enum example exception \
1098 f$ f[ f] file fn hideinitializer htmlinclude htmlonly \
1099 if image include ingroup internal invariant interface latexonly li line link \
1100 mainpage name namespace nosubgrouping note overload \
1101 p page par param post pre ref relates remarks return retval \
1102 sa section see showinitializer since skip skipline struct subsection \
1103 test throw todo typedef union until \
1104 var verbatim verbinclude version warning weakgroup $ @ \\ & < > # { }").GetBuffer()));
1105 SetupCppLexer();
1107 if (wcscmp(line, L"cs") == 0)
1109 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1110 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(L"abstract as base bool break byte case catch char checked class \
1111 const continue decimal default delegate do double else enum \
1112 event explicit extern false finally fixed float for foreach goto if \
1113 implicit in int interface internal is lock long namespace new null \
1114 object operator out override params private protected public \
1115 readonly ref return sbyte sealed short sizeof stackalloc static \
1116 string struct switch this throw true try typeof uint ulong \
1117 unchecked unsafe ushort using virtual void while").GetBuffer()));
1118 SetupCppLexer();
1120 if ((wcscmp(line, L"rc") == 0) ||
1121 (wcscmp(line, L"rc2") == 0))
1123 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1124 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(L"ACCELERATORS ALT AUTO3STATE AUTOCHECKBOX AUTORADIOBUTTON \
1125 BEGIN BITMAP BLOCK BUTTON CAPTION CHARACTERISTICS CHECKBOX CLASS \
1126 COMBOBOX CONTROL CTEXT CURSOR DEFPUSHBUTTON DIALOG DIALOGEX DISCARDABLE \
1127 EDITTEXT END EXSTYLE FONT GROUPBOX ICON LANGUAGE LISTBOX LTEXT \
1128 MENU MENUEX MENUITEM MESSAGETABLE POPUP \
1129 PUSHBUTTON RADIOBUTTON RCDATA RTEXT SCROLLBAR SEPARATOR SHIFT STATE3 \
1130 STRINGTABLE STYLE TEXTINCLUDE VALUE VERSION VERSIONINFO VIRTKEY").GetBuffer()));
1131 SetupCppLexer();
1133 if ((wcscmp(line, L"idl") == 0) ||
1134 (wcscmp(line, L"odl") == 0))
1136 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1137 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(L"aggregatable allocate appobject arrays async async_uuid \
1138 auto_handle \
1139 bindable boolean broadcast byte byte_count \
1140 call_as callback char coclass code comm_status \
1141 const context_handle context_handle_noserialize \
1142 context_handle_serialize control cpp_quote custom \
1143 decode default defaultbind defaultcollelem \
1144 defaultvalue defaultvtable dispinterface displaybind dllname \
1145 double dual \
1146 enable_allocate encode endpoint entry enum error_status_t \
1147 explicit_handle \
1148 fault_status first_is float \
1149 handle_t heap helpcontext helpfile helpstring \
1150 helpstringcontext helpstringdll hidden hyper \
1151 id idempotent ignore iid_as iid_is immediatebind implicit_handle \
1152 import importlib in include in_line int __int64 __int3264 interface \
1153 last_is lcid length_is library licensed local long \
1154 max_is maybe message methods midl_pragma \
1155 midl_user_allocate midl_user_free min_is module ms_union \
1156 ncacn_at_dsp ncacn_dnet_nsp ncacn_http ncacn_ip_tcp \
1157 ncacn_nb_ipx ncacn_nb_nb ncacn_nb_tcp ncacn_np \
1158 ncacn_spx ncacn_vns_spp ncadg_ip_udp ncadg_ipx ncadg_mq \
1159 ncalrpc nocode nonbrowsable noncreatable nonextensible notify \
1160 object odl oleautomation optimize optional out out_of_line \
1161 pipe pointer_default pragma properties propget propput propputref \
1162 ptr public \
1163 range readonly ref represent_as requestedit restricted retval \
1164 shape short signed size_is small source strict_context_handle \
1165 string struct switch switch_is switch_type \
1166 transmit_as typedef \
1167 uidefault union unique unsigned user_marshal usesgetlasterror uuid \
1168 v1_enum vararg version void wchar_t wire_marshal").GetBuffer()));
1169 SetupCppLexer();
1171 if (wcscmp(line, L"java") == 0)
1173 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1174 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(L"abstract assert boolean break byte case catch char class \
1175 const continue default do double else extends final finally float for future \
1176 generic goto if implements import inner instanceof int interface long \
1177 native new null outer package private protected public rest \
1178 return short static super switch synchronized this throw throws \
1179 transient try var void volatile while").GetBuffer()));
1180 SetupCppLexer();
1182 if (wcscmp(line, L"js") == 0)
1184 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1185 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(L"abstract boolean break byte case catch char class \
1186 const continue debugger default delete do double else enum export extends \
1187 final finally float for function goto if implements import in instanceof \
1188 int interface long native new package private protected public \
1189 return short static super switch synchronized this throw throws \
1190 transient try typeof var void volatile while with").GetBuffer()));
1191 SetupCppLexer();
1193 if ((wcscmp(line, L"pas") == 0) ||
1194 (wcscmp(line, L"dpr") == 0) ||
1195 (wcscmp(line, L"pp") == 0))
1197 SendEditor(SCI_SETLEXER, SCLEX_PASCAL);
1198 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(L"and array as begin case class const constructor \
1199 destructor div do downto else end except file finally \
1200 for function goto if implementation in inherited \
1201 interface is mod not object of on or packed \
1202 procedure program property raise record repeat \
1203 set shl shr then threadvar to try type unit \
1204 until uses var while with xor").GetBuffer()));
1205 SetupCppLexer();
1207 if ((wcscmp(line, L"as") == 0) ||
1208 (wcscmp(line, L"asc") == 0) ||
1209 (wcscmp(line, L"jsfl") == 0))
1211 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1212 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(L"add and break case catch class continue default delete do \
1213 dynamic else eq extends false finally for function ge get gt if implements import in \
1214 instanceof interface intrinsic le lt ne new not null or private public return \
1215 set static super switch this throw true try typeof undefined var void while with").GetBuffer()));
1216 SendEditor(SCI_SETKEYWORDS, 1, (LPARAM)(m_TextView.StringForControl(L"Array Arguments Accessibility Boolean Button Camera Color \
1217 ContextMenu ContextMenuItem Date Error Function Key LoadVars LocalConnection Math \
1218 Microphone Mouse MovieClip MovieClipLoader NetConnection NetStream Number Object \
1219 PrintJob Selection SharedObject Sound Stage String StyleSheet System TextField \
1220 TextFormat TextSnapshot Video Void XML XMLNode XMLSocket \
1221 _accProps _focusrect _global _highquality _parent _quality _root _soundbuftime \
1222 arguments asfunction call capabilities chr clearInterval duplicateMovieClip \
1223 escape eval fscommand getProperty getTimer getURL getVersion gotoAndPlay gotoAndStop \
1224 ifFrameLoaded Infinity -Infinity int isFinite isNaN length loadMovie loadMovieNum \
1225 loadVariables loadVariablesNum maxscroll mbchr mblength mbord mbsubstring MMExecute \
1226 NaN newline nextFrame nextScene on onClipEvent onUpdate ord parseFloat parseInt play \
1227 prevFrame prevScene print printAsBitmap printAsBitmapNum printNum random removeMovieClip \
1228 scroll set setInterval setProperty startDrag stop stopAllSounds stopDrag substring \
1229 targetPath tellTarget toggleHighQuality trace unescape unloadMovie unLoadMovieNum updateAfterEvent").GetBuffer()));
1230 SetupCppLexer();
1232 if ((wcscmp(line, L"html") == 0) ||
1233 (wcscmp(line, L"htm") == 0) ||
1234 (wcscmp(line, L"shtml") == 0) ||
1235 (wcscmp(line, L"htt") == 0) ||
1236 (wcscmp(line, L"xml") == 0) ||
1237 (wcscmp(line, L"asp") == 0) ||
1238 (wcscmp(line, L"xsl") == 0) ||
1239 (wcscmp(line, L"php") == 0) ||
1240 (wcscmp(line, L"xhtml") == 0) ||
1241 (wcscmp(line, L"phtml") == 0) ||
1242 (wcscmp(line, L"cfm") == 0) ||
1243 (wcscmp(line, L"tpl") == 0) ||
1244 (wcscmp(line, L"dtd") == 0) ||
1245 (wcscmp(line, L"hta") == 0) ||
1246 (wcscmp(line, L"htd") == 0) ||
1247 (wcscmp(line, L"wxs") == 0))
1249 SendEditor(SCI_SETLEXER, SCLEX_HTML);
1250 SendEditor(SCI_SETSTYLEBITS, 7);
1251 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(L"a abbr acronym address applet area b base basefont \
1252 bdo big blockquote body br button caption center \
1253 cite code col colgroup dd del dfn dir div dl dt em \
1254 fieldset font form frame frameset h1 h2 h3 h4 h5 h6 \
1255 head hr html i iframe img input ins isindex kbd label \
1256 legend li link map menu meta noframes noscript \
1257 object ol optgroup option p param pre q s samp \
1258 script select small span strike strong style sub sup \
1259 table tbody td textarea tfoot th thead title tr tt u ul \
1260 var xml xmlns abbr accept-charset accept accesskey action align alink \
1261 alt archive axis background bgcolor border \
1262 cellpadding cellspacing char charoff charset checked cite \
1263 class classid clear codebase codetype color cols colspan \
1264 compact content coords \
1265 data datafld dataformatas datapagesize datasrc datetime \
1266 declare defer dir disabled enctype event \
1267 face for frame frameborder \
1268 headers height href hreflang hspace http-equiv \
1269 id ismap label lang language leftmargin link longdesc \
1270 marginwidth marginheight maxlength media method multiple \
1271 name nohref noresize noshade nowrap \
1272 object onblur onchange onclick ondblclick onfocus \
1273 onkeydown onkeypress onkeyup onload onmousedown \
1274 onmousemove onmouseover onmouseout onmouseup \
1275 onreset onselect onsubmit onunload \
1276 profile prompt readonly rel rev rows rowspan rules \
1277 scheme scope selected shape size span src standby start style \
1278 summary tabindex target text title topmargin type usemap \
1279 valign value valuetype version vlink vspace width \
1280 text password checkbox radio submit reset \
1281 file hidden image").GetBuffer()));
1282 SendEditor(SCI_SETKEYWORDS, 1, (LPARAM)(m_TextView.StringForControl(L"assign audio block break catch choice clear disconnect else elseif \
1283 emphasis enumerate error exit field filled form goto grammar help \
1284 if initial link log menu meta noinput nomatch object option p paragraph \
1285 param phoneme prompt property prosody record reprompt return s say-as \
1286 script sentence subdialog submit throw transfer value var voice vxml").GetBuffer()));
1287 SendEditor(SCI_SETKEYWORDS, 2, (LPARAM)(m_TextView.StringForControl(L"accept age alphabet anchor application base beep bridge category charset \
1288 classid cond connecttimeout content contour count dest destexpr dtmf dtmfterm \
1289 duration enctype event eventexpr expr expritem fetchtimeout finalsilence \
1290 gender http-equiv id level maxage maxstale maxtime message messageexpr \
1291 method mime modal mode name namelist next nextitem ph pitch range rate \
1292 scope size sizeexpr skiplist slot src srcexpr sub time timeexpr timeout \
1293 transferaudio type value variant version volume xml:lang").GetBuffer()));
1294 SendEditor(SCI_SETKEYWORDS, 3, (LPARAM)(m_TextView.StringForControl(L"and assert break class continue def del elif \
1295 else except exec finally for from global if import in is lambda None \
1296 not or pass print raise return try while yield").GetBuffer()));
1297 SendEditor(SCI_SETKEYWORDS, 4, (LPARAM)(m_TextView.StringForControl(L"and argv as argc break case cfunction class continue declare default do \
1298 die echo else elseif empty enddeclare endfor endforeach endif endswitch \
1299 endwhile e_all e_parse e_error e_warning eval exit extends false for \
1300 foreach function global http_cookie_vars http_get_vars http_post_vars \
1301 http_post_files http_env_vars http_server_vars if include include_once \
1302 list new not null old_function or parent php_os php_self php_version \
1303 print require require_once return static switch stdclass this true var \
1304 xor virtual while __file__ __line__ __sleep __wakeup").GetBuffer()));
1306 SetAStyle(SCE_H_TAG, darkBlue);
1307 SetAStyle(SCE_H_TAGUNKNOWN, red);
1308 SetAStyle(SCE_H_ATTRIBUTE, darkBlue);
1309 SetAStyle(SCE_H_ATTRIBUTEUNKNOWN, red);
1310 SetAStyle(SCE_H_NUMBER, RGB(0x80,0,0x80));
1311 SetAStyle(SCE_H_DOUBLESTRING, RGB(0,0x80,0));
1312 SetAStyle(SCE_H_SINGLESTRING, RGB(0,0x80,0));
1313 SetAStyle(SCE_H_OTHER, RGB(0x80,0,0x80));
1314 SetAStyle(SCE_H_COMMENT, RGB(0x80,0x80,0));
1315 SetAStyle(SCE_H_ENTITY, RGB(0x80,0,0x80));
1317 SetAStyle(SCE_H_TAGEND, darkBlue);
1318 SetAStyle(SCE_H_XMLSTART, darkBlue); // <?
1319 SetAStyle(SCE_H_QUESTION, darkBlue); // <?
1320 SetAStyle(SCE_H_XMLEND, darkBlue); // ?>
1321 SetAStyle(SCE_H_SCRIPT, darkBlue); // <script
1322 SetAStyle(SCE_H_ASP, RGB(0x4F, 0x4F, 0), RGB(0xFF, 0xFF, 0)); // <% ... %>
1323 SetAStyle(SCE_H_ASPAT, RGB(0x4F, 0x4F, 0), RGB(0xFF, 0xFF, 0)); // <%@ ... %>
1325 SetAStyle(SCE_HB_DEFAULT, black);
1326 SetAStyle(SCE_HB_COMMENTLINE, darkGreen);
1327 SetAStyle(SCE_HB_NUMBER, RGB(0,0x80,0x80));
1328 SetAStyle(SCE_HB_WORD, darkBlue);
1329 SendEditor(SCI_STYLESETBOLD, SCE_HB_WORD, 1);
1330 SetAStyle(SCE_HB_STRING, RGB(0x80,0,0x80));
1331 SetAStyle(SCE_HB_IDENTIFIER, black);
1333 // This light blue is found in the windows system palette so is safe to use even in 256 colour modes.
1334 // Show the whole section of VBScript with light blue background
1335 for (int bstyle = SCE_HB_DEFAULT; bstyle <= SCE_HB_STRINGEOL; ++bstyle) {
1336 SendEditor(SCI_STYLESETFONT, bstyle,
1337 reinterpret_cast<LPARAM>(m_TextView.StringForControl(L"Lucida Console").GetBuffer()));
1338 SendEditor(SCI_STYLESETBACK, bstyle, lightBlue);
1339 // This call extends the backround colour of the last style on the line to the edge of the window
1340 SendEditor(SCI_STYLESETEOLFILLED, bstyle, 1);
1342 SendEditor(SCI_STYLESETBACK, SCE_HB_STRINGEOL, RGB(0x7F,0x7F,0xFF));
1343 SendEditor(SCI_STYLESETFONT, SCE_HB_COMMENTLINE,
1344 reinterpret_cast<LPARAM>(m_TextView.StringForControl(L"Lucida Console").GetBuffer()));
1346 SetAStyle(SCE_HBA_DEFAULT, black);
1347 SetAStyle(SCE_HBA_COMMENTLINE, darkGreen);
1348 SetAStyle(SCE_HBA_NUMBER, RGB(0,0x80,0x80));
1349 SetAStyle(SCE_HBA_WORD, darkBlue);
1350 SendEditor(SCI_STYLESETBOLD, SCE_HBA_WORD, 1);
1351 SetAStyle(SCE_HBA_STRING, RGB(0x80,0,0x80));
1352 SetAStyle(SCE_HBA_IDENTIFIER, black);
1354 // Show the whole section of ASP VBScript with bright yellow background
1355 for (int bastyle = SCE_HBA_DEFAULT; bastyle <= SCE_HBA_STRINGEOL; ++bastyle) {
1356 SendEditor(SCI_STYLESETFONT, bastyle,
1357 reinterpret_cast<LPARAM>(m_TextView.StringForControl(L"Lucida Console").GetBuffer()));
1358 SendEditor(SCI_STYLESETBACK, bastyle, RGB(0xFF, 0xFF, 0));
1359 // This call extends the backround colour of the last style on the line to the edge of the window
1360 SendEditor(SCI_STYLESETEOLFILLED, bastyle, 1);
1362 SendEditor(SCI_STYLESETBACK, SCE_HBA_STRINGEOL, RGB(0xCF,0xCF,0x7F));
1363 SendEditor(SCI_STYLESETFONT, SCE_HBA_COMMENTLINE,
1364 reinterpret_cast<LPARAM>(m_TextView.StringForControl(L"Lucida Console").GetBuffer()));
1366 // If there is no need to support embedded Javascript, the following code can be dropped.
1367 // Javascript will still be correctly processed but will be displayed in just the default style.
1369 SetAStyle(SCE_HJ_START, RGB(0x80,0x80,0));
1370 SetAStyle(SCE_HJ_DEFAULT, black);
1371 SetAStyle(SCE_HJ_COMMENT, darkGreen);
1372 SetAStyle(SCE_HJ_COMMENTLINE, darkGreen);
1373 SetAStyle(SCE_HJ_COMMENTDOC, darkGreen);
1374 SetAStyle(SCE_HJ_NUMBER, RGB(0,0x80,0x80));
1375 SetAStyle(SCE_HJ_WORD, black);
1376 SetAStyle(SCE_HJ_KEYWORD, darkBlue);
1377 SetAStyle(SCE_HJ_DOUBLESTRING, RGB(0x80,0,0x80));
1378 SetAStyle(SCE_HJ_SINGLESTRING, RGB(0x80,0,0x80));
1379 SetAStyle(SCE_HJ_SYMBOLS, black);
1381 SetAStyle(SCE_HJA_START, RGB(0x80,0x80,0));
1382 SetAStyle(SCE_HJA_DEFAULT, black);
1383 SetAStyle(SCE_HJA_COMMENT, darkGreen);
1384 SetAStyle(SCE_HJA_COMMENTLINE, darkGreen);
1385 SetAStyle(SCE_HJA_COMMENTDOC, darkGreen);
1386 SetAStyle(SCE_HJA_NUMBER, RGB(0,0x80,0x80));
1387 SetAStyle(SCE_HJA_WORD, black);
1388 SetAStyle(SCE_HJA_KEYWORD, darkBlue);
1389 SetAStyle(SCE_HJA_DOUBLESTRING, RGB(0x80,0,0x80));
1390 SetAStyle(SCE_HJA_SINGLESTRING, RGB(0x80,0,0x80));
1391 SetAStyle(SCE_HJA_SYMBOLS, black);
1393 SetAStyle(SCE_HPHP_DEFAULT, black);
1394 SetAStyle(SCE_HPHP_HSTRING, RGB(0x80,0,0x80));
1395 SetAStyle(SCE_HPHP_SIMPLESTRING, RGB(0x80,0,0x80));
1396 SetAStyle(SCE_HPHP_WORD, darkBlue);
1397 SetAStyle(SCE_HPHP_NUMBER, RGB(0,0x80,0x80));
1398 SetAStyle(SCE_HPHP_VARIABLE, red);
1399 SetAStyle(SCE_HPHP_HSTRING_VARIABLE, red);
1400 SetAStyle(SCE_HPHP_COMPLEX_VARIABLE, red);
1401 SetAStyle(SCE_HPHP_COMMENT, darkGreen);
1402 SetAStyle(SCE_HPHP_COMMENTLINE, darkGreen);
1403 SetAStyle(SCE_HPHP_OPERATOR, darkBlue);
1405 // Show the whole section of Javascript with off white background
1406 for (int jstyle = SCE_HJ_DEFAULT; jstyle <= SCE_HJ_SYMBOLS; ++jstyle) {
1407 SendEditor(SCI_STYLESETFONT, jstyle,
1408 reinterpret_cast<LPARAM>(m_TextView.StringForControl(L"Lucida Console").GetBuffer()));
1409 SendEditor(SCI_STYLESETBACK, jstyle, offWhite);
1410 SendEditor(SCI_STYLESETEOLFILLED, jstyle, 1);
1412 SendEditor(SCI_STYLESETBACK, SCE_HJ_STRINGEOL, RGB(0xDF, 0xDF, 0x7F));
1413 SendEditor(SCI_STYLESETEOLFILLED, SCE_HJ_STRINGEOL, 1);
1415 // Show the whole section of Javascript with brown background
1416 for (int jastyle = SCE_HJA_DEFAULT; jastyle <= SCE_HJA_SYMBOLS; ++jastyle) {
1417 SendEditor(SCI_STYLESETFONT, jastyle,
1418 reinterpret_cast<LPARAM>(m_TextView.StringForControl(L"Lucida Console").GetBuffer()));
1419 SendEditor(SCI_STYLESETBACK, jastyle, RGB(0xDF, 0xDF, 0x7F));
1420 SendEditor(SCI_STYLESETEOLFILLED, jastyle, 1);
1422 SendEditor(SCI_STYLESETBACK, SCE_HJA_STRINGEOL, RGB(0x0,0xAF,0x5F));
1423 SendEditor(SCI_STYLESETEOLFILLED, SCE_HJA_STRINGEOL, 1);
1426 else
1428 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1429 SetupCppLexer();
1431 SendEditor(SCI_COLOURISE, 0, -1);
1434 void CTortoiseGitBlameView::SetupCppLexer()
1436 SetAStyle(SCE_C_DEFAULT, RGB(0, 0, 0));
1437 SetAStyle(SCE_C_COMMENT, RGB(0, 0x80, 0));
1438 SetAStyle(SCE_C_COMMENTLINE, RGB(0, 0x80, 0));
1439 SetAStyle(SCE_C_COMMENTDOC, RGB(0, 0x80, 0));
1440 SetAStyle(SCE_C_COMMENTLINEDOC, RGB(0, 0x80, 0));
1441 SetAStyle(SCE_C_COMMENTDOCKEYWORD, RGB(0, 0x80, 0));
1442 SetAStyle(SCE_C_COMMENTDOCKEYWORDERROR, RGB(0, 0x80, 0));
1443 SetAStyle(SCE_C_NUMBER, RGB(0, 0x80, 0x80));
1444 SetAStyle(SCE_C_WORD, RGB(0, 0, 0x80));
1445 SendEditor(SCE_C_WORD, 1);
1446 SetAStyle(SCE_C_STRING, RGB(0x80, 0, 0x80));
1447 SetAStyle(SCE_C_IDENTIFIER, RGB(0, 0, 0));
1448 SetAStyle(SCE_C_PREPROCESSOR, RGB(0x80, 0, 0));
1449 SetAStyle(SCE_C_OPERATOR, RGB(0x80, 0x80, 0));
1450 SendEditor(SCI_SETPROPERTY, (WPARAM)"lexer.cpp.track.preprocessor", (LPARAM)"0");
1453 int CTortoiseGitBlameView::GetEncode(unsigned char *buff, int size, int *bomoffset)
1455 CFileTextLines textlines;
1456 CFileTextLines::UnicodeType type = textlines.CheckUnicodeType(buff, size);
1458 if(type == CFileTextLines::UTF8BOM)
1460 *bomoffset = 3;
1461 return CP_UTF8;
1463 if(type == CFileTextLines::UTF8)
1464 return CP_UTF8;
1466 if(type == CFileTextLines::UTF16_LE)
1467 return 1200;
1468 if (type == CFileTextLines::UTF16_LEBOM)
1470 *bomoffset = 2;
1471 return 1200;
1474 if(type == CFileTextLines::UTF16_BE)
1475 return 1201;
1476 if (type == CFileTextLines::UTF16_BEBOM)
1478 *bomoffset = 2;
1479 return 1201;
1482 return GetACP();
1485 void CTortoiseGitBlameView::ParseBlame()
1487 m_data.ParseBlameOutput(GetDocument()->m_BlameData, GetLogData()->m_pLogCache->m_HashMap, m_DateFormat, m_bRelativeTimes);
1488 CString filename = GetDocument()->m_GitPath.GetGitPathString();
1489 m_bBlameOuputContainsOtherFilenames = m_data.ContainsOnlyFilename(filename) ? FALSE : TRUE;
1492 void CTortoiseGitBlameView::MapLineToLogIndex()
1494 std::vector<int> lineToLogIndex;
1497 int numberOfLines = m_data.GetNumberOfLines();
1498 lineToLogIndex.reserve(numberOfLines);
1499 size_t logSize = this->GetLogData()->size();
1500 for (int j = 0; j < numberOfLines; ++j)
1502 CGitHash& hash = m_data.GetHash(j);
1504 int index = -2;
1505 for (size_t i = 0; i < logSize; ++i)
1507 if (hash == (*GetLogData())[i])
1509 index = (int)i;
1510 break;
1513 lineToLogIndex.push_back(index);
1515 this->m_lineToLogIndex.swap(lineToLogIndex);
1518 void CTortoiseGitBlameView::UpdateInfo(int Encode)
1520 CreateFont();
1522 InitialiseEditor();
1523 SendEditor(SCI_SETREADONLY, FALSE);
1524 SendEditor(SCI_CLEARALL);
1525 SendEditor(EM_EMPTYUNDOBUFFER);
1526 SendEditor(SCI_SETSAVEPOINT);
1527 SendEditor(SCI_CANCEL);
1528 SendEditor(SCI_SETUNDOCOLLECTION, 0);
1530 SendEditor(SCI_SETCODEPAGE, SC_CP_UTF8);
1532 int encoding = m_data.UpdateEncoding(Encode);
1534 int numberOfLines = m_data.GetNumberOfLines();
1535 if (numberOfLines > 0)
1537 CStringA text;
1538 for (int i = 0; i < numberOfLines; ++i)
1540 text += m_data.GetUtf8Line(i);
1541 text += '\n';
1543 text.TrimRight("\r\n");
1544 SendEditor(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)text);
1548 UINT nID;
1549 UINT nStyle;
1550 int cxWidth;
1551 int nIndex = ((CMainFrame *)::AfxGetApp()->GetMainWnd())->m_wndStatusBar.CommandToIndex(ID_INDICATOR_ENCODING);
1552 ((CMainFrame *)::AfxGetApp()->GetMainWnd())->m_wndStatusBar.GetPaneInfo(nIndex, nID, nStyle, cxWidth);
1553 CString sBarText;
1554 for (int i = 0; i < _countof(encodings); ++i)
1556 if (encodings[i].id == encoding)
1558 sBarText = CString(encodings[i].name);
1559 break;
1562 //calculate the width of the text
1563 CDC * pDC = ((CMainFrame *)::AfxGetApp()->GetMainWnd())->m_wndStatusBar.GetDC();
1564 if (pDC)
1566 CSize size = pDC->GetTextExtent(sBarText);
1567 ((CMainFrame *)::AfxGetApp()->GetMainWnd())->m_wndStatusBar.SetPaneInfo(nIndex, nID, nStyle, size.cx+2);
1568 ReleaseDC(pDC);
1570 ((CMainFrame *)::AfxGetApp()->GetMainWnd())->m_wndStatusBar.SetPaneText(nIndex, sBarText);
1573 #ifdef USE_TEMPFILENAME
1574 delete m_Buffer;
1575 m_Buffer = nullptr;
1577 CFile file;
1578 file.Open(this->GetDocument()->m_TempFileName,CFile::modeRead);
1580 m_Buffer = new char[file.GetLength()+4];
1581 m_Buffer[file.GetLength()] =0;
1582 m_Buffer[file.GetLength()+1] =0;
1583 m_Buffer[file.GetLength()+2] =0;
1584 m_Buffer[file.GetLength()+3] =0;
1586 file.Read(m_Buffer, file.GetLength());
1588 int bomoffset =0;
1589 int encoding = GetEncode( (unsigned char *)m_Buffer, file.GetLength(), &bomoffset);
1591 file.Close();
1592 //SendEditor(SCI_SETCODEPAGE, encoding);
1594 //SendEditor(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)(m_Buffer + bomoffset));
1595 #endif
1596 SetupLexer(GetDocument()->m_CurrentFileName);
1598 SendEditor(SCI_SETUNDOCOLLECTION, 1);
1599 SendEditor(EM_EMPTYUNDOBUFFER);
1600 SendEditor(SCI_SETSAVEPOINT);
1601 SendEditor(SCI_GOTOPOS, 0);
1602 SendEditor(SCI_SETSCROLLWIDTHTRACKING, TRUE);
1603 SendEditor(SCI_SETREADONLY, TRUE);
1605 GetBlameWidth();
1606 CRect rect;
1607 this->GetClientRect(rect);
1608 //this->m_TextView.GetWindowRect(rect);
1609 //this->m_TextView.ScreenToClient(rect);
1610 rect.left=this->m_blamewidth;
1611 this->m_TextView.MoveWindow(rect);
1613 this->Invalidate();
1616 CString CTortoiseGitBlameView::ResolveCommitFile(int line)
1618 return ResolveCommitFile(m_data.GetFilename(line));
1621 CString CTortoiseGitBlameView::ResolveCommitFile(const CString& path)
1623 if (path.IsEmpty())
1625 return ((CMainFrame*)::AfxGetApp()->GetMainWnd())->GetActiveView()->GetDocument()->GetPathName();
1627 else
1629 return g_Git.CombinePath(path);
1633 COLORREF CTortoiseGitBlameView::GetLineColor(int line)
1635 if (m_colorage && line >= 0 && (size_t)line < m_lineToLogIndex.size())
1637 int logIndex = m_lineToLogIndex[line];
1638 if (logIndex >= 0)
1640 int slider = (int)((GetLogData()->size() - logIndex) * 100 / (GetLogData()->size() + 1));
1641 return InterColor(DWORD(m_regOldLinesColor), DWORD(m_regNewLinesColor), slider);
1644 return m_windowcolor;
1647 CGitBlameLogList * CTortoiseGitBlameView::GetLogList()
1649 return &(GetDocument()->GetMainFrame()->m_wndOutput.m_LogList);
1653 CLogDataVector * CTortoiseGitBlameView::GetLogData()
1655 return &(GetDocument()->GetMainFrame()->m_wndOutput.m_LogList.m_logEntries);
1658 void CTortoiseGitBlameView::OnSciPainted(NMHDR *,LRESULT *)
1660 this->Invalidate();
1663 void CTortoiseGitBlameView::OnLButtonDown(UINT nFlags,CPoint point)
1665 int line = GetLineUnderCursor(point);
1666 if (line < m_data.GetNumberOfLines())
1668 SetSelectedLine(line);
1669 if (m_data.GetHash(line) != m_SelectedHash)
1671 m_SelectedHash = m_data.GetHash(line);
1673 int logIndex = m_lineToLogIndex[line];
1674 if (logIndex >= 0)
1676 this->GetLogList()->SetItemState(logIndex, LVIS_SELECTED, LVIS_SELECTED);
1677 this->GetLogList()->EnsureVisible(logIndex, FALSE);
1679 else
1681 GitRevLoglist* pRev = m_data.GetRev(line, GetLogData()->m_pLogCache->m_HashMap);
1682 this->GetDocument()->GetMainFrame()->m_wndProperties.UpdateProperties(pRev);
1685 else
1687 m_SelectedHash.Empty();
1689 this->Invalidate();
1690 this->m_TextView.Invalidate();
1693 else
1695 SetSelectedLine(-1);
1698 CView::OnLButtonDown(nFlags,point);
1701 void CTortoiseGitBlameView::OnSciGetBkColor(NMHDR* hdr, LRESULT* /*result*/)
1703 SCNotification *notification=reinterpret_cast<SCNotification *>(hdr);
1705 if (notification->line < m_data.GetNumberOfLines())
1707 if (m_data.GetHash(notification->line) == this->m_SelectedHash)
1708 notification->lParam = m_selectedauthorcolor;
1709 else
1710 notification->lParam = GetLineColor(notification->line);
1714 void CTortoiseGitBlameView::FocusOn(GitRevLoglist* pRev)
1716 this->GetDocument()->GetMainFrame()->m_wndProperties.UpdateProperties(pRev);
1718 this->Invalidate();
1720 if (m_SelectedHash != pRev->m_CommitHash) {
1721 m_SelectedHash = pRev->m_CommitHash;
1722 int line = m_data.FindFirstLine(m_SelectedHash, 0);
1723 if (line >= 0)
1725 GotoLine(line + 1);
1726 m_TextView.Invalidate();
1727 return;
1729 SendEditor(SCI_SETSEL, INT_MAX, -1);
1733 void CTortoiseGitBlameView::OnMouseHover(UINT /*nFlags*/, CPoint point)
1735 int line = GetLineUnderCursor(point);
1736 if (m_data.IsValidLine(line))
1738 if (line != m_MouseLine)
1740 m_MouseLine = line;
1741 GitRev *pRev = nullptr;
1742 int logIndex = m_lineToLogIndex[line];
1743 if (logIndex >= 0)
1744 pRev = &GetLogData()->GetGitRevAt(logIndex);
1745 else
1746 pRev = m_data.GetRev(line, GetLogData()->m_pLogCache->m_HashMap);
1748 if (!pRev)
1749 return;
1751 CString body = pRev->GetBody();
1752 int maxLine = 15;
1753 int iline = 0;
1754 int pos = 0;
1755 while (iline++ < maxLine)
1757 int pos2 = body.Find(L'\n', pos);
1758 if (pos2 < 0)
1759 break;
1760 int lineLength = pos2 - pos - 1;
1761 pos = pos2 + 1;
1762 iline += lineLength / 70;
1765 CString filename;
1766 if ((m_bShowCompleteLog && m_bFollowRenames && !m_bOnlyFirstParent) || !BlameIsLimitedToOneFilename(m_dwDetectMovedOrCopiedLines) || m_bBlameOuputContainsOtherFilenames)
1767 filename.Format(L"%s: %s\n", (LPCTSTR)m_sFileName, (LPCTSTR)m_data.GetFilename(line));
1769 CString str;
1770 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,
1771 (LPCTSTR)m_sAuthor, (LPCTSTR)pRev->GetAuthorName(), (LPCTSTR)pRev->GetAuthorEmail(),
1772 (LPCTSTR)m_sDate, (LPCTSTR)CLoglistUtils::FormatDateAndTime(pRev->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
1773 (LPCTSTR)m_sMessage, (LPCTSTR)pRev->GetSubject(),
1774 iline <= maxLine ? (LPCTSTR)body : (body.Left(pos) + L"\n...................."));
1776 m_ToolTip.Pop();
1777 m_ToolTip.AddTool(this, str);
1779 Invalidate();
1784 void CTortoiseGitBlameView::OnMouseMove(UINT /*nFlags*/, CPoint /*point*/)
1786 TRACKMOUSEEVENT tme;
1787 tme.cbSize=sizeof(TRACKMOUSEEVENT);
1788 tme.dwFlags=TME_HOVER|TME_LEAVE;
1789 tme.hwndTrack=this->m_hWnd;
1790 tme.dwHoverTime=1;
1791 TrackMouseEvent(&tme);
1792 Invalidate();
1795 void CTortoiseGitBlameView::OnMouseLeave()
1797 if (m_MouseLine == -1)
1798 return;
1800 m_MouseLine = -1;
1801 Invalidate();
1804 BOOL CTortoiseGitBlameView::PreTranslateMessage(MSG* pMsg)
1806 if (m_ToolTip.GetSafeHwnd())
1807 m_ToolTip.RelayEvent(pMsg);
1808 return CView::PreTranslateMessage(pMsg);
1811 void CTortoiseGitBlameView::OnEditFind()
1813 if (m_pFindDialog)
1814 return;
1816 m_pFindDialog=new CFindReplaceDialog();
1818 CString oneline = theApp.GetString(L"FindString");
1819 if (m_TextView.Call(SCI_GETSELECTIONSTART) != m_TextView.Call(SCI_GETSELECTIONEND))
1821 LRESULT bufsize = m_TextView.Call(SCI_GETSELECTIONEND) - m_TextView.Call(SCI_GETSELECTIONSTART);
1822 auto linebuf = std::make_unique<char[]>(bufsize + 1);
1823 SecureZeroMemory(linebuf.get(), bufsize + 1);
1824 SendEditor(SCI_GETSELTEXT, 0, (LPARAM)linebuf.get());
1825 oneline = m_TextView.StringFromControl(linebuf.get());
1828 DWORD flags = FR_DOWN | FR_HIDEWHOLEWORD;
1829 if (theApp.GetInt(L"FindMatchCase"))
1830 flags |= FR_MATCHCASE;
1832 m_pFindDialog->Create(TRUE, oneline, nullptr, flags, this);
1835 void CTortoiseGitBlameView::OnEditGoto()
1837 CEditGotoDlg dlg;
1838 if(dlg.DoModal()==IDOK)
1840 this->GotoLine(dlg.m_LineNumber);
1844 LRESULT CTortoiseGitBlameView::OnFindDialogMessage(WPARAM /*wParam*/, LPARAM /*lParam*/)
1846 ASSERT(m_pFindDialog);
1848 // If the FR_DIALOGTERM flag is set,
1849 // invalidate the handle identifying the dialog box.
1850 if (m_pFindDialog->IsTerminating())
1852 m_pFindDialog = nullptr;
1853 return 0;
1856 if (m_data.GetNumberOfLines()==0)
1857 return 0;
1859 // If the FR_FINDNEXT flag is set,
1860 // call the application-defined search routine
1861 // to search for the requested string.
1862 if(m_pFindDialog->FindNext())
1864 m_bMatchCase = !!(m_pFindDialog->MatchCase());
1865 m_sFindText = m_pFindDialog->GetFindString();
1867 theApp.WriteInt(L"FindMatchCase", m_bMatchCase ? 1 : 0);
1868 theApp.WriteString(L"FindString", m_sFindText);
1870 DoSearch(m_pFindDialog->SearchDown() ? CTortoiseGitBlameData::SearchNext : CTortoiseGitBlameData::SearchPrevious);
1873 return 0;
1876 void CTortoiseGitBlameView::OnViewNext()
1878 int startline = (int)SendEditor(SCI_GETFIRSTVISIBLELINE);
1879 int line = m_data.FindNextLine(this->m_SelectedHash, (int)SendEditor(SCI_GETFIRSTVISIBLELINE), false);
1880 if(line >= 0)
1881 SendEditor(SCI_LINESCROLL, 0, line - startline - 2);
1883 void CTortoiseGitBlameView::OnViewPrev()
1885 int startline = (int)SendEditor(SCI_GETFIRSTVISIBLELINE);
1886 int line = m_data.FindNextLine(this->m_SelectedHash, (int)SendEditor(SCI_GETFIRSTVISIBLELINE), true);
1887 if(line >= 0)
1888 SendEditor(SCI_LINESCROLL, 0, line - startline - 2);
1891 void CTortoiseGitBlameView::OnViewToggleAuthor()
1893 m_bShowAuthor = ! m_bShowAuthor;
1895 theApp.WriteInt(L"ShowAuthor", m_bShowAuthor);
1897 CRect rect;
1898 this->GetClientRect(&rect);
1899 rect.left=GetBlameWidth();
1901 m_TextView.MoveWindow(&rect);
1904 void CTortoiseGitBlameView::OnUpdateViewToggleAuthor(CCmdUI *pCmdUI)
1906 pCmdUI->SetCheck(m_bShowAuthor);
1909 void CTortoiseGitBlameView::OnViewToggleDate()
1911 m_bShowDate = ! m_bShowDate;
1913 theApp.WriteInt(L"ShowDate", m_bShowDate);
1915 CRect rect;
1916 this->GetClientRect(&rect);
1917 rect.left=GetBlameWidth();
1919 m_TextView.MoveWindow(&rect);
1922 void CTortoiseGitBlameView::OnUpdateViewToggleDate(CCmdUI *pCmdUI)
1924 pCmdUI->SetCheck(m_bShowDate);
1927 void CTortoiseGitBlameView::OnViewToggleShowFilename()
1929 m_bShowFilename = ! m_bShowFilename;
1931 theApp.WriteInt(L"ShowFilename", m_bShowFilename);
1933 CRect rect;
1934 this->GetClientRect(&rect);
1935 rect.left = GetBlameWidth();
1937 m_TextView.MoveWindow(&rect);
1940 void CTortoiseGitBlameView::OnUpdateViewToggleShowFilename(CCmdUI *pCmdUI)
1942 pCmdUI->SetCheck(m_bShowFilename);
1945 void CTortoiseGitBlameView::OnViewToggleShowOriginalLineNumber()
1947 m_bShowOriginalLineNumber = ! m_bShowOriginalLineNumber;
1949 theApp.WriteInt(L"ShowOriginalLineNumber", m_bShowOriginalLineNumber);
1951 CRect rect;
1952 this->GetClientRect(&rect);
1953 rect.left = GetBlameWidth();
1955 m_TextView.MoveWindow(&rect);
1958 void CTortoiseGitBlameView::OnUpdateViewToggleShowOriginalLineNumber(CCmdUI *pCmdUI)
1960 pCmdUI->SetCheck(m_bShowOriginalLineNumber);
1963 void CTortoiseGitBlameView::OnViewDetectMovedOrCopiedLines(DWORD dwDetectMovedOrCopiedLines)
1965 m_dwDetectMovedOrCopiedLines = dwDetectMovedOrCopiedLines;
1967 theApp.DoWaitCursor(1);
1969 theApp.WriteInt(L"DetectMovedOrCopiedLines", m_dwDetectMovedOrCopiedLines);
1971 auto document = static_cast<CTortoiseGitBlameDoc*>(m_pDocument);
1972 if (!document->m_CurrentFileName.IsEmpty())
1974 document->m_lLine = (int)SendEditor(SCI_GETFIRSTVISIBLELINE) + 1;
1975 theApp.m_pDocManager->OnFileNew();
1976 document->OnOpenDocument(document->m_CurrentFileName, document->m_Rev);
1978 theApp.DoWaitCursor(-1);
1981 void CTortoiseGitBlameView::OnViewDetectMovedOrCopiedLinesToggleDisabled()
1983 OnViewDetectMovedOrCopiedLines(BLAME_DETECT_MOVED_OR_COPIED_LINES_DISABLED);
1986 void CTortoiseGitBlameView::OnUpdateViewDetectMovedOrCopiedLinesToggleDisabled(CCmdUI *pCmdUI)
1988 pCmdUI->SetRadio(m_dwDetectMovedOrCopiedLines == BLAME_DETECT_MOVED_OR_COPIED_LINES_DISABLED);
1991 void CTortoiseGitBlameView::OnViewDetectMovedOrCopiedLinesToggleWithinFile()
1993 OnViewDetectMovedOrCopiedLines(BLAME_DETECT_MOVED_OR_COPIED_LINES_WITHIN_FILE);
1996 void CTortoiseGitBlameView::OnUpdateViewDetectMovedOrCopiedLinesToggleWithinFile(CCmdUI *pCmdUI)
1998 pCmdUI->SetRadio(m_dwDetectMovedOrCopiedLines == BLAME_DETECT_MOVED_OR_COPIED_LINES_WITHIN_FILE);
2001 void CTortoiseGitBlameView::OnViewDetectMovedOrCopiedLinesToggleFromModifiedFiles()
2003 OnViewDetectMovedOrCopiedLines(BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_MODIFIED_FILES);
2006 void CTortoiseGitBlameView::OnUpdateViewDetectMovedOrCopiedLinesToggleFromModifiedFiles(CCmdUI *pCmdUI)
2008 pCmdUI->SetRadio(m_dwDetectMovedOrCopiedLines == BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_MODIFIED_FILES);
2011 void CTortoiseGitBlameView::OnViewDetectMovedOrCopiedLinesToggleFromExistingFilesAtFileCreation()
2013 OnViewDetectMovedOrCopiedLines(BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES_AT_FILE_CREATION);
2016 void CTortoiseGitBlameView::OnUpdateViewDetectMovedOrCopiedLinesToggleFromExistingFilesAtFileCreation(CCmdUI *pCmdUI)
2018 pCmdUI->SetRadio(m_dwDetectMovedOrCopiedLines == BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES_AT_FILE_CREATION);
2021 void CTortoiseGitBlameView::OnViewDetectMovedOrCopiedLinesToggleFromExistingFiles()
2023 OnViewDetectMovedOrCopiedLines(BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES);
2026 void CTortoiseGitBlameView::OnUpdateViewDetectMovedOrCopiedLinesToggleFromExistingFiles(CCmdUI *pCmdUI)
2028 pCmdUI->SetRadio(m_dwDetectMovedOrCopiedLines == BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES);
2031 void CTortoiseGitBlameView::ReloadDocument()
2033 theApp.DoWaitCursor(1);
2034 auto document = static_cast<CTortoiseGitBlameDoc*>(m_pDocument);
2035 if (!document->m_CurrentFileName.IsEmpty())
2037 document->m_lLine = (int)SendEditor(SCI_GETFIRSTVISIBLELINE) + 1;
2038 theApp.m_pDocManager->OnFileNew();
2039 document->OnOpenDocument(document->m_CurrentFileName, document->m_Rev);
2041 theApp.DoWaitCursor(-1);
2044 void CTortoiseGitBlameView::OnViewToggleIgnoreWhitespace()
2046 m_bIgnoreWhitespace = ! m_bIgnoreWhitespace;
2048 theApp.WriteInt(L"IgnoreWhitespace", m_bIgnoreWhitespace ? 1 : 0);
2050 ReloadDocument();
2053 void CTortoiseGitBlameView::OnUpdateViewToggleIgnoreWhitespace(CCmdUI *pCmdUI)
2055 pCmdUI->SetCheck(m_bIgnoreWhitespace);
2058 void CTortoiseGitBlameView::OnViewToggleShowCompleteLog()
2060 m_bShowCompleteLog = ! m_bShowCompleteLog;
2062 theApp.WriteInt(L"ShowCompleteLog", m_bShowCompleteLog ? 1 : 0);
2064 ReloadDocument();
2067 void CTortoiseGitBlameView::OnUpdateViewToggleOnlyFirstParent(CCmdUI* pCmdUI)
2069 pCmdUI->SetCheck(m_bOnlyFirstParent);
2072 void CTortoiseGitBlameView::OnViewToggleOnlyFirstParent()
2074 m_bOnlyFirstParent = !m_bOnlyFirstParent;
2076 theApp.WriteInt(L"OnlyFirstParent", m_bOnlyFirstParent ? 1 : 0);
2078 ReloadDocument();
2081 void CTortoiseGitBlameView::OnUpdateViewToggleShowCompleteLog(CCmdUI *pCmdUI)
2083 pCmdUI->Enable(BlameIsLimitedToOneFilename(m_dwDetectMovedOrCopiedLines) && !m_bOnlyFirstParent);
2084 pCmdUI->SetCheck(m_bShowCompleteLog && BlameIsLimitedToOneFilename(m_dwDetectMovedOrCopiedLines) && !m_bOnlyFirstParent);
2087 void CTortoiseGitBlameView::OnViewToggleFollowRenames()
2089 m_bFollowRenames = ! m_bFollowRenames;
2091 theApp.WriteInt(L"FollowRenames", m_bFollowRenames ? 1 : 0);
2093 ReloadDocument();
2096 void CTortoiseGitBlameView::OnUpdateViewToggleFollowRenames(CCmdUI *pCmdUI)
2098 pCmdUI->Enable(m_bShowCompleteLog && BlameIsLimitedToOneFilename(m_dwDetectMovedOrCopiedLines) && !m_bOnlyFirstParent);
2099 pCmdUI->SetCheck(m_bFollowRenames && m_bShowCompleteLog && BlameIsLimitedToOneFilename(m_dwDetectMovedOrCopiedLines) && !m_bOnlyFirstParent);
2102 void CTortoiseGitBlameView::OnViewToggleColorByAge()
2104 m_colorage = ! m_colorage;
2106 theApp.WriteInt(L"ColorAge", m_colorage);
2108 m_TextView.Invalidate();
2111 void CTortoiseGitBlameView::OnUpdateViewToggleColorByAge(CCmdUI *pCmdUI)
2113 pCmdUI->SetCheck(m_colorage);
2116 void CTortoiseGitBlameView::OnViewToggleLexer()
2118 m_bLexer = !m_bLexer;
2120 theApp.WriteInt(L"EnableLexer", m_bLexer);
2122 InitialiseEditor();
2123 SetupLexer(GetDocument()->m_CurrentFileName);
2124 this->Invalidate();
2127 void CTortoiseGitBlameView::OnUpdateViewToggleLexer(CCmdUI *pCmdUI)
2129 pCmdUI->SetCheck(m_bLexer);
2132 void CTortoiseGitBlameView::OnViewWrapLongLines()
2134 m_bWrapLongLines = !m_bWrapLongLines;
2136 theApp.WriteInt(L"WrapLongLines", m_bWrapLongLines);
2138 if (m_bWrapLongLines)
2139 SendEditor(SCI_SETWRAPMODE, SC_WRAP_WORD);
2140 else
2141 SendEditor(SCI_SETWRAPMODE, SC_WRAP_NONE);
2144 void CTortoiseGitBlameView::OnUpdateViewWrapLongLines(CCmdUI* pCmdUI)
2146 pCmdUI->SetCheck(m_bWrapLongLines);
2149 void CTortoiseGitBlameView::OnUpdateViewCopyToClipboard(CCmdUI *pCmdUI)
2151 CWnd * wnd = GetFocus();
2152 if (wnd == GetLogList())
2153 pCmdUI->Enable(GetLogList()->GetSelectedCount() > 0);
2154 else if (wnd)
2156 if (CString(wnd->GetRuntimeClass()->m_lpszClassName) == L"CMFCPropertyGridCtrl")
2158 CMFCPropertyGridCtrl *grid = (CMFCPropertyGridCtrl *)wnd;
2159 pCmdUI->Enable(grid->GetCurSel() && !grid->GetCurSel()->IsGroup() && !CString(grid->GetCurSel()->GetValue()).IsEmpty());
2161 else
2162 pCmdUI->Enable(m_TextView.Call(SCI_GETSELECTIONSTART) != m_TextView.Call(SCI_GETSELECTIONEND));
2164 else
2165 pCmdUI->Enable(FALSE);
2168 void CTortoiseGitBlameView::OnSysColorChange()
2170 __super::OnSysColorChange();
2171 m_windowcolor = ::GetSysColor(COLOR_WINDOW);
2172 m_textcolor = ::GetSysColor(COLOR_WINDOWTEXT);
2173 m_texthighlightcolor = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
2174 m_mouserevcolor = InterColor(m_windowcolor, m_textcolor, 20);
2175 m_mouseauthorcolor = InterColor(m_windowcolor, m_textcolor, 10);
2176 m_selectedrevcolor = ::GetSysColor(COLOR_HIGHLIGHT);
2177 m_selectedauthorcolor = InterColor(m_selectedrevcolor, m_texthighlightcolor, 35);
2178 InitialiseEditor();
2179 SetupLexer(GetDocument()->m_CurrentFileName);