1 // TortoiseGitBlame - a Viewer for Git Blames
3 // Copyright (C) 2008-2013 - TortoiseGit
4 // Copyright (C) 2010-2013 Sven Strickroth <email@cs-ware.de>
5 // Copyright (C) 2003-2008 - TortoiseSVN
7 // Copyright (C)2003 Don HO <donho@altern.org>
9 // This program is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU General Public License
11 // as published by the Free Software Foundation; either version 2
12 // of the License, or (at your option) any later version.
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
19 // You should have received a copy of the GNU General Public License
20 // along with this program; if not, write to the Free Software Foundation,
21 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 // CTortoiseGitBlameView.cpp : implementation of the CTortoiseGitBlameView class
27 #include "TortoiseGitBlame.h"
28 #include "CommonAppUtils.h"
29 #include "TortoiseGitBlameDoc.h"
30 #include "TortoiseGitBlameView.h"
32 #include "EditGotoDlg.h"
33 #include "LoglistUtils.h"
34 #include "FileTextLines.h"
35 #include "UniCodeUtils.h"
36 #include "MenuEncode.h"
39 #include "StringUtils.h"
40 #include "BlameIndexColors.h"
46 wchar_t WideCharSwap2(wchar_t nValue
)
48 return (((nValue
>> 8)) | (nValue
<< 8));
51 UINT
CTortoiseGitBlameView::m_FindDialogMessage
;
53 // CTortoiseGitBlameView
54 IMPLEMENT_DYNAMIC(CSciEditBlame
,CSciEdit
)
56 IMPLEMENT_DYNCREATE(CTortoiseGitBlameView
, CView
)
58 BEGIN_MESSAGE_MAP(CTortoiseGitBlameView
, CView
)
59 // Standard printing commands
60 ON_COMMAND(ID_FILE_PRINT
, &CView::OnFilePrint
)
61 ON_COMMAND(ID_FILE_PRINT_DIRECT
, &CView::OnFilePrint
)
62 ON_COMMAND(ID_FILE_PRINT_PREVIEW
, &CTortoiseGitBlameView::OnFilePrintPreview
)
63 ON_COMMAND(ID_EDIT_FIND
,OnEditFind
)
64 ON_COMMAND(ID_EDIT_GOTO
,OnEditGoto
)
65 ON_COMMAND(ID_EDIT_COPY
, CopyToClipboard
)
66 ON_UPDATE_COMMAND_UI(ID_EDIT_COPY
, OnUpdateViewCopyToClipboard
)
67 ON_COMMAND(ID_VIEW_NEXT
,OnViewNext
)
68 ON_COMMAND(ID_VIEW_PREV
,OnViewPrev
)
69 ON_COMMAND(ID_VIEW_SHOWAUTHOR
, OnViewToggleAuthor
)
70 ON_UPDATE_COMMAND_UI(ID_VIEW_SHOWAUTHOR
, OnUpdateViewToggleAuthor
)
71 ON_COMMAND(ID_VIEW_SHOWDATE
, OnViewToggleDate
)
72 ON_UPDATE_COMMAND_UI(ID_VIEW_SHOWDATE
, OnUpdateViewToggleDate
)
73 ON_COMMAND(ID_VIEW_FOLLOWRENAMES
, OnViewToggleFollowRenames
)
74 ON_UPDATE_COMMAND_UI(ID_VIEW_FOLLOWRENAMES
, OnUpdateViewToggleFollowRenames
)
75 ON_COMMAND(ID_VIEW_COLORBYAGE
, OnViewToggleColorByAge
)
76 ON_UPDATE_COMMAND_UI(ID_VIEW_COLORBYAGE
, OnUpdateViewToggleColorByAge
)
77 ON_COMMAND(ID_BLAMEPOPUP_COPYHASHTOCLIPBOARD
, CopyHashToClipboard
)
78 ON_COMMAND(ID_BLAMEPOPUP_COPYLOGTOCLIPBOARD
, CopySelectedLogToClipboard
)
79 ON_COMMAND(ID_BLAMEPOPUP_BLAMEPREVIOUSREVISION
, BlamePreviousRevision
)
80 ON_COMMAND(ID_BLAMEPOPUP_DIFFPREVIOUS
, DiffPreviousRevision
)
81 ON_COMMAND(ID_BLAMEPOPUP_SHOWLOG
, ShowLog
)
82 ON_UPDATE_COMMAND_UI(ID_BLAMEPOPUP_BLAMEPREVIOUSREVISION
, OnUpdateBlamePopupBlamePrevious
)
83 ON_UPDATE_COMMAND_UI(ID_BLAMEPOPUP_DIFFPREVIOUS
, OnUpdateBlamePopupDiffPrevious
)
84 ON_COMMAND_RANGE(IDM_FORMAT_ENCODE
, IDM_FORMAT_ENCODE_END
, OnChangeEncode
)
93 ON_NOTIFY(SCN_PAINTED
, IDC_SCINTILLA
, OnSciPainted
)
94 ON_NOTIFY(SCN_GETBKCOLOR
, IDC_SCINTILLA
, OnSciGetBkColor
)
95 ON_REGISTERED_MESSAGE(m_FindDialogMessage
, OnFindDialogMessage
)
99 // CTortoiseGitBlameView construction/destruction
101 CTortoiseGitBlameView::CTortoiseGitBlameView()
118 m_windowcolor
= ::GetSysColor(COLOR_WINDOW
);
119 m_textcolor
= ::GetSysColor(COLOR_WINDOWTEXT
);
120 m_texthighlightcolor
= ::GetSysColor(COLOR_HIGHLIGHTTEXT
);
121 m_mouserevcolor
= InterColor(m_windowcolor
, m_textcolor
, 20);
122 m_mouseauthorcolor
= InterColor(m_windowcolor
, m_textcolor
, 10);
123 m_selectedrevcolor
= ::GetSysColor(COLOR_HIGHLIGHT
);
124 m_selectedauthorcolor
= InterColor(m_selectedrevcolor
, m_texthighlightcolor
, 35);
128 m_selectedorigrev
= -1;
131 m_directFunction
= 0;
133 m_lowestrev
= LONG_MAX
;
135 m_colorage
= !!theApp
.GetInt(_T("ColorAge"));
139 m_bShowAuthor
= (theApp
.GetInt(_T("ShowAuthor"), 1) == 1);
140 m_bShowDate
= (theApp
.GetInt(_T("ShowDate"), 0) == 1);
141 m_bFollowRenames
= (theApp
.GetInt(_T("FollowRenames"), 0) == 1);
143 m_FindDialogMessage
= ::RegisterWindowMessage(FINDMSGSTRING
);
144 m_pFindDialog
= NULL
;
145 // get short/long datetime setting from registry
146 DWORD RegUseShortDateFormat
= CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE
);
147 if ( RegUseShortDateFormat
)
149 m_DateFormat
= DATE_SHORTDATE
;
153 m_DateFormat
= DATE_LONGDATE
;
155 // get relative time display setting from registry
156 DWORD regRelativeTimes
= CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE
);
157 m_bRelativeTimes
= (regRelativeTimes
!= 0);
159 m_sRev
.LoadString(IDS_LOG_REVISION
);
160 m_sAuthor
.LoadString(IDS_LOG_AUTHOR
);
161 m_sDate
.LoadString(IDS_LOG_DATE
);
162 m_sMessage
.LoadString(IDS_LOG_MESSAGE
);
167 CTortoiseGitBlameView::~CTortoiseGitBlameView()
170 DeleteObject(m_font
);
172 DeleteObject(m_italicfont
);
186 static EncodingUnit encodings
[] = {
187 {1250, "windows-1250"}, //IDM_FORMAT_WIN_1250
188 {1251, "windows-1251"}, //IDM_FORMAT_WIN_1251
189 {1252, "windows-1252"}, //IDM_FORMAT_WIN_1252
190 {1253, "windows-1253"}, //IDM_FORMAT_WIN_1253
191 {1254, "windows-1254"}, //IDM_FORMAT_WIN_1254
192 {1255, "windows-1255"}, //IDM_FORMAT_WIN_1255
193 {1256, "windows-1256"}, //IDM_FORMAT_WIN_1256
194 {1257, "windows-1257"}, //IDM_FORMAT_WIN_1257
195 {1258, "windows-1258"}, //IDM_FORMAT_WIN_1258
196 {28591, "latin1 ISO_8859-1 ISO-8859-1 CP819 IBM819 csISOLatin1 iso-ir-100 l1"}, //IDM_FORMAT_ISO_8859_1
197 {28592, "latin2 ISO_8859-2 ISO-8859-2 csISOLatin2 iso-ir-101 l2"}, //IDM_FORMAT_ISO_8859_2
198 {28593, "latin3 ISO_8859-3 ISO-8859-3 csISOLatin3 iso-ir-109 l3"}, //IDM_FORMAT_ISO_8859_3
199 {28594, "latin4 ISO_8859-4 ISO-8859-4 csISOLatin4 iso-ir-110 l4"}, //IDM_FORMAT_ISO_8859_4
200 {28595, "cyrillic ISO_8859-5 ISO-8859-5 csISOLatinCyrillic iso-ir-144"}, //IDM_FORMAT_ISO_8859_5
201 {28596, "arabic ISO_8859-6 ISO-8859-6 csISOLatinArabic iso-ir-127 ASMO-708 ECMA-114"}, //IDM_FORMAT_ISO_8859_6
202 {28597, "greek ISO_8859-7 ISO-8859-7 csISOLatinGreek greek8 iso-ir-126 ELOT_928 ECMA-118"}, //IDM_FORMAT_ISO_8859_7
203 {28598, "hebrew ISO_8859-8 ISO-8859-8 csISOLatinHebrew iso-ir-138"}, //IDM_FORMAT_ISO_8859_8
204 {28599, "latin5 ISO_8859-9 ISO-8859-9 csISOLatin5 iso-ir-148 l5"}, //IDM_FORMAT_ISO_8859_9
205 {28600, "latin6 ISO_8859-10 ISO-8859-10 csISOLatin6 iso-ir-157 l6"}, //IDM_FORMAT_ISO_8859_10
206 {28601, "ISO_8859-11 ISO-8859-11"}, //IDM_FORMAT_ISO_8859_11
207 {28603, "ISO_8859-13 ISO-8859-13"}, //IDM_FORMAT_ISO_8859_13
208 {28604, "iso-celtic latin8 ISO_8859-14 ISO-8859-14 18 iso-ir-199"}, //IDM_FORMAT_ISO_8859_14
209 {28605, "Latin-9 ISO_8859-15 ISO-8859-15"}, //IDM_FORMAT_ISO_8859_15
210 {28606, "latin10 ISO_8859-16 ISO-8859-16 110 iso-ir-226"}, //IDM_FORMAT_ISO_8859_16
211 {437, "IBM437 cp437 437 csPC8CodePage437"}, //IDM_FORMAT_DOS_437
212 {720, "IBM720 cp720 oem720 720"}, //IDM_FORMAT_DOS_720
213 {737, "IBM737 cp737 oem737 737"}, //IDM_FORMAT_DOS_737
214 {775, "IBM775 cp775 oem775 775"}, //IDM_FORMAT_DOS_775
215 {850, "IBM850 cp850 oem850 850"}, //IDM_FORMAT_DOS_850
216 {852, "IBM852 cp852 oem852 852"}, //IDM_FORMAT_DOS_852
217 {855, "IBM855 cp855 oem855 855 csIBM855"}, //IDM_FORMAT_DOS_855
218 {857, "IBM857 cp857 oem857 857"}, //IDM_FORMAT_DOS_857
219 {858, "IBM858 cp858 oem858 858"}, //IDM_FORMAT_DOS_858
220 {860, "IBM860 cp860 oem860 860"}, //IDM_FORMAT_DOS_860
221 {861, "IBM861 cp861 oem861 861"}, //IDM_FORMAT_DOS_861
222 {862, "IBM862 cp862 oem862 862"}, //IDM_FORMAT_DOS_862
223 {863, "IBM863 cp863 oem863 863"}, //IDM_FORMAT_DOS_863
224 {865, "IBM865 cp865 oem865 865"}, //IDM_FORMAT_DOS_865
225 {866, "IBM866 cp866 oem866 866"}, //IDM_FORMAT_DOS_866
226 {869, "IBM869 cp869 oem869 869"}, //IDM_FORMAT_DOS_869
227 {950, "big5 csBig5"}, //IDM_FORMAT_BIG5
228 {936, "gb2312 gbk csGB2312"}, //IDM_FORMAT_GB2312
229 {932, "Shift_JIS MS_Kanji csShiftJIS csWindows31J"}, //IDM_FORMAT_SHIFT_JIS
230 {949, "windows-949 korean"}, //IDM_FORMAT_KOREAN_WIN
231 {51949, "euc-kr csEUCKR"}, //IDM_FORMAT_EUC_KR
232 {874, "tis-620"}, //IDM_FORMAT_TIS_620
233 {10007, "x-mac-cyrillic xmaccyrillic"}, //IDM_FORMAT_MAC_CYRILLIC
234 {21866, "koi8_u"}, //IDM_FORMAT_KOI8U_CYRILLIC
235 {20866, "koi8_r csKOI8R"}, //IDM_FORMAT_KOI8R_CYRILLIC
236 {65001, "UTF-8"}, //IDM_FORMAT_UTF8
237 {1200, "UTF-16 LE"}, //IDM_FORMAT_UTF16LE
238 {1201, "UTF-16 BE"}, //IDM_FORMAT_UTF16BE
240 void CTortoiseGitBlameView::OnChangeEncode(UINT nId
)
242 if(nId
>= IDM_FORMAT_ENCODE
&& nId
<= IDM_FORMAT_ENCODE_END
)
243 this->UpdateInfo(encodings
[nId
- IDM_FORMAT_ENCODE
].id
);
245 int CTortoiseGitBlameView::OnCreate(LPCREATESTRUCT lpcs
)
249 this->GetWindowRect(&rect1
);
250 rect
.left
=m_blamewidth
+LOCATOR_WIDTH
;
251 rect
.right
=rect
.Width();
253 rect
.bottom
=rect
.Height();
254 if (!m_TextView
.Create(_T("Scintilla"), _T("source"), 0, rect
, this, IDC_SCINTILLA
, 0))
256 TRACE0("Failed to create view\n");
257 return -1; // fail to create
259 m_TextView
.Init(0,FALSE
);
260 m_TextView
.ShowWindow( SW_SHOW
);
261 m_wEditor
= m_TextView
.m_hWnd
;
264 m_ToolTip
.Create(this->GetParent());
266 ::AfxGetApp()->GetMainWnd();
267 return CView::OnCreate(lpcs
);
271 void CTortoiseGitBlameView::OnSize(UINT
/*nType*/, int cx
, int cy
)
275 rect
.left
=m_blamewidth
;
280 m_TextView
.MoveWindow(&rect
);
283 BOOL
CTortoiseGitBlameView::PreCreateWindow(CREATESTRUCT
& cs
)
285 return CView::PreCreateWindow(cs
);
288 // CTortoiseGitBlameView drawing
290 void CTortoiseGitBlameView::OnDraw(CDC
* /*pDC*/)
292 CTortoiseGitBlameDoc
* pDoc
= GetDocument();
297 DrawBlame(this->GetDC()->m_hDC
);
298 DrawLocatorBar(this->GetDC()->m_hDC
);
299 // TODO: add draw code for native data here
303 // CTortoiseGitBlameView printing
306 void CTortoiseGitBlameView::OnFilePrintPreview()
308 AFXPrintPreview(this);
311 BOOL
CTortoiseGitBlameView::OnPreparePrinting(CPrintInfo
* pInfo
)
313 // default preparation
314 return DoPreparePrinting(pInfo
);
317 void CTortoiseGitBlameView::OnBeginPrinting(CDC
* /*pDC*/, CPrintInfo
* /*pInfo*/)
319 // TODO: add extra initialization before printing
322 void CTortoiseGitBlameView::OnEndPrinting(CDC
* /*pDC*/, CPrintInfo
* /*pInfo*/)
324 // TODO: add cleanup after printing
327 void CTortoiseGitBlameView::OnRButtonUp(UINT
/*nFlags*/, CPoint point
)
329 LONG_PTR line
= SendEditor(SCI_GETFIRSTVISIBLELINE
);
330 LONG_PTR height
= SendEditor(SCI_TEXTHEIGHT
);
331 line
= line
+ (point
.y
/height
);
332 if (line
< (LONG
)m_CommitHash
.size())
334 if(line
< (LONG
)m_ID
.size() && m_ID
[line
] >= 0) // only show context menu if we have log data for it
336 m_MouseLine
= (LONG
)line
;
337 ClientToScreen(&point
);
338 theApp
.GetContextMenuManager()->ShowPopupMenu(IDR_BLAME_POPUP
, point
.x
, point
.y
, this, TRUE
);
343 void CTortoiseGitBlameView::OnUpdateBlamePopupBlamePrevious(CCmdUI
*pCmdUI
)
345 if (m_MouseLine
< 0 || m_MouseLine
>= (LONG
)m_ID
.size() || m_ID
[m_MouseLine
] <= 1)
347 pCmdUI
->Enable(false);
351 pCmdUI
->Enable(true);
355 void CTortoiseGitBlameView::OnUpdateBlamePopupDiffPrevious(CCmdUI
*pCmdUI
)
357 if (m_MouseLine
< 0 || m_MouseLine
>= (LONG
)m_ID
.size() || m_ID
[m_MouseLine
] <= 1)
359 pCmdUI
->Enable(false);
363 pCmdUI
->Enable(true);
367 void CTortoiseGitBlameView::CopyHashToClipboard()
369 this->GetLogList()->CopySelectionToClipBoard(CGitLogListBase::ID_COPY_HASH
);
372 // CTortoiseGitBlameView diagnostics
375 void CTortoiseGitBlameView::AssertValid() const
377 CView::AssertValid();
380 void CTortoiseGitBlameView::Dump(CDumpContext
& dc
) const
385 CTortoiseGitBlameDoc
* CTortoiseGitBlameView::GetDocument() const // non-debug version is inline
387 ASSERT(m_pDocument
->IsKindOf(RUNTIME_CLASS(CTortoiseGitBlameDoc
)));
388 return (CTortoiseGitBlameDoc
*)m_pDocument
;
393 // CTortoiseGitBlameView message handlers
394 CString
CTortoiseGitBlameView::GetAppDirectory()
398 DWORD bufferlen
= MAX_PATH
; // MAX_PATH is not the limit here!
401 bufferlen
+= MAX_PATH
; // MAX_PATH is not the limit here!
402 std::unique_ptr
<TCHAR
[]> pBuf(new TCHAR
[bufferlen
]);
403 len
= GetModuleFileName(NULL
, pBuf
.get(), bufferlen
);
404 path
= CString(pBuf
.get(), len
);
405 } while(len
== bufferlen
);
407 path
= path
.Left(path
.ReverseFind(_T('\\')));
408 //path = path.substr(0, path.rfind('\\') + 1);
413 // Return a color which is interpolated between c1 and c2.
414 // Slider controls the relative proportions as a percentage:
415 // Slider = 0 represents pure c1
416 // Slider = 50 represents equal mixture
417 // Slider = 100 represents pure c2
418 COLORREF
CTortoiseGitBlameView::InterColor(COLORREF c1
, COLORREF c2
, int Slider
)
422 // Limit Slider to 0..100% range
428 // The color components have to be treated individually.
429 r
= (GetRValue(c2
) * Slider
+ GetRValue(c1
) * (100 - Slider
)) / 100;
430 g
= (GetGValue(c2
) * Slider
+ GetGValue(c1
) * (100 - Slider
)) / 100;
431 b
= (GetBValue(c2
) * Slider
+ GetBValue(c1
) * (100 - Slider
)) / 100;
436 LRESULT
CTortoiseGitBlameView::SendEditor(UINT Msg
, WPARAM wParam
, LPARAM lParam
)
438 if (m_directFunction
)
440 return ((SciFnDirect
) m_directFunction
)(m_directPointer
, Msg
, wParam
, lParam
);
442 return ::SendMessage(m_wEditor
, Msg
, wParam
, lParam
);
445 void CTortoiseGitBlameView::SetAStyle(int style
, COLORREF fore
, COLORREF back
, int size
, CString
*face
)
447 SendEditor(SCI_STYLESETFORE
, style
, fore
);
448 SendEditor(SCI_STYLESETBACK
, style
, back
);
450 SendEditor(SCI_STYLESETSIZE
, style
, size
);
452 SendEditor(SCI_STYLESETFONT
, style
, reinterpret_cast<LPARAM
>(this->m_TextView
.StringForControl(*face
).GetBuffer()));
455 void CTortoiseGitBlameView::InitialiseEditor()
458 m_directFunction
= ::SendMessage(m_wEditor
, SCI_GETDIRECTFUNCTION
, 0, 0);
459 m_directPointer
= ::SendMessage(m_wEditor
, SCI_GETDIRECTPOINTER
, 0, 0);
460 // Set up the global default style. These attributes are used wherever no explicit choices are made.
461 CString
fontName(((stdstring
)CRegStdString(_T("Software\\TortoiseGit\\BlameFontName"), _T("Courier New"))).c_str());
462 SetAStyle(STYLE_DEFAULT
,
465 (DWORD
)CRegStdDWORD(_T("Software\\TortoiseGit\\BlameFontSize"), 10),
468 SendEditor(SCI_SETTABWIDTH
, (DWORD
)CRegStdDWORD(_T("Software\\TortoiseGit\\BlameTabSize"), 4));
469 SendEditor(SCI_SETREADONLY
, TRUE
);
470 LRESULT pix
= SendEditor(SCI_TEXTWIDTH
, STYLE_LINENUMBER
, (LPARAM
)this->m_TextView
.StringForControl(_T("_99999")).GetBuffer());
472 SendEditor(SCI_SETMARGINWIDTHN
, 0, pix
);
474 SendEditor(SCI_SETMARGINWIDTHN
, 0);
475 SendEditor(SCI_SETMARGINWIDTHN
, 1);
476 SendEditor(SCI_SETMARGINWIDTHN
, 2);
477 //Set the default windows colors for edit controls
478 SendEditor(SCI_STYLESETFORE
, STYLE_DEFAULT
, ::GetSysColor(COLOR_WINDOWTEXT
));
479 SendEditor(SCI_STYLESETBACK
, STYLE_DEFAULT
, ::GetSysColor(COLOR_WINDOW
));
480 SendEditor(SCI_SETSELFORE
, TRUE
, ::GetSysColor(COLOR_HIGHLIGHTTEXT
));
481 SendEditor(SCI_SETSELBACK
, TRUE
, ::GetSysColor(COLOR_HIGHLIGHT
));
482 SendEditor(SCI_SETCARETFORE
, ::GetSysColor(COLOR_WINDOWTEXT
));
483 m_regOldLinesColor
= CRegStdDWORD(_T("Software\\TortoiseGit\\BlameOldColor"), BLAMEOLDCOLOR
);
484 m_regNewLinesColor
= CRegStdDWORD(_T("Software\\TortoiseGit\\BlameNewColor"), BLAMENEWCOLOR
);
485 CRegStdDWORD
used2d(L
"Software\\TortoiseGit\\ScintillaDirect2D", FALSE
);
486 if (SysInfo::Instance().IsWin7OrLater() && DWORD(used2d
))
488 SendEditor(SCI_SETTECHNOLOGY
, SC_TECHNOLOGY_DIRECTWRITE
);
489 SendEditor(SCI_SETBUFFEREDDRAW
, 0);
491 SendEditor(SCI_SETFONTQUALITY
, SC_EFF_QUALITY_DEFAULT
);
493 this->m_TextView
.Call(SCI_SETWRAPMODE
, SC_WRAP_NONE
);
497 bool CTortoiseGitBlameView::DoSearch(CString what
, DWORD flags
)
499 int pos
= (int)SendEditor(SCI_GETCURRENTPOS
);
500 int line
= (int)SendEditor(SCI_LINEFROMPOSITION
, pos
);
502 bool bCaseSensitive
= !!(flags
& FR_MATCHCASE
);
503 theApp
.WriteInt(_T("FindMatchCase"), bCaseSensitive
? 1 : 0);
504 theApp
.WriteString(_T("FindString"), what
);
510 if(i
>= (signed int)m_CommitHash
.size())
514 int bufsize
= (int)SendEditor(SCI_GETLINE
, i
);
515 char * linebuf
= new char[bufsize
+1];
516 SecureZeroMemory(linebuf
, bufsize
+1);
517 SendEditor(SCI_GETLINE
, i
, (LPARAM
)linebuf
);
518 CString oneline
=this->m_TextView
.StringFromControl(linebuf
);
522 CString lcAuthor
= m_Authors
[i
];
523 if (lcAuthor
.MakeLower().Find(what
) >= 0)
525 else if (oneline
.MakeLower().Find(what
) >=0)
528 else if (m_Authors
[i
].Find(what
) >= 0)
530 else if (oneline
.Find(what
) >=0)
534 if(!bFound
&& i
>= (signed int)m_CommitHash
.size())
536 }while(i
!=line
&&(!bFound
));
541 int selstart
= (int)SendEditor(SCI_GETCURRENTPOS
);
542 int selend
= (int)SendEditor(SCI_POSITIONFROMLINE
, i
);
543 SendEditor(SCI_SETSELECTIONSTART
, selstart
);
544 SendEditor(SCI_SETSELECTIONEND
, selend
);
545 m_SelectedLine
= i
-1;
549 ::MessageBox(wMain
, _T("\"") + what
+ _T("\" ") + CString(MAKEINTRESOURCE(IDS_NOTFOUND
)), _T("TortoiseGitBlame"), MB_ICONINFORMATION
);
555 bool CTortoiseGitBlameView::GotoLine(long line
)
560 if ((unsigned long)line
>= m_CommitHash
.size())
562 line
= (long)m_CommitHash
.size()-1;
565 int nCurrentPos
= (int)SendEditor(SCI_GETCURRENTPOS
);
566 int nCurrentLine
= (int)SendEditor(SCI_LINEFROMPOSITION
,nCurrentPos
);
567 int nFirstVisibleLine
= (int)SendEditor(SCI_GETFIRSTVISIBLELINE
);
568 int nLinesOnScreen
= (int)SendEditor(SCI_LINESONSCREEN
);
570 if ( line
>=nFirstVisibleLine
&& line
<=nFirstVisibleLine
+nLinesOnScreen
)
573 SendEditor(SCI_GOTOLINE
, line
);
577 // Place the requested line one third from the top
578 if ( line
> nCurrentLine
)
580 SendEditor(SCI_GOTOLINE
, (WPARAM
)(line
+(int)nLinesOnScreen
*(2/3.0)));
584 SendEditor(SCI_GOTOLINE
, (WPARAM
)(line
-(int)nLinesOnScreen
*(1/3.0)));
588 // Highlight the line
589 int nPosStart
= (int)SendEditor(SCI_POSITIONFROMLINE
,line
);
590 int nPosEnd
= (int)SendEditor(SCI_GETLINEENDPOSITION
,line
);
591 SendEditor(SCI_SETSEL
,nPosEnd
,nPosStart
);
596 bool CTortoiseGitBlameView::ScrollToLine(long line
)
601 int nCurrentLine
= (int)SendEditor(SCI_GETFIRSTVISIBLELINE
);
603 int scrolldelta
= line
- nCurrentLine
;
604 SendEditor(SCI_LINESCROLL
, 0, scrolldelta
);
609 void CTortoiseGitBlameView::CopyToClipboard()
611 CWnd
* wnd
= GetFocus();
612 if (wnd
== this->GetLogList())
613 CopySelectedLogToClipboard();
616 if (CString(wnd
->GetRuntimeClass()->m_lpszClassName
) == _T("CMFCPropertyGridCtrl"))
618 CMFCPropertyGridCtrl
*grid
= (CMFCPropertyGridCtrl
*)wnd
;
619 if (grid
->GetCurSel() && !grid
->GetCurSel()->IsGroup())
620 CStringUtils::WriteAsciiStringToClipboard(grid
->GetCurSel()->GetValue(), GetSafeHwnd());
623 m_TextView
.Call(SCI_COPY
);
627 void CTortoiseGitBlameView::CopySelectedLogToClipboard()
629 this->GetLogList()->CopySelectionToClipBoard(FALSE
);
632 void CTortoiseGitBlameView::BlamePreviousRevision()
634 if (m_MouseLine
< 0 || m_MouseLine
>= (LONG
)m_ID
.size())
637 CString procCmd
= _T("/path:\"");
638 procCmd
+= ((CMainFrame
*)::AfxGetApp()->GetMainWnd())->GetActiveView()->GetDocument()->GetPathName();
639 procCmd
+= _T("\" ");
640 procCmd
+= _T(" /command:blame");
641 procCmd
+= _T(" /endrev:") + this->GetLogData()->GetGitRevAt(this->GetLogData()->size()-m_ID
[m_MouseLine
]+1).m_CommitHash
.ToString();
643 CCommonAppUtils::RunTortoiseGitProc(procCmd
);
646 void CTortoiseGitBlameView::DiffPreviousRevision()
648 if (m_MouseLine
< 0 || m_MouseLine
>= (LONG
)m_ID
.size())
651 CString procCmd
= _T("/path:\"");
652 procCmd
+= ((CMainFrame
*)::AfxGetApp()->GetMainWnd())->GetActiveView()->GetDocument()->GetPathName();
653 procCmd
+= _T("\" ");
654 procCmd
+= _T(" /command:diff");
655 procCmd
+= _T(" /startrev:") + this->GetLogData()->GetGitRevAt(this->GetLogData()->size() - m_ID
[m_MouseLine
]).m_CommitHash
.ToString();
656 procCmd
+= _T(" /endrev:") + this->GetLogData()->GetGitRevAt(this->GetLogData()->size() - m_ID
[m_MouseLine
] + 1).m_CommitHash
.ToString();
658 CCommonAppUtils::RunTortoiseGitProc(procCmd
);
661 void CTortoiseGitBlameView::ShowLog()
663 if (m_MouseLine
< 0 || m_MouseLine
>= (LONG
)m_ID
.size())
666 CString procCmd
= _T("/path:\"");
667 procCmd
+= ((CMainFrame
*)::AfxGetApp()->GetMainWnd())->GetActiveView()->GetDocument()->GetPathName();
668 procCmd
+= _T("\" ");
669 procCmd
+= _T(" /command:log");
670 procCmd
+= _T(" /rev:") + this->GetLogData()->GetGitRevAt(this->GetLogData()->size() - m_ID
[m_MouseLine
]).m_CommitHash
.ToString();
672 CCommonAppUtils::RunTortoiseGitProc(procCmd
);
675 LONG
CTortoiseGitBlameView::GetBlameWidth()
680 HDC hDC
= this->GetDC()->m_hDC
;
681 HFONT oldfont
= (HFONT
)::SelectObject(hDC
, m_font
);
683 CString
shortHash('f', g_Git
.GetShortHASHLength() + 1);
684 ::GetTextExtentPoint32(hDC
, shortHash
, g_Git
.GetShortHASHLength() + 1, &width
);
685 m_revwidth
= width
.cx
+ BLAMESPACE
;
686 blamewidth
+= m_revwidth
;
692 for (size_t i
= 0; i
< this->m_Dates
.size(); ++i
)
694 ::GetTextExtentPoint32(hDC
, m_Dates
[i
] , m_Dates
[i
].GetLength(), &width
);
695 if (width
.cx
> maxwidth
.cx
)
698 m_datewidth
= maxwidth
.cx
+ BLAMESPACE
;
699 blamewidth
+= m_datewidth
;
705 for (unsigned int i
= 0; i
< this->m_Authors
.size(); ++i
)
707 ::GetTextExtentPoint32(hDC
,m_Authors
[i
] , m_Authors
[i
].GetLength(), &width
);
708 if (width
.cx
> maxwidth
.cx
)
711 m_authorwidth
= maxwidth
.cx
+ BLAMESPACE
;
712 blamewidth
+= m_authorwidth
;
714 ::SelectObject(hDC
, oldfont
);
715 POINT pt
= {blamewidth
, 0};
718 //::ReleaseDC(wBlame, hDC);
723 void CTortoiseGitBlameView::CreateFont()
729 HDC hDC
= ::GetDC(wBlame
);
730 lf
.lfHeight
= -MulDiv((DWORD
)CRegStdDWORD(_T("Software\\TortoiseGit\\BlameFontSize"), 10), GetDeviceCaps(hDC
, LOGPIXELSY
), 72);
731 lf
.lfCharSet
= DEFAULT_CHARSET
;
732 CRegStdString fontname
= CRegStdString(_T("Software\\TortoiseGit\\BlameFontName"), _T("Courier New"));
733 _tcscpy_s(lf
.lfFaceName
, 32, ((stdstring
)fontname
).c_str());
734 m_font
= ::CreateFontIndirect(&lf
);
737 m_italicfont
= ::CreateFontIndirect(&lf
);
739 ::ReleaseDC(wBlame
, hDC
);
742 void CTortoiseGitBlameView::DrawBlame(HDC hDC
)
749 HFONT oldfont
= NULL
;
750 LONG_PTR line
= SendEditor(SCI_GETFIRSTVISIBLELINE
);
751 LONG_PTR linesonscreen
= SendEditor(SCI_LINESONSCREEN
);
752 LONG_PTR height
= SendEditor(SCI_TEXTHEIGHT
);
757 //::GetClientRect(this->m_hWnd, &rc);
758 for (LRESULT i
=line
; i
<(line
+linesonscreen
); ++i
)
761 if (i
< (int)m_CommitHash
.size())
763 // if (mergelines[i])
764 // oldfont = (HFONT)::SelectObject(hDC, m_italicfont);
766 oldfont
= (HFONT
)::SelectObject(hDC
, m_font
);
767 ::SetBkColor(hDC
, m_windowcolor
);
768 ::SetTextColor(hDC
, m_textcolor
);
769 if (!m_CommitHash
[i
].IsEmpty())
771 //if (m_CommitHash[i].Compare(m_MouseHash)==0)
772 // ::SetBkColor(hDC, m_mouseauthorcolor);
773 if (m_CommitHash
[i
] == m_SelectedHash
)
775 ::SetBkColor(hDC
, m_selectedauthorcolor
);
776 ::SetTextColor(hDC
, m_texthighlightcolor
);
782 ::SetBkColor(hDC
, m_mouserevcolor
);
784 //if ((revs[i] == m_mouserev)&&(!sel))
785 // ::SetBkColor(hDC, m_mouserevcolor);
786 //if (revs[i] == m_selectedrev)
788 // ::SetBkColor(hDC, m_selectedrevcolor);
789 // ::SetTextColor(hDC, m_texthighlightcolor);
793 str
= m_CommitHash
[i
].ToString().Left(g_Git
.GetShortHASHLength());
795 //_stprintf_s(buf, MAX_PATH, _T("%8ld "), revs[i]);
797 rc
.left
=LOCATOR_WIDTH
;
798 rc
.bottom
= (LONG
)(Y
+ height
);
799 rc
.right
= rc
.left
+ m_blamewidth
;
800 ::ExtTextOut(hDC
, LOCATOR_WIDTH
, (int)Y
, ETO_CLIPPED
, &rc
, str
, str
.GetLength(), 0);
801 int Left
= m_revwidth
;
805 rc
.right
= rc
.left
+ Left
+ m_authorwidth
;
806 ::ExtTextOut(hDC
, Left
, (int)Y
, ETO_CLIPPED
, &rc
, m_Authors
[i
], m_Authors
[i
].GetLength(), 0);
807 Left
+= m_authorwidth
;
811 rc
.right
= rc
.left
+ Left
+ m_datewidth
;
812 ::ExtTextOut(hDC
, Left
, (int)Y
, ETO_CLIPPED
, &rc
, m_Dates
[i
], m_Dates
[i
].GetLength(), 0);
815 if ((i
==m_SelectedLine
)&&(m_pFindDialog
))
818 brush
.lbColor
= m_textcolor
;
820 brush
.lbStyle
= BS_SOLID
;
821 HPEN pen
= ExtCreatePen(PS_SOLID
| PS_GEOMETRIC
, 2, &brush
, 0, NULL
);
822 HGDIOBJ hPenOld
= SelectObject(hDC
, pen
);
825 rc2
.bottom
= (LONG
)(Y
+ height
);
826 ::MoveToEx(hDC
, rc2
.left
, rc2
.top
, NULL
);
827 ::LineTo(hDC
, rc2
.right
, rc2
.top
);
828 ::LineTo(hDC
, rc2
.right
, rc2
.bottom
);
829 ::LineTo(hDC
, rc2
.left
, rc2
.bottom
);
830 ::LineTo(hDC
, rc2
.left
, rc2
.top
);
831 SelectObject(hDC
, hPenOld
);
835 ::SelectObject(hDC
, oldfont
);
839 ::SetBkColor(hDC
, m_windowcolor
);
840 for (int j
=0; j
< MAX_PATH
; ++j
)
842 ::ExtTextOut(hDC
, 0, (int)Y
, ETO_CLIPPED
, &rc
, buf
, MAX_PATH
-1, 0);
848 void CTortoiseGitBlameView::DrawLocatorBar(HDC hDC
)
853 LONG_PTR line
= SendEditor(SCI_GETFIRSTVISIBLELINE
);
854 LONG_PTR linesonscreen
= SendEditor(SCI_LINESONSCREEN
);
856 COLORREF blackColor
= GetSysColor(COLOR_WINDOWTEXT
);
859 //::GetClientRect(wLocator, &rc);
860 this->GetClientRect(&rc
);
862 rc
.right
=LOCATOR_WIDTH
;
865 LONG height
= rc
.bottom
-rc
.top
;
866 LONG currentLine
= 0;
868 // draw the colored bar
869 for (std::vector
<LONG
>::const_iterator it
= m_ID
.begin(); it
!= m_ID
.end(); ++it
)
871 COLORREF cr
= GetLineColor(currentLine
);
873 // get the line color
874 if ((currentLine
> line
)&&(currentLine
<= (line
+ linesonscreen
)))
876 cr
= InterColor(cr
, blackColor
, 10);
879 lineRect
.top
= (LONG
)Y
;
880 lineRect
.bottom
= (currentLine
* height
/ (LONG
)m_ID
.size());
881 ::ExtTextOut(hDC
, 0, 0, ETO_OPAQUE
, &lineRect
, NULL
, 0, NULL
);
887 // now draw two lines indicating the scroll position of the source view
888 SetBkColor(hDC
, blackColor
);
889 lineRect
.top
= (LONG
)line
* height
/ (LONG
)m_ID
.size();
890 lineRect
.bottom
= lineRect
.top
+1;
891 ::ExtTextOut(hDC
, 0, 0, ETO_OPAQUE
, &lineRect
, NULL
, 0, NULL
);
892 lineRect
.top
= (LONG
)(line
+ linesonscreen
) * height
/ (LONG
)m_ID
.size();
893 lineRect
.bottom
= lineRect
.top
+1;
894 ::ExtTextOut(hDC
, 0, 0, ETO_OPAQUE
, &lineRect
, NULL
, 0, NULL
);
899 void CTortoiseGitBlameView::StringExpand(LPSTR str
)
904 cPos
= strchr(cPos
, '\n');
907 memmove(cPos
+1, cPos
, strlen(cPos
)*sizeof(char));
912 } while (cPos
!= NULL
);
914 void CTortoiseGitBlameView::StringExpand(LPWSTR str
)
916 wchar_t * cPos
= str
;
919 cPos
= wcschr(cPos
, '\n');
922 memmove(cPos
+1, cPos
, wcslen(cPos
)*sizeof(wchar_t));
927 } while (cPos
!= NULL
);
930 void CTortoiseGitBlameView::SetupLexer(CString filename
)
934 //const char * lineptr = _tcsrchr(filename, '.');
935 int start
=filename
.ReverseFind(_T('.'));
938 //_tcscpy_s(line, 20, lineptr+1);
939 //_tcslwr_s(line, 20);
940 CString ext
=filename
.Right(filename
.GetLength()-start
-1);
941 line
=ext
.GetBuffer();
943 if ((_tcscmp(line
, _T("py"))==0)||
944 (_tcscmp(line
, _T("pyw"))==0))
946 SendEditor(SCI_SETLEXER
, SCLEX_PYTHON
);
947 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("and assert break class continue def del elif \
948 else except exec finally for from global if import in is lambda None \
949 not or pass print raise return try while yield")).GetBuffer()));
950 SetAStyle(SCE_P_DEFAULT
, black
);
951 SetAStyle(SCE_P_COMMENTLINE
, darkGreen
);
952 SetAStyle(SCE_P_NUMBER
, RGB(0, 0x80, 0x80));
953 SetAStyle(SCE_P_STRING
, RGB(0, 0, 0x80));
954 SetAStyle(SCE_P_CHARACTER
, RGB(0, 0, 0x80));
955 SetAStyle(SCE_P_WORD
, RGB(0x80, 0, 0x80));
956 SetAStyle(SCE_P_TRIPLE
, black
);
957 SetAStyle(SCE_P_TRIPLEDOUBLE
, black
);
958 SetAStyle(SCE_P_CLASSNAME
, darkBlue
);
959 SetAStyle(SCE_P_DEFNAME
, darkBlue
);
960 SetAStyle(SCE_P_OPERATOR
, darkBlue
);
961 SetAStyle(SCE_P_IDENTIFIER
, darkBlue
);
962 SetAStyle(SCE_P_COMMENTBLOCK
, darkGreen
);
963 SetAStyle(SCE_P_STRINGEOL
, red
);
965 if ((_tcscmp(line
, _T("c"))==0)||
966 (_tcscmp(line
, _T("cc"))==0)||
967 (_tcscmp(line
, _T("cpp"))==0)||
968 (_tcscmp(line
, _T("cxx"))==0)||
969 (_tcscmp(line
, _T("h"))==0)||
970 (_tcscmp(line
, _T("hh"))==0)||
971 (_tcscmp(line
, _T("hpp"))==0)||
972 (_tcscmp(line
, _T("hxx"))==0)||
973 (_tcscmp(line
, _T("dlg"))==0)||
974 (_tcscmp(line
, _T("mak"))==0))
976 SendEditor(SCI_SETLEXER
, SCLEX_CPP
);
977 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("and and_eq asm auto bitand bitor bool break \
978 case catch char class compl const const_cast continue \
979 default delete do double dynamic_cast else enum explicit export extern false float for \
980 friend goto if inline int long mutable namespace new not not_eq \
981 operator or or_eq private protected public \
982 register reinterpret_cast return short signed sizeof static static_cast struct switch \
983 template this throw true try typedef typeid typename union unsigned using \
984 virtual void volatile wchar_t while xor xor_eq")).GetBuffer()));
985 SendEditor(SCI_SETKEYWORDS
, 3, (LPARAM
)(m_TextView
.StringForControl(_T("a addindex addtogroup anchor arg attention \
986 author b brief bug c class code date def defgroup deprecated dontinclude \
987 e em endcode endhtmlonly endif endlatexonly endlink endverbatim enum example exception \
988 f$ f[ f] file fn hideinitializer htmlinclude htmlonly \
989 if image include ingroup internal invariant interface latexonly li line link \
990 mainpage name namespace nosubgrouping note overload \
991 p page par param post pre ref relates remarks return retval \
992 sa section see showinitializer since skip skipline struct subsection \
993 test throw todo typedef union until \
994 var verbatim verbinclude version warning weakgroup $ @ \\ & < > # { }")).GetBuffer()));
997 if (_tcscmp(line
, _T("cs"))==0)
999 SendEditor(SCI_SETLEXER
, SCLEX_CPP
);
1000 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("abstract as base bool break byte case catch char checked class \
1001 const continue decimal default delegate do double else enum \
1002 event explicit extern false finally fixed float for foreach goto if \
1003 implicit in int interface internal is lock long namespace new null \
1004 object operator out override params private protected public \
1005 readonly ref return sbyte sealed short sizeof stackalloc static \
1006 string struct switch this throw true try typeof uint ulong \
1007 unchecked unsafe ushort using virtual void while")).GetBuffer()));
1010 if ((_tcscmp(line
, _T("rc"))==0)||
1011 (_tcscmp(line
, _T("rc2"))==0))
1013 SendEditor(SCI_SETLEXER
, SCLEX_CPP
);
1014 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("ACCELERATORS ALT AUTO3STATE AUTOCHECKBOX AUTORADIOBUTTON \
1015 BEGIN BITMAP BLOCK BUTTON CAPTION CHARACTERISTICS CHECKBOX CLASS \
1016 COMBOBOX CONTROL CTEXT CURSOR DEFPUSHBUTTON DIALOG DIALOGEX DISCARDABLE \
1017 EDITTEXT END EXSTYLE FONT GROUPBOX ICON LANGUAGE LISTBOX LTEXT \
1018 MENU MENUEX MENUITEM MESSAGETABLE POPUP \
1019 PUSHBUTTON RADIOBUTTON RCDATA RTEXT SCROLLBAR SEPARATOR SHIFT STATE3 \
1020 STRINGTABLE STYLE TEXTINCLUDE VALUE VERSION VERSIONINFO VIRTKEY")).GetBuffer()));
1023 if ((_tcscmp(line
, _T("idl"))==0)||
1024 (_tcscmp(line
, _T("odl"))==0))
1026 SendEditor(SCI_SETLEXER
, SCLEX_CPP
);
1027 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("aggregatable allocate appobject arrays async async_uuid \
1029 bindable boolean broadcast byte byte_count \
1030 call_as callback char coclass code comm_status \
1031 const context_handle context_handle_noserialize \
1032 context_handle_serialize control cpp_quote custom \
1033 decode default defaultbind defaultcollelem \
1034 defaultvalue defaultvtable dispinterface displaybind dllname \
1036 enable_allocate encode endpoint entry enum error_status_t \
1038 fault_status first_is float \
1039 handle_t heap helpcontext helpfile helpstring \
1040 helpstringcontext helpstringdll hidden hyper \
1041 id idempotent ignore iid_as iid_is immediatebind implicit_handle \
1042 import importlib in include in_line int __int64 __int3264 interface \
1043 last_is lcid length_is library licensed local long \
1044 max_is maybe message methods midl_pragma \
1045 midl_user_allocate midl_user_free min_is module ms_union \
1046 ncacn_at_dsp ncacn_dnet_nsp ncacn_http ncacn_ip_tcp \
1047 ncacn_nb_ipx ncacn_nb_nb ncacn_nb_tcp ncacn_np \
1048 ncacn_spx ncacn_vns_spp ncadg_ip_udp ncadg_ipx ncadg_mq \
1049 ncalrpc nocode nonbrowsable noncreatable nonextensible notify \
1050 object odl oleautomation optimize optional out out_of_line \
1051 pipe pointer_default pragma properties propget propput propputref \
1053 range readonly ref represent_as requestedit restricted retval \
1054 shape short signed size_is small source strict_context_handle \
1055 string struct switch switch_is switch_type \
1056 transmit_as typedef \
1057 uidefault union unique unsigned user_marshal usesgetlasterror uuid \
1058 v1_enum vararg version void wchar_t wire_marshal")).GetBuffer()));
1061 if (_tcscmp(line
, _T("java"))==0)
1063 SendEditor(SCI_SETLEXER
, SCLEX_CPP
);
1064 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("abstract assert boolean break byte case catch char class \
1065 const continue default do double else extends final finally float for future \
1066 generic goto if implements import inner instanceof int interface long \
1067 native new null outer package private protected public rest \
1068 return short static super switch synchronized this throw throws \
1069 transient try var void volatile while")).GetBuffer()));
1072 if (_tcscmp(line
, _T("js"))==0)
1074 SendEditor(SCI_SETLEXER
, SCLEX_CPP
);
1075 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("abstract boolean break byte case catch char class \
1076 const continue debugger default delete do double else enum export extends \
1077 final finally float for function goto if implements import in instanceof \
1078 int interface long native new package private protected public \
1079 return short static super switch synchronized this throw throws \
1080 transient try typeof var void volatile while with")).GetBuffer()));
1083 if ((_tcscmp(line
, _T("pas"))==0)||
1084 (_tcscmp(line
, _T("dpr"))==0)||
1085 (_tcscmp(line
, _T("pp"))==0))
1087 SendEditor(SCI_SETLEXER
, SCLEX_PASCAL
);
1088 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("and array as begin case class const constructor \
1089 destructor div do downto else end except file finally \
1090 for function goto if implementation in inherited \
1091 interface is mod not object of on or packed \
1092 procedure program property raise record repeat \
1093 set shl shr then threadvar to try type unit \
1094 until uses var while with xor")).GetBuffer()));
1097 if ((_tcscmp(line
, _T("as"))==0)||
1098 (_tcscmp(line
, _T("asc"))==0)||
1099 (_tcscmp(line
, _T("jsfl"))==0))
1101 SendEditor(SCI_SETLEXER
, SCLEX_CPP
);
1102 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("add and break case catch class continue default delete do \
1103 dynamic else eq extends false finally for function ge get gt if implements import in \
1104 instanceof interface intrinsic le lt ne new not null or private public return \
1105 set static super switch this throw true try typeof undefined var void while with")).GetBuffer()));
1106 SendEditor(SCI_SETKEYWORDS
, 1, (LPARAM
)(m_TextView
.StringForControl(_T("Array Arguments Accessibility Boolean Button Camera Color \
1107 ContextMenu ContextMenuItem Date Error Function Key LoadVars LocalConnection Math \
1108 Microphone Mouse MovieClip MovieClipLoader NetConnection NetStream Number Object \
1109 PrintJob Selection SharedObject Sound Stage String StyleSheet System TextField \
1110 TextFormat TextSnapshot Video Void XML XMLNode XMLSocket \
1111 _accProps _focusrect _global _highquality _parent _quality _root _soundbuftime \
1112 arguments asfunction call capabilities chr clearInterval duplicateMovieClip \
1113 escape eval fscommand getProperty getTimer getURL getVersion gotoAndPlay gotoAndStop \
1114 ifFrameLoaded Infinity -Infinity int isFinite isNaN length loadMovie loadMovieNum \
1115 loadVariables loadVariablesNum maxscroll mbchr mblength mbord mbsubstring MMExecute \
1116 NaN newline nextFrame nextScene on onClipEvent onUpdate ord parseFloat parseInt play \
1117 prevFrame prevScene print printAsBitmap printAsBitmapNum printNum random removeMovieClip \
1118 scroll set setInterval setProperty startDrag stop stopAllSounds stopDrag substring \
1119 targetPath tellTarget toggleHighQuality trace unescape unloadMovie unLoadMovieNum updateAfterEvent")).GetBuffer()));
1122 if ((_tcscmp(line
, _T("html"))==0)||
1123 (_tcscmp(line
, _T("htm"))==0)||
1124 (_tcscmp(line
, _T("shtml"))==0)||
1125 (_tcscmp(line
, _T("htt"))==0)||
1126 (_tcscmp(line
, _T("xml"))==0)||
1127 (_tcscmp(line
, _T("asp"))==0)||
1128 (_tcscmp(line
, _T("xsl"))==0)||
1129 (_tcscmp(line
, _T("php"))==0)||
1130 (_tcscmp(line
, _T("xhtml"))==0)||
1131 (_tcscmp(line
, _T("phtml"))==0)||
1132 (_tcscmp(line
, _T("cfm"))==0)||
1133 (_tcscmp(line
, _T("tpl"))==0)||
1134 (_tcscmp(line
, _T("dtd"))==0)||
1135 (_tcscmp(line
, _T("hta"))==0)||
1136 (_tcscmp(line
, _T("htd"))==0)||
1137 (_tcscmp(line
, _T("wxs"))==0))
1139 SendEditor(SCI_SETLEXER
, SCLEX_HTML
);
1140 SendEditor(SCI_SETSTYLEBITS
, 7);
1141 SendEditor(SCI_SETKEYWORDS
, 0, (LPARAM
)(m_TextView
.StringForControl(_T("a abbr acronym address applet area b base basefont \
1142 bdo big blockquote body br button caption center \
1143 cite code col colgroup dd del dfn dir div dl dt em \
1144 fieldset font form frame frameset h1 h2 h3 h4 h5 h6 \
1145 head hr html i iframe img input ins isindex kbd label \
1146 legend li link map menu meta noframes noscript \
1147 object ol optgroup option p param pre q s samp \
1148 script select small span strike strong style sub sup \
1149 table tbody td textarea tfoot th thead title tr tt u ul \
1150 var xml xmlns abbr accept-charset accept accesskey action align alink \
1151 alt archive axis background bgcolor border \
1152 cellpadding cellspacing char charoff charset checked cite \
1153 class classid clear codebase codetype color cols colspan \
1154 compact content coords \
1155 data datafld dataformatas datapagesize datasrc datetime \
1156 declare defer dir disabled enctype event \
1157 face for frame frameborder \
1158 headers height href hreflang hspace http-equiv \
1159 id ismap label lang language leftmargin link longdesc \
1160 marginwidth marginheight maxlength media method multiple \
1161 name nohref noresize noshade nowrap \
1162 object onblur onchange onclick ondblclick onfocus \
1163 onkeydown onkeypress onkeyup onload onmousedown \
1164 onmousemove onmouseover onmouseout onmouseup \
1165 onreset onselect onsubmit onunload \
1166 profile prompt readonly rel rev rows rowspan rules \
1167 scheme scope selected shape size span src standby start style \
1168 summary tabindex target text title topmargin type usemap \
1169 valign value valuetype version vlink vspace width \
1170 text password checkbox radio submit reset \
1171 file hidden image")).GetBuffer()));
1172 SendEditor(SCI_SETKEYWORDS
, 1, (LPARAM
)(m_TextView
.StringForControl(_T("assign audio block break catch choice clear disconnect else elseif \
1173 emphasis enumerate error exit field filled form goto grammar help \
1174 if initial link log menu meta noinput nomatch object option p paragraph \
1175 param phoneme prompt property prosody record reprompt return s say-as \
1176 script sentence subdialog submit throw transfer value var voice vxml")).GetBuffer()));
1177 SendEditor(SCI_SETKEYWORDS
, 2, (LPARAM
)(m_TextView
.StringForControl(_T("accept age alphabet anchor application base beep bridge category charset \
1178 classid cond connecttimeout content contour count dest destexpr dtmf dtmfterm \
1179 duration enctype event eventexpr expr expritem fetchtimeout finalsilence \
1180 gender http-equiv id level maxage maxstale maxtime message messageexpr \
1181 method mime modal mode name namelist next nextitem ph pitch range rate \
1182 scope size sizeexpr skiplist slot src srcexpr sub time timeexpr timeout \
1183 transferaudio type value variant version volume xml:lang")).GetBuffer()));
1184 SendEditor(SCI_SETKEYWORDS
, 3, (LPARAM
)(m_TextView
.StringForControl(_T("and assert break class continue def del elif \
1185 else except exec finally for from global if import in is lambda None \
1186 not or pass print raise return try while yield")).GetBuffer()));
1187 SendEditor(SCI_SETKEYWORDS
, 4, (LPARAM
)(m_TextView
.StringForControl(_T("and argv as argc break case cfunction class continue declare default do \
1188 die echo else elseif empty enddeclare endfor endforeach endif endswitch \
1189 endwhile e_all e_parse e_error e_warning eval exit extends false for \
1190 foreach function global http_cookie_vars http_get_vars http_post_vars \
1191 http_post_files http_env_vars http_server_vars if include include_once \
1192 list new not null old_function or parent php_os php_self php_version \
1193 print require require_once return static switch stdclass this true var \
1194 xor virtual while __file__ __line__ __sleep __wakeup")).GetBuffer()));
1196 SetAStyle(SCE_H_TAG
, darkBlue
);
1197 SetAStyle(SCE_H_TAGUNKNOWN
, red
);
1198 SetAStyle(SCE_H_ATTRIBUTE
, darkBlue
);
1199 SetAStyle(SCE_H_ATTRIBUTEUNKNOWN
, red
);
1200 SetAStyle(SCE_H_NUMBER
, RGB(0x80,0,0x80));
1201 SetAStyle(SCE_H_DOUBLESTRING
, RGB(0,0x80,0));
1202 SetAStyle(SCE_H_SINGLESTRING
, RGB(0,0x80,0));
1203 SetAStyle(SCE_H_OTHER
, RGB(0x80,0,0x80));
1204 SetAStyle(SCE_H_COMMENT
, RGB(0x80,0x80,0));
1205 SetAStyle(SCE_H_ENTITY
, RGB(0x80,0,0x80));
1207 SetAStyle(SCE_H_TAGEND
, darkBlue
);
1208 SetAStyle(SCE_H_XMLSTART
, darkBlue
); // <?
1209 SetAStyle(SCE_H_QUESTION
, darkBlue
); // <?
1210 SetAStyle(SCE_H_XMLEND
, darkBlue
); // ?>
1211 SetAStyle(SCE_H_SCRIPT
, darkBlue
); // <script
1212 SetAStyle(SCE_H_ASP
, RGB(0x4F, 0x4F, 0), RGB(0xFF, 0xFF, 0)); // <% ... %>
1213 SetAStyle(SCE_H_ASPAT
, RGB(0x4F, 0x4F, 0), RGB(0xFF, 0xFF, 0)); // <%@ ... %>
1215 SetAStyle(SCE_HB_DEFAULT
, black
);
1216 SetAStyle(SCE_HB_COMMENTLINE
, darkGreen
);
1217 SetAStyle(SCE_HB_NUMBER
, RGB(0,0x80,0x80));
1218 SetAStyle(SCE_HB_WORD
, darkBlue
);
1219 SendEditor(SCI_STYLESETBOLD
, SCE_HB_WORD
, 1);
1220 SetAStyle(SCE_HB_STRING
, RGB(0x80,0,0x80));
1221 SetAStyle(SCE_HB_IDENTIFIER
, black
);
1223 // This light blue is found in the windows system palette so is safe to use even in 256 colour modes.
1224 // Show the whole section of VBScript with light blue background
1225 for (int bstyle
= SCE_HB_DEFAULT
; bstyle
<= SCE_HB_STRINGEOL
; ++bstyle
) {
1226 SendEditor(SCI_STYLESETFONT
, bstyle
,
1227 reinterpret_cast<LPARAM
>(m_TextView
.StringForControl(_T("Lucida Console")).GetBuffer()));
1228 SendEditor(SCI_STYLESETBACK
, bstyle
, lightBlue
);
1229 // This call extends the backround colour of the last style on the line to the edge of the window
1230 SendEditor(SCI_STYLESETEOLFILLED
, bstyle
, 1);
1232 SendEditor(SCI_STYLESETBACK
, SCE_HB_STRINGEOL
, RGB(0x7F,0x7F,0xFF));
1233 SendEditor(SCI_STYLESETFONT
, SCE_HB_COMMENTLINE
,
1234 reinterpret_cast<LPARAM
>(m_TextView
.StringForControl(_T("Lucida Console")).GetBuffer()));
1236 SetAStyle(SCE_HBA_DEFAULT
, black
);
1237 SetAStyle(SCE_HBA_COMMENTLINE
, darkGreen
);
1238 SetAStyle(SCE_HBA_NUMBER
, RGB(0,0x80,0x80));
1239 SetAStyle(SCE_HBA_WORD
, darkBlue
);
1240 SendEditor(SCI_STYLESETBOLD
, SCE_HBA_WORD
, 1);
1241 SetAStyle(SCE_HBA_STRING
, RGB(0x80,0,0x80));
1242 SetAStyle(SCE_HBA_IDENTIFIER
, black
);
1244 // Show the whole section of ASP VBScript with bright yellow background
1245 for (int bastyle
= SCE_HBA_DEFAULT
; bastyle
<= SCE_HBA_STRINGEOL
; ++bastyle
) {
1246 SendEditor(SCI_STYLESETFONT
, bastyle
,
1247 reinterpret_cast<LPARAM
>(m_TextView
.StringForControl(_T("Lucida Console")).GetBuffer()));
1248 SendEditor(SCI_STYLESETBACK
, bastyle
, RGB(0xFF, 0xFF, 0));
1249 // This call extends the backround colour of the last style on the line to the edge of the window
1250 SendEditor(SCI_STYLESETEOLFILLED
, bastyle
, 1);
1252 SendEditor(SCI_STYLESETBACK
, SCE_HBA_STRINGEOL
, RGB(0xCF,0xCF,0x7F));
1253 SendEditor(SCI_STYLESETFONT
, SCE_HBA_COMMENTLINE
,
1254 reinterpret_cast<LPARAM
>(m_TextView
.StringForControl(_T("Lucida Console")).GetBuffer()));
1256 // If there is no need to support embedded Javascript, the following code can be dropped.
1257 // Javascript will still be correctly processed but will be displayed in just the default style.
1259 SetAStyle(SCE_HJ_START
, RGB(0x80,0x80,0));
1260 SetAStyle(SCE_HJ_DEFAULT
, black
);
1261 SetAStyle(SCE_HJ_COMMENT
, darkGreen
);
1262 SetAStyle(SCE_HJ_COMMENTLINE
, darkGreen
);
1263 SetAStyle(SCE_HJ_COMMENTDOC
, darkGreen
);
1264 SetAStyle(SCE_HJ_NUMBER
, RGB(0,0x80,0x80));
1265 SetAStyle(SCE_HJ_WORD
, black
);
1266 SetAStyle(SCE_HJ_KEYWORD
, darkBlue
);
1267 SetAStyle(SCE_HJ_DOUBLESTRING
, RGB(0x80,0,0x80));
1268 SetAStyle(SCE_HJ_SINGLESTRING
, RGB(0x80,0,0x80));
1269 SetAStyle(SCE_HJ_SYMBOLS
, black
);
1271 SetAStyle(SCE_HJA_START
, RGB(0x80,0x80,0));
1272 SetAStyle(SCE_HJA_DEFAULT
, black
);
1273 SetAStyle(SCE_HJA_COMMENT
, darkGreen
);
1274 SetAStyle(SCE_HJA_COMMENTLINE
, darkGreen
);
1275 SetAStyle(SCE_HJA_COMMENTDOC
, darkGreen
);
1276 SetAStyle(SCE_HJA_NUMBER
, RGB(0,0x80,0x80));
1277 SetAStyle(SCE_HJA_WORD
, black
);
1278 SetAStyle(SCE_HJA_KEYWORD
, darkBlue
);
1279 SetAStyle(SCE_HJA_DOUBLESTRING
, RGB(0x80,0,0x80));
1280 SetAStyle(SCE_HJA_SINGLESTRING
, RGB(0x80,0,0x80));
1281 SetAStyle(SCE_HJA_SYMBOLS
, black
);
1283 SetAStyle(SCE_HPHP_DEFAULT
, black
);
1284 SetAStyle(SCE_HPHP_HSTRING
, RGB(0x80,0,0x80));
1285 SetAStyle(SCE_HPHP_SIMPLESTRING
, RGB(0x80,0,0x80));
1286 SetAStyle(SCE_HPHP_WORD
, darkBlue
);
1287 SetAStyle(SCE_HPHP_NUMBER
, RGB(0,0x80,0x80));
1288 SetAStyle(SCE_HPHP_VARIABLE
, red
);
1289 SetAStyle(SCE_HPHP_HSTRING_VARIABLE
, red
);
1290 SetAStyle(SCE_HPHP_COMPLEX_VARIABLE
, red
);
1291 SetAStyle(SCE_HPHP_COMMENT
, darkGreen
);
1292 SetAStyle(SCE_HPHP_COMMENTLINE
, darkGreen
);
1293 SetAStyle(SCE_HPHP_OPERATOR
, darkBlue
);
1295 // Show the whole section of Javascript with off white background
1296 for (int jstyle
= SCE_HJ_DEFAULT
; jstyle
<= SCE_HJ_SYMBOLS
; ++jstyle
) {
1297 SendEditor(SCI_STYLESETFONT
, jstyle
,
1298 reinterpret_cast<LPARAM
>(m_TextView
.StringForControl(_T("Lucida Console")).GetBuffer()));
1299 SendEditor(SCI_STYLESETBACK
, jstyle
, offWhite
);
1300 SendEditor(SCI_STYLESETEOLFILLED
, jstyle
, 1);
1302 SendEditor(SCI_STYLESETBACK
, SCE_HJ_STRINGEOL
, RGB(0xDF, 0xDF, 0x7F));
1303 SendEditor(SCI_STYLESETEOLFILLED
, SCE_HJ_STRINGEOL
, 1);
1305 // Show the whole section of Javascript with brown background
1306 for (int jastyle
= SCE_HJA_DEFAULT
; jastyle
<= SCE_HJA_SYMBOLS
; ++jastyle
) {
1307 SendEditor(SCI_STYLESETFONT
, jastyle
,
1308 reinterpret_cast<LPARAM
>(m_TextView
.StringForControl(_T("Lucida Console")).GetBuffer()));
1309 SendEditor(SCI_STYLESETBACK
, jastyle
, RGB(0xDF, 0xDF, 0x7F));
1310 SendEditor(SCI_STYLESETEOLFILLED
, jastyle
, 1);
1312 SendEditor(SCI_STYLESETBACK
, SCE_HJA_STRINGEOL
, RGB(0x0,0xAF,0x5F));
1313 SendEditor(SCI_STYLESETEOLFILLED
, SCE_HJA_STRINGEOL
, 1);
1318 SendEditor(SCI_SETLEXER
, SCLEX_CPP
);
1321 SendEditor(SCI_COLOURISE
, 0, -1);
1325 void CTortoiseGitBlameView::SetupCppLexer()
1327 SetAStyle(SCE_C_DEFAULT
, RGB(0, 0, 0));
1328 SetAStyle(SCE_C_COMMENT
, RGB(0, 0x80, 0));
1329 SetAStyle(SCE_C_COMMENTLINE
, RGB(0, 0x80, 0));
1330 SetAStyle(SCE_C_COMMENTDOC
, RGB(0, 0x80, 0));
1331 SetAStyle(SCE_C_COMMENTLINEDOC
, RGB(0, 0x80, 0));
1332 SetAStyle(SCE_C_COMMENTDOCKEYWORD
, RGB(0, 0x80, 0));
1333 SetAStyle(SCE_C_COMMENTDOCKEYWORDERROR
, RGB(0, 0x80, 0));
1334 SetAStyle(SCE_C_NUMBER
, RGB(0, 0x80, 0x80));
1335 SetAStyle(SCE_C_WORD
, RGB(0, 0, 0x80));
1336 SendEditor(SCE_C_WORD
, 1);
1337 SetAStyle(SCE_C_STRING
, RGB(0x80, 0, 0x80));
1338 SetAStyle(SCE_C_IDENTIFIER
, RGB(0, 0, 0));
1339 SetAStyle(SCE_C_PREPROCESSOR
, RGB(0x80, 0, 0));
1340 SetAStyle(SCE_C_OPERATOR
, RGB(0x80, 0x80, 0));
1343 int CTortoiseGitBlameView::GetEncode(unsigned char *buff
, int size
, int *bomoffset
)
1345 CFileTextLines textlines
;
1346 CFileTextLines::UnicodeType type
= textlines
.CheckUnicodeType(buff
, size
);
1348 if(type
== CFileTextLines::UTF8BOM
)
1353 if(type
== CFileTextLines::UTF8
)
1356 if(type
== CFileTextLines::UTF16_LE
)
1362 if(type
== CFileTextLines::UTF16_BE
)
1371 void CTortoiseGitBlameView::UpdateInfo(int Encode
)
1373 BYTE_VECTOR
&data
= GetDocument()->m_BlameData
;
1379 this->m_CommitHash
.clear();
1380 this->m_Authors
.clear();
1381 this->m_Dates
.clear();
1387 SendEditor(SCI_SETREADONLY
, FALSE
);
1388 SendEditor(SCI_CLEARALL
);
1389 SendEditor(EM_EMPTYUNDOBUFFER
);
1390 SendEditor(SCI_SETSAVEPOINT
);
1391 SendEditor(SCI_CANCEL
);
1392 SendEditor(SCI_SETUNDOCOLLECTION
, 0);
1394 SendEditor(SCI_SETCODEPAGE
, SC_CP_UTF8
);
1397 int encoding
= Encode
;
1398 while( pos
>=0 && current
>=0 && pos
<data
.size() )
1400 current
= data
.findData((const BYTE
*)"\n",1,pos
);
1401 //one=data.Tokenize(_T("\n"),pos);
1403 bool isbound
= ( data
[pos
] == _T('^') );
1405 if( (data
.size() - pos
) >1 && data
[pos
] == _T('^'))
1417 [] { git_init(); } ();
1420 catch (const char* msg
)
1422 ::MessageBox(NULL
, _T("Could not initialize libgit.\nlibgit reports:\n") + CString(msg
), _T("TortoiseGit"), MB_ICONERROR
);
1429 if (git_get_sha1((const char*)&data
[pos
], hash
.m_hash
))
1430 ::MessageBox(NULL
, _T("Can't get hash"), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
1432 catch (const char* msg
)
1434 ::MessageBox(NULL
, _T("Can't get hash.\nlibgit reports:\n") + CString(msg
), _T("TortoiseGit"), MB_ICONERROR
);
1440 hash
.ConvertFromStrA((char*)&data
[pos
]);
1444 start
=data
.findData((const BYTE
*)")",1,pos
+ 40);
1457 if( pos
<40 && encoding
==0)
1460 encoding
= GetEncode(&data
[start
+ 2], (int)(data
.size() - start
- 2), &bomoffset
);
1463 if(encoding
== 1201)
1466 DWORD size
= ((current
- start
-2 - bomoffset
)/2);
1467 TCHAR
*buffer
= strw
.GetBuffer(size
);
1468 memcpy(buffer
, &data
[start
+ 2 + bomoffset
],sizeof(TCHAR
)*size
);
1469 // swap the bytes to little-endian order to get proper strings in wchar_t format
1470 wchar_t * pSwapBuf
= buffer
;
1471 for (DWORD i
= 0; i
<size
; ++i
)
1473 *pSwapBuf
= WideCharSwap2(*pSwapBuf
);
1476 strw
.ReleaseBuffer();
1478 stra
= CUnicodeUtils::GetUTF8(strw
);
1480 else if(encoding
== 1200)
1483 // the first bomoffset is 2, after that it's 1 (see issue #920)
1484 // also: don't set bomoffset if called from Encodings menu (i.e. start == 42 and bomoffset == 0); bomoffset gets only set if autodetected
1485 if (bomoffset
== 0 && start
!= 42)
1487 int size
= ((current
- start
-2 - bomoffset
)/2);
1488 TCHAR
*buffer
= strw
.GetBuffer(size
);
1489 memcpy(buffer
, &data
[start
+ 2 + bomoffset
],sizeof(TCHAR
)*size
);
1490 strw
.ReleaseBuffer();
1492 stra
= CUnicodeUtils::GetUTF8(strw
);
1494 else if(encoding
== CP_UTF8
)
1496 stra
= &data
[start
+ 2 + bomoffset
];
1501 strw
= CUnicodeUtils::GetUnicode(CStringA(&data
[start
+ 2 + bomoffset
]), encoding
);
1502 stra
= CUnicodeUtils::GetUTF8(strw
);
1506 SendEditor(SCI_REPLACESEL
, 0, (LPARAM
)(LPCSTR
)stra
);
1507 SendEditor(SCI_REPLACESEL
, 0, (LPARAM
)(LPCSTR
)"\n\0\0\0");
1510 data
[current
] = '\n';
1514 if(this->m_NoListCommit
.find(hash
) == m_NoListCommit
.end() )
1516 this->m_NoListCommit
[hash
].GetCommitFromHash(hash
);
1520 for (size_t i
= 0; i
< this->GetLogData()->size(); ++i
)
1522 if(hash
== this->GetLogData()->at(i
))
1524 m_ID
.push_back((LONG
)(this->GetLogData()->size() - i
));
1532 m_Authors
.push_back(m_NoListCommit
[hash
].GetAuthorName());
1533 m_Dates
.push_back(CLoglistUtils::FormatDateAndTime(m_NoListCommit
[hash
].GetAuthorDate(), m_DateFormat
, true, m_bRelativeTimes
));
1535 m_CommitHash
.push_back(hash
);
1542 int nIndex
= ((CMainFrame
*)::AfxGetApp()->GetMainWnd())->m_wndStatusBar
.CommandToIndex(ID_INDICATOR_ENCODING
);
1543 ((CMainFrame
*)::AfxGetApp()->GetMainWnd())->m_wndStatusBar
.GetPaneInfo(nIndex
, nID
, nStyle
, cxWidth
);
1544 CString sBarText
= L
"";
1545 for (int i
= 0; i
< _countof(encodings
); ++i
)
1547 if (encodings
[i
].id
== encoding
)
1549 sBarText
= CString(encodings
[i
].name
);
1553 //calculate the width of the text
1554 CDC
* pDC
= ((CMainFrame
*)::AfxGetApp()->GetMainWnd())->m_wndStatusBar
.GetDC();
1557 CSize size
= pDC
->GetTextExtent(sBarText
);
1558 ((CMainFrame
*)::AfxGetApp()->GetMainWnd())->m_wndStatusBar
.SetPaneInfo(nIndex
, nID
, nStyle
, size
.cx
+2);
1561 ((CMainFrame
*)::AfxGetApp()->GetMainWnd())->m_wndStatusBar
.SetPaneText(nIndex
, sBarText
);
1572 file
.Open(this->GetDocument()->m_TempFileName
,CFile::modeRead
);
1574 m_Buffer
= new char[file
.GetLength()+4];
1575 m_Buffer
[file
.GetLength()] =0;
1576 m_Buffer
[file
.GetLength()+1] =0;
1577 m_Buffer
[file
.GetLength()+2] =0;
1578 m_Buffer
[file
.GetLength()+3] =0;
1580 file
.Read(m_Buffer
, file
.GetLength());
1583 int encoding
= GetEncode( (unsigned char *)m_Buffer
, file
.GetLength(), &bomoffset
);
1586 //SendEditor(SCI_SETCODEPAGE, encoding);
1588 //SendEditor(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)(m_Buffer + bomoffset));
1590 SetupLexer(GetDocument()->m_CurrentFileName
);
1592 SendEditor(SCI_SETUNDOCOLLECTION
, 1);
1593 SendEditor(EM_EMPTYUNDOBUFFER
);
1594 SendEditor(SCI_SETSAVEPOINT
);
1595 SendEditor(SCI_GOTOPOS
, 0);
1596 SendEditor(SCI_SETSCROLLWIDTHTRACKING
, TRUE
);
1597 SendEditor(SCI_SETREADONLY
, TRUE
);
1600 m_highestrev
= (long)(this->GetLogData()->size());
1604 this->GetClientRect(rect
);
1605 //this->m_TextView.GetWindowRect(rect);
1606 //this->m_TextView.ScreenToClient(rect);
1607 rect
.left
=this->m_blamewidth
;
1608 this->m_TextView
.MoveWindow(rect
);
1613 COLORREF
CTortoiseGitBlameView::GetLineColor(int line
)
1615 if (m_colorage
&& line
>= 0 && line
< m_ID
.size())
1616 return InterColor(DWORD(m_regOldLinesColor
), DWORD(m_regNewLinesColor
), (m_ID
[line
] - m_lowestrev
) * 100 / ((m_highestrev
- m_lowestrev
) + 1));
1618 return m_windowcolor
;
1621 CGitBlameLogList
* CTortoiseGitBlameView::GetLogList()
1623 return &(GetDocument()->GetMainFrame()->m_wndOutput
.m_LogList
);
1627 CLogDataVector
* CTortoiseGitBlameView::GetLogData()
1629 return &(GetDocument()->GetMainFrame()->m_wndOutput
.m_LogList
.m_logEntries
);
1632 void CTortoiseGitBlameView::OnSciPainted(NMHDR
*,LRESULT
*)
1637 void CTortoiseGitBlameView::OnLButtonDown(UINT nFlags
,CPoint point
)
1640 LONG line
= (LONG
)SendEditor(SCI_GETFIRSTVISIBLELINE
);
1641 LONG height
= (LONG
)SendEditor(SCI_TEXTHEIGHT
);
1642 line
= line
+ (point
.y
/height
);
1644 if (line
< (LONG
)m_CommitHash
.size())
1646 SetSelectedLine(line
);
1647 if (m_CommitHash
[line
] != m_SelectedHash
)
1649 m_SelectedHash
= m_CommitHash
[line
];
1653 this->GetLogList()->SetItemState(this->GetLogList()->GetItemCount()-m_ID
[line
],
1656 this->GetLogList()->EnsureVisible(this->GetLogList()->GetItemCount()-m_ID
[line
], FALSE
);
1660 this->GetDocument()->GetMainFrame()->m_wndProperties
.UpdateProperties(&m_NoListCommit
[m_CommitHash
[line
]]);
1665 m_SelectedHash
.Empty();
1667 //::InvalidateRect( NULL, FALSE);
1669 this->m_TextView
.Invalidate();
1674 SetSelectedLine(-1);
1677 CView::OnLButtonDown(nFlags
,point
);
1680 void CTortoiseGitBlameView::OnSciGetBkColor(NMHDR
* hdr
, LRESULT
* /*result*/)
1682 SCNotification
*notification
=reinterpret_cast<SCNotification
*>(hdr
);
1684 if (notification
->line
< (int)m_CommitHash
.size())
1686 if (m_CommitHash
[notification
->line
] == this->m_SelectedHash
)
1687 notification
->lParam
= m_selectedauthorcolor
;
1689 notification
->lParam
= GetLineColor(notification
->line
);
1693 void CTortoiseGitBlameView::FocusOn(GitRev
*pRev
)
1695 this->GetDocument()->GetMainFrame()->m_wndProperties
.UpdateProperties(pRev
);
1699 if (m_SelectedHash
!= pRev
->m_CommitHash
) {
1700 m_SelectedHash
= pRev
->m_CommitHash
;
1701 for (size_t i
= 0; i
< m_CommitHash
.size(); ++i
)
1703 if (pRev
->m_CommitHash
== m_CommitHash
[i
])
1705 GotoLine((long)(i
+ 1));
1706 m_TextView
.Invalidate();
1710 SendEditor(SCI_SETSEL
, LONG_MAX
, -1);
1714 void CTortoiseGitBlameView::OnMouseHover(UINT
/*nFlags*/, CPoint point
)
1716 LONG_PTR line
= SendEditor(SCI_GETFIRSTVISIBLELINE
);
1717 LONG_PTR height
= SendEditor(SCI_TEXTHEIGHT
);
1718 line
= line
+ (point
.y
/height
);
1720 if (line
< (LONG
)m_CommitHash
.size())
1722 if (line
!= m_MouseLine
)
1724 m_MouseLine
= (LONG
)line
;//m_CommitHash[line];
1728 pRev
=&this->m_NoListCommit
[m_CommitHash
[line
]];
1733 pRev
=&this->GetLogData()->GetGitRevAt(this->GetLogList()->GetItemCount()-m_ID
[line
]);
1736 CString body
= pRev
->GetBody();
1740 while (line
++ < maxLine
)
1742 int pos2
= body
.Find(_T("\n"), pos
);
1745 int lineLength
= pos2
- pos
- 1;
1747 line
+= lineLength
/ 70;
1751 str
.Format(_T("%s: %s\n%s: %s <%s>\n%s: %s\n%s:\n%s\n%s"), m_sRev
, pRev
->m_CommitHash
.ToString(),
1752 m_sAuthor
, pRev
->GetAuthorName(), pRev
->GetAuthorEmail(),
1753 m_sDate
, CLoglistUtils::FormatDateAndTime(pRev
->GetAuthorDate(), m_DateFormat
, true, m_bRelativeTimes
),
1754 m_sMessage
, pRev
->GetSubject(),
1755 line
<= maxLine
? body
: (body
.Left(pos
) + _T("\n....................")));
1758 m_ToolTip
.AddTool(this, str
);
1761 rect
.left
=LOCATOR_WIDTH
;
1762 rect
.right
=this->m_blamewidth
+rect
.left
;
1763 rect
.top
= point
.y
- (LONG
)height
;
1764 rect
.bottom
= point
.y
+ (LONG
)height
;
1765 this->InvalidateRect(rect
);
1770 void CTortoiseGitBlameView::OnMouseMove(UINT
/*nFlags*/, CPoint
/*point*/)
1772 TRACKMOUSEEVENT tme
;
1773 tme
.cbSize
=sizeof(TRACKMOUSEEVENT
);
1774 tme
.dwFlags
=TME_HOVER
|TME_LEAVE
;
1775 tme
.hwndTrack
=this->m_hWnd
;
1777 TrackMouseEvent(&tme
);
1781 BOOL
CTortoiseGitBlameView::PreTranslateMessage(MSG
* pMsg
)
1783 m_ToolTip
.RelayEvent(pMsg
);
1784 return CView::PreTranslateMessage(pMsg
);
1787 void CTortoiseGitBlameView::OnEditFind()
1789 m_pFindDialog
=new CFindReplaceDialog();
1791 CString oneline
= theApp
.GetString(_T("FindString"));
1792 if (m_TextView
.Call(SCI_GETSELECTIONSTART
) != m_TextView
.Call(SCI_GETSELECTIONEND
))
1794 LRESULT bufsize
= m_TextView
.Call(SCI_GETSELECTIONEND
) - m_TextView
.Call(SCI_GETSELECTIONSTART
);
1795 char * linebuf
= new char[bufsize
+ 1];
1796 SecureZeroMemory(linebuf
, bufsize
+ 1);
1797 SendEditor(SCI_GETSELTEXT
, 0, (LPARAM
)linebuf
);
1798 oneline
= m_TextView
.StringFromControl(linebuf
);
1802 DWORD flags
= FR_DOWN
| FR_HIDEWHOLEWORD
| FR_HIDEUPDOWN
;
1803 if (theApp
.GetInt(_T("FindMatchCase")))
1804 flags
|= FR_MATCHCASE
;
1806 m_pFindDialog
->Create(TRUE
, oneline
, NULL
, flags
, this);
1809 void CTortoiseGitBlameView::OnEditGoto()
1812 if(dlg
.DoModal()==IDOK
)
1814 this->GotoLine(dlg
.m_LineNumber
);
1818 LRESULT
CTortoiseGitBlameView::OnFindDialogMessage(WPARAM
/*wParam*/, LPARAM
/*lParam*/)
1820 ASSERT(m_pFindDialog
!= NULL
);
1822 if (m_CommitHash
.empty())
1825 // If the FR_DIALOGTERM flag is set,
1826 // invalidate the handle identifying the dialog box.
1827 if (m_pFindDialog
->IsTerminating())
1829 m_pFindDialog
= NULL
;
1833 // If the FR_FINDNEXT flag is set,
1834 // call the application-defined search routine
1835 // to search for the requested string.
1836 if(m_pFindDialog
->FindNext())
1838 //read data from dialog
1839 CString FindName
= m_pFindDialog
->GetFindString();
1841 DoSearch(FindName
,m_pFindDialog
->m_fr
.Flags
);
1847 void CTortoiseGitBlameView::OnViewNext()
1849 FindNextLine(this->m_SelectedHash
,false);
1851 void CTortoiseGitBlameView::OnViewPrev()
1853 FindNextLine(this->m_SelectedHash
,true);
1856 void CTortoiseGitBlameView::OnViewToggleAuthor()
1858 m_bShowAuthor
= ! m_bShowAuthor
;
1860 theApp
.WriteInt(_T("ShowAuthor"), m_bShowAuthor
);
1863 this->GetClientRect(&rect
);
1864 rect
.left
=GetBlameWidth();
1866 m_TextView
.MoveWindow(&rect
);
1869 void CTortoiseGitBlameView::OnUpdateViewToggleAuthor(CCmdUI
*pCmdUI
)
1871 pCmdUI
->SetCheck(m_bShowAuthor
);
1874 void CTortoiseGitBlameView::OnViewToggleDate()
1876 m_bShowDate
= ! m_bShowDate
;
1878 theApp
.WriteInt(_T("ShowDate"), m_bShowDate
);
1881 this->GetClientRect(&rect
);
1882 rect
.left
=GetBlameWidth();
1884 m_TextView
.MoveWindow(&rect
);
1887 void CTortoiseGitBlameView::OnUpdateViewToggleDate(CCmdUI
*pCmdUI
)
1889 pCmdUI
->SetCheck(m_bShowDate
);
1892 void CTortoiseGitBlameView::OnViewToggleFollowRenames()
1894 m_bFollowRenames
= ! m_bFollowRenames
;
1896 theApp
.WriteInt(_T("FollowRenames"), m_bFollowRenames
);
1898 CTortoiseGitBlameDoc
*document
= (CTortoiseGitBlameDoc
*) m_pDocument
;
1899 if (!document
->m_CurrentFileName
.IsEmpty())
1901 document
->m_lLine
= (LONG
)SendEditor(SCI_GETFIRSTVISIBLELINE
) + 1;
1902 theApp
.m_pDocManager
->OnFileNew();
1903 document
->OnOpenDocument(document
->m_CurrentFileName
, document
->m_Rev
);
1907 void CTortoiseGitBlameView::OnUpdateViewToggleFollowRenames(CCmdUI
*pCmdUI
)
1909 pCmdUI
->SetCheck(m_bFollowRenames
);
1912 void CTortoiseGitBlameView::OnViewToggleColorByAge()
1914 m_colorage
= ! m_colorage
;
1916 theApp
.WriteInt(_T("ColorAge"), m_colorage
);
1918 m_TextView
.Invalidate();
1921 void CTortoiseGitBlameView::OnUpdateViewToggleColorByAge(CCmdUI
*pCmdUI
)
1923 pCmdUI
->SetCheck(m_colorage
);
1926 void CTortoiseGitBlameView::OnUpdateViewCopyToClipboard(CCmdUI
*pCmdUI
)
1928 CWnd
* wnd
= GetFocus();
1929 if (wnd
== GetLogList())
1931 pCmdUI
->Enable(GetLogList()->GetSelectedCount() > 0);
1935 if (CString(wnd
->GetRuntimeClass()->m_lpszClassName
) == _T("CMFCPropertyGridCtrl"))
1937 CMFCPropertyGridCtrl
*grid
= (CMFCPropertyGridCtrl
*)wnd
;
1938 pCmdUI
->Enable(grid
->GetCurSel() && !grid
->GetCurSel()->IsGroup() && !CString(grid
->GetCurSel()->GetValue()).IsEmpty());
1941 pCmdUI
->Enable(m_TextView
.Call(SCI_GETSELECTIONSTART
) != m_TextView
.Call(SCI_GETSELECTIONEND
));
1944 pCmdUI
->Enable(FALSE
);
1947 int CTortoiseGitBlameView::FindNextLine(CGitHash CommitHash
,bool bUpOrDown
)
1949 LONG line
= (LONG
)SendEditor(SCI_GETFIRSTVISIBLELINE
);
1950 LONG startline
= line
;
1951 bool findNoMatch
=false;
1952 while(line
>=0 && line
<m_CommitHash
.size())
1954 if(m_CommitHash
[line
]!=CommitHash
)
1959 if(m_CommitHash
[line
] == CommitHash
&& findNoMatch
)
1961 if( line
== startline
+2 )
1969 line
=FindFirstLine(CommitHash
,line
);
1971 SendEditor(SCI_LINESCROLL
,0,line
-startline
-2);