TortoiseGitBlame: Fixed width of the SHA-1 column
[TortoiseGit.git] / src / TortoiseGitBlame / TortoiseGitBlameView.cpp
blobb6348f5e2db1b2824dff8380ae7780776f894098
1 // TortoiseGitBlame - a Viewer for Git Blames
3 // Copyright (C) 2008-2012 - TortoiseGit
4 // Copyright (C) 2010-2012 Sven Strickroth <email@cs-ware.de>
5 // Copyright (C) 2003-2008 - TortoiseSVN
7 // Copyright (C)2003 Don HO <donho@altern.org>
9 // This program is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU General Public License
11 // as published by the Free Software Foundation; either version 2
12 // of the License, or (at your option) any later version.
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
19 // You should have received a copy of the GNU General Public License
20 // along with this program; if not, write to the Free Software Foundation,
21 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 // CTortoiseGitBlameView.cpp : implementation of the CTortoiseGitBlameView class
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"
40 #ifdef _DEBUG
41 #define new DEBUG_NEW
42 #endif
44 wchar_t WideCharSwap2(wchar_t nValue)
46 return (((nValue>> 8)) | (nValue << 8));
49 UINT CTortoiseGitBlameView::m_FindDialogMessage;
51 // CTortoiseGitBlameView
52 IMPLEMENT_DYNAMIC(CSciEditBlame,CSciEdit)
54 IMPLEMENT_DYNCREATE(CTortoiseGitBlameView, CView)
56 BEGIN_MESSAGE_MAP(CTortoiseGitBlameView, CView)
57 // Standard printing commands
58 ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)
59 ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
60 ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CTortoiseGitBlameView::OnFilePrintPreview)
61 ON_COMMAND(ID_EDIT_FIND,OnEditFind)
62 ON_COMMAND(ID_EDIT_GOTO,OnEditGoto)
63 ON_COMMAND(ID_EDIT_COPY,CopySelectedLogToClipboard)
64 ON_COMMAND(ID_VIEW_NEXT,OnViewNext)
65 ON_COMMAND(ID_VIEW_PREV,OnViewPrev)
66 ON_COMMAND(ID_VIEW_SHOWAUTHOR, OnViewToggleAuthor)
67 ON_UPDATE_COMMAND_UI(ID_VIEW_SHOWAUTHOR, OnUpdateViewToggleAuthor)
68 ON_COMMAND(ID_VIEW_FOLLOWRENAMES, OnViewToggleFollowRenames)
69 ON_UPDATE_COMMAND_UI(ID_VIEW_FOLLOWRENAMES, OnUpdateViewToggleFollowRenames)
70 ON_COMMAND(ID_BLAMEPOPUP_COPYHASHTOCLIPBOARD, CopyHashToClipboard)
71 ON_COMMAND(ID_BLAMEPOPUP_COPYLOGTOCLIPBOARD, CopySelectedLogToClipboard)
72 ON_COMMAND(ID_BLAMEPOPUP_BLAMEPREVIOUSREVISION, BlamePreviousRevision)
73 ON_COMMAND(ID_BLAMEPOPUP_DIFFPREVIOUS, DiffPreviousRevision)
74 ON_COMMAND(ID_BLAMEPOPUP_SHOWLOG, ShowLog)
75 ON_UPDATE_COMMAND_UI(ID_BLAMEPOPUP_BLAMEPREVIOUSREVISION, OnUpdateBlamePopupBlamePrevious)
76 ON_UPDATE_COMMAND_UI(ID_BLAMEPOPUP_DIFFPREVIOUS, OnUpdateBlamePopupDiffPrevious)
77 ON_COMMAND_RANGE(IDM_FORMAT_ENCODE, IDM_FORMAT_ENCODE_END, OnChangeEncode)
78 ON_WM_CREATE()
79 ON_WM_SIZE()
80 ON_WM_MOUSEMOVE()
81 ON_WM_MOUSEHOVER()
82 ON_WM_MOUSELEAVE()
83 ON_WM_LBUTTONDOWN()
84 ON_WM_RBUTTONDOWN()
85 ON_WM_RBUTTONUP()
86 ON_NOTIFY(SCN_PAINTED,0,OnSciPainted)
87 ON_NOTIFY(SCN_GETBKCOLOR,0,OnSciGetBkColor)
88 ON_REGISTERED_MESSAGE(m_FindDialogMessage, OnFindDialogMessage)
89 END_MESSAGE_MAP()
92 // CTortoiseGitBlameView construction/destruction
94 CTortoiseGitBlameView::CTortoiseGitBlameView()
96 hInstance = 0;
97 hResource = 0;
98 currentDialog = 0;
99 wMain = 0;
100 m_wEditor = 0;
101 wLocator = 0;
103 m_font = 0;
104 m_italicfont = 0;
105 m_blamewidth = 0;
106 m_revwidth = 0;
107 m_datewidth = 0;
108 m_authorwidth = 0;
109 m_linewidth = 0;
111 m_windowcolor = ::GetSysColor(COLOR_WINDOW);
112 m_textcolor = ::GetSysColor(COLOR_WINDOWTEXT);
113 m_texthighlightcolor = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
114 m_mouserevcolor = InterColor(m_windowcolor, m_textcolor, 20);
115 m_mouseauthorcolor = InterColor(m_windowcolor, m_textcolor, 10);
116 m_selectedrevcolor = ::GetSysColor(COLOR_HIGHLIGHT);
117 m_selectedauthorcolor = InterColor(m_selectedrevcolor, m_texthighlightcolor, 35);
118 m_mouserev = -2;
120 m_selectedrev = -1;
121 m_selectedorigrev = -1;
122 m_SelectedLine = -1;
123 m_directPointer = 0;
124 m_directFunction = 0;
126 m_lowestrev = LONG_MAX;
127 m_highestrev = 0;
128 m_colorage = true;
130 m_bShowLine=true;
132 m_bShowAuthor = (theApp.GetInt(_T("ShowAuthor"), 1) == 1);
133 m_bShowDate=false;
134 m_bFollowRenames = (theApp.GetInt(_T("FollowRenames"), 0) == 1);
136 m_FindDialogMessage = ::RegisterWindowMessage(FINDMSGSTRING);
137 m_pFindDialog = NULL;
138 // get short/long datetime setting from registry
139 DWORD RegUseShortDateFormat = CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE);
140 if ( RegUseShortDateFormat )
142 m_DateFormat = DATE_SHORTDATE;
144 else
146 m_DateFormat = DATE_LONGDATE;
148 // get relative time display setting from registry
149 DWORD regRelativeTimes = CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE);
150 m_bRelativeTimes = (regRelativeTimes != 0);
152 m_sRev.LoadString(IDS_LOG_REVISION);
153 m_sAuthor.LoadString(IDS_LOG_AUTHOR);
154 m_sDate.LoadString(IDS_LOG_DATE);
155 m_sMessage.LoadString(IDS_LOG_MESSAGE);
157 m_Buffer = NULL;
160 CTortoiseGitBlameView::~CTortoiseGitBlameView()
162 if (m_font)
163 DeleteObject(m_font);
164 if (m_italicfont)
165 DeleteObject(m_italicfont);
167 if(m_Buffer)
169 delete m_Buffer;
170 m_Buffer=NULL;
173 struct EncodingUnit
175 int id;
176 char *name;
179 void CTortoiseGitBlameView::OnChangeEncode(UINT nId)
182 static EncodingUnit encodings[] = {
183 {1250, "windows-1250"}, //IDM_FORMAT_WIN_1250
184 {1251, "windows-1251"}, //IDM_FORMAT_WIN_1251
185 {1252, "windows-1252"}, //IDM_FORMAT_WIN_1252
186 {1253, "windows-1253"}, //IDM_FORMAT_WIN_1253
187 {1254, "windows-1254"}, //IDM_FORMAT_WIN_1254
188 {1255, "windows-1255"}, //IDM_FORMAT_WIN_1255
189 {1256, "windows-1256"}, //IDM_FORMAT_WIN_1256
190 {1257, "windows-1257"}, //IDM_FORMAT_WIN_1257
191 {1258, "windows-1258"}, //IDM_FORMAT_WIN_1258
192 {28591, "latin1 ISO_8859-1 ISO-8859-1 CP819 IBM819 csISOLatin1 iso-ir-100 l1"}, //IDM_FORMAT_ISO_8859_1
193 {28592, "latin2 ISO_8859-2 ISO-8859-2 csISOLatin2 iso-ir-101 l2"}, //IDM_FORMAT_ISO_8859_2
194 {28593, "latin3 ISO_8859-3 ISO-8859-3 csISOLatin3 iso-ir-109 l3"}, //IDM_FORMAT_ISO_8859_3
195 {28594, "latin4 ISO_8859-4 ISO-8859-4 csISOLatin4 iso-ir-110 l4"}, //IDM_FORMAT_ISO_8859_4
196 {28595, "cyrillic ISO_8859-5 ISO-8859-5 csISOLatinCyrillic iso-ir-144"}, //IDM_FORMAT_ISO_8859_5
197 {28596, "arabic ISO_8859-6 ISO-8859-6 csISOLatinArabic iso-ir-127 ASMO-708 ECMA-114"}, //IDM_FORMAT_ISO_8859_6
198 {28597, "greek ISO_8859-7 ISO-8859-7 csISOLatinGreek greek8 iso-ir-126 ELOT_928 ECMA-118"}, //IDM_FORMAT_ISO_8859_7
199 {28598, "hebrew ISO_8859-8 ISO-8859-8 csISOLatinHebrew iso-ir-138"}, //IDM_FORMAT_ISO_8859_8
200 {28599, "latin5 ISO_8859-9 ISO-8859-9 csISOLatin5 iso-ir-148 l5"}, //IDM_FORMAT_ISO_8859_9
201 {28600, "latin6 ISO_8859-10 ISO-8859-10 csISOLatin6 iso-ir-157 l6"}, //IDM_FORMAT_ISO_8859_10
202 {28601, "ISO_8859-11 ISO-8859-11"}, //IDM_FORMAT_ISO_8859_11
203 {28603, "ISO_8859-13 ISO-8859-13"}, //IDM_FORMAT_ISO_8859_13
204 {28604, "iso-celtic latin8 ISO_8859-14 ISO-8859-14 18 iso-ir-199"}, //IDM_FORMAT_ISO_8859_14
205 {28605, "Latin-9 ISO_8859-15 ISO-8859-15"}, //IDM_FORMAT_ISO_8859_15
206 {28606, "latin10 ISO_8859-16 ISO-8859-16 110 iso-ir-226"}, //IDM_FORMAT_ISO_8859_16
207 {437, "IBM437 cp437 437 csPC8CodePage437"}, //IDM_FORMAT_DOS_437
208 {720, "IBM720 cp720 oem720 720"}, //IDM_FORMAT_DOS_720
209 {737, "IBM737 cp737 oem737 737"}, //IDM_FORMAT_DOS_737
210 {775, "IBM775 cp775 oem775 775"}, //IDM_FORMAT_DOS_775
211 {850, "IBM850 cp850 oem850 850"}, //IDM_FORMAT_DOS_850
212 {852, "IBM852 cp852 oem852 852"}, //IDM_FORMAT_DOS_852
213 {855, "IBM855 cp855 oem855 855 csIBM855"}, //IDM_FORMAT_DOS_855
214 {857, "IBM857 cp857 oem857 857"}, //IDM_FORMAT_DOS_857
215 {858, "IBM858 cp858 oem858 858"}, //IDM_FORMAT_DOS_858
216 {860, "IBM860 cp860 oem860 860"}, //IDM_FORMAT_DOS_860
217 {861, "IBM861 cp861 oem861 861"}, //IDM_FORMAT_DOS_861
218 {862, "IBM862 cp862 oem862 862"}, //IDM_FORMAT_DOS_862
219 {863, "IBM863 cp863 oem863 863"}, //IDM_FORMAT_DOS_863
220 {865, "IBM865 cp865 oem865 865"}, //IDM_FORMAT_DOS_865
221 {866, "IBM866 cp866 oem866 866"}, //IDM_FORMAT_DOS_866
222 {869, "IBM869 cp869 oem869 869"}, //IDM_FORMAT_DOS_869
223 {950, "big5 csBig5"}, //IDM_FORMAT_BIG5
224 {936, "gb2312 gbk csGB2312"}, //IDM_FORMAT_GB2312
225 {932, "Shift_JIS MS_Kanji csShiftJIS csWindows31J"}, //IDM_FORMAT_SHIFT_JIS
226 {949, "windows-949 korean"}, //IDM_FORMAT_KOREAN_WIN
227 {51949, "euc-kr csEUCKR"}, //IDM_FORMAT_EUC_KR
228 {874, "tis-620"}, //IDM_FORMAT_TIS_620
229 {10007, "x-mac-cyrillic xmaccyrillic"}, //IDM_FORMAT_MAC_CYRILLIC
230 {21866, "koi8_u"}, //IDM_FORMAT_KOI8U_CYRILLIC
231 {20866, "koi8_r csKOI8R"} //IDM_FORMAT_KOI8R_CYRILLIC
233 if(nId >= IDM_FORMAT_ENCODE && nId <= IDM_FORMAT_ENCODE_END)
234 this->UpdateInfo(encodings[nId - IDM_FORMAT_ENCODE].id);
236 int CTortoiseGitBlameView::OnCreate(LPCREATESTRUCT lpcs)
239 CRect rect,rect1;
240 this->GetWindowRect(&rect1);
241 rect.left=m_blamewidth+LOCATOR_WIDTH;
242 rect.right=rect.Width();
243 rect.top=0;
244 rect.bottom=rect.Height();
245 BOOL b=m_TextView.Create(_T("Scintilla"),_T("source"),0,rect,this,0,0);
246 m_TextView.Init(0,FALSE);
247 m_TextView.ShowWindow( SW_SHOW);
248 //m_TextView.InsertText(_T("Abdadfasdf"));
249 m_wEditor = m_TextView.m_hWnd;
250 CreateFont();
251 InitialiseEditor();
252 m_ToolTip.Create(this->GetParent());
254 ::AfxGetApp()->GetMainWnd();
255 return CView::OnCreate(lpcs);
259 void CTortoiseGitBlameView::OnSize(UINT nType,int cx, int cy)
262 CRect rect;
263 rect.left=m_blamewidth;
264 rect.right=cx;
265 rect.top=0;
266 rect.bottom=cy;
268 m_TextView.MoveWindow(&rect);
271 BOOL CTortoiseGitBlameView::PreCreateWindow(CREATESTRUCT& cs)
273 return CView::PreCreateWindow(cs);
276 // CTortoiseGitBlameView drawing
278 void CTortoiseGitBlameView::OnDraw(CDC* /*pDC*/)
280 CTortoiseGitBlameDoc* pDoc = GetDocument();
281 ASSERT_VALID(pDoc);
282 if (!pDoc)
283 return;
285 DrawBlame(this->GetDC()->m_hDC);
286 DrawLocatorBar(this->GetDC()->m_hDC);
287 // TODO: add draw code for native data here
291 // CTortoiseGitBlameView printing
294 void CTortoiseGitBlameView::OnFilePrintPreview()
296 AFXPrintPreview(this);
299 BOOL CTortoiseGitBlameView::OnPreparePrinting(CPrintInfo* pInfo)
301 // default preparation
302 return DoPreparePrinting(pInfo);
305 void CTortoiseGitBlameView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
307 // TODO: add extra initialization before printing
310 void CTortoiseGitBlameView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
312 // TODO: add cleanup after printing
315 void CTortoiseGitBlameView::OnRButtonUp(UINT nFlags, CPoint point)
317 LONG_PTR line = SendEditor(SCI_GETFIRSTVISIBLELINE);
318 LONG_PTR height = SendEditor(SCI_TEXTHEIGHT);
319 line = line + (point.y/height);
320 if (line < (LONG)m_CommitHash.size())
322 if(m_ID[line] >= 0) // only show context menu if we have log data for it
324 m_MouseLine = line;
325 ClientToScreen(&point);
326 theApp.GetContextMenuManager()->ShowPopupMenu(IDR_BLAME_POPUP, point.x, point.y, this, TRUE);
331 void CTortoiseGitBlameView::OnUpdateBlamePopupBlamePrevious(CCmdUI *pCmdUI)
333 if (m_ID[m_MouseLine] <= 1)
335 pCmdUI->Enable(false);
337 else
339 pCmdUI->Enable(true);
343 void CTortoiseGitBlameView::OnUpdateBlamePopupDiffPrevious(CCmdUI *pCmdUI)
345 if (m_ID[m_MouseLine] <= 1)
347 pCmdUI->Enable(false);
349 else
351 pCmdUI->Enable(true);
355 void CTortoiseGitBlameView::CopyHashToClipboard()
357 this->GetLogList()->CopySelectionToClipBoard(TRUE);
360 // CTortoiseGitBlameView diagnostics
362 #ifdef _DEBUG
363 void CTortoiseGitBlameView::AssertValid() const
365 CView::AssertValid();
368 void CTortoiseGitBlameView::Dump(CDumpContext& dc) const
370 CView::Dump(dc);
373 CTortoiseGitBlameDoc* CTortoiseGitBlameView::GetDocument() const // non-debug version is inline
375 ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTortoiseGitBlameDoc)));
376 return (CTortoiseGitBlameDoc*)m_pDocument;
378 #endif //_DEBUG
381 // CTortoiseGitBlameView message handlers
382 CString CTortoiseGitBlameView::GetAppDirectory()
384 CString path;
385 DWORD len = 0;
386 DWORD bufferlen = MAX_PATH; // MAX_PATH is not the limit here!
389 bufferlen += MAX_PATH; // MAX_PATH is not the limit here!
390 TCHAR * pBuf = new TCHAR[bufferlen];
391 len = GetModuleFileName(NULL, pBuf, bufferlen);
392 path = CString(pBuf, len);
393 delete [] pBuf;
394 } while(len == bufferlen);
396 path = path.Left(path.ReverseFind(_T('\\')));
397 //path = path.substr(0, path.rfind('\\') + 1);
399 return path;
402 // Return a color which is interpolated between c1 and c2.
403 // Slider controls the relative proportions as a percentage:
404 // Slider = 0 represents pure c1
405 // Slider = 50 represents equal mixture
406 // Slider = 100 represents pure c2
407 COLORREF CTortoiseGitBlameView::InterColor(COLORREF c1, COLORREF c2, int Slider)
409 int r, g, b;
411 // Limit Slider to 0..100% range
412 if (Slider < 0)
413 Slider = 0;
414 if (Slider > 100)
415 Slider = 100;
417 // The color components have to be treated individually.
418 r = (GetRValue(c2) * Slider + GetRValue(c1) * (100 - Slider)) / 100;
419 g = (GetGValue(c2) * Slider + GetGValue(c1) * (100 - Slider)) / 100;
420 b = (GetBValue(c2) * Slider + GetBValue(c1) * (100 - Slider)) / 100;
422 return RGB(r, g, b);
425 LRESULT CTortoiseGitBlameView::SendEditor(UINT Msg, WPARAM wParam, LPARAM lParam)
427 if (m_directFunction)
429 return ((SciFnDirect) m_directFunction)(m_directPointer, Msg, wParam, lParam);
431 return ::SendMessage(m_wEditor, Msg, wParam, lParam);
434 void CTortoiseGitBlameView::SetAStyle(int style, COLORREF fore, COLORREF back, int size, CString *face)
436 SendEditor(SCI_STYLESETFORE, style, fore);
437 SendEditor(SCI_STYLESETBACK, style, back);
438 if (size >= 1)
439 SendEditor(SCI_STYLESETSIZE, style, size);
440 if (face)
441 SendEditor(SCI_STYLESETFONT, style, reinterpret_cast<LPARAM>(this->m_TextView.StringForControl(*face).GetBuffer()));
444 void CTortoiseGitBlameView::InitialiseEditor()
447 m_directFunction = ::SendMessage(m_wEditor, SCI_GETDIRECTFUNCTION, 0, 0);
448 m_directPointer = ::SendMessage(m_wEditor, SCI_GETDIRECTPOINTER, 0, 0);
449 // Set up the global default style. These attributes are used wherever no explicit choices are made.
450 SetAStyle(STYLE_DEFAULT,
451 black,
452 white,
453 (DWORD)CRegStdDWORD(_T("Software\\TortoiseGit\\BlameFontSize"), 10),
454 &CString(((stdstring)CRegStdString(_T("Software\\TortoiseGit\\BlameFontName"), _T("Courier New"))).c_str())
456 SendEditor(SCI_SETTABWIDTH, (DWORD)CRegStdDWORD(_T("Software\\TortoiseGit\\BlameTabSize"), 4));
457 SendEditor(SCI_SETREADONLY, TRUE);
458 LRESULT pix = SendEditor(SCI_TEXTWIDTH, STYLE_LINENUMBER, (LPARAM)this->m_TextView.StringForControl(_T("_99999")).GetBuffer());
459 if (m_bShowLine)
460 SendEditor(SCI_SETMARGINWIDTHN, 0, pix);
461 else
462 SendEditor(SCI_SETMARGINWIDTHN, 0);
463 SendEditor(SCI_SETMARGINWIDTHN, 1);
464 SendEditor(SCI_SETMARGINWIDTHN, 2);
465 //Set the default windows colors for edit controls
466 SendEditor(SCI_STYLESETFORE, STYLE_DEFAULT, ::GetSysColor(COLOR_WINDOWTEXT));
467 SendEditor(SCI_STYLESETBACK, STYLE_DEFAULT, ::GetSysColor(COLOR_WINDOW));
468 SendEditor(SCI_SETSELFORE, TRUE, ::GetSysColor(COLOR_HIGHLIGHTTEXT));
469 SendEditor(SCI_SETSELBACK, TRUE, ::GetSysColor(COLOR_HIGHLIGHT));
470 SendEditor(SCI_SETCARETFORE, ::GetSysColor(COLOR_WINDOWTEXT));
471 m_regOldLinesColor = CRegStdDWORD(_T("Software\\TortoiseGit\\BlameOldColor"), RGB(230, 230, 255));
472 m_regNewLinesColor = CRegStdDWORD(_T("Software\\TortoiseGit\\BlameNewColor"), RGB(255, 230, 230));
473 CRegStdDWORD used2d(L"Software\\TortoiseGit\\ScintillaDirect2D", TRUE);
474 if (SysInfo::Instance().IsWin7OrLater() && DWORD(used2d))
476 SendEditor(SCI_SETTECHNOLOGY, SC_TECHNOLOGY_DIRECTWRITE);
477 SendEditor(SCI_SETBUFFEREDDRAW, 0);
479 SendEditor(SCI_SETFONTQUALITY, SC_EFF_QUALITY_LCD_OPTIMIZED);
481 this->m_TextView.Call(SCI_SETWRAPMODE, SC_WRAP_NONE);
485 void CTortoiseGitBlameView::StartSearch()
487 if (m_pFindDialog)
488 return;
489 bool bCase = false;
490 // Initialize FINDREPLACE
491 if (fr.Flags & FR_MATCHCASE)
492 bCase = true;
493 SecureZeroMemory(&fr, sizeof(fr));
494 fr.lStructSize = sizeof(fr);
495 fr.hwndOwner = wMain;
496 fr.lpstrFindWhat = szFindWhat;
497 fr.wFindWhatLen = 80;
498 fr.Flags = FR_HIDEUPDOWN | FR_HIDEWHOLEWORD;
499 fr.Flags |= bCase ? FR_MATCHCASE : 0;
501 currentDialog = FindText(&fr);
504 bool CTortoiseGitBlameView::DoSearch(CString what, DWORD flags)
507 //char szWhat[80];
508 int pos = SendEditor(SCI_GETCURRENTPOS);
509 int line = SendEditor(SCI_LINEFROMPOSITION, pos);
510 bool bFound = false;
511 bool bCaseSensitive = !!(flags & FR_MATCHCASE);
513 //strcpy_s(szWhat, sizeof(szWhat), what);
515 if(!bCaseSensitive)
517 what=what.MakeLower();
520 //CString sWhat = CString(szWhat);
522 //char buf[20];
523 //int i=0;
524 int i=line;
527 int bufsize = SendEditor(SCI_GETLINE, i);
528 char * linebuf = new char[bufsize+1];
529 SecureZeroMemory(linebuf, bufsize+1);
530 SendEditor(SCI_GETLINE, i, (LPARAM)linebuf);
531 CString oneline=this->m_TextView.StringFromControl(linebuf);
532 if (!bCaseSensitive)
534 oneline=oneline.MakeLower();
536 //_stprintf_s(buf, 20, _T("%ld"), revs[i]);
537 if (this->m_Authors[i].Find(what)>=0)
538 bFound = true;
539 else if ((!bCaseSensitive)&&(this->m_Authors[i].MakeLower().Find(what)>=0))
540 bFound = true;
541 else if (oneline.Find(what) >=0)
542 bFound = true;
544 delete [] linebuf;
546 i++;
547 if(i>=(signed int)m_CommitHash.size())
548 i=0;
549 }while(i!=line &&(!bFound));
551 if (bFound)
553 GotoLine(i);
554 int selstart = SendEditor(SCI_GETCURRENTPOS);
555 int selend = SendEditor(SCI_POSITIONFROMLINE, i);
556 SendEditor(SCI_SETSELECTIONSTART, selstart);
557 SendEditor(SCI_SETSELECTIONEND, selend);
558 m_SelectedLine = i-1;
560 else
562 ::MessageBox(wMain, _T("\"") + what + _T("\" ") + CString(MAKEINTRESOURCE(IDS_NOTFOUND)), _T("TortoiseGitBlame"), MB_ICONINFORMATION);
565 return true;
568 bool CTortoiseGitBlameView::GotoLine(long line)
570 --line;
571 if (line < 0)
572 return false;
573 if ((unsigned long)line >= m_CommitHash.size())
575 line = m_CommitHash.size()-1;
578 int nCurrentPos = SendEditor(SCI_GETCURRENTPOS);
579 int nCurrentLine = SendEditor(SCI_LINEFROMPOSITION,nCurrentPos);
580 int nFirstVisibleLine = SendEditor(SCI_GETFIRSTVISIBLELINE);
581 int nLinesOnScreen = SendEditor(SCI_LINESONSCREEN);
583 if ( line>=nFirstVisibleLine && line<=nFirstVisibleLine+nLinesOnScreen)
585 // no need to scroll
586 SendEditor(SCI_GOTOLINE, line);
588 else
590 // Place the requested line one third from the top
591 if ( line > nCurrentLine )
593 SendEditor(SCI_GOTOLINE, (WPARAM)(line+(int)nLinesOnScreen*(2/3.0)));
595 else
597 SendEditor(SCI_GOTOLINE, (WPARAM)(line-(int)nLinesOnScreen*(1/3.0)));
601 // Highlight the line
602 int nPosStart = SendEditor(SCI_POSITIONFROMLINE,line);
603 int nPosEnd = SendEditor(SCI_GETLINEENDPOSITION,line);
604 SendEditor(SCI_SETSEL,nPosEnd,nPosStart);
606 return true;
609 bool CTortoiseGitBlameView::ScrollToLine(long line)
611 if (line < 0)
612 return false;
614 int nCurrentLine = SendEditor(SCI_GETFIRSTVISIBLELINE);
616 int scrolldelta = line - nCurrentLine;
617 SendEditor(SCI_LINESCROLL, 0, scrolldelta);
619 return true;
622 void CTortoiseGitBlameView::CopySelectedLogToClipboard()
624 this->GetLogList()->CopySelectionToClipBoard(FALSE);
627 void CTortoiseGitBlameView::BlamePreviousRevision()
629 CString procCmd = _T("/path:\"");
630 procCmd += ((CMainFrame*)::AfxGetApp()->GetMainWnd())->GetActiveView()->GetDocument()->GetPathName();
631 procCmd += _T("\" ");
632 procCmd += _T(" /command:blame");
633 procCmd += _T(" /endrev:") + this->GetLogData()->GetGitRevAt(this->GetLogData()->size()-m_ID[m_MouseLine]+1).m_CommitHash.ToString();
635 CCommonAppUtils::RunTortoiseProc(procCmd);
638 void CTortoiseGitBlameView::DiffPreviousRevision()
640 CString procCmd = _T("/path:\"");
641 procCmd += ((CMainFrame*)::AfxGetApp()->GetMainWnd())->GetActiveView()->GetDocument()->GetPathName();
642 procCmd += _T("\" ");
643 procCmd += _T(" /command:diff");
644 procCmd += _T(" /startrev:") + this->GetLogData()->GetGitRevAt(this->GetLogData()->size() - m_ID[m_MouseLine]).m_CommitHash.ToString();
645 procCmd += _T(" /endrev:") + this->GetLogData()->GetGitRevAt(this->GetLogData()->size() - m_ID[m_MouseLine] + 1).m_CommitHash.ToString();
647 CCommonAppUtils::RunTortoiseProc(procCmd);
650 void CTortoiseGitBlameView::ShowLog()
652 CString procCmd = _T("/path:\"");
653 procCmd += ((CMainFrame*)::AfxGetApp()->GetMainWnd())->GetActiveView()->GetDocument()->GetPathName();
654 procCmd += _T("\" ");
655 procCmd += _T(" /command:log");
656 procCmd += _T(" /rev:") + this->GetLogData()->GetGitRevAt(this->GetLogData()->size() - m_ID[m_MouseLine]).m_CommitHash.ToString();
658 CCommonAppUtils::RunTortoiseProc(procCmd);
661 LONG CTortoiseGitBlameView::GetBlameWidth()
663 LONG blamewidth = 0;
664 SIZE width;
665 CreateFont();
666 HDC hDC = this->GetDC()->m_hDC;
667 HFONT oldfont = (HFONT)::SelectObject(hDC, m_font);
669 TCHAR buf[MAX_PATH];
671 CString shortHash('f', g_Git.GetShortHASHLength() + 1);
672 ::GetTextExtentPoint32(hDC, shortHash, g_Git.GetShortHASHLength() + 1, &width);
673 m_revwidth = width.cx + BLAMESPACE;
674 blamewidth += m_revwidth;
676 if (m_bShowDate)
678 _stprintf_s(buf, MAX_PATH, _T("%30s"), _T("31.08.2001 06:24:14"));
679 ::GetTextExtentPoint32(hDC, buf, _tcslen(buf), &width);
680 m_datewidth = width.cx + BLAMESPACE;
681 blamewidth += m_datewidth;
683 if ( m_bShowAuthor)
685 SIZE maxwidth = {0};
687 for (unsigned int i=0;i<this->m_Authors.size();i++)
689 ::GetTextExtentPoint32(hDC,m_Authors[i] , m_Authors[i].GetLength(), &width);
690 if (width.cx > maxwidth.cx)
691 maxwidth = width;
693 m_authorwidth = maxwidth.cx + BLAMESPACE;
694 blamewidth += m_authorwidth;
696 ::SelectObject(hDC, oldfont);
697 POINT pt = {blamewidth, 0};
698 LPtoDP(hDC, &pt, 1);
699 m_blamewidth = pt.x;
700 //::ReleaseDC(wBlame, hDC);
701 return blamewidth;
705 void CTortoiseGitBlameView::CreateFont()
707 if (m_font)
708 return;
709 LOGFONT lf = {0};
710 lf.lfWeight = 400;
711 HDC hDC = ::GetDC(wBlame);
712 lf.lfHeight = -MulDiv((DWORD)CRegStdDWORD(_T("Software\\TortoiseGit\\BlameFontSize"), 10), GetDeviceCaps(hDC, LOGPIXELSY), 72);
713 lf.lfCharSet = DEFAULT_CHARSET;
714 CRegStdString fontname = CRegStdString(_T("Software\\TortoiseGit\\BlameFontName"), _T("Courier New"));
715 _tcscpy_s(lf.lfFaceName, 32, ((stdstring)fontname).c_str());
716 m_font = ::CreateFontIndirect(&lf);
718 lf.lfItalic = TRUE;
719 m_italicfont = ::CreateFontIndirect(&lf);
721 ::ReleaseDC(wBlame, hDC);
724 void CTortoiseGitBlameView::DrawBlame(HDC hDC)
726 if (hDC == NULL)
727 return;
728 if (m_font == NULL)
729 return;
731 HFONT oldfont = NULL;
732 LONG_PTR line = SendEditor(SCI_GETFIRSTVISIBLELINE);
733 LONG_PTR linesonscreen = SendEditor(SCI_LINESONSCREEN);
734 LONG_PTR height = SendEditor(SCI_TEXTHEIGHT);
735 LONG_PTR Y = 0;
736 TCHAR buf[MAX_PATH];
737 RECT rc;
738 BOOL sel = FALSE;
739 //::GetClientRect(this->m_hWnd, &rc);
740 for (LRESULT i=line; i<(line+linesonscreen); ++i)
742 sel = FALSE;
743 if (i < (int)m_CommitHash.size())
745 // if (mergelines[i])
746 // oldfont = (HFONT)::SelectObject(hDC, m_italicfont);
747 // else
748 oldfont = (HFONT)::SelectObject(hDC, m_font);
749 ::SetBkColor(hDC, m_windowcolor);
750 ::SetTextColor(hDC, m_textcolor);
751 if (!m_CommitHash[i].IsEmpty())
753 //if (m_CommitHash[i].Compare(m_MouseHash)==0)
754 // ::SetBkColor(hDC, m_mouseauthorcolor);
755 if (m_CommitHash[i] == m_SelectedHash )
757 ::SetBkColor(hDC, m_selectedauthorcolor);
758 ::SetTextColor(hDC, m_texthighlightcolor);
759 sel = TRUE;
763 if(m_MouseLine == i)
764 ::SetBkColor(hDC, m_mouserevcolor);
766 //if ((revs[i] == m_mouserev)&&(!sel))
767 // ::SetBkColor(hDC, m_mouserevcolor);
768 //if (revs[i] == m_selectedrev)
770 // ::SetBkColor(hDC, m_selectedrevcolor);
771 // ::SetTextColor(hDC, m_texthighlightcolor);
774 CString str;
775 str = m_CommitHash[i].ToString().Left(g_Git.GetShortHASHLength());
777 //_stprintf_s(buf, MAX_PATH, _T("%8ld "), revs[i]);
778 rc.top=Y;
779 rc.left=LOCATOR_WIDTH;
780 rc.bottom=Y+height;
781 rc.right = rc.left + m_blamewidth;
782 ::ExtTextOut(hDC, LOCATOR_WIDTH, Y, ETO_CLIPPED, &rc, str, str.GetLength(), 0);
783 int Left = m_revwidth;
785 if (m_bShowAuthor)
787 rc.right = rc.left + Left + m_authorwidth;
788 //_stprintf_s(buf, MAX_PATH, _T("%-30s "), authors[i].c_str());
789 ::ExtTextOut(hDC, Left, Y, ETO_CLIPPED, &rc, m_Authors[i], m_Authors[i].GetLength(), 0);
790 Left += m_authorwidth;
792 #if 0
793 if (ShowDate)
795 rc.right = rc.left + Left + m_datewidth;
796 _stprintf_s(buf, MAX_PATH, _T("%30s "), dates[i].c_str());
797 ::ExtTextOut(hDC, Left, Y, ETO_CLIPPED, &rc, buf, _tcslen(buf), 0);
798 Left += m_datewidth;
801 #endif
802 if ((i==m_SelectedLine)&&(m_pFindDialog))
804 LOGBRUSH brush;
805 brush.lbColor = m_textcolor;
806 brush.lbHatch = 0;
807 brush.lbStyle = BS_SOLID;
808 HPEN pen = ExtCreatePen(PS_SOLID | PS_GEOMETRIC, 2, &brush, 0, NULL);
809 HGDIOBJ hPenOld = SelectObject(hDC, pen);
810 RECT rc2 = rc;
811 rc2.top = Y;
812 rc2.bottom = Y + height;
813 ::MoveToEx(hDC, rc2.left, rc2.top, NULL);
814 ::LineTo(hDC, rc2.right, rc2.top);
815 ::LineTo(hDC, rc2.right, rc2.bottom);
816 ::LineTo(hDC, rc2.left, rc2.bottom);
817 ::LineTo(hDC, rc2.left, rc2.top);
818 SelectObject(hDC, hPenOld);
819 DeleteObject(pen);
821 Y += height;
822 ::SelectObject(hDC, oldfont);
824 else
826 ::SetBkColor(hDC, m_windowcolor);
827 for (int j=0; j< MAX_PATH; ++j)
828 buf[j]=' ';
829 ::ExtTextOut(hDC, 0, Y, ETO_CLIPPED, &rc, buf, MAX_PATH-1, 0);
830 Y += height;
835 void CTortoiseGitBlameView::DrawLocatorBar(HDC hDC)
837 if (hDC == NULL)
838 return;
840 LONG_PTR line = SendEditor(SCI_GETFIRSTVISIBLELINE);
841 LONG_PTR linesonscreen = SendEditor(SCI_LINESONSCREEN);
842 LONG_PTR Y = 0;
843 COLORREF blackColor = GetSysColor(COLOR_WINDOWTEXT);
845 RECT rc;
846 //::GetClientRect(wLocator, &rc);
847 this->GetClientRect(&rc);
849 rc.right=LOCATOR_WIDTH;
851 RECT lineRect = rc;
852 LONG height = rc.bottom-rc.top;
853 LONG currentLine = 0;
855 // draw the colored bar
856 for (std::vector<LONG>::const_iterator it = m_ID.begin(); it != m_ID.end(); ++it)
858 currentLine++;
859 // get the line color
860 COLORREF cr = InterColor(DWORD(m_regOldLinesColor), DWORD(m_regNewLinesColor), (*it - m_lowestrev)*100/((m_highestrev-m_lowestrev)+1));
861 if ((currentLine > line)&&(currentLine <= (line + linesonscreen)))
863 cr = InterColor(cr, blackColor, 10);
865 SetBkColor(hDC, cr);
866 lineRect.top = Y;
867 lineRect.bottom = (currentLine * height / m_ID.size());
868 ::ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &lineRect, NULL, 0, NULL);
869 Y = lineRect.bottom;
872 if (m_ID.size())
874 // now draw two lines indicating the scroll position of the source view
875 SetBkColor(hDC, blackColor);
876 lineRect.top = line * height / m_ID.size();
877 lineRect.bottom = lineRect.top+1;
878 ::ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &lineRect, NULL, 0, NULL);
879 lineRect.top = (line + linesonscreen) * height / m_ID.size();
880 lineRect.bottom = lineRect.top+1;
881 ::ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &lineRect, NULL, 0, NULL);
886 void CTortoiseGitBlameView::StringExpand(LPSTR str)
888 char * cPos = str;
891 cPos = strchr(cPos, '\n');
892 if (cPos)
894 memmove(cPos+1, cPos, strlen(cPos)*sizeof(char));
895 *cPos = '\r';
896 cPos++;
897 cPos++;
899 } while (cPos != NULL);
901 void CTortoiseGitBlameView::StringExpand(LPWSTR str)
903 wchar_t * cPos = str;
906 cPos = wcschr(cPos, '\n');
907 if (cPos)
909 memmove(cPos+1, cPos, wcslen(cPos)*sizeof(wchar_t));
910 *cPos = '\r';
911 cPos++;
912 cPos++;
914 } while (cPos != NULL);
917 void CTortoiseGitBlameView::SetupLexer(CString filename)
920 TCHAR *line;
921 //const char * lineptr = _tcsrchr(filename, '.');
922 int start=filename.ReverseFind(_T('.'));
923 if (start>0)
925 //_tcscpy_s(line, 20, lineptr+1);
926 //_tcslwr_s(line, 20);
927 CString ext=filename.Right(filename.GetLength()-start-1);
928 line=ext.GetBuffer();
930 if ((_tcscmp(line, _T("py"))==0)||
931 (_tcscmp(line, _T("pyw"))==0))
933 SendEditor(SCI_SETLEXER, SCLEX_PYTHON);
934 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("and assert break class continue def del elif \
935 else except exec finally for from global if import in is lambda None \
936 not or pass print raise return try while yield")).GetBuffer()));
937 SetAStyle(SCE_P_DEFAULT, black);
938 SetAStyle(SCE_P_COMMENTLINE, darkGreen);
939 SetAStyle(SCE_P_NUMBER, RGB(0, 0x80, 0x80));
940 SetAStyle(SCE_P_STRING, RGB(0, 0, 0x80));
941 SetAStyle(SCE_P_CHARACTER, RGB(0, 0, 0x80));
942 SetAStyle(SCE_P_WORD, RGB(0x80, 0, 0x80));
943 SetAStyle(SCE_P_TRIPLE, black);
944 SetAStyle(SCE_P_TRIPLEDOUBLE, black);
945 SetAStyle(SCE_P_CLASSNAME, darkBlue);
946 SetAStyle(SCE_P_DEFNAME, darkBlue);
947 SetAStyle(SCE_P_OPERATOR, darkBlue);
948 SetAStyle(SCE_P_IDENTIFIER, darkBlue);
949 SetAStyle(SCE_P_COMMENTBLOCK, darkGreen);
950 SetAStyle(SCE_P_STRINGEOL, red);
952 if ((_tcscmp(line, _T("c"))==0)||
953 (_tcscmp(line, _T("cc"))==0)||
954 (_tcscmp(line, _T("cpp"))==0)||
955 (_tcscmp(line, _T("cxx"))==0)||
956 (_tcscmp(line, _T("h"))==0)||
957 (_tcscmp(line, _T("hh"))==0)||
958 (_tcscmp(line, _T("hpp"))==0)||
959 (_tcscmp(line, _T("hxx"))==0)||
960 (_tcscmp(line, _T("dlg"))==0)||
961 (_tcscmp(line, _T("mak"))==0))
963 SendEditor(SCI_SETLEXER, SCLEX_CPP);
964 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("and and_eq asm auto bitand bitor bool break \
965 case catch char class compl const const_cast continue \
966 default delete do double dynamic_cast else enum explicit export extern false float for \
967 friend goto if inline int long mutable namespace new not not_eq \
968 operator or or_eq private protected public \
969 register reinterpret_cast return short signed sizeof static static_cast struct switch \
970 template this throw true try typedef typeid typename union unsigned using \
971 virtual void volatile wchar_t while xor xor_eq")).GetBuffer()));
972 SendEditor(SCI_SETKEYWORDS, 3, (LPARAM)(m_TextView.StringForControl(_T("a addindex addtogroup anchor arg attention \
973 author b brief bug c class code date def defgroup deprecated dontinclude \
974 e em endcode endhtmlonly endif endlatexonly endlink endverbatim enum example exception \
975 f$ f[ f] file fn hideinitializer htmlinclude htmlonly \
976 if image include ingroup internal invariant interface latexonly li line link \
977 mainpage name namespace nosubgrouping note overload \
978 p page par param post pre ref relates remarks return retval \
979 sa section see showinitializer since skip skipline struct subsection \
980 test throw todo typedef union until \
981 var verbatim verbinclude version warning weakgroup $ @ \\ & < > # { }")).GetBuffer()));
982 SetupCppLexer();
984 if (_tcscmp(line, _T("cs"))==0)
986 SendEditor(SCI_SETLEXER, SCLEX_CPP);
987 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("abstract as base bool break byte case catch char checked class \
988 const continue decimal default delegate do double else enum \
989 event explicit extern false finally fixed float for foreach goto if \
990 implicit in int interface internal is lock long namespace new null \
991 object operator out override params private protected public \
992 readonly ref return sbyte sealed short sizeof stackalloc static \
993 string struct switch this throw true try typeof uint ulong \
994 unchecked unsafe ushort using virtual void while")).GetBuffer()));
995 SetupCppLexer();
997 if ((_tcscmp(line, _T("rc"))==0)||
998 (_tcscmp(line, _T("rc2"))==0))
1000 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1001 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("ACCELERATORS ALT AUTO3STATE AUTOCHECKBOX AUTORADIOBUTTON \
1002 BEGIN BITMAP BLOCK BUTTON CAPTION CHARACTERISTICS CHECKBOX CLASS \
1003 COMBOBOX CONTROL CTEXT CURSOR DEFPUSHBUTTON DIALOG DIALOGEX DISCARDABLE \
1004 EDITTEXT END EXSTYLE FONT GROUPBOX ICON LANGUAGE LISTBOX LTEXT \
1005 MENU MENUEX MENUITEM MESSAGETABLE POPUP \
1006 PUSHBUTTON RADIOBUTTON RCDATA RTEXT SCROLLBAR SEPARATOR SHIFT STATE3 \
1007 STRINGTABLE STYLE TEXTINCLUDE VALUE VERSION VERSIONINFO VIRTKEY")).GetBuffer()));
1008 SetupCppLexer();
1010 if ((_tcscmp(line, _T("idl"))==0)||
1011 (_tcscmp(line, _T("odl"))==0))
1013 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1014 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("aggregatable allocate appobject arrays async async_uuid \
1015 auto_handle \
1016 bindable boolean broadcast byte byte_count \
1017 call_as callback char coclass code comm_status \
1018 const context_handle context_handle_noserialize \
1019 context_handle_serialize control cpp_quote custom \
1020 decode default defaultbind defaultcollelem \
1021 defaultvalue defaultvtable dispinterface displaybind dllname \
1022 double dual \
1023 enable_allocate encode endpoint entry enum error_status_t \
1024 explicit_handle \
1025 fault_status first_is float \
1026 handle_t heap helpcontext helpfile helpstring \
1027 helpstringcontext helpstringdll hidden hyper \
1028 id idempotent ignore iid_as iid_is immediatebind implicit_handle \
1029 import importlib in include in_line int __int64 __int3264 interface \
1030 last_is lcid length_is library licensed local long \
1031 max_is maybe message methods midl_pragma \
1032 midl_user_allocate midl_user_free min_is module ms_union \
1033 ncacn_at_dsp ncacn_dnet_nsp ncacn_http ncacn_ip_tcp \
1034 ncacn_nb_ipx ncacn_nb_nb ncacn_nb_tcp ncacn_np \
1035 ncacn_spx ncacn_vns_spp ncadg_ip_udp ncadg_ipx ncadg_mq \
1036 ncalrpc nocode nonbrowsable noncreatable nonextensible notify \
1037 object odl oleautomation optimize optional out out_of_line \
1038 pipe pointer_default pragma properties propget propput propputref \
1039 ptr public \
1040 range readonly ref represent_as requestedit restricted retval \
1041 shape short signed size_is small source strict_context_handle \
1042 string struct switch switch_is switch_type \
1043 transmit_as typedef \
1044 uidefault union unique unsigned user_marshal usesgetlasterror uuid \
1045 v1_enum vararg version void wchar_t wire_marshal")).GetBuffer()));
1046 SetupCppLexer();
1048 if (_tcscmp(line, _T("java"))==0)
1050 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1051 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("abstract assert boolean break byte case catch char class \
1052 const continue default do double else extends final finally float for future \
1053 generic goto if implements import inner instanceof int interface long \
1054 native new null outer package private protected public rest \
1055 return short static super switch synchronized this throw throws \
1056 transient try var void volatile while")).GetBuffer()));
1057 SetupCppLexer();
1059 if (_tcscmp(line, _T("js"))==0)
1061 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1062 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("abstract boolean break byte case catch char class \
1063 const continue debugger default delete do double else enum export extends \
1064 final finally float for function goto if implements import in instanceof \
1065 int interface long native new package private protected public \
1066 return short static super switch synchronized this throw throws \
1067 transient try typeof var void volatile while with")).GetBuffer()));
1068 SetupCppLexer();
1070 if ((_tcscmp(line, _T("pas"))==0)||
1071 (_tcscmp(line, _T("dpr"))==0)||
1072 (_tcscmp(line, _T("pp"))==0))
1074 SendEditor(SCI_SETLEXER, SCLEX_PASCAL);
1075 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("and array as begin case class const constructor \
1076 destructor div do downto else end except file finally \
1077 for function goto if implementation in inherited \
1078 interface is mod not object of on or packed \
1079 procedure program property raise record repeat \
1080 set shl shr then threadvar to try type unit \
1081 until uses var while with xor")).GetBuffer()));
1082 SetupCppLexer();
1084 if ((_tcscmp(line, _T("as"))==0)||
1085 (_tcscmp(line, _T("asc"))==0)||
1086 (_tcscmp(line, _T("jsfl"))==0))
1088 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1089 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("add and break case catch class continue default delete do \
1090 dynamic else eq extends false finally for function ge get gt if implements import in \
1091 instanceof interface intrinsic le lt ne new not null or private public return \
1092 set static super switch this throw true try typeof undefined var void while with")).GetBuffer()));
1093 SendEditor(SCI_SETKEYWORDS, 1, (LPARAM)(m_TextView.StringForControl(_T("Array Arguments Accessibility Boolean Button Camera Color \
1094 ContextMenu ContextMenuItem Date Error Function Key LoadVars LocalConnection Math \
1095 Microphone Mouse MovieClip MovieClipLoader NetConnection NetStream Number Object \
1096 PrintJob Selection SharedObject Sound Stage String StyleSheet System TextField \
1097 TextFormat TextSnapshot Video Void XML XMLNode XMLSocket \
1098 _accProps _focusrect _global _highquality _parent _quality _root _soundbuftime \
1099 arguments asfunction call capabilities chr clearInterval duplicateMovieClip \
1100 escape eval fscommand getProperty getTimer getURL getVersion gotoAndPlay gotoAndStop \
1101 ifFrameLoaded Infinity -Infinity int isFinite isNaN length loadMovie loadMovieNum \
1102 loadVariables loadVariablesNum maxscroll mbchr mblength mbord mbsubstring MMExecute \
1103 NaN newline nextFrame nextScene on onClipEvent onUpdate ord parseFloat parseInt play \
1104 prevFrame prevScene print printAsBitmap printAsBitmapNum printNum random removeMovieClip \
1105 scroll set setInterval setProperty startDrag stop stopAllSounds stopDrag substring \
1106 targetPath tellTarget toggleHighQuality trace unescape unloadMovie unLoadMovieNum updateAfterEvent")).GetBuffer()));
1107 SetupCppLexer();
1109 if ((_tcscmp(line, _T("html"))==0)||
1110 (_tcscmp(line, _T("htm"))==0)||
1111 (_tcscmp(line, _T("shtml"))==0)||
1112 (_tcscmp(line, _T("htt"))==0)||
1113 (_tcscmp(line, _T("xml"))==0)||
1114 (_tcscmp(line, _T("asp"))==0)||
1115 (_tcscmp(line, _T("xsl"))==0)||
1116 (_tcscmp(line, _T("php"))==0)||
1117 (_tcscmp(line, _T("xhtml"))==0)||
1118 (_tcscmp(line, _T("phtml"))==0)||
1119 (_tcscmp(line, _T("cfm"))==0)||
1120 (_tcscmp(line, _T("tpl"))==0)||
1121 (_tcscmp(line, _T("dtd"))==0)||
1122 (_tcscmp(line, _T("hta"))==0)||
1123 (_tcscmp(line, _T("htd"))==0)||
1124 (_tcscmp(line, _T("wxs"))==0))
1126 SendEditor(SCI_SETLEXER, SCLEX_HTML);
1127 SendEditor(SCI_SETSTYLEBITS, 7);
1128 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("a abbr acronym address applet area b base basefont \
1129 bdo big blockquote body br button caption center \
1130 cite code col colgroup dd del dfn dir div dl dt em \
1131 fieldset font form frame frameset h1 h2 h3 h4 h5 h6 \
1132 head hr html i iframe img input ins isindex kbd label \
1133 legend li link map menu meta noframes noscript \
1134 object ol optgroup option p param pre q s samp \
1135 script select small span strike strong style sub sup \
1136 table tbody td textarea tfoot th thead title tr tt u ul \
1137 var xml xmlns abbr accept-charset accept accesskey action align alink \
1138 alt archive axis background bgcolor border \
1139 cellpadding cellspacing char charoff charset checked cite \
1140 class classid clear codebase codetype color cols colspan \
1141 compact content coords \
1142 data datafld dataformatas datapagesize datasrc datetime \
1143 declare defer dir disabled enctype event \
1144 face for frame frameborder \
1145 headers height href hreflang hspace http-equiv \
1146 id ismap label lang language leftmargin link longdesc \
1147 marginwidth marginheight maxlength media method multiple \
1148 name nohref noresize noshade nowrap \
1149 object onblur onchange onclick ondblclick onfocus \
1150 onkeydown onkeypress onkeyup onload onmousedown \
1151 onmousemove onmouseover onmouseout onmouseup \
1152 onreset onselect onsubmit onunload \
1153 profile prompt readonly rel rev rows rowspan rules \
1154 scheme scope selected shape size span src standby start style \
1155 summary tabindex target text title topmargin type usemap \
1156 valign value valuetype version vlink vspace width \
1157 text password checkbox radio submit reset \
1158 file hidden image")).GetBuffer()));
1159 SendEditor(SCI_SETKEYWORDS, 1, (LPARAM)(m_TextView.StringForControl(_T("assign audio block break catch choice clear disconnect else elseif \
1160 emphasis enumerate error exit field filled form goto grammar help \
1161 if initial link log menu meta noinput nomatch object option p paragraph \
1162 param phoneme prompt property prosody record reprompt return s say-as \
1163 script sentence subdialog submit throw transfer value var voice vxml")).GetBuffer()));
1164 SendEditor(SCI_SETKEYWORDS, 2, (LPARAM)(m_TextView.StringForControl(_T("accept age alphabet anchor application base beep bridge category charset \
1165 classid cond connecttimeout content contour count dest destexpr dtmf dtmfterm \
1166 duration enctype event eventexpr expr expritem fetchtimeout finalsilence \
1167 gender http-equiv id level maxage maxstale maxtime message messageexpr \
1168 method mime modal mode name namelist next nextitem ph pitch range rate \
1169 scope size sizeexpr skiplist slot src srcexpr sub time timeexpr timeout \
1170 transferaudio type value variant version volume xml:lang")).GetBuffer()));
1171 SendEditor(SCI_SETKEYWORDS, 3, (LPARAM)(m_TextView.StringForControl(_T("and assert break class continue def del elif \
1172 else except exec finally for from global if import in is lambda None \
1173 not or pass print raise return try while yield")).GetBuffer()));
1174 SendEditor(SCI_SETKEYWORDS, 4, (LPARAM)(m_TextView.StringForControl(_T("and argv as argc break case cfunction class continue declare default do \
1175 die echo else elseif empty enddeclare endfor endforeach endif endswitch \
1176 endwhile e_all e_parse e_error e_warning eval exit extends false for \
1177 foreach function global http_cookie_vars http_get_vars http_post_vars \
1178 http_post_files http_env_vars http_server_vars if include include_once \
1179 list new not null old_function or parent php_os php_self php_version \
1180 print require require_once return static switch stdclass this true var \
1181 xor virtual while __file__ __line__ __sleep __wakeup")).GetBuffer()));
1183 SetAStyle(SCE_H_TAG, darkBlue);
1184 SetAStyle(SCE_H_TAGUNKNOWN, red);
1185 SetAStyle(SCE_H_ATTRIBUTE, darkBlue);
1186 SetAStyle(SCE_H_ATTRIBUTEUNKNOWN, red);
1187 SetAStyle(SCE_H_NUMBER, RGB(0x80,0,0x80));
1188 SetAStyle(SCE_H_DOUBLESTRING, RGB(0,0x80,0));
1189 SetAStyle(SCE_H_SINGLESTRING, RGB(0,0x80,0));
1190 SetAStyle(SCE_H_OTHER, RGB(0x80,0,0x80));
1191 SetAStyle(SCE_H_COMMENT, RGB(0x80,0x80,0));
1192 SetAStyle(SCE_H_ENTITY, RGB(0x80,0,0x80));
1194 SetAStyle(SCE_H_TAGEND, darkBlue);
1195 SetAStyle(SCE_H_XMLSTART, darkBlue); // <?
1196 SetAStyle(SCE_H_QUESTION, darkBlue); // <?
1197 SetAStyle(SCE_H_XMLEND, darkBlue); // ?>
1198 SetAStyle(SCE_H_SCRIPT, darkBlue); // <script
1199 SetAStyle(SCE_H_ASP, RGB(0x4F, 0x4F, 0), RGB(0xFF, 0xFF, 0)); // <% ... %>
1200 SetAStyle(SCE_H_ASPAT, RGB(0x4F, 0x4F, 0), RGB(0xFF, 0xFF, 0)); // <%@ ... %>
1202 SetAStyle(SCE_HB_DEFAULT, black);
1203 SetAStyle(SCE_HB_COMMENTLINE, darkGreen);
1204 SetAStyle(SCE_HB_NUMBER, RGB(0,0x80,0x80));
1205 SetAStyle(SCE_HB_WORD, darkBlue);
1206 SendEditor(SCI_STYLESETBOLD, SCE_HB_WORD, 1);
1207 SetAStyle(SCE_HB_STRING, RGB(0x80,0,0x80));
1208 SetAStyle(SCE_HB_IDENTIFIER, black);
1210 // This light blue is found in the windows system palette so is safe to use even in 256 colour modes.
1211 // Show the whole section of VBScript with light blue background
1212 for (int bstyle=SCE_HB_DEFAULT; bstyle<=SCE_HB_STRINGEOL; bstyle++) {
1213 SendEditor(SCI_STYLESETFONT, bstyle,
1214 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
1215 SendEditor(SCI_STYLESETBACK, bstyle, lightBlue);
1216 // This call extends the backround colour of the last style on the line to the edge of the window
1217 SendEditor(SCI_STYLESETEOLFILLED, bstyle, 1);
1219 SendEditor(SCI_STYLESETBACK, SCE_HB_STRINGEOL, RGB(0x7F,0x7F,0xFF));
1220 SendEditor(SCI_STYLESETFONT, SCE_HB_COMMENTLINE,
1221 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
1223 SetAStyle(SCE_HBA_DEFAULT, black);
1224 SetAStyle(SCE_HBA_COMMENTLINE, darkGreen);
1225 SetAStyle(SCE_HBA_NUMBER, RGB(0,0x80,0x80));
1226 SetAStyle(SCE_HBA_WORD, darkBlue);
1227 SendEditor(SCI_STYLESETBOLD, SCE_HBA_WORD, 1);
1228 SetAStyle(SCE_HBA_STRING, RGB(0x80,0,0x80));
1229 SetAStyle(SCE_HBA_IDENTIFIER, black);
1231 // Show the whole section of ASP VBScript with bright yellow background
1232 for (int bastyle=SCE_HBA_DEFAULT; bastyle<=SCE_HBA_STRINGEOL; bastyle++) {
1233 SendEditor(SCI_STYLESETFONT, bastyle,
1234 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
1235 SendEditor(SCI_STYLESETBACK, bastyle, RGB(0xFF, 0xFF, 0));
1236 // This call extends the backround colour of the last style on the line to the edge of the window
1237 SendEditor(SCI_STYLESETEOLFILLED, bastyle, 1);
1239 SendEditor(SCI_STYLESETBACK, SCE_HBA_STRINGEOL, RGB(0xCF,0xCF,0x7F));
1240 SendEditor(SCI_STYLESETFONT, SCE_HBA_COMMENTLINE,
1241 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
1243 // If there is no need to support embedded Javascript, the following code can be dropped.
1244 // Javascript will still be correctly processed but will be displayed in just the default style.
1246 SetAStyle(SCE_HJ_START, RGB(0x80,0x80,0));
1247 SetAStyle(SCE_HJ_DEFAULT, black);
1248 SetAStyle(SCE_HJ_COMMENT, darkGreen);
1249 SetAStyle(SCE_HJ_COMMENTLINE, darkGreen);
1250 SetAStyle(SCE_HJ_COMMENTDOC, darkGreen);
1251 SetAStyle(SCE_HJ_NUMBER, RGB(0,0x80,0x80));
1252 SetAStyle(SCE_HJ_WORD, black);
1253 SetAStyle(SCE_HJ_KEYWORD, darkBlue);
1254 SetAStyle(SCE_HJ_DOUBLESTRING, RGB(0x80,0,0x80));
1255 SetAStyle(SCE_HJ_SINGLESTRING, RGB(0x80,0,0x80));
1256 SetAStyle(SCE_HJ_SYMBOLS, black);
1258 SetAStyle(SCE_HJA_START, RGB(0x80,0x80,0));
1259 SetAStyle(SCE_HJA_DEFAULT, black);
1260 SetAStyle(SCE_HJA_COMMENT, darkGreen);
1261 SetAStyle(SCE_HJA_COMMENTLINE, darkGreen);
1262 SetAStyle(SCE_HJA_COMMENTDOC, darkGreen);
1263 SetAStyle(SCE_HJA_NUMBER, RGB(0,0x80,0x80));
1264 SetAStyle(SCE_HJA_WORD, black);
1265 SetAStyle(SCE_HJA_KEYWORD, darkBlue);
1266 SetAStyle(SCE_HJA_DOUBLESTRING, RGB(0x80,0,0x80));
1267 SetAStyle(SCE_HJA_SINGLESTRING, RGB(0x80,0,0x80));
1268 SetAStyle(SCE_HJA_SYMBOLS, black);
1270 SetAStyle(SCE_HPHP_DEFAULT, black);
1271 SetAStyle(SCE_HPHP_HSTRING, RGB(0x80,0,0x80));
1272 SetAStyle(SCE_HPHP_SIMPLESTRING, RGB(0x80,0,0x80));
1273 SetAStyle(SCE_HPHP_WORD, darkBlue);
1274 SetAStyle(SCE_HPHP_NUMBER, RGB(0,0x80,0x80));
1275 SetAStyle(SCE_HPHP_VARIABLE, red);
1276 SetAStyle(SCE_HPHP_HSTRING_VARIABLE, red);
1277 SetAStyle(SCE_HPHP_COMPLEX_VARIABLE, red);
1278 SetAStyle(SCE_HPHP_COMMENT, darkGreen);
1279 SetAStyle(SCE_HPHP_COMMENTLINE, darkGreen);
1280 SetAStyle(SCE_HPHP_OPERATOR, darkBlue);
1282 // Show the whole section of Javascript with off white background
1283 for (int jstyle=SCE_HJ_DEFAULT; jstyle<=SCE_HJ_SYMBOLS; jstyle++) {
1284 SendEditor(SCI_STYLESETFONT, jstyle,
1285 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
1286 SendEditor(SCI_STYLESETBACK, jstyle, offWhite);
1287 SendEditor(SCI_STYLESETEOLFILLED, jstyle, 1);
1289 SendEditor(SCI_STYLESETBACK, SCE_HJ_STRINGEOL, RGB(0xDF, 0xDF, 0x7F));
1290 SendEditor(SCI_STYLESETEOLFILLED, SCE_HJ_STRINGEOL, 1);
1292 // Show the whole section of Javascript with brown background
1293 for (int jastyle=SCE_HJA_DEFAULT; jastyle<=SCE_HJA_SYMBOLS; jastyle++) {
1294 SendEditor(SCI_STYLESETFONT, jastyle,
1295 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
1296 SendEditor(SCI_STYLESETBACK, jastyle, RGB(0xDF, 0xDF, 0x7F));
1297 SendEditor(SCI_STYLESETEOLFILLED, jastyle, 1);
1299 SendEditor(SCI_STYLESETBACK, SCE_HJA_STRINGEOL, RGB(0x0,0xAF,0x5F));
1300 SendEditor(SCI_STYLESETEOLFILLED, SCE_HJA_STRINGEOL, 1);
1303 else
1305 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1306 SetupCppLexer();
1308 SendEditor(SCI_COLOURISE, 0, -1);
1312 void CTortoiseGitBlameView::SetupCppLexer()
1314 SetAStyle(SCE_C_DEFAULT, RGB(0, 0, 0));
1315 SetAStyle(SCE_C_COMMENT, RGB(0, 0x80, 0));
1316 SetAStyle(SCE_C_COMMENTLINE, RGB(0, 0x80, 0));
1317 SetAStyle(SCE_C_COMMENTDOC, RGB(0, 0x80, 0));
1318 SetAStyle(SCE_C_COMMENTLINEDOC, RGB(0, 0x80, 0));
1319 SetAStyle(SCE_C_COMMENTDOCKEYWORD, RGB(0, 0x80, 0));
1320 SetAStyle(SCE_C_COMMENTDOCKEYWORDERROR, RGB(0, 0x80, 0));
1321 SetAStyle(SCE_C_NUMBER, RGB(0, 0x80, 0x80));
1322 SetAStyle(SCE_C_WORD, RGB(0, 0, 0x80));
1323 SendEditor(SCE_C_WORD, 1);
1324 SetAStyle(SCE_C_STRING, RGB(0x80, 0, 0x80));
1325 SetAStyle(SCE_C_IDENTIFIER, RGB(0, 0, 0));
1326 SetAStyle(SCE_C_PREPROCESSOR, RGB(0x80, 0, 0));
1327 SetAStyle(SCE_C_OPERATOR, RGB(0x80, 0x80, 0));
1330 int CTortoiseGitBlameView::GetEncode(unsigned char *buff, int size, int *bomoffset)
1332 CFileTextLines textlines;
1333 CFileTextLines::UnicodeType type = textlines.CheckUnicodeType(buff, size);
1335 if(type == CFileTextLines::UTF8BOM)
1337 *bomoffset = 3;
1338 return CP_UTF8;
1340 if(type == CFileTextLines::UTF8)
1341 return CP_UTF8;
1343 if(type == CFileTextLines::UNICODE_LE)
1345 *bomoffset = 2;
1346 return 1200;
1349 // check for UNICODE_BE does not work, because git blame produces two NUL chars in a row
1350 if(type == CFileTextLines::BINARY && size > 2 && buff[0] == 0xFE && buff[1] == 0xFF)
1352 *bomoffset = 2;
1353 return 1201;
1356 return GetACP();
1359 void CTortoiseGitBlameView::UpdateInfo(int Encode)
1361 BYTE_VECTOR &data = GetDocument()->m_BlameData;
1362 CString one;
1363 int pos=0;
1365 BYTE_VECTOR vector;
1367 CLogDataVector * pRevs= GetLogData();
1369 this->m_CommitHash.clear();
1370 this->m_Authors.clear();
1371 this->m_ID.clear();
1372 CString line;
1374 CreateFont();
1376 SendEditor(SCI_SETREADONLY, FALSE);
1377 SendEditor(SCI_CLEARALL);
1378 SendEditor(EM_EMPTYUNDOBUFFER);
1379 SendEditor(SCI_SETSAVEPOINT);
1380 SendEditor(SCI_CANCEL);
1381 SendEditor(SCI_SETUNDOCOLLECTION, 0);
1383 SendEditor(SCI_SETCODEPAGE, SC_CP_UTF8);
1385 int current = 0;
1386 int encoding = Encode;
1387 while( pos>=0 && current >=0 && pos<data.size() )
1389 current = data.findData((const BYTE*)"\n",1,pos);
1390 //one=data.Tokenize(_T("\n"),pos);
1392 bool isbound = ( data[pos] == _T('^') );
1394 if( (data.size() - pos) >1 && data[pos] == _T('^'))
1395 pos ++;
1397 if( data[pos] == 0)
1398 continue;
1400 CGitHash hash;
1401 if(isbound)
1403 git_init();
1404 data[pos+39]=0;
1405 if(git_get_sha1((const char*)&data[pos], hash.m_hash))
1407 ::MessageBox(NULL, _T("Can't get hash"), _T("TortoiseGit"), MB_OK|MB_ICONERROR);
1411 else
1412 hash.ConvertFromStrA((char*)&data[pos]);
1415 int start=0;
1416 start=data.findData((const BYTE*)")",1,pos + 40);
1417 if(start>0)
1420 int bomoffset = 0;
1421 CStringA stra;
1422 stra.Empty();
1424 if(current>=0)
1425 data[current] = 0;
1426 else
1427 data.push_back(0);
1429 if( pos <40 && encoding==0)
1431 // first line
1432 encoding = GetEncode( &data[start+2], data.size() - start -2, &bomoffset);
1435 if(encoding == 1201)
1437 CString strw;
1438 int size = ((current - start -2 - bomoffset)/2);
1439 TCHAR *buffer = strw.GetBuffer(size);
1440 memcpy(buffer, &data[start + 2 + bomoffset],sizeof(TCHAR)*size);
1441 // swap the bytes to little-endian order to get proper strings in wchar_t format
1442 wchar_t * pSwapBuf = buffer;
1443 for (DWORD i = 0; i<size; ++i)
1445 *pSwapBuf = WideCharSwap2(*pSwapBuf);
1446 ++pSwapBuf;
1448 strw.ReleaseBuffer();
1450 stra = CUnicodeUtils::GetUTF8(strw);
1452 else if(encoding == 1200)
1454 CString strw;
1455 // the first bomoffset is 2, after that it's 1 (see issue #920)
1456 if (bomoffset == 0)
1457 bomoffset = 1;
1458 int size = ((current - start -2 - bomoffset)/2);
1459 TCHAR *buffer = strw.GetBuffer(size);
1460 memcpy(buffer, &data[start + 2 + bomoffset],sizeof(TCHAR)*size);
1461 strw.ReleaseBuffer();
1463 stra = CUnicodeUtils::GetUTF8(strw);
1465 else if(encoding == CP_UTF8)
1467 stra = &data[start + 2 + bomoffset ];
1469 else
1471 CString strw;
1472 strw = CUnicodeUtils::GetUnicode(CStringA(&data[start + 2 + bomoffset ]), encoding);
1473 stra = CUnicodeUtils::GetUTF8(strw);
1477 SendEditor(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)stra);
1478 SendEditor(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)"\n\0\0\0");
1480 if(current>=0)
1481 data[current] = '\n';
1485 if(this->m_NoListCommit.find(hash) == m_NoListCommit.end() )
1487 this->m_NoListCommit[hash].GetCommitFromHash(hash);
1489 m_ID.push_back(-1); // m_ID is calculated lazy on demand
1490 m_Authors.push_back(m_NoListCommit[hash].GetAuthorName());
1492 m_CommitHash.push_back(hash);
1493 pos = current+1;
1496 #if 0
1497 if(m_Buffer)
1499 delete m_Buffer;
1500 m_Buffer=NULL;
1503 CFile file;
1504 file.Open(this->GetDocument()->m_TempFileName,CFile::modeRead);
1506 m_Buffer = new char[file.GetLength()+4];
1507 m_Buffer[file.GetLength()] =0;
1508 m_Buffer[file.GetLength()+1] =0;
1509 m_Buffer[file.GetLength()+2] =0;
1510 m_Buffer[file.GetLength()+3] =0;
1512 file.Read(m_Buffer, file.GetLength());
1514 int bomoffset =0;
1515 int encoding = GetEncode( (unsigned char *)m_Buffer, file.GetLength(), &bomoffset);
1517 file.Close();
1518 //SendEditor(SCI_SETCODEPAGE, encoding);
1520 //SendEditor(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)(m_Buffer + bomoffset));
1521 #endif
1522 SetupLexer(GetDocument()->m_CurrentFileName);
1524 SendEditor(SCI_SETUNDOCOLLECTION, 1);
1525 SendEditor(EM_EMPTYUNDOBUFFER);
1526 SendEditor(SCI_SETSAVEPOINT);
1527 SendEditor(SCI_GOTOPOS, 0);
1528 SendEditor(SCI_SETSCROLLWIDTHTRACKING, TRUE);
1529 SendEditor(SCI_SETREADONLY, TRUE);
1531 m_lowestrev=0;
1532 m_highestrev=this->GetLogData()->size()+m_NoListCommit.size();
1534 GetBlameWidth();
1535 CRect rect;
1536 this->GetClientRect(rect);
1537 //this->m_TextView.GetWindowRect(rect);
1538 //this->m_TextView.ScreenToClient(rect);
1539 rect.left=this->m_blamewidth;
1540 this->m_TextView.MoveWindow(rect);
1542 this->Invalidate();
1545 CGitBlameLogList * CTortoiseGitBlameView::GetLogList()
1547 return &(GetDocument()->GetMainFrame()->m_wndOutput.m_LogList);
1551 CLogDataVector * CTortoiseGitBlameView::GetLogData()
1553 return &(GetDocument()->GetMainFrame()->m_wndOutput.m_LogList.m_logEntries);
1556 void CTortoiseGitBlameView::OnSciPainted(NMHDR *,LRESULT *)
1558 this->Invalidate();
1561 void CTortoiseGitBlameView::OnLButtonDown(UINT nFlags,CPoint point)
1564 LONG_PTR line = SendEditor(SCI_GETFIRSTVISIBLELINE);
1565 LONG_PTR height = SendEditor(SCI_TEXTHEIGHT);
1566 line = line + (point.y/height);
1568 if (line < (LONG)m_CommitHash.size())
1570 SetSelectedLine(line);
1571 if (m_CommitHash[line] != m_SelectedHash)
1573 m_SelectedHash = m_CommitHash[line];
1575 // lazy calculate m_ID
1576 if (m_ID[line] == -1)
1578 m_ID[line] = -2; // don't do this lazy calculation again and again for unfindable hashes
1579 for(int i = 0; i<this->GetLogData()->size(); i++)
1581 if(m_SelectedHash == this->GetLogData()->at(i))
1583 m_ID[line] = this->GetLogData()->size()-i;
1584 break;
1589 if(m_ID[line]>=0)
1591 this->GetLogList()->SetItemState(this->GetLogList()->GetItemCount()-m_ID[line],
1592 LVIS_SELECTED,
1593 LVIS_SELECTED);
1594 this->GetLogList()->EnsureVisible(this->GetLogList()->GetItemCount()-m_ID[line], FALSE);
1596 else
1598 this->GetDocument()->GetMainFrame()->m_wndProperties.UpdateProperties(&m_NoListCommit[m_CommitHash[line]]);
1601 else
1603 m_SelectedHash.Empty();
1605 //::InvalidateRect( NULL, FALSE);
1606 this->Invalidate();
1607 this->m_TextView.Invalidate();
1610 else
1612 SetSelectedLine(-1);
1615 CView::OnLButtonDown(nFlags,point);
1618 void CTortoiseGitBlameView::OnSciGetBkColor(NMHDR* hdr, LRESULT* result)
1621 SCNotification *notification=reinterpret_cast<SCNotification *>(hdr);
1623 if ((m_colorage)&&(notification->line < (int)m_CommitHash.size()))
1625 if(m_CommitHash[notification->line] == this->m_SelectedHash )
1626 notification->lParam = m_selectedauthorcolor;
1627 else
1628 notification->lParam = InterColor(DWORD(m_regOldLinesColor), DWORD(m_regNewLinesColor), (m_ID[notification->line]-m_lowestrev)*100/((m_highestrev-m_lowestrev)+1));
1633 void CTortoiseGitBlameView::FocusOn(GitRev *pRev)
1635 this->GetDocument()->GetMainFrame()->m_wndProperties.UpdateProperties(pRev);
1637 this->Invalidate();
1639 if (m_SelectedHash != pRev->m_CommitHash) {
1640 m_SelectedHash = pRev->m_CommitHash;
1641 int i;
1642 for(i=0;i<m_CommitHash.size();i++)
1644 if( pRev->m_CommitHash == m_CommitHash[i] )
1645 break;
1647 this->GotoLine(i);
1648 this->m_TextView.Invalidate();
1652 void CTortoiseGitBlameView::OnMouseHover(UINT nFlags, CPoint point)
1654 LONG_PTR line = SendEditor(SCI_GETFIRSTVISIBLELINE);
1655 LONG_PTR height = SendEditor(SCI_TEXTHEIGHT);
1656 line = line + (point.y/height);
1658 if (line < (LONG)m_CommitHash.size())
1660 if (line != m_MouseLine)
1662 m_MouseLine = line;//m_CommitHash[line];
1663 GitRev *pRev;
1664 if(m_ID[line]<0)
1666 pRev=&this->m_NoListCommit[m_CommitHash[line]];
1669 else
1671 pRev=&this->GetLogData()->GetGitRevAt(this->GetLogList()->GetItemCount()-m_ID[line]);
1674 CString str;
1675 str.Format(_T("%s: %s\n%s: %s\n%s: %s\n%s:\n%s\n%s"), m_sRev, pRev->m_CommitHash.ToString(),
1676 m_sAuthor, pRev->GetAuthorName(),
1677 m_sDate, CLoglistUtils::FormatDateAndTime(pRev->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
1678 m_sMessage, pRev->GetSubject(),
1679 pRev->GetBody());
1681 m_ToolTip.Pop();
1682 m_ToolTip.AddTool(this, str);
1684 CRect rect;
1685 rect.left=LOCATOR_WIDTH;
1686 rect.right=this->m_blamewidth+rect.left;
1687 rect.top=point.y-height;
1688 rect.bottom=point.y+height;
1689 this->InvalidateRect(rect);
1694 void CTortoiseGitBlameView::OnMouseMove(UINT nFlags, CPoint point)
1696 TRACKMOUSEEVENT tme;
1697 tme.cbSize=sizeof(TRACKMOUSEEVENT);
1698 tme.dwFlags=TME_HOVER|TME_LEAVE;
1699 tme.hwndTrack=this->m_hWnd;
1700 tme.dwHoverTime=1;
1701 TrackMouseEvent(&tme);
1705 BOOL CTortoiseGitBlameView::PreTranslateMessage(MSG* pMsg)
1707 m_ToolTip.RelayEvent(pMsg);
1708 return CView::PreTranslateMessage(pMsg);
1711 void CTortoiseGitBlameView::OnEditFind()
1713 m_pFindDialog=new CFindReplaceDialog();
1715 m_pFindDialog->Create(TRUE,_T(""),NULL,FR_DOWN,this);
1718 void CTortoiseGitBlameView::OnEditGoto()
1720 CEditGotoDlg dlg;
1721 if(dlg.DoModal()==IDOK)
1723 this->GotoLine(dlg.m_LineNumber);
1727 LRESULT CTortoiseGitBlameView::OnFindDialogMessage(WPARAM wParam, LPARAM lParam)
1729 ASSERT(m_pFindDialog != NULL);
1731 // If the FR_DIALOGTERM flag is set,
1732 // invalidate the handle identifying the dialog box.
1733 if (m_pFindDialog->IsTerminating())
1735 m_pFindDialog = NULL;
1736 return 0;
1739 // If the FR_FINDNEXT flag is set,
1740 // call the application-defined search routine
1741 // to search for the requested string.
1742 if(m_pFindDialog->FindNext())
1744 //read data from dialog
1745 CString FindName = m_pFindDialog->GetFindString();
1746 bool bMatchCase = m_pFindDialog->MatchCase() == TRUE;
1747 bool bMatchWholeWord = m_pFindDialog->MatchWholeWord() == TRUE;
1748 bool bSearchDown = m_pFindDialog->SearchDown() == TRUE;
1750 DoSearch(FindName,m_pFindDialog->m_fr.Flags);
1751 //with given name do search
1752 // *FindWhatYouNeed(FindName, bMatchCase, bMatchWholeWord, bSearchDown);
1755 return 0;
1758 void CTortoiseGitBlameView::OnViewNext()
1760 FindNextLine(this->m_SelectedHash,false);
1762 void CTortoiseGitBlameView::OnViewPrev()
1764 FindNextLine(this->m_SelectedHash,true);
1767 void CTortoiseGitBlameView::OnViewToggleAuthor()
1769 m_bShowAuthor = ! m_bShowAuthor;
1771 theApp.WriteInt(_T("ShowAuthor"), m_bShowAuthor);
1773 CRect rect;
1774 this->GetClientRect(&rect);
1775 rect.left=GetBlameWidth();
1777 m_TextView.MoveWindow(&rect);
1780 void CTortoiseGitBlameView::OnUpdateViewToggleAuthor(CCmdUI *pCmdUI)
1782 pCmdUI->SetCheck(m_bShowAuthor);
1785 void CTortoiseGitBlameView::OnViewToggleFollowRenames()
1787 m_bFollowRenames = ! m_bFollowRenames;
1789 theApp.WriteInt(_T("FollowRenames"), m_bFollowRenames);
1791 UINT uCheck = MF_BYCOMMAND;
1792 uCheck |= m_bFollowRenames ? MF_CHECKED : MF_UNCHECKED;
1793 CheckMenuItem(GetMenu()->m_hMenu, ID_VIEW_FOLLOWRENAMES, uCheck);
1795 CTortoiseGitBlameDoc *document = (CTortoiseGitBlameDoc *) m_pDocument;
1796 if (!document->m_CurrentFileName.IsEmpty())
1798 theApp.m_pDocManager->OnFileNew();
1799 document->OnOpenDocument(document->m_CurrentFileName, document->m_Rev);
1803 void CTortoiseGitBlameView::OnUpdateViewToggleFollowRenames(CCmdUI *pCmdUI)
1805 pCmdUI->SetCheck(m_bFollowRenames);
1808 int CTortoiseGitBlameView::FindNextLine(CGitHash CommitHash,bool bUpOrDown)
1810 LONG_PTR line = SendEditor(SCI_GETFIRSTVISIBLELINE);
1811 LONG_PTR startline =line;
1812 bool findNoMatch =false;
1813 while(line>=0 && line<m_CommitHash.size())
1815 if(m_CommitHash[line]!=CommitHash)
1817 findNoMatch=true;
1820 if(m_CommitHash[line] == CommitHash && findNoMatch)
1822 if( line == startline+2 )
1824 findNoMatch=false;
1826 else
1828 if( bUpOrDown )
1830 line=FindFirstLine(CommitHash,line);
1832 SendEditor(SCI_LINESCROLL,0,line-startline-2);
1833 return line;
1836 if(bUpOrDown)
1837 line--;
1838 else
1839 line++;
1841 return -1;