Improve error handling in GitRev
[TortoiseGit.git] / src / TortoiseGitBlame / TortoiseGitBlameView.cpp
blob2a89da6e1d1cc371982c7ef4706178e66d04bc99
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 m_wEditor = 0;
127 wLocator = 0;
129 m_font = 0;
130 m_italicfont = 0;
131 m_blamewidth = 0;
132 m_revwidth = 0;
133 m_datewidth = 0;
134 m_authorwidth = 0;
135 m_filenameWidth = 0;
136 m_originalLineNumberWidth = 0;
137 m_linewidth = 0;
139 m_windowcolor = ::GetSysColor(COLOR_WINDOW);
140 m_textcolor = ::GetSysColor(COLOR_WINDOWTEXT);
141 m_texthighlightcolor = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
142 m_mouserevcolor = InterColor(m_windowcolor, m_textcolor, 20);
143 m_mouseauthorcolor = InterColor(m_windowcolor, m_textcolor, 10);
144 m_selectedrevcolor = ::GetSysColor(COLOR_HIGHLIGHT);
145 m_selectedauthorcolor = InterColor(m_selectedrevcolor, m_texthighlightcolor, 35);
147 m_SelectedLine = -1;
148 m_directPointer = 0;
149 m_directFunction = 0;
151 m_colorage = !!theApp.GetInt(_T("ColorAge"));
153 m_bShowLine=true;
155 m_bShowAuthor = (theApp.GetInt(_T("ShowAuthor"), 1) == 1);
156 m_bShowDate = (theApp.GetInt(_T("ShowDate"), 0) == 1);
157 m_bShowFilename = (theApp.GetInt(_T("ShowFilename"), 0) == 1);
158 m_bShowOriginalLineNumber = (theApp.GetInt(_T("ShowOriginalLineNumber"), 0) == 1);
159 m_dwDetectMovedOrCopiedLines = theApp.GetInt(_T("DetectMovedOrCopiedLines"), 0);
160 m_bIgnoreWhitespace = (theApp.GetInt(_T("IgnoreWhitespace"), 0) == 1);
161 m_bShowCompleteLog = (theApp.GetInt(_T("ShowCompleteLog"), 1) == 1);
162 m_bFollowRenames = (theApp.GetInt(_T("FollowRenames"), 0) == 1);
163 m_bBlameOuputContainsOtherFilenames = FALSE;
165 m_FindDialogMessage = ::RegisterWindowMessage(FINDMSGSTRING);
166 m_pFindDialog = NULL;
167 // get short/long datetime setting from registry
168 DWORD RegUseShortDateFormat = CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE);
169 if ( RegUseShortDateFormat )
171 m_DateFormat = DATE_SHORTDATE;
173 else
175 m_DateFormat = DATE_LONGDATE;
177 // get relative time display setting from registry
178 DWORD regRelativeTimes = CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE);
179 m_bRelativeTimes = (regRelativeTimes != 0);
181 m_sRev.LoadString(IDS_LOG_REVISION);
182 m_sFileName.LoadString(IDS_FILENAME);
183 m_sAuthor.LoadString(IDS_LOG_AUTHOR);
184 m_sDate.LoadString(IDS_LOG_DATE);
185 m_sMessage.LoadString(IDS_LOG_MESSAGE);
187 #ifdef USE_TEMPFILENAME
188 m_Buffer = NULL;
189 #endif
192 CTortoiseGitBlameView::~CTortoiseGitBlameView()
194 if (m_font)
195 DeleteObject(m_font);
196 if (m_italicfont)
197 DeleteObject(m_italicfont);
199 #ifdef USE_TEMPFILENAME
200 if(m_Buffer)
202 delete m_Buffer;
203 m_Buffer=NULL;
205 #endif
207 struct EncodingUnit
209 int id;
210 char *name;
213 static EncodingUnit encodings[] = {
214 {1250, "windows-1250"}, //IDM_FORMAT_WIN_1250
215 {1251, "windows-1251"}, //IDM_FORMAT_WIN_1251
216 {1252, "windows-1252"}, //IDM_FORMAT_WIN_1252
217 {1253, "windows-1253"}, //IDM_FORMAT_WIN_1253
218 {1254, "windows-1254"}, //IDM_FORMAT_WIN_1254
219 {1255, "windows-1255"}, //IDM_FORMAT_WIN_1255
220 {1256, "windows-1256"}, //IDM_FORMAT_WIN_1256
221 {1257, "windows-1257"}, //IDM_FORMAT_WIN_1257
222 {1258, "windows-1258"}, //IDM_FORMAT_WIN_1258
223 {28591, "latin1 ISO_8859-1 ISO-8859-1 CP819 IBM819 csISOLatin1 iso-ir-100 l1"}, //IDM_FORMAT_ISO_8859_1
224 {28592, "latin2 ISO_8859-2 ISO-8859-2 csISOLatin2 iso-ir-101 l2"}, //IDM_FORMAT_ISO_8859_2
225 {28593, "latin3 ISO_8859-3 ISO-8859-3 csISOLatin3 iso-ir-109 l3"}, //IDM_FORMAT_ISO_8859_3
226 {28594, "latin4 ISO_8859-4 ISO-8859-4 csISOLatin4 iso-ir-110 l4"}, //IDM_FORMAT_ISO_8859_4
227 {28595, "cyrillic ISO_8859-5 ISO-8859-5 csISOLatinCyrillic iso-ir-144"}, //IDM_FORMAT_ISO_8859_5
228 {28596, "arabic ISO_8859-6 ISO-8859-6 csISOLatinArabic iso-ir-127 ASMO-708 ECMA-114"}, //IDM_FORMAT_ISO_8859_6
229 {28597, "greek ISO_8859-7 ISO-8859-7 csISOLatinGreek greek8 iso-ir-126 ELOT_928 ECMA-118"}, //IDM_FORMAT_ISO_8859_7
230 {28598, "hebrew ISO_8859-8 ISO-8859-8 csISOLatinHebrew iso-ir-138"}, //IDM_FORMAT_ISO_8859_8
231 {28599, "latin5 ISO_8859-9 ISO-8859-9 csISOLatin5 iso-ir-148 l5"}, //IDM_FORMAT_ISO_8859_9
232 {28600, "latin6 ISO_8859-10 ISO-8859-10 csISOLatin6 iso-ir-157 l6"}, //IDM_FORMAT_ISO_8859_10
233 {28601, "ISO_8859-11 ISO-8859-11"}, //IDM_FORMAT_ISO_8859_11
234 {28603, "ISO_8859-13 ISO-8859-13"}, //IDM_FORMAT_ISO_8859_13
235 {28604, "iso-celtic latin8 ISO_8859-14 ISO-8859-14 18 iso-ir-199"}, //IDM_FORMAT_ISO_8859_14
236 {28605, "Latin-9 ISO_8859-15 ISO-8859-15"}, //IDM_FORMAT_ISO_8859_15
237 {28606, "latin10 ISO_8859-16 ISO-8859-16 110 iso-ir-226"}, //IDM_FORMAT_ISO_8859_16
238 {437, "IBM437 cp437 437 csPC8CodePage437"}, //IDM_FORMAT_DOS_437
239 {720, "IBM720 cp720 oem720 720"}, //IDM_FORMAT_DOS_720
240 {737, "IBM737 cp737 oem737 737"}, //IDM_FORMAT_DOS_737
241 {775, "IBM775 cp775 oem775 775"}, //IDM_FORMAT_DOS_775
242 {850, "IBM850 cp850 oem850 850"}, //IDM_FORMAT_DOS_850
243 {852, "IBM852 cp852 oem852 852"}, //IDM_FORMAT_DOS_852
244 {855, "IBM855 cp855 oem855 855 csIBM855"}, //IDM_FORMAT_DOS_855
245 {857, "IBM857 cp857 oem857 857"}, //IDM_FORMAT_DOS_857
246 {858, "IBM858 cp858 oem858 858"}, //IDM_FORMAT_DOS_858
247 {860, "IBM860 cp860 oem860 860"}, //IDM_FORMAT_DOS_860
248 {861, "IBM861 cp861 oem861 861"}, //IDM_FORMAT_DOS_861
249 {862, "IBM862 cp862 oem862 862"}, //IDM_FORMAT_DOS_862
250 {863, "IBM863 cp863 oem863 863"}, //IDM_FORMAT_DOS_863
251 {865, "IBM865 cp865 oem865 865"}, //IDM_FORMAT_DOS_865
252 {866, "IBM866 cp866 oem866 866"}, //IDM_FORMAT_DOS_866
253 {869, "IBM869 cp869 oem869 869"}, //IDM_FORMAT_DOS_869
254 {950, "big5 csBig5"}, //IDM_FORMAT_BIG5
255 {936, "gb2312 gbk csGB2312"}, //IDM_FORMAT_GB2312
256 {932, "Shift_JIS MS_Kanji csShiftJIS csWindows31J"}, //IDM_FORMAT_SHIFT_JIS
257 {949, "windows-949 korean"}, //IDM_FORMAT_KOREAN_WIN
258 {51949, "euc-kr csEUCKR"}, //IDM_FORMAT_EUC_KR
259 {874, "tis-620"}, //IDM_FORMAT_TIS_620
260 {10007, "x-mac-cyrillic xmaccyrillic"}, //IDM_FORMAT_MAC_CYRILLIC
261 {21866, "koi8_u"}, //IDM_FORMAT_KOI8U_CYRILLIC
262 {20866, "koi8_r csKOI8R"}, //IDM_FORMAT_KOI8R_CYRILLIC
263 {65001, "UTF-8"}, //IDM_FORMAT_UTF8
264 {1200, "UTF-16 LE"}, //IDM_FORMAT_UTF16LE
265 {1201, "UTF-16 BE"}, //IDM_FORMAT_UTF16BE
267 void CTortoiseGitBlameView::OnChangeEncode(UINT nId)
269 if(nId >= IDM_FORMAT_ENCODE && nId <= IDM_FORMAT_ENCODE_END)
270 this->UpdateInfo(encodings[nId - IDM_FORMAT_ENCODE].id);
272 int CTortoiseGitBlameView::OnCreate(LPCREATESTRUCT lpcs)
275 CRect rect,rect1;
276 this->GetWindowRect(&rect1);
277 rect.left=m_blamewidth+LOCATOR_WIDTH;
278 rect.right=rect.Width();
279 rect.top=0;
280 rect.bottom=rect.Height();
281 if (!m_TextView.Create(_T("Scintilla"), _T("source"), 0, rect, this, IDC_SCINTILLA, 0))
283 TRACE0("Failed to create view\n");
284 return -1; // fail to create
286 m_TextView.Init(0,FALSE);
287 m_TextView.ShowWindow( SW_SHOW);
288 m_wEditor = m_TextView.m_hWnd;
289 CreateFont();
290 InitialiseEditor();
291 m_ToolTip.Create(this->GetParent());
293 ::AfxGetApp()->GetMainWnd();
294 return CView::OnCreate(lpcs);
298 void CTortoiseGitBlameView::OnSize(UINT /*nType*/, int cx, int cy)
301 CRect rect;
302 rect.left=m_blamewidth;
303 rect.right=cx;
304 rect.top=0;
305 rect.bottom=cy;
307 m_TextView.MoveWindow(&rect);
310 BOOL CTortoiseGitBlameView::PreCreateWindow(CREATESTRUCT& cs)
312 return CView::PreCreateWindow(cs);
315 // CTortoiseGitBlameView drawing
317 void CTortoiseGitBlameView::OnDraw(CDC* /*pDC*/)
319 CTortoiseGitBlameDoc* pDoc = GetDocument();
320 ASSERT_VALID(pDoc);
321 if (!pDoc)
322 return;
324 DrawBlame(this->GetDC()->m_hDC);
325 DrawLocatorBar(this->GetDC()->m_hDC);
326 // TODO: add draw code for native data here
330 // CTortoiseGitBlameView printing
333 void CTortoiseGitBlameView::OnFilePrintPreview()
335 AFXPrintPreview(this);
338 BOOL CTortoiseGitBlameView::OnPreparePrinting(CPrintInfo* pInfo)
340 // default preparation
341 return DoPreparePrinting(pInfo);
344 void CTortoiseGitBlameView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
346 // TODO: add extra initialization before printing
349 void CTortoiseGitBlameView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
351 // TODO: add cleanup after printing
354 void CTortoiseGitBlameView::OnRButtonUp(UINT /*nFlags*/, CPoint point)
356 int line = (int)SendEditor(SCI_GETFIRSTVISIBLELINE);
357 int height = (int)SendEditor(SCI_TEXTHEIGHT);
358 line = line + (int)(point.y / height);
359 if (m_data.IsValidLine(line))
361 m_MouseLine = line;
362 ClientToScreen(&point);
364 CGitHash hash = m_data.GetHash(line);
365 CString hashStr = hash.ToString();
367 GitRevLoglist* pRev = nullptr;
368 int logIndex = m_lineToLogIndex[line];
369 if (logIndex >= 0)
370 pRev = &GetLogData()->GetGitRevAt(logIndex);
371 else
373 pRev = m_data.GetRev(line, GetLogData()->m_pLogCache->m_HashMap);
374 if (pRev && pRev->m_ParentHash.empty())
376 if (pRev->GetParentFromHash(pRev->m_CommitHash))
377 MessageBox(pRev->GetLastErr(), _T("TortoiseGit"), MB_ICONERROR);
381 if (!pRev)
382 return;
384 CIconMenu popup;
385 CIconMenu blamemenu, diffmenu;
387 if (!popup.CreatePopupMenu())
388 return;
390 // Now find the relevant parent commits, they must contain the file which is blamed to be the source of the selected line,
391 // otherwise there is no previous file to compare to (only another previous revision).
393 GIT_REV_LIST parentHashWithFile;
394 std::vector<CString> parentFilename;
397 CTGitPath path(m_data.GetFilename(line));
398 const CTGitPathList & files = pRev->GetFiles(NULL);
399 for (int j = 0, j_size = files.GetCount(); j < j_size; ++j)
401 const CTGitPath &file = files[j];
402 if (file.IsEquivalentTo(path))
404 if (!(file.m_ParentNo & MERGE_MASK))
406 int action = file.m_Action;
407 // ignore (action & CTGitPath::LOGACTIONS_ADDED), as then there is nothing to blame/diff
408 // ignore (action & CTGitPath::LOGACTIONS_DELETED), should never happen as the file must exist
409 if (action & (CTGitPath::LOGACTIONS_MODIFIED | CTGitPath::LOGACTIONS_REPLACED))
411 int parentNo = file.m_ParentNo & PARENT_MASK;
412 if (parentNo >= 0 && (size_t)parentNo < pRev->m_ParentHash.size())
414 parentHashWithFile.push_back(pRev->m_ParentHash[parentNo]);
415 parentFilename.push_back((action & CTGitPath::LOGACTIONS_REPLACED) ? file.GetGitOldPathString() : file.GetGitPathString());
422 catch (const char* msg)
424 MessageBox(_T("Could not get files of parents.\nlibgit reports:\n") + CString(msg), _T("TortoiseGit"), MB_ICONERROR);
427 // blame previous
428 if (!parentHashWithFile.empty())
430 if (parentHashWithFile.size() == 1)
432 popup.AppendMenuIcon(ID_BLAMEPREVIOUS, IDS_BLAME_POPUP_BLAME, IDI_BLAME_POPUP_BLAME);
434 else
436 blamemenu.CreatePopupMenu();
437 popup.AppendMenuIcon(ID_BLAMEPREVIOUS, IDS_BLAME_POPUP_BLAME, IDI_BLAME_POPUP_BLAME, blamemenu.m_hMenu);
439 for (size_t i = 0; i < parentHashWithFile.size(); ++i)
441 CString str;
442 str.Format(IDS_PARENT, i + 1);
443 blamemenu.AppendMenuIcon(ID_BLAMEPREVIOUS + ((i + 1) << 16), str);
448 // compare with previous
449 if (!parentHashWithFile.empty())
451 if (parentHashWithFile.size() == 1)
453 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_BLAME_POPUP_COMPARE, IDI_BLAME_POPUP_COMPARE);
454 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
455 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
457 else
459 diffmenu.CreatePopupMenu();
460 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_BLAME_POPUP_COMPARE, IDI_BLAME_POPUP_COMPARE, diffmenu.m_hMenu);
461 for (size_t i = 0; i < parentHashWithFile.size(); ++i)
463 CString str;
464 str.Format(IDS_BLAME_POPUP_PARENT, i + 1);
465 diffmenu.AppendMenuIcon((UINT)(ID_COMPAREWITHPREVIOUS + ((i + 1) << 16)),str);
466 if (i == 0 && CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
468 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
469 diffmenu.SetDefaultItem((UINT)(ID_COMPAREWITHPREVIOUS + ((i + 1) << 16)), FALSE);
475 popup.AppendMenuIcon(ID_SHOWLOG, IDS_BLAME_POPUP_LOG, IDI_BLAME_POPUP_LOG);
476 popup.AppendMenu(MF_SEPARATOR, NULL);
477 popup.AppendMenuIcon(ID_COPYHASHTOCLIPBOARD, IDS_BLAME_POPUP_COPYHASHTOCLIPBOARD, IDI_BLAME_POPUP_COPY);
478 popup.AppendMenuIcon(ID_COPYLOGTOCLIPBOARD, IDS_BLAME_POPUP_COPYLOGTOCLIPBOARD, IDI_BLAME_POPUP_COPY);
480 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
481 this->ContextMenuAction(cmd, pRev, parentHashWithFile, parentFilename);
485 void CTortoiseGitBlameView::ContextMenuAction(int cmd, GitRev *pRev, GIT_REV_LIST& parentHashWithFile, const std::vector<CString>& parentFilename)
487 switch (cmd & 0xFFFF)
489 case ID_BLAMEPREVIOUS:
491 int index = (cmd>>16) & 0xFFFF;
492 if (index > 0)
493 index -= 1;
495 CString path = ResolveCommitFile(parentFilename[index]);
496 CString endrev = parentHashWithFile[index].ToString();
497 int line = m_data.GetOriginalLineNumber(m_MouseLine);
498 CString lineNumber;
499 lineNumber.Format(_T("%d"), line);
501 CString procCmd = _T("/path:\"") + path + _T("\" ");
502 procCmd += _T(" /command:blame");
503 procCmd += _T(" /endrev:") + endrev;
504 procCmd += _T(" /line:") + lineNumber;
506 CCommonAppUtils::RunTortoiseGitProc(procCmd);
508 break;
510 case ID_COMPAREWITHPREVIOUS:
512 int index = (cmd >> 16) & 0xFFFF;
513 if (index > 0)
514 index -= 1;
516 CString path = ResolveCommitFile(parentFilename[index]);
517 CString startrev = pRev->m_CommitHash.ToString();
518 CString endrev = parentHashWithFile[index].ToString();
520 CString procCmd = _T("/path:\"") + path + _T("\" ");
521 procCmd += _T(" /command:diff");
522 procCmd += _T(" /startrev:") + startrev;
523 procCmd += _T(" /endrev:") + endrev;
525 CCommonAppUtils::RunTortoiseGitProc(procCmd);
527 break;
529 case ID_SHOWLOG:
531 CString path = ResolveCommitFile(m_MouseLine);
532 CString rev = m_data.GetHash(m_MouseLine).ToString();
534 CString procCmd = _T("/path:\"") + path + _T("\" ");
535 procCmd += _T(" /command:log");
536 procCmd += _T(" /rev:") + rev;
538 CCommonAppUtils::RunTortoiseGitProc(procCmd);
540 break;
542 case ID_COPYHASHTOCLIPBOARD:
543 this->GetLogList()->CopySelectionToClipBoard(CGitLogListBase::ID_COPY_HASH);
544 break;
546 case ID_COPYLOGTOCLIPBOARD:
547 this->GetLogList()->CopySelectionToClipBoard();
548 break;
552 // CTortoiseGitBlameView diagnostics
554 #ifdef _DEBUG
555 void CTortoiseGitBlameView::AssertValid() const
557 CView::AssertValid();
560 void CTortoiseGitBlameView::Dump(CDumpContext& dc) const
562 CView::Dump(dc);
565 CTortoiseGitBlameDoc* CTortoiseGitBlameView::GetDocument() const // non-debug version is inline
567 ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTortoiseGitBlameDoc)));
568 return (CTortoiseGitBlameDoc*)m_pDocument;
570 #endif //_DEBUG
573 // CTortoiseGitBlameView message handlers
574 CString CTortoiseGitBlameView::GetAppDirectory()
576 CString path;
577 DWORD len = 0;
578 DWORD bufferlen = MAX_PATH; // MAX_PATH is not the limit here!
581 bufferlen += MAX_PATH; // MAX_PATH is not the limit here!
582 std::unique_ptr<TCHAR[]> pBuf(new TCHAR[bufferlen]);
583 len = GetModuleFileName(NULL, pBuf.get(), bufferlen);
584 path = CString(pBuf.get(), len);
585 } while(len == bufferlen);
587 path = path.Left(path.ReverseFind(_T('\\')));
588 //path = path.substr(0, path.rfind('\\') + 1);
590 return path;
593 // Return a color which is interpolated between c1 and c2.
594 // Slider controls the relative proportions as a percentage:
595 // Slider = 0 represents pure c1
596 // Slider = 50 represents equal mixture
597 // Slider = 100 represents pure c2
598 COLORREF CTortoiseGitBlameView::InterColor(COLORREF c1, COLORREF c2, int Slider)
600 int r, g, b;
602 // Limit Slider to 0..100% range
603 if (Slider < 0)
604 Slider = 0;
605 if (Slider > 100)
606 Slider = 100;
608 // The color components have to be treated individually.
609 r = (GetRValue(c2) * Slider + GetRValue(c1) * (100 - Slider)) / 100;
610 g = (GetGValue(c2) * Slider + GetGValue(c1) * (100 - Slider)) / 100;
611 b = (GetBValue(c2) * Slider + GetBValue(c1) * (100 - Slider)) / 100;
613 return RGB(r, g, b);
616 LRESULT CTortoiseGitBlameView::SendEditor(UINT Msg, WPARAM wParam, LPARAM lParam)
618 if (m_directFunction)
620 return ((SciFnDirect) m_directFunction)(m_directPointer, Msg, wParam, lParam);
622 return ::SendMessage(m_wEditor, Msg, wParam, lParam);
625 void CTortoiseGitBlameView::SetAStyle(int style, COLORREF fore, COLORREF back, int size, const char *face)
627 SendEditor(SCI_STYLESETFORE, style, fore);
628 SendEditor(SCI_STYLESETBACK, style, back);
629 if (size >= 1)
630 SendEditor(SCI_STYLESETSIZE, style, size);
631 if (face)
632 SendEditor(SCI_STYLESETFONT, style, reinterpret_cast<LPARAM>(face));
635 void CTortoiseGitBlameView::InitialiseEditor()
638 m_directFunction = ::SendMessage(m_wEditor, SCI_GETDIRECTFUNCTION, 0, 0);
639 m_directPointer = ::SendMessage(m_wEditor, SCI_GETDIRECTPOINTER, 0, 0);
640 // Set up the global default style. These attributes are used wherever no explicit choices are made.
641 std::string fontName = CUnicodeUtils::StdGetUTF8((stdstring)CRegStdString(_T("Software\\TortoiseGit\\BlameFontName"), _T("Courier New")));
642 SetAStyle(STYLE_DEFAULT,
643 black,
644 white,
645 (DWORD)CRegStdDWORD(_T("Software\\TortoiseGit\\BlameFontSize"), 10),
646 fontName.c_str()
648 SendEditor(SCI_SETTABWIDTH, (DWORD)CRegStdDWORD(_T("Software\\TortoiseGit\\BlameTabSize"), 4));
649 SendEditor(SCI_SETREADONLY, TRUE);
650 LRESULT pix = SendEditor(SCI_TEXTWIDTH, STYLE_LINENUMBER, (LPARAM)this->m_TextView.StringForControl(_T("_99999")).GetBuffer());
651 if (m_bShowLine)
652 SendEditor(SCI_SETMARGINWIDTHN, 0, pix);
653 else
654 SendEditor(SCI_SETMARGINWIDTHN, 0);
655 SendEditor(SCI_SETMARGINWIDTHN, 1);
656 SendEditor(SCI_SETMARGINWIDTHN, 2);
657 //Set the default windows colors for edit controls
658 SendEditor(SCI_STYLESETFORE, STYLE_DEFAULT, ::GetSysColor(COLOR_WINDOWTEXT));
659 SendEditor(SCI_STYLESETBACK, STYLE_DEFAULT, ::GetSysColor(COLOR_WINDOW));
660 SendEditor(SCI_SETSELFORE, TRUE, ::GetSysColor(COLOR_HIGHLIGHTTEXT));
661 SendEditor(SCI_SETSELBACK, TRUE, ::GetSysColor(COLOR_HIGHLIGHT));
662 SendEditor(SCI_SETCARETFORE, ::GetSysColor(COLOR_WINDOWTEXT));
663 m_regOldLinesColor = CRegStdDWORD(_T("Software\\TortoiseGit\\BlameOldColor"), BLAMEOLDCOLOR);
664 m_regNewLinesColor = CRegStdDWORD(_T("Software\\TortoiseGit\\BlameNewColor"), BLAMENEWCOLOR);
665 CRegStdDWORD used2d(L"Software\\TortoiseGit\\ScintillaDirect2D", FALSE);
666 if (SysInfo::Instance().IsWin7OrLater() && DWORD(used2d))
668 SendEditor(SCI_SETTECHNOLOGY, SC_TECHNOLOGY_DIRECTWRITERETAIN);
669 SendEditor(SCI_SETBUFFEREDDRAW, 0);
672 this->m_TextView.Call(SCI_SETWRAPMODE, SC_WRAP_NONE);
676 bool CTortoiseGitBlameView::DoSearch(CTortoiseGitBlameData::SearchDirection direction)
678 int pos = (int)SendEditor(SCI_GETCURRENTPOS);
679 int line = (int)SendEditor(SCI_LINEFROMPOSITION, pos);
681 int i = m_data.FindFirstLineWrapAround(direction, m_sFindText, line, m_bMatchCase);
682 if (i >= 0)
684 GotoLine(i + 1);
685 int selstart = (int)SendEditor(SCI_GETCURRENTPOS);
686 int selend = (int)SendEditor(SCI_POSITIONFROMLINE, i + 1);
687 SendEditor(SCI_SETSELECTIONSTART, selstart);
688 SendEditor(SCI_SETSELECTIONEND, selend);
689 m_SelectedLine = i;
691 else
693 ::MessageBox(m_pFindDialog && m_pFindDialog->GetSafeHwnd() ? m_pFindDialog->GetSafeHwnd() : wMain, _T("\"") + m_sFindText + _T("\" ") + CString(MAKEINTRESOURCE(IDS_NOTFOUND)), _T("TortoiseGitBlame"), MB_ICONINFORMATION);
696 return true;
699 void CTortoiseGitBlameView::OnFindPrev()
701 if (m_sFindText.IsEmpty())
702 return;
703 DoSearch(CTortoiseGitBlameData::SearchPrevious);
706 void CTortoiseGitBlameView::OnFindNext()
708 if (m_sFindText.IsEmpty())
709 return;
710 DoSearch(CTortoiseGitBlameData::SearchNext);
713 bool CTortoiseGitBlameView::GotoLine(int line)
715 --line;
716 int numberOfLines = m_data.GetNumberOfLines();
717 if (line < 0 || numberOfLines == 0)
718 return false;
719 if (line >= numberOfLines)
721 line = numberOfLines - 1;
724 int nCurrentPos = (int)SendEditor(SCI_GETCURRENTPOS);
725 int nCurrentLine = (int)SendEditor(SCI_LINEFROMPOSITION,nCurrentPos);
726 int nFirstVisibleLine = (int)SendEditor(SCI_GETFIRSTVISIBLELINE);
727 int nLinesOnScreen = (int)SendEditor(SCI_LINESONSCREEN);
729 if ( line>=nFirstVisibleLine && line<=nFirstVisibleLine+nLinesOnScreen)
731 // no need to scroll
732 SendEditor(SCI_GOTOLINE, line);
734 else
736 // Place the requested line one third from the top
737 if ( line > nCurrentLine )
739 SendEditor(SCI_GOTOLINE, (WPARAM)(line+(int)nLinesOnScreen*(2/3.0)));
741 else
743 SendEditor(SCI_GOTOLINE, (WPARAM)(line-(int)nLinesOnScreen*(1/3.0)));
747 // Highlight the line
748 int nPosStart = (int)SendEditor(SCI_POSITIONFROMLINE,line);
749 int nPosEnd = (int)SendEditor(SCI_GETLINEENDPOSITION,line);
750 SendEditor(SCI_SETSEL,nPosEnd,nPosStart);
752 return true;
755 bool CTortoiseGitBlameView::ScrollToLine(long line)
757 if (line < 0)
758 return false;
760 int nCurrentLine = (int)SendEditor(SCI_GETFIRSTVISIBLELINE);
762 int scrolldelta = line - nCurrentLine;
763 SendEditor(SCI_LINESCROLL, 0, scrolldelta);
765 return true;
768 void CTortoiseGitBlameView::CopyToClipboard()
770 CWnd * wnd = GetFocus();
771 if (wnd == this->GetLogList())
772 GetLogList()->CopySelectionToClipBoard();
773 else if (wnd)
775 if (CString(wnd->GetRuntimeClass()->m_lpszClassName) == _T("CMFCPropertyGridCtrl"))
777 CMFCPropertyGridCtrl *grid = (CMFCPropertyGridCtrl *)wnd;
778 if (grid->GetCurSel() && !grid->GetCurSel()->IsGroup())
779 CStringUtils::WriteAsciiStringToClipboard(grid->GetCurSel()->GetValue(), GetSafeHwnd());
781 else
782 m_TextView.Call(SCI_COPY);
786 LONG CTortoiseGitBlameView::GetBlameWidth()
788 LONG blamewidth = 0;
789 SIZE width;
790 CreateFont();
791 HDC hDC = this->GetDC()->m_hDC;
792 HFONT oldfont = (HFONT)::SelectObject(hDC, m_font);
794 CString shortHash('f', g_Git.GetShortHASHLength() + 1);
795 ::GetTextExtentPoint32(hDC, shortHash, g_Git.GetShortHASHLength() + 1, &width);
796 m_revwidth = width.cx + BLAMESPACE;
797 blamewidth += m_revwidth;
799 if (m_bShowDate)
801 SIZE maxwidth = {0};
803 int numberOfLines = m_data.GetNumberOfLines();
804 for (int i = 0; i < numberOfLines; ++i)
806 ::GetTextExtentPoint32(hDC, m_data.GetDate(i), m_data.GetDate(i).GetLength(), &width);
807 if (width.cx > maxwidth.cx)
808 maxwidth = width;
810 m_datewidth = maxwidth.cx + BLAMESPACE;
811 blamewidth += m_datewidth;
813 if ( m_bShowAuthor)
815 SIZE maxwidth = {0};
817 int numberOfLines = m_data.GetNumberOfLines();
818 for (int i = 0; i < numberOfLines; ++i)
820 ::GetTextExtentPoint32(hDC,m_data.GetAuthor(i) , m_data.GetAuthor(i).GetLength(), &width);
821 if (width.cx > maxwidth.cx)
822 maxwidth = width;
824 m_authorwidth = maxwidth.cx + BLAMESPACE;
825 blamewidth += m_authorwidth;
827 if (m_bShowFilename)
829 SIZE maxwidth = {0};
831 int numberOfLines = m_data.GetNumberOfLines();
832 for (int i = 0; i < numberOfLines; ++i)
834 ::GetTextExtentPoint32(hDC, m_data.GetFilename(i), m_data.GetFilename(i).GetLength(), &width);
835 if (width.cx > maxwidth.cx)
836 maxwidth = width;
838 m_filenameWidth = maxwidth.cx + BLAMESPACE;
839 blamewidth += m_filenameWidth;
841 if (m_bShowOriginalLineNumber)
843 SIZE maxwidth = {0};
845 int numberOfLines = m_data.GetNumberOfLines();
846 CString str;
847 for (int i = 0; i < numberOfLines; ++i)
849 str.Format(_T("%5d"), m_data.GetOriginalLineNumber(i));
850 ::GetTextExtentPoint32(hDC, str, str.GetLength(), &width);
851 if (width.cx > maxwidth.cx)
852 maxwidth = width;
854 m_originalLineNumberWidth = maxwidth.cx + BLAMESPACE;
855 blamewidth += m_originalLineNumberWidth;
857 ::SelectObject(hDC, oldfont);
858 POINT pt = {blamewidth, 0};
859 LPtoDP(hDC, &pt, 1);
860 m_blamewidth = pt.x;
861 //::ReleaseDC(wBlame, hDC);
862 return blamewidth;
866 void CTortoiseGitBlameView::CreateFont()
868 if (m_font)
869 return;
870 LOGFONT lf = {0};
871 lf.lfWeight = 400;
872 HDC hDC = ::GetDC(wBlame);
873 lf.lfHeight = -MulDiv((DWORD)CRegStdDWORD(_T("Software\\TortoiseGit\\BlameFontSize"), 10), GetDeviceCaps(hDC, LOGPIXELSY), 72);
874 lf.lfCharSet = DEFAULT_CHARSET;
875 CRegStdString fontname = CRegStdString(_T("Software\\TortoiseGit\\BlameFontName"), _T("Courier New"));
876 _tcscpy_s(lf.lfFaceName, 32, ((stdstring)fontname).c_str());
877 m_font = ::CreateFontIndirect(&lf);
879 lf.lfItalic = TRUE;
880 m_italicfont = ::CreateFontIndirect(&lf);
882 ::ReleaseDC(wBlame, hDC);
885 void CTortoiseGitBlameView::DrawBlame(HDC hDC)
887 if (hDC == NULL)
888 return;
889 if (m_font == NULL)
890 return;
892 HFONT oldfont = NULL;
893 int line = (int)SendEditor(SCI_GETFIRSTVISIBLELINE);
894 int linesonscreen = (int)SendEditor(SCI_LINESONSCREEN);
895 int height = (int)SendEditor(SCI_TEXTHEIGHT);
896 int Y = 0;
897 TCHAR buf[MAX_PATH] = {0};
898 RECT rc;
899 BOOL sel = FALSE;
900 //::GetClientRect(this->m_hWnd, &rc);
901 for (int i = line; i < (line + linesonscreen); ++i)
903 sel = FALSE;
904 if (i < m_data.GetNumberOfLines())
906 CGitHash hash(m_data.GetHash(i));
907 // if (mergelines[i])
908 // oldfont = (HFONT)::SelectObject(hDC, m_italicfont);
909 // else
910 oldfont = (HFONT)::SelectObject(hDC, m_font);
911 ::SetBkColor(hDC, m_windowcolor);
912 ::SetTextColor(hDC, m_textcolor);
913 if (!hash.IsEmpty())
915 //if (m_CommitHash[i].Compare(m_MouseHash)==0)
916 // ::SetBkColor(hDC, m_mouseauthorcolor);
917 if (hash == m_SelectedHash)
919 ::SetBkColor(hDC, m_selectedauthorcolor);
920 ::SetTextColor(hDC, m_texthighlightcolor);
921 sel = TRUE;
925 if(m_MouseLine == i)
926 ::SetBkColor(hDC, m_mouserevcolor);
928 //if ((revs[i] == m_mouserev)&&(!sel))
929 // ::SetBkColor(hDC, m_mouserevcolor);
930 //if (revs[i] == m_selectedrev)
932 // ::SetBkColor(hDC, m_selectedrevcolor);
933 // ::SetTextColor(hDC, m_texthighlightcolor);
936 CString shortHashStr;
937 shortHashStr = hash.ToString().Left(g_Git.GetShortHASHLength());
939 //_stprintf_s(buf, MAX_PATH, _T("%8ld "), revs[i]);
940 rc.top = (LONG)Y;
941 rc.left=LOCATOR_WIDTH;
942 rc.bottom = (LONG)(Y + height);
943 rc.right = rc.left + m_blamewidth;
944 ::ExtTextOut(hDC, LOCATOR_WIDTH, Y, ETO_CLIPPED, &rc, shortHashStr, shortHashStr.GetLength(), 0);
945 int Left = m_revwidth;
947 if (m_bShowAuthor)
949 rc.right = rc.left + Left + m_authorwidth;
950 ::ExtTextOut(hDC, Left, Y, ETO_CLIPPED, &rc, m_data.GetAuthor(i), m_data.GetAuthor(i).GetLength(), 0);
951 Left += m_authorwidth;
953 if (m_bShowDate)
955 rc.right = rc.left + Left + m_datewidth;
956 ::ExtTextOut(hDC, Left, Y, ETO_CLIPPED, &rc, m_data.GetDate(i), m_data.GetDate(i).GetLength(), 0);
957 Left += m_datewidth;
959 if (m_bShowFilename)
961 rc.right = rc.left + Left + m_filenameWidth;
962 ::ExtTextOut(hDC, Left, (int)Y, ETO_CLIPPED, &rc, m_data.GetFilename(i), m_data.GetFilename(i).GetLength(), 0);
963 Left += m_filenameWidth;
965 if (m_bShowOriginalLineNumber)
967 rc.right = rc.left + Left + m_originalLineNumberWidth;
968 CString str;
969 str.Format(_T("%5d"), m_data.GetOriginalLineNumber(i));
970 ::ExtTextOut(hDC, Left, (int)Y, ETO_CLIPPED, &rc, str, str.GetLength(), 0);
971 Left += m_originalLineNumberWidth;
973 if ((i==m_SelectedLine)&&(m_pFindDialog))
975 LOGBRUSH brush;
976 brush.lbColor = m_textcolor;
977 brush.lbHatch = 0;
978 brush.lbStyle = BS_SOLID;
979 HPEN pen = ExtCreatePen(PS_SOLID | PS_GEOMETRIC, 2, &brush, 0, NULL);
980 HGDIOBJ hPenOld = SelectObject(hDC, pen);
981 RECT rc2 = rc;
982 rc2.top = (LONG)Y;
983 rc2.bottom = (LONG)(Y + height);
984 ::MoveToEx(hDC, rc2.left, rc2.top, NULL);
985 ::LineTo(hDC, rc2.right, rc2.top);
986 ::LineTo(hDC, rc2.right, rc2.bottom);
987 ::LineTo(hDC, rc2.left, rc2.bottom);
988 ::LineTo(hDC, rc2.left, rc2.top);
989 SelectObject(hDC, hPenOld);
990 DeleteObject(pen);
992 Y += height;
993 ::SelectObject(hDC, oldfont);
995 else
997 ::SetBkColor(hDC, m_windowcolor);
998 for (int j=0; j< MAX_PATH; ++j)
999 buf[j]=' ';
1000 ::ExtTextOut(hDC, 0, (int)Y, ETO_CLIPPED, &rc, buf, MAX_PATH-1, 0);
1001 Y += height;
1006 void CTortoiseGitBlameView::DrawLocatorBar(HDC hDC)
1008 if (hDC == NULL)
1009 return;
1011 int line = (int)SendEditor(SCI_GETFIRSTVISIBLELINE);
1012 int linesonscreen = (int)SendEditor(SCI_LINESONSCREEN);
1013 int Y = 0;
1014 COLORREF blackColor = GetSysColor(COLOR_WINDOWTEXT);
1016 RECT rc;
1017 //::GetClientRect(wLocator, &rc);
1018 this->GetClientRect(&rc);
1020 rc.right=LOCATOR_WIDTH;
1022 RECT lineRect = rc;
1023 LONG height = rc.bottom-rc.top;
1025 int numberOfLines = m_data.GetNumberOfLines();
1026 // draw the colored bar
1027 for (int currentLine = 0; currentLine<numberOfLines; ++currentLine)
1029 COLORREF cr = GetLineColor(currentLine);
1030 // get the line color
1031 if ((currentLine >= line)&&(currentLine < (line + linesonscreen)))
1033 cr = InterColor(cr, blackColor, 10);
1035 SetBkColor(hDC, cr);
1036 lineRect.top = (LONG)Y;
1037 lineRect.bottom = ((currentLine + 1) * height / numberOfLines);
1038 ::ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &lineRect, NULL, 0, NULL);
1039 Y = lineRect.bottom;
1042 if (numberOfLines > 0)
1044 // now draw two lines indicating the scroll position of the source view
1045 SetBkColor(hDC, blackColor);
1046 lineRect.top = (LONG)line * height / numberOfLines;
1047 lineRect.bottom = lineRect.top+1;
1048 ::ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &lineRect, NULL, 0, NULL);
1049 lineRect.top = (LONG)(line + linesonscreen) * height / numberOfLines;
1050 lineRect.bottom = lineRect.top+1;
1051 ::ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &lineRect, NULL, 0, NULL);
1056 void CTortoiseGitBlameView::StringExpand(LPSTR str) const
1058 char * cPos = str;
1061 cPos = strchr(cPos, '\n');
1062 if (cPos)
1064 memmove(cPos+1, cPos, strlen(cPos)*sizeof(char));
1065 *cPos = '\r';
1066 ++cPos;
1067 ++cPos;
1069 } while (cPos != NULL);
1071 void CTortoiseGitBlameView::StringExpand(LPWSTR str) const
1073 wchar_t * cPos = str;
1076 cPos = wcschr(cPos, '\n');
1077 if (cPos)
1079 memmove(cPos+1, cPos, wcslen(cPos)*sizeof(wchar_t));
1080 *cPos = '\r';
1081 ++cPos;
1082 ++cPos;
1084 } while (cPos != NULL);
1087 void CTortoiseGitBlameView::SetupLexer(CString filename)
1089 int start=filename.ReverseFind(_T('.'));
1090 if (start>0)
1092 //_tcscpy_s(line, 20, lineptr+1);
1093 //_tcslwr_s(line, 20);
1094 CString ext=filename.Right(filename.GetLength()-start-1);
1095 TCHAR * line = ext.GetBuffer();
1097 if ((_tcscmp(line, _T("py"))==0)||
1098 (_tcscmp(line, _T("pyw"))==0))
1100 SendEditor(SCI_SETLEXER, SCLEX_PYTHON);
1101 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("and assert break class continue def del elif \
1102 else except exec finally for from global if import in is lambda None \
1103 not or pass print raise return try while yield")).GetBuffer()));
1104 SetAStyle(SCE_P_DEFAULT, black);
1105 SetAStyle(SCE_P_COMMENTLINE, darkGreen);
1106 SetAStyle(SCE_P_NUMBER, RGB(0, 0x80, 0x80));
1107 SetAStyle(SCE_P_STRING, RGB(0, 0, 0x80));
1108 SetAStyle(SCE_P_CHARACTER, RGB(0, 0, 0x80));
1109 SetAStyle(SCE_P_WORD, RGB(0x80, 0, 0x80));
1110 SetAStyle(SCE_P_TRIPLE, black);
1111 SetAStyle(SCE_P_TRIPLEDOUBLE, black);
1112 SetAStyle(SCE_P_CLASSNAME, darkBlue);
1113 SetAStyle(SCE_P_DEFNAME, darkBlue);
1114 SetAStyle(SCE_P_OPERATOR, darkBlue);
1115 SetAStyle(SCE_P_IDENTIFIER, darkBlue);
1116 SetAStyle(SCE_P_COMMENTBLOCK, darkGreen);
1117 SetAStyle(SCE_P_STRINGEOL, red);
1119 if ((_tcscmp(line, _T("c"))==0)||
1120 (_tcscmp(line, _T("cc"))==0)||
1121 (_tcscmp(line, _T("cpp"))==0)||
1122 (_tcscmp(line, _T("cxx"))==0)||
1123 (_tcscmp(line, _T("h"))==0)||
1124 (_tcscmp(line, _T("hh"))==0)||
1125 (_tcscmp(line, _T("hpp"))==0)||
1126 (_tcscmp(line, _T("hxx"))==0)||
1127 (_tcscmp(line, _T("dlg"))==0)||
1128 (_tcscmp(line, _T("mak"))==0))
1130 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1131 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("and and_eq asm auto bitand bitor bool break \
1132 case catch char class compl const const_cast continue \
1133 default delete do double dynamic_cast else enum explicit export extern false float for \
1134 friend goto if inline int long mutable namespace new not not_eq \
1135 operator or or_eq private protected public \
1136 register reinterpret_cast return short signed sizeof static static_cast struct switch \
1137 template this throw true try typedef typeid typename union unsigned using \
1138 virtual void volatile wchar_t while xor xor_eq")).GetBuffer()));
1139 SendEditor(SCI_SETKEYWORDS, 3, (LPARAM)(m_TextView.StringForControl(_T("a addindex addtogroup anchor arg attention \
1140 author b brief bug c class code date def defgroup deprecated dontinclude \
1141 e em endcode endhtmlonly endif endlatexonly endlink endverbatim enum example exception \
1142 f$ f[ f] file fn hideinitializer htmlinclude htmlonly \
1143 if image include ingroup internal invariant interface latexonly li line link \
1144 mainpage name namespace nosubgrouping note overload \
1145 p page par param post pre ref relates remarks return retval \
1146 sa section see showinitializer since skip skipline struct subsection \
1147 test throw todo typedef union until \
1148 var verbatim verbinclude version warning weakgroup $ @ \\ & < > # { }")).GetBuffer()));
1149 SetupCppLexer();
1151 if (_tcscmp(line, _T("cs"))==0)
1153 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1154 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("abstract as base bool break byte case catch char checked class \
1155 const continue decimal default delegate do double else enum \
1156 event explicit extern false finally fixed float for foreach goto if \
1157 implicit in int interface internal is lock long namespace new null \
1158 object operator out override params private protected public \
1159 readonly ref return sbyte sealed short sizeof stackalloc static \
1160 string struct switch this throw true try typeof uint ulong \
1161 unchecked unsafe ushort using virtual void while")).GetBuffer()));
1162 SetupCppLexer();
1164 if ((_tcscmp(line, _T("rc"))==0)||
1165 (_tcscmp(line, _T("rc2"))==0))
1167 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1168 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("ACCELERATORS ALT AUTO3STATE AUTOCHECKBOX AUTORADIOBUTTON \
1169 BEGIN BITMAP BLOCK BUTTON CAPTION CHARACTERISTICS CHECKBOX CLASS \
1170 COMBOBOX CONTROL CTEXT CURSOR DEFPUSHBUTTON DIALOG DIALOGEX DISCARDABLE \
1171 EDITTEXT END EXSTYLE FONT GROUPBOX ICON LANGUAGE LISTBOX LTEXT \
1172 MENU MENUEX MENUITEM MESSAGETABLE POPUP \
1173 PUSHBUTTON RADIOBUTTON RCDATA RTEXT SCROLLBAR SEPARATOR SHIFT STATE3 \
1174 STRINGTABLE STYLE TEXTINCLUDE VALUE VERSION VERSIONINFO VIRTKEY")).GetBuffer()));
1175 SetupCppLexer();
1177 if ((_tcscmp(line, _T("idl"))==0)||
1178 (_tcscmp(line, _T("odl"))==0))
1180 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1181 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("aggregatable allocate appobject arrays async async_uuid \
1182 auto_handle \
1183 bindable boolean broadcast byte byte_count \
1184 call_as callback char coclass code comm_status \
1185 const context_handle context_handle_noserialize \
1186 context_handle_serialize control cpp_quote custom \
1187 decode default defaultbind defaultcollelem \
1188 defaultvalue defaultvtable dispinterface displaybind dllname \
1189 double dual \
1190 enable_allocate encode endpoint entry enum error_status_t \
1191 explicit_handle \
1192 fault_status first_is float \
1193 handle_t heap helpcontext helpfile helpstring \
1194 helpstringcontext helpstringdll hidden hyper \
1195 id idempotent ignore iid_as iid_is immediatebind implicit_handle \
1196 import importlib in include in_line int __int64 __int3264 interface \
1197 last_is lcid length_is library licensed local long \
1198 max_is maybe message methods midl_pragma \
1199 midl_user_allocate midl_user_free min_is module ms_union \
1200 ncacn_at_dsp ncacn_dnet_nsp ncacn_http ncacn_ip_tcp \
1201 ncacn_nb_ipx ncacn_nb_nb ncacn_nb_tcp ncacn_np \
1202 ncacn_spx ncacn_vns_spp ncadg_ip_udp ncadg_ipx ncadg_mq \
1203 ncalrpc nocode nonbrowsable noncreatable nonextensible notify \
1204 object odl oleautomation optimize optional out out_of_line \
1205 pipe pointer_default pragma properties propget propput propputref \
1206 ptr public \
1207 range readonly ref represent_as requestedit restricted retval \
1208 shape short signed size_is small source strict_context_handle \
1209 string struct switch switch_is switch_type \
1210 transmit_as typedef \
1211 uidefault union unique unsigned user_marshal usesgetlasterror uuid \
1212 v1_enum vararg version void wchar_t wire_marshal")).GetBuffer()));
1213 SetupCppLexer();
1215 if (_tcscmp(line, _T("java"))==0)
1217 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1218 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("abstract assert boolean break byte case catch char class \
1219 const continue default do double else extends final finally float for future \
1220 generic goto if implements import inner instanceof int interface long \
1221 native new null outer package private protected public rest \
1222 return short static super switch synchronized this throw throws \
1223 transient try var void volatile while")).GetBuffer()));
1224 SetupCppLexer();
1226 if (_tcscmp(line, _T("js"))==0)
1228 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1229 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("abstract boolean break byte case catch char class \
1230 const continue debugger default delete do double else enum export extends \
1231 final finally float for function goto if implements import in instanceof \
1232 int interface long native new package private protected public \
1233 return short static super switch synchronized this throw throws \
1234 transient try typeof var void volatile while with")).GetBuffer()));
1235 SetupCppLexer();
1237 if ((_tcscmp(line, _T("pas"))==0)||
1238 (_tcscmp(line, _T("dpr"))==0)||
1239 (_tcscmp(line, _T("pp"))==0))
1241 SendEditor(SCI_SETLEXER, SCLEX_PASCAL);
1242 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("and array as begin case class const constructor \
1243 destructor div do downto else end except file finally \
1244 for function goto if implementation in inherited \
1245 interface is mod not object of on or packed \
1246 procedure program property raise record repeat \
1247 set shl shr then threadvar to try type unit \
1248 until uses var while with xor")).GetBuffer()));
1249 SetupCppLexer();
1251 if ((_tcscmp(line, _T("as"))==0)||
1252 (_tcscmp(line, _T("asc"))==0)||
1253 (_tcscmp(line, _T("jsfl"))==0))
1255 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1256 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("add and break case catch class continue default delete do \
1257 dynamic else eq extends false finally for function ge get gt if implements import in \
1258 instanceof interface intrinsic le lt ne new not null or private public return \
1259 set static super switch this throw true try typeof undefined var void while with")).GetBuffer()));
1260 SendEditor(SCI_SETKEYWORDS, 1, (LPARAM)(m_TextView.StringForControl(_T("Array Arguments Accessibility Boolean Button Camera Color \
1261 ContextMenu ContextMenuItem Date Error Function Key LoadVars LocalConnection Math \
1262 Microphone Mouse MovieClip MovieClipLoader NetConnection NetStream Number Object \
1263 PrintJob Selection SharedObject Sound Stage String StyleSheet System TextField \
1264 TextFormat TextSnapshot Video Void XML XMLNode XMLSocket \
1265 _accProps _focusrect _global _highquality _parent _quality _root _soundbuftime \
1266 arguments asfunction call capabilities chr clearInterval duplicateMovieClip \
1267 escape eval fscommand getProperty getTimer getURL getVersion gotoAndPlay gotoAndStop \
1268 ifFrameLoaded Infinity -Infinity int isFinite isNaN length loadMovie loadMovieNum \
1269 loadVariables loadVariablesNum maxscroll mbchr mblength mbord mbsubstring MMExecute \
1270 NaN newline nextFrame nextScene on onClipEvent onUpdate ord parseFloat parseInt play \
1271 prevFrame prevScene print printAsBitmap printAsBitmapNum printNum random removeMovieClip \
1272 scroll set setInterval setProperty startDrag stop stopAllSounds stopDrag substring \
1273 targetPath tellTarget toggleHighQuality trace unescape unloadMovie unLoadMovieNum updateAfterEvent")).GetBuffer()));
1274 SetupCppLexer();
1276 if ((_tcscmp(line, _T("html"))==0)||
1277 (_tcscmp(line, _T("htm"))==0)||
1278 (_tcscmp(line, _T("shtml"))==0)||
1279 (_tcscmp(line, _T("htt"))==0)||
1280 (_tcscmp(line, _T("xml"))==0)||
1281 (_tcscmp(line, _T("asp"))==0)||
1282 (_tcscmp(line, _T("xsl"))==0)||
1283 (_tcscmp(line, _T("php"))==0)||
1284 (_tcscmp(line, _T("xhtml"))==0)||
1285 (_tcscmp(line, _T("phtml"))==0)||
1286 (_tcscmp(line, _T("cfm"))==0)||
1287 (_tcscmp(line, _T("tpl"))==0)||
1288 (_tcscmp(line, _T("dtd"))==0)||
1289 (_tcscmp(line, _T("hta"))==0)||
1290 (_tcscmp(line, _T("htd"))==0)||
1291 (_tcscmp(line, _T("wxs"))==0))
1293 SendEditor(SCI_SETLEXER, SCLEX_HTML);
1294 SendEditor(SCI_SETSTYLEBITS, 7);
1295 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("a abbr acronym address applet area b base basefont \
1296 bdo big blockquote body br button caption center \
1297 cite code col colgroup dd del dfn dir div dl dt em \
1298 fieldset font form frame frameset h1 h2 h3 h4 h5 h6 \
1299 head hr html i iframe img input ins isindex kbd label \
1300 legend li link map menu meta noframes noscript \
1301 object ol optgroup option p param pre q s samp \
1302 script select small span strike strong style sub sup \
1303 table tbody td textarea tfoot th thead title tr tt u ul \
1304 var xml xmlns abbr accept-charset accept accesskey action align alink \
1305 alt archive axis background bgcolor border \
1306 cellpadding cellspacing char charoff charset checked cite \
1307 class classid clear codebase codetype color cols colspan \
1308 compact content coords \
1309 data datafld dataformatas datapagesize datasrc datetime \
1310 declare defer dir disabled enctype event \
1311 face for frame frameborder \
1312 headers height href hreflang hspace http-equiv \
1313 id ismap label lang language leftmargin link longdesc \
1314 marginwidth marginheight maxlength media method multiple \
1315 name nohref noresize noshade nowrap \
1316 object onblur onchange onclick ondblclick onfocus \
1317 onkeydown onkeypress onkeyup onload onmousedown \
1318 onmousemove onmouseover onmouseout onmouseup \
1319 onreset onselect onsubmit onunload \
1320 profile prompt readonly rel rev rows rowspan rules \
1321 scheme scope selected shape size span src standby start style \
1322 summary tabindex target text title topmargin type usemap \
1323 valign value valuetype version vlink vspace width \
1324 text password checkbox radio submit reset \
1325 file hidden image")).GetBuffer()));
1326 SendEditor(SCI_SETKEYWORDS, 1, (LPARAM)(m_TextView.StringForControl(_T("assign audio block break catch choice clear disconnect else elseif \
1327 emphasis enumerate error exit field filled form goto grammar help \
1328 if initial link log menu meta noinput nomatch object option p paragraph \
1329 param phoneme prompt property prosody record reprompt return s say-as \
1330 script sentence subdialog submit throw transfer value var voice vxml")).GetBuffer()));
1331 SendEditor(SCI_SETKEYWORDS, 2, (LPARAM)(m_TextView.StringForControl(_T("accept age alphabet anchor application base beep bridge category charset \
1332 classid cond connecttimeout content contour count dest destexpr dtmf dtmfterm \
1333 duration enctype event eventexpr expr expritem fetchtimeout finalsilence \
1334 gender http-equiv id level maxage maxstale maxtime message messageexpr \
1335 method mime modal mode name namelist next nextitem ph pitch range rate \
1336 scope size sizeexpr skiplist slot src srcexpr sub time timeexpr timeout \
1337 transferaudio type value variant version volume xml:lang")).GetBuffer()));
1338 SendEditor(SCI_SETKEYWORDS, 3, (LPARAM)(m_TextView.StringForControl(_T("and assert break class continue def del elif \
1339 else except exec finally for from global if import in is lambda None \
1340 not or pass print raise return try while yield")).GetBuffer()));
1341 SendEditor(SCI_SETKEYWORDS, 4, (LPARAM)(m_TextView.StringForControl(_T("and argv as argc break case cfunction class continue declare default do \
1342 die echo else elseif empty enddeclare endfor endforeach endif endswitch \
1343 endwhile e_all e_parse e_error e_warning eval exit extends false for \
1344 foreach function global http_cookie_vars http_get_vars http_post_vars \
1345 http_post_files http_env_vars http_server_vars if include include_once \
1346 list new not null old_function or parent php_os php_self php_version \
1347 print require require_once return static switch stdclass this true var \
1348 xor virtual while __file__ __line__ __sleep __wakeup")).GetBuffer()));
1350 SetAStyle(SCE_H_TAG, darkBlue);
1351 SetAStyle(SCE_H_TAGUNKNOWN, red);
1352 SetAStyle(SCE_H_ATTRIBUTE, darkBlue);
1353 SetAStyle(SCE_H_ATTRIBUTEUNKNOWN, red);
1354 SetAStyle(SCE_H_NUMBER, RGB(0x80,0,0x80));
1355 SetAStyle(SCE_H_DOUBLESTRING, RGB(0,0x80,0));
1356 SetAStyle(SCE_H_SINGLESTRING, RGB(0,0x80,0));
1357 SetAStyle(SCE_H_OTHER, RGB(0x80,0,0x80));
1358 SetAStyle(SCE_H_COMMENT, RGB(0x80,0x80,0));
1359 SetAStyle(SCE_H_ENTITY, RGB(0x80,0,0x80));
1361 SetAStyle(SCE_H_TAGEND, darkBlue);
1362 SetAStyle(SCE_H_XMLSTART, darkBlue); // <?
1363 SetAStyle(SCE_H_QUESTION, darkBlue); // <?
1364 SetAStyle(SCE_H_XMLEND, darkBlue); // ?>
1365 SetAStyle(SCE_H_SCRIPT, darkBlue); // <script
1366 SetAStyle(SCE_H_ASP, RGB(0x4F, 0x4F, 0), RGB(0xFF, 0xFF, 0)); // <% ... %>
1367 SetAStyle(SCE_H_ASPAT, RGB(0x4F, 0x4F, 0), RGB(0xFF, 0xFF, 0)); // <%@ ... %>
1369 SetAStyle(SCE_HB_DEFAULT, black);
1370 SetAStyle(SCE_HB_COMMENTLINE, darkGreen);
1371 SetAStyle(SCE_HB_NUMBER, RGB(0,0x80,0x80));
1372 SetAStyle(SCE_HB_WORD, darkBlue);
1373 SendEditor(SCI_STYLESETBOLD, SCE_HB_WORD, 1);
1374 SetAStyle(SCE_HB_STRING, RGB(0x80,0,0x80));
1375 SetAStyle(SCE_HB_IDENTIFIER, black);
1377 // This light blue is found in the windows system palette so is safe to use even in 256 colour modes.
1378 // Show the whole section of VBScript with light blue background
1379 for (int bstyle = SCE_HB_DEFAULT; bstyle <= SCE_HB_STRINGEOL; ++bstyle) {
1380 SendEditor(SCI_STYLESETFONT, bstyle,
1381 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
1382 SendEditor(SCI_STYLESETBACK, bstyle, lightBlue);
1383 // This call extends the backround colour of the last style on the line to the edge of the window
1384 SendEditor(SCI_STYLESETEOLFILLED, bstyle, 1);
1386 SendEditor(SCI_STYLESETBACK, SCE_HB_STRINGEOL, RGB(0x7F,0x7F,0xFF));
1387 SendEditor(SCI_STYLESETFONT, SCE_HB_COMMENTLINE,
1388 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
1390 SetAStyle(SCE_HBA_DEFAULT, black);
1391 SetAStyle(SCE_HBA_COMMENTLINE, darkGreen);
1392 SetAStyle(SCE_HBA_NUMBER, RGB(0,0x80,0x80));
1393 SetAStyle(SCE_HBA_WORD, darkBlue);
1394 SendEditor(SCI_STYLESETBOLD, SCE_HBA_WORD, 1);
1395 SetAStyle(SCE_HBA_STRING, RGB(0x80,0,0x80));
1396 SetAStyle(SCE_HBA_IDENTIFIER, black);
1398 // Show the whole section of ASP VBScript with bright yellow background
1399 for (int bastyle = SCE_HBA_DEFAULT; bastyle <= SCE_HBA_STRINGEOL; ++bastyle) {
1400 SendEditor(SCI_STYLESETFONT, bastyle,
1401 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
1402 SendEditor(SCI_STYLESETBACK, bastyle, RGB(0xFF, 0xFF, 0));
1403 // This call extends the backround colour of the last style on the line to the edge of the window
1404 SendEditor(SCI_STYLESETEOLFILLED, bastyle, 1);
1406 SendEditor(SCI_STYLESETBACK, SCE_HBA_STRINGEOL, RGB(0xCF,0xCF,0x7F));
1407 SendEditor(SCI_STYLESETFONT, SCE_HBA_COMMENTLINE,
1408 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
1410 // If there is no need to support embedded Javascript, the following code can be dropped.
1411 // Javascript will still be correctly processed but will be displayed in just the default style.
1413 SetAStyle(SCE_HJ_START, RGB(0x80,0x80,0));
1414 SetAStyle(SCE_HJ_DEFAULT, black);
1415 SetAStyle(SCE_HJ_COMMENT, darkGreen);
1416 SetAStyle(SCE_HJ_COMMENTLINE, darkGreen);
1417 SetAStyle(SCE_HJ_COMMENTDOC, darkGreen);
1418 SetAStyle(SCE_HJ_NUMBER, RGB(0,0x80,0x80));
1419 SetAStyle(SCE_HJ_WORD, black);
1420 SetAStyle(SCE_HJ_KEYWORD, darkBlue);
1421 SetAStyle(SCE_HJ_DOUBLESTRING, RGB(0x80,0,0x80));
1422 SetAStyle(SCE_HJ_SINGLESTRING, RGB(0x80,0,0x80));
1423 SetAStyle(SCE_HJ_SYMBOLS, black);
1425 SetAStyle(SCE_HJA_START, RGB(0x80,0x80,0));
1426 SetAStyle(SCE_HJA_DEFAULT, black);
1427 SetAStyle(SCE_HJA_COMMENT, darkGreen);
1428 SetAStyle(SCE_HJA_COMMENTLINE, darkGreen);
1429 SetAStyle(SCE_HJA_COMMENTDOC, darkGreen);
1430 SetAStyle(SCE_HJA_NUMBER, RGB(0,0x80,0x80));
1431 SetAStyle(SCE_HJA_WORD, black);
1432 SetAStyle(SCE_HJA_KEYWORD, darkBlue);
1433 SetAStyle(SCE_HJA_DOUBLESTRING, RGB(0x80,0,0x80));
1434 SetAStyle(SCE_HJA_SINGLESTRING, RGB(0x80,0,0x80));
1435 SetAStyle(SCE_HJA_SYMBOLS, black);
1437 SetAStyle(SCE_HPHP_DEFAULT, black);
1438 SetAStyle(SCE_HPHP_HSTRING, RGB(0x80,0,0x80));
1439 SetAStyle(SCE_HPHP_SIMPLESTRING, RGB(0x80,0,0x80));
1440 SetAStyle(SCE_HPHP_WORD, darkBlue);
1441 SetAStyle(SCE_HPHP_NUMBER, RGB(0,0x80,0x80));
1442 SetAStyle(SCE_HPHP_VARIABLE, red);
1443 SetAStyle(SCE_HPHP_HSTRING_VARIABLE, red);
1444 SetAStyle(SCE_HPHP_COMPLEX_VARIABLE, red);
1445 SetAStyle(SCE_HPHP_COMMENT, darkGreen);
1446 SetAStyle(SCE_HPHP_COMMENTLINE, darkGreen);
1447 SetAStyle(SCE_HPHP_OPERATOR, darkBlue);
1449 // Show the whole section of Javascript with off white background
1450 for (int jstyle = SCE_HJ_DEFAULT; jstyle <= SCE_HJ_SYMBOLS; ++jstyle) {
1451 SendEditor(SCI_STYLESETFONT, jstyle,
1452 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
1453 SendEditor(SCI_STYLESETBACK, jstyle, offWhite);
1454 SendEditor(SCI_STYLESETEOLFILLED, jstyle, 1);
1456 SendEditor(SCI_STYLESETBACK, SCE_HJ_STRINGEOL, RGB(0xDF, 0xDF, 0x7F));
1457 SendEditor(SCI_STYLESETEOLFILLED, SCE_HJ_STRINGEOL, 1);
1459 // Show the whole section of Javascript with brown background
1460 for (int jastyle = SCE_HJA_DEFAULT; jastyle <= SCE_HJA_SYMBOLS; ++jastyle) {
1461 SendEditor(SCI_STYLESETFONT, jastyle,
1462 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
1463 SendEditor(SCI_STYLESETBACK, jastyle, RGB(0xDF, 0xDF, 0x7F));
1464 SendEditor(SCI_STYLESETEOLFILLED, jastyle, 1);
1466 SendEditor(SCI_STYLESETBACK, SCE_HJA_STRINGEOL, RGB(0x0,0xAF,0x5F));
1467 SendEditor(SCI_STYLESETEOLFILLED, SCE_HJA_STRINGEOL, 1);
1470 else
1472 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1473 SetupCppLexer();
1475 SendEditor(SCI_COLOURISE, 0, -1);
1479 void CTortoiseGitBlameView::SetupCppLexer()
1481 SetAStyle(SCE_C_DEFAULT, RGB(0, 0, 0));
1482 SetAStyle(SCE_C_COMMENT, RGB(0, 0x80, 0));
1483 SetAStyle(SCE_C_COMMENTLINE, RGB(0, 0x80, 0));
1484 SetAStyle(SCE_C_COMMENTDOC, RGB(0, 0x80, 0));
1485 SetAStyle(SCE_C_COMMENTLINEDOC, RGB(0, 0x80, 0));
1486 SetAStyle(SCE_C_COMMENTDOCKEYWORD, RGB(0, 0x80, 0));
1487 SetAStyle(SCE_C_COMMENTDOCKEYWORDERROR, RGB(0, 0x80, 0));
1488 SetAStyle(SCE_C_NUMBER, RGB(0, 0x80, 0x80));
1489 SetAStyle(SCE_C_WORD, RGB(0, 0, 0x80));
1490 SendEditor(SCE_C_WORD, 1);
1491 SetAStyle(SCE_C_STRING, RGB(0x80, 0, 0x80));
1492 SetAStyle(SCE_C_IDENTIFIER, RGB(0, 0, 0));
1493 SetAStyle(SCE_C_PREPROCESSOR, RGB(0x80, 0, 0));
1494 SetAStyle(SCE_C_OPERATOR, RGB(0x80, 0x80, 0));
1495 SendEditor(SCI_SETPROPERTY, (WPARAM)"lexer.cpp.track.preprocessor", (LPARAM)"0");
1498 int CTortoiseGitBlameView::GetEncode(unsigned char *buff, int size, int *bomoffset)
1500 CFileTextLines textlines;
1501 CFileTextLines::UnicodeType type = textlines.CheckUnicodeType(buff, size);
1503 if(type == CFileTextLines::UTF8BOM)
1505 *bomoffset = 3;
1506 return CP_UTF8;
1508 if(type == CFileTextLines::UTF8)
1509 return CP_UTF8;
1511 if(type == CFileTextLines::UTF16_LE)
1512 return 1200;
1513 if (type == CFileTextLines::UTF16_LEBOM)
1515 *bomoffset = 2;
1516 return 1200;
1519 if(type == CFileTextLines::UTF16_BE)
1520 return 1201;
1521 if (type == CFileTextLines::UTF16_BEBOM)
1523 *bomoffset = 2;
1524 return 1201;
1527 return GetACP();
1530 void CTortoiseGitBlameView::ParseBlame()
1532 m_data.ParseBlameOutput(GetDocument()->m_BlameData, GetLogData()->m_pLogCache->m_HashMap, m_DateFormat, m_bRelativeTimes);
1533 CString filename = GetDocument()->m_GitPath.GetGitPathString();
1534 m_bBlameOuputContainsOtherFilenames = m_data.ContainsOnlyFilename(filename) ? FALSE : TRUE;
1537 void CTortoiseGitBlameView::MapLineToLogIndex()
1539 std::vector<int> lineToLogIndex;
1542 int numberOfLines = m_data.GetNumberOfLines();
1543 lineToLogIndex.reserve(numberOfLines);
1544 size_t logSize = this->GetLogData()->size();
1545 for (int j = 0; j < numberOfLines; ++j)
1547 CGitHash& hash = m_data.GetHash(j);
1549 int index = -2;
1550 for (size_t i = 0; i < logSize; ++i)
1552 if (hash == this->GetLogData()->at(i))
1554 index = (int)i;
1555 break;
1558 lineToLogIndex.push_back(index);
1560 this->m_lineToLogIndex.swap(lineToLogIndex);
1563 void CTortoiseGitBlameView::UpdateInfo(int Encode)
1565 CreateFont();
1567 SendEditor(SCI_SETREADONLY, FALSE);
1568 SendEditor(SCI_CLEARALL);
1569 SendEditor(EM_EMPTYUNDOBUFFER);
1570 SendEditor(SCI_SETSAVEPOINT);
1571 SendEditor(SCI_CANCEL);
1572 SendEditor(SCI_SETUNDOCOLLECTION, 0);
1574 SendEditor(SCI_SETCODEPAGE, SC_CP_UTF8);
1576 int encoding = m_data.UpdateEncoding(Encode);
1578 int numberOfLines = m_data.GetNumberOfLines();
1579 if (numberOfLines > 0)
1581 for (int i = 0; i < numberOfLines - 1; ++i)
1583 SendEditor(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)m_data.GetUtf8Line(i));
1584 SendEditor(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)"\n\0\0\0");
1587 // as it will add another line number in scintilla which has no counter part in the blame output
1588 // prevent carriage return and line feed for the last line
1589 CStringA s = m_data.GetUtf8Line(numberOfLines - 1);
1590 int length = s.GetLength();
1591 if (length > 0 && s.GetAt(length - 1) == '\r')
1592 s.Truncate(length - 1);
1593 SendEditor(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)s);
1598 UINT nID;
1599 UINT nStyle;
1600 int cxWidth;
1601 int nIndex = ((CMainFrame *)::AfxGetApp()->GetMainWnd())->m_wndStatusBar.CommandToIndex(ID_INDICATOR_ENCODING);
1602 ((CMainFrame *)::AfxGetApp()->GetMainWnd())->m_wndStatusBar.GetPaneInfo(nIndex, nID, nStyle, cxWidth);
1603 CString sBarText = L"";
1604 for (int i = 0; i < _countof(encodings); ++i)
1606 if (encodings[i].id == encoding)
1608 sBarText = CString(encodings[i].name);
1609 break;
1612 //calculate the width of the text
1613 CDC * pDC = ((CMainFrame *)::AfxGetApp()->GetMainWnd())->m_wndStatusBar.GetDC();
1614 if (pDC)
1616 CSize size = pDC->GetTextExtent(sBarText);
1617 ((CMainFrame *)::AfxGetApp()->GetMainWnd())->m_wndStatusBar.SetPaneInfo(nIndex, nID, nStyle, size.cx+2);
1618 ReleaseDC(pDC);
1620 ((CMainFrame *)::AfxGetApp()->GetMainWnd())->m_wndStatusBar.SetPaneText(nIndex, sBarText);
1623 #ifdef USE_TEMPFILENAME
1624 if(m_Buffer)
1626 delete m_Buffer;
1627 m_Buffer=NULL;
1630 CFile file;
1631 file.Open(this->GetDocument()->m_TempFileName,CFile::modeRead);
1633 m_Buffer = new char[file.GetLength()+4];
1634 m_Buffer[file.GetLength()] =0;
1635 m_Buffer[file.GetLength()+1] =0;
1636 m_Buffer[file.GetLength()+2] =0;
1637 m_Buffer[file.GetLength()+3] =0;
1639 file.Read(m_Buffer, file.GetLength());
1641 int bomoffset =0;
1642 int encoding = GetEncode( (unsigned char *)m_Buffer, file.GetLength(), &bomoffset);
1644 file.Close();
1645 //SendEditor(SCI_SETCODEPAGE, encoding);
1647 //SendEditor(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)(m_Buffer + bomoffset));
1648 #endif
1649 SetupLexer(GetDocument()->m_CurrentFileName);
1651 SendEditor(SCI_SETUNDOCOLLECTION, 1);
1652 SendEditor(EM_EMPTYUNDOBUFFER);
1653 SendEditor(SCI_SETSAVEPOINT);
1654 SendEditor(SCI_GOTOPOS, 0);
1655 SendEditor(SCI_SETSCROLLWIDTHTRACKING, TRUE);
1656 SendEditor(SCI_SETREADONLY, TRUE);
1658 GetBlameWidth();
1659 CRect rect;
1660 this->GetClientRect(rect);
1661 //this->m_TextView.GetWindowRect(rect);
1662 //this->m_TextView.ScreenToClient(rect);
1663 rect.left=this->m_blamewidth;
1664 this->m_TextView.MoveWindow(rect);
1666 this->Invalidate();
1669 CString CTortoiseGitBlameView::ResolveCommitFile(int line)
1671 return ResolveCommitFile(m_data.GetFilename(line));
1674 CString CTortoiseGitBlameView::ResolveCommitFile(const CString& path)
1676 if (path.IsEmpty())
1678 return ((CMainFrame*)::AfxGetApp()->GetMainWnd())->GetActiveView()->GetDocument()->GetPathName();
1680 else
1682 return g_Git.CombinePath(path);
1686 COLORREF CTortoiseGitBlameView::GetLineColor(int line)
1688 if (m_colorage && m_data.IsValidLine(line))
1690 int logIndex = m_lineToLogIndex[line];
1691 if (logIndex >= 0)
1693 int slider = (int)((GetLogData()->size() - logIndex) * 100 / (GetLogData()->size() + 1));
1694 return InterColor(DWORD(m_regOldLinesColor), DWORD(m_regNewLinesColor), slider);
1697 return m_windowcolor;
1700 CGitBlameLogList * CTortoiseGitBlameView::GetLogList()
1702 return &(GetDocument()->GetMainFrame()->m_wndOutput.m_LogList);
1706 CLogDataVector * CTortoiseGitBlameView::GetLogData()
1708 return &(GetDocument()->GetMainFrame()->m_wndOutput.m_LogList.m_logEntries);
1711 void CTortoiseGitBlameView::OnSciPainted(NMHDR *,LRESULT *)
1713 this->Invalidate();
1716 void CTortoiseGitBlameView::OnLButtonDown(UINT nFlags,CPoint point)
1719 int line = (int)SendEditor(SCI_GETFIRSTVISIBLELINE);
1720 int height = (int)SendEditor(SCI_TEXTHEIGHT);
1721 line = line + (int)(point.y/height);
1723 if (line < m_data.GetNumberOfLines())
1725 SetSelectedLine(line);
1726 if (m_data.GetHash(line) != m_SelectedHash)
1728 m_SelectedHash = m_data.GetHash(line);
1730 int logIndex = m_lineToLogIndex[line];
1731 if (logIndex >= 0)
1733 this->GetLogList()->SetItemState(logIndex, LVIS_SELECTED, LVIS_SELECTED);
1734 this->GetLogList()->EnsureVisible(logIndex, FALSE);
1736 else
1738 GitRevLoglist* pRev = m_data.GetRev(line, GetLogData()->m_pLogCache->m_HashMap);
1739 this->GetDocument()->GetMainFrame()->m_wndProperties.UpdateProperties(pRev);
1742 else
1744 m_SelectedHash.Empty();
1746 //::InvalidateRect( NULL, FALSE);
1747 this->Invalidate();
1748 this->m_TextView.Invalidate();
1751 else
1753 SetSelectedLine(-1);
1756 CView::OnLButtonDown(nFlags,point);
1759 void CTortoiseGitBlameView::OnSciGetBkColor(NMHDR* hdr, LRESULT* /*result*/)
1761 SCNotification *notification=reinterpret_cast<SCNotification *>(hdr);
1763 if (notification->line < m_data.GetNumberOfLines())
1765 if (m_data.GetHash(notification->line) == this->m_SelectedHash)
1766 notification->lParam = m_selectedauthorcolor;
1767 else
1768 notification->lParam = GetLineColor(notification->line);
1772 void CTortoiseGitBlameView::FocusOn(GitRevLoglist* pRev)
1774 this->GetDocument()->GetMainFrame()->m_wndProperties.UpdateProperties(pRev);
1776 this->Invalidate();
1778 if (m_SelectedHash != pRev->m_CommitHash) {
1779 m_SelectedHash = pRev->m_CommitHash;
1780 int line = m_data.FindFirstLine(m_SelectedHash, 0);
1781 if (line >= 0)
1783 GotoLine(line + 1);
1784 m_TextView.Invalidate();
1785 return;
1787 SendEditor(SCI_SETSEL, INT_MAX, -1);
1791 void CTortoiseGitBlameView::OnMouseHover(UINT /*nFlags*/, CPoint point)
1793 int line = (int)SendEditor(SCI_GETFIRSTVISIBLELINE);
1794 int height = (int)SendEditor(SCI_TEXTHEIGHT);
1795 line = line + (point.y/height);
1797 if (m_data.IsValidLine(line))
1799 if (line != m_MouseLine)
1801 m_MouseLine = line;
1802 GitRev *pRev = nullptr;
1803 int logIndex = m_lineToLogIndex[line];
1804 if (logIndex >= 0)
1805 pRev = &GetLogData()->GetGitRevAt(logIndex);
1806 else
1807 pRev = m_data.GetRev(line, GetLogData()->m_pLogCache->m_HashMap);
1809 if (!pRev)
1810 return;
1812 CString body = pRev->GetBody();
1813 int maxLine = 15;
1814 int iline = 0;
1815 int pos = 0;
1816 while (iline++ < maxLine)
1818 int pos2 = body.Find(_T("\n"), pos);
1819 if (pos2 < 0)
1820 break;
1821 int lineLength = pos2 - pos - 1;
1822 pos = pos2 + 1;
1823 iline += lineLength / 70;
1826 CString filename;
1827 if ((m_bShowCompleteLog && m_bFollowRenames) || !BlameIsLimitedToOneFilename(m_dwDetectMovedOrCopiedLines) || m_bBlameOuputContainsOtherFilenames)
1828 filename.Format(_T("%s: %s\n"), m_sFileName, m_data.GetFilename(line));
1830 CString str;
1831 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,
1832 m_sAuthor, pRev->GetAuthorName(), pRev->GetAuthorEmail(),
1833 m_sDate, CLoglistUtils::FormatDateAndTime(pRev->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
1834 m_sMessage, pRev->GetSubject(),
1835 iline <= maxLine ? body : (body.Left(pos) + _T("\n....................")));
1837 m_ToolTip.Pop();
1838 m_ToolTip.AddTool(this, str);
1840 CRect rect;
1841 rect.left=LOCATOR_WIDTH;
1842 rect.right=this->m_blamewidth+rect.left;
1843 rect.top = point.y - (LONG)height;
1844 rect.bottom = point.y + (LONG)height;
1845 this->InvalidateRect(rect);
1850 void CTortoiseGitBlameView::OnMouseMove(UINT /*nFlags*/, CPoint /*point*/)
1852 TRACKMOUSEEVENT tme;
1853 tme.cbSize=sizeof(TRACKMOUSEEVENT);
1854 tme.dwFlags=TME_HOVER|TME_LEAVE;
1855 tme.hwndTrack=this->m_hWnd;
1856 tme.dwHoverTime=1;
1857 TrackMouseEvent(&tme);
1861 BOOL CTortoiseGitBlameView::PreTranslateMessage(MSG* pMsg)
1863 m_ToolTip.RelayEvent(pMsg);
1864 return CView::PreTranslateMessage(pMsg);
1867 void CTortoiseGitBlameView::OnEditFind()
1869 if (m_pFindDialog)
1870 return;
1872 m_pFindDialog=new CFindReplaceDialog();
1874 CString oneline = theApp.GetString(_T("FindString"));
1875 if (m_TextView.Call(SCI_GETSELECTIONSTART) != m_TextView.Call(SCI_GETSELECTIONEND))
1877 LRESULT bufsize = m_TextView.Call(SCI_GETSELECTIONEND) - m_TextView.Call(SCI_GETSELECTIONSTART);
1878 std::unique_ptr<char> linebuf(new char[bufsize + 1]);
1879 SecureZeroMemory(linebuf.get(), bufsize + 1);
1880 SendEditor(SCI_GETSELTEXT, 0, (LPARAM)linebuf.get());
1881 oneline = m_TextView.StringFromControl(linebuf.get());
1884 DWORD flags = FR_DOWN | FR_HIDEWHOLEWORD | FR_HIDEUPDOWN;
1885 if (theApp.GetInt(_T("FindMatchCase")))
1886 flags |= FR_MATCHCASE;
1888 m_pFindDialog->Create(TRUE, oneline, NULL, flags, this);
1891 void CTortoiseGitBlameView::OnEditGoto()
1893 CEditGotoDlg dlg;
1894 if(dlg.DoModal()==IDOK)
1896 this->GotoLine(dlg.m_LineNumber);
1900 LRESULT CTortoiseGitBlameView::OnFindDialogMessage(WPARAM /*wParam*/, LPARAM /*lParam*/)
1902 ASSERT(m_pFindDialog != NULL);
1904 // If the FR_DIALOGTERM flag is set,
1905 // invalidate the handle identifying the dialog box.
1906 if (m_pFindDialog->IsTerminating())
1908 m_pFindDialog = NULL;
1909 return 0;
1912 if (m_data.GetNumberOfLines()==0)
1913 return 0;
1915 // If the FR_FINDNEXT flag is set,
1916 // call the application-defined search routine
1917 // to search for the requested string.
1918 if(m_pFindDialog->FindNext())
1920 m_bMatchCase = !!(m_pFindDialog->m_nFlags & FR_MATCHCASE);
1921 m_sFindText = m_pFindDialog->GetFindString();
1923 theApp.WriteInt(_T("FindMatchCase"), m_bMatchCase ? 1 : 0);
1924 theApp.WriteString(_T("FindString"), m_sFindText);
1926 DoSearch(CTortoiseGitBlameData::SearchNext);
1929 return 0;
1932 void CTortoiseGitBlameView::OnViewNext()
1934 int startline = (int)SendEditor(SCI_GETFIRSTVISIBLELINE);
1935 int line = m_data.FindNextLine(this->m_SelectedHash, (int)SendEditor(SCI_GETFIRSTVISIBLELINE), false);
1936 if(line >= 0)
1937 SendEditor(SCI_LINESCROLL, 0, line - startline - 2);
1939 void CTortoiseGitBlameView::OnViewPrev()
1941 int startline = (int)SendEditor(SCI_GETFIRSTVISIBLELINE);
1942 int line = m_data.FindNextLine(this->m_SelectedHash, (int)SendEditor(SCI_GETFIRSTVISIBLELINE), true);
1943 if(line >= 0)
1944 SendEditor(SCI_LINESCROLL, 0, line - startline - 2);
1947 void CTortoiseGitBlameView::OnViewToggleAuthor()
1949 m_bShowAuthor = ! m_bShowAuthor;
1951 theApp.WriteInt(_T("ShowAuthor"), m_bShowAuthor);
1953 CRect rect;
1954 this->GetClientRect(&rect);
1955 rect.left=GetBlameWidth();
1957 m_TextView.MoveWindow(&rect);
1960 void CTortoiseGitBlameView::OnUpdateViewToggleAuthor(CCmdUI *pCmdUI)
1962 pCmdUI->SetCheck(m_bShowAuthor);
1965 void CTortoiseGitBlameView::OnViewToggleDate()
1967 m_bShowDate = ! m_bShowDate;
1969 theApp.WriteInt(_T("ShowDate"), m_bShowDate);
1971 CRect rect;
1972 this->GetClientRect(&rect);
1973 rect.left=GetBlameWidth();
1975 m_TextView.MoveWindow(&rect);
1978 void CTortoiseGitBlameView::OnUpdateViewToggleDate(CCmdUI *pCmdUI)
1980 pCmdUI->SetCheck(m_bShowDate);
1983 void CTortoiseGitBlameView::OnViewToggleShowFilename()
1985 m_bShowFilename = ! m_bShowFilename;
1987 theApp.WriteInt(_T("ShowFilename"), m_bShowFilename);
1989 CRect rect;
1990 this->GetClientRect(&rect);
1991 rect.left = GetBlameWidth();
1993 m_TextView.MoveWindow(&rect);
1996 void CTortoiseGitBlameView::OnUpdateViewToggleShowFilename(CCmdUI *pCmdUI)
1998 pCmdUI->SetCheck(m_bShowFilename);
2001 void CTortoiseGitBlameView::OnViewToggleShowOriginalLineNumber()
2003 m_bShowOriginalLineNumber = ! m_bShowOriginalLineNumber;
2005 theApp.WriteInt(_T("ShowOriginalLineNumber"), m_bShowOriginalLineNumber);
2007 CRect rect;
2008 this->GetClientRect(&rect);
2009 rect.left = GetBlameWidth();
2011 m_TextView.MoveWindow(&rect);
2014 void CTortoiseGitBlameView::OnUpdateViewToggleShowOriginalLineNumber(CCmdUI *pCmdUI)
2016 pCmdUI->SetCheck(m_bShowOriginalLineNumber);
2019 void CTortoiseGitBlameView::OnViewDetectMovedOrCopiedLines(DWORD dwDetectMovedOrCopiedLines)
2021 m_dwDetectMovedOrCopiedLines = dwDetectMovedOrCopiedLines;
2023 theApp.DoWaitCursor(1);
2025 theApp.WriteInt(_T("DetectMovedOrCopiedLines"), m_dwDetectMovedOrCopiedLines);
2027 CTortoiseGitBlameDoc *document = (CTortoiseGitBlameDoc *) m_pDocument;
2028 if (!document->m_CurrentFileName.IsEmpty())
2030 document->m_lLine = (int)SendEditor(SCI_GETFIRSTVISIBLELINE) + 1;
2031 theApp.m_pDocManager->OnFileNew();
2032 document->OnOpenDocument(document->m_CurrentFileName, document->m_Rev);
2034 theApp.DoWaitCursor(-1);
2037 void CTortoiseGitBlameView::OnViewDetectMovedOrCopiedLinesToggleDisabled()
2039 OnViewDetectMovedOrCopiedLines(BLAME_DETECT_MOVED_OR_COPIED_LINES_DISABLED);
2042 void CTortoiseGitBlameView::OnUpdateViewDetectMovedOrCopiedLinesToggleDisabled(CCmdUI *pCmdUI)
2044 pCmdUI->SetRadio(m_dwDetectMovedOrCopiedLines == BLAME_DETECT_MOVED_OR_COPIED_LINES_DISABLED);
2047 void CTortoiseGitBlameView::OnViewDetectMovedOrCopiedLinesToggleWithinFile()
2049 OnViewDetectMovedOrCopiedLines(BLAME_DETECT_MOVED_OR_COPIED_LINES_WITHIN_FILE);
2052 void CTortoiseGitBlameView::OnUpdateViewDetectMovedOrCopiedLinesToggleWithinFile(CCmdUI *pCmdUI)
2054 pCmdUI->SetRadio(m_dwDetectMovedOrCopiedLines == BLAME_DETECT_MOVED_OR_COPIED_LINES_WITHIN_FILE);
2057 void CTortoiseGitBlameView::OnViewDetectMovedOrCopiedLinesToggleFromModifiedFiles()
2059 OnViewDetectMovedOrCopiedLines(BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_MODIFIED_FILES);
2062 void CTortoiseGitBlameView::OnUpdateViewDetectMovedOrCopiedLinesToggleFromModifiedFiles(CCmdUI *pCmdUI)
2064 pCmdUI->SetRadio(m_dwDetectMovedOrCopiedLines == BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_MODIFIED_FILES);
2067 void CTortoiseGitBlameView::OnViewDetectMovedOrCopiedLinesToggleFromExistingFilesAtFileCreation()
2069 OnViewDetectMovedOrCopiedLines(BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES_AT_FILE_CREATION);
2072 void CTortoiseGitBlameView::OnUpdateViewDetectMovedOrCopiedLinesToggleFromExistingFilesAtFileCreation(CCmdUI *pCmdUI)
2074 pCmdUI->SetRadio(m_dwDetectMovedOrCopiedLines == BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES_AT_FILE_CREATION);
2077 void CTortoiseGitBlameView::OnViewDetectMovedOrCopiedLinesToggleFromExistingFiles()
2079 OnViewDetectMovedOrCopiedLines(BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES);
2082 void CTortoiseGitBlameView::OnUpdateViewDetectMovedOrCopiedLinesToggleFromExistingFiles(CCmdUI *pCmdUI)
2084 pCmdUI->SetRadio(m_dwDetectMovedOrCopiedLines == BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES);
2087 void CTortoiseGitBlameView::ReloadDocument()
2089 theApp.DoWaitCursor(1);
2090 CTortoiseGitBlameDoc *document = (CTortoiseGitBlameDoc *) m_pDocument;
2091 if (!document->m_CurrentFileName.IsEmpty())
2093 document->m_lLine = (int)SendEditor(SCI_GETFIRSTVISIBLELINE) + 1;
2094 theApp.m_pDocManager->OnFileNew();
2095 document->OnOpenDocument(document->m_CurrentFileName, document->m_Rev);
2097 theApp.DoWaitCursor(-1);
2100 void CTortoiseGitBlameView::OnViewToggleIgnoreWhitespace()
2102 m_bIgnoreWhitespace = ! m_bIgnoreWhitespace;
2104 theApp.WriteInt(_T("IgnoreWhitespace"), m_bIgnoreWhitespace ? 1 : 0);
2106 ReloadDocument();
2109 void CTortoiseGitBlameView::OnUpdateViewToggleIgnoreWhitespace(CCmdUI *pCmdUI)
2111 pCmdUI->SetCheck(m_bIgnoreWhitespace);
2114 void CTortoiseGitBlameView::OnViewToggleShowCompleteLog()
2116 m_bShowCompleteLog = ! m_bShowCompleteLog;
2118 theApp.WriteInt(_T("ShowCompleteLog"), m_bShowCompleteLog ? 1 : 0);
2120 ReloadDocument();
2123 void CTortoiseGitBlameView::OnUpdateViewToggleShowCompleteLog(CCmdUI *pCmdUI)
2125 pCmdUI->Enable(BlameIsLimitedToOneFilename(m_dwDetectMovedOrCopiedLines));
2126 pCmdUI->SetCheck(m_bShowCompleteLog && BlameIsLimitedToOneFilename(m_dwDetectMovedOrCopiedLines));
2129 void CTortoiseGitBlameView::OnViewToggleFollowRenames()
2131 m_bFollowRenames = ! m_bFollowRenames;
2133 theApp.WriteInt(_T("FollowRenames"), m_bFollowRenames ? 1 : 0);
2135 ReloadDocument();
2138 void CTortoiseGitBlameView::OnUpdateViewToggleFollowRenames(CCmdUI *pCmdUI)
2140 pCmdUI->Enable(m_bShowCompleteLog && BlameIsLimitedToOneFilename(m_dwDetectMovedOrCopiedLines));
2141 pCmdUI->SetCheck(m_bFollowRenames && m_bShowCompleteLog && BlameIsLimitedToOneFilename(m_dwDetectMovedOrCopiedLines));
2144 void CTortoiseGitBlameView::OnViewToggleColorByAge()
2146 m_colorage = ! m_colorage;
2148 theApp.WriteInt(_T("ColorAge"), m_colorage);
2150 m_TextView.Invalidate();
2153 void CTortoiseGitBlameView::OnUpdateViewToggleColorByAge(CCmdUI *pCmdUI)
2155 pCmdUI->SetCheck(m_colorage);
2158 void CTortoiseGitBlameView::OnUpdateViewCopyToClipboard(CCmdUI *pCmdUI)
2160 CWnd * wnd = GetFocus();
2161 if (wnd == GetLogList())
2163 pCmdUI->Enable(GetLogList()->GetSelectedCount() > 0);
2165 else if (wnd)
2167 if (CString(wnd->GetRuntimeClass()->m_lpszClassName) == _T("CMFCPropertyGridCtrl"))
2169 CMFCPropertyGridCtrl *grid = (CMFCPropertyGridCtrl *)wnd;
2170 pCmdUI->Enable(grid->GetCurSel() && !grid->GetCurSel()->IsGroup() && !CString(grid->GetCurSel()->GetValue()).IsEmpty());
2172 else
2173 pCmdUI->Enable(m_TextView.Call(SCI_GETSELECTIONSTART) != m_TextView.Call(SCI_GETSELECTIONEND));
2175 else
2176 pCmdUI->Enable(FALSE);