OSDN Git Service

TortoiseMerge Basic Support Git patch created by format patch
[tortoisegit/TortoiseGitJp.git] / src / TortoiseMerge / LeftView.cpp
1 // TortoiseMerge - a Diff/Patch program\r
2 \r
3 // Copyright (C) 2006-2009 - 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                                                 m_pwndBottom->m_pViewData->SetLineEnding(i, m_pViewData->GetLineEnding(i));\r
131                                                 if (m_pwndBottom->IsLineConflicted(i))\r
132                                                 {\r
133                                                         if (m_pViewData->GetState(i) == DIFFSTATE_CONFLICTEMPTY)\r
134                                                                 m_pwndBottom->m_pViewData->SetState(i, DIFFSTATE_CONFLICTRESOLVEDEMPTY);\r
135                                                         else\r
136                                                                 m_pwndBottom->m_pViewData->SetState(i, DIFFSTATE_CONFLICTRESOLVED);\r
137                                                 }\r
138                                         }\r
139                                         m_pwndBottom->SetModified();\r
140                                 }\r
141                                 else\r
142                                 {\r
143                                         for (int i=0; i<GetLineCount(); i++)\r
144                                         {\r
145                                                 rightstate.difflines[i] = m_pwndRight->m_pViewData->GetLine(i);\r
146                                                 m_pwndRight->m_pViewData->SetLine(i, m_pViewData->GetLine(i));\r
147                                                 m_pwndRight->m_pViewData->SetLineEnding(i, m_pViewData->GetLineEnding(i));\r
148                                                 DiffStates state2 = m_pViewData->GetState(i);\r
149                                                 switch (state2)\r
150                                                 {\r
151                                                 case DIFFSTATE_CONFLICTEMPTY:\r
152                                                 case DIFFSTATE_UNKNOWN:\r
153                                                 case DIFFSTATE_EMPTY:\r
154                                                         rightstate.linestates[i] = m_pwndRight->m_pViewData->GetState(i);\r
155                                                         m_pwndRight->m_pViewData->SetState(i, state2);\r
156                                                         break;\r
157                                                 case DIFFSTATE_YOURSADDED:\r
158                                                 case DIFFSTATE_IDENTICALADDED:\r
159                                                 case DIFFSTATE_NORMAL:\r
160                                                 case DIFFSTATE_THEIRSADDED:\r
161                                                 case DIFFSTATE_ADDED:\r
162                                                 case DIFFSTATE_CONFLICTADDED:\r
163                                                 case DIFFSTATE_CONFLICTED:\r
164                                                 case DIFFSTATE_CONFLICTED_IGNORED:\r
165                                                 case DIFFSTATE_IDENTICALREMOVED:\r
166                                                 case DIFFSTATE_REMOVED:\r
167                                                 case DIFFSTATE_THEIRSREMOVED:\r
168                                                 case DIFFSTATE_YOURSREMOVED:\r
169                                                         rightstate.linestates[i] = m_pwndRight->m_pViewData->GetState(i);\r
170                                                         m_pwndRight->m_pViewData->SetState(i, DIFFSTATE_NORMAL);\r
171                                                         leftstate.linestates[i] = m_pViewData->GetState(i);\r
172                                                         m_pViewData->SetState(i, DIFFSTATE_NORMAL);\r
173                                                         break;\r
174                                                 default:\r
175                                                         break;\r
176                                                 }\r
177                                         }\r
178                                         m_pwndRight->SetModified();\r
179                                         if (m_pwndLocator)\r
180                                                 m_pwndLocator->DocumentUpdated();\r
181                                 }\r
182                         }\r
183                         break;\r
184                 case ID_USEBLOCK:\r
185                         {\r
186                 if ((m_nSelBlockStart == -1)||(m_nSelBlockEnd == -1))\r
187                     break;\r
188                                 if (m_pwndBottom->IsWindowVisible())\r
189                                 {\r
190                                         for (int i=m_nSelBlockStart; i<=m_nSelBlockEnd; i++)\r
191                                         {\r
192                                                 bottomstate.difflines[i] = m_pwndBottom->m_pViewData->GetLine(i);\r
193                                                 m_pwndBottom->m_pViewData->SetLine(i, m_pViewData->GetLine(i));\r
194                                                 bottomstate.linestates[i] = m_pwndBottom->m_pViewData->GetState(i);\r
195                                                 m_pwndBottom->m_pViewData->SetState(i, m_pViewData->GetState(i));\r
196                                                 m_pwndBottom->m_pViewData->SetLineEnding(i, EOL_AUTOLINE);\r
197                                                 if (m_pwndBottom->IsLineConflicted(i))\r
198                                                 {\r
199                                                         if (m_pViewData->GetState(i) == DIFFSTATE_CONFLICTEMPTY)\r
200                                                                 m_pwndBottom->m_pViewData->SetState(i, DIFFSTATE_CONFLICTRESOLVEDEMPTY);\r
201                                                         else\r
202                                                                 m_pwndBottom->m_pViewData->SetState(i, DIFFSTATE_CONFLICTRESOLVED);\r
203                                                 }\r
204                                         }\r
205                                         m_pwndBottom->SetModified();\r
206                                 }\r
207                                 else\r
208                                 {\r
209                                         for (int i=m_nSelBlockStart; i<=m_nSelBlockEnd; i++)\r
210                                         {\r
211                                                 rightstate.difflines[i] = m_pwndRight->m_pViewData->GetLine(i);\r
212                                                 m_pwndRight->m_pViewData->SetLine(i, m_pViewData->GetLine(i));\r
213                                                 m_pwndRight->m_pViewData->SetLineEnding(i, EOL_AUTOLINE);\r
214                                                 DiffStates state2 = m_pViewData->GetState(i);\r
215                                                 switch (state2)\r
216                                                 {\r
217                                                 case DIFFSTATE_ADDED:\r
218                                                 case DIFFSTATE_CONFLICTADDED:\r
219                                                 case DIFFSTATE_CONFLICTED:\r
220                                                 case DIFFSTATE_CONFLICTED_IGNORED:\r
221                                                 case DIFFSTATE_CONFLICTEMPTY:\r
222                                                 case DIFFSTATE_IDENTICALADDED:\r
223                                                 case DIFFSTATE_NORMAL:\r
224                                                 case DIFFSTATE_THEIRSADDED:\r
225                                                 case DIFFSTATE_UNKNOWN:\r
226                                                 case DIFFSTATE_YOURSADDED:\r
227                                                 case DIFFSTATE_EMPTY:\r
228                                                         rightstate.linestates[i] = m_pwndRight->m_pViewData->GetState(i);\r
229                                                         m_pwndRight->m_pViewData->SetState(i, state2);\r
230                                                         break;\r
231                                                 case DIFFSTATE_IDENTICALREMOVED:\r
232                                                 case DIFFSTATE_REMOVED:\r
233                                                 case DIFFSTATE_THEIRSREMOVED:\r
234                                                 case DIFFSTATE_YOURSREMOVED:\r
235                                                         rightstate.linestates[i] = m_pwndRight->m_pViewData->GetState(i);\r
236                                                         m_pwndRight->m_pViewData->SetState(i, DIFFSTATE_ADDED);\r
237                                                         break;\r
238                                                 default:\r
239                                                         break;\r
240                                                 }\r
241                                         }\r
242                                         m_pwndRight->SetModified();\r
243                                 }\r
244                         } \r
245                         break;\r
246                 case ID_USEYOURANDTHEIRBLOCK:\r
247                         {\r
248                                 UseYourAndTheirBlock(rightstate, bottomstate, leftstate);\r
249                         }\r
250                         break;\r
251                 case ID_USETHEIRANDYOURBLOCK:\r
252                         {\r
253                                 UseTheirAndYourBlock(rightstate, bottomstate, leftstate);\r
254                         }\r
255                         break;\r
256                 case ID_USEBOTHTHISLAST:\r
257                         {\r
258                                 UseBothRightFirst(rightstate, leftstate);\r
259                         }\r
260                         break;\r
261                 case ID_USEBOTHTHISFIRST:\r
262                         {\r
263                                 UseBothLeftFirst(rightstate, leftstate);\r
264                         }\r
265                         break;\r
266                 default:\r
267                         return false;\r
268                 } // switch (cmd) \r
269                 CUndo::GetInstance().AddState(leftstate, rightstate, bottomstate, m_ptCaretPos);\r
270         } // if (popup.CreatePopupMenu()) \r
271         return false;\r
272 }\r