1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2013, 2015 - TortoiseGit
4 // Copyright (C) 2003-2008, 2014 - TortoiseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 // TortoiseGitBlameView.h : interface of the CTortoiseGitBlameView class
28 #include "Scintilla.h"
33 #include "GitBlameLogList.h"
34 #include "TortoiseGitBlameData.h"
37 const COLORREF black
= RGB(0,0,0);
38 const COLORREF white
= RGB(0xff,0xff,0xff);
39 const COLORREF red
= RGB(0xFF, 0, 0);
40 const COLORREF offWhite
= RGB(0xFF, 0xFB, 0xF0);
41 const COLORREF darkGreen
= RGB(0, 0x80, 0);
42 const COLORREF darkBlue
= RGB(0, 0, 0x80);
43 const COLORREF lightBlue
= RGB(0xA6, 0xCA, 0xF0);
44 const int blockSize
= 128 * 1024;
47 #define HEADER_HEIGHT 18
48 #define LOCATOR_WIDTH 10
50 #define MAX_LOG_LENGTH 2000
54 #define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp))
57 #define GET_Y_LPARAM(lp) ((int)(short)HIWORD(lp))
60 class CSciEditBlame
: public CSciEdit
62 DECLARE_DYNAMIC(CSciEditBlame
)
64 afx_msg
void OnKeyDown(UINT nChar
, UINT nRepCnt
, UINT nFlags
)
70 if ((Call(SCI_AUTOCACTIVE
)==0)&&(Call(SCI_CALLTIPACTIVE
)==0))
72 ::SendMessage(::AfxGetApp()->GetMainWnd()->m_hWnd
, WM_CLOSE
, 0, 0);
78 CWnd::OnKeyDown(nChar
, nRepCnt
, nFlags
);
82 class CTortoiseGitBlameView
: public CView
86 // needs to start with 1, since 0 is the return value if *nothing* is clicked on in the context menu
88 ID_COMPAREWITHPREVIOUS
,
90 ID_COPYHASHTOCLIPBOARD
,
94 protected: // create from serialization only
95 CTortoiseGitBlameView();
96 DECLARE_DYNCREATE(CTortoiseGitBlameView
)
100 CTortoiseGitBlameDoc
* GetDocument() const;
101 int GetEncode(unsigned char * buffer
, int size
, int *bomoffset
);
107 virtual void OnDraw(CDC
* pDC
); // overridden to draw this view
108 virtual BOOL
PreCreateWindow(CREATESTRUCT
& cs
);
110 virtual BOOL
OnPreparePrinting(CPrintInfo
* pInfo
);
111 virtual void OnBeginPrinting(CDC
* pDC
, CPrintInfo
* pInfo
);
112 virtual void OnEndPrinting(CDC
* pDC
, CPrintInfo
* pInfo
);
116 virtual ~CTortoiseGitBlameView();
118 virtual void AssertValid() const;
119 virtual void Dump(CDumpContext
& dc
) const;
124 // Generated message map functions
126 BOOL
PreTranslateMessage(MSG
* pMsg
);
127 afx_msg
void OnChangeEncode(UINT nID
);
128 afx_msg
void OnEditFind();
129 afx_msg
void OnEditGoto();
130 afx_msg
void OnFindNext();
131 afx_msg
void OnFindPrev();
132 afx_msg
void OnFilePrintPreview();
133 afx_msg
void OnRButtonUp(UINT nFlags
, CPoint point
);
134 afx_msg
int OnCreate(LPCREATESTRUCT lpcs
);
135 afx_msg
void OnSize(UINT nType
, int cx
, int cy
);
136 afx_msg
void OnSciPainted(NMHDR
*, LRESULT
*);
137 afx_msg
void OnLButtonDown(UINT nFlags
,CPoint point
);
138 afx_msg
void OnRButtonDown(UINT nFlags
,CPoint point
){OnLButtonDown(nFlags
,point
);CView::OnRButtonDown(nFlags
,point
);};
139 afx_msg
void OnSciGetBkColor(NMHDR
*, LRESULT
*);
140 afx_msg
void OnMouseHover(UINT nFlags
, CPoint point
);
141 afx_msg
void OnMouseMove(UINT nFlags
, CPoint point
);
142 afx_msg LRESULT
OnFindDialogMessage(WPARAM wParam
, LPARAM lParam
);
143 afx_msg
void OnViewNext();
144 afx_msg
void OnViewPrev();
145 afx_msg
void OnViewToggleAuthor();
146 afx_msg
void OnUpdateViewToggleAuthor(CCmdUI
*pCmdUI
);
147 afx_msg
void OnViewToggleDate();
148 afx_msg
void OnUpdateViewToggleDate(CCmdUI
*pCmdUI
);
149 afx_msg
void OnViewToggleShowFilename();
150 afx_msg
void OnUpdateViewToggleShowFilename(CCmdUI
*pCmdUI
);
151 afx_msg
void OnViewToggleShowOriginalLineNumber();
152 afx_msg
void OnUpdateViewToggleShowOriginalLineNumber(CCmdUI
*pCmdUI
);
153 afx_msg
void OnViewDetectMovedOrCopiedLinesToggleDisabled();
154 afx_msg
void OnUpdateViewDetectMovedOrCopiedLinesToggleDisabled(CCmdUI
*pCmdUI
);
155 afx_msg
void OnViewDetectMovedOrCopiedLinesToggleWithinFile();
156 afx_msg
void OnUpdateViewDetectMovedOrCopiedLinesToggleWithinFile(CCmdUI
*pCmdUI
);
157 afx_msg
void OnViewDetectMovedOrCopiedLinesToggleFromModifiedFiles();
158 afx_msg
void OnUpdateViewDetectMovedOrCopiedLinesToggleFromModifiedFiles(CCmdUI
*pCmdUI
);
159 afx_msg
void OnViewDetectMovedOrCopiedLinesToggleFromExistingFilesAtFileCreation();
160 afx_msg
void OnUpdateViewDetectMovedOrCopiedLinesToggleFromExistingFilesAtFileCreation(CCmdUI
*pCmdUI
);
161 afx_msg
void OnViewDetectMovedOrCopiedLinesToggleFromExistingFiles();
162 afx_msg
void OnUpdateViewDetectMovedOrCopiedLinesToggleFromExistingFiles(CCmdUI
*pCmdUI
);
163 afx_msg
void OnViewToggleIgnoreWhitespace();
164 afx_msg
void OnUpdateViewToggleIgnoreWhitespace(CCmdUI
*pCmdUI
);
165 afx_msg
void OnViewToggleShowCompleteLog();
166 afx_msg
void OnUpdateViewToggleShowCompleteLog(CCmdUI
*pCmdUI
);
167 afx_msg
void OnViewToggleFollowRenames();
168 afx_msg
void OnUpdateViewToggleFollowRenames(CCmdUI
*pCmdUI
);
169 afx_msg
void OnViewToggleColorByAge();
170 afx_msg
void OnUpdateViewToggleColorByAge(CCmdUI
*pCmdUI
);
171 afx_msg
void OnUpdateViewCopyToClipboard(CCmdUI
*pCmdUI
);
172 void OnViewDetectMovedOrCopiedLines(DWORD dwDetectMovedOrCopiedLines
);
173 void ContextMenuAction(int cmd
, GitRev
* pRev
, GIT_REV_LIST
& parentHash
, const std::vector
<CString
>& parentFilename
);
174 void ReloadDocument();
176 DECLARE_MESSAGE_MAP()
178 static UINT m_FindDialogMessage
;
181 void MapLineToLogIndex();
182 void UpdateInfo(int encode
= 0);
183 CString
ResolveCommitFile(int line
);
184 CString
ResolveCommitFile(const CString
& path
);
185 void FocusOn(GitRevLoglist
* pRev
);
187 CSciEditBlame m_TextView
;
202 BOOL bIgnoreAllSpaces
;
206 BOOL m_bShowFilename
;
207 BOOL m_bShowOriginalLineNumber
;
208 DWORD m_dwDetectMovedOrCopiedLines
;
209 BOOL m_bIgnoreWhitespace
;
210 BOOL m_bShowCompleteLog
;
211 BOOL m_bFollowRenames
;
212 BOOL m_bBlameOuputContainsOtherFilenames
;
214 LRESULT
SendEditor(UINT Msg
, WPARAM wParam
=0, LPARAM lParam
=0);
216 void SetAStyle(int style
, COLORREF fore
, COLORREF back
= ::GetSysColor(COLOR_WINDOW
), int size
= -1, const char *face
= NULL
);
218 void InitialiseEditor();
219 LONG
GetBlameWidth();
220 void DrawBlame(HDC hDC
);
221 void DrawLocatorBar(HDC hDC
);
222 void CopyToClipboard();
223 bool DoSearch(CTortoiseGitBlameData::SearchDirection direction
);
224 bool GotoLine(int line
);
225 bool ScrollToLine(long line
);
227 static INT_PTR CALLBACK
GotoDlgProc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
229 void SetSelectedLine(int line
) { m_SelectedLine
= line
;};
232 CGitHash m_SelectedHash
;
233 CGitHash m_selecteddate
;
236 CTortoiseGitBlameData m_data
;
237 std::vector
<int> m_lineToLogIndex
;
239 void StringExpand(LPSTR str
) const;
240 void StringExpand(LPWSTR str
) const;
242 CLogDataVector
* GetLogData();
248 void SetupLexer(CString filename
);
249 void SetupCppLexer();
250 COLORREF
GetLineColor(int line
);
251 COLORREF
InterColor(COLORREF c1
, COLORREF c2
, int Slider
);
252 CString
GetAppDirectory();
259 LONG m_filenameWidth
;
260 LONG m_originalLineNumberWidth
;
262 int m_SelectedLine
; ///< zero-based
264 COLORREF m_mouserevcolor
;
265 COLORREF m_mouseauthorcolor
;
266 COLORREF m_selectedrevcolor
;
267 COLORREF m_selectedauthorcolor
;
268 COLORREF m_windowcolor
;
269 COLORREF m_textcolor
;
270 COLORREF m_texthighlightcolor
;
272 LRESULT m_directFunction
;
273 LRESULT m_directPointer
;
275 CRegStdDWORD m_regOldLinesColor
;
276 CRegStdDWORD m_regNewLinesColor
;
278 CGitBlameLogList
* GetLogList();
280 CFindReplaceDialog
*m_pFindDialog
;
282 #ifdef USE_TEMPFILENAME
286 DWORD m_DateFormat
; // DATE_SHORTDATE or DATE_LONGDATE
287 bool m_bRelativeTimes
; // Show relative times
299 #ifndef _DEBUG // debug version in TortoiseGitBlameView.cpp
300 inline CTortoiseGitBlameDoc
* CTortoiseGitBlameView::GetDocument() const
301 { return reinterpret_cast<CTortoiseGitBlameDoc
*>(m_pDocument
); }