OSDN Git Service

Update version number to 1.2.1.0
[tortoisegit/TortoiseGitJp.git] / src / TortoiseMerge / BottomView.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 ".\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                 m_pViewData->SetLineEnding(i, EOL_AUTOLINE);\r
141                 if (IsLineConflicted(i))\r
142                 {\r
143                         if (m_pwndLeft->m_pViewData->GetState(i) == DIFFSTATE_CONFLICTEMPTY)\r
144                                 m_pViewData->SetState(i, DIFFSTATE_CONFLICTRESOLVEDEMPTY);\r
145                         else\r
146                                 m_pViewData->SetState(i, DIFFSTATE_CONFLICTRESOLVED);\r
147                 }\r
148         }\r
149         CUndo::GetInstance().AddState(leftstate, rightstate, bottomstate, m_ptCaretPos);\r
150         SetModified();\r
151         RefreshViews();\r
152 }\r
153 \r
154 void CBottomView::UseMyTextBlock()\r
155 {\r
156         viewstate leftstate;\r
157         viewstate rightstate;\r
158         viewstate bottomstate;\r
159         if ((m_nSelBlockStart < 0)||(m_nSelBlockEnd < 0))\r
160                 return;\r
161 \r
162         for (int i=m_nSelBlockStart; i<=m_nSelBlockEnd; i++)\r
163         {\r
164                 bottomstate.difflines[i] = m_pViewData->GetLine(i);\r
165                 m_pViewData->SetLine(i, m_pwndRight->m_pViewData->GetLine(i));\r
166                 bottomstate.linestates[i] = m_pViewData->GetState(i);\r
167                 m_pViewData->SetState(i, m_pwndRight->m_pViewData->GetState(i));\r
168                 m_pViewData->SetLineEnding(i, EOL_AUTOLINE);\r
169                 m_pViewData->SetLineEnding(i, EOL_AUTOLINE);\r
170                 {\r
171                         if (m_pwndRight->m_pViewData->GetState(i) == DIFFSTATE_CONFLICTEMPTY)\r
172                                 m_pViewData->SetState(i, DIFFSTATE_CONFLICTRESOLVEDEMPTY);\r
173                         else\r
174                                 m_pViewData->SetState(i, DIFFSTATE_CONFLICTRESOLVED);\r
175                 }\r
176         }\r
177         CUndo::GetInstance().AddState(leftstate, rightstate, bottomstate, m_ptCaretPos);\r
178         SetModified();\r
179         RefreshViews();\r
180 }\r
181 \r
182 void CBottomView::UseTheirThenMyTextBlock()\r
183 {\r
184         viewstate leftstate;\r
185         viewstate rightstate;\r
186         viewstate bottomstate;\r
187         UseTheirAndYourBlock(rightstate, bottomstate, leftstate);\r
188         CUndo::GetInstance().AddState(leftstate, rightstate, bottomstate, m_ptCaretPos);\r
189         RefreshViews();\r
190 }\r
191 \r
192 void CBottomView::UseMyThenTheirTextBlock()\r
193 {\r
194         viewstate leftstate;\r
195         viewstate rightstate;\r
196         viewstate bottomstate;\r
197         UseYourAndTheirBlock(rightstate, bottomstate, leftstate);\r
198         CUndo::GetInstance().AddState(leftstate, rightstate, bottomstate, m_ptCaretPos);\r
199         RefreshViews();\r
200 }\r