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.
24 #include "BottomView.h"
26 IMPLEMENT_DYNCREATE(CLeftView
, CBaseView
)
28 CLeftView::CLeftView(void)
31 m_pState
= &m_AllState
.left
;
32 m_nStatusBarID
= ID_INDICATOR_LEFTVIEW
;
35 CLeftView::~CLeftView(void)
40 void CLeftView::UseBothLeftFirst()
42 if (!IsRightViewGood())
44 int nFirstViewLine
= 0; // first view line in selection
45 int nLastViewLine
= 0; // last view line in selection
49 if (!GetViewSelection(nFirstViewLine
, nLastViewLine
))
52 int nNextViewLine
= nLastViewLine
+ 1; // first view line after selected block
54 CUndo::GetInstance().BeginGrouping();
56 // right original become added
57 for (int viewLine
= nFirstViewLine
; viewLine
<= nLastViewLine
; viewLine
++)
59 if (!IsStateEmpty(GetViewState(viewLine
)))
61 SetViewState(viewLine
, DIFFSTATE_REMOVED
);
66 // your block is done, now insert their block
67 int viewindex
= nNextViewLine
;
68 for (int viewLine
= nFirstViewLine
; viewLine
<= nLastViewLine
; viewLine
++)
70 viewdata line
= m_pwndRight
->GetViewData(viewLine
);
71 if (IsStateEmpty(line
.state
))
73 line
.state
= DIFFSTATE_EMPTY
;
77 if (line
.state
!=DIFFSTATE_NORMAL
) {
78 m_pwndRight
->SetViewState(viewLine
, DIFFSTATE_NORMAL
);
79 line
.state
= DIFFSTATE_NORMAL
;
83 InsertViewData(viewindex
++, line
);
87 // now insert an empty block in right view
88 int nCount
= nLastViewLine
- nFirstViewLine
+ 1;
89 m_pwndRight
->InsertViewEmptyLines(nFirstViewLine
, nCount
);
90 m_pwndRight
->Invalidate();
94 int nRemovedLines
= CleanEmptyLines();
96 UpdateViewLineNumbers();
99 CUndo::GetInstance().EndGrouping();
103 SetupAllViewSelection(nFirstViewLine
, 2*nLastViewLine
- nFirstViewLine
- nRemovedLines
+ 1);
104 BuildAllScreen2ViewVector();
108 void CLeftView::UseBothRightFirst()
110 if (!IsRightViewGood())
112 int nFirstViewLine
= 0; // first view line in selection
113 int nLastViewLine
= 0; // last view line in selection
117 if (!GetViewSelection(nFirstViewLine
, nLastViewLine
))
120 int nNextViewLine
= nLastViewLine
+ 1; // first view line after selected block
122 CUndo::GetInstance().BeginGrouping();
124 // left original become removed
125 for (int viewLine
= nFirstViewLine
; viewLine
<= nLastViewLine
; viewLine
++)
127 if (!IsStateEmpty(GetViewState(viewLine
)))
129 SetViewState(viewLine
, DIFFSTATE_THEIRSREMOVED
);
134 for (int viewLine
= nFirstViewLine
; viewLine
<= nLastViewLine
; viewLine
++)
136 viewdata line
= m_pwndRight
->GetViewData(viewLine
);
137 if (IsStateEmpty(line
.state
))
139 line
.state
= DIFFSTATE_EMPTY
;
143 if (line
.state
!=DIFFSTATE_NORMAL
) {
144 m_pwndRight
->SetViewState(viewLine
, DIFFSTATE_NORMAL
);
145 line
.state
= DIFFSTATE_NORMAL
;
149 InsertViewData(viewLine
, line
);
152 // now insert an empty block in right view
153 int nCount
= nLastViewLine
- nFirstViewLine
+ 1;
154 m_pwndRight
->InsertViewEmptyLines(nNextViewLine
, nCount
);
155 m_pwndRight
->Invalidate(); // empty lines added
159 int nRemovedLines
= CleanEmptyLines();
161 UpdateViewLineNumbers();
164 CUndo::GetInstance().EndGrouping();
168 SetupAllViewSelection(nFirstViewLine
, 2*nLastViewLine
- nFirstViewLine
- nRemovedLines
+ 1);
169 BuildAllScreen2ViewVector();
173 void CLeftView::UseRightBlock()
175 int nFirstViewLine
= 0;
176 int nLastViewLine
= 0;
180 if (!GetViewSelection(nFirstViewLine
, nLastViewLine
))
183 return UseViewBlock(m_pwndRight
, nFirstViewLine
, nLastViewLine
);
186 void CLeftView::UseRightFile()
188 int nFirstViewLine
= 0;
189 int nLastViewLine
= GetViewCount()-1;
194 return UseViewBlock(m_pwndRight
, nFirstViewLine
, nLastViewLine
);
198 void CLeftView::AddContextItems(CIconMenu
& popup
, DiffStates state
)
200 const bool bShow
= HasSelection() && (state
!= DIFFSTATE_UNKNOWN
);
202 if (IsBottomViewGood())
205 popup
.AppendMenuIcon(POPUPCOMMAND_USETHEIRBLOCK
, IDS_VIEWCONTEXTMENU_USETHISBLOCK
);
206 popup
.AppendMenuIcon(POPUPCOMMAND_USETHEIRFILE
, IDS_VIEWCONTEXTMENU_USETHISFILE
);
209 popup
.AppendMenuIcon(POPUPCOMMAND_USEYOURANDTHEIRBLOCK
, IDS_VIEWCONTEXTMENU_USEYOURANDTHEIRBLOCK
);
210 popup
.AppendMenuIcon(POPUPCOMMAND_USETHEIRANDYOURBLOCK
, IDS_VIEWCONTEXTMENU_USETHEIRANDYOURBLOCK
);
217 popup
.AppendMenuIcon(POPUPCOMMAND_USELEFTBLOCK
, IDS_VIEWCONTEXTMENU_USETHISBLOCK
);
218 popup
.AppendMenuIcon(POPUPCOMMAND_USEBOTHLEFTFIRST
, IDS_VIEWCONTEXTMENU_USEBOTHTHISFIRST
);
219 popup
.AppendMenuIcon(POPUPCOMMAND_USEBOTHRIGHTFIRST
, IDS_VIEWCONTEXTMENU_USEBOTHTHISLAST
);
220 if (IsLeftViewGood() && !m_pwndLeft
->IsReadonly())
222 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
223 popup
.AppendMenuIcon(POPUPCOMMAND_PREPENDFROMRIGHT
, IDS_VIEWCONTEXTMENU_PREPENDRIGHT
);
224 popup
.AppendMenuIcon(POPUPCOMMAND_REPLACEBYRIGHT
, IDS_VIEWCONTEXTMENU_USERIGHT
);
225 popup
.AppendMenuIcon(POPUPCOMMAND_APPENDFROMRIGHT
, IDS_VIEWCONTEXTMENU_APPENDRIGHT
);
227 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
229 popup
.AppendMenuIcon(POPUPCOMMAND_USELEFTFILE
, IDS_VIEWCONTEXTMENU_USETHISFILE
);
230 if (IsLeftViewGood() && !m_pwndLeft
->IsReadonly())
232 popup
.AppendMenuIcon(POPUPCOMMAND_USERIGHTFILE
, IDS_VIEWCONTEXTMENU_USEOTHERFILE
);
236 CBaseView::AddContextItems(popup
, state
);