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