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.
23 #include "LocatorBar.h"
24 #include "LineDiffBar.h"
25 #include "FilePatchesDlg.h"
27 #include "XSplitter.h"
29 #include "../../ext/SimpleIni/SimpleIni.h"
30 #include "CustomMFCRibbonStatusBar.h"
32 #include "NativeRibbonApp.h"
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
51 * \ingroup TortoiseMerge
52 * The main frame of TortoiseMerge. Handles all the menu and toolbar commands.
54 class CMainFrame
: public CFrameWndEx
, public CPatchFilesDlgCallBack
//CFrameWndEx
58 virtual ~CMainFrame();
60 void ShowDiffBar(bool bShow
);
61 void DiffLeftToBase();
62 void DiffRightToBase();
65 virtual void AssertValid() const;
66 virtual void Dump(CDumpContext
& dc
) const;
69 DECLARE_DYNCREATE(CMainFrame
)
71 virtual BOOL
PreCreateWindow(CREATESTRUCT
& cs
);
72 virtual BOOL
OnCreateClient(LPCREATESTRUCT lpcs
, CCreateContext
* pContext
);
73 virtual void ActivateFrame(int nCmdShow
= -1);
74 virtual BOOL
OnShowPopupMenu(CMFCPopupMenu
* pMenuPopup
);
75 /// line = -1 means keep the current position,
76 /// line >= 0 means scroll to that line,
77 /// and line == -2 means do nothing or scroll to first diff depending on registry setting
78 bool LoadViews(int line
= -2);
79 void ClearViewNamesAndPaths();
80 void SetWindowTitle();
81 void RecalcLayout(BOOL bNotify
= TRUE
) override
;
83 afx_msg LRESULT
OnTaskbarButtonCreated(WPARAM wParam
, LPARAM lParam
);
84 afx_msg LRESULT
OnIdleUpdateCmdUI(WPARAM wParam
, LPARAM
);
86 afx_msg
void OnFileSave();
87 afx_msg
void OnFileSaveAs();
88 afx_msg
void OnFileOpen();
89 afx_msg
void OnFileOpen(bool fillyours
);
91 afx_msg
void OnFileReload();
92 afx_msg
void OnClose();
93 afx_msg
void OnActivate(UINT
, CWnd
*, BOOL
);
94 afx_msg
void OnViewWhitespaces();
95 afx_msg
int OnCreate(LPCREATESTRUCT lpCreateStruct
);
96 afx_msg
void OnDestroy();
97 afx_msg
void OnSize(UINT nType
, int cx
, int cy
);
98 afx_msg
void OnUpdateFileSave(CCmdUI
*pCmdUI
);
99 afx_msg
void OnUpdateFileSaveAs(CCmdUI
*pCmdUI
);
100 afx_msg
void OnViewOnewaydiff();
101 afx_msg
void OnUpdateViewOnewaydiff(CCmdUI
*pCmdUI
);
102 afx_msg
void OnUpdateViewWhitespaces(CCmdUI
*pCmdUI
);
103 afx_msg
void OnViewOptions();
104 afx_msg
void OnViewLinedown();
105 afx_msg
void OnViewLineup();
106 afx_msg
void OnViewLineleft();
107 afx_msg
void OnViewLineright();
108 afx_msg
void OnEditUseTheirs();
109 afx_msg
void OnEditUseMine();
110 afx_msg
void OnEditUseTheirsThenMine();
111 afx_msg
void OnEditUseMineThenTheirs();
112 afx_msg
void OnUpdateEditUseminethentheirblock(CCmdUI
*pCmdUI
);
113 afx_msg
void OnUpdateEditUsemyblock(CCmdUI
*pCmdUI
);
114 afx_msg
void OnUpdateEditUsetheirblock(CCmdUI
*pCmdUI
);
115 afx_msg
void OnUpdateEditUsetheirthenmyblock(CCmdUI
*pCmdUI
);
116 afx_msg
void OnUpdateMergeMarkasresolved(CCmdUI
*pCmdUI
);
117 afx_msg
void OnMergeMarkasresolved();
118 afx_msg
void OnUpdateMergeNextconflict(CCmdUI
*pCmdUI
);
119 afx_msg
void OnUpdateMergePreviousconflict(CCmdUI
*pCmdUI
);
120 afx_msg
void OnUpdateEditCopy(CCmdUI
*pCmdUI
);
121 afx_msg
void OnUpdateEditPaste(CCmdUI
*pCmdUI
);
122 afx_msg
void OnMoving(UINT fwSide
, LPRECT pRect
);
123 afx_msg
void OnViewSwitchleft();
124 afx_msg
void OnUpdateViewSwitchleft(CCmdUI
*pCmdUI
);
125 afx_msg
void OnUpdateViewShowfilelist(CCmdUI
*pCmdUI
);
126 afx_msg
void OnViewShowfilelist();
127 afx_msg
void OnEditUndo();
128 afx_msg
void OnUpdateEditUndo(CCmdUI
*pCmdUI
);
129 afx_msg
void OnEditRedo();
130 afx_msg
void OnUpdateEditRedo(CCmdUI
*pCmdUI
);
131 afx_msg
void OnEditEnable();
132 afx_msg
void OnUpdateEditEnable(CCmdUI
*pCmdUI
);
133 afx_msg
void OnViewInlinediffword();
134 afx_msg
void OnUpdateViewInlinediffword(CCmdUI
*pCmdUI
);
135 afx_msg
void OnViewInlinediff();
136 afx_msg
void OnUpdateViewInlinediff(CCmdUI
*pCmdUI
);
137 afx_msg
void OnUpdateEditCreateunifieddifffile(CCmdUI
*pCmdUI
);
138 afx_msg
void OnEditCreateunifieddifffile();
139 afx_msg
void OnUpdateViewLinediffbar(CCmdUI
*pCmdUI
);
140 afx_msg
void OnViewLinediffbar();
141 afx_msg
void OnUpdateViewLocatorbar(CCmdUI
*pCmdUI
);
142 afx_msg
void OnUpdateViewBars(CCmdUI
*pCmdUI
);
143 afx_msg
void OnViewLocatorbar();
144 afx_msg
void OnEditUseleftblock();
145 afx_msg
void OnUpdateUseBlock(CCmdUI
*pCmdUI
);
146 afx_msg
void OnUpdateEditUseleftblock(CCmdUI
*pCmdUI
);
147 afx_msg
void OnEditUseleftfile();
148 afx_msg
void OnUpdateEditUseleftfile(CCmdUI
*pCmdUI
);
149 afx_msg
void OnEditUseblockfromleftbeforeright();
150 afx_msg
void OnUpdateEditUseblockfromleftbeforeright(CCmdUI
*pCmdUI
);
151 afx_msg
void OnEditUseblockfromrightbeforeleft();
152 afx_msg
void OnUpdateEditUseblockfromrightbeforeleft(CCmdUI
*pCmdUI
);
153 afx_msg
void OnUpdateNavigateNextdifference(CCmdUI
*pCmdUI
);
154 afx_msg
void OnUpdateNavigatePreviousdifference(CCmdUI
*pCmdUI
);
155 afx_msg
void OnViewCollapsed();
156 afx_msg
void OnUpdateViewCollapsed(CCmdUI
*pCmdUI
);
157 afx_msg
void OnViewComparewhitespaces();
158 afx_msg
void OnUpdateViewComparewhitespaces(CCmdUI
*pCmdUI
);
159 afx_msg
void OnViewIgnorewhitespacechanges();
160 afx_msg
void OnUpdateViewIgnorewhitespacechanges(CCmdUI
*pCmdUI
);
161 afx_msg
void OnViewIgnoreallwhitespacechanges();
162 afx_msg
void OnUpdateViewIgnoreallwhitespacechanges(CCmdUI
*pCmdUI
);
163 afx_msg
void OnUpdateNavigateNextinlinediff(CCmdUI
*pCmdUI
);
164 afx_msg
void OnUpdateNavigatePrevinlinediff(CCmdUI
*pCmdUI
);
165 afx_msg
void OnViewMovedBlocks();
166 afx_msg
void OnUpdateViewMovedBlocks(CCmdUI
*pCmdUI
);
167 afx_msg
void OnViewWraplonglines();
168 afx_msg
void OnUpdateViewWraplonglines(CCmdUI
*pCmdUI
);
169 afx_msg
void OnIndicatorLeftview();
170 afx_msg
void OnIndicatorRightview();
171 afx_msg
void OnIndicatorBottomview();
172 afx_msg
void OnTimer(UINT_PTR nIDEvent
);
173 afx_msg
void OnViewIgnorecomments();
174 afx_msg
void OnUpdateViewIgnorecomments(CCmdUI
*pCmdUI
);
175 afx_msg
void OnUpdateViewRegexFilter(CCmdUI
*pCmdUI
);
176 afx_msg
void OnRegexfilter(UINT cmd
);
177 afx_msg
void OnDummyEnabled() {};
178 afx_msg
void OnEncodingLeft(UINT cmd
);
179 afx_msg
void OnEncodingRight(UINT cmd
);
180 afx_msg
void OnEncodingBottom(UINT cmd
);
181 afx_msg
void OnEOLLeft(UINT cmd
);
182 afx_msg
void OnEOLRight(UINT cmd
);
183 afx_msg
void OnEOLBottom(UINT cmd
);
184 afx_msg
void OnTabModeLeft(UINT cmd
);
185 afx_msg
void OnTabModeRight(UINT cmd
);
186 afx_msg
void OnTabModeBottom(UINT cmd
);
187 afx_msg
void OnUpdateEncodingLeft(CCmdUI
*pCmdUI
);
188 afx_msg
void OnUpdateEncodingRight(CCmdUI
*pCmdUI
);
189 afx_msg
void OnUpdateEncodingBottom(CCmdUI
*pCmdUI
);
190 afx_msg
void OnUpdateEOLLeft(CCmdUI
*pCmdUI
);
191 afx_msg
void OnUpdateEOLRight(CCmdUI
*pCmdUI
);
192 afx_msg
void OnUpdateEOLBottom(CCmdUI
*pCmdUI
);
193 afx_msg
void OnUpdateTabModeLeft(CCmdUI
*pCmdUI
);
194 afx_msg
void OnUpdateTabModeRight(CCmdUI
*pCmdUI
);
195 afx_msg
void OnUpdateTabModeBottom(CCmdUI
*pCmdUI
);
196 afx_msg
void OnUpdateThreeWayActions(CCmdUI
* pCmdUI
);
197 afx_msg
void OnRegexNoFilter();
198 afx_msg
void OnUpdateRegexNoFilter(CCmdUI
* pCmdUI
);
200 DECLARE_MESSAGE_MAP()
203 virtual BOOL
PatchFile(CString sFilePath
, bool bContentMods
, bool bPropMods
, CString sVersion
, BOOL bAutoPatch
) override
;
204 virtual BOOL
DiffFiles(CString sURL1
, CString sRev1
, CString sURL2
, CString sRev2
) override
;
206 BOOL
MarkAsResolved();
207 int SaveFile(const CString
& sFilePath
);
208 void WriteWindowPlacement(WINDOWPLACEMENT
* pwp
);
209 BOOL
ReadWindowPlacement(WINDOWPLACEMENT
* pwp
);
210 bool FileSave(bool bCheckResolved
=true);
212 bool FileSaveAs(bool bCheckResolved
=true);
213 void LoadIgnoreCommentData();
214 /// checks if there are modifications and asks the user to save them first
215 /// IDCANCEL is returned if the user wants to cancel.
216 /// If the user wanted to save the modifications, this method does the saving
218 int CheckForReload();
219 enum ECheckForSaveReason
{
220 CHFSR_CLOSE
, ///< closing apps
221 CHFSR_SWITCH
, ///< switching views
222 CHFSR_RELOAD
, ///< reload views also switching between 1 and 2 way diff
223 CHFSR_OPTIONS
, ///< white space change, options
224 CHFSR_OPEN
, ///< open open dialog
226 /// checks if there are modifications and asks the user to save them first
227 /// IDCANCEL is returned if the user wants to cancel.
228 /// If the user wanted to save the modifications, this method does the saving
230 int CheckForSave(ECheckForSaveReason eReason
/* = CHFSR_SWITCH*/);
231 void DeleteBaseTheirsMineOnClose();
232 void OnViewLineUpDown(int direction
);
233 void OnViewLineLeftRight(int direction
);
234 static void OnTabMode(CBaseView
*view
, int cmd
);
235 static void OnUpdateTabMode(CBaseView
*view
, CCmdUI
*pCmdUI
, int startid
);
236 bool HasConflictsWontKeep();
237 bool TryGetFileName(CString
& result
);
238 CBaseView
* GetActiveBaseView() const;
239 void OnViewTextFoldUnfold();
240 void OnViewTextFoldUnfold(CBaseView
* view
);
241 bool HasUnsavedEdits() const;
242 static bool HasUnsavedEdits(const CBaseView
* view
);
243 bool HasMarkedBlocks() const;
244 static bool IsViewGood(const CBaseView
* view
);
245 static bool HasPrevConflict(CBaseView
* view
);
246 static bool HasNextConflict(CBaseView
* view
);
247 static bool HasPrevInlineDiff(CBaseView
* view
);
248 static bool HasNextInlineDiff(CBaseView
* view
);
249 void BuildRegexSubitems(CMFCPopupMenu
* pMenuPopup
= nullptr);
250 bool AdjustUnicodeTypeForLoad(CFileTextLines::UnicodeType
& type
);
251 void DiffTwo(const CWorkingFile
& file1
, const CWorkingFile
& file2
);
254 CMFCStatusBar m_wndStatusBar
;
255 CCustomMFCRibbonStatusBar m_wndRibbonStatusBar
;
256 CLocatorBar m_wndLocatorBar
;
257 CLineDiffBar m_wndLineDiffBar
;
258 CXSplitter m_wndSplitter
;
259 CXSplitter m_wndSplitter2
;
260 CFilePatchesDlg m_dlgFilePatches
;
263 BOOL m_bInitSplitter
;
266 bool m_bHasConflicts
;
268 bool m_bInlineWordDiff
;
274 CRegDWORD m_regWrapLines
;
275 CRegDWORD m_regViewModedBlocks
;
276 CRegDWORD m_regOneWay
;
277 CRegDWORD m_regCollapsed
;
278 CRegDWORD m_regInlineDiff
;
279 CRegDWORD m_regUseRibbons
;
280 CRegDWORD m_regIgnoreComments
;
282 std::map
<CString
, std::tuple
<CString
, CString
, CString
>> m_IgnoreCommentsMap
;
283 CSimpleIni m_regexIni
;
286 CLeftView
* m_pwndLeftView
;
287 CRightView
* m_pwndRightView
;
288 CBottomView
* m_pwndBottomView
;
290 BOOL m_bReversedPatch
;
294 int m_nMoveMovesToIgnore
;
296 bool m_bViewMovedBlocks
;
298 bool m_bSaveRequired
;
299 bool m_bSaveRequiredOnConflicts
;
300 bool m_bDeleteBaseTheirsMineOnClose
;
302 WPARAM resolveMsgWParam
;
303 LPARAM resolveMsgLParam
;
305 const CMFCToolBar
* GetToolbar() const { return &m_wndToolBar
; }
306 void FillEncodingButton( CMFCRibbonButton
* pButton
, int start
);
307 void FillEOLButton( CMFCRibbonButton
* pButton
, int start
);
308 void FillTabModeButton(CMFCRibbonButton
* pButton
, int start
);
309 CMFCMenuBar m_wndMenuBar
;
310 CMFCToolBar m_wndToolBar
;
312 std::unique_ptr
<CNativeRibbonApp
> m_pRibbonApp
;
313 CComPtr
<IUIFramework
> m_pRibbonFramework
;