1 // TortoiseGitMerge - a Diff/Patch program
3 // Copyright (C) 2013 - TortoiseGit
4 // Copyright (C) 2006-2014 - 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 "SimpleIni.h"
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
50 * \ingroup TortoiseMerge
51 * The main frame of TortoiseMerge. Handles all the menu and toolbar commands.
53 class CMainFrame
: public CFrameWndEx
, public CPatchFilesDlgCallBack
//CFrameWndEx
57 virtual ~CMainFrame();
59 void ShowDiffBar(bool bShow
);
61 virtual void AssertValid() const;
62 virtual void Dump(CDumpContext
& dc
) const;
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 /// line = -1 means keep the current position,
71 /// line >= 0 means scroll to that line,
72 /// and line == -2 means do nothing or scroll to first diff depending on registry setting
73 bool LoadViews(int line
= -2);
74 void ClearViewNamesAndPaths();
75 void SetWindowTitle();
77 afx_msg LRESULT
OnTaskbarButtonCreated(WPARAM wParam
, LPARAM lParam
);
78 afx_msg
void OnApplicationLook(UINT id
);
79 afx_msg
void OnUpdateApplicationLook(CCmdUI
* pCmdUI
);
81 afx_msg
void OnFileSave();
82 afx_msg
void OnFileSaveAs();
83 afx_msg
void OnFileOpen();
84 afx_msg
void OnFileOpen(bool fillyours
);
86 afx_msg
void OnFileReload();
87 afx_msg
void OnClose();
88 afx_msg
void OnActivate(UINT
, CWnd
*, BOOL
);
89 afx_msg
void OnViewWhitespaces();
90 afx_msg
int OnCreate(LPCREATESTRUCT lpCreateStruct
);
91 afx_msg
void OnSize(UINT nType
, int cx
, int cy
);
92 afx_msg
void OnUpdateFileSave(CCmdUI
*pCmdUI
);
93 afx_msg
void OnUpdateFileSaveAs(CCmdUI
*pCmdUI
);
94 afx_msg
void OnViewOnewaydiff();
95 afx_msg
void OnUpdateViewOnewaydiff(CCmdUI
*pCmdUI
);
96 afx_msg
void OnUpdateViewWhitespaces(CCmdUI
*pCmdUI
);
97 afx_msg
void OnViewOptions();
98 afx_msg
void OnViewLinedown();
99 afx_msg
void OnViewLineup();
100 afx_msg
void OnViewLineleft();
101 afx_msg
void OnViewLineright();
102 afx_msg
void OnEditUseTheirs();
103 afx_msg
void OnEditUseMine();
104 afx_msg
void OnEditUseTheirsThenMine();
105 afx_msg
void OnEditUseMineThenTheirs();
106 afx_msg
void OnUpdateEditUseminethentheirblock(CCmdUI
*pCmdUI
);
107 afx_msg
void OnUpdateEditUsemyblock(CCmdUI
*pCmdUI
);
108 afx_msg
void OnUpdateEditUsetheirblock(CCmdUI
*pCmdUI
);
109 afx_msg
void OnUpdateEditUsetheirthenmyblock(CCmdUI
*pCmdUI
);
110 afx_msg
void OnUpdateMergeMarkasresolved(CCmdUI
*pCmdUI
);
111 afx_msg
void OnMergeMarkasresolved();
112 afx_msg
void OnUpdateMergeNextconflict(CCmdUI
*pCmdUI
);
113 afx_msg
void OnUpdateMergePreviousconflict(CCmdUI
*pCmdUI
);
114 afx_msg
void OnUpdateEditCopy(CCmdUI
*pCmdUI
);
115 afx_msg
void OnUpdateEditPaste(CCmdUI
*pCmdUI
);
116 afx_msg
void OnMoving(UINT fwSide
, LPRECT pRect
);
117 afx_msg
void OnViewSwitchleft();
118 afx_msg
void OnUpdateViewSwitchleft(CCmdUI
*pCmdUI
);
119 afx_msg
void OnUpdateViewShowfilelist(CCmdUI
*pCmdUI
);
120 afx_msg
void OnViewShowfilelist();
121 afx_msg
void OnEditUndo();
122 afx_msg
void OnUpdateEditUndo(CCmdUI
*pCmdUI
);
123 afx_msg
void OnEditEnable();
124 afx_msg
void OnUpdateEditEnable(CCmdUI
*pCmdUI
);
125 afx_msg
void OnViewInlinediffword();
126 afx_msg
void OnUpdateViewInlinediffword(CCmdUI
*pCmdUI
);
127 afx_msg
void OnViewInlinediff();
128 afx_msg
void OnUpdateViewInlinediff(CCmdUI
*pCmdUI
);
129 afx_msg
void OnUpdateEditCreateunifieddifffile(CCmdUI
*pCmdUI
);
130 afx_msg
void OnEditCreateunifieddifffile();
131 afx_msg
void OnUpdateViewLinediffbar(CCmdUI
*pCmdUI
);
132 afx_msg
void OnViewLinediffbar();
133 afx_msg
void OnUpdateViewLocatorbar(CCmdUI
*pCmdUI
);
134 afx_msg
void OnViewLocatorbar();
135 afx_msg
void OnEditUseleftblock();
136 afx_msg
void OnUpdateUseBlock(CCmdUI
*pCmdUI
);
137 afx_msg
void OnUpdateEditUseleftblock(CCmdUI
*pCmdUI
);
138 afx_msg
void OnEditUseleftfile();
139 afx_msg
void OnUpdateEditUseleftfile(CCmdUI
*pCmdUI
);
140 afx_msg
void OnEditUseblockfromleftbeforeright();
141 afx_msg
void OnUpdateEditUseblockfromleftbeforeright(CCmdUI
*pCmdUI
);
142 afx_msg
void OnEditUseblockfromrightbeforeleft();
143 afx_msg
void OnUpdateEditUseblockfromrightbeforeleft(CCmdUI
*pCmdUI
);
144 afx_msg
void OnUpdateNavigateNextdifference(CCmdUI
*pCmdUI
);
145 afx_msg
void OnUpdateNavigatePreviousdifference(CCmdUI
*pCmdUI
);
146 afx_msg
void OnViewCollapsed();
147 afx_msg
void OnUpdateViewCollapsed(CCmdUI
*pCmdUI
);
148 afx_msg
void OnViewComparewhitespaces();
149 afx_msg
void OnUpdateViewComparewhitespaces(CCmdUI
*pCmdUI
);
150 afx_msg
void OnViewIgnorewhitespacechanges();
151 afx_msg
void OnUpdateViewIgnorewhitespacechanges(CCmdUI
*pCmdUI
);
152 afx_msg
void OnViewIgnoreallwhitespacechanges();
153 afx_msg
void OnUpdateViewIgnoreallwhitespacechanges(CCmdUI
*pCmdUI
);
154 afx_msg
void OnUpdateNavigateNextinlinediff(CCmdUI
*pCmdUI
);
155 afx_msg
void OnUpdateNavigatePrevinlinediff(CCmdUI
*pCmdUI
);
156 afx_msg
void OnViewMovedBlocks();
157 afx_msg
void OnUpdateViewMovedBlocks(CCmdUI
*pCmdUI
);
158 afx_msg
void OnViewWraplonglines();
159 afx_msg
void OnUpdateViewWraplonglines(CCmdUI
*pCmdUI
);
160 afx_msg
void OnIndicatorLeftview();
161 afx_msg
void OnIndicatorRightview();
162 afx_msg
void OnIndicatorBottomview();
163 afx_msg
void OnTimer(UINT_PTR nIDEvent
);
164 afx_msg
void OnViewIgnorecomments();
165 afx_msg
void OnUpdateViewIgnorecomments(CCmdUI
*pCmdUI
);
166 afx_msg
void OnUpdateViewRegexFilter(CCmdUI
*pCmdUI
);
167 afx_msg
void OnRegexfilter(UINT cmd
);
168 afx_msg
void OnDummyEnabled() {};
169 afx_msg
void OnEncodingLeft(UINT cmd
);
170 afx_msg
void OnEncodingRight(UINT cmd
);
171 afx_msg
void OnEncodingBottom(UINT cmd
);
172 afx_msg
void OnEOLLeft(UINT cmd
);
173 afx_msg
void OnEOLRight(UINT cmd
);
174 afx_msg
void OnEOLBottom(UINT cmd
);
175 afx_msg
void OnTabModeLeft(UINT cmd
);
176 afx_msg
void OnTabModeRight(UINT cmd
);
177 afx_msg
void OnTabModeBottom(UINT cmd
);
178 afx_msg
void OnUpdateEncodingLeft(CCmdUI
*pCmdUI
);
179 afx_msg
void OnUpdateEncodingRight(CCmdUI
*pCmdUI
);
180 afx_msg
void OnUpdateEncodingBottom(CCmdUI
*pCmdUI
);
181 afx_msg
void OnUpdateEOLLeft(CCmdUI
*pCmdUI
);
182 afx_msg
void OnUpdateEOLRight(CCmdUI
*pCmdUI
);
183 afx_msg
void OnUpdateEOLBottom(CCmdUI
*pCmdUI
);
184 afx_msg
void OnUpdateTabModeLeft(CCmdUI
*pCmdUI
);
185 afx_msg
void OnUpdateTabModeRight(CCmdUI
*pCmdUI
);
186 afx_msg
void OnUpdateTabModeBottom(CCmdUI
*pCmdUI
);
188 DECLARE_MESSAGE_MAP()
191 virtual BOOL
PatchFile(CString sFilePath
, bool bContentMods
, bool bPropMods
, CString sVersion
, BOOL bAutoPatch
) override
;
192 virtual BOOL
DiffFiles(CString sURL1
, CString sRev1
, CString sURL2
, CString sRev2
) override
;
194 BOOL
MarkAsResolved();
195 int SaveFile(const CString
& sFilePath
);
196 void WriteWindowPlacement(WINDOWPLACEMENT
* pwp
);
197 BOOL
ReadWindowPlacement(WINDOWPLACEMENT
* pwp
);
198 bool FileSave(bool bCheckResolved
=true);
200 bool FileSaveAs(bool bCheckResolved
=true);
201 void LoadIgnoreCommentData();
202 /// checks if there are modifications and asks the user to save them first
203 /// IDCANCEL is returned if the user wants to cancel.
204 /// If the user wanted to save the modifications, this method does the saving
206 int CheckForReload();
207 enum ECheckForSaveReason
{
208 CHFSR_CLOSE
, ///< closing apps
209 CHFSR_SWITCH
, ///< switching views
210 CHFSR_RELOAD
, ///< reload views also switching between 1 and 2 way diff
211 CHFSR_OPTIONS
, ///< white space change, options
212 CHFSR_OPEN
, ///< open open dialog
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 CheckForSave(ECheckForSaveReason eReason
/* = CHFSR_SWITCH*/);
219 void OnViewLineUpDown(int direction
);
220 void OnViewLineLeftRight(int direction
);
221 static void OnTabMode(CBaseView
*view
, int cmd
);
222 static void OnUpdateTabMode(CBaseView
*view
, CCmdUI
*pCmdUI
, int startid
);
223 bool HasConflictsWontKeep();
224 bool TryGetFileName(CString
& result
);
225 CBaseView
* GetActiveBaseView() const;
226 void OnViewTextFoldUnfold();
227 void OnViewTextFoldUnfold(CBaseView
* view
);
228 bool HasUnsavedEdits() const;
229 static bool HasUnsavedEdits(const CBaseView
* view
);
230 static bool IsViewGood(const CBaseView
* view
);
231 static bool HasPrevConflict(CBaseView
* view
);
232 static bool HasNextConflict(CBaseView
* view
);
233 static bool HasPrevInlineDiff(CBaseView
* view
);
234 static bool HasNextInlineDiff(CBaseView
* view
);
235 void BuildRegexSubitems();
238 CMFCStatusBar m_wndStatusBar
;
239 CMFCRibbonStatusBar m_wndRibbonStatusBar
;
240 CLocatorBar m_wndLocatorBar
;
241 CLineDiffBar m_wndLineDiffBar
;
242 CXSplitter m_wndSplitter
;
243 CXSplitter m_wndSplitter2
;
244 CFilePatchesDlg m_dlgFilePatches
;
247 BOOL m_bInitSplitter
;
250 bool m_bHasConflicts
;
252 bool m_bInlineWordDiff
;
257 bool m_bUseTaskDialog
;
259 CMFCRibbonBar m_wndRibbonBar
;
260 CMFCRibbonApplicationButton m_MainButton
;
262 CRegDWORD m_regWrapLines
;
263 CRegDWORD m_regViewModedBlocks
;
264 CRegDWORD m_regOneWay
;
265 CRegDWORD m_regCollapsed
;
266 CRegDWORD m_regInlineDiff
;
267 CRegDWORD m_regUseRibbons
;
268 CRegDWORD m_regUseTaskDialog
;
269 CRegDWORD m_regIgnoreComments
;
271 std::map
<CString
, std::tuple
<CString
, CString
, CString
>> m_IgnoreCommentsMap
;
272 CSimpleIni m_regexIni
;
275 CLeftView
* m_pwndLeftView
;
276 CRightView
* m_pwndRightView
;
277 CBottomView
* m_pwndBottomView
;
279 BOOL m_bReversedPatch
;
283 int m_nMoveMovesToIgnore
;
285 bool m_bViewMovedBlocks
;
287 bool m_bSaveRequired
;
288 bool m_bSaveRequiredOnConflicts
;
290 WPARAM resolveMsgWParam
;
291 LPARAM resolveMsgLParam
;
293 const CMFCToolBar
* GetToolbar() const { return &m_wndToolBar
; }
294 void FillEncodingButton( CMFCRibbonButton
* pButton
, int start
);
295 void FillEOLButton( CMFCRibbonButton
* pButton
, int start
);
296 void FillTabModeButton(CMFCRibbonButton
* pButton
, int start
);
297 CMFCMenuBar m_wndMenuBar
;
298 CMFCToolBar m_wndToolBar
;