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 ".\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 m_pViewData
->SetLineEnding(i
, EOL_AUTOLINE
);
141 if (IsLineConflicted(i
))
143 if (m_pwndLeft
->m_pViewData
->GetState(i
) == DIFFSTATE_CONFLICTEMPTY
)
144 m_pViewData
->SetState(i
, DIFFSTATE_CONFLICTRESOLVEDEMPTY
);
146 m_pViewData
->SetState(i
, DIFFSTATE_CONFLICTRESOLVED
);
149 CUndo::GetInstance().AddState(leftstate
, rightstate
, bottomstate
, m_ptCaretPos
);
154 void CBottomView::UseMyTextBlock()
157 viewstate rightstate
;
158 viewstate bottomstate
;
159 if ((m_nSelBlockStart
< 0)||(m_nSelBlockEnd
< 0))
162 for (int i
=m_nSelBlockStart
; i
<=m_nSelBlockEnd
; i
++)
164 bottomstate
.difflines
[i
] = m_pViewData
->GetLine(i
);
165 m_pViewData
->SetLine(i
, m_pwndRight
->m_pViewData
->GetLine(i
));
166 bottomstate
.linestates
[i
] = m_pViewData
->GetState(i
);
167 m_pViewData
->SetState(i
, m_pwndRight
->m_pViewData
->GetState(i
));
168 m_pViewData
->SetLineEnding(i
, EOL_AUTOLINE
);
169 m_pViewData
->SetLineEnding(i
, EOL_AUTOLINE
);
171 if (m_pwndRight
->m_pViewData
->GetState(i
) == DIFFSTATE_CONFLICTEMPTY
)
172 m_pViewData
->SetState(i
, DIFFSTATE_CONFLICTRESOLVEDEMPTY
);
174 m_pViewData
->SetState(i
, DIFFSTATE_CONFLICTRESOLVED
);
177 CUndo::GetInstance().AddState(leftstate
, rightstate
, bottomstate
, m_ptCaretPos
);
182 void CBottomView::UseTheirThenMyTextBlock()
185 viewstate rightstate
;
186 viewstate bottomstate
;
187 UseTheirAndYourBlock(rightstate
, bottomstate
, leftstate
);
188 CUndo::GetInstance().AddState(leftstate
, rightstate
, bottomstate
, m_ptCaretPos
);
192 void CBottomView::UseMyThenTheirTextBlock()
195 viewstate rightstate
;
196 viewstate bottomstate
;
197 UseYourAndTheirBlock(rightstate
, bottomstate
, leftstate
);
198 CUndo::GetInstance().AddState(leftstate
, rightstate
, bottomstate
, m_ptCaretPos
);