1 // TortoiseMerge - a Diff/Patch program
3 // Copyright (C) 2006-2009 - 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.
22 #include ".\rightview.h"
24 IMPLEMENT_DYNCREATE(CRightView
, CBaseView
)
26 CRightView::CRightView(void)
29 m_nStatusBarID
= ID_INDICATOR_RIGHTVIEW
;
32 CRightView::~CRightView(void)
36 bool CRightView::OnContextMenu(CPoint point
, int /*nLine*/, DiffStates state
)
38 if (!this->IsWindowVisible())
42 if (popup
.CreatePopupMenu())
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
;
56 bool bImportantBlock
= true;
59 case DIFFSTATE_UNKNOWN
:
60 bImportantBlock
= false;
64 if (!m_pwndBottom
->IsWindowVisible())
66 temp
.LoadString(IDS_VIEWCONTEXTMENU_USEOTHERBLOCK
);
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
);
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
);
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
);
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))
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
;
126 RemoveSelectedText();
141 case ID_USEYOURANDTHEIRBLOCK
:
143 UseYourAndTheirBlock(rightstate
, bottomstate
, leftstate
);
144 CUndo::GetInstance().AddState(leftstate
, rightstate
, bottomstate
, m_ptCaretPos
);
147 case ID_USETHEIRANDYOURBLOCK
:
149 UseTheirAndYourBlock(rightstate
, bottomstate
, leftstate
);
150 CUndo::GetInstance().AddState(leftstate
, rightstate
, bottomstate
, m_ptCaretPos
);
153 case ID_USEBOTHTHISFIRST
:
155 UseBothRightFirst(rightstate
, leftstate
);
156 CUndo::GetInstance().AddState(leftstate
, rightstate
, bottomstate
, m_ptCaretPos
);
159 case ID_USEBOTHTHISLAST
:
161 UseBothLeftFirst(rightstate
, leftstate
);
162 CUndo::GetInstance().AddState(leftstate
, rightstate
, bottomstate
, m_ptCaretPos
);
168 } // if (popup.CreatePopupMenu())
172 void CRightView::UseFile(bool refreshViews
/* = true */)
174 viewstate rightstate
;
175 viewstate bottomstate
;
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();
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
);
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
);
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
);
229 m_pwndLocator
->DocumentUpdated();
232 CUndo::GetInstance().AddState(leftstate
, rightstate
, bottomstate
, m_ptCaretPos
);
237 void CRightView::UseBlock(bool refreshViews
/* = true */)
239 viewstate rightstate
;
240 viewstate bottomstate
;
243 if ((m_nSelBlockStart
== -1)||(m_nSelBlockEnd
== -1))
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
, EOL_AUTOLINE
);
254 if (m_pwndBottom
->IsLineConflicted(i
))
256 if (m_pViewData
->GetState(i
) == DIFFSTATE_CONFLICTEMPTY
)
257 m_pwndBottom
->m_pViewData
->SetState(i
, DIFFSTATE_CONFLICTRESOLVEDEMPTY
);
259 m_pwndBottom
->m_pViewData
->SetState(i
, DIFFSTATE_CONFLICTRESOLVED
);
262 m_pwndBottom
->SetModified();
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
, EOL_AUTOLINE
);
271 DiffStates state
= m_pwndLeft
->m_pViewData
->GetState(i
);
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
);
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
);
301 CUndo::GetInstance().AddState(leftstate
, rightstate
, bottomstate
, m_ptCaretPos
);
306 void CRightView::UseLeftBeforeRight(bool refreshViews
/* = true */)
308 viewstate rightstate
;
309 viewstate bottomstate
;
311 UseBothLeftFirst(rightstate
, leftstate
);
312 CUndo::GetInstance().AddState(leftstate
, rightstate
, bottomstate
, m_ptCaretPos
);
317 void CRightView::UseRightBeforeLeft(bool refreshViews
/* = true */)
319 viewstate rightstate
;
320 viewstate bottomstate
;
322 UseBothRightFirst(rightstate
, leftstate
);
323 CUndo::GetInstance().AddState(leftstate
, rightstate
, bottomstate
, m_ptCaretPos
);