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"
33 #include "EditGotoDlg.h"
34 #include "TortoiseGitBlameAppUtils.h"
35 #include "FileTextLines.h"
36 #include "UniCodeUtils.h"
37 #include "MenuEncode.h"
39 #include "PathUtils.h"
45 UINT
CTortoiseGitBlameView::m_FindDialogMessage
;
47 // CTortoiseGitBlameView
48 IMPLEMENT_DYNAMIC(CSciEditBlame
,CSciEdit
)
50 IMPLEMENT_DYNCREATE(CTortoiseGitBlameView
, CView
)
52 BEGIN_MESSAGE_MAP(CTortoiseGitBlameView
, CView
)
53 // Standard printing commands
54 ON_COMMAND(ID_FILE_PRINT
, &CView::OnFilePrint
)
55 ON_COMMAND(ID_FILE_PRINT_DIRECT
, &CView::OnFilePrint
)
56 ON_COMMAND(ID_FILE_PRINT_PREVIEW
, &CTortoiseGitBlameView::OnFilePrintPreview
)
57 ON_COMMAND(ID_EDIT_FIND
,OnEditFind
)
58 ON_COMMAND(ID_EDIT_GOTO
,OnEditGoto
)
59 ON_COMMAND(ID_EDIT_COPY
,CopySelectedLogToClipboard
)
60 ON_COMMAND(ID_VIEW_NEXT
,OnViewNext
)
61 ON_COMMAND(ID_VIEW_PREV
,OnViewPrev
)
62 ON_COMMAND(ID_VIEW_SHOWAUTHOR
, OnViewToggleAuthor
)
63 ON_UPDATE_COMMAND_UI(ID_VIEW_SHOWAUTHOR
, OnUpdateViewToggleAuthor
)
64 ON_COMMAND(ID_BLAMEPOPUP_COPYHASHTOCLIPBOARD
, CopyHashToClipboard
)
65 ON_COMMAND(ID_BLAMEPOPUP_COPYLOGTOCLIPBOARD
, CopySelectedLogToClipboard
)
66 ON_COMMAND(ID_BLAMEPOPUP_BLAMEPREVIOUSREVISION
, BlamePreviousRevision
)
67 ON_COMMAND(ID_BLAMEPOPUP_DIFFPREVIOUS
, DiffPreviousRevision
)
68 ON_UPDATE_COMMAND_UI(ID_BLAMEPOPUP_BLAMEPREVIOUSREVISION
, OnUpdateBlamePopupBlamePrevious
)
69 ON_UPDATE_COMMAND_UI(ID_BLAMEPOPUP_DIFFPREVIOUS
, OnUpdateBlamePopupDiffPrevious
)
70 ON_COMMAND_RANGE(IDM_FORMAT_ENCODE
, IDM_FORMAT_ENCODE_END
, OnChangeEncode
)
79 ON_NOTIFY(SCN_PAINTED
,0,OnSciPainted
)
80 ON_NOTIFY(SCN_GETBKCOLOR
,0,OnSciGetBkColor
)
81 ON_REGISTERED_MESSAGE(m_FindDialogMessage
, OnFindDialogMessage
)
85 // CTortoiseGitBlameView construction/destruction
87 CTortoiseGitBlameView::CTortoiseGitBlameView()
105 m_windowcolor
= ::GetSysColor(COLOR_WINDOW
);
106 m_textcolor
= ::GetSysColor(COLOR_WINDOWTEXT
);
107 m_texthighlightcolor
= ::GetSysColor(COLOR_HIGHLIGHTTEXT
);
108 m_mouserevcolor
= InterColor(m_windowcolor
, m_textcolor
, 20);
109 m_mouseauthorcolor
= InterColor(m_windowcolor
, m_textcolor
, 10);
110 m_selectedrevcolor
= ::GetSysColor(COLOR_HIGHLIGHT
);
111 m_selectedauthorcolor
= InterColor(m_selectedrevcolor
, m_texthighlightcolor
, 35);
115 m_selectedorigrev
= -1;
118 m_directFunction
= 0;
120 m_lowestrev
= LONG_MAX
;
126 m_bShowAuthor
= (theApp
.GetInt(_T("ShowAuthor"), 1) == 1);
129 m_FindDialogMessage
= ::RegisterWindowMessage(FINDMSGSTRING
);
130 m_pFindDialog
= NULL
;
131 // get short/long datetime setting from registry
132 DWORD RegUseShortDateFormat
= CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE
);
133 if ( RegUseShortDateFormat
)
135 m_DateFormat
= DATE_SHORTDATE
;
139 m_DateFormat
= DATE_LONGDATE
;
145 CTortoiseGitBlameView::~CTortoiseGitBlameView()
148 DeleteObject(m_font
);
150 DeleteObject(m_italicfont
);
164 void CTortoiseGitBlameView::OnChangeEncode(UINT nId
)
167 static EncodingUnit encodings
[] = {
168 {1250, "windows-1250"}, //IDM_FORMAT_WIN_1250
169 {1251, "windows-1251"}, //IDM_FORMAT_WIN_1251
170 {1252, "windows-1252"}, //IDM_FORMAT_WIN_1252
171 {1253, "windows-1253"}, //IDM_FORMAT_WIN_1253
172 {1254, "windows-1254"}, //IDM_FORMAT_WIN_1254
173 {1255, "windows-1255"}, //IDM_FORMAT_WIN_1255
174 {1256, "windows-1256"}, //IDM_FORMAT_WIN_1256
175 {1257, "windows-1257"}, //IDM_FORMAT_WIN_1257
176 {1258, "windows-1258"}, //IDM_FORMAT_WIN_1258
177 {28591, "latin1 ISO_8859-1 ISO-8859-1 CP819 IBM819 csISOLatin1 iso-ir-100 l1"}, //IDM_FORMAT_ISO_8859_1
178 {28592, "latin2 ISO_8859-2 ISO-8859-2 csISOLatin2 iso-ir-101 l2"}, //IDM_FORMAT_ISO_8859_2
179 {28593, "latin3 ISO_8859-3 ISO-8859-3 csISOLatin3 iso-ir-109 l3"}, //IDM_FORMAT_ISO_8859_3
180 {28594, "latin4 ISO_8859-4 ISO-8859-4 csISOLatin4 iso-ir-110 l4"}, //IDM_FORMAT_ISO_8859_4
181 {28595, "cyrillic ISO_8859-5 ISO-8859-5 csISOLatinCyrillic iso-ir-144"}, //IDM_FORMAT_ISO_8859_5
182 {28596, "arabic ISO_8859-6 ISO-8859-6 csISOLatinArabic iso-ir-127 ASMO-708 ECMA-114"}, //IDM_FORMAT_ISO_8859_6
183 {28597, "greek ISO_8859-7 ISO-8859-7 csISOLatinGreek greek8 iso-ir-126 ELOT_928 ECMA-118"}, //IDM_FORMAT_ISO_8859_7
184 {28598, "hebrew ISO_8859-8 ISO-8859-8 csISOLatinHebrew iso-ir-138"}, //IDM_FORMAT_ISO_8859_8
185 {28599, "latin5 ISO_8859-9 ISO-8859-9 csISOLatin5 iso-ir-148 l5"}, //IDM_FORMAT_ISO_8859_9
186 {28600, "latin6 ISO_8859-10 ISO-8859-10 csISOLatin6 iso-ir-157 l6"}, //IDM_FORMAT_ISO_8859_10
187 {28601, "ISO_8859-11 ISO-8859-11"}, //IDM_FORMAT_ISO_8859_11
188 {28603, "ISO_8859-13 ISO-8859-13"}, //IDM_FORMAT_ISO_8859_13
189 {28604, "iso-celtic latin8 ISO_8859-14 ISO-8859-14 18 iso-ir-199"}, //IDM_FORMAT_ISO_8859_14
190 {28605, "Latin-9 ISO_8859-15 ISO-8859-15"}, //IDM_FORMAT_ISO_8859_15
191 {28606, "latin10 ISO_8859-16 ISO-8859-16 110 iso-ir-226"}, //IDM_FORMAT_ISO_8859_16
192 {437, "IBM437 cp437 437 csPC8CodePage437"}, //IDM_FORMAT_DOS_437
193 {720, "IBM720 cp720 oem720 720"}, //IDM_FORMAT_DOS_720
194 {737, "IBM737 cp737 oem737 737"}, //IDM_FORMAT_DOS_737
195 {775, "IBM775 cp775 oem775 775"}, //IDM_FORMAT_DOS_775
196 {850, "IBM850 cp850 oem850 850"}, //IDM_FORMAT_DOS_850
197 {852, "IBM852 cp852 oem852 852"}, //IDM_FORMAT_DOS_852
198 {855, "IBM855 cp855 oem855 855 csIBM855"}, //IDM_FORMAT_DOS_855
199 {857, "IBM857 cp857 oem857 857"}, //IDM_FORMAT_DOS_857
200 {858, "IBM858 cp858 oem858 858"}, //IDM_FORMAT_DOS_858
201 {860, "IBM860 cp860 oem860 860"}, //IDM_FORMAT_DOS_860
202 {861, "IBM861 cp861 oem861 861"}, //IDM_FORMAT_DOS_861
203 {862, "IBM862 cp862 oem862 862"}, //IDM_FORMAT_DOS_862
204 {863, "IBM863 cp863 oem863 863"}, //IDM_FORMAT_DOS_863
205 {865, "IBM865 cp865 oem865 865"}, //IDM_FORMAT_DOS_865
206 {866, "IBM866 cp866 oem866 866"}, //IDM_FORMAT_DOS_866
207 {869, "IBM869 cp869 oem869 869"}, //IDM_FORMAT_DOS_869
208 {950, "big5 csBig5"}, //IDM_FORMAT_BIG5
209 {936, "gb2312 gbk csGB2312"}, //IDM_FORMAT_GB2312
210 {932, "Shift_JIS MS_Kanji csShiftJIS csWindows31J"}, //IDM_FORMAT_SHIFT_JIS
211 {949, "windows-949 korean"}, //IDM_FORMAT_KOREAN_WIN
212 {51949, "euc-kr csEUCKR"}, //IDM_FORMAT_EUC_KR
213 {874, "tis-620"}, //IDM_FORMAT_TIS_620
214 {10007, "x-mac-cyrillic xmaccyrillic"}, //IDM_FORMAT_MAC_CYRILLIC
215 {21866, "koi8_u"}, //IDM_FORMAT_KOI8U_CYRILLIC
216 {20866, "koi8_r csKOI8R"} //IDM_FORMAT_KOI8R_CYRILLIC
218 if(nId
>= IDM_FORMAT_ENCODE
&& nId
<= IDM_FORMAT_ENCODE_END
)
219 this->UpdateInfo(encodings
[nId
- IDM_FORMAT_ENCODE
].id
);
221 int CTortoiseGitBlameView::OnCreate(LPCREATESTRUCT lpcs
)
225 this->GetWindowRect(&rect1
);
226 rect
.left
=m_blamewidth
+LOCATOR_WIDTH
;
227 rect
.right
=rect
.Width();
229 rect
.bottom
=rect
.Height();
230 BOOL b
=m_TextView
.Create(_T("Scintilla"),_T("source"),0,rect
,this,0,0);
231 m_TextView
.Init(0,FALSE
);
232 m_TextView
.ShowWindow( SW_SHOW
);
233 //m_TextView.InsertText(_T("Abdadfasdf"));
234 m_wEditor
= m_TextView
.m_hWnd
;
237 m_ToolTip
.Create(this->GetParent());
238 m_ToolTip
.AddTool(this,_T("Test"));
240 ::AfxGetApp()->GetMainWnd();
241 return CView::OnCreate(lpcs
);
245 void CTortoiseGitBlameView::OnSize(UINT nType
,int cx
, int cy
)
249 rect
.left
=m_blamewidth
;
254 m_TextView
.MoveWindow(&rect
);
257 BOOL
CTortoiseGitBlameView::PreCreateWindow(CREATESTRUCT
& cs
)
259 return CView::PreCreateWindow(cs
);
262 // CTortoiseGitBlameView drawing
264 void CTortoiseGitBlameView::OnDraw(CDC
* /*pDC*/)
266 CTortoiseGitBlameDoc
* pDoc
= GetDocument();
271 DrawBlame(this->GetDC()->m_hDC
);
272 DrawLocatorBar(this->GetDC()->m_hDC
);
273 // TODO: add draw code for native data here
277 // CTortoiseGitBlameView printing
280 void CTortoiseGitBlameView::OnFilePrintPreview()
282 AFXPrintPreview(this);
285 BOOL
CTortoiseGitBlameView::OnPreparePrinting(CPrintInfo
* pInfo
)
287 // default preparation
288 return DoPreparePrinting(pInfo
);
291 void CTortoiseGitBlameView::OnBeginPrinting(CDC
* /*pDC*/, CPrintInfo
* /*pInfo*/)
293 // TODO: add extra initialization before printing
296 void CTortoiseGitBlameView::OnEndPrinting(CDC
* /*pDC*/, CPrintInfo
* /*pInfo*/)
298 // TODO: add cleanup after printing
301 void CTortoiseGitBlameView::OnRButtonUp(UINT nFlags
, CPoint point
)
303 LONG_PTR line
= SendEditor(SCI_GETFIRSTVISIBLELINE
);
304 LONG_PTR height
= SendEditor(SCI_TEXTHEIGHT
);
305 line
= line
+ (point
.y
/height
);
306 if (line
< (LONG
)m_CommitHash
.size())
308 if(m_ID
[line
] >= 0) // only show context menu if we have log data for it
311 ClientToScreen(&point
);
312 theApp
.GetContextMenuManager()->ShowPopupMenu(IDR_BLAME_POPUP
, point
.x
, point
.y
, this, TRUE
);
317 void CTortoiseGitBlameView::OnUpdateBlamePopupBlamePrevious(CCmdUI
*pCmdUI
)
319 if (m_ID
[m_MouseLine
] <= 1)
321 pCmdUI
->Enable(false);
325 pCmdUI
->Enable(true);
329 void CTortoiseGitBlameView::OnUpdateBlamePopupDiffPrevious(CCmdUI
*pCmdUI
)
331 if (m_ID
[m_MouseLine
] <= 1)
333 pCmdUI
->Enable(false);
337 pCmdUI
->Enable(true);
341 void CTortoiseGitBlameView::CopyHashToClipboard()
343 this->GetLogList()->CopySelectionToClipBoard(TRUE
);
346 // CTortoiseGitBlameView diagnostics
349 void CTortoiseGitBlameView::AssertValid() const
351 CView::AssertValid();
354 void CTortoiseGitBlameView::Dump(CDumpContext
& dc
) const
359 CTortoiseGitBlameDoc
* CTortoiseGitBlameView::GetDocument() const // non-debug version is inline
361 ASSERT(m_pDocument
->IsKindOf(RUNTIME_CLASS(CTortoiseGitBlameDoc
)));
362 return (CTortoiseGitBlameDoc
*)m_pDocument
;
367 // CTortoiseGitBlameView message handlers
368 CString
CTortoiseGitBlameView::GetAppDirectory()
372 DWORD bufferlen
= MAX_PATH
; // MAX_PATH is not the limit here!
375 bufferlen
+= MAX_PATH
; // MAX_PATH is not the limit here!
376 TCHAR
* pBuf
= new TCHAR
[bufferlen
];
377 len
= GetModuleFileName(NULL
, pBuf
, bufferlen
);
378 path
= CString(pBuf
, len
);
380 } while(len
== bufferlen
);
382 path
= path
.Left(path
.ReverseFind(_T('\\')));
383 //path = path.substr(0, path.rfind('\\') + 1);
388 // Return a color which is interpolated between c1 and c2.
389 // Slider controls the relative proportions as a percentage:
390 // Slider = 0 represents pure c1
391 // Slider = 50 represents equal mixture
392 // Slider = 100 represents pure c2
393 COLORREF
CTortoiseGitBlameView::InterColor(COLORREF c1
, COLORREF c2
, int Slider
)
397 // Limit Slider to 0..100% range
403 // The color components have to be treated individually.
404 r
= (GetRValue(c2
) * Slider
+ GetRValue(c1
) * (100 - Slider
)) / 100;
405 g
= (GetGValue(c2
) * Slider
+ GetGValue(c1
) * (100 - Slider
)) / 100;
406 b
= (GetBValue(c2
) * Slider
+ GetBValue(c1
) * (100 - Slider
)) / 100;
411 LRESULT
CTortoiseGitBlameView::SendEditor(UINT Msg
, WPARAM wParam
, LPARAM lParam
)
413 if (m_directFunction
)
415 return ((SciFnDirect
) m_directFunction
)(m_directPointer
, Msg
, wParam
, lParam
);
417 return ::SendMessage(m_wEditor
, Msg
, wParam
, lParam
);
420 void CTortoiseGitBlameView::GetRange(int start
, int end
, char *text
)
424 tr
.chrg
.cpMin
= start
;
428 SendMessage(m_wEditor
, EM_GETTEXTRANGE
, 0, reinterpret_cast<LPARAM
>(&tr
));
432 void CTortoiseGitBlameView::SetTitle()
435 char title
[MAX_PATH
+ 100];
436 strcpy_s(title
, MAX_PATH
+ 100, szTitle
);
437 strcat_s(title
, MAX_PATH
+ 100, " - ");
438 strcat_s(title
, MAX_PATH
+ 100, szViewtitle
);
439 ::SetWindowText(wMain
, title
);
443 BOOL
CTortoiseGitBlameView::OpenLogFile(const char *fileName
)
446 char logmsgbuf
[10000+1];
448 fopen_s(&File
, fileName
, "rb");
458 wchar_t wbuf
[MAX_LOG_LENGTH
+6];
461 len
= fread(&rev
, sizeof(LONG
), 1, File
);
468 len
= fread(&slength
, sizeof(int), 1, File
);
475 if (slength
> MAX_LOG_LENGTH
)
477 reallength
= slength
;
478 slength
= MAX_LOG_LENGTH
;
482 len
= fread(logmsgbuf
, sizeof(char), slength
, File
);
483 if (len
< (size_t)slength
)
489 msg
= CString(logmsgbuf
, slength
);
492 fseek(File
, reallength
-MAX_LOG_LENGTH
, SEEK_CUR
);
493 msg
= msg
+ _T("\n...");
495 int len2
= ::MultiByteToWideChar(CP_UTF8
, NULL
, msg
.c_str(), min(msg
.size(), MAX_LOG_LENGTH
+5), wbuf
, MAX_LOG_LENGTH
+5);
497 len2
= ::WideCharToMultiByte(CP_ACP
, NULL
, wbuf
, len2
, logmsgbuf
, MAX_LOG_LENGTH
+5, NULL
, NULL
);
499 msg
= CString(logmsgbuf
);
500 logmessages
[rev
] = msg
;
506 BOOL
CTortoiseGitBlameView::OpenFile(const char *fileName
)
509 SendEditor(SCI_SETREADONLY
, FALSE
);
510 SendEditor(SCI_CLEARALL
);
511 SendEditor(EM_EMPTYUNDOBUFFER
);
513 SendEditor(SCI_SETSAVEPOINT
);
514 SendEditor(SCI_CANCEL
);
515 SendEditor(SCI_SETUNDOCOLLECTION
, 0);
516 ::ShowWindow(m_wEditor
, SW_HIDE
);
524 char * lineptr
= NULL
;
525 char * trimptr
= NULL
;
526 //ignore the first two lines, they're of no interest to us
527 File
.getline(line
, _countof(line
));
528 File
.getline(line
, _countof(line
));
529 m_lowestrev
= LONG_MAX
;
534 File
.getline(line
, _countof(line
));
535 if (File
.gcount()>139)
537 mergelines
.push_back((line
[0] != ' '));
539 long rev
= _ttol(lineptr
);
541 m_lowestrev
= min(m_lowestrev
, rev
);
542 m_highestrev
= max(m_highestrev
, rev
);
544 rev
= _ttol(lineptr
);
545 origrevs
.push_back(rev
);
547 dates
.push_back(CString(lineptr
, 30));
549 // unfortunately, the 'path' entry can be longer than the 60 chars
550 // we made the column. We therefore have to step through the path
551 // string until we find a space
555 // TODO: how can we deal with the situation where the path has
556 // a space in it, but the space is after the 60 chars reserved
558 // The only way to deal with that would be to use a custom
559 // binary format for the blame file.
561 trimptr
= _tcschr(trimptr
, ' ');
562 } while ((trimptr
)&&(trimptr
+1 < lineptr
+61));
567 paths
.push_back(CString(lineptr
));
568 if (trimptr
+1 < lineptr
+61)
571 lineptr
= (trimptr
+1);
572 trimptr
= lineptr
+30;
573 while ((*trimptr
== ' ')&&(trimptr
> lineptr
))
576 authors
.push_back(CString(lineptr
));
578 // in case we find an UTF8 BOM at the beginning of the line, we remove it
579 if (((unsigned char)lineptr
[0] == 0xEF)&&((unsigned char)lineptr
[1] == 0xBB)&&((unsigned char)lineptr
[2] == 0xBF))
583 if (((unsigned char)lineptr
[0] == 0xBB)&&((unsigned char)lineptr
[1] == 0xEF)&&((unsigned char)lineptr
[2] == 0xBF))
587 // check each line for illegal utf8 sequences. If one is found, we treat
588 // the file as ASCII, otherwise we assume an UTF8 file.
589 char * utf8CheckBuf
= lineptr
;
590 while ((bUTF8
)&&(*utf8CheckBuf
))
592 if ((*utf8CheckBuf
== 0xC0)||(*utf8CheckBuf
== 0xC1)||(*utf8CheckBuf
>= 0xF5))
597 if ((*utf8CheckBuf
& 0xE0)==0xC0)
600 if (*utf8CheckBuf
== 0)
602 if ((*utf8CheckBuf
& 0xC0)!=0x80)
608 if ((*utf8CheckBuf
& 0xF0)==0xE0)
611 if (*utf8CheckBuf
== 0)
613 if ((*utf8CheckBuf
& 0xC0)!=0x80)
619 if (*utf8CheckBuf
== 0)
621 if ((*utf8CheckBuf
& 0xC0)!=0x80)
627 if ((*utf8CheckBuf
& 0xF8)==0xF0)
630 if (*utf8CheckBuf
== 0)
632 if ((*utf8CheckBuf
& 0xC0)!=0x80)
638 if (*utf8CheckBuf
== 0)
640 if ((*utf8CheckBuf
& 0xC0)!=0x80)
646 if (*utf8CheckBuf
== 0)
648 if ((*utf8CheckBuf
& 0xC0)!=0x80)
657 SendEditor(SCI_ADDTEXT
, _tcslen(lineptr
), reinterpret_cast<LPARAM
>(static_cast<char *>(lineptr
)));
658 SendEditor(SCI_ADDTEXT
, 2, (LPARAM
)_T("\r\n"));
660 } while (File
.gcount() > 0);
663 SendEditor(SCI_SETCODEPAGE
, SC_CP_UTF8
);
665 SendEditor(SCI_SETUNDOCOLLECTION
, 1);
666 ::SetFocus(m_wEditor
);
667 SendEditor(EM_EMPTYUNDOBUFFER
);
668 SendEditor(SCI_SETSAVEPOINT
);
669 SendEditor(SCI_GOTOPOS
, 0);
670 SendEditor(SCI_SETSCROLLWIDTHTRACKING
, TRUE
);
671 SendEditor(SCI_SETREADONLY
, TRUE
);
673 //check which lexer to use, depending on the filetype
674 SetupLexer(fileName
);
675 ::ShowWindow(m_wEditor
, SW_SHOW
);
677 ::InvalidateRect(wMain
, NULL
, TRUE
);
679 GetWindowRect(wMain
, &rc
);
680 SetWindowPos(wMain
, 0, rc
.left
, rc
.top
, rc
.right
-rc
.left
-1, rc
.bottom
- rc
.top
, 0);
685 void CTortoiseGitBlameView::SetAStyle(int style
, COLORREF fore
, COLORREF back
, int size
, CString
*face
)
687 SendEditor(SCI_STYLESETFORE
, style
, fore
);
688 SendEditor(SCI_STYLESETBACK
, style
, back
);
690 SendEditor(SCI_STYLESETSIZE
, style
, size
);
692 SendEditor(SCI_STYLESETFONT
, style
, reinterpret_cast<LPARAM
>(this->m_TextView
.StringForControl(*face
).GetBuffer()));
695 void CTortoiseGitBlameView::InitialiseEditor()
698 m_directFunction
= ::SendMessage(m_wEditor
, SCI_GETDIRECTFUNCTION
, 0, 0);
699 m_directPointer
= ::SendMessage(m_wEditor
, SCI_GETDIRECTPOINTER
, 0, 0);
700 // Set up the global default style. These attributes are used wherever no explicit choices are made.
701 SetAStyle(STYLE_DEFAULT
,
704 (DWORD
)CRegStdDWORD(_T("Software\\TortoiseGit\\BlameFontSize"), 10),
705 &CString(((stdstring
)CRegStdString(_T("Software\\TortoiseGit\\BlameFontName"), _T("Courier New"))).c_str())
707 SendEditor(SCI_SETTABWIDTH
, (DWORD
)CRegStdDWORD(_T("Software\\TortoiseGit\\BlameTabSize"), 4));
708 SendEditor(SCI_SETREADONLY
, TRUE
);
709 LRESULT pix
= SendEditor(SCI_TEXTWIDTH
, STYLE_LINENUMBER
, (LPARAM
)this->m_TextView
.StringForControl(_T("_99999")).GetBuffer());
711 SendEditor(SCI_SETMARGINWIDTHN
, 0, pix
);
713 SendEditor(SCI_SETMARGINWIDTHN
, 0);
714 SendEditor(SCI_SETMARGINWIDTHN
, 1);
715 SendEditor(SCI_SETMARGINWIDTHN
, 2);
716 //Set the default windows colors for edit controls
717 SendEditor(SCI_STYLESETFORE
, STYLE_DEFAULT
, ::GetSysColor(COLOR_WINDOWTEXT
));
718 SendEditor(SCI_STYLESETBACK
, STYLE_DEFAULT
, ::GetSysColor(COLOR_WINDOW
));
719 SendEditor(SCI_SETSELFORE
, TRUE
, ::GetSysColor(COLOR_HIGHLIGHTTEXT
));
720 SendEditor(SCI_SETSELBACK
, TRUE
, ::GetSysColor(COLOR_HIGHLIGHT
));
721 SendEditor(SCI_SETCARETFORE
, ::GetSysColor(COLOR_WINDOWTEXT
));
722 m_regOldLinesColor
= CRegStdDWORD(_T("Software\\TortoiseGit\\BlameOldColor"), RGB(230, 230, 255));
723 m_regNewLinesColor
= CRegStdDWORD(_T("Software\\TortoiseGit\\BlameNewColor"), RGB(255, 230, 230));
725 this->m_TextView
.Call(SCI_SETWRAPMODE
, SC_WRAP_NONE
);
729 void CTortoiseGitBlameView::StartSearch()
734 // Initialize FINDREPLACE
735 if (fr
.Flags
& FR_MATCHCASE
)
737 SecureZeroMemory(&fr
, sizeof(fr
));
738 fr
.lStructSize
= sizeof(fr
);
739 fr
.hwndOwner
= wMain
;
740 fr
.lpstrFindWhat
= szFindWhat
;
741 fr
.wFindWhatLen
= 80;
742 fr
.Flags
= FR_HIDEUPDOWN
| FR_HIDEWHOLEWORD
;
743 fr
.Flags
|= bCase
? FR_MATCHCASE
: 0;
745 currentDialog
= FindText(&fr
);
748 bool CTortoiseGitBlameView::DoSearch(CString what
, DWORD flags
)
752 int pos
= SendEditor(SCI_GETCURRENTPOS
);
753 int line
= SendEditor(SCI_LINEFROMPOSITION
, pos
);
755 bool bCaseSensitive
= !!(flags
& FR_MATCHCASE
);
757 //strcpy_s(szWhat, sizeof(szWhat), what);
761 what
=what
.MakeLower();
764 //CString sWhat = CString(szWhat);
771 int bufsize
= SendEditor(SCI_GETLINE
, i
);
772 char * linebuf
= new char[bufsize
+1];
773 SecureZeroMemory(linebuf
, bufsize
+1);
774 SendEditor(SCI_GETLINE
, i
, (LPARAM
)linebuf
);
775 CString oneline
=this->m_TextView
.StringFromControl(linebuf
);
778 oneline
=oneline
.MakeLower();
780 //_stprintf_s(buf, 20, _T("%ld"), revs[i]);
781 if (this->m_Authors
[i
].Find(what
)>=0)
783 else if ((!bCaseSensitive
)&&(this->m_Authors
[i
].MakeLower().Find(what
)>=0))
785 else if (oneline
.Find(what
) >=0)
791 if(i
>=(signed int)m_CommitHash
.size())
793 }while(i
!=line
&&(!bFound
));
798 int selstart
= SendEditor(SCI_GETCURRENTPOS
);
799 int selend
= SendEditor(SCI_POSITIONFROMLINE
, i
);
800 SendEditor(SCI_SETSELECTIONSTART
, selstart
);
801 SendEditor(SCI_SETSELECTIONEND
, selend
);
802 m_SelectedLine
= i
-1;
806 ::MessageBox(wMain
, what
+_T(" not found"), _T("CTortoiseGitBlameView"), MB_ICONINFORMATION
);
812 bool CTortoiseGitBlameView::GotoLine(long line
)
817 if ((unsigned long)line
>= m_CommitHash
.size())
819 line
= m_CommitHash
.size()-1;
822 int nCurrentPos
= SendEditor(SCI_GETCURRENTPOS
);
823 int nCurrentLine
= SendEditor(SCI_LINEFROMPOSITION
,nCurrentPos
);
824 int nFirstVisibleLine
= SendEditor(SCI_GETFIRSTVISIBLELINE
);
825 int nLinesOnScreen
= SendEditor(SCI_LINESONSCREEN
);
827 if ( line
>=nFirstVisibleLine
&& line
<=nFirstVisibleLine
+nLinesOnScreen
)
830 SendEditor(SCI_GOTOLINE
, line
);
834 // Place the requested line one third from the top
835 if ( line
> nCurrentLine
)
837 SendEditor(SCI_GOTOLINE
, (WPARAM
)(line
+(int)nLinesOnScreen
*(2/3.0)));
841 SendEditor(SCI_GOTOLINE
, (WPARAM
)(line
-(int)nLinesOnScreen
*(1/3.0)));
845 // Highlight the line
846 int nPosStart
= SendEditor(SCI_POSITIONFROMLINE
,line
);
847 int nPosEnd
= SendEditor(SCI_GETLINEENDPOSITION
,line
);
848 SendEditor(SCI_SETSEL
,nPosEnd
,nPosStart
);
853 bool CTortoiseGitBlameView::ScrollToLine(long line
)
858 int nCurrentLine
= SendEditor(SCI_GETFIRSTVISIBLELINE
);
860 int scrolldelta
= line
- nCurrentLine
;
861 SendEditor(SCI_LINESCROLL
, 0, scrolldelta
);
866 void CTortoiseGitBlameView::CopySelectedLogToClipboard()
868 this->GetLogList()->CopySelectionToClipBoard(FALSE
);
871 void CTortoiseGitBlameView::BlamePreviousRevision()
874 procCmd
+= _T(" /path:\"");
875 procCmd
+= ((CMainFrame
*)::AfxGetApp()->GetMainWnd())->GetActiveView()->GetDocument()->GetPathName();
876 procCmd
+= _T("\" ");
877 procCmd
+= _T(" /command:blame");
878 procCmd
+= _T(" /endrev:") + this->GetLogData()->GetGitRevAt(this->GetLogData()->size()-m_ID
[m_MouseLine
]+1).m_CommitHash
.ToString();
881 PROCESS_INFORMATION process
;
882 memset(&startup
, 0, sizeof(startup
));
883 startup
.cb
= sizeof(startup
);
884 memset(&process
, 0, sizeof(process
));
885 CString tortoiseProcPath
= CPathUtils::GetAppDirectory() + _T("TortoiseProc.exe");
887 if (CreateProcess(tortoiseProcPath
, procCmd
.GetBuffer(), NULL
, NULL
, FALSE
, 0, 0, 0, &startup
, &process
))
889 CloseHandle(process
.hThread
);
890 CloseHandle(process
.hProcess
);
894 void CTortoiseGitBlameView::DiffPreviousRevision()
897 procCmd
+= _T(" /path:\"");
898 procCmd
+= ((CMainFrame
*)::AfxGetApp()->GetMainWnd())->GetActiveView()->GetDocument()->GetPathName();
899 procCmd
+= _T("\" ");
900 procCmd
+= _T(" /command:diff");
901 procCmd
+= _T(" /startrev:") + this->GetLogData()->GetGitRevAt(this->GetLogData()->size() - m_ID
[m_MouseLine
]).m_CommitHash
.ToString();
902 procCmd
+= _T(" /endrev:") + this->GetLogData()->GetGitRevAt(this->GetLogData()->size() - m_ID
[m_MouseLine
] + 1).m_CommitHash
.ToString();
905 PROCESS_INFORMATION process
;
906 memset(&startup
, 0, sizeof(startup
));
907 startup
.cb
= sizeof(startup
);
908 memset(&process
, 0, sizeof(process
));
909 CString tortoiseProcPath
= CPathUtils::GetAppDirectory() + _T("TortoiseProc.exe");
911 if (CreateProcess(tortoiseProcPath
, procCmd
.GetBuffer(), NULL
, NULL
, FALSE
, 0, 0, 0, &startup
, &process
))
913 CloseHandle(process
.hThread
);
914 CloseHandle(process
.hProcess
);
918 void CTortoiseGitBlameView::ShowLog()
922 _stprintf_s(bufRev
, 20, _T("%d"), m_selectedorigrev
);
925 PROCESS_INFORMATION process
;
926 memset(&startup
, 0, sizeof(startup
));
927 startup
.cb
= sizeof(startup
);
928 memset(&process
, 0, sizeof(process
));
929 stdstring tortoiseProcPath
= GetAppDirectory() + _T("TortoiseProc.exe");
930 stdstring svnCmd
= _T(" /command:log ");
931 svnCmd
+= _T(" /path:\"");
932 svnCmd
+= szOrigPath
;
934 svnCmd
+= _T(" /startrev:");
936 svnCmd
+= _T(" /pegrev:");
938 if (CreateProcess(tortoiseProcPath
.c_str(), const_cast<TCHAR
*>(svnCmd
.c_str()), NULL
, NULL
, FALSE
, 0, 0, 0, &startup
, &process
))
940 CloseHandle(process
.hThread
);
941 CloseHandle(process
.hProcess
);
946 void CTortoiseGitBlameView::Notify(SCNotification
*notification
)
948 switch (notification
->nmhdr
.code
)
950 case SCN_SAVEPOINTREACHED
:
953 case SCN_SAVEPOINTLEFT
:
956 // InvalidateRect(wBlame, NULL, FALSE);
957 // InvalidateRect(wLocator, NULL, FALSE);
960 // if ((m_colorage)&&(notification->line < (int)revs.size()))
962 // notification->lParam = InterColor(DWORD(m_regOldLinesColor), DWORD(m_regNewLinesColor), (revs[notification->line]-m_lowestrev)*100/((m_highestrev-m_lowestrev)+1));
968 void CTortoiseGitBlameView::Command(int id
)
974 // ::PostQuitMessage(0);
979 case ID_COPYTOCLIPBOARD
:
980 CopySelectedLogToClipboard();
982 case ID_BLAME_PREVIOUS_REVISION
:
983 BlamePreviousRevision();
985 case ID_DIFF_PREVIOUS_REVISION
:
986 DiffPreviousRevision();
991 case ID_EDIT_GOTOLINE
:
994 case ID_VIEW_COLORAGEOFLINES
:
996 m_colorage
= !m_colorage
;
997 HMENU hMenu
= GetMenu(wMain
);
998 UINT uCheck
= MF_BYCOMMAND
;
999 uCheck
|= m_colorage
? MF_CHECKED
: MF_UNCHECKED
;
1000 CheckMenuItem(hMenu
, ID_VIEW_COLORAGEOFLINES
, uCheck
);
1005 case ID_VIEW_MERGEPATH
:
1007 ShowPath
= !ShowPath
;
1008 HMENU hMenu
= GetMenu(wMain
);
1009 UINT uCheck
= MF_BYCOMMAND
;
1010 uCheck
|= ShowPath
? MF_CHECKED
: MF_UNCHECKED
;
1011 CheckMenuItem(hMenu
, ID_VIEW_MERGEPATH
, uCheck
);
1022 LONG
CTortoiseGitBlameView::GetBlameWidth()
1024 LONG blamewidth
= 0;
1027 HDC hDC
= this->GetDC()->m_hDC
;
1028 HFONT oldfont
= (HFONT
)::SelectObject(hDC
, m_font
);
1030 TCHAR buf
[MAX_PATH
];
1032 ::GetTextExtentPoint32(hDC
, _T("fffffff"), 7, &width
);
1033 m_revwidth
= width
.cx
+ BLAMESPACE
;
1034 blamewidth
+= m_revwidth
;
1037 _stprintf_s(buf
, MAX_PATH
, _T("%d"), m_CommitHash
.size());
1038 ::GetTextExtentPoint(hDC
, buf
, _tcslen(buf
), &width
);
1039 m_linewidth
= width
.cx
+ BLAMESPACE
;
1040 blamewidth
+= m_revwidth
;
1045 _stprintf_s(buf
, MAX_PATH
, _T("%30s"), _T("31.08.2001 06:24:14"));
1046 ::GetTextExtentPoint32(hDC
, buf
, _tcslen(buf
), &width
);
1047 m_datewidth
= width
.cx
+ BLAMESPACE
;
1048 blamewidth
+= m_datewidth
;
1052 SIZE maxwidth
= {0};
1054 for (unsigned int i
=0;i
<this->m_Authors
.size();i
++)
1055 //for (std::vector<CString>::iterator I = authors.begin(); I != authors.end(); ++I)
1057 ::GetTextExtentPoint32(hDC
,m_Authors
[i
] , m_Authors
[i
].GetLength(), &width
);
1058 if (width
.cx
> maxwidth
.cx
)
1061 m_authorwidth
= maxwidth
.cx
+ BLAMESPACE
;
1062 blamewidth
+= m_authorwidth
;
1067 SIZE maxwidth
= {0};
1068 for (std::vector
<CString
>::iterator I
= paths
.begin(); I
!= paths
.end(); ++I
)
1070 ::GetTextExtentPoint32(hDC
, I
->c_str(), I
->size(), &width
);
1071 if (width
.cx
> maxwidth
.cx
)
1074 m_pathwidth
= maxwidth
.cx
+ BLAMESPACE
;
1075 blamewidth
+= m_pathwidth
;
1078 ::SelectObject(hDC
, oldfont
);
1079 POINT pt
= {blamewidth
, 0};
1080 LPtoDP(hDC
, &pt
, 1);
1081 m_blamewidth
= pt
.x
;
1082 //::ReleaseDC(wBlame, hDC);
1084 //return m_blamewidth;
1089 void CTortoiseGitBlameView::CreateFont()
1095 HDC hDC
= ::GetDC(wBlame
);
1096 lf
.lfHeight
= -MulDiv((DWORD
)CRegStdDWORD(_T("Software\\TortoiseGit\\BlameFontSize"), 10), GetDeviceCaps(hDC
, LOGPIXELSY
), 72);
1097 lf
.lfCharSet
= DEFAULT_CHARSET
;
1098 CRegStdString fontname
= CRegStdString(_T("Software\\TortoiseGit\\BlameFontName"), _T("Courier New"));
1099 _tcscpy_s(lf
.lfFaceName
, 32, ((stdstring
)fontname
).c_str());
1100 m_font
= ::CreateFontIndirect(&lf
);
1103 m_italicfont
= ::CreateFontIndirect(&lf
);
1105 ::ReleaseDC(wBlame
, hDC
);
1107 //m_TextView.SetFont(lf.lfFaceName,((DWORD)CRegStdDWORD(_T("Software\\TortoiseGit\\BlameFontSize"), 10)));
1110 void CTortoiseGitBlameView::DrawBlame(HDC hDC
)
1118 HFONT oldfont
= NULL
;
1119 LONG_PTR line
= SendEditor(SCI_GETFIRSTVISIBLELINE
);
1120 LONG_PTR linesonscreen
= SendEditor(SCI_LINESONSCREEN
);
1121 LONG_PTR height
= SendEditor(SCI_TEXTHEIGHT
);
1123 TCHAR buf
[MAX_PATH
];
1126 //::GetClientRect(this->m_hWnd, &rc);
1127 for (LRESULT i
=line
; i
<(line
+linesonscreen
); ++i
)
1130 if (i
< (int)m_CommitHash
.size())
1132 // if (mergelines[i])
1133 // oldfont = (HFONT)::SelectObject(hDC, m_italicfont);
1135 oldfont
= (HFONT
)::SelectObject(hDC
, m_font
);
1136 ::SetBkColor(hDC
, m_windowcolor
);
1137 ::SetTextColor(hDC
, m_textcolor
);
1138 if (!m_CommitHash
[i
].IsEmpty())
1140 //if (m_CommitHash[i].Compare(m_MouseHash)==0)
1141 // ::SetBkColor(hDC, m_mouseauthorcolor);
1142 if (m_CommitHash
[i
] == m_SelectedHash
)
1144 ::SetBkColor(hDC
, m_selectedauthorcolor
);
1145 ::SetTextColor(hDC
, m_texthighlightcolor
);
1150 if(m_MouseLine
== i
)
1151 ::SetBkColor(hDC
, m_mouserevcolor
);
1153 //if ((revs[i] == m_mouserev)&&(!sel))
1154 // ::SetBkColor(hDC, m_mouserevcolor);
1155 //if (revs[i] == m_selectedrev)
1157 // ::SetBkColor(hDC, m_selectedrevcolor);
1158 // ::SetTextColor(hDC, m_texthighlightcolor);
1162 str
= m_CommitHash
[i
].ToString().Left(6);
1164 //_stprintf_s(buf, MAX_PATH, _T("%8ld "), revs[i]);
1166 rc
.left
=LOCATOR_WIDTH
;
1168 rc
.right
= rc
.left
+ m_blamewidth
;
1169 ::ExtTextOut(hDC
, LOCATOR_WIDTH
, Y
, ETO_CLIPPED
, &rc
, str
, str
.GetLength(), 0);
1170 int Left
= m_revwidth
;
1174 rc
.right
= rc
.left
+ Left
+ m_authorwidth
;
1175 //_stprintf_s(buf, MAX_PATH, _T("%-30s "), authors[i].c_str());
1176 ::ExtTextOut(hDC
, Left
, Y
, ETO_CLIPPED
, &rc
, m_Authors
[i
], m_Authors
[i
].GetLength(), 0);
1177 Left
+= m_authorwidth
;
1182 rc
.right
= rc
.left
+ Left
+ m_datewidth
;
1183 _stprintf_s(buf
, MAX_PATH
, _T("%30s "), dates
[i
].c_str());
1184 ::ExtTextOut(hDC
, Left
, Y
, ETO_CLIPPED
, &rc
, buf
, _tcslen(buf
), 0);
1185 Left
+= m_datewidth
;
1192 rc
.right
= rc
.left
+ Left
+ m_pathwidth
;
1193 _stprintf_s(buf
, MAX_PATH
, _T("%-60s "), paths
[i
].c_str());
1194 ::ExtTextOut(hDC
, Left
, Y
, ETO_CLIPPED
, &rc
, buf
, _tcslen(buf
), 0);
1195 Left
+= m_authorwidth
;
1198 if ((i
==m_SelectedLine
)&&(m_pFindDialog
))
1201 brush
.lbColor
= m_textcolor
;
1203 brush
.lbStyle
= BS_SOLID
;
1204 HPEN pen
= ExtCreatePen(PS_SOLID
| PS_GEOMETRIC
, 2, &brush
, 0, NULL
);
1205 HGDIOBJ hPenOld
= SelectObject(hDC
, pen
);
1208 rc2
.bottom
= Y
+ height
;
1209 ::MoveToEx(hDC
, rc2
.left
, rc2
.top
, NULL
);
1210 ::LineTo(hDC
, rc2
.right
, rc2
.top
);
1211 ::LineTo(hDC
, rc2
.right
, rc2
.bottom
);
1212 ::LineTo(hDC
, rc2
.left
, rc2
.bottom
);
1213 ::LineTo(hDC
, rc2
.left
, rc2
.top
);
1214 SelectObject(hDC
, hPenOld
);
1218 ::SelectObject(hDC
, oldfont
);
1222 ::SetBkColor(hDC
, m_windowcolor
);
1223 for (int j
=0; j
< MAX_PATH
; ++j
)
1225 ::ExtTextOut(hDC
, 0, Y
, ETO_CLIPPED
, &rc
, buf
, MAX_PATH
-1, 0);
1231 void CTortoiseGitBlameView::DrawHeader(HDC hDC
)
1238 HFONT oldfont
= (HFONT
)::SelectObject(hDC
, GetStockObject(DEFAULT_GUI_FONT
));
1239 ::GetClientRect(wHeader
, &rc
);
1241 ::SetBkColor(hDC
, ::GetSysColor(COLOR_BTNFACE
));
1243 TCHAR szText
[MAX_LOADSTRING
];
1244 LoadString(app
.hResource
, IDS_HEADER_REVISION
, szText
, MAX_LOADSTRING
);
1245 ::ExtTextOut(hDC
, LOCATOR_WIDTH
, 0, ETO_CLIPPED
, &rc
, szText
, _tcslen(szText
), 0);
1246 int Left
= m_revwidth
+LOCATOR_WIDTH
;
1249 LoadString(app
.hResource
, IDS_HEADER_DATE
, szText
, MAX_LOADSTRING
);
1250 ::ExtTextOut(hDC
, Left
, 0, ETO_CLIPPED
, &rc
, szText
, _tcslen(szText
), 0);
1251 Left
+= m_datewidth
;
1255 LoadString(app
.hResource
, IDS_HEADER_AUTHOR
, szText
, MAX_LOADSTRING
);
1256 ::ExtTextOut(hDC
, Left
, 0, ETO_CLIPPED
, &rc
, szText
, _tcslen(szText
), 0);
1257 Left
+= m_authorwidth
;
1261 LoadString(app
.hResource
, IDS_HEADER_PATH
, szText
, MAX_LOADSTRING
);
1262 ::ExtTextOut(hDC
, Left
, 0, ETO_CLIPPED
, &rc
, szText
, _tcslen(szText
), 0);
1263 Left
+= m_pathwidth
;
1265 LoadString(app
.hResource
, IDS_HEADER_LINE
, szText
, MAX_LOADSTRING
);
1266 ::ExtTextOut(hDC
, Left
, 0, ETO_CLIPPED
, &rc
, szText
, _tcslen(szText
), 0);
1268 ::SelectObject(hDC
, oldfont
);
1272 void CTortoiseGitBlameView::DrawLocatorBar(HDC hDC
)
1277 LONG_PTR line
= SendEditor(SCI_GETFIRSTVISIBLELINE
);
1278 LONG_PTR linesonscreen
= SendEditor(SCI_LINESONSCREEN
);
1280 COLORREF blackColor
= GetSysColor(COLOR_WINDOWTEXT
);
1283 //::GetClientRect(wLocator, &rc);
1284 this->GetClientRect(&rc
);
1286 rc
.right
=LOCATOR_WIDTH
;
1289 LONG height
= rc
.bottom
-rc
.top
;
1290 LONG currentLine
= 0;
1292 // draw the colored bar
1293 for (std::vector
<LONG
>::const_iterator it
= m_ID
.begin(); it
!= m_ID
.end(); ++it
)
1296 // get the line color
1297 COLORREF cr
= InterColor(DWORD(m_regOldLinesColor
), DWORD(m_regNewLinesColor
), (*it
- m_lowestrev
)*100/((m_highestrev
-m_lowestrev
)+1));
1298 if ((currentLine
> line
)&&(currentLine
<= (line
+ linesonscreen
)))
1300 cr
= InterColor(cr
, blackColor
, 10);
1302 SetBkColor(hDC
, cr
);
1304 lineRect
.bottom
= (currentLine
* height
/ m_ID
.size());
1305 ::ExtTextOut(hDC
, 0, 0, ETO_OPAQUE
, &lineRect
, NULL
, 0, NULL
);
1306 Y
= lineRect
.bottom
;
1311 // now draw two lines indicating the scroll position of the source view
1312 SetBkColor(hDC
, blackColor
);
1313 lineRect
.top
= line
* height
/ m_ID
.size();
1314 lineRect
.bottom
= lineRect
.top
+1;
1315 ::ExtTextOut(hDC
, 0, 0, ETO_OPAQUE
, &lineRect
, NULL
, 0, NULL
);
1316 lineRect
.top
= (line
+ linesonscreen
) * height
/ m_ID
.size();
1317 lineRect
.bottom
= lineRect
.top
+1;
1318 ::ExtTextOut(hDC
, 0, 0, ETO_OPAQUE
, &lineRect
, NULL
, 0, NULL
);
1323 void CTortoiseGitBlameView::StringExpand(LPSTR str
)
1328 cPos
= strchr(cPos
, '\n');
1331 memmove(cPos
+1, cPos
, strlen(cPos
)*sizeof(char));
1336 } while (cPos
!= NULL
);
1338 void CTortoiseGitBlameView::StringExpand(LPWSTR str
)
1340 wchar_t * cPos
= str
;
1343 cPos
= wcschr(cPos
, '\n');
1346 memmove(cPos
+1, cPos
, wcslen(cPos
)*sizeof(wchar_t));
1351 } while (cPos
!= NULL
);
1354 // Forward declarations of functions included in this code module:
1355 ATOM
MyRegisterClass(HINSTANCE hResource
);
1356 ATOM
MyRegisterBlameClass(HINSTANCE hResource
);
1357 ATOM
MyRegisterHeaderClass(HINSTANCE hResource
);
1358 ATOM
MyRegisterLocatorClass(HINSTANCE hResource
);
1359 BOOL
InitInstance(HINSTANCE
, int);
1360 LRESULT CALLBACK
WndProc(HWND
, UINT
, WPARAM
, LPARAM
);
1361 LRESULT CALLBACK
WndBlameProc(HWND
, UINT
, WPARAM
, LPARAM
);
1362 LRESULT CALLBACK
WndHeaderProc(HWND
, UINT
, WPARAM
, LPARAM
);
1363 LRESULT CALLBACK
WndLocatorProc(HWND
, UINT
, WPARAM
, LPARAM
);
1364 UINT uFindReplaceMsg
;
1367 int APIENTRY
_tWinMain(HINSTANCE hInstance
,
1368 HINSTANCE
/*hPrevInstance*/,
1372 app
.hInstance
= hInstance
;
1376 if (::LoadLibrary("SciLexer.DLL") == NULL
)
1379 CRegStdDWORD loc
= CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), 1033);
1383 app
.hResource
= langDLL
.Init(_T("CTortoiseGitBlameView"), langId
);
1384 if (app
.hResource
== NULL
)
1385 app
.hResource
= app
.hInstance
;
1387 // Initialize global strings
1388 LoadString(app
.hResource
, IDS_APP_TITLE
, szTitle
, MAX_LOADSTRING
);
1389 LoadString(app
.hResource
, IDC_TortoiseGitBlameView
, szWindowClass
, MAX_LOADSTRING
);
1390 LoadString(app
.hResource
, IDS_SEARCHNOTFOUND
, searchstringnotfound
, MAX_LOADSTRING
);
1391 MyRegisterClass(app
.hResource
);
1392 MyRegisterBlameClass(app
.hResource
);
1393 MyRegisterHeaderClass(app
.hResource
);
1394 MyRegisterLocatorClass(app
.hResource
);
1396 // Perform application initialization:
1397 if (!InitInstance (app
.hResource
, nCmdShow
))
1403 SecureZeroMemory(szViewtitle
, MAX_PATH
);
1404 SecureZeroMemory(szOrigPath
, MAX_PATH
);
1405 char blamefile
[MAX_PATH
] = {0};
1406 char logfile
[MAX_PATH
] = {0};
1408 CCmdLineParser
parser(lpCmdLine
);
1413 _tcscpy_s(blamefile
, MAX_PATH
, __argv
[1]);
1417 _tcscpy_s(logfile
, MAX_PATH
, __argv
[2]);
1421 _tcscpy_s(szViewtitle
, MAX_PATH
, __argv
[3]);
1422 if (parser
.HasVal(_T("revrange")))
1424 _tcscat_s(szViewtitle
, MAX_PATH
, _T(" : "));
1425 _tcscat_s(szViewtitle
, MAX_PATH
, parser
.GetVal(_T("revrange")));
1428 if ((_tcslen(blamefile
)==0) || parser
.HasKey(_T("?")) || parser
.HasKey(_T("help")))
1430 TCHAR szInfo
[MAX_LOADSTRING
];
1431 LoadString(app
.hResource
, IDS_COMMANDLINE_INFO
, szInfo
, MAX_LOADSTRING
);
1432 MessageBox(NULL
, szInfo
, _T("CTortoiseGitBlameView"), MB_ICONERROR
);
1437 if ( parser
.HasKey(_T("path")) )
1439 _tcscpy_s(szOrigPath
, MAX_PATH
, parser
.GetVal(_T("path")));
1441 app
.bIgnoreEOL
= parser
.HasKey(_T("ignoreeol"));
1442 app
.bIgnoreSpaces
= parser
.HasKey(_T("ignorespaces"));
1443 app
.bIgnoreAllSpaces
= parser
.HasKey(_T("ignoreallspaces"));
1445 app
.SendEditor(SCI_SETCODEPAGE
, GetACP());
1446 app
.OpenFile(blamefile
);
1447 if (_tcslen(logfile
)>0)
1448 app
.OpenLogFile(logfile
);
1450 if (parser
.HasKey(_T("line")))
1452 app
.GotoLine(parser
.GetLongVal(_T("line")));
1455 CheckMenuItem(GetMenu(app
.wMain
), ID_VIEW_COLORAGEOFLINES
, MF_CHECKED
|MF_BYCOMMAND
);
1458 hAccelTable
= LoadAccelerators(app
.hResource
, (LPCTSTR
)IDC_TortoiseGitBlameView
);
1464 going
= GetMessage(&msg
, NULL
, 0, 0);
1465 if (app
.currentDialog
&& going
)
1467 if (!IsDialogMessage(app
.currentDialog
, &msg
))
1469 if (TranslateAccelerator(msg
.hwnd
, hAccelTable
, &msg
) == 0)
1471 TranslateMessage(&msg
);
1472 DispatchMessage(&msg
);
1478 if (TranslateAccelerator(app
.wMain
, hAccelTable
, &msg
) == 0)
1480 TranslateMessage(&msg
);
1481 DispatchMessage(&msg
);
1489 ATOM
MyRegisterClass(HINSTANCE hResource
)
1493 wcex
.cbSize
= sizeof(WNDCLASSEX
);
1495 wcex
.style
= CS_HREDRAW
| CS_VREDRAW
;
1496 wcex
.lpfnWndProc
= (WNDPROC
)WndProc
;
1497 wcex
.cbClsExtra
= 0;
1498 wcex
.cbWndExtra
= 0;
1499 wcex
.hInstance
= hResource
;
1500 wcex
.hIcon
= LoadIcon(hResource
, (LPCTSTR
)IDI_TortoiseGitBlameView
);
1501 wcex
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
1502 wcex
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+1);
1503 wcex
.lpszMenuName
= (LPCTSTR
)IDC_TortoiseGitBlameView
;
1504 wcex
.lpszClassName
= szWindowClass
;
1505 wcex
.hIconSm
= LoadIcon(wcex
.hInstance
, (LPCTSTR
)IDI_SMALL
);
1507 return RegisterClassEx(&wcex
);
1510 ATOM
MyRegisterBlameClass(HINSTANCE hResource
)
1514 wcex
.cbSize
= sizeof(WNDCLASSEX
);
1516 wcex
.style
= CS_HREDRAW
| CS_VREDRAW
;
1517 wcex
.lpfnWndProc
= (WNDPROC
)WndBlameProc
;
1518 wcex
.cbClsExtra
= 0;
1519 wcex
.cbWndExtra
= 0;
1520 wcex
.hInstance
= hResource
;
1521 wcex
.hIcon
= LoadIcon(hResource
, (LPCTSTR
)IDI_TortoiseGitBlameView
);
1522 wcex
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
1523 wcex
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+1);
1524 wcex
.lpszMenuName
= 0;
1525 wcex
.lpszClassName
= _T("TortoiseGitBlameViewBlame");
1526 wcex
.hIconSm
= LoadIcon(wcex
.hInstance
, (LPCTSTR
)IDI_SMALL
);
1528 return RegisterClassEx(&wcex
);
1531 ATOM
MyRegisterHeaderClass(HINSTANCE hResource
)
1535 wcex
.cbSize
= sizeof(WNDCLASSEX
);
1537 wcex
.style
= CS_HREDRAW
| CS_VREDRAW
;
1538 wcex
.lpfnWndProc
= (WNDPROC
)WndHeaderProc
;
1539 wcex
.cbClsExtra
= 0;
1540 wcex
.cbWndExtra
= 0;
1541 wcex
.hInstance
= hResource
;
1542 wcex
.hIcon
= LoadIcon(hResource
, (LPCTSTR
)IDI_TortoiseGitBlameView
);
1543 wcex
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
1544 wcex
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+1);
1545 wcex
.lpszMenuName
= 0;
1546 wcex
.lpszClassName
= _T("TortoiseGitBlameViewHeader");
1547 wcex
.hIconSm
= LoadIcon(wcex
.hInstance
, (LPCTSTR
)IDI_SMALL
);
1549 return RegisterClassEx(&wcex
);
1552 ATOM
MyRegisterLocatorClass(HINSTANCE hResource
)
1556 wcex
.cbSize
= sizeof(WNDCLASSEX
);
1558 wcex
.style
= CS_HREDRAW
| CS_VREDRAW
;
1559 wcex
.lpfnWndProc
= (WNDPROC
)WndLocatorProc
;
1560 wcex
.cbClsExtra
= 0;
1561 wcex
.cbWndExtra
= 0;
1562 wcex
.hInstance
= hResource
;
1563 wcex
.hIcon
= LoadIcon(hResource
, (LPCTSTR
)IDI_TortoiseGitBlameView
);
1564 wcex
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
1565 wcex
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+1);
1566 wcex
.lpszMenuName
= 0;
1567 wcex
.lpszClassName
= _T("TortoiseGitBlameViewLocator");
1568 wcex
.hIconSm
= LoadIcon(wcex
.hInstance
, (LPCTSTR
)IDI_SMALL
);
1570 return RegisterClassEx(&wcex
);
1573 BOOL
InitInstance(HINSTANCE hResource
, int nCmdShow
)
1575 app
.wMain
= CreateWindow(szWindowClass
, szTitle
, WS_OVERLAPPEDWINDOW
,
1576 CW_USEDEFAULT
, 0, CW_USEDEFAULT
, 0, NULL
, NULL
, hResource
, NULL
);
1583 CRegStdDWORD
pos(_T("Software\\TortoiseGit\\TBlamePos"), 0);
1584 CRegStdDWORD
width(_T("Software\\TortoiseGit\\TBlameSize"), 0);
1585 CRegStdDWORD
state(_T("Software\\TortoiseGit\\TBlameState"), 0);
1586 if (DWORD(pos
) && DWORD(width
))
1589 rc
.left
= LOWORD(DWORD(pos
));
1590 rc
.top
= HIWORD(DWORD(pos
));
1591 rc
.right
= rc
.left
+ LOWORD(DWORD(width
));
1592 rc
.bottom
= rc
.top
+ HIWORD(DWORD(width
));
1593 HMONITOR hMon
= MonitorFromRect(&rc
, MONITOR_DEFAULTTONULL
);
1596 // only restore the window position if the monitor is valid
1597 MoveWindow(app
.wMain
, LOWORD(DWORD(pos
)), HIWORD(DWORD(pos
)),
1598 LOWORD(DWORD(width
)), HIWORD(DWORD(width
)), FALSE
);
1601 if (DWORD(state
) == SW_MAXIMIZE
)
1602 ShowWindow(app
.wMain
, SW_MAXIMIZE
);
1604 ShowWindow(app
.wMain
, nCmdShow
);
1605 UpdateWindow(app
.wMain
);
1607 //Create the tooltips
1609 INITCOMMONCONTROLSEX iccex
;
1610 app
.hwndTT
; // handle to the ToolTip control
1612 RECT rect
; // for client area coordinates
1613 iccex
.dwICC
= ICC_WIN95_CLASSES
;
1614 iccex
.dwSize
= sizeof(INITCOMMONCONTROLSEX
);
1615 InitCommonControlsEx(&iccex
);
1617 /* CREATE A TOOLTIP WINDOW */
1618 app
.hwndTT
= CreateWindowEx(WS_EX_TOPMOST
,
1621 WS_POPUP
| TTS_NOPREFIX
| TTS_ALWAYSTIP
,
1632 SetWindowPos(app
.hwndTT
,
1638 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
1640 /* GET COORDINATES OF THE MAIN CLIENT AREA */
1641 GetClientRect (app
.wBlame
, &rect
);
1643 /* INITIALIZE MEMBERS OF THE TOOLINFO STRUCTURE */
1644 ti
.cbSize
= sizeof(TOOLINFO
);
1645 ti
.uFlags
= TTF_TRACK
| TTF_ABSOLUTE
;//TTF_SUBCLASS | TTF_PARSELINKS;
1646 ti
.hwnd
= app
.wBlame
;
1647 ti
.hinst
= app
.hResource
;
1649 ti
.lpszText
= LPSTR_TEXTCALLBACK
;
1650 // ToolTip control will cover the whole window
1651 ti
.rect
.left
= rect
.left
;
1652 ti
.rect
.top
= rect
.top
;
1653 ti
.rect
.right
= rect
.right
;
1654 ti
.rect
.bottom
= rect
.bottom
;
1656 /* SEND AN ADDTOOL MESSAGE TO THE TOOLTIP CONTROL WINDOW */
1657 SendMessage(app
.hwndTT
, TTM_ADDTOOL
, 0, (LPARAM
) (LPTOOLINFO
) &ti
);
1658 SendMessage(app
.hwndTT
, TTM_SETMAXTIPWIDTH
, 0, 600);
1659 //SendMessage(app.hwndTT, TTM_SETDELAYTIME, TTDT_AUTOPOP, MAKELONG(50000, 0));
1660 //SendMessage(app.hwndTT, TTM_SETDELAYTIME, TTDT_RESHOW, MAKELONG(1000, 0));
1662 uFindReplaceMsg
= RegisterWindowMessage(FINDMSGSTRING
);
1667 void CTortoiseGitBlameView::InitSize()
1672 ::GetClientRect(wMain
, &rc
);
1673 ::SetWindowPos(wHeader
, 0, rc
.left
, rc
.top
, rc
.right
-rc
.left
, HEADER_HEIGHT
, 0);
1674 rc
.top
+= HEADER_HEIGHT
;
1675 blamerc
.left
= rc
.left
;
1676 blamerc
.top
= rc
.top
;
1677 LONG w
= GetBlameWidth();
1678 blamerc
.right
= w
> abs(rc
.right
- rc
.left
) ? rc
.right
: w
+ rc
.left
;
1679 blamerc
.bottom
= rc
.bottom
;
1680 sourcerc
.left
= blamerc
.right
;
1681 sourcerc
.top
= rc
.top
;
1682 sourcerc
.bottom
= rc
.bottom
;
1683 sourcerc
.right
= rc
.right
;
1686 ::OffsetRect(&blamerc
, LOCATOR_WIDTH
, 0);
1687 ::OffsetRect(&sourcerc
, LOCATOR_WIDTH
, 0);
1688 sourcerc
.right
-= LOCATOR_WIDTH
;
1690 ::InvalidateRect(wMain
, NULL
, FALSE
);
1691 ::SetWindowPos(m_wEditor
, 0, sourcerc
.left
, sourcerc
.top
, sourcerc
.right
- sourcerc
.left
, sourcerc
.bottom
- sourcerc
.top
, 0);
1692 ::SetWindowPos(wBlame
, 0, blamerc
.left
, blamerc
.top
, blamerc
.right
- blamerc
.left
, blamerc
.bottom
- blamerc
.top
, 0);
1694 ::SetWindowPos(wLocator
, 0, 0, blamerc
.top
, LOCATOR_WIDTH
, blamerc
.bottom
- blamerc
.top
, SWP_SHOWWINDOW
);
1696 ::ShowWindow(wLocator
, SW_HIDE
);
1700 LRESULT CALLBACK
WndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1702 if (message
== uFindReplaceMsg
)
1704 LPFINDREPLACE lpfr
= (LPFINDREPLACE
)lParam
;
1706 // If the FR_DIALOGTERM flag is set,
1707 // invalidate the handle identifying the dialog box.
1708 if (lpfr
->Flags
& FR_DIALOGTERM
)
1710 app
.currentDialog
= NULL
;
1713 if (lpfr
->Flags
& FR_FINDNEXT
)
1715 app
.DoSearch(lpfr
->lpstrFindWhat
, lpfr
->Flags
);
1722 app
.m_wEditor
= ::CreateWindow(
1725 WS_CHILD
| WS_VSCROLL
| WS_HSCROLL
| WS_CLIPCHILDREN
,
1732 app
.InitialiseEditor();
1733 ::ShowWindow(app
.m_wEditor
, SW_SHOW
);
1734 ::SetFocus(app
.m_wEditor
);
1735 app
.wBlame
= ::CreateWindow(
1736 _T("TortoiseGitBlameViewBlame"),
1738 WS_CHILD
| WS_CLIPCHILDREN
,
1745 ::ShowWindow(app
.wBlame
, SW_SHOW
);
1746 app
.wHeader
= ::CreateWindow(
1747 _T("TortoiseGitBlameViewHeader"),
1749 WS_CHILD
| WS_CLIPCHILDREN
| WS_BORDER
,
1756 ::ShowWindow(app
.wHeader
, SW_SHOW
);
1757 app
.wLocator
= ::CreateWindow(
1758 _T("TortoiseGitBlameViewLocator"),
1760 WS_CHILD
| WS_CLIPCHILDREN
| WS_BORDER
,
1767 ::ShowWindow(app
.wLocator
, SW_SHOW
);
1778 app
.Command(LOWORD(wParam
));
1781 app
.Notify(reinterpret_cast<SCNotification
*>(lParam
));
1788 CRegStdDWORD
pos(_T("Software\\TortoiseGit\\TBlamePos"), 0);
1789 CRegStdDWORD
width(_T("Software\\TortoiseGit\\TBlameSize"), 0);
1790 CRegStdDWORD
state(_T("Software\\TortoiseGit\\TBlameState"), 0);
1792 GetWindowRect(app
.wMain
, &rc
);
1793 if ((rc
.left
>= 0)&&(rc
.top
>= 0))
1795 pos
= MAKELONG(rc
.left
, rc
.top
);
1796 width
= MAKELONG(rc
.right
-rc
.left
, rc
.bottom
-rc
.top
);
1798 WINDOWPLACEMENT wp
= {0};
1799 wp
.length
= sizeof(WINDOWPLACEMENT
);
1800 GetWindowPlacement(app
.wMain
, &wp
);
1802 ::DestroyWindow(app
.m_wEditor
);
1803 ::PostQuitMessage(0);
1807 ::SetFocus(app
.wBlame
);
1810 return DefWindowProc(hWnd
, message
, wParam
, lParam
);
1815 LRESULT CALLBACK
WndBlameProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1818 TRACKMOUSEEVENT mevt
;
1825 hDC
= BeginPaint(app
.wBlame
, &ps
);
1827 EndPaint(app
.wBlame
, &ps
);
1830 app
.Command(LOWORD(wParam
));
1833 switch (((LPNMHDR
)lParam
)->code
)
1835 case TTN_GETDISPINFO
:
1837 LPNMHDR pNMHDR
= (LPNMHDR
)lParam
;
1838 NMTTDISPINFOA
* pTTTA
= (NMTTDISPINFOA
*)pNMHDR
;
1839 NMTTDISPINFOW
* pTTTW
= (NMTTDISPINFOW
*)pNMHDR
;
1841 DWORD ptW
= GetMessagePos();
1842 point
.x
= GET_X_LPARAM(ptW
);
1843 point
.y
= GET_Y_LPARAM(ptW
);
1844 ::ScreenToClient(app
.wBlame
, &point
);
1845 LONG_PTR line
= app
.SendEditor(SCI_GETFIRSTVISIBLELINE
);
1846 LONG_PTR height
= app
.SendEditor(SCI_TEXTHEIGHT
);
1847 line
= line
+ (point
.y
/height
);
1848 if (line
>= (LONG
)app
.revs
.size())
1852 LONG rev
= app
.revs
[line
];
1853 if (line
>= (LONG
)app
.revs
.size())
1856 SecureZeroMemory(app
.m_szTip
, sizeof(app
.m_szTip
));
1857 SecureZeroMemory(app
.m_wszTip
, sizeof(app
.m_wszTip
));
1858 std::map
<LONG
, CString
>::iterator iter
;
1859 if ((iter
= app
.logmessages
.find(rev
)) != app
.logmessages
.end())
1864 msg
+= app
.authors
[line
];
1868 if (!ShowAuthor
) msg
+= " ";
1869 msg
+= app
.dates
[line
];
1871 if (!ShowAuthor
|| !ShowDate
)
1873 msg
+= iter
->second
;
1874 // an empty tooltip string will deactivate the tooltips,
1875 // which means we must make sure that the tooltip won't
1879 if (pNMHDR
->code
== TTN_NEEDTEXTA
)
1881 lstrcpyn(app
.m_szTip
, msg
.c_str(), MAX_LOG_LENGTH
*2);
1882 app
.StringExpand(app
.m_szTip
);
1883 pTTTA
->lpszText
= app
.m_szTip
;
1887 pTTTW
->lpszText
= app
.m_wszTip
;
1888 ::MultiByteToWideChar( CP_ACP
, 0, msg
.c_str(), min(msg
.size(), MAX_LOG_LENGTH
*2), app
.m_wszTip
, MAX_LOG_LENGTH
*2);
1889 app
.StringExpand(app
.m_wszTip
);
1901 app
.m_mouserev
= -2;
1902 app
.m_mouseauthor
.clear();
1903 app
.ttVisible
= FALSE
;
1904 SendMessage(app
.hwndTT
, TTM_TRACKACTIVATE
, FALSE
, 0);
1905 ::InvalidateRect(app
.wBlame
, NULL
, FALSE
);
1909 mevt
.cbSize
= sizeof(TRACKMOUSEEVENT
);
1910 mevt
.dwFlags
= TME_LEAVE
;
1911 mevt
.dwHoverTime
= HOVER_DEFAULT
;
1912 mevt
.hwndTrack
= app
.wBlame
;
1913 ::TrackMouseEvent(&mevt
);
1914 POINT pt
= {((int)(short)LOWORD(lParam
)), ((int)(short)HIWORD(lParam
))};
1915 ClientToScreen(app
.wBlame
, &pt
);
1918 SendMessage(app
.hwndTT
, TTM_TRACKPOSITION
, 0, MAKELONG(pt
.x
, pt
.y
));
1922 ti
.cbSize
= sizeof(TOOLINFO
);
1923 ti
.hwnd
= app
.wBlame
;
1925 SendMessage(app
.hwndTT
, TTM_TRACKACTIVATE
, TRUE
, (LPARAM
)&ti
);
1927 int y
= ((int)(short)HIWORD(lParam
));
1928 LONG_PTR line
= app
.SendEditor(SCI_GETFIRSTVISIBLELINE
);
1929 LONG_PTR height
= app
.SendEditor(SCI_TEXTHEIGHT
);
1930 line
= line
+ (y
/height
);
1931 app
.ttVisible
= (line
< (LONG
)app
.revs
.size());
1932 if ( app
.ttVisible
)
1934 if (app
.authors
[line
].compare(app
.m_mouseauthor
) != 0)
1936 app
.m_mouseauthor
= app
.authors
[line
];
1938 if (app
.revs
[line
] != app
.m_mouserev
)
1940 app
.m_mouserev
= app
.revs
[line
];
1941 ::InvalidateRect(app
.wBlame
, NULL
, FALSE
);
1942 SendMessage(app
.hwndTT
, TTM_UPDATE
, 0, 0);
1947 case WM_RBUTTONDOWN
:
1949 case WM_LBUTTONDOWN
:
1953 ::SetFocus(app
.wBlame
);
1954 app
.SendEditor(SCI_GRABFOCUS
);
1956 case WM_CONTEXTMENU
:
1958 if (app
.m_selectedrev
<= 0)
1960 int xPos
= GET_X_LPARAM(lParam
);
1961 int yPos
= GET_Y_LPARAM(lParam
);
1962 if ((xPos
< 0)||(yPos
< 0))
1964 // requested from keyboard, not mouse pointer
1965 // use the center of the window
1967 GetClientRect(app
.wBlame
, &rect
);
1968 xPos
= rect
.right
-rect
.left
;
1969 yPos
= rect
.bottom
-rect
.top
;
1971 HMENU hMenu
= LoadMenu(app
.hResource
, MAKEINTRESOURCE(IDR_BLAMEPOPUP
));
1972 HMENU hPopMenu
= GetSubMenu(hMenu
, 0);
1974 if ( _tcslen(szOrigPath
)==0 )
1976 // Without knowing the original path we cannot blame the previous revision
1977 // because we don't know which filename to pass to tortoiseproc.
1978 EnableMenuItem(hPopMenu
,ID_BLAME_PREVIOUS_REVISION
, MF_DISABLED
|MF_GRAYED
);
1981 TrackPopupMenu(hPopMenu
, TPM_LEFTALIGN
| TPM_RIGHTBUTTON
, xPos
, yPos
, 0, app
.wBlame
, NULL
);
1986 return DefWindowProc(hWnd
, message
, wParam
, lParam
);
1991 LRESULT CALLBACK
WndHeaderProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
2000 hDC
= BeginPaint(app
.wHeader
, &ps
);
2001 app
.DrawHeader(hDC
);
2002 EndPaint(app
.wHeader
, &ps
);
2011 return DefWindowProc(hWnd
, message
, wParam
, lParam
);
2016 LRESULT CALLBACK
WndLocatorProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
2023 hDC
= BeginPaint(app
.wLocator
, &ps
);
2024 app
.DrawLocatorBar(hDC
);
2025 EndPaint(app
.wLocator
, &ps
);
2027 case WM_LBUTTONDOWN
:
2029 if (wParam
& MK_LBUTTON
)
2032 ::GetClientRect(hWnd
, &rect
);
2033 int nLine
= HIWORD(lParam
)*app
.revs
.size()/(rect
.bottom
-rect
.top
);
2037 app
.ScrollToLine(nLine
);
2041 return DefWindowProc(hWnd
, message
, wParam
, lParam
);
2047 void CTortoiseGitBlameView::SetupLexer(CString filename
)
2051 //const char * lineptr = _tcsrchr(filename, '.');
2052 int start
=filename
.ReverseFind(_T('.'));
2055 //_tcscpy_s(line, 20, lineptr+1);
2056 //_tcslwr_s(line, 20);
2057 CString ext
=filename
.Right(filename
.GetLength()-start
-1);
2058 line
=ext
.GetBuffer();
2060 if ((_tcscmp(line
, _T("py"))==0)||
2061 (_tcscmp(line
, _T("pyw"))==0)||
2062 (_tcscmp(line
, _T("pyw"))==0))
2064 SendEditor(SCI_SETLEXER
, SCLEX_PYTHON
);
2065 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("and assert break class continue def del elif \
2066 else except exec finally for from global if import in is lambda None \
2067 not or pass print raise return try while yield")).GetBuffer()));
2068 SetAStyle(SCE_P_DEFAULT
, black
);
2069 SetAStyle(SCE_P_COMMENTLINE
, darkGreen
);
2070 SetAStyle(SCE_P_NUMBER
, RGB(0, 0x80, 0x80));
2071 SetAStyle(SCE_P_STRING
, RGB(0, 0, 0x80));
2072 SetAStyle(SCE_P_CHARACTER
, RGB(0, 0, 0x80));
2073 SetAStyle(SCE_P_WORD
, RGB(0x80, 0, 0x80));
2074 SetAStyle(SCE_P_TRIPLE
, black
);
2075 SetAStyle(SCE_P_TRIPLEDOUBLE
, black
);
2076 SetAStyle(SCE_P_CLASSNAME
, darkBlue
);
2077 SetAStyle(SCE_P_DEFNAME
, darkBlue
);
2078 SetAStyle(SCE_P_OPERATOR
, darkBlue
);
2079 SetAStyle(SCE_P_IDENTIFIER
, darkBlue
);
2080 SetAStyle(SCE_P_COMMENTBLOCK
, darkGreen
);
2081 SetAStyle(SCE_P_STRINGEOL
, red
);
2083 if ((_tcscmp(line
, _T("c"))==0)||
2084 (_tcscmp(line
, _T("cc"))==0)||
2085 (_tcscmp(line
, _T("cpp"))==0)||
2086 (_tcscmp(line
, _T("cxx"))==0)||
2087 (_tcscmp(line
, _T("h"))==0)||
2088 (_tcscmp(line
, _T("hh"))==0)||
2089 (_tcscmp(line
, _T("hpp"))==0)||
2090 (_tcscmp(line
, _T("hxx"))==0)||
2091 (_tcscmp(line
, _T("dlg"))==0)||
2092 (_tcscmp(line
, _T("mak"))==0))
2094 SendEditor(SCI_SETLEXER
, SCLEX_CPP
);
2095 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("and and_eq asm auto bitand bitor bool break \
2096 case catch char class compl const const_cast continue \
2097 default delete do double dynamic_cast else enum explicit export extern false float for \
2098 friend goto if inline int long mutable namespace new not not_eq \
2099 operator or or_eq private protected public \
2100 register reinterpret_cast return short signed sizeof static static_cast struct switch \
2101 template this throw true try typedef typeid typename union unsigned using \
2102 virtual void volatile wchar_t while xor xor_eq")).GetBuffer()));
2103 SendEditor(SCI_SETKEYWORDS
, 3, (LPARAM
)(m_TextView
.StringForControl(_T("a addindex addtogroup anchor arg attention \
2104 author b brief bug c class code date def defgroup deprecated dontinclude \
2105 e em endcode endhtmlonly endif endlatexonly endlink endverbatim enum example exception \
2106 f$ f[ f] file fn hideinitializer htmlinclude htmlonly \
2107 if image include ingroup internal invariant interface latexonly li line link \
2108 mainpage name namespace nosubgrouping note overload \
2109 p page par param post pre ref relates remarks return retval \
2110 sa section see showinitializer since skip skipline struct subsection \
2111 test throw todo typedef union until \
2112 var verbatim verbinclude version warning weakgroup $ @ \\ & < > # { }")).GetBuffer()));
2115 if (_tcscmp(line
, _T("cs"))==0)
2117 SendEditor(SCI_SETLEXER
, SCLEX_CPP
);
2118 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("abstract as base bool break byte case catch char checked class \
2119 const continue decimal default delegate do double else enum \
2120 event explicit extern false finally fixed float for foreach goto if \
2121 implicit in int interface internal is lock long namespace new null \
2122 object operator out override params private protected public \
2123 readonly ref return sbyte sealed short sizeof stackalloc static \
2124 string struct switch this throw true try typeof uint ulong \
2125 unchecked unsafe ushort using virtual void while")).GetBuffer()));
2128 if ((_tcscmp(line
, _T("rc"))==0)||
2129 (_tcscmp(line
, _T("rc2"))==0))
2131 SendEditor(SCI_SETLEXER
, SCLEX_CPP
);
2132 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("ACCELERATORS ALT AUTO3STATE AUTOCHECKBOX AUTORADIOBUTTON \
2133 BEGIN BITMAP BLOCK BUTTON CAPTION CHARACTERISTICS CHECKBOX CLASS \
2134 COMBOBOX CONTROL CTEXT CURSOR DEFPUSHBUTTON DIALOG DIALOGEX DISCARDABLE \
2135 EDITTEXT END EXSTYLE FONT GROUPBOX ICON LANGUAGE LISTBOX LTEXT \
2136 MENU MENUEX MENUITEM MESSAGETABLE POPUP \
2137 PUSHBUTTON RADIOBUTTON RCDATA RTEXT SCROLLBAR SEPARATOR SHIFT STATE3 \
2138 STRINGTABLE STYLE TEXTINCLUDE VALUE VERSION VERSIONINFO VIRTKEY")).GetBuffer()));
2141 if ((_tcscmp(line
, _T("idl"))==0)||
2142 (_tcscmp(line
, _T("odl"))==0))
2144 SendEditor(SCI_SETLEXER
, SCLEX_CPP
);
2145 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("aggregatable allocate appobject arrays async async_uuid \
2147 bindable boolean broadcast byte byte_count \
2148 call_as callback char coclass code comm_status \
2149 const context_handle context_handle_noserialize \
2150 context_handle_serialize control cpp_quote custom \
2151 decode default defaultbind defaultcollelem \
2152 defaultvalue defaultvtable dispinterface displaybind dllname \
2154 enable_allocate encode endpoint entry enum error_status_t \
2156 fault_status first_is float \
2157 handle_t heap helpcontext helpfile helpstring \
2158 helpstringcontext helpstringdll hidden hyper \
2159 id idempotent ignore iid_as iid_is immediatebind implicit_handle \
2160 import importlib in include in_line int __int64 __int3264 interface \
2161 last_is lcid length_is library licensed local long \
2162 max_is maybe message methods midl_pragma \
2163 midl_user_allocate midl_user_free min_is module ms_union \
2164 ncacn_at_dsp ncacn_dnet_nsp ncacn_http ncacn_ip_tcp \
2165 ncacn_nb_ipx ncacn_nb_nb ncacn_nb_tcp ncacn_np \
2166 ncacn_spx ncacn_vns_spp ncadg_ip_udp ncadg_ipx ncadg_mq \
2167 ncalrpc nocode nonbrowsable noncreatable nonextensible notify \
2168 object odl oleautomation optimize optional out out_of_line \
2169 pipe pointer_default pragma properties propget propput propputref \
2171 range readonly ref represent_as requestedit restricted retval \
2172 shape short signed size_is small source strict_context_handle \
2173 string struct switch switch_is switch_type \
2174 transmit_as typedef \
2175 uidefault union unique unsigned user_marshal usesgetlasterror uuid \
2176 v1_enum vararg version void wchar_t wire_marshal")).GetBuffer()));
2179 if (_tcscmp(line
, _T("java"))==0)
2181 SendEditor(SCI_SETLEXER
, SCLEX_CPP
);
2182 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("abstract assert boolean break byte case catch char class \
2183 const continue default do double else extends final finally float for future \
2184 generic goto if implements import inner instanceof int interface long \
2185 native new null outer package private protected public rest \
2186 return short static super switch synchronized this throw throws \
2187 transient try var void volatile while")).GetBuffer()));
2190 if (_tcscmp(line
, _T("js"))==0)
2192 SendEditor(SCI_SETLEXER
, SCLEX_CPP
);
2193 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("abstract boolean break byte case catch char class \
2194 const continue debugger default delete do double else enum export extends \
2195 final finally float for function goto if implements import in instanceof \
2196 int interface long native new package private protected public \
2197 return short static super switch synchronized this throw throws \
2198 transient try typeof var void volatile while with")).GetBuffer()));
2201 if ((_tcscmp(line
, _T("pas"))==0)||
2202 (_tcscmp(line
, _T("dpr"))==0)||
2203 (_tcscmp(line
, _T("pp"))==0))
2205 SendEditor(SCI_SETLEXER
, SCLEX_PASCAL
);
2206 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("and array as begin case class const constructor \
2207 destructor div do downto else end except file finally \
2208 for function goto if implementation in inherited \
2209 interface is mod not object of on or packed \
2210 procedure program property raise record repeat \
2211 set shl shr then threadvar to try type unit \
2212 until uses var while with xor")).GetBuffer()));
2215 if ((_tcscmp(line
, _T("as"))==0)||
2216 (_tcscmp(line
, _T("asc"))==0)||
2217 (_tcscmp(line
, _T("jsfl"))==0))
2219 SendEditor(SCI_SETLEXER
, SCLEX_CPP
);
2220 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("add and break case catch class continue default delete do \
2221 dynamic else eq extends false finally for function ge get gt if implements import in \
2222 instanceof interface intrinsic le lt ne new not null or private public return \
2223 set static super switch this throw true try typeof undefined var void while with")).GetBuffer()));
2224 SendEditor(SCI_SETKEYWORDS
, 1, (LPARAM
)(m_TextView
.StringForControl(_T("Array Arguments Accessibility Boolean Button Camera Color \
2225 ContextMenu ContextMenuItem Date Error Function Key LoadVars LocalConnection Math \
2226 Microphone Mouse MovieClip MovieClipLoader NetConnection NetStream Number Object \
2227 PrintJob Selection SharedObject Sound Stage String StyleSheet System TextField \
2228 TextFormat TextSnapshot Video Void XML XMLNode XMLSocket \
2229 _accProps _focusrect _global _highquality _parent _quality _root _soundbuftime \
2230 arguments asfunction call capabilities chr clearInterval duplicateMovieClip \
2231 escape eval fscommand getProperty getTimer getURL getVersion gotoAndPlay gotoAndStop \
2232 ifFrameLoaded Infinity -Infinity int isFinite isNaN length loadMovie loadMovieNum \
2233 loadVariables loadVariablesNum maxscroll mbchr mblength mbord mbsubstring MMExecute \
2234 NaN newline nextFrame nextScene on onClipEvent onUpdate ord parseFloat parseInt play \
2235 prevFrame prevScene print printAsBitmap printAsBitmapNum printNum random removeMovieClip \
2236 scroll set setInterval setProperty startDrag stop stopAllSounds stopDrag substring \
2237 targetPath tellTarget toggleHighQuality trace unescape unloadMovie unLoadMovieNum updateAfterEvent")).GetBuffer()));
2240 if ((_tcscmp(line
, _T("html"))==0)||
2241 (_tcscmp(line
, _T("htm"))==0)||
2242 (_tcscmp(line
, _T("shtml"))==0)||
2243 (_tcscmp(line
, _T("htt"))==0)||
2244 (_tcscmp(line
, _T("xml"))==0)||
2245 (_tcscmp(line
, _T("asp"))==0)||
2246 (_tcscmp(line
, _T("xsl"))==0)||
2247 (_tcscmp(line
, _T("php"))==0)||
2248 (_tcscmp(line
, _T("xhtml"))==0)||
2249 (_tcscmp(line
, _T("phtml"))==0)||
2250 (_tcscmp(line
, _T("cfm"))==0)||
2251 (_tcscmp(line
, _T("tpl"))==0)||
2252 (_tcscmp(line
, _T("dtd"))==0)||
2253 (_tcscmp(line
, _T("hta"))==0)||
2254 (_tcscmp(line
, _T("htd"))==0)||
2255 (_tcscmp(line
, _T("wxs"))==0))
2257 SendEditor(SCI_SETLEXER
, SCLEX_HTML
);
2258 SendEditor(SCI_SETSTYLEBITS
, 7);
2259 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("a abbr acronym address applet area b base basefont \
2260 bdo big blockquote body br button caption center \
2261 cite code col colgroup dd del dfn dir div dl dt em \
2262 fieldset font form frame frameset h1 h2 h3 h4 h5 h6 \
2263 head hr html i iframe img input ins isindex kbd label \
2264 legend li link map menu meta noframes noscript \
2265 object ol optgroup option p param pre q s samp \
2266 script select small span strike strong style sub sup \
2267 table tbody td textarea tfoot th thead title tr tt u ul \
2268 var xml xmlns abbr accept-charset accept accesskey action align alink \
2269 alt archive axis background bgcolor border \
2270 cellpadding cellspacing char charoff charset checked cite \
2271 class classid clear codebase codetype color cols colspan \
2272 compact content coords \
2273 data datafld dataformatas datapagesize datasrc datetime \
2274 declare defer dir disabled enctype event \
2275 face for frame frameborder \
2276 headers height href hreflang hspace http-equiv \
2277 id ismap label lang language leftmargin link longdesc \
2278 marginwidth marginheight maxlength media method multiple \
2279 name nohref noresize noshade nowrap \
2280 object onblur onchange onclick ondblclick onfocus \
2281 onkeydown onkeypress onkeyup onload onmousedown \
2282 onmousemove onmouseover onmouseout onmouseup \
2283 onreset onselect onsubmit onunload \
2284 profile prompt readonly rel rev rows rowspan rules \
2285 scheme scope selected shape size span src standby start style \
2286 summary tabindex target text title topmargin type usemap \
2287 valign value valuetype version vlink vspace width \
2288 text password checkbox radio submit reset \
2289 file hidden image")).GetBuffer()));
2290 SendEditor(SCI_SETKEYWORDS
, 1, (LPARAM
)(m_TextView
.StringForControl(_T("assign audio block break catch choice clear disconnect else elseif \
2291 emphasis enumerate error exit field filled form goto grammar help \
2292 if initial link log menu meta noinput nomatch object option p paragraph \
2293 param phoneme prompt property prosody record reprompt return s say-as \
2294 script sentence subdialog submit throw transfer value var voice vxml")).GetBuffer()));
2295 SendEditor(SCI_SETKEYWORDS
, 2, (LPARAM
)(m_TextView
.StringForControl(_T("accept age alphabet anchor application base beep bridge category charset \
2296 classid cond connecttimeout content contour count dest destexpr dtmf dtmfterm \
2297 duration enctype event eventexpr expr expritem fetchtimeout finalsilence \
2298 gender http-equiv id level maxage maxstale maxtime message messageexpr \
2299 method mime modal mode name namelist next nextitem ph pitch range rate \
2300 scope size sizeexpr skiplist slot src srcexpr sub time timeexpr timeout \
2301 transferaudio type value variant version volume xml:lang")).GetBuffer()));
2302 SendEditor(SCI_SETKEYWORDS
, 3, (LPARAM
)(m_TextView
.StringForControl(_T("and assert break class continue def del elif \
2303 else except exec finally for from global if import in is lambda None \
2304 not or pass print raise return try while yield")).GetBuffer()));
2305 SendEditor(SCI_SETKEYWORDS
, 4, (LPARAM
)(m_TextView
.StringForControl(_T("and argv as argc break case cfunction class continue declare default do \
2306 die echo else elseif empty enddeclare endfor endforeach endif endswitch \
2307 endwhile e_all e_parse e_error e_warning eval exit extends false for \
2308 foreach function global http_cookie_vars http_get_vars http_post_vars \
2309 http_post_files http_env_vars http_server_vars if include include_once \
2310 list new not null old_function or parent php_os php_self php_version \
2311 print require require_once return static switch stdclass this true var \
2312 xor virtual while __file__ __line__ __sleep __wakeup")).GetBuffer()));
2314 SetAStyle(SCE_H_TAG
, darkBlue
);
2315 SetAStyle(SCE_H_TAGUNKNOWN
, red
);
2316 SetAStyle(SCE_H_ATTRIBUTE
, darkBlue
);
2317 SetAStyle(SCE_H_ATTRIBUTEUNKNOWN
, red
);
2318 SetAStyle(SCE_H_NUMBER
, RGB(0x80,0,0x80));
2319 SetAStyle(SCE_H_DOUBLESTRING
, RGB(0,0x80,0));
2320 SetAStyle(SCE_H_SINGLESTRING
, RGB(0,0x80,0));
2321 SetAStyle(SCE_H_OTHER
, RGB(0x80,0,0x80));
2322 SetAStyle(SCE_H_COMMENT
, RGB(0x80,0x80,0));
2323 SetAStyle(SCE_H_ENTITY
, RGB(0x80,0,0x80));
2325 SetAStyle(SCE_H_TAGEND
, darkBlue
);
2326 SetAStyle(SCE_H_XMLSTART
, darkBlue
); // <?
2327 SetAStyle(SCE_H_QUESTION
, darkBlue
); // <?
2328 SetAStyle(SCE_H_XMLEND
, darkBlue
); // ?>
2329 SetAStyle(SCE_H_SCRIPT
, darkBlue
); // <script
2330 SetAStyle(SCE_H_ASP
, RGB(0x4F, 0x4F, 0), RGB(0xFF, 0xFF, 0)); // <% ... %>
2331 SetAStyle(SCE_H_ASPAT
, RGB(0x4F, 0x4F, 0), RGB(0xFF, 0xFF, 0)); // <%@ ... %>
2333 SetAStyle(SCE_HB_DEFAULT
, black
);
2334 SetAStyle(SCE_HB_COMMENTLINE
, darkGreen
);
2335 SetAStyle(SCE_HB_NUMBER
, RGB(0,0x80,0x80));
2336 SetAStyle(SCE_HB_WORD
, darkBlue
);
2337 SendEditor(SCI_STYLESETBOLD
, SCE_HB_WORD
, 1);
2338 SetAStyle(SCE_HB_STRING
, RGB(0x80,0,0x80));
2339 SetAStyle(SCE_HB_IDENTIFIER
, black
);
2341 // This light blue is found in the windows system palette so is safe to use even in 256 colour modes.
2342 // Show the whole section of VBScript with light blue background
2343 for (int bstyle
=SCE_HB_DEFAULT
; bstyle
<=SCE_HB_STRINGEOL
; bstyle
++) {
2344 SendEditor(SCI_STYLESETFONT
, bstyle
,
2345 reinterpret_cast<LPARAM
>(m_TextView
.StringForControl(_T("Lucida Console")).GetBuffer()));
2346 SendEditor(SCI_STYLESETBACK
, bstyle
, lightBlue
);
2347 // This call extends the backround colour of the last style on the line to the edge of the window
2348 SendEditor(SCI_STYLESETEOLFILLED
, bstyle
, 1);
2350 SendEditor(SCI_STYLESETBACK
, SCE_HB_STRINGEOL
, RGB(0x7F,0x7F,0xFF));
2351 SendEditor(SCI_STYLESETFONT
, SCE_HB_COMMENTLINE
,
2352 reinterpret_cast<LPARAM
>(m_TextView
.StringForControl(_T("Lucida Console")).GetBuffer()));
2354 SetAStyle(SCE_HBA_DEFAULT
, black
);
2355 SetAStyle(SCE_HBA_COMMENTLINE
, darkGreen
);
2356 SetAStyle(SCE_HBA_NUMBER
, RGB(0,0x80,0x80));
2357 SetAStyle(SCE_HBA_WORD
, darkBlue
);
2358 SendEditor(SCI_STYLESETBOLD
, SCE_HBA_WORD
, 1);
2359 SetAStyle(SCE_HBA_STRING
, RGB(0x80,0,0x80));
2360 SetAStyle(SCE_HBA_IDENTIFIER
, black
);
2362 // Show the whole section of ASP VBScript with bright yellow background
2363 for (int bastyle
=SCE_HBA_DEFAULT
; bastyle
<=SCE_HBA_STRINGEOL
; bastyle
++) {
2364 SendEditor(SCI_STYLESETFONT
, bastyle
,
2365 reinterpret_cast<LPARAM
>(m_TextView
.StringForControl(_T("Lucida Console")).GetBuffer()));
2366 SendEditor(SCI_STYLESETBACK
, bastyle
, RGB(0xFF, 0xFF, 0));
2367 // This call extends the backround colour of the last style on the line to the edge of the window
2368 SendEditor(SCI_STYLESETEOLFILLED
, bastyle
, 1);
2370 SendEditor(SCI_STYLESETBACK
, SCE_HBA_STRINGEOL
, RGB(0xCF,0xCF,0x7F));
2371 SendEditor(SCI_STYLESETFONT
, SCE_HBA_COMMENTLINE
,
2372 reinterpret_cast<LPARAM
>(m_TextView
.StringForControl(_T("Lucida Console")).GetBuffer()));
2374 // If there is no need to support embedded Javascript, the following code can be dropped.
2375 // Javascript will still be correctly processed but will be displayed in just the default style.
2377 SetAStyle(SCE_HJ_START
, RGB(0x80,0x80,0));
2378 SetAStyle(SCE_HJ_DEFAULT
, black
);
2379 SetAStyle(SCE_HJ_COMMENT
, darkGreen
);
2380 SetAStyle(SCE_HJ_COMMENTLINE
, darkGreen
);
2381 SetAStyle(SCE_HJ_COMMENTDOC
, darkGreen
);
2382 SetAStyle(SCE_HJ_NUMBER
, RGB(0,0x80,0x80));
2383 SetAStyle(SCE_HJ_WORD
, black
);
2384 SetAStyle(SCE_HJ_KEYWORD
, darkBlue
);
2385 SetAStyle(SCE_HJ_DOUBLESTRING
, RGB(0x80,0,0x80));
2386 SetAStyle(SCE_HJ_SINGLESTRING
, RGB(0x80,0,0x80));
2387 SetAStyle(SCE_HJ_SYMBOLS
, black
);
2389 SetAStyle(SCE_HJA_START
, RGB(0x80,0x80,0));
2390 SetAStyle(SCE_HJA_DEFAULT
, black
);
2391 SetAStyle(SCE_HJA_COMMENT
, darkGreen
);
2392 SetAStyle(SCE_HJA_COMMENTLINE
, darkGreen
);
2393 SetAStyle(SCE_HJA_COMMENTDOC
, darkGreen
);
2394 SetAStyle(SCE_HJA_NUMBER
, RGB(0,0x80,0x80));
2395 SetAStyle(SCE_HJA_WORD
, black
);
2396 SetAStyle(SCE_HJA_KEYWORD
, darkBlue
);
2397 SetAStyle(SCE_HJA_DOUBLESTRING
, RGB(0x80,0,0x80));
2398 SetAStyle(SCE_HJA_SINGLESTRING
, RGB(0x80,0,0x80));
2399 SetAStyle(SCE_HJA_SYMBOLS
, black
);
2401 SetAStyle(SCE_HPHP_DEFAULT
, black
);
2402 SetAStyle(SCE_HPHP_HSTRING
, RGB(0x80,0,0x80));
2403 SetAStyle(SCE_HPHP_SIMPLESTRING
, RGB(0x80,0,0x80));
2404 SetAStyle(SCE_HPHP_WORD
, darkBlue
);
2405 SetAStyle(SCE_HPHP_NUMBER
, RGB(0,0x80,0x80));
2406 SetAStyle(SCE_HPHP_VARIABLE
, red
);
2407 SetAStyle(SCE_HPHP_HSTRING_VARIABLE
, red
);
2408 SetAStyle(SCE_HPHP_COMPLEX_VARIABLE
, red
);
2409 SetAStyle(SCE_HPHP_COMMENT
, darkGreen
);
2410 SetAStyle(SCE_HPHP_COMMENTLINE
, darkGreen
);
2411 SetAStyle(SCE_HPHP_OPERATOR
, darkBlue
);
2413 // Show the whole section of Javascript with off white background
2414 for (int jstyle
=SCE_HJ_DEFAULT
; jstyle
<=SCE_HJ_SYMBOLS
; jstyle
++) {
2415 SendEditor(SCI_STYLESETFONT
, jstyle
,
2416 reinterpret_cast<LPARAM
>(m_TextView
.StringForControl(_T("Lucida Console")).GetBuffer()));
2417 SendEditor(SCI_STYLESETBACK
, jstyle
, offWhite
);
2418 SendEditor(SCI_STYLESETEOLFILLED
, jstyle
, 1);
2420 SendEditor(SCI_STYLESETBACK
, SCE_HJ_STRINGEOL
, RGB(0xDF, 0xDF, 0x7F));
2421 SendEditor(SCI_STYLESETEOLFILLED
, SCE_HJ_STRINGEOL
, 1);
2423 // Show the whole section of Javascript with brown background
2424 for (int jastyle
=SCE_HJA_DEFAULT
; jastyle
<=SCE_HJA_SYMBOLS
; jastyle
++) {
2425 SendEditor(SCI_STYLESETFONT
, jastyle
,
2426 reinterpret_cast<LPARAM
>(m_TextView
.StringForControl(_T("Lucida Console")).GetBuffer()));
2427 SendEditor(SCI_STYLESETBACK
, jastyle
, RGB(0xDF, 0xDF, 0x7F));
2428 SendEditor(SCI_STYLESETEOLFILLED
, jastyle
, 1);
2430 SendEditor(SCI_STYLESETBACK
, SCE_HJA_STRINGEOL
, RGB(0x0,0xAF,0x5F));
2431 SendEditor(SCI_STYLESETEOLFILLED
, SCE_HJA_STRINGEOL
, 1);
2436 SendEditor(SCI_SETLEXER
, SCLEX_CPP
);
2439 SendEditor(SCI_COLOURISE
, 0, -1);
2443 void CTortoiseGitBlameView::SetupCppLexer()
2445 SetAStyle(SCE_C_DEFAULT
, RGB(0, 0, 0));
2446 SetAStyle(SCE_C_COMMENT
, RGB(0, 0x80, 0));
2447 SetAStyle(SCE_C_COMMENTLINE
, RGB(0, 0x80, 0));
2448 SetAStyle(SCE_C_COMMENTDOC
, RGB(0, 0x80, 0));
2449 SetAStyle(SCE_C_COMMENTLINEDOC
, RGB(0, 0x80, 0));
2450 SetAStyle(SCE_C_COMMENTDOCKEYWORD
, RGB(0, 0x80, 0));
2451 SetAStyle(SCE_C_COMMENTDOCKEYWORDERROR
, RGB(0, 0x80, 0));
2452 SetAStyle(SCE_C_NUMBER
, RGB(0, 0x80, 0x80));
2453 SetAStyle(SCE_C_WORD
, RGB(0, 0, 0x80));
2454 SendEditor(SCE_C_WORD
, 1);
2455 SetAStyle(SCE_C_STRING
, RGB(0x80, 0, 0x80));
2456 SetAStyle(SCE_C_IDENTIFIER
, RGB(0, 0, 0));
2457 SetAStyle(SCE_C_PREPROCESSOR
, RGB(0x80, 0, 0));
2458 SetAStyle(SCE_C_OPERATOR
, RGB(0x80, 0x80, 0));
2461 int CTortoiseGitBlameView::GetEncode(unsigned char *buff
, int size
, int *bomoffset
)
2463 CFileTextLines textlines
;
2464 CFileTextLines::UnicodeType type
= textlines
.CheckUnicodeType(buff
, size
);
2466 if(type
== CFileTextLines::UTF8BOM
)
2471 if(type
== CFileTextLines::UTF8
)
2474 if(type
== CFileTextLines::UNICODE_LE
)
2483 void CTortoiseGitBlameView::UpdateInfo(int Encode
)
2485 BYTE_VECTOR
&data
= GetDocument()->m_BlameData
;
2491 CLogDataVector
* pRevs
= GetLogData();
2493 this->m_CommitHash
.clear();
2494 this->m_Authors
.clear();
2500 SendEditor(SCI_SETREADONLY
, FALSE
);
2501 SendEditor(SCI_CLEARALL
);
2502 SendEditor(EM_EMPTYUNDOBUFFER
);
2503 SendEditor(SCI_SETSAVEPOINT
);
2504 SendEditor(SCI_CANCEL
);
2505 SendEditor(SCI_SETUNDOCOLLECTION
, 0);
2507 SendEditor(SCI_SETCODEPAGE
, SC_CP_UTF8
);
2510 int encoding
= Encode
;
2511 while( pos
>=0 && current
>=0 && pos
<data
.size() )
2513 current
= data
.findData((const BYTE
*)"\n",1,pos
);
2514 //one=data.Tokenize(_T("\n"),pos);
2516 bool isbound
= ( data
[pos
] == _T('^') );
2518 if( (data
.size() - pos
) >1 && data
[pos
] == _T('^'))
2529 if(git_get_sha1((const char*)&data
[pos
], hash
.m_hash
))
2531 ::MessageBox(NULL
, _T("Can't get hash"), _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
2536 hash
.ConvertFromStrA((char*)&data
[pos
]);
2540 start
=data
.findData((const BYTE
*)")",1,pos
+ 40);
2553 if( pos
<40 && encoding
==0)
2556 encoding
= GetEncode( &data
[start
+2], data
.size() - start
-2, &bomoffset
);
2559 if(encoding
== 1200)
2562 int size
= ((current
- start
-2 - bomoffset
)/2);
2563 TCHAR
*buffer
= strw
.GetBuffer(size
);
2564 memcpy(buffer
, &data
[start
+ 2 + bomoffset
],sizeof(TCHAR
)*size
);
2565 strw
.ReleaseBuffer();
2567 stra
= CUnicodeUtils::GetUTF8(strw
);
2570 else if(encoding
== CP_UTF8
)
2572 stra
= &data
[start
+ 2 + bomoffset
];
2577 strw
= CUnicodeUtils::GetUnicode(CStringA(&data
[start
+ 2 + bomoffset
]), encoding
);
2578 stra
= CUnicodeUtils::GetUTF8(strw
);
2582 SendEditor(SCI_REPLACESEL
, 0, (LPARAM
)(LPCSTR
)stra
);
2583 SendEditor(SCI_REPLACESEL
, 0, (LPARAM
)(LPCSTR
)"\n\0\0\0");
2586 data
[current
] = '\n';
2590 if(this->m_NoListCommit
.find(hash
) == m_NoListCommit
.end() )
2592 this->m_NoListCommit
[hash
].GetCommitFromHash(hash
);
2594 m_ID
.push_back(-1); // m_ID is calculated lazy on demand
2595 m_Authors
.push_back(m_NoListCommit
[hash
].GetAuthorName());
2597 m_CommitHash
.push_back(hash
);
2609 file
.Open(this->GetDocument()->m_TempFileName
,CFile::modeRead
);
2611 m_Buffer
= new char[file
.GetLength()+4];
2612 m_Buffer
[file
.GetLength()] =0;
2613 m_Buffer
[file
.GetLength()+1] =0;
2614 m_Buffer
[file
.GetLength()+2] =0;
2615 m_Buffer
[file
.GetLength()+3] =0;
2617 file
.Read(m_Buffer
, file
.GetLength());
2620 int encoding
= GetEncode( (unsigned char *)m_Buffer
, file
.GetLength(), &bomoffset
);
2623 //SendEditor(SCI_SETCODEPAGE, encoding);
2625 //SendEditor(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)(m_Buffer + bomoffset));
2627 SetupLexer(GetDocument()->m_CurrentFileName
);
2629 SendEditor(SCI_SETUNDOCOLLECTION
, 1);
2630 SendEditor(EM_EMPTYUNDOBUFFER
);
2631 SendEditor(SCI_SETSAVEPOINT
);
2632 SendEditor(SCI_GOTOPOS
, 0);
2633 SendEditor(SCI_SETSCROLLWIDTHTRACKING
, TRUE
);
2634 SendEditor(SCI_SETREADONLY
, TRUE
);
2637 m_highestrev
=this->GetLogData()->size()+m_NoListCommit
.size();
2641 this->GetClientRect(rect
);
2642 //this->m_TextView.GetWindowRect(rect);
2643 //this->m_TextView.ScreenToClient(rect);
2644 rect
.left
=this->m_blamewidth
;
2645 this->m_TextView
.MoveWindow(rect
);
2650 CGitBlameLogList
* CTortoiseGitBlameView::GetLogList()
2652 return &(GetDocument()->GetMainFrame()->m_wndOutput
.m_LogList
);
2656 CLogDataVector
* CTortoiseGitBlameView::GetLogData()
2658 return &(GetDocument()->GetMainFrame()->m_wndOutput
.m_LogList
.m_logEntries
);
2661 void CTortoiseGitBlameView::OnSciPainted(NMHDR
*,LRESULT
*)
2666 void CTortoiseGitBlameView::OnLButtonDown(UINT nFlags
,CPoint point
)
2669 LONG_PTR line
= SendEditor(SCI_GETFIRSTVISIBLELINE
);
2670 LONG_PTR height
= SendEditor(SCI_TEXTHEIGHT
);
2671 line
= line
+ (point
.y
/height
);
2673 if (line
< (LONG
)m_CommitHash
.size())
2675 SetSelectedLine(line
);
2676 if (m_CommitHash
[line
] != m_SelectedHash
)
2678 m_SelectedHash
= m_CommitHash
[line
];
2680 // lazy calculate m_ID
2681 if (m_ID
[line
] == -1)
2683 m_ID
[line
] = -2; // don't do this lazy calculation again and again for unfindable hashes
2684 for(int i
= 0; i
<this->GetLogData()->size(); i
++)
2686 if(m_SelectedHash
== this->GetLogData()->at(i
))
2688 m_ID
[line
] = this->GetLogData()->size()-i
;
2696 this->GetLogList()->SetItemState(this->GetLogList()->GetItemCount()-m_ID
[line
],
2702 this->GetDocument()->GetMainFrame()->m_wndProperties
.UpdateProperties(&m_NoListCommit
[m_CommitHash
[line
]]);
2707 m_SelectedHash
.Empty();
2709 //::InvalidateRect( NULL, FALSE);
2711 this->m_TextView
.Invalidate();
2716 SetSelectedLine(-1);
2719 CView::OnLButtonDown(nFlags
,point
);
2722 void CTortoiseGitBlameView::OnSciGetBkColor(NMHDR
* hdr
, LRESULT
* result
)
2725 SCNotification
*notification
=reinterpret_cast<SCNotification
*>(hdr
);
2727 if ((m_colorage
)&&(notification
->line
< (int)m_CommitHash
.size()))
2729 if(m_CommitHash
[notification
->line
] == this->m_SelectedHash
)
2730 notification
->lParam
= m_selectedauthorcolor
;
2732 notification
->lParam
= InterColor(DWORD(m_regOldLinesColor
), DWORD(m_regNewLinesColor
), (m_ID
[notification
->line
]-m_lowestrev
)*100/((m_highestrev
-m_lowestrev
)+1));
2737 void CTortoiseGitBlameView::FocusOn(GitRev
*pRev
)
2739 this->GetDocument()->GetMainFrame()->m_wndProperties
.UpdateProperties(pRev
);
2743 if (m_SelectedHash
!= pRev
->m_CommitHash
) {
2744 m_SelectedHash
= pRev
->m_CommitHash
;
2746 for(i
=0;i
<m_CommitHash
.size();i
++)
2748 if( pRev
->m_CommitHash
== m_CommitHash
[i
] )
2752 this->m_TextView
.Invalidate();
2756 void CTortoiseGitBlameView::OnMouseHover(UINT nFlags
, CPoint point
)
2759 LONG_PTR line
= SendEditor(SCI_GETFIRSTVISIBLELINE
);
2760 LONG_PTR height
= SendEditor(SCI_TEXTHEIGHT
);
2761 line
= line
+ (point
.y
/height
);
2763 if (line
< (LONG
)m_CommitHash
.size())
2765 if (line
!= m_MouseLine
)
2767 m_MouseLine
= line
;//m_CommitHash[line];
2771 pRev
=&this->m_NoListCommit
[m_CommitHash
[line
]];
2776 pRev
=&this->GetLogData()->GetGitRevAt(this->GetLogList()->GetItemCount()-m_ID
[line
]);
2779 this->ClientToScreen(&point
);
2782 str
.Format(_T("%s\n<b>%s</b>\n%s %s\n%s"),pRev
->m_CommitHash
.ToString(),
2784 pRev
->GetAuthorName(),
2785 CAppUtils::FormatDateAndTime( pRev
->GetAuthorDate(), m_DateFormat
),
2787 m_ToolTip
.AddTool(this,str
);
2788 m_ToolTip
.DisplayToolTip(&point
);
2791 this->ScreenToClient(&point
);
2792 rect
.left
=LOCATOR_WIDTH
;
2793 rect
.right
=this->m_blamewidth
+rect
.left
;
2794 rect
.top
=point
.y
-height
;
2795 rect
.bottom
=point
.y
+height
;
2796 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 int CTortoiseGitBlameView::FindNextLine(CGitHash CommitHash
,bool bUpOrDown
)
2899 LONG_PTR line
= SendEditor(SCI_GETFIRSTVISIBLELINE
);
2900 LONG_PTR startline
=line
;
2901 bool findNoMatch
=false;
2902 while(line
>=0 && line
<m_CommitHash
.size())
2904 if(m_CommitHash
[line
]!=CommitHash
)
2909 if(m_CommitHash
[line
] == CommitHash
&& findNoMatch
)
2911 if( line
== startline
+2 )
2919 line
=FindFirstLine(CommitHash
,line
);
2921 SendEditor(SCI_LINESCROLL
,0,line
-startline
-2);