GitProcessList: Add success/failure info when finish command
[TortoiseGit.git] / src / TortoiseGitBlame / TortoiseGitBlameView.cpp
blob9e547d6feae111abb7151f942bf3e833d6fa95cb
1 // TortoiseGitBlame - a Viewer for Git Blames
3 // Copyright (C) 2008-2013 - TortoiseGit
4 // Copyright (C) 2010-2013 Sven Strickroth <email@cs-ware.de>
5 // Copyright (C) 2003-2008 - TortoiseSVN
7 // Copyright (C)2003 Don HO <donho@altern.org>
9 // This program is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU General Public License
11 // as published by the Free Software Foundation; either version 2
12 // of the License, or (at your option) any later version.
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
19 // You should have received a copy of the GNU General Public License
20 // along with this program; if not, write to the Free Software Foundation,
21 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 // CTortoiseGitBlameView.cpp : implementation of the CTortoiseGitBlameView class
26 #include "stdafx.h"
27 #include "TortoiseGitBlame.h"
28 #include "CommonAppUtils.h"
29 #include "TortoiseGitBlameDoc.h"
30 #include "TortoiseGitBlameView.h"
31 #include "MainFrm.h"
32 #include "EditGotoDlg.h"
33 #include "LoglistUtils.h"
34 #include "FileTextLines.h"
35 #include "UniCodeUtils.h"
36 #include "MenuEncode.h"
37 #include "gitdll.h"
38 #include "SysInfo.h"
39 #include "StringUtils.h"
41 #ifdef _DEBUG
42 #define new DEBUG_NEW
43 #endif
45 wchar_t WideCharSwap2(wchar_t nValue)
47 return (((nValue>> 8)) | (nValue << 8));
50 UINT CTortoiseGitBlameView::m_FindDialogMessage;
52 // CTortoiseGitBlameView
53 IMPLEMENT_DYNAMIC(CSciEditBlame,CSciEdit)
55 IMPLEMENT_DYNCREATE(CTortoiseGitBlameView, CView)
57 BEGIN_MESSAGE_MAP(CTortoiseGitBlameView, CView)
58 // Standard printing commands
59 ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)
60 ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
61 ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CTortoiseGitBlameView::OnFilePrintPreview)
62 ON_COMMAND(ID_EDIT_FIND,OnEditFind)
63 ON_COMMAND(ID_EDIT_GOTO,OnEditGoto)
64 ON_COMMAND(ID_EDIT_COPY, CopyToClipboard)
65 ON_UPDATE_COMMAND_UI(ID_EDIT_COPY, OnUpdateViewCopyToClipboard)
66 ON_COMMAND(ID_VIEW_NEXT,OnViewNext)
67 ON_COMMAND(ID_VIEW_PREV,OnViewPrev)
68 ON_COMMAND(ID_VIEW_SHOWAUTHOR, OnViewToggleAuthor)
69 ON_UPDATE_COMMAND_UI(ID_VIEW_SHOWAUTHOR, OnUpdateViewToggleAuthor)
70 ON_COMMAND(ID_VIEW_SHOWDATE, OnViewToggleDate)
71 ON_UPDATE_COMMAND_UI(ID_VIEW_SHOWDATE, OnUpdateViewToggleDate)
72 ON_COMMAND(ID_VIEW_FOLLOWRENAMES, OnViewToggleFollowRenames)
73 ON_UPDATE_COMMAND_UI(ID_VIEW_FOLLOWRENAMES, OnUpdateViewToggleFollowRenames)
74 ON_COMMAND(ID_BLAMEPOPUP_COPYHASHTOCLIPBOARD, CopyHashToClipboard)
75 ON_COMMAND(ID_BLAMEPOPUP_COPYLOGTOCLIPBOARD, CopySelectedLogToClipboard)
76 ON_COMMAND(ID_BLAMEPOPUP_BLAMEPREVIOUSREVISION, BlamePreviousRevision)
77 ON_COMMAND(ID_BLAMEPOPUP_DIFFPREVIOUS, DiffPreviousRevision)
78 ON_COMMAND(ID_BLAMEPOPUP_SHOWLOG, ShowLog)
79 ON_UPDATE_COMMAND_UI(ID_BLAMEPOPUP_BLAMEPREVIOUSREVISION, OnUpdateBlamePopupBlamePrevious)
80 ON_UPDATE_COMMAND_UI(ID_BLAMEPOPUP_DIFFPREVIOUS, OnUpdateBlamePopupDiffPrevious)
81 ON_COMMAND_RANGE(IDM_FORMAT_ENCODE, IDM_FORMAT_ENCODE_END, OnChangeEncode)
82 ON_WM_CREATE()
83 ON_WM_SIZE()
84 ON_WM_MOUSEMOVE()
85 ON_WM_MOUSEHOVER()
86 ON_WM_MOUSELEAVE()
87 ON_WM_LBUTTONDOWN()
88 ON_WM_RBUTTONDOWN()
89 ON_WM_RBUTTONUP()
90 ON_NOTIFY(SCN_PAINTED, IDC_SCINTILLA, OnSciPainted)
91 ON_NOTIFY(SCN_GETBKCOLOR, IDC_SCINTILLA, OnSciGetBkColor)
92 ON_REGISTERED_MESSAGE(m_FindDialogMessage, OnFindDialogMessage)
93 END_MESSAGE_MAP()
96 // CTortoiseGitBlameView construction/destruction
98 CTortoiseGitBlameView::CTortoiseGitBlameView()
100 hInstance = 0;
101 hResource = 0;
102 currentDialog = 0;
103 wMain = 0;
104 m_wEditor = 0;
105 wLocator = 0;
107 m_font = 0;
108 m_italicfont = 0;
109 m_blamewidth = 0;
110 m_revwidth = 0;
111 m_datewidth = 0;
112 m_authorwidth = 0;
113 m_linewidth = 0;
115 m_windowcolor = ::GetSysColor(COLOR_WINDOW);
116 m_textcolor = ::GetSysColor(COLOR_WINDOWTEXT);
117 m_texthighlightcolor = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
118 m_mouserevcolor = InterColor(m_windowcolor, m_textcolor, 20);
119 m_mouseauthorcolor = InterColor(m_windowcolor, m_textcolor, 10);
120 m_selectedrevcolor = ::GetSysColor(COLOR_HIGHLIGHT);
121 m_selectedauthorcolor = InterColor(m_selectedrevcolor, m_texthighlightcolor, 35);
122 m_mouserev = -2;
124 m_selectedrev = -1;
125 m_selectedorigrev = -1;
126 m_SelectedLine = -1;
127 m_directPointer = 0;
128 m_directFunction = 0;
130 m_lowestrev = LONG_MAX;
131 m_highestrev = 0;
132 m_colorage = true;
134 m_bShowLine=true;
136 m_bShowAuthor = (theApp.GetInt(_T("ShowAuthor"), 1) == 1);
137 m_bShowDate = (theApp.GetInt(_T("ShowDate"), 0) == 1);
138 m_bFollowRenames = (theApp.GetInt(_T("FollowRenames"), 0) == 1);
140 m_FindDialogMessage = ::RegisterWindowMessage(FINDMSGSTRING);
141 m_pFindDialog = NULL;
142 // get short/long datetime setting from registry
143 DWORD RegUseShortDateFormat = CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE);
144 if ( RegUseShortDateFormat )
146 m_DateFormat = DATE_SHORTDATE;
148 else
150 m_DateFormat = DATE_LONGDATE;
152 // get relative time display setting from registry
153 DWORD regRelativeTimes = CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE);
154 m_bRelativeTimes = (regRelativeTimes != 0);
156 m_sRev.LoadString(IDS_LOG_REVISION);
157 m_sAuthor.LoadString(IDS_LOG_AUTHOR);
158 m_sDate.LoadString(IDS_LOG_DATE);
159 m_sMessage.LoadString(IDS_LOG_MESSAGE);
161 m_Buffer = NULL;
164 CTortoiseGitBlameView::~CTortoiseGitBlameView()
166 if (m_font)
167 DeleteObject(m_font);
168 if (m_italicfont)
169 DeleteObject(m_italicfont);
171 if(m_Buffer)
173 delete m_Buffer;
174 m_Buffer=NULL;
177 struct EncodingUnit
179 int id;
180 char *name;
183 static EncodingUnit encodings[] = {
184 {1250, "windows-1250"}, //IDM_FORMAT_WIN_1250
185 {1251, "windows-1251"}, //IDM_FORMAT_WIN_1251
186 {1252, "windows-1252"}, //IDM_FORMAT_WIN_1252
187 {1253, "windows-1253"}, //IDM_FORMAT_WIN_1253
188 {1254, "windows-1254"}, //IDM_FORMAT_WIN_1254
189 {1255, "windows-1255"}, //IDM_FORMAT_WIN_1255
190 {1256, "windows-1256"}, //IDM_FORMAT_WIN_1256
191 {1257, "windows-1257"}, //IDM_FORMAT_WIN_1257
192 {1258, "windows-1258"}, //IDM_FORMAT_WIN_1258
193 {28591, "latin1 ISO_8859-1 ISO-8859-1 CP819 IBM819 csISOLatin1 iso-ir-100 l1"}, //IDM_FORMAT_ISO_8859_1
194 {28592, "latin2 ISO_8859-2 ISO-8859-2 csISOLatin2 iso-ir-101 l2"}, //IDM_FORMAT_ISO_8859_2
195 {28593, "latin3 ISO_8859-3 ISO-8859-3 csISOLatin3 iso-ir-109 l3"}, //IDM_FORMAT_ISO_8859_3
196 {28594, "latin4 ISO_8859-4 ISO-8859-4 csISOLatin4 iso-ir-110 l4"}, //IDM_FORMAT_ISO_8859_4
197 {28595, "cyrillic ISO_8859-5 ISO-8859-5 csISOLatinCyrillic iso-ir-144"}, //IDM_FORMAT_ISO_8859_5
198 {28596, "arabic ISO_8859-6 ISO-8859-6 csISOLatinArabic iso-ir-127 ASMO-708 ECMA-114"}, //IDM_FORMAT_ISO_8859_6
199 {28597, "greek ISO_8859-7 ISO-8859-7 csISOLatinGreek greek8 iso-ir-126 ELOT_928 ECMA-118"}, //IDM_FORMAT_ISO_8859_7
200 {28598, "hebrew ISO_8859-8 ISO-8859-8 csISOLatinHebrew iso-ir-138"}, //IDM_FORMAT_ISO_8859_8
201 {28599, "latin5 ISO_8859-9 ISO-8859-9 csISOLatin5 iso-ir-148 l5"}, //IDM_FORMAT_ISO_8859_9
202 {28600, "latin6 ISO_8859-10 ISO-8859-10 csISOLatin6 iso-ir-157 l6"}, //IDM_FORMAT_ISO_8859_10
203 {28601, "ISO_8859-11 ISO-8859-11"}, //IDM_FORMAT_ISO_8859_11
204 {28603, "ISO_8859-13 ISO-8859-13"}, //IDM_FORMAT_ISO_8859_13
205 {28604, "iso-celtic latin8 ISO_8859-14 ISO-8859-14 18 iso-ir-199"}, //IDM_FORMAT_ISO_8859_14
206 {28605, "Latin-9 ISO_8859-15 ISO-8859-15"}, //IDM_FORMAT_ISO_8859_15
207 {28606, "latin10 ISO_8859-16 ISO-8859-16 110 iso-ir-226"}, //IDM_FORMAT_ISO_8859_16
208 {437, "IBM437 cp437 437 csPC8CodePage437"}, //IDM_FORMAT_DOS_437
209 {720, "IBM720 cp720 oem720 720"}, //IDM_FORMAT_DOS_720
210 {737, "IBM737 cp737 oem737 737"}, //IDM_FORMAT_DOS_737
211 {775, "IBM775 cp775 oem775 775"}, //IDM_FORMAT_DOS_775
212 {850, "IBM850 cp850 oem850 850"}, //IDM_FORMAT_DOS_850
213 {852, "IBM852 cp852 oem852 852"}, //IDM_FORMAT_DOS_852
214 {855, "IBM855 cp855 oem855 855 csIBM855"}, //IDM_FORMAT_DOS_855
215 {857, "IBM857 cp857 oem857 857"}, //IDM_FORMAT_DOS_857
216 {858, "IBM858 cp858 oem858 858"}, //IDM_FORMAT_DOS_858
217 {860, "IBM860 cp860 oem860 860"}, //IDM_FORMAT_DOS_860
218 {861, "IBM861 cp861 oem861 861"}, //IDM_FORMAT_DOS_861
219 {862, "IBM862 cp862 oem862 862"}, //IDM_FORMAT_DOS_862
220 {863, "IBM863 cp863 oem863 863"}, //IDM_FORMAT_DOS_863
221 {865, "IBM865 cp865 oem865 865"}, //IDM_FORMAT_DOS_865
222 {866, "IBM866 cp866 oem866 866"}, //IDM_FORMAT_DOS_866
223 {869, "IBM869 cp869 oem869 869"}, //IDM_FORMAT_DOS_869
224 {950, "big5 csBig5"}, //IDM_FORMAT_BIG5
225 {936, "gb2312 gbk csGB2312"}, //IDM_FORMAT_GB2312
226 {932, "Shift_JIS MS_Kanji csShiftJIS csWindows31J"}, //IDM_FORMAT_SHIFT_JIS
227 {949, "windows-949 korean"}, //IDM_FORMAT_KOREAN_WIN
228 {51949, "euc-kr csEUCKR"}, //IDM_FORMAT_EUC_KR
229 {874, "tis-620"}, //IDM_FORMAT_TIS_620
230 {10007, "x-mac-cyrillic xmaccyrillic"}, //IDM_FORMAT_MAC_CYRILLIC
231 {21866, "koi8_u"}, //IDM_FORMAT_KOI8U_CYRILLIC
232 {20866, "koi8_r csKOI8R"}, //IDM_FORMAT_KOI8R_CYRILLIC
233 {65001, "UTF-8"}, //IDM_FORMAT_UTF8
234 {1200, "UTF-16 LE"}, //IDM_FORMAT_UTF16LE
235 {1201, "UTF-16 BE"}, //IDM_FORMAT_UTF16BE
237 void CTortoiseGitBlameView::OnChangeEncode(UINT nId)
239 if(nId >= IDM_FORMAT_ENCODE && nId <= IDM_FORMAT_ENCODE_END)
240 this->UpdateInfo(encodings[nId - IDM_FORMAT_ENCODE].id);
242 int CTortoiseGitBlameView::OnCreate(LPCREATESTRUCT lpcs)
245 CRect rect,rect1;
246 this->GetWindowRect(&rect1);
247 rect.left=m_blamewidth+LOCATOR_WIDTH;
248 rect.right=rect.Width();
249 rect.top=0;
250 rect.bottom=rect.Height();
251 if (!m_TextView.Create(_T("Scintilla"), _T("source"), 0, rect, this, IDC_SCINTILLA, 0))
253 TRACE0("Failed to create view\n");
254 return -1; // fail to create
256 m_TextView.Init(0,FALSE);
257 m_TextView.ShowWindow( SW_SHOW);
258 m_wEditor = m_TextView.m_hWnd;
259 CreateFont();
260 InitialiseEditor();
261 m_ToolTip.Create(this->GetParent());
263 ::AfxGetApp()->GetMainWnd();
264 return CView::OnCreate(lpcs);
268 void CTortoiseGitBlameView::OnSize(UINT /*nType*/, int cx, int cy)
271 CRect rect;
272 rect.left=m_blamewidth;
273 rect.right=cx;
274 rect.top=0;
275 rect.bottom=cy;
277 m_TextView.MoveWindow(&rect);
280 BOOL CTortoiseGitBlameView::PreCreateWindow(CREATESTRUCT& cs)
282 return CView::PreCreateWindow(cs);
285 // CTortoiseGitBlameView drawing
287 void CTortoiseGitBlameView::OnDraw(CDC* /*pDC*/)
289 CTortoiseGitBlameDoc* pDoc = GetDocument();
290 ASSERT_VALID(pDoc);
291 if (!pDoc)
292 return;
294 DrawBlame(this->GetDC()->m_hDC);
295 DrawLocatorBar(this->GetDC()->m_hDC);
296 // TODO: add draw code for native data here
300 // CTortoiseGitBlameView printing
303 void CTortoiseGitBlameView::OnFilePrintPreview()
305 AFXPrintPreview(this);
308 BOOL CTortoiseGitBlameView::OnPreparePrinting(CPrintInfo* pInfo)
310 // default preparation
311 return DoPreparePrinting(pInfo);
314 void CTortoiseGitBlameView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
316 // TODO: add extra initialization before printing
319 void CTortoiseGitBlameView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
321 // TODO: add cleanup after printing
324 void CTortoiseGitBlameView::OnRButtonUp(UINT /*nFlags*/, CPoint point)
326 LONG_PTR line = SendEditor(SCI_GETFIRSTVISIBLELINE);
327 LONG_PTR height = SendEditor(SCI_TEXTHEIGHT);
328 line = line + (point.y/height);
329 if (line < (LONG)m_CommitHash.size())
331 if(m_ID[line] >= 0) // only show context menu if we have log data for it
333 m_MouseLine = (LONG)line;
334 ClientToScreen(&point);
335 theApp.GetContextMenuManager()->ShowPopupMenu(IDR_BLAME_POPUP, point.x, point.y, this, TRUE);
340 void CTortoiseGitBlameView::OnUpdateBlamePopupBlamePrevious(CCmdUI *pCmdUI)
342 if (m_ID[m_MouseLine] <= 1)
344 pCmdUI->Enable(false);
346 else
348 pCmdUI->Enable(true);
352 void CTortoiseGitBlameView::OnUpdateBlamePopupDiffPrevious(CCmdUI *pCmdUI)
354 if (m_ID[m_MouseLine] <= 1)
356 pCmdUI->Enable(false);
358 else
360 pCmdUI->Enable(true);
364 void CTortoiseGitBlameView::CopyHashToClipboard()
366 this->GetLogList()->CopySelectionToClipBoard(CGitLogListBase::ID_COPY_HASH);
369 // CTortoiseGitBlameView diagnostics
371 #ifdef _DEBUG
372 void CTortoiseGitBlameView::AssertValid() const
374 CView::AssertValid();
377 void CTortoiseGitBlameView::Dump(CDumpContext& dc) const
379 CView::Dump(dc);
382 CTortoiseGitBlameDoc* CTortoiseGitBlameView::GetDocument() const // non-debug version is inline
384 ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTortoiseGitBlameDoc)));
385 return (CTortoiseGitBlameDoc*)m_pDocument;
387 #endif //_DEBUG
390 // CTortoiseGitBlameView message handlers
391 CString CTortoiseGitBlameView::GetAppDirectory()
393 CString path;
394 DWORD len = 0;
395 DWORD bufferlen = MAX_PATH; // MAX_PATH is not the limit here!
398 bufferlen += MAX_PATH; // MAX_PATH is not the limit here!
399 std::unique_ptr<TCHAR[]> pBuf(new TCHAR[bufferlen]);
400 len = GetModuleFileName(NULL, pBuf.get(), bufferlen);
401 path = CString(pBuf.get(), len);
402 } while(len == bufferlen);
404 path = path.Left(path.ReverseFind(_T('\\')));
405 //path = path.substr(0, path.rfind('\\') + 1);
407 return path;
410 // Return a color which is interpolated between c1 and c2.
411 // Slider controls the relative proportions as a percentage:
412 // Slider = 0 represents pure c1
413 // Slider = 50 represents equal mixture
414 // Slider = 100 represents pure c2
415 COLORREF CTortoiseGitBlameView::InterColor(COLORREF c1, COLORREF c2, int Slider)
417 int r, g, b;
419 // Limit Slider to 0..100% range
420 if (Slider < 0)
421 Slider = 0;
422 if (Slider > 100)
423 Slider = 100;
425 // The color components have to be treated individually.
426 r = (GetRValue(c2) * Slider + GetRValue(c1) * (100 - Slider)) / 100;
427 g = (GetGValue(c2) * Slider + GetGValue(c1) * (100 - Slider)) / 100;
428 b = (GetBValue(c2) * Slider + GetBValue(c1) * (100 - Slider)) / 100;
430 return RGB(r, g, b);
433 LRESULT CTortoiseGitBlameView::SendEditor(UINT Msg, WPARAM wParam, LPARAM lParam)
435 if (m_directFunction)
437 return ((SciFnDirect) m_directFunction)(m_directPointer, Msg, wParam, lParam);
439 return ::SendMessage(m_wEditor, Msg, wParam, lParam);
442 void CTortoiseGitBlameView::SetAStyle(int style, COLORREF fore, COLORREF back, int size, CString *face)
444 SendEditor(SCI_STYLESETFORE, style, fore);
445 SendEditor(SCI_STYLESETBACK, style, back);
446 if (size >= 1)
447 SendEditor(SCI_STYLESETSIZE, style, size);
448 if (face)
449 SendEditor(SCI_STYLESETFONT, style, reinterpret_cast<LPARAM>(this->m_TextView.StringForControl(*face).GetBuffer()));
452 void CTortoiseGitBlameView::InitialiseEditor()
455 m_directFunction = ::SendMessage(m_wEditor, SCI_GETDIRECTFUNCTION, 0, 0);
456 m_directPointer = ::SendMessage(m_wEditor, SCI_GETDIRECTPOINTER, 0, 0);
457 // Set up the global default style. These attributes are used wherever no explicit choices are made.
458 CString fontName(((stdstring)CRegStdString(_T("Software\\TortoiseGit\\BlameFontName"), _T("Courier New"))).c_str());
459 SetAStyle(STYLE_DEFAULT,
460 black,
461 white,
462 (DWORD)CRegStdDWORD(_T("Software\\TortoiseGit\\BlameFontSize"), 10),
463 &fontName
465 SendEditor(SCI_SETTABWIDTH, (DWORD)CRegStdDWORD(_T("Software\\TortoiseGit\\BlameTabSize"), 4));
466 SendEditor(SCI_SETREADONLY, TRUE);
467 LRESULT pix = SendEditor(SCI_TEXTWIDTH, STYLE_LINENUMBER, (LPARAM)this->m_TextView.StringForControl(_T("_99999")).GetBuffer());
468 if (m_bShowLine)
469 SendEditor(SCI_SETMARGINWIDTHN, 0, pix);
470 else
471 SendEditor(SCI_SETMARGINWIDTHN, 0);
472 SendEditor(SCI_SETMARGINWIDTHN, 1);
473 SendEditor(SCI_SETMARGINWIDTHN, 2);
474 //Set the default windows colors for edit controls
475 SendEditor(SCI_STYLESETFORE, STYLE_DEFAULT, ::GetSysColor(COLOR_WINDOWTEXT));
476 SendEditor(SCI_STYLESETBACK, STYLE_DEFAULT, ::GetSysColor(COLOR_WINDOW));
477 SendEditor(SCI_SETSELFORE, TRUE, ::GetSysColor(COLOR_HIGHLIGHTTEXT));
478 SendEditor(SCI_SETSELBACK, TRUE, ::GetSysColor(COLOR_HIGHLIGHT));
479 SendEditor(SCI_SETCARETFORE, ::GetSysColor(COLOR_WINDOWTEXT));
480 m_regOldLinesColor = CRegStdDWORD(_T("Software\\TortoiseGit\\BlameOldColor"), RGB(230, 230, 255));
481 m_regNewLinesColor = CRegStdDWORD(_T("Software\\TortoiseGit\\BlameNewColor"), RGB(255, 230, 230));
482 CRegStdDWORD used2d(L"Software\\TortoiseGit\\ScintillaDirect2D", FALSE);
483 if (SysInfo::Instance().IsWin7OrLater() && DWORD(used2d))
485 SendEditor(SCI_SETTECHNOLOGY, SC_TECHNOLOGY_DIRECTWRITE);
486 SendEditor(SCI_SETBUFFEREDDRAW, 0);
488 SendEditor(SCI_SETFONTQUALITY, SC_EFF_QUALITY_DEFAULT);
490 this->m_TextView.Call(SCI_SETWRAPMODE, SC_WRAP_NONE);
494 bool CTortoiseGitBlameView::DoSearch(CString what, DWORD flags)
496 int pos = (int)SendEditor(SCI_GETCURRENTPOS);
497 int line = (int)SendEditor(SCI_LINEFROMPOSITION, pos);
498 bool bFound = false;
499 bool bCaseSensitive = !!(flags & FR_MATCHCASE);
501 if(!bCaseSensitive)
502 what.MakeLower();
504 int i=line;
505 if(i >= (signed int)m_CommitHash.size())
506 i = 0;
509 int bufsize = (int)SendEditor(SCI_GETLINE, i);
510 char * linebuf = new char[bufsize+1];
511 SecureZeroMemory(linebuf, bufsize+1);
512 SendEditor(SCI_GETLINE, i, (LPARAM)linebuf);
513 CString oneline=this->m_TextView.StringFromControl(linebuf);
514 delete [] linebuf;
515 if (!bCaseSensitive)
517 CString lcAuthor = m_Authors[i];
518 if (lcAuthor.MakeLower().Find(what) >= 0)
519 bFound = true;
520 else if (oneline.MakeLower().Find(what) >=0)
521 bFound = true;
523 else if (m_Authors[i].Find(what) >= 0)
524 bFound = true;
525 else if (oneline.Find(what) >=0)
526 bFound = true;
528 ++i;
529 if(!bFound && i >= (signed int)m_CommitHash.size())
530 i=0;
531 }while(i!=line &&(!bFound));
533 if (bFound)
535 GotoLine(i);
536 int selstart = (int)SendEditor(SCI_GETCURRENTPOS);
537 int selend = (int)SendEditor(SCI_POSITIONFROMLINE, i);
538 SendEditor(SCI_SETSELECTIONSTART, selstart);
539 SendEditor(SCI_SETSELECTIONEND, selend);
540 m_SelectedLine = i-1;
542 else
544 ::MessageBox(wMain, _T("\"") + what + _T("\" ") + CString(MAKEINTRESOURCE(IDS_NOTFOUND)), _T("TortoiseGitBlame"), MB_ICONINFORMATION);
547 return true;
550 bool CTortoiseGitBlameView::GotoLine(long line)
552 --line;
553 if (line < 0)
554 return false;
555 if ((unsigned long)line >= m_CommitHash.size())
557 line = (long)m_CommitHash.size()-1;
560 int nCurrentPos = (int)SendEditor(SCI_GETCURRENTPOS);
561 int nCurrentLine = (int)SendEditor(SCI_LINEFROMPOSITION,nCurrentPos);
562 int nFirstVisibleLine = (int)SendEditor(SCI_GETFIRSTVISIBLELINE);
563 int nLinesOnScreen = (int)SendEditor(SCI_LINESONSCREEN);
565 if ( line>=nFirstVisibleLine && line<=nFirstVisibleLine+nLinesOnScreen)
567 // no need to scroll
568 SendEditor(SCI_GOTOLINE, line);
570 else
572 // Place the requested line one third from the top
573 if ( line > nCurrentLine )
575 SendEditor(SCI_GOTOLINE, (WPARAM)(line+(int)nLinesOnScreen*(2/3.0)));
577 else
579 SendEditor(SCI_GOTOLINE, (WPARAM)(line-(int)nLinesOnScreen*(1/3.0)));
583 // Highlight the line
584 int nPosStart = (int)SendEditor(SCI_POSITIONFROMLINE,line);
585 int nPosEnd = (int)SendEditor(SCI_GETLINEENDPOSITION,line);
586 SendEditor(SCI_SETSEL,nPosEnd,nPosStart);
588 return true;
591 bool CTortoiseGitBlameView::ScrollToLine(long line)
593 if (line < 0)
594 return false;
596 int nCurrentLine = (int)SendEditor(SCI_GETFIRSTVISIBLELINE);
598 int scrolldelta = line - nCurrentLine;
599 SendEditor(SCI_LINESCROLL, 0, scrolldelta);
601 return true;
604 void CTortoiseGitBlameView::CopyToClipboard()
606 CWnd * wnd = GetFocus();
607 if (wnd == this->GetLogList())
608 CopySelectedLogToClipboard();
609 else if (wnd)
611 if (CString(wnd->GetRuntimeClass()->m_lpszClassName) == _T("CMFCPropertyGridCtrl"))
613 CMFCPropertyGridCtrl *grid = (CMFCPropertyGridCtrl *)wnd;
614 if (grid->GetCurSel() && !grid->GetCurSel()->IsGroup())
615 CStringUtils::WriteAsciiStringToClipboard(grid->GetCurSel()->GetValue(), GetSafeHwnd());
617 else
618 m_TextView.Call(SCI_COPY);
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::RunTortoiseGitProc(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::RunTortoiseGitProc(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::RunTortoiseGitProc(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 CString shortHash('f', g_Git.GetShortHASHLength() + 1);
670 ::GetTextExtentPoint32(hDC, shortHash, g_Git.GetShortHASHLength() + 1, &width);
671 m_revwidth = width.cx + BLAMESPACE;
672 blamewidth += m_revwidth;
674 if (m_bShowDate)
676 SIZE maxwidth = {0};
678 for (size_t i = 0; i < this->m_Dates.size(); ++i)
680 ::GetTextExtentPoint32(hDC, m_Dates[i] , m_Dates[i].GetLength(), &width);
681 if (width.cx > maxwidth.cx)
682 maxwidth = width;
684 m_datewidth = maxwidth.cx + BLAMESPACE;
685 blamewidth += m_datewidth;
687 if ( m_bShowAuthor)
689 SIZE maxwidth = {0};
691 for (unsigned int i = 0; i < this->m_Authors.size(); ++i)
693 ::GetTextExtentPoint32(hDC,m_Authors[i] , m_Authors[i].GetLength(), &width);
694 if (width.cx > maxwidth.cx)
695 maxwidth = width;
697 m_authorwidth = maxwidth.cx + BLAMESPACE;
698 blamewidth += m_authorwidth;
700 ::SelectObject(hDC, oldfont);
701 POINT pt = {blamewidth, 0};
702 LPtoDP(hDC, &pt, 1);
703 m_blamewidth = pt.x;
704 //::ReleaseDC(wBlame, hDC);
705 return blamewidth;
709 void CTortoiseGitBlameView::CreateFont()
711 if (m_font)
712 return;
713 LOGFONT lf = {0};
714 lf.lfWeight = 400;
715 HDC hDC = ::GetDC(wBlame);
716 lf.lfHeight = -MulDiv((DWORD)CRegStdDWORD(_T("Software\\TortoiseGit\\BlameFontSize"), 10), GetDeviceCaps(hDC, LOGPIXELSY), 72);
717 lf.lfCharSet = DEFAULT_CHARSET;
718 CRegStdString fontname = CRegStdString(_T("Software\\TortoiseGit\\BlameFontName"), _T("Courier New"));
719 _tcscpy_s(lf.lfFaceName, 32, ((stdstring)fontname).c_str());
720 m_font = ::CreateFontIndirect(&lf);
722 lf.lfItalic = TRUE;
723 m_italicfont = ::CreateFontIndirect(&lf);
725 ::ReleaseDC(wBlame, hDC);
728 void CTortoiseGitBlameView::DrawBlame(HDC hDC)
730 if (hDC == NULL)
731 return;
732 if (m_font == NULL)
733 return;
735 HFONT oldfont = NULL;
736 LONG_PTR line = SendEditor(SCI_GETFIRSTVISIBLELINE);
737 LONG_PTR linesonscreen = SendEditor(SCI_LINESONSCREEN);
738 LONG_PTR height = SendEditor(SCI_TEXTHEIGHT);
739 LONG_PTR Y = 0;
740 TCHAR buf[MAX_PATH];
741 RECT rc;
742 BOOL sel = FALSE;
743 //::GetClientRect(this->m_hWnd, &rc);
744 for (LRESULT i=line; i<(line+linesonscreen); ++i)
746 sel = FALSE;
747 if (i < (int)m_CommitHash.size())
749 // if (mergelines[i])
750 // oldfont = (HFONT)::SelectObject(hDC, m_italicfont);
751 // else
752 oldfont = (HFONT)::SelectObject(hDC, m_font);
753 ::SetBkColor(hDC, m_windowcolor);
754 ::SetTextColor(hDC, m_textcolor);
755 if (!m_CommitHash[i].IsEmpty())
757 //if (m_CommitHash[i].Compare(m_MouseHash)==0)
758 // ::SetBkColor(hDC, m_mouseauthorcolor);
759 if (m_CommitHash[i] == m_SelectedHash )
761 ::SetBkColor(hDC, m_selectedauthorcolor);
762 ::SetTextColor(hDC, m_texthighlightcolor);
763 sel = TRUE;
767 if(m_MouseLine == i)
768 ::SetBkColor(hDC, m_mouserevcolor);
770 //if ((revs[i] == m_mouserev)&&(!sel))
771 // ::SetBkColor(hDC, m_mouserevcolor);
772 //if (revs[i] == m_selectedrev)
774 // ::SetBkColor(hDC, m_selectedrevcolor);
775 // ::SetTextColor(hDC, m_texthighlightcolor);
778 CString str;
779 str = m_CommitHash[i].ToString().Left(g_Git.GetShortHASHLength());
781 //_stprintf_s(buf, MAX_PATH, _T("%8ld "), revs[i]);
782 rc.top = (LONG)Y;
783 rc.left=LOCATOR_WIDTH;
784 rc.bottom = (LONG)(Y + height);
785 rc.right = rc.left + m_blamewidth;
786 ::ExtTextOut(hDC, LOCATOR_WIDTH, (int)Y, ETO_CLIPPED, &rc, str, str.GetLength(), 0);
787 int Left = m_revwidth;
789 if (m_bShowAuthor)
791 rc.right = rc.left + Left + m_authorwidth;
792 ::ExtTextOut(hDC, Left, (int)Y, ETO_CLIPPED, &rc, m_Authors[i], m_Authors[i].GetLength(), 0);
793 Left += m_authorwidth;
795 if (m_bShowDate)
797 rc.right = rc.left + Left + m_datewidth;
798 ::ExtTextOut(hDC, Left, (int)Y, ETO_CLIPPED, &rc, m_Dates[i], m_Dates[i].GetLength(), 0);
799 Left += m_datewidth;
801 if ((i==m_SelectedLine)&&(m_pFindDialog))
803 LOGBRUSH brush;
804 brush.lbColor = m_textcolor;
805 brush.lbHatch = 0;
806 brush.lbStyle = BS_SOLID;
807 HPEN pen = ExtCreatePen(PS_SOLID | PS_GEOMETRIC, 2, &brush, 0, NULL);
808 HGDIOBJ hPenOld = SelectObject(hDC, pen);
809 RECT rc2 = rc;
810 rc2.top = (LONG)Y;
811 rc2.bottom = (LONG)(Y + height);
812 ::MoveToEx(hDC, rc2.left, rc2.top, NULL);
813 ::LineTo(hDC, rc2.right, rc2.top);
814 ::LineTo(hDC, rc2.right, rc2.bottom);
815 ::LineTo(hDC, rc2.left, rc2.bottom);
816 ::LineTo(hDC, rc2.left, rc2.top);
817 SelectObject(hDC, hPenOld);
818 DeleteObject(pen);
820 Y += height;
821 ::SelectObject(hDC, oldfont);
823 else
825 ::SetBkColor(hDC, m_windowcolor);
826 for (int j=0; j< MAX_PATH; ++j)
827 buf[j]=' ';
828 ::ExtTextOut(hDC, 0, (int)Y, ETO_CLIPPED, &rc, buf, MAX_PATH-1, 0);
829 Y += height;
834 void CTortoiseGitBlameView::DrawLocatorBar(HDC hDC)
836 if (hDC == NULL)
837 return;
839 LONG_PTR line = SendEditor(SCI_GETFIRSTVISIBLELINE);
840 LONG_PTR linesonscreen = SendEditor(SCI_LINESONSCREEN);
841 LONG_PTR Y = 0;
842 COLORREF blackColor = GetSysColor(COLOR_WINDOWTEXT);
844 RECT rc;
845 //::GetClientRect(wLocator, &rc);
846 this->GetClientRect(&rc);
848 rc.right=LOCATOR_WIDTH;
850 RECT lineRect = rc;
851 LONG height = rc.bottom-rc.top;
852 LONG currentLine = 0;
854 // draw the colored bar
855 for (std::vector<LONG>::const_iterator it = m_ID.begin(); it != m_ID.end(); ++it)
857 ++currentLine;
858 // get the line color
859 COLORREF cr = InterColor(DWORD(m_regOldLinesColor), DWORD(m_regNewLinesColor), (*it - m_lowestrev)*100/((m_highestrev-m_lowestrev)+1));
860 if ((currentLine > line)&&(currentLine <= (line + linesonscreen)))
862 cr = InterColor(cr, blackColor, 10);
864 SetBkColor(hDC, cr);
865 lineRect.top = (LONG)Y;
866 lineRect.bottom = (currentLine * height / (LONG)m_ID.size());
867 ::ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &lineRect, NULL, 0, NULL);
868 Y = lineRect.bottom;
871 if (!m_ID.empty())
873 // now draw two lines indicating the scroll position of the source view
874 SetBkColor(hDC, blackColor);
875 lineRect.top = (LONG)line * height / (LONG)m_ID.size();
876 lineRect.bottom = lineRect.top+1;
877 ::ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &lineRect, NULL, 0, NULL);
878 lineRect.top = (LONG)(line + linesonscreen) * height / (LONG)m_ID.size();
879 lineRect.bottom = lineRect.top+1;
880 ::ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &lineRect, NULL, 0, NULL);
885 void CTortoiseGitBlameView::StringExpand(LPSTR str)
887 char * cPos = str;
890 cPos = strchr(cPos, '\n');
891 if (cPos)
893 memmove(cPos+1, cPos, strlen(cPos)*sizeof(char));
894 *cPos = '\r';
895 ++cPos;
896 ++cPos;
898 } while (cPos != NULL);
900 void CTortoiseGitBlameView::StringExpand(LPWSTR str)
902 wchar_t * cPos = str;
905 cPos = wcschr(cPos, '\n');
906 if (cPos)
908 memmove(cPos+1, cPos, wcslen(cPos)*sizeof(wchar_t));
909 *cPos = '\r';
910 ++cPos;
911 ++cPos;
913 } while (cPos != NULL);
916 void CTortoiseGitBlameView::SetupLexer(CString filename)
919 TCHAR *line;
920 //const char * lineptr = _tcsrchr(filename, '.');
921 int start=filename.ReverseFind(_T('.'));
922 if (start>0)
924 //_tcscpy_s(line, 20, lineptr+1);
925 //_tcslwr_s(line, 20);
926 CString ext=filename.Right(filename.GetLength()-start-1);
927 line=ext.GetBuffer();
929 if ((_tcscmp(line, _T("py"))==0)||
930 (_tcscmp(line, _T("pyw"))==0))
932 SendEditor(SCI_SETLEXER, SCLEX_PYTHON);
933 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("and assert break class continue def del elif \
934 else except exec finally for from global if import in is lambda None \
935 not or pass print raise return try while yield")).GetBuffer()));
936 SetAStyle(SCE_P_DEFAULT, black);
937 SetAStyle(SCE_P_COMMENTLINE, darkGreen);
938 SetAStyle(SCE_P_NUMBER, RGB(0, 0x80, 0x80));
939 SetAStyle(SCE_P_STRING, RGB(0, 0, 0x80));
940 SetAStyle(SCE_P_CHARACTER, RGB(0, 0, 0x80));
941 SetAStyle(SCE_P_WORD, RGB(0x80, 0, 0x80));
942 SetAStyle(SCE_P_TRIPLE, black);
943 SetAStyle(SCE_P_TRIPLEDOUBLE, black);
944 SetAStyle(SCE_P_CLASSNAME, darkBlue);
945 SetAStyle(SCE_P_DEFNAME, darkBlue);
946 SetAStyle(SCE_P_OPERATOR, darkBlue);
947 SetAStyle(SCE_P_IDENTIFIER, darkBlue);
948 SetAStyle(SCE_P_COMMENTBLOCK, darkGreen);
949 SetAStyle(SCE_P_STRINGEOL, red);
951 if ((_tcscmp(line, _T("c"))==0)||
952 (_tcscmp(line, _T("cc"))==0)||
953 (_tcscmp(line, _T("cpp"))==0)||
954 (_tcscmp(line, _T("cxx"))==0)||
955 (_tcscmp(line, _T("h"))==0)||
956 (_tcscmp(line, _T("hh"))==0)||
957 (_tcscmp(line, _T("hpp"))==0)||
958 (_tcscmp(line, _T("hxx"))==0)||
959 (_tcscmp(line, _T("dlg"))==0)||
960 (_tcscmp(line, _T("mak"))==0))
962 SendEditor(SCI_SETLEXER, SCLEX_CPP);
963 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("and and_eq asm auto bitand bitor bool break \
964 case catch char class compl const const_cast continue \
965 default delete do double dynamic_cast else enum explicit export extern false float for \
966 friend goto if inline int long mutable namespace new not not_eq \
967 operator or or_eq private protected public \
968 register reinterpret_cast return short signed sizeof static static_cast struct switch \
969 template this throw true try typedef typeid typename union unsigned using \
970 virtual void volatile wchar_t while xor xor_eq")).GetBuffer()));
971 SendEditor(SCI_SETKEYWORDS, 3, (LPARAM)(m_TextView.StringForControl(_T("a addindex addtogroup anchor arg attention \
972 author b brief bug c class code date def defgroup deprecated dontinclude \
973 e em endcode endhtmlonly endif endlatexonly endlink endverbatim enum example exception \
974 f$ f[ f] file fn hideinitializer htmlinclude htmlonly \
975 if image include ingroup internal invariant interface latexonly li line link \
976 mainpage name namespace nosubgrouping note overload \
977 p page par param post pre ref relates remarks return retval \
978 sa section see showinitializer since skip skipline struct subsection \
979 test throw todo typedef union until \
980 var verbatim verbinclude version warning weakgroup $ @ \\ & < > # { }")).GetBuffer()));
981 SetupCppLexer();
983 if (_tcscmp(line, _T("cs"))==0)
985 SendEditor(SCI_SETLEXER, SCLEX_CPP);
986 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("abstract as base bool break byte case catch char checked class \
987 const continue decimal default delegate do double else enum \
988 event explicit extern false finally fixed float for foreach goto if \
989 implicit in int interface internal is lock long namespace new null \
990 object operator out override params private protected public \
991 readonly ref return sbyte sealed short sizeof stackalloc static \
992 string struct switch this throw true try typeof uint ulong \
993 unchecked unsafe ushort using virtual void while")).GetBuffer()));
994 SetupCppLexer();
996 if ((_tcscmp(line, _T("rc"))==0)||
997 (_tcscmp(line, _T("rc2"))==0))
999 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1000 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("ACCELERATORS ALT AUTO3STATE AUTOCHECKBOX AUTORADIOBUTTON \
1001 BEGIN BITMAP BLOCK BUTTON CAPTION CHARACTERISTICS CHECKBOX CLASS \
1002 COMBOBOX CONTROL CTEXT CURSOR DEFPUSHBUTTON DIALOG DIALOGEX DISCARDABLE \
1003 EDITTEXT END EXSTYLE FONT GROUPBOX ICON LANGUAGE LISTBOX LTEXT \
1004 MENU MENUEX MENUITEM MESSAGETABLE POPUP \
1005 PUSHBUTTON RADIOBUTTON RCDATA RTEXT SCROLLBAR SEPARATOR SHIFT STATE3 \
1006 STRINGTABLE STYLE TEXTINCLUDE VALUE VERSION VERSIONINFO VIRTKEY")).GetBuffer()));
1007 SetupCppLexer();
1009 if ((_tcscmp(line, _T("idl"))==0)||
1010 (_tcscmp(line, _T("odl"))==0))
1012 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1013 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("aggregatable allocate appobject arrays async async_uuid \
1014 auto_handle \
1015 bindable boolean broadcast byte byte_count \
1016 call_as callback char coclass code comm_status \
1017 const context_handle context_handle_noserialize \
1018 context_handle_serialize control cpp_quote custom \
1019 decode default defaultbind defaultcollelem \
1020 defaultvalue defaultvtable dispinterface displaybind dllname \
1021 double dual \
1022 enable_allocate encode endpoint entry enum error_status_t \
1023 explicit_handle \
1024 fault_status first_is float \
1025 handle_t heap helpcontext helpfile helpstring \
1026 helpstringcontext helpstringdll hidden hyper \
1027 id idempotent ignore iid_as iid_is immediatebind implicit_handle \
1028 import importlib in include in_line int __int64 __int3264 interface \
1029 last_is lcid length_is library licensed local long \
1030 max_is maybe message methods midl_pragma \
1031 midl_user_allocate midl_user_free min_is module ms_union \
1032 ncacn_at_dsp ncacn_dnet_nsp ncacn_http ncacn_ip_tcp \
1033 ncacn_nb_ipx ncacn_nb_nb ncacn_nb_tcp ncacn_np \
1034 ncacn_spx ncacn_vns_spp ncadg_ip_udp ncadg_ipx ncadg_mq \
1035 ncalrpc nocode nonbrowsable noncreatable nonextensible notify \
1036 object odl oleautomation optimize optional out out_of_line \
1037 pipe pointer_default pragma properties propget propput propputref \
1038 ptr public \
1039 range readonly ref represent_as requestedit restricted retval \
1040 shape short signed size_is small source strict_context_handle \
1041 string struct switch switch_is switch_type \
1042 transmit_as typedef \
1043 uidefault union unique unsigned user_marshal usesgetlasterror uuid \
1044 v1_enum vararg version void wchar_t wire_marshal")).GetBuffer()));
1045 SetupCppLexer();
1047 if (_tcscmp(line, _T("java"))==0)
1049 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1050 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("abstract assert boolean break byte case catch char class \
1051 const continue default do double else extends final finally float for future \
1052 generic goto if implements import inner instanceof int interface long \
1053 native new null outer package private protected public rest \
1054 return short static super switch synchronized this throw throws \
1055 transient try var void volatile while")).GetBuffer()));
1056 SetupCppLexer();
1058 if (_tcscmp(line, _T("js"))==0)
1060 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1061 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("abstract boolean break byte case catch char class \
1062 const continue debugger default delete do double else enum export extends \
1063 final finally float for function goto if implements import in instanceof \
1064 int interface long native new package private protected public \
1065 return short static super switch synchronized this throw throws \
1066 transient try typeof var void volatile while with")).GetBuffer()));
1067 SetupCppLexer();
1069 if ((_tcscmp(line, _T("pas"))==0)||
1070 (_tcscmp(line, _T("dpr"))==0)||
1071 (_tcscmp(line, _T("pp"))==0))
1073 SendEditor(SCI_SETLEXER, SCLEX_PASCAL);
1074 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("and array as begin case class const constructor \
1075 destructor div do downto else end except file finally \
1076 for function goto if implementation in inherited \
1077 interface is mod not object of on or packed \
1078 procedure program property raise record repeat \
1079 set shl shr then threadvar to try type unit \
1080 until uses var while with xor")).GetBuffer()));
1081 SetupCppLexer();
1083 if ((_tcscmp(line, _T("as"))==0)||
1084 (_tcscmp(line, _T("asc"))==0)||
1085 (_tcscmp(line, _T("jsfl"))==0))
1087 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1088 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("add and break case catch class continue default delete do \
1089 dynamic else eq extends false finally for function ge get gt if implements import in \
1090 instanceof interface intrinsic le lt ne new not null or private public return \
1091 set static super switch this throw true try typeof undefined var void while with")).GetBuffer()));
1092 SendEditor(SCI_SETKEYWORDS, 1, (LPARAM)(m_TextView.StringForControl(_T("Array Arguments Accessibility Boolean Button Camera Color \
1093 ContextMenu ContextMenuItem Date Error Function Key LoadVars LocalConnection Math \
1094 Microphone Mouse MovieClip MovieClipLoader NetConnection NetStream Number Object \
1095 PrintJob Selection SharedObject Sound Stage String StyleSheet System TextField \
1096 TextFormat TextSnapshot Video Void XML XMLNode XMLSocket \
1097 _accProps _focusrect _global _highquality _parent _quality _root _soundbuftime \
1098 arguments asfunction call capabilities chr clearInterval duplicateMovieClip \
1099 escape eval fscommand getProperty getTimer getURL getVersion gotoAndPlay gotoAndStop \
1100 ifFrameLoaded Infinity -Infinity int isFinite isNaN length loadMovie loadMovieNum \
1101 loadVariables loadVariablesNum maxscroll mbchr mblength mbord mbsubstring MMExecute \
1102 NaN newline nextFrame nextScene on onClipEvent onUpdate ord parseFloat parseInt play \
1103 prevFrame prevScene print printAsBitmap printAsBitmapNum printNum random removeMovieClip \
1104 scroll set setInterval setProperty startDrag stop stopAllSounds stopDrag substring \
1105 targetPath tellTarget toggleHighQuality trace unescape unloadMovie unLoadMovieNum updateAfterEvent")).GetBuffer()));
1106 SetupCppLexer();
1108 if ((_tcscmp(line, _T("html"))==0)||
1109 (_tcscmp(line, _T("htm"))==0)||
1110 (_tcscmp(line, _T("shtml"))==0)||
1111 (_tcscmp(line, _T("htt"))==0)||
1112 (_tcscmp(line, _T("xml"))==0)||
1113 (_tcscmp(line, _T("asp"))==0)||
1114 (_tcscmp(line, _T("xsl"))==0)||
1115 (_tcscmp(line, _T("php"))==0)||
1116 (_tcscmp(line, _T("xhtml"))==0)||
1117 (_tcscmp(line, _T("phtml"))==0)||
1118 (_tcscmp(line, _T("cfm"))==0)||
1119 (_tcscmp(line, _T("tpl"))==0)||
1120 (_tcscmp(line, _T("dtd"))==0)||
1121 (_tcscmp(line, _T("hta"))==0)||
1122 (_tcscmp(line, _T("htd"))==0)||
1123 (_tcscmp(line, _T("wxs"))==0))
1125 SendEditor(SCI_SETLEXER, SCLEX_HTML);
1126 SendEditor(SCI_SETSTYLEBITS, 7);
1127 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("a abbr acronym address applet area b base basefont \
1128 bdo big blockquote body br button caption center \
1129 cite code col colgroup dd del dfn dir div dl dt em \
1130 fieldset font form frame frameset h1 h2 h3 h4 h5 h6 \
1131 head hr html i iframe img input ins isindex kbd label \
1132 legend li link map menu meta noframes noscript \
1133 object ol optgroup option p param pre q s samp \
1134 script select small span strike strong style sub sup \
1135 table tbody td textarea tfoot th thead title tr tt u ul \
1136 var xml xmlns abbr accept-charset accept accesskey action align alink \
1137 alt archive axis background bgcolor border \
1138 cellpadding cellspacing char charoff charset checked cite \
1139 class classid clear codebase codetype color cols colspan \
1140 compact content coords \
1141 data datafld dataformatas datapagesize datasrc datetime \
1142 declare defer dir disabled enctype event \
1143 face for frame frameborder \
1144 headers height href hreflang hspace http-equiv \
1145 id ismap label lang language leftmargin link longdesc \
1146 marginwidth marginheight maxlength media method multiple \
1147 name nohref noresize noshade nowrap \
1148 object onblur onchange onclick ondblclick onfocus \
1149 onkeydown onkeypress onkeyup onload onmousedown \
1150 onmousemove onmouseover onmouseout onmouseup \
1151 onreset onselect onsubmit onunload \
1152 profile prompt readonly rel rev rows rowspan rules \
1153 scheme scope selected shape size span src standby start style \
1154 summary tabindex target text title topmargin type usemap \
1155 valign value valuetype version vlink vspace width \
1156 text password checkbox radio submit reset \
1157 file hidden image")).GetBuffer()));
1158 SendEditor(SCI_SETKEYWORDS, 1, (LPARAM)(m_TextView.StringForControl(_T("assign audio block break catch choice clear disconnect else elseif \
1159 emphasis enumerate error exit field filled form goto grammar help \
1160 if initial link log menu meta noinput nomatch object option p paragraph \
1161 param phoneme prompt property prosody record reprompt return s say-as \
1162 script sentence subdialog submit throw transfer value var voice vxml")).GetBuffer()));
1163 SendEditor(SCI_SETKEYWORDS, 2, (LPARAM)(m_TextView.StringForControl(_T("accept age alphabet anchor application base beep bridge category charset \
1164 classid cond connecttimeout content contour count dest destexpr dtmf dtmfterm \
1165 duration enctype event eventexpr expr expritem fetchtimeout finalsilence \
1166 gender http-equiv id level maxage maxstale maxtime message messageexpr \
1167 method mime modal mode name namelist next nextitem ph pitch range rate \
1168 scope size sizeexpr skiplist slot src srcexpr sub time timeexpr timeout \
1169 transferaudio type value variant version volume xml:lang")).GetBuffer()));
1170 SendEditor(SCI_SETKEYWORDS, 3, (LPARAM)(m_TextView.StringForControl(_T("and assert break class continue def del elif \
1171 else except exec finally for from global if import in is lambda None \
1172 not or pass print raise return try while yield")).GetBuffer()));
1173 SendEditor(SCI_SETKEYWORDS, 4, (LPARAM)(m_TextView.StringForControl(_T("and argv as argc break case cfunction class continue declare default do \
1174 die echo else elseif empty enddeclare endfor endforeach endif endswitch \
1175 endwhile e_all e_parse e_error e_warning eval exit extends false for \
1176 foreach function global http_cookie_vars http_get_vars http_post_vars \
1177 http_post_files http_env_vars http_server_vars if include include_once \
1178 list new not null old_function or parent php_os php_self php_version \
1179 print require require_once return static switch stdclass this true var \
1180 xor virtual while __file__ __line__ __sleep __wakeup")).GetBuffer()));
1182 SetAStyle(SCE_H_TAG, darkBlue);
1183 SetAStyle(SCE_H_TAGUNKNOWN, red);
1184 SetAStyle(SCE_H_ATTRIBUTE, darkBlue);
1185 SetAStyle(SCE_H_ATTRIBUTEUNKNOWN, red);
1186 SetAStyle(SCE_H_NUMBER, RGB(0x80,0,0x80));
1187 SetAStyle(SCE_H_DOUBLESTRING, RGB(0,0x80,0));
1188 SetAStyle(SCE_H_SINGLESTRING, RGB(0,0x80,0));
1189 SetAStyle(SCE_H_OTHER, RGB(0x80,0,0x80));
1190 SetAStyle(SCE_H_COMMENT, RGB(0x80,0x80,0));
1191 SetAStyle(SCE_H_ENTITY, RGB(0x80,0,0x80));
1193 SetAStyle(SCE_H_TAGEND, darkBlue);
1194 SetAStyle(SCE_H_XMLSTART, darkBlue); // <?
1195 SetAStyle(SCE_H_QUESTION, darkBlue); // <?
1196 SetAStyle(SCE_H_XMLEND, darkBlue); // ?>
1197 SetAStyle(SCE_H_SCRIPT, darkBlue); // <script
1198 SetAStyle(SCE_H_ASP, RGB(0x4F, 0x4F, 0), RGB(0xFF, 0xFF, 0)); // <% ... %>
1199 SetAStyle(SCE_H_ASPAT, RGB(0x4F, 0x4F, 0), RGB(0xFF, 0xFF, 0)); // <%@ ... %>
1201 SetAStyle(SCE_HB_DEFAULT, black);
1202 SetAStyle(SCE_HB_COMMENTLINE, darkGreen);
1203 SetAStyle(SCE_HB_NUMBER, RGB(0,0x80,0x80));
1204 SetAStyle(SCE_HB_WORD, darkBlue);
1205 SendEditor(SCI_STYLESETBOLD, SCE_HB_WORD, 1);
1206 SetAStyle(SCE_HB_STRING, RGB(0x80,0,0x80));
1207 SetAStyle(SCE_HB_IDENTIFIER, black);
1209 // This light blue is found in the windows system palette so is safe to use even in 256 colour modes.
1210 // Show the whole section of VBScript with light blue background
1211 for (int bstyle = SCE_HB_DEFAULT; bstyle <= SCE_HB_STRINGEOL; ++bstyle) {
1212 SendEditor(SCI_STYLESETFONT, bstyle,
1213 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
1214 SendEditor(SCI_STYLESETBACK, bstyle, lightBlue);
1215 // This call extends the backround colour of the last style on the line to the edge of the window
1216 SendEditor(SCI_STYLESETEOLFILLED, bstyle, 1);
1218 SendEditor(SCI_STYLESETBACK, SCE_HB_STRINGEOL, RGB(0x7F,0x7F,0xFF));
1219 SendEditor(SCI_STYLESETFONT, SCE_HB_COMMENTLINE,
1220 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
1222 SetAStyle(SCE_HBA_DEFAULT, black);
1223 SetAStyle(SCE_HBA_COMMENTLINE, darkGreen);
1224 SetAStyle(SCE_HBA_NUMBER, RGB(0,0x80,0x80));
1225 SetAStyle(SCE_HBA_WORD, darkBlue);
1226 SendEditor(SCI_STYLESETBOLD, SCE_HBA_WORD, 1);
1227 SetAStyle(SCE_HBA_STRING, RGB(0x80,0,0x80));
1228 SetAStyle(SCE_HBA_IDENTIFIER, black);
1230 // Show the whole section of ASP VBScript with bright yellow background
1231 for (int bastyle = SCE_HBA_DEFAULT; bastyle <= SCE_HBA_STRINGEOL; ++bastyle) {
1232 SendEditor(SCI_STYLESETFONT, bastyle,
1233 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
1234 SendEditor(SCI_STYLESETBACK, bastyle, RGB(0xFF, 0xFF, 0));
1235 // This call extends the backround colour of the last style on the line to the edge of the window
1236 SendEditor(SCI_STYLESETEOLFILLED, bastyle, 1);
1238 SendEditor(SCI_STYLESETBACK, SCE_HBA_STRINGEOL, RGB(0xCF,0xCF,0x7F));
1239 SendEditor(SCI_STYLESETFONT, SCE_HBA_COMMENTLINE,
1240 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
1242 // If there is no need to support embedded Javascript, the following code can be dropped.
1243 // Javascript will still be correctly processed but will be displayed in just the default style.
1245 SetAStyle(SCE_HJ_START, RGB(0x80,0x80,0));
1246 SetAStyle(SCE_HJ_DEFAULT, black);
1247 SetAStyle(SCE_HJ_COMMENT, darkGreen);
1248 SetAStyle(SCE_HJ_COMMENTLINE, darkGreen);
1249 SetAStyle(SCE_HJ_COMMENTDOC, darkGreen);
1250 SetAStyle(SCE_HJ_NUMBER, RGB(0,0x80,0x80));
1251 SetAStyle(SCE_HJ_WORD, black);
1252 SetAStyle(SCE_HJ_KEYWORD, darkBlue);
1253 SetAStyle(SCE_HJ_DOUBLESTRING, RGB(0x80,0,0x80));
1254 SetAStyle(SCE_HJ_SINGLESTRING, RGB(0x80,0,0x80));
1255 SetAStyle(SCE_HJ_SYMBOLS, black);
1257 SetAStyle(SCE_HJA_START, RGB(0x80,0x80,0));
1258 SetAStyle(SCE_HJA_DEFAULT, black);
1259 SetAStyle(SCE_HJA_COMMENT, darkGreen);
1260 SetAStyle(SCE_HJA_COMMENTLINE, darkGreen);
1261 SetAStyle(SCE_HJA_COMMENTDOC, darkGreen);
1262 SetAStyle(SCE_HJA_NUMBER, RGB(0,0x80,0x80));
1263 SetAStyle(SCE_HJA_WORD, black);
1264 SetAStyle(SCE_HJA_KEYWORD, darkBlue);
1265 SetAStyle(SCE_HJA_DOUBLESTRING, RGB(0x80,0,0x80));
1266 SetAStyle(SCE_HJA_SINGLESTRING, RGB(0x80,0,0x80));
1267 SetAStyle(SCE_HJA_SYMBOLS, black);
1269 SetAStyle(SCE_HPHP_DEFAULT, black);
1270 SetAStyle(SCE_HPHP_HSTRING, RGB(0x80,0,0x80));
1271 SetAStyle(SCE_HPHP_SIMPLESTRING, RGB(0x80,0,0x80));
1272 SetAStyle(SCE_HPHP_WORD, darkBlue);
1273 SetAStyle(SCE_HPHP_NUMBER, RGB(0,0x80,0x80));
1274 SetAStyle(SCE_HPHP_VARIABLE, red);
1275 SetAStyle(SCE_HPHP_HSTRING_VARIABLE, red);
1276 SetAStyle(SCE_HPHP_COMPLEX_VARIABLE, red);
1277 SetAStyle(SCE_HPHP_COMMENT, darkGreen);
1278 SetAStyle(SCE_HPHP_COMMENTLINE, darkGreen);
1279 SetAStyle(SCE_HPHP_OPERATOR, darkBlue);
1281 // Show the whole section of Javascript with off white background
1282 for (int jstyle = SCE_HJ_DEFAULT; jstyle <= SCE_HJ_SYMBOLS; ++jstyle) {
1283 SendEditor(SCI_STYLESETFONT, jstyle,
1284 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
1285 SendEditor(SCI_STYLESETBACK, jstyle, offWhite);
1286 SendEditor(SCI_STYLESETEOLFILLED, jstyle, 1);
1288 SendEditor(SCI_STYLESETBACK, SCE_HJ_STRINGEOL, RGB(0xDF, 0xDF, 0x7F));
1289 SendEditor(SCI_STYLESETEOLFILLED, SCE_HJ_STRINGEOL, 1);
1291 // Show the whole section of Javascript with brown background
1292 for (int jastyle = SCE_HJA_DEFAULT; jastyle <= SCE_HJA_SYMBOLS; ++jastyle) {
1293 SendEditor(SCI_STYLESETFONT, jastyle,
1294 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
1295 SendEditor(SCI_STYLESETBACK, jastyle, RGB(0xDF, 0xDF, 0x7F));
1296 SendEditor(SCI_STYLESETEOLFILLED, jastyle, 1);
1298 SendEditor(SCI_STYLESETBACK, SCE_HJA_STRINGEOL, RGB(0x0,0xAF,0x5F));
1299 SendEditor(SCI_STYLESETEOLFILLED, SCE_HJA_STRINGEOL, 1);
1302 else
1304 SendEditor(SCI_SETLEXER, SCLEX_CPP);
1305 SetupCppLexer();
1307 SendEditor(SCI_COLOURISE, 0, -1);
1311 void CTortoiseGitBlameView::SetupCppLexer()
1313 SetAStyle(SCE_C_DEFAULT, RGB(0, 0, 0));
1314 SetAStyle(SCE_C_COMMENT, RGB(0, 0x80, 0));
1315 SetAStyle(SCE_C_COMMENTLINE, RGB(0, 0x80, 0));
1316 SetAStyle(SCE_C_COMMENTDOC, RGB(0, 0x80, 0));
1317 SetAStyle(SCE_C_COMMENTLINEDOC, RGB(0, 0x80, 0));
1318 SetAStyle(SCE_C_COMMENTDOCKEYWORD, RGB(0, 0x80, 0));
1319 SetAStyle(SCE_C_COMMENTDOCKEYWORDERROR, RGB(0, 0x80, 0));
1320 SetAStyle(SCE_C_NUMBER, RGB(0, 0x80, 0x80));
1321 SetAStyle(SCE_C_WORD, RGB(0, 0, 0x80));
1322 SendEditor(SCE_C_WORD, 1);
1323 SetAStyle(SCE_C_STRING, RGB(0x80, 0, 0x80));
1324 SetAStyle(SCE_C_IDENTIFIER, RGB(0, 0, 0));
1325 SetAStyle(SCE_C_PREPROCESSOR, RGB(0x80, 0, 0));
1326 SetAStyle(SCE_C_OPERATOR, RGB(0x80, 0x80, 0));
1329 int CTortoiseGitBlameView::GetEncode(unsigned char *buff, int size, int *bomoffset)
1331 CFileTextLines textlines;
1332 CFileTextLines::UnicodeType type = textlines.CheckUnicodeType(buff, size);
1334 if(type == CFileTextLines::UTF8BOM)
1336 *bomoffset = 3;
1337 return CP_UTF8;
1339 if(type == CFileTextLines::UTF8)
1340 return CP_UTF8;
1342 if(type == CFileTextLines::UTF16_LE)
1344 *bomoffset = 2;
1345 return 1200;
1348 if(type == CFileTextLines::UTF16_BE)
1350 *bomoffset = 2;
1351 return 1201;
1354 return GetACP();
1357 void CTortoiseGitBlameView::UpdateInfo(int Encode)
1359 BYTE_VECTOR &data = GetDocument()->m_BlameData;
1360 CString one;
1361 int pos=0;
1363 BYTE_VECTOR vector;
1365 this->m_CommitHash.clear();
1366 this->m_Authors.clear();
1367 this->m_Dates.clear();
1368 this->m_ID.clear();
1369 CString line;
1371 CreateFont();
1373 SendEditor(SCI_SETREADONLY, FALSE);
1374 SendEditor(SCI_CLEARALL);
1375 SendEditor(EM_EMPTYUNDOBUFFER);
1376 SendEditor(SCI_SETSAVEPOINT);
1377 SendEditor(SCI_CANCEL);
1378 SendEditor(SCI_SETUNDOCOLLECTION, 0);
1380 SendEditor(SCI_SETCODEPAGE, SC_CP_UTF8);
1382 int current = 0;
1383 int encoding = Encode;
1384 while( pos>=0 && current >=0 && pos<data.size() )
1386 current = data.findData((const BYTE*)"\n",1,pos);
1387 //one=data.Tokenize(_T("\n"),pos);
1389 bool isbound = ( data[pos] == _T('^') );
1391 if( (data.size() - pos) >1 && data[pos] == _T('^'))
1392 ++pos;
1394 if( data[pos] == 0)
1395 continue;
1397 CGitHash hash;
1398 if(isbound)
1400 git_init();
1401 data[pos+39]=0;
1402 if(git_get_sha1((const char*)&data[pos], hash.m_hash))
1404 ::MessageBox(NULL, _T("Can't get hash"), _T("TortoiseGit"), MB_OK|MB_ICONERROR);
1408 else
1409 hash.ConvertFromStrA((char*)&data[pos]);
1412 int start=0;
1413 start=data.findData((const BYTE*)")",1,pos + 40);
1414 if(start>0)
1417 int bomoffset = 0;
1418 CStringA stra;
1419 stra.Empty();
1421 if(current>=0)
1422 data[current] = 0;
1423 else
1424 data.push_back(0);
1426 if( pos <40 && encoding==0)
1428 // first line
1429 encoding = GetEncode(&data[start + 2], (int)(data.size() - start - 2), &bomoffset);
1432 if(encoding == 1201)
1434 CString strw;
1435 DWORD size = ((current - start -2 - bomoffset)/2);
1436 TCHAR *buffer = strw.GetBuffer(size);
1437 memcpy(buffer, &data[start + 2 + bomoffset],sizeof(TCHAR)*size);
1438 // swap the bytes to little-endian order to get proper strings in wchar_t format
1439 wchar_t * pSwapBuf = buffer;
1440 for (DWORD i = 0; i<size; ++i)
1442 *pSwapBuf = WideCharSwap2(*pSwapBuf);
1443 ++pSwapBuf;
1445 strw.ReleaseBuffer();
1447 stra = CUnicodeUtils::GetUTF8(strw);
1449 else if(encoding == 1200)
1451 CString strw;
1452 // the first bomoffset is 2, after that it's 1 (see issue #920)
1453 // also: don't set bomoffset if called from Encodings menu (i.e. start == 42 and bomoffset == 0); bomoffset gets only set if autodetected
1454 if (bomoffset == 0 && start != 42)
1455 bomoffset = 1;
1456 int size = ((current - start -2 - bomoffset)/2);
1457 TCHAR *buffer = strw.GetBuffer(size);
1458 memcpy(buffer, &data[start + 2 + bomoffset],sizeof(TCHAR)*size);
1459 strw.ReleaseBuffer();
1461 stra = CUnicodeUtils::GetUTF8(strw);
1463 else if(encoding == CP_UTF8)
1465 stra = &data[start + 2 + bomoffset ];
1467 else
1469 CString strw;
1470 strw = CUnicodeUtils::GetUnicode(CStringA(&data[start + 2 + bomoffset ]), encoding);
1471 stra = CUnicodeUtils::GetUTF8(strw);
1475 SendEditor(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)stra);
1476 SendEditor(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)"\n\0\0\0");
1478 if(current>=0)
1479 data[current] = '\n';
1483 if(this->m_NoListCommit.find(hash) == m_NoListCommit.end() )
1485 this->m_NoListCommit[hash].GetCommitFromHash(hash);
1487 m_ID.push_back(-1); // m_ID is calculated lazy on demand
1488 m_Authors.push_back(m_NoListCommit[hash].GetAuthorName());
1489 m_Dates.push_back(CLoglistUtils::FormatDateAndTime(m_NoListCommit[hash].GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes));
1491 m_CommitHash.push_back(hash);
1492 pos = current+1;
1495 UINT nID;
1496 UINT nStyle;
1497 int cxWidth;
1498 int nIndex = ((CMainFrame *)::AfxGetApp()->GetMainWnd())->m_wndStatusBar.CommandToIndex(ID_INDICATOR_ENCODING);
1499 ((CMainFrame *)::AfxGetApp()->GetMainWnd())->m_wndStatusBar.GetPaneInfo(nIndex, nID, nStyle, cxWidth);
1500 CString sBarText = L"";
1501 for (int i = 0; i < _countof(encodings); ++i)
1503 if (encodings[i].id == encoding)
1505 sBarText = CString(encodings[i].name);
1506 break;
1509 //calculate the width of the text
1510 CDC * pDC = ((CMainFrame *)::AfxGetApp()->GetMainWnd())->m_wndStatusBar.GetDC();
1511 if (pDC)
1513 CSize size = pDC->GetTextExtent(sBarText);
1514 ((CMainFrame *)::AfxGetApp()->GetMainWnd())->m_wndStatusBar.SetPaneInfo(nIndex, nID, nStyle, size.cx+2);
1515 ReleaseDC(pDC);
1517 ((CMainFrame *)::AfxGetApp()->GetMainWnd())->m_wndStatusBar.SetPaneText(nIndex, sBarText);
1520 #if 0
1521 if(m_Buffer)
1523 delete m_Buffer;
1524 m_Buffer=NULL;
1527 CFile file;
1528 file.Open(this->GetDocument()->m_TempFileName,CFile::modeRead);
1530 m_Buffer = new char[file.GetLength()+4];
1531 m_Buffer[file.GetLength()] =0;
1532 m_Buffer[file.GetLength()+1] =0;
1533 m_Buffer[file.GetLength()+2] =0;
1534 m_Buffer[file.GetLength()+3] =0;
1536 file.Read(m_Buffer, file.GetLength());
1538 int bomoffset =0;
1539 int encoding = GetEncode( (unsigned char *)m_Buffer, file.GetLength(), &bomoffset);
1541 file.Close();
1542 //SendEditor(SCI_SETCODEPAGE, encoding);
1544 //SendEditor(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)(m_Buffer + bomoffset));
1545 #endif
1546 SetupLexer(GetDocument()->m_CurrentFileName);
1548 SendEditor(SCI_SETUNDOCOLLECTION, 1);
1549 SendEditor(EM_EMPTYUNDOBUFFER);
1550 SendEditor(SCI_SETSAVEPOINT);
1551 SendEditor(SCI_GOTOPOS, 0);
1552 SendEditor(SCI_SETSCROLLWIDTHTRACKING, TRUE);
1553 SendEditor(SCI_SETREADONLY, TRUE);
1555 m_lowestrev=0;
1556 m_highestrev = (long)(this->GetLogData()->size() + m_NoListCommit.size());
1558 GetBlameWidth();
1559 CRect rect;
1560 this->GetClientRect(rect);
1561 //this->m_TextView.GetWindowRect(rect);
1562 //this->m_TextView.ScreenToClient(rect);
1563 rect.left=this->m_blamewidth;
1564 this->m_TextView.MoveWindow(rect);
1566 this->Invalidate();
1569 CGitBlameLogList * CTortoiseGitBlameView::GetLogList()
1571 return &(GetDocument()->GetMainFrame()->m_wndOutput.m_LogList);
1575 CLogDataVector * CTortoiseGitBlameView::GetLogData()
1577 return &(GetDocument()->GetMainFrame()->m_wndOutput.m_LogList.m_logEntries);
1580 void CTortoiseGitBlameView::OnSciPainted(NMHDR *,LRESULT *)
1582 this->Invalidate();
1585 void CTortoiseGitBlameView::OnLButtonDown(UINT nFlags,CPoint point)
1588 LONG line = (LONG)SendEditor(SCI_GETFIRSTVISIBLELINE);
1589 LONG height = (LONG)SendEditor(SCI_TEXTHEIGHT);
1590 line = line + (point.y/height);
1592 if (line < (LONG)m_CommitHash.size())
1594 SetSelectedLine(line);
1595 if (m_CommitHash[line] != m_SelectedHash)
1597 m_SelectedHash = m_CommitHash[line];
1599 // lazy calculate m_ID
1600 if (m_ID[line] == -1)
1602 m_ID[line] = -2; // don't do this lazy calculation again and again for unfindable hashes
1603 for (size_t i = 0; i < this->GetLogData()->size(); ++i)
1605 if(m_SelectedHash == this->GetLogData()->at(i))
1607 m_ID[line] = (LONG)(this->GetLogData()->size() - i);
1608 break;
1613 if(m_ID[line]>=0)
1615 this->GetLogList()->SetItemState(this->GetLogList()->GetItemCount()-m_ID[line],
1616 LVIS_SELECTED,
1617 LVIS_SELECTED);
1618 this->GetLogList()->EnsureVisible(this->GetLogList()->GetItemCount()-m_ID[line], FALSE);
1620 else
1622 this->GetDocument()->GetMainFrame()->m_wndProperties.UpdateProperties(&m_NoListCommit[m_CommitHash[line]]);
1625 else
1627 m_SelectedHash.Empty();
1629 //::InvalidateRect( NULL, FALSE);
1630 this->Invalidate();
1631 this->m_TextView.Invalidate();
1634 else
1636 SetSelectedLine(-1);
1639 CView::OnLButtonDown(nFlags,point);
1642 void CTortoiseGitBlameView::OnSciGetBkColor(NMHDR* hdr, LRESULT* /*result*/)
1645 SCNotification *notification=reinterpret_cast<SCNotification *>(hdr);
1647 if ((m_colorage)&&(notification->line < (int)m_CommitHash.size()))
1649 if(m_CommitHash[notification->line] == this->m_SelectedHash )
1650 notification->lParam = m_selectedauthorcolor;
1651 else
1652 notification->lParam = InterColor(DWORD(m_regOldLinesColor), DWORD(m_regNewLinesColor), (m_ID[notification->line]-m_lowestrev)*100/((m_highestrev-m_lowestrev)+1));
1657 void CTortoiseGitBlameView::FocusOn(GitRev *pRev)
1659 this->GetDocument()->GetMainFrame()->m_wndProperties.UpdateProperties(pRev);
1661 this->Invalidate();
1663 if (m_SelectedHash != pRev->m_CommitHash) {
1664 m_SelectedHash = pRev->m_CommitHash;
1665 for (size_t i = 0; i < m_CommitHash.size(); ++i)
1667 if (pRev->m_CommitHash == m_CommitHash[i])
1669 GotoLine((long)(i + 1));
1670 m_TextView.Invalidate();
1671 return;
1674 SendEditor(SCI_SETSEL, LONG_MAX, -1);
1678 void CTortoiseGitBlameView::OnMouseHover(UINT /*nFlags*/, CPoint point)
1680 LONG_PTR line = SendEditor(SCI_GETFIRSTVISIBLELINE);
1681 LONG_PTR height = SendEditor(SCI_TEXTHEIGHT);
1682 line = line + (point.y/height);
1684 if (line < (LONG)m_CommitHash.size())
1686 if (line != m_MouseLine)
1688 m_MouseLine = (LONG)line;//m_CommitHash[line];
1689 GitRev *pRev;
1690 if(m_ID[line]<0)
1692 pRev=&this->m_NoListCommit[m_CommitHash[line]];
1695 else
1697 pRev=&this->GetLogData()->GetGitRevAt(this->GetLogList()->GetItemCount()-m_ID[line]);
1700 CString body = pRev->GetBody();
1701 int maxLine = 15;
1702 int line = 0;
1703 int pos = 0;
1704 while (line++ < maxLine)
1706 int pos2 = body.Find(_T("\n"), pos);
1707 if (pos2 < 0)
1708 break;
1709 int lineLength = pos2 - pos - 1;
1710 pos = pos2 + 1;
1711 line += lineLength / 70;
1714 CString str;
1715 str.Format(_T("%s: %s\n%s: %s <%s>\n%s: %s\n%s:\n%s\n%s"), m_sRev, pRev->m_CommitHash.ToString(),
1716 m_sAuthor, pRev->GetAuthorName(), pRev->GetAuthorEmail(),
1717 m_sDate, CLoglistUtils::FormatDateAndTime(pRev->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
1718 m_sMessage, pRev->GetSubject(),
1719 line <= maxLine ? body : (body.Left(pos) + _T("\n....................")));
1721 m_ToolTip.Pop();
1722 m_ToolTip.AddTool(this, str);
1724 CRect rect;
1725 rect.left=LOCATOR_WIDTH;
1726 rect.right=this->m_blamewidth+rect.left;
1727 rect.top = point.y - (LONG)height;
1728 rect.bottom = point.y + (LONG)height;
1729 this->InvalidateRect(rect);
1734 void CTortoiseGitBlameView::OnMouseMove(UINT /*nFlags*/, CPoint /*point*/)
1736 TRACKMOUSEEVENT tme;
1737 tme.cbSize=sizeof(TRACKMOUSEEVENT);
1738 tme.dwFlags=TME_HOVER|TME_LEAVE;
1739 tme.hwndTrack=this->m_hWnd;
1740 tme.dwHoverTime=1;
1741 TrackMouseEvent(&tme);
1745 BOOL CTortoiseGitBlameView::PreTranslateMessage(MSG* pMsg)
1747 m_ToolTip.RelayEvent(pMsg);
1748 return CView::PreTranslateMessage(pMsg);
1751 void CTortoiseGitBlameView::OnEditFind()
1753 m_pFindDialog=new CFindReplaceDialog();
1755 m_pFindDialog->Create(TRUE, _T(""), NULL, FR_DOWN | FR_HIDEWHOLEWORD | FR_HIDEUPDOWN, this);
1758 void CTortoiseGitBlameView::OnEditGoto()
1760 CEditGotoDlg dlg;
1761 if(dlg.DoModal()==IDOK)
1763 this->GotoLine(dlg.m_LineNumber);
1767 LRESULT CTortoiseGitBlameView::OnFindDialogMessage(WPARAM /*wParam*/, LPARAM /*lParam*/)
1769 ASSERT(m_pFindDialog != NULL);
1771 if (m_CommitHash.empty())
1772 return 0;
1774 // If the FR_DIALOGTERM flag is set,
1775 // invalidate the handle identifying the dialog box.
1776 if (m_pFindDialog->IsTerminating())
1778 m_pFindDialog = NULL;
1779 return 0;
1782 // If the FR_FINDNEXT flag is set,
1783 // call the application-defined search routine
1784 // to search for the requested string.
1785 if(m_pFindDialog->FindNext())
1787 //read data from dialog
1788 CString FindName = m_pFindDialog->GetFindString();
1790 DoSearch(FindName,m_pFindDialog->m_fr.Flags);
1793 return 0;
1796 void CTortoiseGitBlameView::OnViewNext()
1798 FindNextLine(this->m_SelectedHash,false);
1800 void CTortoiseGitBlameView::OnViewPrev()
1802 FindNextLine(this->m_SelectedHash,true);
1805 void CTortoiseGitBlameView::OnViewToggleAuthor()
1807 m_bShowAuthor = ! m_bShowAuthor;
1809 theApp.WriteInt(_T("ShowAuthor"), m_bShowAuthor);
1811 CRect rect;
1812 this->GetClientRect(&rect);
1813 rect.left=GetBlameWidth();
1815 m_TextView.MoveWindow(&rect);
1818 void CTortoiseGitBlameView::OnUpdateViewToggleAuthor(CCmdUI *pCmdUI)
1820 pCmdUI->SetCheck(m_bShowAuthor);
1823 void CTortoiseGitBlameView::OnViewToggleDate()
1825 m_bShowDate = ! m_bShowDate;
1827 theApp.WriteInt(_T("ShowDate"), m_bShowDate);
1829 CRect rect;
1830 this->GetClientRect(&rect);
1831 rect.left=GetBlameWidth();
1833 m_TextView.MoveWindow(&rect);
1836 void CTortoiseGitBlameView::OnUpdateViewToggleDate(CCmdUI *pCmdUI)
1838 pCmdUI->SetCheck(m_bShowDate);
1841 void CTortoiseGitBlameView::OnViewToggleFollowRenames()
1843 m_bFollowRenames = ! m_bFollowRenames;
1845 theApp.WriteInt(_T("FollowRenames"), m_bFollowRenames);
1847 UINT uCheck = MF_BYCOMMAND;
1848 uCheck |= m_bFollowRenames ? MF_CHECKED : MF_UNCHECKED;
1849 CheckMenuItem(GetMenu()->m_hMenu, ID_VIEW_FOLLOWRENAMES, uCheck);
1851 CTortoiseGitBlameDoc *document = (CTortoiseGitBlameDoc *) m_pDocument;
1852 if (!document->m_CurrentFileName.IsEmpty())
1854 theApp.m_pDocManager->OnFileNew();
1855 document->OnOpenDocument(document->m_CurrentFileName, document->m_Rev);
1859 void CTortoiseGitBlameView::OnUpdateViewToggleFollowRenames(CCmdUI *pCmdUI)
1861 pCmdUI->SetCheck(m_bFollowRenames);
1864 void CTortoiseGitBlameView::OnUpdateViewCopyToClipboard(CCmdUI *pCmdUI)
1866 CWnd * wnd = GetFocus();
1867 if (wnd == GetLogList())
1869 pCmdUI->Enable(GetLogList()->GetSelectedCount() > 0);
1871 else if (wnd)
1873 if (CString(wnd->GetRuntimeClass()->m_lpszClassName) == _T("CMFCPropertyGridCtrl"))
1875 CMFCPropertyGridCtrl *grid = (CMFCPropertyGridCtrl *)wnd;
1876 pCmdUI->Enable(grid->GetCurSel() && !grid->GetCurSel()->IsGroup() && !CString(grid->GetCurSel()->GetValue()).IsEmpty());
1878 else
1879 pCmdUI->Enable(m_TextView.Call(SCI_GETSELECTIONSTART) != m_TextView.Call(SCI_GETSELECTIONEND));
1881 else
1882 pCmdUI->Enable(FALSE);
1885 int CTortoiseGitBlameView::FindNextLine(CGitHash CommitHash,bool bUpOrDown)
1887 LONG line = (LONG)SendEditor(SCI_GETFIRSTVISIBLELINE);
1888 LONG startline = line;
1889 bool findNoMatch =false;
1890 while(line>=0 && line<m_CommitHash.size())
1892 if(m_CommitHash[line]!=CommitHash)
1894 findNoMatch=true;
1897 if(m_CommitHash[line] == CommitHash && findNoMatch)
1899 if( line == startline+2 )
1901 findNoMatch=false;
1903 else
1905 if( bUpOrDown )
1907 line=FindFirstLine(CommitHash,line);
1909 SendEditor(SCI_LINESCROLL,0,line-startline-2);
1910 return line;
1913 if(bUpOrDown)
1914 --line;
1915 else
1916 ++line;
1918 return -1;