1 // TortoiseGitBlame - a Viewer for Git Blames
3 // Copyright (C) 2008-2011 - TortoiseGit
4 // Copyright (C) 2010-2011 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"
29 #include "TortoiseGitBlameDoc.h"
30 #include "TortoiseGitBlameView.h"
32 #include "EditGotoDlg.h"
33 #include "TortoiseGitBlameAppUtils.h"
34 #include "FileTextLines.h"
35 #include "UniCodeUtils.h"
36 #include "MenuEncode.h"
38 #include "PathUtils.h"
44 UINT
CTortoiseGitBlameView::m_FindDialogMessage
;
46 // CTortoiseGitBlameView
47 IMPLEMENT_DYNAMIC(CSciEditBlame
,CSciEdit
)
49 IMPLEMENT_DYNCREATE(CTortoiseGitBlameView
, CView
)
51 BEGIN_MESSAGE_MAP(CTortoiseGitBlameView
, CView
)
52 // Standard printing commands
53 ON_COMMAND(ID_FILE_PRINT
, &CView::OnFilePrint
)
54 ON_COMMAND(ID_FILE_PRINT_DIRECT
, &CView::OnFilePrint
)
55 ON_COMMAND(ID_FILE_PRINT_PREVIEW
, &CTortoiseGitBlameView::OnFilePrintPreview
)
56 ON_COMMAND(ID_EDIT_FIND
,OnEditFind
)
57 ON_COMMAND(ID_EDIT_GOTO
,OnEditGoto
)
58 ON_COMMAND(ID_EDIT_COPY
,CopySelectedLogToClipboard
)
59 ON_COMMAND(ID_VIEW_NEXT
,OnViewNext
)
60 ON_COMMAND(ID_VIEW_PREV
,OnViewPrev
)
61 ON_COMMAND(ID_VIEW_SHOWAUTHOR
, OnViewToggleAuthor
)
62 ON_UPDATE_COMMAND_UI(ID_VIEW_SHOWAUTHOR
, OnUpdateViewToggleAuthor
)
63 ON_COMMAND(ID_VIEW_FOLLOWRENAMES
, OnViewToggleFollowRenames
)
64 ON_UPDATE_COMMAND_UI(ID_VIEW_FOLLOWRENAMES
, OnUpdateViewToggleFollowRenames
)
65 ON_COMMAND(ID_BLAMEPOPUP_COPYHASHTOCLIPBOARD
, CopyHashToClipboard
)
66 ON_COMMAND(ID_BLAMEPOPUP_COPYLOGTOCLIPBOARD
, CopySelectedLogToClipboard
)
67 ON_COMMAND(ID_BLAMEPOPUP_BLAMEPREVIOUSREVISION
, BlamePreviousRevision
)
68 ON_COMMAND(ID_BLAMEPOPUP_DIFFPREVIOUS
, DiffPreviousRevision
)
69 ON_COMMAND(ID_BLAMEPOPUP_SHOWLOG
, ShowLog
)
70 ON_UPDATE_COMMAND_UI(ID_BLAMEPOPUP_BLAMEPREVIOUSREVISION
, OnUpdateBlamePopupBlamePrevious
)
71 ON_UPDATE_COMMAND_UI(ID_BLAMEPOPUP_DIFFPREVIOUS
, OnUpdateBlamePopupDiffPrevious
)
72 ON_COMMAND_RANGE(IDM_FORMAT_ENCODE
, IDM_FORMAT_ENCODE_END
, OnChangeEncode
)
81 ON_NOTIFY(SCN_PAINTED
,0,OnSciPainted
)
82 ON_NOTIFY(SCN_GETBKCOLOR
,0,OnSciGetBkColor
)
83 ON_REGISTERED_MESSAGE(m_FindDialogMessage
, OnFindDialogMessage
)
87 // CTortoiseGitBlameView construction/destruction
89 CTortoiseGitBlameView::CTortoiseGitBlameView()
107 m_windowcolor
= ::GetSysColor(COLOR_WINDOW
);
108 m_textcolor
= ::GetSysColor(COLOR_WINDOWTEXT
);
109 m_texthighlightcolor
= ::GetSysColor(COLOR_HIGHLIGHTTEXT
);
110 m_mouserevcolor
= InterColor(m_windowcolor
, m_textcolor
, 20);
111 m_mouseauthorcolor
= InterColor(m_windowcolor
, m_textcolor
, 10);
112 m_selectedrevcolor
= ::GetSysColor(COLOR_HIGHLIGHT
);
113 m_selectedauthorcolor
= InterColor(m_selectedrevcolor
, m_texthighlightcolor
, 35);
117 m_selectedorigrev
= -1;
120 m_directFunction
= 0;
122 m_lowestrev
= LONG_MAX
;
128 m_bShowAuthor
= (theApp
.GetInt(_T("ShowAuthor"), 1) == 1);
130 m_bFollowRenames
= (theApp
.GetInt(_T("FollowRenames"), 0) == 1);
132 m_FindDialogMessage
= ::RegisterWindowMessage(FINDMSGSTRING
);
133 m_pFindDialog
= NULL
;
134 // get short/long datetime setting from registry
135 DWORD RegUseShortDateFormat
= CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE
);
136 if ( RegUseShortDateFormat
)
138 m_DateFormat
= DATE_SHORTDATE
;
142 m_DateFormat
= DATE_LONGDATE
;
144 // get relative time display setting from registry
145 DWORD regRelativeTimes
= CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE
);
146 m_bRelativeTimes
= (regRelativeTimes
!= 0);
148 m_sRev
.LoadString(IDS_LOG_REVISION
);
149 m_sAuthor
.LoadString(IDS_LOG_AUTHOR
);
150 m_sDate
.LoadString(IDS_LOG_DATE
);
151 m_sMessage
.LoadString(IDS_LOG_MESSAGE
);
156 CTortoiseGitBlameView::~CTortoiseGitBlameView()
159 DeleteObject(m_font
);
161 DeleteObject(m_italicfont
);
175 void CTortoiseGitBlameView::OnChangeEncode(UINT nId
)
178 static EncodingUnit encodings
[] = {
179 {1250, "windows-1250"}, //IDM_FORMAT_WIN_1250
180 {1251, "windows-1251"}, //IDM_FORMAT_WIN_1251
181 {1252, "windows-1252"}, //IDM_FORMAT_WIN_1252
182 {1253, "windows-1253"}, //IDM_FORMAT_WIN_1253
183 {1254, "windows-1254"}, //IDM_FORMAT_WIN_1254
184 {1255, "windows-1255"}, //IDM_FORMAT_WIN_1255
185 {1256, "windows-1256"}, //IDM_FORMAT_WIN_1256
186 {1257, "windows-1257"}, //IDM_FORMAT_WIN_1257
187 {1258, "windows-1258"}, //IDM_FORMAT_WIN_1258
188 {28591, "latin1 ISO_8859-1 ISO-8859-1 CP819 IBM819 csISOLatin1 iso-ir-100 l1"}, //IDM_FORMAT_ISO_8859_1
189 {28592, "latin2 ISO_8859-2 ISO-8859-2 csISOLatin2 iso-ir-101 l2"}, //IDM_FORMAT_ISO_8859_2
190 {28593, "latin3 ISO_8859-3 ISO-8859-3 csISOLatin3 iso-ir-109 l3"}, //IDM_FORMAT_ISO_8859_3
191 {28594, "latin4 ISO_8859-4 ISO-8859-4 csISOLatin4 iso-ir-110 l4"}, //IDM_FORMAT_ISO_8859_4
192 {28595, "cyrillic ISO_8859-5 ISO-8859-5 csISOLatinCyrillic iso-ir-144"}, //IDM_FORMAT_ISO_8859_5
193 {28596, "arabic ISO_8859-6 ISO-8859-6 csISOLatinArabic iso-ir-127 ASMO-708 ECMA-114"}, //IDM_FORMAT_ISO_8859_6
194 {28597, "greek ISO_8859-7 ISO-8859-7 csISOLatinGreek greek8 iso-ir-126 ELOT_928 ECMA-118"}, //IDM_FORMAT_ISO_8859_7
195 {28598, "hebrew ISO_8859-8 ISO-8859-8 csISOLatinHebrew iso-ir-138"}, //IDM_FORMAT_ISO_8859_8
196 {28599, "latin5 ISO_8859-9 ISO-8859-9 csISOLatin5 iso-ir-148 l5"}, //IDM_FORMAT_ISO_8859_9
197 {28600, "latin6 ISO_8859-10 ISO-8859-10 csISOLatin6 iso-ir-157 l6"}, //IDM_FORMAT_ISO_8859_10
198 {28601, "ISO_8859-11 ISO-8859-11"}, //IDM_FORMAT_ISO_8859_11
199 {28603, "ISO_8859-13 ISO-8859-13"}, //IDM_FORMAT_ISO_8859_13
200 {28604, "iso-celtic latin8 ISO_8859-14 ISO-8859-14 18 iso-ir-199"}, //IDM_FORMAT_ISO_8859_14
201 {28605, "Latin-9 ISO_8859-15 ISO-8859-15"}, //IDM_FORMAT_ISO_8859_15
202 {28606, "latin10 ISO_8859-16 ISO-8859-16 110 iso-ir-226"}, //IDM_FORMAT_ISO_8859_16
203 {437, "IBM437 cp437 437 csPC8CodePage437"}, //IDM_FORMAT_DOS_437
204 {720, "IBM720 cp720 oem720 720"}, //IDM_FORMAT_DOS_720
205 {737, "IBM737 cp737 oem737 737"}, //IDM_FORMAT_DOS_737
206 {775, "IBM775 cp775 oem775 775"}, //IDM_FORMAT_DOS_775
207 {850, "IBM850 cp850 oem850 850"}, //IDM_FORMAT_DOS_850
208 {852, "IBM852 cp852 oem852 852"}, //IDM_FORMAT_DOS_852
209 {855, "IBM855 cp855 oem855 855 csIBM855"}, //IDM_FORMAT_DOS_855
210 {857, "IBM857 cp857 oem857 857"}, //IDM_FORMAT_DOS_857
211 {858, "IBM858 cp858 oem858 858"}, //IDM_FORMAT_DOS_858
212 {860, "IBM860 cp860 oem860 860"}, //IDM_FORMAT_DOS_860
213 {861, "IBM861 cp861 oem861 861"}, //IDM_FORMAT_DOS_861
214 {862, "IBM862 cp862 oem862 862"}, //IDM_FORMAT_DOS_862
215 {863, "IBM863 cp863 oem863 863"}, //IDM_FORMAT_DOS_863
216 {865, "IBM865 cp865 oem865 865"}, //IDM_FORMAT_DOS_865
217 {866, "IBM866 cp866 oem866 866"}, //IDM_FORMAT_DOS_866
218 {869, "IBM869 cp869 oem869 869"}, //IDM_FORMAT_DOS_869
219 {950, "big5 csBig5"}, //IDM_FORMAT_BIG5
220 {936, "gb2312 gbk csGB2312"}, //IDM_FORMAT_GB2312
221 {932, "Shift_JIS MS_Kanji csShiftJIS csWindows31J"}, //IDM_FORMAT_SHIFT_JIS
222 {949, "windows-949 korean"}, //IDM_FORMAT_KOREAN_WIN
223 {51949, "euc-kr csEUCKR"}, //IDM_FORMAT_EUC_KR
224 {874, "tis-620"}, //IDM_FORMAT_TIS_620
225 {10007, "x-mac-cyrillic xmaccyrillic"}, //IDM_FORMAT_MAC_CYRILLIC
226 {21866, "koi8_u"}, //IDM_FORMAT_KOI8U_CYRILLIC
227 {20866, "koi8_r csKOI8R"} //IDM_FORMAT_KOI8R_CYRILLIC
229 if(nId
>= IDM_FORMAT_ENCODE
&& nId
<= IDM_FORMAT_ENCODE_END
)
230 this->UpdateInfo(encodings
[nId
- IDM_FORMAT_ENCODE
].id
);
232 int CTortoiseGitBlameView::OnCreate(LPCREATESTRUCT lpcs
)
236 this->GetWindowRect(&rect1
);
237 rect
.left
=m_blamewidth
+LOCATOR_WIDTH
;
238 rect
.right
=rect
.Width();
240 rect
.bottom
=rect
.Height();
241 BOOL b
=m_TextView
.Create(_T("Scintilla"),_T("source"),0,rect
,this,0,0);
242 m_TextView
.Init(0,FALSE
);
243 m_TextView
.ShowWindow( SW_SHOW
);
244 //m_TextView.InsertText(_T("Abdadfasdf"));
245 m_wEditor
= m_TextView
.m_hWnd
;
248 m_ToolTip
.Create(this->GetParent());
250 ::AfxGetApp()->GetMainWnd();
251 return CView::OnCreate(lpcs
);
255 void CTortoiseGitBlameView::OnSize(UINT nType
,int cx
, int cy
)
259 rect
.left
=m_blamewidth
;
264 m_TextView
.MoveWindow(&rect
);
267 BOOL
CTortoiseGitBlameView::PreCreateWindow(CREATESTRUCT
& cs
)
269 return CView::PreCreateWindow(cs
);
272 // CTortoiseGitBlameView drawing
274 void CTortoiseGitBlameView::OnDraw(CDC
* /*pDC*/)
276 CTortoiseGitBlameDoc
* pDoc
= GetDocument();
281 DrawBlame(this->GetDC()->m_hDC
);
282 DrawLocatorBar(this->GetDC()->m_hDC
);
283 // TODO: add draw code for native data here
287 // CTortoiseGitBlameView printing
290 void CTortoiseGitBlameView::OnFilePrintPreview()
292 AFXPrintPreview(this);
295 BOOL
CTortoiseGitBlameView::OnPreparePrinting(CPrintInfo
* pInfo
)
297 // default preparation
298 return DoPreparePrinting(pInfo
);
301 void CTortoiseGitBlameView::OnBeginPrinting(CDC
* /*pDC*/, CPrintInfo
* /*pInfo*/)
303 // TODO: add extra initialization before printing
306 void CTortoiseGitBlameView::OnEndPrinting(CDC
* /*pDC*/, CPrintInfo
* /*pInfo*/)
308 // TODO: add cleanup after printing
311 void CTortoiseGitBlameView::OnRButtonUp(UINT nFlags
, CPoint point
)
313 LONG_PTR line
= SendEditor(SCI_GETFIRSTVISIBLELINE
);
314 LONG_PTR height
= SendEditor(SCI_TEXTHEIGHT
);
315 line
= line
+ (point
.y
/height
);
316 if (line
< (LONG
)m_CommitHash
.size())
318 if(m_ID
[line
] >= 0) // only show context menu if we have log data for it
321 ClientToScreen(&point
);
322 theApp
.GetContextMenuManager()->ShowPopupMenu(IDR_BLAME_POPUP
, point
.x
, point
.y
, this, TRUE
);
327 void CTortoiseGitBlameView::OnUpdateBlamePopupBlamePrevious(CCmdUI
*pCmdUI
)
329 if (m_ID
[m_MouseLine
] <= 1)
331 pCmdUI
->Enable(false);
335 pCmdUI
->Enable(true);
339 void CTortoiseGitBlameView::OnUpdateBlamePopupDiffPrevious(CCmdUI
*pCmdUI
)
341 if (m_ID
[m_MouseLine
] <= 1)
343 pCmdUI
->Enable(false);
347 pCmdUI
->Enable(true);
351 void CTortoiseGitBlameView::CopyHashToClipboard()
353 this->GetLogList()->CopySelectionToClipBoard(TRUE
);
356 // CTortoiseGitBlameView diagnostics
359 void CTortoiseGitBlameView::AssertValid() const
361 CView::AssertValid();
364 void CTortoiseGitBlameView::Dump(CDumpContext
& dc
) const
369 CTortoiseGitBlameDoc
* CTortoiseGitBlameView::GetDocument() const // non-debug version is inline
371 ASSERT(m_pDocument
->IsKindOf(RUNTIME_CLASS(CTortoiseGitBlameDoc
)));
372 return (CTortoiseGitBlameDoc
*)m_pDocument
;
377 // CTortoiseGitBlameView message handlers
378 CString
CTortoiseGitBlameView::GetAppDirectory()
382 DWORD bufferlen
= MAX_PATH
; // MAX_PATH is not the limit here!
385 bufferlen
+= MAX_PATH
; // MAX_PATH is not the limit here!
386 TCHAR
* pBuf
= new TCHAR
[bufferlen
];
387 len
= GetModuleFileName(NULL
, pBuf
, bufferlen
);
388 path
= CString(pBuf
, len
);
390 } while(len
== bufferlen
);
392 path
= path
.Left(path
.ReverseFind(_T('\\')));
393 //path = path.substr(0, path.rfind('\\') + 1);
398 // Return a color which is interpolated between c1 and c2.
399 // Slider controls the relative proportions as a percentage:
400 // Slider = 0 represents pure c1
401 // Slider = 50 represents equal mixture
402 // Slider = 100 represents pure c2
403 COLORREF
CTortoiseGitBlameView::InterColor(COLORREF c1
, COLORREF c2
, int Slider
)
407 // Limit Slider to 0..100% range
413 // The color components have to be treated individually.
414 r
= (GetRValue(c2
) * Slider
+ GetRValue(c1
) * (100 - Slider
)) / 100;
415 g
= (GetGValue(c2
) * Slider
+ GetGValue(c1
) * (100 - Slider
)) / 100;
416 b
= (GetBValue(c2
) * Slider
+ GetBValue(c1
) * (100 - Slider
)) / 100;
421 LRESULT
CTortoiseGitBlameView::SendEditor(UINT Msg
, WPARAM wParam
, LPARAM lParam
)
423 if (m_directFunction
)
425 return ((SciFnDirect
) m_directFunction
)(m_directPointer
, Msg
, wParam
, lParam
);
427 return ::SendMessage(m_wEditor
, Msg
, wParam
, lParam
);
430 void CTortoiseGitBlameView::GetRange(int start
, int end
, char *text
)
434 tr
.chrg
.cpMin
= start
;
438 SendMessage(m_wEditor
, EM_GETTEXTRANGE
, 0, reinterpret_cast<LPARAM
>(&tr
));
442 void CTortoiseGitBlameView::SetTitle()
445 char title
[MAX_PATH
+ 100];
446 strcpy_s(title
, MAX_PATH
+ 100, szTitle
);
447 strcat_s(title
, MAX_PATH
+ 100, " - ");
448 strcat_s(title
, MAX_PATH
+ 100, szViewtitle
);
449 ::SetWindowText(wMain
, title
);
453 BOOL
CTortoiseGitBlameView::OpenLogFile(const char *fileName
)
456 char logmsgbuf
[10000+1];
458 fopen_s(&File
, fileName
, "rb");
468 wchar_t wbuf
[MAX_LOG_LENGTH
+6];
471 len
= fread(&rev
, sizeof(LONG
), 1, File
);
478 len
= fread(&slength
, sizeof(int), 1, File
);
485 if (slength
> MAX_LOG_LENGTH
)
487 reallength
= slength
;
488 slength
= MAX_LOG_LENGTH
;
492 len
= fread(logmsgbuf
, sizeof(char), slength
, File
);
493 if (len
< (size_t)slength
)
499 msg
= CString(logmsgbuf
, slength
);
502 fseek(File
, reallength
-MAX_LOG_LENGTH
, SEEK_CUR
);
503 msg
= msg
+ _T("\n...");
505 int len2
= ::MultiByteToWideChar(CP_UTF8
, NULL
, msg
.c_str(), min(msg
.size(), MAX_LOG_LENGTH
+5), wbuf
, MAX_LOG_LENGTH
+5);
507 len2
= ::WideCharToMultiByte(CP_ACP
, NULL
, wbuf
, len2
, logmsgbuf
, MAX_LOG_LENGTH
+5, NULL
, NULL
);
509 msg
= CString(logmsgbuf
);
510 logmessages
[rev
] = msg
;
516 BOOL
CTortoiseGitBlameView::OpenFile(const char *fileName
)
519 SendEditor(SCI_SETREADONLY
, FALSE
);
520 SendEditor(SCI_CLEARALL
);
521 SendEditor(EM_EMPTYUNDOBUFFER
);
523 SendEditor(SCI_SETSAVEPOINT
);
524 SendEditor(SCI_CANCEL
);
525 SendEditor(SCI_SETUNDOCOLLECTION
, 0);
526 ::ShowWindow(m_wEditor
, SW_HIDE
);
534 char * lineptr
= NULL
;
535 char * trimptr
= NULL
;
536 //ignore the first two lines, they're of no interest to us
537 File
.getline(line
, _countof(line
));
538 File
.getline(line
, _countof(line
));
539 m_lowestrev
= LONG_MAX
;
544 File
.getline(line
, _countof(line
));
545 if (File
.gcount()>139)
547 mergelines
.push_back((line
[0] != ' '));
549 long rev
= _ttol(lineptr
);
551 m_lowestrev
= min(m_lowestrev
, rev
);
552 m_highestrev
= max(m_highestrev
, rev
);
554 rev
= _ttol(lineptr
);
555 origrevs
.push_back(rev
);
557 dates
.push_back(CString(lineptr
, 30));
559 // unfortunately, the 'path' entry can be longer than the 60 chars
560 // we made the column. We therefore have to step through the path
561 // string until we find a space
565 // TODO: how can we deal with the situation where the path has
566 // a space in it, but the space is after the 60 chars reserved
568 // The only way to deal with that would be to use a custom
569 // binary format for the blame file.
571 trimptr
= _tcschr(trimptr
, ' ');
572 } while ((trimptr
)&&(trimptr
+1 < lineptr
+61));
577 paths
.push_back(CString(lineptr
));
578 if (trimptr
+1 < lineptr
+61)
581 lineptr
= (trimptr
+1);
582 trimptr
= lineptr
+30;
583 while ((*trimptr
== ' ')&&(trimptr
> lineptr
))
586 authors
.push_back(CString(lineptr
));
588 // in case we find an UTF8 BOM at the beginning of the line, we remove it
589 if (((unsigned char)lineptr
[0] == 0xEF)&&((unsigned char)lineptr
[1] == 0xBB)&&((unsigned char)lineptr
[2] == 0xBF))
593 if (((unsigned char)lineptr
[0] == 0xBB)&&((unsigned char)lineptr
[1] == 0xEF)&&((unsigned char)lineptr
[2] == 0xBF))
597 // check each line for illegal utf8 sequences. If one is found, we treat
598 // the file as ASCII, otherwise we assume an UTF8 file.
599 char * utf8CheckBuf
= lineptr
;
600 while ((bUTF8
)&&(*utf8CheckBuf
))
602 if ((*utf8CheckBuf
== 0xC0)||(*utf8CheckBuf
== 0xC1)||(*utf8CheckBuf
>= 0xF5))
607 if ((*utf8CheckBuf
& 0xE0)==0xC0)
610 if (*utf8CheckBuf
== 0)
612 if ((*utf8CheckBuf
& 0xC0)!=0x80)
618 if ((*utf8CheckBuf
& 0xF0)==0xE0)
621 if (*utf8CheckBuf
== 0)
623 if ((*utf8CheckBuf
& 0xC0)!=0x80)
629 if (*utf8CheckBuf
== 0)
631 if ((*utf8CheckBuf
& 0xC0)!=0x80)
637 if ((*utf8CheckBuf
& 0xF8)==0xF0)
640 if (*utf8CheckBuf
== 0)
642 if ((*utf8CheckBuf
& 0xC0)!=0x80)
648 if (*utf8CheckBuf
== 0)
650 if ((*utf8CheckBuf
& 0xC0)!=0x80)
656 if (*utf8CheckBuf
== 0)
658 if ((*utf8CheckBuf
& 0xC0)!=0x80)
667 SendEditor(SCI_ADDTEXT
, _tcslen(lineptr
), reinterpret_cast<LPARAM
>(static_cast<char *>(lineptr
)));
668 SendEditor(SCI_ADDTEXT
, 2, (LPARAM
)_T("\r\n"));
670 } while (File
.gcount() > 0);
673 SendEditor(SCI_SETCODEPAGE
, SC_CP_UTF8
);
675 SendEditor(SCI_SETUNDOCOLLECTION
, 1);
676 ::SetFocus(m_wEditor
);
677 SendEditor(EM_EMPTYUNDOBUFFER
);
678 SendEditor(SCI_SETSAVEPOINT
);
679 SendEditor(SCI_GOTOPOS
, 0);
680 SendEditor(SCI_SETSCROLLWIDTHTRACKING
, TRUE
);
681 SendEditor(SCI_SETREADONLY
, TRUE
);
683 //check which lexer to use, depending on the filetype
684 SetupLexer(fileName
);
685 ::ShowWindow(m_wEditor
, SW_SHOW
);
687 ::InvalidateRect(wMain
, NULL
, TRUE
);
689 GetWindowRect(wMain
, &rc
);
690 SetWindowPos(wMain
, 0, rc
.left
, rc
.top
, rc
.right
-rc
.left
-1, rc
.bottom
- rc
.top
, 0);
695 void CTortoiseGitBlameView::SetAStyle(int style
, COLORREF fore
, COLORREF back
, int size
, CString
*face
)
697 SendEditor(SCI_STYLESETFORE
, style
, fore
);
698 SendEditor(SCI_STYLESETBACK
, style
, back
);
700 SendEditor(SCI_STYLESETSIZE
, style
, size
);
702 SendEditor(SCI_STYLESETFONT
, style
, reinterpret_cast<LPARAM
>(this->m_TextView
.StringForControl(*face
).GetBuffer()));
705 void CTortoiseGitBlameView::InitialiseEditor()
708 m_directFunction
= ::SendMessage(m_wEditor
, SCI_GETDIRECTFUNCTION
, 0, 0);
709 m_directPointer
= ::SendMessage(m_wEditor
, SCI_GETDIRECTPOINTER
, 0, 0);
710 // Set up the global default style. These attributes are used wherever no explicit choices are made.
711 SetAStyle(STYLE_DEFAULT
,
714 (DWORD
)CRegStdDWORD(_T("Software\\TortoiseGit\\BlameFontSize"), 10),
715 &CString(((stdstring
)CRegStdString(_T("Software\\TortoiseGit\\BlameFontName"), _T("Courier New"))).c_str())
717 SendEditor(SCI_SETTABWIDTH
, (DWORD
)CRegStdDWORD(_T("Software\\TortoiseGit\\BlameTabSize"), 4));
718 SendEditor(SCI_SETREADONLY
, TRUE
);
719 LRESULT pix
= SendEditor(SCI_TEXTWIDTH
, STYLE_LINENUMBER
, (LPARAM
)this->m_TextView
.StringForControl(_T("_99999")).GetBuffer());
721 SendEditor(SCI_SETMARGINWIDTHN
, 0, pix
);
723 SendEditor(SCI_SETMARGINWIDTHN
, 0);
724 SendEditor(SCI_SETMARGINWIDTHN
, 1);
725 SendEditor(SCI_SETMARGINWIDTHN
, 2);
726 //Set the default windows colors for edit controls
727 SendEditor(SCI_STYLESETFORE
, STYLE_DEFAULT
, ::GetSysColor(COLOR_WINDOWTEXT
));
728 SendEditor(SCI_STYLESETBACK
, STYLE_DEFAULT
, ::GetSysColor(COLOR_WINDOW
));
729 SendEditor(SCI_SETSELFORE
, TRUE
, ::GetSysColor(COLOR_HIGHLIGHTTEXT
));
730 SendEditor(SCI_SETSELBACK
, TRUE
, ::GetSysColor(COLOR_HIGHLIGHT
));
731 SendEditor(SCI_SETCARETFORE
, ::GetSysColor(COLOR_WINDOWTEXT
));
732 m_regOldLinesColor
= CRegStdDWORD(_T("Software\\TortoiseGit\\BlameOldColor"), RGB(230, 230, 255));
733 m_regNewLinesColor
= CRegStdDWORD(_T("Software\\TortoiseGit\\BlameNewColor"), RGB(255, 230, 230));
735 this->m_TextView
.Call(SCI_SETWRAPMODE
, SC_WRAP_NONE
);
739 void CTortoiseGitBlameView::StartSearch()
744 // Initialize FINDREPLACE
745 if (fr
.Flags
& FR_MATCHCASE
)
747 SecureZeroMemory(&fr
, sizeof(fr
));
748 fr
.lStructSize
= sizeof(fr
);
749 fr
.hwndOwner
= wMain
;
750 fr
.lpstrFindWhat
= szFindWhat
;
751 fr
.wFindWhatLen
= 80;
752 fr
.Flags
= FR_HIDEUPDOWN
| FR_HIDEWHOLEWORD
;
753 fr
.Flags
|= bCase
? FR_MATCHCASE
: 0;
755 currentDialog
= FindText(&fr
);
758 bool CTortoiseGitBlameView::DoSearch(CString what
, DWORD flags
)
762 int pos
= SendEditor(SCI_GETCURRENTPOS
);
763 int line
= SendEditor(SCI_LINEFROMPOSITION
, pos
);
765 bool bCaseSensitive
= !!(flags
& FR_MATCHCASE
);
767 //strcpy_s(szWhat, sizeof(szWhat), what);
771 what
=what
.MakeLower();
774 //CString sWhat = CString(szWhat);
781 int bufsize
= SendEditor(SCI_GETLINE
, i
);
782 char * linebuf
= new char[bufsize
+1];
783 SecureZeroMemory(linebuf
, bufsize
+1);
784 SendEditor(SCI_GETLINE
, i
, (LPARAM
)linebuf
);
785 CString oneline
=this->m_TextView
.StringFromControl(linebuf
);
788 oneline
=oneline
.MakeLower();
790 //_stprintf_s(buf, 20, _T("%ld"), revs[i]);
791 if (this->m_Authors
[i
].Find(what
)>=0)
793 else if ((!bCaseSensitive
)&&(this->m_Authors
[i
].MakeLower().Find(what
)>=0))
795 else if (oneline
.Find(what
) >=0)
801 if(i
>=(signed int)m_CommitHash
.size())
803 }while(i
!=line
&&(!bFound
));
808 int selstart
= SendEditor(SCI_GETCURRENTPOS
);
809 int selend
= SendEditor(SCI_POSITIONFROMLINE
, i
);
810 SendEditor(SCI_SETSELECTIONSTART
, selstart
);
811 SendEditor(SCI_SETSELECTIONEND
, selend
);
812 m_SelectedLine
= i
-1;
816 ::MessageBox(wMain
, what
+_T(" not found"), _T("CTortoiseGitBlameView"), MB_ICONINFORMATION
);
822 bool CTortoiseGitBlameView::GotoLine(long line
)
827 if ((unsigned long)line
>= m_CommitHash
.size())
829 line
= m_CommitHash
.size()-1;
832 int nCurrentPos
= SendEditor(SCI_GETCURRENTPOS
);
833 int nCurrentLine
= SendEditor(SCI_LINEFROMPOSITION
,nCurrentPos
);
834 int nFirstVisibleLine
= SendEditor(SCI_GETFIRSTVISIBLELINE
);
835 int nLinesOnScreen
= SendEditor(SCI_LINESONSCREEN
);
837 if ( line
>=nFirstVisibleLine
&& line
<=nFirstVisibleLine
+nLinesOnScreen
)
840 SendEditor(SCI_GOTOLINE
, line
);
844 // Place the requested line one third from the top
845 if ( line
> nCurrentLine
)
847 SendEditor(SCI_GOTOLINE
, (WPARAM
)(line
+(int)nLinesOnScreen
*(2/3.0)));
851 SendEditor(SCI_GOTOLINE
, (WPARAM
)(line
-(int)nLinesOnScreen
*(1/3.0)));
855 // Highlight the line
856 int nPosStart
= SendEditor(SCI_POSITIONFROMLINE
,line
);
857 int nPosEnd
= SendEditor(SCI_GETLINEENDPOSITION
,line
);
858 SendEditor(SCI_SETSEL
,nPosEnd
,nPosStart
);
863 bool CTortoiseGitBlameView::ScrollToLine(long line
)
868 int nCurrentLine
= SendEditor(SCI_GETFIRSTVISIBLELINE
);
870 int scrolldelta
= line
- nCurrentLine
;
871 SendEditor(SCI_LINESCROLL
, 0, scrolldelta
);
876 void CTortoiseGitBlameView::CopySelectedLogToClipboard()
878 this->GetLogList()->CopySelectionToClipBoard(FALSE
);
881 void CTortoiseGitBlameView::BlamePreviousRevision()
884 procCmd
+= _T(" /path:\"");
885 procCmd
+= ((CMainFrame
*)::AfxGetApp()->GetMainWnd())->GetActiveView()->GetDocument()->GetPathName();
886 procCmd
+= _T("\" ");
887 procCmd
+= _T(" /command:blame");
888 procCmd
+= _T(" /endrev:") + this->GetLogData()->GetGitRevAt(this->GetLogData()->size()-m_ID
[m_MouseLine
]+1).m_CommitHash
.ToString();
891 PROCESS_INFORMATION process
;
892 memset(&startup
, 0, sizeof(startup
));
893 startup
.cb
= sizeof(startup
);
894 memset(&process
, 0, sizeof(process
));
895 CString tortoiseProcPath
= CPathUtils::GetAppDirectory() + _T("TortoiseProc.exe");
897 if (CreateProcess(tortoiseProcPath
, procCmd
.GetBuffer(), NULL
, NULL
, FALSE
, 0, 0, 0, &startup
, &process
))
899 CloseHandle(process
.hThread
);
900 CloseHandle(process
.hProcess
);
904 void CTortoiseGitBlameView::DiffPreviousRevision()
907 procCmd
+= _T(" /path:\"");
908 procCmd
+= ((CMainFrame
*)::AfxGetApp()->GetMainWnd())->GetActiveView()->GetDocument()->GetPathName();
909 procCmd
+= _T("\" ");
910 procCmd
+= _T(" /command:diff");
911 procCmd
+= _T(" /startrev:") + this->GetLogData()->GetGitRevAt(this->GetLogData()->size() - m_ID
[m_MouseLine
]).m_CommitHash
.ToString();
912 procCmd
+= _T(" /endrev:") + this->GetLogData()->GetGitRevAt(this->GetLogData()->size() - m_ID
[m_MouseLine
] + 1).m_CommitHash
.ToString();
915 PROCESS_INFORMATION process
;
916 memset(&startup
, 0, sizeof(startup
));
917 startup
.cb
= sizeof(startup
);
918 memset(&process
, 0, sizeof(process
));
919 CString tortoiseProcPath
= CPathUtils::GetAppDirectory() + _T("TortoiseProc.exe");
921 if (CreateProcess(tortoiseProcPath
, procCmd
.GetBuffer(), NULL
, NULL
, FALSE
, 0, 0, 0, &startup
, &process
))
923 CloseHandle(process
.hThread
);
924 CloseHandle(process
.hProcess
);
928 void CTortoiseGitBlameView::ShowLog()
931 procCmd
+= _T(" /path:\"");
932 procCmd
+= ((CMainFrame
*)::AfxGetApp()->GetMainWnd())->GetActiveView()->GetDocument()->GetPathName();
933 procCmd
+= _T("\" ");
934 procCmd
+= _T(" /command:log");
935 procCmd
+= _T(" /rev:") + this->GetLogData()->GetGitRevAt(this->GetLogData()->size() - m_ID
[m_MouseLine
]).m_CommitHash
.ToString();
938 PROCESS_INFORMATION process
;
939 memset(&startup
, 0, sizeof(startup
));
940 startup
.cb
= sizeof(startup
);
941 memset(&process
, 0, sizeof(process
));
942 CString tortoiseProcPath
= CPathUtils::GetAppDirectory() + _T("TortoiseProc.exe");
944 if (CreateProcess(tortoiseProcPath
, procCmd
.GetBuffer(), NULL
, NULL
, FALSE
, 0, 0, 0, &startup
, &process
))
946 CloseHandle(process
.hThread
);
947 CloseHandle(process
.hProcess
);
951 void CTortoiseGitBlameView::Notify(SCNotification
*notification
)
953 switch (notification
->nmhdr
.code
)
955 case SCN_SAVEPOINTREACHED
:
958 case SCN_SAVEPOINTLEFT
:
961 // InvalidateRect(wBlame, NULL, FALSE);
962 // InvalidateRect(wLocator, NULL, FALSE);
965 // if ((m_colorage)&&(notification->line < (int)revs.size()))
967 // notification->lParam = InterColor(DWORD(m_regOldLinesColor), DWORD(m_regNewLinesColor), (revs[notification->line]-m_lowestrev)*100/((m_highestrev-m_lowestrev)+1));
973 void CTortoiseGitBlameView::Command(int id
)
979 // ::PostQuitMessage(0);
984 case ID_COPYTOCLIPBOARD
:
985 CopySelectedLogToClipboard();
987 case ID_BLAME_PREVIOUS_REVISION
:
988 BlamePreviousRevision();
990 case ID_DIFF_PREVIOUS_REVISION
:
991 DiffPreviousRevision();
996 case ID_EDIT_GOTOLINE
:
999 case ID_VIEW_COLORAGEOFLINES
:
1001 m_colorage
= !m_colorage
;
1002 HMENU hMenu
= GetMenu(wMain
);
1003 UINT uCheck
= MF_BYCOMMAND
;
1004 uCheck
|= m_colorage
? MF_CHECKED
: MF_UNCHECKED
;
1005 CheckMenuItem(hMenu
, ID_VIEW_COLORAGEOFLINES
, uCheck
);
1010 case ID_VIEW_MERGEPATH
:
1012 ShowPath
= !ShowPath
;
1013 HMENU hMenu
= GetMenu(wMain
);
1014 UINT uCheck
= MF_BYCOMMAND
;
1015 uCheck
|= ShowPath
? MF_CHECKED
: MF_UNCHECKED
;
1016 CheckMenuItem(hMenu
, ID_VIEW_MERGEPATH
, uCheck
);
1027 LONG
CTortoiseGitBlameView::GetBlameWidth()
1029 LONG blamewidth
= 0;
1032 HDC hDC
= this->GetDC()->m_hDC
;
1033 HFONT oldfont
= (HFONT
)::SelectObject(hDC
, m_font
);
1035 TCHAR buf
[MAX_PATH
];
1037 ::GetTextExtentPoint32(hDC
, _T("fffffff"), 7, &width
);
1038 m_revwidth
= width
.cx
+ BLAMESPACE
;
1039 blamewidth
+= m_revwidth
;
1042 _stprintf_s(buf
, MAX_PATH
, _T("%d"), m_CommitHash
.size());
1043 ::GetTextExtentPoint(hDC
, buf
, _tcslen(buf
), &width
);
1044 m_linewidth
= width
.cx
+ BLAMESPACE
;
1045 blamewidth
+= m_revwidth
;
1050 _stprintf_s(buf
, MAX_PATH
, _T("%30s"), _T("31.08.2001 06:24:14"));
1051 ::GetTextExtentPoint32(hDC
, buf
, _tcslen(buf
), &width
);
1052 m_datewidth
= width
.cx
+ BLAMESPACE
;
1053 blamewidth
+= m_datewidth
;
1057 SIZE maxwidth
= {0};
1059 for (unsigned int i
=0;i
<this->m_Authors
.size();i
++)
1060 //for (std::vector<CString>::iterator I = authors.begin(); I != authors.end(); ++I)
1062 ::GetTextExtentPoint32(hDC
,m_Authors
[i
] , m_Authors
[i
].GetLength(), &width
);
1063 if (width
.cx
> maxwidth
.cx
)
1066 m_authorwidth
= maxwidth
.cx
+ BLAMESPACE
;
1067 blamewidth
+= m_authorwidth
;
1072 SIZE maxwidth
= {0};
1073 for (std::vector
<CString
>::iterator I
= paths
.begin(); I
!= paths
.end(); ++I
)
1075 ::GetTextExtentPoint32(hDC
, I
->c_str(), I
->size(), &width
);
1076 if (width
.cx
> maxwidth
.cx
)
1079 m_pathwidth
= maxwidth
.cx
+ BLAMESPACE
;
1080 blamewidth
+= m_pathwidth
;
1083 ::SelectObject(hDC
, oldfont
);
1084 POINT pt
= {blamewidth
, 0};
1085 LPtoDP(hDC
, &pt
, 1);
1086 m_blamewidth
= pt
.x
;
1087 //::ReleaseDC(wBlame, hDC);
1089 //return m_blamewidth;
1094 void CTortoiseGitBlameView::CreateFont()
1100 HDC hDC
= ::GetDC(wBlame
);
1101 lf
.lfHeight
= -MulDiv((DWORD
)CRegStdDWORD(_T("Software\\TortoiseGit\\BlameFontSize"), 10), GetDeviceCaps(hDC
, LOGPIXELSY
), 72);
1102 lf
.lfCharSet
= DEFAULT_CHARSET
;
1103 CRegStdString fontname
= CRegStdString(_T("Software\\TortoiseGit\\BlameFontName"), _T("Courier New"));
1104 _tcscpy_s(lf
.lfFaceName
, 32, ((stdstring
)fontname
).c_str());
1105 m_font
= ::CreateFontIndirect(&lf
);
1108 m_italicfont
= ::CreateFontIndirect(&lf
);
1110 ::ReleaseDC(wBlame
, hDC
);
1112 //m_TextView.SetFont(lf.lfFaceName,((DWORD)CRegStdDWORD(_T("Software\\TortoiseGit\\BlameFontSize"), 10)));
1115 void CTortoiseGitBlameView::DrawBlame(HDC hDC
)
1123 HFONT oldfont
= NULL
;
1124 LONG_PTR line
= SendEditor(SCI_GETFIRSTVISIBLELINE
);
1125 LONG_PTR linesonscreen
= SendEditor(SCI_LINESONSCREEN
);
1126 LONG_PTR height
= SendEditor(SCI_TEXTHEIGHT
);
1128 TCHAR buf
[MAX_PATH
];
1131 //::GetClientRect(this->m_hWnd, &rc);
1132 for (LRESULT i
=line
; i
<(line
+linesonscreen
); ++i
)
1135 if (i
< (int)m_CommitHash
.size())
1137 // if (mergelines[i])
1138 // oldfont = (HFONT)::SelectObject(hDC, m_italicfont);
1140 oldfont
= (HFONT
)::SelectObject(hDC
, m_font
);
1141 ::SetBkColor(hDC
, m_windowcolor
);
1142 ::SetTextColor(hDC
, m_textcolor
);
1143 if (!m_CommitHash
[i
].IsEmpty())
1145 //if (m_CommitHash[i].Compare(m_MouseHash)==0)
1146 // ::SetBkColor(hDC, m_mouseauthorcolor);
1147 if (m_CommitHash
[i
] == m_SelectedHash
)
1149 ::SetBkColor(hDC
, m_selectedauthorcolor
);
1150 ::SetTextColor(hDC
, m_texthighlightcolor
);
1155 if(m_MouseLine
== i
)
1156 ::SetBkColor(hDC
, m_mouserevcolor
);
1158 //if ((revs[i] == m_mouserev)&&(!sel))
1159 // ::SetBkColor(hDC, m_mouserevcolor);
1160 //if (revs[i] == m_selectedrev)
1162 // ::SetBkColor(hDC, m_selectedrevcolor);
1163 // ::SetTextColor(hDC, m_texthighlightcolor);
1167 str
= m_CommitHash
[i
].ToString().Left(6);
1169 //_stprintf_s(buf, MAX_PATH, _T("%8ld "), revs[i]);
1171 rc
.left
=LOCATOR_WIDTH
;
1173 rc
.right
= rc
.left
+ m_blamewidth
;
1174 ::ExtTextOut(hDC
, LOCATOR_WIDTH
, Y
, ETO_CLIPPED
, &rc
, str
, str
.GetLength(), 0);
1175 int Left
= m_revwidth
;
1179 rc
.right
= rc
.left
+ Left
+ m_authorwidth
;
1180 //_stprintf_s(buf, MAX_PATH, _T("%-30s "), authors[i].c_str());
1181 ::ExtTextOut(hDC
, Left
, Y
, ETO_CLIPPED
, &rc
, m_Authors
[i
], m_Authors
[i
].GetLength(), 0);
1182 Left
+= m_authorwidth
;
1187 rc
.right
= rc
.left
+ Left
+ m_datewidth
;
1188 _stprintf_s(buf
, MAX_PATH
, _T("%30s "), dates
[i
].c_str());
1189 ::ExtTextOut(hDC
, Left
, Y
, ETO_CLIPPED
, &rc
, buf
, _tcslen(buf
), 0);
1190 Left
+= m_datewidth
;
1197 rc
.right
= rc
.left
+ Left
+ m_pathwidth
;
1198 _stprintf_s(buf
, MAX_PATH
, _T("%-60s "), paths
[i
].c_str());
1199 ::ExtTextOut(hDC
, Left
, Y
, ETO_CLIPPED
, &rc
, buf
, _tcslen(buf
), 0);
1200 Left
+= m_authorwidth
;
1203 if ((i
==m_SelectedLine
)&&(m_pFindDialog
))
1206 brush
.lbColor
= m_textcolor
;
1208 brush
.lbStyle
= BS_SOLID
;
1209 HPEN pen
= ExtCreatePen(PS_SOLID
| PS_GEOMETRIC
, 2, &brush
, 0, NULL
);
1210 HGDIOBJ hPenOld
= SelectObject(hDC
, pen
);
1213 rc2
.bottom
= Y
+ height
;
1214 ::MoveToEx(hDC
, rc2
.left
, rc2
.top
, NULL
);
1215 ::LineTo(hDC
, rc2
.right
, rc2
.top
);
1216 ::LineTo(hDC
, rc2
.right
, rc2
.bottom
);
1217 ::LineTo(hDC
, rc2
.left
, rc2
.bottom
);
1218 ::LineTo(hDC
, rc2
.left
, rc2
.top
);
1219 SelectObject(hDC
, hPenOld
);
1223 ::SelectObject(hDC
, oldfont
);
1227 ::SetBkColor(hDC
, m_windowcolor
);
1228 for (int j
=0; j
< MAX_PATH
; ++j
)
1230 ::ExtTextOut(hDC
, 0, Y
, ETO_CLIPPED
, &rc
, buf
, MAX_PATH
-1, 0);
1236 void CTortoiseGitBlameView::DrawHeader(HDC hDC
)
1243 HFONT oldfont
= (HFONT
)::SelectObject(hDC
, GetStockObject(DEFAULT_GUI_FONT
));
1244 ::GetClientRect(wHeader
, &rc
);
1246 ::SetBkColor(hDC
, ::GetSysColor(COLOR_BTNFACE
));
1248 TCHAR szText
[MAX_LOADSTRING
];
1249 LoadString(app
.hResource
, IDS_HEADER_REVISION
, szText
, MAX_LOADSTRING
);
1250 ::ExtTextOut(hDC
, LOCATOR_WIDTH
, 0, ETO_CLIPPED
, &rc
, szText
, _tcslen(szText
), 0);
1251 int Left
= m_revwidth
+LOCATOR_WIDTH
;
1254 LoadString(app
.hResource
, IDS_HEADER_DATE
, szText
, MAX_LOADSTRING
);
1255 ::ExtTextOut(hDC
, Left
, 0, ETO_CLIPPED
, &rc
, szText
, _tcslen(szText
), 0);
1256 Left
+= m_datewidth
;
1260 LoadString(app
.hResource
, IDS_HEADER_AUTHOR
, szText
, MAX_LOADSTRING
);
1261 ::ExtTextOut(hDC
, Left
, 0, ETO_CLIPPED
, &rc
, szText
, _tcslen(szText
), 0);
1262 Left
+= m_authorwidth
;
1266 LoadString(app
.hResource
, IDS_HEADER_PATH
, szText
, MAX_LOADSTRING
);
1267 ::ExtTextOut(hDC
, Left
, 0, ETO_CLIPPED
, &rc
, szText
, _tcslen(szText
), 0);
1268 Left
+= m_pathwidth
;
1270 LoadString(app
.hResource
, IDS_HEADER_LINE
, szText
, MAX_LOADSTRING
);
1271 ::ExtTextOut(hDC
, Left
, 0, ETO_CLIPPED
, &rc
, szText
, _tcslen(szText
), 0);
1273 ::SelectObject(hDC
, oldfont
);
1277 void CTortoiseGitBlameView::DrawLocatorBar(HDC hDC
)
1282 LONG_PTR line
= SendEditor(SCI_GETFIRSTVISIBLELINE
);
1283 LONG_PTR linesonscreen
= SendEditor(SCI_LINESONSCREEN
);
1285 COLORREF blackColor
= GetSysColor(COLOR_WINDOWTEXT
);
1288 //::GetClientRect(wLocator, &rc);
1289 this->GetClientRect(&rc
);
1291 rc
.right
=LOCATOR_WIDTH
;
1294 LONG height
= rc
.bottom
-rc
.top
;
1295 LONG currentLine
= 0;
1297 // draw the colored bar
1298 for (std::vector
<LONG
>::const_iterator it
= m_ID
.begin(); it
!= m_ID
.end(); ++it
)
1301 // get the line color
1302 COLORREF cr
= InterColor(DWORD(m_regOldLinesColor
), DWORD(m_regNewLinesColor
), (*it
- m_lowestrev
)*100/((m_highestrev
-m_lowestrev
)+1));
1303 if ((currentLine
> line
)&&(currentLine
<= (line
+ linesonscreen
)))
1305 cr
= InterColor(cr
, blackColor
, 10);
1307 SetBkColor(hDC
, cr
);
1309 lineRect
.bottom
= (currentLine
* height
/ m_ID
.size());
1310 ::ExtTextOut(hDC
, 0, 0, ETO_OPAQUE
, &lineRect
, NULL
, 0, NULL
);
1311 Y
= lineRect
.bottom
;
1316 // now draw two lines indicating the scroll position of the source view
1317 SetBkColor(hDC
, blackColor
);
1318 lineRect
.top
= line
* height
/ m_ID
.size();
1319 lineRect
.bottom
= lineRect
.top
+1;
1320 ::ExtTextOut(hDC
, 0, 0, ETO_OPAQUE
, &lineRect
, NULL
, 0, NULL
);
1321 lineRect
.top
= (line
+ linesonscreen
) * height
/ m_ID
.size();
1322 lineRect
.bottom
= lineRect
.top
+1;
1323 ::ExtTextOut(hDC
, 0, 0, ETO_OPAQUE
, &lineRect
, NULL
, 0, NULL
);
1328 void CTortoiseGitBlameView::StringExpand(LPSTR str
)
1333 cPos
= strchr(cPos
, '\n');
1336 memmove(cPos
+1, cPos
, strlen(cPos
)*sizeof(char));
1341 } while (cPos
!= NULL
);
1343 void CTortoiseGitBlameView::StringExpand(LPWSTR str
)
1345 wchar_t * cPos
= str
;
1348 cPos
= wcschr(cPos
, '\n');
1351 memmove(cPos
+1, cPos
, wcslen(cPos
)*sizeof(wchar_t));
1356 } while (cPos
!= NULL
);
1359 // Forward declarations of functions included in this code module:
1360 ATOM
MyRegisterClass(HINSTANCE hResource
);
1361 ATOM
MyRegisterBlameClass(HINSTANCE hResource
);
1362 ATOM
MyRegisterHeaderClass(HINSTANCE hResource
);
1363 ATOM
MyRegisterLocatorClass(HINSTANCE hResource
);
1364 BOOL
InitInstance(HINSTANCE
, int);
1365 LRESULT CALLBACK
WndProc(HWND
, UINT
, WPARAM
, LPARAM
);
1366 LRESULT CALLBACK
WndBlameProc(HWND
, UINT
, WPARAM
, LPARAM
);
1367 LRESULT CALLBACK
WndHeaderProc(HWND
, UINT
, WPARAM
, LPARAM
);
1368 LRESULT CALLBACK
WndLocatorProc(HWND
, UINT
, WPARAM
, LPARAM
);
1369 UINT uFindReplaceMsg
;
1372 int APIENTRY
_tWinMain(HINSTANCE hInstance
,
1373 HINSTANCE
/*hPrevInstance*/,
1377 app
.hInstance
= hInstance
;
1381 if (::LoadLibrary("SciLexer.DLL") == NULL
)
1384 CRegStdDWORD loc
= CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), 1033);
1388 app
.hResource
= langDLL
.Init(_T("CTortoiseGitBlameView"), langId
);
1389 if (app
.hResource
== NULL
)
1390 app
.hResource
= app
.hInstance
;
1392 // Initialize global strings
1393 LoadString(app
.hResource
, IDS_APP_TITLE
, szTitle
, MAX_LOADSTRING
);
1394 LoadString(app
.hResource
, IDC_TortoiseGitBlameView
, szWindowClass
, MAX_LOADSTRING
);
1395 LoadString(app
.hResource
, IDS_SEARCHNOTFOUND
, searchstringnotfound
, MAX_LOADSTRING
);
1396 MyRegisterClass(app
.hResource
);
1397 MyRegisterBlameClass(app
.hResource
);
1398 MyRegisterHeaderClass(app
.hResource
);
1399 MyRegisterLocatorClass(app
.hResource
);
1401 // Perform application initialization:
1402 if (!InitInstance (app
.hResource
, nCmdShow
))
1408 SecureZeroMemory(szViewtitle
, MAX_PATH
);
1409 SecureZeroMemory(szOrigPath
, MAX_PATH
);
1410 char blamefile
[MAX_PATH
] = {0};
1411 char logfile
[MAX_PATH
] = {0};
1413 CCmdLineParser
parser(lpCmdLine
);
1418 _tcscpy_s(blamefile
, MAX_PATH
, __argv
[1]);
1422 _tcscpy_s(logfile
, MAX_PATH
, __argv
[2]);
1426 _tcscpy_s(szViewtitle
, MAX_PATH
, __argv
[3]);
1427 if (parser
.HasVal(_T("revrange")))
1429 _tcscat_s(szViewtitle
, MAX_PATH
, _T(" : "));
1430 _tcscat_s(szViewtitle
, MAX_PATH
, parser
.GetVal(_T("revrange")));
1433 if ((_tcslen(blamefile
)==0) || parser
.HasKey(_T("?")) || parser
.HasKey(_T("help")))
1435 TCHAR szInfo
[MAX_LOADSTRING
];
1436 LoadString(app
.hResource
, IDS_COMMANDLINE_INFO
, szInfo
, MAX_LOADSTRING
);
1437 MessageBox(NULL
, szInfo
, _T("CTortoiseGitBlameView"), MB_ICONERROR
);
1442 if ( parser
.HasKey(_T("path")) )
1444 _tcscpy_s(szOrigPath
, MAX_PATH
, parser
.GetVal(_T("path")));
1446 app
.bIgnoreEOL
= parser
.HasKey(_T("ignoreeol"));
1447 app
.bIgnoreSpaces
= parser
.HasKey(_T("ignorespaces"));
1448 app
.bIgnoreAllSpaces
= parser
.HasKey(_T("ignoreallspaces"));
1450 app
.SendEditor(SCI_SETCODEPAGE
, GetACP());
1451 app
.OpenFile(blamefile
);
1452 if (_tcslen(logfile
)>0)
1453 app
.OpenLogFile(logfile
);
1455 if (parser
.HasKey(_T("line")))
1457 app
.GotoLine(parser
.GetLongVal(_T("line")));
1460 CheckMenuItem(GetMenu(app
.wMain
), ID_VIEW_COLORAGEOFLINES
, MF_CHECKED
|MF_BYCOMMAND
);
1463 hAccelTable
= LoadAccelerators(app
.hResource
, (LPCTSTR
)IDC_TortoiseGitBlameView
);
1469 going
= GetMessage(&msg
, NULL
, 0, 0);
1470 if (app
.currentDialog
&& going
)
1472 if (!IsDialogMessage(app
.currentDialog
, &msg
))
1474 if (TranslateAccelerator(msg
.hwnd
, hAccelTable
, &msg
) == 0)
1476 TranslateMessage(&msg
);
1477 DispatchMessage(&msg
);
1483 if (TranslateAccelerator(app
.wMain
, hAccelTable
, &msg
) == 0)
1485 TranslateMessage(&msg
);
1486 DispatchMessage(&msg
);
1494 ATOM
MyRegisterClass(HINSTANCE hResource
)
1498 wcex
.cbSize
= sizeof(WNDCLASSEX
);
1500 wcex
.style
= CS_HREDRAW
| CS_VREDRAW
;
1501 wcex
.lpfnWndProc
= (WNDPROC
)WndProc
;
1502 wcex
.cbClsExtra
= 0;
1503 wcex
.cbWndExtra
= 0;
1504 wcex
.hInstance
= hResource
;
1505 wcex
.hIcon
= LoadIcon(hResource
, (LPCTSTR
)IDI_TortoiseGitBlameView
);
1506 wcex
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
1507 wcex
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+1);
1508 wcex
.lpszMenuName
= (LPCTSTR
)IDC_TortoiseGitBlameView
;
1509 wcex
.lpszClassName
= szWindowClass
;
1510 wcex
.hIconSm
= LoadIcon(wcex
.hInstance
, (LPCTSTR
)IDI_SMALL
);
1512 return RegisterClassEx(&wcex
);
1515 ATOM
MyRegisterBlameClass(HINSTANCE hResource
)
1519 wcex
.cbSize
= sizeof(WNDCLASSEX
);
1521 wcex
.style
= CS_HREDRAW
| CS_VREDRAW
;
1522 wcex
.lpfnWndProc
= (WNDPROC
)WndBlameProc
;
1523 wcex
.cbClsExtra
= 0;
1524 wcex
.cbWndExtra
= 0;
1525 wcex
.hInstance
= hResource
;
1526 wcex
.hIcon
= LoadIcon(hResource
, (LPCTSTR
)IDI_TortoiseGitBlameView
);
1527 wcex
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
1528 wcex
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+1);
1529 wcex
.lpszMenuName
= 0;
1530 wcex
.lpszClassName
= _T("TortoiseGitBlameViewBlame");
1531 wcex
.hIconSm
= LoadIcon(wcex
.hInstance
, (LPCTSTR
)IDI_SMALL
);
1533 return RegisterClassEx(&wcex
);
1536 ATOM
MyRegisterHeaderClass(HINSTANCE hResource
)
1540 wcex
.cbSize
= sizeof(WNDCLASSEX
);
1542 wcex
.style
= CS_HREDRAW
| CS_VREDRAW
;
1543 wcex
.lpfnWndProc
= (WNDPROC
)WndHeaderProc
;
1544 wcex
.cbClsExtra
= 0;
1545 wcex
.cbWndExtra
= 0;
1546 wcex
.hInstance
= hResource
;
1547 wcex
.hIcon
= LoadIcon(hResource
, (LPCTSTR
)IDI_TortoiseGitBlameView
);
1548 wcex
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
1549 wcex
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+1);
1550 wcex
.lpszMenuName
= 0;
1551 wcex
.lpszClassName
= _T("TortoiseGitBlameViewHeader");
1552 wcex
.hIconSm
= LoadIcon(wcex
.hInstance
, (LPCTSTR
)IDI_SMALL
);
1554 return RegisterClassEx(&wcex
);
1557 ATOM
MyRegisterLocatorClass(HINSTANCE hResource
)
1561 wcex
.cbSize
= sizeof(WNDCLASSEX
);
1563 wcex
.style
= CS_HREDRAW
| CS_VREDRAW
;
1564 wcex
.lpfnWndProc
= (WNDPROC
)WndLocatorProc
;
1565 wcex
.cbClsExtra
= 0;
1566 wcex
.cbWndExtra
= 0;
1567 wcex
.hInstance
= hResource
;
1568 wcex
.hIcon
= LoadIcon(hResource
, (LPCTSTR
)IDI_TortoiseGitBlameView
);
1569 wcex
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
1570 wcex
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+1);
1571 wcex
.lpszMenuName
= 0;
1572 wcex
.lpszClassName
= _T("TortoiseGitBlameViewLocator");
1573 wcex
.hIconSm
= LoadIcon(wcex
.hInstance
, (LPCTSTR
)IDI_SMALL
);
1575 return RegisterClassEx(&wcex
);
1578 BOOL
InitInstance(HINSTANCE hResource
, int nCmdShow
)
1580 app
.wMain
= CreateWindow(szWindowClass
, szTitle
, WS_OVERLAPPEDWINDOW
,
1581 CW_USEDEFAULT
, 0, CW_USEDEFAULT
, 0, NULL
, NULL
, hResource
, NULL
);
1588 CRegStdDWORD
pos(_T("Software\\TortoiseGit\\TBlamePos"), 0);
1589 CRegStdDWORD
width(_T("Software\\TortoiseGit\\TBlameSize"), 0);
1590 CRegStdDWORD
state(_T("Software\\TortoiseGit\\TBlameState"), 0);
1591 if (DWORD(pos
) && DWORD(width
))
1594 rc
.left
= LOWORD(DWORD(pos
));
1595 rc
.top
= HIWORD(DWORD(pos
));
1596 rc
.right
= rc
.left
+ LOWORD(DWORD(width
));
1597 rc
.bottom
= rc
.top
+ HIWORD(DWORD(width
));
1598 HMONITOR hMon
= MonitorFromRect(&rc
, MONITOR_DEFAULTTONULL
);
1601 // only restore the window position if the monitor is valid
1602 MoveWindow(app
.wMain
, LOWORD(DWORD(pos
)), HIWORD(DWORD(pos
)),
1603 LOWORD(DWORD(width
)), HIWORD(DWORD(width
)), FALSE
);
1606 if (DWORD(state
) == SW_MAXIMIZE
)
1607 ShowWindow(app
.wMain
, SW_MAXIMIZE
);
1609 ShowWindow(app
.wMain
, nCmdShow
);
1610 UpdateWindow(app
.wMain
);
1612 //Create the tooltips
1614 INITCOMMONCONTROLSEX iccex
;
1615 app
.hwndTT
; // handle to the ToolTip control
1617 RECT rect
; // for client area coordinates
1618 iccex
.dwICC
= ICC_WIN95_CLASSES
;
1619 iccex
.dwSize
= sizeof(INITCOMMONCONTROLSEX
);
1620 InitCommonControlsEx(&iccex
);
1622 /* CREATE A TOOLTIP WINDOW */
1623 app
.hwndTT
= CreateWindowEx(WS_EX_TOPMOST
,
1626 WS_POPUP
| TTS_NOPREFIX
| TTS_ALWAYSTIP
,
1637 SetWindowPos(app
.hwndTT
,
1643 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
1645 /* GET COORDINATES OF THE MAIN CLIENT AREA */
1646 GetClientRect (app
.wBlame
, &rect
);
1648 /* INITIALIZE MEMBERS OF THE TOOLINFO STRUCTURE */
1649 ti
.cbSize
= sizeof(TOOLINFO
);
1650 ti
.uFlags
= TTF_TRACK
| TTF_ABSOLUTE
;//TTF_SUBCLASS | TTF_PARSELINKS;
1651 ti
.hwnd
= app
.wBlame
;
1652 ti
.hinst
= app
.hResource
;
1654 ti
.lpszText
= LPSTR_TEXTCALLBACK
;
1655 // ToolTip control will cover the whole window
1656 ti
.rect
.left
= rect
.left
;
1657 ti
.rect
.top
= rect
.top
;
1658 ti
.rect
.right
= rect
.right
;
1659 ti
.rect
.bottom
= rect
.bottom
;
1661 /* SEND AN ADDTOOL MESSAGE TO THE TOOLTIP CONTROL WINDOW */
1662 SendMessage(app
.hwndTT
, TTM_ADDTOOL
, 0, (LPARAM
) (LPTOOLINFO
) &ti
);
1663 SendMessage(app
.hwndTT
, TTM_SETMAXTIPWIDTH
, 0, 600);
1664 //SendMessage(app.hwndTT, TTM_SETDELAYTIME, TTDT_AUTOPOP, MAKELONG(50000, 0));
1665 //SendMessage(app.hwndTT, TTM_SETDELAYTIME, TTDT_RESHOW, MAKELONG(1000, 0));
1667 uFindReplaceMsg
= RegisterWindowMessage(FINDMSGSTRING
);
1672 void CTortoiseGitBlameView::InitSize()
1677 ::GetClientRect(wMain
, &rc
);
1678 ::SetWindowPos(wHeader
, 0, rc
.left
, rc
.top
, rc
.right
-rc
.left
, HEADER_HEIGHT
, 0);
1679 rc
.top
+= HEADER_HEIGHT
;
1680 blamerc
.left
= rc
.left
;
1681 blamerc
.top
= rc
.top
;
1682 LONG w
= GetBlameWidth();
1683 blamerc
.right
= w
> abs(rc
.right
- rc
.left
) ? rc
.right
: w
+ rc
.left
;
1684 blamerc
.bottom
= rc
.bottom
;
1685 sourcerc
.left
= blamerc
.right
;
1686 sourcerc
.top
= rc
.top
;
1687 sourcerc
.bottom
= rc
.bottom
;
1688 sourcerc
.right
= rc
.right
;
1691 ::OffsetRect(&blamerc
, LOCATOR_WIDTH
, 0);
1692 ::OffsetRect(&sourcerc
, LOCATOR_WIDTH
, 0);
1693 sourcerc
.right
-= LOCATOR_WIDTH
;
1695 ::InvalidateRect(wMain
, NULL
, FALSE
);
1696 ::SetWindowPos(m_wEditor
, 0, sourcerc
.left
, sourcerc
.top
, sourcerc
.right
- sourcerc
.left
, sourcerc
.bottom
- sourcerc
.top
, 0);
1697 ::SetWindowPos(wBlame
, 0, blamerc
.left
, blamerc
.top
, blamerc
.right
- blamerc
.left
, blamerc
.bottom
- blamerc
.top
, 0);
1699 ::SetWindowPos(wLocator
, 0, 0, blamerc
.top
, LOCATOR_WIDTH
, blamerc
.bottom
- blamerc
.top
, SWP_SHOWWINDOW
);
1701 ::ShowWindow(wLocator
, SW_HIDE
);
1705 LRESULT CALLBACK
WndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1707 if (message
== uFindReplaceMsg
)
1709 LPFINDREPLACE lpfr
= (LPFINDREPLACE
)lParam
;
1711 // If the FR_DIALOGTERM flag is set,
1712 // invalidate the handle identifying the dialog box.
1713 if (lpfr
->Flags
& FR_DIALOGTERM
)
1715 app
.currentDialog
= NULL
;
1718 if (lpfr
->Flags
& FR_FINDNEXT
)
1720 app
.DoSearch(lpfr
->lpstrFindWhat
, lpfr
->Flags
);
1727 app
.m_wEditor
= ::CreateWindow(
1730 WS_CHILD
| WS_VSCROLL
| WS_HSCROLL
| WS_CLIPCHILDREN
,
1737 app
.InitialiseEditor();
1738 ::ShowWindow(app
.m_wEditor
, SW_SHOW
);
1739 ::SetFocus(app
.m_wEditor
);
1740 app
.wBlame
= ::CreateWindow(
1741 _T("TortoiseGitBlameViewBlame"),
1743 WS_CHILD
| WS_CLIPCHILDREN
,
1750 ::ShowWindow(app
.wBlame
, SW_SHOW
);
1751 app
.wHeader
= ::CreateWindow(
1752 _T("TortoiseGitBlameViewHeader"),
1754 WS_CHILD
| WS_CLIPCHILDREN
| WS_BORDER
,
1761 ::ShowWindow(app
.wHeader
, SW_SHOW
);
1762 app
.wLocator
= ::CreateWindow(
1763 _T("TortoiseGitBlameViewLocator"),
1765 WS_CHILD
| WS_CLIPCHILDREN
| WS_BORDER
,
1772 ::ShowWindow(app
.wLocator
, SW_SHOW
);
1783 app
.Command(LOWORD(wParam
));
1786 app
.Notify(reinterpret_cast<SCNotification
*>(lParam
));
1793 CRegStdDWORD
pos(_T("Software\\TortoiseGit\\TBlamePos"), 0);
1794 CRegStdDWORD
width(_T("Software\\TortoiseGit\\TBlameSize"), 0);
1795 CRegStdDWORD
state(_T("Software\\TortoiseGit\\TBlameState"), 0);
1797 GetWindowRect(app
.wMain
, &rc
);
1798 if ((rc
.left
>= 0)&&(rc
.top
>= 0))
1800 pos
= MAKELONG(rc
.left
, rc
.top
);
1801 width
= MAKELONG(rc
.right
-rc
.left
, rc
.bottom
-rc
.top
);
1803 WINDOWPLACEMENT wp
= {0};
1804 wp
.length
= sizeof(WINDOWPLACEMENT
);
1805 GetWindowPlacement(app
.wMain
, &wp
);
1807 ::DestroyWindow(app
.m_wEditor
);
1808 ::PostQuitMessage(0);
1812 ::SetFocus(app
.wBlame
);
1815 return DefWindowProc(hWnd
, message
, wParam
, lParam
);
1820 LRESULT CALLBACK
WndBlameProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1823 TRACKMOUSEEVENT mevt
;
1830 hDC
= BeginPaint(app
.wBlame
, &ps
);
1832 EndPaint(app
.wBlame
, &ps
);
1835 app
.Command(LOWORD(wParam
));
1838 switch (((LPNMHDR
)lParam
)->code
)
1840 case TTN_GETDISPINFO
:
1842 LPNMHDR pNMHDR
= (LPNMHDR
)lParam
;
1843 NMTTDISPINFOA
* pTTTA
= (NMTTDISPINFOA
*)pNMHDR
;
1844 NMTTDISPINFOW
* pTTTW
= (NMTTDISPINFOW
*)pNMHDR
;
1846 DWORD ptW
= GetMessagePos();
1847 point
.x
= GET_X_LPARAM(ptW
);
1848 point
.y
= GET_Y_LPARAM(ptW
);
1849 ::ScreenToClient(app
.wBlame
, &point
);
1850 LONG_PTR line
= app
.SendEditor(SCI_GETFIRSTVISIBLELINE
);
1851 LONG_PTR height
= app
.SendEditor(SCI_TEXTHEIGHT
);
1852 line
= line
+ (point
.y
/height
);
1853 if (line
>= (LONG
)app
.revs
.size())
1857 LONG rev
= app
.revs
[line
];
1858 if (line
>= (LONG
)app
.revs
.size())
1861 SecureZeroMemory(app
.m_szTip
, sizeof(app
.m_szTip
));
1862 SecureZeroMemory(app
.m_wszTip
, sizeof(app
.m_wszTip
));
1863 std::map
<LONG
, CString
>::iterator iter
;
1864 if ((iter
= app
.logmessages
.find(rev
)) != app
.logmessages
.end())
1869 msg
+= app
.authors
[line
];
1873 if (!ShowAuthor
) msg
+= " ";
1874 msg
+= app
.dates
[line
];
1876 if (!ShowAuthor
|| !ShowDate
)
1878 msg
+= iter
->second
;
1879 // an empty tooltip string will deactivate the tooltips,
1880 // which means we must make sure that the tooltip won't
1884 if (pNMHDR
->code
== TTN_NEEDTEXTA
)
1886 lstrcpyn(app
.m_szTip
, msg
.c_str(), MAX_LOG_LENGTH
*2);
1887 app
.StringExpand(app
.m_szTip
);
1888 pTTTA
->lpszText
= app
.m_szTip
;
1892 pTTTW
->lpszText
= app
.m_wszTip
;
1893 ::MultiByteToWideChar( CP_ACP
, 0, msg
.c_str(), min(msg
.size(), MAX_LOG_LENGTH
*2), app
.m_wszTip
, MAX_LOG_LENGTH
*2);
1894 app
.StringExpand(app
.m_wszTip
);
1906 app
.m_mouserev
= -2;
1907 app
.m_mouseauthor
.clear();
1908 app
.ttVisible
= FALSE
;
1909 SendMessage(app
.hwndTT
, TTM_TRACKACTIVATE
, FALSE
, 0);
1910 ::InvalidateRect(app
.wBlame
, NULL
, FALSE
);
1914 mevt
.cbSize
= sizeof(TRACKMOUSEEVENT
);
1915 mevt
.dwFlags
= TME_LEAVE
;
1916 mevt
.dwHoverTime
= HOVER_DEFAULT
;
1917 mevt
.hwndTrack
= app
.wBlame
;
1918 ::TrackMouseEvent(&mevt
);
1919 POINT pt
= {((int)(short)LOWORD(lParam
)), ((int)(short)HIWORD(lParam
))};
1920 ClientToScreen(app
.wBlame
, &pt
);
1923 SendMessage(app
.hwndTT
, TTM_TRACKPOSITION
, 0, MAKELONG(pt
.x
, pt
.y
));
1927 ti
.cbSize
= sizeof(TOOLINFO
);
1928 ti
.hwnd
= app
.wBlame
;
1930 SendMessage(app
.hwndTT
, TTM_TRACKACTIVATE
, TRUE
, (LPARAM
)&ti
);
1932 int y
= ((int)(short)HIWORD(lParam
));
1933 LONG_PTR line
= app
.SendEditor(SCI_GETFIRSTVISIBLELINE
);
1934 LONG_PTR height
= app
.SendEditor(SCI_TEXTHEIGHT
);
1935 line
= line
+ (y
/height
);
1936 app
.ttVisible
= (line
< (LONG
)app
.revs
.size());
1937 if ( app
.ttVisible
)
1939 if (app
.authors
[line
].compare(app
.m_mouseauthor
) != 0)
1941 app
.m_mouseauthor
= app
.authors
[line
];
1943 if (app
.revs
[line
] != app
.m_mouserev
)
1945 app
.m_mouserev
= app
.revs
[line
];
1946 ::InvalidateRect(app
.wBlame
, NULL
, FALSE
);
1947 SendMessage(app
.hwndTT
, TTM_UPDATE
, 0, 0);
1952 case WM_RBUTTONDOWN
:
1954 case WM_LBUTTONDOWN
:
1958 ::SetFocus(app
.wBlame
);
1959 app
.SendEditor(SCI_GRABFOCUS
);
1961 case WM_CONTEXTMENU
:
1963 if (app
.m_selectedrev
<= 0)
1965 int xPos
= GET_X_LPARAM(lParam
);
1966 int yPos
= GET_Y_LPARAM(lParam
);
1967 if ((xPos
< 0)||(yPos
< 0))
1969 // requested from keyboard, not mouse pointer
1970 // use the center of the window
1972 GetClientRect(app
.wBlame
, &rect
);
1973 xPos
= rect
.right
-rect
.left
;
1974 yPos
= rect
.bottom
-rect
.top
;
1976 HMENU hMenu
= LoadMenu(app
.hResource
, MAKEINTRESOURCE(IDR_BLAMEPOPUP
));
1977 HMENU hPopMenu
= GetSubMenu(hMenu
, 0);
1979 if ( _tcslen(szOrigPath
)==0 )
1981 // Without knowing the original path we cannot blame the previous revision
1982 // because we don't know which filename to pass to tortoiseproc.
1983 EnableMenuItem(hPopMenu
,ID_BLAME_PREVIOUS_REVISION
, MF_DISABLED
|MF_GRAYED
);
1986 TrackPopupMenu(hPopMenu
, TPM_LEFTALIGN
| TPM_RIGHTBUTTON
, xPos
, yPos
, 0, app
.wBlame
, NULL
);
1991 return DefWindowProc(hWnd
, message
, wParam
, lParam
);
1996 LRESULT CALLBACK
WndHeaderProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
2005 hDC
= BeginPaint(app
.wHeader
, &ps
);
2006 app
.DrawHeader(hDC
);
2007 EndPaint(app
.wHeader
, &ps
);
2016 return DefWindowProc(hWnd
, message
, wParam
, lParam
);
2021 LRESULT CALLBACK
WndLocatorProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
2028 hDC
= BeginPaint(app
.wLocator
, &ps
);
2029 app
.DrawLocatorBar(hDC
);
2030 EndPaint(app
.wLocator
, &ps
);
2032 case WM_LBUTTONDOWN
:
2034 if (wParam
& MK_LBUTTON
)
2037 ::GetClientRect(hWnd
, &rect
);
2038 int nLine
= HIWORD(lParam
)*app
.revs
.size()/(rect
.bottom
-rect
.top
);
2042 app
.ScrollToLine(nLine
);
2046 return DefWindowProc(hWnd
, message
, wParam
, lParam
);
2052 void CTortoiseGitBlameView::SetupLexer(CString filename
)
2056 //const char * lineptr = _tcsrchr(filename, '.');
2057 int start
=filename
.ReverseFind(_T('.'));
2060 //_tcscpy_s(line, 20, lineptr+1);
2061 //_tcslwr_s(line, 20);
2062 CString ext
=filename
.Right(filename
.GetLength()-start
-1);
2063 line
=ext
.GetBuffer();
2065 if ((_tcscmp(line
, _T("py"))==0)||
2066 (_tcscmp(line
, _T("pyw"))==0)||
2067 (_tcscmp(line
, _T("pyw"))==0))
2069 SendEditor(SCI_SETLEXER
, SCLEX_PYTHON
);
2070 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("and assert break class continue def del elif \
2071 else except exec finally for from global if import in is lambda None \
2072 not or pass print raise return try while yield")).GetBuffer()));
2073 SetAStyle(SCE_P_DEFAULT
, black
);
2074 SetAStyle(SCE_P_COMMENTLINE
, darkGreen
);
2075 SetAStyle(SCE_P_NUMBER
, RGB(0, 0x80, 0x80));
2076 SetAStyle(SCE_P_STRING
, RGB(0, 0, 0x80));
2077 SetAStyle(SCE_P_CHARACTER
, RGB(0, 0, 0x80));
2078 SetAStyle(SCE_P_WORD
, RGB(0x80, 0, 0x80));
2079 SetAStyle(SCE_P_TRIPLE
, black
);
2080 SetAStyle(SCE_P_TRIPLEDOUBLE
, black
);
2081 SetAStyle(SCE_P_CLASSNAME
, darkBlue
);
2082 SetAStyle(SCE_P_DEFNAME
, darkBlue
);
2083 SetAStyle(SCE_P_OPERATOR
, darkBlue
);
2084 SetAStyle(SCE_P_IDENTIFIER
, darkBlue
);
2085 SetAStyle(SCE_P_COMMENTBLOCK
, darkGreen
);
2086 SetAStyle(SCE_P_STRINGEOL
, red
);
2088 if ((_tcscmp(line
, _T("c"))==0)||
2089 (_tcscmp(line
, _T("cc"))==0)||
2090 (_tcscmp(line
, _T("cpp"))==0)||
2091 (_tcscmp(line
, _T("cxx"))==0)||
2092 (_tcscmp(line
, _T("h"))==0)||
2093 (_tcscmp(line
, _T("hh"))==0)||
2094 (_tcscmp(line
, _T("hpp"))==0)||
2095 (_tcscmp(line
, _T("hxx"))==0)||
2096 (_tcscmp(line
, _T("dlg"))==0)||
2097 (_tcscmp(line
, _T("mak"))==0))
2099 SendEditor(SCI_SETLEXER
, SCLEX_CPP
);
2100 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("and and_eq asm auto bitand bitor bool break \
2101 case catch char class compl const const_cast continue \
2102 default delete do double dynamic_cast else enum explicit export extern false float for \
2103 friend goto if inline int long mutable namespace new not not_eq \
2104 operator or or_eq private protected public \
2105 register reinterpret_cast return short signed sizeof static static_cast struct switch \
2106 template this throw true try typedef typeid typename union unsigned using \
2107 virtual void volatile wchar_t while xor xor_eq")).GetBuffer()));
2108 SendEditor(SCI_SETKEYWORDS
, 3, (LPARAM
)(m_TextView
.StringForControl(_T("a addindex addtogroup anchor arg attention \
2109 author b brief bug c class code date def defgroup deprecated dontinclude \
2110 e em endcode endhtmlonly endif endlatexonly endlink endverbatim enum example exception \
2111 f$ f[ f] file fn hideinitializer htmlinclude htmlonly \
2112 if image include ingroup internal invariant interface latexonly li line link \
2113 mainpage name namespace nosubgrouping note overload \
2114 p page par param post pre ref relates remarks return retval \
2115 sa section see showinitializer since skip skipline struct subsection \
2116 test throw todo typedef union until \
2117 var verbatim verbinclude version warning weakgroup $ @ \\ & < > # { }")).GetBuffer()));
2120 if (_tcscmp(line
, _T("cs"))==0)
2122 SendEditor(SCI_SETLEXER
, SCLEX_CPP
);
2123 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("abstract as base bool break byte case catch char checked class \
2124 const continue decimal default delegate do double else enum \
2125 event explicit extern false finally fixed float for foreach goto if \
2126 implicit in int interface internal is lock long namespace new null \
2127 object operator out override params private protected public \
2128 readonly ref return sbyte sealed short sizeof stackalloc static \
2129 string struct switch this throw true try typeof uint ulong \
2130 unchecked unsafe ushort using virtual void while")).GetBuffer()));
2133 if ((_tcscmp(line
, _T("rc"))==0)||
2134 (_tcscmp(line
, _T("rc2"))==0))
2136 SendEditor(SCI_SETLEXER
, SCLEX_CPP
);
2137 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("ACCELERATORS ALT AUTO3STATE AUTOCHECKBOX AUTORADIOBUTTON \
2138 BEGIN BITMAP BLOCK BUTTON CAPTION CHARACTERISTICS CHECKBOX CLASS \
2139 COMBOBOX CONTROL CTEXT CURSOR DEFPUSHBUTTON DIALOG DIALOGEX DISCARDABLE \
2140 EDITTEXT END EXSTYLE FONT GROUPBOX ICON LANGUAGE LISTBOX LTEXT \
2141 MENU MENUEX MENUITEM MESSAGETABLE POPUP \
2142 PUSHBUTTON RADIOBUTTON RCDATA RTEXT SCROLLBAR SEPARATOR SHIFT STATE3 \
2143 STRINGTABLE STYLE TEXTINCLUDE VALUE VERSION VERSIONINFO VIRTKEY")).GetBuffer()));
2146 if ((_tcscmp(line
, _T("idl"))==0)||
2147 (_tcscmp(line
, _T("odl"))==0))
2149 SendEditor(SCI_SETLEXER
, SCLEX_CPP
);
2150 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("aggregatable allocate appobject arrays async async_uuid \
2152 bindable boolean broadcast byte byte_count \
2153 call_as callback char coclass code comm_status \
2154 const context_handle context_handle_noserialize \
2155 context_handle_serialize control cpp_quote custom \
2156 decode default defaultbind defaultcollelem \
2157 defaultvalue defaultvtable dispinterface displaybind dllname \
2159 enable_allocate encode endpoint entry enum error_status_t \
2161 fault_status first_is float \
2162 handle_t heap helpcontext helpfile helpstring \
2163 helpstringcontext helpstringdll hidden hyper \
2164 id idempotent ignore iid_as iid_is immediatebind implicit_handle \
2165 import importlib in include in_line int __int64 __int3264 interface \
2166 last_is lcid length_is library licensed local long \
2167 max_is maybe message methods midl_pragma \
2168 midl_user_allocate midl_user_free min_is module ms_union \
2169 ncacn_at_dsp ncacn_dnet_nsp ncacn_http ncacn_ip_tcp \
2170 ncacn_nb_ipx ncacn_nb_nb ncacn_nb_tcp ncacn_np \
2171 ncacn_spx ncacn_vns_spp ncadg_ip_udp ncadg_ipx ncadg_mq \
2172 ncalrpc nocode nonbrowsable noncreatable nonextensible notify \
2173 object odl oleautomation optimize optional out out_of_line \
2174 pipe pointer_default pragma properties propget propput propputref \
2176 range readonly ref represent_as requestedit restricted retval \
2177 shape short signed size_is small source strict_context_handle \
2178 string struct switch switch_is switch_type \
2179 transmit_as typedef \
2180 uidefault union unique unsigned user_marshal usesgetlasterror uuid \
2181 v1_enum vararg version void wchar_t wire_marshal")).GetBuffer()));
2184 if (_tcscmp(line
, _T("java"))==0)
2186 SendEditor(SCI_SETLEXER
, SCLEX_CPP
);
2187 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("abstract assert boolean break byte case catch char class \
2188 const continue default do double else extends final finally float for future \
2189 generic goto if implements import inner instanceof int interface long \
2190 native new null outer package private protected public rest \
2191 return short static super switch synchronized this throw throws \
2192 transient try var void volatile while")).GetBuffer()));
2195 if (_tcscmp(line
, _T("js"))==0)
2197 SendEditor(SCI_SETLEXER
, SCLEX_CPP
);
2198 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("abstract boolean break byte case catch char class \
2199 const continue debugger default delete do double else enum export extends \
2200 final finally float for function goto if implements import in instanceof \
2201 int interface long native new package private protected public \
2202 return short static super switch synchronized this throw throws \
2203 transient try typeof var void volatile while with")).GetBuffer()));
2206 if ((_tcscmp(line
, _T("pas"))==0)||
2207 (_tcscmp(line
, _T("dpr"))==0)||
2208 (_tcscmp(line
, _T("pp"))==0))
2210 SendEditor(SCI_SETLEXER
, SCLEX_PASCAL
);
2211 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("and array as begin case class const constructor \
2212 destructor div do downto else end except file finally \
2213 for function goto if implementation in inherited \
2214 interface is mod not object of on or packed \
2215 procedure program property raise record repeat \
2216 set shl shr then threadvar to try type unit \
2217 until uses var while with xor")).GetBuffer()));
2220 if ((_tcscmp(line
, _T("as"))==0)||
2221 (_tcscmp(line
, _T("asc"))==0)||
2222 (_tcscmp(line
, _T("jsfl"))==0))
2224 SendEditor(SCI_SETLEXER
, SCLEX_CPP
);
2225 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("add and break case catch class continue default delete do \
2226 dynamic else eq extends false finally for function ge get gt if implements import in \
2227 instanceof interface intrinsic le lt ne new not null or private public return \
2228 set static super switch this throw true try typeof undefined var void while with")).GetBuffer()));
2229 SendEditor(SCI_SETKEYWORDS
, 1, (LPARAM
)(m_TextView
.StringForControl(_T("Array Arguments Accessibility Boolean Button Camera Color \
2230 ContextMenu ContextMenuItem Date Error Function Key LoadVars LocalConnection Math \
2231 Microphone Mouse MovieClip MovieClipLoader NetConnection NetStream Number Object \
2232 PrintJob Selection SharedObject Sound Stage String StyleSheet System TextField \
2233 TextFormat TextSnapshot Video Void XML XMLNode XMLSocket \
2234 _accProps _focusrect _global _highquality _parent _quality _root _soundbuftime \
2235 arguments asfunction call capabilities chr clearInterval duplicateMovieClip \
2236 escape eval fscommand getProperty getTimer getURL getVersion gotoAndPlay gotoAndStop \
2237 ifFrameLoaded Infinity -Infinity int isFinite isNaN length loadMovie loadMovieNum \
2238 loadVariables loadVariablesNum maxscroll mbchr mblength mbord mbsubstring MMExecute \
2239 NaN newline nextFrame nextScene on onClipEvent onUpdate ord parseFloat parseInt play \
2240 prevFrame prevScene print printAsBitmap printAsBitmapNum printNum random removeMovieClip \
2241 scroll set setInterval setProperty startDrag stop stopAllSounds stopDrag substring \
2242 targetPath tellTarget toggleHighQuality trace unescape unloadMovie unLoadMovieNum updateAfterEvent")).GetBuffer()));
2245 if ((_tcscmp(line
, _T("html"))==0)||
2246 (_tcscmp(line
, _T("htm"))==0)||
2247 (_tcscmp(line
, _T("shtml"))==0)||
2248 (_tcscmp(line
, _T("htt"))==0)||
2249 (_tcscmp(line
, _T("xml"))==0)||
2250 (_tcscmp(line
, _T("asp"))==0)||
2251 (_tcscmp(line
, _T("xsl"))==0)||
2252 (_tcscmp(line
, _T("php"))==0)||
2253 (_tcscmp(line
, _T("xhtml"))==0)||
2254 (_tcscmp(line
, _T("phtml"))==0)||
2255 (_tcscmp(line
, _T("cfm"))==0)||
2256 (_tcscmp(line
, _T("tpl"))==0)||
2257 (_tcscmp(line
, _T("dtd"))==0)||
2258 (_tcscmp(line
, _T("hta"))==0)||
2259 (_tcscmp(line
, _T("htd"))==0)||
2260 (_tcscmp(line
, _T("wxs"))==0))
2262 SendEditor(SCI_SETLEXER
, SCLEX_HTML
);
2263 SendEditor(SCI_SETSTYLEBITS
, 7);
2264 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("a abbr acronym address applet area b base basefont \
2265 bdo big blockquote body br button caption center \
2266 cite code col colgroup dd del dfn dir div dl dt em \
2267 fieldset font form frame frameset h1 h2 h3 h4 h5 h6 \
2268 head hr html i iframe img input ins isindex kbd label \
2269 legend li link map menu meta noframes noscript \
2270 object ol optgroup option p param pre q s samp \
2271 script select small span strike strong style sub sup \
2272 table tbody td textarea tfoot th thead title tr tt u ul \
2273 var xml xmlns abbr accept-charset accept accesskey action align alink \
2274 alt archive axis background bgcolor border \
2275 cellpadding cellspacing char charoff charset checked cite \
2276 class classid clear codebase codetype color cols colspan \
2277 compact content coords \
2278 data datafld dataformatas datapagesize datasrc datetime \
2279 declare defer dir disabled enctype event \
2280 face for frame frameborder \
2281 headers height href hreflang hspace http-equiv \
2282 id ismap label lang language leftmargin link longdesc \
2283 marginwidth marginheight maxlength media method multiple \
2284 name nohref noresize noshade nowrap \
2285 object onblur onchange onclick ondblclick onfocus \
2286 onkeydown onkeypress onkeyup onload onmousedown \
2287 onmousemove onmouseover onmouseout onmouseup \
2288 onreset onselect onsubmit onunload \
2289 profile prompt readonly rel rev rows rowspan rules \
2290 scheme scope selected shape size span src standby start style \
2291 summary tabindex target text title topmargin type usemap \
2292 valign value valuetype version vlink vspace width \
2293 text password checkbox radio submit reset \
2294 file hidden image")).GetBuffer()));
2295 SendEditor(SCI_SETKEYWORDS
, 1, (LPARAM
)(m_TextView
.StringForControl(_T("assign audio block break catch choice clear disconnect else elseif \
2296 emphasis enumerate error exit field filled form goto grammar help \
2297 if initial link log menu meta noinput nomatch object option p paragraph \
2298 param phoneme prompt property prosody record reprompt return s say-as \
2299 script sentence subdialog submit throw transfer value var voice vxml")).GetBuffer()));
2300 SendEditor(SCI_SETKEYWORDS
, 2, (LPARAM
)(m_TextView
.StringForControl(_T("accept age alphabet anchor application base beep bridge category charset \
2301 classid cond connecttimeout content contour count dest destexpr dtmf dtmfterm \
2302 duration enctype event eventexpr expr expritem fetchtimeout finalsilence \
2303 gender http-equiv id level maxage maxstale maxtime message messageexpr \
2304 method mime modal mode name namelist next nextitem ph pitch range rate \
2305 scope size sizeexpr skiplist slot src srcexpr sub time timeexpr timeout \
2306 transferaudio type value variant version volume xml:lang")).GetBuffer()));
2307 SendEditor(SCI_SETKEYWORDS
, 3, (LPARAM
)(m_TextView
.StringForControl(_T("and assert break class continue def del elif \
2308 else except exec finally for from global if import in is lambda None \
2309 not or pass print raise return try while yield")).GetBuffer()));
2310 SendEditor(SCI_SETKEYWORDS
, 4, (LPARAM
)(m_TextView
.StringForControl(_T("and argv as argc break case cfunction class continue declare default do \
2311 die echo else elseif empty enddeclare endfor endforeach endif endswitch \
2312 endwhile e_all e_parse e_error e_warning eval exit extends false for \
2313 foreach function global http_cookie_vars http_get_vars http_post_vars \
2314 http_post_files http_env_vars http_server_vars if include include_once \
2315 list new not null old_function or parent php_os php_self php_version \
2316 print require require_once return static switch stdclass this true var \
2317 xor virtual while __file__ __line__ __sleep __wakeup")).GetBuffer()));
2319 SetAStyle(SCE_H_TAG
, darkBlue
);
2320 SetAStyle(SCE_H_TAGUNKNOWN
, red
);
2321 SetAStyle(SCE_H_ATTRIBUTE
, darkBlue
);
2322 SetAStyle(SCE_H_ATTRIBUTEUNKNOWN
, red
);
2323 SetAStyle(SCE_H_NUMBER
, RGB(0x80,0,0x80));
2324 SetAStyle(SCE_H_DOUBLESTRING
, RGB(0,0x80,0));
2325 SetAStyle(SCE_H_SINGLESTRING
, RGB(0,0x80,0));
2326 SetAStyle(SCE_H_OTHER
, RGB(0x80,0,0x80));
2327 SetAStyle(SCE_H_COMMENT
, RGB(0x80,0x80,0));
2328 SetAStyle(SCE_H_ENTITY
, RGB(0x80,0,0x80));
2330 SetAStyle(SCE_H_TAGEND
, darkBlue
);
2331 SetAStyle(SCE_H_XMLSTART
, darkBlue
); // <?
2332 SetAStyle(SCE_H_QUESTION
, darkBlue
); // <?
2333 SetAStyle(SCE_H_XMLEND
, darkBlue
); // ?>
2334 SetAStyle(SCE_H_SCRIPT
, darkBlue
); // <script
2335 SetAStyle(SCE_H_ASP
, RGB(0x4F, 0x4F, 0), RGB(0xFF, 0xFF, 0)); // <% ... %>
2336 SetAStyle(SCE_H_ASPAT
, RGB(0x4F, 0x4F, 0), RGB(0xFF, 0xFF, 0)); // <%@ ... %>
2338 SetAStyle(SCE_HB_DEFAULT
, black
);
2339 SetAStyle(SCE_HB_COMMENTLINE
, darkGreen
);
2340 SetAStyle(SCE_HB_NUMBER
, RGB(0,0x80,0x80));
2341 SetAStyle(SCE_HB_WORD
, darkBlue
);
2342 SendEditor(SCI_STYLESETBOLD
, SCE_HB_WORD
, 1);
2343 SetAStyle(SCE_HB_STRING
, RGB(0x80,0,0x80));
2344 SetAStyle(SCE_HB_IDENTIFIER
, black
);
2346 // This light blue is found in the windows system palette so is safe to use even in 256 colour modes.
2347 // Show the whole section of VBScript with light blue background
2348 for (int bstyle
=SCE_HB_DEFAULT
; bstyle
<=SCE_HB_STRINGEOL
; bstyle
++) {
2349 SendEditor(SCI_STYLESETFONT
, bstyle
,
2350 reinterpret_cast<LPARAM
>(m_TextView
.StringForControl(_T("Lucida Console")).GetBuffer()));
2351 SendEditor(SCI_STYLESETBACK
, bstyle
, lightBlue
);
2352 // This call extends the backround colour of the last style on the line to the edge of the window
2353 SendEditor(SCI_STYLESETEOLFILLED
, bstyle
, 1);
2355 SendEditor(SCI_STYLESETBACK
, SCE_HB_STRINGEOL
, RGB(0x7F,0x7F,0xFF));
2356 SendEditor(SCI_STYLESETFONT
, SCE_HB_COMMENTLINE
,
2357 reinterpret_cast<LPARAM
>(m_TextView
.StringForControl(_T("Lucida Console")).GetBuffer()));
2359 SetAStyle(SCE_HBA_DEFAULT
, black
);
2360 SetAStyle(SCE_HBA_COMMENTLINE
, darkGreen
);
2361 SetAStyle(SCE_HBA_NUMBER
, RGB(0,0x80,0x80));
2362 SetAStyle(SCE_HBA_WORD
, darkBlue
);
2363 SendEditor(SCI_STYLESETBOLD
, SCE_HBA_WORD
, 1);
2364 SetAStyle(SCE_HBA_STRING
, RGB(0x80,0,0x80));
2365 SetAStyle(SCE_HBA_IDENTIFIER
, black
);
2367 // Show the whole section of ASP VBScript with bright yellow background
2368 for (int bastyle
=SCE_HBA_DEFAULT
; bastyle
<=SCE_HBA_STRINGEOL
; bastyle
++) {
2369 SendEditor(SCI_STYLESETFONT
, bastyle
,
2370 reinterpret_cast<LPARAM
>(m_TextView
.StringForControl(_T("Lucida Console")).GetBuffer()));
2371 SendEditor(SCI_STYLESETBACK
, bastyle
, RGB(0xFF, 0xFF, 0));
2372 // This call extends the backround colour of the last style on the line to the edge of the window
2373 SendEditor(SCI_STYLESETEOLFILLED
, bastyle
, 1);
2375 SendEditor(SCI_STYLESETBACK
, SCE_HBA_STRINGEOL
, RGB(0xCF,0xCF,0x7F));
2376 SendEditor(SCI_STYLESETFONT
, SCE_HBA_COMMENTLINE
,
2377 reinterpret_cast<LPARAM
>(m_TextView
.StringForControl(_T("Lucida Console")).GetBuffer()));
2379 // If there is no need to support embedded Javascript, the following code can be dropped.
2380 // Javascript will still be correctly processed but will be displayed in just the default style.
2382 SetAStyle(SCE_HJ_START
, RGB(0x80,0x80,0));
2383 SetAStyle(SCE_HJ_DEFAULT
, black
);
2384 SetAStyle(SCE_HJ_COMMENT
, darkGreen
);
2385 SetAStyle(SCE_HJ_COMMENTLINE
, darkGreen
);
2386 SetAStyle(SCE_HJ_COMMENTDOC
, darkGreen
);
2387 SetAStyle(SCE_HJ_NUMBER
, RGB(0,0x80,0x80));
2388 SetAStyle(SCE_HJ_WORD
, black
);
2389 SetAStyle(SCE_HJ_KEYWORD
, darkBlue
);
2390 SetAStyle(SCE_HJ_DOUBLESTRING
, RGB(0x80,0,0x80));
2391 SetAStyle(SCE_HJ_SINGLESTRING
, RGB(0x80,0,0x80));
2392 SetAStyle(SCE_HJ_SYMBOLS
, black
);
2394 SetAStyle(SCE_HJA_START
, RGB(0x80,0x80,0));
2395 SetAStyle(SCE_HJA_DEFAULT
, black
);
2396 SetAStyle(SCE_HJA_COMMENT
, darkGreen
);
2397 SetAStyle(SCE_HJA_COMMENTLINE
, darkGreen
);
2398 SetAStyle(SCE_HJA_COMMENTDOC
, darkGreen
);
2399 SetAStyle(SCE_HJA_NUMBER
, RGB(0,0x80,0x80));
2400 SetAStyle(SCE_HJA_WORD
, black
);
2401 SetAStyle(SCE_HJA_KEYWORD
, darkBlue
);
2402 SetAStyle(SCE_HJA_DOUBLESTRING
, RGB(0x80,0,0x80));
2403 SetAStyle(SCE_HJA_SINGLESTRING
, RGB(0x80,0,0x80));
2404 SetAStyle(SCE_HJA_SYMBOLS
, black
);
2406 SetAStyle(SCE_HPHP_DEFAULT
, black
);
2407 SetAStyle(SCE_HPHP_HSTRING
, RGB(0x80,0,0x80));
2408 SetAStyle(SCE_HPHP_SIMPLESTRING
, RGB(0x80,0,0x80));
2409 SetAStyle(SCE_HPHP_WORD
, darkBlue
);
2410 SetAStyle(SCE_HPHP_NUMBER
, RGB(0,0x80,0x80));
2411 SetAStyle(SCE_HPHP_VARIABLE
, red
);
2412 SetAStyle(SCE_HPHP_HSTRING_VARIABLE
, red
);
2413 SetAStyle(SCE_HPHP_COMPLEX_VARIABLE
, red
);
2414 SetAStyle(SCE_HPHP_COMMENT
, darkGreen
);
2415 SetAStyle(SCE_HPHP_COMMENTLINE
, darkGreen
);
2416 SetAStyle(SCE_HPHP_OPERATOR
, darkBlue
);
2418 // Show the whole section of Javascript with off white background
2419 for (int jstyle
=SCE_HJ_DEFAULT
; jstyle
<=SCE_HJ_SYMBOLS
; jstyle
++) {
2420 SendEditor(SCI_STYLESETFONT
, jstyle
,
2421 reinterpret_cast<LPARAM
>(m_TextView
.StringForControl(_T("Lucida Console")).GetBuffer()));
2422 SendEditor(SCI_STYLESETBACK
, jstyle
, offWhite
);
2423 SendEditor(SCI_STYLESETEOLFILLED
, jstyle
, 1);
2425 SendEditor(SCI_STYLESETBACK
, SCE_HJ_STRINGEOL
, RGB(0xDF, 0xDF, 0x7F));
2426 SendEditor(SCI_STYLESETEOLFILLED
, SCE_HJ_STRINGEOL
, 1);
2428 // Show the whole section of Javascript with brown background
2429 for (int jastyle
=SCE_HJA_DEFAULT
; jastyle
<=SCE_HJA_SYMBOLS
; jastyle
++) {
2430 SendEditor(SCI_STYLESETFONT
, jastyle
,
2431 reinterpret_cast<LPARAM
>(m_TextView
.StringForControl(_T("Lucida Console")).GetBuffer()));
2432 SendEditor(SCI_STYLESETBACK
, jastyle
, RGB(0xDF, 0xDF, 0x7F));
2433 SendEditor(SCI_STYLESETEOLFILLED
, jastyle
, 1);
2435 SendEditor(SCI_STYLESETBACK
, SCE_HJA_STRINGEOL
, RGB(0x0,0xAF,0x5F));
2436 SendEditor(SCI_STYLESETEOLFILLED
, SCE_HJA_STRINGEOL
, 1);
2441 SendEditor(SCI_SETLEXER
, SCLEX_CPP
);
2444 SendEditor(SCI_COLOURISE
, 0, -1);
2448 void CTortoiseGitBlameView::SetupCppLexer()
2450 SetAStyle(SCE_C_DEFAULT
, RGB(0, 0, 0));
2451 SetAStyle(SCE_C_COMMENT
, RGB(0, 0x80, 0));
2452 SetAStyle(SCE_C_COMMENTLINE
, RGB(0, 0x80, 0));
2453 SetAStyle(SCE_C_COMMENTDOC
, RGB(0, 0x80, 0));
2454 SetAStyle(SCE_C_COMMENTLINEDOC
, RGB(0, 0x80, 0));
2455 SetAStyle(SCE_C_COMMENTDOCKEYWORD
, RGB(0, 0x80, 0));
2456 SetAStyle(SCE_C_COMMENTDOCKEYWORDERROR
, RGB(0, 0x80, 0));
2457 SetAStyle(SCE_C_NUMBER
, RGB(0, 0x80, 0x80));
2458 SetAStyle(SCE_C_WORD
, RGB(0, 0, 0x80));
2459 SendEditor(SCE_C_WORD
, 1);
2460 SetAStyle(SCE_C_STRING
, RGB(0x80, 0, 0x80));
2461 SetAStyle(SCE_C_IDENTIFIER
, RGB(0, 0, 0));
2462 SetAStyle(SCE_C_PREPROCESSOR
, RGB(0x80, 0, 0));
2463 SetAStyle(SCE_C_OPERATOR
, RGB(0x80, 0x80, 0));
2466 int CTortoiseGitBlameView::GetEncode(unsigned char *buff
, int size
, int *bomoffset
)
2468 CFileTextLines textlines
;
2469 CFileTextLines::UnicodeType type
= textlines
.CheckUnicodeType(buff
, size
);
2471 if(type
== CFileTextLines::UTF8BOM
)
2476 if(type
== CFileTextLines::UTF8
)
2479 if(type
== CFileTextLines::UNICODE_LE
)
2488 void CTortoiseGitBlameView::UpdateInfo(int Encode
)
2490 BYTE_VECTOR
&data
= GetDocument()->m_BlameData
;
2496 CLogDataVector
* pRevs
= GetLogData();
2498 this->m_CommitHash
.clear();
2499 this->m_Authors
.clear();
2505 SendEditor(SCI_SETREADONLY
, FALSE
);
2506 SendEditor(SCI_CLEARALL
);
2507 SendEditor(EM_EMPTYUNDOBUFFER
);
2508 SendEditor(SCI_SETSAVEPOINT
);
2509 SendEditor(SCI_CANCEL
);
2510 SendEditor(SCI_SETUNDOCOLLECTION
, 0);
2512 SendEditor(SCI_SETCODEPAGE
, SC_CP_UTF8
);
2515 int encoding
= Encode
;
2516 while( pos
>=0 && current
>=0 && pos
<data
.size() )
2518 current
= data
.findData((const BYTE
*)"\n",1,pos
);
2519 //one=data.Tokenize(_T("\n"),pos);
2521 bool isbound
= ( data
[pos
] == _T('^') );
2523 if( (data
.size() - pos
) >1 && data
[pos
] == _T('^'))
2534 if(git_get_sha1((const char*)&data
[pos
], hash
.m_hash
))
2536 ::MessageBox(NULL
, _T("Can't get hash"), _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
2541 hash
.ConvertFromStrA((char*)&data
[pos
]);
2545 start
=data
.findData((const BYTE
*)")",1,pos
+ 40);
2558 if( pos
<40 && encoding
==0)
2561 encoding
= GetEncode( &data
[start
+2], data
.size() - start
-2, &bomoffset
);
2564 if(encoding
== 1200)
2567 // the first bomoffset is 2, after that it's 1 (see issue #920)
2570 int size
= ((current
- start
-2 - bomoffset
)/2);
2571 TCHAR
*buffer
= strw
.GetBuffer(size
);
2572 memcpy(buffer
, &data
[start
+ 2 + bomoffset
],sizeof(TCHAR
)*size
);
2573 strw
.ReleaseBuffer();
2575 stra
= CUnicodeUtils::GetUTF8(strw
);
2577 else if(encoding
== CP_UTF8
)
2579 stra
= &data
[start
+ 2 + bomoffset
];
2584 strw
= CUnicodeUtils::GetUnicode(CStringA(&data
[start
+ 2 + bomoffset
]), encoding
);
2585 stra
= CUnicodeUtils::GetUTF8(strw
);
2589 SendEditor(SCI_REPLACESEL
, 0, (LPARAM
)(LPCSTR
)stra
);
2590 SendEditor(SCI_REPLACESEL
, 0, (LPARAM
)(LPCSTR
)"\n\0\0\0");
2593 data
[current
] = '\n';
2597 if(this->m_NoListCommit
.find(hash
) == m_NoListCommit
.end() )
2599 this->m_NoListCommit
[hash
].GetCommitFromHash(hash
);
2601 m_ID
.push_back(-1); // m_ID is calculated lazy on demand
2602 m_Authors
.push_back(m_NoListCommit
[hash
].GetAuthorName());
2604 m_CommitHash
.push_back(hash
);
2616 file
.Open(this->GetDocument()->m_TempFileName
,CFile::modeRead
);
2618 m_Buffer
= new char[file
.GetLength()+4];
2619 m_Buffer
[file
.GetLength()] =0;
2620 m_Buffer
[file
.GetLength()+1] =0;
2621 m_Buffer
[file
.GetLength()+2] =0;
2622 m_Buffer
[file
.GetLength()+3] =0;
2624 file
.Read(m_Buffer
, file
.GetLength());
2627 int encoding
= GetEncode( (unsigned char *)m_Buffer
, file
.GetLength(), &bomoffset
);
2630 //SendEditor(SCI_SETCODEPAGE, encoding);
2632 //SendEditor(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)(m_Buffer + bomoffset));
2634 SetupLexer(GetDocument()->m_CurrentFileName
);
2636 SendEditor(SCI_SETUNDOCOLLECTION
, 1);
2637 SendEditor(EM_EMPTYUNDOBUFFER
);
2638 SendEditor(SCI_SETSAVEPOINT
);
2639 SendEditor(SCI_GOTOPOS
, 0);
2640 SendEditor(SCI_SETSCROLLWIDTHTRACKING
, TRUE
);
2641 SendEditor(SCI_SETREADONLY
, TRUE
);
2644 m_highestrev
=this->GetLogData()->size()+m_NoListCommit
.size();
2648 this->GetClientRect(rect
);
2649 //this->m_TextView.GetWindowRect(rect);
2650 //this->m_TextView.ScreenToClient(rect);
2651 rect
.left
=this->m_blamewidth
;
2652 this->m_TextView
.MoveWindow(rect
);
2657 CGitBlameLogList
* CTortoiseGitBlameView::GetLogList()
2659 return &(GetDocument()->GetMainFrame()->m_wndOutput
.m_LogList
);
2663 CLogDataVector
* CTortoiseGitBlameView::GetLogData()
2665 return &(GetDocument()->GetMainFrame()->m_wndOutput
.m_LogList
.m_logEntries
);
2668 void CTortoiseGitBlameView::OnSciPainted(NMHDR
*,LRESULT
*)
2673 void CTortoiseGitBlameView::OnLButtonDown(UINT nFlags
,CPoint point
)
2676 LONG_PTR line
= SendEditor(SCI_GETFIRSTVISIBLELINE
);
2677 LONG_PTR height
= SendEditor(SCI_TEXTHEIGHT
);
2678 line
= line
+ (point
.y
/height
);
2680 if (line
< (LONG
)m_CommitHash
.size())
2682 SetSelectedLine(line
);
2683 if (m_CommitHash
[line
] != m_SelectedHash
)
2685 m_SelectedHash
= m_CommitHash
[line
];
2687 // lazy calculate m_ID
2688 if (m_ID
[line
] == -1)
2690 m_ID
[line
] = -2; // don't do this lazy calculation again and again for unfindable hashes
2691 for(int i
= 0; i
<this->GetLogData()->size(); i
++)
2693 if(m_SelectedHash
== this->GetLogData()->at(i
))
2695 m_ID
[line
] = this->GetLogData()->size()-i
;
2703 this->GetLogList()->SetItemState(this->GetLogList()->GetItemCount()-m_ID
[line
],
2706 this->GetLogList()->EnsureVisible(this->GetLogList()->GetItemCount()-m_ID
[line
], FALSE
);
2710 this->GetDocument()->GetMainFrame()->m_wndProperties
.UpdateProperties(&m_NoListCommit
[m_CommitHash
[line
]]);
2715 m_SelectedHash
.Empty();
2717 //::InvalidateRect( NULL, FALSE);
2719 this->m_TextView
.Invalidate();
2724 SetSelectedLine(-1);
2727 CView::OnLButtonDown(nFlags
,point
);
2730 void CTortoiseGitBlameView::OnSciGetBkColor(NMHDR
* hdr
, LRESULT
* result
)
2733 SCNotification
*notification
=reinterpret_cast<SCNotification
*>(hdr
);
2735 if ((m_colorage
)&&(notification
->line
< (int)m_CommitHash
.size()))
2737 if(m_CommitHash
[notification
->line
] == this->m_SelectedHash
)
2738 notification
->lParam
= m_selectedauthorcolor
;
2740 notification
->lParam
= InterColor(DWORD(m_regOldLinesColor
), DWORD(m_regNewLinesColor
), (m_ID
[notification
->line
]-m_lowestrev
)*100/((m_highestrev
-m_lowestrev
)+1));
2745 void CTortoiseGitBlameView::FocusOn(GitRev
*pRev
)
2747 this->GetDocument()->GetMainFrame()->m_wndProperties
.UpdateProperties(pRev
);
2751 if (m_SelectedHash
!= pRev
->m_CommitHash
) {
2752 m_SelectedHash
= pRev
->m_CommitHash
;
2754 for(i
=0;i
<m_CommitHash
.size();i
++)
2756 if( pRev
->m_CommitHash
== m_CommitHash
[i
] )
2760 this->m_TextView
.Invalidate();
2764 void CTortoiseGitBlameView::OnMouseHover(UINT nFlags
, CPoint point
)
2766 LONG_PTR line
= SendEditor(SCI_GETFIRSTVISIBLELINE
);
2767 LONG_PTR height
= SendEditor(SCI_TEXTHEIGHT
);
2768 line
= line
+ (point
.y
/height
);
2770 if (line
< (LONG
)m_CommitHash
.size())
2772 if (line
!= m_MouseLine
)
2774 m_MouseLine
= line
;//m_CommitHash[line];
2778 pRev
=&this->m_NoListCommit
[m_CommitHash
[line
]];
2783 pRev
=&this->GetLogData()->GetGitRevAt(this->GetLogList()->GetItemCount()-m_ID
[line
]);
2787 str
.Format(_T("%s: %s\n%s: %s\n%s: %s\n%s:\n%s\n%s"), m_sRev
, pRev
->m_CommitHash
.ToString(),
2788 m_sAuthor
, pRev
->GetAuthorName(),
2789 m_sDate
, CAppUtils::FormatDateAndTime(pRev
->GetAuthorDate(), m_DateFormat
, true, m_bRelativeTimes
),
2790 m_sMessage
, pRev
->GetSubject(),
2794 m_ToolTip
.AddTool(this, str
);
2797 rect
.left
=LOCATOR_WIDTH
;
2798 rect
.right
=this->m_blamewidth
+rect
.left
;
2799 rect
.top
=point
.y
-height
;
2800 rect
.bottom
=point
.y
+height
;
2801 this->InvalidateRect(rect
);
2806 void CTortoiseGitBlameView::OnMouseMove(UINT nFlags
, CPoint point
)
2808 TRACKMOUSEEVENT tme
;
2809 tme
.cbSize
=sizeof(TRACKMOUSEEVENT
);
2810 tme
.dwFlags
=TME_HOVER
|TME_LEAVE
;
2811 tme
.hwndTrack
=this->m_hWnd
;
2813 TrackMouseEvent(&tme
);
2817 BOOL
CTortoiseGitBlameView::PreTranslateMessage(MSG
* pMsg
)
2819 m_ToolTip
.RelayEvent(pMsg
);
2820 return CView::PreTranslateMessage(pMsg
);
2823 void CTortoiseGitBlameView::OnEditFind()
2825 m_pFindDialog
=new CFindReplaceDialog();
2827 m_pFindDialog
->Create(TRUE
,_T(""),NULL
,FR_DOWN
,this);
2830 void CTortoiseGitBlameView::OnEditGoto()
2833 if(dlg
.DoModal()==IDOK
)
2835 this->GotoLine(dlg
.m_LineNumber
);
2839 LRESULT
CTortoiseGitBlameView::OnFindDialogMessage(WPARAM wParam
, LPARAM lParam
)
2841 ASSERT(m_pFindDialog
!= NULL
);
2843 // If the FR_DIALOGTERM flag is set,
2844 // invalidate the handle identifying the dialog box.
2845 if (m_pFindDialog
->IsTerminating())
2847 m_pFindDialog
= NULL
;
2851 // If the FR_FINDNEXT flag is set,
2852 // call the application-defined search routine
2853 // to search for the requested string.
2854 if(m_pFindDialog
->FindNext())
2856 //read data from dialog
2857 CString FindName
= m_pFindDialog
->GetFindString();
2858 bool bMatchCase
= m_pFindDialog
->MatchCase() == TRUE
;
2859 bool bMatchWholeWord
= m_pFindDialog
->MatchWholeWord() == TRUE
;
2860 bool bSearchDown
= m_pFindDialog
->SearchDown() == TRUE
;
2862 DoSearch(FindName
,m_pFindDialog
->m_fr
.Flags
);
2863 //with given name do search
2864 // *FindWhatYouNeed(FindName, bMatchCase, bMatchWholeWord, bSearchDown);
2870 void CTortoiseGitBlameView::OnViewNext()
2872 FindNextLine(this->m_SelectedHash
,false);
2874 void CTortoiseGitBlameView::OnViewPrev()
2876 FindNextLine(this->m_SelectedHash
,true);
2879 void CTortoiseGitBlameView::OnViewToggleAuthor()
2881 m_bShowAuthor
= ! m_bShowAuthor
;
2883 theApp
.WriteInt(_T("ShowAuthor"), m_bShowAuthor
);
2886 this->GetClientRect(&rect
);
2887 rect
.left
=GetBlameWidth();
2889 m_TextView
.MoveWindow(&rect
);
2892 void CTortoiseGitBlameView::OnUpdateViewToggleAuthor(CCmdUI
*pCmdUI
)
2894 pCmdUI
->SetCheck(m_bShowAuthor
);
2897 void CTortoiseGitBlameView::OnViewToggleFollowRenames()
2899 m_bFollowRenames
= ! m_bFollowRenames
;
2901 theApp
.WriteInt(_T("FollowRenames"), m_bFollowRenames
);
2903 UINT uCheck
= MF_BYCOMMAND
;
2904 uCheck
|= m_bFollowRenames
? MF_CHECKED
: MF_UNCHECKED
;
2905 CheckMenuItem(GetMenu()->m_hMenu
, ID_VIEW_FOLLOWRENAMES
, uCheck
);
2907 CTortoiseGitBlameDoc
*document
= (CTortoiseGitBlameDoc
*) m_pDocument
;
2908 if (!document
->m_CurrentFileName
.IsEmpty())
2910 theApp
.m_pDocManager
->OnFileNew();
2911 document
->OnOpenDocument(document
->m_CurrentFileName
, document
->m_Rev
);
2915 void CTortoiseGitBlameView::OnUpdateViewToggleFollowRenames(CCmdUI
*pCmdUI
)
2917 pCmdUI
->SetCheck(m_bFollowRenames
);
2920 int CTortoiseGitBlameView::FindNextLine(CGitHash CommitHash
,bool bUpOrDown
)
2922 LONG_PTR line
= SendEditor(SCI_GETFIRSTVISIBLELINE
);
2923 LONG_PTR startline
=line
;
2924 bool findNoMatch
=false;
2925 while(line
>=0 && line
<m_CommitHash
.size())
2927 if(m_CommitHash
[line
]!=CommitHash
)
2932 if(m_CommitHash
[line
] == CommitHash
&& findNoMatch
)
2934 if( line
== startline
+2 )
2942 line
=FindFirstLine(CommitHash
,line
);
2944 SendEditor(SCI_LINESCROLL
,0,line
-startline
-2);