Fixed issue #1507: Submodule Diff Dialog should show dirty state only on working...
[TortoiseGit.git] / src / TortoiseMerge / BottomView.cpp
blob40f0de4dc9f34304b49d8bc761babfbe86e46382
1 // TortoiseMerge - a Diff/Patch program
3 // Copyright (C) 2006-2009,2011 - 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.
19 #include "StdAfx.h"
20 #include "Resource.h"
21 #include "AppUtils.h"
22 #include ".\bottomview.h"
24 IMPLEMENT_DYNCREATE(CBottomView, CBaseView)
26 CBottomView::CBottomView(void)
28 m_pwndBottom = this;
29 m_nStatusBarID = ID_INDICATOR_BOTTOMVIEW;
32 CBottomView::~CBottomView(void)
36 bool CBottomView::OnContextMenu(CPoint point, int /*nLine*/, DiffStates state)
38 if (!this->IsWindowVisible())
39 return false;
41 CMenu popup;
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;
51 CString temp;
53 bool bImportantBlock = true;
54 switch (state)
56 case DIFFSTATE_UNKNOWN:
57 bImportantBlock = false;
58 break;
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);
74 if (!m_bCaretHidden)
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))
86 CRect rect;
87 GetWindowRect(&rect);
88 point = rect.CenterPoint();
91 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
92 viewstate rightstate;
93 viewstate bottomstate;
94 viewstate leftstate;
95 switch (cmd)
97 case ID_USETHEIRBLOCK:
98 UseTheirTextBlock();
99 break;
100 case ID_USEYOURBLOCK:
101 UseMyTextBlock();
102 break;
103 case ID_USEYOURANDTHEIRBLOCK:
104 UseYourAndTheirBlock(rightstate, bottomstate, leftstate);
105 CUndo::GetInstance().AddState(leftstate, rightstate, bottomstate, m_ptCaretPos);
106 break;
107 case ID_USETHEIRANDYOURBLOCK:
108 UseTheirAndYourBlock(rightstate, bottomstate, leftstate);
109 CUndo::GetInstance().AddState(leftstate, rightstate, bottomstate, m_ptCaretPos);
110 break;
111 case ID_EDIT_COPY:
112 OnEditCopy();
113 return true;
114 case ID_EDIT_CUT:
115 OnEditCopy();
116 RemoveSelectedText();
117 break;
118 case ID_EDIT_PASTE:
119 PasteText();
120 break;
123 return false;
126 void CBottomView::UseTheirTextBlock()
128 viewstate leftstate;
129 viewstate rightstate;
130 viewstate bottomstate;
131 if ((m_nSelBlockStart < 0)||(m_nSelBlockEnd < 0))
132 return;
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, lineendings);
141 if (IsLineConflicted(i))
143 if (m_pwndLeft->m_pViewData->GetState(i) == DIFFSTATE_CONFLICTEMPTY)
144 m_pViewData->SetState(i, DIFFSTATE_CONFLICTRESOLVEDEMPTY);
145 else
146 m_pViewData->SetState(i, DIFFSTATE_CONFLICTRESOLVED);
149 CUndo::GetInstance().AddState(leftstate, rightstate, bottomstate, m_ptCaretPos);
150 SetModified();
151 RefreshViews();
154 void CBottomView::UseMyTextBlock()
156 viewstate leftstate;
157 viewstate rightstate;
158 viewstate bottomstate;
159 if ((m_nSelBlockStart < 0)||(m_nSelBlockEnd < 0))
160 return;
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, lineendings);
170 if (m_pwndRight->m_pViewData->GetState(i) == DIFFSTATE_CONFLICTEMPTY)
171 m_pViewData->SetState(i, DIFFSTATE_CONFLICTRESOLVEDEMPTY);
172 else
173 m_pViewData->SetState(i, DIFFSTATE_CONFLICTRESOLVED);
176 CUndo::GetInstance().AddState(leftstate, rightstate, bottomstate, m_ptCaretPos);
177 SetModified();
178 RefreshViews();
181 void CBottomView::UseTheirThenMyTextBlock()
183 viewstate leftstate;
184 viewstate rightstate;
185 viewstate bottomstate;
186 UseTheirAndYourBlock(rightstate, bottomstate, leftstate);
187 CUndo::GetInstance().AddState(leftstate, rightstate, bottomstate, m_ptCaretPos);
188 RefreshViews();
191 void CBottomView::UseMyThenTheirTextBlock()
193 viewstate leftstate;
194 viewstate rightstate;
195 viewstate bottomstate;
196 UseYourAndTheirBlock(rightstate, bottomstate, leftstate);
197 CUndo::GetInstance().AddState(leftstate, rightstate, bottomstate, m_ptCaretPos);
198 RefreshViews();