Fix typos
[TortoiseGit.git] / src / TortoiseGitBlame / TortoiseGitBlameView.h
bloba8c3b15a35e6c437ba7afaac36811a435651c35e
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2013, 2015-2023 - 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
26 #pragma once
28 #include "ILexer.h"
29 #include "Scintilla.h"
30 #include "SciLexer.h"
31 #include "registry.h"
32 #include "SciEdit.h"
34 #include "GitBlameLogList.h"
35 #include "TortoiseGitBlameData.h"
36 #include "Tooltip.h"
38 const COLORREF black = RGB(0,0,0);
39 const COLORREF white = RGB(0xff,0xff,0xff);
40 const COLORREF red = RGB(0xFF, 0, 0);
41 const COLORREF offWhite = RGB(0xFF, 0xFB, 0xF0);
42 const COLORREF darkGreen = RGB(0, 0x80, 0);
43 const COLORREF darkBlue = RGB(0, 0, 0x80);
44 const COLORREF lightBlue = RGB(0xA6, 0xCA, 0xF0);
45 const int blockSize = 128 * 1024;
47 #define BLAMESPACE 5
48 #define LOCATOR_WIDTH 10
50 class CSciEditBlame: public CSciEdit
52 DECLARE_DYNAMIC(CSciEditBlame)
53 public:
54 afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) override
56 switch (nChar)
58 case (VK_ESCAPE):
60 if ((Call(SCI_AUTOCACTIVE)==0)&&(Call(SCI_CALLTIPACTIVE)==0))
62 ::SendMessage(::AfxGetApp()->GetMainWnd()->m_hWnd, WM_CLOSE, 0, 0);
63 return;
66 break;
68 CWnd::OnKeyDown(nChar, nRepCnt, nFlags);
72 class CTortoiseGitBlameView : public CView
74 enum
76 // needs to start with 1, since 0 is the return value if *nothing* is clicked on in the context menu
77 ID_BLAMEPREVIOUS = 1,
78 ID_COMPAREWITHPREVIOUS,
79 ID_SHOWLOG,
80 ID_COPYHASHTOCLIPBOARD,
81 ID_COPYLOGTOCLIPBOARD
84 protected: // create from serialization only
85 CTortoiseGitBlameView();
86 DECLARE_DYNCREATE(CTortoiseGitBlameView)
88 // Attributes
89 public:
90 CTortoiseGitBlameDoc* GetDocument() const;
91 int GetEncode(unsigned char * buffer, int size, int *bomoffset);
93 // Overrides
94 public:
95 afx_msg void OnDraw(CDC* pDC); // overridden to draw this view
96 afx_msg BOOL OnEraseBkgnd(CDC* pDC);
97 BOOL PreCreateWindow(CREATESTRUCT& cs) override;
98 protected:
99 ULONG GetGestureStatus(CPoint ptTouch) override;
101 // Implementation
102 public:
103 virtual ~CTortoiseGitBlameView();
104 #ifdef _DEBUG
105 void AssertValid() const override;
106 void Dump(CDumpContext& dc) const override;
107 #endif
109 // Generated message map functions
110 protected:
111 BOOL PreTranslateMessage(MSG* pMsg) override;
112 afx_msg void OnSysColorChange();
113 afx_msg void OnDestroy();
114 afx_msg void OnChangeEncode(UINT nID);
115 afx_msg void OnEditFind();
116 afx_msg void OnEditGoto();
117 afx_msg void OnFindNext();
118 afx_msg void OnFindPrev();
119 afx_msg void OnRButtonUp(UINT nFlags, CPoint point);
120 afx_msg int OnCreate(LPCREATESTRUCT lpcs);
121 afx_msg void OnSize(UINT nType, int cx, int cy);
122 afx_msg void OnSciPainted(NMHDR*, LRESULT*);
123 afx_msg void OnLButtonDown(UINT nFlags,CPoint point);
124 afx_msg void OnRButtonDown(UINT nFlags,CPoint point){OnLButtonDown(nFlags,point);CView::OnRButtonDown(nFlags,point);};
125 afx_msg void OnSciGetBkColor(NMHDR*, LRESULT*);
126 afx_msg void OnSciZoom(NMHDR*, LRESULT*);
127 afx_msg void OnMouseHover(UINT nFlags, CPoint point);
128 afx_msg void OnMouseMove(UINT nFlags, CPoint point);
129 afx_msg void OnMouseLeave();
130 afx_msg LRESULT OnFindDialogMessage(WPARAM wParam, LPARAM lParam);
131 afx_msg void OnViewNext();
132 afx_msg void OnViewPrev();
133 afx_msg void OnViewToggleLogID();
134 afx_msg void OnUpdateViewToggleLogID(CCmdUI* pCmdUI);
135 afx_msg void OnViewToggleAuthor();
136 afx_msg void OnUpdateViewToggleAuthor(CCmdUI *pCmdUI);
137 afx_msg void OnViewToggleDate();
138 afx_msg void OnUpdateViewToggleDate(CCmdUI *pCmdUI);
139 afx_msg void OnViewToggleShowFilename();
140 afx_msg void OnUpdateViewToggleShowFilename(CCmdUI *pCmdUI);
141 afx_msg void OnViewToggleShowOriginalLineNumber();
142 afx_msg void OnUpdateViewToggleShowOriginalLineNumber(CCmdUI *pCmdUI);
143 afx_msg void OnViewDetectMovedOrCopiedLinesToggleDisabled();
144 afx_msg void OnUpdateViewDetectMovedOrCopiedLinesToggleDisabled(CCmdUI *pCmdUI);
145 afx_msg void OnViewDetectMovedOrCopiedLinesToggleWithinFile();
146 afx_msg void OnUpdateViewDetectMovedOrCopiedLinesToggleWithinFile(CCmdUI *pCmdUI);
147 afx_msg void OnViewDetectMovedOrCopiedLinesToggleFromModifiedFiles();
148 afx_msg void OnUpdateViewDetectMovedOrCopiedLinesToggleFromModifiedFiles(CCmdUI *pCmdUI);
149 afx_msg void OnViewDetectMovedOrCopiedLinesToggleFromExistingFilesAtFileCreation();
150 afx_msg void OnUpdateViewDetectMovedOrCopiedLinesToggleFromExistingFilesAtFileCreation(CCmdUI *pCmdUI);
151 afx_msg void OnViewDetectMovedOrCopiedLinesToggleFromExistingFiles();
152 afx_msg void OnUpdateViewDetectMovedOrCopiedLinesToggleFromExistingFiles(CCmdUI *pCmdUI);
153 afx_msg void OnViewToggleIgnoreWhitespace();
154 afx_msg void OnUpdateViewToggleIgnoreWhitespace(CCmdUI *pCmdUI);
155 afx_msg void OnViewToggleShowCompleteLog();
156 afx_msg void OnUpdateViewToggleShowCompleteLog(CCmdUI *pCmdUI);
157 afx_msg void OnViewToggleOnlyFirstParent();
158 afx_msg void OnUpdateViewToggleOnlyFirstParent(CCmdUI* pCmdUI);
159 afx_msg void OnViewToggleFollowRenames();
160 afx_msg void OnUpdateViewToggleFollowRenames(CCmdUI *pCmdUI);
161 afx_msg void OnViewToggleColorByAge();
162 afx_msg void OnUpdateViewToggleColorByAge(CCmdUI *pCmdUI);
163 afx_msg void OnViewToggleLexer();
164 afx_msg void OnUpdateViewToggleDarkMode(CCmdUI* pCmdUI);
165 afx_msg void OnViewToggleDarkMode();
166 afx_msg void OnUpdateViewToggleLexer(CCmdUI *pCmdUI);
167 afx_msg void OnViewWrapLongLines();
168 afx_msg void OnUpdateViewWrapLongLines(CCmdUI* pCmdUI);
169 afx_msg void OnUpdateViewCopyToClipboard(CCmdUI *pCmdUI);
170 void OnViewDetectMovedOrCopiedLines(DWORD dwDetectMovedOrCopiedLines);
171 void ContextMenuAction(int cmd, GitRev* pRev, GIT_REV_LIST& parentHash, const std::vector<CString>& parentFilename, int line);
172 void ReloadDocument();
174 DECLARE_MESSAGE_MAP()
176 static UINT m_FindDialogMessage;
177 public:
178 void ParseBlame();
179 void MapLineToLogIndex();
180 void UpdateInfo(int encode = 0);
181 CString ResolveCommitFile(int line);
182 CString ResolveCommitFile(const CString& path);
183 void FocusOn(std::unordered_set<CGitHash>&& pRevs, GitRevLoglist* selected);
185 CSciEditBlame m_TextView;
186 CToolTips m_ToolTip;
187 CString m_sLastFilename;
189 HINSTANCE hInstance = nullptr;
190 HINSTANCE hResource = nullptr;
191 HWND currentDialog = nullptr;
193 BOOL bIgnoreEOL = FALSE;
194 BOOL bIgnoreSpaces = FALSE;
195 BOOL bIgnoreAllSpaces = FALSE;
197 BOOL m_bShowLogID = FALSE;
198 BOOL m_bShowAuthor = FALSE;
199 BOOL m_bShowDate = FALSE;
200 BOOL m_bShowFilename = FALSE;
201 BOOL m_bShowOriginalLineNumber = FALSE;
202 DWORD m_dwDetectMovedOrCopiedLines = 0;
203 BOOL m_bIgnoreWhitespace = FALSE;
204 BOOL m_bShowCompleteLog = FALSE;
205 BOOL m_bOnlyFirstParent = FALSE;
206 BOOL m_bFollowRenames = FALSE;
207 BOOL m_bBlameOutputContainsOtherFilenames = FALSE;
209 LRESULT SendEditor(UINT Msg, WPARAM wParam=0, LPARAM lParam=0);
211 void SetAStyle(int style, COLORREF fore, COLORREF back = ::GetSysColor(COLOR_WINDOW), int size = -1, const char* face = nullptr);
213 void InitialiseEditor();
214 LONG GetBlameWidth();
215 void DrawBlame(HDC hDC);
216 void DrawLocatorBar(HDC hDC);
217 void SetTheme(bool bDark);
218 void CopyToClipboard();
219 bool DoSearch(CTortoiseGitBlameData::SearchDirection direction);
220 bool GotoLine(int line);
221 bool ScrollToLine(long line);
223 void SetSelectedLine(int line) { m_SelectedLine = line;};
225 int m_MouseLine = -1;
226 std::unordered_set<CGitHash> m_selectedHashes;
227 bool m_colorage = false;
228 bool m_bLexer = false;
229 bool m_bWrapLongLines = false;
231 CTortoiseGitBlameData m_data;
232 std::vector<int> m_lineToLogIndex;
234 CLogDataVector * GetLogData();
236 BOOL m_bShowLine = TRUE;
238 protected:
239 void CreateFont();
240 void CreateNewFont(bool resize);
241 void SetupColoring();
242 void SetupLexer(CString filename);
243 void SetupCppLexer();
244 int GetLineUnderCursor(CPoint point);
245 COLORREF GetLineColor(size_t line);
246 COLORREF InterColor(COLORREF c1, COLORREF c2, int Slider);
247 CFont m_font;
248 CFont m_italicfont;
249 LONG m_blamewidth = 0;
250 LONG m_revwidth = 0;
251 LONG m_logidwidth = 0;
252 LONG m_datewidth = 0;
253 LONG m_authorwidth = 0;
254 LONG m_filenameWidth = 0;
255 LONG m_originalLineNumberWidth = 0;
256 LONG m_linewidth = 0;
257 int m_SelectedLine = -1; ///< zero-based
259 CString m_sLogIDFormat;
261 COLORREF m_mouserevcolor;
262 COLORREF m_mouseauthorcolor;
263 COLORREF m_selectedrevcolor;
264 COLORREF m_selectedauthorcolor;
265 COLORREF m_windowcolor;
266 COLORREF m_textcolor;
267 COLORREF m_texthighlightcolor;
269 CRegStdDWORD m_regOldLinesColor;
270 CRegStdDWORD m_regNewLinesColor;
271 CRegStdDWORD m_regDarkOldLinesColor;
272 CRegStdDWORD m_regDarkNewLinesColor;
274 CGitBlameLogList * GetLogList();
276 CFindReplaceDialog* m_pFindDialog = nullptr;
278 #ifdef USE_TEMPFILENAME
279 char* m_Buffer = nullptr;
280 #endif
282 int m_themeCallbackId = 0;
284 DWORD m_DateFormat = DATE_SHORTDATE; // DATE_SHORTDATE or DATE_LONGDATE
285 bool m_bRelativeTimes = false; // Show relative times
287 CString m_sRev;
288 CString m_sFileName;
289 CString m_sAuthor;
290 CString m_sDate;
291 CString m_sMessage;
293 CString m_sFindText;
294 bool m_bMatchCase = false;
296 bool m_bBlockUpdates = false;
299 #ifndef _DEBUG // debug version in TortoiseGitBlameView.cpp
300 inline CTortoiseGitBlameDoc* CTortoiseGitBlameView::GetDocument() const
301 { return reinterpret_cast<CTortoiseGitBlameDoc*>(m_pDocument); }
302 #endif