1
// TortoiseGitMerge - a Diff/Patch program
3 // Copyright (C) 2023 - TortoiseGit
4 // Copyright (C) 2006-2013 - 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.
25 #include "BottomView.h"
27 IMPLEMENT_DYNCREATE(CLeftView
, CBaseView
)
29 CLeftView::CLeftView()
32 m_pState
= &m_AllState
.left
;
33 m_nStatusBarID
= ID_INDICATOR_LEFTVIEW
;
36 CLeftView::~CLeftView()
41 void CLeftView::UseBothLeftFirst()
43 if (!IsRightViewGood())
45 int nFirstViewLine
= 0; // first view line in selection
46 int nLastViewLine
= 0; // last view line in selection
50 if (!GetViewSelection(nFirstViewLine
, nLastViewLine
))
53 int nNextViewLine
= nLastViewLine
+ 1; // first view line after selected block
55 CUndo::GetInstance().BeginGrouping();
57 // right original become added
58 for (int viewLine
= nFirstViewLine
; viewLine
<= nLastViewLine
; viewLine
++)
60 if (!IsStateEmpty(GetViewState(viewLine
)))
62 SetViewState(viewLine
, DiffState::Removed
);
67 // your block is done, now insert their block
68 int viewindex
= nNextViewLine
;
69 for (int viewLine
= nFirstViewLine
; viewLine
<= nLastViewLine
; viewLine
++)
71 viewdata line
= m_pwndRight
->GetViewData(viewLine
);
72 if (IsStateEmpty(line
.state
))
74 line
.state
= DiffState::Empty
;
78 if (line
.state
!=DiffState::Normal
) {
79 m_pwndRight
->SetViewState(viewLine
, DiffState::Normal
);
80 line
.state
= DiffState::Normal
;
84 InsertViewData(viewindex
++, line
);
88 // now insert an empty block in right view
89 int nCount
= nLastViewLine
- nFirstViewLine
+ 1;
90 m_pwndRight
->InsertViewEmptyLines(nFirstViewLine
, nCount
);
91 m_pwndRight
->Invalidate();
95 int nRemovedLines
= CleanEmptyLines();
97 UpdateViewLineNumbers();
100 CUndo::GetInstance().EndGrouping();
104 SetupAllViewSelection(nFirstViewLine
, 2*nLastViewLine
- nFirstViewLine
- nRemovedLines
+ 1);
105 BuildAllScreen2ViewVector();
109 void CLeftView::UseBothRightFirst()
111 if (!IsRightViewGood())
113 int nFirstViewLine
= 0; // first view line in selection
114 int nLastViewLine
= 0; // last view line in selection
118 if (!GetViewSelection(nFirstViewLine
, nLastViewLine
))
121 int nNextViewLine
= nLastViewLine
+ 1; // first view line after selected block
123 CUndo::GetInstance().BeginGrouping();
125 // left original become removed
126 for (int viewLine
= nFirstViewLine
; viewLine
<= nLastViewLine
; viewLine
++)
128 if (!IsStateEmpty(GetViewState(viewLine
)))
130 SetViewState(viewLine
, DiffState::TheirsRemoved
);
135 for (int viewLine
= nFirstViewLine
; viewLine
<= nLastViewLine
; viewLine
++)
137 viewdata line
= m_pwndRight
->GetViewData(viewLine
);
138 if (IsStateEmpty(line
.state
))
140 line
.state
= DiffState::Empty
;
144 if (line
.state
!=DiffState::Normal
) {
145 m_pwndRight
->SetViewState(viewLine
, DiffState::Normal
);
146 line
.state
= DiffState::Normal
;
150 InsertViewData(viewLine
, line
);
153 // now insert an empty block in right view
154 int nCount
= nLastViewLine
- nFirstViewLine
+ 1;
155 m_pwndRight
->InsertViewEmptyLines(nNextViewLine
, nCount
);
156 m_pwndRight
->Invalidate(); // empty lines added
160 int nRemovedLines
= CleanEmptyLines();
162 UpdateViewLineNumbers();
165 CUndo::GetInstance().EndGrouping();
169 SetupAllViewSelection(nFirstViewLine
, 2*nLastViewLine
- nFirstViewLine
- nRemovedLines
+ 1);
170 BuildAllScreen2ViewVector();
174 void CLeftView::UseRightBlock()
176 int nFirstViewLine
= 0;
177 int nLastViewLine
= 0;
181 if (!GetViewSelection(nFirstViewLine
, nLastViewLine
))
184 return UseViewBlock(m_pwndRight
, nFirstViewLine
, nLastViewLine
);
187 void CLeftView::UseRightFile()
189 int nFirstViewLine
= 0;
190 int nLastViewLine
= GetViewCount()-1;
195 return UseViewBlock(m_pwndRight
, nFirstViewLine
, nLastViewLine
);
199 void CLeftView::AddContextItems(CIconMenu
& popup
, DiffState state
)
201 const bool bShow
= HasSelection() && (state
!= DiffState::Unknown
);
203 if (IsBottomViewGood())
206 popup
.AppendMenuIcon(POPUPCOMMAND_USETHEIRBLOCK
, IDS_VIEWCONTEXTMENU_USETHISBLOCK
);
207 popup
.AppendMenuIcon(POPUPCOMMAND_USETHEIRFILE
, IDS_VIEWCONTEXTMENU_USETHISFILE
);
210 popup
.AppendMenuIcon(POPUPCOMMAND_USEYOURANDTHEIRBLOCK
, IDS_VIEWCONTEXTMENU_USEYOURANDTHEIRBLOCK
);
211 popup
.AppendMenuIcon(POPUPCOMMAND_USETHEIRANDYOURBLOCK
, IDS_VIEWCONTEXTMENU_USETHEIRANDYOURBLOCK
);
218 popup
.AppendMenuIcon(POPUPCOMMAND_USELEFTBLOCK
, IDS_VIEWCONTEXTMENU_USETHISBLOCK
);
219 popup
.AppendMenuIcon(POPUPCOMMAND_USEBOTHLEFTFIRST
, IDS_VIEWCONTEXTMENU_USEBOTHTHISFIRST
);
220 popup
.AppendMenuIcon(POPUPCOMMAND_USEBOTHRIGHTFIRST
, IDS_VIEWCONTEXTMENU_USEBOTHTHISLAST
);
221 if (IsLeftViewGood() && !m_pwndLeft
->IsReadonly())
223 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
224 popup
.AppendMenuIcon(POPUPCOMMAND_PREPENDFROMRIGHT
, IDS_VIEWCONTEXTMENU_PREPENDRIGHT
);
225 popup
.AppendMenuIcon(POPUPCOMMAND_REPLACEBYRIGHT
, IDS_VIEWCONTEXTMENU_USERIGHT
);
226 popup
.AppendMenuIcon(POPUPCOMMAND_APPENDFROMRIGHT
, IDS_VIEWCONTEXTMENU_APPENDRIGHT
);
228 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
230 popup
.AppendMenuIcon(POPUPCOMMAND_USELEFTFILE
, IDS_VIEWCONTEXTMENU_USETHISFILE
);
231 if (IsLeftViewGood() && !m_pwndLeft
->IsReadonly())
233 popup
.AppendMenuIcon(POPUPCOMMAND_USERIGHTFILE
, IDS_VIEWCONTEXTMENU_USEOTHERFILE
);
237 CBaseView::AddContextItems(popup
, state
);