1 // TortoiseGitMerge - a Diff/Patch program
3 // Copyright (C) 2006-2013 - TortoiseSVN
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "IconBitmapUtils.h"
26 #include "RightView.h"
27 #include "BottomView.h"
29 IMPLEMENT_DYNCREATE(CRightView
, CBaseView
)
31 CRightView::CRightView(void)
34 m_pState
= &m_AllState
.right
;
35 m_nStatusBarID
= ID_INDICATOR_RIGHTVIEW
;
38 CRightView::~CRightView(void)
42 void CRightView::UseBothLeftFirst()
44 if (!IsLeftViewGood())
46 int nFirstViewLine
= 0; // first view line in selection
47 int nLastViewLine
= 0; // last view line in selection
51 if (!GetViewSelection(nFirstViewLine
, nLastViewLine
))
54 int nNextViewLine
= nLastViewLine
+ 1; // first view line after selected block
56 CUndo::GetInstance().BeginGrouping();
58 // right original become added
59 for (int viewLine
= nFirstViewLine
; viewLine
<= nLastViewLine
; viewLine
++)
61 if (!IsStateEmpty(GetViewState(viewLine
)))
63 SetViewState(viewLine
, DIFFSTATE_YOURSADDED
);
68 for (int viewLine
= nFirstViewLine
; viewLine
<= nLastViewLine
; viewLine
++)
70 viewdata line
= m_pwndLeft
->GetViewData(viewLine
);
71 if (IsStateEmpty(line
.state
))
73 line
.state
= DIFFSTATE_EMPTY
;
77 line
.state
= DIFFSTATE_THEIRSADDED
;
79 InsertViewData(viewLine
, line
);
82 // now insert an empty block in left view
83 int nCount
= nLastViewLine
- nFirstViewLine
+ 1;
84 m_pwndLeft
->InsertViewEmptyLines(nNextViewLine
, nCount
);
88 int nRemovedLines
= CleanEmptyLines();
90 UpdateViewLineNumbers();
93 CUndo::GetInstance().EndGrouping();
97 SetupAllViewSelection(nFirstViewLine
, 2*nLastViewLine
- nFirstViewLine
- nRemovedLines
+ 1);
98 BuildAllScreen2ViewVector();
99 m_pwndLeft
->SetModified();
104 void CRightView::UseBothRightFirst()
106 if (!IsLeftViewGood())
108 int nFirstViewLine
= 0; // first view line in selection
109 int nLastViewLine
= 0; // last view line in selection
113 if (!GetViewSelection(nFirstViewLine
, nLastViewLine
))
116 int nNextViewLine
= nLastViewLine
+ 1; // first view line after selected block
118 CUndo::GetInstance().BeginGrouping();
120 // right original become added
121 for (int viewLine
= nFirstViewLine
; viewLine
<= nLastViewLine
; viewLine
++)
123 if (!IsStateEmpty(GetViewState(viewLine
)))
125 SetViewState(viewLine
, DIFFSTATE_ADDED
);
130 // your block is done, now insert their block
131 int viewindex
= nNextViewLine
;
132 for (int viewLine
= nFirstViewLine
; viewLine
<= nLastViewLine
; viewLine
++)
134 viewdata line
= m_pwndLeft
->GetViewData(viewLine
);
135 if (IsStateEmpty(line
.state
))
137 line
.state
= DIFFSTATE_EMPTY
;
141 line
.state
= DIFFSTATE_THEIRSADDED
;
143 InsertViewData(viewindex
++, line
);
147 // now insert an empty block in left view
148 int nCount
= nLastViewLine
- nFirstViewLine
+ 1;
149 m_pwndLeft
->InsertViewEmptyLines(nFirstViewLine
, nCount
);
153 int nRemovedLines
= CleanEmptyLines();
155 UpdateViewLineNumbers();
158 CUndo::GetInstance().EndGrouping();
162 SetupAllViewSelection(nFirstViewLine
, 2*nLastViewLine
- nFirstViewLine
- nRemovedLines
+ 1);
163 BuildAllScreen2ViewVector();
164 m_pwndLeft
->SetModified();
169 void CRightView::UseLeftBlock()
171 int nFirstViewLine
= 0;
172 int nLastViewLine
= 0;
176 if (!GetViewSelection(nFirstViewLine
, nLastViewLine
))
179 return UseBlock(nFirstViewLine
, nLastViewLine
);
182 void CRightView::UseLeftFile()
184 int nFirstViewLine
= 0;
185 int nLastViewLine
= GetViewCount()-1;
189 return UseBlock(nFirstViewLine
, nLastViewLine
);
193 void CRightView::AddContextItems(CIconMenu
& popup
, DiffStates state
)
195 const bool bShow
= HasSelection() && (state
!= DIFFSTATE_UNKNOWN
);
197 if (IsBottomViewGood())
200 popup
.AppendMenuIcon(POPUPCOMMAND_USEYOURBLOCK
, IDS_VIEWCONTEXTMENU_USETHISBLOCK
);
201 popup
.AppendMenuIcon(POPUPCOMMAND_USEYOURFILE
, IDS_VIEWCONTEXTMENU_USETHISFILE
);
204 popup
.AppendMenuIcon(POPUPCOMMAND_USEYOURANDTHEIRBLOCK
, IDS_VIEWCONTEXTMENU_USEYOURANDTHEIRBLOCK
);
205 popup
.AppendMenuIcon(POPUPCOMMAND_USETHEIRANDYOURBLOCK
, IDS_VIEWCONTEXTMENU_USETHEIRANDYOURBLOCK
);
211 popup
.AppendMenuIcon(POPUPCOMMAND_USELEFTBLOCK
, IDS_VIEWCONTEXTMENU_USEOTHERBLOCK
);
212 popup
.AppendMenuIcon(POPUPCOMMAND_USELEFTFILE
, IDS_VIEWCONTEXTMENU_USEOTHERFILE
);
215 popup
.AppendMenuIcon(POPUPCOMMAND_USEBOTHRIGHTFIRST
, IDS_VIEWCONTEXTMENU_USEBOTHTHISFIRST
);
216 popup
.AppendMenuIcon(POPUPCOMMAND_USEBOTHLEFTFIRST
, IDS_VIEWCONTEXTMENU_USEBOTHTHISLAST
);
220 CBaseView::AddContextItems(popup
, state
);
224 void CRightView::UseBlock(int nFirstViewLine
, int nLastViewLine
)
226 if (!IsLeftViewGood())
230 CUndo::GetInstance().BeginGrouping();
232 for (int viewLine
= nFirstViewLine
; viewLine
<= nLastViewLine
; viewLine
++)
234 viewdata line
= m_pwndLeft
->GetViewData(viewLine
);
235 if ((line
.ending
!= EOL_NOENDING
)||(viewLine
< (GetViewCount()-1)))
236 line
.ending
= lineendings
;
239 case DIFFSTATE_CONFLICTEMPTY
:
240 case DIFFSTATE_UNKNOWN
:
241 case DIFFSTATE_EMPTY
:
242 line
.state
= DIFFSTATE_EMPTY
;
244 case DIFFSTATE_ADDED
:
245 case DIFFSTATE_MOVED_TO
:
246 case DIFFSTATE_MOVED_FROM
:
247 case DIFFSTATE_CONFLICTADDED
:
248 case DIFFSTATE_CONFLICTED
:
249 case DIFFSTATE_CONFLICTED_IGNORED
:
250 case DIFFSTATE_IDENTICALADDED
:
251 case DIFFSTATE_NORMAL
:
252 case DIFFSTATE_THEIRSADDED
:
253 case DIFFSTATE_YOURSADDED
:
255 case DIFFSTATE_IDENTICALREMOVED
:
256 case DIFFSTATE_REMOVED
:
257 case DIFFSTATE_THEIRSREMOVED
:
258 case DIFFSTATE_YOURSREMOVED
:
259 line
.state
= DIFFSTATE_ADDED
;
264 SetViewData(viewLine
, line
);
266 // make sure previous (non empty) line have EOL set
267 for (int nCheckViewLine
= nFirstViewLine
-1; nCheckViewLine
> 0; nCheckViewLine
--)
269 if (!IsViewLineEmpty(nCheckViewLine
))
271 if (GetViewLineEnding(nCheckViewLine
) == EOL_NOENDING
)
273 SetViewLineEnding(nCheckViewLine
, lineendings
);
280 int nRemovedLines
= CleanEmptyLines();
282 UpdateViewLineNumbers();
285 CUndo::GetInstance().EndGrouping();
289 // some lines are gone update selection
291 SetupAllViewSelection(nFirstViewLine
, nLastViewLine
- nRemovedLines
);
293 BuildAllScreen2ViewVector();
294 m_pwndLeft
->SetModified();