1 // TortoiseGitBlame - a Viewer for Git Blames
3 // Copyright (C) 2003-2008 - TortoiseSVN
5 // Copyright (C)2003 Don HO <donho@altern.org>
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software Foundation,
19 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 // CTortoiseGitBlameView.cpp : implementation of the CTortoiseGitBlameView class
25 #include "TortoiseGitBlame.h"
27 #include "TortoiseGitBlameDoc.h"
28 #include "TortoiseGitBlameView.h"
31 #include "EditGotoDlg.h"
32 #include "TortoiseGitBlameAppUtils.h"
33 #include "FileTextLines.h"
34 #include "UniCodeUtils.h"
35 #include "MenuEncode.h"
42 UINT
CTortoiseGitBlameView::m_FindDialogMessage
;
44 // CTortoiseGitBlameView
45 IMPLEMENT_DYNAMIC(CSciEditBlame
,CSciEdit
)
47 IMPLEMENT_DYNCREATE(CTortoiseGitBlameView
, CView
)
49 BEGIN_MESSAGE_MAP(CTortoiseGitBlameView
, CView
)
50 // Standard printing commands
51 ON_COMMAND(ID_FILE_PRINT
, &CView::OnFilePrint
)
52 ON_COMMAND(ID_FILE_PRINT_DIRECT
, &CView::OnFilePrint
)
53 ON_COMMAND(ID_FILE_PRINT_PREVIEW
, &CTortoiseGitBlameView::OnFilePrintPreview
)
54 ON_COMMAND(ID_EDIT_FIND
,OnEditFind
)
55 ON_COMMAND(ID_EDIT_GOTO
,OnEditGoto
)
56 ON_COMMAND(ID_EDIT_COPY
,CopySelectedLogToClipboard
)
57 ON_COMMAND(ID_VIEW_NEXT
,OnViewNext
)
58 ON_COMMAND(ID_VIEW_PREV
,OnViewPrev
)
59 ON_COMMAND_RANGE(IDM_FORMAT_ENCODE
, IDM_FORMAT_ENCODE_END
, OnChangeEncode
)
67 ON_NOTIFY(SCN_PAINTED
,0,OnSciPainted
)
68 ON_NOTIFY(SCN_GETBKCOLOR
,0,OnSciGetBkColor
)
69 ON_REGISTERED_MESSAGE(m_FindDialogMessage
, OnFindDialogMessage
)
73 // CTortoiseGitBlameView construction/destruction
75 CTortoiseGitBlameView::CTortoiseGitBlameView()
77 // TODO: add construction code here
94 m_windowcolor
= ::GetSysColor(COLOR_WINDOW
);
95 m_textcolor
= ::GetSysColor(COLOR_WINDOWTEXT
);
96 m_texthighlightcolor
= ::GetSysColor(COLOR_HIGHLIGHTTEXT
);
97 m_mouserevcolor
= InterColor(m_windowcolor
, m_textcolor
, 20);
98 m_mouseauthorcolor
= InterColor(m_windowcolor
, m_textcolor
, 10);
99 m_selectedrevcolor
= ::GetSysColor(COLOR_HIGHLIGHT
);
100 m_selectedauthorcolor
= InterColor(m_selectedrevcolor
, m_texthighlightcolor
, 35);
104 m_selectedorigrev
= -1;
107 m_directFunction
= 0;
109 m_lowestrev
= LONG_MAX
;
118 m_FindDialogMessage
= ::RegisterWindowMessage(FINDMSGSTRING
);
119 m_pFindDialog
= NULL
;
120 // get short/long datetime setting from registry
121 DWORD RegUseShortDateFormat
= CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE
);
122 if ( RegUseShortDateFormat
)
124 m_DateFormat
= DATE_SHORTDATE
;
128 m_DateFormat
= DATE_LONGDATE
;
134 CTortoiseGitBlameView::~CTortoiseGitBlameView()
137 DeleteObject(m_font
);
139 DeleteObject(m_italicfont
);
153 void CTortoiseGitBlameView::OnChangeEncode(UINT nId
)
156 static EncodingUnit encodings
[] = {
157 {1250, "windows-1250"}, //IDM_FORMAT_WIN_1250
158 {1251, "windows-1251"}, //IDM_FORMAT_WIN_1251
159 {1252, "windows-1252"}, //IDM_FORMAT_WIN_1252
160 {1253, "windows-1253"}, //IDM_FORMAT_WIN_1253
161 {1254, "windows-1254"}, //IDM_FORMAT_WIN_1254
162 {1255, "windows-1255"}, //IDM_FORMAT_WIN_1255
163 {1256, "windows-1256"}, //IDM_FORMAT_WIN_1256
164 {1257, "windows-1257"}, //IDM_FORMAT_WIN_1257
165 {1258, "windows-1258"}, //IDM_FORMAT_WIN_1258
166 {28591, "latin1 ISO_8859-1 ISO-8859-1 CP819 IBM819 csISOLatin1 iso-ir-100 l1"}, //IDM_FORMAT_ISO_8859_1
167 {28592, "latin2 ISO_8859-2 ISO-8859-2 csISOLatin2 iso-ir-101 l2"}, //IDM_FORMAT_ISO_8859_2
168 {28593, "latin3 ISO_8859-3 ISO-8859-3 csISOLatin3 iso-ir-109 l3"}, //IDM_FORMAT_ISO_8859_3
169 {28594, "latin4 ISO_8859-4 ISO-8859-4 csISOLatin4 iso-ir-110 l4"}, //IDM_FORMAT_ISO_8859_4
170 {28595, "cyrillic ISO_8859-5 ISO-8859-5 csISOLatinCyrillic iso-ir-144"}, //IDM_FORMAT_ISO_8859_5
171 {28596, "arabic ISO_8859-6 ISO-8859-6 csISOLatinArabic iso-ir-127 ASMO-708 ECMA-114"}, //IDM_FORMAT_ISO_8859_6
172 {28597, "greek ISO_8859-7 ISO-8859-7 csISOLatinGreek greek8 iso-ir-126 ELOT_928 ECMA-118"}, //IDM_FORMAT_ISO_8859_7
173 {28598, "hebrew ISO_8859-8 ISO-8859-8 csISOLatinHebrew iso-ir-138"}, //IDM_FORMAT_ISO_8859_8
174 {28599, "latin5 ISO_8859-9 ISO-8859-9 csISOLatin5 iso-ir-148 l5"}, //IDM_FORMAT_ISO_8859_9
175 {28600, "latin6 ISO_8859-10 ISO-8859-10 csISOLatin6 iso-ir-157 l6"}, //IDM_FORMAT_ISO_8859_10
176 {28601, "ISO_8859-11 ISO-8859-11"}, //IDM_FORMAT_ISO_8859_11
177 {28603, "ISO_8859-13 ISO-8859-13"}, //IDM_FORMAT_ISO_8859_13
178 {28604, "iso-celtic latin8 ISO_8859-14 ISO-8859-14 18 iso-ir-199"}, //IDM_FORMAT_ISO_8859_14
179 {28605, "Latin-9 ISO_8859-15 ISO-8859-15"}, //IDM_FORMAT_ISO_8859_15
180 {28606, "latin10 ISO_8859-16 ISO-8859-16 110 iso-ir-226"}, //IDM_FORMAT_ISO_8859_16
181 {437, "IBM437 cp437 437 csPC8CodePage437"}, //IDM_FORMAT_DOS_437
182 {720, "IBM720 cp720 oem720 720"}, //IDM_FORMAT_DOS_720
183 {737, "IBM737 cp737 oem737 737"}, //IDM_FORMAT_DOS_737
184 {775, "IBM775 cp775 oem775 775"}, //IDM_FORMAT_DOS_775
185 {850, "IBM850 cp850 oem850 850"}, //IDM_FORMAT_DOS_850
186 {852, "IBM852 cp852 oem852 852"}, //IDM_FORMAT_DOS_852
187 {855, "IBM855 cp855 oem855 855 csIBM855"}, //IDM_FORMAT_DOS_855
188 {857, "IBM857 cp857 oem857 857"}, //IDM_FORMAT_DOS_857
189 {858, "IBM858 cp858 oem858 858"}, //IDM_FORMAT_DOS_858
190 {860, "IBM860 cp860 oem860 860"}, //IDM_FORMAT_DOS_860
191 {861, "IBM861 cp861 oem861 861"}, //IDM_FORMAT_DOS_861
192 {862, "IBM862 cp862 oem862 862"}, //IDM_FORMAT_DOS_862
193 {863, "IBM863 cp863 oem863 863"}, //IDM_FORMAT_DOS_863
194 {865, "IBM865 cp865 oem865 865"}, //IDM_FORMAT_DOS_865
195 {866, "IBM866 cp866 oem866 866"}, //IDM_FORMAT_DOS_866
196 {869, "IBM869 cp869 oem869 869"}, //IDM_FORMAT_DOS_869
197 {950, "big5 csBig5"}, //IDM_FORMAT_BIG5
198 {936, "gb2312 gbk csGB2312"}, //IDM_FORMAT_GB2312
199 {932, "Shift_JIS MS_Kanji csShiftJIS csWindows31J"}, //IDM_FORMAT_SHIFT_JIS
200 {949, "windows-949 korean"}, //IDM_FORMAT_KOREAN_WIN
201 {51949, "euc-kr csEUCKR"}, //IDM_FORMAT_EUC_KR
202 {874, "tis-620"}, //IDM_FORMAT_TIS_620
203 {10007, "x-mac-cyrillic xmaccyrillic"}, //IDM_FORMAT_MAC_CYRILLIC
204 {21866, "koi8_u"}, //IDM_FORMAT_KOI8U_CYRILLIC
205 {20866, "koi8_r csKOI8R"} //IDM_FORMAT_KOI8R_CYRILLIC
208 if(nId
>= IDM_FORMAT_ENCODE
&& nId
<= IDM_FORMAT_ENCODE_END
)
209 this->UpdateInfo(encodings
[nId
- IDM_FORMAT_ENCODE
].id
);
211 int CTortoiseGitBlameView::OnCreate(LPCREATESTRUCT lpcs
)
215 this->GetWindowRect(&rect1
);
216 rect
.left
=m_blamewidth
+LOCATOR_WIDTH
;
217 rect
.right
=rect
.Width();
219 rect
.bottom
=rect
.Height();
220 BOOL b
=m_TextView
.Create(_T("Scintilla"),_T("source"),0,rect
,this,0,0);
221 m_TextView
.Init(0,FALSE
);
222 m_TextView
.ShowWindow( SW_SHOW
);
223 //m_TextView.InsertText(_T("Abdadfasdf"));
224 m_wEditor
= m_TextView
.m_hWnd
;
227 m_ToolTip
.Create(this->GetParent());
228 m_ToolTip
.AddTool(this,_T("Test"));
230 ::AfxGetApp()->GetMainWnd();
231 return CView::OnCreate(lpcs
);
235 void CTortoiseGitBlameView::OnSize(UINT nType
,int cx
, int cy
)
239 rect
.left
=m_blamewidth
;
244 m_TextView
.MoveWindow(&rect
);
247 BOOL
CTortoiseGitBlameView::PreCreateWindow(CREATESTRUCT
& cs
)
249 // TODO: Modify the Window class or styles here by modifying
250 // the CREATESTRUCT cs
252 return CView::PreCreateWindow(cs
);
255 // CTortoiseGitBlameView drawing
257 void CTortoiseGitBlameView::OnDraw(CDC
* /*pDC*/)
259 CTortoiseGitBlameDoc
* pDoc
= GetDocument();
264 DrawBlame(this->GetDC()->m_hDC
);
265 DrawLocatorBar(this->GetDC()->m_hDC
);
266 // TODO: add draw code for native data here
270 // CTortoiseGitBlameView printing
273 void CTortoiseGitBlameView::OnFilePrintPreview()
275 AFXPrintPreview(this);
278 BOOL
CTortoiseGitBlameView::OnPreparePrinting(CPrintInfo
* pInfo
)
280 // default preparation
281 return DoPreparePrinting(pInfo
);
284 void CTortoiseGitBlameView::OnBeginPrinting(CDC
* /*pDC*/, CPrintInfo
* /*pInfo*/)
286 // TODO: add extra initialization before printing
289 void CTortoiseGitBlameView::OnEndPrinting(CDC
* /*pDC*/, CPrintInfo
* /*pInfo*/)
291 // TODO: add cleanup after printing
294 void CTortoiseGitBlameView::OnRButtonUp(UINT nFlags
, CPoint point
)
296 ClientToScreen(&point
);
297 OnContextMenu(this, point
);
300 void CTortoiseGitBlameView::OnContextMenu(CWnd
* pWnd
, CPoint point
)
302 theApp
.GetContextMenuManager()->ShowPopupMenu(IDR_POPUP_EDIT
, point
.x
, point
.y
, this, TRUE
);
306 // CTortoiseGitBlameView diagnostics
309 void CTortoiseGitBlameView::AssertValid() const
311 CView::AssertValid();
314 void CTortoiseGitBlameView::Dump(CDumpContext
& dc
) const
319 CTortoiseGitBlameDoc
* CTortoiseGitBlameView::GetDocument() const // non-debug version is inline
321 ASSERT(m_pDocument
->IsKindOf(RUNTIME_CLASS(CTortoiseGitBlameDoc
)));
322 return (CTortoiseGitBlameDoc
*)m_pDocument
;
327 // CTortoiseGitBlameView message handlers
328 CString
CTortoiseGitBlameView::GetAppDirectory()
332 DWORD bufferlen
= MAX_PATH
; // MAX_PATH is not the limit here!
335 bufferlen
+= MAX_PATH
; // MAX_PATH is not the limit here!
336 TCHAR
* pBuf
= new TCHAR
[bufferlen
];
337 len
= GetModuleFileName(NULL
, pBuf
, bufferlen
);
338 path
= CString(pBuf
, len
);
340 } while(len
== bufferlen
);
342 path
= path
.Left(path
.ReverseFind(_T('\\')));
343 //path = path.substr(0, path.rfind('\\') + 1);
348 // Return a color which is interpolated between c1 and c2.
349 // Slider controls the relative proportions as a percentage:
350 // Slider = 0 represents pure c1
351 // Slider = 50 represents equal mixture
352 // Slider = 100 represents pure c2
353 COLORREF
CTortoiseGitBlameView::InterColor(COLORREF c1
, COLORREF c2
, int Slider
)
357 // Limit Slider to 0..100% range
363 // The color components have to be treated individually.
364 r
= (GetRValue(c2
) * Slider
+ GetRValue(c1
) * (100 - Slider
)) / 100;
365 g
= (GetGValue(c2
) * Slider
+ GetGValue(c1
) * (100 - Slider
)) / 100;
366 b
= (GetBValue(c2
) * Slider
+ GetBValue(c1
) * (100 - Slider
)) / 100;
371 LRESULT
CTortoiseGitBlameView::SendEditor(UINT Msg
, WPARAM wParam
, LPARAM lParam
)
373 if (m_directFunction
)
375 return ((SciFnDirect
) m_directFunction
)(m_directPointer
, Msg
, wParam
, lParam
);
377 return ::SendMessage(m_wEditor
, Msg
, wParam
, lParam
);
380 void CTortoiseGitBlameView::GetRange(int start
, int end
, char *text
)
384 tr
.chrg
.cpMin
= start
;
388 SendMessage(m_wEditor
, EM_GETTEXTRANGE
, 0, reinterpret_cast<LPARAM
>(&tr
));
392 void CTortoiseGitBlameView::SetTitle()
395 char title
[MAX_PATH
+ 100];
396 strcpy_s(title
, MAX_PATH
+ 100, szTitle
);
397 strcat_s(title
, MAX_PATH
+ 100, " - ");
398 strcat_s(title
, MAX_PATH
+ 100, szViewtitle
);
399 ::SetWindowText(wMain
, title
);
403 BOOL
CTortoiseGitBlameView::OpenLogFile(const char *fileName
)
406 char logmsgbuf
[10000+1];
408 fopen_s(&File
, fileName
, "rb");
418 wchar_t wbuf
[MAX_LOG_LENGTH
+6];
421 len
= fread(&rev
, sizeof(LONG
), 1, File
);
428 len
= fread(&slength
, sizeof(int), 1, File
);
435 if (slength
> MAX_LOG_LENGTH
)
437 reallength
= slength
;
438 slength
= MAX_LOG_LENGTH
;
442 len
= fread(logmsgbuf
, sizeof(char), slength
, File
);
443 if (len
< (size_t)slength
)
449 msg
= CString(logmsgbuf
, slength
);
452 fseek(File
, reallength
-MAX_LOG_LENGTH
, SEEK_CUR
);
453 msg
= msg
+ _T("\n...");
455 int len2
= ::MultiByteToWideChar(CP_UTF8
, NULL
, msg
.c_str(), min(msg
.size(), MAX_LOG_LENGTH
+5), wbuf
, MAX_LOG_LENGTH
+5);
457 len2
= ::WideCharToMultiByte(CP_ACP
, NULL
, wbuf
, len2
, logmsgbuf
, MAX_LOG_LENGTH
+5, NULL
, NULL
);
459 msg
= CString(logmsgbuf
);
460 logmessages
[rev
] = msg
;
466 BOOL
CTortoiseGitBlameView::OpenFile(const char *fileName
)
469 SendEditor(SCI_SETREADONLY
, FALSE
);
470 SendEditor(SCI_CLEARALL
);
471 SendEditor(EM_EMPTYUNDOBUFFER
);
473 SendEditor(SCI_SETSAVEPOINT
);
474 SendEditor(SCI_CANCEL
);
475 SendEditor(SCI_SETUNDOCOLLECTION
, 0);
476 ::ShowWindow(m_wEditor
, SW_HIDE
);
484 char * lineptr
= NULL
;
485 char * trimptr
= NULL
;
486 //ignore the first two lines, they're of no interest to us
487 File
.getline(line
, sizeof(line
)/sizeof(char));
488 File
.getline(line
, sizeof(line
)/sizeof(char));
489 m_lowestrev
= LONG_MAX
;
494 File
.getline(line
, sizeof(line
)/sizeof(TCHAR
));
495 if (File
.gcount()>139)
497 mergelines
.push_back((line
[0] != ' '));
499 long rev
= _ttol(lineptr
);
501 m_lowestrev
= min(m_lowestrev
, rev
);
502 m_highestrev
= max(m_highestrev
, rev
);
504 rev
= _ttol(lineptr
);
505 origrevs
.push_back(rev
);
507 dates
.push_back(CString(lineptr
, 30));
509 // unfortunately, the 'path' entry can be longer than the 60 chars
510 // we made the column. We therefore have to step through the path
511 // string until we find a space
515 // TODO: how can we deal with the situation where the path has
516 // a space in it, but the space is after the 60 chars reserved
518 // The only way to deal with that would be to use a custom
519 // binary format for the blame file.
521 trimptr
= _tcschr(trimptr
, ' ');
522 } while ((trimptr
)&&(trimptr
+1 < lineptr
+61));
527 paths
.push_back(CString(lineptr
));
528 if (trimptr
+1 < lineptr
+61)
531 lineptr
= (trimptr
+1);
532 trimptr
= lineptr
+30;
533 while ((*trimptr
== ' ')&&(trimptr
> lineptr
))
536 authors
.push_back(CString(lineptr
));
538 // in case we find an UTF8 BOM at the beginning of the line, we remove it
539 if (((unsigned char)lineptr
[0] == 0xEF)&&((unsigned char)lineptr
[1] == 0xBB)&&((unsigned char)lineptr
[2] == 0xBF))
543 if (((unsigned char)lineptr
[0] == 0xBB)&&((unsigned char)lineptr
[1] == 0xEF)&&((unsigned char)lineptr
[2] == 0xBF))
547 // check each line for illegal utf8 sequences. If one is found, we treat
548 // the file as ASCII, otherwise we assume an UTF8 file.
549 char * utf8CheckBuf
= lineptr
;
550 while ((bUTF8
)&&(*utf8CheckBuf
))
552 if ((*utf8CheckBuf
== 0xC0)||(*utf8CheckBuf
== 0xC1)||(*utf8CheckBuf
>= 0xF5))
557 if ((*utf8CheckBuf
& 0xE0)==0xC0)
560 if (*utf8CheckBuf
== 0)
562 if ((*utf8CheckBuf
& 0xC0)!=0x80)
568 if ((*utf8CheckBuf
& 0xF0)==0xE0)
571 if (*utf8CheckBuf
== 0)
573 if ((*utf8CheckBuf
& 0xC0)!=0x80)
579 if (*utf8CheckBuf
== 0)
581 if ((*utf8CheckBuf
& 0xC0)!=0x80)
587 if ((*utf8CheckBuf
& 0xF8)==0xF0)
590 if (*utf8CheckBuf
== 0)
592 if ((*utf8CheckBuf
& 0xC0)!=0x80)
598 if (*utf8CheckBuf
== 0)
600 if ((*utf8CheckBuf
& 0xC0)!=0x80)
606 if (*utf8CheckBuf
== 0)
608 if ((*utf8CheckBuf
& 0xC0)!=0x80)
617 SendEditor(SCI_ADDTEXT
, _tcslen(lineptr
), reinterpret_cast<LPARAM
>(static_cast<char *>(lineptr
)));
618 SendEditor(SCI_ADDTEXT
, 2, (LPARAM
)_T("\r\n"));
620 } while (File
.gcount() > 0);
623 SendEditor(SCI_SETCODEPAGE
, SC_CP_UTF8
);
625 SendEditor(SCI_SETUNDOCOLLECTION
, 1);
626 ::SetFocus(m_wEditor
);
627 SendEditor(EM_EMPTYUNDOBUFFER
);
628 SendEditor(SCI_SETSAVEPOINT
);
629 SendEditor(SCI_GOTOPOS
, 0);
630 SendEditor(SCI_SETSCROLLWIDTHTRACKING
, TRUE
);
631 SendEditor(SCI_SETREADONLY
, TRUE
);
633 //check which lexer to use, depending on the filetype
634 SetupLexer(fileName
);
635 ::ShowWindow(m_wEditor
, SW_SHOW
);
637 ::InvalidateRect(wMain
, NULL
, TRUE
);
639 GetWindowRect(wMain
, &rc
);
640 SetWindowPos(wMain
, 0, rc
.left
, rc
.top
, rc
.right
-rc
.left
-1, rc
.bottom
- rc
.top
, 0);
645 void CTortoiseGitBlameView::SetAStyle(int style
, COLORREF fore
, COLORREF back
, int size
, CString
*face
)
647 SendEditor(SCI_STYLESETFORE
, style
, fore
);
648 SendEditor(SCI_STYLESETBACK
, style
, back
);
650 SendEditor(SCI_STYLESETSIZE
, style
, size
);
652 SendEditor(SCI_STYLESETFONT
, style
, reinterpret_cast<LPARAM
>(this->m_TextView
.StringForControl(*face
).GetBuffer()));
655 void CTortoiseGitBlameView::InitialiseEditor()
658 m_directFunction
= ::SendMessage(m_wEditor
, SCI_GETDIRECTFUNCTION
, 0, 0);
659 m_directPointer
= ::SendMessage(m_wEditor
, SCI_GETDIRECTPOINTER
, 0, 0);
660 // Set up the global default style. These attributes are used wherever no explicit choices are made.
661 SetAStyle(STYLE_DEFAULT
,
664 (DWORD
)CRegStdWORD(_T("Software\\TortoiseGit\\BlameFontSize"), 10),
665 &CString(((stdstring
)CRegStdString(_T("Software\\TortoiseGit\\BlameFontName"), _T("Courier New"))).c_str())
667 SendEditor(SCI_SETTABWIDTH
, (DWORD
)CRegStdWORD(_T("Software\\TortoiseGit\\BlameTabSize"), 4));
668 SendEditor(SCI_SETREADONLY
, TRUE
);
669 LRESULT pix
= SendEditor(SCI_TEXTWIDTH
, STYLE_LINENUMBER
, (LPARAM
)this->m_TextView
.StringForControl(_T("_99999")).GetBuffer());
671 SendEditor(SCI_SETMARGINWIDTHN
, 0, pix
);
673 SendEditor(SCI_SETMARGINWIDTHN
, 0);
674 SendEditor(SCI_SETMARGINWIDTHN
, 1);
675 SendEditor(SCI_SETMARGINWIDTHN
, 2);
676 //Set the default windows colors for edit controls
677 SendEditor(SCI_STYLESETFORE
, STYLE_DEFAULT
, ::GetSysColor(COLOR_WINDOWTEXT
));
678 SendEditor(SCI_STYLESETBACK
, STYLE_DEFAULT
, ::GetSysColor(COLOR_WINDOW
));
679 SendEditor(SCI_SETSELFORE
, TRUE
, ::GetSysColor(COLOR_HIGHLIGHTTEXT
));
680 SendEditor(SCI_SETSELBACK
, TRUE
, ::GetSysColor(COLOR_HIGHLIGHT
));
681 SendEditor(SCI_SETCARETFORE
, ::GetSysColor(COLOR_WINDOWTEXT
));
682 m_regOldLinesColor
= CRegStdWORD(_T("Software\\TortoiseGit\\BlameOldColor"), RGB(230, 230, 255));
683 m_regNewLinesColor
= CRegStdWORD(_T("Software\\TortoiseGit\\BlameNewColor"), RGB(255, 230, 230));
685 this->m_TextView
.Call(SCI_SETWRAPMODE
, SC_WRAP_NONE
);
689 void CTortoiseGitBlameView::StartSearch()
694 // Initialize FINDREPLACE
695 if (fr
.Flags
& FR_MATCHCASE
)
697 SecureZeroMemory(&fr
, sizeof(fr
));
698 fr
.lStructSize
= sizeof(fr
);
699 fr
.hwndOwner
= wMain
;
700 fr
.lpstrFindWhat
= szFindWhat
;
701 fr
.wFindWhatLen
= 80;
702 fr
.Flags
= FR_HIDEUPDOWN
| FR_HIDEWHOLEWORD
;
703 fr
.Flags
|= bCase
? FR_MATCHCASE
: 0;
705 currentDialog
= FindText(&fr
);
708 bool CTortoiseGitBlameView::DoSearch(CString what
, DWORD flags
)
712 int pos
= SendEditor(SCI_GETCURRENTPOS
);
713 int line
= SendEditor(SCI_LINEFROMPOSITION
, pos
);
715 bool bCaseSensitive
= !!(flags
& FR_MATCHCASE
);
717 //strcpy_s(szWhat, sizeof(szWhat), what);
721 what
=what
.MakeLower();
724 //CString sWhat = CString(szWhat);
731 int bufsize
= SendEditor(SCI_GETLINE
, i
);
732 char * linebuf
= new char[bufsize
+1];
733 SecureZeroMemory(linebuf
, bufsize
+1);
734 SendEditor(SCI_GETLINE
, i
, (LPARAM
)linebuf
);
735 CString oneline
=this->m_TextView
.StringFromControl(linebuf
);
738 oneline
=oneline
.MakeLower();
740 //_stprintf_s(buf, 20, _T("%ld"), revs[i]);
741 if (this->m_Authors
[i
].Find(what
)>=0)
743 else if ((!bCaseSensitive
)&&(this->m_Authors
[i
].MakeLower().Find(what
)>=0))
745 else if (oneline
.Find(what
) >=0)
751 if(i
>=(signed int)m_CommitHash
.size())
753 }while(i
!=line
&&(!bFound
));
758 int selstart
= SendEditor(SCI_GETCURRENTPOS
);
759 int selend
= SendEditor(SCI_POSITIONFROMLINE
, i
);
760 SendEditor(SCI_SETSELECTIONSTART
, selstart
);
761 SendEditor(SCI_SETSELECTIONEND
, selend
);
762 m_SelectedLine
= i
-1;
766 ::MessageBox(wMain
, what
+_T(" not found"), _T("CTortoiseGitBlameView"), MB_ICONINFORMATION
);
772 bool CTortoiseGitBlameView::GotoLine(long line
)
777 if ((unsigned long)line
>= m_CommitHash
.size())
779 line
= m_CommitHash
.size()-1;
782 int nCurrentPos
= SendEditor(SCI_GETCURRENTPOS
);
783 int nCurrentLine
= SendEditor(SCI_LINEFROMPOSITION
,nCurrentPos
);
784 int nFirstVisibleLine
= SendEditor(SCI_GETFIRSTVISIBLELINE
);
785 int nLinesOnScreen
= SendEditor(SCI_LINESONSCREEN
);
787 if ( line
>=nFirstVisibleLine
&& line
<=nFirstVisibleLine
+nLinesOnScreen
)
790 SendEditor(SCI_GOTOLINE
, line
);
794 // Place the requested line one third from the top
795 if ( line
> nCurrentLine
)
797 SendEditor(SCI_GOTOLINE
, (WPARAM
)(line
+(int)nLinesOnScreen
*(2/3.0)));
801 SendEditor(SCI_GOTOLINE
, (WPARAM
)(line
-(int)nLinesOnScreen
*(1/3.0)));
805 // Highlight the line
806 int nPosStart
= SendEditor(SCI_POSITIONFROMLINE
,line
);
807 int nPosEnd
= SendEditor(SCI_GETLINEENDPOSITION
,line
);
808 SendEditor(SCI_SETSEL
,nPosEnd
,nPosStart
);
813 bool CTortoiseGitBlameView::ScrollToLine(long line
)
818 int nCurrentLine
= SendEditor(SCI_GETFIRSTVISIBLELINE
);
820 int scrolldelta
= line
- nCurrentLine
;
821 SendEditor(SCI_LINESCROLL
, 0, scrolldelta
);
826 void CTortoiseGitBlameView::CopySelectedLogToClipboard()
828 this->GetLogList()->CopySelectionToClipBoard(FALSE
);
831 void CTortoiseGitBlameView::BlamePreviousRevision()
834 LONG nRevisionTo
= m_selectedorigrev
- 1;
840 // We now determine the smallest revision number in the blame file (but ignore "-1")
841 // We do this for two reasons:
842 // 1. we respect the "From revision" which the user entered
843 // 2. we speed up the call of "svn blame" because previous smaller revision numbers don't have any effect on the result
844 LONG nSmallestRevision
= -1;
845 for (LONG line
=0;line
<(LONG
)app
.revs
.size();line
++)
847 const LONG nRevision
= app
.revs
[line
];
850 if ( nSmallestRevision
< 1 )
852 nSmallestRevision
= nRevision
;
856 nSmallestRevision
= min(nSmallestRevision
,nRevision
);
861 char bufStartRev
[20];
862 _stprintf_s(bufStartRev
, 20, _T("%d"), nSmallestRevision
);
865 _stprintf_s(bufEndRev
, 20, _T("%d"), nRevisionTo
);
868 _stprintf_s(bufLine
, 20, _T("%d"), m_SelectedLine
+1); //using the current line is a good guess.
871 PROCESS_INFORMATION process
;
872 memset(&startup
, 0, sizeof(startup
));
873 startup
.cb
= sizeof(startup
);
874 memset(&process
, 0, sizeof(process
));
875 stdstring tortoiseProcPath
= GetAppDirectory() + _T("TortoiseProc.exe");
876 stdstring svnCmd
= _T(" /command:blame ");
877 svnCmd
+= _T(" /path:\"");
878 svnCmd
+= szOrigPath
;
880 svnCmd
+= _T(" /startrev:");
881 svnCmd
+= bufStartRev
;
882 svnCmd
+= _T(" /endrev:");
884 svnCmd
+= _T(" /line:");
887 svnCmd
+= _T(" /ignoreeol");
889 svnCmd
+= _T(" /ignorespaces");
890 if (bIgnoreAllSpaces
)
891 svnCmd
+= _T(" /ignoreallspaces");
892 if (CreateProcess(tortoiseProcPath
.c_str(), const_cast<TCHAR
*>(svnCmd
.c_str()), NULL
, NULL
, FALSE
, 0, 0, 0, &startup
, &process
))
894 CloseHandle(process
.hThread
);
895 CloseHandle(process
.hProcess
);
900 void CTortoiseGitBlameView::DiffPreviousRevision()
903 LONG nRevisionTo
= m_selectedorigrev
;
909 LONG nRevisionFrom
= nRevisionTo
-1;
911 char bufStartRev
[20];
912 _stprintf_s(bufStartRev
, 20, _T("%d"), nRevisionFrom
);
915 _stprintf_s(bufEndRev
, 20, _T("%d"), nRevisionTo
);
918 PROCESS_INFORMATION process
;
919 memset(&startup
, 0, sizeof(startup
));
920 startup
.cb
= sizeof(startup
);
921 memset(&process
, 0, sizeof(process
));
922 stdstring tortoiseProcPath
= GetAppDirectory() + _T("TortoiseProc.exe");
923 stdstring svnCmd
= _T(" /command:diff ");
924 svnCmd
+= _T(" /path:\"");
925 svnCmd
+= szOrigPath
;
927 svnCmd
+= _T(" /startrev:");
928 svnCmd
+= bufStartRev
;
929 svnCmd
+= _T(" /endrev:");
931 if (CreateProcess(tortoiseProcPath
.c_str(), const_cast<TCHAR
*>(svnCmd
.c_str()), NULL
, NULL
, FALSE
, 0, 0, 0, &startup
, &process
))
933 CloseHandle(process
.hThread
);
934 CloseHandle(process
.hProcess
);
939 void CTortoiseGitBlameView::ShowLog()
943 _stprintf_s(bufRev
, 20, _T("%d"), m_selectedorigrev
);
946 PROCESS_INFORMATION process
;
947 memset(&startup
, 0, sizeof(startup
));
948 startup
.cb
= sizeof(startup
);
949 memset(&process
, 0, sizeof(process
));
950 stdstring tortoiseProcPath
= GetAppDirectory() + _T("TortoiseProc.exe");
951 stdstring svnCmd
= _T(" /command:log ");
952 svnCmd
+= _T(" /path:\"");
953 svnCmd
+= szOrigPath
;
955 svnCmd
+= _T(" /startrev:");
957 svnCmd
+= _T(" /pegrev:");
959 if (CreateProcess(tortoiseProcPath
.c_str(), const_cast<TCHAR
*>(svnCmd
.c_str()), NULL
, NULL
, FALSE
, 0, 0, 0, &startup
, &process
))
961 CloseHandle(process
.hThread
);
962 CloseHandle(process
.hProcess
);
967 void CTortoiseGitBlameView::Notify(SCNotification
*notification
)
969 switch (notification
->nmhdr
.code
)
971 case SCN_SAVEPOINTREACHED
:
974 case SCN_SAVEPOINTLEFT
:
977 // InvalidateRect(wBlame, NULL, FALSE);
978 // InvalidateRect(wLocator, NULL, FALSE);
981 // if ((m_colorage)&&(notification->line < (int)revs.size()))
983 // notification->lParam = InterColor(DWORD(m_regOldLinesColor), DWORD(m_regNewLinesColor), (revs[notification->line]-m_lowestrev)*100/((m_highestrev-m_lowestrev)+1));
989 void CTortoiseGitBlameView::Command(int id
)
995 // ::PostQuitMessage(0);
1000 case ID_COPYTOCLIPBOARD
:
1001 CopySelectedLogToClipboard();
1003 case ID_BLAME_PREVIOUS_REVISION
:
1004 BlamePreviousRevision();
1006 case ID_DIFF_PREVIOUS_REVISION
:
1007 DiffPreviousRevision();
1012 case ID_EDIT_GOTOLINE
:
1015 case ID_VIEW_COLORAGEOFLINES
:
1017 m_colorage
= !m_colorage
;
1018 HMENU hMenu
= GetMenu(wMain
);
1019 UINT uCheck
= MF_BYCOMMAND
;
1020 uCheck
|= m_colorage
? MF_CHECKED
: MF_UNCHECKED
;
1021 CheckMenuItem(hMenu
, ID_VIEW_COLORAGEOFLINES
, uCheck
);
1026 case ID_VIEW_MERGEPATH
:
1028 ShowPath
= !ShowPath
;
1029 HMENU hMenu
= GetMenu(wMain
);
1030 UINT uCheck
= MF_BYCOMMAND
;
1031 uCheck
|= ShowPath
? MF_CHECKED
: MF_UNCHECKED
;
1032 CheckMenuItem(hMenu
, ID_VIEW_MERGEPATH
, uCheck
);
1043 LONG
CTortoiseGitBlameView::GetBlameWidth()
1045 LONG blamewidth
= 0;
1048 HDC hDC
= this->GetDC()->m_hDC
;
1049 HFONT oldfont
= (HFONT
)::SelectObject(hDC
, m_font
);
1051 TCHAR buf
[MAX_PATH
];
1054 for (unsigned int i
=0;i
<this->m_ID
.size();i
++)
1059 _stprintf_s(buf
, MAX_PATH
, _T("%d."), maxnum
);
1060 ::GetTextExtentPoint(hDC
, buf
, _tcslen(buf
), &width
);
1061 m_revwidth
= width
.cx
+ BLAMESPACE
;
1062 blamewidth
+= m_revwidth
;
1065 _stprintf_s(buf
, MAX_PATH
, _T("%d"), m_CommitHash
.size());
1066 ::GetTextExtentPoint(hDC
, buf
, _tcslen(buf
), &width
);
1067 m_linewidth
= width
.cx
+ BLAMESPACE
;
1068 blamewidth
+= m_revwidth
;
1073 _stprintf_s(buf
, MAX_PATH
, _T("%30s"), _T("31.08.2001 06:24:14"));
1074 ::GetTextExtentPoint32(hDC
, buf
, _tcslen(buf
), &width
);
1075 m_datewidth
= width
.cx
+ BLAMESPACE
;
1076 blamewidth
+= m_datewidth
;
1080 SIZE maxwidth
= {0};
1082 for (unsigned int i
=0;i
<this->m_Authors
.size();i
++)
1083 //for (std::vector<CString>::iterator I = authors.begin(); I != authors.end(); ++I)
1085 ::GetTextExtentPoint32(hDC
,m_Authors
[i
] , m_Authors
[i
].GetLength(), &width
);
1086 if (width
.cx
> maxwidth
.cx
)
1089 m_authorwidth
= maxwidth
.cx
+ BLAMESPACE
;
1090 blamewidth
+= m_authorwidth
;
1095 SIZE maxwidth
= {0};
1096 for (std::vector
<CString
>::iterator I
= paths
.begin(); I
!= paths
.end(); ++I
)
1098 ::GetTextExtentPoint32(hDC
, I
->c_str(), I
->size(), &width
);
1099 if (width
.cx
> maxwidth
.cx
)
1102 m_pathwidth
= maxwidth
.cx
+ BLAMESPACE
;
1103 blamewidth
+= m_pathwidth
;
1106 ::SelectObject(hDC
, oldfont
);
1107 POINT pt
= {blamewidth
, 0};
1108 LPtoDP(hDC
, &pt
, 1);
1109 m_blamewidth
= pt
.x
;
1110 //::ReleaseDC(wBlame, hDC);
1112 //return m_blamewidth;
1117 void CTortoiseGitBlameView::CreateFont()
1123 HDC hDC
= ::GetDC(wBlame
);
1124 lf
.lfHeight
= -MulDiv((DWORD
)CRegStdWORD(_T("Software\\TortoiseGit\\BlameFontSize"), 10), GetDeviceCaps(hDC
, LOGPIXELSY
), 72);
1125 lf
.lfCharSet
= DEFAULT_CHARSET
;
1126 CRegStdString fontname
= CRegStdString(_T("Software\\TortoiseGit\\BlameFontName"), _T("Courier New"));
1127 _tcscpy_s(lf
.lfFaceName
, 32, ((stdstring
)fontname
).c_str());
1128 m_font
= ::CreateFontIndirect(&lf
);
1131 m_italicfont
= ::CreateFontIndirect(&lf
);
1133 ::ReleaseDC(wBlame
, hDC
);
1135 //m_TextView.SetFont(lf.lfFaceName,((DWORD)CRegStdWORD(_T("Software\\TortoiseGit\\BlameFontSize"), 10)));
1138 void CTortoiseGitBlameView::DrawBlame(HDC hDC
)
1146 HFONT oldfont
= NULL
;
1147 LONG_PTR line
= SendEditor(SCI_GETFIRSTVISIBLELINE
);
1148 LONG_PTR linesonscreen
= SendEditor(SCI_LINESONSCREEN
);
1149 LONG_PTR height
= SendEditor(SCI_TEXTHEIGHT
);
1151 TCHAR buf
[MAX_PATH
];
1154 //::GetClientRect(this->m_hWnd, &rc);
1155 for (LRESULT i
=line
; i
<(line
+linesonscreen
); ++i
)
1158 if (i
< (int)m_CommitHash
.size())
1160 // if (mergelines[i])
1161 // oldfont = (HFONT)::SelectObject(hDC, m_italicfont);
1163 oldfont
= (HFONT
)::SelectObject(hDC
, m_font
);
1164 ::SetBkColor(hDC
, m_windowcolor
);
1165 ::SetTextColor(hDC
, m_textcolor
);
1166 if (!m_CommitHash
[i
].IsEmpty())
1168 //if (m_CommitHash[i].Compare(m_MouseHash)==0)
1169 // ::SetBkColor(hDC, m_mouseauthorcolor);
1170 if (m_CommitHash
[i
] == m_SelectedHash
)
1172 ::SetBkColor(hDC
, m_selectedauthorcolor
);
1173 ::SetTextColor(hDC
, m_texthighlightcolor
);
1178 if(m_MouseLine
== i
)
1179 ::SetBkColor(hDC
, m_mouserevcolor
);
1181 //if ((revs[i] == m_mouserev)&&(!sel))
1182 // ::SetBkColor(hDC, m_mouserevcolor);
1183 //if (revs[i] == m_selectedrev)
1185 // ::SetBkColor(hDC, m_selectedrevcolor);
1186 // ::SetTextColor(hDC, m_texthighlightcolor);
1190 if(i
<m_ID
.size() && m_ID
[i
]>=0)
1191 str
.Format(_T("%d"),m_ID
[i
]);
1193 //_stprintf_s(buf, MAX_PATH, _T("%8ld "), revs[i]);
1195 rc
.left
=LOCATOR_WIDTH
;
1197 rc
.right
= rc
.left
+ m_blamewidth
;
1198 ::ExtTextOut(hDC
, LOCATOR_WIDTH
, Y
, ETO_CLIPPED
, &rc
, str
, str
.GetLength(), 0);
1199 int Left
= m_revwidth
;
1203 rc
.right
= rc
.left
+ Left
+ m_authorwidth
;
1204 //_stprintf_s(buf, MAX_PATH, _T("%-30s "), authors[i].c_str());
1205 ::ExtTextOut(hDC
, Left
, Y
, ETO_CLIPPED
, &rc
, m_Authors
[i
], m_Authors
[i
].GetLength(), 0);
1206 Left
+= m_authorwidth
;
1211 rc
.right
= rc
.left
+ Left
+ m_datewidth
;
1212 _stprintf_s(buf
, MAX_PATH
, _T("%30s "), dates
[i
].c_str());
1213 ::ExtTextOut(hDC
, Left
, Y
, ETO_CLIPPED
, &rc
, buf
, _tcslen(buf
), 0);
1214 Left
+= m_datewidth
;
1221 rc
.right
= rc
.left
+ Left
+ m_pathwidth
;
1222 _stprintf_s(buf
, MAX_PATH
, _T("%-60s "), paths
[i
].c_str());
1223 ::ExtTextOut(hDC
, Left
, Y
, ETO_CLIPPED
, &rc
, buf
, _tcslen(buf
), 0);
1224 Left
+= m_authorwidth
;
1227 if ((i
==m_SelectedLine
)&&(m_pFindDialog
))
1230 brush
.lbColor
= m_textcolor
;
1232 brush
.lbStyle
= BS_SOLID
;
1233 HPEN pen
= ExtCreatePen(PS_SOLID
| PS_GEOMETRIC
, 2, &brush
, 0, NULL
);
1234 HGDIOBJ hPenOld
= SelectObject(hDC
, pen
);
1237 rc2
.bottom
= Y
+ height
;
1238 ::MoveToEx(hDC
, rc2
.left
, rc2
.top
, NULL
);
1239 ::LineTo(hDC
, rc2
.right
, rc2
.top
);
1240 ::LineTo(hDC
, rc2
.right
, rc2
.bottom
);
1241 ::LineTo(hDC
, rc2
.left
, rc2
.bottom
);
1242 ::LineTo(hDC
, rc2
.left
, rc2
.top
);
1243 SelectObject(hDC
, hPenOld
);
1247 ::SelectObject(hDC
, oldfont
);
1251 ::SetBkColor(hDC
, m_windowcolor
);
1252 for (int j
=0; j
< MAX_PATH
; ++j
)
1254 ::ExtTextOut(hDC
, 0, Y
, ETO_CLIPPED
, &rc
, buf
, MAX_PATH
-1, 0);
1260 void CTortoiseGitBlameView::DrawHeader(HDC hDC
)
1267 HFONT oldfont
= (HFONT
)::SelectObject(hDC
, GetStockObject(DEFAULT_GUI_FONT
));
1268 ::GetClientRect(wHeader
, &rc
);
1270 ::SetBkColor(hDC
, ::GetSysColor(COLOR_BTNFACE
));
1272 TCHAR szText
[MAX_LOADSTRING
];
1273 LoadString(app
.hResource
, IDS_HEADER_REVISION
, szText
, MAX_LOADSTRING
);
1274 ::ExtTextOut(hDC
, LOCATOR_WIDTH
, 0, ETO_CLIPPED
, &rc
, szText
, _tcslen(szText
), 0);
1275 int Left
= m_revwidth
+LOCATOR_WIDTH
;
1278 LoadString(app
.hResource
, IDS_HEADER_DATE
, szText
, MAX_LOADSTRING
);
1279 ::ExtTextOut(hDC
, Left
, 0, ETO_CLIPPED
, &rc
, szText
, _tcslen(szText
), 0);
1280 Left
+= m_datewidth
;
1284 LoadString(app
.hResource
, IDS_HEADER_AUTHOR
, szText
, MAX_LOADSTRING
);
1285 ::ExtTextOut(hDC
, Left
, 0, ETO_CLIPPED
, &rc
, szText
, _tcslen(szText
), 0);
1286 Left
+= m_authorwidth
;
1290 LoadString(app
.hResource
, IDS_HEADER_PATH
, szText
, MAX_LOADSTRING
);
1291 ::ExtTextOut(hDC
, Left
, 0, ETO_CLIPPED
, &rc
, szText
, _tcslen(szText
), 0);
1292 Left
+= m_pathwidth
;
1294 LoadString(app
.hResource
, IDS_HEADER_LINE
, szText
, MAX_LOADSTRING
);
1295 ::ExtTextOut(hDC
, Left
, 0, ETO_CLIPPED
, &rc
, szText
, _tcslen(szText
), 0);
1297 ::SelectObject(hDC
, oldfont
);
1301 void CTortoiseGitBlameView::DrawLocatorBar(HDC hDC
)
1306 LONG_PTR line
= SendEditor(SCI_GETFIRSTVISIBLELINE
);
1307 LONG_PTR linesonscreen
= SendEditor(SCI_LINESONSCREEN
);
1309 COLORREF blackColor
= GetSysColor(COLOR_WINDOWTEXT
);
1312 //::GetClientRect(wLocator, &rc);
1313 this->GetClientRect(&rc
);
1315 rc
.right
=LOCATOR_WIDTH
;
1318 LONG height
= rc
.bottom
-rc
.top
;
1319 LONG currentLine
= 0;
1321 // draw the colored bar
1322 for (std::vector
<LONG
>::const_iterator it
= m_ID
.begin(); it
!= m_ID
.end(); ++it
)
1325 // get the line color
1326 COLORREF cr
= InterColor(DWORD(m_regOldLinesColor
), DWORD(m_regNewLinesColor
), (*it
- m_lowestrev
)*100/((m_highestrev
-m_lowestrev
)+1));
1327 if ((currentLine
> line
)&&(currentLine
<= (line
+ linesonscreen
)))
1329 cr
= InterColor(cr
, blackColor
, 10);
1331 SetBkColor(hDC
, cr
);
1333 lineRect
.bottom
= (currentLine
* height
/ m_ID
.size());
1334 ::ExtTextOut(hDC
, 0, 0, ETO_OPAQUE
, &lineRect
, NULL
, 0, NULL
);
1335 Y
= lineRect
.bottom
;
1340 // now draw two lines indicating the scroll position of the source view
1341 SetBkColor(hDC
, blackColor
);
1342 lineRect
.top
= line
* height
/ m_ID
.size();
1343 lineRect
.bottom
= lineRect
.top
+1;
1344 ::ExtTextOut(hDC
, 0, 0, ETO_OPAQUE
, &lineRect
, NULL
, 0, NULL
);
1345 lineRect
.top
= (line
+ linesonscreen
) * height
/ m_ID
.size();
1346 lineRect
.bottom
= lineRect
.top
+1;
1347 ::ExtTextOut(hDC
, 0, 0, ETO_OPAQUE
, &lineRect
, NULL
, 0, NULL
);
1352 void CTortoiseGitBlameView::StringExpand(LPSTR str
)
1357 cPos
= strchr(cPos
, '\n');
1360 memmove(cPos
+1, cPos
, strlen(cPos
)*sizeof(char));
1365 } while (cPos
!= NULL
);
1367 void CTortoiseGitBlameView::StringExpand(LPWSTR str
)
1369 wchar_t * cPos
= str
;
1372 cPos
= wcschr(cPos
, '\n');
1375 memmove(cPos
+1, cPos
, wcslen(cPos
)*sizeof(wchar_t));
1380 } while (cPos
!= NULL
);
1383 // Forward declarations of functions included in this code module:
1384 ATOM
MyRegisterClass(HINSTANCE hResource
);
1385 ATOM
MyRegisterBlameClass(HINSTANCE hResource
);
1386 ATOM
MyRegisterHeaderClass(HINSTANCE hResource
);
1387 ATOM
MyRegisterLocatorClass(HINSTANCE hResource
);
1388 BOOL
InitInstance(HINSTANCE
, int);
1389 LRESULT CALLBACK
WndProc(HWND
, UINT
, WPARAM
, LPARAM
);
1390 LRESULT CALLBACK
WndBlameProc(HWND
, UINT
, WPARAM
, LPARAM
);
1391 LRESULT CALLBACK
WndHeaderProc(HWND
, UINT
, WPARAM
, LPARAM
);
1392 LRESULT CALLBACK
WndLocatorProc(HWND
, UINT
, WPARAM
, LPARAM
);
1393 UINT uFindReplaceMsg
;
1396 int APIENTRY
_tWinMain(HINSTANCE hInstance
,
1397 HINSTANCE
/*hPrevInstance*/,
1401 app
.hInstance
= hInstance
;
1405 if (::LoadLibrary("SciLexer.DLL") == NULL
)
1408 CRegStdWORD loc
= CRegStdWORD(_T("Software\\TortoiseGit\\LanguageID"), 1033);
1412 app
.hResource
= langDLL
.Init(_T("CTortoiseGitBlameView"), langId
);
1413 if (app
.hResource
== NULL
)
1414 app
.hResource
= app
.hInstance
;
1416 // Initialize global strings
1417 LoadString(app
.hResource
, IDS_APP_TITLE
, szTitle
, MAX_LOADSTRING
);
1418 LoadString(app
.hResource
, IDC_TortoiseGitBlameView
, szWindowClass
, MAX_LOADSTRING
);
1419 LoadString(app
.hResource
, IDS_SEARCHNOTFOUND
, searchstringnotfound
, MAX_LOADSTRING
);
1420 MyRegisterClass(app
.hResource
);
1421 MyRegisterBlameClass(app
.hResource
);
1422 MyRegisterHeaderClass(app
.hResource
);
1423 MyRegisterLocatorClass(app
.hResource
);
1425 // Perform application initialization:
1426 if (!InitInstance (app
.hResource
, nCmdShow
))
1432 SecureZeroMemory(szViewtitle
, MAX_PATH
);
1433 SecureZeroMemory(szOrigPath
, MAX_PATH
);
1434 char blamefile
[MAX_PATH
] = {0};
1435 char logfile
[MAX_PATH
] = {0};
1437 CCmdLineParser
parser(lpCmdLine
);
1442 _tcscpy_s(blamefile
, MAX_PATH
, __argv
[1]);
1446 _tcscpy_s(logfile
, MAX_PATH
, __argv
[2]);
1450 _tcscpy_s(szViewtitle
, MAX_PATH
, __argv
[3]);
1451 if (parser
.HasVal(_T("revrange")))
1453 _tcscat_s(szViewtitle
, MAX_PATH
, _T(" : "));
1454 _tcscat_s(szViewtitle
, MAX_PATH
, parser
.GetVal(_T("revrange")));
1457 if ((_tcslen(blamefile
)==0) || parser
.HasKey(_T("?")) || parser
.HasKey(_T("help")))
1459 TCHAR szInfo
[MAX_LOADSTRING
];
1460 LoadString(app
.hResource
, IDS_COMMANDLINE_INFO
, szInfo
, MAX_LOADSTRING
);
1461 MessageBox(NULL
, szInfo
, _T("CTortoiseGitBlameView"), MB_ICONERROR
);
1466 if ( parser
.HasKey(_T("path")) )
1468 _tcscpy_s(szOrigPath
, MAX_PATH
, parser
.GetVal(_T("path")));
1470 app
.bIgnoreEOL
= parser
.HasKey(_T("ignoreeol"));
1471 app
.bIgnoreSpaces
= parser
.HasKey(_T("ignorespaces"));
1472 app
.bIgnoreAllSpaces
= parser
.HasKey(_T("ignoreallspaces"));
1474 app
.SendEditor(SCI_SETCODEPAGE
, GetACP());
1475 app
.OpenFile(blamefile
);
1476 if (_tcslen(logfile
)>0)
1477 app
.OpenLogFile(logfile
);
1479 if (parser
.HasKey(_T("line")))
1481 app
.GotoLine(parser
.GetLongVal(_T("line")));
1484 CheckMenuItem(GetMenu(app
.wMain
), ID_VIEW_COLORAGEOFLINES
, MF_CHECKED
|MF_BYCOMMAND
);
1487 hAccelTable
= LoadAccelerators(app
.hResource
, (LPCTSTR
)IDC_TortoiseGitBlameView
);
1493 going
= GetMessage(&msg
, NULL
, 0, 0);
1494 if (app
.currentDialog
&& going
)
1496 if (!IsDialogMessage(app
.currentDialog
, &msg
))
1498 if (TranslateAccelerator(msg
.hwnd
, hAccelTable
, &msg
) == 0)
1500 TranslateMessage(&msg
);
1501 DispatchMessage(&msg
);
1507 if (TranslateAccelerator(app
.wMain
, hAccelTable
, &msg
) == 0)
1509 TranslateMessage(&msg
);
1510 DispatchMessage(&msg
);
1518 ATOM
MyRegisterClass(HINSTANCE hResource
)
1522 wcex
.cbSize
= sizeof(WNDCLASSEX
);
1524 wcex
.style
= CS_HREDRAW
| CS_VREDRAW
;
1525 wcex
.lpfnWndProc
= (WNDPROC
)WndProc
;
1526 wcex
.cbClsExtra
= 0;
1527 wcex
.cbWndExtra
= 0;
1528 wcex
.hInstance
= hResource
;
1529 wcex
.hIcon
= LoadIcon(hResource
, (LPCTSTR
)IDI_TortoiseGitBlameView
);
1530 wcex
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
1531 wcex
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+1);
1532 wcex
.lpszMenuName
= (LPCTSTR
)IDC_TortoiseGitBlameView
;
1533 wcex
.lpszClassName
= szWindowClass
;
1534 wcex
.hIconSm
= LoadIcon(wcex
.hInstance
, (LPCTSTR
)IDI_SMALL
);
1536 return RegisterClassEx(&wcex
);
1539 ATOM
MyRegisterBlameClass(HINSTANCE hResource
)
1543 wcex
.cbSize
= sizeof(WNDCLASSEX
);
1545 wcex
.style
= CS_HREDRAW
| CS_VREDRAW
;
1546 wcex
.lpfnWndProc
= (WNDPROC
)WndBlameProc
;
1547 wcex
.cbClsExtra
= 0;
1548 wcex
.cbWndExtra
= 0;
1549 wcex
.hInstance
= hResource
;
1550 wcex
.hIcon
= LoadIcon(hResource
, (LPCTSTR
)IDI_TortoiseGitBlameView
);
1551 wcex
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
1552 wcex
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+1);
1553 wcex
.lpszMenuName
= 0;
1554 wcex
.lpszClassName
= _T("TortoiseGitBlameViewBlame");
1555 wcex
.hIconSm
= LoadIcon(wcex
.hInstance
, (LPCTSTR
)IDI_SMALL
);
1557 return RegisterClassEx(&wcex
);
1560 ATOM
MyRegisterHeaderClass(HINSTANCE hResource
)
1564 wcex
.cbSize
= sizeof(WNDCLASSEX
);
1566 wcex
.style
= CS_HREDRAW
| CS_VREDRAW
;
1567 wcex
.lpfnWndProc
= (WNDPROC
)WndHeaderProc
;
1568 wcex
.cbClsExtra
= 0;
1569 wcex
.cbWndExtra
= 0;
1570 wcex
.hInstance
= hResource
;
1571 wcex
.hIcon
= LoadIcon(hResource
, (LPCTSTR
)IDI_TortoiseGitBlameView
);
1572 wcex
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
1573 wcex
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+1);
1574 wcex
.lpszMenuName
= 0;
1575 wcex
.lpszClassName
= _T("TortoiseGitBlameViewHeader");
1576 wcex
.hIconSm
= LoadIcon(wcex
.hInstance
, (LPCTSTR
)IDI_SMALL
);
1578 return RegisterClassEx(&wcex
);
1581 ATOM
MyRegisterLocatorClass(HINSTANCE hResource
)
1585 wcex
.cbSize
= sizeof(WNDCLASSEX
);
1587 wcex
.style
= CS_HREDRAW
| CS_VREDRAW
;
1588 wcex
.lpfnWndProc
= (WNDPROC
)WndLocatorProc
;
1589 wcex
.cbClsExtra
= 0;
1590 wcex
.cbWndExtra
= 0;
1591 wcex
.hInstance
= hResource
;
1592 wcex
.hIcon
= LoadIcon(hResource
, (LPCTSTR
)IDI_TortoiseGitBlameView
);
1593 wcex
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
1594 wcex
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+1);
1595 wcex
.lpszMenuName
= 0;
1596 wcex
.lpszClassName
= _T("TortoiseGitBlameViewLocator");
1597 wcex
.hIconSm
= LoadIcon(wcex
.hInstance
, (LPCTSTR
)IDI_SMALL
);
1599 return RegisterClassEx(&wcex
);
1602 BOOL
InitInstance(HINSTANCE hResource
, int nCmdShow
)
1604 app
.wMain
= CreateWindow(szWindowClass
, szTitle
, WS_OVERLAPPEDWINDOW
,
1605 CW_USEDEFAULT
, 0, CW_USEDEFAULT
, 0, NULL
, NULL
, hResource
, NULL
);
1612 CRegStdWORD
pos(_T("Software\\TortoiseGit\\TBlamePos"), 0);
1613 CRegStdWORD
width(_T("Software\\TortoiseGit\\TBlameSize"), 0);
1614 CRegStdWORD
state(_T("Software\\TortoiseGit\\TBlameState"), 0);
1615 if (DWORD(pos
) && DWORD(width
))
1618 rc
.left
= LOWORD(DWORD(pos
));
1619 rc
.top
= HIWORD(DWORD(pos
));
1620 rc
.right
= rc
.left
+ LOWORD(DWORD(width
));
1621 rc
.bottom
= rc
.top
+ HIWORD(DWORD(width
));
1622 HMONITOR hMon
= MonitorFromRect(&rc
, MONITOR_DEFAULTTONULL
);
1625 // only restore the window position if the monitor is valid
1626 MoveWindow(app
.wMain
, LOWORD(DWORD(pos
)), HIWORD(DWORD(pos
)),
1627 LOWORD(DWORD(width
)), HIWORD(DWORD(width
)), FALSE
);
1630 if (DWORD(state
) == SW_MAXIMIZE
)
1631 ShowWindow(app
.wMain
, SW_MAXIMIZE
);
1633 ShowWindow(app
.wMain
, nCmdShow
);
1634 UpdateWindow(app
.wMain
);
1636 //Create the tooltips
1638 INITCOMMONCONTROLSEX iccex
;
1639 app
.hwndTT
; // handle to the ToolTip control
1641 RECT rect
; // for client area coordinates
1642 iccex
.dwICC
= ICC_WIN95_CLASSES
;
1643 iccex
.dwSize
= sizeof(INITCOMMONCONTROLSEX
);
1644 InitCommonControlsEx(&iccex
);
1646 /* CREATE A TOOLTIP WINDOW */
1647 app
.hwndTT
= CreateWindowEx(WS_EX_TOPMOST
,
1650 WS_POPUP
| TTS_NOPREFIX
| TTS_ALWAYSTIP
,
1661 SetWindowPos(app
.hwndTT
,
1667 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
1669 /* GET COORDINATES OF THE MAIN CLIENT AREA */
1670 GetClientRect (app
.wBlame
, &rect
);
1672 /* INITIALIZE MEMBERS OF THE TOOLINFO STRUCTURE */
1673 ti
.cbSize
= sizeof(TOOLINFO
);
1674 ti
.uFlags
= TTF_TRACK
| TTF_ABSOLUTE
;//TTF_SUBCLASS | TTF_PARSELINKS;
1675 ti
.hwnd
= app
.wBlame
;
1676 ti
.hinst
= app
.hResource
;
1678 ti
.lpszText
= LPSTR_TEXTCALLBACK
;
1679 // ToolTip control will cover the whole window
1680 ti
.rect
.left
= rect
.left
;
1681 ti
.rect
.top
= rect
.top
;
1682 ti
.rect
.right
= rect
.right
;
1683 ti
.rect
.bottom
= rect
.bottom
;
1685 /* SEND AN ADDTOOL MESSAGE TO THE TOOLTIP CONTROL WINDOW */
1686 SendMessage(app
.hwndTT
, TTM_ADDTOOL
, 0, (LPARAM
) (LPTOOLINFO
) &ti
);
1687 SendMessage(app
.hwndTT
, TTM_SETMAXTIPWIDTH
, 0, 600);
1688 //SendMessage(app.hwndTT, TTM_SETDELAYTIME, TTDT_AUTOPOP, MAKELONG(50000, 0));
1689 //SendMessage(app.hwndTT, TTM_SETDELAYTIME, TTDT_RESHOW, MAKELONG(1000, 0));
1691 uFindReplaceMsg
= RegisterWindowMessage(FINDMSGSTRING
);
1696 void CTortoiseGitBlameView::InitSize()
1701 ::GetClientRect(wMain
, &rc
);
1702 ::SetWindowPos(wHeader
, 0, rc
.left
, rc
.top
, rc
.right
-rc
.left
, HEADER_HEIGHT
, 0);
1703 rc
.top
+= HEADER_HEIGHT
;
1704 blamerc
.left
= rc
.left
;
1705 blamerc
.top
= rc
.top
;
1706 LONG w
= GetBlameWidth();
1707 blamerc
.right
= w
> abs(rc
.right
- rc
.left
) ? rc
.right
: w
+ rc
.left
;
1708 blamerc
.bottom
= rc
.bottom
;
1709 sourcerc
.left
= blamerc
.right
;
1710 sourcerc
.top
= rc
.top
;
1711 sourcerc
.bottom
= rc
.bottom
;
1712 sourcerc
.right
= rc
.right
;
1715 ::OffsetRect(&blamerc
, LOCATOR_WIDTH
, 0);
1716 ::OffsetRect(&sourcerc
, LOCATOR_WIDTH
, 0);
1717 sourcerc
.right
-= LOCATOR_WIDTH
;
1719 ::InvalidateRect(wMain
, NULL
, FALSE
);
1720 ::SetWindowPos(m_wEditor
, 0, sourcerc
.left
, sourcerc
.top
, sourcerc
.right
- sourcerc
.left
, sourcerc
.bottom
- sourcerc
.top
, 0);
1721 ::SetWindowPos(wBlame
, 0, blamerc
.left
, blamerc
.top
, blamerc
.right
- blamerc
.left
, blamerc
.bottom
- blamerc
.top
, 0);
1723 ::SetWindowPos(wLocator
, 0, 0, blamerc
.top
, LOCATOR_WIDTH
, blamerc
.bottom
- blamerc
.top
, SWP_SHOWWINDOW
);
1725 ::ShowWindow(wLocator
, SW_HIDE
);
1729 LRESULT CALLBACK
WndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1731 if (message
== uFindReplaceMsg
)
1733 LPFINDREPLACE lpfr
= (LPFINDREPLACE
)lParam
;
1735 // If the FR_DIALOGTERM flag is set,
1736 // invalidate the handle identifying the dialog box.
1737 if (lpfr
->Flags
& FR_DIALOGTERM
)
1739 app
.currentDialog
= NULL
;
1742 if (lpfr
->Flags
& FR_FINDNEXT
)
1744 app
.DoSearch(lpfr
->lpstrFindWhat
, lpfr
->Flags
);
1751 app
.m_wEditor
= ::CreateWindow(
1754 WS_CHILD
| WS_VSCROLL
| WS_HSCROLL
| WS_CLIPCHILDREN
,
1761 app
.InitialiseEditor();
1762 ::ShowWindow(app
.m_wEditor
, SW_SHOW
);
1763 ::SetFocus(app
.m_wEditor
);
1764 app
.wBlame
= ::CreateWindow(
1765 _T("TortoiseGitBlameViewBlame"),
1767 WS_CHILD
| WS_CLIPCHILDREN
,
1774 ::ShowWindow(app
.wBlame
, SW_SHOW
);
1775 app
.wHeader
= ::CreateWindow(
1776 _T("TortoiseGitBlameViewHeader"),
1778 WS_CHILD
| WS_CLIPCHILDREN
| WS_BORDER
,
1785 ::ShowWindow(app
.wHeader
, SW_SHOW
);
1786 app
.wLocator
= ::CreateWindow(
1787 _T("TortoiseGitBlameViewLocator"),
1789 WS_CHILD
| WS_CLIPCHILDREN
| WS_BORDER
,
1796 ::ShowWindow(app
.wLocator
, SW_SHOW
);
1807 app
.Command(LOWORD(wParam
));
1810 app
.Notify(reinterpret_cast<SCNotification
*>(lParam
));
1817 CRegStdWORD
pos(_T("Software\\TortoiseGit\\TBlamePos"), 0);
1818 CRegStdWORD
width(_T("Software\\TortoiseGit\\TBlameSize"), 0);
1819 CRegStdWORD
state(_T("Software\\TortoiseGit\\TBlameState"), 0);
1821 GetWindowRect(app
.wMain
, &rc
);
1822 if ((rc
.left
>= 0)&&(rc
.top
>= 0))
1824 pos
= MAKELONG(rc
.left
, rc
.top
);
1825 width
= MAKELONG(rc
.right
-rc
.left
, rc
.bottom
-rc
.top
);
1827 WINDOWPLACEMENT wp
= {0};
1828 wp
.length
= sizeof(WINDOWPLACEMENT
);
1829 GetWindowPlacement(app
.wMain
, &wp
);
1831 ::DestroyWindow(app
.m_wEditor
);
1832 ::PostQuitMessage(0);
1836 ::SetFocus(app
.wBlame
);
1839 return DefWindowProc(hWnd
, message
, wParam
, lParam
);
1844 LRESULT CALLBACK
WndBlameProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1847 TRACKMOUSEEVENT mevt
;
1854 hDC
= BeginPaint(app
.wBlame
, &ps
);
1856 EndPaint(app
.wBlame
, &ps
);
1859 app
.Command(LOWORD(wParam
));
1862 switch (((LPNMHDR
)lParam
)->code
)
1864 case TTN_GETDISPINFO
:
1866 LPNMHDR pNMHDR
= (LPNMHDR
)lParam
;
1867 NMTTDISPINFOA
* pTTTA
= (NMTTDISPINFOA
*)pNMHDR
;
1868 NMTTDISPINFOW
* pTTTW
= (NMTTDISPINFOW
*)pNMHDR
;
1870 DWORD ptW
= GetMessagePos();
1871 point
.x
= GET_X_LPARAM(ptW
);
1872 point
.y
= GET_Y_LPARAM(ptW
);
1873 ::ScreenToClient(app
.wBlame
, &point
);
1874 LONG_PTR line
= app
.SendEditor(SCI_GETFIRSTVISIBLELINE
);
1875 LONG_PTR height
= app
.SendEditor(SCI_TEXTHEIGHT
);
1876 line
= line
+ (point
.y
/height
);
1877 if (line
>= (LONG
)app
.revs
.size())
1881 LONG rev
= app
.revs
[line
];
1882 if (line
>= (LONG
)app
.revs
.size())
1885 SecureZeroMemory(app
.m_szTip
, sizeof(app
.m_szTip
));
1886 SecureZeroMemory(app
.m_wszTip
, sizeof(app
.m_wszTip
));
1887 std::map
<LONG
, CString
>::iterator iter
;
1888 if ((iter
= app
.logmessages
.find(rev
)) != app
.logmessages
.end())
1893 msg
+= app
.authors
[line
];
1897 if (!ShowAuthor
) msg
+= " ";
1898 msg
+= app
.dates
[line
];
1900 if (!ShowAuthor
|| !ShowDate
)
1902 msg
+= iter
->second
;
1903 // an empty tooltip string will deactivate the tooltips,
1904 // which means we must make sure that the tooltip won't
1908 if (pNMHDR
->code
== TTN_NEEDTEXTA
)
1910 lstrcpyn(app
.m_szTip
, msg
.c_str(), MAX_LOG_LENGTH
*2);
1911 app
.StringExpand(app
.m_szTip
);
1912 pTTTA
->lpszText
= app
.m_szTip
;
1916 pTTTW
->lpszText
= app
.m_wszTip
;
1917 ::MultiByteToWideChar( CP_ACP
, 0, msg
.c_str(), min(msg
.size(), MAX_LOG_LENGTH
*2), app
.m_wszTip
, MAX_LOG_LENGTH
*2);
1918 app
.StringExpand(app
.m_wszTip
);
1930 app
.m_mouserev
= -2;
1931 app
.m_mouseauthor
.clear();
1932 app
.ttVisible
= FALSE
;
1933 SendMessage(app
.hwndTT
, TTM_TRACKACTIVATE
, FALSE
, 0);
1934 ::InvalidateRect(app
.wBlame
, NULL
, FALSE
);
1938 mevt
.cbSize
= sizeof(TRACKMOUSEEVENT
);
1939 mevt
.dwFlags
= TME_LEAVE
;
1940 mevt
.dwHoverTime
= HOVER_DEFAULT
;
1941 mevt
.hwndTrack
= app
.wBlame
;
1942 ::TrackMouseEvent(&mevt
);
1943 POINT pt
= {((int)(short)LOWORD(lParam
)), ((int)(short)HIWORD(lParam
))};
1944 ClientToScreen(app
.wBlame
, &pt
);
1947 SendMessage(app
.hwndTT
, TTM_TRACKPOSITION
, 0, MAKELONG(pt
.x
, pt
.y
));
1951 ti
.cbSize
= sizeof(TOOLINFO
);
1952 ti
.hwnd
= app
.wBlame
;
1954 SendMessage(app
.hwndTT
, TTM_TRACKACTIVATE
, TRUE
, (LPARAM
)&ti
);
1956 int y
= ((int)(short)HIWORD(lParam
));
1957 LONG_PTR line
= app
.SendEditor(SCI_GETFIRSTVISIBLELINE
);
1958 LONG_PTR height
= app
.SendEditor(SCI_TEXTHEIGHT
);
1959 line
= line
+ (y
/height
);
1960 app
.ttVisible
= (line
< (LONG
)app
.revs
.size());
1961 if ( app
.ttVisible
)
1963 if (app
.authors
[line
].compare(app
.m_mouseauthor
) != 0)
1965 app
.m_mouseauthor
= app
.authors
[line
];
1967 if (app
.revs
[line
] != app
.m_mouserev
)
1969 app
.m_mouserev
= app
.revs
[line
];
1970 ::InvalidateRect(app
.wBlame
, NULL
, FALSE
);
1971 SendMessage(app
.hwndTT
, TTM_UPDATE
, 0, 0);
1976 case WM_RBUTTONDOWN
:
1978 case WM_LBUTTONDOWN
:
1982 ::SetFocus(app
.wBlame
);
1983 app
.SendEditor(SCI_GRABFOCUS
);
1985 case WM_CONTEXTMENU
:
1987 if (app
.m_selectedrev
<= 0)
1989 int xPos
= GET_X_LPARAM(lParam
);
1990 int yPos
= GET_Y_LPARAM(lParam
);
1991 if ((xPos
< 0)||(yPos
< 0))
1993 // requested from keyboard, not mouse pointer
1994 // use the center of the window
1996 GetClientRect(app
.wBlame
, &rect
);
1997 xPos
= rect
.right
-rect
.left
;
1998 yPos
= rect
.bottom
-rect
.top
;
2000 HMENU hMenu
= LoadMenu(app
.hResource
, MAKEINTRESOURCE(IDR_BLAMEPOPUP
));
2001 HMENU hPopMenu
= GetSubMenu(hMenu
, 0);
2003 if ( _tcslen(szOrigPath
)==0 )
2005 // Without knowing the original path we cannot blame the previous revision
2006 // because we don't know which filename to pass to tortoiseproc.
2007 EnableMenuItem(hPopMenu
,ID_BLAME_PREVIOUS_REVISION
, MF_DISABLED
|MF_GRAYED
);
2010 TrackPopupMenu(hPopMenu
, TPM_LEFTALIGN
| TPM_RIGHTBUTTON
, xPos
, yPos
, 0, app
.wBlame
, NULL
);
2015 return DefWindowProc(hWnd
, message
, wParam
, lParam
);
2020 LRESULT CALLBACK
WndHeaderProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
2029 hDC
= BeginPaint(app
.wHeader
, &ps
);
2030 app
.DrawHeader(hDC
);
2031 EndPaint(app
.wHeader
, &ps
);
2040 return DefWindowProc(hWnd
, message
, wParam
, lParam
);
2045 LRESULT CALLBACK
WndLocatorProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
2052 hDC
= BeginPaint(app
.wLocator
, &ps
);
2053 app
.DrawLocatorBar(hDC
);
2054 EndPaint(app
.wLocator
, &ps
);
2056 case WM_LBUTTONDOWN
:
2058 if (wParam
& MK_LBUTTON
)
2061 ::GetClientRect(hWnd
, &rect
);
2062 int nLine
= HIWORD(lParam
)*app
.revs
.size()/(rect
.bottom
-rect
.top
);
2066 app
.ScrollToLine(nLine
);
2070 return DefWindowProc(hWnd
, message
, wParam
, lParam
);
2076 void CTortoiseGitBlameView::SetupLexer(CString filename
)
2080 //const char * lineptr = _tcsrchr(filename, '.');
2081 int start
=filename
.ReverseFind(_T('.'));
2084 //_tcscpy_s(line, 20, lineptr+1);
2085 //_tcslwr_s(line, 20);
2086 CString ext
=filename
.Right(filename
.GetLength()-start
-1);
2087 line
=ext
.GetBuffer();
2089 if ((_tcscmp(line
, _T("py"))==0)||
2090 (_tcscmp(line
, _T("pyw"))==0)||
2091 (_tcscmp(line
, _T("pyw"))==0))
2093 SendEditor(SCI_SETLEXER
, SCLEX_PYTHON
);
2094 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("and assert break class continue def del elif \
2095 else except exec finally for from global if import in is lambda None \
2096 not or pass print raise return try while yield")).GetBuffer()));
2097 SetAStyle(SCE_P_DEFAULT
, black
);
2098 SetAStyle(SCE_P_COMMENTLINE
, darkGreen
);
2099 SetAStyle(SCE_P_NUMBER
, RGB(0, 0x80, 0x80));
2100 SetAStyle(SCE_P_STRING
, RGB(0, 0, 0x80));
2101 SetAStyle(SCE_P_CHARACTER
, RGB(0, 0, 0x80));
2102 SetAStyle(SCE_P_WORD
, RGB(0x80, 0, 0x80));
2103 SetAStyle(SCE_P_TRIPLE
, black
);
2104 SetAStyle(SCE_P_TRIPLEDOUBLE
, black
);
2105 SetAStyle(SCE_P_CLASSNAME
, darkBlue
);
2106 SetAStyle(SCE_P_DEFNAME
, darkBlue
);
2107 SetAStyle(SCE_P_OPERATOR
, darkBlue
);
2108 SetAStyle(SCE_P_IDENTIFIER
, darkBlue
);
2109 SetAStyle(SCE_P_COMMENTBLOCK
, darkGreen
);
2110 SetAStyle(SCE_P_STRINGEOL
, red
);
2112 if ((_tcscmp(line
, _T("c"))==0)||
2113 (_tcscmp(line
, _T("cc"))==0)||
2114 (_tcscmp(line
, _T("cpp"))==0)||
2115 (_tcscmp(line
, _T("cxx"))==0)||
2116 (_tcscmp(line
, _T("h"))==0)||
2117 (_tcscmp(line
, _T("hh"))==0)||
2118 (_tcscmp(line
, _T("hpp"))==0)||
2119 (_tcscmp(line
, _T("hxx"))==0)||
2120 (_tcscmp(line
, _T("dlg"))==0)||
2121 (_tcscmp(line
, _T("mak"))==0))
2123 SendEditor(SCI_SETLEXER
, SCLEX_CPP
);
2124 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("and and_eq asm auto bitand bitor bool break \
2125 case catch char class compl const const_cast continue \
2126 default delete do double dynamic_cast else enum explicit export extern false float for \
2127 friend goto if inline int long mutable namespace new not not_eq \
2128 operator or or_eq private protected public \
2129 register reinterpret_cast return short signed sizeof static static_cast struct switch \
2130 template this throw true try typedef typeid typename union unsigned using \
2131 virtual void volatile wchar_t while xor xor_eq")).GetBuffer()));
2132 SendEditor(SCI_SETKEYWORDS
, 3, (LPARAM
)(m_TextView
.StringForControl(_T("a addindex addtogroup anchor arg attention \
2133 author b brief bug c class code date def defgroup deprecated dontinclude \
2134 e em endcode endhtmlonly endif endlatexonly endlink endverbatim enum example exception \
2135 f$ f[ f] file fn hideinitializer htmlinclude htmlonly \
2136 if image include ingroup internal invariant interface latexonly li line link \
2137 mainpage name namespace nosubgrouping note overload \
2138 p page par param post pre ref relates remarks return retval \
2139 sa section see showinitializer since skip skipline struct subsection \
2140 test throw todo typedef union until \
2141 var verbatim verbinclude version warning weakgroup $ @ \\ & < > # { }")).GetBuffer()));
2144 if (_tcscmp(line
, _T("cs"))==0)
2146 SendEditor(SCI_SETLEXER
, SCLEX_CPP
);
2147 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("abstract as base bool break byte case catch char checked class \
2148 const continue decimal default delegate do double else enum \
2149 event explicit extern false finally fixed float for foreach goto if \
2150 implicit in int interface internal is lock long namespace new null \
2151 object operator out override params private protected public \
2152 readonly ref return sbyte sealed short sizeof stackalloc static \
2153 string struct switch this throw true try typeof uint ulong \
2154 unchecked unsafe ushort using virtual void while")).GetBuffer()));
2157 if ((_tcscmp(line
, _T("rc"))==0)||
2158 (_tcscmp(line
, _T("rc2"))==0))
2160 SendEditor(SCI_SETLEXER
, SCLEX_CPP
);
2161 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("ACCELERATORS ALT AUTO3STATE AUTOCHECKBOX AUTORADIOBUTTON \
2162 BEGIN BITMAP BLOCK BUTTON CAPTION CHARACTERISTICS CHECKBOX CLASS \
2163 COMBOBOX CONTROL CTEXT CURSOR DEFPUSHBUTTON DIALOG DIALOGEX DISCARDABLE \
2164 EDITTEXT END EXSTYLE FONT GROUPBOX ICON LANGUAGE LISTBOX LTEXT \
2165 MENU MENUEX MENUITEM MESSAGETABLE POPUP \
2166 PUSHBUTTON RADIOBUTTON RCDATA RTEXT SCROLLBAR SEPARATOR SHIFT STATE3 \
2167 STRINGTABLE STYLE TEXTINCLUDE VALUE VERSION VERSIONINFO VIRTKEY")).GetBuffer()));
2170 if ((_tcscmp(line
, _T("idl"))==0)||
2171 (_tcscmp(line
, _T("odl"))==0))
2173 SendEditor(SCI_SETLEXER
, SCLEX_CPP
);
2174 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("aggregatable allocate appobject arrays async async_uuid \
2176 bindable boolean broadcast byte byte_count \
2177 call_as callback char coclass code comm_status \
2178 const context_handle context_handle_noserialize \
2179 context_handle_serialize control cpp_quote custom \
2180 decode default defaultbind defaultcollelem \
2181 defaultvalue defaultvtable dispinterface displaybind dllname \
2183 enable_allocate encode endpoint entry enum error_status_t \
2185 fault_status first_is float \
2186 handle_t heap helpcontext helpfile helpstring \
2187 helpstringcontext helpstringdll hidden hyper \
2188 id idempotent ignore iid_as iid_is immediatebind implicit_handle \
2189 import importlib in include in_line int __int64 __int3264 interface \
2190 last_is lcid length_is library licensed local long \
2191 max_is maybe message methods midl_pragma \
2192 midl_user_allocate midl_user_free min_is module ms_union \
2193 ncacn_at_dsp ncacn_dnet_nsp ncacn_http ncacn_ip_tcp \
2194 ncacn_nb_ipx ncacn_nb_nb ncacn_nb_tcp ncacn_np \
2195 ncacn_spx ncacn_vns_spp ncadg_ip_udp ncadg_ipx ncadg_mq \
2196 ncalrpc nocode nonbrowsable noncreatable nonextensible notify \
2197 object odl oleautomation optimize optional out out_of_line \
2198 pipe pointer_default pragma properties propget propput propputref \
2200 range readonly ref represent_as requestedit restricted retval \
2201 shape short signed size_is small source strict_context_handle \
2202 string struct switch switch_is switch_type \
2203 transmit_as typedef \
2204 uidefault union unique unsigned user_marshal usesgetlasterror uuid \
2205 v1_enum vararg version void wchar_t wire_marshal")).GetBuffer()));
2208 if (_tcscmp(line
, _T("java"))==0)
2210 SendEditor(SCI_SETLEXER
, SCLEX_CPP
);
2211 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("abstract assert boolean break byte case catch char class \
2212 const continue default do double else extends final finally float for future \
2213 generic goto if implements import inner instanceof int interface long \
2214 native new null outer package private protected public rest \
2215 return short static super switch synchronized this throw throws \
2216 transient try var void volatile while")).GetBuffer()));
2219 if (_tcscmp(line
, _T("js"))==0)
2221 SendEditor(SCI_SETLEXER
, SCLEX_CPP
);
2222 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("abstract boolean break byte case catch char class \
2223 const continue debugger default delete do double else enum export extends \
2224 final finally float for function goto if implements import in instanceof \
2225 int interface long native new package private protected public \
2226 return short static super switch synchronized this throw throws \
2227 transient try typeof var void volatile while with")).GetBuffer()));
2230 if ((_tcscmp(line
, _T("pas"))==0)||
2231 (_tcscmp(line
, _T("dpr"))==0)||
2232 (_tcscmp(line
, _T("pp"))==0))
2234 SendEditor(SCI_SETLEXER
, SCLEX_PASCAL
);
2235 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("and array as begin case class const constructor \
2236 destructor div do downto else end except file finally \
2237 for function goto if implementation in inherited \
2238 interface is mod not object of on or packed \
2239 procedure program property raise record repeat \
2240 set shl shr then threadvar to try type unit \
2241 until uses var while with xor")).GetBuffer()));
2244 if ((_tcscmp(line
, _T("as"))==0)||
2245 (_tcscmp(line
, _T("asc"))==0)||
2246 (_tcscmp(line
, _T("jsfl"))==0))
2248 SendEditor(SCI_SETLEXER
, SCLEX_CPP
);
2249 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("add and break case catch class continue default delete do \
2250 dynamic else eq extends false finally for function ge get gt if implements import in \
2251 instanceof interface intrinsic le lt ne new not null or private public return \
2252 set static super switch this throw true try typeof undefined var void while with")).GetBuffer()));
2253 SendEditor(SCI_SETKEYWORDS
, 1, (LPARAM
)(m_TextView
.StringForControl(_T("Array Arguments Accessibility Boolean Button Camera Color \
2254 ContextMenu ContextMenuItem Date Error Function Key LoadVars LocalConnection Math \
2255 Microphone Mouse MovieClip MovieClipLoader NetConnection NetStream Number Object \
2256 PrintJob Selection SharedObject Sound Stage String StyleSheet System TextField \
2257 TextFormat TextSnapshot Video Void XML XMLNode XMLSocket \
2258 _accProps _focusrect _global _highquality _parent _quality _root _soundbuftime \
2259 arguments asfunction call capabilities chr clearInterval duplicateMovieClip \
2260 escape eval fscommand getProperty getTimer getURL getVersion gotoAndPlay gotoAndStop \
2261 ifFrameLoaded Infinity -Infinity int isFinite isNaN length loadMovie loadMovieNum \
2262 loadVariables loadVariablesNum maxscroll mbchr mblength mbord mbsubstring MMExecute \
2263 NaN newline nextFrame nextScene on onClipEvent onUpdate ord parseFloat parseInt play \
2264 prevFrame prevScene print printAsBitmap printAsBitmapNum printNum random removeMovieClip \
2265 scroll set setInterval setProperty startDrag stop stopAllSounds stopDrag substring \
2266 targetPath tellTarget toggleHighQuality trace unescape unloadMovie unLoadMovieNum updateAfterEvent")).GetBuffer()));
2269 if ((_tcscmp(line
, _T("html"))==0)||
2270 (_tcscmp(line
, _T("htm"))==0)||
2271 (_tcscmp(line
, _T("shtml"))==0)||
2272 (_tcscmp(line
, _T("htt"))==0)||
2273 (_tcscmp(line
, _T("xml"))==0)||
2274 (_tcscmp(line
, _T("asp"))==0)||
2275 (_tcscmp(line
, _T("xsl"))==0)||
2276 (_tcscmp(line
, _T("php"))==0)||
2277 (_tcscmp(line
, _T("xhtml"))==0)||
2278 (_tcscmp(line
, _T("phtml"))==0)||
2279 (_tcscmp(line
, _T("cfm"))==0)||
2280 (_tcscmp(line
, _T("tpl"))==0)||
2281 (_tcscmp(line
, _T("dtd"))==0)||
2282 (_tcscmp(line
, _T("hta"))==0)||
2283 (_tcscmp(line
, _T("htd"))==0)||
2284 (_tcscmp(line
, _T("wxs"))==0))
2286 SendEditor(SCI_SETLEXER
, SCLEX_HTML
);
2287 SendEditor(SCI_SETSTYLEBITS
, 7);
2288 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("a abbr acronym address applet area b base basefont \
2289 bdo big blockquote body br button caption center \
2290 cite code col colgroup dd del dfn dir div dl dt em \
2291 fieldset font form frame frameset h1 h2 h3 h4 h5 h6 \
2292 head hr html i iframe img input ins isindex kbd label \
2293 legend li link map menu meta noframes noscript \
2294 object ol optgroup option p param pre q s samp \
2295 script select small span strike strong style sub sup \
2296 table tbody td textarea tfoot th thead title tr tt u ul \
2297 var xml xmlns abbr accept-charset accept accesskey action align alink \
2298 alt archive axis background bgcolor border \
2299 cellpadding cellspacing char charoff charset checked cite \
2300 class classid clear codebase codetype color cols colspan \
2301 compact content coords \
2302 data datafld dataformatas datapagesize datasrc datetime \
2303 declare defer dir disabled enctype event \
2304 face for frame frameborder \
2305 headers height href hreflang hspace http-equiv \
2306 id ismap label lang language leftmargin link longdesc \
2307 marginwidth marginheight maxlength media method multiple \
2308 name nohref noresize noshade nowrap \
2309 object onblur onchange onclick ondblclick onfocus \
2310 onkeydown onkeypress onkeyup onload onmousedown \
2311 onmousemove onmouseover onmouseout onmouseup \
2312 onreset onselect onsubmit onunload \
2313 profile prompt readonly rel rev rows rowspan rules \
2314 scheme scope selected shape size span src standby start style \
2315 summary tabindex target text title topmargin type usemap \
2316 valign value valuetype version vlink vspace width \
2317 text password checkbox radio submit reset \
2318 file hidden image")).GetBuffer()));
2319 SendEditor(SCI_SETKEYWORDS
, 1, (LPARAM
)(m_TextView
.StringForControl(_T("assign audio block break catch choice clear disconnect else elseif \
2320 emphasis enumerate error exit field filled form goto grammar help \
2321 if initial link log menu meta noinput nomatch object option p paragraph \
2322 param phoneme prompt property prosody record reprompt return s say-as \
2323 script sentence subdialog submit throw transfer value var voice vxml")).GetBuffer()));
2324 SendEditor(SCI_SETKEYWORDS
, 2, (LPARAM
)(m_TextView
.StringForControl(_T("accept age alphabet anchor application base beep bridge category charset \
2325 classid cond connecttimeout content contour count dest destexpr dtmf dtmfterm \
2326 duration enctype event eventexpr expr expritem fetchtimeout finalsilence \
2327 gender http-equiv id level maxage maxstale maxtime message messageexpr \
2328 method mime modal mode name namelist next nextitem ph pitch range rate \
2329 scope size sizeexpr skiplist slot src srcexpr sub time timeexpr timeout \
2330 transferaudio type value variant version volume xml:lang")).GetBuffer()));
2331 SendEditor(SCI_SETKEYWORDS
, 3, (LPARAM
)(m_TextView
.StringForControl(_T("and assert break class continue def del elif \
2332 else except exec finally for from global if import in is lambda None \
2333 not or pass print raise return try while yield")).GetBuffer()));
2334 SendEditor(SCI_SETKEYWORDS
, 4, (LPARAM
)(m_TextView
.StringForControl(_T("and argv as argc break case cfunction class continue declare default do \
2335 die echo else elseif empty enddeclare endfor endforeach endif endswitch \
2336 endwhile e_all e_parse e_error e_warning eval exit extends false for \
2337 foreach function global http_cookie_vars http_get_vars http_post_vars \
2338 http_post_files http_env_vars http_server_vars if include include_once \
2339 list new not null old_function or parent php_os php_self php_version \
2340 print require require_once return static switch stdclass this true var \
2341 xor virtual while __file__ __line__ __sleep __wakeup")).GetBuffer()));
2343 SetAStyle(SCE_H_TAG
, darkBlue
);
2344 SetAStyle(SCE_H_TAGUNKNOWN
, red
);
2345 SetAStyle(SCE_H_ATTRIBUTE
, darkBlue
);
2346 SetAStyle(SCE_H_ATTRIBUTEUNKNOWN
, red
);
2347 SetAStyle(SCE_H_NUMBER
, RGB(0x80,0,0x80));
2348 SetAStyle(SCE_H_DOUBLESTRING
, RGB(0,0x80,0));
2349 SetAStyle(SCE_H_SINGLESTRING
, RGB(0,0x80,0));
2350 SetAStyle(SCE_H_OTHER
, RGB(0x80,0,0x80));
2351 SetAStyle(SCE_H_COMMENT
, RGB(0x80,0x80,0));
2352 SetAStyle(SCE_H_ENTITY
, RGB(0x80,0,0x80));
2354 SetAStyle(SCE_H_TAGEND
, darkBlue
);
2355 SetAStyle(SCE_H_XMLSTART
, darkBlue
); // <?
2356 SetAStyle(SCE_H_QUESTION
, darkBlue
); // <?
2357 SetAStyle(SCE_H_XMLEND
, darkBlue
); // ?>
2358 SetAStyle(SCE_H_SCRIPT
, darkBlue
); // <script
2359 SetAStyle(SCE_H_ASP
, RGB(0x4F, 0x4F, 0), RGB(0xFF, 0xFF, 0)); // <% ... %>
2360 SetAStyle(SCE_H_ASPAT
, RGB(0x4F, 0x4F, 0), RGB(0xFF, 0xFF, 0)); // <%@ ... %>
2362 SetAStyle(SCE_HB_DEFAULT
, black
);
2363 SetAStyle(SCE_HB_COMMENTLINE
, darkGreen
);
2364 SetAStyle(SCE_HB_NUMBER
, RGB(0,0x80,0x80));
2365 SetAStyle(SCE_HB_WORD
, darkBlue
);
2366 SendEditor(SCI_STYLESETBOLD
, SCE_HB_WORD
, 1);
2367 SetAStyle(SCE_HB_STRING
, RGB(0x80,0,0x80));
2368 SetAStyle(SCE_HB_IDENTIFIER
, black
);
2370 // This light blue is found in the windows system palette so is safe to use even in 256 colour modes.
2371 // Show the whole section of VBScript with light blue background
2372 for (int bstyle
=SCE_HB_DEFAULT
; bstyle
<=SCE_HB_STRINGEOL
; bstyle
++) {
2373 SendEditor(SCI_STYLESETFONT
, bstyle
,
2374 reinterpret_cast<LPARAM
>(m_TextView
.StringForControl(_T("Lucida Console")).GetBuffer()));
2375 SendEditor(SCI_STYLESETBACK
, bstyle
, lightBlue
);
2376 // This call extends the backround colour of the last style on the line to the edge of the window
2377 SendEditor(SCI_STYLESETEOLFILLED
, bstyle
, 1);
2379 SendEditor(SCI_STYLESETBACK
, SCE_HB_STRINGEOL
, RGB(0x7F,0x7F,0xFF));
2380 SendEditor(SCI_STYLESETFONT
, SCE_HB_COMMENTLINE
,
2381 reinterpret_cast<LPARAM
>(m_TextView
.StringForControl(_T("Lucida Console")).GetBuffer()));
2383 SetAStyle(SCE_HBA_DEFAULT
, black
);
2384 SetAStyle(SCE_HBA_COMMENTLINE
, darkGreen
);
2385 SetAStyle(SCE_HBA_NUMBER
, RGB(0,0x80,0x80));
2386 SetAStyle(SCE_HBA_WORD
, darkBlue
);
2387 SendEditor(SCI_STYLESETBOLD
, SCE_HBA_WORD
, 1);
2388 SetAStyle(SCE_HBA_STRING
, RGB(0x80,0,0x80));
2389 SetAStyle(SCE_HBA_IDENTIFIER
, black
);
2391 // Show the whole section of ASP VBScript with bright yellow background
2392 for (int bastyle
=SCE_HBA_DEFAULT
; bastyle
<=SCE_HBA_STRINGEOL
; bastyle
++) {
2393 SendEditor(SCI_STYLESETFONT
, bastyle
,
2394 reinterpret_cast<LPARAM
>(m_TextView
.StringForControl(_T("Lucida Console")).GetBuffer()));
2395 SendEditor(SCI_STYLESETBACK
, bastyle
, RGB(0xFF, 0xFF, 0));
2396 // This call extends the backround colour of the last style on the line to the edge of the window
2397 SendEditor(SCI_STYLESETEOLFILLED
, bastyle
, 1);
2399 SendEditor(SCI_STYLESETBACK
, SCE_HBA_STRINGEOL
, RGB(0xCF,0xCF,0x7F));
2400 SendEditor(SCI_STYLESETFONT
, SCE_HBA_COMMENTLINE
,
2401 reinterpret_cast<LPARAM
>(m_TextView
.StringForControl(_T("Lucida Console")).GetBuffer()));
2403 // If there is no need to support embedded Javascript, the following code can be dropped.
2404 // Javascript will still be correctly processed but will be displayed in just the default style.
2406 SetAStyle(SCE_HJ_START
, RGB(0x80,0x80,0));
2407 SetAStyle(SCE_HJ_DEFAULT
, black
);
2408 SetAStyle(SCE_HJ_COMMENT
, darkGreen
);
2409 SetAStyle(SCE_HJ_COMMENTLINE
, darkGreen
);
2410 SetAStyle(SCE_HJ_COMMENTDOC
, darkGreen
);
2411 SetAStyle(SCE_HJ_NUMBER
, RGB(0,0x80,0x80));
2412 SetAStyle(SCE_HJ_WORD
, black
);
2413 SetAStyle(SCE_HJ_KEYWORD
, darkBlue
);
2414 SetAStyle(SCE_HJ_DOUBLESTRING
, RGB(0x80,0,0x80));
2415 SetAStyle(SCE_HJ_SINGLESTRING
, RGB(0x80,0,0x80));
2416 SetAStyle(SCE_HJ_SYMBOLS
, black
);
2418 SetAStyle(SCE_HJA_START
, RGB(0x80,0x80,0));
2419 SetAStyle(SCE_HJA_DEFAULT
, black
);
2420 SetAStyle(SCE_HJA_COMMENT
, darkGreen
);
2421 SetAStyle(SCE_HJA_COMMENTLINE
, darkGreen
);
2422 SetAStyle(SCE_HJA_COMMENTDOC
, darkGreen
);
2423 SetAStyle(SCE_HJA_NUMBER
, RGB(0,0x80,0x80));
2424 SetAStyle(SCE_HJA_WORD
, black
);
2425 SetAStyle(SCE_HJA_KEYWORD
, darkBlue
);
2426 SetAStyle(SCE_HJA_DOUBLESTRING
, RGB(0x80,0,0x80));
2427 SetAStyle(SCE_HJA_SINGLESTRING
, RGB(0x80,0,0x80));
2428 SetAStyle(SCE_HJA_SYMBOLS
, black
);
2430 SetAStyle(SCE_HPHP_DEFAULT
, black
);
2431 SetAStyle(SCE_HPHP_HSTRING
, RGB(0x80,0,0x80));
2432 SetAStyle(SCE_HPHP_SIMPLESTRING
, RGB(0x80,0,0x80));
2433 SetAStyle(SCE_HPHP_WORD
, darkBlue
);
2434 SetAStyle(SCE_HPHP_NUMBER
, RGB(0,0x80,0x80));
2435 SetAStyle(SCE_HPHP_VARIABLE
, red
);
2436 SetAStyle(SCE_HPHP_HSTRING_VARIABLE
, red
);
2437 SetAStyle(SCE_HPHP_COMPLEX_VARIABLE
, red
);
2438 SetAStyle(SCE_HPHP_COMMENT
, darkGreen
);
2439 SetAStyle(SCE_HPHP_COMMENTLINE
, darkGreen
);
2440 SetAStyle(SCE_HPHP_OPERATOR
, darkBlue
);
2442 // Show the whole section of Javascript with off white background
2443 for (int jstyle
=SCE_HJ_DEFAULT
; jstyle
<=SCE_HJ_SYMBOLS
; jstyle
++) {
2444 SendEditor(SCI_STYLESETFONT
, jstyle
,
2445 reinterpret_cast<LPARAM
>(m_TextView
.StringForControl(_T("Lucida Console")).GetBuffer()));
2446 SendEditor(SCI_STYLESETBACK
, jstyle
, offWhite
);
2447 SendEditor(SCI_STYLESETEOLFILLED
, jstyle
, 1);
2449 SendEditor(SCI_STYLESETBACK
, SCE_HJ_STRINGEOL
, RGB(0xDF, 0xDF, 0x7F));
2450 SendEditor(SCI_STYLESETEOLFILLED
, SCE_HJ_STRINGEOL
, 1);
2452 // Show the whole section of Javascript with brown background
2453 for (int jastyle
=SCE_HJA_DEFAULT
; jastyle
<=SCE_HJA_SYMBOLS
; jastyle
++) {
2454 SendEditor(SCI_STYLESETFONT
, jastyle
,
2455 reinterpret_cast<LPARAM
>(m_TextView
.StringForControl(_T("Lucida Console")).GetBuffer()));
2456 SendEditor(SCI_STYLESETBACK
, jastyle
, RGB(0xDF, 0xDF, 0x7F));
2457 SendEditor(SCI_STYLESETEOLFILLED
, jastyle
, 1);
2459 SendEditor(SCI_STYLESETBACK
, SCE_HJA_STRINGEOL
, RGB(0x0,0xAF,0x5F));
2460 SendEditor(SCI_STYLESETEOLFILLED
, SCE_HJA_STRINGEOL
, 1);
2465 SendEditor(SCI_SETLEXER
, SCLEX_CPP
);
2468 SendEditor(SCI_COLOURISE
, 0, -1);
2472 void CTortoiseGitBlameView::SetupCppLexer()
2474 SetAStyle(SCE_C_DEFAULT
, RGB(0, 0, 0));
2475 SetAStyle(SCE_C_COMMENT
, RGB(0, 0x80, 0));
2476 SetAStyle(SCE_C_COMMENTLINE
, RGB(0, 0x80, 0));
2477 SetAStyle(SCE_C_COMMENTDOC
, RGB(0, 0x80, 0));
2478 SetAStyle(SCE_C_COMMENTLINEDOC
, RGB(0, 0x80, 0));
2479 SetAStyle(SCE_C_COMMENTDOCKEYWORD
, RGB(0, 0x80, 0));
2480 SetAStyle(SCE_C_COMMENTDOCKEYWORDERROR
, RGB(0, 0x80, 0));
2481 SetAStyle(SCE_C_NUMBER
, RGB(0, 0x80, 0x80));
2482 SetAStyle(SCE_C_WORD
, RGB(0, 0, 0x80));
2483 SendEditor(SCE_C_WORD
, 1);
2484 SetAStyle(SCE_C_STRING
, RGB(0x80, 0, 0x80));
2485 SetAStyle(SCE_C_IDENTIFIER
, RGB(0, 0, 0));
2486 SetAStyle(SCE_C_PREPROCESSOR
, RGB(0x80, 0, 0));
2487 SetAStyle(SCE_C_OPERATOR
, RGB(0x80, 0x80, 0));
2490 int CTortoiseGitBlameView::GetEncode(unsigned char *buff
, int size
, int *bomoffset
)
2492 CFileTextLines textlines
;
2493 CFileTextLines::UnicodeType type
= textlines
.CheckUnicodeType(buff
, size
);
2495 if(type
== CFileTextLines::UTF8BOM
)
2500 if(type
== CFileTextLines::UTF8
)
2503 if(type
== CFileTextLines::UNICODE_LE
)
2512 void CTortoiseGitBlameView::UpdateInfo(int Encode
)
2514 BYTE_VECTOR
&data
= GetDocument()->m_BlameData
;
2520 CLogDataVector
* pRevs
= GetLogData();
2522 this->m_CommitHash
.clear();
2523 this->m_Authors
.clear();
2529 SendEditor(SCI_SETREADONLY
, FALSE
);
2530 SendEditor(SCI_CLEARALL
);
2531 SendEditor(EM_EMPTYUNDOBUFFER
);
2532 SendEditor(SCI_SETSAVEPOINT
);
2533 SendEditor(SCI_CANCEL
);
2534 SendEditor(SCI_SETUNDOCOLLECTION
, 0);
2536 SendEditor(SCI_SETCODEPAGE
, SC_CP_UTF8
);
2539 int encoding
= Encode
;
2540 while( pos
>=0 && current
>=0 && pos
<data
.size() )
2542 current
= data
.findData((const BYTE
*)"\n",1,pos
);
2543 //one=data.Tokenize(_T("\n"),pos);
2545 bool isbound
= ( data
[pos
] == _T('^') );
2547 if( (data
.size() - pos
) >1 && data
[pos
] == _T('^'))
2558 if(git_get_sha1((const char*)&data
[pos
], hash
.m_hash
))
2560 ::MessageBox(NULL
, _T("Can't get hash"), _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
2564 hash
.ConvertFromStrA((char*)&data
[pos
]);
2568 start
=data
.findData((const BYTE
*)")",1,pos
+ 40);
2581 if( pos
<40 && encoding
==0)
2584 encoding
= GetEncode( &data
[start
+2], data
.size() - start
-2, &bomoffset
);
2587 if(encoding
== 1200)
2590 int size
= ((current
- start
-2 - bomoffset
)/2);
2591 TCHAR
*buffer
= strw
.GetBuffer(size
);
2592 memcpy(buffer
, &data
[start
+ 2 + bomoffset
],sizeof(TCHAR
)*size
);
2593 strw
.ReleaseBuffer();
2595 stra
= CUnicodeUtils::GetUTF8(strw
);
2597 }else if(encoding
== CP_UTF8
)
2599 stra
= &data
[start
+ 2 + bomoffset
];
2604 strw
= CUnicodeUtils::GetUnicode(CStringA(&data
[start
+ 2 + bomoffset
]), encoding
);
2605 stra
= CUnicodeUtils::GetUTF8(strw
);
2610 SendEditor(SCI_REPLACESEL
, 0, (LPARAM
)(LPCSTR
)stra
);
2611 SendEditor(SCI_REPLACESEL
, 0, (LPARAM
)(LPCSTR
)"\n\0\0\0");
2614 data
[current
] = '\n';
2619 if(pRevs
->m_HashMap
.find(hash
)!=pRevs
->m_HashMap
.end())
2621 id
=pRevs
->m_HashMap
[hash
];
2626 if(this->m_NoListCommit
.find(hash
) == m_NoListCommit
.end() )
2628 g_Git
.GetLog(vector
,hash
.ToString(),NULL
,1);
2629 this->m_NoListCommit
[hash
].ParserFromLog(vector
);
2634 if(id
>=0 && id
<(int)GetLogData()->size())
2636 m_ID
.push_back(pRevs
->size()-id
);
2637 m_Authors
.push_back(pRevs
->GetGitRevAt(id
).m_AuthorName
);
2641 m_Authors
.push_back(hash
.ToString().Left(6));
2644 m_CommitHash
.push_back(hash
);
2656 file
.Open(this->GetDocument()->m_TempFileName
,CFile::modeRead
);
2658 m_Buffer
= new char[file
.GetLength()+4];
2659 m_Buffer
[file
.GetLength()] =0;
2660 m_Buffer
[file
.GetLength()+1] =0;
2661 m_Buffer
[file
.GetLength()+2] =0;
2662 m_Buffer
[file
.GetLength()+3] =0;
2664 file
.Read(m_Buffer
, file
.GetLength());
2668 int encoding
= GetEncode( (unsigned char *)m_Buffer
, file
.GetLength(), &bomoffset
);
2671 //SendEditor(SCI_SETCODEPAGE, encoding);
2673 //SendEditor(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)(m_Buffer + bomoffset));
2675 SetupLexer(GetDocument()->m_CurrentFileName
);
2677 SendEditor(SCI_SETUNDOCOLLECTION
, 1);
2678 SendEditor(EM_EMPTYUNDOBUFFER
);
2679 SendEditor(SCI_SETSAVEPOINT
);
2680 SendEditor(SCI_GOTOPOS
, 0);
2681 SendEditor(SCI_SETSCROLLWIDTHTRACKING
, TRUE
);
2682 SendEditor(SCI_SETREADONLY
, TRUE
);
2685 m_highestrev
=this->GetLogData()->size()+m_NoListCommit
.size();
2689 this->GetClientRect(rect
);
2690 //this->m_TextView.GetWindowRect(rect);
2691 //this->m_TextView.ScreenToClient(rect);
2692 rect
.left
=this->m_blamewidth
;
2693 this->m_TextView
.MoveWindow(rect
);
2698 CGitBlameLogList
* CTortoiseGitBlameView::GetLogList()
2700 return &(GetDocument()->GetMainFrame()->m_wndOutput
.m_LogList
);
2704 CLogDataVector
* CTortoiseGitBlameView::GetLogData()
2706 return &(GetDocument()->GetMainFrame()->m_wndOutput
.m_LogList
.m_logEntries
);
2709 void CTortoiseGitBlameView::OnSciPainted(NMHDR
*,LRESULT
*)
2714 void CTortoiseGitBlameView::OnLButtonDown(UINT nFlags
,CPoint point
)
2717 LONG_PTR line
= SendEditor(SCI_GETFIRSTVISIBLELINE
);
2718 LONG_PTR height
= SendEditor(SCI_TEXTHEIGHT
);
2719 line
= line
+ (point
.y
/height
);
2721 if (line
< (LONG
)m_CommitHash
.size())
2723 SetSelectedLine(line
);
2724 if (m_CommitHash
[line
] != m_SelectedHash
)
2726 m_SelectedHash
= m_CommitHash
[line
];
2730 this->GetLogList()->SetItemState(this->GetLogList()->GetItemCount()-m_ID
[line
],
2735 pRev
=&this->GetLogData()->GetGitRevAt(this->GetLogList()->GetItemCount()-m_ID
[line
]);
2736 this->GetDocument()->GetMainFrame()->m_wndProperties
.UpdateProperties(pRev
);
2739 this->GetDocument()->GetMainFrame()->m_wndProperties
.UpdateProperties(&m_NoListCommit
[m_CommitHash
[line
]]);
2744 m_SelectedHash
.Empty();
2746 //::InvalidateRect( NULL, FALSE);
2748 this->m_TextView
.Invalidate();
2753 SetSelectedLine(-1);
2756 CView::OnLButtonDown(nFlags
,point
);
2759 void CTortoiseGitBlameView::OnSciGetBkColor(NMHDR
* hdr
, LRESULT
* result
)
2762 SCNotification
*notification
=reinterpret_cast<SCNotification
*>(hdr
);
2764 if ((m_colorage
)&&(notification
->line
< (int)m_CommitHash
.size()))
2766 if(m_CommitHash
[notification
->line
] == this->m_SelectedHash
)
2767 notification
->lParam
= m_selectedauthorcolor
;
2769 notification
->lParam
= InterColor(DWORD(m_regOldLinesColor
), DWORD(m_regNewLinesColor
), (m_ID
[notification
->line
]-m_lowestrev
)*100/((m_highestrev
-m_lowestrev
)+1));
2774 void CTortoiseGitBlameView::FocusOn(GitRev
*pRev
)
2776 m_SelectedHash
= pRev
->m_CommitHash
;
2779 //pRev=&this->GetLogData()->at(this->GetLogList()->GetItemCount()-m_ID[line]);
2780 this->GetDocument()->GetMainFrame()->m_wndProperties
.UpdateProperties(pRev
);
2785 for(i
=0;i
<m_CommitHash
.size();i
++)
2787 if( pRev
->m_CommitHash
== m_CommitHash
[i
] )
2791 this->m_TextView
.Invalidate();
2795 void CTortoiseGitBlameView::OnMouseHover(UINT nFlags
, CPoint point
)
2798 LONG_PTR line
= SendEditor(SCI_GETFIRSTVISIBLELINE
);
2799 LONG_PTR height
= SendEditor(SCI_TEXTHEIGHT
);
2800 line
= line
+ (point
.y
/height
);
2802 if (line
< (LONG
)m_CommitHash
.size())
2804 if (line
!= m_MouseLine
)
2806 m_MouseLine
= line
;//m_CommitHash[line];
2810 pRev
=&this->m_NoListCommit
[m_CommitHash
[line
]];
2814 pRev
=&this->GetLogData()->GetGitRevAt(this->GetLogList()->GetItemCount()-m_ID
[line
]);
2817 this->ClientToScreen(&point
);
2820 str
.Format(_T("%s\n<b>%s</b>\n%s %s\n%s"),pRev
->m_CommitHash
.ToString(),
2823 CAppUtils::FormatDateAndTime( pRev
->m_AuthorDate
, m_DateFormat
),
2825 m_ToolTip
.AddTool(this,str
);
2826 m_ToolTip
.DisplayToolTip(&point
);
2829 this->ScreenToClient(&point
);
2830 rect
.left
=LOCATOR_WIDTH
;
2831 rect
.right
=this->m_blamewidth
+rect
.left
;
2832 rect
.top
=point
.y
-height
;
2833 rect
.bottom
=point
.y
+height
;
2834 this->InvalidateRect(rect
);
2844 void CTortoiseGitBlameView::OnMouseMove(UINT nFlags
, CPoint point
)
2846 TRACKMOUSEEVENT tme
;
2847 tme
.cbSize
=sizeof(TRACKMOUSEEVENT
);
2848 tme
.dwFlags
=TME_HOVER
|TME_LEAVE
;
2849 tme
.hwndTrack
=this->m_hWnd
;
2851 TrackMouseEvent(&tme
);
2855 BOOL
CTortoiseGitBlameView::PreTranslateMessage(MSG
* pMsg
)
2857 m_ToolTip
.RelayEvent(pMsg
);
2858 return CView::PreTranslateMessage(pMsg
);
2861 void CTortoiseGitBlameView::OnEditFind()
2863 m_pFindDialog
=new CFindReplaceDialog();
2865 m_pFindDialog
->Create(TRUE
,_T(""),NULL
,FR_DOWN
,this);
2868 void CTortoiseGitBlameView::OnEditGoto()
2871 if(dlg
.DoModal()==IDOK
)
2873 this->GotoLine(dlg
.m_LineNumber
);
2877 LRESULT
CTortoiseGitBlameView::OnFindDialogMessage(WPARAM wParam
, LPARAM lParam
)//Õâ¸öÒ²ÊÇÕÒÄǸö³ÌÐò¸ÄµÄ£¬Ö»²»¹ý»»³ÉÁË×Ô¼ºµÄÀà
2879 ASSERT(m_pFindDialog
!= NULL
);
2881 // If the FR_DIALOGTERM flag is set,
2882 // invalidate the handle identifying the dialog box.
2883 if (m_pFindDialog
->IsTerminating())
2885 m_pFindDialog
= NULL
;
2889 // If the FR_FINDNEXT flag is set,
2890 // call the application-defined search routine
2891 // to search for the requested string.
2892 if(m_pFindDialog
->FindNext())
2894 //read data from dialog
2895 CString FindName
= m_pFindDialog
->GetFindString();
2896 bool bMatchCase
= m_pFindDialog
->MatchCase() == TRUE
;
2897 bool bMatchWholeWord
= m_pFindDialog
->MatchWholeWord() == TRUE
;
2898 bool bSearchDown
= m_pFindDialog
->SearchDown() == TRUE
;
2900 DoSearch(FindName
,m_pFindDialog
->m_fr
.Flags
);
2901 //with given name do search
2902 // *FindWhatYouNeed(FindName, bMatchCase, bMatchWholeWord, bSearchDown);
2908 void CTortoiseGitBlameView::OnViewNext()
2910 FindNextLine(this->m_SelectedHash
,false);
2912 void CTortoiseGitBlameView::OnViewPrev()
2914 FindNextLine(this->m_SelectedHash
,true);
2917 int CTortoiseGitBlameView::FindNextLine(CGitHash CommitHash
,bool bUpOrDown
)
2919 LONG_PTR line
= SendEditor(SCI_GETFIRSTVISIBLELINE
);
2920 LONG_PTR startline
=line
;
2921 bool findNoMatch
=false;
2922 while(line
>=0 && line
<m_CommitHash
.size())
2924 if(m_CommitHash
[line
]!=CommitHash
)
2929 if(m_CommitHash
[line
] == CommitHash
&& findNoMatch
)
2931 if( line
== startline
+2 )
2939 line
=FindFirstLine(CommitHash
,line
);
2941 SendEditor(SCI_LINESCROLL
,0,line
-startline
-2);
2952 BOOL
CTortoiseGitBlameView::OnCommand(WPARAM wParam
, LPARAM lParam
)
2954 // TODO: Add your specialized code here and/or call the base class
2956 return CView::OnCommand(wParam
, lParam
);