OSDN Git Service

Show Ignore Sub Menu
[tortoisegit/TortoiseGitJp.git] / src / TortoiseMerge / BottomView.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 ".\bottomview.h"\r
23 \r
24 IMPLEMENT_DYNCREATE(CBottomView, CBaseView)\r
25 \r
26 CBottomView::CBottomView(void)\r
27 {\r
28         m_pwndBottom = this;\r
29         m_nStatusBarID = ID_INDICATOR_BOTTOMVIEW;\r
30 }\r
31 \r
32 CBottomView::~CBottomView(void)\r
33 {\r
34 }\r
35 \r
36 bool CBottomView::OnContextMenu(CPoint point, int /*nLine*/, DiffStates state)\r
37 {\r
38         if (!this->IsWindowVisible())\r
39                 return false;\r
40 \r
41         CMenu popup;\r
42         if (popup.CreatePopupMenu())\r
43         {\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
51                 CString temp;\r
52 \r
53                 bool bImportantBlock = true;\r
54                 switch (state)\r
55                 {\r
56                 case DIFFSTATE_UNKNOWN:\r
57                         bImportantBlock = false;\r
58                         break;\r
59                 }\r
60 \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
69 \r
70                 popup.AppendMenu(MF_SEPARATOR, NULL);\r
71 \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
75                 {\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
80                 }\r
81 \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
85                 {\r
86                         CRect rect;\r
87                         GetWindowRect(&rect);\r
88                         point = rect.CenterPoint();\r
89                 }\r
90 \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
95                 switch (cmd)\r
96                 {\r
97                 case ID_USETHEIRBLOCK:\r
98                         UseTheirTextBlock();\r
99                         break;\r
100                 case ID_USEYOURBLOCK:\r
101                         UseMyTextBlock();\r
102                         break;\r
103                 case ID_USEYOURANDTHEIRBLOCK:\r
104                         UseYourAndTheirBlock(rightstate, bottomstate, leftstate);\r
105                         CUndo::GetInstance().AddState(leftstate, rightstate, bottomstate, m_ptCaretPos);\r
106                         break;\r
107                 case ID_USETHEIRANDYOURBLOCK:\r
108                         UseTheirAndYourBlock(rightstate, bottomstate, leftstate);\r
109                         CUndo::GetInstance().AddState(leftstate, rightstate, bottomstate, m_ptCaretPos);\r
110                         break;\r
111                 case ID_EDIT_COPY:\r
112                         OnEditCopy();\r
113                         return true;\r
114                 case ID_EDIT_CUT:\r
115                         OnEditCopy();\r
116                         RemoveSelectedText();\r
117                         break;\r
118                 case ID_EDIT_PASTE:\r
119                         PasteText();\r
120                         break;\r
121                 }\r
122         }\r
123         return false;\r
124 }\r
125 \r
126 void CBottomView::UseTheirTextBlock()\r
127 {\r
128         viewstate leftstate;\r
129         viewstate rightstate;\r
130         viewstate bottomstate;\r
131         if ((m_nSelBlockStart < 0)||(m_nSelBlockEnd < 0))\r
132                 return;\r
133 \r
134         for (int i=m_nSelBlockStart; i<=m_nSelBlockEnd; i++)\r
135         {\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
141                 {\r
142                         if (m_pwndLeft->m_pViewData->GetState(i) == DIFFSTATE_CONFLICTEMPTY)\r
143                                 m_pViewData->SetState(i, DIFFSTATE_CONFLICTRESOLVEDEMPTY);\r
144                         else\r
145                                 m_pViewData->SetState(i, DIFFSTATE_CONFLICTRESOLVED);\r
146                 }\r
147         }\r
148         CUndo::GetInstance().AddState(leftstate, rightstate, bottomstate, m_ptCaretPos);\r
149         SetModified();\r
150         RefreshViews();\r
151 }\r
152 \r
153 void CBottomView::UseMyTextBlock()\r
154 {\r
155         viewstate leftstate;\r
156         viewstate rightstate;\r
157         viewstate bottomstate;\r
158         if ((m_nSelBlockStart < 0)||(m_nSelBlockEnd < 0))\r
159                 return;\r
160 \r
161         for (int i=m_nSelBlockStart; i<=m_nSelBlockEnd; i++)\r
162         {\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
167                 {\r
168                         if (m_pwndRight->m_pViewData->GetState(i) == DIFFSTATE_CONFLICTEMPTY)\r
169                                 m_pViewData->SetState(i, DIFFSTATE_CONFLICTRESOLVEDEMPTY);\r
170                         else\r
171                                 m_pViewData->SetState(i, DIFFSTATE_CONFLICTRESOLVED);\r
172                 }\r
173         }\r
174         CUndo::GetInstance().AddState(leftstate, rightstate, bottomstate, m_ptCaretPos);\r
175         SetModified();\r
176         RefreshViews();\r
177 }\r
178 \r
179 void CBottomView::UseTheirThenMyTextBlock()\r
180 {\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
186         RefreshViews();\r
187 }\r
188 \r
189 void CBottomView::UseMyThenTheirTextBlock()\r
190 {\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
196         RefreshViews();\r
197 }\r