use the right case and drop unnecessary slashes for includes
[TortoiseGit.git] / src / TortoiseMerge / RightView.cpp
blob97ee281ee1e6864b4a73b820bbc130e28e3ce058
1 // TortoiseMerge - a Diff/Patch program
3 // Copyright (C) 2006-2009,2011 - 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 #include "rightview.h"
24 IMPLEMENT_DYNCREATE(CRightView, CBaseView)
26 CRightView::CRightView(void)
28 m_pwndRight = this;
29 m_nStatusBarID = ID_INDICATOR_RIGHTVIEW;
32 CRightView::~CRightView(void)
36 bool CRightView::OnContextMenu(CPoint point, int /*nLine*/, DiffStates state)
38 if (!this->IsWindowVisible())
39 return false;
41 CMenu popup;
42 if (popup.CreatePopupMenu())
44 #define ID_USEBLOCK 1
45 #define ID_USEFILE 2
46 #define ID_USETHEIRANDYOURBLOCK 3
47 #define ID_USEYOURANDTHEIRBLOCK 4
48 #define ID_USEBOTHTHISFIRST 5
49 #define ID_USEBOTHTHISLAST 6
51 UINT uEnabled = MF_ENABLED;
52 if ((m_nSelBlockStart == -1)||(m_nSelBlockEnd == -1))
53 uEnabled |= MF_DISABLED | MF_GRAYED;
54 CString temp;
56 bool bImportantBlock = true;
57 switch (state)
59 case DIFFSTATE_UNKNOWN:
60 bImportantBlock = false;
61 break;
64 if (!m_pwndBottom->IsWindowVisible())
66 temp.LoadString(IDS_VIEWCONTEXTMENU_USEOTHERBLOCK);
68 else
69 temp.LoadString(IDS_VIEWCONTEXTMENU_USETHISBLOCK);
70 popup.AppendMenu(MF_STRING | uEnabled | (bImportantBlock ? MF_ENABLED : MF_DISABLED|MF_GRAYED), ID_USEBLOCK, temp);
72 if (!m_pwndBottom->IsWindowVisible())
74 temp.LoadString(IDS_VIEWCONTEXTMENU_USEOTHERFILE);
76 else
77 temp.LoadString(IDS_VIEWCONTEXTMENU_USETHISFILE);
78 popup.AppendMenu(MF_STRING | MF_ENABLED, ID_USEFILE, temp);
80 if (m_pwndBottom->IsWindowVisible())
82 temp.LoadString(IDS_VIEWCONTEXTMENU_USEYOURANDTHEIRBLOCK);
83 popup.AppendMenu(MF_STRING | uEnabled | (bImportantBlock ? MF_ENABLED : MF_DISABLED|MF_GRAYED), ID_USEYOURANDTHEIRBLOCK, temp);
84 temp.LoadString(IDS_VIEWCONTEXTMENU_USETHEIRANDYOURBLOCK);
85 popup.AppendMenu(MF_STRING | uEnabled | (bImportantBlock ? MF_ENABLED : MF_DISABLED|MF_GRAYED), ID_USETHEIRANDYOURBLOCK, temp);
87 else
89 temp.LoadString(IDS_VIEWCONTEXTMENU_USEBOTHTHISFIRST);
90 popup.AppendMenu(MF_STRING | uEnabled | (bImportantBlock ? MF_ENABLED : MF_DISABLED|MF_GRAYED), ID_USEBOTHTHISFIRST, temp);
91 temp.LoadString(IDS_VIEWCONTEXTMENU_USEBOTHTHISLAST);
92 popup.AppendMenu(MF_STRING | uEnabled | (bImportantBlock ? MF_ENABLED : MF_DISABLED|MF_GRAYED), ID_USEBOTHTHISLAST, temp);
95 popup.AppendMenu(MF_SEPARATOR, NULL);
97 temp.LoadString(IDS_EDIT_COPY);
98 popup.AppendMenu(MF_STRING | (HasTextSelection() ? MF_ENABLED : MF_DISABLED|MF_GRAYED), ID_EDIT_COPY, temp);
99 if (!m_bCaretHidden)
101 temp.LoadString(IDS_EDIT_CUT);
102 popup.AppendMenu(MF_STRING | (HasTextSelection() ? MF_ENABLED : MF_DISABLED|MF_GRAYED), ID_EDIT_CUT, temp);
103 temp.LoadString(IDS_EDIT_PASTE);
104 popup.AppendMenu(MF_STRING | (CAppUtils::HasClipboardFormat(CF_UNICODETEXT)||CAppUtils::HasClipboardFormat(CF_TEXT) ? MF_ENABLED : MF_DISABLED|MF_GRAYED), ID_EDIT_PASTE, temp);
107 // if the context menu is invoked through the keyboard, we have to use
108 // a calculated position on where to anchor the menu on
109 if ((point.x == -1) && (point.y == -1))
111 CRect rect;
112 GetWindowRect(&rect);
113 point = rect.CenterPoint();
115 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
116 viewstate rightstate;
117 viewstate bottomstate;
118 viewstate leftstate;
119 switch (cmd)
121 case ID_EDIT_COPY:
122 OnEditCopy();
123 return true;
124 case ID_EDIT_CUT:
125 OnEditCopy();
126 RemoveSelectedText();
127 return false;
128 case ID_EDIT_PASTE:
129 PasteText();
130 return false;
131 case ID_USEFILE:
133 UseFile(false);
135 break;
136 case ID_USEBLOCK:
138 UseBlock(false);
140 break;
141 case ID_USEYOURANDTHEIRBLOCK:
143 UseYourAndTheirBlock(rightstate, bottomstate, leftstate);
144 CUndo::GetInstance().AddState(leftstate, rightstate, bottomstate, m_ptCaretPos);
146 break;
147 case ID_USETHEIRANDYOURBLOCK:
149 UseTheirAndYourBlock(rightstate, bottomstate, leftstate);
150 CUndo::GetInstance().AddState(leftstate, rightstate, bottomstate, m_ptCaretPos);
152 break;
153 case ID_USEBOTHTHISFIRST:
155 UseBothRightFirst(rightstate, leftstate);
156 CUndo::GetInstance().AddState(leftstate, rightstate, bottomstate, m_ptCaretPos);
158 break;
159 case ID_USEBOTHTHISLAST:
161 UseBothLeftFirst(rightstate, leftstate);
162 CUndo::GetInstance().AddState(leftstate, rightstate, bottomstate, m_ptCaretPos);
164 break;
165 default:
166 return false;
167 } // switch (cmd)
168 } // if (popup.CreatePopupMenu())
169 return false;
172 void CRightView::UseFile(bool refreshViews /* = true */)
174 viewstate rightstate;
175 viewstate bottomstate;
176 viewstate leftstate;
177 if (m_pwndBottom->IsWindowVisible())
179 for (int i=0; i<GetLineCount(); i++)
181 bottomstate.difflines[i] = m_pwndBottom->m_pViewData->GetLine(i);
182 m_pwndBottom->m_pViewData->SetLine(i, m_pViewData->GetLine(i));
183 bottomstate.linestates[i] = m_pwndBottom->m_pViewData->GetState(i);
184 m_pwndBottom->m_pViewData->SetState(i, m_pViewData->GetState(i));
185 m_pwndBottom->m_pViewData->SetLineEnding(i, m_pViewData->GetLineEnding(i));
186 if (m_pwndBottom->IsLineConflicted(i))
187 m_pwndBottom->m_pViewData->SetState(i, DIFFSTATE_CONFLICTRESOLVED);
189 m_pwndBottom->SetModified();
191 else
193 for (int i=0; i<GetLineCount(); i++)
195 rightstate.difflines[i] = m_pViewData->GetLine(i);
196 m_pViewData->SetLine(i, m_pwndLeft->m_pViewData->GetLine(i));
197 m_pViewData->SetLineEnding(i, m_pwndLeft->m_pViewData->GetLineEnding(i));
198 DiffStates state = m_pwndLeft->m_pViewData->GetState(i);
199 switch (state)
201 case DIFFSTATE_CONFLICTEMPTY:
202 case DIFFSTATE_UNKNOWN:
203 case DIFFSTATE_EMPTY:
204 rightstate.linestates[i] = m_pViewData->GetState(i);
205 m_pViewData->SetState(i, state);
206 break;
207 case DIFFSTATE_YOURSADDED:
208 case DIFFSTATE_IDENTICALADDED:
209 case DIFFSTATE_NORMAL:
210 case DIFFSTATE_THEIRSADDED:
211 case DIFFSTATE_ADDED:
212 case DIFFSTATE_CONFLICTADDED:
213 case DIFFSTATE_CONFLICTED:
214 case DIFFSTATE_CONFLICTED_IGNORED:
215 case DIFFSTATE_IDENTICALREMOVED:
216 case DIFFSTATE_REMOVED:
217 case DIFFSTATE_THEIRSREMOVED:
218 case DIFFSTATE_YOURSREMOVED:
219 rightstate.linestates[i] = m_pViewData->GetState(i);
220 m_pViewData->SetState(i, DIFFSTATE_NORMAL);
221 leftstate.linestates[i] = m_pwndLeft->m_pViewData->GetState(i);
222 m_pwndLeft->m_pViewData->SetState(i, DIFFSTATE_NORMAL);
223 break;
224 default:
225 break;
227 SetModified();
228 if (m_pwndLocator)
229 m_pwndLocator->DocumentUpdated();
232 CUndo::GetInstance().AddState(leftstate, rightstate, bottomstate, m_ptCaretPos);
233 if (refreshViews)
234 RefreshViews();
237 void CRightView::UseBlock(bool refreshViews /* = true */)
239 viewstate rightstate;
240 viewstate bottomstate;
241 viewstate leftstate;
243 if ((m_nSelBlockStart == -1)||(m_nSelBlockEnd == -1))
244 return;
245 if (m_pwndBottom->IsWindowVisible())
247 for (int i=m_nSelBlockStart; i<=m_nSelBlockEnd; i++)
249 bottomstate.difflines[i] = m_pwndBottom->m_pViewData->GetLine(i);
250 m_pwndBottom->m_pViewData->SetLine(i, m_pViewData->GetLine(i));
251 bottomstate.linestates[i] = m_pwndBottom->m_pViewData->GetState(i);
252 m_pwndBottom->m_pViewData->SetState(i, m_pViewData->GetState(i));
253 m_pwndBottom->m_pViewData->SetLineEnding(i, lineendings);
254 if (m_pwndBottom->IsLineConflicted(i))
256 if (m_pViewData->GetState(i) == DIFFSTATE_CONFLICTEMPTY)
257 m_pwndBottom->m_pViewData->SetState(i, DIFFSTATE_CONFLICTRESOLVEDEMPTY);
258 else
259 m_pwndBottom->m_pViewData->SetState(i, DIFFSTATE_CONFLICTRESOLVED);
262 m_pwndBottom->SetModified();
264 else
266 for (int i=m_nSelBlockStart; i<=m_nSelBlockEnd; i++)
268 rightstate.difflines[i] = m_pViewData->GetLine(i);
269 m_pViewData->SetLine(i, m_pwndLeft->m_pViewData->GetLine(i));
270 m_pViewData->SetLineEnding(i, lineendings);
271 DiffStates state = m_pwndLeft->m_pViewData->GetState(i);
272 switch (state)
274 case DIFFSTATE_ADDED:
275 case DIFFSTATE_CONFLICTADDED:
276 case DIFFSTATE_CONFLICTED:
277 case DIFFSTATE_CONFLICTED_IGNORED:
278 case DIFFSTATE_CONFLICTEMPTY:
279 case DIFFSTATE_IDENTICALADDED:
280 case DIFFSTATE_NORMAL:
281 case DIFFSTATE_THEIRSADDED:
282 case DIFFSTATE_UNKNOWN:
283 case DIFFSTATE_YOURSADDED:
284 case DIFFSTATE_EMPTY:
285 rightstate.linestates[i] = m_pViewData->GetState(i);
286 m_pViewData->SetState(i, state);
287 break;
288 case DIFFSTATE_IDENTICALREMOVED:
289 case DIFFSTATE_REMOVED:
290 case DIFFSTATE_THEIRSREMOVED:
291 case DIFFSTATE_YOURSREMOVED:
292 rightstate.linestates[i] = m_pViewData->GetState(i);
293 m_pViewData->SetState(i, DIFFSTATE_ADDED);
294 break;
295 default:
296 break;
299 SetModified();
301 CUndo::GetInstance().AddState(leftstate, rightstate, bottomstate, m_ptCaretPos);
302 if (refreshViews)
303 RefreshViews();
306 void CRightView::UseLeftBeforeRight(bool refreshViews /* = true */)
308 viewstate rightstate;
309 viewstate bottomstate;
310 viewstate leftstate;
311 UseBothLeftFirst(rightstate, leftstate);
312 CUndo::GetInstance().AddState(leftstate, rightstate, bottomstate, m_ptCaretPos);
313 if (refreshViews)
314 RefreshViews();
317 void CRightView::UseRightBeforeLeft(bool refreshViews /* = true */)
319 viewstate rightstate;
320 viewstate bottomstate;
321 viewstate leftstate;
322 UseBothRightFirst(rightstate, leftstate);
323 CUndo::GetInstance().AddState(leftstate, rightstate, bottomstate, m_ptCaretPos);
324 if (refreshViews)
325 RefreshViews();