Doc: Fix broken link
[TortoiseGit.git] / src / TortoiseMerge / MainFrm.h
blob5011a3a141ab1e1609e8c8d75c6295684cb045ce
1 // TortoiseGitMerge - a Diff/Patch program
3 // Copyright (C) 2013 - TortoiseGit
4 // Copyright (C) 2006-2015, 2017 - 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.
20 #pragma once
22 #include "DiffData.h"
23 #include "LocatorBar.h"
24 #include "LineDiffBar.h"
25 #include "FilePatchesDlg.h"
26 #include "TempFile.h"
27 #include "XSplitter.h"
28 #include "GitPatch.h"
29 #include "../../ext/SimpleIni/SimpleIni.h"
30 #include "CustomMFCRibbonStatusBar.h"
31 #include <tuple>
33 class CLeftView;
34 class CRightView;
35 class CBottomView;
36 #define MOVESTOIGNORE 3
38 #define TABMODE_NONE 0x00
39 #define TABMODE_USESPACES 0x01
40 #define TABMODE_SMARTINDENT 0x02
42 #define TABSIZEBUTTON1 3
43 #define TABSIZEBUTTON2 4
44 #define TABSIZEBUTTON4 5
45 #define TABSIZEBUTTON8 6
46 #define ENABLEEDITORCONFIG 8
49 /**
50 * \ingroup TortoiseMerge
51 * The main frame of TortoiseMerge. Handles all the menu and toolbar commands.
53 class CMainFrame : public CFrameWndEx, public CPatchFilesDlgCallBack //CFrameWndEx
55 public:
56 CMainFrame();
57 virtual ~CMainFrame();
59 void ShowDiffBar(bool bShow);
60 void DiffLeftToBase();
61 void DiffRightToBase();
63 #ifdef _DEBUG
64 virtual void AssertValid() const;
65 virtual void Dump(CDumpContext& dc) const;
66 #endif
67 protected:
68 DECLARE_DYNCREATE(CMainFrame)
70 virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
71 virtual BOOL OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext);
72 virtual void ActivateFrame(int nCmdShow = -1);
73 virtual BOOL OnShowPopupMenu(CMFCPopupMenu* pMenuPopup);
74 /// line = -1 means keep the current position,
75 /// line >= 0 means scroll to that line,
76 /// and line == -2 means do nothing or scroll to first diff depending on registry setting
77 bool LoadViews(int line = -2);
78 void ClearViewNamesAndPaths();
79 void SetWindowTitle();
81 afx_msg LRESULT OnTaskbarButtonCreated(WPARAM wParam, LPARAM lParam);
82 afx_msg void OnApplicationLook(UINT id);
83 afx_msg void OnUpdateApplicationLook(CCmdUI* pCmdUI);
85 afx_msg void OnFileSave();
86 afx_msg void OnFileSaveAs();
87 afx_msg void OnFileOpen();
88 afx_msg void OnFileOpen(bool fillyours);
90 afx_msg void OnFileReload();
91 afx_msg void OnClose();
92 afx_msg void OnActivate(UINT, CWnd*, BOOL);
93 afx_msg void OnViewWhitespaces();
94 afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
95 afx_msg void OnSize(UINT nType, int cx, int cy);
96 afx_msg void OnUpdateFileSave(CCmdUI *pCmdUI);
97 afx_msg void OnUpdateFileSaveAs(CCmdUI *pCmdUI);
98 afx_msg void OnViewOnewaydiff();
99 afx_msg void OnUpdateViewOnewaydiff(CCmdUI *pCmdUI);
100 afx_msg void OnUpdateViewWhitespaces(CCmdUI *pCmdUI);
101 afx_msg void OnViewOptions();
102 afx_msg void OnViewLinedown();
103 afx_msg void OnViewLineup();
104 afx_msg void OnViewLineleft();
105 afx_msg void OnViewLineright();
106 afx_msg void OnEditUseTheirs();
107 afx_msg void OnEditUseMine();
108 afx_msg void OnEditUseTheirsThenMine();
109 afx_msg void OnEditUseMineThenTheirs();
110 afx_msg void OnUpdateEditUseminethentheirblock(CCmdUI *pCmdUI);
111 afx_msg void OnUpdateEditUsemyblock(CCmdUI *pCmdUI);
112 afx_msg void OnUpdateEditUsetheirblock(CCmdUI *pCmdUI);
113 afx_msg void OnUpdateEditUsetheirthenmyblock(CCmdUI *pCmdUI);
114 afx_msg void OnUpdateMergeMarkasresolved(CCmdUI *pCmdUI);
115 afx_msg void OnMergeMarkasresolved();
116 afx_msg void OnUpdateMergeNextconflict(CCmdUI *pCmdUI);
117 afx_msg void OnUpdateMergePreviousconflict(CCmdUI *pCmdUI);
118 afx_msg void OnUpdateEditCopy(CCmdUI *pCmdUI);
119 afx_msg void OnUpdateEditPaste(CCmdUI *pCmdUI);
120 afx_msg void OnMoving(UINT fwSide, LPRECT pRect);
121 afx_msg void OnViewSwitchleft();
122 afx_msg void OnUpdateViewSwitchleft(CCmdUI *pCmdUI);
123 afx_msg void OnUpdateViewShowfilelist(CCmdUI *pCmdUI);
124 afx_msg void OnViewShowfilelist();
125 afx_msg void OnEditUndo();
126 afx_msg void OnUpdateEditUndo(CCmdUI *pCmdUI);
127 afx_msg void OnEditRedo();
128 afx_msg void OnUpdateEditRedo(CCmdUI *pCmdUI);
129 afx_msg void OnEditEnable();
130 afx_msg void OnUpdateEditEnable(CCmdUI *pCmdUI);
131 afx_msg void OnViewInlinediffword();
132 afx_msg void OnUpdateViewInlinediffword(CCmdUI *pCmdUI);
133 afx_msg void OnViewInlinediff();
134 afx_msg void OnUpdateViewInlinediff(CCmdUI *pCmdUI);
135 afx_msg void OnUpdateEditCreateunifieddifffile(CCmdUI *pCmdUI);
136 afx_msg void OnEditCreateunifieddifffile();
137 afx_msg void OnUpdateViewLinediffbar(CCmdUI *pCmdUI);
138 afx_msg void OnViewLinediffbar();
139 afx_msg void OnUpdateViewLocatorbar(CCmdUI *pCmdUI);
140 afx_msg void OnUpdateViewBars(CCmdUI *pCmdUI);
141 afx_msg void OnViewLocatorbar();
142 afx_msg void OnEditUseleftblock();
143 afx_msg void OnUpdateUseBlock(CCmdUI *pCmdUI);
144 afx_msg void OnUpdateEditUseleftblock(CCmdUI *pCmdUI);
145 afx_msg void OnEditUseleftfile();
146 afx_msg void OnUpdateEditUseleftfile(CCmdUI *pCmdUI);
147 afx_msg void OnEditUseblockfromleftbeforeright();
148 afx_msg void OnUpdateEditUseblockfromleftbeforeright(CCmdUI *pCmdUI);
149 afx_msg void OnEditUseblockfromrightbeforeleft();
150 afx_msg void OnUpdateEditUseblockfromrightbeforeleft(CCmdUI *pCmdUI);
151 afx_msg void OnUpdateNavigateNextdifference(CCmdUI *pCmdUI);
152 afx_msg void OnUpdateNavigatePreviousdifference(CCmdUI *pCmdUI);
153 afx_msg void OnViewCollapsed();
154 afx_msg void OnUpdateViewCollapsed(CCmdUI *pCmdUI);
155 afx_msg void OnViewComparewhitespaces();
156 afx_msg void OnUpdateViewComparewhitespaces(CCmdUI *pCmdUI);
157 afx_msg void OnViewIgnorewhitespacechanges();
158 afx_msg void OnUpdateViewIgnorewhitespacechanges(CCmdUI *pCmdUI);
159 afx_msg void OnViewIgnoreallwhitespacechanges();
160 afx_msg void OnUpdateViewIgnoreallwhitespacechanges(CCmdUI *pCmdUI);
161 afx_msg void OnUpdateNavigateNextinlinediff(CCmdUI *pCmdUI);
162 afx_msg void OnUpdateNavigatePrevinlinediff(CCmdUI *pCmdUI);
163 afx_msg void OnViewMovedBlocks();
164 afx_msg void OnUpdateViewMovedBlocks(CCmdUI *pCmdUI);
165 afx_msg void OnViewWraplonglines();
166 afx_msg void OnUpdateViewWraplonglines(CCmdUI *pCmdUI);
167 afx_msg void OnIndicatorLeftview();
168 afx_msg void OnIndicatorRightview();
169 afx_msg void OnIndicatorBottomview();
170 afx_msg void OnTimer(UINT_PTR nIDEvent);
171 afx_msg void OnViewIgnorecomments();
172 afx_msg void OnUpdateViewIgnorecomments(CCmdUI *pCmdUI);
173 afx_msg void OnUpdateViewRegexFilter(CCmdUI *pCmdUI);
174 afx_msg void OnRegexfilter(UINT cmd);
175 afx_msg void OnDummyEnabled() {};
176 afx_msg void OnEncodingLeft(UINT cmd);
177 afx_msg void OnEncodingRight(UINT cmd);
178 afx_msg void OnEncodingBottom(UINT cmd);
179 afx_msg void OnEOLLeft(UINT cmd);
180 afx_msg void OnEOLRight(UINT cmd);
181 afx_msg void OnEOLBottom(UINT cmd);
182 afx_msg void OnTabModeLeft(UINT cmd);
183 afx_msg void OnTabModeRight(UINT cmd);
184 afx_msg void OnTabModeBottom(UINT cmd);
185 afx_msg void OnUpdateEncodingLeft(CCmdUI *pCmdUI);
186 afx_msg void OnUpdateEncodingRight(CCmdUI *pCmdUI);
187 afx_msg void OnUpdateEncodingBottom(CCmdUI *pCmdUI);
188 afx_msg void OnUpdateEOLLeft(CCmdUI *pCmdUI);
189 afx_msg void OnUpdateEOLRight(CCmdUI *pCmdUI);
190 afx_msg void OnUpdateEOLBottom(CCmdUI *pCmdUI);
191 afx_msg void OnUpdateTabModeLeft(CCmdUI *pCmdUI);
192 afx_msg void OnUpdateTabModeRight(CCmdUI *pCmdUI);
193 afx_msg void OnUpdateTabModeBottom(CCmdUI *pCmdUI);
194 afx_msg void OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS* lpncsp);
196 DECLARE_MESSAGE_MAP()
197 protected:
198 void UpdateLayout();
199 virtual BOOL PatchFile(CString sFilePath, bool bContentMods, bool bPropMods, CString sVersion, BOOL bAutoPatch) override;
200 virtual BOOL DiffFiles(CString sURL1, CString sRev1, CString sURL2, CString sRev2) override;
201 int CheckResolved();
202 BOOL MarkAsResolved();
203 int SaveFile(const CString& sFilePath);
204 void WriteWindowPlacement(WINDOWPLACEMENT * pwp);
205 BOOL ReadWindowPlacement(WINDOWPLACEMENT * pwp);
206 bool FileSave(bool bCheckResolved=true);
207 void PatchSave();
208 bool FileSaveAs(bool bCheckResolved=true);
209 void LoadIgnoreCommentData();
210 /// checks if there are modifications and asks the user to save them first
211 /// IDCANCEL is returned if the user wants to cancel.
212 /// If the user wanted to save the modifications, this method does the saving
213 /// itself.
214 int CheckForReload();
215 enum ECheckForSaveReason {
216 CHFSR_CLOSE, ///< closing apps
217 CHFSR_SWITCH, ///< switching views
218 CHFSR_RELOAD, ///< reload views also switching between 1 and 2 way diff
219 CHFSR_OPTIONS, ///< white space change, options
220 CHFSR_OPEN, ///< open open dialog
222 /// checks if there are modifications and asks the user to save them first
223 /// IDCANCEL is returned if the user wants to cancel.
224 /// If the user wanted to save the modifications, this method does the saving
225 /// itself.
226 int CheckForSave(ECheckForSaveReason eReason/* = CHFSR_SWITCH*/);
227 void DeleteBaseTheirsMineOnClose();
228 void OnViewLineUpDown(int direction);
229 void OnViewLineLeftRight(int direction);
230 static void OnTabMode(CBaseView *view, int cmd);
231 static void OnUpdateTabMode(CBaseView *view, CCmdUI *pCmdUI, int startid);
232 bool HasConflictsWontKeep();
233 bool TryGetFileName(CString& result);
234 CBaseView* GetActiveBaseView() const;
235 void OnViewTextFoldUnfold();
236 void OnViewTextFoldUnfold(CBaseView* view);
237 bool HasUnsavedEdits() const;
238 static bool HasUnsavedEdits(const CBaseView* view);
239 bool HasMarkedBlocks() const;
240 static bool IsViewGood(const CBaseView* view);
241 static bool HasPrevConflict(CBaseView* view);
242 static bool HasNextConflict(CBaseView* view);
243 static bool HasPrevInlineDiff(CBaseView* view);
244 static bool HasNextInlineDiff(CBaseView* view);
245 void BuildRegexSubitems(CMFCPopupMenu* pMenuPopup = nullptr);
246 bool AdjustUnicodeTypeForLoad(CFileTextLines::UnicodeType& type);
247 void DiffTwo(const CWorkingFile& file1, const CWorkingFile& file2);
249 protected:
250 CMFCStatusBar m_wndStatusBar;
251 CCustomMFCRibbonStatusBar m_wndRibbonStatusBar;
252 CLocatorBar m_wndLocatorBar;
253 CLineDiffBar m_wndLineDiffBar;
254 CXSplitter m_wndSplitter;
255 CXSplitter m_wndSplitter2;
256 CFilePatchesDlg m_dlgFilePatches;
258 GitPatch m_Patch;
259 BOOL m_bInitSplitter;
260 bool m_bCheckReload;
262 bool m_bHasConflicts;
264 bool m_bInlineWordDiff;
265 bool m_bInlineDiff;
266 bool m_bLineDiff;
267 bool m_bLocatorBar;
268 bool m_bUseRibbons;
270 CMFCRibbonBar m_wndRibbonBar;
271 CMFCRibbonApplicationButton m_MainButton;
273 CRegDWORD m_regWrapLines;
274 CRegDWORD m_regViewModedBlocks;
275 CRegDWORD m_regOneWay;
276 CRegDWORD m_regCollapsed;
277 CRegDWORD m_regInlineDiff;
278 CRegDWORD m_regUseRibbons;
279 CRegDWORD m_regIgnoreComments;
281 std::map<CString, std::tuple<CString, CString, CString>> m_IgnoreCommentsMap;
282 CSimpleIni m_regexIni;
283 int m_regexIndex;
284 public:
285 CLeftView * m_pwndLeftView;
286 CRightView * m_pwndRightView;
287 CBottomView * m_pwndBottomView;
288 BOOL m_bOneWay;
289 BOOL m_bReversedPatch;
290 CDiffData m_Data;
291 bool m_bReadOnly;
292 bool m_bBlame;
293 int m_nMoveMovesToIgnore;
294 bool m_bCollapsed;
295 bool m_bViewMovedBlocks;
296 bool m_bWrapLines;
297 bool m_bSaveRequired;
298 bool m_bSaveRequiredOnConflicts;
299 bool m_bDeleteBaseTheirsMineOnClose;
300 HWND resolveMsgWnd;
301 WPARAM resolveMsgWParam;
302 LPARAM resolveMsgLParam;
304 const CMFCToolBar * GetToolbar() const { return &m_wndToolBar; }
305 void FillEncodingButton( CMFCRibbonButton * pButton, int start );
306 void FillEOLButton( CMFCRibbonButton * pButton, int start );
307 void FillTabModeButton(CMFCRibbonButton * pButton, int start);
308 CMFCMenuBar m_wndMenuBar;
309 CMFCToolBar m_wndToolBar;