Update editorconfig
[TortoiseGit.git] / src / TortoiseMerge / MainFrm.h
bloba45959d5e02794ee3aaf62f6f4dff255e445c9e3
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 OnEditRedo();
125 afx_msg void OnUpdateEditRedo(CCmdUI *pCmdUI);
126 afx_msg void OnEditEnable();
127 afx_msg void OnUpdateEditEnable(CCmdUI *pCmdUI);
128 afx_msg void OnViewInlinediffword();
129 afx_msg void OnUpdateViewInlinediffword(CCmdUI *pCmdUI);
130 afx_msg void OnViewInlinediff();
131 afx_msg void OnUpdateViewInlinediff(CCmdUI *pCmdUI);
132 afx_msg void OnUpdateEditCreateunifieddifffile(CCmdUI *pCmdUI);
133 afx_msg void OnEditCreateunifieddifffile();
134 afx_msg void OnUpdateViewLinediffbar(CCmdUI *pCmdUI);
135 afx_msg void OnViewLinediffbar();
136 afx_msg void OnUpdateViewLocatorbar(CCmdUI *pCmdUI);
137 afx_msg void OnUpdateViewBars(CCmdUI *pCmdUI);
138 afx_msg void OnViewLocatorbar();
139 afx_msg void OnEditUseleftblock();
140 afx_msg void OnUpdateUseBlock(CCmdUI *pCmdUI);
141 afx_msg void OnUpdateEditUseleftblock(CCmdUI *pCmdUI);
142 afx_msg void OnEditUseleftfile();
143 afx_msg void OnUpdateEditUseleftfile(CCmdUI *pCmdUI);
144 afx_msg void OnEditUseblockfromleftbeforeright();
145 afx_msg void OnUpdateEditUseblockfromleftbeforeright(CCmdUI *pCmdUI);
146 afx_msg void OnEditUseblockfromrightbeforeleft();
147 afx_msg void OnUpdateEditUseblockfromrightbeforeleft(CCmdUI *pCmdUI);
148 afx_msg void OnUpdateNavigateNextdifference(CCmdUI *pCmdUI);
149 afx_msg void OnUpdateNavigatePreviousdifference(CCmdUI *pCmdUI);
150 afx_msg void OnViewCollapsed();
151 afx_msg void OnUpdateViewCollapsed(CCmdUI *pCmdUI);
152 afx_msg void OnViewComparewhitespaces();
153 afx_msg void OnUpdateViewComparewhitespaces(CCmdUI *pCmdUI);
154 afx_msg void OnViewIgnorewhitespacechanges();
155 afx_msg void OnUpdateViewIgnorewhitespacechanges(CCmdUI *pCmdUI);
156 afx_msg void OnViewIgnoreallwhitespacechanges();
157 afx_msg void OnUpdateViewIgnoreallwhitespacechanges(CCmdUI *pCmdUI);
158 afx_msg void OnUpdateNavigateNextinlinediff(CCmdUI *pCmdUI);
159 afx_msg void OnUpdateNavigatePrevinlinediff(CCmdUI *pCmdUI);
160 afx_msg void OnViewMovedBlocks();
161 afx_msg void OnUpdateViewMovedBlocks(CCmdUI *pCmdUI);
162 afx_msg void OnViewWraplonglines();
163 afx_msg void OnUpdateViewWraplonglines(CCmdUI *pCmdUI);
164 afx_msg void OnIndicatorLeftview();
165 afx_msg void OnIndicatorRightview();
166 afx_msg void OnIndicatorBottomview();
167 afx_msg void OnTimer(UINT_PTR nIDEvent);
168 afx_msg void OnViewIgnorecomments();
169 afx_msg void OnUpdateViewIgnorecomments(CCmdUI *pCmdUI);
170 afx_msg void OnUpdateViewRegexFilter(CCmdUI *pCmdUI);
171 afx_msg void OnRegexfilter(UINT cmd);
172 afx_msg void OnDummyEnabled() {};
173 afx_msg void OnEncodingLeft(UINT cmd);
174 afx_msg void OnEncodingRight(UINT cmd);
175 afx_msg void OnEncodingBottom(UINT cmd);
176 afx_msg void OnEOLLeft(UINT cmd);
177 afx_msg void OnEOLRight(UINT cmd);
178 afx_msg void OnEOLBottom(UINT cmd);
179 afx_msg void OnTabModeLeft(UINT cmd);
180 afx_msg void OnTabModeRight(UINT cmd);
181 afx_msg void OnTabModeBottom(UINT cmd);
182 afx_msg void OnUpdateEncodingLeft(CCmdUI *pCmdUI);
183 afx_msg void OnUpdateEncodingRight(CCmdUI *pCmdUI);
184 afx_msg void OnUpdateEncodingBottom(CCmdUI *pCmdUI);
185 afx_msg void OnUpdateEOLLeft(CCmdUI *pCmdUI);
186 afx_msg void OnUpdateEOLRight(CCmdUI *pCmdUI);
187 afx_msg void OnUpdateEOLBottom(CCmdUI *pCmdUI);
188 afx_msg void OnUpdateTabModeLeft(CCmdUI *pCmdUI);
189 afx_msg void OnUpdateTabModeRight(CCmdUI *pCmdUI);
190 afx_msg void OnUpdateTabModeBottom(CCmdUI *pCmdUI);
192 DECLARE_MESSAGE_MAP()
193 protected:
194 void UpdateLayout();
195 virtual BOOL PatchFile(CString sFilePath, bool bContentMods, bool bPropMods, CString sVersion, BOOL bAutoPatch) override;
196 virtual BOOL DiffFiles(CString sURL1, CString sRev1, CString sURL2, CString sRev2) override;
197 int CheckResolved();
198 BOOL MarkAsResolved();
199 int SaveFile(const CString& sFilePath);
200 void WriteWindowPlacement(WINDOWPLACEMENT * pwp);
201 BOOL ReadWindowPlacement(WINDOWPLACEMENT * pwp);
202 bool FileSave(bool bCheckResolved=true);
203 void PatchSave();
204 bool FileSaveAs(bool bCheckResolved=true);
205 void LoadIgnoreCommentData();
206 /// checks if there are modifications and asks the user to save them first
207 /// IDCANCEL is returned if the user wants to cancel.
208 /// If the user wanted to save the modifications, this method does the saving
209 /// itself.
210 int CheckForReload();
211 enum ECheckForSaveReason {
212 CHFSR_CLOSE, ///< closing apps
213 CHFSR_SWITCH, ///< switching views
214 CHFSR_RELOAD, ///< reload views also switching between 1 and 2 way diff
215 CHFSR_OPTIONS, ///< white space change, options
216 CHFSR_OPEN, ///< open open dialog
218 /// checks if there are modifications and asks the user to save them first
219 /// IDCANCEL is returned if the user wants to cancel.
220 /// If the user wanted to save the modifications, this method does the saving
221 /// itself.
222 int CheckForSave(ECheckForSaveReason eReason/* = CHFSR_SWITCH*/);
223 void DeleteBaseTheirsMineOnClose();
224 void OnViewLineUpDown(int direction);
225 void OnViewLineLeftRight(int direction);
226 static void OnTabMode(CBaseView *view, int cmd);
227 static void OnUpdateTabMode(CBaseView *view, CCmdUI *pCmdUI, int startid);
228 bool HasConflictsWontKeep();
229 bool TryGetFileName(CString& result);
230 CBaseView* GetActiveBaseView() const;
231 void OnViewTextFoldUnfold();
232 void OnViewTextFoldUnfold(CBaseView* view);
233 bool HasUnsavedEdits() const;
234 static bool HasUnsavedEdits(const CBaseView* view);
235 bool HasMarkedBlocks() const;
236 static bool IsViewGood(const CBaseView* view);
237 static bool HasPrevConflict(CBaseView* view);
238 static bool HasNextConflict(CBaseView* view);
239 static bool HasPrevInlineDiff(CBaseView* view);
240 static bool HasNextInlineDiff(CBaseView* view);
241 void BuildRegexSubitems(CMFCPopupMenu* pMenuPopup = nullptr);
242 bool AdjustUnicodeTypeForLoad(CFileTextLines::UnicodeType& type);
244 protected:
245 CMFCStatusBar m_wndStatusBar;
246 CCustomMFCRibbonStatusBar m_wndRibbonStatusBar;
247 CLocatorBar m_wndLocatorBar;
248 CLineDiffBar m_wndLineDiffBar;
249 CXSplitter m_wndSplitter;
250 CXSplitter m_wndSplitter2;
251 CFilePatchesDlg m_dlgFilePatches;
253 GitPatch m_Patch;
254 BOOL m_bInitSplitter;
255 bool m_bCheckReload;
257 bool m_bHasConflicts;
259 bool m_bInlineWordDiff;
260 bool m_bInlineDiff;
261 bool m_bLineDiff;
262 bool m_bLocatorBar;
263 bool m_bUseRibbons;
265 CMFCRibbonBar m_wndRibbonBar;
266 CMFCRibbonApplicationButton m_MainButton;
268 CRegDWORD m_regWrapLines;
269 CRegDWORD m_regViewModedBlocks;
270 CRegDWORD m_regOneWay;
271 CRegDWORD m_regCollapsed;
272 CRegDWORD m_regInlineDiff;
273 CRegDWORD m_regUseRibbons;
274 CRegDWORD m_regIgnoreComments;
276 std::map<CString, std::tuple<CString, CString, CString>> m_IgnoreCommentsMap;
277 CSimpleIni m_regexIni;
278 int m_regexIndex;
279 public:
280 CLeftView * m_pwndLeftView;
281 CRightView * m_pwndRightView;
282 CBottomView * m_pwndBottomView;
283 BOOL m_bOneWay;
284 BOOL m_bReversedPatch;
285 CDiffData m_Data;
286 bool m_bReadOnly;
287 bool m_bBlame;
288 int m_nMoveMovesToIgnore;
289 bool m_bCollapsed;
290 bool m_bViewMovedBlocks;
291 bool m_bWrapLines;
292 bool m_bSaveRequired;
293 bool m_bSaveRequiredOnConflicts;
294 bool m_bDeleteBaseTheirsMineOnClose;
295 HWND resolveMsgWnd;
296 WPARAM resolveMsgWParam;
297 LPARAM resolveMsgLParam;
299 const CMFCToolBar * GetToolbar() const { return &m_wndToolBar; }
300 void FillEncodingButton( CMFCRibbonButton * pButton, int start );
301 void FillEOLButton( CMFCRibbonButton * pButton, int start );
302 void FillTabModeButton(CMFCRibbonButton * pButton, int start);
303 CMFCMenuBar m_wndMenuBar;
304 CMFCToolBar m_wndToolBar;