TGitBlame: Allow to select UTF-8 and UTF-16 (L|B)E in Encodings menu
[TortoiseGit.git] / src / TortoiseGitBlame / TortoiseGitBlameView.cpp
blob9fa6bfdb00e9641bc6b58a7f59179467057cff3e
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
26 #include "stdafx.h"
27 #include "TortoiseGitBlame.h"
28 #include "CommonAppUtils.h"
29 #include "TortoiseGitBlameDoc.h"
30 #include "TortoiseGitBlameView.h"
31 #include "MainFrm.h"
32 #include "EditGotoDlg.h"
33 #include "LoglistUtils.h"
34 #include "FileTextLines.h"
35 #include "UniCodeUtils.h"
36 #include "MenuEncode.h"
37 #include "gitdll.h"
38 #include "SysInfo.h"
39 #include "StringUtils.h"
41 #ifdef _DEBUG
42 #define new DEBUG_NEW
43 #endif
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)
80 ON_WM_CREATE()
81 ON_WM_SIZE()
82 ON_WM_MOUSEMOVE()
83 ON_WM_MOUSEHOVER()
84 ON_WM_MOUSELEAVE()
85 ON_WM_LBUTTONDOWN()
86 ON_WM_RBUTTONDOWN()
87 ON_WM_RBUTTONUP()
88 ON_NOTIFY(SCN_PAINTED, IDC_SCINTILLA, OnSciPainted)
89 ON_NOTIFY(SCN_GETBKCOLOR, IDC_SCINTILLA, OnSciGetBkColor)
90 ON_REGISTERED_MESSAGE(m_FindDialogMessage, OnFindDialogMessage)
91 END_MESSAGE_MAP()
94 // CTortoiseGitBlameView construction/destruction
96 CTortoiseGitBlameView::CTortoiseGitBlameView()
98 hInstance = 0;
99 hResource = 0;
100 currentDialog = 0;
101 wMain = 0;
102 m_wEditor = 0;
103 wLocator = 0;
105 m_font = 0;
106 m_italicfont = 0;
107 m_blamewidth = 0;
108 m_revwidth = 0;
109 m_datewidth = 0;
110 m_authorwidth = 0;
111 m_linewidth = 0;
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);
120 m_mouserev = -2;
122 m_selectedrev = -1;
123 m_selectedorigrev = -1;
124 m_SelectedLine = -1;
125 m_directPointer = 0;
126 m_directFunction = 0;
128 m_lowestrev = LONG_MAX;
129 m_highestrev = 0;
130 m_colorage = true;
132 m_bShowLine=true;
134 m_bShowAuthor = (theApp.GetInt(_T("ShowAuthor"), 1) == 1);
135 m_bShowDate=false;
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;
146 else
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);
159 m_Buffer = NULL;
162 CTortoiseGitBlameView::~CTortoiseGitBlameView()
164 if (m_font)
165 DeleteObject(m_font);
166 if (m_italicfont)
167 DeleteObject(m_italicfont);
169 if(m_Buffer)
171 delete m_Buffer;
172 m_Buffer=NULL;
175 struct EncodingUnit
177 int id;
178 char *name;
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
234 {65001, "UTF-8"}, //IDM_FORMAT_UTF8
235 {1200, "UTF-16 LE"}, //IDM_FORMAT_UTF16LE
236 {1201, "UTF-16 BE"}, //IDM_FORMAT_UTF16BE
238 if(nId >= IDM_FORMAT_ENCODE && nId <= IDM_FORMAT_ENCODE_END)
239 this->UpdateInfo(encodings[nId - IDM_FORMAT_ENCODE].id);
241 int CTortoiseGitBlameView::OnCreate(LPCREATESTRUCT lpcs)
244 CRect rect,rect1;
245 this->GetWindowRect(&rect1);
246 rect.left=m_blamewidth+LOCATOR_WIDTH;
247 rect.right=rect.Width();
248 rect.top=0;
249 rect.bottom=rect.Height();
250 if (!m_TextView.Create(_T("Scintilla"), _T("source"), 0, rect, this, IDC_SCINTILLA, 0))
252 TRACE0("Failed to create view\n");
253 return -1; // fail to create
255 m_TextView.Init(0,FALSE);
256 m_TextView.ShowWindow( SW_SHOW);
257 m_wEditor = m_TextView.m_hWnd;
258 CreateFont();
259 InitialiseEditor();
260 m_ToolTip.Create(this->GetParent());
262 ::AfxGetApp()->GetMainWnd();
263 return CView::OnCreate(lpcs);
267 void CTortoiseGitBlameView::OnSize(UINT /*nType*/, int cx, int cy)
270 CRect rect;
271 rect.left=m_blamewidth;
272 rect.right=cx;
273 rect.top=0;
274 rect.bottom=cy;
276 m_TextView.MoveWindow(&rect);
279 BOOL CTortoiseGitBlameView::PreCreateWindow(CREATESTRUCT& cs)
281 return CView::PreCreateWindow(cs);
284 // CTortoiseGitBlameView drawing
286 void CTortoiseGitBlameView::OnDraw(CDC* /*pDC*/)
288 CTortoiseGitBlameDoc* pDoc = GetDocument();
289 ASSERT_VALID(pDoc);
290 if (!pDoc)
291 return;
293 DrawBlame(this->GetDC()->m_hDC);
294 DrawLocatorBar(this->GetDC()->m_hDC);
295 // TODO: add draw code for native data here
299 // CTortoiseGitBlameView printing
302 void CTortoiseGitBlameView::OnFilePrintPreview()
304 AFXPrintPreview(this);
307 BOOL CTortoiseGitBlameView::OnPreparePrinting(CPrintInfo* pInfo)
309 // default preparation
310 return DoPreparePrinting(pInfo);
313 void CTortoiseGitBlameView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
315 // TODO: add extra initialization before printing
318 void CTortoiseGitBlameView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
320 // TODO: add cleanup after printing
323 void CTortoiseGitBlameView::OnRButtonUp(UINT /*nFlags*/, CPoint point)
325 LONG_PTR line = SendEditor(SCI_GETFIRSTVISIBLELINE);
326 LONG_PTR height = SendEditor(SCI_TEXTHEIGHT);
327 line = line + (point.y/height);
328 if (line < (LONG)m_CommitHash.size())
330 if(m_ID[line] >= 0) // only show context menu if we have log data for it
332 m_MouseLine = (LONG)line;
333 ClientToScreen(&point);
334 theApp.GetContextMenuManager()->ShowPopupMenu(IDR_BLAME_POPUP, point.x, point.y, this, TRUE);
339 void CTortoiseGitBlameView::OnUpdateBlamePopupBlamePrevious(CCmdUI *pCmdUI)
341 if (m_ID[m_MouseLine] <= 1)
343 pCmdUI->Enable(false);
345 else
347 pCmdUI->Enable(true);
351 void CTortoiseGitBlameView::OnUpdateBlamePopupDiffPrevious(CCmdUI *pCmdUI)
353 if (m_ID[m_MouseLine] <= 1)
355 pCmdUI->Enable(false);
357 else
359 pCmdUI->Enable(true);
363 void CTortoiseGitBlameView::CopyHashToClipboard()
365 this->GetLogList()->CopySelectionToClipBoard(CGitLogListBase::ID_COPY_HASH);
368 // CTortoiseGitBlameView diagnostics
370 #ifdef _DEBUG
371 void CTortoiseGitBlameView::AssertValid() const
373 CView::AssertValid();
376 void CTortoiseGitBlameView::Dump(CDumpContext& dc) const
378 CView::Dump(dc);
381 CTortoiseGitBlameDoc* CTortoiseGitBlameView::GetDocument() const // non-debug version is inline
383 ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTortoiseGitBlameDoc)));
384 return (CTortoiseGitBlameDoc*)m_pDocument;
386 #endif //_DEBUG
389 // CTortoiseGitBlameView message handlers
390 CString CTortoiseGitBlameView::GetAppDirectory()
392 CString path;
393 DWORD len = 0;
394 DWORD bufferlen = MAX_PATH; // MAX_PATH is not the limit here!
397 bufferlen += MAX_PATH; // MAX_PATH is not the limit here!
398 std::unique_ptr<TCHAR[]> pBuf(new TCHAR[bufferlen]);
399 len = GetModuleFileName(NULL, pBuf.get(), bufferlen);
400 path = CString(pBuf.get(), len);
401 } while(len == bufferlen);
403 path = path.Left(path.ReverseFind(_T('\\')));
404 //path = path.substr(0, path.rfind('\\') + 1);
406 return path;
409 // Return a color which is interpolated between c1 and c2.
410 // Slider controls the relative proportions as a percentage:
411 // Slider = 0 represents pure c1
412 // Slider = 50 represents equal mixture
413 // Slider = 100 represents pure c2
414 COLORREF CTortoiseGitBlameView::InterColor(COLORREF c1, COLORREF c2, int Slider)
416 int r, g, b;
418 // Limit Slider to 0..100% range
419 if (Slider < 0)
420 Slider = 0;
421 if (Slider > 100)
422 Slider = 100;
424 // The color components have to be treated individually.
425 r = (GetRValue(c2) * Slider + GetRValue(c1) * (100 - Slider)) / 100;
426 g = (GetGValue(c2) * Slider + GetGValue(c1) * (100 - Slider)) / 100;
427 b = (GetBValue(c2) * Slider + GetBValue(c1) * (100 - Slider)) / 100;
429 return RGB(r, g, b);
432 LRESULT CTortoiseGitBlameView::SendEditor(UINT Msg, WPARAM wParam, LPARAM lParam)
434 if (m_directFunction)
436 return ((SciFnDirect) m_directFunction)(m_directPointer, Msg, wParam, lParam);
438 return ::SendMessage(m_wEditor, Msg, wParam, lParam);
441 void CTortoiseGitBlameView::SetAStyle(int style, COLORREF fore, COLORREF back, int size, CString *face)
443 SendEditor(SCI_STYLESETFORE, style, fore);
444 SendEditor(SCI_STYLESETBACK, style, back);
445 if (size >= 1)
446 SendEditor(SCI_STYLESETSIZE, style, size);
447 if (face)
448 SendEditor(SCI_STYLESETFONT, style, reinterpret_cast<LPARAM>(this->m_TextView.StringForControl(*face).GetBuffer()));
451 void CTortoiseGitBlameView::InitialiseEditor()
454 m_directFunction = ::SendMessage(m_wEditor, SCI_GETDIRECTFUNCTION, 0, 0);
455 m_directPointer = ::SendMessage(m_wEditor, SCI_GETDIRECTPOINTER, 0, 0);
456 // Set up the global default style. These attributes are used wherever no explicit choices are made.
457 SetAStyle(STYLE_DEFAULT,
458 black,
459 white,
460 (DWORD)CRegStdDWORD(_T("Software\\TortoiseGit\\BlameFontSize"), 10),
461 &CString(((stdstring)CRegStdString(_T("Software\\TortoiseGit\\BlameFontName"), _T("Courier New"))).c_str())
463 SendEditor(SCI_SETTABWIDTH, (DWORD)CRegStdDWORD(_T("Software\\TortoiseGit\\BlameTabSize"), 4));
464 SendEditor(SCI_SETREADONLY, TRUE);
465 LRESULT pix = SendEditor(SCI_TEXTWIDTH, STYLE_LINENUMBER, (LPARAM)this->m_TextView.StringForControl(_T("_99999")).GetBuffer());
466 if (m_bShowLine)
467 SendEditor(SCI_SETMARGINWIDTHN, 0, pix);
468 else
469 SendEditor(SCI_SETMARGINWIDTHN, 0);
470 SendEditor(SCI_SETMARGINWIDTHN, 1);
471 SendEditor(SCI_SETMARGINWIDTHN, 2);
472 //Set the default windows colors for edit controls
473 SendEditor(SCI_STYLESETFORE, STYLE_DEFAULT, ::GetSysColor(COLOR_WINDOWTEXT));
474 SendEditor(SCI_STYLESETBACK, STYLE_DEFAULT, ::GetSysColor(COLOR_WINDOW));
475 SendEditor(SCI_SETSELFORE, TRUE, ::GetSysColor(COLOR_HIGHLIGHTTEXT));
476 SendEditor(SCI_SETSELBACK, TRUE, ::GetSysColor(COLOR_HIGHLIGHT));
477 SendEditor(SCI_SETCARETFORE, ::GetSysColor(COLOR_WINDOWTEXT));
478 m_regOldLinesColor = CRegStdDWORD(_T("Software\\TortoiseGit\\BlameOldColor"), RGB(230, 230, 255));
479 m_regNewLinesColor = CRegStdDWORD(_T("Software\\TortoiseGit\\BlameNewColor"), RGB(255, 230, 230));
480 CRegStdDWORD used2d(L"Software\\TortoiseGit\\ScintillaDirect2D", FALSE);
481 if (SysInfo::Instance().IsWin7OrLater() && DWORD(used2d))
483 SendEditor(SCI_SETTECHNOLOGY, SC_TECHNOLOGY_DIRECTWRITE);
484 SendEditor(SCI_SETBUFFEREDDRAW, 0);
486 SendEditor(SCI_SETFONTQUALITY, SC_EFF_QUALITY_DEFAULT);
488 this->m_TextView.Call(SCI_SETWRAPMODE, SC_WRAP_NONE);
492 bool CTortoiseGitBlameView::DoSearch(CString what, DWORD flags)
494 int pos = (int)SendEditor(SCI_GETCURRENTPOS);
495 int line = (int)SendEditor(SCI_LINEFROMPOSITION, pos);
496 bool bFound = false;
497 bool bCaseSensitive = !!(flags & FR_MATCHCASE);
499 if(!bCaseSensitive)
500 what.MakeLower();
502 int i=line;
503 if(i >= (signed int)m_CommitHash.size())
504 i = 0;
507 int bufsize = (int)SendEditor(SCI_GETLINE, i);
508 char * linebuf = new char[bufsize+1];
509 SecureZeroMemory(linebuf, bufsize+1);
510 SendEditor(SCI_GETLINE, i, (LPARAM)linebuf);
511 CString oneline=this->m_TextView.StringFromControl(linebuf);
512 delete [] linebuf;
513 if (!bCaseSensitive)
515 CString lcAuthor = m_Authors[i];
516 if (lcAuthor.MakeLower().Find(what) >= 0)
517 bFound = true;
518 else if (oneline.MakeLower().Find(what) >=0)
519 bFound = true;
521 else if (m_Authors[i].Find(what) >= 0)
522 bFound = true;
523 else if (oneline.Find(what) >=0)
524 bFound = true;
526 i++;
527 if(!bFound && i >= (signed int)m_CommitHash.size())
528 i=0;
529 }while(i!=line &&(!bFound));
531 if (bFound)
533 GotoLine(i);
534 int selstart = (int)SendEditor(SCI_GETCURRENTPOS);
535 int selend = (int)SendEditor(SCI_POSITIONFROMLINE, i);
536 SendEditor(SCI_SETSELECTIONSTART, selstart);
537 SendEditor(SCI_SETSELECTIONEND, selend);
538 m_SelectedLine = i-1;
540 else
542 ::MessageBox(wMain, _T("\"") + what + _T("\" ") + CString(MAKEINTRESOURCE(IDS_NOTFOUND)), _T("TortoiseGitBlame"), MB_ICONINFORMATION);
545 return true;
548 bool CTortoiseGitBlameView::GotoLine(long line)
550 --line;
551 if (line < 0)
552 return false;
553 if ((unsigned long)line >= m_CommitHash.size())
555 line = (long)m_CommitHash.size()-1;
558 int nCurrentPos = (int)SendEditor(SCI_GETCURRENTPOS);
559 int nCurrentLine = (int)SendEditor(SCI_LINEFROMPOSITION,nCurrentPos);
560 int nFirstVisibleLine = (int)SendEditor(SCI_GETFIRSTVISIBLELINE);
561 int nLinesOnScreen = (int)SendEditor(SCI_LINESONSCREEN);
563 if ( line>=nFirstVisibleLine && line<=nFirstVisibleLine+nLinesOnScreen)
565 // no need to scroll
566 SendEditor(SCI_GOTOLINE, line);
568 else
570 // Place the requested line one third from the top
571 if ( line > nCurrentLine )
573 SendEditor(SCI_GOTOLINE, (WPARAM)(line+(int)nLinesOnScreen*(2/3.0)));
575 else
577 SendEditor(SCI_GOTOLINE, (WPARAM)(line-(int)nLinesOnScreen*(1/3.0)));
581 // Highlight the line
582 int nPosStart = (int)SendEditor(SCI_POSITIONFROMLINE,line);
583 int nPosEnd = (int)SendEditor(SCI_GETLINEENDPOSITION,line);
584 SendEditor(SCI_SETSEL,nPosEnd,nPosStart);
586 return true;
589 bool CTortoiseGitBlameView::ScrollToLine(long line)
591 if (line < 0)
592 return false;
594 int nCurrentLine = (int)SendEditor(SCI_GETFIRSTVISIBLELINE);
596 int scrolldelta = line - nCurrentLine;
597 SendEditor(SCI_LINESCROLL, 0, scrolldelta);
599 return true;
602 void CTortoiseGitBlameView::CopyToClipboard()
604 CWnd * wnd = GetFocus();
605 if (wnd == this->GetLogList())
606 CopySelectedLogToClipboard();
607 else if (wnd)
609 if (CString(wnd->GetRuntimeClass()->m_lpszClassName) == _T("CMFCPropertyGridCtrl"))
611 CMFCPropertyGridCtrl *grid = (CMFCPropertyGridCtrl *)wnd;
612 if (grid->GetCurSel() && !grid->GetCurSel()->IsGroup())
613 CStringUtils::WriteAsciiStringToClipboard(grid->GetCurSel()->GetValue(), GetSafeHwnd());
615 else
616 m_TextView.Call(SCI_COPY);
620 void CTortoiseGitBlameView::CopySelectedLogToClipboard()
622 this->GetLogList()->CopySelectionToClipBoard(FALSE);
625 void CTortoiseGitBlameView::BlamePreviousRevision()
627 CString procCmd = _T("/path:\"");
628 procCmd += ((CMainFrame*)::AfxGetApp()->GetMainWnd())->GetActiveView()->GetDocument()->GetPathName();
629 procCmd += _T("\" ");
630 procCmd += _T(" /command:blame");
631 procCmd += _T(" /endrev:") + this->GetLogData()->GetGitRevAt(this->GetLogData()->size()-m_ID[m_MouseLine]+1).m_CommitHash.ToString();
633 CCommonAppUtils::RunTortoiseGitProc(procCmd);
636 void CTortoiseGitBlameView::DiffPreviousRevision()
638 CString procCmd = _T("/path:\"");
639 procCmd += ((CMainFrame*)::AfxGetApp()->GetMainWnd())->GetActiveView()->GetDocument()->GetPathName();
640 procCmd += _T("\" ");
641 procCmd += _T(" /command:diff");
642 procCmd += _T(" /startrev:") + this->GetLogData()->GetGitRevAt(this->GetLogData()->size() - m_ID[m_MouseLine]).m_CommitHash.ToString();
643 procCmd += _T(" /endrev:") + this->GetLogData()->GetGitRevAt(this->GetLogData()->size() - m_ID[m_MouseLine] + 1).m_CommitHash.ToString();
645 CCommonAppUtils::RunTortoiseGitProc(procCmd);
648 void CTortoiseGitBlameView::ShowLog()
650 CString procCmd = _T("/path:\"");
651 procCmd += ((CMainFrame*)::AfxGetApp()->GetMainWnd())->GetActiveView()->GetDocument()->GetPathName();
652 procCmd += _T("\" ");
653 procCmd += _T(" /command:log");
654 procCmd += _T(" /rev:") + this->GetLogData()->GetGitRevAt(this->GetLogData()->size() - m_ID[m_MouseLine]).m_CommitHash.ToString();
656 CCommonAppUtils::RunTortoiseGitProc(procCmd);
659 LONG CTortoiseGitBlameView::GetBlameWidth()
661 LONG blamewidth = 0;
662 SIZE width;
663 CreateFont();
664 HDC hDC = this->GetDC()->m_hDC;
665 HFONT oldfont = (HFONT)::SelectObject(hDC, m_font);
667 TCHAR buf[MAX_PATH];
669 CString shortHash('f', g_Git.GetShortHASHLength() + 1);
670 ::GetTextExtentPoint32(hDC, shortHash, g_Git.GetShortHASHLength() + 1, &width);
671 m_revwidth = width.cx + BLAMESPACE;
672 blamewidth += m_revwidth;
674 if (m_bShowDate)
676 _stprintf_s(buf, MAX_PATH, _T("%30s"), _T("31.08.2001 06:24:14"));
677 ::GetTextExtentPoint32(hDC, buf, (int)_tcslen(buf), &width);
678 m_datewidth = width.cx + BLAMESPACE;
679 blamewidth += m_datewidth;
681 if ( m_bShowAuthor)
683 SIZE maxwidth = {0};
685 for (unsigned int i=0;i<this->m_Authors.size();i++)
687 ::GetTextExtentPoint32(hDC,m_Authors[i] , m_Authors[i].GetLength(), &width);
688 if (width.cx > maxwidth.cx)
689 maxwidth = width;
691 m_authorwidth = maxwidth.cx + BLAMESPACE;
692 blamewidth += m_authorwidth;
694 ::SelectObject(hDC, oldfont);
695 POINT pt = {blamewidth, 0};
696 LPtoDP(hDC, &pt, 1);
697 m_blamewidth = pt.x;
698 //::ReleaseDC(wBlame, hDC);
699 return blamewidth;
703 void CTortoiseGitBlameView::CreateFont()
705 if (m_font)
706 return;
707 LOGFONT lf = {0};
708 lf.lfWeight = 400;
709 HDC hDC = ::GetDC(wBlame);
710 lf.lfHeight = -MulDiv((DWORD)CRegStdDWORD(_T("Software\\TortoiseGit\\BlameFontSize"), 10), GetDeviceCaps(hDC, LOGPIXELSY), 72);
711 lf.lfCharSet = DEFAULT_CHARSET;
712 CRegStdString fontname = CRegStdString(_T("Software\\TortoiseGit\\BlameFontName"), _T("Courier New"));
713 _tcscpy_s(lf.lfFaceName, 32, ((stdstring)fontname).c_str());
714 m_font = ::CreateFontIndirect(&lf);
716 lf.lfItalic = TRUE;
717 m_italicfont = ::CreateFontIndirect(&lf);
719 ::ReleaseDC(wBlame, hDC);
722 void CTortoiseGitBlameView::DrawBlame(HDC hDC)
724 if (hDC == NULL)
725 return;
726 if (m_font == NULL)
727 return;
729 HFONT oldfont = NULL;
730 LONG_PTR line = SendEditor(SCI_GETFIRSTVISIBLELINE);
731 LONG_PTR linesonscreen = SendEditor(SCI_LINESONSCREEN);
732 LONG_PTR height = SendEditor(SCI_TEXTHEIGHT);
733 LONG_PTR Y = 0;
734 TCHAR buf[MAX_PATH];
735 RECT rc;
736 BOOL sel = FALSE;
737 //::GetClientRect(this->m_hWnd, &rc);
738 for (LRESULT i=line; i<(line+linesonscreen); ++i)
740 sel = FALSE;
741 if (i < (int)m_CommitHash.size())
743 // if (mergelines[i])
744 // oldfont = (HFONT)::SelectObject(hDC, m_italicfont);
745 // else
746 oldfont = (HFONT)::SelectObject(hDC, m_font);
747 ::SetBkColor(hDC, m_windowcolor);
748 ::SetTextColor(hDC, m_textcolor);
749 if (!m_CommitHash[i].IsEmpty())
751 //if (m_CommitHash[i].Compare(m_MouseHash)==0)
752 // ::SetBkColor(hDC, m_mouseauthorcolor);
753 if (m_CommitHash[i] == m_SelectedHash )
755 ::SetBkColor(hDC, m_selectedauthorcolor);
756 ::SetTextColor(hDC, m_texthighlightcolor);
757 sel = TRUE;
761 if(m_MouseLine == i)
762 ::SetBkColor(hDC, m_mouserevcolor);
764 //if ((revs[i] == m_mouserev)&&(!sel))
765 // ::SetBkColor(hDC, m_mouserevcolor);
766 //if (revs[i] == m_selectedrev)
768 // ::SetBkColor(hDC, m_selectedrevcolor);
769 // ::SetTextColor(hDC, m_texthighlightcolor);
772 CString str;
773 str = m_CommitHash[i].ToString().Left(g_Git.GetShortHASHLength());
775 //_stprintf_s(buf, MAX_PATH, _T("%8ld "), revs[i]);
776 rc.top = (LONG)Y;
777 rc.left=LOCATOR_WIDTH;
778 rc.bottom = (LONG)(Y + height);
779 rc.right = rc.left + m_blamewidth;
780 ::ExtTextOut(hDC, LOCATOR_WIDTH, (int)Y, ETO_CLIPPED, &rc, str, str.GetLength(), 0);
781 int Left = m_revwidth;
783 if (m_bShowAuthor)
785 rc.right = rc.left + Left + m_authorwidth;
786 //_stprintf_s(buf, MAX_PATH, _T("%-30s "), authors[i].c_str());
787 ::ExtTextOut(hDC, Left, (int)Y, ETO_CLIPPED, &rc, m_Authors[i], m_Authors[i].GetLength(), 0);
788 Left += m_authorwidth;
790 #if 0
791 if (ShowDate)
793 rc.right = rc.left + Left + m_datewidth;
794 _stprintf_s(buf, MAX_PATH, _T("%30s "), dates[i].c_str());
795 ::ExtTextOut(hDC, Left, Y, ETO_CLIPPED, &rc, buf, _tcslen(buf), 0);
796 Left += m_datewidth;
799 #endif
800 if ((i==m_SelectedLine)&&(m_pFindDialog))
802 LOGBRUSH brush;
803 brush.lbColor = m_textcolor;
804 brush.lbHatch = 0;
805 brush.lbStyle = BS_SOLID;
806 HPEN pen = ExtCreatePen(PS_SOLID | PS_GEOMETRIC, 2, &brush, 0, NULL);
807 HGDIOBJ hPenOld = SelectObject(hDC, pen);
808 RECT rc2 = rc;
809 rc2.top = (LONG)Y;
810 rc2.bottom = (LONG)(Y + height);
811 ::MoveToEx(hDC, rc2.left, rc2.top, NULL);
812 ::LineTo(hDC, rc2.right, rc2.top);
813 ::LineTo(hDC, rc2.right, rc2.bottom);
814 ::LineTo(hDC, rc2.left, rc2.bottom);
815 ::LineTo(hDC, rc2.left, rc2.top);
816 SelectObject(hDC, hPenOld);
817 DeleteObject(pen);
819 Y += height;
820 ::SelectObject(hDC, oldfont);
822 else
824 ::SetBkColor(hDC, m_windowcolor);
825 for (int j=0; j< MAX_PATH; ++j)
826 buf[j]=' ';
827 ::ExtTextOut(hDC, 0, (int)Y, ETO_CLIPPED, &rc, buf, MAX_PATH-1, 0);
828 Y += height;
833 void CTortoiseGitBlameView::DrawLocatorBar(HDC hDC)
835 if (hDC == NULL)
836 return;
838 LONG_PTR line = SendEditor(SCI_GETFIRSTVISIBLELINE);
839 LONG_PTR linesonscreen = SendEditor(SCI_LINESONSCREEN);
840 LONG_PTR Y = 0;
841 COLORREF blackColor = GetSysColor(COLOR_WINDOWTEXT);
843 RECT rc;
844 //::GetClientRect(wLocator, &rc);
845 this->GetClientRect(&rc);
847 rc.right=LOCATOR_WIDTH;
849 RECT lineRect = rc;
850 LONG height = rc.bottom-rc.top;
851 LONG currentLine = 0;
853 // draw the colored bar
854 for (std::vector<LONG>::const_iterator it = m_ID.begin(); it != m_ID.end(); ++it)
856 currentLine++;
857 // get the line color
858 COLORREF cr = InterColor(DWORD(m_regOldLinesColor), DWORD(m_regNewLinesColor), (*it - m_lowestrev)*100/((m_highestrev-m_lowestrev)+1));
859 if ((currentLine > line)&&(currentLine <= (line + linesonscreen)))
861 cr = InterColor(cr, blackColor, 10);
863 SetBkColor(hDC, cr);
864 lineRect.top = (LONG)Y;
865 lineRect.bottom = (currentLine * height / (LONG)m_ID.size());
866 ::ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &lineRect, NULL, 0, NULL);
867 Y = lineRect.bottom;
870 if (!m_ID.empty())
872 // now draw two lines indicating the scroll position of the source view
873 SetBkColor(hDC, blackColor);
874 lineRect.top = (LONG)line * height / (LONG)m_ID.size();
875 lineRect.bottom = lineRect.top+1;
876 ::ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &lineRect, NULL, 0, NULL);
877 lineRect.top = (LONG)(line + linesonscreen) * height / (LONG)m_ID.size();
878 lineRect.bottom = lineRect.top+1;
879 ::ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &lineRect, NULL, 0, NULL);
884 void CTortoiseGitBlameView::StringExpand(LPSTR str)
886 char * cPos = str;
889 cPos = strchr(cPos, '\n');
890 if (cPos)
892 memmove(cPos+1, cPos, strlen(cPos)*sizeof(char));
893 *cPos = '\r';
894 cPos++;
895 cPos++;
897 } while (cPos != NULL);
899 void CTortoiseGitBlameView::StringExpand(LPWSTR str)
901 wchar_t * cPos = str;
904 cPos = wcschr(cPos, '\n');
905 if (cPos)
907 memmove(cPos+1, cPos, wcslen(cPos)*sizeof(wchar_t));
908 *cPos = '\r';
909 cPos++;
910 cPos++;
912 } while (cPos != NULL);
915 void CTortoiseGitBlameView::SetupLexer(CString filename)
918 TCHAR *line;
919 //const char * lineptr = _tcsrchr(filename, '.');
920 int start=filename.ReverseFind(_T('.'));
921 if (start>0)
923 //_tcscpy_s(line, 20, lineptr+1);
924 //_tcslwr_s(line, 20);
925 CString ext=filename.Right(filename.GetLength()-start-1);
926 line=ext.GetBuffer();
928 if ((_tcscmp(line, _T("py"))==0)||
929 (_tcscmp(line, _T("pyw"))==0))
931 SendEditor(SCI_SETLEXER, SCLEX_PYTHON);
932 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("and assert break class continue def del elif \
933 else except exec finally for from global if import in is lambda None \
934 not or pass print raise return try while yield")).GetBuffer()));
935 SetAStyle(SCE_P_DEFAULT, black);
936 SetAStyle(SCE_P_COMMENTLINE, darkGreen);
937 SetAStyle(SCE_P_NUMBER, RGB(0, 0x80, 0x80));
938 SetAStyle(SCE_P_STRING, RGB(0, 0, 0x80));
939 SetAStyle(SCE_P_CHARACTER, RGB(0, 0, 0x80));
940 SetAStyle(SCE_P_WORD, RGB(0x80, 0, 0x80));
941 SetAStyle(SCE_P_TRIPLE, black);
942 SetAStyle(SCE_P_TRIPLEDOUBLE, black);
943 SetAStyle(SCE_P_CLASSNAME, darkBlue);
944 SetAStyle(SCE_P_DEFNAME, darkBlue);
945 SetAStyle(SCE_P_OPERATOR, darkBlue);
946 SetAStyle(SCE_P_IDENTIFIER, darkBlue);
947 SetAStyle(SCE_P_COMMENTBLOCK, darkGreen);
948 SetAStyle(SCE_P_STRINGEOL, red);
950 if ((_tcscmp(line, _T("c"))==0)||
951 (_tcscmp(line, _T("cc"))==0)||
952 (_tcscmp(line, _T("cpp"))==0)||
953 (_tcscmp(line, _T("cxx"))==0)||
954 (_tcscmp(line, _T("h"))==0)||
955 (_tcscmp(line, _T("hh"))==0)||
956 (_tcscmp(line, _T("hpp"))==0)||
957 (_tcscmp(line, _T("hxx"))==0)||
958 (_tcscmp(line, _T("dlg"))==0)||
959 (_tcscmp(line, _T("mak"))==0))
961 SendEditor(SCI_SETLEXER, SCLEX_CPP);
962 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("and and_eq asm auto bitand bitor bool break \
963 case catch char class compl const const_cast continue \
964 default delete do double dynamic_cast else enum explicit export extern false float for \
965 friend goto if inline int long mutable namespace new not not_eq \
966 operator or or_eq private protected public \
967 register reinterpret_cast return short signed sizeof static static_cast struct switch \
968 template this throw true try typedef typeid typename union unsigned using \
969 virtual void volatile wchar_t while xor xor_eq")).GetBuffer()));
970 SendEditor(SCI_SETKEYWORDS, 3, (LPARAM)(m_TextView.StringForControl(_T("a addindex addtogroup anchor arg attention \
971 author b brief bug c class code date def defgroup deprecated dontinclude \
972 e em endcode endhtmlonly endif endlatexonly endlink endverbatim enum example exception \
973 f$ f[ f] file fn hideinitializer htmlinclude htmlonly \
974 if image include ingroup internal invariant interface latexonly li line link \
975 mainpage name namespace nosubgrouping note overload \
976 p page par param post pre ref relates remarks return retval \
977 sa section see showinitializer since skip skipline struct subsection \
978 test throw todo typedef union until \
979 var verbatim verbinclude version warning weakgroup $ @ \\ & < > # { }")).GetBuffer()));
980 SetupCppLexer();
982 if (_tcscmp(line, _T("cs"))==0)
984 SendEditor(SCI_SETLEXER, SCLEX_CPP);
985 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("abstract as base bool break byte case catch char checked class \
986 const continue decimal default delegate do double else enum \
987 event explicit extern false finally fixed float for foreach goto if \
988 implicit in int interface internal is lock long namespace new null \
989 object operator out override params private protected public \
990 readonly ref return sbyte sealed short sizeof stackalloc static \
991 string struct switch this throw true try typeof uint ulong \
992 unchecked unsafe ushort using virtual void while")).GetBuffer()));
993 SetupCppLexer();
995 if ((_tcscmp(line, _T("rc"))==0)||
996 (_tcscmp(line, _T("rc2"))==0))
998 SendEditor(SCI_SETLEXER, SCLEX_CPP);
999 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("ACCELERATORS ALT AUTO3STATE AUTOCHECKBOX AUTORADIOBUTTON \
1000 BEGIN BITMAP BLOCK BUTTON CAPTION CHARACTERISTICS CHECKBOX CLASS \
1001 COMBOBOX CONTROL CTEXT CURSOR DEFPUSHBUTTON DIALOG DIALOGEX DISCARDABLE \
1002 EDITTEXT END EXSTYLE FONT GROUPBOX ICON LANGUAGE LISTBOX LTEXT \
1003 MENU MENUEX MENUITEM MESSAGETABLE POPUP \
1004 PUSHBUTTON RADIOBUTTON RCDATA RTEXT SCROLLBAR SEPARATOR SHIFT STATE3 \
1005 STRINGTABLE STYLE TEXTINCLUDE VALUE VERSION VERSIONINFO VIRTKEY")).GetBuffer()));
1006 SetupCppLexer();
1008 if ((_tcscmp(line, _T("idl"))==0)||
1009 (_tcscmp(line, _T("odl"))==0))
1011 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1012 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("aggregatable allocate appobject arrays async async_uuid \
1013 auto_handle \
1014 bindable boolean broadcast byte byte_count \
1015 call_as callback char coclass code comm_status \
1016 const context_handle context_handle_noserialize \
1017 context_handle_serialize control cpp_quote custom \
1018 decode default defaultbind defaultcollelem \
1019 defaultvalue defaultvtable dispinterface displaybind dllname \
1020 double dual \
1021 enable_allocate encode endpoint entry enum error_status_t \
1022 explicit_handle \
1023 fault_status first_is float \
1024 handle_t heap helpcontext helpfile helpstring \
1025 helpstringcontext helpstringdll hidden hyper \
1026 id idempotent ignore iid_as iid_is immediatebind implicit_handle \
1027 import importlib in include in_line int __int64 __int3264 interface \
1028 last_is lcid length_is library licensed local long \
1029 max_is maybe message methods midl_pragma \
1030 midl_user_allocate midl_user_free min_is module ms_union \
1031 ncacn_at_dsp ncacn_dnet_nsp ncacn_http ncacn_ip_tcp \
1032 ncacn_nb_ipx ncacn_nb_nb ncacn_nb_tcp ncacn_np \
1033 ncacn_spx ncacn_vns_spp ncadg_ip_udp ncadg_ipx ncadg_mq \
1034 ncalrpc nocode nonbrowsable noncreatable nonextensible notify \
1035 object odl oleautomation optimize optional out out_of_line \
1036 pipe pointer_default pragma properties propget propput propputref \
1037 ptr public \
1038 range readonly ref represent_as requestedit restricted retval \
1039 shape short signed size_is small source strict_context_handle \
1040 string struct switch switch_is switch_type \
1041 transmit_as typedef \
1042 uidefault union unique unsigned user_marshal usesgetlasterror uuid \
1043 v1_enum vararg version void wchar_t wire_marshal")).GetBuffer()));
1044 SetupCppLexer();
1046 if (_tcscmp(line, _T("java"))==0)
1048 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1049 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("abstract assert boolean break byte case catch char class \
1050 const continue default do double else extends final finally float for future \
1051 generic goto if implements import inner instanceof int interface long \
1052 native new null outer package private protected public rest \
1053 return short static super switch synchronized this throw throws \
1054 transient try var void volatile while")).GetBuffer()));
1055 SetupCppLexer();
1057 if (_tcscmp(line, _T("js"))==0)
1059 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1060 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("abstract boolean break byte case catch char class \
1061 const continue debugger default delete do double else enum export extends \
1062 final finally float for function goto if implements import in instanceof \
1063 int interface long native new package private protected public \
1064 return short static super switch synchronized this throw throws \
1065 transient try typeof var void volatile while with")).GetBuffer()));
1066 SetupCppLexer();
1068 if ((_tcscmp(line, _T("pas"))==0)||
1069 (_tcscmp(line, _T("dpr"))==0)||
1070 (_tcscmp(line, _T("pp"))==0))
1072 SendEditor(SCI_SETLEXER, SCLEX_PASCAL);
1073 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("and array as begin case class const constructor \
1074 destructor div do downto else end except file finally \
1075 for function goto if implementation in inherited \
1076 interface is mod not object of on or packed \
1077 procedure program property raise record repeat \
1078 set shl shr then threadvar to try type unit \
1079 until uses var while with xor")).GetBuffer()));
1080 SetupCppLexer();
1082 if ((_tcscmp(line, _T("as"))==0)||
1083 (_tcscmp(line, _T("asc"))==0)||
1084 (_tcscmp(line, _T("jsfl"))==0))
1086 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1087 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("add and break case catch class continue default delete do \
1088 dynamic else eq extends false finally for function ge get gt if implements import in \
1089 instanceof interface intrinsic le lt ne new not null or private public return \
1090 set static super switch this throw true try typeof undefined var void while with")).GetBuffer()));
1091 SendEditor(SCI_SETKEYWORDS, 1, (LPARAM)(m_TextView.StringForControl(_T("Array Arguments Accessibility Boolean Button Camera Color \
1092 ContextMenu ContextMenuItem Date Error Function Key LoadVars LocalConnection Math \
1093 Microphone Mouse MovieClip MovieClipLoader NetConnection NetStream Number Object \
1094 PrintJob Selection SharedObject Sound Stage String StyleSheet System TextField \
1095 TextFormat TextSnapshot Video Void XML XMLNode XMLSocket \
1096 _accProps _focusrect _global _highquality _parent _quality _root _soundbuftime \
1097 arguments asfunction call capabilities chr clearInterval duplicateMovieClip \
1098 escape eval fscommand getProperty getTimer getURL getVersion gotoAndPlay gotoAndStop \
1099 ifFrameLoaded Infinity -Infinity int isFinite isNaN length loadMovie loadMovieNum \
1100 loadVariables loadVariablesNum maxscroll mbchr mblength mbord mbsubstring MMExecute \
1101 NaN newline nextFrame nextScene on onClipEvent onUpdate ord parseFloat parseInt play \
1102 prevFrame prevScene print printAsBitmap printAsBitmapNum printNum random removeMovieClip \
1103 scroll set setInterval setProperty startDrag stop stopAllSounds stopDrag substring \
1104 targetPath tellTarget toggleHighQuality trace unescape unloadMovie unLoadMovieNum updateAfterEvent")).GetBuffer()));
1105 SetupCppLexer();
1107 if ((_tcscmp(line, _T("html"))==0)||
1108 (_tcscmp(line, _T("htm"))==0)||
1109 (_tcscmp(line, _T("shtml"))==0)||
1110 (_tcscmp(line, _T("htt"))==0)||
1111 (_tcscmp(line, _T("xml"))==0)||
1112 (_tcscmp(line, _T("asp"))==0)||
1113 (_tcscmp(line, _T("xsl"))==0)||
1114 (_tcscmp(line, _T("php"))==0)||
1115 (_tcscmp(line, _T("xhtml"))==0)||
1116 (_tcscmp(line, _T("phtml"))==0)||
1117 (_tcscmp(line, _T("cfm"))==0)||
1118 (_tcscmp(line, _T("tpl"))==0)||
1119 (_tcscmp(line, _T("dtd"))==0)||
1120 (_tcscmp(line, _T("hta"))==0)||
1121 (_tcscmp(line, _T("htd"))==0)||
1122 (_tcscmp(line, _T("wxs"))==0))
1124 SendEditor(SCI_SETLEXER, SCLEX_HTML);
1125 SendEditor(SCI_SETSTYLEBITS, 7);
1126 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("a abbr acronym address applet area b base basefont \
1127 bdo big blockquote body br button caption center \
1128 cite code col colgroup dd del dfn dir div dl dt em \
1129 fieldset font form frame frameset h1 h2 h3 h4 h5 h6 \
1130 head hr html i iframe img input ins isindex kbd label \
1131 legend li link map menu meta noframes noscript \
1132 object ol optgroup option p param pre q s samp \
1133 script select small span strike strong style sub sup \
1134 table tbody td textarea tfoot th thead title tr tt u ul \
1135 var xml xmlns abbr accept-charset accept accesskey action align alink \
1136 alt archive axis background bgcolor border \
1137 cellpadding cellspacing char charoff charset checked cite \
1138 class classid clear codebase codetype color cols colspan \
1139 compact content coords \
1140 data datafld dataformatas datapagesize datasrc datetime \
1141 declare defer dir disabled enctype event \
1142 face for frame frameborder \
1143 headers height href hreflang hspace http-equiv \
1144 id ismap label lang language leftmargin link longdesc \
1145 marginwidth marginheight maxlength media method multiple \
1146 name nohref noresize noshade nowrap \
1147 object onblur onchange onclick ondblclick onfocus \
1148 onkeydown onkeypress onkeyup onload onmousedown \
1149 onmousemove onmouseover onmouseout onmouseup \
1150 onreset onselect onsubmit onunload \
1151 profile prompt readonly rel rev rows rowspan rules \
1152 scheme scope selected shape size span src standby start style \
1153 summary tabindex target text title topmargin type usemap \
1154 valign value valuetype version vlink vspace width \
1155 text password checkbox radio submit reset \
1156 file hidden image")).GetBuffer()));
1157 SendEditor(SCI_SETKEYWORDS, 1, (LPARAM)(m_TextView.StringForControl(_T("assign audio block break catch choice clear disconnect else elseif \
1158 emphasis enumerate error exit field filled form goto grammar help \
1159 if initial link log menu meta noinput nomatch object option p paragraph \
1160 param phoneme prompt property prosody record reprompt return s say-as \
1161 script sentence subdialog submit throw transfer value var voice vxml")).GetBuffer()));
1162 SendEditor(SCI_SETKEYWORDS, 2, (LPARAM)(m_TextView.StringForControl(_T("accept age alphabet anchor application base beep bridge category charset \
1163 classid cond connecttimeout content contour count dest destexpr dtmf dtmfterm \
1164 duration enctype event eventexpr expr expritem fetchtimeout finalsilence \
1165 gender http-equiv id level maxage maxstale maxtime message messageexpr \
1166 method mime modal mode name namelist next nextitem ph pitch range rate \
1167 scope size sizeexpr skiplist slot src srcexpr sub time timeexpr timeout \
1168 transferaudio type value variant version volume xml:lang")).GetBuffer()));
1169 SendEditor(SCI_SETKEYWORDS, 3, (LPARAM)(m_TextView.StringForControl(_T("and assert break class continue def del elif \
1170 else except exec finally for from global if import in is lambda None \
1171 not or pass print raise return try while yield")).GetBuffer()));
1172 SendEditor(SCI_SETKEYWORDS, 4, (LPARAM)(m_TextView.StringForControl(_T("and argv as argc break case cfunction class continue declare default do \
1173 die echo else elseif empty enddeclare endfor endforeach endif endswitch \
1174 endwhile e_all e_parse e_error e_warning eval exit extends false for \
1175 foreach function global http_cookie_vars http_get_vars http_post_vars \
1176 http_post_files http_env_vars http_server_vars if include include_once \
1177 list new not null old_function or parent php_os php_self php_version \
1178 print require require_once return static switch stdclass this true var \
1179 xor virtual while __file__ __line__ __sleep __wakeup")).GetBuffer()));
1181 SetAStyle(SCE_H_TAG, darkBlue);
1182 SetAStyle(SCE_H_TAGUNKNOWN, red);
1183 SetAStyle(SCE_H_ATTRIBUTE, darkBlue);
1184 SetAStyle(SCE_H_ATTRIBUTEUNKNOWN, red);
1185 SetAStyle(SCE_H_NUMBER, RGB(0x80,0,0x80));
1186 SetAStyle(SCE_H_DOUBLESTRING, RGB(0,0x80,0));
1187 SetAStyle(SCE_H_SINGLESTRING, RGB(0,0x80,0));
1188 SetAStyle(SCE_H_OTHER, RGB(0x80,0,0x80));
1189 SetAStyle(SCE_H_COMMENT, RGB(0x80,0x80,0));
1190 SetAStyle(SCE_H_ENTITY, RGB(0x80,0,0x80));
1192 SetAStyle(SCE_H_TAGEND, darkBlue);
1193 SetAStyle(SCE_H_XMLSTART, darkBlue); // <?
1194 SetAStyle(SCE_H_QUESTION, darkBlue); // <?
1195 SetAStyle(SCE_H_XMLEND, darkBlue); // ?>
1196 SetAStyle(SCE_H_SCRIPT, darkBlue); // <script
1197 SetAStyle(SCE_H_ASP, RGB(0x4F, 0x4F, 0), RGB(0xFF, 0xFF, 0)); // <% ... %>
1198 SetAStyle(SCE_H_ASPAT, RGB(0x4F, 0x4F, 0), RGB(0xFF, 0xFF, 0)); // <%@ ... %>
1200 SetAStyle(SCE_HB_DEFAULT, black);
1201 SetAStyle(SCE_HB_COMMENTLINE, darkGreen);
1202 SetAStyle(SCE_HB_NUMBER, RGB(0,0x80,0x80));
1203 SetAStyle(SCE_HB_WORD, darkBlue);
1204 SendEditor(SCI_STYLESETBOLD, SCE_HB_WORD, 1);
1205 SetAStyle(SCE_HB_STRING, RGB(0x80,0,0x80));
1206 SetAStyle(SCE_HB_IDENTIFIER, black);
1208 // This light blue is found in the windows system palette so is safe to use even in 256 colour modes.
1209 // Show the whole section of VBScript with light blue background
1210 for (int bstyle=SCE_HB_DEFAULT; bstyle<=SCE_HB_STRINGEOL; bstyle++) {
1211 SendEditor(SCI_STYLESETFONT, bstyle,
1212 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
1213 SendEditor(SCI_STYLESETBACK, bstyle, lightBlue);
1214 // This call extends the backround colour of the last style on the line to the edge of the window
1215 SendEditor(SCI_STYLESETEOLFILLED, bstyle, 1);
1217 SendEditor(SCI_STYLESETBACK, SCE_HB_STRINGEOL, RGB(0x7F,0x7F,0xFF));
1218 SendEditor(SCI_STYLESETFONT, SCE_HB_COMMENTLINE,
1219 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
1221 SetAStyle(SCE_HBA_DEFAULT, black);
1222 SetAStyle(SCE_HBA_COMMENTLINE, darkGreen);
1223 SetAStyle(SCE_HBA_NUMBER, RGB(0,0x80,0x80));
1224 SetAStyle(SCE_HBA_WORD, darkBlue);
1225 SendEditor(SCI_STYLESETBOLD, SCE_HBA_WORD, 1);
1226 SetAStyle(SCE_HBA_STRING, RGB(0x80,0,0x80));
1227 SetAStyle(SCE_HBA_IDENTIFIER, black);
1229 // Show the whole section of ASP VBScript with bright yellow background
1230 for (int bastyle=SCE_HBA_DEFAULT; bastyle<=SCE_HBA_STRINGEOL; bastyle++) {
1231 SendEditor(SCI_STYLESETFONT, bastyle,
1232 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
1233 SendEditor(SCI_STYLESETBACK, bastyle, RGB(0xFF, 0xFF, 0));
1234 // This call extends the backround colour of the last style on the line to the edge of the window
1235 SendEditor(SCI_STYLESETEOLFILLED, bastyle, 1);
1237 SendEditor(SCI_STYLESETBACK, SCE_HBA_STRINGEOL, RGB(0xCF,0xCF,0x7F));
1238 SendEditor(SCI_STYLESETFONT, SCE_HBA_COMMENTLINE,
1239 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
1241 // If there is no need to support embedded Javascript, the following code can be dropped.
1242 // Javascript will still be correctly processed but will be displayed in just the default style.
1244 SetAStyle(SCE_HJ_START, RGB(0x80,0x80,0));
1245 SetAStyle(SCE_HJ_DEFAULT, black);
1246 SetAStyle(SCE_HJ_COMMENT, darkGreen);
1247 SetAStyle(SCE_HJ_COMMENTLINE, darkGreen);
1248 SetAStyle(SCE_HJ_COMMENTDOC, darkGreen);
1249 SetAStyle(SCE_HJ_NUMBER, RGB(0,0x80,0x80));
1250 SetAStyle(SCE_HJ_WORD, black);
1251 SetAStyle(SCE_HJ_KEYWORD, darkBlue);
1252 SetAStyle(SCE_HJ_DOUBLESTRING, RGB(0x80,0,0x80));
1253 SetAStyle(SCE_HJ_SINGLESTRING, RGB(0x80,0,0x80));
1254 SetAStyle(SCE_HJ_SYMBOLS, black);
1256 SetAStyle(SCE_HJA_START, RGB(0x80,0x80,0));
1257 SetAStyle(SCE_HJA_DEFAULT, black);
1258 SetAStyle(SCE_HJA_COMMENT, darkGreen);
1259 SetAStyle(SCE_HJA_COMMENTLINE, darkGreen);
1260 SetAStyle(SCE_HJA_COMMENTDOC, darkGreen);
1261 SetAStyle(SCE_HJA_NUMBER, RGB(0,0x80,0x80));
1262 SetAStyle(SCE_HJA_WORD, black);
1263 SetAStyle(SCE_HJA_KEYWORD, darkBlue);
1264 SetAStyle(SCE_HJA_DOUBLESTRING, RGB(0x80,0,0x80));
1265 SetAStyle(SCE_HJA_SINGLESTRING, RGB(0x80,0,0x80));
1266 SetAStyle(SCE_HJA_SYMBOLS, black);
1268 SetAStyle(SCE_HPHP_DEFAULT, black);
1269 SetAStyle(SCE_HPHP_HSTRING, RGB(0x80,0,0x80));
1270 SetAStyle(SCE_HPHP_SIMPLESTRING, RGB(0x80,0,0x80));
1271 SetAStyle(SCE_HPHP_WORD, darkBlue);
1272 SetAStyle(SCE_HPHP_NUMBER, RGB(0,0x80,0x80));
1273 SetAStyle(SCE_HPHP_VARIABLE, red);
1274 SetAStyle(SCE_HPHP_HSTRING_VARIABLE, red);
1275 SetAStyle(SCE_HPHP_COMPLEX_VARIABLE, red);
1276 SetAStyle(SCE_HPHP_COMMENT, darkGreen);
1277 SetAStyle(SCE_HPHP_COMMENTLINE, darkGreen);
1278 SetAStyle(SCE_HPHP_OPERATOR, darkBlue);
1280 // Show the whole section of Javascript with off white background
1281 for (int jstyle=SCE_HJ_DEFAULT; jstyle<=SCE_HJ_SYMBOLS; jstyle++) {
1282 SendEditor(SCI_STYLESETFONT, jstyle,
1283 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
1284 SendEditor(SCI_STYLESETBACK, jstyle, offWhite);
1285 SendEditor(SCI_STYLESETEOLFILLED, jstyle, 1);
1287 SendEditor(SCI_STYLESETBACK, SCE_HJ_STRINGEOL, RGB(0xDF, 0xDF, 0x7F));
1288 SendEditor(SCI_STYLESETEOLFILLED, SCE_HJ_STRINGEOL, 1);
1290 // Show the whole section of Javascript with brown background
1291 for (int jastyle=SCE_HJA_DEFAULT; jastyle<=SCE_HJA_SYMBOLS; jastyle++) {
1292 SendEditor(SCI_STYLESETFONT, jastyle,
1293 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
1294 SendEditor(SCI_STYLESETBACK, jastyle, RGB(0xDF, 0xDF, 0x7F));
1295 SendEditor(SCI_STYLESETEOLFILLED, jastyle, 1);
1297 SendEditor(SCI_STYLESETBACK, SCE_HJA_STRINGEOL, RGB(0x0,0xAF,0x5F));
1298 SendEditor(SCI_STYLESETEOLFILLED, SCE_HJA_STRINGEOL, 1);
1301 else
1303 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1304 SetupCppLexer();
1306 SendEditor(SCI_COLOURISE, 0, -1);
1310 void CTortoiseGitBlameView::SetupCppLexer()
1312 SetAStyle(SCE_C_DEFAULT, RGB(0, 0, 0));
1313 SetAStyle(SCE_C_COMMENT, RGB(0, 0x80, 0));
1314 SetAStyle(SCE_C_COMMENTLINE, RGB(0, 0x80, 0));
1315 SetAStyle(SCE_C_COMMENTDOC, RGB(0, 0x80, 0));
1316 SetAStyle(SCE_C_COMMENTLINEDOC, RGB(0, 0x80, 0));
1317 SetAStyle(SCE_C_COMMENTDOCKEYWORD, RGB(0, 0x80, 0));
1318 SetAStyle(SCE_C_COMMENTDOCKEYWORDERROR, RGB(0, 0x80, 0));
1319 SetAStyle(SCE_C_NUMBER, RGB(0, 0x80, 0x80));
1320 SetAStyle(SCE_C_WORD, RGB(0, 0, 0x80));
1321 SendEditor(SCE_C_WORD, 1);
1322 SetAStyle(SCE_C_STRING, RGB(0x80, 0, 0x80));
1323 SetAStyle(SCE_C_IDENTIFIER, RGB(0, 0, 0));
1324 SetAStyle(SCE_C_PREPROCESSOR, RGB(0x80, 0, 0));
1325 SetAStyle(SCE_C_OPERATOR, RGB(0x80, 0x80, 0));
1328 int CTortoiseGitBlameView::GetEncode(unsigned char *buff, int size, int *bomoffset)
1330 CFileTextLines textlines;
1331 CFileTextLines::UnicodeType type = textlines.CheckUnicodeType(buff, size);
1333 if(type == CFileTextLines::UTF8BOM)
1335 *bomoffset = 3;
1336 return CP_UTF8;
1338 if(type == CFileTextLines::UTF8)
1339 return CP_UTF8;
1341 if(type == CFileTextLines::UTF16_LE)
1343 *bomoffset = 2;
1344 return 1200;
1347 if(type == CFileTextLines::UTF16_BE)
1349 *bomoffset = 2;
1350 return 1201;
1353 return GetACP();
1356 void CTortoiseGitBlameView::UpdateInfo(int Encode)
1358 BYTE_VECTOR &data = GetDocument()->m_BlameData;
1359 CString one;
1360 int pos=0;
1362 BYTE_VECTOR vector;
1364 this->m_CommitHash.clear();
1365 this->m_Authors.clear();
1366 this->m_ID.clear();
1367 CString line;
1369 CreateFont();
1371 SendEditor(SCI_SETREADONLY, FALSE);
1372 SendEditor(SCI_CLEARALL);
1373 SendEditor(EM_EMPTYUNDOBUFFER);
1374 SendEditor(SCI_SETSAVEPOINT);
1375 SendEditor(SCI_CANCEL);
1376 SendEditor(SCI_SETUNDOCOLLECTION, 0);
1378 SendEditor(SCI_SETCODEPAGE, SC_CP_UTF8);
1380 int current = 0;
1381 int encoding = Encode;
1382 while( pos>=0 && current >=0 && pos<data.size() )
1384 current = data.findData((const BYTE*)"\n",1,pos);
1385 //one=data.Tokenize(_T("\n"),pos);
1387 bool isbound = ( data[pos] == _T('^') );
1389 if( (data.size() - pos) >1 && data[pos] == _T('^'))
1390 pos ++;
1392 if( data[pos] == 0)
1393 continue;
1395 CGitHash hash;
1396 if(isbound)
1398 git_init();
1399 data[pos+39]=0;
1400 if(git_get_sha1((const char*)&data[pos], hash.m_hash))
1402 ::MessageBox(NULL, _T("Can't get hash"), _T("TortoiseGit"), MB_OK|MB_ICONERROR);
1406 else
1407 hash.ConvertFromStrA((char*)&data[pos]);
1410 int start=0;
1411 start=data.findData((const BYTE*)")",1,pos + 40);
1412 if(start>0)
1415 int bomoffset = 0;
1416 CStringA stra;
1417 stra.Empty();
1419 if(current>=0)
1420 data[current] = 0;
1421 else
1422 data.push_back(0);
1424 if( pos <40 && encoding==0)
1426 // first line
1427 encoding = GetEncode(&data[start + 2], (int)(data.size() - start - 2), &bomoffset);
1430 if(encoding == 1201)
1432 CString strw;
1433 DWORD size = ((current - start -2 - bomoffset)/2);
1434 TCHAR *buffer = strw.GetBuffer(size);
1435 memcpy(buffer, &data[start + 2 + bomoffset],sizeof(TCHAR)*size);
1436 // swap the bytes to little-endian order to get proper strings in wchar_t format
1437 wchar_t * pSwapBuf = buffer;
1438 for (DWORD i = 0; i<size; ++i)
1440 *pSwapBuf = WideCharSwap2(*pSwapBuf);
1441 ++pSwapBuf;
1443 strw.ReleaseBuffer();
1445 stra = CUnicodeUtils::GetUTF8(strw);
1447 else if(encoding == 1200)
1449 CString strw;
1450 // the first bomoffset is 2, after that it's 1 (see issue #920)
1451 // also: don't set bomoffset if called from Encodings menu (i.e. start == 42 and bomoffset == 0); bomoffset gets only set if autodetected
1452 if (bomoffset == 0 && start != 42)
1453 bomoffset = 1;
1454 int size = ((current - start -2 - bomoffset)/2);
1455 TCHAR *buffer = strw.GetBuffer(size);
1456 memcpy(buffer, &data[start + 2 + bomoffset],sizeof(TCHAR)*size);
1457 strw.ReleaseBuffer();
1459 stra = CUnicodeUtils::GetUTF8(strw);
1461 else if(encoding == CP_UTF8)
1463 stra = &data[start + 2 + bomoffset ];
1465 else
1467 CString strw;
1468 strw = CUnicodeUtils::GetUnicode(CStringA(&data[start + 2 + bomoffset ]), encoding);
1469 stra = CUnicodeUtils::GetUTF8(strw);
1473 SendEditor(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)stra);
1474 SendEditor(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)"\n\0\0\0");
1476 if(current>=0)
1477 data[current] = '\n';
1481 if(this->m_NoListCommit.find(hash) == m_NoListCommit.end() )
1483 this->m_NoListCommit[hash].GetCommitFromHash(hash);
1485 m_ID.push_back(-1); // m_ID is calculated lazy on demand
1486 m_Authors.push_back(m_NoListCommit[hash].GetAuthorName());
1488 m_CommitHash.push_back(hash);
1489 pos = current+1;
1492 #if 0
1493 if(m_Buffer)
1495 delete m_Buffer;
1496 m_Buffer=NULL;
1499 CFile file;
1500 file.Open(this->GetDocument()->m_TempFileName,CFile::modeRead);
1502 m_Buffer = new char[file.GetLength()+4];
1503 m_Buffer[file.GetLength()] =0;
1504 m_Buffer[file.GetLength()+1] =0;
1505 m_Buffer[file.GetLength()+2] =0;
1506 m_Buffer[file.GetLength()+3] =0;
1508 file.Read(m_Buffer, file.GetLength());
1510 int bomoffset =0;
1511 int encoding = GetEncode( (unsigned char *)m_Buffer, file.GetLength(), &bomoffset);
1513 file.Close();
1514 //SendEditor(SCI_SETCODEPAGE, encoding);
1516 //SendEditor(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)(m_Buffer + bomoffset));
1517 #endif
1518 SetupLexer(GetDocument()->m_CurrentFileName);
1520 SendEditor(SCI_SETUNDOCOLLECTION, 1);
1521 SendEditor(EM_EMPTYUNDOBUFFER);
1522 SendEditor(SCI_SETSAVEPOINT);
1523 SendEditor(SCI_GOTOPOS, 0);
1524 SendEditor(SCI_SETSCROLLWIDTHTRACKING, TRUE);
1525 SendEditor(SCI_SETREADONLY, TRUE);
1527 m_lowestrev=0;
1528 m_highestrev = (long)(this->GetLogData()->size() + m_NoListCommit.size());
1530 GetBlameWidth();
1531 CRect rect;
1532 this->GetClientRect(rect);
1533 //this->m_TextView.GetWindowRect(rect);
1534 //this->m_TextView.ScreenToClient(rect);
1535 rect.left=this->m_blamewidth;
1536 this->m_TextView.MoveWindow(rect);
1538 this->Invalidate();
1541 CGitBlameLogList * CTortoiseGitBlameView::GetLogList()
1543 return &(GetDocument()->GetMainFrame()->m_wndOutput.m_LogList);
1547 CLogDataVector * CTortoiseGitBlameView::GetLogData()
1549 return &(GetDocument()->GetMainFrame()->m_wndOutput.m_LogList.m_logEntries);
1552 void CTortoiseGitBlameView::OnSciPainted(NMHDR *,LRESULT *)
1554 this->Invalidate();
1557 void CTortoiseGitBlameView::OnLButtonDown(UINT nFlags,CPoint point)
1560 LONG line = (LONG)SendEditor(SCI_GETFIRSTVISIBLELINE);
1561 LONG height = (LONG)SendEditor(SCI_TEXTHEIGHT);
1562 line = line + (point.y/height);
1564 if (line < (LONG)m_CommitHash.size())
1566 SetSelectedLine(line);
1567 if (m_CommitHash[line] != m_SelectedHash)
1569 m_SelectedHash = m_CommitHash[line];
1571 // lazy calculate m_ID
1572 if (m_ID[line] == -1)
1574 m_ID[line] = -2; // don't do this lazy calculation again and again for unfindable hashes
1575 for(int i = 0; i<this->GetLogData()->size(); i++)
1577 if(m_SelectedHash == this->GetLogData()->at(i))
1579 m_ID[line] = (LONG)(this->GetLogData()->size() - i);
1580 break;
1585 if(m_ID[line]>=0)
1587 this->GetLogList()->SetItemState(this->GetLogList()->GetItemCount()-m_ID[line],
1588 LVIS_SELECTED,
1589 LVIS_SELECTED);
1590 this->GetLogList()->EnsureVisible(this->GetLogList()->GetItemCount()-m_ID[line], FALSE);
1592 else
1594 this->GetDocument()->GetMainFrame()->m_wndProperties.UpdateProperties(&m_NoListCommit[m_CommitHash[line]]);
1597 else
1599 m_SelectedHash.Empty();
1601 //::InvalidateRect( NULL, FALSE);
1602 this->Invalidate();
1603 this->m_TextView.Invalidate();
1606 else
1608 SetSelectedLine(-1);
1611 CView::OnLButtonDown(nFlags,point);
1614 void CTortoiseGitBlameView::OnSciGetBkColor(NMHDR* hdr, LRESULT* /*result*/)
1617 SCNotification *notification=reinterpret_cast<SCNotification *>(hdr);
1619 if ((m_colorage)&&(notification->line < (int)m_CommitHash.size()))
1621 if(m_CommitHash[notification->line] == this->m_SelectedHash )
1622 notification->lParam = m_selectedauthorcolor;
1623 else
1624 notification->lParam = InterColor(DWORD(m_regOldLinesColor), DWORD(m_regNewLinesColor), (m_ID[notification->line]-m_lowestrev)*100/((m_highestrev-m_lowestrev)+1));
1629 void CTortoiseGitBlameView::FocusOn(GitRev *pRev)
1631 this->GetDocument()->GetMainFrame()->m_wndProperties.UpdateProperties(pRev);
1633 this->Invalidate();
1635 if (m_SelectedHash != pRev->m_CommitHash) {
1636 m_SelectedHash = pRev->m_CommitHash;
1637 for (int i = 0; i < m_CommitHash.size(); ++i)
1639 if (pRev->m_CommitHash == m_CommitHash[i])
1641 GotoLine(i + 1);
1642 m_TextView.Invalidate();
1643 return;
1646 SendEditor(SCI_SETSEL, LONG_MAX, -1);
1650 void CTortoiseGitBlameView::OnMouseHover(UINT /*nFlags*/, CPoint point)
1652 LONG_PTR line = SendEditor(SCI_GETFIRSTVISIBLELINE);
1653 LONG_PTR height = SendEditor(SCI_TEXTHEIGHT);
1654 line = line + (point.y/height);
1656 if (line < (LONG)m_CommitHash.size())
1658 if (line != m_MouseLine)
1660 m_MouseLine = (LONG)line;//m_CommitHash[line];
1661 GitRev *pRev;
1662 if(m_ID[line]<0)
1664 pRev=&this->m_NoListCommit[m_CommitHash[line]];
1667 else
1669 pRev=&this->GetLogData()->GetGitRevAt(this->GetLogList()->GetItemCount()-m_ID[line]);
1672 CString str;
1673 str.Format(_T("%s: %s\n%s: %s <%s>\n%s: %s\n%s:\n%s\n%s"), m_sRev, pRev->m_CommitHash.ToString(),
1674 m_sAuthor, pRev->GetAuthorName(), pRev->GetAuthorEmail(),
1675 m_sDate, CLoglistUtils::FormatDateAndTime(pRev->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
1676 m_sMessage, pRev->GetSubject(),
1677 pRev->GetBody());
1679 m_ToolTip.Pop();
1680 m_ToolTip.AddTool(this, str);
1682 CRect rect;
1683 rect.left=LOCATOR_WIDTH;
1684 rect.right=this->m_blamewidth+rect.left;
1685 rect.top = point.y - (LONG)height;
1686 rect.bottom = point.y + (LONG)height;
1687 this->InvalidateRect(rect);
1692 void CTortoiseGitBlameView::OnMouseMove(UINT /*nFlags*/, CPoint /*point*/)
1694 TRACKMOUSEEVENT tme;
1695 tme.cbSize=sizeof(TRACKMOUSEEVENT);
1696 tme.dwFlags=TME_HOVER|TME_LEAVE;
1697 tme.hwndTrack=this->m_hWnd;
1698 tme.dwHoverTime=1;
1699 TrackMouseEvent(&tme);
1703 BOOL CTortoiseGitBlameView::PreTranslateMessage(MSG* pMsg)
1705 m_ToolTip.RelayEvent(pMsg);
1706 return CView::PreTranslateMessage(pMsg);
1709 void CTortoiseGitBlameView::OnEditFind()
1711 m_pFindDialog=new CFindReplaceDialog();
1713 m_pFindDialog->Create(TRUE, _T(""), NULL, FR_DOWN | FR_HIDEWHOLEWORD | FR_HIDEUPDOWN, this);
1716 void CTortoiseGitBlameView::OnEditGoto()
1718 CEditGotoDlg dlg;
1719 if(dlg.DoModal()==IDOK)
1721 this->GotoLine(dlg.m_LineNumber);
1725 LRESULT CTortoiseGitBlameView::OnFindDialogMessage(WPARAM /*wParam*/, LPARAM /*lParam*/)
1727 ASSERT(m_pFindDialog != NULL);
1729 if (m_CommitHash.empty())
1730 return 0;
1732 // If the FR_DIALOGTERM flag is set,
1733 // invalidate the handle identifying the dialog box.
1734 if (m_pFindDialog->IsTerminating())
1736 m_pFindDialog = NULL;
1737 return 0;
1740 // If the FR_FINDNEXT flag is set,
1741 // call the application-defined search routine
1742 // to search for the requested string.
1743 if(m_pFindDialog->FindNext())
1745 //read data from dialog
1746 CString FindName = m_pFindDialog->GetFindString();
1748 DoSearch(FindName,m_pFindDialog->m_fr.Flags);
1751 return 0;
1754 void CTortoiseGitBlameView::OnViewNext()
1756 FindNextLine(this->m_SelectedHash,false);
1758 void CTortoiseGitBlameView::OnViewPrev()
1760 FindNextLine(this->m_SelectedHash,true);
1763 void CTortoiseGitBlameView::OnViewToggleAuthor()
1765 m_bShowAuthor = ! m_bShowAuthor;
1767 theApp.WriteInt(_T("ShowAuthor"), m_bShowAuthor);
1769 CRect rect;
1770 this->GetClientRect(&rect);
1771 rect.left=GetBlameWidth();
1773 m_TextView.MoveWindow(&rect);
1776 void CTortoiseGitBlameView::OnUpdateViewToggleAuthor(CCmdUI *pCmdUI)
1778 pCmdUI->SetCheck(m_bShowAuthor);
1781 void CTortoiseGitBlameView::OnViewToggleFollowRenames()
1783 m_bFollowRenames = ! m_bFollowRenames;
1785 theApp.WriteInt(_T("FollowRenames"), m_bFollowRenames);
1787 UINT uCheck = MF_BYCOMMAND;
1788 uCheck |= m_bFollowRenames ? MF_CHECKED : MF_UNCHECKED;
1789 CheckMenuItem(GetMenu()->m_hMenu, ID_VIEW_FOLLOWRENAMES, uCheck);
1791 CTortoiseGitBlameDoc *document = (CTortoiseGitBlameDoc *) m_pDocument;
1792 if (!document->m_CurrentFileName.IsEmpty())
1794 theApp.m_pDocManager->OnFileNew();
1795 document->OnOpenDocument(document->m_CurrentFileName, document->m_Rev);
1799 void CTortoiseGitBlameView::OnUpdateViewToggleFollowRenames(CCmdUI *pCmdUI)
1801 pCmdUI->SetCheck(m_bFollowRenames);
1804 void CTortoiseGitBlameView::OnUpdateViewCopyToClipboard(CCmdUI *pCmdUI)
1806 CWnd * wnd = GetFocus();
1807 if (wnd == GetLogList())
1809 pCmdUI->Enable(GetLogList()->GetSelectedCount() > 0);
1811 else if (wnd)
1813 if (CString(wnd->GetRuntimeClass()->m_lpszClassName) == _T("CMFCPropertyGridCtrl"))
1815 CMFCPropertyGridCtrl *grid = (CMFCPropertyGridCtrl *)wnd;
1816 pCmdUI->Enable(grid->GetCurSel() && !grid->GetCurSel()->IsGroup() && !CString(grid->GetCurSel()->GetValue()).IsEmpty());
1818 else
1819 pCmdUI->Enable(m_TextView.Call(SCI_GETSELECTIONSTART) != m_TextView.Call(SCI_GETSELECTIONEND));
1821 else
1822 pCmdUI->Enable(FALSE);
1825 int CTortoiseGitBlameView::FindNextLine(CGitHash CommitHash,bool bUpOrDown)
1827 LONG line = (LONG)SendEditor(SCI_GETFIRSTVISIBLELINE);
1828 LONG startline = line;
1829 bool findNoMatch =false;
1830 while(line>=0 && line<m_CommitHash.size())
1832 if(m_CommitHash[line]!=CommitHash)
1834 findNoMatch=true;
1837 if(m_CommitHash[line] == CommitHash && findNoMatch)
1839 if( line == startline+2 )
1841 findNoMatch=false;
1843 else
1845 if( bUpOrDown )
1847 line=FindFirstLine(CommitHash,line);
1849 SendEditor(SCI_LINESCROLL,0,line-startline-2);
1850 return line;
1853 if(bUpOrDown)
1854 line--;
1855 else
1856 line++;
1858 return -1;