OSDN Git Service

653c197a05d16000a55a4e3ed496419247d0df0e
[tortoisegit/TortoiseGitJp.git] / src / TortoiseMerge / LeftView.cpp
1 // TortoiseMerge - a Diff/Patch program\r
2 \r
3 // Copyright (C) 2006-2008 - TortoiseSVN\r
4 \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
9 \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
14 \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
18 //\r
19 #include "StdAfx.h"\r
20 #include "Resource.h"\r
21 #include "AppUtils.h"\r
22 #include ".\leftview.h"\r
23 \r
24 IMPLEMENT_DYNCREATE(CLeftView, CBaseView)\r
25 \r
26 CLeftView::CLeftView(void)\r
27 {\r
28         m_pwndLeft = this;\r
29         m_nStatusBarID = ID_INDICATOR_LEFTVIEW;\r
30 }\r
31 \r
32 CLeftView::~CLeftView(void)\r
33 {\r
34 }\r
35 \r
36 bool CLeftView::OnContextMenu(CPoint point, int /*nLine*/, DiffStates state)\r
37 {\r
38         if (!m_pwndRight->IsWindowVisible())\r
39                 return false;\r
40 \r
41         CMenu popup;\r
42         if (popup.CreatePopupMenu())\r
43         {\r
44 #define ID_USEBLOCK 1\r
45 #define ID_USEFILE 2\r
46 #define ID_USETHEIRANDYOURBLOCK 3\r
47 #define ID_USEYOURANDTHEIRBLOCK 4\r
48 #define ID_USEBOTHTHISFIRST 5\r
49 #define ID_USEBOTHTHISLAST 6\r
50 \r
51                 UINT uFlags = MF_ENABLED;\r
52                 if ((m_nSelBlockStart == -1)||(m_nSelBlockEnd == -1))\r
53                         uFlags |= MF_DISABLED | MF_GRAYED;\r
54                 CString temp;\r
55                 \r
56                 bool bImportantBlock = true;\r
57                 switch (state)\r
58                 {\r
59                 case DIFFSTATE_UNKNOWN:\r
60                         bImportantBlock = false;\r
61                         break;\r
62                 }\r
63                 temp.LoadString(IDS_VIEWCONTEXTMENU_USETHISBLOCK);\r
64                 popup.AppendMenu(MF_STRING | uFlags | (bImportantBlock ? MF_ENABLED : MF_DISABLED|MF_GRAYED), ID_USEBLOCK, temp);\r
65 \r
66                 temp.LoadString(IDS_VIEWCONTEXTMENU_USETHISFILE);\r
67                 popup.AppendMenu(MF_STRING | MF_ENABLED, ID_USEFILE, temp);\r
68 \r
69                 if (m_pwndBottom->IsWindowVisible())\r
70                 {\r
71                         temp.LoadString(IDS_VIEWCONTEXTMENU_USEYOURANDTHEIRBLOCK);\r
72                         popup.AppendMenu(MF_STRING | uFlags | (bImportantBlock ? MF_ENABLED : MF_DISABLED|MF_GRAYED), ID_USEYOURANDTHEIRBLOCK, temp);\r
73                         temp.LoadString(IDS_VIEWCONTEXTMENU_USETHEIRANDYOURBLOCK);\r
74                         popup.AppendMenu(MF_STRING | uFlags | (bImportantBlock ? MF_ENABLED : MF_DISABLED|MF_GRAYED), ID_USETHEIRANDYOURBLOCK, temp);\r
75                 }\r
76                 else\r
77                 {\r
78                         temp.LoadString(IDS_VIEWCONTEXTMENU_USEBOTHTHISFIRST);\r
79                         popup.AppendMenu(MF_STRING | uFlags | (bImportantBlock ? MF_ENABLED : MF_DISABLED|MF_GRAYED), ID_USEBOTHTHISFIRST, temp);\r
80                         temp.LoadString(IDS_VIEWCONTEXTMENU_USEBOTHTHISLAST);\r
81                         popup.AppendMenu(MF_STRING | uFlags | (bImportantBlock ? MF_ENABLED : MF_DISABLED|MF_GRAYED), ID_USEBOTHTHISLAST, temp);\r
82                 }\r
83 \r
84                 popup.AppendMenu(MF_SEPARATOR, NULL);\r
85 \r
86                 temp.LoadString(IDS_EDIT_COPY);\r
87                 popup.AppendMenu(MF_STRING | (HasTextSelection() ? MF_ENABLED : MF_DISABLED|MF_GRAYED), ID_EDIT_COPY, temp);\r
88                 if (!m_bCaretHidden)\r
89                 {\r
90                         temp.LoadString(IDS_EDIT_CUT);\r
91                         popup.AppendMenu(MF_STRING | (HasTextSelection() ? MF_ENABLED : MF_DISABLED|MF_GRAYED), ID_EDIT_CUT, temp);\r
92                         temp.LoadString(IDS_EDIT_PASTE);\r
93                         popup.AppendMenu(MF_STRING | (CAppUtils::HasClipboardFormat(CF_UNICODETEXT)||CAppUtils::HasClipboardFormat(CF_TEXT) ? MF_ENABLED : MF_DISABLED|MF_GRAYED), ID_EDIT_PASTE, temp);\r
94                 }\r
95 \r
96                 // if the context menu is invoked through the keyboard, we have to use\r
97                 // a calculated position on where to anchor the menu on\r
98                 if ((point.x == -1) && (point.y == -1))\r
99                 {\r
100                         CRect rect;\r
101                         GetWindowRect(&rect);\r
102                         point = rect.CenterPoint();\r
103                 }\r
104                 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);\r
105                 viewstate leftstate;\r
106                 viewstate bottomstate;\r
107                 viewstate rightstate;\r
108                 switch (cmd)\r
109                 {\r
110                 case ID_EDIT_COPY:\r
111                         OnEditCopy();\r
112                         return true;\r
113                 case ID_EDIT_CUT:\r
114                         OnEditCopy();\r
115                         RemoveSelectedText();\r
116                         return false;\r
117                 case ID_EDIT_PASTE:\r
118                         PasteText();\r
119                         return false;\r
120                 case ID_USEFILE:\r
121                         {\r
122                                 if (m_pwndBottom->IsWindowVisible())\r
123                                 {\r
124                                         for (int i=0; i<GetLineCount(); i++)\r
125                                         {\r
126                                                 bottomstate.difflines[i] = m_pwndBottom->m_pViewData->GetLine(i);\r
127                                                 m_pwndBottom->m_pViewData->SetLine(i, m_pViewData->GetLine(i));\r
128                                                 bottomstate.linestates[i] = m_pwndBottom->m_pViewData->GetState(i);\r
129                                                 m_pwndBottom->m_pViewData->SetState(i, m_pViewData->GetState(i));\r
130                                                 if (m_pwndBottom->IsLineConflicted(i))\r
131                                                 {\r
132                                                         if (m_pViewData->GetState(i) == DIFFSTATE_CONFLICTEMPTY)\r
133                                                                 m_pwndBottom->m_pViewData->SetState(i, DIFFSTATE_CONFLICTRESOLVEDEMPTY);\r
134                                                         else\r
135                                                                 m_pwndBottom->m_pViewData->SetState(i, DIFFSTATE_CONFLICTRESOLVED);\r
136                                                 }\r
137                                         }\r
138                                         m_pwndBottom->SetModified();\r
139                                 }\r
140                                 else\r
141                                 {\r
142                                         for (int i=0; i<GetLineCount(); i++)\r
143                                         {\r
144                                                 rightstate.difflines[i] = m_pwndRight->m_pViewData->GetLine(i);\r
145                                                 m_pwndRight->m_pViewData->SetLine(i, m_pViewData->GetLine(i));\r
146                                                 DiffStates state = m_pViewData->GetState(i);\r
147                                                 switch (state)\r
148                                                 {\r
149                                                 case DIFFSTATE_CONFLICTEMPTY:\r
150                                                 case DIFFSTATE_UNKNOWN:\r
151                                                 case DIFFSTATE_EMPTY:\r
152                                                         rightstate.linestates[i] = m_pwndRight->m_pViewData->GetState(i);\r
153                                                         m_pwndRight->m_pViewData->SetState(i, state);\r
154                                                         break;\r
155                                                 case DIFFSTATE_YOURSADDED:\r
156                                                 case DIFFSTATE_IDENTICALADDED:\r
157                                                 case DIFFSTATE_NORMAL:\r
158                                                 case DIFFSTATE_THEIRSADDED:\r
159                                                 case DIFFSTATE_ADDED:\r
160                                                 case DIFFSTATE_CONFLICTADDED:\r
161                                                 case DIFFSTATE_CONFLICTED:\r
162                                                 case DIFFSTATE_CONFLICTED_IGNORED:\r
163                                                 case DIFFSTATE_IDENTICALREMOVED:\r
164                                                 case DIFFSTATE_REMOVED:\r
165                                                 case DIFFSTATE_THEIRSREMOVED:\r
166                                                 case DIFFSTATE_YOURSREMOVED:\r
167                                                         rightstate.linestates[i] = m_pwndRight->m_pViewData->GetState(i);\r
168                                                         m_pwndRight->m_pViewData->SetState(i, DIFFSTATE_NORMAL);\r
169                                                         leftstate.linestates[i] = m_pViewData->GetState(i);\r
170                                                         m_pViewData->SetState(i, DIFFSTATE_NORMAL);\r
171                                                         break;\r
172                                                 default:\r
173                                                         break;\r
174                                                 }\r
175                                         }\r
176                                         m_pwndRight->SetModified();\r
177                                         if (m_pwndLocator)\r
178                                                 m_pwndLocator->DocumentUpdated();\r
179                                 }\r
180                         }\r
181                         break;\r
182                 case ID_USEBLOCK:\r
183                         {\r
184                 if ((m_nSelBlockStart == -1)||(m_nSelBlockEnd == -1))\r
185                     break;\r
186                                 if (m_pwndBottom->IsWindowVisible())\r
187                                 {\r
188                                         for (int i=m_nSelBlockStart; i<=m_nSelBlockEnd; i++)\r
189                                         {\r
190                                                 bottomstate.difflines[i] = m_pwndBottom->m_pViewData->GetLine(i);\r
191                                                 m_pwndBottom->m_pViewData->SetLine(i, m_pViewData->GetLine(i));\r
192                                                 bottomstate.linestates[i] = m_pwndBottom->m_pViewData->GetState(i);\r
193                                                 m_pwndBottom->m_pViewData->SetState(i, m_pViewData->GetState(i));\r
194                                                 if (m_pwndBottom->IsLineConflicted(i))\r
195                                                 {\r
196                                                         if (m_pViewData->GetState(i) == DIFFSTATE_CONFLICTEMPTY)\r
197                                                                 m_pwndBottom->m_pViewData->SetState(i, DIFFSTATE_CONFLICTRESOLVEDEMPTY);\r
198                                                         else\r
199                                                                 m_pwndBottom->m_pViewData->SetState(i, DIFFSTATE_CONFLICTRESOLVED);\r
200                                                 }\r
201                                         }\r
202                                         m_pwndBottom->SetModified();\r
203                                 }\r
204                                 else\r
205                                 {\r
206                                         for (int i=m_nSelBlockStart; i<=m_nSelBlockEnd; i++)\r
207                                         {\r
208                                                 rightstate.difflines[i] = m_pwndRight->m_pViewData->GetLine(i);\r
209                                                 m_pwndRight->m_pViewData->SetLine(i, m_pViewData->GetLine(i));\r
210                                                 DiffStates state = m_pViewData->GetState(i);\r
211                                                 switch (state)\r
212                                                 {\r
213                                                 case DIFFSTATE_ADDED:\r
214                                                 case DIFFSTATE_CONFLICTADDED:\r
215                                                 case DIFFSTATE_CONFLICTED:\r
216                                                 case DIFFSTATE_CONFLICTED_IGNORED:\r
217                                                 case DIFFSTATE_CONFLICTEMPTY:\r
218                                                 case DIFFSTATE_IDENTICALADDED:\r
219                                                 case DIFFSTATE_NORMAL:\r
220                                                 case DIFFSTATE_THEIRSADDED:\r
221                                                 case DIFFSTATE_UNKNOWN:\r
222                                                 case DIFFSTATE_YOURSADDED:\r
223                                                 case DIFFSTATE_EMPTY:\r
224                                                         rightstate.linestates[i] = m_pwndRight->m_pViewData->GetState(i);\r
225                                                         m_pwndRight->m_pViewData->SetState(i, state);\r
226                                                         break;\r
227                                                 case DIFFSTATE_IDENTICALREMOVED:\r
228                                                 case DIFFSTATE_REMOVED:\r
229                                                 case DIFFSTATE_THEIRSREMOVED:\r
230                                                 case DIFFSTATE_YOURSREMOVED:\r
231                                                         rightstate.linestates[i] = m_pwndRight->m_pViewData->GetState(i);\r
232                                                         m_pwndRight->m_pViewData->SetState(i, DIFFSTATE_ADDED);\r
233                                                         break;\r
234                                                 default:\r
235                                                         break;\r
236                                                 }\r
237                                         }\r
238                                         m_pwndRight->SetModified();\r
239                                 }\r
240                         } \r
241                         break;\r
242                 case ID_USEYOURANDTHEIRBLOCK:\r
243                         {\r
244                                 UseYourAndTheirBlock(rightstate, bottomstate, leftstate);\r
245                         }\r
246                         break;\r
247                 case ID_USETHEIRANDYOURBLOCK:\r
248                         {\r
249                                 UseTheirAndYourBlock(rightstate, bottomstate, leftstate);\r
250                         }\r
251                         break;\r
252                 case ID_USEBOTHTHISLAST:\r
253                         {\r
254                                 UseBothRightFirst(rightstate, leftstate);\r
255                         }\r
256                         break;\r
257                 case ID_USEBOTHTHISFIRST:\r
258                         {\r
259                                 UseBothLeftFirst(rightstate, leftstate);\r
260                         }\r
261                         break;\r
262                 default:\r
263                         return false;\r
264                 } // switch (cmd) \r
265                 CUndo::GetInstance().AddState(leftstate, rightstate, bottomstate, m_ptCaretPos);\r
266         } // if (popup.CreatePopupMenu()) \r
267         return false;\r
268 }\r