1 // TortoiseGitBlame - a Viewer for Git Blames
3 // Copyright (C) 2008-2013 - 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
27 #include "TortoiseGitBlame.h"
28 #include "CommonAppUtils.h"
29 #include "TortoiseGitBlameDoc.h"
30 #include "TortoiseGitBlameView.h"
32 #include "EditGotoDlg.h"
33 #include "LoglistUtils.h"
34 #include "FileTextLines.h"
35 #include "UnicodeUtils.h"
36 #include "MenuEncode.h"
39 #include "StringUtils.h"
40 #include "BlameIndexColors.h"
41 #include "BlameDetectMovedOrCopiedLines.h"
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_DETECT_MOVED_OR_COPIED_LINES_DISABLED
, OnViewDetectMovedOrCopiedLinesToggleDisabled
)
72 ON_UPDATE_COMMAND_UI(ID_VIEW_DETECT_MOVED_OR_COPIED_LINES_DISABLED
, OnUpdateViewDetectMovedOrCopiedLinesToggleDisabled
)
73 ON_COMMAND(ID_VIEW_DETECT_MOVED_OR_COPIED_LINES_WITHIN_FILE
, OnViewDetectMovedOrCopiedLinesToggleWithinFile
)
74 ON_UPDATE_COMMAND_UI(ID_VIEW_DETECT_MOVED_OR_COPIED_LINES_WITHIN_FILE
, OnUpdateViewDetectMovedOrCopiedLinesToggleWithinFile
)
75 ON_COMMAND(ID_VIEW_DETECT_MOVED_OR_COPIED_LINES_FROM_MODIFIED_FILES
, OnViewDetectMovedOrCopiedLinesToggleFromModifiedFiles
)
76 ON_UPDATE_COMMAND_UI(ID_VIEW_DETECT_MOVED_OR_COPIED_LINES_FROM_MODIFIED_FILES
, OnUpdateViewDetectMovedOrCopiedLinesToggleFromModifiedFiles
)
77 ON_COMMAND(ID_VIEW_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES_AT_FILE_CREATION
, OnViewDetectMovedOrCopiedLinesToggleFromExistingFilesAtFileCreation
)
78 ON_UPDATE_COMMAND_UI(ID_VIEW_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES_AT_FILE_CREATION
, OnUpdateViewDetectMovedOrCopiedLinesToggleFromExistingFilesAtFileCreation
)
79 ON_COMMAND(ID_VIEW_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES
, OnViewDetectMovedOrCopiedLinesToggleFromExistingFiles
)
80 ON_UPDATE_COMMAND_UI(ID_VIEW_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES
, OnUpdateViewDetectMovedOrCopiedLinesToggleFromExistingFiles
)
81 ON_COMMAND(ID_VIEW_IGNORE_WHITESPACE
, OnViewToggleIgnoreWhitespace
)
82 ON_UPDATE_COMMAND_UI(ID_VIEW_IGNORE_WHITESPACE
, OnUpdateViewToggleIgnoreWhitespace
)
83 ON_COMMAND(ID_VIEW_FOLLOWRENAMES
, OnViewToggleFollowRenames
)
84 ON_UPDATE_COMMAND_UI(ID_VIEW_FOLLOWRENAMES
, OnUpdateViewToggleFollowRenames
)
85 ON_COMMAND(ID_VIEW_COLORBYAGE
, OnViewToggleColorByAge
)
86 ON_UPDATE_COMMAND_UI(ID_VIEW_COLORBYAGE
, OnUpdateViewToggleColorByAge
)
87 ON_COMMAND_RANGE(IDM_FORMAT_ENCODE
, IDM_FORMAT_ENCODE_END
, OnChangeEncode
)
96 ON_NOTIFY(SCN_PAINTED
, IDC_SCINTILLA
, OnSciPainted
)
97 ON_NOTIFY(SCN_GETBKCOLOR
, IDC_SCINTILLA
, OnSciGetBkColor
)
98 ON_REGISTERED_MESSAGE(m_FindDialogMessage
, OnFindDialogMessage
)
102 // CTortoiseGitBlameView construction/destruction
104 CTortoiseGitBlameView::CTortoiseGitBlameView()
109 , bIgnoreSpaces(false)
110 , bIgnoreAllSpaces(false)
128 m_windowcolor
= ::GetSysColor(COLOR_WINDOW
);
129 m_textcolor
= ::GetSysColor(COLOR_WINDOWTEXT
);
130 m_texthighlightcolor
= ::GetSysColor(COLOR_HIGHLIGHTTEXT
);
131 m_mouserevcolor
= InterColor(m_windowcolor
, m_textcolor
, 20);
132 m_mouseauthorcolor
= InterColor(m_windowcolor
, m_textcolor
, 10);
133 m_selectedrevcolor
= ::GetSysColor(COLOR_HIGHLIGHT
);
134 m_selectedauthorcolor
= InterColor(m_selectedrevcolor
, m_texthighlightcolor
, 35);
138 m_selectedorigrev
= -1;
141 m_directFunction
= 0;
143 m_lowestrev
= LONG_MAX
;
145 m_colorage
= !!theApp
.GetInt(_T("ColorAge"));
149 m_bShowAuthor
= (theApp
.GetInt(_T("ShowAuthor"), 1) == 1);
150 m_bShowDate
= (theApp
.GetInt(_T("ShowDate"), 0) == 1);
151 m_dwDetectMovedOrCopiedLines
= theApp
.GetInt(_T("DetectMovedOrCopiedLines"), 0);
152 m_bIgnoreWhitespace
= (theApp
.GetInt(_T("IgnoreWhitespace"), 0) == 1);
153 m_bFollowRenames
= (theApp
.GetInt(_T("FollowRenames"), 0) == 1);
155 m_FindDialogMessage
= ::RegisterWindowMessage(FINDMSGSTRING
);
156 m_pFindDialog
= NULL
;
157 // get short/long datetime setting from registry
158 DWORD RegUseShortDateFormat
= CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE
);
159 if ( RegUseShortDateFormat
)
161 m_DateFormat
= DATE_SHORTDATE
;
165 m_DateFormat
= DATE_LONGDATE
;
167 // get relative time display setting from registry
168 DWORD regRelativeTimes
= CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE
);
169 m_bRelativeTimes
= (regRelativeTimes
!= 0);
171 m_sRev
.LoadString(IDS_LOG_REVISION
);
172 m_sFileName
.LoadString(IDS_FILENAME
);
173 m_sAuthor
.LoadString(IDS_LOG_AUTHOR
);
174 m_sDate
.LoadString(IDS_LOG_DATE
);
175 m_sMessage
.LoadString(IDS_LOG_MESSAGE
);
177 #ifdef USE_TEMPFILENAME
182 CTortoiseGitBlameView::~CTortoiseGitBlameView()
185 DeleteObject(m_font
);
187 DeleteObject(m_italicfont
);
189 #ifdef USE_TEMPFILENAME
203 static EncodingUnit encodings
[] = {
204 {1250, "windows-1250"}, //IDM_FORMAT_WIN_1250
205 {1251, "windows-1251"}, //IDM_FORMAT_WIN_1251
206 {1252, "windows-1252"}, //IDM_FORMAT_WIN_1252
207 {1253, "windows-1253"}, //IDM_FORMAT_WIN_1253
208 {1254, "windows-1254"}, //IDM_FORMAT_WIN_1254
209 {1255, "windows-1255"}, //IDM_FORMAT_WIN_1255
210 {1256, "windows-1256"}, //IDM_FORMAT_WIN_1256
211 {1257, "windows-1257"}, //IDM_FORMAT_WIN_1257
212 {1258, "windows-1258"}, //IDM_FORMAT_WIN_1258
213 {28591, "latin1 ISO_8859-1 ISO-8859-1 CP819 IBM819 csISOLatin1 iso-ir-100 l1"}, //IDM_FORMAT_ISO_8859_1
214 {28592, "latin2 ISO_8859-2 ISO-8859-2 csISOLatin2 iso-ir-101 l2"}, //IDM_FORMAT_ISO_8859_2
215 {28593, "latin3 ISO_8859-3 ISO-8859-3 csISOLatin3 iso-ir-109 l3"}, //IDM_FORMAT_ISO_8859_3
216 {28594, "latin4 ISO_8859-4 ISO-8859-4 csISOLatin4 iso-ir-110 l4"}, //IDM_FORMAT_ISO_8859_4
217 {28595, "cyrillic ISO_8859-5 ISO-8859-5 csISOLatinCyrillic iso-ir-144"}, //IDM_FORMAT_ISO_8859_5
218 {28596, "arabic ISO_8859-6 ISO-8859-6 csISOLatinArabic iso-ir-127 ASMO-708 ECMA-114"}, //IDM_FORMAT_ISO_8859_6
219 {28597, "greek ISO_8859-7 ISO-8859-7 csISOLatinGreek greek8 iso-ir-126 ELOT_928 ECMA-118"}, //IDM_FORMAT_ISO_8859_7
220 {28598, "hebrew ISO_8859-8 ISO-8859-8 csISOLatinHebrew iso-ir-138"}, //IDM_FORMAT_ISO_8859_8
221 {28599, "latin5 ISO_8859-9 ISO-8859-9 csISOLatin5 iso-ir-148 l5"}, //IDM_FORMAT_ISO_8859_9
222 {28600, "latin6 ISO_8859-10 ISO-8859-10 csISOLatin6 iso-ir-157 l6"}, //IDM_FORMAT_ISO_8859_10
223 {28601, "ISO_8859-11 ISO-8859-11"}, //IDM_FORMAT_ISO_8859_11
224 {28603, "ISO_8859-13 ISO-8859-13"}, //IDM_FORMAT_ISO_8859_13
225 {28604, "iso-celtic latin8 ISO_8859-14 ISO-8859-14 18 iso-ir-199"}, //IDM_FORMAT_ISO_8859_14
226 {28605, "Latin-9 ISO_8859-15 ISO-8859-15"}, //IDM_FORMAT_ISO_8859_15
227 {28606, "latin10 ISO_8859-16 ISO-8859-16 110 iso-ir-226"}, //IDM_FORMAT_ISO_8859_16
228 {437, "IBM437 cp437 437 csPC8CodePage437"}, //IDM_FORMAT_DOS_437
229 {720, "IBM720 cp720 oem720 720"}, //IDM_FORMAT_DOS_720
230 {737, "IBM737 cp737 oem737 737"}, //IDM_FORMAT_DOS_737
231 {775, "IBM775 cp775 oem775 775"}, //IDM_FORMAT_DOS_775
232 {850, "IBM850 cp850 oem850 850"}, //IDM_FORMAT_DOS_850
233 {852, "IBM852 cp852 oem852 852"}, //IDM_FORMAT_DOS_852
234 {855, "IBM855 cp855 oem855 855 csIBM855"}, //IDM_FORMAT_DOS_855
235 {857, "IBM857 cp857 oem857 857"}, //IDM_FORMAT_DOS_857
236 {858, "IBM858 cp858 oem858 858"}, //IDM_FORMAT_DOS_858
237 {860, "IBM860 cp860 oem860 860"}, //IDM_FORMAT_DOS_860
238 {861, "IBM861 cp861 oem861 861"}, //IDM_FORMAT_DOS_861
239 {862, "IBM862 cp862 oem862 862"}, //IDM_FORMAT_DOS_862
240 {863, "IBM863 cp863 oem863 863"}, //IDM_FORMAT_DOS_863
241 {865, "IBM865 cp865 oem865 865"}, //IDM_FORMAT_DOS_865
242 {866, "IBM866 cp866 oem866 866"}, //IDM_FORMAT_DOS_866
243 {869, "IBM869 cp869 oem869 869"}, //IDM_FORMAT_DOS_869
244 {950, "big5 csBig5"}, //IDM_FORMAT_BIG5
245 {936, "gb2312 gbk csGB2312"}, //IDM_FORMAT_GB2312
246 {932, "Shift_JIS MS_Kanji csShiftJIS csWindows31J"}, //IDM_FORMAT_SHIFT_JIS
247 {949, "windows-949 korean"}, //IDM_FORMAT_KOREAN_WIN
248 {51949, "euc-kr csEUCKR"}, //IDM_FORMAT_EUC_KR
249 {874, "tis-620"}, //IDM_FORMAT_TIS_620
250 {10007, "x-mac-cyrillic xmaccyrillic"}, //IDM_FORMAT_MAC_CYRILLIC
251 {21866, "koi8_u"}, //IDM_FORMAT_KOI8U_CYRILLIC
252 {20866, "koi8_r csKOI8R"}, //IDM_FORMAT_KOI8R_CYRILLIC
253 {65001, "UTF-8"}, //IDM_FORMAT_UTF8
254 {1200, "UTF-16 LE"}, //IDM_FORMAT_UTF16LE
255 {1201, "UTF-16 BE"}, //IDM_FORMAT_UTF16BE
257 void CTortoiseGitBlameView::OnChangeEncode(UINT nId
)
259 if(nId
>= IDM_FORMAT_ENCODE
&& nId
<= IDM_FORMAT_ENCODE_END
)
260 this->UpdateInfo(encodings
[nId
- IDM_FORMAT_ENCODE
].id
);
262 int CTortoiseGitBlameView::OnCreate(LPCREATESTRUCT lpcs
)
266 this->GetWindowRect(&rect1
);
267 rect
.left
=m_blamewidth
+LOCATOR_WIDTH
;
268 rect
.right
=rect
.Width();
270 rect
.bottom
=rect
.Height();
271 if (!m_TextView
.Create(_T("Scintilla"), _T("source"), 0, rect
, this, IDC_SCINTILLA
, 0))
273 TRACE0("Failed to create view\n");
274 return -1; // fail to create
276 m_TextView
.Init(0,FALSE
);
277 m_TextView
.ShowWindow( SW_SHOW
);
278 m_wEditor
= m_TextView
.m_hWnd
;
281 m_ToolTip
.Create(this->GetParent());
283 ::AfxGetApp()->GetMainWnd();
284 return CView::OnCreate(lpcs
);
288 void CTortoiseGitBlameView::OnSize(UINT
/*nType*/, int cx
, int cy
)
292 rect
.left
=m_blamewidth
;
297 m_TextView
.MoveWindow(&rect
);
300 BOOL
CTortoiseGitBlameView::PreCreateWindow(CREATESTRUCT
& cs
)
302 return CView::PreCreateWindow(cs
);
305 // CTortoiseGitBlameView drawing
307 void CTortoiseGitBlameView::OnDraw(CDC
* /*pDC*/)
309 CTortoiseGitBlameDoc
* pDoc
= GetDocument();
314 DrawBlame(this->GetDC()->m_hDC
);
315 DrawLocatorBar(this->GetDC()->m_hDC
);
316 // TODO: add draw code for native data here
320 // CTortoiseGitBlameView printing
323 void CTortoiseGitBlameView::OnFilePrintPreview()
325 AFXPrintPreview(this);
328 BOOL
CTortoiseGitBlameView::OnPreparePrinting(CPrintInfo
* pInfo
)
330 // default preparation
331 return DoPreparePrinting(pInfo
);
334 void CTortoiseGitBlameView::OnBeginPrinting(CDC
* /*pDC*/, CPrintInfo
* /*pInfo*/)
336 // TODO: add extra initialization before printing
339 void CTortoiseGitBlameView::OnEndPrinting(CDC
* /*pDC*/, CPrintInfo
* /*pInfo*/)
341 // TODO: add cleanup after printing
344 void CTortoiseGitBlameView::OnRButtonUp(UINT
/*nFlags*/, CPoint point
)
346 int line
= (int)SendEditor(SCI_GETFIRSTVISIBLELINE
);
347 LONG_PTR height
= SendEditor(SCI_TEXTHEIGHT
);
348 line
= line
+ (int)(point
.y
/ height
);
349 if (m_data
.IsValidLine(line
))
351 m_MouseLine
= (LONG
)line
;
352 ClientToScreen(&point
);
354 CGitHash hash
= m_data
.GetHash(line
);
355 CString hashStr
= hash
.ToString();
357 GitRev
* pRev
= &GetLogData()->GetGitRevAt(m_lineToLogIndex
[line
]);
362 CIconMenu blamemenu
, diffmenu
;
364 if (!popup
.CreatePopupMenu())
367 // Now find the relevant parent commits, they must contain the file which is blamed to be the source of the selected line,
368 // otherwise there is no previous file to compare to (only another previous revision).
370 GIT_REV_LIST parentHashWithFile
;
371 std::vector
<CString
> parentFilename
;
374 CTGitPath
path(m_data
.GetFilename(line
));
375 const CTGitPathList
& files
= pRev
->GetFiles(NULL
);
376 for (int j
= 0, j_size
= files
.GetCount(); j
< j_size
; ++j
)
378 const CTGitPath
&file
= files
[j
];
379 if (file
.IsEquivalentTo(path
))
381 if (!(file
.m_ParentNo
& MERGE_MASK
))
383 int action
= file
.m_Action
;
384 // ignore (action & CTGitPath::LOGACTIONS_ADDED), as then there is nothing to blame/diff
385 // ignore (action & CTGitPath::LOGACTIONS_DELETED), should never happen as the file must exist
386 if (action
& (CTGitPath::LOGACTIONS_MODIFIED
| CTGitPath::LOGACTIONS_REPLACED
))
388 int parentNo
= file
.m_ParentNo
& PARENT_MASK
;
389 parentHashWithFile
.push_back(pRev
->m_ParentHash
[parentNo
]);
390 parentFilename
.push_back((action
& CTGitPath::LOGACTIONS_REPLACED
) ? file
.GetGitOldPathString() : file
.GetGitPathString());
396 catch (const char* msg
)
398 MessageBox(_T("Could not get files of parents.\nlibgit reports:\n") + CString(msg
), _T("TortoiseGit"), MB_ICONERROR
);
402 if (!parentHashWithFile
.empty())
404 if (parentHashWithFile
.size() == 1)
406 popup
.AppendMenuIcon(ID_BLAMEPREVIOUS
, IDS_BLAME_POPUP_BLAME
, IDI_BLAME_POPUP_BLAME
);
410 blamemenu
.CreatePopupMenu();
411 popup
.AppendMenuIcon(ID_BLAMEPREVIOUS
, IDS_BLAME_POPUP_BLAME
, IDI_BLAME_POPUP_BLAME
, blamemenu
.m_hMenu
);
413 for (size_t i
= 0; i
< parentHashWithFile
.size(); ++i
)
416 str
.Format(IDS_PARENT
, i
+ 1);
417 blamemenu
.AppendMenuIcon(ID_BLAMEPREVIOUS
+ ((i
+ 1) << 16), str
);
422 // compare with previous
423 if (!parentHashWithFile
.empty())
425 if (parentHashWithFile
.size() == 1)
427 popup
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
, IDS_BLAME_POPUP_COMPARE
, IDI_BLAME_POPUP_COMPARE
);
428 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
429 popup
.SetDefaultItem(ID_COMPAREWITHPREVIOUS
, FALSE
);
433 diffmenu
.CreatePopupMenu();
434 popup
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
, IDS_BLAME_POPUP_COMPARE
, IDI_BLAME_POPUP_COMPARE
, diffmenu
.m_hMenu
);
435 for (size_t i
= 0; i
< parentHashWithFile
.size(); ++i
)
438 str
.Format(IDS_BLAME_POPUP_PARENT
, i
+ 1);
439 diffmenu
.AppendMenuIcon((UINT
)(ID_COMPAREWITHPREVIOUS
+ ((i
+ 1) << 16)),str
);
440 if (i
== 0 && CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
442 popup
.SetDefaultItem(ID_COMPAREWITHPREVIOUS
, FALSE
);
443 diffmenu
.SetDefaultItem((UINT
)(ID_COMPAREWITHPREVIOUS
+ ((i
+ 1) << 16)), FALSE
);
449 popup
.AppendMenuIcon(ID_SHOWLOG
, IDS_BLAME_POPUP_LOG
);
450 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
451 popup
.AppendMenuIcon(ID_COPYHASHTOCLIPBOARD
, IDS_BLAME_POPUP_COPYHASHTOCLIPBOARD
);
452 popup
.AppendMenuIcon(ID_COPYLOGTOCLIPBOARD
, IDS_BLAME_POPUP_COPYLOGTOCLIPBOARD
);
454 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, this, 0);
455 this->ContextMenuAction(cmd
, pRev
, parentHashWithFile
, parentFilename
);
459 void CTortoiseGitBlameView::ContextMenuAction(int cmd
, GitRev
*pRev
, GIT_REV_LIST
& parentHashWithFile
, const std::vector
<CString
>& parentFilename
)
461 switch (cmd
& 0xFFFF)
463 case ID_BLAMEPREVIOUS
:
465 int index
= (cmd
>>16) & 0xFFFF;
469 CString path
= ResolveCommitFile(parentFilename
[index
]);
470 CString endrev
= parentHashWithFile
[index
].ToString();
471 LONG line
= m_data
.GetOriginalLineNumber(m_MouseLine
);
473 lineNumber
.Format(_T("%d"), line
);
475 CString procCmd
= _T("/path:\"") + path
+ _T("\" ");
476 procCmd
+= _T(" /command:blame");
477 procCmd
+= _T(" /endrev:") + endrev
;
478 procCmd
+= _T(" /line:") + lineNumber
;
480 CCommonAppUtils::RunTortoiseGitProc(procCmd
);
484 case ID_COMPAREWITHPREVIOUS
:
486 int index
= (cmd
>> 16) & 0xFFFF;
490 CString path
= ResolveCommitFile(parentFilename
[index
]);
491 CString startrev
= pRev
->m_CommitHash
.ToString();
492 CString endrev
= parentHashWithFile
[index
].ToString();
494 CString procCmd
= _T("/path:\"") + path
+ _T("\" ");
495 procCmd
+= _T(" /command:diff");
496 procCmd
+= _T(" /startrev:") + startrev
;
497 procCmd
+= _T(" /endrev:") + endrev
;
499 CCommonAppUtils::RunTortoiseGitProc(procCmd
);
505 CString path
= ResolveCommitFile(m_MouseLine
);
506 CString rev
= m_data
.GetHash(m_MouseLine
).ToString();
508 CString procCmd
= _T("/path:\"") + path
+ _T("\" ");
509 procCmd
+= _T(" /command:log");
510 procCmd
+= _T(" /rev:") + rev
;
512 CCommonAppUtils::RunTortoiseGitProc(procCmd
);
516 case ID_COPYHASHTOCLIPBOARD
:
517 this->GetLogList()->CopySelectionToClipBoard(CGitLogListBase::ID_COPY_HASH
);
520 case ID_COPYLOGTOCLIPBOARD
:
521 this->GetLogList()->CopySelectionToClipBoard();
526 // CTortoiseGitBlameView diagnostics
529 void CTortoiseGitBlameView::AssertValid() const
531 CView::AssertValid();
534 void CTortoiseGitBlameView::Dump(CDumpContext
& dc
) const
539 CTortoiseGitBlameDoc
* CTortoiseGitBlameView::GetDocument() const // non-debug version is inline
541 ASSERT(m_pDocument
->IsKindOf(RUNTIME_CLASS(CTortoiseGitBlameDoc
)));
542 return (CTortoiseGitBlameDoc
*)m_pDocument
;
547 // CTortoiseGitBlameView message handlers
548 CString
CTortoiseGitBlameView::GetAppDirectory()
552 DWORD bufferlen
= MAX_PATH
; // MAX_PATH is not the limit here!
555 bufferlen
+= MAX_PATH
; // MAX_PATH is not the limit here!
556 std::unique_ptr
<TCHAR
[]> pBuf(new TCHAR
[bufferlen
]);
557 len
= GetModuleFileName(NULL
, pBuf
.get(), bufferlen
);
558 path
= CString(pBuf
.get(), len
);
559 } while(len
== bufferlen
);
561 path
= path
.Left(path
.ReverseFind(_T('\\')));
562 //path = path.substr(0, path.rfind('\\') + 1);
567 // Return a color which is interpolated between c1 and c2.
568 // Slider controls the relative proportions as a percentage:
569 // Slider = 0 represents pure c1
570 // Slider = 50 represents equal mixture
571 // Slider = 100 represents pure c2
572 COLORREF
CTortoiseGitBlameView::InterColor(COLORREF c1
, COLORREF c2
, int Slider
)
576 // Limit Slider to 0..100% range
582 // The color components have to be treated individually.
583 r
= (GetRValue(c2
) * Slider
+ GetRValue(c1
) * (100 - Slider
)) / 100;
584 g
= (GetGValue(c2
) * Slider
+ GetGValue(c1
) * (100 - Slider
)) / 100;
585 b
= (GetBValue(c2
) * Slider
+ GetBValue(c1
) * (100 - Slider
)) / 100;
590 LRESULT
CTortoiseGitBlameView::SendEditor(UINT Msg
, WPARAM wParam
, LPARAM lParam
)
592 if (m_directFunction
)
594 return ((SciFnDirect
) m_directFunction
)(m_directPointer
, Msg
, wParam
, lParam
);
596 return ::SendMessage(m_wEditor
, Msg
, wParam
, lParam
);
599 void CTortoiseGitBlameView::SetAStyle(int style
, COLORREF fore
, COLORREF back
, int size
, CString
*face
)
601 SendEditor(SCI_STYLESETFORE
, style
, fore
);
602 SendEditor(SCI_STYLESETBACK
, style
, back
);
604 SendEditor(SCI_STYLESETSIZE
, style
, size
);
606 SendEditor(SCI_STYLESETFONT
, style
, reinterpret_cast<LPARAM
>(this->m_TextView
.StringForControl(*face
).GetBuffer()));
609 void CTortoiseGitBlameView::InitialiseEditor()
612 m_directFunction
= ::SendMessage(m_wEditor
, SCI_GETDIRECTFUNCTION
, 0, 0);
613 m_directPointer
= ::SendMessage(m_wEditor
, SCI_GETDIRECTPOINTER
, 0, 0);
614 // Set up the global default style. These attributes are used wherever no explicit choices are made.
615 CString
fontName(((stdstring
)CRegStdString(_T("Software\\TortoiseGit\\BlameFontName"), _T("Courier New"))).c_str());
616 SetAStyle(STYLE_DEFAULT
,
619 (DWORD
)CRegStdDWORD(_T("Software\\TortoiseGit\\BlameFontSize"), 10),
622 SendEditor(SCI_SETTABWIDTH
, (DWORD
)CRegStdDWORD(_T("Software\\TortoiseGit\\BlameTabSize"), 4));
623 SendEditor(SCI_SETREADONLY
, TRUE
);
624 LRESULT pix
= SendEditor(SCI_TEXTWIDTH
, STYLE_LINENUMBER
, (LPARAM
)this->m_TextView
.StringForControl(_T("_99999")).GetBuffer());
626 SendEditor(SCI_SETMARGINWIDTHN
, 0, pix
);
628 SendEditor(SCI_SETMARGINWIDTHN
, 0);
629 SendEditor(SCI_SETMARGINWIDTHN
, 1);
630 SendEditor(SCI_SETMARGINWIDTHN
, 2);
631 //Set the default windows colors for edit controls
632 SendEditor(SCI_STYLESETFORE
, STYLE_DEFAULT
, ::GetSysColor(COLOR_WINDOWTEXT
));
633 SendEditor(SCI_STYLESETBACK
, STYLE_DEFAULT
, ::GetSysColor(COLOR_WINDOW
));
634 SendEditor(SCI_SETSELFORE
, TRUE
, ::GetSysColor(COLOR_HIGHLIGHTTEXT
));
635 SendEditor(SCI_SETSELBACK
, TRUE
, ::GetSysColor(COLOR_HIGHLIGHT
));
636 SendEditor(SCI_SETCARETFORE
, ::GetSysColor(COLOR_WINDOWTEXT
));
637 m_regOldLinesColor
= CRegStdDWORD(_T("Software\\TortoiseGit\\BlameOldColor"), BLAMEOLDCOLOR
);
638 m_regNewLinesColor
= CRegStdDWORD(_T("Software\\TortoiseGit\\BlameNewColor"), BLAMENEWCOLOR
);
639 CRegStdDWORD
used2d(L
"Software\\TortoiseGit\\ScintillaDirect2D", FALSE
);
640 if (SysInfo::Instance().IsWin7OrLater() && DWORD(used2d
))
642 SendEditor(SCI_SETTECHNOLOGY
, SC_TECHNOLOGY_DIRECTWRITE
);
643 SendEditor(SCI_SETBUFFEREDDRAW
, 0);
646 this->m_TextView
.Call(SCI_SETWRAPMODE
, SC_WRAP_NONE
);
650 bool CTortoiseGitBlameView::DoSearch(CString what
, DWORD flags
)
652 int pos
= (int)SendEditor(SCI_GETCURRENTPOS
);
653 int line
= (int)SendEditor(SCI_LINEFROMPOSITION
, pos
);
654 bool bCaseSensitive
= !!(flags
& FR_MATCHCASE
);
655 theApp
.WriteInt(_T("FindMatchCase"), bCaseSensitive
? 1 : 0);
656 theApp
.WriteString(_T("FindString"), what
);
658 int i
= m_data
.FindFirstLineWrapAround(what
, line
, bCaseSensitive
);
662 int selstart
= (int)SendEditor(SCI_GETCURRENTPOS
);
663 int selend
= (int)SendEditor(SCI_POSITIONFROMLINE
, i
+ 1);
664 SendEditor(SCI_SETSELECTIONSTART
, selstart
);
665 SendEditor(SCI_SETSELECTIONEND
, selend
);
670 ::MessageBox(wMain
, _T("\"") + what
+ _T("\" ") + CString(MAKEINTRESOURCE(IDS_NOTFOUND
)), _T("TortoiseGitBlame"), MB_ICONINFORMATION
);
676 bool CTortoiseGitBlameView::GotoLine(long line
)
679 int numberOfLines
= m_data
.GetNumberOfLines();
680 if (line
< 0 || numberOfLines
== 0)
682 if (line
>= numberOfLines
)
684 line
= numberOfLines
- 1;
687 int nCurrentPos
= (int)SendEditor(SCI_GETCURRENTPOS
);
688 int nCurrentLine
= (int)SendEditor(SCI_LINEFROMPOSITION
,nCurrentPos
);
689 int nFirstVisibleLine
= (int)SendEditor(SCI_GETFIRSTVISIBLELINE
);
690 int nLinesOnScreen
= (int)SendEditor(SCI_LINESONSCREEN
);
692 if ( line
>=nFirstVisibleLine
&& line
<=nFirstVisibleLine
+nLinesOnScreen
)
695 SendEditor(SCI_GOTOLINE
, line
);
699 // Place the requested line one third from the top
700 if ( line
> nCurrentLine
)
702 SendEditor(SCI_GOTOLINE
, (WPARAM
)(line
+(int)nLinesOnScreen
*(2/3.0)));
706 SendEditor(SCI_GOTOLINE
, (WPARAM
)(line
-(int)nLinesOnScreen
*(1/3.0)));
710 // Highlight the line
711 int nPosStart
= (int)SendEditor(SCI_POSITIONFROMLINE
,line
);
712 int nPosEnd
= (int)SendEditor(SCI_GETLINEENDPOSITION
,line
);
713 SendEditor(SCI_SETSEL
,nPosEnd
,nPosStart
);
718 bool CTortoiseGitBlameView::ScrollToLine(long line
)
723 int nCurrentLine
= (int)SendEditor(SCI_GETFIRSTVISIBLELINE
);
725 int scrolldelta
= line
- nCurrentLine
;
726 SendEditor(SCI_LINESCROLL
, 0, scrolldelta
);
731 void CTortoiseGitBlameView::CopyToClipboard()
733 CWnd
* wnd
= GetFocus();
734 if (wnd
== this->GetLogList())
735 GetLogList()->CopySelectionToClipBoard();
738 if (CString(wnd
->GetRuntimeClass()->m_lpszClassName
) == _T("CMFCPropertyGridCtrl"))
740 CMFCPropertyGridCtrl
*grid
= (CMFCPropertyGridCtrl
*)wnd
;
741 if (grid
->GetCurSel() && !grid
->GetCurSel()->IsGroup())
742 CStringUtils::WriteAsciiStringToClipboard(grid
->GetCurSel()->GetValue(), GetSafeHwnd());
745 m_TextView
.Call(SCI_COPY
);
749 LONG
CTortoiseGitBlameView::GetBlameWidth()
754 HDC hDC
= this->GetDC()->m_hDC
;
755 HFONT oldfont
= (HFONT
)::SelectObject(hDC
, m_font
);
757 CString
shortHash('f', g_Git
.GetShortHASHLength() + 1);
758 ::GetTextExtentPoint32(hDC
, shortHash
, g_Git
.GetShortHASHLength() + 1, &width
);
759 m_revwidth
= width
.cx
+ BLAMESPACE
;
760 blamewidth
+= m_revwidth
;
766 int numberOfLines
= m_data
.GetNumberOfLines();
767 for (int i
= 0; i
< numberOfLines
; ++i
)
769 ::GetTextExtentPoint32(hDC
, m_data
.GetDate(i
), m_data
.GetDate(i
).GetLength(), &width
);
770 if (width
.cx
> maxwidth
.cx
)
773 m_datewidth
= maxwidth
.cx
+ BLAMESPACE
;
774 blamewidth
+= m_datewidth
;
780 int numberOfLines
= m_data
.GetNumberOfLines();
781 for (int i
= 0; i
< numberOfLines
; ++i
)
783 ::GetTextExtentPoint32(hDC
,m_data
.GetAuthor(i
) , m_data
.GetAuthor(i
).GetLength(), &width
);
784 if (width
.cx
> maxwidth
.cx
)
787 m_authorwidth
= maxwidth
.cx
+ BLAMESPACE
;
788 blamewidth
+= m_authorwidth
;
790 ::SelectObject(hDC
, oldfont
);
791 POINT pt
= {blamewidth
, 0};
794 //::ReleaseDC(wBlame, hDC);
799 void CTortoiseGitBlameView::CreateFont()
805 HDC hDC
= ::GetDC(wBlame
);
806 lf
.lfHeight
= -MulDiv((DWORD
)CRegStdDWORD(_T("Software\\TortoiseGit\\BlameFontSize"), 10), GetDeviceCaps(hDC
, LOGPIXELSY
), 72);
807 lf
.lfCharSet
= DEFAULT_CHARSET
;
808 CRegStdString fontname
= CRegStdString(_T("Software\\TortoiseGit\\BlameFontName"), _T("Courier New"));
809 _tcscpy_s(lf
.lfFaceName
, 32, ((stdstring
)fontname
).c_str());
810 m_font
= ::CreateFontIndirect(&lf
);
813 m_italicfont
= ::CreateFontIndirect(&lf
);
815 ::ReleaseDC(wBlame
, hDC
);
818 void CTortoiseGitBlameView::DrawBlame(HDC hDC
)
825 HFONT oldfont
= NULL
;
826 int line
= (int)SendEditor(SCI_GETFIRSTVISIBLELINE
);
827 int linesonscreen
= (int)SendEditor(SCI_LINESONSCREEN
);
828 LONG_PTR height
= SendEditor(SCI_TEXTHEIGHT
);
833 //::GetClientRect(this->m_hWnd, &rc);
834 for (int i
= line
; i
< (line
+ linesonscreen
); ++i
)
837 if (i
< m_data
.GetNumberOfLines())
839 CGitHash
hash(m_data
.GetHash(i
));
840 // if (mergelines[i])
841 // oldfont = (HFONT)::SelectObject(hDC, m_italicfont);
843 oldfont
= (HFONT
)::SelectObject(hDC
, m_font
);
844 ::SetBkColor(hDC
, m_windowcolor
);
845 ::SetTextColor(hDC
, m_textcolor
);
848 //if (m_CommitHash[i].Compare(m_MouseHash)==0)
849 // ::SetBkColor(hDC, m_mouseauthorcolor);
850 if (hash
== m_SelectedHash
)
852 ::SetBkColor(hDC
, m_selectedauthorcolor
);
853 ::SetTextColor(hDC
, m_texthighlightcolor
);
859 ::SetBkColor(hDC
, m_mouserevcolor
);
861 //if ((revs[i] == m_mouserev)&&(!sel))
862 // ::SetBkColor(hDC, m_mouserevcolor);
863 //if (revs[i] == m_selectedrev)
865 // ::SetBkColor(hDC, m_selectedrevcolor);
866 // ::SetTextColor(hDC, m_texthighlightcolor);
869 CString shortHashStr
;
870 shortHashStr
= hash
.ToString().Left(g_Git
.GetShortHASHLength());
872 //_stprintf_s(buf, MAX_PATH, _T("%8ld "), revs[i]);
874 rc
.left
=LOCATOR_WIDTH
;
875 rc
.bottom
= (LONG
)(Y
+ height
);
876 rc
.right
= rc
.left
+ m_blamewidth
;
877 ::ExtTextOut(hDC
, LOCATOR_WIDTH
, (int)Y
, ETO_CLIPPED
, &rc
, shortHashStr
, shortHashStr
.GetLength(), 0);
878 int Left
= m_revwidth
;
882 rc
.right
= rc
.left
+ Left
+ m_authorwidth
;
883 ::ExtTextOut(hDC
, Left
, (int)Y
, ETO_CLIPPED
, &rc
, m_data
.GetAuthor(i
), m_data
.GetAuthor(i
).GetLength(), 0);
884 Left
+= m_authorwidth
;
888 rc
.right
= rc
.left
+ Left
+ m_datewidth
;
889 ::ExtTextOut(hDC
, Left
, (int)Y
, ETO_CLIPPED
, &rc
, m_data
.GetDate(i
), m_data
.GetDate(i
).GetLength(), 0);
892 if ((i
==m_SelectedLine
)&&(m_pFindDialog
))
895 brush
.lbColor
= m_textcolor
;
897 brush
.lbStyle
= BS_SOLID
;
898 HPEN pen
= ExtCreatePen(PS_SOLID
| PS_GEOMETRIC
, 2, &brush
, 0, NULL
);
899 HGDIOBJ hPenOld
= SelectObject(hDC
, pen
);
902 rc2
.bottom
= (LONG
)(Y
+ height
);
903 ::MoveToEx(hDC
, rc2
.left
, rc2
.top
, NULL
);
904 ::LineTo(hDC
, rc2
.right
, rc2
.top
);
905 ::LineTo(hDC
, rc2
.right
, rc2
.bottom
);
906 ::LineTo(hDC
, rc2
.left
, rc2
.bottom
);
907 ::LineTo(hDC
, rc2
.left
, rc2
.top
);
908 SelectObject(hDC
, hPenOld
);
912 ::SelectObject(hDC
, oldfont
);
916 ::SetBkColor(hDC
, m_windowcolor
);
917 for (int j
=0; j
< MAX_PATH
; ++j
)
919 ::ExtTextOut(hDC
, 0, (int)Y
, ETO_CLIPPED
, &rc
, buf
, MAX_PATH
-1, 0);
925 void CTortoiseGitBlameView::DrawLocatorBar(HDC hDC
)
930 LONG_PTR line
= SendEditor(SCI_GETFIRSTVISIBLELINE
);
931 LONG_PTR linesonscreen
= SendEditor(SCI_LINESONSCREEN
);
933 COLORREF blackColor
= GetSysColor(COLOR_WINDOWTEXT
);
936 //::GetClientRect(wLocator, &rc);
937 this->GetClientRect(&rc
);
939 rc
.right
=LOCATOR_WIDTH
;
942 LONG height
= rc
.bottom
-rc
.top
;
944 LONG numberOfLines
= (LONG
)m_data
.GetNumberOfLines();
945 // draw the colored bar
946 for (LONG currentLine
= 0; currentLine
< numberOfLines
; ++currentLine
)
948 COLORREF cr
= GetLineColor(currentLine
);
949 // get the line color
950 if ((currentLine
>= line
)&&(currentLine
< (line
+ linesonscreen
)))
952 cr
= InterColor(cr
, blackColor
, 10);
955 lineRect
.top
= (LONG
)Y
;
956 lineRect
.bottom
= ((currentLine
+ 1) * height
/ numberOfLines
);
957 ::ExtTextOut(hDC
, 0, 0, ETO_OPAQUE
, &lineRect
, NULL
, 0, NULL
);
961 if (numberOfLines
> 0)
963 // now draw two lines indicating the scroll position of the source view
964 SetBkColor(hDC
, blackColor
);
965 lineRect
.top
= (LONG
)line
* height
/ numberOfLines
;
966 lineRect
.bottom
= lineRect
.top
+1;
967 ::ExtTextOut(hDC
, 0, 0, ETO_OPAQUE
, &lineRect
, NULL
, 0, NULL
);
968 lineRect
.top
= (LONG
)(line
+ linesonscreen
) * height
/ numberOfLines
;
969 lineRect
.bottom
= lineRect
.top
+1;
970 ::ExtTextOut(hDC
, 0, 0, ETO_OPAQUE
, &lineRect
, NULL
, 0, NULL
);
975 void CTortoiseGitBlameView::StringExpand(LPSTR str
)
980 cPos
= strchr(cPos
, '\n');
983 memmove(cPos
+1, cPos
, strlen(cPos
)*sizeof(char));
988 } while (cPos
!= NULL
);
990 void CTortoiseGitBlameView::StringExpand(LPWSTR str
)
992 wchar_t * cPos
= str
;
995 cPos
= wcschr(cPos
, '\n');
998 memmove(cPos
+1, cPos
, wcslen(cPos
)*sizeof(wchar_t));
1003 } while (cPos
!= NULL
);
1006 void CTortoiseGitBlameView::SetupLexer(CString filename
)
1008 int start
=filename
.ReverseFind(_T('.'));
1011 //_tcscpy_s(line, 20, lineptr+1);
1012 //_tcslwr_s(line, 20);
1013 CString ext
=filename
.Right(filename
.GetLength()-start
-1);
1014 TCHAR
* line
= ext
.GetBuffer();
1016 if ((_tcscmp(line
, _T("py"))==0)||
1017 (_tcscmp(line
, _T("pyw"))==0))
1019 SendEditor(SCI_SETLEXER
, SCLEX_PYTHON
);
1020 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("and assert break class continue def del elif \
1021 else except exec finally for from global if import in is lambda None \
1022 not or pass print raise return try while yield")).GetBuffer()));
1023 SetAStyle(SCE_P_DEFAULT
, black
);
1024 SetAStyle(SCE_P_COMMENTLINE
, darkGreen
);
1025 SetAStyle(SCE_P_NUMBER
, RGB(0, 0x80, 0x80));
1026 SetAStyle(SCE_P_STRING
, RGB(0, 0, 0x80));
1027 SetAStyle(SCE_P_CHARACTER
, RGB(0, 0, 0x80));
1028 SetAStyle(SCE_P_WORD
, RGB(0x80, 0, 0x80));
1029 SetAStyle(SCE_P_TRIPLE
, black
);
1030 SetAStyle(SCE_P_TRIPLEDOUBLE
, black
);
1031 SetAStyle(SCE_P_CLASSNAME
, darkBlue
);
1032 SetAStyle(SCE_P_DEFNAME
, darkBlue
);
1033 SetAStyle(SCE_P_OPERATOR
, darkBlue
);
1034 SetAStyle(SCE_P_IDENTIFIER
, darkBlue
);
1035 SetAStyle(SCE_P_COMMENTBLOCK
, darkGreen
);
1036 SetAStyle(SCE_P_STRINGEOL
, red
);
1038 if ((_tcscmp(line
, _T("c"))==0)||
1039 (_tcscmp(line
, _T("cc"))==0)||
1040 (_tcscmp(line
, _T("cpp"))==0)||
1041 (_tcscmp(line
, _T("cxx"))==0)||
1042 (_tcscmp(line
, _T("h"))==0)||
1043 (_tcscmp(line
, _T("hh"))==0)||
1044 (_tcscmp(line
, _T("hpp"))==0)||
1045 (_tcscmp(line
, _T("hxx"))==0)||
1046 (_tcscmp(line
, _T("dlg"))==0)||
1047 (_tcscmp(line
, _T("mak"))==0))
1049 SendEditor(SCI_SETLEXER
, SCLEX_CPP
);
1050 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("and and_eq asm auto bitand bitor bool break \
1051 case catch char class compl const const_cast continue \
1052 default delete do double dynamic_cast else enum explicit export extern false float for \
1053 friend goto if inline int long mutable namespace new not not_eq \
1054 operator or or_eq private protected public \
1055 register reinterpret_cast return short signed sizeof static static_cast struct switch \
1056 template this throw true try typedef typeid typename union unsigned using \
1057 virtual void volatile wchar_t while xor xor_eq")).GetBuffer()));
1058 SendEditor(SCI_SETKEYWORDS
, 3, (LPARAM
)(m_TextView
.StringForControl(_T("a addindex addtogroup anchor arg attention \
1059 author b brief bug c class code date def defgroup deprecated dontinclude \
1060 e em endcode endhtmlonly endif endlatexonly endlink endverbatim enum example exception \
1061 f$ f[ f] file fn hideinitializer htmlinclude htmlonly \
1062 if image include ingroup internal invariant interface latexonly li line link \
1063 mainpage name namespace nosubgrouping note overload \
1064 p page par param post pre ref relates remarks return retval \
1065 sa section see showinitializer since skip skipline struct subsection \
1066 test throw todo typedef union until \
1067 var verbatim verbinclude version warning weakgroup $ @ \\ & < > # { }")).GetBuffer()));
1070 if (_tcscmp(line
, _T("cs"))==0)
1072 SendEditor(SCI_SETLEXER
, SCLEX_CPP
);
1073 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("abstract as base bool break byte case catch char checked class \
1074 const continue decimal default delegate do double else enum \
1075 event explicit extern false finally fixed float for foreach goto if \
1076 implicit in int interface internal is lock long namespace new null \
1077 object operator out override params private protected public \
1078 readonly ref return sbyte sealed short sizeof stackalloc static \
1079 string struct switch this throw true try typeof uint ulong \
1080 unchecked unsafe ushort using virtual void while")).GetBuffer()));
1083 if ((_tcscmp(line
, _T("rc"))==0)||
1084 (_tcscmp(line
, _T("rc2"))==0))
1086 SendEditor(SCI_SETLEXER
, SCLEX_CPP
);
1087 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("ACCELERATORS ALT AUTO3STATE AUTOCHECKBOX AUTORADIOBUTTON \
1088 BEGIN BITMAP BLOCK BUTTON CAPTION CHARACTERISTICS CHECKBOX CLASS \
1089 COMBOBOX CONTROL CTEXT CURSOR DEFPUSHBUTTON DIALOG DIALOGEX DISCARDABLE \
1090 EDITTEXT END EXSTYLE FONT GROUPBOX ICON LANGUAGE LISTBOX LTEXT \
1091 MENU MENUEX MENUITEM MESSAGETABLE POPUP \
1092 PUSHBUTTON RADIOBUTTON RCDATA RTEXT SCROLLBAR SEPARATOR SHIFT STATE3 \
1093 STRINGTABLE STYLE TEXTINCLUDE VALUE VERSION VERSIONINFO VIRTKEY")).GetBuffer()));
1096 if ((_tcscmp(line
, _T("idl"))==0)||
1097 (_tcscmp(line
, _T("odl"))==0))
1099 SendEditor(SCI_SETLEXER
, SCLEX_CPP
);
1100 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("aggregatable allocate appobject arrays async async_uuid \
1102 bindable boolean broadcast byte byte_count \
1103 call_as callback char coclass code comm_status \
1104 const context_handle context_handle_noserialize \
1105 context_handle_serialize control cpp_quote custom \
1106 decode default defaultbind defaultcollelem \
1107 defaultvalue defaultvtable dispinterface displaybind dllname \
1109 enable_allocate encode endpoint entry enum error_status_t \
1111 fault_status first_is float \
1112 handle_t heap helpcontext helpfile helpstring \
1113 helpstringcontext helpstringdll hidden hyper \
1114 id idempotent ignore iid_as iid_is immediatebind implicit_handle \
1115 import importlib in include in_line int __int64 __int3264 interface \
1116 last_is lcid length_is library licensed local long \
1117 max_is maybe message methods midl_pragma \
1118 midl_user_allocate midl_user_free min_is module ms_union \
1119 ncacn_at_dsp ncacn_dnet_nsp ncacn_http ncacn_ip_tcp \
1120 ncacn_nb_ipx ncacn_nb_nb ncacn_nb_tcp ncacn_np \
1121 ncacn_spx ncacn_vns_spp ncadg_ip_udp ncadg_ipx ncadg_mq \
1122 ncalrpc nocode nonbrowsable noncreatable nonextensible notify \
1123 object odl oleautomation optimize optional out out_of_line \
1124 pipe pointer_default pragma properties propget propput propputref \
1126 range readonly ref represent_as requestedit restricted retval \
1127 shape short signed size_is small source strict_context_handle \
1128 string struct switch switch_is switch_type \
1129 transmit_as typedef \
1130 uidefault union unique unsigned user_marshal usesgetlasterror uuid \
1131 v1_enum vararg version void wchar_t wire_marshal")).GetBuffer()));
1134 if (_tcscmp(line
, _T("java"))==0)
1136 SendEditor(SCI_SETLEXER
, SCLEX_CPP
);
1137 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("abstract assert boolean break byte case catch char class \
1138 const continue default do double else extends final finally float for future \
1139 generic goto if implements import inner instanceof int interface long \
1140 native new null outer package private protected public rest \
1141 return short static super switch synchronized this throw throws \
1142 transient try var void volatile while")).GetBuffer()));
1145 if (_tcscmp(line
, _T("js"))==0)
1147 SendEditor(SCI_SETLEXER
, SCLEX_CPP
);
1148 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("abstract boolean break byte case catch char class \
1149 const continue debugger default delete do double else enum export extends \
1150 final finally float for function goto if implements import in instanceof \
1151 int interface long native new package private protected public \
1152 return short static super switch synchronized this throw throws \
1153 transient try typeof var void volatile while with")).GetBuffer()));
1156 if ((_tcscmp(line
, _T("pas"))==0)||
1157 (_tcscmp(line
, _T("dpr"))==0)||
1158 (_tcscmp(line
, _T("pp"))==0))
1160 SendEditor(SCI_SETLEXER
, SCLEX_PASCAL
);
1161 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("and array as begin case class const constructor \
1162 destructor div do downto else end except file finally \
1163 for function goto if implementation in inherited \
1164 interface is mod not object of on or packed \
1165 procedure program property raise record repeat \
1166 set shl shr then threadvar to try type unit \
1167 until uses var while with xor")).GetBuffer()));
1170 if ((_tcscmp(line
, _T("as"))==0)||
1171 (_tcscmp(line
, _T("asc"))==0)||
1172 (_tcscmp(line
, _T("jsfl"))==0))
1174 SendEditor(SCI_SETLEXER
, SCLEX_CPP
);
1175 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("add and break case catch class continue default delete do \
1176 dynamic else eq extends false finally for function ge get gt if implements import in \
1177 instanceof interface intrinsic le lt ne new not null or private public return \
1178 set static super switch this throw true try typeof undefined var void while with")).GetBuffer()));
1179 SendEditor(SCI_SETKEYWORDS
, 1, (LPARAM
)(m_TextView
.StringForControl(_T("Array Arguments Accessibility Boolean Button Camera Color \
1180 ContextMenu ContextMenuItem Date Error Function Key LoadVars LocalConnection Math \
1181 Microphone Mouse MovieClip MovieClipLoader NetConnection NetStream Number Object \
1182 PrintJob Selection SharedObject Sound Stage String StyleSheet System TextField \
1183 TextFormat TextSnapshot Video Void XML XMLNode XMLSocket \
1184 _accProps _focusrect _global _highquality _parent _quality _root _soundbuftime \
1185 arguments asfunction call capabilities chr clearInterval duplicateMovieClip \
1186 escape eval fscommand getProperty getTimer getURL getVersion gotoAndPlay gotoAndStop \
1187 ifFrameLoaded Infinity -Infinity int isFinite isNaN length loadMovie loadMovieNum \
1188 loadVariables loadVariablesNum maxscroll mbchr mblength mbord mbsubstring MMExecute \
1189 NaN newline nextFrame nextScene on onClipEvent onUpdate ord parseFloat parseInt play \
1190 prevFrame prevScene print printAsBitmap printAsBitmapNum printNum random removeMovieClip \
1191 scroll set setInterval setProperty startDrag stop stopAllSounds stopDrag substring \
1192 targetPath tellTarget toggleHighQuality trace unescape unloadMovie unLoadMovieNum updateAfterEvent")).GetBuffer()));
1195 if ((_tcscmp(line
, _T("html"))==0)||
1196 (_tcscmp(line
, _T("htm"))==0)||
1197 (_tcscmp(line
, _T("shtml"))==0)||
1198 (_tcscmp(line
, _T("htt"))==0)||
1199 (_tcscmp(line
, _T("xml"))==0)||
1200 (_tcscmp(line
, _T("asp"))==0)||
1201 (_tcscmp(line
, _T("xsl"))==0)||
1202 (_tcscmp(line
, _T("php"))==0)||
1203 (_tcscmp(line
, _T("xhtml"))==0)||
1204 (_tcscmp(line
, _T("phtml"))==0)||
1205 (_tcscmp(line
, _T("cfm"))==0)||
1206 (_tcscmp(line
, _T("tpl"))==0)||
1207 (_tcscmp(line
, _T("dtd"))==0)||
1208 (_tcscmp(line
, _T("hta"))==0)||
1209 (_tcscmp(line
, _T("htd"))==0)||
1210 (_tcscmp(line
, _T("wxs"))==0))
1212 SendEditor(SCI_SETLEXER
, SCLEX_HTML
);
1213 SendEditor(SCI_SETSTYLEBITS
, 7);
1214 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("a abbr acronym address applet area b base basefont \
1215 bdo big blockquote body br button caption center \
1216 cite code col colgroup dd del dfn dir div dl dt em \
1217 fieldset font form frame frameset h1 h2 h3 h4 h5 h6 \
1218 head hr html i iframe img input ins isindex kbd label \
1219 legend li link map menu meta noframes noscript \
1220 object ol optgroup option p param pre q s samp \
1221 script select small span strike strong style sub sup \
1222 table tbody td textarea tfoot th thead title tr tt u ul \
1223 var xml xmlns abbr accept-charset accept accesskey action align alink \
1224 alt archive axis background bgcolor border \
1225 cellpadding cellspacing char charoff charset checked cite \
1226 class classid clear codebase codetype color cols colspan \
1227 compact content coords \
1228 data datafld dataformatas datapagesize datasrc datetime \
1229 declare defer dir disabled enctype event \
1230 face for frame frameborder \
1231 headers height href hreflang hspace http-equiv \
1232 id ismap label lang language leftmargin link longdesc \
1233 marginwidth marginheight maxlength media method multiple \
1234 name nohref noresize noshade nowrap \
1235 object onblur onchange onclick ondblclick onfocus \
1236 onkeydown onkeypress onkeyup onload onmousedown \
1237 onmousemove onmouseover onmouseout onmouseup \
1238 onreset onselect onsubmit onunload \
1239 profile prompt readonly rel rev rows rowspan rules \
1240 scheme scope selected shape size span src standby start style \
1241 summary tabindex target text title topmargin type usemap \
1242 valign value valuetype version vlink vspace width \
1243 text password checkbox radio submit reset \
1244 file hidden image")).GetBuffer()));
1245 SendEditor(SCI_SETKEYWORDS
, 1, (LPARAM
)(m_TextView
.StringForControl(_T("assign audio block break catch choice clear disconnect else elseif \
1246 emphasis enumerate error exit field filled form goto grammar help \
1247 if initial link log menu meta noinput nomatch object option p paragraph \
1248 param phoneme prompt property prosody record reprompt return s say-as \
1249 script sentence subdialog submit throw transfer value var voice vxml")).GetBuffer()));
1250 SendEditor(SCI_SETKEYWORDS
, 2, (LPARAM
)(m_TextView
.StringForControl(_T("accept age alphabet anchor application base beep bridge category charset \
1251 classid cond connecttimeout content contour count dest destexpr dtmf dtmfterm \
1252 duration enctype event eventexpr expr expritem fetchtimeout finalsilence \
1253 gender http-equiv id level maxage maxstale maxtime message messageexpr \
1254 method mime modal mode name namelist next nextitem ph pitch range rate \
1255 scope size sizeexpr skiplist slot src srcexpr sub time timeexpr timeout \
1256 transferaudio type value variant version volume xml:lang")).GetBuffer()));
1257 SendEditor(SCI_SETKEYWORDS
, 3, (LPARAM
)(m_TextView
.StringForControl(_T("and assert break class continue def del elif \
1258 else except exec finally for from global if import in is lambda None \
1259 not or pass print raise return try while yield")).GetBuffer()));
1260 SendEditor(SCI_SETKEYWORDS
, 4, (LPARAM
)(m_TextView
.StringForControl(_T("and argv as argc break case cfunction class continue declare default do \
1261 die echo else elseif empty enddeclare endfor endforeach endif endswitch \
1262 endwhile e_all e_parse e_error e_warning eval exit extends false for \
1263 foreach function global http_cookie_vars http_get_vars http_post_vars \
1264 http_post_files http_env_vars http_server_vars if include include_once \
1265 list new not null old_function or parent php_os php_self php_version \
1266 print require require_once return static switch stdclass this true var \
1267 xor virtual while __file__ __line__ __sleep __wakeup")).GetBuffer()));
1269 SetAStyle(SCE_H_TAG
, darkBlue
);
1270 SetAStyle(SCE_H_TAGUNKNOWN
, red
);
1271 SetAStyle(SCE_H_ATTRIBUTE
, darkBlue
);
1272 SetAStyle(SCE_H_ATTRIBUTEUNKNOWN
, red
);
1273 SetAStyle(SCE_H_NUMBER
, RGB(0x80,0,0x80));
1274 SetAStyle(SCE_H_DOUBLESTRING
, RGB(0,0x80,0));
1275 SetAStyle(SCE_H_SINGLESTRING
, RGB(0,0x80,0));
1276 SetAStyle(SCE_H_OTHER
, RGB(0x80,0,0x80));
1277 SetAStyle(SCE_H_COMMENT
, RGB(0x80,0x80,0));
1278 SetAStyle(SCE_H_ENTITY
, RGB(0x80,0,0x80));
1280 SetAStyle(SCE_H_TAGEND
, darkBlue
);
1281 SetAStyle(SCE_H_XMLSTART
, darkBlue
); // <?
1282 SetAStyle(SCE_H_QUESTION
, darkBlue
); // <?
1283 SetAStyle(SCE_H_XMLEND
, darkBlue
); // ?>
1284 SetAStyle(SCE_H_SCRIPT
, darkBlue
); // <script
1285 SetAStyle(SCE_H_ASP
, RGB(0x4F, 0x4F, 0), RGB(0xFF, 0xFF, 0)); // <% ... %>
1286 SetAStyle(SCE_H_ASPAT
, RGB(0x4F, 0x4F, 0), RGB(0xFF, 0xFF, 0)); // <%@ ... %>
1288 SetAStyle(SCE_HB_DEFAULT
, black
);
1289 SetAStyle(SCE_HB_COMMENTLINE
, darkGreen
);
1290 SetAStyle(SCE_HB_NUMBER
, RGB(0,0x80,0x80));
1291 SetAStyle(SCE_HB_WORD
, darkBlue
);
1292 SendEditor(SCI_STYLESETBOLD
, SCE_HB_WORD
, 1);
1293 SetAStyle(SCE_HB_STRING
, RGB(0x80,0,0x80));
1294 SetAStyle(SCE_HB_IDENTIFIER
, black
);
1296 // This light blue is found in the windows system palette so is safe to use even in 256 colour modes.
1297 // Show the whole section of VBScript with light blue background
1298 for (int bstyle
= SCE_HB_DEFAULT
; bstyle
<= SCE_HB_STRINGEOL
; ++bstyle
) {
1299 SendEditor(SCI_STYLESETFONT
, bstyle
,
1300 reinterpret_cast<LPARAM
>(m_TextView
.StringForControl(_T("Lucida Console")).GetBuffer()));
1301 SendEditor(SCI_STYLESETBACK
, bstyle
, lightBlue
);
1302 // This call extends the backround colour of the last style on the line to the edge of the window
1303 SendEditor(SCI_STYLESETEOLFILLED
, bstyle
, 1);
1305 SendEditor(SCI_STYLESETBACK
, SCE_HB_STRINGEOL
, RGB(0x7F,0x7F,0xFF));
1306 SendEditor(SCI_STYLESETFONT
, SCE_HB_COMMENTLINE
,
1307 reinterpret_cast<LPARAM
>(m_TextView
.StringForControl(_T("Lucida Console")).GetBuffer()));
1309 SetAStyle(SCE_HBA_DEFAULT
, black
);
1310 SetAStyle(SCE_HBA_COMMENTLINE
, darkGreen
);
1311 SetAStyle(SCE_HBA_NUMBER
, RGB(0,0x80,0x80));
1312 SetAStyle(SCE_HBA_WORD
, darkBlue
);
1313 SendEditor(SCI_STYLESETBOLD
, SCE_HBA_WORD
, 1);
1314 SetAStyle(SCE_HBA_STRING
, RGB(0x80,0,0x80));
1315 SetAStyle(SCE_HBA_IDENTIFIER
, black
);
1317 // Show the whole section of ASP VBScript with bright yellow background
1318 for (int bastyle
= SCE_HBA_DEFAULT
; bastyle
<= SCE_HBA_STRINGEOL
; ++bastyle
) {
1319 SendEditor(SCI_STYLESETFONT
, bastyle
,
1320 reinterpret_cast<LPARAM
>(m_TextView
.StringForControl(_T("Lucida Console")).GetBuffer()));
1321 SendEditor(SCI_STYLESETBACK
, bastyle
, RGB(0xFF, 0xFF, 0));
1322 // This call extends the backround colour of the last style on the line to the edge of the window
1323 SendEditor(SCI_STYLESETEOLFILLED
, bastyle
, 1);
1325 SendEditor(SCI_STYLESETBACK
, SCE_HBA_STRINGEOL
, RGB(0xCF,0xCF,0x7F));
1326 SendEditor(SCI_STYLESETFONT
, SCE_HBA_COMMENTLINE
,
1327 reinterpret_cast<LPARAM
>(m_TextView
.StringForControl(_T("Lucida Console")).GetBuffer()));
1329 // If there is no need to support embedded Javascript, the following code can be dropped.
1330 // Javascript will still be correctly processed but will be displayed in just the default style.
1332 SetAStyle(SCE_HJ_START
, RGB(0x80,0x80,0));
1333 SetAStyle(SCE_HJ_DEFAULT
, black
);
1334 SetAStyle(SCE_HJ_COMMENT
, darkGreen
);
1335 SetAStyle(SCE_HJ_COMMENTLINE
, darkGreen
);
1336 SetAStyle(SCE_HJ_COMMENTDOC
, darkGreen
);
1337 SetAStyle(SCE_HJ_NUMBER
, RGB(0,0x80,0x80));
1338 SetAStyle(SCE_HJ_WORD
, black
);
1339 SetAStyle(SCE_HJ_KEYWORD
, darkBlue
);
1340 SetAStyle(SCE_HJ_DOUBLESTRING
, RGB(0x80,0,0x80));
1341 SetAStyle(SCE_HJ_SINGLESTRING
, RGB(0x80,0,0x80));
1342 SetAStyle(SCE_HJ_SYMBOLS
, black
);
1344 SetAStyle(SCE_HJA_START
, RGB(0x80,0x80,0));
1345 SetAStyle(SCE_HJA_DEFAULT
, black
);
1346 SetAStyle(SCE_HJA_COMMENT
, darkGreen
);
1347 SetAStyle(SCE_HJA_COMMENTLINE
, darkGreen
);
1348 SetAStyle(SCE_HJA_COMMENTDOC
, darkGreen
);
1349 SetAStyle(SCE_HJA_NUMBER
, RGB(0,0x80,0x80));
1350 SetAStyle(SCE_HJA_WORD
, black
);
1351 SetAStyle(SCE_HJA_KEYWORD
, darkBlue
);
1352 SetAStyle(SCE_HJA_DOUBLESTRING
, RGB(0x80,0,0x80));
1353 SetAStyle(SCE_HJA_SINGLESTRING
, RGB(0x80,0,0x80));
1354 SetAStyle(SCE_HJA_SYMBOLS
, black
);
1356 SetAStyle(SCE_HPHP_DEFAULT
, black
);
1357 SetAStyle(SCE_HPHP_HSTRING
, RGB(0x80,0,0x80));
1358 SetAStyle(SCE_HPHP_SIMPLESTRING
, RGB(0x80,0,0x80));
1359 SetAStyle(SCE_HPHP_WORD
, darkBlue
);
1360 SetAStyle(SCE_HPHP_NUMBER
, RGB(0,0x80,0x80));
1361 SetAStyle(SCE_HPHP_VARIABLE
, red
);
1362 SetAStyle(SCE_HPHP_HSTRING_VARIABLE
, red
);
1363 SetAStyle(SCE_HPHP_COMPLEX_VARIABLE
, red
);
1364 SetAStyle(SCE_HPHP_COMMENT
, darkGreen
);
1365 SetAStyle(SCE_HPHP_COMMENTLINE
, darkGreen
);
1366 SetAStyle(SCE_HPHP_OPERATOR
, darkBlue
);
1368 // Show the whole section of Javascript with off white background
1369 for (int jstyle
= SCE_HJ_DEFAULT
; jstyle
<= SCE_HJ_SYMBOLS
; ++jstyle
) {
1370 SendEditor(SCI_STYLESETFONT
, jstyle
,
1371 reinterpret_cast<LPARAM
>(m_TextView
.StringForControl(_T("Lucida Console")).GetBuffer()));
1372 SendEditor(SCI_STYLESETBACK
, jstyle
, offWhite
);
1373 SendEditor(SCI_STYLESETEOLFILLED
, jstyle
, 1);
1375 SendEditor(SCI_STYLESETBACK
, SCE_HJ_STRINGEOL
, RGB(0xDF, 0xDF, 0x7F));
1376 SendEditor(SCI_STYLESETEOLFILLED
, SCE_HJ_STRINGEOL
, 1);
1378 // Show the whole section of Javascript with brown background
1379 for (int jastyle
= SCE_HJA_DEFAULT
; jastyle
<= SCE_HJA_SYMBOLS
; ++jastyle
) {
1380 SendEditor(SCI_STYLESETFONT
, jastyle
,
1381 reinterpret_cast<LPARAM
>(m_TextView
.StringForControl(_T("Lucida Console")).GetBuffer()));
1382 SendEditor(SCI_STYLESETBACK
, jastyle
, RGB(0xDF, 0xDF, 0x7F));
1383 SendEditor(SCI_STYLESETEOLFILLED
, jastyle
, 1);
1385 SendEditor(SCI_STYLESETBACK
, SCE_HJA_STRINGEOL
, RGB(0x0,0xAF,0x5F));
1386 SendEditor(SCI_STYLESETEOLFILLED
, SCE_HJA_STRINGEOL
, 1);
1391 SendEditor(SCI_SETLEXER
, SCLEX_CPP
);
1394 SendEditor(SCI_COLOURISE
, 0, -1);
1398 void CTortoiseGitBlameView::SetupCppLexer()
1400 SetAStyle(SCE_C_DEFAULT
, RGB(0, 0, 0));
1401 SetAStyle(SCE_C_COMMENT
, RGB(0, 0x80, 0));
1402 SetAStyle(SCE_C_COMMENTLINE
, RGB(0, 0x80, 0));
1403 SetAStyle(SCE_C_COMMENTDOC
, RGB(0, 0x80, 0));
1404 SetAStyle(SCE_C_COMMENTLINEDOC
, RGB(0, 0x80, 0));
1405 SetAStyle(SCE_C_COMMENTDOCKEYWORD
, RGB(0, 0x80, 0));
1406 SetAStyle(SCE_C_COMMENTDOCKEYWORDERROR
, RGB(0, 0x80, 0));
1407 SetAStyle(SCE_C_NUMBER
, RGB(0, 0x80, 0x80));
1408 SetAStyle(SCE_C_WORD
, RGB(0, 0, 0x80));
1409 SendEditor(SCE_C_WORD
, 1);
1410 SetAStyle(SCE_C_STRING
, RGB(0x80, 0, 0x80));
1411 SetAStyle(SCE_C_IDENTIFIER
, RGB(0, 0, 0));
1412 SetAStyle(SCE_C_PREPROCESSOR
, RGB(0x80, 0, 0));
1413 SetAStyle(SCE_C_OPERATOR
, RGB(0x80, 0x80, 0));
1416 int CTortoiseGitBlameView::GetEncode(unsigned char *buff
, int size
, int *bomoffset
)
1418 CFileTextLines textlines
;
1419 CFileTextLines::UnicodeType type
= textlines
.CheckUnicodeType(buff
, size
);
1421 if(type
== CFileTextLines::UTF8BOM
)
1426 if(type
== CFileTextLines::UTF8
)
1429 if(type
== CFileTextLines::UTF16_LE
)
1431 if (type
== CFileTextLines::UTF16_LEBOM
)
1437 if(type
== CFileTextLines::UTF16_BE
)
1439 if (type
== CFileTextLines::UTF16_BEBOM
)
1448 void CTortoiseGitBlameView::ParseBlame()
1450 m_data
.ParseBlameOutput(GetDocument()->m_BlameData
, GetLogData()->m_pLogCache
->m_HashMap
, m_DateFormat
, m_bRelativeTimes
);
1453 void CTortoiseGitBlameView::MapLineToLogIndex()
1455 std::vector
<LONG
> lineToLogIndex
;
1458 int numberOfLines
= m_data
.GetNumberOfLines();
1459 lineToLogIndex
.reserve(numberOfLines
);
1460 size_t logSize
= this->GetLogData()->size();
1461 for (int j
= 0; j
< numberOfLines
; ++j
)
1463 CGitHash
& hash
= m_data
.GetHash(j
);
1466 for (size_t i
= 0; i
< logSize
; ++i
)
1468 if (hash
== this->GetLogData()->at(i
))
1474 lineToLogIndex
.push_back(index
);
1476 this->m_lineToLogIndex
.swap(lineToLogIndex
);
1479 void CTortoiseGitBlameView::UpdateInfo(int Encode
)
1483 SendEditor(SCI_SETREADONLY
, FALSE
);
1484 SendEditor(SCI_CLEARALL
);
1485 SendEditor(EM_EMPTYUNDOBUFFER
);
1486 SendEditor(SCI_SETSAVEPOINT
);
1487 SendEditor(SCI_CANCEL
);
1488 SendEditor(SCI_SETUNDOCOLLECTION
, 0);
1490 SendEditor(SCI_SETCODEPAGE
, SC_CP_UTF8
);
1492 int encoding
= m_data
.UpdateEncoding(Encode
);
1494 int numberOfLines
= m_data
.GetNumberOfLines();
1495 if (numberOfLines
> 0)
1497 for (int i
= 0; i
< numberOfLines
- 1; ++i
)
1499 SendEditor(SCI_REPLACESEL
, 0, (LPARAM
)(LPCSTR
)m_data
.GetUtf8Line(i
));
1500 SendEditor(SCI_REPLACESEL
, 0, (LPARAM
)(LPCSTR
)"\n\0\0\0");
1503 // as it will add another line number in scintilla which has no counter part in the blame output
1504 // prevent carriage return and line feed for the last line
1505 CStringA s
= m_data
.GetUtf8Line(numberOfLines
- 1);
1506 int length
= s
.GetLength();
1507 if (length
> 0 && s
.GetAt(length
- 1) == '\r')
1508 s
.Truncate(length
- 1);
1509 SendEditor(SCI_REPLACESEL
, 0, (LPARAM
)(LPCSTR
)s
);
1517 int nIndex
= ((CMainFrame
*)::AfxGetApp()->GetMainWnd())->m_wndStatusBar
.CommandToIndex(ID_INDICATOR_ENCODING
);
1518 ((CMainFrame
*)::AfxGetApp()->GetMainWnd())->m_wndStatusBar
.GetPaneInfo(nIndex
, nID
, nStyle
, cxWidth
);
1519 CString sBarText
= L
"";
1520 for (int i
= 0; i
< _countof(encodings
); ++i
)
1522 if (encodings
[i
].id
== encoding
)
1524 sBarText
= CString(encodings
[i
].name
);
1528 //calculate the width of the text
1529 CDC
* pDC
= ((CMainFrame
*)::AfxGetApp()->GetMainWnd())->m_wndStatusBar
.GetDC();
1532 CSize size
= pDC
->GetTextExtent(sBarText
);
1533 ((CMainFrame
*)::AfxGetApp()->GetMainWnd())->m_wndStatusBar
.SetPaneInfo(nIndex
, nID
, nStyle
, size
.cx
+2);
1536 ((CMainFrame
*)::AfxGetApp()->GetMainWnd())->m_wndStatusBar
.SetPaneText(nIndex
, sBarText
);
1539 #ifdef USE_TEMPFILENAME
1547 file
.Open(this->GetDocument()->m_TempFileName
,CFile::modeRead
);
1549 m_Buffer
= new char[file
.GetLength()+4];
1550 m_Buffer
[file
.GetLength()] =0;
1551 m_Buffer
[file
.GetLength()+1] =0;
1552 m_Buffer
[file
.GetLength()+2] =0;
1553 m_Buffer
[file
.GetLength()+3] =0;
1555 file
.Read(m_Buffer
, file
.GetLength());
1558 int encoding
= GetEncode( (unsigned char *)m_Buffer
, file
.GetLength(), &bomoffset
);
1561 //SendEditor(SCI_SETCODEPAGE, encoding);
1563 //SendEditor(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)(m_Buffer + bomoffset));
1565 SetupLexer(GetDocument()->m_CurrentFileName
);
1567 SendEditor(SCI_SETUNDOCOLLECTION
, 1);
1568 SendEditor(EM_EMPTYUNDOBUFFER
);
1569 SendEditor(SCI_SETSAVEPOINT
);
1570 SendEditor(SCI_GOTOPOS
, 0);
1571 SendEditor(SCI_SETSCROLLWIDTHTRACKING
, TRUE
);
1572 SendEditor(SCI_SETREADONLY
, TRUE
);
1575 m_highestrev
= (long)(this->GetLogData()->size());
1579 this->GetClientRect(rect
);
1580 //this->m_TextView.GetWindowRect(rect);
1581 //this->m_TextView.ScreenToClient(rect);
1582 rect
.left
=this->m_blamewidth
;
1583 this->m_TextView
.MoveWindow(rect
);
1588 CString
CTortoiseGitBlameView::ResolveCommitFile(LONG line
)
1590 return ResolveCommitFile(m_data
.GetFilename(line
));
1593 CString
CTortoiseGitBlameView::ResolveCommitFile(const CString
& path
)
1597 return ((CMainFrame
*)::AfxGetApp()->GetMainWnd())->GetActiveView()->GetDocument()->GetPathName();
1601 CTGitPath
tgp(g_Git
.m_CurrentDir
);
1602 tgp
.AppendPathString(path
);
1603 return tgp
.GetWinPathString();
1607 COLORREF
CTortoiseGitBlameView::GetLineColor(int line
)
1609 if (m_colorage
&& m_data
.IsValidLine(line
))
1611 int slider
= (int)((GetLogData()->size() - m_lineToLogIndex
[line
] - m_lowestrev
) * 100 / ((m_highestrev
- m_lowestrev
) + 1));
1612 return InterColor(DWORD(m_regOldLinesColor
), DWORD(m_regNewLinesColor
), slider
);
1615 return m_windowcolor
;
1618 CGitBlameLogList
* CTortoiseGitBlameView::GetLogList()
1620 return &(GetDocument()->GetMainFrame()->m_wndOutput
.m_LogList
);
1624 CLogDataVector
* CTortoiseGitBlameView::GetLogData()
1626 return &(GetDocument()->GetMainFrame()->m_wndOutput
.m_LogList
.m_logEntries
);
1629 void CTortoiseGitBlameView::OnSciPainted(NMHDR
*,LRESULT
*)
1634 void CTortoiseGitBlameView::OnLButtonDown(UINT nFlags
,CPoint point
)
1637 LONG line
= (LONG
)SendEditor(SCI_GETFIRSTVISIBLELINE
);
1638 LONG height
= (LONG
)SendEditor(SCI_TEXTHEIGHT
);
1639 line
= line
+ (point
.y
/height
);
1641 if (line
< (LONG
)m_data
.GetNumberOfLines())
1643 SetSelectedLine(line
);
1644 if (m_data
.GetHash(line
) != m_SelectedHash
)
1646 m_SelectedHash
= m_data
.GetHash(line
);
1648 int logIndex
= m_lineToLogIndex
[line
];
1649 this->GetLogList()->SetItemState(logIndex
, LVIS_SELECTED
, LVIS_SELECTED
);
1650 this->GetLogList()->EnsureVisible(logIndex
, FALSE
);
1654 m_SelectedHash
.Empty();
1656 //::InvalidateRect( NULL, FALSE);
1658 this->m_TextView
.Invalidate();
1663 SetSelectedLine(-1);
1666 CView::OnLButtonDown(nFlags
,point
);
1669 void CTortoiseGitBlameView::OnSciGetBkColor(NMHDR
* hdr
, LRESULT
* /*result*/)
1671 SCNotification
*notification
=reinterpret_cast<SCNotification
*>(hdr
);
1673 if (notification
->line
< m_data
.GetNumberOfLines())
1675 if (m_data
.GetHash(notification
->line
) == this->m_SelectedHash
)
1676 notification
->lParam
= m_selectedauthorcolor
;
1678 notification
->lParam
= GetLineColor(notification
->line
);
1682 void CTortoiseGitBlameView::FocusOn(GitRev
*pRev
)
1684 this->GetDocument()->GetMainFrame()->m_wndProperties
.UpdateProperties(pRev
);
1688 if (m_SelectedHash
!= pRev
->m_CommitHash
) {
1689 m_SelectedHash
= pRev
->m_CommitHash
;
1690 int line
= m_data
.FindFirstLine(m_SelectedHash
, 0);
1693 GotoLine((long)(line
+ 1));
1694 m_TextView
.Invalidate();
1697 SendEditor(SCI_SETSEL
, LONG_MAX
, -1);
1701 void CTortoiseGitBlameView::OnMouseHover(UINT
/*nFlags*/, CPoint point
)
1703 int line
= (int)SendEditor(SCI_GETFIRSTVISIBLELINE
);
1704 LONG_PTR height
= SendEditor(SCI_TEXTHEIGHT
);
1705 line
= line
+ (int)(point
.y
/ height
);
1707 if (m_data
.IsValidLine(line
))
1709 if (line
!= m_MouseLine
)
1711 m_MouseLine
= (LONG
)line
;
1712 GitRev
*pRev
= &this->GetLogData()->GetGitRevAt(m_lineToLogIndex
[line
]);
1713 CString body
= pRev
->GetBody();
1717 while (iline
++ < maxLine
)
1719 int pos2
= body
.Find(_T("\n"), pos
);
1722 int lineLength
= pos2
- pos
- 1;
1724 iline
+= lineLength
/ 70;
1728 if (m_bFollowRenames
)
1729 filename
.Format(_T("%s: %s\n"), m_sFileName
, m_data
.GetFilename(line
));
1732 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
,
1733 m_sAuthor
, pRev
->GetAuthorName(), pRev
->GetAuthorEmail(),
1734 m_sDate
, CLoglistUtils::FormatDateAndTime(pRev
->GetAuthorDate(), m_DateFormat
, true, m_bRelativeTimes
),
1735 m_sMessage
, pRev
->GetSubject(),
1736 iline
<= maxLine
? body
: (body
.Left(pos
) + _T("\n....................")));
1739 m_ToolTip
.AddTool(this, str
);
1742 rect
.left
=LOCATOR_WIDTH
;
1743 rect
.right
=this->m_blamewidth
+rect
.left
;
1744 rect
.top
= point
.y
- (LONG
)height
;
1745 rect
.bottom
= point
.y
+ (LONG
)height
;
1746 this->InvalidateRect(rect
);
1751 void CTortoiseGitBlameView::OnMouseMove(UINT
/*nFlags*/, CPoint
/*point*/)
1753 TRACKMOUSEEVENT tme
;
1754 tme
.cbSize
=sizeof(TRACKMOUSEEVENT
);
1755 tme
.dwFlags
=TME_HOVER
|TME_LEAVE
;
1756 tme
.hwndTrack
=this->m_hWnd
;
1758 TrackMouseEvent(&tme
);
1762 BOOL
CTortoiseGitBlameView::PreTranslateMessage(MSG
* pMsg
)
1764 m_ToolTip
.RelayEvent(pMsg
);
1765 return CView::PreTranslateMessage(pMsg
);
1768 void CTortoiseGitBlameView::OnEditFind()
1773 m_pFindDialog
=new CFindReplaceDialog();
1775 CString oneline
= theApp
.GetString(_T("FindString"));
1776 if (m_TextView
.Call(SCI_GETSELECTIONSTART
) != m_TextView
.Call(SCI_GETSELECTIONEND
))
1778 LRESULT bufsize
= m_TextView
.Call(SCI_GETSELECTIONEND
) - m_TextView
.Call(SCI_GETSELECTIONSTART
);
1779 char * linebuf
= new char[bufsize
+ 1];
1780 SecureZeroMemory(linebuf
, bufsize
+ 1);
1781 SendEditor(SCI_GETSELTEXT
, 0, (LPARAM
)linebuf
);
1782 oneline
= m_TextView
.StringFromControl(linebuf
);
1786 DWORD flags
= FR_DOWN
| FR_HIDEWHOLEWORD
| FR_HIDEUPDOWN
;
1787 if (theApp
.GetInt(_T("FindMatchCase")))
1788 flags
|= FR_MATCHCASE
;
1790 m_pFindDialog
->Create(TRUE
, oneline
, NULL
, flags
, this);
1793 void CTortoiseGitBlameView::OnEditGoto()
1796 if(dlg
.DoModal()==IDOK
)
1798 this->GotoLine(dlg
.m_LineNumber
);
1802 LRESULT
CTortoiseGitBlameView::OnFindDialogMessage(WPARAM
/*wParam*/, LPARAM
/*lParam*/)
1804 ASSERT(m_pFindDialog
!= NULL
);
1806 // If the FR_DIALOGTERM flag is set,
1807 // invalidate the handle identifying the dialog box.
1808 if (m_pFindDialog
->IsTerminating())
1810 m_pFindDialog
= NULL
;
1814 if (m_data
.GetNumberOfLines()==0)
1817 // If the FR_FINDNEXT flag is set,
1818 // call the application-defined search routine
1819 // to search for the requested string.
1820 if(m_pFindDialog
->FindNext())
1822 //read data from dialog
1823 CString FindName
= m_pFindDialog
->GetFindString();
1825 DoSearch(FindName
,m_pFindDialog
->m_fr
.Flags
);
1831 void CTortoiseGitBlameView::OnViewNext()
1833 int startline
= (int)SendEditor(SCI_GETFIRSTVISIBLELINE
);
1834 int line
= m_data
.FindNextLine(this->m_SelectedHash
, (int)SendEditor(SCI_GETFIRSTVISIBLELINE
), false);
1836 SendEditor(SCI_LINESCROLL
, 0, line
- startline
- 2);
1838 void CTortoiseGitBlameView::OnViewPrev()
1840 int startline
= (int)SendEditor(SCI_GETFIRSTVISIBLELINE
);
1841 int line
= m_data
.FindNextLine(this->m_SelectedHash
, (int)SendEditor(SCI_GETFIRSTVISIBLELINE
), true);
1843 SendEditor(SCI_LINESCROLL
, 0, line
- startline
- 2);
1846 void CTortoiseGitBlameView::OnViewToggleAuthor()
1848 m_bShowAuthor
= ! m_bShowAuthor
;
1850 theApp
.WriteInt(_T("ShowAuthor"), m_bShowAuthor
);
1853 this->GetClientRect(&rect
);
1854 rect
.left
=GetBlameWidth();
1856 m_TextView
.MoveWindow(&rect
);
1859 void CTortoiseGitBlameView::OnUpdateViewToggleAuthor(CCmdUI
*pCmdUI
)
1861 pCmdUI
->SetCheck(m_bShowAuthor
);
1864 void CTortoiseGitBlameView::OnViewToggleDate()
1866 m_bShowDate
= ! m_bShowDate
;
1868 theApp
.WriteInt(_T("ShowDate"), m_bShowDate
);
1871 this->GetClientRect(&rect
);
1872 rect
.left
=GetBlameWidth();
1874 m_TextView
.MoveWindow(&rect
);
1877 void CTortoiseGitBlameView::OnUpdateViewToggleDate(CCmdUI
*pCmdUI
)
1879 pCmdUI
->SetCheck(m_bShowDate
);
1882 void CTortoiseGitBlameView::OnViewDetectMovedOrCopiedLines(DWORD dwDetectMovedOrCopiedLines
)
1884 m_dwDetectMovedOrCopiedLines
= dwDetectMovedOrCopiedLines
;
1886 theApp
.WriteInt(_T("DetectMovedOrCopiedLines"), m_dwDetectMovedOrCopiedLines
);
1888 CTortoiseGitBlameDoc
*document
= (CTortoiseGitBlameDoc
*) m_pDocument
;
1889 if (!document
->m_CurrentFileName
.IsEmpty())
1891 document
->m_lLine
= (LONG
)SendEditor(SCI_GETFIRSTVISIBLELINE
) + 1;
1892 theApp
.m_pDocManager
->OnFileNew();
1893 document
->OnOpenDocument(document
->m_CurrentFileName
, document
->m_Rev
);
1897 void CTortoiseGitBlameView::OnViewDetectMovedOrCopiedLinesToggleDisabled()
1899 OnViewDetectMovedOrCopiedLines(BLAME_DETECT_MOVED_OR_COPIED_LINES_DISABLED
);
1902 void CTortoiseGitBlameView::OnUpdateViewDetectMovedOrCopiedLinesToggleDisabled(CCmdUI
*pCmdUI
)
1904 pCmdUI
->SetRadio(m_dwDetectMovedOrCopiedLines
== BLAME_DETECT_MOVED_OR_COPIED_LINES_DISABLED
);
1907 void CTortoiseGitBlameView::OnViewDetectMovedOrCopiedLinesToggleWithinFile()
1909 OnViewDetectMovedOrCopiedLines(BLAME_DETECT_MOVED_OR_COPIED_LINES_WITHIN_FILE
);
1912 void CTortoiseGitBlameView::OnUpdateViewDetectMovedOrCopiedLinesToggleWithinFile(CCmdUI
*pCmdUI
)
1914 pCmdUI
->SetRadio(m_dwDetectMovedOrCopiedLines
== BLAME_DETECT_MOVED_OR_COPIED_LINES_WITHIN_FILE
);
1917 void CTortoiseGitBlameView::OnViewDetectMovedOrCopiedLinesToggleFromModifiedFiles()
1919 OnViewDetectMovedOrCopiedLines(BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_MODIFIED_FILES
);
1922 void CTortoiseGitBlameView::OnUpdateViewDetectMovedOrCopiedLinesToggleFromModifiedFiles(CCmdUI
*pCmdUI
)
1924 pCmdUI
->SetRadio(m_dwDetectMovedOrCopiedLines
== BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_MODIFIED_FILES
);
1927 void CTortoiseGitBlameView::OnViewDetectMovedOrCopiedLinesToggleFromExistingFilesAtFileCreation()
1929 OnViewDetectMovedOrCopiedLines(BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES_AT_FILE_CREATION
);
1932 void CTortoiseGitBlameView::OnUpdateViewDetectMovedOrCopiedLinesToggleFromExistingFilesAtFileCreation(CCmdUI
*pCmdUI
)
1934 pCmdUI
->SetRadio(m_dwDetectMovedOrCopiedLines
== BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES_AT_FILE_CREATION
);
1937 void CTortoiseGitBlameView::OnViewDetectMovedOrCopiedLinesToggleFromExistingFiles()
1939 OnViewDetectMovedOrCopiedLines(BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES
);
1942 void CTortoiseGitBlameView::OnUpdateViewDetectMovedOrCopiedLinesToggleFromExistingFiles(CCmdUI
*pCmdUI
)
1944 pCmdUI
->SetRadio(m_dwDetectMovedOrCopiedLines
== BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES
);
1947 void CTortoiseGitBlameView::OnViewToggleIgnoreWhitespace()
1949 m_bIgnoreWhitespace
= ! m_bIgnoreWhitespace
;
1951 theApp
.WriteInt(_T("IgnoreWhitespace"), m_bIgnoreWhitespace
);
1953 CTortoiseGitBlameDoc
*document
= (CTortoiseGitBlameDoc
*) m_pDocument
;
1954 if (!document
->m_CurrentFileName
.IsEmpty())
1956 document
->m_lLine
= (LONG
)SendEditor(SCI_GETFIRSTVISIBLELINE
) + 1;
1957 theApp
.m_pDocManager
->OnFileNew();
1958 document
->OnOpenDocument(document
->m_CurrentFileName
, document
->m_Rev
);
1962 void CTortoiseGitBlameView::OnUpdateViewToggleIgnoreWhitespace(CCmdUI
*pCmdUI
)
1964 pCmdUI
->SetCheck(m_bIgnoreWhitespace
);
1967 void CTortoiseGitBlameView::OnViewToggleFollowRenames()
1969 m_bFollowRenames
= ! m_bFollowRenames
;
1970 theApp
.DoWaitCursor(1);
1972 theApp
.WriteInt(_T("FollowRenames"), m_bFollowRenames
);
1974 CTortoiseGitBlameDoc
*document
= (CTortoiseGitBlameDoc
*) m_pDocument
;
1975 if (!document
->m_CurrentFileName
.IsEmpty())
1977 document
->m_lLine
= (LONG
)SendEditor(SCI_GETFIRSTVISIBLELINE
) + 1;
1978 theApp
.m_pDocManager
->OnFileNew();
1979 document
->OnOpenDocument(document
->m_CurrentFileName
, document
->m_Rev
);
1980 document
->SetPathName(document
->m_CurrentFileName
, FALSE
);
1982 theApp
.DoWaitCursor(-1);
1985 void CTortoiseGitBlameView::OnUpdateViewToggleFollowRenames(CCmdUI
*pCmdUI
)
1987 pCmdUI
->SetCheck(m_bFollowRenames
);
1990 void CTortoiseGitBlameView::OnViewToggleColorByAge()
1992 m_colorage
= ! m_colorage
;
1994 theApp
.WriteInt(_T("ColorAge"), m_colorage
);
1996 m_TextView
.Invalidate();
1999 void CTortoiseGitBlameView::OnUpdateViewToggleColorByAge(CCmdUI
*pCmdUI
)
2001 pCmdUI
->SetCheck(m_colorage
);
2004 void CTortoiseGitBlameView::OnUpdateViewCopyToClipboard(CCmdUI
*pCmdUI
)
2006 CWnd
* wnd
= GetFocus();
2007 if (wnd
== GetLogList())
2009 pCmdUI
->Enable(GetLogList()->GetSelectedCount() > 0);
2013 if (CString(wnd
->GetRuntimeClass()->m_lpszClassName
) == _T("CMFCPropertyGridCtrl"))
2015 CMFCPropertyGridCtrl
*grid
= (CMFCPropertyGridCtrl
*)wnd
;
2016 pCmdUI
->Enable(grid
->GetCurSel() && !grid
->GetCurSel()->IsGroup() && !CString(grid
->GetCurSel()->GetValue()).IsEmpty());
2019 pCmdUI
->Enable(m_TextView
.Call(SCI_GETSELECTIONSTART
) != m_TextView
.Call(SCI_GETSELECTIONEND
));
2022 pCmdUI
->Enable(FALSE
);