1 // TortoiseGitMerge - a Diff/Patch program
3 // Copyright (C) 2013 - TortoiseGit
4 // Copyright (C) 2006-2012 - 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"
33 #define MOVESTOIGNORE 3
36 * \ingroup TortoiseMerge
37 * The main frame of TortoiseMerge. Handles all the menu and toolbar commands.
39 class CMainFrame
: public CFrameWndEx
, public CPatchFilesDlgCallBack
//CFrameWndEx
44 virtual ~CMainFrame();
46 void ShowDiffBar(bool bShow
);
48 virtual void AssertValid() const;
49 virtual void Dump(CDumpContext
& dc
) const;
52 DECLARE_DYNCREATE(CMainFrame
)
54 virtual BOOL
PreCreateWindow(CREATESTRUCT
& cs
);
55 virtual BOOL
OnCreateClient(LPCREATESTRUCT lpcs
, CCreateContext
* pContext
);
56 virtual void ActivateFrame(int nCmdShow
= -1);
57 /// line = -1 means keep the current position,
58 /// line >= 0 means scroll to that line,
59 /// and line == -2 means do nothing or scroll to first diff depending on registry setting
60 bool LoadViews(int line
= -2);
61 void ClearViewNamesAndPaths();
62 void SetWindowTitle();
64 afx_msg LRESULT
OnTaskbarButtonCreated(WPARAM wParam
, LPARAM lParam
);
65 afx_msg
void OnApplicationLook(UINT id
);
66 afx_msg
void OnUpdateApplicationLook(CCmdUI
* pCmdUI
);
68 afx_msg
void OnFileSave();
69 afx_msg
void OnFileSaveAs();
70 afx_msg
void OnFileOpen();
71 afx_msg
void OnFileReload();
72 afx_msg
void OnClose();
73 afx_msg
void OnActivate(UINT
, CWnd
*, BOOL
);
74 afx_msg
void OnViewWhitespaces();
75 afx_msg
int OnCreate(LPCREATESTRUCT lpCreateStruct
);
76 afx_msg
void OnSize(UINT nType
, int cx
, int cy
);
77 afx_msg
void OnUpdateFileSave(CCmdUI
*pCmdUI
);
78 afx_msg
void OnUpdateFileSaveAs(CCmdUI
*pCmdUI
);
79 afx_msg
void OnViewOnewaydiff();
80 afx_msg
void OnUpdateViewOnewaydiff(CCmdUI
*pCmdUI
);
81 afx_msg
void OnUpdateViewWhitespaces(CCmdUI
*pCmdUI
);
82 afx_msg
void OnViewOptions();
83 afx_msg
void OnViewLinedown();
84 afx_msg
void OnViewLineup();
85 afx_msg
void OnViewLineleft();
86 afx_msg
void OnViewLineright();
87 afx_msg
void OnEditUseTheirs();
88 afx_msg
void OnEditUseMine();
89 afx_msg
void OnEditUseTheirsThenMine();
90 afx_msg
void OnEditUseMineThenTheirs();
91 afx_msg
void OnUpdateEditUseminethentheirblock(CCmdUI
*pCmdUI
);
92 afx_msg
void OnUpdateEditUsemyblock(CCmdUI
*pCmdUI
);
93 afx_msg
void OnUpdateEditUsetheirblock(CCmdUI
*pCmdUI
);
94 afx_msg
void OnUpdateEditUsetheirthenmyblock(CCmdUI
*pCmdUI
);
95 afx_msg
void OnUpdateMergeMarkasresolved(CCmdUI
*pCmdUI
);
96 afx_msg
void OnMergeMarkasresolved();
97 afx_msg
void OnUpdateMergeNextconflict(CCmdUI
*pCmdUI
);
98 afx_msg
void OnUpdateMergePreviousconflict(CCmdUI
*pCmdUI
);
99 afx_msg
void OnUpdateEditCopy(CCmdUI
*pCmdUI
);
100 afx_msg
void OnUpdateEditPaste(CCmdUI
*pCmdUI
);
101 afx_msg
void OnMoving(UINT fwSide
, LPRECT pRect
);
102 afx_msg
void OnViewSwitchleft();
103 afx_msg
void OnUpdateViewSwitchleft(CCmdUI
*pCmdUI
);
104 afx_msg
void OnUpdateViewShowfilelist(CCmdUI
*pCmdUI
);
105 afx_msg
void OnViewShowfilelist();
106 afx_msg
void OnEditUndo();
107 afx_msg
void OnUpdateEditUndo(CCmdUI
*pCmdUI
);
108 afx_msg
void OnEditEnable();
109 afx_msg
void OnUpdateEditEnable(CCmdUI
*pCmdUI
);
110 afx_msg
void OnViewInlinediffword();
111 afx_msg
void OnUpdateViewInlinediffword(CCmdUI
*pCmdUI
);
112 afx_msg
void OnViewInlinediff();
113 afx_msg
void OnUpdateViewInlinediff(CCmdUI
*pCmdUI
);
114 afx_msg
void OnUpdateEditCreateunifieddifffile(CCmdUI
*pCmdUI
);
115 afx_msg
void OnEditCreateunifieddifffile();
116 afx_msg
void OnUpdateViewLinediffbar(CCmdUI
*pCmdUI
);
117 afx_msg
void OnViewLinediffbar();
118 afx_msg
void OnUpdateViewLocatorbar(CCmdUI
*pCmdUI
);
119 afx_msg
void OnViewLocatorbar();
120 afx_msg
void OnEditUseleftblock();
121 afx_msg
void OnUpdateUseBlock(CCmdUI
*pCmdUI
);
122 afx_msg
void OnUpdateEditUseleftblock(CCmdUI
*pCmdUI
);
123 afx_msg
void OnEditUseleftfile();
124 afx_msg
void OnUpdateEditUseleftfile(CCmdUI
*pCmdUI
);
125 afx_msg
void OnEditUseblockfromleftbeforeright();
126 afx_msg
void OnUpdateEditUseblockfromleftbeforeright(CCmdUI
*pCmdUI
);
127 afx_msg
void OnEditUseblockfromrightbeforeleft();
128 afx_msg
void OnUpdateEditUseblockfromrightbeforeleft(CCmdUI
*pCmdUI
);
129 afx_msg
void OnUpdateNavigateNextdifference(CCmdUI
*pCmdUI
);
130 afx_msg
void OnUpdateNavigatePreviousdifference(CCmdUI
*pCmdUI
);
131 afx_msg
void OnViewCollapsed();
132 afx_msg
void OnUpdateViewCollapsed(CCmdUI
*pCmdUI
);
133 afx_msg
void OnViewComparewhitespaces();
134 afx_msg
void OnUpdateViewComparewhitespaces(CCmdUI
*pCmdUI
);
135 afx_msg
void OnViewIgnorewhitespacechanges();
136 afx_msg
void OnUpdateViewIgnorewhitespacechanges(CCmdUI
*pCmdUI
);
137 afx_msg
void OnViewIgnoreallwhitespacechanges();
138 afx_msg
void OnUpdateViewIgnoreallwhitespacechanges(CCmdUI
*pCmdUI
);
139 afx_msg
void OnUpdateNavigateNextinlinediff(CCmdUI
*pCmdUI
);
140 afx_msg
void OnUpdateNavigatePrevinlinediff(CCmdUI
*pCmdUI
);
141 afx_msg
void OnViewMovedBlocks();
142 afx_msg
void OnUpdateViewMovedBlocks(CCmdUI
*pCmdUI
);
143 afx_msg
void OnViewWraplonglines();
144 afx_msg
void OnUpdateViewWraplonglines(CCmdUI
*pCmdUI
);
146 DECLARE_MESSAGE_MAP()
149 virtual BOOL
PatchFile(CString sFilePath
, bool bContentMods
, bool bPropMods
, CString sVersion
, BOOL bAutoPatch
) override
;
150 virtual BOOL
DiffFiles(CString sURL1
, CString sRev1
, CString sURL2
, CString sRev2
) override
;
152 BOOL
MarkAsResolved();
153 int SaveFile(const CString
& sFilePath
);
154 void WriteWindowPlacement(WINDOWPLACEMENT
* pwp
);
155 BOOL
ReadWindowPlacement(WINDOWPLACEMENT
* pwp
);
156 bool FileSave(bool bCheckResolved
=true);
158 bool FileSaveAs(bool bCheckResolved
=true);
159 /// checks if there are modifications and asks the user to save them first
160 /// IDCANCEL is returned if the user wants to cancel.
161 /// If the user wanted to save the modifications, this method does the saving
163 int CheckForReload();
164 enum ECheckForSaveReason
{
165 CHFSR_CLOSE
, ///< closing apps
166 CHFSR_SWITCH
, ///< switching views
167 CHFSR_RELOAD
, ///< reload views also switching between 1 and 2 way diff
168 CHFSR_OPTIONS
, ///< white space change, options
169 CHFSR_OPEN
, ///< open open dialog
171 /// checks if there are modifications and asks the user to save them first
172 /// IDCANCEL is returned if the user wants to cancel.
173 /// If the user wanted to save the modifications, this method does the saving
175 int CheckForSave(ECheckForSaveReason eReason
/* = CHFSR_SWITCH*/);
176 void OnViewLineUpDown(int direction
);
177 void OnViewLineLeftRight(int direction
);
178 bool HasConflictsWontKeep();
179 bool TryGetFileName(CString
& result
);
180 CBaseView
* GetActiveBaseView() const;
181 void OnViewTextFoldUnfold();
182 void OnViewTextFoldUnfold(CBaseView
* view
);
183 bool HasUnsavedEdits() const;
184 static bool HasUnsavedEdits(const CBaseView
* view
);
185 static bool IsViewGood(const CBaseView
* view
);
186 static bool HasPrevConflict(CBaseView
* view
);
187 static bool HasNextConflict(CBaseView
* view
);
188 static bool HasPrevInlineDiff(CBaseView
* view
);
189 static bool HasNextInlineDiff(CBaseView
* view
);
192 CMFCStatusBar m_wndStatusBar
;
193 CLocatorBar m_wndLocatorBar
;
194 CLineDiffBar m_wndLineDiffBar
;
195 CXSplitter m_wndSplitter
;
196 CXSplitter m_wndSplitter2
;
197 CFilePatchesDlg m_dlgFilePatches
;
200 BOOL m_bInitSplitter
;
203 bool m_bHasConflicts
;
205 bool m_bInlineWordDiff
;
211 CMFCRibbonBar m_wndRibbonBar
;
212 CMFCRibbonApplicationButton m_MainButton
;
214 CRegDWORD m_regWrapLines
;
215 CRegDWORD m_regViewModedBlocks
;
216 CRegDWORD m_regOneWay
;
217 CRegDWORD m_regCollapsed
;
218 CRegDWORD m_regInlineDiff
;
219 CRegDWORD m_regUseRibbons
;
221 CLeftView
* m_pwndLeftView
;
222 CRightView
* m_pwndRightView
;
223 CBottomView
* m_pwndBottomView
;
225 BOOL m_bReversedPatch
;
229 int m_nMoveMovesToIgnore
;
231 bool m_bViewMovedBlocks
;
233 bool m_bSaveRequired
;
235 WPARAM resolveMsgWParam
;
236 LPARAM resolveMsgLParam
;
238 const CMFCToolBar
* GetToolbar() const { return &m_wndToolBar
; }
239 CMFCMenuBar m_wndMenuBar
;
240 CMFCToolBar m_wndToolBar
;