1 // TortoiseGitMerge - a Diff/Patch program
3 // Copyright (C) 2006-2014 - 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
;
78 line
.state
= DIFFSTATE_THEIRSADDED
;
80 InsertViewData(viewLine
, line
);
83 // now insert an empty block in left view
84 int nCount
= nLastViewLine
- nFirstViewLine
+ 1;
85 m_pwndLeft
->InsertViewEmptyLines(nNextViewLine
, nCount
);
89 int nRemovedLines
= CleanEmptyLines();
91 UpdateViewLineNumbers();
94 CUndo::GetInstance().EndGrouping();
98 SetupAllViewSelection(nFirstViewLine
, 2*nLastViewLine
- nFirstViewLine
- nRemovedLines
+ 1);
99 BuildAllScreen2ViewVector();
100 m_pwndLeft
->Invalidate();
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
;
142 line
.state
= DIFFSTATE_THEIRSADDED
;
144 InsertViewData(viewindex
++, line
);
148 // now insert an empty block in left view
149 int nCount
= nLastViewLine
- nFirstViewLine
+ 1;
150 m_pwndLeft
->InsertViewEmptyLines(nFirstViewLine
, nCount
);
154 int nRemovedLines
= CleanEmptyLines();
156 UpdateViewLineNumbers();
159 CUndo::GetInstance().EndGrouping();
163 SetupAllViewSelection(nFirstViewLine
, 2*nLastViewLine
- nFirstViewLine
- nRemovedLines
+ 1);
164 BuildAllScreen2ViewVector();
165 m_pwndLeft
->Invalidate();
169 void CRightView::UseLeftBlock()
171 int nFirstViewLine
= 0;
172 int nLastViewLine
= 0;
176 if (!GetViewSelection(nFirstViewLine
, nLastViewLine
))
179 return UseViewBlock(m_pwndLeft
, nFirstViewLine
, nLastViewLine
);
182 void CRightView::UseLeftFile()
184 int nFirstViewLine
= 0;
185 int nLastViewLine
= GetViewCount()-1;
190 return UseViewBlock(m_pwndLeft
, nFirstViewLine
, nLastViewLine
);
193 void CRightView::MarkBlock(bool marked
)
195 int nFirstViewLine
= 0;
196 int nLastViewLine
= 0;
200 if (!GetViewSelection(nFirstViewLine
, nLastViewLine
))
202 CBaseView::MarkBlock(marked
, nFirstViewLine
, nLastViewLine
);
205 void CRightView::LeaveOnlyMarkedBlocks()
207 CBaseView::LeaveOnlyMarkedBlocks(m_pwndLeft
);
210 void CRightView::UseViewFileOfMarked()
212 CBaseView::UseViewFileOfMarked(m_pwndLeft
);
215 void CRightView::UseViewFileExceptEdited()
217 CBaseView::UseViewFileExceptEdited(m_pwndLeft
);
220 void CRightView::AddContextItems(CIconMenu
& popup
, DiffStates state
)
222 const bool bShow
= HasSelection() && (state
!= DIFFSTATE_UNKNOWN
);
224 if (IsBottomViewGood())
227 popup
.AppendMenuIcon(POPUPCOMMAND_USEYOURBLOCK
, IDS_VIEWCONTEXTMENU_USETHISBLOCK
);
228 popup
.AppendMenuIcon(POPUPCOMMAND_USEYOURFILE
, IDS_VIEWCONTEXTMENU_USETHISFILE
);
231 popup
.AppendMenuIcon(POPUPCOMMAND_USEYOURANDTHEIRBLOCK
, IDS_VIEWCONTEXTMENU_USEYOURANDTHEIRBLOCK
);
232 popup
.AppendMenuIcon(POPUPCOMMAND_USETHEIRANDYOURBLOCK
, IDS_VIEWCONTEXTMENU_USETHEIRANDYOURBLOCK
);
239 popup
.AppendMenuIcon(POPUPCOMMAND_USELEFTBLOCK
, IDS_VIEWCONTEXTMENU_USEOTHERBLOCK
);
240 popup
.AppendMenuIcon(POPUPCOMMAND_USEBOTHRIGHTFIRST
, IDS_VIEWCONTEXTMENU_USEBOTHTHISFIRST
);
241 popup
.AppendMenuIcon(POPUPCOMMAND_USEBOTHLEFTFIRST
, IDS_VIEWCONTEXTMENU_USEBOTHTHISLAST
);
242 if (IsLeftViewGood() && !m_pwndLeft
->IsReadonly())
244 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
245 popup
.AppendMenuIcon(POPUPCOMMAND_PREPENDFROMRIGHT
, IDS_VIEWCONTEXTMENU_PREPENDTHIS
);
246 popup
.AppendMenuIcon(POPUPCOMMAND_REPLACEBYRIGHT
, IDS_VIEWCONTEXTMENU_USETHIS
);
247 popup
.AppendMenuIcon(POPUPCOMMAND_APPENDFROMRIGHT
, IDS_VIEWCONTEXTMENU_APPENDTHIS
);
249 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
252 int nFirstViewLine
= 0;
253 int nLastViewLine
= 0;
254 if (GetViewSelection(nFirstViewLine
, nLastViewLine
))
256 bool showMark
= true;
257 bool showUnmark
= true;
258 if (nFirstViewLine
== nLastViewLine
)
260 showUnmark
= GetViewMarked(nFirstViewLine
);
261 showMark
= !showUnmark
;
264 popup
.AppendMenuIcon(POPUPCOMMAND_MARKBLOCK
, IDS_VIEWCONTEXTMENU_MARKBLOCK
);
266 popup
.AppendMenuIcon(POPUPCOMMAND_UNMARKBLOCK
, IDS_VIEWCONTEXTMENU_UNMARKBLOCK
);
268 popup
.AppendMenuIcon(POPUPCOMMAND_LEAVEONLYMARKEDBLOCKS
, IDS_VIEWCONTEXTMENU_LEAVEONLYMARKEDBLOCKS
);
269 popup
.AppendMenuIcon(POPUPCOMMAND_USELEFTFILE
, IDS_VIEWCONTEXTMENU_USEOTHERFILE
);
270 if (IsLeftViewGood() && !m_pwndLeft
->IsReadonly())
272 popup
.AppendMenuIcon(POPUPCOMMAND_USERIGHTFILE
, IDS_VIEWCONTEXTMENU_USETHISFILE
);
276 CBaseView::AddContextItems(popup
, state
);