1 // TortoiseGitBlame - a Viewer for Git Blames
3 // Copyright (C) 2008-2012 - TortoiseGit
4 // Copyright (C) 2010-2012 Sven Strickroth <email@cs-ware.de>
5 // Copyright (C) 2003-2008 - TortoiseSVN
7 // Copyright (C)2003 Don HO <donho@altern.org>
9 // This program is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU General Public License
11 // as published by the Free Software Foundation; either version 2
12 // of the License, or (at your option) any later version.
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
19 // You should have received a copy of the GNU General Public License
20 // along with this program; if not, write to the Free Software Foundation,
21 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 // CTortoiseGitBlameView.cpp : implementation of the CTortoiseGitBlameView class
27 #include "TortoiseGitBlame.h"
28 #include "CommonAppUtils.h"
29 #include "TortoiseGitBlameDoc.h"
30 #include "TortoiseGitBlameView.h"
32 #include "EditGotoDlg.h"
33 #include "LoglistUtils.h"
34 #include "FileTextLines.h"
35 #include "UniCodeUtils.h"
36 #include "MenuEncode.h"
39 #include "StringUtils.h"
45 wchar_t WideCharSwap2(wchar_t nValue
)
47 return (((nValue
>> 8)) | (nValue
<< 8));
50 UINT
CTortoiseGitBlameView::m_FindDialogMessage
;
52 // CTortoiseGitBlameView
53 IMPLEMENT_DYNAMIC(CSciEditBlame
,CSciEdit
)
55 IMPLEMENT_DYNCREATE(CTortoiseGitBlameView
, CView
)
57 BEGIN_MESSAGE_MAP(CTortoiseGitBlameView
, CView
)
58 // Standard printing commands
59 ON_COMMAND(ID_FILE_PRINT
, &CView::OnFilePrint
)
60 ON_COMMAND(ID_FILE_PRINT_DIRECT
, &CView::OnFilePrint
)
61 ON_COMMAND(ID_FILE_PRINT_PREVIEW
, &CTortoiseGitBlameView::OnFilePrintPreview
)
62 ON_COMMAND(ID_EDIT_FIND
,OnEditFind
)
63 ON_COMMAND(ID_EDIT_GOTO
,OnEditGoto
)
64 ON_COMMAND(ID_EDIT_COPY
, CopyToClipboard
)
65 ON_UPDATE_COMMAND_UI(ID_EDIT_COPY
, OnUpdateViewCopyToClipboard
)
66 ON_COMMAND(ID_VIEW_NEXT
,OnViewNext
)
67 ON_COMMAND(ID_VIEW_PREV
,OnViewPrev
)
68 ON_COMMAND(ID_VIEW_SHOWAUTHOR
, OnViewToggleAuthor
)
69 ON_UPDATE_COMMAND_UI(ID_VIEW_SHOWAUTHOR
, OnUpdateViewToggleAuthor
)
70 ON_COMMAND(ID_VIEW_FOLLOWRENAMES
, OnViewToggleFollowRenames
)
71 ON_UPDATE_COMMAND_UI(ID_VIEW_FOLLOWRENAMES
, OnUpdateViewToggleFollowRenames
)
72 ON_COMMAND(ID_BLAMEPOPUP_COPYHASHTOCLIPBOARD
, CopyHashToClipboard
)
73 ON_COMMAND(ID_BLAMEPOPUP_COPYLOGTOCLIPBOARD
, CopySelectedLogToClipboard
)
74 ON_COMMAND(ID_BLAMEPOPUP_BLAMEPREVIOUSREVISION
, BlamePreviousRevision
)
75 ON_COMMAND(ID_BLAMEPOPUP_DIFFPREVIOUS
, DiffPreviousRevision
)
76 ON_COMMAND(ID_BLAMEPOPUP_SHOWLOG
, ShowLog
)
77 ON_UPDATE_COMMAND_UI(ID_BLAMEPOPUP_BLAMEPREVIOUSREVISION
, OnUpdateBlamePopupBlamePrevious
)
78 ON_UPDATE_COMMAND_UI(ID_BLAMEPOPUP_DIFFPREVIOUS
, OnUpdateBlamePopupDiffPrevious
)
79 ON_COMMAND_RANGE(IDM_FORMAT_ENCODE
, IDM_FORMAT_ENCODE_END
, OnChangeEncode
)
88 ON_NOTIFY(SCN_PAINTED
,0,OnSciPainted
)
89 ON_NOTIFY(SCN_GETBKCOLOR
,0,OnSciGetBkColor
)
90 ON_REGISTERED_MESSAGE(m_FindDialogMessage
, OnFindDialogMessage
)
94 // CTortoiseGitBlameView construction/destruction
96 CTortoiseGitBlameView::CTortoiseGitBlameView()
113 m_windowcolor
= ::GetSysColor(COLOR_WINDOW
);
114 m_textcolor
= ::GetSysColor(COLOR_WINDOWTEXT
);
115 m_texthighlightcolor
= ::GetSysColor(COLOR_HIGHLIGHTTEXT
);
116 m_mouserevcolor
= InterColor(m_windowcolor
, m_textcolor
, 20);
117 m_mouseauthorcolor
= InterColor(m_windowcolor
, m_textcolor
, 10);
118 m_selectedrevcolor
= ::GetSysColor(COLOR_HIGHLIGHT
);
119 m_selectedauthorcolor
= InterColor(m_selectedrevcolor
, m_texthighlightcolor
, 35);
123 m_selectedorigrev
= -1;
126 m_directFunction
= 0;
128 m_lowestrev
= LONG_MAX
;
134 m_bShowAuthor
= (theApp
.GetInt(_T("ShowAuthor"), 1) == 1);
136 m_bFollowRenames
= (theApp
.GetInt(_T("FollowRenames"), 0) == 1);
138 m_FindDialogMessage
= ::RegisterWindowMessage(FINDMSGSTRING
);
139 m_pFindDialog
= NULL
;
140 // get short/long datetime setting from registry
141 DWORD RegUseShortDateFormat
= CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE
);
142 if ( RegUseShortDateFormat
)
144 m_DateFormat
= DATE_SHORTDATE
;
148 m_DateFormat
= DATE_LONGDATE
;
150 // get relative time display setting from registry
151 DWORD regRelativeTimes
= CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE
);
152 m_bRelativeTimes
= (regRelativeTimes
!= 0);
154 m_sRev
.LoadString(IDS_LOG_REVISION
);
155 m_sAuthor
.LoadString(IDS_LOG_AUTHOR
);
156 m_sDate
.LoadString(IDS_LOG_DATE
);
157 m_sMessage
.LoadString(IDS_LOG_MESSAGE
);
162 CTortoiseGitBlameView::~CTortoiseGitBlameView()
165 DeleteObject(m_font
);
167 DeleteObject(m_italicfont
);
181 void CTortoiseGitBlameView::OnChangeEncode(UINT nId
)
184 static EncodingUnit encodings
[] = {
185 {1250, "windows-1250"}, //IDM_FORMAT_WIN_1250
186 {1251, "windows-1251"}, //IDM_FORMAT_WIN_1251
187 {1252, "windows-1252"}, //IDM_FORMAT_WIN_1252
188 {1253, "windows-1253"}, //IDM_FORMAT_WIN_1253
189 {1254, "windows-1254"}, //IDM_FORMAT_WIN_1254
190 {1255, "windows-1255"}, //IDM_FORMAT_WIN_1255
191 {1256, "windows-1256"}, //IDM_FORMAT_WIN_1256
192 {1257, "windows-1257"}, //IDM_FORMAT_WIN_1257
193 {1258, "windows-1258"}, //IDM_FORMAT_WIN_1258
194 {28591, "latin1 ISO_8859-1 ISO-8859-1 CP819 IBM819 csISOLatin1 iso-ir-100 l1"}, //IDM_FORMAT_ISO_8859_1
195 {28592, "latin2 ISO_8859-2 ISO-8859-2 csISOLatin2 iso-ir-101 l2"}, //IDM_FORMAT_ISO_8859_2
196 {28593, "latin3 ISO_8859-3 ISO-8859-3 csISOLatin3 iso-ir-109 l3"}, //IDM_FORMAT_ISO_8859_3
197 {28594, "latin4 ISO_8859-4 ISO-8859-4 csISOLatin4 iso-ir-110 l4"}, //IDM_FORMAT_ISO_8859_4
198 {28595, "cyrillic ISO_8859-5 ISO-8859-5 csISOLatinCyrillic iso-ir-144"}, //IDM_FORMAT_ISO_8859_5
199 {28596, "arabic ISO_8859-6 ISO-8859-6 csISOLatinArabic iso-ir-127 ASMO-708 ECMA-114"}, //IDM_FORMAT_ISO_8859_6
200 {28597, "greek ISO_8859-7 ISO-8859-7 csISOLatinGreek greek8 iso-ir-126 ELOT_928 ECMA-118"}, //IDM_FORMAT_ISO_8859_7
201 {28598, "hebrew ISO_8859-8 ISO-8859-8 csISOLatinHebrew iso-ir-138"}, //IDM_FORMAT_ISO_8859_8
202 {28599, "latin5 ISO_8859-9 ISO-8859-9 csISOLatin5 iso-ir-148 l5"}, //IDM_FORMAT_ISO_8859_9
203 {28600, "latin6 ISO_8859-10 ISO-8859-10 csISOLatin6 iso-ir-157 l6"}, //IDM_FORMAT_ISO_8859_10
204 {28601, "ISO_8859-11 ISO-8859-11"}, //IDM_FORMAT_ISO_8859_11
205 {28603, "ISO_8859-13 ISO-8859-13"}, //IDM_FORMAT_ISO_8859_13
206 {28604, "iso-celtic latin8 ISO_8859-14 ISO-8859-14 18 iso-ir-199"}, //IDM_FORMAT_ISO_8859_14
207 {28605, "Latin-9 ISO_8859-15 ISO-8859-15"}, //IDM_FORMAT_ISO_8859_15
208 {28606, "latin10 ISO_8859-16 ISO-8859-16 110 iso-ir-226"}, //IDM_FORMAT_ISO_8859_16
209 {437, "IBM437 cp437 437 csPC8CodePage437"}, //IDM_FORMAT_DOS_437
210 {720, "IBM720 cp720 oem720 720"}, //IDM_FORMAT_DOS_720
211 {737, "IBM737 cp737 oem737 737"}, //IDM_FORMAT_DOS_737
212 {775, "IBM775 cp775 oem775 775"}, //IDM_FORMAT_DOS_775
213 {850, "IBM850 cp850 oem850 850"}, //IDM_FORMAT_DOS_850
214 {852, "IBM852 cp852 oem852 852"}, //IDM_FORMAT_DOS_852
215 {855, "IBM855 cp855 oem855 855 csIBM855"}, //IDM_FORMAT_DOS_855
216 {857, "IBM857 cp857 oem857 857"}, //IDM_FORMAT_DOS_857
217 {858, "IBM858 cp858 oem858 858"}, //IDM_FORMAT_DOS_858
218 {860, "IBM860 cp860 oem860 860"}, //IDM_FORMAT_DOS_860
219 {861, "IBM861 cp861 oem861 861"}, //IDM_FORMAT_DOS_861
220 {862, "IBM862 cp862 oem862 862"}, //IDM_FORMAT_DOS_862
221 {863, "IBM863 cp863 oem863 863"}, //IDM_FORMAT_DOS_863
222 {865, "IBM865 cp865 oem865 865"}, //IDM_FORMAT_DOS_865
223 {866, "IBM866 cp866 oem866 866"}, //IDM_FORMAT_DOS_866
224 {869, "IBM869 cp869 oem869 869"}, //IDM_FORMAT_DOS_869
225 {950, "big5 csBig5"}, //IDM_FORMAT_BIG5
226 {936, "gb2312 gbk csGB2312"}, //IDM_FORMAT_GB2312
227 {932, "Shift_JIS MS_Kanji csShiftJIS csWindows31J"}, //IDM_FORMAT_SHIFT_JIS
228 {949, "windows-949 korean"}, //IDM_FORMAT_KOREAN_WIN
229 {51949, "euc-kr csEUCKR"}, //IDM_FORMAT_EUC_KR
230 {874, "tis-620"}, //IDM_FORMAT_TIS_620
231 {10007, "x-mac-cyrillic xmaccyrillic"}, //IDM_FORMAT_MAC_CYRILLIC
232 {21866, "koi8_u"}, //IDM_FORMAT_KOI8U_CYRILLIC
233 {20866, "koi8_r csKOI8R"} //IDM_FORMAT_KOI8R_CYRILLIC
235 if(nId
>= IDM_FORMAT_ENCODE
&& nId
<= IDM_FORMAT_ENCODE_END
)
236 this->UpdateInfo(encodings
[nId
- IDM_FORMAT_ENCODE
].id
);
238 int CTortoiseGitBlameView::OnCreate(LPCREATESTRUCT lpcs
)
242 this->GetWindowRect(&rect1
);
243 rect
.left
=m_blamewidth
+LOCATOR_WIDTH
;
244 rect
.right
=rect
.Width();
246 rect
.bottom
=rect
.Height();
247 BOOL b
=m_TextView
.Create(_T("Scintilla"),_T("source"),0,rect
,this,0,0);
248 m_TextView
.Init(0,FALSE
);
249 m_TextView
.ShowWindow( SW_SHOW
);
250 //m_TextView.InsertText(_T("Abdadfasdf"));
251 m_wEditor
= m_TextView
.m_hWnd
;
254 m_ToolTip
.Create(this->GetParent());
256 ::AfxGetApp()->GetMainWnd();
257 return CView::OnCreate(lpcs
);
261 void CTortoiseGitBlameView::OnSize(UINT nType
,int cx
, int cy
)
265 rect
.left
=m_blamewidth
;
270 m_TextView
.MoveWindow(&rect
);
273 BOOL
CTortoiseGitBlameView::PreCreateWindow(CREATESTRUCT
& cs
)
275 return CView::PreCreateWindow(cs
);
278 // CTortoiseGitBlameView drawing
280 void CTortoiseGitBlameView::OnDraw(CDC
* /*pDC*/)
282 CTortoiseGitBlameDoc
* pDoc
= GetDocument();
287 DrawBlame(this->GetDC()->m_hDC
);
288 DrawLocatorBar(this->GetDC()->m_hDC
);
289 // TODO: add draw code for native data here
293 // CTortoiseGitBlameView printing
296 void CTortoiseGitBlameView::OnFilePrintPreview()
298 AFXPrintPreview(this);
301 BOOL
CTortoiseGitBlameView::OnPreparePrinting(CPrintInfo
* pInfo
)
303 // default preparation
304 return DoPreparePrinting(pInfo
);
307 void CTortoiseGitBlameView::OnBeginPrinting(CDC
* /*pDC*/, CPrintInfo
* /*pInfo*/)
309 // TODO: add extra initialization before printing
312 void CTortoiseGitBlameView::OnEndPrinting(CDC
* /*pDC*/, CPrintInfo
* /*pInfo*/)
314 // TODO: add cleanup after printing
317 void CTortoiseGitBlameView::OnRButtonUp(UINT nFlags
, CPoint point
)
319 LONG_PTR line
= SendEditor(SCI_GETFIRSTVISIBLELINE
);
320 LONG_PTR height
= SendEditor(SCI_TEXTHEIGHT
);
321 line
= line
+ (point
.y
/height
);
322 if (line
< (LONG
)m_CommitHash
.size())
324 if(m_ID
[line
] >= 0) // only show context menu if we have log data for it
326 m_MouseLine
= (LONG
)line
;
327 ClientToScreen(&point
);
328 theApp
.GetContextMenuManager()->ShowPopupMenu(IDR_BLAME_POPUP
, point
.x
, point
.y
, this, TRUE
);
333 void CTortoiseGitBlameView::OnUpdateBlamePopupBlamePrevious(CCmdUI
*pCmdUI
)
335 if (m_ID
[m_MouseLine
] <= 1)
337 pCmdUI
->Enable(false);
341 pCmdUI
->Enable(true);
345 void CTortoiseGitBlameView::OnUpdateBlamePopupDiffPrevious(CCmdUI
*pCmdUI
)
347 if (m_ID
[m_MouseLine
] <= 1)
349 pCmdUI
->Enable(false);
353 pCmdUI
->Enable(true);
357 void CTortoiseGitBlameView::CopyHashToClipboard()
359 this->GetLogList()->CopySelectionToClipBoard(CGitLogListBase::ID_COPY_HASH
);
362 // CTortoiseGitBlameView diagnostics
365 void CTortoiseGitBlameView::AssertValid() const
367 CView::AssertValid();
370 void CTortoiseGitBlameView::Dump(CDumpContext
& dc
) const
375 CTortoiseGitBlameDoc
* CTortoiseGitBlameView::GetDocument() const // non-debug version is inline
377 ASSERT(m_pDocument
->IsKindOf(RUNTIME_CLASS(CTortoiseGitBlameDoc
)));
378 return (CTortoiseGitBlameDoc
*)m_pDocument
;
383 // CTortoiseGitBlameView message handlers
384 CString
CTortoiseGitBlameView::GetAppDirectory()
388 DWORD bufferlen
= MAX_PATH
; // MAX_PATH is not the limit here!
391 bufferlen
+= MAX_PATH
; // MAX_PATH is not the limit here!
392 TCHAR
* pBuf
= new TCHAR
[bufferlen
];
393 len
= GetModuleFileName(NULL
, pBuf
, bufferlen
);
394 path
= CString(pBuf
, len
);
396 } while(len
== bufferlen
);
398 path
= path
.Left(path
.ReverseFind(_T('\\')));
399 //path = path.substr(0, path.rfind('\\') + 1);
404 // Return a color which is interpolated between c1 and c2.
405 // Slider controls the relative proportions as a percentage:
406 // Slider = 0 represents pure c1
407 // Slider = 50 represents equal mixture
408 // Slider = 100 represents pure c2
409 COLORREF
CTortoiseGitBlameView::InterColor(COLORREF c1
, COLORREF c2
, int Slider
)
413 // Limit Slider to 0..100% range
419 // The color components have to be treated individually.
420 r
= (GetRValue(c2
) * Slider
+ GetRValue(c1
) * (100 - Slider
)) / 100;
421 g
= (GetGValue(c2
) * Slider
+ GetGValue(c1
) * (100 - Slider
)) / 100;
422 b
= (GetBValue(c2
) * Slider
+ GetBValue(c1
) * (100 - Slider
)) / 100;
427 LRESULT
CTortoiseGitBlameView::SendEditor(UINT Msg
, WPARAM wParam
, LPARAM lParam
)
429 if (m_directFunction
)
431 return ((SciFnDirect
) m_directFunction
)(m_directPointer
, Msg
, wParam
, lParam
);
433 return ::SendMessage(m_wEditor
, Msg
, wParam
, lParam
);
436 void CTortoiseGitBlameView::SetAStyle(int style
, COLORREF fore
, COLORREF back
, int size
, CString
*face
)
438 SendEditor(SCI_STYLESETFORE
, style
, fore
);
439 SendEditor(SCI_STYLESETBACK
, style
, back
);
441 SendEditor(SCI_STYLESETSIZE
, style
, size
);
443 SendEditor(SCI_STYLESETFONT
, style
, reinterpret_cast<LPARAM
>(this->m_TextView
.StringForControl(*face
).GetBuffer()));
446 void CTortoiseGitBlameView::InitialiseEditor()
449 m_directFunction
= ::SendMessage(m_wEditor
, SCI_GETDIRECTFUNCTION
, 0, 0);
450 m_directPointer
= ::SendMessage(m_wEditor
, SCI_GETDIRECTPOINTER
, 0, 0);
451 // Set up the global default style. These attributes are used wherever no explicit choices are made.
452 SetAStyle(STYLE_DEFAULT
,
455 (DWORD
)CRegStdDWORD(_T("Software\\TortoiseGit\\BlameFontSize"), 10),
456 &CString(((stdstring
)CRegStdString(_T("Software\\TortoiseGit\\BlameFontName"), _T("Courier New"))).c_str())
458 SendEditor(SCI_SETTABWIDTH
, (DWORD
)CRegStdDWORD(_T("Software\\TortoiseGit\\BlameTabSize"), 4));
459 SendEditor(SCI_SETREADONLY
, TRUE
);
460 LRESULT pix
= SendEditor(SCI_TEXTWIDTH
, STYLE_LINENUMBER
, (LPARAM
)this->m_TextView
.StringForControl(_T("_99999")).GetBuffer());
462 SendEditor(SCI_SETMARGINWIDTHN
, 0, pix
);
464 SendEditor(SCI_SETMARGINWIDTHN
, 0);
465 SendEditor(SCI_SETMARGINWIDTHN
, 1);
466 SendEditor(SCI_SETMARGINWIDTHN
, 2);
467 //Set the default windows colors for edit controls
468 SendEditor(SCI_STYLESETFORE
, STYLE_DEFAULT
, ::GetSysColor(COLOR_WINDOWTEXT
));
469 SendEditor(SCI_STYLESETBACK
, STYLE_DEFAULT
, ::GetSysColor(COLOR_WINDOW
));
470 SendEditor(SCI_SETSELFORE
, TRUE
, ::GetSysColor(COLOR_HIGHLIGHTTEXT
));
471 SendEditor(SCI_SETSELBACK
, TRUE
, ::GetSysColor(COLOR_HIGHLIGHT
));
472 SendEditor(SCI_SETCARETFORE
, ::GetSysColor(COLOR_WINDOWTEXT
));
473 m_regOldLinesColor
= CRegStdDWORD(_T("Software\\TortoiseGit\\BlameOldColor"), RGB(230, 230, 255));
474 m_regNewLinesColor
= CRegStdDWORD(_T("Software\\TortoiseGit\\BlameNewColor"), RGB(255, 230, 230));
475 CRegStdDWORD
used2d(L
"Software\\TortoiseGit\\ScintillaDirect2D", FALSE
);
476 if (SysInfo::Instance().IsWin7OrLater() && DWORD(used2d
))
478 SendEditor(SCI_SETTECHNOLOGY
, SC_TECHNOLOGY_DIRECTWRITE
);
479 SendEditor(SCI_SETBUFFEREDDRAW
, 0);
481 SendEditor(SCI_SETFONTQUALITY
, SC_EFF_QUALITY_DEFAULT
);
483 this->m_TextView
.Call(SCI_SETWRAPMODE
, SC_WRAP_NONE
);
487 void CTortoiseGitBlameView::StartSearch()
492 // Initialize FINDREPLACE
493 if (fr
.Flags
& FR_MATCHCASE
)
495 SecureZeroMemory(&fr
, sizeof(fr
));
496 fr
.lStructSize
= sizeof(fr
);
497 fr
.hwndOwner
= wMain
;
498 fr
.lpstrFindWhat
= szFindWhat
;
499 fr
.wFindWhatLen
= 80;
500 fr
.Flags
= FR_HIDEUPDOWN
| FR_HIDEWHOLEWORD
;
501 fr
.Flags
|= bCase
? FR_MATCHCASE
: 0;
503 currentDialog
= FindText(&fr
);
506 bool CTortoiseGitBlameView::DoSearch(CString what
, DWORD flags
)
510 int pos
= (int)SendEditor(SCI_GETCURRENTPOS
);
511 int line
= (int)SendEditor(SCI_LINEFROMPOSITION
, pos
);
513 bool bCaseSensitive
= !!(flags
& FR_MATCHCASE
);
515 //strcpy_s(szWhat, sizeof(szWhat), what);
519 what
=what
.MakeLower();
522 //CString sWhat = CString(szWhat);
529 int bufsize
= (int)SendEditor(SCI_GETLINE
, i
);
530 char * linebuf
= new char[bufsize
+1];
531 SecureZeroMemory(linebuf
, bufsize
+1);
532 SendEditor(SCI_GETLINE
, i
, (LPARAM
)linebuf
);
533 CString oneline
=this->m_TextView
.StringFromControl(linebuf
);
536 oneline
=oneline
.MakeLower();
538 //_stprintf_s(buf, 20, _T("%ld"), revs[i]);
539 if (this->m_Authors
[i
].Find(what
)>=0)
541 else if ((!bCaseSensitive
)&&(this->m_Authors
[i
].MakeLower().Find(what
)>=0))
543 else if (oneline
.Find(what
) >=0)
549 if(i
>=(signed int)m_CommitHash
.size())
551 }while(i
!=line
&&(!bFound
));
556 int selstart
= (int)SendEditor(SCI_GETCURRENTPOS
);
557 int selend
= (int)SendEditor(SCI_POSITIONFROMLINE
, i
);
558 SendEditor(SCI_SETSELECTIONSTART
, selstart
);
559 SendEditor(SCI_SETSELECTIONEND
, selend
);
560 m_SelectedLine
= i
-1;
564 ::MessageBox(wMain
, _T("\"") + what
+ _T("\" ") + CString(MAKEINTRESOURCE(IDS_NOTFOUND
)), _T("TortoiseGitBlame"), MB_ICONINFORMATION
);
570 bool CTortoiseGitBlameView::GotoLine(long line
)
575 if ((unsigned long)line
>= m_CommitHash
.size())
577 line
= (long)m_CommitHash
.size()-1;
580 int nCurrentPos
= (int)SendEditor(SCI_GETCURRENTPOS
);
581 int nCurrentLine
= (int)SendEditor(SCI_LINEFROMPOSITION
,nCurrentPos
);
582 int nFirstVisibleLine
= (int)SendEditor(SCI_GETFIRSTVISIBLELINE
);
583 int nLinesOnScreen
= (int)SendEditor(SCI_LINESONSCREEN
);
585 if ( line
>=nFirstVisibleLine
&& line
<=nFirstVisibleLine
+nLinesOnScreen
)
588 SendEditor(SCI_GOTOLINE
, line
);
592 // Place the requested line one third from the top
593 if ( line
> nCurrentLine
)
595 SendEditor(SCI_GOTOLINE
, (WPARAM
)(line
+(int)nLinesOnScreen
*(2/3.0)));
599 SendEditor(SCI_GOTOLINE
, (WPARAM
)(line
-(int)nLinesOnScreen
*(1/3.0)));
603 // Highlight the line
604 int nPosStart
= (int)SendEditor(SCI_POSITIONFROMLINE
,line
);
605 int nPosEnd
= (int)SendEditor(SCI_GETLINEENDPOSITION
,line
);
606 SendEditor(SCI_SETSEL
,nPosEnd
,nPosStart
);
611 bool CTortoiseGitBlameView::ScrollToLine(long line
)
616 int nCurrentLine
= (int)SendEditor(SCI_GETFIRSTVISIBLELINE
);
618 int scrolldelta
= line
- nCurrentLine
;
619 SendEditor(SCI_LINESCROLL
, 0, scrolldelta
);
624 void CTortoiseGitBlameView::CopyToClipboard()
626 CWnd
* wnd
= GetFocus();
627 if (wnd
== this->GetLogList())
628 CopySelectedLogToClipboard();
631 if (CString(wnd
->GetRuntimeClass()->m_lpszClassName
) == _T("CMFCPropertyGridCtrl"))
633 CMFCPropertyGridCtrl
*grid
= (CMFCPropertyGridCtrl
*)wnd
;
634 if (grid
->GetCurSel() && !grid
->GetCurSel()->IsGroup())
635 CStringUtils::WriteAsciiStringToClipboard(grid
->GetCurSel()->GetValue(), GetSafeHwnd());
638 m_TextView
.Call(SCI_COPY
);
642 void CTortoiseGitBlameView::CopySelectedLogToClipboard()
644 this->GetLogList()->CopySelectionToClipBoard(FALSE
);
647 void CTortoiseGitBlameView::BlamePreviousRevision()
649 CString procCmd
= _T("/path:\"");
650 procCmd
+= ((CMainFrame
*)::AfxGetApp()->GetMainWnd())->GetActiveView()->GetDocument()->GetPathName();
651 procCmd
+= _T("\" ");
652 procCmd
+= _T(" /command:blame");
653 procCmd
+= _T(" /endrev:") + this->GetLogData()->GetGitRevAt(this->GetLogData()->size()-m_ID
[m_MouseLine
]+1).m_CommitHash
.ToString();
655 CCommonAppUtils::RunTortoiseProc(procCmd
);
658 void CTortoiseGitBlameView::DiffPreviousRevision()
660 CString procCmd
= _T("/path:\"");
661 procCmd
+= ((CMainFrame
*)::AfxGetApp()->GetMainWnd())->GetActiveView()->GetDocument()->GetPathName();
662 procCmd
+= _T("\" ");
663 procCmd
+= _T(" /command:diff");
664 procCmd
+= _T(" /startrev:") + this->GetLogData()->GetGitRevAt(this->GetLogData()->size() - m_ID
[m_MouseLine
]).m_CommitHash
.ToString();
665 procCmd
+= _T(" /endrev:") + this->GetLogData()->GetGitRevAt(this->GetLogData()->size() - m_ID
[m_MouseLine
] + 1).m_CommitHash
.ToString();
667 CCommonAppUtils::RunTortoiseProc(procCmd
);
670 void CTortoiseGitBlameView::ShowLog()
672 CString procCmd
= _T("/path:\"");
673 procCmd
+= ((CMainFrame
*)::AfxGetApp()->GetMainWnd())->GetActiveView()->GetDocument()->GetPathName();
674 procCmd
+= _T("\" ");
675 procCmd
+= _T(" /command:log");
676 procCmd
+= _T(" /rev:") + this->GetLogData()->GetGitRevAt(this->GetLogData()->size() - m_ID
[m_MouseLine
]).m_CommitHash
.ToString();
678 CCommonAppUtils::RunTortoiseProc(procCmd
);
681 LONG
CTortoiseGitBlameView::GetBlameWidth()
686 HDC hDC
= this->GetDC()->m_hDC
;
687 HFONT oldfont
= (HFONT
)::SelectObject(hDC
, m_font
);
691 CString
shortHash('f', g_Git
.GetShortHASHLength() + 1);
692 ::GetTextExtentPoint32(hDC
, shortHash
, g_Git
.GetShortHASHLength() + 1, &width
);
693 m_revwidth
= width
.cx
+ BLAMESPACE
;
694 blamewidth
+= m_revwidth
;
698 _stprintf_s(buf
, MAX_PATH
, _T("%30s"), _T("31.08.2001 06:24:14"));
699 ::GetTextExtentPoint32(hDC
, buf
, (int)_tcslen(buf
), &width
);
700 m_datewidth
= width
.cx
+ BLAMESPACE
;
701 blamewidth
+= m_datewidth
;
707 for (unsigned int i
=0;i
<this->m_Authors
.size();i
++)
709 ::GetTextExtentPoint32(hDC
,m_Authors
[i
] , m_Authors
[i
].GetLength(), &width
);
710 if (width
.cx
> maxwidth
.cx
)
713 m_authorwidth
= maxwidth
.cx
+ BLAMESPACE
;
714 blamewidth
+= m_authorwidth
;
716 ::SelectObject(hDC
, oldfont
);
717 POINT pt
= {blamewidth
, 0};
720 //::ReleaseDC(wBlame, hDC);
725 void CTortoiseGitBlameView::CreateFont()
731 HDC hDC
= ::GetDC(wBlame
);
732 lf
.lfHeight
= -MulDiv((DWORD
)CRegStdDWORD(_T("Software\\TortoiseGit\\BlameFontSize"), 10), GetDeviceCaps(hDC
, LOGPIXELSY
), 72);
733 lf
.lfCharSet
= DEFAULT_CHARSET
;
734 CRegStdString fontname
= CRegStdString(_T("Software\\TortoiseGit\\BlameFontName"), _T("Courier New"));
735 _tcscpy_s(lf
.lfFaceName
, 32, ((stdstring
)fontname
).c_str());
736 m_font
= ::CreateFontIndirect(&lf
);
739 m_italicfont
= ::CreateFontIndirect(&lf
);
741 ::ReleaseDC(wBlame
, hDC
);
744 void CTortoiseGitBlameView::DrawBlame(HDC hDC
)
751 HFONT oldfont
= NULL
;
752 LONG_PTR line
= SendEditor(SCI_GETFIRSTVISIBLELINE
);
753 LONG_PTR linesonscreen
= SendEditor(SCI_LINESONSCREEN
);
754 LONG_PTR height
= SendEditor(SCI_TEXTHEIGHT
);
759 //::GetClientRect(this->m_hWnd, &rc);
760 for (LRESULT i
=line
; i
<(line
+linesonscreen
); ++i
)
763 if (i
< (int)m_CommitHash
.size())
765 // if (mergelines[i])
766 // oldfont = (HFONT)::SelectObject(hDC, m_italicfont);
768 oldfont
= (HFONT
)::SelectObject(hDC
, m_font
);
769 ::SetBkColor(hDC
, m_windowcolor
);
770 ::SetTextColor(hDC
, m_textcolor
);
771 if (!m_CommitHash
[i
].IsEmpty())
773 //if (m_CommitHash[i].Compare(m_MouseHash)==0)
774 // ::SetBkColor(hDC, m_mouseauthorcolor);
775 if (m_CommitHash
[i
] == m_SelectedHash
)
777 ::SetBkColor(hDC
, m_selectedauthorcolor
);
778 ::SetTextColor(hDC
, m_texthighlightcolor
);
784 ::SetBkColor(hDC
, m_mouserevcolor
);
786 //if ((revs[i] == m_mouserev)&&(!sel))
787 // ::SetBkColor(hDC, m_mouserevcolor);
788 //if (revs[i] == m_selectedrev)
790 // ::SetBkColor(hDC, m_selectedrevcolor);
791 // ::SetTextColor(hDC, m_texthighlightcolor);
795 str
= m_CommitHash
[i
].ToString().Left(g_Git
.GetShortHASHLength());
797 //_stprintf_s(buf, MAX_PATH, _T("%8ld "), revs[i]);
799 rc
.left
=LOCATOR_WIDTH
;
800 rc
.bottom
= (LONG
)(Y
+ height
);
801 rc
.right
= rc
.left
+ m_blamewidth
;
802 ::ExtTextOut(hDC
, LOCATOR_WIDTH
, (int)Y
, ETO_CLIPPED
, &rc
, str
, str
.GetLength(), 0);
803 int Left
= m_revwidth
;
807 rc
.right
= rc
.left
+ Left
+ m_authorwidth
;
808 //_stprintf_s(buf, MAX_PATH, _T("%-30s "), authors[i].c_str());
809 ::ExtTextOut(hDC
, Left
, (int)Y
, ETO_CLIPPED
, &rc
, m_Authors
[i
], m_Authors
[i
].GetLength(), 0);
810 Left
+= m_authorwidth
;
815 rc
.right
= rc
.left
+ Left
+ m_datewidth
;
816 _stprintf_s(buf
, MAX_PATH
, _T("%30s "), dates
[i
].c_str());
817 ::ExtTextOut(hDC
, Left
, Y
, ETO_CLIPPED
, &rc
, buf
, _tcslen(buf
), 0);
822 if ((i
==m_SelectedLine
)&&(m_pFindDialog
))
825 brush
.lbColor
= m_textcolor
;
827 brush
.lbStyle
= BS_SOLID
;
828 HPEN pen
= ExtCreatePen(PS_SOLID
| PS_GEOMETRIC
, 2, &brush
, 0, NULL
);
829 HGDIOBJ hPenOld
= SelectObject(hDC
, pen
);
832 rc2
.bottom
= (LONG
)(Y
+ height
);
833 ::MoveToEx(hDC
, rc2
.left
, rc2
.top
, NULL
);
834 ::LineTo(hDC
, rc2
.right
, rc2
.top
);
835 ::LineTo(hDC
, rc2
.right
, rc2
.bottom
);
836 ::LineTo(hDC
, rc2
.left
, rc2
.bottom
);
837 ::LineTo(hDC
, rc2
.left
, rc2
.top
);
838 SelectObject(hDC
, hPenOld
);
842 ::SelectObject(hDC
, oldfont
);
846 ::SetBkColor(hDC
, m_windowcolor
);
847 for (int j
=0; j
< MAX_PATH
; ++j
)
849 ::ExtTextOut(hDC
, 0, (int)Y
, ETO_CLIPPED
, &rc
, buf
, MAX_PATH
-1, 0);
855 void CTortoiseGitBlameView::DrawLocatorBar(HDC hDC
)
860 LONG_PTR line
= SendEditor(SCI_GETFIRSTVISIBLELINE
);
861 LONG_PTR linesonscreen
= SendEditor(SCI_LINESONSCREEN
);
863 COLORREF blackColor
= GetSysColor(COLOR_WINDOWTEXT
);
866 //::GetClientRect(wLocator, &rc);
867 this->GetClientRect(&rc
);
869 rc
.right
=LOCATOR_WIDTH
;
872 LONG height
= rc
.bottom
-rc
.top
;
873 LONG currentLine
= 0;
875 // draw the colored bar
876 for (std::vector
<LONG
>::const_iterator it
= m_ID
.begin(); it
!= m_ID
.end(); ++it
)
879 // get the line color
880 COLORREF cr
= InterColor(DWORD(m_regOldLinesColor
), DWORD(m_regNewLinesColor
), (*it
- m_lowestrev
)*100/((m_highestrev
-m_lowestrev
)+1));
881 if ((currentLine
> line
)&&(currentLine
<= (line
+ linesonscreen
)))
883 cr
= InterColor(cr
, blackColor
, 10);
886 lineRect
.top
= (LONG
)Y
;
887 lineRect
.bottom
= (currentLine
* height
/ (LONG
)m_ID
.size());
888 ::ExtTextOut(hDC
, 0, 0, ETO_OPAQUE
, &lineRect
, NULL
, 0, NULL
);
894 // now draw two lines indicating the scroll position of the source view
895 SetBkColor(hDC
, blackColor
);
896 lineRect
.top
= (LONG
)line
* height
/ (LONG
)m_ID
.size();
897 lineRect
.bottom
= lineRect
.top
+1;
898 ::ExtTextOut(hDC
, 0, 0, ETO_OPAQUE
, &lineRect
, NULL
, 0, NULL
);
899 lineRect
.top
= (LONG
)(line
+ linesonscreen
) * height
/ (LONG
)m_ID
.size();
900 lineRect
.bottom
= lineRect
.top
+1;
901 ::ExtTextOut(hDC
, 0, 0, ETO_OPAQUE
, &lineRect
, NULL
, 0, NULL
);
906 void CTortoiseGitBlameView::StringExpand(LPSTR str
)
911 cPos
= strchr(cPos
, '\n');
914 memmove(cPos
+1, cPos
, strlen(cPos
)*sizeof(char));
919 } while (cPos
!= NULL
);
921 void CTortoiseGitBlameView::StringExpand(LPWSTR str
)
923 wchar_t * cPos
= str
;
926 cPos
= wcschr(cPos
, '\n');
929 memmove(cPos
+1, cPos
, wcslen(cPos
)*sizeof(wchar_t));
934 } while (cPos
!= NULL
);
937 void CTortoiseGitBlameView::SetupLexer(CString filename
)
941 //const char * lineptr = _tcsrchr(filename, '.');
942 int start
=filename
.ReverseFind(_T('.'));
945 //_tcscpy_s(line, 20, lineptr+1);
946 //_tcslwr_s(line, 20);
947 CString ext
=filename
.Right(filename
.GetLength()-start
-1);
948 line
=ext
.GetBuffer();
950 if ((_tcscmp(line
, _T("py"))==0)||
951 (_tcscmp(line
, _T("pyw"))==0))
953 SendEditor(SCI_SETLEXER
, SCLEX_PYTHON
);
954 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("and assert break class continue def del elif \
955 else except exec finally for from global if import in is lambda None \
956 not or pass print raise return try while yield")).GetBuffer()));
957 SetAStyle(SCE_P_DEFAULT
, black
);
958 SetAStyle(SCE_P_COMMENTLINE
, darkGreen
);
959 SetAStyle(SCE_P_NUMBER
, RGB(0, 0x80, 0x80));
960 SetAStyle(SCE_P_STRING
, RGB(0, 0, 0x80));
961 SetAStyle(SCE_P_CHARACTER
, RGB(0, 0, 0x80));
962 SetAStyle(SCE_P_WORD
, RGB(0x80, 0, 0x80));
963 SetAStyle(SCE_P_TRIPLE
, black
);
964 SetAStyle(SCE_P_TRIPLEDOUBLE
, black
);
965 SetAStyle(SCE_P_CLASSNAME
, darkBlue
);
966 SetAStyle(SCE_P_DEFNAME
, darkBlue
);
967 SetAStyle(SCE_P_OPERATOR
, darkBlue
);
968 SetAStyle(SCE_P_IDENTIFIER
, darkBlue
);
969 SetAStyle(SCE_P_COMMENTBLOCK
, darkGreen
);
970 SetAStyle(SCE_P_STRINGEOL
, red
);
972 if ((_tcscmp(line
, _T("c"))==0)||
973 (_tcscmp(line
, _T("cc"))==0)||
974 (_tcscmp(line
, _T("cpp"))==0)||
975 (_tcscmp(line
, _T("cxx"))==0)||
976 (_tcscmp(line
, _T("h"))==0)||
977 (_tcscmp(line
, _T("hh"))==0)||
978 (_tcscmp(line
, _T("hpp"))==0)||
979 (_tcscmp(line
, _T("hxx"))==0)||
980 (_tcscmp(line
, _T("dlg"))==0)||
981 (_tcscmp(line
, _T("mak"))==0))
983 SendEditor(SCI_SETLEXER
, SCLEX_CPP
);
984 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("and and_eq asm auto bitand bitor bool break \
985 case catch char class compl const const_cast continue \
986 default delete do double dynamic_cast else enum explicit export extern false float for \
987 friend goto if inline int long mutable namespace new not not_eq \
988 operator or or_eq private protected public \
989 register reinterpret_cast return short signed sizeof static static_cast struct switch \
990 template this throw true try typedef typeid typename union unsigned using \
991 virtual void volatile wchar_t while xor xor_eq")).GetBuffer()));
992 SendEditor(SCI_SETKEYWORDS
, 3, (LPARAM
)(m_TextView
.StringForControl(_T("a addindex addtogroup anchor arg attention \
993 author b brief bug c class code date def defgroup deprecated dontinclude \
994 e em endcode endhtmlonly endif endlatexonly endlink endverbatim enum example exception \
995 f$ f[ f] file fn hideinitializer htmlinclude htmlonly \
996 if image include ingroup internal invariant interface latexonly li line link \
997 mainpage name namespace nosubgrouping note overload \
998 p page par param post pre ref relates remarks return retval \
999 sa section see showinitializer since skip skipline struct subsection \
1000 test throw todo typedef union until \
1001 var verbatim verbinclude version warning weakgroup $ @ \\ & < > # { }")).GetBuffer()));
1004 if (_tcscmp(line
, _T("cs"))==0)
1006 SendEditor(SCI_SETLEXER
, SCLEX_CPP
);
1007 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("abstract as base bool break byte case catch char checked class \
1008 const continue decimal default delegate do double else enum \
1009 event explicit extern false finally fixed float for foreach goto if \
1010 implicit in int interface internal is lock long namespace new null \
1011 object operator out override params private protected public \
1012 readonly ref return sbyte sealed short sizeof stackalloc static \
1013 string struct switch this throw true try typeof uint ulong \
1014 unchecked unsafe ushort using virtual void while")).GetBuffer()));
1017 if ((_tcscmp(line
, _T("rc"))==0)||
1018 (_tcscmp(line
, _T("rc2"))==0))
1020 SendEditor(SCI_SETLEXER
, SCLEX_CPP
);
1021 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("ACCELERATORS ALT AUTO3STATE AUTOCHECKBOX AUTORADIOBUTTON \
1022 BEGIN BITMAP BLOCK BUTTON CAPTION CHARACTERISTICS CHECKBOX CLASS \
1023 COMBOBOX CONTROL CTEXT CURSOR DEFPUSHBUTTON DIALOG DIALOGEX DISCARDABLE \
1024 EDITTEXT END EXSTYLE FONT GROUPBOX ICON LANGUAGE LISTBOX LTEXT \
1025 MENU MENUEX MENUITEM MESSAGETABLE POPUP \
1026 PUSHBUTTON RADIOBUTTON RCDATA RTEXT SCROLLBAR SEPARATOR SHIFT STATE3 \
1027 STRINGTABLE STYLE TEXTINCLUDE VALUE VERSION VERSIONINFO VIRTKEY")).GetBuffer()));
1030 if ((_tcscmp(line
, _T("idl"))==0)||
1031 (_tcscmp(line
, _T("odl"))==0))
1033 SendEditor(SCI_SETLEXER
, SCLEX_CPP
);
1034 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("aggregatable allocate appobject arrays async async_uuid \
1036 bindable boolean broadcast byte byte_count \
1037 call_as callback char coclass code comm_status \
1038 const context_handle context_handle_noserialize \
1039 context_handle_serialize control cpp_quote custom \
1040 decode default defaultbind defaultcollelem \
1041 defaultvalue defaultvtable dispinterface displaybind dllname \
1043 enable_allocate encode endpoint entry enum error_status_t \
1045 fault_status first_is float \
1046 handle_t heap helpcontext helpfile helpstring \
1047 helpstringcontext helpstringdll hidden hyper \
1048 id idempotent ignore iid_as iid_is immediatebind implicit_handle \
1049 import importlib in include in_line int __int64 __int3264 interface \
1050 last_is lcid length_is library licensed local long \
1051 max_is maybe message methods midl_pragma \
1052 midl_user_allocate midl_user_free min_is module ms_union \
1053 ncacn_at_dsp ncacn_dnet_nsp ncacn_http ncacn_ip_tcp \
1054 ncacn_nb_ipx ncacn_nb_nb ncacn_nb_tcp ncacn_np \
1055 ncacn_spx ncacn_vns_spp ncadg_ip_udp ncadg_ipx ncadg_mq \
1056 ncalrpc nocode nonbrowsable noncreatable nonextensible notify \
1057 object odl oleautomation optimize optional out out_of_line \
1058 pipe pointer_default pragma properties propget propput propputref \
1060 range readonly ref represent_as requestedit restricted retval \
1061 shape short signed size_is small source strict_context_handle \
1062 string struct switch switch_is switch_type \
1063 transmit_as typedef \
1064 uidefault union unique unsigned user_marshal usesgetlasterror uuid \
1065 v1_enum vararg version void wchar_t wire_marshal")).GetBuffer()));
1068 if (_tcscmp(line
, _T("java"))==0)
1070 SendEditor(SCI_SETLEXER
, SCLEX_CPP
);
1071 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("abstract assert boolean break byte case catch char class \
1072 const continue default do double else extends final finally float for future \
1073 generic goto if implements import inner instanceof int interface long \
1074 native new null outer package private protected public rest \
1075 return short static super switch synchronized this throw throws \
1076 transient try var void volatile while")).GetBuffer()));
1079 if (_tcscmp(line
, _T("js"))==0)
1081 SendEditor(SCI_SETLEXER
, SCLEX_CPP
);
1082 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("abstract boolean break byte case catch char class \
1083 const continue debugger default delete do double else enum export extends \
1084 final finally float for function goto if implements import in instanceof \
1085 int interface long native new package private protected public \
1086 return short static super switch synchronized this throw throws \
1087 transient try typeof var void volatile while with")).GetBuffer()));
1090 if ((_tcscmp(line
, _T("pas"))==0)||
1091 (_tcscmp(line
, _T("dpr"))==0)||
1092 (_tcscmp(line
, _T("pp"))==0))
1094 SendEditor(SCI_SETLEXER
, SCLEX_PASCAL
);
1095 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("and array as begin case class const constructor \
1096 destructor div do downto else end except file finally \
1097 for function goto if implementation in inherited \
1098 interface is mod not object of on or packed \
1099 procedure program property raise record repeat \
1100 set shl shr then threadvar to try type unit \
1101 until uses var while with xor")).GetBuffer()));
1104 if ((_tcscmp(line
, _T("as"))==0)||
1105 (_tcscmp(line
, _T("asc"))==0)||
1106 (_tcscmp(line
, _T("jsfl"))==0))
1108 SendEditor(SCI_SETLEXER
, SCLEX_CPP
);
1109 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("add and break case catch class continue default delete do \
1110 dynamic else eq extends false finally for function ge get gt if implements import in \
1111 instanceof interface intrinsic le lt ne new not null or private public return \
1112 set static super switch this throw true try typeof undefined var void while with")).GetBuffer()));
1113 SendEditor(SCI_SETKEYWORDS
, 1, (LPARAM
)(m_TextView
.StringForControl(_T("Array Arguments Accessibility Boolean Button Camera Color \
1114 ContextMenu ContextMenuItem Date Error Function Key LoadVars LocalConnection Math \
1115 Microphone Mouse MovieClip MovieClipLoader NetConnection NetStream Number Object \
1116 PrintJob Selection SharedObject Sound Stage String StyleSheet System TextField \
1117 TextFormat TextSnapshot Video Void XML XMLNode XMLSocket \
1118 _accProps _focusrect _global _highquality _parent _quality _root _soundbuftime \
1119 arguments asfunction call capabilities chr clearInterval duplicateMovieClip \
1120 escape eval fscommand getProperty getTimer getURL getVersion gotoAndPlay gotoAndStop \
1121 ifFrameLoaded Infinity -Infinity int isFinite isNaN length loadMovie loadMovieNum \
1122 loadVariables loadVariablesNum maxscroll mbchr mblength mbord mbsubstring MMExecute \
1123 NaN newline nextFrame nextScene on onClipEvent onUpdate ord parseFloat parseInt play \
1124 prevFrame prevScene print printAsBitmap printAsBitmapNum printNum random removeMovieClip \
1125 scroll set setInterval setProperty startDrag stop stopAllSounds stopDrag substring \
1126 targetPath tellTarget toggleHighQuality trace unescape unloadMovie unLoadMovieNum updateAfterEvent")).GetBuffer()));
1129 if ((_tcscmp(line
, _T("html"))==0)||
1130 (_tcscmp(line
, _T("htm"))==0)||
1131 (_tcscmp(line
, _T("shtml"))==0)||
1132 (_tcscmp(line
, _T("htt"))==0)||
1133 (_tcscmp(line
, _T("xml"))==0)||
1134 (_tcscmp(line
, _T("asp"))==0)||
1135 (_tcscmp(line
, _T("xsl"))==0)||
1136 (_tcscmp(line
, _T("php"))==0)||
1137 (_tcscmp(line
, _T("xhtml"))==0)||
1138 (_tcscmp(line
, _T("phtml"))==0)||
1139 (_tcscmp(line
, _T("cfm"))==0)||
1140 (_tcscmp(line
, _T("tpl"))==0)||
1141 (_tcscmp(line
, _T("dtd"))==0)||
1142 (_tcscmp(line
, _T("hta"))==0)||
1143 (_tcscmp(line
, _T("htd"))==0)||
1144 (_tcscmp(line
, _T("wxs"))==0))
1146 SendEditor(SCI_SETLEXER
, SCLEX_HTML
);
1147 SendEditor(SCI_SETSTYLEBITS
, 7);
1148 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("a abbr acronym address applet area b base basefont \
1149 bdo big blockquote body br button caption center \
1150 cite code col colgroup dd del dfn dir div dl dt em \
1151 fieldset font form frame frameset h1 h2 h3 h4 h5 h6 \
1152 head hr html i iframe img input ins isindex kbd label \
1153 legend li link map menu meta noframes noscript \
1154 object ol optgroup option p param pre q s samp \
1155 script select small span strike strong style sub sup \
1156 table tbody td textarea tfoot th thead title tr tt u ul \
1157 var xml xmlns abbr accept-charset accept accesskey action align alink \
1158 alt archive axis background bgcolor border \
1159 cellpadding cellspacing char charoff charset checked cite \
1160 class classid clear codebase codetype color cols colspan \
1161 compact content coords \
1162 data datafld dataformatas datapagesize datasrc datetime \
1163 declare defer dir disabled enctype event \
1164 face for frame frameborder \
1165 headers height href hreflang hspace http-equiv \
1166 id ismap label lang language leftmargin link longdesc \
1167 marginwidth marginheight maxlength media method multiple \
1168 name nohref noresize noshade nowrap \
1169 object onblur onchange onclick ondblclick onfocus \
1170 onkeydown onkeypress onkeyup onload onmousedown \
1171 onmousemove onmouseover onmouseout onmouseup \
1172 onreset onselect onsubmit onunload \
1173 profile prompt readonly rel rev rows rowspan rules \
1174 scheme scope selected shape size span src standby start style \
1175 summary tabindex target text title topmargin type usemap \
1176 valign value valuetype version vlink vspace width \
1177 text password checkbox radio submit reset \
1178 file hidden image")).GetBuffer()));
1179 SendEditor(SCI_SETKEYWORDS
, 1, (LPARAM
)(m_TextView
.StringForControl(_T("assign audio block break catch choice clear disconnect else elseif \
1180 emphasis enumerate error exit field filled form goto grammar help \
1181 if initial link log menu meta noinput nomatch object option p paragraph \
1182 param phoneme prompt property prosody record reprompt return s say-as \
1183 script sentence subdialog submit throw transfer value var voice vxml")).GetBuffer()));
1184 SendEditor(SCI_SETKEYWORDS
, 2, (LPARAM
)(m_TextView
.StringForControl(_T("accept age alphabet anchor application base beep bridge category charset \
1185 classid cond connecttimeout content contour count dest destexpr dtmf dtmfterm \
1186 duration enctype event eventexpr expr expritem fetchtimeout finalsilence \
1187 gender http-equiv id level maxage maxstale maxtime message messageexpr \
1188 method mime modal mode name namelist next nextitem ph pitch range rate \
1189 scope size sizeexpr skiplist slot src srcexpr sub time timeexpr timeout \
1190 transferaudio type value variant version volume xml:lang")).GetBuffer()));
1191 SendEditor(SCI_SETKEYWORDS
, 3, (LPARAM
)(m_TextView
.StringForControl(_T("and assert break class continue def del elif \
1192 else except exec finally for from global if import in is lambda None \
1193 not or pass print raise return try while yield")).GetBuffer()));
1194 SendEditor(SCI_SETKEYWORDS
, 4, (LPARAM
)(m_TextView
.StringForControl(_T("and argv as argc break case cfunction class continue declare default do \
1195 die echo else elseif empty enddeclare endfor endforeach endif endswitch \
1196 endwhile e_all e_parse e_error e_warning eval exit extends false for \
1197 foreach function global http_cookie_vars http_get_vars http_post_vars \
1198 http_post_files http_env_vars http_server_vars if include include_once \
1199 list new not null old_function or parent php_os php_self php_version \
1200 print require require_once return static switch stdclass this true var \
1201 xor virtual while __file__ __line__ __sleep __wakeup")).GetBuffer()));
1203 SetAStyle(SCE_H_TAG
, darkBlue
);
1204 SetAStyle(SCE_H_TAGUNKNOWN
, red
);
1205 SetAStyle(SCE_H_ATTRIBUTE
, darkBlue
);
1206 SetAStyle(SCE_H_ATTRIBUTEUNKNOWN
, red
);
1207 SetAStyle(SCE_H_NUMBER
, RGB(0x80,0,0x80));
1208 SetAStyle(SCE_H_DOUBLESTRING
, RGB(0,0x80,0));
1209 SetAStyle(SCE_H_SINGLESTRING
, RGB(0,0x80,0));
1210 SetAStyle(SCE_H_OTHER
, RGB(0x80,0,0x80));
1211 SetAStyle(SCE_H_COMMENT
, RGB(0x80,0x80,0));
1212 SetAStyle(SCE_H_ENTITY
, RGB(0x80,0,0x80));
1214 SetAStyle(SCE_H_TAGEND
, darkBlue
);
1215 SetAStyle(SCE_H_XMLSTART
, darkBlue
); // <?
1216 SetAStyle(SCE_H_QUESTION
, darkBlue
); // <?
1217 SetAStyle(SCE_H_XMLEND
, darkBlue
); // ?>
1218 SetAStyle(SCE_H_SCRIPT
, darkBlue
); // <script
1219 SetAStyle(SCE_H_ASP
, RGB(0x4F, 0x4F, 0), RGB(0xFF, 0xFF, 0)); // <% ... %>
1220 SetAStyle(SCE_H_ASPAT
, RGB(0x4F, 0x4F, 0), RGB(0xFF, 0xFF, 0)); // <%@ ... %>
1222 SetAStyle(SCE_HB_DEFAULT
, black
);
1223 SetAStyle(SCE_HB_COMMENTLINE
, darkGreen
);
1224 SetAStyle(SCE_HB_NUMBER
, RGB(0,0x80,0x80));
1225 SetAStyle(SCE_HB_WORD
, darkBlue
);
1226 SendEditor(SCI_STYLESETBOLD
, SCE_HB_WORD
, 1);
1227 SetAStyle(SCE_HB_STRING
, RGB(0x80,0,0x80));
1228 SetAStyle(SCE_HB_IDENTIFIER
, black
);
1230 // This light blue is found in the windows system palette so is safe to use even in 256 colour modes.
1231 // Show the whole section of VBScript with light blue background
1232 for (int bstyle
=SCE_HB_DEFAULT
; bstyle
<=SCE_HB_STRINGEOL
; bstyle
++) {
1233 SendEditor(SCI_STYLESETFONT
, bstyle
,
1234 reinterpret_cast<LPARAM
>(m_TextView
.StringForControl(_T("Lucida Console")).GetBuffer()));
1235 SendEditor(SCI_STYLESETBACK
, bstyle
, lightBlue
);
1236 // This call extends the backround colour of the last style on the line to the edge of the window
1237 SendEditor(SCI_STYLESETEOLFILLED
, bstyle
, 1);
1239 SendEditor(SCI_STYLESETBACK
, SCE_HB_STRINGEOL
, RGB(0x7F,0x7F,0xFF));
1240 SendEditor(SCI_STYLESETFONT
, SCE_HB_COMMENTLINE
,
1241 reinterpret_cast<LPARAM
>(m_TextView
.StringForControl(_T("Lucida Console")).GetBuffer()));
1243 SetAStyle(SCE_HBA_DEFAULT
, black
);
1244 SetAStyle(SCE_HBA_COMMENTLINE
, darkGreen
);
1245 SetAStyle(SCE_HBA_NUMBER
, RGB(0,0x80,0x80));
1246 SetAStyle(SCE_HBA_WORD
, darkBlue
);
1247 SendEditor(SCI_STYLESETBOLD
, SCE_HBA_WORD
, 1);
1248 SetAStyle(SCE_HBA_STRING
, RGB(0x80,0,0x80));
1249 SetAStyle(SCE_HBA_IDENTIFIER
, black
);
1251 // Show the whole section of ASP VBScript with bright yellow background
1252 for (int bastyle
=SCE_HBA_DEFAULT
; bastyle
<=SCE_HBA_STRINGEOL
; bastyle
++) {
1253 SendEditor(SCI_STYLESETFONT
, bastyle
,
1254 reinterpret_cast<LPARAM
>(m_TextView
.StringForControl(_T("Lucida Console")).GetBuffer()));
1255 SendEditor(SCI_STYLESETBACK
, bastyle
, RGB(0xFF, 0xFF, 0));
1256 // This call extends the backround colour of the last style on the line to the edge of the window
1257 SendEditor(SCI_STYLESETEOLFILLED
, bastyle
, 1);
1259 SendEditor(SCI_STYLESETBACK
, SCE_HBA_STRINGEOL
, RGB(0xCF,0xCF,0x7F));
1260 SendEditor(SCI_STYLESETFONT
, SCE_HBA_COMMENTLINE
,
1261 reinterpret_cast<LPARAM
>(m_TextView
.StringForControl(_T("Lucida Console")).GetBuffer()));
1263 // If there is no need to support embedded Javascript, the following code can be dropped.
1264 // Javascript will still be correctly processed but will be displayed in just the default style.
1266 SetAStyle(SCE_HJ_START
, RGB(0x80,0x80,0));
1267 SetAStyle(SCE_HJ_DEFAULT
, black
);
1268 SetAStyle(SCE_HJ_COMMENT
, darkGreen
);
1269 SetAStyle(SCE_HJ_COMMENTLINE
, darkGreen
);
1270 SetAStyle(SCE_HJ_COMMENTDOC
, darkGreen
);
1271 SetAStyle(SCE_HJ_NUMBER
, RGB(0,0x80,0x80));
1272 SetAStyle(SCE_HJ_WORD
, black
);
1273 SetAStyle(SCE_HJ_KEYWORD
, darkBlue
);
1274 SetAStyle(SCE_HJ_DOUBLESTRING
, RGB(0x80,0,0x80));
1275 SetAStyle(SCE_HJ_SINGLESTRING
, RGB(0x80,0,0x80));
1276 SetAStyle(SCE_HJ_SYMBOLS
, black
);
1278 SetAStyle(SCE_HJA_START
, RGB(0x80,0x80,0));
1279 SetAStyle(SCE_HJA_DEFAULT
, black
);
1280 SetAStyle(SCE_HJA_COMMENT
, darkGreen
);
1281 SetAStyle(SCE_HJA_COMMENTLINE
, darkGreen
);
1282 SetAStyle(SCE_HJA_COMMENTDOC
, darkGreen
);
1283 SetAStyle(SCE_HJA_NUMBER
, RGB(0,0x80,0x80));
1284 SetAStyle(SCE_HJA_WORD
, black
);
1285 SetAStyle(SCE_HJA_KEYWORD
, darkBlue
);
1286 SetAStyle(SCE_HJA_DOUBLESTRING
, RGB(0x80,0,0x80));
1287 SetAStyle(SCE_HJA_SINGLESTRING
, RGB(0x80,0,0x80));
1288 SetAStyle(SCE_HJA_SYMBOLS
, black
);
1290 SetAStyle(SCE_HPHP_DEFAULT
, black
);
1291 SetAStyle(SCE_HPHP_HSTRING
, RGB(0x80,0,0x80));
1292 SetAStyle(SCE_HPHP_SIMPLESTRING
, RGB(0x80,0,0x80));
1293 SetAStyle(SCE_HPHP_WORD
, darkBlue
);
1294 SetAStyle(SCE_HPHP_NUMBER
, RGB(0,0x80,0x80));
1295 SetAStyle(SCE_HPHP_VARIABLE
, red
);
1296 SetAStyle(SCE_HPHP_HSTRING_VARIABLE
, red
);
1297 SetAStyle(SCE_HPHP_COMPLEX_VARIABLE
, red
);
1298 SetAStyle(SCE_HPHP_COMMENT
, darkGreen
);
1299 SetAStyle(SCE_HPHP_COMMENTLINE
, darkGreen
);
1300 SetAStyle(SCE_HPHP_OPERATOR
, darkBlue
);
1302 // Show the whole section of Javascript with off white background
1303 for (int jstyle
=SCE_HJ_DEFAULT
; jstyle
<=SCE_HJ_SYMBOLS
; jstyle
++) {
1304 SendEditor(SCI_STYLESETFONT
, jstyle
,
1305 reinterpret_cast<LPARAM
>(m_TextView
.StringForControl(_T("Lucida Console")).GetBuffer()));
1306 SendEditor(SCI_STYLESETBACK
, jstyle
, offWhite
);
1307 SendEditor(SCI_STYLESETEOLFILLED
, jstyle
, 1);
1309 SendEditor(SCI_STYLESETBACK
, SCE_HJ_STRINGEOL
, RGB(0xDF, 0xDF, 0x7F));
1310 SendEditor(SCI_STYLESETEOLFILLED
, SCE_HJ_STRINGEOL
, 1);
1312 // Show the whole section of Javascript with brown background
1313 for (int jastyle
=SCE_HJA_DEFAULT
; jastyle
<=SCE_HJA_SYMBOLS
; jastyle
++) {
1314 SendEditor(SCI_STYLESETFONT
, jastyle
,
1315 reinterpret_cast<LPARAM
>(m_TextView
.StringForControl(_T("Lucida Console")).GetBuffer()));
1316 SendEditor(SCI_STYLESETBACK
, jastyle
, RGB(0xDF, 0xDF, 0x7F));
1317 SendEditor(SCI_STYLESETEOLFILLED
, jastyle
, 1);
1319 SendEditor(SCI_STYLESETBACK
, SCE_HJA_STRINGEOL
, RGB(0x0,0xAF,0x5F));
1320 SendEditor(SCI_STYLESETEOLFILLED
, SCE_HJA_STRINGEOL
, 1);
1325 SendEditor(SCI_SETLEXER
, SCLEX_CPP
);
1328 SendEditor(SCI_COLOURISE
, 0, -1);
1332 void CTortoiseGitBlameView::SetupCppLexer()
1334 SetAStyle(SCE_C_DEFAULT
, RGB(0, 0, 0));
1335 SetAStyle(SCE_C_COMMENT
, RGB(0, 0x80, 0));
1336 SetAStyle(SCE_C_COMMENTLINE
, RGB(0, 0x80, 0));
1337 SetAStyle(SCE_C_COMMENTDOC
, RGB(0, 0x80, 0));
1338 SetAStyle(SCE_C_COMMENTLINEDOC
, RGB(0, 0x80, 0));
1339 SetAStyle(SCE_C_COMMENTDOCKEYWORD
, RGB(0, 0x80, 0));
1340 SetAStyle(SCE_C_COMMENTDOCKEYWORDERROR
, RGB(0, 0x80, 0));
1341 SetAStyle(SCE_C_NUMBER
, RGB(0, 0x80, 0x80));
1342 SetAStyle(SCE_C_WORD
, RGB(0, 0, 0x80));
1343 SendEditor(SCE_C_WORD
, 1);
1344 SetAStyle(SCE_C_STRING
, RGB(0x80, 0, 0x80));
1345 SetAStyle(SCE_C_IDENTIFIER
, RGB(0, 0, 0));
1346 SetAStyle(SCE_C_PREPROCESSOR
, RGB(0x80, 0, 0));
1347 SetAStyle(SCE_C_OPERATOR
, RGB(0x80, 0x80, 0));
1350 int CTortoiseGitBlameView::GetEncode(unsigned char *buff
, int size
, int *bomoffset
)
1352 CFileTextLines textlines
;
1353 CFileTextLines::UnicodeType type
= textlines
.CheckUnicodeType(buff
, size
);
1355 if(type
== CFileTextLines::UTF8BOM
)
1360 if(type
== CFileTextLines::UTF8
)
1363 if(type
== CFileTextLines::UNICODE_LE
)
1369 // check for UNICODE_BE does not work, because git blame produces two NUL chars in a row
1370 if(type
== CFileTextLines::BINARY
&& size
> 2 && buff
[0] == 0xFE && buff
[1] == 0xFF)
1379 void CTortoiseGitBlameView::UpdateInfo(int Encode
)
1381 BYTE_VECTOR
&data
= GetDocument()->m_BlameData
;
1387 CLogDataVector
* pRevs
= GetLogData();
1389 this->m_CommitHash
.clear();
1390 this->m_Authors
.clear();
1396 SendEditor(SCI_SETREADONLY
, FALSE
);
1397 SendEditor(SCI_CLEARALL
);
1398 SendEditor(EM_EMPTYUNDOBUFFER
);
1399 SendEditor(SCI_SETSAVEPOINT
);
1400 SendEditor(SCI_CANCEL
);
1401 SendEditor(SCI_SETUNDOCOLLECTION
, 0);
1403 SendEditor(SCI_SETCODEPAGE
, SC_CP_UTF8
);
1406 int encoding
= Encode
;
1407 while( pos
>=0 && current
>=0 && pos
<data
.size() )
1409 current
= data
.findData((const BYTE
*)"\n",1,pos
);
1410 //one=data.Tokenize(_T("\n"),pos);
1412 bool isbound
= ( data
[pos
] == _T('^') );
1414 if( (data
.size() - pos
) >1 && data
[pos
] == _T('^'))
1425 if(git_get_sha1((const char*)&data
[pos
], hash
.m_hash
))
1427 ::MessageBox(NULL
, _T("Can't get hash"), _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
1432 hash
.ConvertFromStrA((char*)&data
[pos
]);
1436 start
=data
.findData((const BYTE
*)")",1,pos
+ 40);
1449 if( pos
<40 && encoding
==0)
1452 encoding
= GetEncode(&data
[start
+ 2], (int)(data
.size() - start
- 2), &bomoffset
);
1455 if(encoding
== 1201)
1458 DWORD size
= ((current
- start
-2 - bomoffset
)/2);
1459 TCHAR
*buffer
= strw
.GetBuffer(size
);
1460 memcpy(buffer
, &data
[start
+ 2 + bomoffset
],sizeof(TCHAR
)*size
);
1461 // swap the bytes to little-endian order to get proper strings in wchar_t format
1462 wchar_t * pSwapBuf
= buffer
;
1463 for (DWORD i
= 0; i
<size
; ++i
)
1465 *pSwapBuf
= WideCharSwap2(*pSwapBuf
);
1468 strw
.ReleaseBuffer();
1470 stra
= CUnicodeUtils::GetUTF8(strw
);
1472 else if(encoding
== 1200)
1475 // the first bomoffset is 2, after that it's 1 (see issue #920)
1478 int size
= ((current
- start
-2 - bomoffset
)/2);
1479 TCHAR
*buffer
= strw
.GetBuffer(size
);
1480 memcpy(buffer
, &data
[start
+ 2 + bomoffset
],sizeof(TCHAR
)*size
);
1481 strw
.ReleaseBuffer();
1483 stra
= CUnicodeUtils::GetUTF8(strw
);
1485 else if(encoding
== CP_UTF8
)
1487 stra
= &data
[start
+ 2 + bomoffset
];
1492 strw
= CUnicodeUtils::GetUnicode(CStringA(&data
[start
+ 2 + bomoffset
]), encoding
);
1493 stra
= CUnicodeUtils::GetUTF8(strw
);
1497 SendEditor(SCI_REPLACESEL
, 0, (LPARAM
)(LPCSTR
)stra
);
1498 SendEditor(SCI_REPLACESEL
, 0, (LPARAM
)(LPCSTR
)"\n\0\0\0");
1501 data
[current
] = '\n';
1505 if(this->m_NoListCommit
.find(hash
) == m_NoListCommit
.end() )
1507 this->m_NoListCommit
[hash
].GetCommitFromHash(hash
);
1509 m_ID
.push_back(-1); // m_ID is calculated lazy on demand
1510 m_Authors
.push_back(m_NoListCommit
[hash
].GetAuthorName());
1512 m_CommitHash
.push_back(hash
);
1524 file
.Open(this->GetDocument()->m_TempFileName
,CFile::modeRead
);
1526 m_Buffer
= new char[file
.GetLength()+4];
1527 m_Buffer
[file
.GetLength()] =0;
1528 m_Buffer
[file
.GetLength()+1] =0;
1529 m_Buffer
[file
.GetLength()+2] =0;
1530 m_Buffer
[file
.GetLength()+3] =0;
1532 file
.Read(m_Buffer
, file
.GetLength());
1535 int encoding
= GetEncode( (unsigned char *)m_Buffer
, file
.GetLength(), &bomoffset
);
1538 //SendEditor(SCI_SETCODEPAGE, encoding);
1540 //SendEditor(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)(m_Buffer + bomoffset));
1542 SetupLexer(GetDocument()->m_CurrentFileName
);
1544 SendEditor(SCI_SETUNDOCOLLECTION
, 1);
1545 SendEditor(EM_EMPTYUNDOBUFFER
);
1546 SendEditor(SCI_SETSAVEPOINT
);
1547 SendEditor(SCI_GOTOPOS
, 0);
1548 SendEditor(SCI_SETSCROLLWIDTHTRACKING
, TRUE
);
1549 SendEditor(SCI_SETREADONLY
, TRUE
);
1552 m_highestrev
= (long)(this->GetLogData()->size() + m_NoListCommit
.size());
1556 this->GetClientRect(rect
);
1557 //this->m_TextView.GetWindowRect(rect);
1558 //this->m_TextView.ScreenToClient(rect);
1559 rect
.left
=this->m_blamewidth
;
1560 this->m_TextView
.MoveWindow(rect
);
1565 CGitBlameLogList
* CTortoiseGitBlameView::GetLogList()
1567 return &(GetDocument()->GetMainFrame()->m_wndOutput
.m_LogList
);
1571 CLogDataVector
* CTortoiseGitBlameView::GetLogData()
1573 return &(GetDocument()->GetMainFrame()->m_wndOutput
.m_LogList
.m_logEntries
);
1576 void CTortoiseGitBlameView::OnSciPainted(NMHDR
*,LRESULT
*)
1581 void CTortoiseGitBlameView::OnLButtonDown(UINT nFlags
,CPoint point
)
1584 LONG line
= (LONG
)SendEditor(SCI_GETFIRSTVISIBLELINE
);
1585 LONG height
= (LONG
)SendEditor(SCI_TEXTHEIGHT
);
1586 line
= line
+ (point
.y
/height
);
1588 if (line
< (LONG
)m_CommitHash
.size())
1590 SetSelectedLine(line
);
1591 if (m_CommitHash
[line
] != m_SelectedHash
)
1593 m_SelectedHash
= m_CommitHash
[line
];
1595 // lazy calculate m_ID
1596 if (m_ID
[line
] == -1)
1598 m_ID
[line
] = -2; // don't do this lazy calculation again and again for unfindable hashes
1599 for(int i
= 0; i
<this->GetLogData()->size(); i
++)
1601 if(m_SelectedHash
== this->GetLogData()->at(i
))
1603 m_ID
[line
] = (LONG
)(this->GetLogData()->size() - i
);
1611 this->GetLogList()->SetItemState(this->GetLogList()->GetItemCount()-m_ID
[line
],
1614 this->GetLogList()->EnsureVisible(this->GetLogList()->GetItemCount()-m_ID
[line
], FALSE
);
1618 this->GetDocument()->GetMainFrame()->m_wndProperties
.UpdateProperties(&m_NoListCommit
[m_CommitHash
[line
]]);
1623 m_SelectedHash
.Empty();
1625 //::InvalidateRect( NULL, FALSE);
1627 this->m_TextView
.Invalidate();
1632 SetSelectedLine(-1);
1635 CView::OnLButtonDown(nFlags
,point
);
1638 void CTortoiseGitBlameView::OnSciGetBkColor(NMHDR
* hdr
, LRESULT
* result
)
1641 SCNotification
*notification
=reinterpret_cast<SCNotification
*>(hdr
);
1643 if ((m_colorage
)&&(notification
->line
< (int)m_CommitHash
.size()))
1645 if(m_CommitHash
[notification
->line
] == this->m_SelectedHash
)
1646 notification
->lParam
= m_selectedauthorcolor
;
1648 notification
->lParam
= InterColor(DWORD(m_regOldLinesColor
), DWORD(m_regNewLinesColor
), (m_ID
[notification
->line
]-m_lowestrev
)*100/((m_highestrev
-m_lowestrev
)+1));
1653 void CTortoiseGitBlameView::FocusOn(GitRev
*pRev
)
1655 this->GetDocument()->GetMainFrame()->m_wndProperties
.UpdateProperties(pRev
);
1659 if (m_SelectedHash
!= pRev
->m_CommitHash
) {
1660 m_SelectedHash
= pRev
->m_CommitHash
;
1662 for(i
=0;i
<m_CommitHash
.size();i
++)
1664 if( pRev
->m_CommitHash
== m_CommitHash
[i
] )
1668 this->m_TextView
.Invalidate();
1672 void CTortoiseGitBlameView::OnMouseHover(UINT nFlags
, CPoint point
)
1674 LONG_PTR line
= SendEditor(SCI_GETFIRSTVISIBLELINE
);
1675 LONG_PTR height
= SendEditor(SCI_TEXTHEIGHT
);
1676 line
= line
+ (point
.y
/height
);
1678 if (line
< (LONG
)m_CommitHash
.size())
1680 if (line
!= m_MouseLine
)
1682 m_MouseLine
= (LONG
)line
;//m_CommitHash[line];
1686 pRev
=&this->m_NoListCommit
[m_CommitHash
[line
]];
1691 pRev
=&this->GetLogData()->GetGitRevAt(this->GetLogList()->GetItemCount()-m_ID
[line
]);
1695 str
.Format(_T("%s: %s\n%s: %s <%s>\n%s: %s\n%s:\n%s\n%s"), m_sRev
, pRev
->m_CommitHash
.ToString(),
1696 m_sAuthor
, pRev
->GetAuthorName(), pRev
->GetAuthorEmail(),
1697 m_sDate
, CLoglistUtils::FormatDateAndTime(pRev
->GetAuthorDate(), m_DateFormat
, true, m_bRelativeTimes
),
1698 m_sMessage
, pRev
->GetSubject(),
1702 m_ToolTip
.AddTool(this, str
);
1705 rect
.left
=LOCATOR_WIDTH
;
1706 rect
.right
=this->m_blamewidth
+rect
.left
;
1707 rect
.top
= point
.y
- (LONG
)height
;
1708 rect
.bottom
= point
.y
+ (LONG
)height
;
1709 this->InvalidateRect(rect
);
1714 void CTortoiseGitBlameView::OnMouseMove(UINT nFlags
, CPoint point
)
1716 TRACKMOUSEEVENT tme
;
1717 tme
.cbSize
=sizeof(TRACKMOUSEEVENT
);
1718 tme
.dwFlags
=TME_HOVER
|TME_LEAVE
;
1719 tme
.hwndTrack
=this->m_hWnd
;
1721 TrackMouseEvent(&tme
);
1725 BOOL
CTortoiseGitBlameView::PreTranslateMessage(MSG
* pMsg
)
1727 m_ToolTip
.RelayEvent(pMsg
);
1728 return CView::PreTranslateMessage(pMsg
);
1731 void CTortoiseGitBlameView::OnEditFind()
1733 m_pFindDialog
=new CFindReplaceDialog();
1735 m_pFindDialog
->Create(TRUE
,_T(""),NULL
,FR_DOWN
,this);
1738 void CTortoiseGitBlameView::OnEditGoto()
1741 if(dlg
.DoModal()==IDOK
)
1743 this->GotoLine(dlg
.m_LineNumber
);
1747 LRESULT
CTortoiseGitBlameView::OnFindDialogMessage(WPARAM wParam
, LPARAM lParam
)
1749 ASSERT(m_pFindDialog
!= NULL
);
1751 // If the FR_DIALOGTERM flag is set,
1752 // invalidate the handle identifying the dialog box.
1753 if (m_pFindDialog
->IsTerminating())
1755 m_pFindDialog
= NULL
;
1759 // If the FR_FINDNEXT flag is set,
1760 // call the application-defined search routine
1761 // to search for the requested string.
1762 if(m_pFindDialog
->FindNext())
1764 //read data from dialog
1765 CString FindName
= m_pFindDialog
->GetFindString();
1766 bool bMatchCase
= m_pFindDialog
->MatchCase() == TRUE
;
1767 bool bMatchWholeWord
= m_pFindDialog
->MatchWholeWord() == TRUE
;
1768 bool bSearchDown
= m_pFindDialog
->SearchDown() == TRUE
;
1770 DoSearch(FindName
,m_pFindDialog
->m_fr
.Flags
);
1771 //with given name do search
1772 // *FindWhatYouNeed(FindName, bMatchCase, bMatchWholeWord, bSearchDown);
1778 void CTortoiseGitBlameView::OnViewNext()
1780 FindNextLine(this->m_SelectedHash
,false);
1782 void CTortoiseGitBlameView::OnViewPrev()
1784 FindNextLine(this->m_SelectedHash
,true);
1787 void CTortoiseGitBlameView::OnViewToggleAuthor()
1789 m_bShowAuthor
= ! m_bShowAuthor
;
1791 theApp
.WriteInt(_T("ShowAuthor"), m_bShowAuthor
);
1794 this->GetClientRect(&rect
);
1795 rect
.left
=GetBlameWidth();
1797 m_TextView
.MoveWindow(&rect
);
1800 void CTortoiseGitBlameView::OnUpdateViewToggleAuthor(CCmdUI
*pCmdUI
)
1802 pCmdUI
->SetCheck(m_bShowAuthor
);
1805 void CTortoiseGitBlameView::OnViewToggleFollowRenames()
1807 m_bFollowRenames
= ! m_bFollowRenames
;
1809 theApp
.WriteInt(_T("FollowRenames"), m_bFollowRenames
);
1811 UINT uCheck
= MF_BYCOMMAND
;
1812 uCheck
|= m_bFollowRenames
? MF_CHECKED
: MF_UNCHECKED
;
1813 CheckMenuItem(GetMenu()->m_hMenu
, ID_VIEW_FOLLOWRENAMES
, uCheck
);
1815 CTortoiseGitBlameDoc
*document
= (CTortoiseGitBlameDoc
*) m_pDocument
;
1816 if (!document
->m_CurrentFileName
.IsEmpty())
1818 theApp
.m_pDocManager
->OnFileNew();
1819 document
->OnOpenDocument(document
->m_CurrentFileName
, document
->m_Rev
);
1823 void CTortoiseGitBlameView::OnUpdateViewToggleFollowRenames(CCmdUI
*pCmdUI
)
1825 pCmdUI
->SetCheck(m_bFollowRenames
);
1828 void CTortoiseGitBlameView::OnUpdateViewCopyToClipboard(CCmdUI
*pCmdUI
)
1830 CWnd
* wnd
= GetFocus();
1831 if (wnd
== GetLogList())
1833 pCmdUI
->Enable(GetLogList()->GetSelectedCount() > 0);
1837 if (CString(wnd
->GetRuntimeClass()->m_lpszClassName
) == _T("CMFCPropertyGridCtrl"))
1839 CMFCPropertyGridCtrl
*grid
= (CMFCPropertyGridCtrl
*)wnd
;
1840 pCmdUI
->Enable(grid
->GetCurSel() && !grid
->GetCurSel()->IsGroup() && !CString(grid
->GetCurSel()->GetValue()).IsEmpty());
1843 pCmdUI
->Enable(m_TextView
.Call(SCI_GETSELECTIONSTART
) != m_TextView
.Call(SCI_GETSELECTIONEND
));
1846 pCmdUI
->Enable(FALSE
);
1849 int CTortoiseGitBlameView::FindNextLine(CGitHash CommitHash
,bool bUpOrDown
)
1851 LONG line
= (LONG
)SendEditor(SCI_GETFIRSTVISIBLELINE
);
1852 LONG startline
= line
;
1853 bool findNoMatch
=false;
1854 while(line
>=0 && line
<m_CommitHash
.size())
1856 if(m_CommitHash
[line
]!=CommitHash
)
1861 if(m_CommitHash
[line
] == CommitHash
&& findNoMatch
)
1863 if( line
== startline
+2 )
1871 line
=FindFirstLine(CommitHash
,line
);
1873 SendEditor(SCI_LINESCROLL
,0,line
-startline
-2);