1 // TortoiseMerge - a Diff/Patch program
\r
3 // Copyright (C) 2006-2009 - 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 m_pwndBottom->m_pViewData->SetLineEnding(i, m_pViewData->GetLineEnding(i));
\r
186 if (m_pwndBottom->IsLineConflicted(i))
\r
187 m_pwndBottom->m_pViewData->SetState(i, DIFFSTATE_CONFLICTRESOLVED);
\r
189 m_pwndBottom->SetModified();
\r
193 for (int i=0; i<GetLineCount(); i++)
\r
195 rightstate.difflines[i] = m_pViewData->GetLine(i);
\r
196 m_pViewData->SetLine(i, m_pwndLeft->m_pViewData->GetLine(i));
\r
197 m_pViewData->SetLineEnding(i, m_pwndLeft->m_pViewData->GetLineEnding(i));
\r
198 DiffStates state = m_pwndLeft->m_pViewData->GetState(i);
\r
201 case DIFFSTATE_CONFLICTEMPTY:
\r
202 case DIFFSTATE_UNKNOWN:
\r
203 case DIFFSTATE_EMPTY:
\r
204 rightstate.linestates[i] = m_pViewData->GetState(i);
\r
205 m_pViewData->SetState(i, state);
\r
207 case DIFFSTATE_YOURSADDED:
\r
208 case DIFFSTATE_IDENTICALADDED:
\r
209 case DIFFSTATE_NORMAL:
\r
210 case DIFFSTATE_THEIRSADDED:
\r
211 case DIFFSTATE_ADDED:
\r
212 case DIFFSTATE_CONFLICTADDED:
\r
213 case DIFFSTATE_CONFLICTED:
\r
214 case DIFFSTATE_CONFLICTED_IGNORED:
\r
215 case DIFFSTATE_IDENTICALREMOVED:
\r
216 case DIFFSTATE_REMOVED:
\r
217 case DIFFSTATE_THEIRSREMOVED:
\r
218 case DIFFSTATE_YOURSREMOVED:
\r
219 rightstate.linestates[i] = m_pViewData->GetState(i);
\r
220 m_pViewData->SetState(i, DIFFSTATE_NORMAL);
\r
221 leftstate.linestates[i] = m_pwndLeft->m_pViewData->GetState(i);
\r
222 m_pwndLeft->m_pViewData->SetState(i, DIFFSTATE_NORMAL);
\r
229 m_pwndLocator->DocumentUpdated();
\r
232 CUndo::GetInstance().AddState(leftstate, rightstate, bottomstate, m_ptCaretPos);
\r
237 void CRightView::UseBlock(bool refreshViews /* = true */)
\r
239 viewstate rightstate;
\r
240 viewstate bottomstate;
\r
241 viewstate leftstate;
\r
243 if ((m_nSelBlockStart == -1)||(m_nSelBlockEnd == -1))
\r
245 if (m_pwndBottom->IsWindowVisible())
\r
247 for (int i=m_nSelBlockStart; i<=m_nSelBlockEnd; i++)
\r
249 bottomstate.difflines[i] = m_pwndBottom->m_pViewData->GetLine(i);
\r
250 m_pwndBottom->m_pViewData->SetLine(i, m_pViewData->GetLine(i));
\r
251 bottomstate.linestates[i] = m_pwndBottom->m_pViewData->GetState(i);
\r
252 m_pwndBottom->m_pViewData->SetState(i, m_pViewData->GetState(i));
\r
253 m_pwndBottom->m_pViewData->SetLineEnding(i, EOL_AUTOLINE);
\r
254 if (m_pwndBottom->IsLineConflicted(i))
\r
256 if (m_pViewData->GetState(i) == DIFFSTATE_CONFLICTEMPTY)
\r
257 m_pwndBottom->m_pViewData->SetState(i, DIFFSTATE_CONFLICTRESOLVEDEMPTY);
\r
259 m_pwndBottom->m_pViewData->SetState(i, DIFFSTATE_CONFLICTRESOLVED);
\r
262 m_pwndBottom->SetModified();
\r
266 for (int i=m_nSelBlockStart; i<=m_nSelBlockEnd; i++)
\r
268 rightstate.difflines[i] = m_pViewData->GetLine(i);
\r
269 m_pViewData->SetLine(i, m_pwndLeft->m_pViewData->GetLine(i));
\r
270 m_pViewData->SetLineEnding(i, EOL_AUTOLINE);
\r
271 DiffStates state = m_pwndLeft->m_pViewData->GetState(i);
\r
274 case DIFFSTATE_ADDED:
\r
275 case DIFFSTATE_CONFLICTADDED:
\r
276 case DIFFSTATE_CONFLICTED:
\r
277 case DIFFSTATE_CONFLICTED_IGNORED:
\r
278 case DIFFSTATE_CONFLICTEMPTY:
\r
279 case DIFFSTATE_IDENTICALADDED:
\r
280 case DIFFSTATE_NORMAL:
\r
281 case DIFFSTATE_THEIRSADDED:
\r
282 case DIFFSTATE_UNKNOWN:
\r
283 case DIFFSTATE_YOURSADDED:
\r
284 case DIFFSTATE_EMPTY:
\r
285 rightstate.linestates[i] = m_pViewData->GetState(i);
\r
286 m_pViewData->SetState(i, state);
\r
288 case DIFFSTATE_IDENTICALREMOVED:
\r
289 case DIFFSTATE_REMOVED:
\r
290 case DIFFSTATE_THEIRSREMOVED:
\r
291 case DIFFSTATE_YOURSREMOVED:
\r
292 rightstate.linestates[i] = m_pViewData->GetState(i);
\r
293 m_pViewData->SetState(i, DIFFSTATE_ADDED);
\r
301 CUndo::GetInstance().AddState(leftstate, rightstate, bottomstate, m_ptCaretPos);
\r
306 void CRightView::UseLeftBeforeRight(bool refreshViews /* = true */)
\r
308 viewstate rightstate;
\r
309 viewstate bottomstate;
\r
310 viewstate leftstate;
\r
311 UseBothLeftFirst(rightstate, leftstate);
\r
312 CUndo::GetInstance().AddState(leftstate, rightstate, bottomstate, m_ptCaretPos);
\r
317 void CRightView::UseRightBeforeLeft(bool refreshViews /* = true */)
\r
319 viewstate rightstate;
\r
320 viewstate bottomstate;
\r
321 viewstate leftstate;
\r
322 UseBothRightFirst(rightstate, leftstate);
\r
323 CUndo::GetInstance().AddState(leftstate, rightstate, bottomstate, m_ptCaretPos);
\r