Initialize buffers
[TortoiseGit.git] / src / TortoiseGitBlame / TortoiseGitBlameView.cpp
blobce65febd7e76d7b581b74a22fb1bfc1c8242b38c
1 // TortoiseGitBlame - a Viewer for Git Blames
3 // Copyright (C) 2008-2014 - TortoiseGit
4 // Copyright (C) 2010-2013 Sven Strickroth <email@cs-ware.de>
5 // Copyright (C) 2003-2008 - 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_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_FOLLOWRENAMES, OnViewToggleFollowRenames)
90 ON_UPDATE_COMMAND_UI(ID_VIEW_FOLLOWRENAMES, OnUpdateViewToggleFollowRenames)
91 ON_COMMAND(ID_VIEW_COLORBYAGE, OnViewToggleColorByAge)
92 ON_UPDATE_COMMAND_UI(ID_VIEW_COLORBYAGE, OnUpdateViewToggleColorByAge)
93 ON_COMMAND_RANGE(IDM_FORMAT_ENCODE, IDM_FORMAT_ENCODE_END, OnChangeEncode)
94 ON_WM_CREATE()
95 ON_WM_SIZE()
96 ON_WM_MOUSEMOVE()
97 ON_WM_MOUSEHOVER()
98 ON_WM_MOUSELEAVE()
99 ON_WM_LBUTTONDOWN()
100 ON_WM_RBUTTONDOWN()
101 ON_WM_RBUTTONUP()
102 ON_NOTIFY(SCN_PAINTED, IDC_SCINTILLA, OnSciPainted)
103 ON_NOTIFY(SCN_GETBKCOLOR, IDC_SCINTILLA, OnSciGetBkColor)
104 ON_REGISTERED_MESSAGE(m_FindDialogMessage, OnFindDialogMessage)
105 END_MESSAGE_MAP()
108 // CTortoiseGitBlameView construction/destruction
110 CTortoiseGitBlameView::CTortoiseGitBlameView()
111 : wBlame(0)
112 , wHeader(0)
113 , hwndTT(0)
114 , bIgnoreEOL(false)
115 , bIgnoreSpaces(false)
116 , bIgnoreAllSpaces(false)
117 , m_MouseLine(-1)
119 hInstance = 0;
120 hResource = 0;
121 currentDialog = 0;
122 wMain = 0;
123 m_wEditor = 0;
124 wLocator = 0;
126 m_font = 0;
127 m_italicfont = 0;
128 m_blamewidth = 0;
129 m_revwidth = 0;
130 m_datewidth = 0;
131 m_authorwidth = 0;
132 m_filenameWidth = 0;
133 m_originalLineNumberWidth = 0;
134 m_linewidth = 0;
136 m_windowcolor = ::GetSysColor(COLOR_WINDOW);
137 m_textcolor = ::GetSysColor(COLOR_WINDOWTEXT);
138 m_texthighlightcolor = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
139 m_mouserevcolor = InterColor(m_windowcolor, m_textcolor, 20);
140 m_mouseauthorcolor = InterColor(m_windowcolor, m_textcolor, 10);
141 m_selectedrevcolor = ::GetSysColor(COLOR_HIGHLIGHT);
142 m_selectedauthorcolor = InterColor(m_selectedrevcolor, m_texthighlightcolor, 35);
144 m_SelectedLine = -1;
145 m_directPointer = 0;
146 m_directFunction = 0;
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 m_wEditor = m_TextView.m_hWnd;
286 CreateFont();
287 InitialiseEditor();
288 m_ToolTip.Create(this->GetParent());
290 ::AfxGetApp()->GetMainWnd();
291 return CView::OnCreate(lpcs);
295 void CTortoiseGitBlameView::OnSize(UINT /*nType*/, int cx, int cy)
298 CRect rect;
299 rect.left=m_blamewidth;
300 rect.right=cx;
301 rect.top=0;
302 rect.bottom=cy;
304 m_TextView.MoveWindow(&rect);
307 BOOL CTortoiseGitBlameView::PreCreateWindow(CREATESTRUCT& cs)
309 return CView::PreCreateWindow(cs);
312 // CTortoiseGitBlameView drawing
314 void CTortoiseGitBlameView::OnDraw(CDC* /*pDC*/)
316 CTortoiseGitBlameDoc* pDoc = GetDocument();
317 ASSERT_VALID(pDoc);
318 if (!pDoc)
319 return;
321 DrawBlame(this->GetDC()->m_hDC);
322 DrawLocatorBar(this->GetDC()->m_hDC);
323 // TODO: add draw code for native data here
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 void CTortoiseGitBlameView::OnRButtonUp(UINT /*nFlags*/, CPoint point)
353 int line = (int)SendEditor(SCI_GETFIRSTVISIBLELINE);
354 int height = (int)SendEditor(SCI_TEXTHEIGHT);
355 line = line + (int)(point.y / height);
356 if (m_data.IsValidLine(line))
358 m_MouseLine = line;
359 ClientToScreen(&point);
361 CGitHash hash = m_data.GetHash(line);
362 CString hashStr = hash.ToString();
364 GitRev* pRev = nullptr;
365 int logIndex = m_lineToLogIndex[line];
366 if (logIndex >= 0)
367 pRev = &GetLogData()->GetGitRevAt(logIndex);
368 else
370 pRev = m_data.GetRev(line, GetLogData()->m_pLogCache->m_HashMap);
371 if (pRev->m_ParentHash.empty())
375 pRev->GetParentFromHash(pRev->m_CommitHash);
377 catch (const char* msg)
379 MessageBox(_T("Could not get parent.\nlibgit reports:\n") + CString(msg), _T("TortoiseGit"), MB_ICONERROR);
384 if (!pRev)
385 return;
387 CIconMenu popup;
388 CIconMenu blamemenu, diffmenu;
390 if (!popup.CreatePopupMenu())
391 return;
393 // Now find the relevant parent commits, they must contain the file which is blamed to be the source of the selected line,
394 // otherwise there is no previous file to compare to (only another previous revision).
396 GIT_REV_LIST parentHashWithFile;
397 std::vector<CString> parentFilename;
400 CTGitPath path(m_data.GetFilename(line));
401 const CTGitPathList & files = pRev->GetFiles(NULL);
402 for (int j = 0, j_size = files.GetCount(); j < j_size; ++j)
404 const CTGitPath &file = files[j];
405 if (file.IsEquivalentTo(path))
407 if (!(file.m_ParentNo & MERGE_MASK))
409 int action = file.m_Action;
410 // ignore (action & CTGitPath::LOGACTIONS_ADDED), as then there is nothing to blame/diff
411 // ignore (action & CTGitPath::LOGACTIONS_DELETED), should never happen as the file must exist
412 if (action & (CTGitPath::LOGACTIONS_MODIFIED | CTGitPath::LOGACTIONS_REPLACED))
414 int parentNo = file.m_ParentNo & PARENT_MASK;
415 if (parentNo >= 0 && (size_t)parentNo < pRev->m_ParentHash.size())
417 parentHashWithFile.push_back(pRev->m_ParentHash[parentNo]);
418 parentFilename.push_back((action & CTGitPath::LOGACTIONS_REPLACED) ? file.GetGitOldPathString() : file.GetGitPathString());
425 catch (const char* msg)
427 MessageBox(_T("Could not get files of parents.\nlibgit reports:\n") + CString(msg), _T("TortoiseGit"), MB_ICONERROR);
430 // blame previous
431 if (!parentHashWithFile.empty())
433 if (parentHashWithFile.size() == 1)
435 popup.AppendMenuIcon(ID_BLAMEPREVIOUS, IDS_BLAME_POPUP_BLAME, IDI_BLAME_POPUP_BLAME);
437 else
439 blamemenu.CreatePopupMenu();
440 popup.AppendMenuIcon(ID_BLAMEPREVIOUS, IDS_BLAME_POPUP_BLAME, IDI_BLAME_POPUP_BLAME, blamemenu.m_hMenu);
442 for (size_t i = 0; i < parentHashWithFile.size(); ++i)
444 CString str;
445 str.Format(IDS_PARENT, i + 1);
446 blamemenu.AppendMenuIcon(ID_BLAMEPREVIOUS + ((i + 1) << 16), str);
451 // compare with previous
452 if (!parentHashWithFile.empty())
454 if (parentHashWithFile.size() == 1)
456 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_BLAME_POPUP_COMPARE, IDI_BLAME_POPUP_COMPARE);
457 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
458 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
460 else
462 diffmenu.CreatePopupMenu();
463 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_BLAME_POPUP_COMPARE, IDI_BLAME_POPUP_COMPARE, diffmenu.m_hMenu);
464 for (size_t i = 0; i < parentHashWithFile.size(); ++i)
466 CString str;
467 str.Format(IDS_BLAME_POPUP_PARENT, i + 1);
468 diffmenu.AppendMenuIcon((UINT)(ID_COMPAREWITHPREVIOUS + ((i + 1) << 16)),str);
469 if (i == 0 && CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
471 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
472 diffmenu.SetDefaultItem((UINT)(ID_COMPAREWITHPREVIOUS + ((i + 1) << 16)), FALSE);
478 popup.AppendMenuIcon(ID_SHOWLOG, IDS_BLAME_POPUP_LOG, IDI_BLAME_POPUP_LOG);
479 popup.AppendMenu(MF_SEPARATOR, NULL);
480 popup.AppendMenuIcon(ID_COPYHASHTOCLIPBOARD, IDS_BLAME_POPUP_COPYHASHTOCLIPBOARD, IDI_BLAME_POPUP_COPY);
481 popup.AppendMenuIcon(ID_COPYLOGTOCLIPBOARD, IDS_BLAME_POPUP_COPYLOGTOCLIPBOARD, IDI_BLAME_POPUP_COPY);
483 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
484 this->ContextMenuAction(cmd, pRev, parentHashWithFile, parentFilename);
488 void CTortoiseGitBlameView::ContextMenuAction(int cmd, GitRev *pRev, GIT_REV_LIST& parentHashWithFile, const std::vector<CString>& parentFilename)
490 switch (cmd & 0xFFFF)
492 case ID_BLAMEPREVIOUS:
494 int index = (cmd>>16) & 0xFFFF;
495 if (index > 0)
496 index -= 1;
498 CString path = ResolveCommitFile(parentFilename[index]);
499 CString endrev = parentHashWithFile[index].ToString();
500 int line = m_data.GetOriginalLineNumber(m_MouseLine);
501 CString lineNumber;
502 lineNumber.Format(_T("%d"), line);
504 CString procCmd = _T("/path:\"") + path + _T("\" ");
505 procCmd += _T(" /command:blame");
506 procCmd += _T(" /endrev:") + endrev;
507 procCmd += _T(" /line:") + lineNumber;
509 CCommonAppUtils::RunTortoiseGitProc(procCmd);
511 break;
513 case ID_COMPAREWITHPREVIOUS:
515 int index = (cmd >> 16) & 0xFFFF;
516 if (index > 0)
517 index -= 1;
519 CString path = ResolveCommitFile(parentFilename[index]);
520 CString startrev = pRev->m_CommitHash.ToString();
521 CString endrev = parentHashWithFile[index].ToString();
523 CString procCmd = _T("/path:\"") + path + _T("\" ");
524 procCmd += _T(" /command:diff");
525 procCmd += _T(" /startrev:") + startrev;
526 procCmd += _T(" /endrev:") + endrev;
528 CCommonAppUtils::RunTortoiseGitProc(procCmd);
530 break;
532 case ID_SHOWLOG:
534 CString path = ResolveCommitFile(m_MouseLine);
535 CString rev = m_data.GetHash(m_MouseLine).ToString();
537 CString procCmd = _T("/path:\"") + path + _T("\" ");
538 procCmd += _T(" /command:log");
539 procCmd += _T(" /rev:") + rev;
541 CCommonAppUtils::RunTortoiseGitProc(procCmd);
543 break;
545 case ID_COPYHASHTOCLIPBOARD:
546 this->GetLogList()->CopySelectionToClipBoard(CGitLogListBase::ID_COPY_HASH);
547 break;
549 case ID_COPYLOGTOCLIPBOARD:
550 this->GetLogList()->CopySelectionToClipBoard();
551 break;
555 // CTortoiseGitBlameView diagnostics
557 #ifdef _DEBUG
558 void CTortoiseGitBlameView::AssertValid() const
560 CView::AssertValid();
563 void CTortoiseGitBlameView::Dump(CDumpContext& dc) const
565 CView::Dump(dc);
568 CTortoiseGitBlameDoc* CTortoiseGitBlameView::GetDocument() const // non-debug version is inline
570 ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTortoiseGitBlameDoc)));
571 return (CTortoiseGitBlameDoc*)m_pDocument;
573 #endif //_DEBUG
576 // CTortoiseGitBlameView message handlers
577 CString CTortoiseGitBlameView::GetAppDirectory()
579 CString path;
580 DWORD len = 0;
581 DWORD bufferlen = MAX_PATH; // MAX_PATH is not the limit here!
584 bufferlen += MAX_PATH; // MAX_PATH is not the limit here!
585 std::unique_ptr<TCHAR[]> pBuf(new TCHAR[bufferlen]);
586 len = GetModuleFileName(NULL, pBuf.get(), bufferlen);
587 path = CString(pBuf.get(), len);
588 } while(len == bufferlen);
590 path = path.Left(path.ReverseFind(_T('\\')));
591 //path = path.substr(0, path.rfind('\\') + 1);
593 return path;
596 // Return a color which is interpolated between c1 and c2.
597 // Slider controls the relative proportions as a percentage:
598 // Slider = 0 represents pure c1
599 // Slider = 50 represents equal mixture
600 // Slider = 100 represents pure c2
601 COLORREF CTortoiseGitBlameView::InterColor(COLORREF c1, COLORREF c2, int Slider)
603 int r, g, b;
605 // Limit Slider to 0..100% range
606 if (Slider < 0)
607 Slider = 0;
608 if (Slider > 100)
609 Slider = 100;
611 // The color components have to be treated individually.
612 r = (GetRValue(c2) * Slider + GetRValue(c1) * (100 - Slider)) / 100;
613 g = (GetGValue(c2) * Slider + GetGValue(c1) * (100 - Slider)) / 100;
614 b = (GetBValue(c2) * Slider + GetBValue(c1) * (100 - Slider)) / 100;
616 return RGB(r, g, b);
619 LRESULT CTortoiseGitBlameView::SendEditor(UINT Msg, WPARAM wParam, LPARAM lParam)
621 if (m_directFunction)
623 return ((SciFnDirect) m_directFunction)(m_directPointer, Msg, wParam, lParam);
625 return ::SendMessage(m_wEditor, Msg, wParam, lParam);
628 void CTortoiseGitBlameView::SetAStyle(int style, COLORREF fore, COLORREF back, int size, CString *face)
630 SendEditor(SCI_STYLESETFORE, style, fore);
631 SendEditor(SCI_STYLESETBACK, style, back);
632 if (size >= 1)
633 SendEditor(SCI_STYLESETSIZE, style, size);
634 if (face)
635 SendEditor(SCI_STYLESETFONT, style, reinterpret_cast<LPARAM>(this->m_TextView.StringForControl(*face).GetBuffer()));
638 void CTortoiseGitBlameView::InitialiseEditor()
641 m_directFunction = ::SendMessage(m_wEditor, SCI_GETDIRECTFUNCTION, 0, 0);
642 m_directPointer = ::SendMessage(m_wEditor, SCI_GETDIRECTPOINTER, 0, 0);
643 // Set up the global default style. These attributes are used wherever no explicit choices are made.
644 CString fontName(((stdstring)CRegStdString(_T("Software\\TortoiseGit\\BlameFontName"), _T("Courier New"))).c_str());
645 SetAStyle(STYLE_DEFAULT,
646 black,
647 white,
648 (DWORD)CRegStdDWORD(_T("Software\\TortoiseGit\\BlameFontSize"), 10),
649 &fontName
651 SendEditor(SCI_SETTABWIDTH, (DWORD)CRegStdDWORD(_T("Software\\TortoiseGit\\BlameTabSize"), 4));
652 SendEditor(SCI_SETREADONLY, TRUE);
653 LRESULT pix = SendEditor(SCI_TEXTWIDTH, STYLE_LINENUMBER, (LPARAM)this->m_TextView.StringForControl(_T("_99999")).GetBuffer());
654 if (m_bShowLine)
655 SendEditor(SCI_SETMARGINWIDTHN, 0, pix);
656 else
657 SendEditor(SCI_SETMARGINWIDTHN, 0);
658 SendEditor(SCI_SETMARGINWIDTHN, 1);
659 SendEditor(SCI_SETMARGINWIDTHN, 2);
660 //Set the default windows colors for edit controls
661 SendEditor(SCI_STYLESETFORE, STYLE_DEFAULT, ::GetSysColor(COLOR_WINDOWTEXT));
662 SendEditor(SCI_STYLESETBACK, STYLE_DEFAULT, ::GetSysColor(COLOR_WINDOW));
663 SendEditor(SCI_SETSELFORE, TRUE, ::GetSysColor(COLOR_HIGHLIGHTTEXT));
664 SendEditor(SCI_SETSELBACK, TRUE, ::GetSysColor(COLOR_HIGHLIGHT));
665 SendEditor(SCI_SETCARETFORE, ::GetSysColor(COLOR_WINDOWTEXT));
666 m_regOldLinesColor = CRegStdDWORD(_T("Software\\TortoiseGit\\BlameOldColor"), BLAMEOLDCOLOR);
667 m_regNewLinesColor = CRegStdDWORD(_T("Software\\TortoiseGit\\BlameNewColor"), BLAMENEWCOLOR);
668 CRegStdDWORD used2d(L"Software\\TortoiseGit\\ScintillaDirect2D", FALSE);
669 if (SysInfo::Instance().IsWin7OrLater() && DWORD(used2d))
671 SendEditor(SCI_SETTECHNOLOGY, SC_TECHNOLOGY_DIRECTWRITE);
672 SendEditor(SCI_SETBUFFEREDDRAW, 0);
675 this->m_TextView.Call(SCI_SETWRAPMODE, SC_WRAP_NONE);
679 bool CTortoiseGitBlameView::DoSearch(CString what, DWORD flags)
681 int pos = (int)SendEditor(SCI_GETCURRENTPOS);
682 int line = (int)SendEditor(SCI_LINEFROMPOSITION, pos);
683 bool bCaseSensitive = !!(flags & FR_MATCHCASE);
684 theApp.WriteInt(_T("FindMatchCase"), bCaseSensitive ? 1 : 0);
685 theApp.WriteString(_T("FindString"), what);
687 int i = m_data.FindFirstLineWrapAround(what, line, bCaseSensitive);
688 if (i >= 0)
690 GotoLine(i + 1);
691 int selstart = (int)SendEditor(SCI_GETCURRENTPOS);
692 int selend = (int)SendEditor(SCI_POSITIONFROMLINE, i + 1);
693 SendEditor(SCI_SETSELECTIONSTART, selstart);
694 SendEditor(SCI_SETSELECTIONEND, selend);
695 m_SelectedLine = i;
697 else
699 ::MessageBox(wMain, _T("\"") + what + _T("\" ") + CString(MAKEINTRESOURCE(IDS_NOTFOUND)), _T("TortoiseGitBlame"), MB_ICONINFORMATION);
702 return true;
705 bool CTortoiseGitBlameView::GotoLine(int line)
707 --line;
708 int numberOfLines = m_data.GetNumberOfLines();
709 if (line < 0 || numberOfLines == 0)
710 return false;
711 if (line >= numberOfLines)
713 line = numberOfLines - 1;
716 int nCurrentPos = (int)SendEditor(SCI_GETCURRENTPOS);
717 int nCurrentLine = (int)SendEditor(SCI_LINEFROMPOSITION,nCurrentPos);
718 int nFirstVisibleLine = (int)SendEditor(SCI_GETFIRSTVISIBLELINE);
719 int nLinesOnScreen = (int)SendEditor(SCI_LINESONSCREEN);
721 if ( line>=nFirstVisibleLine && line<=nFirstVisibleLine+nLinesOnScreen)
723 // no need to scroll
724 SendEditor(SCI_GOTOLINE, line);
726 else
728 // Place the requested line one third from the top
729 if ( line > nCurrentLine )
731 SendEditor(SCI_GOTOLINE, (WPARAM)(line+(int)nLinesOnScreen*(2/3.0)));
733 else
735 SendEditor(SCI_GOTOLINE, (WPARAM)(line-(int)nLinesOnScreen*(1/3.0)));
739 // Highlight the line
740 int nPosStart = (int)SendEditor(SCI_POSITIONFROMLINE,line);
741 int nPosEnd = (int)SendEditor(SCI_GETLINEENDPOSITION,line);
742 SendEditor(SCI_SETSEL,nPosEnd,nPosStart);
744 return true;
747 bool CTortoiseGitBlameView::ScrollToLine(long line)
749 if (line < 0)
750 return false;
752 int nCurrentLine = (int)SendEditor(SCI_GETFIRSTVISIBLELINE);
754 int scrolldelta = line - nCurrentLine;
755 SendEditor(SCI_LINESCROLL, 0, scrolldelta);
757 return true;
760 void CTortoiseGitBlameView::CopyToClipboard()
762 CWnd * wnd = GetFocus();
763 if (wnd == this->GetLogList())
764 GetLogList()->CopySelectionToClipBoard();
765 else if (wnd)
767 if (CString(wnd->GetRuntimeClass()->m_lpszClassName) == _T("CMFCPropertyGridCtrl"))
769 CMFCPropertyGridCtrl *grid = (CMFCPropertyGridCtrl *)wnd;
770 if (grid->GetCurSel() && !grid->GetCurSel()->IsGroup())
771 CStringUtils::WriteAsciiStringToClipboard(grid->GetCurSel()->GetValue(), GetSafeHwnd());
773 else
774 m_TextView.Call(SCI_COPY);
778 LONG CTortoiseGitBlameView::GetBlameWidth()
780 LONG blamewidth = 0;
781 SIZE width;
782 CreateFont();
783 HDC hDC = this->GetDC()->m_hDC;
784 HFONT oldfont = (HFONT)::SelectObject(hDC, m_font);
786 CString shortHash('f', g_Git.GetShortHASHLength() + 1);
787 ::GetTextExtentPoint32(hDC, shortHash, g_Git.GetShortHASHLength() + 1, &width);
788 m_revwidth = width.cx + BLAMESPACE;
789 blamewidth += m_revwidth;
791 if (m_bShowDate)
793 SIZE maxwidth = {0};
795 int numberOfLines = m_data.GetNumberOfLines();
796 for (int i = 0; i < numberOfLines; ++i)
798 ::GetTextExtentPoint32(hDC, m_data.GetDate(i), m_data.GetDate(i).GetLength(), &width);
799 if (width.cx > maxwidth.cx)
800 maxwidth = width;
802 m_datewidth = maxwidth.cx + BLAMESPACE;
803 blamewidth += m_datewidth;
805 if ( m_bShowAuthor)
807 SIZE maxwidth = {0};
809 int numberOfLines = m_data.GetNumberOfLines();
810 for (int i = 0; i < numberOfLines; ++i)
812 ::GetTextExtentPoint32(hDC,m_data.GetAuthor(i) , m_data.GetAuthor(i).GetLength(), &width);
813 if (width.cx > maxwidth.cx)
814 maxwidth = width;
816 m_authorwidth = maxwidth.cx + BLAMESPACE;
817 blamewidth += m_authorwidth;
819 if (m_bShowFilename)
821 SIZE maxwidth = {0};
823 int numberOfLines = m_data.GetNumberOfLines();
824 for (int i = 0; i < numberOfLines; ++i)
826 ::GetTextExtentPoint32(hDC, m_data.GetFilename(i), m_data.GetFilename(i).GetLength(), &width);
827 if (width.cx > maxwidth.cx)
828 maxwidth = width;
830 m_filenameWidth = maxwidth.cx + BLAMESPACE;
831 blamewidth += m_filenameWidth;
833 if (m_bShowOriginalLineNumber)
835 SIZE maxwidth = {0};
837 int numberOfLines = m_data.GetNumberOfLines();
838 CString str;
839 for (int i = 0; i < numberOfLines; ++i)
841 str.Format(_T("%5d"), m_data.GetOriginalLineNumber(i));
842 ::GetTextExtentPoint32(hDC, str, str.GetLength(), &width);
843 if (width.cx > maxwidth.cx)
844 maxwidth = width;
846 m_originalLineNumberWidth = maxwidth.cx + BLAMESPACE;
847 blamewidth += m_originalLineNumberWidth;
849 ::SelectObject(hDC, oldfont);
850 POINT pt = {blamewidth, 0};
851 LPtoDP(hDC, &pt, 1);
852 m_blamewidth = pt.x;
853 //::ReleaseDC(wBlame, hDC);
854 return blamewidth;
858 void CTortoiseGitBlameView::CreateFont()
860 if (m_font)
861 return;
862 LOGFONT lf = {0};
863 lf.lfWeight = 400;
864 HDC hDC = ::GetDC(wBlame);
865 lf.lfHeight = -MulDiv((DWORD)CRegStdDWORD(_T("Software\\TortoiseGit\\BlameFontSize"), 10), GetDeviceCaps(hDC, LOGPIXELSY), 72);
866 lf.lfCharSet = DEFAULT_CHARSET;
867 CRegStdString fontname = CRegStdString(_T("Software\\TortoiseGit\\BlameFontName"), _T("Courier New"));
868 _tcscpy_s(lf.lfFaceName, 32, ((stdstring)fontname).c_str());
869 m_font = ::CreateFontIndirect(&lf);
871 lf.lfItalic = TRUE;
872 m_italicfont = ::CreateFontIndirect(&lf);
874 ::ReleaseDC(wBlame, hDC);
877 void CTortoiseGitBlameView::DrawBlame(HDC hDC)
879 if (hDC == NULL)
880 return;
881 if (m_font == NULL)
882 return;
884 HFONT oldfont = NULL;
885 int line = (int)SendEditor(SCI_GETFIRSTVISIBLELINE);
886 int linesonscreen = (int)SendEditor(SCI_LINESONSCREEN);
887 int height = (int)SendEditor(SCI_TEXTHEIGHT);
888 int Y = 0;
889 TCHAR buf[MAX_PATH] = {0};
890 RECT rc;
891 BOOL sel = FALSE;
892 //::GetClientRect(this->m_hWnd, &rc);
893 for (int i = line; i < (line + linesonscreen); ++i)
895 sel = FALSE;
896 if (i < m_data.GetNumberOfLines())
898 CGitHash hash(m_data.GetHash(i));
899 // if (mergelines[i])
900 // oldfont = (HFONT)::SelectObject(hDC, m_italicfont);
901 // else
902 oldfont = (HFONT)::SelectObject(hDC, m_font);
903 ::SetBkColor(hDC, m_windowcolor);
904 ::SetTextColor(hDC, m_textcolor);
905 if (!hash.IsEmpty())
907 //if (m_CommitHash[i].Compare(m_MouseHash)==0)
908 // ::SetBkColor(hDC, m_mouseauthorcolor);
909 if (hash == m_SelectedHash)
911 ::SetBkColor(hDC, m_selectedauthorcolor);
912 ::SetTextColor(hDC, m_texthighlightcolor);
913 sel = TRUE;
917 if(m_MouseLine == i)
918 ::SetBkColor(hDC, m_mouserevcolor);
920 //if ((revs[i] == m_mouserev)&&(!sel))
921 // ::SetBkColor(hDC, m_mouserevcolor);
922 //if (revs[i] == m_selectedrev)
924 // ::SetBkColor(hDC, m_selectedrevcolor);
925 // ::SetTextColor(hDC, m_texthighlightcolor);
928 CString shortHashStr;
929 shortHashStr = hash.ToString().Left(g_Git.GetShortHASHLength());
931 //_stprintf_s(buf, MAX_PATH, _T("%8ld "), revs[i]);
932 rc.top = (LONG)Y;
933 rc.left=LOCATOR_WIDTH;
934 rc.bottom = (LONG)(Y + height);
935 rc.right = rc.left + m_blamewidth;
936 ::ExtTextOut(hDC, LOCATOR_WIDTH, Y, ETO_CLIPPED, &rc, shortHashStr, shortHashStr.GetLength(), 0);
937 int Left = m_revwidth;
939 if (m_bShowAuthor)
941 rc.right = rc.left + Left + m_authorwidth;
942 ::ExtTextOut(hDC, Left, Y, ETO_CLIPPED, &rc, m_data.GetAuthor(i), m_data.GetAuthor(i).GetLength(), 0);
943 Left += m_authorwidth;
945 if (m_bShowDate)
947 rc.right = rc.left + Left + m_datewidth;
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 ::ExtTextOut(hDC, Left, (int)Y, ETO_CLIPPED, &rc, m_data.GetFilename(i), m_data.GetFilename(i).GetLength(), 0);
955 Left += m_filenameWidth;
957 if (m_bShowOriginalLineNumber)
959 rc.right = rc.left + Left + m_originalLineNumberWidth;
960 CString str;
961 str.Format(_T("%5d"), m_data.GetOriginalLineNumber(i));
962 ::ExtTextOut(hDC, Left, (int)Y, ETO_CLIPPED, &rc, str, str.GetLength(), 0);
963 Left += m_originalLineNumberWidth;
965 if ((i==m_SelectedLine)&&(m_pFindDialog))
967 LOGBRUSH brush;
968 brush.lbColor = m_textcolor;
969 brush.lbHatch = 0;
970 brush.lbStyle = BS_SOLID;
971 HPEN pen = ExtCreatePen(PS_SOLID | PS_GEOMETRIC, 2, &brush, 0, NULL);
972 HGDIOBJ hPenOld = SelectObject(hDC, pen);
973 RECT rc2 = rc;
974 rc2.top = (LONG)Y;
975 rc2.bottom = (LONG)(Y + height);
976 ::MoveToEx(hDC, rc2.left, rc2.top, NULL);
977 ::LineTo(hDC, rc2.right, rc2.top);
978 ::LineTo(hDC, rc2.right, rc2.bottom);
979 ::LineTo(hDC, rc2.left, rc2.bottom);
980 ::LineTo(hDC, rc2.left, rc2.top);
981 SelectObject(hDC, hPenOld);
982 DeleteObject(pen);
984 Y += height;
985 ::SelectObject(hDC, oldfont);
987 else
989 ::SetBkColor(hDC, m_windowcolor);
990 for (int j=0; j< MAX_PATH; ++j)
991 buf[j]=' ';
992 ::ExtTextOut(hDC, 0, (int)Y, ETO_CLIPPED, &rc, buf, MAX_PATH-1, 0);
993 Y += height;
998 void CTortoiseGitBlameView::DrawLocatorBar(HDC hDC)
1000 if (hDC == NULL)
1001 return;
1003 int line = (int)SendEditor(SCI_GETFIRSTVISIBLELINE);
1004 int linesonscreen = (int)SendEditor(SCI_LINESONSCREEN);
1005 int Y = 0;
1006 COLORREF blackColor = GetSysColor(COLOR_WINDOWTEXT);
1008 RECT rc;
1009 //::GetClientRect(wLocator, &rc);
1010 this->GetClientRect(&rc);
1012 rc.right=LOCATOR_WIDTH;
1014 RECT lineRect = rc;
1015 LONG height = rc.bottom-rc.top;
1017 int numberOfLines = m_data.GetNumberOfLines();
1018 // draw the colored bar
1019 for (int currentLine = 0; currentLine<numberOfLines; ++currentLine)
1021 COLORREF cr = GetLineColor(currentLine);
1022 // get the line color
1023 if ((currentLine >= line)&&(currentLine < (line + linesonscreen)))
1025 cr = InterColor(cr, blackColor, 10);
1027 SetBkColor(hDC, cr);
1028 lineRect.top = (LONG)Y;
1029 lineRect.bottom = ((currentLine + 1) * height / numberOfLines);
1030 ::ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &lineRect, NULL, 0, NULL);
1031 Y = lineRect.bottom;
1034 if (numberOfLines > 0)
1036 // now draw two lines indicating the scroll position of the source view
1037 SetBkColor(hDC, blackColor);
1038 lineRect.top = (LONG)line * height / numberOfLines;
1039 lineRect.bottom = lineRect.top+1;
1040 ::ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &lineRect, NULL, 0, NULL);
1041 lineRect.top = (LONG)(line + linesonscreen) * height / numberOfLines;
1042 lineRect.bottom = lineRect.top+1;
1043 ::ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &lineRect, NULL, 0, NULL);
1048 void CTortoiseGitBlameView::StringExpand(LPSTR str)
1050 char * cPos = str;
1053 cPos = strchr(cPos, '\n');
1054 if (cPos)
1056 memmove(cPos+1, cPos, strlen(cPos)*sizeof(char));
1057 *cPos = '\r';
1058 ++cPos;
1059 ++cPos;
1061 } while (cPos != NULL);
1063 void CTortoiseGitBlameView::StringExpand(LPWSTR str)
1065 wchar_t * cPos = str;
1068 cPos = wcschr(cPos, '\n');
1069 if (cPos)
1071 memmove(cPos+1, cPos, wcslen(cPos)*sizeof(wchar_t));
1072 *cPos = '\r';
1073 ++cPos;
1074 ++cPos;
1076 } while (cPos != NULL);
1079 void CTortoiseGitBlameView::SetupLexer(CString filename)
1081 int start=filename.ReverseFind(_T('.'));
1082 if (start>0)
1084 //_tcscpy_s(line, 20, lineptr+1);
1085 //_tcslwr_s(line, 20);
1086 CString ext=filename.Right(filename.GetLength()-start-1);
1087 TCHAR * line = ext.GetBuffer();
1089 if ((_tcscmp(line, _T("py"))==0)||
1090 (_tcscmp(line, _T("pyw"))==0))
1092 SendEditor(SCI_SETLEXER, SCLEX_PYTHON);
1093 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("and assert break class continue def del elif \
1094 else except exec finally for from global if import in is lambda None \
1095 not or pass print raise return try while yield")).GetBuffer()));
1096 SetAStyle(SCE_P_DEFAULT, black);
1097 SetAStyle(SCE_P_COMMENTLINE, darkGreen);
1098 SetAStyle(SCE_P_NUMBER, RGB(0, 0x80, 0x80));
1099 SetAStyle(SCE_P_STRING, RGB(0, 0, 0x80));
1100 SetAStyle(SCE_P_CHARACTER, RGB(0, 0, 0x80));
1101 SetAStyle(SCE_P_WORD, RGB(0x80, 0, 0x80));
1102 SetAStyle(SCE_P_TRIPLE, black);
1103 SetAStyle(SCE_P_TRIPLEDOUBLE, black);
1104 SetAStyle(SCE_P_CLASSNAME, darkBlue);
1105 SetAStyle(SCE_P_DEFNAME, darkBlue);
1106 SetAStyle(SCE_P_OPERATOR, darkBlue);
1107 SetAStyle(SCE_P_IDENTIFIER, darkBlue);
1108 SetAStyle(SCE_P_COMMENTBLOCK, darkGreen);
1109 SetAStyle(SCE_P_STRINGEOL, red);
1111 if ((_tcscmp(line, _T("c"))==0)||
1112 (_tcscmp(line, _T("cc"))==0)||
1113 (_tcscmp(line, _T("cpp"))==0)||
1114 (_tcscmp(line, _T("cxx"))==0)||
1115 (_tcscmp(line, _T("h"))==0)||
1116 (_tcscmp(line, _T("hh"))==0)||
1117 (_tcscmp(line, _T("hpp"))==0)||
1118 (_tcscmp(line, _T("hxx"))==0)||
1119 (_tcscmp(line, _T("dlg"))==0)||
1120 (_tcscmp(line, _T("mak"))==0))
1122 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1123 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("and and_eq asm auto bitand bitor bool break \
1124 case catch char class compl const const_cast continue \
1125 default delete do double dynamic_cast else enum explicit export extern false float for \
1126 friend goto if inline int long mutable namespace new not not_eq \
1127 operator or or_eq private protected public \
1128 register reinterpret_cast return short signed sizeof static static_cast struct switch \
1129 template this throw true try typedef typeid typename union unsigned using \
1130 virtual void volatile wchar_t while xor xor_eq")).GetBuffer()));
1131 SendEditor(SCI_SETKEYWORDS, 3, (LPARAM)(m_TextView.StringForControl(_T("a addindex addtogroup anchor arg attention \
1132 author b brief bug c class code date def defgroup deprecated dontinclude \
1133 e em endcode endhtmlonly endif endlatexonly endlink endverbatim enum example exception \
1134 f$ f[ f] file fn hideinitializer htmlinclude htmlonly \
1135 if image include ingroup internal invariant interface latexonly li line link \
1136 mainpage name namespace nosubgrouping note overload \
1137 p page par param post pre ref relates remarks return retval \
1138 sa section see showinitializer since skip skipline struct subsection \
1139 test throw todo typedef union until \
1140 var verbatim verbinclude version warning weakgroup $ @ \\ & < > # { }")).GetBuffer()));
1141 SetupCppLexer();
1143 if (_tcscmp(line, _T("cs"))==0)
1145 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1146 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("abstract as base bool break byte case catch char checked class \
1147 const continue decimal default delegate do double else enum \
1148 event explicit extern false finally fixed float for foreach goto if \
1149 implicit in int interface internal is lock long namespace new null \
1150 object operator out override params private protected public \
1151 readonly ref return sbyte sealed short sizeof stackalloc static \
1152 string struct switch this throw true try typeof uint ulong \
1153 unchecked unsafe ushort using virtual void while")).GetBuffer()));
1154 SetupCppLexer();
1156 if ((_tcscmp(line, _T("rc"))==0)||
1157 (_tcscmp(line, _T("rc2"))==0))
1159 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1160 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("ACCELERATORS ALT AUTO3STATE AUTOCHECKBOX AUTORADIOBUTTON \
1161 BEGIN BITMAP BLOCK BUTTON CAPTION CHARACTERISTICS CHECKBOX CLASS \
1162 COMBOBOX CONTROL CTEXT CURSOR DEFPUSHBUTTON DIALOG DIALOGEX DISCARDABLE \
1163 EDITTEXT END EXSTYLE FONT GROUPBOX ICON LANGUAGE LISTBOX LTEXT \
1164 MENU MENUEX MENUITEM MESSAGETABLE POPUP \
1165 PUSHBUTTON RADIOBUTTON RCDATA RTEXT SCROLLBAR SEPARATOR SHIFT STATE3 \
1166 STRINGTABLE STYLE TEXTINCLUDE VALUE VERSION VERSIONINFO VIRTKEY")).GetBuffer()));
1167 SetupCppLexer();
1169 if ((_tcscmp(line, _T("idl"))==0)||
1170 (_tcscmp(line, _T("odl"))==0))
1172 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1173 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("aggregatable allocate appobject arrays async async_uuid \
1174 auto_handle \
1175 bindable boolean broadcast byte byte_count \
1176 call_as callback char coclass code comm_status \
1177 const context_handle context_handle_noserialize \
1178 context_handle_serialize control cpp_quote custom \
1179 decode default defaultbind defaultcollelem \
1180 defaultvalue defaultvtable dispinterface displaybind dllname \
1181 double dual \
1182 enable_allocate encode endpoint entry enum error_status_t \
1183 explicit_handle \
1184 fault_status first_is float \
1185 handle_t heap helpcontext helpfile helpstring \
1186 helpstringcontext helpstringdll hidden hyper \
1187 id idempotent ignore iid_as iid_is immediatebind implicit_handle \
1188 import importlib in include in_line int __int64 __int3264 interface \
1189 last_is lcid length_is library licensed local long \
1190 max_is maybe message methods midl_pragma \
1191 midl_user_allocate midl_user_free min_is module ms_union \
1192 ncacn_at_dsp ncacn_dnet_nsp ncacn_http ncacn_ip_tcp \
1193 ncacn_nb_ipx ncacn_nb_nb ncacn_nb_tcp ncacn_np \
1194 ncacn_spx ncacn_vns_spp ncadg_ip_udp ncadg_ipx ncadg_mq \
1195 ncalrpc nocode nonbrowsable noncreatable nonextensible notify \
1196 object odl oleautomation optimize optional out out_of_line \
1197 pipe pointer_default pragma properties propget propput propputref \
1198 ptr public \
1199 range readonly ref represent_as requestedit restricted retval \
1200 shape short signed size_is small source strict_context_handle \
1201 string struct switch switch_is switch_type \
1202 transmit_as typedef \
1203 uidefault union unique unsigned user_marshal usesgetlasterror uuid \
1204 v1_enum vararg version void wchar_t wire_marshal")).GetBuffer()));
1205 SetupCppLexer();
1207 if (_tcscmp(line, _T("java"))==0)
1209 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1210 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("abstract assert boolean break byte case catch char class \
1211 const continue default do double else extends final finally float for future \
1212 generic goto if implements import inner instanceof int interface long \
1213 native new null outer package private protected public rest \
1214 return short static super switch synchronized this throw throws \
1215 transient try var void volatile while")).GetBuffer()));
1216 SetupCppLexer();
1218 if (_tcscmp(line, _T("js"))==0)
1220 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1221 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("abstract boolean break byte case catch char class \
1222 const continue debugger default delete do double else enum export extends \
1223 final finally float for function goto if implements import in instanceof \
1224 int interface long native new package private protected public \
1225 return short static super switch synchronized this throw throws \
1226 transient try typeof var void volatile while with")).GetBuffer()));
1227 SetupCppLexer();
1229 if ((_tcscmp(line, _T("pas"))==0)||
1230 (_tcscmp(line, _T("dpr"))==0)||
1231 (_tcscmp(line, _T("pp"))==0))
1233 SendEditor(SCI_SETLEXER, SCLEX_PASCAL);
1234 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("and array as begin case class const constructor \
1235 destructor div do downto else end except file finally \
1236 for function goto if implementation in inherited \
1237 interface is mod not object of on or packed \
1238 procedure program property raise record repeat \
1239 set shl shr then threadvar to try type unit \
1240 until uses var while with xor")).GetBuffer()));
1241 SetupCppLexer();
1243 if ((_tcscmp(line, _T("as"))==0)||
1244 (_tcscmp(line, _T("asc"))==0)||
1245 (_tcscmp(line, _T("jsfl"))==0))
1247 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1248 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("add and break case catch class continue default delete do \
1249 dynamic else eq extends false finally for function ge get gt if implements import in \
1250 instanceof interface intrinsic le lt ne new not null or private public return \
1251 set static super switch this throw true try typeof undefined var void while with")).GetBuffer()));
1252 SendEditor(SCI_SETKEYWORDS, 1, (LPARAM)(m_TextView.StringForControl(_T("Array Arguments Accessibility Boolean Button Camera Color \
1253 ContextMenu ContextMenuItem Date Error Function Key LoadVars LocalConnection Math \
1254 Microphone Mouse MovieClip MovieClipLoader NetConnection NetStream Number Object \
1255 PrintJob Selection SharedObject Sound Stage String StyleSheet System TextField \
1256 TextFormat TextSnapshot Video Void XML XMLNode XMLSocket \
1257 _accProps _focusrect _global _highquality _parent _quality _root _soundbuftime \
1258 arguments asfunction call capabilities chr clearInterval duplicateMovieClip \
1259 escape eval fscommand getProperty getTimer getURL getVersion gotoAndPlay gotoAndStop \
1260 ifFrameLoaded Infinity -Infinity int isFinite isNaN length loadMovie loadMovieNum \
1261 loadVariables loadVariablesNum maxscroll mbchr mblength mbord mbsubstring MMExecute \
1262 NaN newline nextFrame nextScene on onClipEvent onUpdate ord parseFloat parseInt play \
1263 prevFrame prevScene print printAsBitmap printAsBitmapNum printNum random removeMovieClip \
1264 scroll set setInterval setProperty startDrag stop stopAllSounds stopDrag substring \
1265 targetPath tellTarget toggleHighQuality trace unescape unloadMovie unLoadMovieNum updateAfterEvent")).GetBuffer()));
1266 SetupCppLexer();
1268 if ((_tcscmp(line, _T("html"))==0)||
1269 (_tcscmp(line, _T("htm"))==0)||
1270 (_tcscmp(line, _T("shtml"))==0)||
1271 (_tcscmp(line, _T("htt"))==0)||
1272 (_tcscmp(line, _T("xml"))==0)||
1273 (_tcscmp(line, _T("asp"))==0)||
1274 (_tcscmp(line, _T("xsl"))==0)||
1275 (_tcscmp(line, _T("php"))==0)||
1276 (_tcscmp(line, _T("xhtml"))==0)||
1277 (_tcscmp(line, _T("phtml"))==0)||
1278 (_tcscmp(line, _T("cfm"))==0)||
1279 (_tcscmp(line, _T("tpl"))==0)||
1280 (_tcscmp(line, _T("dtd"))==0)||
1281 (_tcscmp(line, _T("hta"))==0)||
1282 (_tcscmp(line, _T("htd"))==0)||
1283 (_tcscmp(line, _T("wxs"))==0))
1285 SendEditor(SCI_SETLEXER, SCLEX_HTML);
1286 SendEditor(SCI_SETSTYLEBITS, 7);
1287 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("a abbr acronym address applet area b base basefont \
1288 bdo big blockquote body br button caption center \
1289 cite code col colgroup dd del dfn dir div dl dt em \
1290 fieldset font form frame frameset h1 h2 h3 h4 h5 h6 \
1291 head hr html i iframe img input ins isindex kbd label \
1292 legend li link map menu meta noframes noscript \
1293 object ol optgroup option p param pre q s samp \
1294 script select small span strike strong style sub sup \
1295 table tbody td textarea tfoot th thead title tr tt u ul \
1296 var xml xmlns abbr accept-charset accept accesskey action align alink \
1297 alt archive axis background bgcolor border \
1298 cellpadding cellspacing char charoff charset checked cite \
1299 class classid clear codebase codetype color cols colspan \
1300 compact content coords \
1301 data datafld dataformatas datapagesize datasrc datetime \
1302 declare defer dir disabled enctype event \
1303 face for frame frameborder \
1304 headers height href hreflang hspace http-equiv \
1305 id ismap label lang language leftmargin link longdesc \
1306 marginwidth marginheight maxlength media method multiple \
1307 name nohref noresize noshade nowrap \
1308 object onblur onchange onclick ondblclick onfocus \
1309 onkeydown onkeypress onkeyup onload onmousedown \
1310 onmousemove onmouseover onmouseout onmouseup \
1311 onreset onselect onsubmit onunload \
1312 profile prompt readonly rel rev rows rowspan rules \
1313 scheme scope selected shape size span src standby start style \
1314 summary tabindex target text title topmargin type usemap \
1315 valign value valuetype version vlink vspace width \
1316 text password checkbox radio submit reset \
1317 file hidden image")).GetBuffer()));
1318 SendEditor(SCI_SETKEYWORDS, 1, (LPARAM)(m_TextView.StringForControl(_T("assign audio block break catch choice clear disconnect else elseif \
1319 emphasis enumerate error exit field filled form goto grammar help \
1320 if initial link log menu meta noinput nomatch object option p paragraph \
1321 param phoneme prompt property prosody record reprompt return s say-as \
1322 script sentence subdialog submit throw transfer value var voice vxml")).GetBuffer()));
1323 SendEditor(SCI_SETKEYWORDS, 2, (LPARAM)(m_TextView.StringForControl(_T("accept age alphabet anchor application base beep bridge category charset \
1324 classid cond connecttimeout content contour count dest destexpr dtmf dtmfterm \
1325 duration enctype event eventexpr expr expritem fetchtimeout finalsilence \
1326 gender http-equiv id level maxage maxstale maxtime message messageexpr \
1327 method mime modal mode name namelist next nextitem ph pitch range rate \
1328 scope size sizeexpr skiplist slot src srcexpr sub time timeexpr timeout \
1329 transferaudio type value variant version volume xml:lang")).GetBuffer()));
1330 SendEditor(SCI_SETKEYWORDS, 3, (LPARAM)(m_TextView.StringForControl(_T("and assert break class continue def del elif \
1331 else except exec finally for from global if import in is lambda None \
1332 not or pass print raise return try while yield")).GetBuffer()));
1333 SendEditor(SCI_SETKEYWORDS, 4, (LPARAM)(m_TextView.StringForControl(_T("and argv as argc break case cfunction class continue declare default do \
1334 die echo else elseif empty enddeclare endfor endforeach endif endswitch \
1335 endwhile e_all e_parse e_error e_warning eval exit extends false for \
1336 foreach function global http_cookie_vars http_get_vars http_post_vars \
1337 http_post_files http_env_vars http_server_vars if include include_once \
1338 list new not null old_function or parent php_os php_self php_version \
1339 print require require_once return static switch stdclass this true var \
1340 xor virtual while __file__ __line__ __sleep __wakeup")).GetBuffer()));
1342 SetAStyle(SCE_H_TAG, darkBlue);
1343 SetAStyle(SCE_H_TAGUNKNOWN, red);
1344 SetAStyle(SCE_H_ATTRIBUTE, darkBlue);
1345 SetAStyle(SCE_H_ATTRIBUTEUNKNOWN, red);
1346 SetAStyle(SCE_H_NUMBER, RGB(0x80,0,0x80));
1347 SetAStyle(SCE_H_DOUBLESTRING, RGB(0,0x80,0));
1348 SetAStyle(SCE_H_SINGLESTRING, RGB(0,0x80,0));
1349 SetAStyle(SCE_H_OTHER, RGB(0x80,0,0x80));
1350 SetAStyle(SCE_H_COMMENT, RGB(0x80,0x80,0));
1351 SetAStyle(SCE_H_ENTITY, RGB(0x80,0,0x80));
1353 SetAStyle(SCE_H_TAGEND, darkBlue);
1354 SetAStyle(SCE_H_XMLSTART, darkBlue); // <?
1355 SetAStyle(SCE_H_QUESTION, darkBlue); // <?
1356 SetAStyle(SCE_H_XMLEND, darkBlue); // ?>
1357 SetAStyle(SCE_H_SCRIPT, darkBlue); // <script
1358 SetAStyle(SCE_H_ASP, RGB(0x4F, 0x4F, 0), RGB(0xFF, 0xFF, 0)); // <% ... %>
1359 SetAStyle(SCE_H_ASPAT, RGB(0x4F, 0x4F, 0), RGB(0xFF, 0xFF, 0)); // <%@ ... %>
1361 SetAStyle(SCE_HB_DEFAULT, black);
1362 SetAStyle(SCE_HB_COMMENTLINE, darkGreen);
1363 SetAStyle(SCE_HB_NUMBER, RGB(0,0x80,0x80));
1364 SetAStyle(SCE_HB_WORD, darkBlue);
1365 SendEditor(SCI_STYLESETBOLD, SCE_HB_WORD, 1);
1366 SetAStyle(SCE_HB_STRING, RGB(0x80,0,0x80));
1367 SetAStyle(SCE_HB_IDENTIFIER, black);
1369 // This light blue is found in the windows system palette so is safe to use even in 256 colour modes.
1370 // Show the whole section of VBScript with light blue background
1371 for (int bstyle = SCE_HB_DEFAULT; bstyle <= SCE_HB_STRINGEOL; ++bstyle) {
1372 SendEditor(SCI_STYLESETFONT, bstyle,
1373 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
1374 SendEditor(SCI_STYLESETBACK, bstyle, lightBlue);
1375 // This call extends the backround colour of the last style on the line to the edge of the window
1376 SendEditor(SCI_STYLESETEOLFILLED, bstyle, 1);
1378 SendEditor(SCI_STYLESETBACK, SCE_HB_STRINGEOL, RGB(0x7F,0x7F,0xFF));
1379 SendEditor(SCI_STYLESETFONT, SCE_HB_COMMENTLINE,
1380 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
1382 SetAStyle(SCE_HBA_DEFAULT, black);
1383 SetAStyle(SCE_HBA_COMMENTLINE, darkGreen);
1384 SetAStyle(SCE_HBA_NUMBER, RGB(0,0x80,0x80));
1385 SetAStyle(SCE_HBA_WORD, darkBlue);
1386 SendEditor(SCI_STYLESETBOLD, SCE_HBA_WORD, 1);
1387 SetAStyle(SCE_HBA_STRING, RGB(0x80,0,0x80));
1388 SetAStyle(SCE_HBA_IDENTIFIER, black);
1390 // Show the whole section of ASP VBScript with bright yellow background
1391 for (int bastyle = SCE_HBA_DEFAULT; bastyle <= SCE_HBA_STRINGEOL; ++bastyle) {
1392 SendEditor(SCI_STYLESETFONT, bastyle,
1393 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
1394 SendEditor(SCI_STYLESETBACK, bastyle, RGB(0xFF, 0xFF, 0));
1395 // This call extends the backround colour of the last style on the line to the edge of the window
1396 SendEditor(SCI_STYLESETEOLFILLED, bastyle, 1);
1398 SendEditor(SCI_STYLESETBACK, SCE_HBA_STRINGEOL, RGB(0xCF,0xCF,0x7F));
1399 SendEditor(SCI_STYLESETFONT, SCE_HBA_COMMENTLINE,
1400 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
1402 // If there is no need to support embedded Javascript, the following code can be dropped.
1403 // Javascript will still be correctly processed but will be displayed in just the default style.
1405 SetAStyle(SCE_HJ_START, RGB(0x80,0x80,0));
1406 SetAStyle(SCE_HJ_DEFAULT, black);
1407 SetAStyle(SCE_HJ_COMMENT, darkGreen);
1408 SetAStyle(SCE_HJ_COMMENTLINE, darkGreen);
1409 SetAStyle(SCE_HJ_COMMENTDOC, darkGreen);
1410 SetAStyle(SCE_HJ_NUMBER, RGB(0,0x80,0x80));
1411 SetAStyle(SCE_HJ_WORD, black);
1412 SetAStyle(SCE_HJ_KEYWORD, darkBlue);
1413 SetAStyle(SCE_HJ_DOUBLESTRING, RGB(0x80,0,0x80));
1414 SetAStyle(SCE_HJ_SINGLESTRING, RGB(0x80,0,0x80));
1415 SetAStyle(SCE_HJ_SYMBOLS, black);
1417 SetAStyle(SCE_HJA_START, RGB(0x80,0x80,0));
1418 SetAStyle(SCE_HJA_DEFAULT, black);
1419 SetAStyle(SCE_HJA_COMMENT, darkGreen);
1420 SetAStyle(SCE_HJA_COMMENTLINE, darkGreen);
1421 SetAStyle(SCE_HJA_COMMENTDOC, darkGreen);
1422 SetAStyle(SCE_HJA_NUMBER, RGB(0,0x80,0x80));
1423 SetAStyle(SCE_HJA_WORD, black);
1424 SetAStyle(SCE_HJA_KEYWORD, darkBlue);
1425 SetAStyle(SCE_HJA_DOUBLESTRING, RGB(0x80,0,0x80));
1426 SetAStyle(SCE_HJA_SINGLESTRING, RGB(0x80,0,0x80));
1427 SetAStyle(SCE_HJA_SYMBOLS, black);
1429 SetAStyle(SCE_HPHP_DEFAULT, black);
1430 SetAStyle(SCE_HPHP_HSTRING, RGB(0x80,0,0x80));
1431 SetAStyle(SCE_HPHP_SIMPLESTRING, RGB(0x80,0,0x80));
1432 SetAStyle(SCE_HPHP_WORD, darkBlue);
1433 SetAStyle(SCE_HPHP_NUMBER, RGB(0,0x80,0x80));
1434 SetAStyle(SCE_HPHP_VARIABLE, red);
1435 SetAStyle(SCE_HPHP_HSTRING_VARIABLE, red);
1436 SetAStyle(SCE_HPHP_COMPLEX_VARIABLE, red);
1437 SetAStyle(SCE_HPHP_COMMENT, darkGreen);
1438 SetAStyle(SCE_HPHP_COMMENTLINE, darkGreen);
1439 SetAStyle(SCE_HPHP_OPERATOR, darkBlue);
1441 // Show the whole section of Javascript with off white background
1442 for (int jstyle = SCE_HJ_DEFAULT; jstyle <= SCE_HJ_SYMBOLS; ++jstyle) {
1443 SendEditor(SCI_STYLESETFONT, jstyle,
1444 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
1445 SendEditor(SCI_STYLESETBACK, jstyle, offWhite);
1446 SendEditor(SCI_STYLESETEOLFILLED, jstyle, 1);
1448 SendEditor(SCI_STYLESETBACK, SCE_HJ_STRINGEOL, RGB(0xDF, 0xDF, 0x7F));
1449 SendEditor(SCI_STYLESETEOLFILLED, SCE_HJ_STRINGEOL, 1);
1451 // Show the whole section of Javascript with brown background
1452 for (int jastyle = SCE_HJA_DEFAULT; jastyle <= SCE_HJA_SYMBOLS; ++jastyle) {
1453 SendEditor(SCI_STYLESETFONT, jastyle,
1454 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
1455 SendEditor(SCI_STYLESETBACK, jastyle, RGB(0xDF, 0xDF, 0x7F));
1456 SendEditor(SCI_STYLESETEOLFILLED, jastyle, 1);
1458 SendEditor(SCI_STYLESETBACK, SCE_HJA_STRINGEOL, RGB(0x0,0xAF,0x5F));
1459 SendEditor(SCI_STYLESETEOLFILLED, SCE_HJA_STRINGEOL, 1);
1462 else
1464 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1465 SetupCppLexer();
1467 SendEditor(SCI_COLOURISE, 0, -1);
1471 void CTortoiseGitBlameView::SetupCppLexer()
1473 SetAStyle(SCE_C_DEFAULT, RGB(0, 0, 0));
1474 SetAStyle(SCE_C_COMMENT, RGB(0, 0x80, 0));
1475 SetAStyle(SCE_C_COMMENTLINE, RGB(0, 0x80, 0));
1476 SetAStyle(SCE_C_COMMENTDOC, RGB(0, 0x80, 0));
1477 SetAStyle(SCE_C_COMMENTLINEDOC, RGB(0, 0x80, 0));
1478 SetAStyle(SCE_C_COMMENTDOCKEYWORD, RGB(0, 0x80, 0));
1479 SetAStyle(SCE_C_COMMENTDOCKEYWORDERROR, RGB(0, 0x80, 0));
1480 SetAStyle(SCE_C_NUMBER, RGB(0, 0x80, 0x80));
1481 SetAStyle(SCE_C_WORD, RGB(0, 0, 0x80));
1482 SendEditor(SCE_C_WORD, 1);
1483 SetAStyle(SCE_C_STRING, RGB(0x80, 0, 0x80));
1484 SetAStyle(SCE_C_IDENTIFIER, RGB(0, 0, 0));
1485 SetAStyle(SCE_C_PREPROCESSOR, RGB(0x80, 0, 0));
1486 SetAStyle(SCE_C_OPERATOR, RGB(0x80, 0x80, 0));
1487 SendEditor(SCI_SETPROPERTY, (WPARAM)"lexer.cpp.track.preprocessor", (LPARAM)"0");
1490 int CTortoiseGitBlameView::GetEncode(unsigned char *buff, int size, int *bomoffset)
1492 CFileTextLines textlines;
1493 CFileTextLines::UnicodeType type = textlines.CheckUnicodeType(buff, size);
1495 if(type == CFileTextLines::UTF8BOM)
1497 *bomoffset = 3;
1498 return CP_UTF8;
1500 if(type == CFileTextLines::UTF8)
1501 return CP_UTF8;
1503 if(type == CFileTextLines::UTF16_LE)
1504 return 1200;
1505 if (type == CFileTextLines::UTF16_LEBOM)
1507 *bomoffset = 2;
1508 return 1200;
1511 if(type == CFileTextLines::UTF16_BE)
1512 return 1201;
1513 if (type == CFileTextLines::UTF16_BEBOM)
1515 *bomoffset = 2;
1516 return 1201;
1519 return GetACP();
1522 void CTortoiseGitBlameView::ParseBlame()
1524 m_data.ParseBlameOutput(GetDocument()->m_BlameData, GetLogData()->m_pLogCache->m_HashMap, m_DateFormat, m_bRelativeTimes);
1525 CString filename = GetDocument()->m_GitPath.GetGitPathString();
1526 m_bBlameOuputContainsOtherFilenames = m_data.ContainsOnlyFilename(filename) ? FALSE : TRUE;
1529 void CTortoiseGitBlameView::MapLineToLogIndex()
1531 std::vector<int> lineToLogIndex;
1534 int numberOfLines = m_data.GetNumberOfLines();
1535 lineToLogIndex.reserve(numberOfLines);
1536 size_t logSize = this->GetLogData()->size();
1537 for (int j = 0; j < numberOfLines; ++j)
1539 CGitHash& hash = m_data.GetHash(j);
1541 int index = -2;
1542 for (size_t i = 0; i < logSize; ++i)
1544 if (hash == this->GetLogData()->at(i))
1546 index = (int)i;
1547 break;
1550 lineToLogIndex.push_back(index);
1552 this->m_lineToLogIndex.swap(lineToLogIndex);
1555 void CTortoiseGitBlameView::UpdateInfo(int Encode)
1557 CreateFont();
1559 SendEditor(SCI_SETREADONLY, FALSE);
1560 SendEditor(SCI_CLEARALL);
1561 SendEditor(EM_EMPTYUNDOBUFFER);
1562 SendEditor(SCI_SETSAVEPOINT);
1563 SendEditor(SCI_CANCEL);
1564 SendEditor(SCI_SETUNDOCOLLECTION, 0);
1566 SendEditor(SCI_SETCODEPAGE, SC_CP_UTF8);
1568 int encoding = m_data.UpdateEncoding(Encode);
1570 int numberOfLines = m_data.GetNumberOfLines();
1571 if (numberOfLines > 0)
1573 for (int i = 0; i < numberOfLines - 1; ++i)
1575 SendEditor(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)m_data.GetUtf8Line(i));
1576 SendEditor(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)"\n\0\0\0");
1579 // as it will add another line number in scintilla which has no counter part in the blame output
1580 // prevent carriage return and line feed for the last line
1581 CStringA s = m_data.GetUtf8Line(numberOfLines - 1);
1582 int length = s.GetLength();
1583 if (length > 0 && s.GetAt(length - 1) == '\r')
1584 s.Truncate(length - 1);
1585 SendEditor(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)s);
1590 UINT nID;
1591 UINT nStyle;
1592 int cxWidth;
1593 int nIndex = ((CMainFrame *)::AfxGetApp()->GetMainWnd())->m_wndStatusBar.CommandToIndex(ID_INDICATOR_ENCODING);
1594 ((CMainFrame *)::AfxGetApp()->GetMainWnd())->m_wndStatusBar.GetPaneInfo(nIndex, nID, nStyle, cxWidth);
1595 CString sBarText = L"";
1596 for (int i = 0; i < _countof(encodings); ++i)
1598 if (encodings[i].id == encoding)
1600 sBarText = CString(encodings[i].name);
1601 break;
1604 //calculate the width of the text
1605 CDC * pDC = ((CMainFrame *)::AfxGetApp()->GetMainWnd())->m_wndStatusBar.GetDC();
1606 if (pDC)
1608 CSize size = pDC->GetTextExtent(sBarText);
1609 ((CMainFrame *)::AfxGetApp()->GetMainWnd())->m_wndStatusBar.SetPaneInfo(nIndex, nID, nStyle, size.cx+2);
1610 ReleaseDC(pDC);
1612 ((CMainFrame *)::AfxGetApp()->GetMainWnd())->m_wndStatusBar.SetPaneText(nIndex, sBarText);
1615 #ifdef USE_TEMPFILENAME
1616 if(m_Buffer)
1618 delete m_Buffer;
1619 m_Buffer=NULL;
1622 CFile file;
1623 file.Open(this->GetDocument()->m_TempFileName,CFile::modeRead);
1625 m_Buffer = new char[file.GetLength()+4];
1626 m_Buffer[file.GetLength()] =0;
1627 m_Buffer[file.GetLength()+1] =0;
1628 m_Buffer[file.GetLength()+2] =0;
1629 m_Buffer[file.GetLength()+3] =0;
1631 file.Read(m_Buffer, file.GetLength());
1633 int bomoffset =0;
1634 int encoding = GetEncode( (unsigned char *)m_Buffer, file.GetLength(), &bomoffset);
1636 file.Close();
1637 //SendEditor(SCI_SETCODEPAGE, encoding);
1639 //SendEditor(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)(m_Buffer + bomoffset));
1640 #endif
1641 SetupLexer(GetDocument()->m_CurrentFileName);
1643 SendEditor(SCI_SETUNDOCOLLECTION, 1);
1644 SendEditor(EM_EMPTYUNDOBUFFER);
1645 SendEditor(SCI_SETSAVEPOINT);
1646 SendEditor(SCI_GOTOPOS, 0);
1647 SendEditor(SCI_SETSCROLLWIDTHTRACKING, TRUE);
1648 SendEditor(SCI_SETREADONLY, TRUE);
1650 GetBlameWidth();
1651 CRect rect;
1652 this->GetClientRect(rect);
1653 //this->m_TextView.GetWindowRect(rect);
1654 //this->m_TextView.ScreenToClient(rect);
1655 rect.left=this->m_blamewidth;
1656 this->m_TextView.MoveWindow(rect);
1658 this->Invalidate();
1661 CString CTortoiseGitBlameView::ResolveCommitFile(int line)
1663 return ResolveCommitFile(m_data.GetFilename(line));
1666 CString CTortoiseGitBlameView::ResolveCommitFile(const CString& path)
1668 if (path.IsEmpty())
1670 return ((CMainFrame*)::AfxGetApp()->GetMainWnd())->GetActiveView()->GetDocument()->GetPathName();
1672 else
1674 CTGitPath tgp(g_Git.m_CurrentDir);
1675 tgp.AppendPathString(path);
1676 return tgp.GetWinPathString();
1680 COLORREF CTortoiseGitBlameView::GetLineColor(int line)
1682 if (m_colorage && m_data.IsValidLine(line))
1684 int logIndex = m_lineToLogIndex[line];
1685 if (logIndex >= 0)
1687 int slider = (int)((GetLogData()->size() - logIndex) * 100 / (GetLogData()->size() + 1));
1688 return InterColor(DWORD(m_regOldLinesColor), DWORD(m_regNewLinesColor), slider);
1691 return m_windowcolor;
1694 CGitBlameLogList * CTortoiseGitBlameView::GetLogList()
1696 return &(GetDocument()->GetMainFrame()->m_wndOutput.m_LogList);
1700 CLogDataVector * CTortoiseGitBlameView::GetLogData()
1702 return &(GetDocument()->GetMainFrame()->m_wndOutput.m_LogList.m_logEntries);
1705 void CTortoiseGitBlameView::OnSciPainted(NMHDR *,LRESULT *)
1707 this->Invalidate();
1710 void CTortoiseGitBlameView::OnLButtonDown(UINT nFlags,CPoint point)
1713 int line = (int)SendEditor(SCI_GETFIRSTVISIBLELINE);
1714 int height = (int)SendEditor(SCI_TEXTHEIGHT);
1715 line = line + (int)(point.y/height);
1717 if (line < m_data.GetNumberOfLines())
1719 SetSelectedLine(line);
1720 if (m_data.GetHash(line) != m_SelectedHash)
1722 m_SelectedHash = m_data.GetHash(line);
1724 int logIndex = m_lineToLogIndex[line];
1725 if (logIndex >= 0)
1727 this->GetLogList()->SetItemState(logIndex, LVIS_SELECTED, LVIS_SELECTED);
1728 this->GetLogList()->EnsureVisible(logIndex, FALSE);
1730 else
1732 GitRev *pRev = m_data.GetRev(line, GetLogData()->m_pLogCache->m_HashMap);
1733 this->GetDocument()->GetMainFrame()->m_wndProperties.UpdateProperties(pRev);
1736 else
1738 m_SelectedHash.Empty();
1740 //::InvalidateRect( NULL, FALSE);
1741 this->Invalidate();
1742 this->m_TextView.Invalidate();
1745 else
1747 SetSelectedLine(-1);
1750 CView::OnLButtonDown(nFlags,point);
1753 void CTortoiseGitBlameView::OnSciGetBkColor(NMHDR* hdr, LRESULT* /*result*/)
1755 SCNotification *notification=reinterpret_cast<SCNotification *>(hdr);
1757 if (notification->line < m_data.GetNumberOfLines())
1759 if (m_data.GetHash(notification->line) == this->m_SelectedHash)
1760 notification->lParam = m_selectedauthorcolor;
1761 else
1762 notification->lParam = GetLineColor(notification->line);
1766 void CTortoiseGitBlameView::FocusOn(GitRev *pRev)
1768 this->GetDocument()->GetMainFrame()->m_wndProperties.UpdateProperties(pRev);
1770 this->Invalidate();
1772 if (m_SelectedHash != pRev->m_CommitHash) {
1773 m_SelectedHash = pRev->m_CommitHash;
1774 int line = m_data.FindFirstLine(m_SelectedHash, 0);
1775 if (line >= 0)
1777 GotoLine(line + 1);
1778 m_TextView.Invalidate();
1779 return;
1781 SendEditor(SCI_SETSEL, INT_MAX, -1);
1785 void CTortoiseGitBlameView::OnMouseHover(UINT /*nFlags*/, CPoint point)
1787 int line = (int)SendEditor(SCI_GETFIRSTVISIBLELINE);
1788 int height = (int)SendEditor(SCI_TEXTHEIGHT);
1789 line = line + (point.y/height);
1791 if (m_data.IsValidLine(line))
1793 if (line != m_MouseLine)
1795 m_MouseLine = line;
1796 GitRev *pRev = nullptr;
1797 int logIndex = m_lineToLogIndex[line];
1798 if (logIndex >= 0)
1799 pRev = &GetLogData()->GetGitRevAt(logIndex);
1800 else
1801 pRev = m_data.GetRev(line, GetLogData()->m_pLogCache->m_HashMap);
1803 if (!pRev)
1804 return;
1806 CString body = pRev->GetBody();
1807 int maxLine = 15;
1808 int iline = 0;
1809 int pos = 0;
1810 while (iline++ < maxLine)
1812 int pos2 = body.Find(_T("\n"), pos);
1813 if (pos2 < 0)
1814 break;
1815 int lineLength = pos2 - pos - 1;
1816 pos = pos2 + 1;
1817 iline += lineLength / 70;
1820 CString filename;
1821 if ((m_bShowCompleteLog && m_bFollowRenames) || !BlameIsLimitedToOneFilename(m_dwDetectMovedOrCopiedLines) || m_bBlameOuputContainsOtherFilenames)
1822 filename.Format(_T("%s: %s\n"), m_sFileName, m_data.GetFilename(line));
1824 CString str;
1825 str.Format(_T("%s: %s\n%s%s: %s <%s>\n%s: %s\n%s:\n%s\n%s"), m_sRev, pRev->m_CommitHash.ToString(), filename,
1826 m_sAuthor, pRev->GetAuthorName(), pRev->GetAuthorEmail(),
1827 m_sDate, CLoglistUtils::FormatDateAndTime(pRev->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
1828 m_sMessage, pRev->GetSubject(),
1829 iline <= maxLine ? body : (body.Left(pos) + _T("\n....................")));
1831 m_ToolTip.Pop();
1832 m_ToolTip.AddTool(this, str);
1834 CRect rect;
1835 rect.left=LOCATOR_WIDTH;
1836 rect.right=this->m_blamewidth+rect.left;
1837 rect.top = point.y - (LONG)height;
1838 rect.bottom = point.y + (LONG)height;
1839 this->InvalidateRect(rect);
1844 void CTortoiseGitBlameView::OnMouseMove(UINT /*nFlags*/, CPoint /*point*/)
1846 TRACKMOUSEEVENT tme;
1847 tme.cbSize=sizeof(TRACKMOUSEEVENT);
1848 tme.dwFlags=TME_HOVER|TME_LEAVE;
1849 tme.hwndTrack=this->m_hWnd;
1850 tme.dwHoverTime=1;
1851 TrackMouseEvent(&tme);
1855 BOOL CTortoiseGitBlameView::PreTranslateMessage(MSG* pMsg)
1857 m_ToolTip.RelayEvent(pMsg);
1858 return CView::PreTranslateMessage(pMsg);
1861 void CTortoiseGitBlameView::OnEditFind()
1863 if (m_pFindDialog)
1864 return;
1866 m_pFindDialog=new CFindReplaceDialog();
1868 CString oneline = theApp.GetString(_T("FindString"));
1869 if (m_TextView.Call(SCI_GETSELECTIONSTART) != m_TextView.Call(SCI_GETSELECTIONEND))
1871 LRESULT bufsize = m_TextView.Call(SCI_GETSELECTIONEND) - m_TextView.Call(SCI_GETSELECTIONSTART);
1872 char * linebuf = new char[bufsize + 1];
1873 SecureZeroMemory(linebuf, bufsize + 1);
1874 SendEditor(SCI_GETSELTEXT, 0, (LPARAM)linebuf);
1875 oneline = m_TextView.StringFromControl(linebuf);
1876 delete [] linebuf;
1879 DWORD flags = FR_DOWN | FR_HIDEWHOLEWORD | FR_HIDEUPDOWN;
1880 if (theApp.GetInt(_T("FindMatchCase")))
1881 flags |= FR_MATCHCASE;
1883 m_pFindDialog->Create(TRUE, oneline, NULL, flags, this);
1886 void CTortoiseGitBlameView::OnEditGoto()
1888 CEditGotoDlg dlg;
1889 if(dlg.DoModal()==IDOK)
1891 this->GotoLine(dlg.m_LineNumber);
1895 LRESULT CTortoiseGitBlameView::OnFindDialogMessage(WPARAM /*wParam*/, LPARAM /*lParam*/)
1897 ASSERT(m_pFindDialog != NULL);
1899 // If the FR_DIALOGTERM flag is set,
1900 // invalidate the handle identifying the dialog box.
1901 if (m_pFindDialog->IsTerminating())
1903 m_pFindDialog = NULL;
1904 return 0;
1907 if (m_data.GetNumberOfLines()==0)
1908 return 0;
1910 // If the FR_FINDNEXT flag is set,
1911 // call the application-defined search routine
1912 // to search for the requested string.
1913 if(m_pFindDialog->FindNext())
1915 //read data from dialog
1916 CString FindName = m_pFindDialog->GetFindString();
1918 DoSearch(FindName,m_pFindDialog->m_fr.Flags);
1921 return 0;
1924 void CTortoiseGitBlameView::OnViewNext()
1926 int startline = (int)SendEditor(SCI_GETFIRSTVISIBLELINE);
1927 int line = m_data.FindNextLine(this->m_SelectedHash, (int)SendEditor(SCI_GETFIRSTVISIBLELINE), false);
1928 if(line >= 0)
1929 SendEditor(SCI_LINESCROLL, 0, line - startline - 2);
1931 void CTortoiseGitBlameView::OnViewPrev()
1933 int startline = (int)SendEditor(SCI_GETFIRSTVISIBLELINE);
1934 int line = m_data.FindNextLine(this->m_SelectedHash, (int)SendEditor(SCI_GETFIRSTVISIBLELINE), true);
1935 if(line >= 0)
1936 SendEditor(SCI_LINESCROLL, 0, line - startline - 2);
1939 void CTortoiseGitBlameView::OnViewToggleAuthor()
1941 m_bShowAuthor = ! m_bShowAuthor;
1943 theApp.WriteInt(_T("ShowAuthor"), m_bShowAuthor);
1945 CRect rect;
1946 this->GetClientRect(&rect);
1947 rect.left=GetBlameWidth();
1949 m_TextView.MoveWindow(&rect);
1952 void CTortoiseGitBlameView::OnUpdateViewToggleAuthor(CCmdUI *pCmdUI)
1954 pCmdUI->SetCheck(m_bShowAuthor);
1957 void CTortoiseGitBlameView::OnViewToggleDate()
1959 m_bShowDate = ! m_bShowDate;
1961 theApp.WriteInt(_T("ShowDate"), m_bShowDate);
1963 CRect rect;
1964 this->GetClientRect(&rect);
1965 rect.left=GetBlameWidth();
1967 m_TextView.MoveWindow(&rect);
1970 void CTortoiseGitBlameView::OnUpdateViewToggleDate(CCmdUI *pCmdUI)
1972 pCmdUI->SetCheck(m_bShowDate);
1975 void CTortoiseGitBlameView::OnViewToggleShowFilename()
1977 m_bShowFilename = ! m_bShowFilename;
1979 theApp.WriteInt(_T("ShowFilename"), m_bShowFilename);
1981 CRect rect;
1982 this->GetClientRect(&rect);
1983 rect.left = GetBlameWidth();
1985 m_TextView.MoveWindow(&rect);
1988 void CTortoiseGitBlameView::OnUpdateViewToggleShowFilename(CCmdUI *pCmdUI)
1990 pCmdUI->SetCheck(m_bShowFilename);
1993 void CTortoiseGitBlameView::OnViewToggleShowOriginalLineNumber()
1995 m_bShowOriginalLineNumber = ! m_bShowOriginalLineNumber;
1997 theApp.WriteInt(_T("ShowOriginalLineNumber"), m_bShowOriginalLineNumber);
1999 CRect rect;
2000 this->GetClientRect(&rect);
2001 rect.left = GetBlameWidth();
2003 m_TextView.MoveWindow(&rect);
2006 void CTortoiseGitBlameView::OnUpdateViewToggleShowOriginalLineNumber(CCmdUI *pCmdUI)
2008 pCmdUI->SetCheck(m_bShowOriginalLineNumber);
2011 void CTortoiseGitBlameView::OnViewDetectMovedOrCopiedLines(DWORD dwDetectMovedOrCopiedLines)
2013 m_dwDetectMovedOrCopiedLines = dwDetectMovedOrCopiedLines;
2015 theApp.DoWaitCursor(1);
2017 theApp.WriteInt(_T("DetectMovedOrCopiedLines"), m_dwDetectMovedOrCopiedLines);
2019 CTortoiseGitBlameDoc *document = (CTortoiseGitBlameDoc *) m_pDocument;
2020 if (!document->m_CurrentFileName.IsEmpty())
2022 document->m_lLine = (int)SendEditor(SCI_GETFIRSTVISIBLELINE) + 1;
2023 theApp.m_pDocManager->OnFileNew();
2024 document->OnOpenDocument(document->m_CurrentFileName, document->m_Rev);
2026 theApp.DoWaitCursor(-1);
2029 void CTortoiseGitBlameView::OnViewDetectMovedOrCopiedLinesToggleDisabled()
2031 OnViewDetectMovedOrCopiedLines(BLAME_DETECT_MOVED_OR_COPIED_LINES_DISABLED);
2034 void CTortoiseGitBlameView::OnUpdateViewDetectMovedOrCopiedLinesToggleDisabled(CCmdUI *pCmdUI)
2036 pCmdUI->SetRadio(m_dwDetectMovedOrCopiedLines == BLAME_DETECT_MOVED_OR_COPIED_LINES_DISABLED);
2039 void CTortoiseGitBlameView::OnViewDetectMovedOrCopiedLinesToggleWithinFile()
2041 OnViewDetectMovedOrCopiedLines(BLAME_DETECT_MOVED_OR_COPIED_LINES_WITHIN_FILE);
2044 void CTortoiseGitBlameView::OnUpdateViewDetectMovedOrCopiedLinesToggleWithinFile(CCmdUI *pCmdUI)
2046 pCmdUI->SetRadio(m_dwDetectMovedOrCopiedLines == BLAME_DETECT_MOVED_OR_COPIED_LINES_WITHIN_FILE);
2049 void CTortoiseGitBlameView::OnViewDetectMovedOrCopiedLinesToggleFromModifiedFiles()
2051 OnViewDetectMovedOrCopiedLines(BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_MODIFIED_FILES);
2054 void CTortoiseGitBlameView::OnUpdateViewDetectMovedOrCopiedLinesToggleFromModifiedFiles(CCmdUI *pCmdUI)
2056 pCmdUI->SetRadio(m_dwDetectMovedOrCopiedLines == BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_MODIFIED_FILES);
2059 void CTortoiseGitBlameView::OnViewDetectMovedOrCopiedLinesToggleFromExistingFilesAtFileCreation()
2061 OnViewDetectMovedOrCopiedLines(BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES_AT_FILE_CREATION);
2064 void CTortoiseGitBlameView::OnUpdateViewDetectMovedOrCopiedLinesToggleFromExistingFilesAtFileCreation(CCmdUI *pCmdUI)
2066 pCmdUI->SetRadio(m_dwDetectMovedOrCopiedLines == BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES_AT_FILE_CREATION);
2069 void CTortoiseGitBlameView::OnViewDetectMovedOrCopiedLinesToggleFromExistingFiles()
2071 OnViewDetectMovedOrCopiedLines(BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES);
2074 void CTortoiseGitBlameView::OnUpdateViewDetectMovedOrCopiedLinesToggleFromExistingFiles(CCmdUI *pCmdUI)
2076 pCmdUI->SetRadio(m_dwDetectMovedOrCopiedLines == BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES);
2079 void CTortoiseGitBlameView::ReloadDocument()
2081 theApp.DoWaitCursor(1);
2082 CTortoiseGitBlameDoc *document = (CTortoiseGitBlameDoc *) m_pDocument;
2083 if (!document->m_CurrentFileName.IsEmpty())
2085 document->m_lLine = (int)SendEditor(SCI_GETFIRSTVISIBLELINE) + 1;
2086 theApp.m_pDocManager->OnFileNew();
2087 document->OnOpenDocument(document->m_CurrentFileName, document->m_Rev);
2089 theApp.DoWaitCursor(-1);
2092 void CTortoiseGitBlameView::OnViewToggleIgnoreWhitespace()
2094 m_bIgnoreWhitespace = ! m_bIgnoreWhitespace;
2096 theApp.WriteInt(_T("IgnoreWhitespace"), m_bIgnoreWhitespace ? 1 : 0);
2098 ReloadDocument();
2101 void CTortoiseGitBlameView::OnUpdateViewToggleIgnoreWhitespace(CCmdUI *pCmdUI)
2103 pCmdUI->SetCheck(m_bIgnoreWhitespace);
2106 void CTortoiseGitBlameView::OnViewToggleShowCompleteLog()
2108 m_bShowCompleteLog = ! m_bShowCompleteLog;
2110 theApp.WriteInt(_T("ShowCompleteLog"), m_bShowCompleteLog ? 1 : 0);
2112 ReloadDocument();
2115 void CTortoiseGitBlameView::OnUpdateViewToggleShowCompleteLog(CCmdUI *pCmdUI)
2117 pCmdUI->Enable(BlameIsLimitedToOneFilename(m_dwDetectMovedOrCopiedLines));
2118 pCmdUI->SetCheck(m_bShowCompleteLog && BlameIsLimitedToOneFilename(m_dwDetectMovedOrCopiedLines));
2121 void CTortoiseGitBlameView::OnViewToggleFollowRenames()
2123 m_bFollowRenames = ! m_bFollowRenames;
2125 theApp.WriteInt(_T("FollowRenames"), m_bFollowRenames ? 1 : 0);
2127 ReloadDocument();
2130 void CTortoiseGitBlameView::OnUpdateViewToggleFollowRenames(CCmdUI *pCmdUI)
2132 pCmdUI->Enable(m_bShowCompleteLog && BlameIsLimitedToOneFilename(m_dwDetectMovedOrCopiedLines));
2133 pCmdUI->SetCheck(m_bFollowRenames && m_bShowCompleteLog && BlameIsLimitedToOneFilename(m_dwDetectMovedOrCopiedLines));
2136 void CTortoiseGitBlameView::OnViewToggleColorByAge()
2138 m_colorage = ! m_colorage;
2140 theApp.WriteInt(_T("ColorAge"), m_colorage);
2142 m_TextView.Invalidate();
2145 void CTortoiseGitBlameView::OnUpdateViewToggleColorByAge(CCmdUI *pCmdUI)
2147 pCmdUI->SetCheck(m_colorage);
2150 void CTortoiseGitBlameView::OnUpdateViewCopyToClipboard(CCmdUI *pCmdUI)
2152 CWnd * wnd = GetFocus();
2153 if (wnd == GetLogList())
2155 pCmdUI->Enable(GetLogList()->GetSelectedCount() > 0);
2157 else if (wnd)
2159 if (CString(wnd->GetRuntimeClass()->m_lpszClassName) == _T("CMFCPropertyGridCtrl"))
2161 CMFCPropertyGridCtrl *grid = (CMFCPropertyGridCtrl *)wnd;
2162 pCmdUI->Enable(grid->GetCurSel() && !grid->GetCurSel()->IsGroup() && !CString(grid->GetCurSel()->GetValue()).IsEmpty());
2164 else
2165 pCmdUI->Enable(m_TextView.Call(SCI_GETSELECTIONSTART) != m_TextView.Call(SCI_GETSELECTIONEND));
2167 else
2168 pCmdUI->Enable(FALSE);