1 // TortoiseMerge - a Diff/Patch program
\r
3 // Copyright (C) 2006-2008 - TortoiseSVN
\r
5 // This program is free software; you can redistribute it and/or
\r
6 // modify it under the terms of the GNU General Public License
\r
7 // as published by the Free Software Foundation; either version 2
\r
8 // of the License, or (at your option) any later version.
\r
10 // This program is distributed in the hope that it will be useful,
\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 // GNU General Public License for more details.
\r
15 // You should have received a copy of the GNU General Public License
\r
16 // along with this program; if not, write to the Free Software Foundation,
\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
\r
20 #include "Resource.h"
\r
21 #include "AppUtils.h"
\r
22 #include ".\rightview.h"
\r
24 IMPLEMENT_DYNCREATE(CRightView, CBaseView)
\r
26 CRightView::CRightView(void)
\r
29 m_nStatusBarID = ID_INDICATOR_RIGHTVIEW;
\r
32 CRightView::~CRightView(void)
\r
36 bool CRightView::OnContextMenu(CPoint point, int /*nLine*/, DiffStates state)
\r
38 if (!this->IsWindowVisible())
\r
42 if (popup.CreatePopupMenu())
\r
44 #define ID_USEBLOCK 1
\r
45 #define ID_USEFILE 2
\r
46 #define ID_USETHEIRANDYOURBLOCK 3
\r
47 #define ID_USEYOURANDTHEIRBLOCK 4
\r
48 #define ID_USEBOTHTHISFIRST 5
\r
49 #define ID_USEBOTHTHISLAST 6
\r
51 UINT uEnabled = MF_ENABLED;
\r
52 if ((m_nSelBlockStart == -1)||(m_nSelBlockEnd == -1))
\r
53 uEnabled |= MF_DISABLED | MF_GRAYED;
\r
56 bool bImportantBlock = true;
\r
59 case DIFFSTATE_UNKNOWN:
\r
60 bImportantBlock = false;
\r
64 if (!m_pwndBottom->IsWindowVisible())
\r
66 temp.LoadString(IDS_VIEWCONTEXTMENU_USEOTHERBLOCK);
\r
69 temp.LoadString(IDS_VIEWCONTEXTMENU_USETHISBLOCK);
\r
70 popup.AppendMenu(MF_STRING | uEnabled | (bImportantBlock ? MF_ENABLED : MF_DISABLED|MF_GRAYED), ID_USEBLOCK, temp);
\r
72 if (!m_pwndBottom->IsWindowVisible())
\r
74 temp.LoadString(IDS_VIEWCONTEXTMENU_USEOTHERFILE);
\r
77 temp.LoadString(IDS_VIEWCONTEXTMENU_USETHISFILE);
\r
78 popup.AppendMenu(MF_STRING | MF_ENABLED, ID_USEFILE, temp);
\r
80 if (m_pwndBottom->IsWindowVisible())
\r
82 temp.LoadString(IDS_VIEWCONTEXTMENU_USEYOURANDTHEIRBLOCK);
\r
83 popup.AppendMenu(MF_STRING | uEnabled | (bImportantBlock ? MF_ENABLED : MF_DISABLED|MF_GRAYED), ID_USEYOURANDTHEIRBLOCK, temp);
\r
84 temp.LoadString(IDS_VIEWCONTEXTMENU_USETHEIRANDYOURBLOCK);
\r
85 popup.AppendMenu(MF_STRING | uEnabled | (bImportantBlock ? MF_ENABLED : MF_DISABLED|MF_GRAYED), ID_USETHEIRANDYOURBLOCK, temp);
\r
89 temp.LoadString(IDS_VIEWCONTEXTMENU_USEBOTHTHISFIRST);
\r
90 popup.AppendMenu(MF_STRING | uEnabled | (bImportantBlock ? MF_ENABLED : MF_DISABLED|MF_GRAYED), ID_USEBOTHTHISFIRST, temp);
\r
91 temp.LoadString(IDS_VIEWCONTEXTMENU_USEBOTHTHISLAST);
\r
92 popup.AppendMenu(MF_STRING | uEnabled | (bImportantBlock ? MF_ENABLED : MF_DISABLED|MF_GRAYED), ID_USEBOTHTHISLAST, temp);
\r
95 popup.AppendMenu(MF_SEPARATOR, NULL);
\r
97 temp.LoadString(IDS_EDIT_COPY);
\r
98 popup.AppendMenu(MF_STRING | (HasTextSelection() ? MF_ENABLED : MF_DISABLED|MF_GRAYED), ID_EDIT_COPY, temp);
\r
99 if (!m_bCaretHidden)
\r
101 temp.LoadString(IDS_EDIT_CUT);
\r
102 popup.AppendMenu(MF_STRING | (HasTextSelection() ? MF_ENABLED : MF_DISABLED|MF_GRAYED), ID_EDIT_CUT, temp);
\r
103 temp.LoadString(IDS_EDIT_PASTE);
\r
104 popup.AppendMenu(MF_STRING | (CAppUtils::HasClipboardFormat(CF_UNICODETEXT)||CAppUtils::HasClipboardFormat(CF_TEXT) ? MF_ENABLED : MF_DISABLED|MF_GRAYED), ID_EDIT_PASTE, temp);
\r
107 // if the context menu is invoked through the keyboard, we have to use
\r
108 // a calculated position on where to anchor the menu on
\r
109 if ((point.x == -1) && (point.y == -1))
\r
112 GetWindowRect(&rect);
\r
113 point = rect.CenterPoint();
\r
115 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
\r
116 viewstate rightstate;
\r
117 viewstate bottomstate;
\r
118 viewstate leftstate;
\r
126 RemoveSelectedText();
\r
128 case ID_EDIT_PASTE:
\r
141 case ID_USEYOURANDTHEIRBLOCK:
\r
143 UseYourAndTheirBlock(rightstate, bottomstate, leftstate);
\r
144 CUndo::GetInstance().AddState(leftstate, rightstate, bottomstate, m_ptCaretPos);
\r
147 case ID_USETHEIRANDYOURBLOCK:
\r
149 UseTheirAndYourBlock(rightstate, bottomstate, leftstate);
\r
150 CUndo::GetInstance().AddState(leftstate, rightstate, bottomstate, m_ptCaretPos);
\r
153 case ID_USEBOTHTHISFIRST:
\r
155 UseBothRightFirst(rightstate, leftstate);
\r
156 CUndo::GetInstance().AddState(leftstate, rightstate, bottomstate, m_ptCaretPos);
\r
159 case ID_USEBOTHTHISLAST:
\r
161 UseBothLeftFirst(rightstate, leftstate);
\r
162 CUndo::GetInstance().AddState(leftstate, rightstate, bottomstate, m_ptCaretPos);
\r
168 } // if (popup.CreatePopupMenu())
\r
172 void CRightView::UseFile(bool refreshViews /* = true */)
\r
174 viewstate rightstate;
\r
175 viewstate bottomstate;
\r
176 viewstate leftstate;
\r
177 if (m_pwndBottom->IsWindowVisible())
\r
179 for (int i=0; i<GetLineCount(); i++)
\r
181 bottomstate.difflines[i] = m_pwndBottom->m_pViewData->GetLine(i);
\r
182 m_pwndBottom->m_pViewData->SetLine(i, m_pViewData->GetLine(i));
\r
183 bottomstate.linestates[i] = m_pwndBottom->m_pViewData->GetState(i);
\r
184 m_pwndBottom->m_pViewData->SetState(i, m_pViewData->GetState(i));
\r
185 if (m_pwndBottom->IsLineConflicted(i))
\r
186 m_pwndBottom->m_pViewData->SetState(i, DIFFSTATE_CONFLICTRESOLVED);
\r
188 m_pwndBottom->SetModified();
\r
192 for (int i=0; i<GetLineCount(); i++)
\r
194 rightstate.difflines[i] = m_pViewData->GetLine(i);
\r
195 m_pViewData->SetLine(i, m_pwndLeft->m_pViewData->GetLine(i));
\r
196 DiffStates state = m_pwndLeft->m_pViewData->GetState(i);
\r
199 case DIFFSTATE_CONFLICTEMPTY:
\r
200 case DIFFSTATE_UNKNOWN:
\r
201 case DIFFSTATE_EMPTY:
\r
202 rightstate.linestates[i] = m_pViewData->GetState(i);
\r
203 m_pViewData->SetState(i, state);
\r
205 case DIFFSTATE_YOURSADDED:
\r
206 case DIFFSTATE_IDENTICALADDED:
\r
207 case DIFFSTATE_NORMAL:
\r
208 case DIFFSTATE_THEIRSADDED:
\r
209 case DIFFSTATE_ADDED:
\r
210 case DIFFSTATE_CONFLICTADDED:
\r
211 case DIFFSTATE_CONFLICTED:
\r
212 case DIFFSTATE_CONFLICTED_IGNORED:
\r
213 case DIFFSTATE_IDENTICALREMOVED:
\r
214 case DIFFSTATE_REMOVED:
\r
215 case DIFFSTATE_THEIRSREMOVED:
\r
216 case DIFFSTATE_YOURSREMOVED:
\r
217 rightstate.linestates[i] = m_pViewData->GetState(i);
\r
218 m_pViewData->SetState(i, DIFFSTATE_NORMAL);
\r
219 leftstate.linestates[i] = m_pwndLeft->m_pViewData->GetState(i);
\r
220 m_pwndLeft->m_pViewData->SetState(i, DIFFSTATE_NORMAL);
\r
227 m_pwndLocator->DocumentUpdated();
\r
230 CUndo::GetInstance().AddState(leftstate, rightstate, bottomstate, m_ptCaretPos);
\r
235 void CRightView::UseBlock(bool refreshViews /* = true */)
\r
237 viewstate rightstate;
\r
238 viewstate bottomstate;
\r
239 viewstate leftstate;
\r
241 if ((m_nSelBlockStart == -1)||(m_nSelBlockEnd == -1))
\r
243 if (m_pwndBottom->IsWindowVisible())
\r
245 for (int i=m_nSelBlockStart; i<=m_nSelBlockEnd; i++)
\r
247 bottomstate.difflines[i] = m_pwndBottom->m_pViewData->GetLine(i);
\r
248 m_pwndBottom->m_pViewData->SetLine(i, m_pViewData->GetLine(i));
\r
249 bottomstate.linestates[i] = m_pwndBottom->m_pViewData->GetState(i);
\r
250 m_pwndBottom->m_pViewData->SetState(i, m_pViewData->GetState(i));
\r
251 if (m_pwndBottom->IsLineConflicted(i))
\r
253 if (m_pViewData->GetState(i) == DIFFSTATE_CONFLICTEMPTY)
\r
254 m_pwndBottom->m_pViewData->SetState(i, DIFFSTATE_CONFLICTRESOLVEDEMPTY);
\r
256 m_pwndBottom->m_pViewData->SetState(i, DIFFSTATE_CONFLICTRESOLVED);
\r
259 m_pwndBottom->SetModified();
\r
263 for (int i=m_nSelBlockStart; i<=m_nSelBlockEnd; i++)
\r
265 rightstate.difflines[i] = m_pViewData->GetLine(i);
\r
266 m_pViewData->SetLine(i, m_pwndLeft->m_pViewData->GetLine(i));
\r
267 DiffStates state = m_pwndLeft->m_pViewData->GetState(i);
\r
270 case DIFFSTATE_ADDED:
\r
271 case DIFFSTATE_CONFLICTADDED:
\r
272 case DIFFSTATE_CONFLICTED:
\r
273 case DIFFSTATE_CONFLICTED_IGNORED:
\r
274 case DIFFSTATE_CONFLICTEMPTY:
\r
275 case DIFFSTATE_IDENTICALADDED:
\r
276 case DIFFSTATE_NORMAL:
\r
277 case DIFFSTATE_THEIRSADDED:
\r
278 case DIFFSTATE_UNKNOWN:
\r
279 case DIFFSTATE_YOURSADDED:
\r
280 case DIFFSTATE_EMPTY:
\r
281 rightstate.linestates[i] = m_pViewData->GetState(i);
\r
282 m_pViewData->SetState(i, state);
\r
284 case DIFFSTATE_IDENTICALREMOVED:
\r
285 case DIFFSTATE_REMOVED:
\r
286 case DIFFSTATE_THEIRSREMOVED:
\r
287 case DIFFSTATE_YOURSREMOVED:
\r
288 rightstate.linestates[i] = m_pViewData->GetState(i);
\r
289 m_pViewData->SetState(i, DIFFSTATE_ADDED);
\r
297 CUndo::GetInstance().AddState(leftstate, rightstate, bottomstate, m_ptCaretPos);
\r
302 void CRightView::UseLeftBeforeRight(bool refreshViews /* = true */)
\r
304 viewstate rightstate;
\r
305 viewstate bottomstate;
\r
306 viewstate leftstate;
\r
307 UseBothLeftFirst(rightstate, leftstate);
\r
308 CUndo::GetInstance().AddState(leftstate, rightstate, bottomstate, m_ptCaretPos);
\r
313 void CRightView::UseRightBeforeLeft(bool refreshViews /* = true */)
\r
315 viewstate rightstate;
\r
316 viewstate bottomstate;
\r
317 viewstate leftstate;
\r
318 UseBothRightFirst(rightstate, leftstate);
\r
319 CUndo::GetInstance().AddState(leftstate, rightstate, bottomstate, m_ptCaretPos);
\r