TortoiseGitBlame: Reinitialize the editor on every file load
[TortoiseGit.git] / src / TortoiseGitBlame / TortoiseGitBlameView.cpp
blob2094796a3602da4361e22f5dc8f4b7a35cc3ed74
1 // TortoiseGitBlame - a Viewer for Git Blames
3 // Copyright (C) 2008-2015 - TortoiseGit
4 // Copyright (C) 2010-2013 Sven Strickroth <email@cs-ware.de>
5 // Copyright (C) 2003-2008, 2014 - TortoiseSVN
7 // Copyright (C)2003 Don HO <donho@altern.org>
9 // This program is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU General Public License
11 // as published by the Free Software Foundation; either version 2
12 // of the License, or (at your option) any later version.
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
19 // You should have received a copy of the GNU General Public License
20 // along with this program; if not, write to the Free Software Foundation,
21 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 // CTortoiseGitBlameView.cpp : implementation of the CTortoiseGitBlameView class
26 #include "stdafx.h"
27 #include "TortoiseGitBlame.h"
28 #include "CommonAppUtils.h"
29 #include "TortoiseGitBlameDoc.h"
30 #include "TortoiseGitBlameView.h"
31 #include "MainFrm.h"
32 #include "EditGotoDlg.h"
33 #include "LoglistUtils.h"
34 #include "FileTextLines.h"
35 #include "UnicodeUtils.h"
36 #include "MenuEncode.h"
37 #include "gitdll.h"
38 #include "SysInfo.h"
39 #include "StringUtils.h"
40 #include "BlameIndexColors.h"
41 #include "BlameDetectMovedOrCopiedLines.h"
42 #include "TGitPath.h"
43 #include "IconMenu.h"
45 #ifdef _DEBUG
46 #define new DEBUG_NEW
47 #endif
49 UINT CTortoiseGitBlameView::m_FindDialogMessage;
51 // CTortoiseGitBlameView
52 IMPLEMENT_DYNAMIC(CSciEditBlame,CSciEdit)
54 IMPLEMENT_DYNCREATE(CTortoiseGitBlameView, CView)
56 BEGIN_MESSAGE_MAP(CTortoiseGitBlameView, CView)
57 // Standard printing commands
58 ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)
59 ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
60 ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CTortoiseGitBlameView::OnFilePrintPreview)
61 ON_COMMAND(ID_EDIT_FIND,OnEditFind)
62 ON_COMMAND(ID_EDIT_GOTO,OnEditGoto)
63 ON_COMMAND(ID_EDIT_COPY, CopyToClipboard)
64 ON_UPDATE_COMMAND_UI(ID_EDIT_COPY, OnUpdateViewCopyToClipboard)
65 ON_COMMAND(ID_VIEW_NEXT,OnViewNext)
66 ON_COMMAND(ID_VIEW_PREV,OnViewPrev)
67 ON_COMMAND(ID_FIND_NEXT, OnFindNext)
68 ON_COMMAND(ID_FIND_PREV, OnFindPrev)
69 ON_COMMAND(ID_VIEW_SHOWAUTHOR, OnViewToggleAuthor)
70 ON_UPDATE_COMMAND_UI(ID_VIEW_SHOWAUTHOR, OnUpdateViewToggleAuthor)
71 ON_COMMAND(ID_VIEW_SHOWDATE, OnViewToggleDate)
72 ON_UPDATE_COMMAND_UI(ID_VIEW_SHOWDATE, OnUpdateViewToggleDate)
73 ON_COMMAND(ID_VIEW_SHOWFILENAME, OnViewToggleShowFilename)
74 ON_UPDATE_COMMAND_UI(ID_VIEW_SHOWFILENAME, OnUpdateViewToggleShowFilename)
75 ON_COMMAND(ID_VIEW_SHOWORIGINALLINENUMBER, OnViewToggleShowOriginalLineNumber)
76 ON_UPDATE_COMMAND_UI(ID_VIEW_SHOWORIGINALLINENUMBER, OnUpdateViewToggleShowOriginalLineNumber)
77 ON_COMMAND(ID_VIEW_DETECT_MOVED_OR_COPIED_LINES_DISABLED, OnViewDetectMovedOrCopiedLinesToggleDisabled)
78 ON_UPDATE_COMMAND_UI(ID_VIEW_DETECT_MOVED_OR_COPIED_LINES_DISABLED, OnUpdateViewDetectMovedOrCopiedLinesToggleDisabled)
79 ON_COMMAND(ID_VIEW_DETECT_MOVED_OR_COPIED_LINES_WITHIN_FILE, OnViewDetectMovedOrCopiedLinesToggleWithinFile)
80 ON_UPDATE_COMMAND_UI(ID_VIEW_DETECT_MOVED_OR_COPIED_LINES_WITHIN_FILE, OnUpdateViewDetectMovedOrCopiedLinesToggleWithinFile)
81 ON_COMMAND(ID_VIEW_DETECT_MOVED_OR_COPIED_LINES_FROM_MODIFIED_FILES, OnViewDetectMovedOrCopiedLinesToggleFromModifiedFiles)
82 ON_UPDATE_COMMAND_UI(ID_VIEW_DETECT_MOVED_OR_COPIED_LINES_FROM_MODIFIED_FILES, OnUpdateViewDetectMovedOrCopiedLinesToggleFromModifiedFiles)
83 ON_COMMAND(ID_VIEW_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES_AT_FILE_CREATION, OnViewDetectMovedOrCopiedLinesToggleFromExistingFilesAtFileCreation)
84 ON_UPDATE_COMMAND_UI(ID_VIEW_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES_AT_FILE_CREATION, OnUpdateViewDetectMovedOrCopiedLinesToggleFromExistingFilesAtFileCreation)
85 ON_COMMAND(ID_VIEW_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES, OnViewDetectMovedOrCopiedLinesToggleFromExistingFiles)
86 ON_UPDATE_COMMAND_UI(ID_VIEW_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES, OnUpdateViewDetectMovedOrCopiedLinesToggleFromExistingFiles)
87 ON_COMMAND(ID_VIEW_IGNORE_WHITESPACE, OnViewToggleIgnoreWhitespace)
88 ON_UPDATE_COMMAND_UI(ID_VIEW_IGNORE_WHITESPACE, OnUpdateViewToggleIgnoreWhitespace)
89 ON_COMMAND(ID_VIEW_SHOWCOMPLETELOG, OnViewToggleShowCompleteLog)
90 ON_UPDATE_COMMAND_UI(ID_VIEW_SHOWCOMPLETELOG, OnUpdateViewToggleShowCompleteLog)
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_RANGE(IDM_FORMAT_ENCODE, IDM_FORMAT_ENCODE_END, OnChangeEncode)
96 ON_WM_CREATE()
97 ON_WM_SIZE()
98 ON_WM_MOUSEMOVE()
99 ON_WM_MOUSEHOVER()
100 ON_WM_MOUSELEAVE()
101 ON_WM_LBUTTONDOWN()
102 ON_WM_RBUTTONDOWN()
103 ON_WM_RBUTTONUP()
104 ON_NOTIFY(SCN_PAINTED, IDC_SCINTILLA, OnSciPainted)
105 ON_NOTIFY(SCN_GETBKCOLOR, IDC_SCINTILLA, OnSciGetBkColor)
106 ON_REGISTERED_MESSAGE(m_FindDialogMessage, OnFindDialogMessage)
107 END_MESSAGE_MAP()
110 // CTortoiseGitBlameView construction/destruction
112 CTortoiseGitBlameView::CTortoiseGitBlameView()
113 : wBlame(0)
114 , wHeader(0)
115 , hwndTT(0)
116 , bIgnoreEOL(false)
117 , bIgnoreSpaces(false)
118 , bIgnoreAllSpaces(false)
119 , m_MouseLine(-1)
120 , m_bMatchCase(false)
122 hInstance = 0;
123 hResource = 0;
124 currentDialog = 0;
125 wMain = 0;
126 wLocator = 0;
128 m_font = 0;
129 m_italicfont = 0;
130 m_blamewidth = 0;
131 m_revwidth = 0;
132 m_datewidth = 0;
133 m_authorwidth = 0;
134 m_filenameWidth = 0;
135 m_originalLineNumberWidth = 0;
136 m_linewidth = 0;
138 m_windowcolor = ::GetSysColor(COLOR_WINDOW);
139 m_textcolor = ::GetSysColor(COLOR_WINDOWTEXT);
140 m_texthighlightcolor = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
141 m_mouserevcolor = InterColor(m_windowcolor, m_textcolor, 20);
142 m_mouseauthorcolor = InterColor(m_windowcolor, m_textcolor, 10);
143 m_selectedrevcolor = ::GetSysColor(COLOR_HIGHLIGHT);
144 m_selectedauthorcolor = InterColor(m_selectedrevcolor, m_texthighlightcolor, 35);
146 m_SelectedLine = -1;
148 m_colorage = !!theApp.GetInt(_T("ColorAge"));
150 m_bShowLine=true;
152 m_bShowAuthor = (theApp.GetInt(_T("ShowAuthor"), 1) == 1);
153 m_bShowDate = (theApp.GetInt(_T("ShowDate"), 0) == 1);
154 m_bShowFilename = (theApp.GetInt(_T("ShowFilename"), 0) == 1);
155 m_bShowOriginalLineNumber = (theApp.GetInt(_T("ShowOriginalLineNumber"), 0) == 1);
156 m_dwDetectMovedOrCopiedLines = theApp.GetInt(_T("DetectMovedOrCopiedLines"), 0);
157 m_bIgnoreWhitespace = (theApp.GetInt(_T("IgnoreWhitespace"), 0) == 1);
158 m_bShowCompleteLog = (theApp.GetInt(_T("ShowCompleteLog"), 1) == 1);
159 m_bFollowRenames = (theApp.GetInt(_T("FollowRenames"), 0) == 1);
160 m_bBlameOuputContainsOtherFilenames = FALSE;
162 m_FindDialogMessage = ::RegisterWindowMessage(FINDMSGSTRING);
163 m_pFindDialog = NULL;
164 // get short/long datetime setting from registry
165 DWORD RegUseShortDateFormat = CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE);
166 if ( RegUseShortDateFormat )
168 m_DateFormat = DATE_SHORTDATE;
170 else
172 m_DateFormat = DATE_LONGDATE;
174 // get relative time display setting from registry
175 DWORD regRelativeTimes = CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE);
176 m_bRelativeTimes = (regRelativeTimes != 0);
178 m_sRev.LoadString(IDS_LOG_REVISION);
179 m_sFileName.LoadString(IDS_FILENAME);
180 m_sAuthor.LoadString(IDS_LOG_AUTHOR);
181 m_sDate.LoadString(IDS_LOG_DATE);
182 m_sMessage.LoadString(IDS_LOG_MESSAGE);
184 #ifdef USE_TEMPFILENAME
185 m_Buffer = NULL;
186 #endif
189 CTortoiseGitBlameView::~CTortoiseGitBlameView()
191 if (m_font)
192 DeleteObject(m_font);
193 if (m_italicfont)
194 DeleteObject(m_italicfont);
196 #ifdef USE_TEMPFILENAME
197 if(m_Buffer)
199 delete m_Buffer;
200 m_Buffer=NULL;
202 #endif
204 struct EncodingUnit
206 int id;
207 char *name;
210 static EncodingUnit encodings[] = {
211 {1250, "windows-1250"}, //IDM_FORMAT_WIN_1250
212 {1251, "windows-1251"}, //IDM_FORMAT_WIN_1251
213 {1252, "windows-1252"}, //IDM_FORMAT_WIN_1252
214 {1253, "windows-1253"}, //IDM_FORMAT_WIN_1253
215 {1254, "windows-1254"}, //IDM_FORMAT_WIN_1254
216 {1255, "windows-1255"}, //IDM_FORMAT_WIN_1255
217 {1256, "windows-1256"}, //IDM_FORMAT_WIN_1256
218 {1257, "windows-1257"}, //IDM_FORMAT_WIN_1257
219 {1258, "windows-1258"}, //IDM_FORMAT_WIN_1258
220 {28591, "latin1 ISO_8859-1 ISO-8859-1 CP819 IBM819 csISOLatin1 iso-ir-100 l1"}, //IDM_FORMAT_ISO_8859_1
221 {28592, "latin2 ISO_8859-2 ISO-8859-2 csISOLatin2 iso-ir-101 l2"}, //IDM_FORMAT_ISO_8859_2
222 {28593, "latin3 ISO_8859-3 ISO-8859-3 csISOLatin3 iso-ir-109 l3"}, //IDM_FORMAT_ISO_8859_3
223 {28594, "latin4 ISO_8859-4 ISO-8859-4 csISOLatin4 iso-ir-110 l4"}, //IDM_FORMAT_ISO_8859_4
224 {28595, "cyrillic ISO_8859-5 ISO-8859-5 csISOLatinCyrillic iso-ir-144"}, //IDM_FORMAT_ISO_8859_5
225 {28596, "arabic ISO_8859-6 ISO-8859-6 csISOLatinArabic iso-ir-127 ASMO-708 ECMA-114"}, //IDM_FORMAT_ISO_8859_6
226 {28597, "greek ISO_8859-7 ISO-8859-7 csISOLatinGreek greek8 iso-ir-126 ELOT_928 ECMA-118"}, //IDM_FORMAT_ISO_8859_7
227 {28598, "hebrew ISO_8859-8 ISO-8859-8 csISOLatinHebrew iso-ir-138"}, //IDM_FORMAT_ISO_8859_8
228 {28599, "latin5 ISO_8859-9 ISO-8859-9 csISOLatin5 iso-ir-148 l5"}, //IDM_FORMAT_ISO_8859_9
229 {28600, "latin6 ISO_8859-10 ISO-8859-10 csISOLatin6 iso-ir-157 l6"}, //IDM_FORMAT_ISO_8859_10
230 {28601, "ISO_8859-11 ISO-8859-11"}, //IDM_FORMAT_ISO_8859_11
231 {28603, "ISO_8859-13 ISO-8859-13"}, //IDM_FORMAT_ISO_8859_13
232 {28604, "iso-celtic latin8 ISO_8859-14 ISO-8859-14 18 iso-ir-199"}, //IDM_FORMAT_ISO_8859_14
233 {28605, "Latin-9 ISO_8859-15 ISO-8859-15"}, //IDM_FORMAT_ISO_8859_15
234 {28606, "latin10 ISO_8859-16 ISO-8859-16 110 iso-ir-226"}, //IDM_FORMAT_ISO_8859_16
235 {437, "IBM437 cp437 437 csPC8CodePage437"}, //IDM_FORMAT_DOS_437
236 {720, "IBM720 cp720 oem720 720"}, //IDM_FORMAT_DOS_720
237 {737, "IBM737 cp737 oem737 737"}, //IDM_FORMAT_DOS_737
238 {775, "IBM775 cp775 oem775 775"}, //IDM_FORMAT_DOS_775
239 {850, "IBM850 cp850 oem850 850"}, //IDM_FORMAT_DOS_850
240 {852, "IBM852 cp852 oem852 852"}, //IDM_FORMAT_DOS_852
241 {855, "IBM855 cp855 oem855 855 csIBM855"}, //IDM_FORMAT_DOS_855
242 {857, "IBM857 cp857 oem857 857"}, //IDM_FORMAT_DOS_857
243 {858, "IBM858 cp858 oem858 858"}, //IDM_FORMAT_DOS_858
244 {860, "IBM860 cp860 oem860 860"}, //IDM_FORMAT_DOS_860
245 {861, "IBM861 cp861 oem861 861"}, //IDM_FORMAT_DOS_861
246 {862, "IBM862 cp862 oem862 862"}, //IDM_FORMAT_DOS_862
247 {863, "IBM863 cp863 oem863 863"}, //IDM_FORMAT_DOS_863
248 {865, "IBM865 cp865 oem865 865"}, //IDM_FORMAT_DOS_865
249 {866, "IBM866 cp866 oem866 866"}, //IDM_FORMAT_DOS_866
250 {869, "IBM869 cp869 oem869 869"}, //IDM_FORMAT_DOS_869
251 {950, "big5 csBig5"}, //IDM_FORMAT_BIG5
252 {936, "gb2312 gbk csGB2312"}, //IDM_FORMAT_GB2312
253 {932, "Shift_JIS MS_Kanji csShiftJIS csWindows31J"}, //IDM_FORMAT_SHIFT_JIS
254 {949, "windows-949 korean"}, //IDM_FORMAT_KOREAN_WIN
255 {51949, "euc-kr csEUCKR"}, //IDM_FORMAT_EUC_KR
256 {874, "tis-620"}, //IDM_FORMAT_TIS_620
257 {10007, "x-mac-cyrillic xmaccyrillic"}, //IDM_FORMAT_MAC_CYRILLIC
258 {21866, "koi8_u"}, //IDM_FORMAT_KOI8U_CYRILLIC
259 {20866, "koi8_r csKOI8R"}, //IDM_FORMAT_KOI8R_CYRILLIC
260 {65001, "UTF-8"}, //IDM_FORMAT_UTF8
261 {1200, "UTF-16 LE"}, //IDM_FORMAT_UTF16LE
262 {1201, "UTF-16 BE"}, //IDM_FORMAT_UTF16BE
264 void CTortoiseGitBlameView::OnChangeEncode(UINT nId)
266 if(nId >= IDM_FORMAT_ENCODE && nId <= IDM_FORMAT_ENCODE_END)
267 this->UpdateInfo(encodings[nId - IDM_FORMAT_ENCODE].id);
269 int CTortoiseGitBlameView::OnCreate(LPCREATESTRUCT lpcs)
272 CRect rect,rect1;
273 this->GetWindowRect(&rect1);
274 rect.left=m_blamewidth+LOCATOR_WIDTH;
275 rect.right=rect.Width();
276 rect.top=0;
277 rect.bottom=rect.Height();
278 if (!m_TextView.Create(_T("Scintilla"), _T("source"), 0, rect, this, IDC_SCINTILLA, 0))
280 TRACE0("Failed to create view\n");
281 return -1; // fail to create
283 m_TextView.Init(0,FALSE);
284 m_TextView.ShowWindow( SW_SHOW);
285 CreateFont();
286 SendEditor(SCI_SETREADONLY, TRUE);
287 m_ToolTip.Create(this->GetParent());
289 ::AfxGetApp()->GetMainWnd();
290 return CView::OnCreate(lpcs);
294 void CTortoiseGitBlameView::OnSize(UINT /*nType*/, int cx, int cy)
297 CRect rect;
298 rect.left=m_blamewidth;
299 rect.right=cx;
300 rect.top=0;
301 rect.bottom=cy;
303 m_TextView.MoveWindow(&rect);
306 BOOL CTortoiseGitBlameView::PreCreateWindow(CREATESTRUCT& cs)
308 return CView::PreCreateWindow(cs);
311 // CTortoiseGitBlameView drawing
313 void CTortoiseGitBlameView::OnDraw(CDC* /*pDC*/)
315 CTortoiseGitBlameDoc* pDoc = GetDocument();
316 ASSERT_VALID(pDoc);
317 if (!pDoc)
318 return;
320 DrawBlame(this->GetDC()->m_hDC);
321 DrawLocatorBar(this->GetDC()->m_hDC);
322 // TODO: add draw code for native data here
326 // CTortoiseGitBlameView printing
329 void CTortoiseGitBlameView::OnFilePrintPreview()
331 AFXPrintPreview(this);
334 BOOL CTortoiseGitBlameView::OnPreparePrinting(CPrintInfo* pInfo)
336 // default preparation
337 return DoPreparePrinting(pInfo);
340 void CTortoiseGitBlameView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
342 // TODO: add extra initialization before printing
345 void CTortoiseGitBlameView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
347 // TODO: add cleanup after printing
350 void CTortoiseGitBlameView::OnRButtonUp(UINT /*nFlags*/, CPoint point)
352 int line = (int)SendEditor(SCI_GETFIRSTVISIBLELINE);
353 int height = (int)SendEditor(SCI_TEXTHEIGHT);
354 line = line + (int)(point.y / height);
355 if (m_data.IsValidLine(line))
357 m_MouseLine = line;
358 ClientToScreen(&point);
360 CGitHash hash = m_data.GetHash(line);
361 CString hashStr = hash.ToString();
363 GitRevLoglist* pRev = nullptr;
364 int logIndex = m_lineToLogIndex[line];
365 if (logIndex >= 0)
366 pRev = &GetLogData()->GetGitRevAt(logIndex);
367 else
369 pRev = m_data.GetRev(line, GetLogData()->m_pLogCache->m_HashMap);
370 if (pRev && pRev->m_ParentHash.empty())
372 if (pRev->GetParentFromHash(pRev->m_CommitHash))
373 MessageBox(pRev->GetLastErr(), _T("TortoiseGit"), MB_ICONERROR);
377 if (!pRev)
378 return;
380 CIconMenu popup;
381 CIconMenu blamemenu, diffmenu;
383 if (!popup.CreatePopupMenu())
384 return;
386 // Now find the relevant parent commits, they must contain the file which is blamed to be the source of the selected line,
387 // otherwise there is no previous file to compare to (only another previous revision).
389 GIT_REV_LIST parentHashWithFile;
390 std::vector<CString> parentFilename;
393 CTGitPath path(m_data.GetFilename(line));
394 const CTGitPathList & files = pRev->GetFiles(NULL);
395 for (int j = 0, j_size = files.GetCount(); j < j_size; ++j)
397 const CTGitPath &file = files[j];
398 if (file.IsEquivalentTo(path))
400 if (!(file.m_ParentNo & MERGE_MASK))
402 int action = file.m_Action;
403 // ignore (action & CTGitPath::LOGACTIONS_ADDED), as then there is nothing to blame/diff
404 // ignore (action & CTGitPath::LOGACTIONS_DELETED), should never happen as the file must exist
405 if (action & (CTGitPath::LOGACTIONS_MODIFIED | CTGitPath::LOGACTIONS_REPLACED))
407 int parentNo = file.m_ParentNo & PARENT_MASK;
408 if (parentNo >= 0 && (size_t)parentNo < pRev->m_ParentHash.size())
410 parentHashWithFile.push_back(pRev->m_ParentHash[parentNo]);
411 parentFilename.push_back((action & CTGitPath::LOGACTIONS_REPLACED) ? file.GetGitOldPathString() : file.GetGitPathString());
418 catch (const char* msg)
420 MessageBox(_T("Could not get files of parents.\nlibgit reports:\n") + CString(msg), _T("TortoiseGit"), MB_ICONERROR);
423 // blame previous
424 if (!parentHashWithFile.empty())
426 if (parentHashWithFile.size() == 1)
428 popup.AppendMenuIcon(ID_BLAMEPREVIOUS, IDS_BLAME_POPUP_BLAME, IDI_BLAME_POPUP_BLAME);
430 else
432 blamemenu.CreatePopupMenu();
433 popup.AppendMenuIcon(ID_BLAMEPREVIOUS, IDS_BLAME_POPUP_BLAME, IDI_BLAME_POPUP_BLAME, blamemenu.m_hMenu);
435 for (size_t i = 0; i < parentHashWithFile.size(); ++i)
437 CString str;
438 str.Format(IDS_PARENT, i + 1);
439 blamemenu.AppendMenuIcon(ID_BLAMEPREVIOUS + ((i + 1) << 16), str);
444 // compare with previous
445 if (!parentHashWithFile.empty())
447 if (parentHashWithFile.size() == 1)
449 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_BLAME_POPUP_COMPARE, IDI_BLAME_POPUP_COMPARE);
450 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
451 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
453 else
455 diffmenu.CreatePopupMenu();
456 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_BLAME_POPUP_COMPARE, IDI_BLAME_POPUP_COMPARE, diffmenu.m_hMenu);
457 for (size_t i = 0; i < parentHashWithFile.size(); ++i)
459 CString str;
460 str.Format(IDS_BLAME_POPUP_PARENT, i + 1);
461 diffmenu.AppendMenuIcon((UINT)(ID_COMPAREWITHPREVIOUS + ((i + 1) << 16)),str);
462 if (i == 0 && CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
464 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
465 diffmenu.SetDefaultItem((UINT)(ID_COMPAREWITHPREVIOUS + ((i + 1) << 16)), FALSE);
471 popup.AppendMenuIcon(ID_SHOWLOG, IDS_BLAME_POPUP_LOG, IDI_BLAME_POPUP_LOG);
472 popup.AppendMenu(MF_SEPARATOR, NULL);
473 popup.AppendMenuIcon(ID_COPYHASHTOCLIPBOARD, IDS_BLAME_POPUP_COPYHASHTOCLIPBOARD, IDI_BLAME_POPUP_COPY);
474 popup.AppendMenuIcon(ID_COPYLOGTOCLIPBOARD, IDS_BLAME_POPUP_COPYLOGTOCLIPBOARD, IDI_BLAME_POPUP_COPY);
476 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
477 this->ContextMenuAction(cmd, pRev, parentHashWithFile, parentFilename);
481 void CTortoiseGitBlameView::ContextMenuAction(int cmd, GitRev *pRev, GIT_REV_LIST& parentHashWithFile, const std::vector<CString>& parentFilename)
483 switch (cmd & 0xFFFF)
485 case ID_BLAMEPREVIOUS:
487 int index = (cmd>>16) & 0xFFFF;
488 if (index > 0)
489 index -= 1;
491 CString path = ResolveCommitFile(parentFilename[index]);
492 CString endrev = parentHashWithFile[index].ToString();
493 int line = m_data.GetOriginalLineNumber(m_MouseLine);
494 CString lineNumber;
495 lineNumber.Format(_T("%d"), line);
497 CString procCmd = _T("/path:\"") + path + _T("\" ");
498 procCmd += _T(" /command:blame");
499 procCmd += _T(" /endrev:") + endrev;
500 procCmd += _T(" /line:") + lineNumber;
502 CCommonAppUtils::RunTortoiseGitProc(procCmd);
504 break;
506 case ID_COMPAREWITHPREVIOUS:
508 int index = (cmd >> 16) & 0xFFFF;
509 if (index > 0)
510 index -= 1;
512 CString path = ResolveCommitFile(parentFilename[index]);
513 CString startrev = pRev->m_CommitHash.ToString();
514 CString endrev = parentHashWithFile[index].ToString();
516 CString procCmd = _T("/path:\"") + path + _T("\" ");
517 procCmd += _T(" /command:diff");
518 procCmd += _T(" /startrev:") + startrev;
519 procCmd += _T(" /endrev:") + endrev;
521 CCommonAppUtils::RunTortoiseGitProc(procCmd);
523 break;
525 case ID_SHOWLOG:
527 CString path = ResolveCommitFile(m_MouseLine);
528 CString rev = m_data.GetHash(m_MouseLine).ToString();
530 CString procCmd = _T("/path:\"") + path + _T("\" ");
531 procCmd += _T(" /command:log");
532 procCmd += _T(" /rev:") + rev;
534 CCommonAppUtils::RunTortoiseGitProc(procCmd);
536 break;
538 case ID_COPYHASHTOCLIPBOARD:
539 this->GetLogList()->CopySelectionToClipBoard(CGitLogListBase::ID_COPY_HASH);
540 break;
542 case ID_COPYLOGTOCLIPBOARD:
543 this->GetLogList()->CopySelectionToClipBoard();
544 break;
548 // CTortoiseGitBlameView diagnostics
550 #ifdef _DEBUG
551 void CTortoiseGitBlameView::AssertValid() const
553 CView::AssertValid();
556 void CTortoiseGitBlameView::Dump(CDumpContext& dc) const
558 CView::Dump(dc);
561 CTortoiseGitBlameDoc* CTortoiseGitBlameView::GetDocument() const // non-debug version is inline
563 ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTortoiseGitBlameDoc)));
564 return (CTortoiseGitBlameDoc*)m_pDocument;
566 #endif //_DEBUG
569 // CTortoiseGitBlameView message handlers
570 CString CTortoiseGitBlameView::GetAppDirectory()
572 CString path;
573 DWORD len = 0;
574 DWORD bufferlen = MAX_PATH; // MAX_PATH is not the limit here!
577 bufferlen += MAX_PATH; // MAX_PATH is not the limit here!
578 std::unique_ptr<TCHAR[]> pBuf(new TCHAR[bufferlen]);
579 len = GetModuleFileName(NULL, pBuf.get(), bufferlen);
580 path = CString(pBuf.get(), len);
581 } while(len == bufferlen);
583 path = path.Left(path.ReverseFind(_T('\\')));
584 //path = path.substr(0, path.rfind('\\') + 1);
586 return path;
589 // Return a color which is interpolated between c1 and c2.
590 // Slider controls the relative proportions as a percentage:
591 // Slider = 0 represents pure c1
592 // Slider = 50 represents equal mixture
593 // Slider = 100 represents pure c2
594 COLORREF CTortoiseGitBlameView::InterColor(COLORREF c1, COLORREF c2, int Slider)
596 int r, g, b;
598 // Limit Slider to 0..100% range
599 if (Slider < 0)
600 Slider = 0;
601 if (Slider > 100)
602 Slider = 100;
604 // The color components have to be treated individually.
605 r = (GetRValue(c2) * Slider + GetRValue(c1) * (100 - Slider)) / 100;
606 g = (GetGValue(c2) * Slider + GetGValue(c1) * (100 - Slider)) / 100;
607 b = (GetBValue(c2) * Slider + GetBValue(c1) * (100 - Slider)) / 100;
609 return RGB(r, g, b);
612 LRESULT CTortoiseGitBlameView::SendEditor(UINT Msg, WPARAM wParam, LPARAM lParam)
614 return m_TextView.Call(Msg, wParam, lParam);
617 void CTortoiseGitBlameView::SetAStyle(int style, COLORREF fore, COLORREF back, int size, const char *face)
619 m_TextView.SetAStyle(style, fore, back, size, face);
622 void CTortoiseGitBlameView::InitialiseEditor()
624 SendEditor(SCI_STYLERESETDEFAULT);
625 // Set up the global default style. These attributes are used wherever no explicit choices are made.
626 std::string fontName = CUnicodeUtils::StdGetUTF8((stdstring)CRegStdString(_T("Software\\TortoiseGit\\BlameFontName"), _T("Courier New")));
627 SetAStyle(STYLE_DEFAULT,
628 ::GetSysColor(COLOR_WINDOWTEXT),
629 ::GetSysColor(COLOR_WINDOW),
630 (DWORD)CRegStdDWORD(_T("Software\\TortoiseGit\\BlameFontSize"), 10),
631 fontName.c_str()
633 SendEditor(SCI_SETTABWIDTH, (DWORD)CRegStdDWORD(_T("Software\\TortoiseGit\\BlameTabSize"), 4));
634 SendEditor(SCI_SETREADONLY, TRUE);
635 LRESULT pix = SendEditor(SCI_TEXTWIDTH, STYLE_LINENUMBER, (LPARAM)this->m_TextView.StringForControl(_T("_99999")).GetBuffer());
636 if (m_bShowLine)
637 SendEditor(SCI_SETMARGINWIDTHN, 0, pix);
638 else
639 SendEditor(SCI_SETMARGINWIDTHN, 0);
640 SendEditor(SCI_SETMARGINWIDTHN, 1);
641 SendEditor(SCI_SETMARGINWIDTHN, 2);
642 //Set the default windows colors for edit controls
643 SendEditor(SCI_SETSELFORE, TRUE, ::GetSysColor(COLOR_HIGHLIGHTTEXT));
644 SendEditor(SCI_SETSELBACK, TRUE, ::GetSysColor(COLOR_HIGHLIGHT));
645 SendEditor(SCI_SETCARETFORE, ::GetSysColor(COLOR_WINDOWTEXT));
646 m_regOldLinesColor = CRegStdDWORD(_T("Software\\TortoiseGit\\BlameOldColor"), BLAMEOLDCOLOR);
647 m_regNewLinesColor = CRegStdDWORD(_T("Software\\TortoiseGit\\BlameNewColor"), BLAMENEWCOLOR);
648 CRegStdDWORD used2d(L"Software\\TortoiseGit\\ScintillaDirect2D", FALSE);
649 if (SysInfo::Instance().IsWin7OrLater() && DWORD(used2d))
651 SendEditor(SCI_SETTECHNOLOGY, SC_TECHNOLOGY_DIRECTWRITERETAIN);
652 SendEditor(SCI_SETBUFFEREDDRAW, 0);
655 SendEditor(SCI_SETWRAPMODE, SC_WRAP_NONE);
656 SendEditor(SCI_STYLECLEARALL);
659 bool CTortoiseGitBlameView::DoSearch(CTortoiseGitBlameData::SearchDirection direction)
661 int pos = (int)SendEditor(SCI_GETCURRENTPOS);
662 int line = (int)SendEditor(SCI_LINEFROMPOSITION, pos);
664 int i = m_data.FindFirstLineWrapAround(direction, m_sFindText, line, m_bMatchCase);
665 if (i >= 0)
667 GotoLine(i + 1);
668 int selstart = (int)SendEditor(SCI_GETCURRENTPOS);
669 int selend = (int)SendEditor(SCI_POSITIONFROMLINE, i + 1);
670 SendEditor(SCI_SETSELECTIONSTART, selstart);
671 SendEditor(SCI_SETSELECTIONEND, selend);
672 m_SelectedLine = i;
674 else
676 ::MessageBox(m_pFindDialog && m_pFindDialog->GetSafeHwnd() ? m_pFindDialog->GetSafeHwnd() : wMain, _T("\"") + m_sFindText + _T("\" ") + CString(MAKEINTRESOURCE(IDS_NOTFOUND)), _T("TortoiseGitBlame"), MB_ICONINFORMATION);
679 return true;
682 void CTortoiseGitBlameView::OnFindPrev()
684 if (m_sFindText.IsEmpty())
685 return;
686 DoSearch(CTortoiseGitBlameData::SearchPrevious);
689 void CTortoiseGitBlameView::OnFindNext()
691 if (m_sFindText.IsEmpty())
692 return;
693 DoSearch(CTortoiseGitBlameData::SearchNext);
696 bool CTortoiseGitBlameView::GotoLine(int line)
698 --line;
699 int numberOfLines = m_data.GetNumberOfLines();
700 if (line < 0 || numberOfLines == 0)
701 return false;
702 if (line >= numberOfLines)
704 line = numberOfLines - 1;
707 int nCurrentPos = (int)SendEditor(SCI_GETCURRENTPOS);
708 int nCurrentLine = (int)SendEditor(SCI_LINEFROMPOSITION,nCurrentPos);
709 int nFirstVisibleLine = (int)SendEditor(SCI_GETFIRSTVISIBLELINE);
710 int nLinesOnScreen = (int)SendEditor(SCI_LINESONSCREEN);
712 if ( line>=nFirstVisibleLine && line<=nFirstVisibleLine+nLinesOnScreen)
714 // no need to scroll
715 SendEditor(SCI_GOTOLINE, line);
717 else
719 // Place the requested line one third from the top
720 if ( line > nCurrentLine )
722 SendEditor(SCI_GOTOLINE, (WPARAM)(line+(int)nLinesOnScreen*(2/3.0)));
724 else
726 SendEditor(SCI_GOTOLINE, (WPARAM)(line-(int)nLinesOnScreen*(1/3.0)));
730 // Highlight the line
731 int nPosStart = (int)SendEditor(SCI_POSITIONFROMLINE,line);
732 int nPosEnd = (int)SendEditor(SCI_GETLINEENDPOSITION,line);
733 SendEditor(SCI_SETSEL,nPosEnd,nPosStart);
735 return true;
738 bool CTortoiseGitBlameView::ScrollToLine(long line)
740 if (line < 0)
741 return false;
743 int nCurrentLine = (int)SendEditor(SCI_GETFIRSTVISIBLELINE);
745 int scrolldelta = line - nCurrentLine;
746 SendEditor(SCI_LINESCROLL, 0, scrolldelta);
748 return true;
751 void CTortoiseGitBlameView::CopyToClipboard()
753 CWnd * wnd = GetFocus();
754 if (wnd == this->GetLogList())
755 GetLogList()->CopySelectionToClipBoard();
756 else if (wnd)
758 if (CString(wnd->GetRuntimeClass()->m_lpszClassName) == _T("CMFCPropertyGridCtrl"))
760 CMFCPropertyGridCtrl *grid = (CMFCPropertyGridCtrl *)wnd;
761 if (grid->GetCurSel() && !grid->GetCurSel()->IsGroup())
762 CStringUtils::WriteAsciiStringToClipboard(grid->GetCurSel()->GetValue(), GetSafeHwnd());
764 else
765 m_TextView.Call(SCI_COPY);
769 LONG CTortoiseGitBlameView::GetBlameWidth()
771 LONG blamewidth = 0;
772 SIZE width;
773 CreateFont();
774 HDC hDC = this->GetDC()->m_hDC;
775 HFONT oldfont = (HFONT)::SelectObject(hDC, m_font);
777 CString shortHash('f', g_Git.GetShortHASHLength() + 1);
778 ::GetTextExtentPoint32(hDC, shortHash, g_Git.GetShortHASHLength() + 1, &width);
779 m_revwidth = width.cx + BLAMESPACE;
780 blamewidth += m_revwidth;
782 if (m_bShowDate)
784 SIZE maxwidth = {0};
786 int numberOfLines = m_data.GetNumberOfLines();
787 for (int i = 0; i < numberOfLines; ++i)
789 ::GetTextExtentPoint32(hDC, m_data.GetDate(i), m_data.GetDate(i).GetLength(), &width);
790 if (width.cx > maxwidth.cx)
791 maxwidth = width;
793 m_datewidth = maxwidth.cx + BLAMESPACE;
794 blamewidth += m_datewidth;
796 if ( m_bShowAuthor)
798 SIZE maxwidth = {0};
800 int numberOfLines = m_data.GetNumberOfLines();
801 for (int i = 0; i < numberOfLines; ++i)
803 ::GetTextExtentPoint32(hDC,m_data.GetAuthor(i) , m_data.GetAuthor(i).GetLength(), &width);
804 if (width.cx > maxwidth.cx)
805 maxwidth = width;
807 m_authorwidth = maxwidth.cx + BLAMESPACE;
808 blamewidth += m_authorwidth;
810 if (m_bShowFilename)
812 SIZE maxwidth = {0};
814 int numberOfLines = m_data.GetNumberOfLines();
815 for (int i = 0; i < numberOfLines; ++i)
817 ::GetTextExtentPoint32(hDC, m_data.GetFilename(i), m_data.GetFilename(i).GetLength(), &width);
818 if (width.cx > maxwidth.cx)
819 maxwidth = width;
821 m_filenameWidth = maxwidth.cx + BLAMESPACE;
822 blamewidth += m_filenameWidth;
824 if (m_bShowOriginalLineNumber)
826 SIZE maxwidth = {0};
828 int numberOfLines = m_data.GetNumberOfLines();
829 CString str;
830 for (int i = 0; i < numberOfLines; ++i)
832 str.Format(_T("%5d"), m_data.GetOriginalLineNumber(i));
833 ::GetTextExtentPoint32(hDC, str, str.GetLength(), &width);
834 if (width.cx > maxwidth.cx)
835 maxwidth = width;
837 m_originalLineNumberWidth = maxwidth.cx + BLAMESPACE;
838 blamewidth += m_originalLineNumberWidth;
840 ::SelectObject(hDC, oldfont);
841 POINT pt = {blamewidth, 0};
842 LPtoDP(hDC, &pt, 1);
843 m_blamewidth = pt.x;
844 //::ReleaseDC(wBlame, hDC);
845 return blamewidth;
849 void CTortoiseGitBlameView::CreateFont()
851 if (m_font)
852 return;
853 LOGFONT lf = {0};
854 lf.lfWeight = 400;
855 HDC hDC = ::GetDC(wBlame);
856 lf.lfHeight = -MulDiv((DWORD)CRegStdDWORD(_T("Software\\TortoiseGit\\BlameFontSize"), 10), GetDeviceCaps(hDC, LOGPIXELSY), 72);
857 lf.lfCharSet = DEFAULT_CHARSET;
858 CRegStdString fontname = CRegStdString(_T("Software\\TortoiseGit\\BlameFontName"), _T("Courier New"));
859 _tcscpy_s(lf.lfFaceName, 32, ((stdstring)fontname).c_str());
860 m_font = ::CreateFontIndirect(&lf);
862 lf.lfItalic = TRUE;
863 m_italicfont = ::CreateFontIndirect(&lf);
865 ::ReleaseDC(wBlame, hDC);
868 void CTortoiseGitBlameView::DrawBlame(HDC hDC)
870 if (hDC == NULL)
871 return;
872 if (m_font == NULL)
873 return;
875 HFONT oldfont = NULL;
876 int line = (int)SendEditor(SCI_GETFIRSTVISIBLELINE);
877 int linesonscreen = (int)SendEditor(SCI_LINESONSCREEN);
878 int height = (int)SendEditor(SCI_TEXTHEIGHT);
879 int Y = 0;
880 TCHAR buf[MAX_PATH] = {0};
881 RECT rc;
882 BOOL sel = FALSE;
883 //::GetClientRect(this->m_hWnd, &rc);
884 for (int i = line; i < (line + linesonscreen); ++i)
886 sel = FALSE;
887 if (i < m_data.GetNumberOfLines())
889 CGitHash hash(m_data.GetHash(i));
890 // if (mergelines[i])
891 // oldfont = (HFONT)::SelectObject(hDC, m_italicfont);
892 // else
893 oldfont = (HFONT)::SelectObject(hDC, m_font);
894 ::SetBkColor(hDC, m_windowcolor);
895 ::SetTextColor(hDC, m_textcolor);
896 if (!hash.IsEmpty())
898 //if (m_CommitHash[i].Compare(m_MouseHash)==0)
899 // ::SetBkColor(hDC, m_mouseauthorcolor);
900 if (hash == m_SelectedHash)
902 ::SetBkColor(hDC, m_selectedauthorcolor);
903 ::SetTextColor(hDC, m_texthighlightcolor);
904 sel = TRUE;
908 if(m_MouseLine == i)
909 ::SetBkColor(hDC, m_mouserevcolor);
911 //if ((revs[i] == m_mouserev)&&(!sel))
912 // ::SetBkColor(hDC, m_mouserevcolor);
913 //if (revs[i] == m_selectedrev)
915 // ::SetBkColor(hDC, m_selectedrevcolor);
916 // ::SetTextColor(hDC, m_texthighlightcolor);
919 CString shortHashStr;
920 shortHashStr = hash.ToString().Left(g_Git.GetShortHASHLength());
922 //_stprintf_s(buf, MAX_PATH, _T("%8ld "), revs[i]);
923 rc.top = (LONG)Y;
924 rc.left=LOCATOR_WIDTH;
925 rc.bottom = (LONG)(Y + height);
926 rc.right = rc.left + m_blamewidth;
927 ::ExtTextOut(hDC, LOCATOR_WIDTH, Y, ETO_CLIPPED, &rc, shortHashStr, shortHashStr.GetLength(), 0);
928 int Left = m_revwidth;
930 if (m_bShowAuthor)
932 rc.right = rc.left + Left + m_authorwidth;
933 ::ExtTextOut(hDC, Left, Y, ETO_CLIPPED, &rc, m_data.GetAuthor(i), m_data.GetAuthor(i).GetLength(), 0);
934 Left += m_authorwidth;
936 if (m_bShowDate)
938 rc.right = rc.left + Left + m_datewidth;
939 ::ExtTextOut(hDC, Left, Y, ETO_CLIPPED, &rc, m_data.GetDate(i), m_data.GetDate(i).GetLength(), 0);
940 Left += m_datewidth;
942 if (m_bShowFilename)
944 rc.right = rc.left + Left + m_filenameWidth;
945 ::ExtTextOut(hDC, Left, (int)Y, ETO_CLIPPED, &rc, m_data.GetFilename(i), m_data.GetFilename(i).GetLength(), 0);
946 Left += m_filenameWidth;
948 if (m_bShowOriginalLineNumber)
950 rc.right = rc.left + Left + m_originalLineNumberWidth;
951 CString str;
952 str.Format(_T("%5d"), m_data.GetOriginalLineNumber(i));
953 ::ExtTextOut(hDC, Left, (int)Y, ETO_CLIPPED, &rc, str, str.GetLength(), 0);
954 Left += m_originalLineNumberWidth;
956 if ((i==m_SelectedLine)&&(m_pFindDialog))
958 LOGBRUSH brush;
959 brush.lbColor = m_textcolor;
960 brush.lbHatch = 0;
961 brush.lbStyle = BS_SOLID;
962 HPEN pen = ExtCreatePen(PS_SOLID | PS_GEOMETRIC, 2, &brush, 0, NULL);
963 HGDIOBJ hPenOld = SelectObject(hDC, pen);
964 RECT rc2 = rc;
965 rc2.top = (LONG)Y;
966 rc2.bottom = (LONG)(Y + height);
967 ::MoveToEx(hDC, rc2.left, rc2.top, NULL);
968 ::LineTo(hDC, rc2.right, rc2.top);
969 ::LineTo(hDC, rc2.right, rc2.bottom);
970 ::LineTo(hDC, rc2.left, rc2.bottom);
971 ::LineTo(hDC, rc2.left, rc2.top);
972 SelectObject(hDC, hPenOld);
973 DeleteObject(pen);
975 Y += height;
976 ::SelectObject(hDC, oldfont);
978 else
980 ::SetBkColor(hDC, m_windowcolor);
981 for (int j=0; j< MAX_PATH; ++j)
982 buf[j]=' ';
983 ::ExtTextOut(hDC, 0, (int)Y, ETO_CLIPPED, &rc, buf, MAX_PATH-1, 0);
984 Y += height;
989 void CTortoiseGitBlameView::DrawLocatorBar(HDC hDC)
991 if (hDC == NULL)
992 return;
994 int line = (int)SendEditor(SCI_GETFIRSTVISIBLELINE);
995 int linesonscreen = (int)SendEditor(SCI_LINESONSCREEN);
996 int Y = 0;
997 COLORREF blackColor = GetSysColor(COLOR_WINDOWTEXT);
999 RECT rc;
1000 //::GetClientRect(wLocator, &rc);
1001 this->GetClientRect(&rc);
1003 rc.right=LOCATOR_WIDTH;
1005 RECT lineRect = rc;
1006 LONG height = rc.bottom-rc.top;
1008 int numberOfLines = m_data.GetNumberOfLines();
1009 // draw the colored bar
1010 for (int currentLine = 0; currentLine<numberOfLines; ++currentLine)
1012 COLORREF cr = GetLineColor(currentLine);
1013 // get the line color
1014 if ((currentLine >= line)&&(currentLine < (line + linesonscreen)))
1016 cr = InterColor(cr, blackColor, 10);
1018 SetBkColor(hDC, cr);
1019 lineRect.top = (LONG)Y;
1020 lineRect.bottom = ((currentLine + 1) * height / numberOfLines);
1021 ::ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &lineRect, NULL, 0, NULL);
1022 Y = lineRect.bottom;
1025 if (numberOfLines > 0)
1027 // now draw two lines indicating the scroll position of the source view
1028 SetBkColor(hDC, blackColor);
1029 lineRect.top = (LONG)line * height / numberOfLines;
1030 lineRect.bottom = lineRect.top+1;
1031 ::ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &lineRect, NULL, 0, NULL);
1032 lineRect.top = (LONG)(line + linesonscreen) * height / numberOfLines;
1033 lineRect.bottom = lineRect.top+1;
1034 ::ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &lineRect, NULL, 0, NULL);
1039 void CTortoiseGitBlameView::StringExpand(LPSTR str) const
1041 char * cPos = str;
1044 cPos = strchr(cPos, '\n');
1045 if (cPos)
1047 memmove(cPos+1, cPos, strlen(cPos)*sizeof(char));
1048 *cPos = '\r';
1049 ++cPos;
1050 ++cPos;
1052 } while (cPos != NULL);
1054 void CTortoiseGitBlameView::StringExpand(LPWSTR str) const
1056 wchar_t * cPos = str;
1059 cPos = wcschr(cPos, '\n');
1060 if (cPos)
1062 memmove(cPos+1, cPos, wcslen(cPos)*sizeof(wchar_t));
1063 *cPos = '\r';
1064 ++cPos;
1065 ++cPos;
1067 } while (cPos != NULL);
1070 void CTortoiseGitBlameView::SetupLexer(CString filename)
1072 int start=filename.ReverseFind(_T('.'));
1073 SendEditor(SCI_SETLEXER, SCLEX_NULL);
1074 if (start>0)
1076 //_tcscpy_s(line, 20, lineptr+1);
1077 //_tcslwr_s(line, 20);
1078 CString ext=filename.Right(filename.GetLength()-start-1);
1079 const TCHAR* line = ext;
1081 if ((_tcscmp(line, _T("py"))==0)||
1082 (_tcscmp(line, _T("pyw"))==0))
1084 SendEditor(SCI_SETLEXER, SCLEX_PYTHON);
1085 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("and assert break class continue def del elif \
1086 else except exec finally for from global if import in is lambda None \
1087 not or pass print raise return try while yield")).GetBuffer()));
1088 SetAStyle(SCE_P_DEFAULT, black);
1089 SetAStyle(SCE_P_COMMENTLINE, darkGreen);
1090 SetAStyle(SCE_P_NUMBER, RGB(0, 0x80, 0x80));
1091 SetAStyle(SCE_P_STRING, RGB(0, 0, 0x80));
1092 SetAStyle(SCE_P_CHARACTER, RGB(0, 0, 0x80));
1093 SetAStyle(SCE_P_WORD, RGB(0x80, 0, 0x80));
1094 SetAStyle(SCE_P_TRIPLE, black);
1095 SetAStyle(SCE_P_TRIPLEDOUBLE, black);
1096 SetAStyle(SCE_P_CLASSNAME, darkBlue);
1097 SetAStyle(SCE_P_DEFNAME, darkBlue);
1098 SetAStyle(SCE_P_OPERATOR, darkBlue);
1099 SetAStyle(SCE_P_IDENTIFIER, darkBlue);
1100 SetAStyle(SCE_P_COMMENTBLOCK, darkGreen);
1101 SetAStyle(SCE_P_STRINGEOL, red);
1103 if ((_tcscmp(line, _T("c"))==0)||
1104 (_tcscmp(line, _T("cc"))==0)||
1105 (_tcscmp(line, _T("cpp"))==0)||
1106 (_tcscmp(line, _T("cxx"))==0)||
1107 (_tcscmp(line, _T("h"))==0)||
1108 (_tcscmp(line, _T("hh"))==0)||
1109 (_tcscmp(line, _T("hpp"))==0)||
1110 (_tcscmp(line, _T("hxx"))==0)||
1111 (_tcscmp(line, _T("dlg"))==0)||
1112 (_tcscmp(line, _T("mak"))==0))
1114 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1115 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("and and_eq asm auto bitand bitor bool break \
1116 case catch char class compl const const_cast continue \
1117 default delete do double dynamic_cast else enum explicit export extern false float for \
1118 friend goto if inline int long mutable namespace new not not_eq \
1119 operator or or_eq private protected public \
1120 register reinterpret_cast return short signed sizeof static static_cast struct switch \
1121 template this throw true try typedef typeid typename union unsigned using \
1122 virtual void volatile wchar_t while xor xor_eq")).GetBuffer()));
1123 SendEditor(SCI_SETKEYWORDS, 3, (LPARAM)(m_TextView.StringForControl(_T("a addindex addtogroup anchor arg attention \
1124 author b brief bug c class code date def defgroup deprecated dontinclude \
1125 e em endcode endhtmlonly endif endlatexonly endlink endverbatim enum example exception \
1126 f$ f[ f] file fn hideinitializer htmlinclude htmlonly \
1127 if image include ingroup internal invariant interface latexonly li line link \
1128 mainpage name namespace nosubgrouping note overload \
1129 p page par param post pre ref relates remarks return retval \
1130 sa section see showinitializer since skip skipline struct subsection \
1131 test throw todo typedef union until \
1132 var verbatim verbinclude version warning weakgroup $ @ \\ & < > # { }")).GetBuffer()));
1133 SetupCppLexer();
1135 if (_tcscmp(line, _T("cs"))==0)
1137 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1138 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("abstract as base bool break byte case catch char checked class \
1139 const continue decimal default delegate do double else enum \
1140 event explicit extern false finally fixed float for foreach goto if \
1141 implicit in int interface internal is lock long namespace new null \
1142 object operator out override params private protected public \
1143 readonly ref return sbyte sealed short sizeof stackalloc static \
1144 string struct switch this throw true try typeof uint ulong \
1145 unchecked unsafe ushort using virtual void while")).GetBuffer()));
1146 SetupCppLexer();
1148 if ((_tcscmp(line, _T("rc"))==0)||
1149 (_tcscmp(line, _T("rc2"))==0))
1151 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1152 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("ACCELERATORS ALT AUTO3STATE AUTOCHECKBOX AUTORADIOBUTTON \
1153 BEGIN BITMAP BLOCK BUTTON CAPTION CHARACTERISTICS CHECKBOX CLASS \
1154 COMBOBOX CONTROL CTEXT CURSOR DEFPUSHBUTTON DIALOG DIALOGEX DISCARDABLE \
1155 EDITTEXT END EXSTYLE FONT GROUPBOX ICON LANGUAGE LISTBOX LTEXT \
1156 MENU MENUEX MENUITEM MESSAGETABLE POPUP \
1157 PUSHBUTTON RADIOBUTTON RCDATA RTEXT SCROLLBAR SEPARATOR SHIFT STATE3 \
1158 STRINGTABLE STYLE TEXTINCLUDE VALUE VERSION VERSIONINFO VIRTKEY")).GetBuffer()));
1159 SetupCppLexer();
1161 if ((_tcscmp(line, _T("idl"))==0)||
1162 (_tcscmp(line, _T("odl"))==0))
1164 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1165 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("aggregatable allocate appobject arrays async async_uuid \
1166 auto_handle \
1167 bindable boolean broadcast byte byte_count \
1168 call_as callback char coclass code comm_status \
1169 const context_handle context_handle_noserialize \
1170 context_handle_serialize control cpp_quote custom \
1171 decode default defaultbind defaultcollelem \
1172 defaultvalue defaultvtable dispinterface displaybind dllname \
1173 double dual \
1174 enable_allocate encode endpoint entry enum error_status_t \
1175 explicit_handle \
1176 fault_status first_is float \
1177 handle_t heap helpcontext helpfile helpstring \
1178 helpstringcontext helpstringdll hidden hyper \
1179 id idempotent ignore iid_as iid_is immediatebind implicit_handle \
1180 import importlib in include in_line int __int64 __int3264 interface \
1181 last_is lcid length_is library licensed local long \
1182 max_is maybe message methods midl_pragma \
1183 midl_user_allocate midl_user_free min_is module ms_union \
1184 ncacn_at_dsp ncacn_dnet_nsp ncacn_http ncacn_ip_tcp \
1185 ncacn_nb_ipx ncacn_nb_nb ncacn_nb_tcp ncacn_np \
1186 ncacn_spx ncacn_vns_spp ncadg_ip_udp ncadg_ipx ncadg_mq \
1187 ncalrpc nocode nonbrowsable noncreatable nonextensible notify \
1188 object odl oleautomation optimize optional out out_of_line \
1189 pipe pointer_default pragma properties propget propput propputref \
1190 ptr public \
1191 range readonly ref represent_as requestedit restricted retval \
1192 shape short signed size_is small source strict_context_handle \
1193 string struct switch switch_is switch_type \
1194 transmit_as typedef \
1195 uidefault union unique unsigned user_marshal usesgetlasterror uuid \
1196 v1_enum vararg version void wchar_t wire_marshal")).GetBuffer()));
1197 SetupCppLexer();
1199 if (_tcscmp(line, _T("java"))==0)
1201 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1202 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("abstract assert boolean break byte case catch char class \
1203 const continue default do double else extends final finally float for future \
1204 generic goto if implements import inner instanceof int interface long \
1205 native new null outer package private protected public rest \
1206 return short static super switch synchronized this throw throws \
1207 transient try var void volatile while")).GetBuffer()));
1208 SetupCppLexer();
1210 if (_tcscmp(line, _T("js"))==0)
1212 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1213 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("abstract boolean break byte case catch char class \
1214 const continue debugger default delete do double else enum export extends \
1215 final finally float for function goto if implements import in instanceof \
1216 int interface long native new package private protected public \
1217 return short static super switch synchronized this throw throws \
1218 transient try typeof var void volatile while with")).GetBuffer()));
1219 SetupCppLexer();
1221 if ((_tcscmp(line, _T("pas"))==0)||
1222 (_tcscmp(line, _T("dpr"))==0)||
1223 (_tcscmp(line, _T("pp"))==0))
1225 SendEditor(SCI_SETLEXER, SCLEX_PASCAL);
1226 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("and array as begin case class const constructor \
1227 destructor div do downto else end except file finally \
1228 for function goto if implementation in inherited \
1229 interface is mod not object of on or packed \
1230 procedure program property raise record repeat \
1231 set shl shr then threadvar to try type unit \
1232 until uses var while with xor")).GetBuffer()));
1233 SetupCppLexer();
1235 if ((_tcscmp(line, _T("as"))==0)||
1236 (_tcscmp(line, _T("asc"))==0)||
1237 (_tcscmp(line, _T("jsfl"))==0))
1239 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1240 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("add and break case catch class continue default delete do \
1241 dynamic else eq extends false finally for function ge get gt if implements import in \
1242 instanceof interface intrinsic le lt ne new not null or private public return \
1243 set static super switch this throw true try typeof undefined var void while with")).GetBuffer()));
1244 SendEditor(SCI_SETKEYWORDS, 1, (LPARAM)(m_TextView.StringForControl(_T("Array Arguments Accessibility Boolean Button Camera Color \
1245 ContextMenu ContextMenuItem Date Error Function Key LoadVars LocalConnection Math \
1246 Microphone Mouse MovieClip MovieClipLoader NetConnection NetStream Number Object \
1247 PrintJob Selection SharedObject Sound Stage String StyleSheet System TextField \
1248 TextFormat TextSnapshot Video Void XML XMLNode XMLSocket \
1249 _accProps _focusrect _global _highquality _parent _quality _root _soundbuftime \
1250 arguments asfunction call capabilities chr clearInterval duplicateMovieClip \
1251 escape eval fscommand getProperty getTimer getURL getVersion gotoAndPlay gotoAndStop \
1252 ifFrameLoaded Infinity -Infinity int isFinite isNaN length loadMovie loadMovieNum \
1253 loadVariables loadVariablesNum maxscroll mbchr mblength mbord mbsubstring MMExecute \
1254 NaN newline nextFrame nextScene on onClipEvent onUpdate ord parseFloat parseInt play \
1255 prevFrame prevScene print printAsBitmap printAsBitmapNum printNum random removeMovieClip \
1256 scroll set setInterval setProperty startDrag stop stopAllSounds stopDrag substring \
1257 targetPath tellTarget toggleHighQuality trace unescape unloadMovie unLoadMovieNum updateAfterEvent")).GetBuffer()));
1258 SetupCppLexer();
1260 if ((_tcscmp(line, _T("html"))==0)||
1261 (_tcscmp(line, _T("htm"))==0)||
1262 (_tcscmp(line, _T("shtml"))==0)||
1263 (_tcscmp(line, _T("htt"))==0)||
1264 (_tcscmp(line, _T("xml"))==0)||
1265 (_tcscmp(line, _T("asp"))==0)||
1266 (_tcscmp(line, _T("xsl"))==0)||
1267 (_tcscmp(line, _T("php"))==0)||
1268 (_tcscmp(line, _T("xhtml"))==0)||
1269 (_tcscmp(line, _T("phtml"))==0)||
1270 (_tcscmp(line, _T("cfm"))==0)||
1271 (_tcscmp(line, _T("tpl"))==0)||
1272 (_tcscmp(line, _T("dtd"))==0)||
1273 (_tcscmp(line, _T("hta"))==0)||
1274 (_tcscmp(line, _T("htd"))==0)||
1275 (_tcscmp(line, _T("wxs"))==0))
1277 SendEditor(SCI_SETLEXER, SCLEX_HTML);
1278 SendEditor(SCI_SETSTYLEBITS, 7);
1279 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("a abbr acronym address applet area b base basefont \
1280 bdo big blockquote body br button caption center \
1281 cite code col colgroup dd del dfn dir div dl dt em \
1282 fieldset font form frame frameset h1 h2 h3 h4 h5 h6 \
1283 head hr html i iframe img input ins isindex kbd label \
1284 legend li link map menu meta noframes noscript \
1285 object ol optgroup option p param pre q s samp \
1286 script select small span strike strong style sub sup \
1287 table tbody td textarea tfoot th thead title tr tt u ul \
1288 var xml xmlns abbr accept-charset accept accesskey action align alink \
1289 alt archive axis background bgcolor border \
1290 cellpadding cellspacing char charoff charset checked cite \
1291 class classid clear codebase codetype color cols colspan \
1292 compact content coords \
1293 data datafld dataformatas datapagesize datasrc datetime \
1294 declare defer dir disabled enctype event \
1295 face for frame frameborder \
1296 headers height href hreflang hspace http-equiv \
1297 id ismap label lang language leftmargin link longdesc \
1298 marginwidth marginheight maxlength media method multiple \
1299 name nohref noresize noshade nowrap \
1300 object onblur onchange onclick ondblclick onfocus \
1301 onkeydown onkeypress onkeyup onload onmousedown \
1302 onmousemove onmouseover onmouseout onmouseup \
1303 onreset onselect onsubmit onunload \
1304 profile prompt readonly rel rev rows rowspan rules \
1305 scheme scope selected shape size span src standby start style \
1306 summary tabindex target text title topmargin type usemap \
1307 valign value valuetype version vlink vspace width \
1308 text password checkbox radio submit reset \
1309 file hidden image")).GetBuffer()));
1310 SendEditor(SCI_SETKEYWORDS, 1, (LPARAM)(m_TextView.StringForControl(_T("assign audio block break catch choice clear disconnect else elseif \
1311 emphasis enumerate error exit field filled form goto grammar help \
1312 if initial link log menu meta noinput nomatch object option p paragraph \
1313 param phoneme prompt property prosody record reprompt return s say-as \
1314 script sentence subdialog submit throw transfer value var voice vxml")).GetBuffer()));
1315 SendEditor(SCI_SETKEYWORDS, 2, (LPARAM)(m_TextView.StringForControl(_T("accept age alphabet anchor application base beep bridge category charset \
1316 classid cond connecttimeout content contour count dest destexpr dtmf dtmfterm \
1317 duration enctype event eventexpr expr expritem fetchtimeout finalsilence \
1318 gender http-equiv id level maxage maxstale maxtime message messageexpr \
1319 method mime modal mode name namelist next nextitem ph pitch range rate \
1320 scope size sizeexpr skiplist slot src srcexpr sub time timeexpr timeout \
1321 transferaudio type value variant version volume xml:lang")).GetBuffer()));
1322 SendEditor(SCI_SETKEYWORDS, 3, (LPARAM)(m_TextView.StringForControl(_T("and assert break class continue def del elif \
1323 else except exec finally for from global if import in is lambda None \
1324 not or pass print raise return try while yield")).GetBuffer()));
1325 SendEditor(SCI_SETKEYWORDS, 4, (LPARAM)(m_TextView.StringForControl(_T("and argv as argc break case cfunction class continue declare default do \
1326 die echo else elseif empty enddeclare endfor endforeach endif endswitch \
1327 endwhile e_all e_parse e_error e_warning eval exit extends false for \
1328 foreach function global http_cookie_vars http_get_vars http_post_vars \
1329 http_post_files http_env_vars http_server_vars if include include_once \
1330 list new not null old_function or parent php_os php_self php_version \
1331 print require require_once return static switch stdclass this true var \
1332 xor virtual while __file__ __line__ __sleep __wakeup")).GetBuffer()));
1334 SetAStyle(SCE_H_TAG, darkBlue);
1335 SetAStyle(SCE_H_TAGUNKNOWN, red);
1336 SetAStyle(SCE_H_ATTRIBUTE, darkBlue);
1337 SetAStyle(SCE_H_ATTRIBUTEUNKNOWN, red);
1338 SetAStyle(SCE_H_NUMBER, RGB(0x80,0,0x80));
1339 SetAStyle(SCE_H_DOUBLESTRING, RGB(0,0x80,0));
1340 SetAStyle(SCE_H_SINGLESTRING, RGB(0,0x80,0));
1341 SetAStyle(SCE_H_OTHER, RGB(0x80,0,0x80));
1342 SetAStyle(SCE_H_COMMENT, RGB(0x80,0x80,0));
1343 SetAStyle(SCE_H_ENTITY, RGB(0x80,0,0x80));
1345 SetAStyle(SCE_H_TAGEND, darkBlue);
1346 SetAStyle(SCE_H_XMLSTART, darkBlue); // <?
1347 SetAStyle(SCE_H_QUESTION, darkBlue); // <?
1348 SetAStyle(SCE_H_XMLEND, darkBlue); // ?>
1349 SetAStyle(SCE_H_SCRIPT, darkBlue); // <script
1350 SetAStyle(SCE_H_ASP, RGB(0x4F, 0x4F, 0), RGB(0xFF, 0xFF, 0)); // <% ... %>
1351 SetAStyle(SCE_H_ASPAT, RGB(0x4F, 0x4F, 0), RGB(0xFF, 0xFF, 0)); // <%@ ... %>
1353 SetAStyle(SCE_HB_DEFAULT, black);
1354 SetAStyle(SCE_HB_COMMENTLINE, darkGreen);
1355 SetAStyle(SCE_HB_NUMBER, RGB(0,0x80,0x80));
1356 SetAStyle(SCE_HB_WORD, darkBlue);
1357 SendEditor(SCI_STYLESETBOLD, SCE_HB_WORD, 1);
1358 SetAStyle(SCE_HB_STRING, RGB(0x80,0,0x80));
1359 SetAStyle(SCE_HB_IDENTIFIER, black);
1361 // This light blue is found in the windows system palette so is safe to use even in 256 colour modes.
1362 // Show the whole section of VBScript with light blue background
1363 for (int bstyle = SCE_HB_DEFAULT; bstyle <= SCE_HB_STRINGEOL; ++bstyle) {
1364 SendEditor(SCI_STYLESETFONT, bstyle,
1365 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
1366 SendEditor(SCI_STYLESETBACK, bstyle, lightBlue);
1367 // This call extends the backround colour of the last style on the line to the edge of the window
1368 SendEditor(SCI_STYLESETEOLFILLED, bstyle, 1);
1370 SendEditor(SCI_STYLESETBACK, SCE_HB_STRINGEOL, RGB(0x7F,0x7F,0xFF));
1371 SendEditor(SCI_STYLESETFONT, SCE_HB_COMMENTLINE,
1372 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
1374 SetAStyle(SCE_HBA_DEFAULT, black);
1375 SetAStyle(SCE_HBA_COMMENTLINE, darkGreen);
1376 SetAStyle(SCE_HBA_NUMBER, RGB(0,0x80,0x80));
1377 SetAStyle(SCE_HBA_WORD, darkBlue);
1378 SendEditor(SCI_STYLESETBOLD, SCE_HBA_WORD, 1);
1379 SetAStyle(SCE_HBA_STRING, RGB(0x80,0,0x80));
1380 SetAStyle(SCE_HBA_IDENTIFIER, black);
1382 // Show the whole section of ASP VBScript with bright yellow background
1383 for (int bastyle = SCE_HBA_DEFAULT; bastyle <= SCE_HBA_STRINGEOL; ++bastyle) {
1384 SendEditor(SCI_STYLESETFONT, bastyle,
1385 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
1386 SendEditor(SCI_STYLESETBACK, bastyle, RGB(0xFF, 0xFF, 0));
1387 // This call extends the backround colour of the last style on the line to the edge of the window
1388 SendEditor(SCI_STYLESETEOLFILLED, bastyle, 1);
1390 SendEditor(SCI_STYLESETBACK, SCE_HBA_STRINGEOL, RGB(0xCF,0xCF,0x7F));
1391 SendEditor(SCI_STYLESETFONT, SCE_HBA_COMMENTLINE,
1392 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
1394 // If there is no need to support embedded Javascript, the following code can be dropped.
1395 // Javascript will still be correctly processed but will be displayed in just the default style.
1397 SetAStyle(SCE_HJ_START, RGB(0x80,0x80,0));
1398 SetAStyle(SCE_HJ_DEFAULT, black);
1399 SetAStyle(SCE_HJ_COMMENT, darkGreen);
1400 SetAStyle(SCE_HJ_COMMENTLINE, darkGreen);
1401 SetAStyle(SCE_HJ_COMMENTDOC, darkGreen);
1402 SetAStyle(SCE_HJ_NUMBER, RGB(0,0x80,0x80));
1403 SetAStyle(SCE_HJ_WORD, black);
1404 SetAStyle(SCE_HJ_KEYWORD, darkBlue);
1405 SetAStyle(SCE_HJ_DOUBLESTRING, RGB(0x80,0,0x80));
1406 SetAStyle(SCE_HJ_SINGLESTRING, RGB(0x80,0,0x80));
1407 SetAStyle(SCE_HJ_SYMBOLS, black);
1409 SetAStyle(SCE_HJA_START, RGB(0x80,0x80,0));
1410 SetAStyle(SCE_HJA_DEFAULT, black);
1411 SetAStyle(SCE_HJA_COMMENT, darkGreen);
1412 SetAStyle(SCE_HJA_COMMENTLINE, darkGreen);
1413 SetAStyle(SCE_HJA_COMMENTDOC, darkGreen);
1414 SetAStyle(SCE_HJA_NUMBER, RGB(0,0x80,0x80));
1415 SetAStyle(SCE_HJA_WORD, black);
1416 SetAStyle(SCE_HJA_KEYWORD, darkBlue);
1417 SetAStyle(SCE_HJA_DOUBLESTRING, RGB(0x80,0,0x80));
1418 SetAStyle(SCE_HJA_SINGLESTRING, RGB(0x80,0,0x80));
1419 SetAStyle(SCE_HJA_SYMBOLS, black);
1421 SetAStyle(SCE_HPHP_DEFAULT, black);
1422 SetAStyle(SCE_HPHP_HSTRING, RGB(0x80,0,0x80));
1423 SetAStyle(SCE_HPHP_SIMPLESTRING, RGB(0x80,0,0x80));
1424 SetAStyle(SCE_HPHP_WORD, darkBlue);
1425 SetAStyle(SCE_HPHP_NUMBER, RGB(0,0x80,0x80));
1426 SetAStyle(SCE_HPHP_VARIABLE, red);
1427 SetAStyle(SCE_HPHP_HSTRING_VARIABLE, red);
1428 SetAStyle(SCE_HPHP_COMPLEX_VARIABLE, red);
1429 SetAStyle(SCE_HPHP_COMMENT, darkGreen);
1430 SetAStyle(SCE_HPHP_COMMENTLINE, darkGreen);
1431 SetAStyle(SCE_HPHP_OPERATOR, darkBlue);
1433 // Show the whole section of Javascript with off white background
1434 for (int jstyle = SCE_HJ_DEFAULT; jstyle <= SCE_HJ_SYMBOLS; ++jstyle) {
1435 SendEditor(SCI_STYLESETFONT, jstyle,
1436 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
1437 SendEditor(SCI_STYLESETBACK, jstyle, offWhite);
1438 SendEditor(SCI_STYLESETEOLFILLED, jstyle, 1);
1440 SendEditor(SCI_STYLESETBACK, SCE_HJ_STRINGEOL, RGB(0xDF, 0xDF, 0x7F));
1441 SendEditor(SCI_STYLESETEOLFILLED, SCE_HJ_STRINGEOL, 1);
1443 // Show the whole section of Javascript with brown background
1444 for (int jastyle = SCE_HJA_DEFAULT; jastyle <= SCE_HJA_SYMBOLS; ++jastyle) {
1445 SendEditor(SCI_STYLESETFONT, jastyle,
1446 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
1447 SendEditor(SCI_STYLESETBACK, jastyle, RGB(0xDF, 0xDF, 0x7F));
1448 SendEditor(SCI_STYLESETEOLFILLED, jastyle, 1);
1450 SendEditor(SCI_STYLESETBACK, SCE_HJA_STRINGEOL, RGB(0x0,0xAF,0x5F));
1451 SendEditor(SCI_STYLESETEOLFILLED, SCE_HJA_STRINGEOL, 1);
1454 else
1456 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1457 SetupCppLexer();
1459 SendEditor(SCI_COLOURISE, 0, -1);
1463 void CTortoiseGitBlameView::SetupCppLexer()
1465 SetAStyle(SCE_C_DEFAULT, RGB(0, 0, 0));
1466 SetAStyle(SCE_C_COMMENT, RGB(0, 0x80, 0));
1467 SetAStyle(SCE_C_COMMENTLINE, RGB(0, 0x80, 0));
1468 SetAStyle(SCE_C_COMMENTDOC, RGB(0, 0x80, 0));
1469 SetAStyle(SCE_C_COMMENTLINEDOC, RGB(0, 0x80, 0));
1470 SetAStyle(SCE_C_COMMENTDOCKEYWORD, RGB(0, 0x80, 0));
1471 SetAStyle(SCE_C_COMMENTDOCKEYWORDERROR, RGB(0, 0x80, 0));
1472 SetAStyle(SCE_C_NUMBER, RGB(0, 0x80, 0x80));
1473 SetAStyle(SCE_C_WORD, RGB(0, 0, 0x80));
1474 SendEditor(SCE_C_WORD, 1);
1475 SetAStyle(SCE_C_STRING, RGB(0x80, 0, 0x80));
1476 SetAStyle(SCE_C_IDENTIFIER, RGB(0, 0, 0));
1477 SetAStyle(SCE_C_PREPROCESSOR, RGB(0x80, 0, 0));
1478 SetAStyle(SCE_C_OPERATOR, RGB(0x80, 0x80, 0));
1479 SendEditor(SCI_SETPROPERTY, (WPARAM)"lexer.cpp.track.preprocessor", (LPARAM)"0");
1482 int CTortoiseGitBlameView::GetEncode(unsigned char *buff, int size, int *bomoffset)
1484 CFileTextLines textlines;
1485 CFileTextLines::UnicodeType type = textlines.CheckUnicodeType(buff, size);
1487 if(type == CFileTextLines::UTF8BOM)
1489 *bomoffset = 3;
1490 return CP_UTF8;
1492 if(type == CFileTextLines::UTF8)
1493 return CP_UTF8;
1495 if(type == CFileTextLines::UTF16_LE)
1496 return 1200;
1497 if (type == CFileTextLines::UTF16_LEBOM)
1499 *bomoffset = 2;
1500 return 1200;
1503 if(type == CFileTextLines::UTF16_BE)
1504 return 1201;
1505 if (type == CFileTextLines::UTF16_BEBOM)
1507 *bomoffset = 2;
1508 return 1201;
1511 return GetACP();
1514 void CTortoiseGitBlameView::ParseBlame()
1516 m_data.ParseBlameOutput(GetDocument()->m_BlameData, GetLogData()->m_pLogCache->m_HashMap, m_DateFormat, m_bRelativeTimes);
1517 CString filename = GetDocument()->m_GitPath.GetGitPathString();
1518 m_bBlameOuputContainsOtherFilenames = m_data.ContainsOnlyFilename(filename) ? FALSE : TRUE;
1521 void CTortoiseGitBlameView::MapLineToLogIndex()
1523 std::vector<int> lineToLogIndex;
1526 int numberOfLines = m_data.GetNumberOfLines();
1527 lineToLogIndex.reserve(numberOfLines);
1528 size_t logSize = this->GetLogData()->size();
1529 for (int j = 0; j < numberOfLines; ++j)
1531 CGitHash& hash = m_data.GetHash(j);
1533 int index = -2;
1534 for (size_t i = 0; i < logSize; ++i)
1536 if (hash == this->GetLogData()->at(i))
1538 index = (int)i;
1539 break;
1542 lineToLogIndex.push_back(index);
1544 this->m_lineToLogIndex.swap(lineToLogIndex);
1547 void CTortoiseGitBlameView::UpdateInfo(int Encode)
1549 CreateFont();
1551 InitialiseEditor();
1552 SendEditor(SCI_SETREADONLY, FALSE);
1553 SendEditor(SCI_CLEARALL);
1554 SendEditor(EM_EMPTYUNDOBUFFER);
1555 SendEditor(SCI_SETSAVEPOINT);
1556 SendEditor(SCI_CANCEL);
1557 SendEditor(SCI_SETUNDOCOLLECTION, 0);
1559 SendEditor(SCI_SETCODEPAGE, SC_CP_UTF8);
1561 int encoding = m_data.UpdateEncoding(Encode);
1563 int numberOfLines = m_data.GetNumberOfLines();
1564 if (numberOfLines > 0)
1566 for (int i = 0; i < numberOfLines - 1; ++i)
1568 SendEditor(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)m_data.GetUtf8Line(i));
1569 SendEditor(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)"\n\0\0\0");
1572 // as it will add another line number in scintilla which has no counter part in the blame output
1573 // prevent carriage return and line feed for the last line
1574 CStringA s = m_data.GetUtf8Line(numberOfLines - 1);
1575 int length = s.GetLength();
1576 if (length > 0 && s.GetAt(length - 1) == '\r')
1577 s.Truncate(length - 1);
1578 SendEditor(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)s);
1583 UINT nID;
1584 UINT nStyle;
1585 int cxWidth;
1586 int nIndex = ((CMainFrame *)::AfxGetApp()->GetMainWnd())->m_wndStatusBar.CommandToIndex(ID_INDICATOR_ENCODING);
1587 ((CMainFrame *)::AfxGetApp()->GetMainWnd())->m_wndStatusBar.GetPaneInfo(nIndex, nID, nStyle, cxWidth);
1588 CString sBarText = L"";
1589 for (int i = 0; i < _countof(encodings); ++i)
1591 if (encodings[i].id == encoding)
1593 sBarText = CString(encodings[i].name);
1594 break;
1597 //calculate the width of the text
1598 CDC * pDC = ((CMainFrame *)::AfxGetApp()->GetMainWnd())->m_wndStatusBar.GetDC();
1599 if (pDC)
1601 CSize size = pDC->GetTextExtent(sBarText);
1602 ((CMainFrame *)::AfxGetApp()->GetMainWnd())->m_wndStatusBar.SetPaneInfo(nIndex, nID, nStyle, size.cx+2);
1603 ReleaseDC(pDC);
1605 ((CMainFrame *)::AfxGetApp()->GetMainWnd())->m_wndStatusBar.SetPaneText(nIndex, sBarText);
1608 #ifdef USE_TEMPFILENAME
1609 if(m_Buffer)
1611 delete m_Buffer;
1612 m_Buffer=NULL;
1615 CFile file;
1616 file.Open(this->GetDocument()->m_TempFileName,CFile::modeRead);
1618 m_Buffer = new char[file.GetLength()+4];
1619 m_Buffer[file.GetLength()] =0;
1620 m_Buffer[file.GetLength()+1] =0;
1621 m_Buffer[file.GetLength()+2] =0;
1622 m_Buffer[file.GetLength()+3] =0;
1624 file.Read(m_Buffer, file.GetLength());
1626 int bomoffset =0;
1627 int encoding = GetEncode( (unsigned char *)m_Buffer, file.GetLength(), &bomoffset);
1629 file.Close();
1630 //SendEditor(SCI_SETCODEPAGE, encoding);
1632 //SendEditor(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)(m_Buffer + bomoffset));
1633 #endif
1634 SetupLexer(GetDocument()->m_CurrentFileName);
1636 SendEditor(SCI_SETUNDOCOLLECTION, 1);
1637 SendEditor(EM_EMPTYUNDOBUFFER);
1638 SendEditor(SCI_SETSAVEPOINT);
1639 SendEditor(SCI_GOTOPOS, 0);
1640 SendEditor(SCI_SETSCROLLWIDTHTRACKING, TRUE);
1641 SendEditor(SCI_SETREADONLY, TRUE);
1643 GetBlameWidth();
1644 CRect rect;
1645 this->GetClientRect(rect);
1646 //this->m_TextView.GetWindowRect(rect);
1647 //this->m_TextView.ScreenToClient(rect);
1648 rect.left=this->m_blamewidth;
1649 this->m_TextView.MoveWindow(rect);
1651 this->Invalidate();
1654 CString CTortoiseGitBlameView::ResolveCommitFile(int line)
1656 return ResolveCommitFile(m_data.GetFilename(line));
1659 CString CTortoiseGitBlameView::ResolveCommitFile(const CString& path)
1661 if (path.IsEmpty())
1663 return ((CMainFrame*)::AfxGetApp()->GetMainWnd())->GetActiveView()->GetDocument()->GetPathName();
1665 else
1667 return g_Git.CombinePath(path);
1671 COLORREF CTortoiseGitBlameView::GetLineColor(int line)
1673 if (m_colorage && m_data.IsValidLine(line))
1675 int logIndex = m_lineToLogIndex[line];
1676 if (logIndex >= 0)
1678 int slider = (int)((GetLogData()->size() - logIndex) * 100 / (GetLogData()->size() + 1));
1679 return InterColor(DWORD(m_regOldLinesColor), DWORD(m_regNewLinesColor), slider);
1682 return m_windowcolor;
1685 CGitBlameLogList * CTortoiseGitBlameView::GetLogList()
1687 return &(GetDocument()->GetMainFrame()->m_wndOutput.m_LogList);
1691 CLogDataVector * CTortoiseGitBlameView::GetLogData()
1693 return &(GetDocument()->GetMainFrame()->m_wndOutput.m_LogList.m_logEntries);
1696 void CTortoiseGitBlameView::OnSciPainted(NMHDR *,LRESULT *)
1698 this->Invalidate();
1701 void CTortoiseGitBlameView::OnLButtonDown(UINT nFlags,CPoint point)
1704 int line = (int)SendEditor(SCI_GETFIRSTVISIBLELINE);
1705 int height = (int)SendEditor(SCI_TEXTHEIGHT);
1706 line = line + (int)(point.y/height);
1708 if (line < m_data.GetNumberOfLines())
1710 SetSelectedLine(line);
1711 if (m_data.GetHash(line) != m_SelectedHash)
1713 m_SelectedHash = m_data.GetHash(line);
1715 int logIndex = m_lineToLogIndex[line];
1716 if (logIndex >= 0)
1718 this->GetLogList()->SetItemState(logIndex, LVIS_SELECTED, LVIS_SELECTED);
1719 this->GetLogList()->EnsureVisible(logIndex, FALSE);
1721 else
1723 GitRevLoglist* pRev = m_data.GetRev(line, GetLogData()->m_pLogCache->m_HashMap);
1724 this->GetDocument()->GetMainFrame()->m_wndProperties.UpdateProperties(pRev);
1727 else
1729 m_SelectedHash.Empty();
1731 //::InvalidateRect( NULL, FALSE);
1732 this->Invalidate();
1733 this->m_TextView.Invalidate();
1736 else
1738 SetSelectedLine(-1);
1741 CView::OnLButtonDown(nFlags,point);
1744 void CTortoiseGitBlameView::OnSciGetBkColor(NMHDR* hdr, LRESULT* /*result*/)
1746 SCNotification *notification=reinterpret_cast<SCNotification *>(hdr);
1748 if (notification->line < m_data.GetNumberOfLines())
1750 if (m_data.GetHash(notification->line) == this->m_SelectedHash)
1751 notification->lParam = m_selectedauthorcolor;
1752 else
1753 notification->lParam = GetLineColor(notification->line);
1757 void CTortoiseGitBlameView::FocusOn(GitRevLoglist* pRev)
1759 this->GetDocument()->GetMainFrame()->m_wndProperties.UpdateProperties(pRev);
1761 this->Invalidate();
1763 if (m_SelectedHash != pRev->m_CommitHash) {
1764 m_SelectedHash = pRev->m_CommitHash;
1765 int line = m_data.FindFirstLine(m_SelectedHash, 0);
1766 if (line >= 0)
1768 GotoLine(line + 1);
1769 m_TextView.Invalidate();
1770 return;
1772 SendEditor(SCI_SETSEL, INT_MAX, -1);
1776 void CTortoiseGitBlameView::OnMouseHover(UINT /*nFlags*/, CPoint point)
1778 int line = (int)SendEditor(SCI_GETFIRSTVISIBLELINE);
1779 int height = (int)SendEditor(SCI_TEXTHEIGHT);
1780 line = line + (point.y/height);
1782 if (m_data.IsValidLine(line))
1784 if (line != m_MouseLine)
1786 m_MouseLine = line;
1787 GitRev *pRev = nullptr;
1788 int logIndex = m_lineToLogIndex[line];
1789 if (logIndex >= 0)
1790 pRev = &GetLogData()->GetGitRevAt(logIndex);
1791 else
1792 pRev = m_data.GetRev(line, GetLogData()->m_pLogCache->m_HashMap);
1794 if (!pRev)
1795 return;
1797 CString body = pRev->GetBody();
1798 int maxLine = 15;
1799 int iline = 0;
1800 int pos = 0;
1801 while (iline++ < maxLine)
1803 int pos2 = body.Find(_T("\n"), pos);
1804 if (pos2 < 0)
1805 break;
1806 int lineLength = pos2 - pos - 1;
1807 pos = pos2 + 1;
1808 iline += lineLength / 70;
1811 CString filename;
1812 if ((m_bShowCompleteLog && m_bFollowRenames) || !BlameIsLimitedToOneFilename(m_dwDetectMovedOrCopiedLines) || m_bBlameOuputContainsOtherFilenames)
1813 filename.Format(_T("%s: %s\n"), (LPCTSTR)m_sFileName, (LPCTSTR)m_data.GetFilename(line));
1815 CString str;
1816 str.Format(_T("%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,
1817 (LPCTSTR)m_sAuthor, (LPCTSTR)pRev->GetAuthorName(), (LPCTSTR)pRev->GetAuthorEmail(),
1818 (LPCTSTR)m_sDate, (LPCTSTR)CLoglistUtils::FormatDateAndTime(pRev->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
1819 (LPCTSTR)m_sMessage, (LPCTSTR)pRev->GetSubject(),
1820 iline <= maxLine ? body : (body.Left(pos) + _T("\n....................")));
1822 m_ToolTip.Pop();
1823 m_ToolTip.AddTool(this, str);
1825 CRect rect;
1826 rect.left=LOCATOR_WIDTH;
1827 rect.right=this->m_blamewidth+rect.left;
1828 rect.top = point.y - (LONG)height;
1829 rect.bottom = point.y + (LONG)height;
1830 this->InvalidateRect(rect);
1835 void CTortoiseGitBlameView::OnMouseMove(UINT /*nFlags*/, CPoint /*point*/)
1837 TRACKMOUSEEVENT tme;
1838 tme.cbSize=sizeof(TRACKMOUSEEVENT);
1839 tme.dwFlags=TME_HOVER|TME_LEAVE;
1840 tme.hwndTrack=this->m_hWnd;
1841 tme.dwHoverTime=1;
1842 TrackMouseEvent(&tme);
1846 BOOL CTortoiseGitBlameView::PreTranslateMessage(MSG* pMsg)
1848 m_ToolTip.RelayEvent(pMsg);
1849 return CView::PreTranslateMessage(pMsg);
1852 void CTortoiseGitBlameView::OnEditFind()
1854 if (m_pFindDialog)
1855 return;
1857 m_pFindDialog=new CFindReplaceDialog();
1859 CString oneline = theApp.GetString(_T("FindString"));
1860 if (m_TextView.Call(SCI_GETSELECTIONSTART) != m_TextView.Call(SCI_GETSELECTIONEND))
1862 LRESULT bufsize = m_TextView.Call(SCI_GETSELECTIONEND) - m_TextView.Call(SCI_GETSELECTIONSTART);
1863 std::unique_ptr<char> linebuf(new char[bufsize + 1]);
1864 SecureZeroMemory(linebuf.get(), bufsize + 1);
1865 SendEditor(SCI_GETSELTEXT, 0, (LPARAM)linebuf.get());
1866 oneline = m_TextView.StringFromControl(linebuf.get());
1869 DWORD flags = FR_DOWN | FR_HIDEWHOLEWORD | FR_HIDEUPDOWN;
1870 if (theApp.GetInt(_T("FindMatchCase")))
1871 flags |= FR_MATCHCASE;
1873 m_pFindDialog->Create(TRUE, oneline, NULL, flags, this);
1876 void CTortoiseGitBlameView::OnEditGoto()
1878 CEditGotoDlg dlg;
1879 if(dlg.DoModal()==IDOK)
1881 this->GotoLine(dlg.m_LineNumber);
1885 LRESULT CTortoiseGitBlameView::OnFindDialogMessage(WPARAM /*wParam*/, LPARAM /*lParam*/)
1887 ASSERT(m_pFindDialog != NULL);
1889 // If the FR_DIALOGTERM flag is set,
1890 // invalidate the handle identifying the dialog box.
1891 if (m_pFindDialog->IsTerminating())
1893 m_pFindDialog = NULL;
1894 return 0;
1897 if (m_data.GetNumberOfLines()==0)
1898 return 0;
1900 // If the FR_FINDNEXT flag is set,
1901 // call the application-defined search routine
1902 // to search for the requested string.
1903 if(m_pFindDialog->FindNext())
1905 m_bMatchCase = !!(m_pFindDialog->m_nFlags & FR_MATCHCASE);
1906 m_sFindText = m_pFindDialog->GetFindString();
1908 theApp.WriteInt(_T("FindMatchCase"), m_bMatchCase ? 1 : 0);
1909 theApp.WriteString(_T("FindString"), m_sFindText);
1911 DoSearch(CTortoiseGitBlameData::SearchNext);
1914 return 0;
1917 void CTortoiseGitBlameView::OnViewNext()
1919 int startline = (int)SendEditor(SCI_GETFIRSTVISIBLELINE);
1920 int line = m_data.FindNextLine(this->m_SelectedHash, (int)SendEditor(SCI_GETFIRSTVISIBLELINE), false);
1921 if(line >= 0)
1922 SendEditor(SCI_LINESCROLL, 0, line - startline - 2);
1924 void CTortoiseGitBlameView::OnViewPrev()
1926 int startline = (int)SendEditor(SCI_GETFIRSTVISIBLELINE);
1927 int line = m_data.FindNextLine(this->m_SelectedHash, (int)SendEditor(SCI_GETFIRSTVISIBLELINE), true);
1928 if(line >= 0)
1929 SendEditor(SCI_LINESCROLL, 0, line - startline - 2);
1932 void CTortoiseGitBlameView::OnViewToggleAuthor()
1934 m_bShowAuthor = ! m_bShowAuthor;
1936 theApp.WriteInt(_T("ShowAuthor"), m_bShowAuthor);
1938 CRect rect;
1939 this->GetClientRect(&rect);
1940 rect.left=GetBlameWidth();
1942 m_TextView.MoveWindow(&rect);
1945 void CTortoiseGitBlameView::OnUpdateViewToggleAuthor(CCmdUI *pCmdUI)
1947 pCmdUI->SetCheck(m_bShowAuthor);
1950 void CTortoiseGitBlameView::OnViewToggleDate()
1952 m_bShowDate = ! m_bShowDate;
1954 theApp.WriteInt(_T("ShowDate"), m_bShowDate);
1956 CRect rect;
1957 this->GetClientRect(&rect);
1958 rect.left=GetBlameWidth();
1960 m_TextView.MoveWindow(&rect);
1963 void CTortoiseGitBlameView::OnUpdateViewToggleDate(CCmdUI *pCmdUI)
1965 pCmdUI->SetCheck(m_bShowDate);
1968 void CTortoiseGitBlameView::OnViewToggleShowFilename()
1970 m_bShowFilename = ! m_bShowFilename;
1972 theApp.WriteInt(_T("ShowFilename"), m_bShowFilename);
1974 CRect rect;
1975 this->GetClientRect(&rect);
1976 rect.left = GetBlameWidth();
1978 m_TextView.MoveWindow(&rect);
1981 void CTortoiseGitBlameView::OnUpdateViewToggleShowFilename(CCmdUI *pCmdUI)
1983 pCmdUI->SetCheck(m_bShowFilename);
1986 void CTortoiseGitBlameView::OnViewToggleShowOriginalLineNumber()
1988 m_bShowOriginalLineNumber = ! m_bShowOriginalLineNumber;
1990 theApp.WriteInt(_T("ShowOriginalLineNumber"), m_bShowOriginalLineNumber);
1992 CRect rect;
1993 this->GetClientRect(&rect);
1994 rect.left = GetBlameWidth();
1996 m_TextView.MoveWindow(&rect);
1999 void CTortoiseGitBlameView::OnUpdateViewToggleShowOriginalLineNumber(CCmdUI *pCmdUI)
2001 pCmdUI->SetCheck(m_bShowOriginalLineNumber);
2004 void CTortoiseGitBlameView::OnViewDetectMovedOrCopiedLines(DWORD dwDetectMovedOrCopiedLines)
2006 m_dwDetectMovedOrCopiedLines = dwDetectMovedOrCopiedLines;
2008 theApp.DoWaitCursor(1);
2010 theApp.WriteInt(_T("DetectMovedOrCopiedLines"), m_dwDetectMovedOrCopiedLines);
2012 CTortoiseGitBlameDoc *document = (CTortoiseGitBlameDoc *) m_pDocument;
2013 if (!document->m_CurrentFileName.IsEmpty())
2015 document->m_lLine = (int)SendEditor(SCI_GETFIRSTVISIBLELINE) + 1;
2016 theApp.m_pDocManager->OnFileNew();
2017 document->OnOpenDocument(document->m_CurrentFileName, document->m_Rev);
2019 theApp.DoWaitCursor(-1);
2022 void CTortoiseGitBlameView::OnViewDetectMovedOrCopiedLinesToggleDisabled()
2024 OnViewDetectMovedOrCopiedLines(BLAME_DETECT_MOVED_OR_COPIED_LINES_DISABLED);
2027 void CTortoiseGitBlameView::OnUpdateViewDetectMovedOrCopiedLinesToggleDisabled(CCmdUI *pCmdUI)
2029 pCmdUI->SetRadio(m_dwDetectMovedOrCopiedLines == BLAME_DETECT_MOVED_OR_COPIED_LINES_DISABLED);
2032 void CTortoiseGitBlameView::OnViewDetectMovedOrCopiedLinesToggleWithinFile()
2034 OnViewDetectMovedOrCopiedLines(BLAME_DETECT_MOVED_OR_COPIED_LINES_WITHIN_FILE);
2037 void CTortoiseGitBlameView::OnUpdateViewDetectMovedOrCopiedLinesToggleWithinFile(CCmdUI *pCmdUI)
2039 pCmdUI->SetRadio(m_dwDetectMovedOrCopiedLines == BLAME_DETECT_MOVED_OR_COPIED_LINES_WITHIN_FILE);
2042 void CTortoiseGitBlameView::OnViewDetectMovedOrCopiedLinesToggleFromModifiedFiles()
2044 OnViewDetectMovedOrCopiedLines(BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_MODIFIED_FILES);
2047 void CTortoiseGitBlameView::OnUpdateViewDetectMovedOrCopiedLinesToggleFromModifiedFiles(CCmdUI *pCmdUI)
2049 pCmdUI->SetRadio(m_dwDetectMovedOrCopiedLines == BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_MODIFIED_FILES);
2052 void CTortoiseGitBlameView::OnViewDetectMovedOrCopiedLinesToggleFromExistingFilesAtFileCreation()
2054 OnViewDetectMovedOrCopiedLines(BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES_AT_FILE_CREATION);
2057 void CTortoiseGitBlameView::OnUpdateViewDetectMovedOrCopiedLinesToggleFromExistingFilesAtFileCreation(CCmdUI *pCmdUI)
2059 pCmdUI->SetRadio(m_dwDetectMovedOrCopiedLines == BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES_AT_FILE_CREATION);
2062 void CTortoiseGitBlameView::OnViewDetectMovedOrCopiedLinesToggleFromExistingFiles()
2064 OnViewDetectMovedOrCopiedLines(BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES);
2067 void CTortoiseGitBlameView::OnUpdateViewDetectMovedOrCopiedLinesToggleFromExistingFiles(CCmdUI *pCmdUI)
2069 pCmdUI->SetRadio(m_dwDetectMovedOrCopiedLines == BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES);
2072 void CTortoiseGitBlameView::ReloadDocument()
2074 theApp.DoWaitCursor(1);
2075 CTortoiseGitBlameDoc *document = (CTortoiseGitBlameDoc *) m_pDocument;
2076 if (!document->m_CurrentFileName.IsEmpty())
2078 document->m_lLine = (int)SendEditor(SCI_GETFIRSTVISIBLELINE) + 1;
2079 theApp.m_pDocManager->OnFileNew();
2080 document->OnOpenDocument(document->m_CurrentFileName, document->m_Rev);
2082 theApp.DoWaitCursor(-1);
2085 void CTortoiseGitBlameView::OnViewToggleIgnoreWhitespace()
2087 m_bIgnoreWhitespace = ! m_bIgnoreWhitespace;
2089 theApp.WriteInt(_T("IgnoreWhitespace"), m_bIgnoreWhitespace ? 1 : 0);
2091 ReloadDocument();
2094 void CTortoiseGitBlameView::OnUpdateViewToggleIgnoreWhitespace(CCmdUI *pCmdUI)
2096 pCmdUI->SetCheck(m_bIgnoreWhitespace);
2099 void CTortoiseGitBlameView::OnViewToggleShowCompleteLog()
2101 m_bShowCompleteLog = ! m_bShowCompleteLog;
2103 theApp.WriteInt(_T("ShowCompleteLog"), m_bShowCompleteLog ? 1 : 0);
2105 ReloadDocument();
2108 void CTortoiseGitBlameView::OnUpdateViewToggleShowCompleteLog(CCmdUI *pCmdUI)
2110 pCmdUI->Enable(BlameIsLimitedToOneFilename(m_dwDetectMovedOrCopiedLines));
2111 pCmdUI->SetCheck(m_bShowCompleteLog && BlameIsLimitedToOneFilename(m_dwDetectMovedOrCopiedLines));
2114 void CTortoiseGitBlameView::OnViewToggleFollowRenames()
2116 m_bFollowRenames = ! m_bFollowRenames;
2118 theApp.WriteInt(_T("FollowRenames"), m_bFollowRenames ? 1 : 0);
2120 ReloadDocument();
2123 void CTortoiseGitBlameView::OnUpdateViewToggleFollowRenames(CCmdUI *pCmdUI)
2125 pCmdUI->Enable(m_bShowCompleteLog && BlameIsLimitedToOneFilename(m_dwDetectMovedOrCopiedLines));
2126 pCmdUI->SetCheck(m_bFollowRenames && m_bShowCompleteLog && BlameIsLimitedToOneFilename(m_dwDetectMovedOrCopiedLines));
2129 void CTortoiseGitBlameView::OnViewToggleColorByAge()
2131 m_colorage = ! m_colorage;
2133 theApp.WriteInt(_T("ColorAge"), m_colorage);
2135 m_TextView.Invalidate();
2138 void CTortoiseGitBlameView::OnUpdateViewToggleColorByAge(CCmdUI *pCmdUI)
2140 pCmdUI->SetCheck(m_colorage);
2143 void CTortoiseGitBlameView::OnUpdateViewCopyToClipboard(CCmdUI *pCmdUI)
2145 CWnd * wnd = GetFocus();
2146 if (wnd == GetLogList())
2148 pCmdUI->Enable(GetLogList()->GetSelectedCount() > 0);
2150 else if (wnd)
2152 if (CString(wnd->GetRuntimeClass()->m_lpszClassName) == _T("CMFCPropertyGridCtrl"))
2154 CMFCPropertyGridCtrl *grid = (CMFCPropertyGridCtrl *)wnd;
2155 pCmdUI->Enable(grid->GetCurSel() && !grid->GetCurSel()->IsGroup() && !CString(grid->GetCurSel()->GetValue()).IsEmpty());
2157 else
2158 pCmdUI->Enable(m_TextView.Call(SCI_GETSELECTIONSTART) != m_TextView.Call(SCI_GETSELECTIONEND));
2160 else
2161 pCmdUI->Enable(FALSE);