0444ed86d9320c15e4d9dc1e1546d23fa3bfb468
[TortoiseGit.git] / src / TortoiseGitBlame / TortoiseGitBlameView.cpp
blob0444ed86d9320c15e4d9dc1e1546d23fa3bfb468
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"
40 #include "BlameIndexColors.h"
42 #ifdef _DEBUG
43 #define new DEBUG_NEW
44 #endif
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)
85 ON_WM_CREATE()
86 ON_WM_SIZE()
87 ON_WM_MOUSEMOVE()
88 ON_WM_MOUSEHOVER()
89 ON_WM_MOUSELEAVE()
90 ON_WM_LBUTTONDOWN()
91 ON_WM_RBUTTONDOWN()
92 ON_WM_RBUTTONUP()
93 ON_NOTIFY(SCN_PAINTED, IDC_SCINTILLA, OnSciPainted)
94 ON_NOTIFY(SCN_GETBKCOLOR, IDC_SCINTILLA, OnSciGetBkColor)
95 ON_REGISTERED_MESSAGE(m_FindDialogMessage, OnFindDialogMessage)
96 END_MESSAGE_MAP()
99 // CTortoiseGitBlameView construction/destruction
101 CTortoiseGitBlameView::CTortoiseGitBlameView()
103 hInstance = 0;
104 hResource = 0;
105 currentDialog = 0;
106 wMain = 0;
107 m_wEditor = 0;
108 wLocator = 0;
110 m_font = 0;
111 m_italicfont = 0;
112 m_blamewidth = 0;
113 m_revwidth = 0;
114 m_datewidth = 0;
115 m_authorwidth = 0;
116 m_linewidth = 0;
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);
125 m_mouserev = -2;
127 m_selectedrev = -1;
128 m_selectedorigrev = -1;
129 m_SelectedLine = -1;
130 m_directPointer = 0;
131 m_directFunction = 0;
133 m_lowestrev = LONG_MAX;
134 m_highestrev = 0;
135 m_colorage = !!theApp.GetInt(_T("ColorAge"));
137 m_bShowLine=true;
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;
151 else
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);
164 m_Buffer = NULL;
167 CTortoiseGitBlameView::~CTortoiseGitBlameView()
169 if (m_font)
170 DeleteObject(m_font);
171 if (m_italicfont)
172 DeleteObject(m_italicfont);
174 if(m_Buffer)
176 delete m_Buffer;
177 m_Buffer=NULL;
180 struct EncodingUnit
182 int id;
183 char *name;
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)
248 CRect rect,rect1;
249 this->GetWindowRect(&rect1);
250 rect.left=m_blamewidth+LOCATOR_WIDTH;
251 rect.right=rect.Width();
252 rect.top=0;
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;
262 CreateFont();
263 InitialiseEditor();
264 m_ToolTip.Create(this->GetParent());
266 ::AfxGetApp()->GetMainWnd();
267 return CView::OnCreate(lpcs);
271 void CTortoiseGitBlameView::OnSize(UINT /*nType*/, int cx, int cy)
274 CRect rect;
275 rect.left=m_blamewidth;
276 rect.right=cx;
277 rect.top=0;
278 rect.bottom=cy;
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();
293 ASSERT_VALID(pDoc);
294 if (!pDoc)
295 return;
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(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_ID[m_MouseLine] <= 1)
347 pCmdUI->Enable(false);
349 else
351 pCmdUI->Enable(true);
355 void CTortoiseGitBlameView::OnUpdateBlamePopupDiffPrevious(CCmdUI *pCmdUI)
357 if (m_ID[m_MouseLine] <= 1)
359 pCmdUI->Enable(false);
361 else
363 pCmdUI->Enable(true);
367 void CTortoiseGitBlameView::CopyHashToClipboard()
369 this->GetLogList()->CopySelectionToClipBoard(CGitLogListBase::ID_COPY_HASH);
372 // CTortoiseGitBlameView diagnostics
374 #ifdef _DEBUG
375 void CTortoiseGitBlameView::AssertValid() const
377 CView::AssertValid();
380 void CTortoiseGitBlameView::Dump(CDumpContext& dc) const
382 CView::Dump(dc);
385 CTortoiseGitBlameDoc* CTortoiseGitBlameView::GetDocument() const // non-debug version is inline
387 ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTortoiseGitBlameDoc)));
388 return (CTortoiseGitBlameDoc*)m_pDocument;
390 #endif //_DEBUG
393 // CTortoiseGitBlameView message handlers
394 CString CTortoiseGitBlameView::GetAppDirectory()
396 CString path;
397 DWORD len = 0;
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);
410 return path;
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)
420 int r, g, b;
422 // Limit Slider to 0..100% range
423 if (Slider < 0)
424 Slider = 0;
425 if (Slider > 100)
426 Slider = 100;
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;
433 return RGB(r, g, b);
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);
449 if (size >= 1)
450 SendEditor(SCI_STYLESETSIZE, style, size);
451 if (face)
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,
463 black,
464 white,
465 (DWORD)CRegStdDWORD(_T("Software\\TortoiseGit\\BlameFontSize"), 10),
466 &fontName
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());
471 if (m_bShowLine)
472 SendEditor(SCI_SETMARGINWIDTHN, 0, pix);
473 else
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);
501 bool bFound = false;
502 bool bCaseSensitive = !!(flags & FR_MATCHCASE);
503 theApp.WriteInt(_T("FindMatchCase"), bCaseSensitive ? 1 : 0);
504 theApp.WriteString(_T("FindString"), what);
506 if(!bCaseSensitive)
507 what.MakeLower();
509 int i=line;
510 if(i >= (signed int)m_CommitHash.size())
511 i = 0;
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);
519 delete [] linebuf;
520 if (!bCaseSensitive)
522 CString lcAuthor = m_Authors[i];
523 if (lcAuthor.MakeLower().Find(what) >= 0)
524 bFound = true;
525 else if (oneline.MakeLower().Find(what) >=0)
526 bFound = true;
528 else if (m_Authors[i].Find(what) >= 0)
529 bFound = true;
530 else if (oneline.Find(what) >=0)
531 bFound = true;
533 ++i;
534 if(!bFound && i >= (signed int)m_CommitHash.size())
535 i=0;
536 }while(i!=line &&(!bFound));
538 if (bFound)
540 GotoLine(i);
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;
547 else
549 ::MessageBox(wMain, _T("\"") + what + _T("\" ") + CString(MAKEINTRESOURCE(IDS_NOTFOUND)), _T("TortoiseGitBlame"), MB_ICONINFORMATION);
552 return true;
555 bool CTortoiseGitBlameView::GotoLine(long line)
557 --line;
558 if (line < 0)
559 return false;
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)
572 // no need to scroll
573 SendEditor(SCI_GOTOLINE, line);
575 else
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)));
582 else
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);
593 return true;
596 bool CTortoiseGitBlameView::ScrollToLine(long line)
598 if (line < 0)
599 return false;
601 int nCurrentLine = (int)SendEditor(SCI_GETFIRSTVISIBLELINE);
603 int scrolldelta = line - nCurrentLine;
604 SendEditor(SCI_LINESCROLL, 0, scrolldelta);
606 return true;
609 void CTortoiseGitBlameView::CopyToClipboard()
611 CWnd * wnd = GetFocus();
612 if (wnd == this->GetLogList())
613 CopySelectedLogToClipboard();
614 else if (wnd)
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());
622 else
623 m_TextView.Call(SCI_COPY);
627 void CTortoiseGitBlameView::CopySelectedLogToClipboard()
629 this->GetLogList()->CopySelectionToClipBoard(FALSE);
632 void CTortoiseGitBlameView::BlamePreviousRevision()
634 CString procCmd = _T("/path:\"");
635 procCmd += ((CMainFrame*)::AfxGetApp()->GetMainWnd())->GetActiveView()->GetDocument()->GetPathName();
636 procCmd += _T("\" ");
637 procCmd += _T(" /command:blame");
638 procCmd += _T(" /endrev:") + this->GetLogData()->GetGitRevAt(this->GetLogData()->size()-m_ID[m_MouseLine]+1).m_CommitHash.ToString();
640 CCommonAppUtils::RunTortoiseGitProc(procCmd);
643 void CTortoiseGitBlameView::DiffPreviousRevision()
645 CString procCmd = _T("/path:\"");
646 procCmd += ((CMainFrame*)::AfxGetApp()->GetMainWnd())->GetActiveView()->GetDocument()->GetPathName();
647 procCmd += _T("\" ");
648 procCmd += _T(" /command:diff");
649 procCmd += _T(" /startrev:") + this->GetLogData()->GetGitRevAt(this->GetLogData()->size() - m_ID[m_MouseLine]).m_CommitHash.ToString();
650 procCmd += _T(" /endrev:") + this->GetLogData()->GetGitRevAt(this->GetLogData()->size() - m_ID[m_MouseLine] + 1).m_CommitHash.ToString();
652 CCommonAppUtils::RunTortoiseGitProc(procCmd);
655 void CTortoiseGitBlameView::ShowLog()
657 CString procCmd = _T("/path:\"");
658 procCmd += ((CMainFrame*)::AfxGetApp()->GetMainWnd())->GetActiveView()->GetDocument()->GetPathName();
659 procCmd += _T("\" ");
660 procCmd += _T(" /command:log");
661 procCmd += _T(" /rev:") + this->GetLogData()->GetGitRevAt(this->GetLogData()->size() - m_ID[m_MouseLine]).m_CommitHash.ToString();
663 CCommonAppUtils::RunTortoiseGitProc(procCmd);
666 LONG CTortoiseGitBlameView::GetBlameWidth()
668 LONG blamewidth = 0;
669 SIZE width;
670 CreateFont();
671 HDC hDC = this->GetDC()->m_hDC;
672 HFONT oldfont = (HFONT)::SelectObject(hDC, m_font);
674 CString shortHash('f', g_Git.GetShortHASHLength() + 1);
675 ::GetTextExtentPoint32(hDC, shortHash, g_Git.GetShortHASHLength() + 1, &width);
676 m_revwidth = width.cx + BLAMESPACE;
677 blamewidth += m_revwidth;
679 if (m_bShowDate)
681 SIZE maxwidth = {0};
683 for (size_t i = 0; i < this->m_Dates.size(); ++i)
685 ::GetTextExtentPoint32(hDC, m_Dates[i] , m_Dates[i].GetLength(), &width);
686 if (width.cx > maxwidth.cx)
687 maxwidth = width;
689 m_datewidth = maxwidth.cx + BLAMESPACE;
690 blamewidth += m_datewidth;
692 if ( m_bShowAuthor)
694 SIZE maxwidth = {0};
696 for (unsigned int i = 0; i < this->m_Authors.size(); ++i)
698 ::GetTextExtentPoint32(hDC,m_Authors[i] , m_Authors[i].GetLength(), &width);
699 if (width.cx > maxwidth.cx)
700 maxwidth = width;
702 m_authorwidth = maxwidth.cx + BLAMESPACE;
703 blamewidth += m_authorwidth;
705 ::SelectObject(hDC, oldfont);
706 POINT pt = {blamewidth, 0};
707 LPtoDP(hDC, &pt, 1);
708 m_blamewidth = pt.x;
709 //::ReleaseDC(wBlame, hDC);
710 return blamewidth;
714 void CTortoiseGitBlameView::CreateFont()
716 if (m_font)
717 return;
718 LOGFONT lf = {0};
719 lf.lfWeight = 400;
720 HDC hDC = ::GetDC(wBlame);
721 lf.lfHeight = -MulDiv((DWORD)CRegStdDWORD(_T("Software\\TortoiseGit\\BlameFontSize"), 10), GetDeviceCaps(hDC, LOGPIXELSY), 72);
722 lf.lfCharSet = DEFAULT_CHARSET;
723 CRegStdString fontname = CRegStdString(_T("Software\\TortoiseGit\\BlameFontName"), _T("Courier New"));
724 _tcscpy_s(lf.lfFaceName, 32, ((stdstring)fontname).c_str());
725 m_font = ::CreateFontIndirect(&lf);
727 lf.lfItalic = TRUE;
728 m_italicfont = ::CreateFontIndirect(&lf);
730 ::ReleaseDC(wBlame, hDC);
733 void CTortoiseGitBlameView::DrawBlame(HDC hDC)
735 if (hDC == NULL)
736 return;
737 if (m_font == NULL)
738 return;
740 HFONT oldfont = NULL;
741 LONG_PTR line = SendEditor(SCI_GETFIRSTVISIBLELINE);
742 LONG_PTR linesonscreen = SendEditor(SCI_LINESONSCREEN);
743 LONG_PTR height = SendEditor(SCI_TEXTHEIGHT);
744 LONG_PTR Y = 0;
745 TCHAR buf[MAX_PATH];
746 RECT rc;
747 BOOL sel = FALSE;
748 //::GetClientRect(this->m_hWnd, &rc);
749 for (LRESULT i=line; i<(line+linesonscreen); ++i)
751 sel = FALSE;
752 if (i < (int)m_CommitHash.size())
754 // if (mergelines[i])
755 // oldfont = (HFONT)::SelectObject(hDC, m_italicfont);
756 // else
757 oldfont = (HFONT)::SelectObject(hDC, m_font);
758 ::SetBkColor(hDC, m_windowcolor);
759 ::SetTextColor(hDC, m_textcolor);
760 if (!m_CommitHash[i].IsEmpty())
762 //if (m_CommitHash[i].Compare(m_MouseHash)==0)
763 // ::SetBkColor(hDC, m_mouseauthorcolor);
764 if (m_CommitHash[i] == m_SelectedHash )
766 ::SetBkColor(hDC, m_selectedauthorcolor);
767 ::SetTextColor(hDC, m_texthighlightcolor);
768 sel = TRUE;
772 if(m_MouseLine == i)
773 ::SetBkColor(hDC, m_mouserevcolor);
775 //if ((revs[i] == m_mouserev)&&(!sel))
776 // ::SetBkColor(hDC, m_mouserevcolor);
777 //if (revs[i] == m_selectedrev)
779 // ::SetBkColor(hDC, m_selectedrevcolor);
780 // ::SetTextColor(hDC, m_texthighlightcolor);
783 CString str;
784 str = m_CommitHash[i].ToString().Left(g_Git.GetShortHASHLength());
786 //_stprintf_s(buf, MAX_PATH, _T("%8ld "), revs[i]);
787 rc.top = (LONG)Y;
788 rc.left=LOCATOR_WIDTH;
789 rc.bottom = (LONG)(Y + height);
790 rc.right = rc.left + m_blamewidth;
791 ::ExtTextOut(hDC, LOCATOR_WIDTH, (int)Y, ETO_CLIPPED, &rc, str, str.GetLength(), 0);
792 int Left = m_revwidth;
794 if (m_bShowAuthor)
796 rc.right = rc.left + Left + m_authorwidth;
797 ::ExtTextOut(hDC, Left, (int)Y, ETO_CLIPPED, &rc, m_Authors[i], m_Authors[i].GetLength(), 0);
798 Left += m_authorwidth;
800 if (m_bShowDate)
802 rc.right = rc.left + Left + m_datewidth;
803 ::ExtTextOut(hDC, Left, (int)Y, ETO_CLIPPED, &rc, m_Dates[i], m_Dates[i].GetLength(), 0);
804 Left += m_datewidth;
806 if ((i==m_SelectedLine)&&(m_pFindDialog))
808 LOGBRUSH brush;
809 brush.lbColor = m_textcolor;
810 brush.lbHatch = 0;
811 brush.lbStyle = BS_SOLID;
812 HPEN pen = ExtCreatePen(PS_SOLID | PS_GEOMETRIC, 2, &brush, 0, NULL);
813 HGDIOBJ hPenOld = SelectObject(hDC, pen);
814 RECT rc2 = rc;
815 rc2.top = (LONG)Y;
816 rc2.bottom = (LONG)(Y + height);
817 ::MoveToEx(hDC, rc2.left, rc2.top, NULL);
818 ::LineTo(hDC, rc2.right, rc2.top);
819 ::LineTo(hDC, rc2.right, rc2.bottom);
820 ::LineTo(hDC, rc2.left, rc2.bottom);
821 ::LineTo(hDC, rc2.left, rc2.top);
822 SelectObject(hDC, hPenOld);
823 DeleteObject(pen);
825 Y += height;
826 ::SelectObject(hDC, oldfont);
828 else
830 ::SetBkColor(hDC, m_windowcolor);
831 for (int j=0; j< MAX_PATH; ++j)
832 buf[j]=' ';
833 ::ExtTextOut(hDC, 0, (int)Y, ETO_CLIPPED, &rc, buf, MAX_PATH-1, 0);
834 Y += height;
839 void CTortoiseGitBlameView::DrawLocatorBar(HDC hDC)
841 if (hDC == NULL)
842 return;
844 LONG_PTR line = SendEditor(SCI_GETFIRSTVISIBLELINE);
845 LONG_PTR linesonscreen = SendEditor(SCI_LINESONSCREEN);
846 LONG_PTR Y = 0;
847 COLORREF blackColor = GetSysColor(COLOR_WINDOWTEXT);
849 RECT rc;
850 //::GetClientRect(wLocator, &rc);
851 this->GetClientRect(&rc);
853 rc.right=LOCATOR_WIDTH;
855 RECT lineRect = rc;
856 LONG height = rc.bottom-rc.top;
857 LONG currentLine = 0;
859 // draw the colored bar
860 for (std::vector<LONG>::const_iterator it = m_ID.begin(); it != m_ID.end(); ++it)
862 COLORREF cr = GetLineColor(currentLine);
863 ++currentLine;
864 // get the line color
865 if ((currentLine > line)&&(currentLine <= (line + linesonscreen)))
867 cr = InterColor(cr, blackColor, 10);
869 SetBkColor(hDC, cr);
870 lineRect.top = (LONG)Y;
871 lineRect.bottom = (currentLine * height / (LONG)m_ID.size());
872 ::ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &lineRect, NULL, 0, NULL);
873 Y = lineRect.bottom;
876 if (!m_ID.empty())
878 // now draw two lines indicating the scroll position of the source view
879 SetBkColor(hDC, blackColor);
880 lineRect.top = (LONG)line * height / (LONG)m_ID.size();
881 lineRect.bottom = lineRect.top+1;
882 ::ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &lineRect, NULL, 0, NULL);
883 lineRect.top = (LONG)(line + linesonscreen) * height / (LONG)m_ID.size();
884 lineRect.bottom = lineRect.top+1;
885 ::ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &lineRect, NULL, 0, NULL);
890 void CTortoiseGitBlameView::StringExpand(LPSTR str)
892 char * cPos = str;
895 cPos = strchr(cPos, '\n');
896 if (cPos)
898 memmove(cPos+1, cPos, strlen(cPos)*sizeof(char));
899 *cPos = '\r';
900 ++cPos;
901 ++cPos;
903 } while (cPos != NULL);
905 void CTortoiseGitBlameView::StringExpand(LPWSTR str)
907 wchar_t * cPos = str;
910 cPos = wcschr(cPos, '\n');
911 if (cPos)
913 memmove(cPos+1, cPos, wcslen(cPos)*sizeof(wchar_t));
914 *cPos = '\r';
915 ++cPos;
916 ++cPos;
918 } while (cPos != NULL);
921 void CTortoiseGitBlameView::SetupLexer(CString filename)
924 TCHAR *line;
925 //const char * lineptr = _tcsrchr(filename, '.');
926 int start=filename.ReverseFind(_T('.'));
927 if (start>0)
929 //_tcscpy_s(line, 20, lineptr+1);
930 //_tcslwr_s(line, 20);
931 CString ext=filename.Right(filename.GetLength()-start-1);
932 line=ext.GetBuffer();
934 if ((_tcscmp(line, _T("py"))==0)||
935 (_tcscmp(line, _T("pyw"))==0))
937 SendEditor(SCI_SETLEXER, SCLEX_PYTHON);
938 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("and assert break class continue def del elif \
939 else except exec finally for from global if import in is lambda None \
940 not or pass print raise return try while yield")).GetBuffer()));
941 SetAStyle(SCE_P_DEFAULT, black);
942 SetAStyle(SCE_P_COMMENTLINE, darkGreen);
943 SetAStyle(SCE_P_NUMBER, RGB(0, 0x80, 0x80));
944 SetAStyle(SCE_P_STRING, RGB(0, 0, 0x80));
945 SetAStyle(SCE_P_CHARACTER, RGB(0, 0, 0x80));
946 SetAStyle(SCE_P_WORD, RGB(0x80, 0, 0x80));
947 SetAStyle(SCE_P_TRIPLE, black);
948 SetAStyle(SCE_P_TRIPLEDOUBLE, black);
949 SetAStyle(SCE_P_CLASSNAME, darkBlue);
950 SetAStyle(SCE_P_DEFNAME, darkBlue);
951 SetAStyle(SCE_P_OPERATOR, darkBlue);
952 SetAStyle(SCE_P_IDENTIFIER, darkBlue);
953 SetAStyle(SCE_P_COMMENTBLOCK, darkGreen);
954 SetAStyle(SCE_P_STRINGEOL, red);
956 if ((_tcscmp(line, _T("c"))==0)||
957 (_tcscmp(line, _T("cc"))==0)||
958 (_tcscmp(line, _T("cpp"))==0)||
959 (_tcscmp(line, _T("cxx"))==0)||
960 (_tcscmp(line, _T("h"))==0)||
961 (_tcscmp(line, _T("hh"))==0)||
962 (_tcscmp(line, _T("hpp"))==0)||
963 (_tcscmp(line, _T("hxx"))==0)||
964 (_tcscmp(line, _T("dlg"))==0)||
965 (_tcscmp(line, _T("mak"))==0))
967 SendEditor(SCI_SETLEXER, SCLEX_CPP);
968 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("and and_eq asm auto bitand bitor bool break \
969 case catch char class compl const const_cast continue \
970 default delete do double dynamic_cast else enum explicit export extern false float for \
971 friend goto if inline int long mutable namespace new not not_eq \
972 operator or or_eq private protected public \
973 register reinterpret_cast return short signed sizeof static static_cast struct switch \
974 template this throw true try typedef typeid typename union unsigned using \
975 virtual void volatile wchar_t while xor xor_eq")).GetBuffer()));
976 SendEditor(SCI_SETKEYWORDS, 3, (LPARAM)(m_TextView.StringForControl(_T("a addindex addtogroup anchor arg attention \
977 author b brief bug c class code date def defgroup deprecated dontinclude \
978 e em endcode endhtmlonly endif endlatexonly endlink endverbatim enum example exception \
979 f$ f[ f] file fn hideinitializer htmlinclude htmlonly \
980 if image include ingroup internal invariant interface latexonly li line link \
981 mainpage name namespace nosubgrouping note overload \
982 p page par param post pre ref relates remarks return retval \
983 sa section see showinitializer since skip skipline struct subsection \
984 test throw todo typedef union until \
985 var verbatim verbinclude version warning weakgroup $ @ \\ & < > # { }")).GetBuffer()));
986 SetupCppLexer();
988 if (_tcscmp(line, _T("cs"))==0)
990 SendEditor(SCI_SETLEXER, SCLEX_CPP);
991 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("abstract as base bool break byte case catch char checked class \
992 const continue decimal default delegate do double else enum \
993 event explicit extern false finally fixed float for foreach goto if \
994 implicit in int interface internal is lock long namespace new null \
995 object operator out override params private protected public \
996 readonly ref return sbyte sealed short sizeof stackalloc static \
997 string struct switch this throw true try typeof uint ulong \
998 unchecked unsafe ushort using virtual void while")).GetBuffer()));
999 SetupCppLexer();
1001 if ((_tcscmp(line, _T("rc"))==0)||
1002 (_tcscmp(line, _T("rc2"))==0))
1004 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1005 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("ACCELERATORS ALT AUTO3STATE AUTOCHECKBOX AUTORADIOBUTTON \
1006 BEGIN BITMAP BLOCK BUTTON CAPTION CHARACTERISTICS CHECKBOX CLASS \
1007 COMBOBOX CONTROL CTEXT CURSOR DEFPUSHBUTTON DIALOG DIALOGEX DISCARDABLE \
1008 EDITTEXT END EXSTYLE FONT GROUPBOX ICON LANGUAGE LISTBOX LTEXT \
1009 MENU MENUEX MENUITEM MESSAGETABLE POPUP \
1010 PUSHBUTTON RADIOBUTTON RCDATA RTEXT SCROLLBAR SEPARATOR SHIFT STATE3 \
1011 STRINGTABLE STYLE TEXTINCLUDE VALUE VERSION VERSIONINFO VIRTKEY")).GetBuffer()));
1012 SetupCppLexer();
1014 if ((_tcscmp(line, _T("idl"))==0)||
1015 (_tcscmp(line, _T("odl"))==0))
1017 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1018 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("aggregatable allocate appobject arrays async async_uuid \
1019 auto_handle \
1020 bindable boolean broadcast byte byte_count \
1021 call_as callback char coclass code comm_status \
1022 const context_handle context_handle_noserialize \
1023 context_handle_serialize control cpp_quote custom \
1024 decode default defaultbind defaultcollelem \
1025 defaultvalue defaultvtable dispinterface displaybind dllname \
1026 double dual \
1027 enable_allocate encode endpoint entry enum error_status_t \
1028 explicit_handle \
1029 fault_status first_is float \
1030 handle_t heap helpcontext helpfile helpstring \
1031 helpstringcontext helpstringdll hidden hyper \
1032 id idempotent ignore iid_as iid_is immediatebind implicit_handle \
1033 import importlib in include in_line int __int64 __int3264 interface \
1034 last_is lcid length_is library licensed local long \
1035 max_is maybe message methods midl_pragma \
1036 midl_user_allocate midl_user_free min_is module ms_union \
1037 ncacn_at_dsp ncacn_dnet_nsp ncacn_http ncacn_ip_tcp \
1038 ncacn_nb_ipx ncacn_nb_nb ncacn_nb_tcp ncacn_np \
1039 ncacn_spx ncacn_vns_spp ncadg_ip_udp ncadg_ipx ncadg_mq \
1040 ncalrpc nocode nonbrowsable noncreatable nonextensible notify \
1041 object odl oleautomation optimize optional out out_of_line \
1042 pipe pointer_default pragma properties propget propput propputref \
1043 ptr public \
1044 range readonly ref represent_as requestedit restricted retval \
1045 shape short signed size_is small source strict_context_handle \
1046 string struct switch switch_is switch_type \
1047 transmit_as typedef \
1048 uidefault union unique unsigned user_marshal usesgetlasterror uuid \
1049 v1_enum vararg version void wchar_t wire_marshal")).GetBuffer()));
1050 SetupCppLexer();
1052 if (_tcscmp(line, _T("java"))==0)
1054 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1055 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("abstract assert boolean break byte case catch char class \
1056 const continue default do double else extends final finally float for future \
1057 generic goto if implements import inner instanceof int interface long \
1058 native new null outer package private protected public rest \
1059 return short static super switch synchronized this throw throws \
1060 transient try var void volatile while")).GetBuffer()));
1061 SetupCppLexer();
1063 if (_tcscmp(line, _T("js"))==0)
1065 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1066 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("abstract boolean break byte case catch char class \
1067 const continue debugger default delete do double else enum export extends \
1068 final finally float for function goto if implements import in instanceof \
1069 int interface long native new package private protected public \
1070 return short static super switch synchronized this throw throws \
1071 transient try typeof var void volatile while with")).GetBuffer()));
1072 SetupCppLexer();
1074 if ((_tcscmp(line, _T("pas"))==0)||
1075 (_tcscmp(line, _T("dpr"))==0)||
1076 (_tcscmp(line, _T("pp"))==0))
1078 SendEditor(SCI_SETLEXER, SCLEX_PASCAL);
1079 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("and array as begin case class const constructor \
1080 destructor div do downto else end except file finally \
1081 for function goto if implementation in inherited \
1082 interface is mod not object of on or packed \
1083 procedure program property raise record repeat \
1084 set shl shr then threadvar to try type unit \
1085 until uses var while with xor")).GetBuffer()));
1086 SetupCppLexer();
1088 if ((_tcscmp(line, _T("as"))==0)||
1089 (_tcscmp(line, _T("asc"))==0)||
1090 (_tcscmp(line, _T("jsfl"))==0))
1092 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1093 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("add and break case catch class continue default delete do \
1094 dynamic else eq extends false finally for function ge get gt if implements import in \
1095 instanceof interface intrinsic le lt ne new not null or private public return \
1096 set static super switch this throw true try typeof undefined var void while with")).GetBuffer()));
1097 SendEditor(SCI_SETKEYWORDS, 1, (LPARAM)(m_TextView.StringForControl(_T("Array Arguments Accessibility Boolean Button Camera Color \
1098 ContextMenu ContextMenuItem Date Error Function Key LoadVars LocalConnection Math \
1099 Microphone Mouse MovieClip MovieClipLoader NetConnection NetStream Number Object \
1100 PrintJob Selection SharedObject Sound Stage String StyleSheet System TextField \
1101 TextFormat TextSnapshot Video Void XML XMLNode XMLSocket \
1102 _accProps _focusrect _global _highquality _parent _quality _root _soundbuftime \
1103 arguments asfunction call capabilities chr clearInterval duplicateMovieClip \
1104 escape eval fscommand getProperty getTimer getURL getVersion gotoAndPlay gotoAndStop \
1105 ifFrameLoaded Infinity -Infinity int isFinite isNaN length loadMovie loadMovieNum \
1106 loadVariables loadVariablesNum maxscroll mbchr mblength mbord mbsubstring MMExecute \
1107 NaN newline nextFrame nextScene on onClipEvent onUpdate ord parseFloat parseInt play \
1108 prevFrame prevScene print printAsBitmap printAsBitmapNum printNum random removeMovieClip \
1109 scroll set setInterval setProperty startDrag stop stopAllSounds stopDrag substring \
1110 targetPath tellTarget toggleHighQuality trace unescape unloadMovie unLoadMovieNum updateAfterEvent")).GetBuffer()));
1111 SetupCppLexer();
1113 if ((_tcscmp(line, _T("html"))==0)||
1114 (_tcscmp(line, _T("htm"))==0)||
1115 (_tcscmp(line, _T("shtml"))==0)||
1116 (_tcscmp(line, _T("htt"))==0)||
1117 (_tcscmp(line, _T("xml"))==0)||
1118 (_tcscmp(line, _T("asp"))==0)||
1119 (_tcscmp(line, _T("xsl"))==0)||
1120 (_tcscmp(line, _T("php"))==0)||
1121 (_tcscmp(line, _T("xhtml"))==0)||
1122 (_tcscmp(line, _T("phtml"))==0)||
1123 (_tcscmp(line, _T("cfm"))==0)||
1124 (_tcscmp(line, _T("tpl"))==0)||
1125 (_tcscmp(line, _T("dtd"))==0)||
1126 (_tcscmp(line, _T("hta"))==0)||
1127 (_tcscmp(line, _T("htd"))==0)||
1128 (_tcscmp(line, _T("wxs"))==0))
1130 SendEditor(SCI_SETLEXER, SCLEX_HTML);
1131 SendEditor(SCI_SETSTYLEBITS, 7);
1132 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("a abbr acronym address applet area b base basefont \
1133 bdo big blockquote body br button caption center \
1134 cite code col colgroup dd del dfn dir div dl dt em \
1135 fieldset font form frame frameset h1 h2 h3 h4 h5 h6 \
1136 head hr html i iframe img input ins isindex kbd label \
1137 legend li link map menu meta noframes noscript \
1138 object ol optgroup option p param pre q s samp \
1139 script select small span strike strong style sub sup \
1140 table tbody td textarea tfoot th thead title tr tt u ul \
1141 var xml xmlns abbr accept-charset accept accesskey action align alink \
1142 alt archive axis background bgcolor border \
1143 cellpadding cellspacing char charoff charset checked cite \
1144 class classid clear codebase codetype color cols colspan \
1145 compact content coords \
1146 data datafld dataformatas datapagesize datasrc datetime \
1147 declare defer dir disabled enctype event \
1148 face for frame frameborder \
1149 headers height href hreflang hspace http-equiv \
1150 id ismap label lang language leftmargin link longdesc \
1151 marginwidth marginheight maxlength media method multiple \
1152 name nohref noresize noshade nowrap \
1153 object onblur onchange onclick ondblclick onfocus \
1154 onkeydown onkeypress onkeyup onload onmousedown \
1155 onmousemove onmouseover onmouseout onmouseup \
1156 onreset onselect onsubmit onunload \
1157 profile prompt readonly rel rev rows rowspan rules \
1158 scheme scope selected shape size span src standby start style \
1159 summary tabindex target text title topmargin type usemap \
1160 valign value valuetype version vlink vspace width \
1161 text password checkbox radio submit reset \
1162 file hidden image")).GetBuffer()));
1163 SendEditor(SCI_SETKEYWORDS, 1, (LPARAM)(m_TextView.StringForControl(_T("assign audio block break catch choice clear disconnect else elseif \
1164 emphasis enumerate error exit field filled form goto grammar help \
1165 if initial link log menu meta noinput nomatch object option p paragraph \
1166 param phoneme prompt property prosody record reprompt return s say-as \
1167 script sentence subdialog submit throw transfer value var voice vxml")).GetBuffer()));
1168 SendEditor(SCI_SETKEYWORDS, 2, (LPARAM)(m_TextView.StringForControl(_T("accept age alphabet anchor application base beep bridge category charset \
1169 classid cond connecttimeout content contour count dest destexpr dtmf dtmfterm \
1170 duration enctype event eventexpr expr expritem fetchtimeout finalsilence \
1171 gender http-equiv id level maxage maxstale maxtime message messageexpr \
1172 method mime modal mode name namelist next nextitem ph pitch range rate \
1173 scope size sizeexpr skiplist slot src srcexpr sub time timeexpr timeout \
1174 transferaudio type value variant version volume xml:lang")).GetBuffer()));
1175 SendEditor(SCI_SETKEYWORDS, 3, (LPARAM)(m_TextView.StringForControl(_T("and assert break class continue def del elif \
1176 else except exec finally for from global if import in is lambda None \
1177 not or pass print raise return try while yield")).GetBuffer()));
1178 SendEditor(SCI_SETKEYWORDS, 4, (LPARAM)(m_TextView.StringForControl(_T("and argv as argc break case cfunction class continue declare default do \
1179 die echo else elseif empty enddeclare endfor endforeach endif endswitch \
1180 endwhile e_all e_parse e_error e_warning eval exit extends false for \
1181 foreach function global http_cookie_vars http_get_vars http_post_vars \
1182 http_post_files http_env_vars http_server_vars if include include_once \
1183 list new not null old_function or parent php_os php_self php_version \
1184 print require require_once return static switch stdclass this true var \
1185 xor virtual while __file__ __line__ __sleep __wakeup")).GetBuffer()));
1187 SetAStyle(SCE_H_TAG, darkBlue);
1188 SetAStyle(SCE_H_TAGUNKNOWN, red);
1189 SetAStyle(SCE_H_ATTRIBUTE, darkBlue);
1190 SetAStyle(SCE_H_ATTRIBUTEUNKNOWN, red);
1191 SetAStyle(SCE_H_NUMBER, RGB(0x80,0,0x80));
1192 SetAStyle(SCE_H_DOUBLESTRING, RGB(0,0x80,0));
1193 SetAStyle(SCE_H_SINGLESTRING, RGB(0,0x80,0));
1194 SetAStyle(SCE_H_OTHER, RGB(0x80,0,0x80));
1195 SetAStyle(SCE_H_COMMENT, RGB(0x80,0x80,0));
1196 SetAStyle(SCE_H_ENTITY, RGB(0x80,0,0x80));
1198 SetAStyle(SCE_H_TAGEND, darkBlue);
1199 SetAStyle(SCE_H_XMLSTART, darkBlue); // <?
1200 SetAStyle(SCE_H_QUESTION, darkBlue); // <?
1201 SetAStyle(SCE_H_XMLEND, darkBlue); // ?>
1202 SetAStyle(SCE_H_SCRIPT, darkBlue); // <script
1203 SetAStyle(SCE_H_ASP, RGB(0x4F, 0x4F, 0), RGB(0xFF, 0xFF, 0)); // <% ... %>
1204 SetAStyle(SCE_H_ASPAT, RGB(0x4F, 0x4F, 0), RGB(0xFF, 0xFF, 0)); // <%@ ... %>
1206 SetAStyle(SCE_HB_DEFAULT, black);
1207 SetAStyle(SCE_HB_COMMENTLINE, darkGreen);
1208 SetAStyle(SCE_HB_NUMBER, RGB(0,0x80,0x80));
1209 SetAStyle(SCE_HB_WORD, darkBlue);
1210 SendEditor(SCI_STYLESETBOLD, SCE_HB_WORD, 1);
1211 SetAStyle(SCE_HB_STRING, RGB(0x80,0,0x80));
1212 SetAStyle(SCE_HB_IDENTIFIER, black);
1214 // This light blue is found in the windows system palette so is safe to use even in 256 colour modes.
1215 // Show the whole section of VBScript with light blue background
1216 for (int bstyle = SCE_HB_DEFAULT; bstyle <= SCE_HB_STRINGEOL; ++bstyle) {
1217 SendEditor(SCI_STYLESETFONT, bstyle,
1218 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
1219 SendEditor(SCI_STYLESETBACK, bstyle, lightBlue);
1220 // This call extends the backround colour of the last style on the line to the edge of the window
1221 SendEditor(SCI_STYLESETEOLFILLED, bstyle, 1);
1223 SendEditor(SCI_STYLESETBACK, SCE_HB_STRINGEOL, RGB(0x7F,0x7F,0xFF));
1224 SendEditor(SCI_STYLESETFONT, SCE_HB_COMMENTLINE,
1225 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
1227 SetAStyle(SCE_HBA_DEFAULT, black);
1228 SetAStyle(SCE_HBA_COMMENTLINE, darkGreen);
1229 SetAStyle(SCE_HBA_NUMBER, RGB(0,0x80,0x80));
1230 SetAStyle(SCE_HBA_WORD, darkBlue);
1231 SendEditor(SCI_STYLESETBOLD, SCE_HBA_WORD, 1);
1232 SetAStyle(SCE_HBA_STRING, RGB(0x80,0,0x80));
1233 SetAStyle(SCE_HBA_IDENTIFIER, black);
1235 // Show the whole section of ASP VBScript with bright yellow background
1236 for (int bastyle = SCE_HBA_DEFAULT; bastyle <= SCE_HBA_STRINGEOL; ++bastyle) {
1237 SendEditor(SCI_STYLESETFONT, bastyle,
1238 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
1239 SendEditor(SCI_STYLESETBACK, bastyle, RGB(0xFF, 0xFF, 0));
1240 // This call extends the backround colour of the last style on the line to the edge of the window
1241 SendEditor(SCI_STYLESETEOLFILLED, bastyle, 1);
1243 SendEditor(SCI_STYLESETBACK, SCE_HBA_STRINGEOL, RGB(0xCF,0xCF,0x7F));
1244 SendEditor(SCI_STYLESETFONT, SCE_HBA_COMMENTLINE,
1245 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
1247 // If there is no need to support embedded Javascript, the following code can be dropped.
1248 // Javascript will still be correctly processed but will be displayed in just the default style.
1250 SetAStyle(SCE_HJ_START, RGB(0x80,0x80,0));
1251 SetAStyle(SCE_HJ_DEFAULT, black);
1252 SetAStyle(SCE_HJ_COMMENT, darkGreen);
1253 SetAStyle(SCE_HJ_COMMENTLINE, darkGreen);
1254 SetAStyle(SCE_HJ_COMMENTDOC, darkGreen);
1255 SetAStyle(SCE_HJ_NUMBER, RGB(0,0x80,0x80));
1256 SetAStyle(SCE_HJ_WORD, black);
1257 SetAStyle(SCE_HJ_KEYWORD, darkBlue);
1258 SetAStyle(SCE_HJ_DOUBLESTRING, RGB(0x80,0,0x80));
1259 SetAStyle(SCE_HJ_SINGLESTRING, RGB(0x80,0,0x80));
1260 SetAStyle(SCE_HJ_SYMBOLS, black);
1262 SetAStyle(SCE_HJA_START, RGB(0x80,0x80,0));
1263 SetAStyle(SCE_HJA_DEFAULT, black);
1264 SetAStyle(SCE_HJA_COMMENT, darkGreen);
1265 SetAStyle(SCE_HJA_COMMENTLINE, darkGreen);
1266 SetAStyle(SCE_HJA_COMMENTDOC, darkGreen);
1267 SetAStyle(SCE_HJA_NUMBER, RGB(0,0x80,0x80));
1268 SetAStyle(SCE_HJA_WORD, black);
1269 SetAStyle(SCE_HJA_KEYWORD, darkBlue);
1270 SetAStyle(SCE_HJA_DOUBLESTRING, RGB(0x80,0,0x80));
1271 SetAStyle(SCE_HJA_SINGLESTRING, RGB(0x80,0,0x80));
1272 SetAStyle(SCE_HJA_SYMBOLS, black);
1274 SetAStyle(SCE_HPHP_DEFAULT, black);
1275 SetAStyle(SCE_HPHP_HSTRING, RGB(0x80,0,0x80));
1276 SetAStyle(SCE_HPHP_SIMPLESTRING, RGB(0x80,0,0x80));
1277 SetAStyle(SCE_HPHP_WORD, darkBlue);
1278 SetAStyle(SCE_HPHP_NUMBER, RGB(0,0x80,0x80));
1279 SetAStyle(SCE_HPHP_VARIABLE, red);
1280 SetAStyle(SCE_HPHP_HSTRING_VARIABLE, red);
1281 SetAStyle(SCE_HPHP_COMPLEX_VARIABLE, red);
1282 SetAStyle(SCE_HPHP_COMMENT, darkGreen);
1283 SetAStyle(SCE_HPHP_COMMENTLINE, darkGreen);
1284 SetAStyle(SCE_HPHP_OPERATOR, darkBlue);
1286 // Show the whole section of Javascript with off white background
1287 for (int jstyle = SCE_HJ_DEFAULT; jstyle <= SCE_HJ_SYMBOLS; ++jstyle) {
1288 SendEditor(SCI_STYLESETFONT, jstyle,
1289 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
1290 SendEditor(SCI_STYLESETBACK, jstyle, offWhite);
1291 SendEditor(SCI_STYLESETEOLFILLED, jstyle, 1);
1293 SendEditor(SCI_STYLESETBACK, SCE_HJ_STRINGEOL, RGB(0xDF, 0xDF, 0x7F));
1294 SendEditor(SCI_STYLESETEOLFILLED, SCE_HJ_STRINGEOL, 1);
1296 // Show the whole section of Javascript with brown background
1297 for (int jastyle = SCE_HJA_DEFAULT; jastyle <= SCE_HJA_SYMBOLS; ++jastyle) {
1298 SendEditor(SCI_STYLESETFONT, jastyle,
1299 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
1300 SendEditor(SCI_STYLESETBACK, jastyle, RGB(0xDF, 0xDF, 0x7F));
1301 SendEditor(SCI_STYLESETEOLFILLED, jastyle, 1);
1303 SendEditor(SCI_STYLESETBACK, SCE_HJA_STRINGEOL, RGB(0x0,0xAF,0x5F));
1304 SendEditor(SCI_STYLESETEOLFILLED, SCE_HJA_STRINGEOL, 1);
1307 else
1309 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1310 SetupCppLexer();
1312 SendEditor(SCI_COLOURISE, 0, -1);
1316 void CTortoiseGitBlameView::SetupCppLexer()
1318 SetAStyle(SCE_C_DEFAULT, RGB(0, 0, 0));
1319 SetAStyle(SCE_C_COMMENT, RGB(0, 0x80, 0));
1320 SetAStyle(SCE_C_COMMENTLINE, RGB(0, 0x80, 0));
1321 SetAStyle(SCE_C_COMMENTDOC, RGB(0, 0x80, 0));
1322 SetAStyle(SCE_C_COMMENTLINEDOC, RGB(0, 0x80, 0));
1323 SetAStyle(SCE_C_COMMENTDOCKEYWORD, RGB(0, 0x80, 0));
1324 SetAStyle(SCE_C_COMMENTDOCKEYWORDERROR, RGB(0, 0x80, 0));
1325 SetAStyle(SCE_C_NUMBER, RGB(0, 0x80, 0x80));
1326 SetAStyle(SCE_C_WORD, RGB(0, 0, 0x80));
1327 SendEditor(SCE_C_WORD, 1);
1328 SetAStyle(SCE_C_STRING, RGB(0x80, 0, 0x80));
1329 SetAStyle(SCE_C_IDENTIFIER, RGB(0, 0, 0));
1330 SetAStyle(SCE_C_PREPROCESSOR, RGB(0x80, 0, 0));
1331 SetAStyle(SCE_C_OPERATOR, RGB(0x80, 0x80, 0));
1334 int CTortoiseGitBlameView::GetEncode(unsigned char *buff, int size, int *bomoffset)
1336 CFileTextLines textlines;
1337 CFileTextLines::UnicodeType type = textlines.CheckUnicodeType(buff, size);
1339 if(type == CFileTextLines::UTF8BOM)
1341 *bomoffset = 3;
1342 return CP_UTF8;
1344 if(type == CFileTextLines::UTF8)
1345 return CP_UTF8;
1347 if(type == CFileTextLines::UTF16_LE)
1349 *bomoffset = 2;
1350 return 1200;
1353 if(type == CFileTextLines::UTF16_BE)
1355 *bomoffset = 2;
1356 return 1201;
1359 return GetACP();
1362 void CTortoiseGitBlameView::UpdateInfo(int Encode)
1364 BYTE_VECTOR &data = GetDocument()->m_BlameData;
1365 CString one;
1366 int pos=0;
1368 BYTE_VECTOR vector;
1370 this->m_CommitHash.clear();
1371 this->m_Authors.clear();
1372 this->m_Dates.clear();
1373 this->m_ID.clear();
1374 CString line;
1376 CreateFont();
1378 SendEditor(SCI_SETREADONLY, FALSE);
1379 SendEditor(SCI_CLEARALL);
1380 SendEditor(EM_EMPTYUNDOBUFFER);
1381 SendEditor(SCI_SETSAVEPOINT);
1382 SendEditor(SCI_CANCEL);
1383 SendEditor(SCI_SETUNDOCOLLECTION, 0);
1385 SendEditor(SCI_SETCODEPAGE, SC_CP_UTF8);
1387 int current = 0;
1388 int encoding = Encode;
1389 while( pos>=0 && current >=0 && pos<data.size() )
1391 current = data.findData((const BYTE*)"\n",1,pos);
1392 //one=data.Tokenize(_T("\n"),pos);
1394 bool isbound = ( data[pos] == _T('^') );
1396 if( (data.size() - pos) >1 && data[pos] == _T('^'))
1397 ++pos;
1399 if( data[pos] == 0)
1400 continue;
1402 CGitHash hash;
1403 if(isbound)
1405 bool ok = false;
1408 [] { git_init(); } ();
1409 ok = true;
1411 catch (const char* msg)
1413 ::MessageBox(NULL, _T("Could not initialize libgit.\nlibgit reports:\n") + CString(msg), _T("TortoiseGit"), MB_ICONERROR);
1415 data[pos+39]=0;
1416 if (ok)
1420 if (git_get_sha1((const char*)&data[pos], hash.m_hash))
1421 ::MessageBox(NULL, _T("Can't get hash"), _T("TortoiseGit"), MB_OK | MB_ICONERROR);
1423 catch (const char* msg)
1425 ::MessageBox(NULL, _T("Can't get hash.\nlibgit reports:\n") + CString(msg), _T("TortoiseGit"), MB_ICONERROR);
1430 else
1431 hash.ConvertFromStrA((char*)&data[pos]);
1434 int start=0;
1435 start=data.findData((const BYTE*)")",1,pos + 40);
1436 if(start>0)
1439 int bomoffset = 0;
1440 CStringA stra;
1441 stra.Empty();
1443 if(current>=0)
1444 data[current] = 0;
1445 else
1446 data.push_back(0);
1448 if( pos <40 && encoding==0)
1450 // first line
1451 encoding = GetEncode(&data[start + 2], (int)(data.size() - start - 2), &bomoffset);
1454 if(encoding == 1201)
1456 CString strw;
1457 DWORD size = ((current - start -2 - bomoffset)/2);
1458 TCHAR *buffer = strw.GetBuffer(size);
1459 memcpy(buffer, &data[start + 2 + bomoffset],sizeof(TCHAR)*size);
1460 // swap the bytes to little-endian order to get proper strings in wchar_t format
1461 wchar_t * pSwapBuf = buffer;
1462 for (DWORD i = 0; i<size; ++i)
1464 *pSwapBuf = WideCharSwap2(*pSwapBuf);
1465 ++pSwapBuf;
1467 strw.ReleaseBuffer();
1469 stra = CUnicodeUtils::GetUTF8(strw);
1471 else if(encoding == 1200)
1473 CString strw;
1474 // the first bomoffset is 2, after that it's 1 (see issue #920)
1475 // also: don't set bomoffset if called from Encodings menu (i.e. start == 42 and bomoffset == 0); bomoffset gets only set if autodetected
1476 if (bomoffset == 0 && start != 42)
1477 bomoffset = 1;
1478 int size = ((current - start -2 - bomoffset)/2);
1479 TCHAR *buffer = strw.GetBuffer(size);
1480 memcpy(buffer, &data[start + 2 + bomoffset],sizeof(TCHAR)*size);
1481 strw.ReleaseBuffer();
1483 stra = CUnicodeUtils::GetUTF8(strw);
1485 else if(encoding == CP_UTF8)
1487 stra = &data[start + 2 + bomoffset ];
1489 else
1491 CString strw;
1492 strw = CUnicodeUtils::GetUnicode(CStringA(&data[start + 2 + bomoffset ]), encoding);
1493 stra = CUnicodeUtils::GetUTF8(strw);
1497 SendEditor(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)stra);
1498 SendEditor(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)"\n\0\0\0");
1500 if(current>=0)
1501 data[current] = '\n';
1505 if(this->m_NoListCommit.find(hash) == m_NoListCommit.end() )
1507 this->m_NoListCommit[hash].GetCommitFromHash(hash);
1510 bool found = false;
1511 for (size_t i = 0; i < this->GetLogData()->size(); ++i)
1513 if(hash == this->GetLogData()->at(i))
1515 m_ID.push_back((LONG)(this->GetLogData()->size() - i));
1516 found = true;
1517 break;
1520 if (!found)
1521 m_ID.push_back(-2);
1523 m_Authors.push_back(m_NoListCommit[hash].GetAuthorName());
1524 m_Dates.push_back(CLoglistUtils::FormatDateAndTime(m_NoListCommit[hash].GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes));
1526 m_CommitHash.push_back(hash);
1527 pos = current+1;
1530 UINT nID;
1531 UINT nStyle;
1532 int cxWidth;
1533 int nIndex = ((CMainFrame *)::AfxGetApp()->GetMainWnd())->m_wndStatusBar.CommandToIndex(ID_INDICATOR_ENCODING);
1534 ((CMainFrame *)::AfxGetApp()->GetMainWnd())->m_wndStatusBar.GetPaneInfo(nIndex, nID, nStyle, cxWidth);
1535 CString sBarText = L"";
1536 for (int i = 0; i < _countof(encodings); ++i)
1538 if (encodings[i].id == encoding)
1540 sBarText = CString(encodings[i].name);
1541 break;
1544 //calculate the width of the text
1545 CDC * pDC = ((CMainFrame *)::AfxGetApp()->GetMainWnd())->m_wndStatusBar.GetDC();
1546 if (pDC)
1548 CSize size = pDC->GetTextExtent(sBarText);
1549 ((CMainFrame *)::AfxGetApp()->GetMainWnd())->m_wndStatusBar.SetPaneInfo(nIndex, nID, nStyle, size.cx+2);
1550 ReleaseDC(pDC);
1552 ((CMainFrame *)::AfxGetApp()->GetMainWnd())->m_wndStatusBar.SetPaneText(nIndex, sBarText);
1555 #if 0
1556 if(m_Buffer)
1558 delete m_Buffer;
1559 m_Buffer=NULL;
1562 CFile file;
1563 file.Open(this->GetDocument()->m_TempFileName,CFile::modeRead);
1565 m_Buffer = new char[file.GetLength()+4];
1566 m_Buffer[file.GetLength()] =0;
1567 m_Buffer[file.GetLength()+1] =0;
1568 m_Buffer[file.GetLength()+2] =0;
1569 m_Buffer[file.GetLength()+3] =0;
1571 file.Read(m_Buffer, file.GetLength());
1573 int bomoffset =0;
1574 int encoding = GetEncode( (unsigned char *)m_Buffer, file.GetLength(), &bomoffset);
1576 file.Close();
1577 //SendEditor(SCI_SETCODEPAGE, encoding);
1579 //SendEditor(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)(m_Buffer + bomoffset));
1580 #endif
1581 SetupLexer(GetDocument()->m_CurrentFileName);
1583 SendEditor(SCI_SETUNDOCOLLECTION, 1);
1584 SendEditor(EM_EMPTYUNDOBUFFER);
1585 SendEditor(SCI_SETSAVEPOINT);
1586 SendEditor(SCI_GOTOPOS, 0);
1587 SendEditor(SCI_SETSCROLLWIDTHTRACKING, TRUE);
1588 SendEditor(SCI_SETREADONLY, TRUE);
1590 m_lowestrev=0;
1591 m_highestrev = (long)(this->GetLogData()->size());
1593 GetBlameWidth();
1594 CRect rect;
1595 this->GetClientRect(rect);
1596 //this->m_TextView.GetWindowRect(rect);
1597 //this->m_TextView.ScreenToClient(rect);
1598 rect.left=this->m_blamewidth;
1599 this->m_TextView.MoveWindow(rect);
1601 this->Invalidate();
1604 COLORREF CTortoiseGitBlameView::GetLineColor(int line)
1606 if (m_colorage)
1607 return InterColor(DWORD(m_regOldLinesColor), DWORD(m_regNewLinesColor), (m_ID[line] - m_lowestrev) * 100 / ((m_highestrev - m_lowestrev) + 1));
1608 else
1609 return m_windowcolor;
1612 CGitBlameLogList * CTortoiseGitBlameView::GetLogList()
1614 return &(GetDocument()->GetMainFrame()->m_wndOutput.m_LogList);
1618 CLogDataVector * CTortoiseGitBlameView::GetLogData()
1620 return &(GetDocument()->GetMainFrame()->m_wndOutput.m_LogList.m_logEntries);
1623 void CTortoiseGitBlameView::OnSciPainted(NMHDR *,LRESULT *)
1625 this->Invalidate();
1628 void CTortoiseGitBlameView::OnLButtonDown(UINT nFlags,CPoint point)
1631 LONG line = (LONG)SendEditor(SCI_GETFIRSTVISIBLELINE);
1632 LONG height = (LONG)SendEditor(SCI_TEXTHEIGHT);
1633 line = line + (point.y/height);
1635 if (line < (LONG)m_CommitHash.size())
1637 SetSelectedLine(line);
1638 if (m_CommitHash[line] != m_SelectedHash)
1640 m_SelectedHash = m_CommitHash[line];
1642 if(m_ID[line]>=0)
1644 this->GetLogList()->SetItemState(this->GetLogList()->GetItemCount()-m_ID[line],
1645 LVIS_SELECTED,
1646 LVIS_SELECTED);
1647 this->GetLogList()->EnsureVisible(this->GetLogList()->GetItemCount()-m_ID[line], FALSE);
1649 else
1651 this->GetDocument()->GetMainFrame()->m_wndProperties.UpdateProperties(&m_NoListCommit[m_CommitHash[line]]);
1654 else
1656 m_SelectedHash.Empty();
1658 //::InvalidateRect( NULL, FALSE);
1659 this->Invalidate();
1660 this->m_TextView.Invalidate();
1663 else
1665 SetSelectedLine(-1);
1668 CView::OnLButtonDown(nFlags,point);
1671 void CTortoiseGitBlameView::OnSciGetBkColor(NMHDR* hdr, LRESULT* /*result*/)
1673 SCNotification *notification=reinterpret_cast<SCNotification *>(hdr);
1675 if (notification->line < (int)m_CommitHash.size())
1677 if (m_CommitHash[notification->line] == this->m_SelectedHash)
1678 notification->lParam = m_selectedauthorcolor;
1679 else
1680 notification->lParam = GetLineColor(notification->line);
1684 void CTortoiseGitBlameView::FocusOn(GitRev *pRev)
1686 this->GetDocument()->GetMainFrame()->m_wndProperties.UpdateProperties(pRev);
1688 this->Invalidate();
1690 if (m_SelectedHash != pRev->m_CommitHash) {
1691 m_SelectedHash = pRev->m_CommitHash;
1692 for (size_t i = 0; i < m_CommitHash.size(); ++i)
1694 if (pRev->m_CommitHash == m_CommitHash[i])
1696 GotoLine((long)(i + 1));
1697 m_TextView.Invalidate();
1698 return;
1701 SendEditor(SCI_SETSEL, LONG_MAX, -1);
1705 void CTortoiseGitBlameView::OnMouseHover(UINT /*nFlags*/, CPoint point)
1707 LONG_PTR line = SendEditor(SCI_GETFIRSTVISIBLELINE);
1708 LONG_PTR height = SendEditor(SCI_TEXTHEIGHT);
1709 line = line + (point.y/height);
1711 if (line < (LONG)m_CommitHash.size())
1713 if (line != m_MouseLine)
1715 m_MouseLine = (LONG)line;//m_CommitHash[line];
1716 GitRev *pRev;
1717 if(m_ID[line]<0)
1719 pRev=&this->m_NoListCommit[m_CommitHash[line]];
1722 else
1724 pRev=&this->GetLogData()->GetGitRevAt(this->GetLogList()->GetItemCount()-m_ID[line]);
1727 CString body = pRev->GetBody();
1728 int maxLine = 15;
1729 int line = 0;
1730 int pos = 0;
1731 while (line++ < maxLine)
1733 int pos2 = body.Find(_T("\n"), pos);
1734 if (pos2 < 0)
1735 break;
1736 int lineLength = pos2 - pos - 1;
1737 pos = pos2 + 1;
1738 line += lineLength / 70;
1741 CString str;
1742 str.Format(_T("%s: %s\n%s: %s <%s>\n%s: %s\n%s:\n%s\n%s"), m_sRev, pRev->m_CommitHash.ToString(),
1743 m_sAuthor, pRev->GetAuthorName(), pRev->GetAuthorEmail(),
1744 m_sDate, CLoglistUtils::FormatDateAndTime(pRev->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
1745 m_sMessage, pRev->GetSubject(),
1746 line <= maxLine ? body : (body.Left(pos) + _T("\n....................")));
1748 m_ToolTip.Pop();
1749 m_ToolTip.AddTool(this, str);
1751 CRect rect;
1752 rect.left=LOCATOR_WIDTH;
1753 rect.right=this->m_blamewidth+rect.left;
1754 rect.top = point.y - (LONG)height;
1755 rect.bottom = point.y + (LONG)height;
1756 this->InvalidateRect(rect);
1761 void CTortoiseGitBlameView::OnMouseMove(UINT /*nFlags*/, CPoint /*point*/)
1763 TRACKMOUSEEVENT tme;
1764 tme.cbSize=sizeof(TRACKMOUSEEVENT);
1765 tme.dwFlags=TME_HOVER|TME_LEAVE;
1766 tme.hwndTrack=this->m_hWnd;
1767 tme.dwHoverTime=1;
1768 TrackMouseEvent(&tme);
1772 BOOL CTortoiseGitBlameView::PreTranslateMessage(MSG* pMsg)
1774 m_ToolTip.RelayEvent(pMsg);
1775 return CView::PreTranslateMessage(pMsg);
1778 void CTortoiseGitBlameView::OnEditFind()
1780 m_pFindDialog=new CFindReplaceDialog();
1782 CString oneline = theApp.GetString(_T("FindString"));
1783 if (m_TextView.Call(SCI_GETSELECTIONSTART) != m_TextView.Call(SCI_GETSELECTIONEND))
1785 LRESULT bufsize = m_TextView.Call(SCI_GETSELECTIONEND) - m_TextView.Call(SCI_GETSELECTIONSTART);
1786 char * linebuf = new char[bufsize + 1];
1787 SecureZeroMemory(linebuf, bufsize + 1);
1788 SendEditor(SCI_GETSELTEXT, 0, (LPARAM)linebuf);
1789 oneline = m_TextView.StringFromControl(linebuf);
1790 delete [] linebuf;
1793 DWORD flags = FR_DOWN | FR_HIDEWHOLEWORD | FR_HIDEUPDOWN;
1794 if (theApp.GetInt(_T("FindMatchCase")))
1795 flags |= FR_MATCHCASE;
1797 m_pFindDialog->Create(TRUE, oneline, NULL, flags, this);
1800 void CTortoiseGitBlameView::OnEditGoto()
1802 CEditGotoDlg dlg;
1803 if(dlg.DoModal()==IDOK)
1805 this->GotoLine(dlg.m_LineNumber);
1809 LRESULT CTortoiseGitBlameView::OnFindDialogMessage(WPARAM /*wParam*/, LPARAM /*lParam*/)
1811 ASSERT(m_pFindDialog != NULL);
1813 if (m_CommitHash.empty())
1814 return 0;
1816 // If the FR_DIALOGTERM flag is set,
1817 // invalidate the handle identifying the dialog box.
1818 if (m_pFindDialog->IsTerminating())
1820 m_pFindDialog = NULL;
1821 return 0;
1824 // If the FR_FINDNEXT flag is set,
1825 // call the application-defined search routine
1826 // to search for the requested string.
1827 if(m_pFindDialog->FindNext())
1829 //read data from dialog
1830 CString FindName = m_pFindDialog->GetFindString();
1832 DoSearch(FindName,m_pFindDialog->m_fr.Flags);
1835 return 0;
1838 void CTortoiseGitBlameView::OnViewNext()
1840 FindNextLine(this->m_SelectedHash,false);
1842 void CTortoiseGitBlameView::OnViewPrev()
1844 FindNextLine(this->m_SelectedHash,true);
1847 void CTortoiseGitBlameView::OnViewToggleAuthor()
1849 m_bShowAuthor = ! m_bShowAuthor;
1851 theApp.WriteInt(_T("ShowAuthor"), m_bShowAuthor);
1853 CRect rect;
1854 this->GetClientRect(&rect);
1855 rect.left=GetBlameWidth();
1857 m_TextView.MoveWindow(&rect);
1860 void CTortoiseGitBlameView::OnUpdateViewToggleAuthor(CCmdUI *pCmdUI)
1862 pCmdUI->SetCheck(m_bShowAuthor);
1865 void CTortoiseGitBlameView::OnViewToggleDate()
1867 m_bShowDate = ! m_bShowDate;
1869 theApp.WriteInt(_T("ShowDate"), m_bShowDate);
1871 CRect rect;
1872 this->GetClientRect(&rect);
1873 rect.left=GetBlameWidth();
1875 m_TextView.MoveWindow(&rect);
1878 void CTortoiseGitBlameView::OnUpdateViewToggleDate(CCmdUI *pCmdUI)
1880 pCmdUI->SetCheck(m_bShowDate);
1883 void CTortoiseGitBlameView::OnViewToggleFollowRenames()
1885 m_bFollowRenames = ! m_bFollowRenames;
1887 theApp.WriteInt(_T("FollowRenames"), m_bFollowRenames);
1889 CTortoiseGitBlameDoc *document = (CTortoiseGitBlameDoc *) m_pDocument;
1890 if (!document->m_CurrentFileName.IsEmpty())
1892 document->m_lLine = (LONG)SendEditor(SCI_GETFIRSTVISIBLELINE) + 1;
1893 theApp.m_pDocManager->OnFileNew();
1894 document->OnOpenDocument(document->m_CurrentFileName, document->m_Rev);
1898 void CTortoiseGitBlameView::OnUpdateViewToggleFollowRenames(CCmdUI *pCmdUI)
1900 pCmdUI->SetCheck(m_bFollowRenames);
1903 void CTortoiseGitBlameView::OnViewToggleColorByAge()
1905 m_colorage = ! m_colorage;
1907 theApp.WriteInt(_T("ColorAge"), m_colorage);
1909 m_TextView.Invalidate();
1912 void CTortoiseGitBlameView::OnUpdateViewToggleColorByAge(CCmdUI *pCmdUI)
1914 pCmdUI->SetCheck(m_colorage);
1917 void CTortoiseGitBlameView::OnUpdateViewCopyToClipboard(CCmdUI *pCmdUI)
1919 CWnd * wnd = GetFocus();
1920 if (wnd == GetLogList())
1922 pCmdUI->Enable(GetLogList()->GetSelectedCount() > 0);
1924 else if (wnd)
1926 if (CString(wnd->GetRuntimeClass()->m_lpszClassName) == _T("CMFCPropertyGridCtrl"))
1928 CMFCPropertyGridCtrl *grid = (CMFCPropertyGridCtrl *)wnd;
1929 pCmdUI->Enable(grid->GetCurSel() && !grid->GetCurSel()->IsGroup() && !CString(grid->GetCurSel()->GetValue()).IsEmpty());
1931 else
1932 pCmdUI->Enable(m_TextView.Call(SCI_GETSELECTIONSTART) != m_TextView.Call(SCI_GETSELECTIONEND));
1934 else
1935 pCmdUI->Enable(FALSE);
1938 int CTortoiseGitBlameView::FindNextLine(CGitHash CommitHash,bool bUpOrDown)
1940 LONG line = (LONG)SendEditor(SCI_GETFIRSTVISIBLELINE);
1941 LONG startline = line;
1942 bool findNoMatch =false;
1943 while(line>=0 && line<m_CommitHash.size())
1945 if(m_CommitHash[line]!=CommitHash)
1947 findNoMatch=true;
1950 if(m_CommitHash[line] == CommitHash && findNoMatch)
1952 if( line == startline+2 )
1954 findNoMatch=false;
1956 else
1958 if( bUpOrDown )
1960 line=FindFirstLine(CommitHash,line);
1962 SendEditor(SCI_LINESCROLL,0,line-startline-2);
1963 return line;
1966 if(bUpOrDown)
1967 --line;
1968 else
1969 ++line;
1971 return -1;