SyncDlg: Disable reflist if libgit2 is disabled
[TortoiseGit.git] / src / TortoiseMerge / RightView.cpp
blob474e58d278114325dd6f1e45ae429423e56b6f79
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.
19 #include "stdafx.h"
20 #include "resource.h"
21 #include "AppUtils.h"
22 #if 0
23 #include "IconBitmapUtils.h"
24 #endif
26 #include "RightView.h"
27 #include "BottomView.h"
29 IMPLEMENT_DYNCREATE(CRightView, CBaseView)
31 CRightView::CRightView(void)
33 m_pwndRight = this;
34 m_pState = &m_AllState.right;
35 m_nStatusBarID = ID_INDICATOR_RIGHTVIEW;
38 CRightView::~CRightView(void)
42 void CRightView::UseBothLeftFirst()
44 if (!IsLeftViewGood())
45 return;
46 int nFirstViewLine = 0; // first view line in selection
47 int nLastViewLine = 0; // last view line in selection
49 if (!IsWritable())
50 return;
51 if (!GetViewSelection(nFirstViewLine, nLastViewLine))
52 return;
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);
66 SaveUndoStep();
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;
75 else
77 SetModified();
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);
86 SaveUndoStep();
88 // clean up
89 int nRemovedLines = CleanEmptyLines();
90 SaveUndoStep();
91 UpdateViewLineNumbers();
92 SaveUndoStep();
94 CUndo::GetInstance().EndGrouping();
96 // final clean up
97 ClearSelection();
98 SetupAllViewSelection(nFirstViewLine, 2*nLastViewLine - nFirstViewLine - nRemovedLines + 1);
99 BuildAllScreen2ViewVector();
100 m_pwndLeft->Invalidate();
101 RefreshViews();
104 void CRightView::UseBothRightFirst()
106 if (!IsLeftViewGood())
107 return;
108 int nFirstViewLine = 0; // first view line in selection
109 int nLastViewLine = 0; // last view line in selection
111 if (!IsWritable())
112 return;
113 if (!GetViewSelection(nFirstViewLine, nLastViewLine))
114 return;
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);
128 SaveUndoStep();
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;
139 else
141 SetModified();
142 line.state = DIFFSTATE_THEIRSADDED;
144 InsertViewData(viewindex++, line);
146 SaveUndoStep();
148 // now insert an empty block in left view
149 int nCount = nLastViewLine - nFirstViewLine + 1;
150 m_pwndLeft->InsertViewEmptyLines(nFirstViewLine, nCount);
151 SaveUndoStep();
153 // clean up
154 int nRemovedLines = CleanEmptyLines();
155 SaveUndoStep();
156 UpdateViewLineNumbers();
157 SaveUndoStep();
159 CUndo::GetInstance().EndGrouping();
161 // final clean up
162 ClearSelection();
163 SetupAllViewSelection(nFirstViewLine, 2*nLastViewLine - nFirstViewLine - nRemovedLines + 1);
164 BuildAllScreen2ViewVector();
165 m_pwndLeft->Invalidate();
166 RefreshViews();
169 void CRightView::UseLeftBlock()
171 int nFirstViewLine = 0;
172 int nLastViewLine = 0;
174 if (!IsWritable())
175 return;
176 if (!GetViewSelection(nFirstViewLine, nLastViewLine))
177 return;
179 return UseViewBlock(m_pwndLeft, nFirstViewLine, nLastViewLine);
182 void CRightView::UseLeftFile()
184 int nFirstViewLine = 0;
185 int nLastViewLine = GetViewCount()-1;
187 if (!IsWritable())
188 return;
189 ClearSelection();
190 return UseViewBlock(m_pwndLeft, nFirstViewLine, nLastViewLine);
193 void CRightView::MarkBlock(bool marked)
195 int nFirstViewLine = 0;
196 int nLastViewLine = 0;
198 if (!IsWritable())
199 return;
200 if (!GetViewSelection(nFirstViewLine, nLastViewLine))
201 return;
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())
226 if (bShow)
227 popup.AppendMenuIcon(POPUPCOMMAND_USEYOURBLOCK, IDS_VIEWCONTEXTMENU_USETHISBLOCK);
228 popup.AppendMenuIcon(POPUPCOMMAND_USEYOURFILE, IDS_VIEWCONTEXTMENU_USETHISFILE);
229 if (bShow)
231 popup.AppendMenuIcon(POPUPCOMMAND_USEYOURANDTHEIRBLOCK, IDS_VIEWCONTEXTMENU_USEYOURANDTHEIRBLOCK);
232 popup.AppendMenuIcon(POPUPCOMMAND_USETHEIRANDYOURBLOCK, IDS_VIEWCONTEXTMENU_USETHEIRANDYOURBLOCK);
235 else
237 if (bShow)
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;
263 if (showMark)
264 popup.AppendMenuIcon(POPUPCOMMAND_MARKBLOCK, IDS_VIEWCONTEXTMENU_MARKBLOCK);
265 if (showUnmark)
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);