1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2013, 2015-2018 - 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 LOCATOR_WIDTH 10
49 class CSciEditBlame
: public CSciEdit
51 DECLARE_DYNAMIC(CSciEditBlame
)
53 afx_msg
void OnKeyDown(UINT nChar
, UINT nRepCnt
, UINT nFlags
)
59 if ((Call(SCI_AUTOCACTIVE
)==0)&&(Call(SCI_CALLTIPACTIVE
)==0))
61 ::SendMessage(::AfxGetApp()->GetMainWnd()->m_hWnd
, WM_CLOSE
, 0, 0);
67 CWnd::OnKeyDown(nChar
, nRepCnt
, nFlags
);
71 class CTortoiseGitBlameView
: public CView
75 // needs to start with 1, since 0 is the return value if *nothing* is clicked on in the context menu
77 ID_COMPAREWITHPREVIOUS
,
79 ID_COPYHASHTOCLIPBOARD
,
83 protected: // create from serialization only
84 CTortoiseGitBlameView();
85 DECLARE_DYNCREATE(CTortoiseGitBlameView
)
89 CTortoiseGitBlameDoc
* GetDocument() const;
90 int GetEncode(unsigned char * buffer
, int size
, int *bomoffset
);
96 afx_msg
void OnDraw(CDC
* pDC
); // overridden to draw this view
97 afx_msg BOOL
OnEraseBkgnd(CDC
* pDC
);
98 virtual BOOL
PreCreateWindow(CREATESTRUCT
& cs
) override
;
100 afx_msg BOOL
OnPreparePrinting(CPrintInfo
* pInfo
);
101 afx_msg
void OnBeginPrinting(CDC
* pDC
, CPrintInfo
* pInfo
);
102 afx_msg
void OnEndPrinting(CDC
* pDC
, CPrintInfo
* pInfo
);
103 virtual ULONG
GetGestureStatus(CPoint ptTouch
) override
;
107 virtual ~CTortoiseGitBlameView();
109 virtual void AssertValid() const override
;
110 virtual void Dump(CDumpContext
& dc
) const override
;
115 // Generated message map functions
117 virtual BOOL
PreTranslateMessage(MSG
* pMsg
) override
;
118 afx_msg
void OnSysColorChange();
119 afx_msg
void OnChangeEncode(UINT nID
);
120 afx_msg
void OnEditFind();
121 afx_msg
void OnEditGoto();
122 afx_msg
void OnFindNext();
123 afx_msg
void OnFindPrev();
124 afx_msg
void OnFilePrintPreview();
125 afx_msg
void OnRButtonUp(UINT nFlags
, CPoint point
);
126 afx_msg
int OnCreate(LPCREATESTRUCT lpcs
);
127 afx_msg
void OnSize(UINT nType
, int cx
, int cy
);
128 afx_msg
void OnSciPainted(NMHDR
*, LRESULT
*);
129 afx_msg
void OnLButtonDown(UINT nFlags
,CPoint point
);
130 afx_msg
void OnRButtonDown(UINT nFlags
,CPoint point
){OnLButtonDown(nFlags
,point
);CView::OnRButtonDown(nFlags
,point
);};
131 afx_msg
void OnSciGetBkColor(NMHDR
*, LRESULT
*);
132 afx_msg
void OnMouseHover(UINT nFlags
, CPoint point
);
133 afx_msg
void OnMouseMove(UINT nFlags
, CPoint point
);
134 afx_msg
void OnMouseLeave();
135 afx_msg LRESULT
OnFindDialogMessage(WPARAM wParam
, LPARAM lParam
);
136 afx_msg
void OnViewNext();
137 afx_msg
void OnViewPrev();
138 afx_msg
void OnViewToggleAuthor();
139 afx_msg
void OnUpdateViewToggleAuthor(CCmdUI
*pCmdUI
);
140 afx_msg
void OnViewToggleDate();
141 afx_msg
void OnUpdateViewToggleDate(CCmdUI
*pCmdUI
);
142 afx_msg
void OnViewToggleShowFilename();
143 afx_msg
void OnUpdateViewToggleShowFilename(CCmdUI
*pCmdUI
);
144 afx_msg
void OnViewToggleShowOriginalLineNumber();
145 afx_msg
void OnUpdateViewToggleShowOriginalLineNumber(CCmdUI
*pCmdUI
);
146 afx_msg
void OnViewDetectMovedOrCopiedLinesToggleDisabled();
147 afx_msg
void OnUpdateViewDetectMovedOrCopiedLinesToggleDisabled(CCmdUI
*pCmdUI
);
148 afx_msg
void OnViewDetectMovedOrCopiedLinesToggleWithinFile();
149 afx_msg
void OnUpdateViewDetectMovedOrCopiedLinesToggleWithinFile(CCmdUI
*pCmdUI
);
150 afx_msg
void OnViewDetectMovedOrCopiedLinesToggleFromModifiedFiles();
151 afx_msg
void OnUpdateViewDetectMovedOrCopiedLinesToggleFromModifiedFiles(CCmdUI
*pCmdUI
);
152 afx_msg
void OnViewDetectMovedOrCopiedLinesToggleFromExistingFilesAtFileCreation();
153 afx_msg
void OnUpdateViewDetectMovedOrCopiedLinesToggleFromExistingFilesAtFileCreation(CCmdUI
*pCmdUI
);
154 afx_msg
void OnViewDetectMovedOrCopiedLinesToggleFromExistingFiles();
155 afx_msg
void OnUpdateViewDetectMovedOrCopiedLinesToggleFromExistingFiles(CCmdUI
*pCmdUI
);
156 afx_msg
void OnViewToggleIgnoreWhitespace();
157 afx_msg
void OnUpdateViewToggleIgnoreWhitespace(CCmdUI
*pCmdUI
);
158 afx_msg
void OnViewToggleShowCompleteLog();
159 afx_msg
void OnUpdateViewToggleShowCompleteLog(CCmdUI
*pCmdUI
);
160 afx_msg
void OnViewToggleOnlyFirstParent();
161 afx_msg
void OnUpdateViewToggleOnlyFirstParent(CCmdUI
* pCmdUI
);
162 afx_msg
void OnViewToggleFollowRenames();
163 afx_msg
void OnUpdateViewToggleFollowRenames(CCmdUI
*pCmdUI
);
164 afx_msg
void OnViewToggleColorByAge();
165 afx_msg
void OnUpdateViewToggleColorByAge(CCmdUI
*pCmdUI
);
166 afx_msg
void OnViewToggleLexer();
167 afx_msg
void OnUpdateViewToggleLexer(CCmdUI
*pCmdUI
);
168 afx_msg
void OnViewWrapLongLines();
169 afx_msg
void OnUpdateViewWrapLongLines(CCmdUI
* pCmdUI
);
170 afx_msg
void OnUpdateViewCopyToClipboard(CCmdUI
*pCmdUI
);
171 void OnViewDetectMovedOrCopiedLines(DWORD dwDetectMovedOrCopiedLines
);
172 void ContextMenuAction(int cmd
, GitRev
* pRev
, GIT_REV_LIST
& parentHash
, const std::vector
<CString
>& parentFilename
, int line
);
173 void ReloadDocument();
175 DECLARE_MESSAGE_MAP()
177 static UINT m_FindDialogMessage
;
180 void MapLineToLogIndex();
181 void UpdateInfo(int encode
= 0);
182 CString
ResolveCommitFile(int line
);
183 CString
ResolveCommitFile(const CString
& path
);
184 void FocusOn(GitRevLoglist
* pRev
);
186 CSciEditBlame m_TextView
;
200 BOOL bIgnoreAllSpaces
;
204 BOOL m_bShowFilename
;
205 BOOL m_bShowOriginalLineNumber
;
206 DWORD m_dwDetectMovedOrCopiedLines
;
207 BOOL m_bIgnoreWhitespace
;
208 BOOL m_bShowCompleteLog
;
209 BOOL m_bOnlyFirstParent
;
210 BOOL m_bFollowRenames
;
211 BOOL m_bBlameOutputContainsOtherFilenames
;
213 LRESULT
SendEditor(UINT Msg
, WPARAM wParam
=0, LPARAM lParam
=0);
215 void SetAStyle(int style
, COLORREF fore
, COLORREF back
= ::GetSysColor(COLOR_WINDOW
), int size
= -1, const char* face
= nullptr);
217 void InitialiseEditor();
218 LONG
GetBlameWidth();
219 void DrawBlame(HDC hDC
);
220 void DrawLocatorBar(HDC hDC
);
221 void CopyToClipboard();
222 bool DoSearch(CTortoiseGitBlameData::SearchDirection direction
);
223 bool GotoLine(int line
);
224 bool ScrollToLine(long line
);
226 void SetSelectedLine(int line
) { m_SelectedLine
= line
;};
229 CGitHash m_SelectedHash
;
230 CGitHash m_selecteddate
;
233 bool m_bWrapLongLines
;
235 CTortoiseGitBlameData m_data
;
236 std::vector
<int> m_lineToLogIndex
;
238 CLogDataVector
* GetLogData();
244 void SetupLexer(CString filename
);
245 void SetupCppLexer();
246 int GetLineUnderCursor(CPoint point
);
247 COLORREF
GetLineColor(size_t line
);
248 COLORREF
InterColor(COLORREF c1
, COLORREF c2
, int Slider
);
255 LONG m_filenameWidth
;
256 LONG m_originalLineNumberWidth
;
258 int m_SelectedLine
; ///< zero-based
260 COLORREF m_mouserevcolor
;
261 COLORREF m_mouseauthorcolor
;
262 COLORREF m_selectedrevcolor
;
263 COLORREF m_selectedauthorcolor
;
264 COLORREF m_windowcolor
;
265 COLORREF m_textcolor
;
266 COLORREF m_texthighlightcolor
;
268 CRegStdDWORD m_regOldLinesColor
;
269 CRegStdDWORD m_regNewLinesColor
;
271 CGitBlameLogList
* GetLogList();
273 CFindReplaceDialog
*m_pFindDialog
;
275 #ifdef USE_TEMPFILENAME
279 DWORD m_DateFormat
; // DATE_SHORTDATE or DATE_LONGDATE
280 bool m_bRelativeTimes
; // Show relative times
292 #ifndef _DEBUG // debug version in TortoiseGitBlameView.cpp
293 inline CTortoiseGitBlameDoc
* CTortoiseGitBlameView::GetDocument() const
294 { return reinterpret_cast<CTortoiseGitBlameDoc
*>(m_pDocument
); }