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