1 // TortoiseMerge - a Diff/Patch program
3 // Copyright (C) 2006-2008 - 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 ".\bottomview.h"
24 IMPLEMENT_DYNCREATE(CBottomView
, CBaseView
)
26 CBottomView::CBottomView(void)
29 m_nStatusBarID
= ID_INDICATOR_BOTTOMVIEW
;
32 CBottomView::~CBottomView(void)
36 bool CBottomView::OnContextMenu(CPoint point
, int /*nLine*/, DiffStates state
)
38 if (!this->IsWindowVisible())
42 if (popup
.CreatePopupMenu())
44 #define ID_USETHEIRBLOCK 1
45 #define ID_USEYOURBLOCK 2
46 #define ID_USETHEIRANDYOURBLOCK 3
47 #define ID_USEYOURANDTHEIRBLOCK 4
48 UINT uEnabled
= MF_ENABLED
;
49 if ((m_nSelBlockStart
== -1)||(m_nSelBlockEnd
== -1))
50 uEnabled
|= MF_DISABLED
| MF_GRAYED
;
53 bool bImportantBlock
= true;
56 case DIFFSTATE_UNKNOWN
:
57 bImportantBlock
= false;
61 temp
.LoadString(IDS_VIEWCONTEXTMENU_USETHEIRBLOCK
);
62 popup
.AppendMenu(MF_STRING
| uEnabled
| (bImportantBlock
? MF_ENABLED
: MF_DISABLED
|MF_GRAYED
), ID_USETHEIRBLOCK
, temp
);
63 temp
.LoadString(IDS_VIEWCONTEXTMENU_USEYOURBLOCK
);
64 popup
.AppendMenu(MF_STRING
| uEnabled
| (bImportantBlock
? MF_ENABLED
: MF_DISABLED
|MF_GRAYED
), ID_USEYOURBLOCK
, temp
);
65 temp
.LoadString(IDS_VIEWCONTEXTMENU_USEYOURANDTHEIRBLOCK
);
66 popup
.AppendMenu(MF_STRING
| uEnabled
| (bImportantBlock
? MF_ENABLED
: MF_DISABLED
|MF_GRAYED
), ID_USEYOURANDTHEIRBLOCK
, temp
);
67 temp
.LoadString(IDS_VIEWCONTEXTMENU_USETHEIRANDYOURBLOCK
);
68 popup
.AppendMenu(MF_STRING
| uEnabled
| (bImportantBlock
? MF_ENABLED
: MF_DISABLED
|MF_GRAYED
), ID_USETHEIRANDYOURBLOCK
, temp
);
70 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
72 temp
.LoadString(IDS_EDIT_COPY
);
73 popup
.AppendMenu(MF_STRING
| (HasTextSelection() ? MF_ENABLED
: MF_DISABLED
|MF_GRAYED
), ID_EDIT_COPY
, temp
);
76 temp
.LoadString(IDS_EDIT_CUT
);
77 popup
.AppendMenu(MF_STRING
| (HasTextSelection() ? MF_ENABLED
: MF_DISABLED
|MF_GRAYED
), ID_EDIT_CUT
, temp
);
78 temp
.LoadString(IDS_EDIT_PASTE
);
79 popup
.AppendMenu(MF_STRING
| (CAppUtils::HasClipboardFormat(CF_UNICODETEXT
)||CAppUtils::HasClipboardFormat(CF_TEXT
) ? MF_ENABLED
: MF_DISABLED
|MF_GRAYED
), ID_EDIT_PASTE
, temp
);
82 // if the context menu is invoked through the keyboard, we have to use
83 // a calculated position on where to anchor the menu on
84 if ((point
.x
== -1) && (point
.y
== -1))
88 point
= rect
.CenterPoint();
91 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, this, 0);
93 viewstate bottomstate
;
97 case ID_USETHEIRBLOCK
:
100 case ID_USEYOURBLOCK
:
103 case ID_USEYOURANDTHEIRBLOCK
:
104 UseYourAndTheirBlock(rightstate
, bottomstate
, leftstate
);
105 CUndo::GetInstance().AddState(leftstate
, rightstate
, bottomstate
, m_ptCaretPos
);
107 case ID_USETHEIRANDYOURBLOCK
:
108 UseTheirAndYourBlock(rightstate
, bottomstate
, leftstate
);
109 CUndo::GetInstance().AddState(leftstate
, rightstate
, bottomstate
, m_ptCaretPos
);
116 RemoveSelectedText();
126 void CBottomView::UseTheirTextBlock()
129 viewstate rightstate
;
130 viewstate bottomstate
;
131 if ((m_nSelBlockStart
< 0)||(m_nSelBlockEnd
< 0))
134 for (int i
=m_nSelBlockStart
; i
<=m_nSelBlockEnd
; i
++)
136 bottomstate
.difflines
[i
] = m_pViewData
->GetLine(i
);
137 m_pViewData
->SetLine(i
, m_pwndLeft
->m_pViewData
->GetLine(i
));
138 bottomstate
.linestates
[i
] = m_pViewData
->GetState(i
);
139 m_pViewData
->SetState(i
, m_pwndLeft
->m_pViewData
->GetState(i
));
140 if (IsLineConflicted(i
))
142 if (m_pwndLeft
->m_pViewData
->GetState(i
) == DIFFSTATE_CONFLICTEMPTY
)
143 m_pViewData
->SetState(i
, DIFFSTATE_CONFLICTRESOLVEDEMPTY
);
145 m_pViewData
->SetState(i
, DIFFSTATE_CONFLICTRESOLVED
);
148 CUndo::GetInstance().AddState(leftstate
, rightstate
, bottomstate
, m_ptCaretPos
);
153 void CBottomView::UseMyTextBlock()
156 viewstate rightstate
;
157 viewstate bottomstate
;
158 if ((m_nSelBlockStart
< 0)||(m_nSelBlockEnd
< 0))
161 for (int i
=m_nSelBlockStart
; i
<=m_nSelBlockEnd
; i
++)
163 bottomstate
.difflines
[i
] = m_pViewData
->GetLine(i
);
164 m_pViewData
->SetLine(i
, m_pwndRight
->m_pViewData
->GetLine(i
));
165 bottomstate
.linestates
[i
] = m_pViewData
->GetState(i
);
166 m_pViewData
->SetState(i
, m_pwndRight
->m_pViewData
->GetState(i
));
168 if (m_pwndRight
->m_pViewData
->GetState(i
) == DIFFSTATE_CONFLICTEMPTY
)
169 m_pViewData
->SetState(i
, DIFFSTATE_CONFLICTRESOLVEDEMPTY
);
171 m_pViewData
->SetState(i
, DIFFSTATE_CONFLICTRESOLVED
);
174 CUndo::GetInstance().AddState(leftstate
, rightstate
, bottomstate
, m_ptCaretPos
);
179 void CBottomView::UseTheirThenMyTextBlock()
182 viewstate rightstate
;
183 viewstate bottomstate
;
184 UseTheirAndYourBlock(rightstate
, bottomstate
, leftstate
);
185 CUndo::GetInstance().AddState(leftstate
, rightstate
, bottomstate
, m_ptCaretPos
);
189 void CBottomView::UseMyThenTheirTextBlock()
192 viewstate rightstate
;
193 viewstate bottomstate
;
194 UseYourAndTheirBlock(rightstate
, bottomstate
, leftstate
);
195 CUndo::GetInstance().AddState(leftstate
, rightstate
, bottomstate
, m_ptCaretPos
);