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