1 // TortoiseGitMerge - a Diff/Patch program
3 // Copyright (C) 2006-2013 - 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.
23 #include "bottomview.h"
25 IMPLEMENT_DYNCREATE(CBottomView
, CBaseView
)
27 CBottomView::CBottomView(void)
30 m_pState
= &m_AllState
.bottom
;
31 m_nStatusBarID
= ID_INDICATOR_BOTTOMVIEW
;
34 CBottomView::~CBottomView(void)
39 void CBottomView::AddContextItems(CIconMenu
& popup
, DiffStates state
)
41 const bool bShow
= HasSelection() && (state
!= DIFFSTATE_UNKNOWN
);
45 popup
.AppendMenuIcon(POPUPCOMMAND_USETHEIRBLOCK
, IDS_VIEWCONTEXTMENU_USETHEIRBLOCK
);
46 popup
.AppendMenuIcon(POPUPCOMMAND_USEYOURBLOCK
, IDS_VIEWCONTEXTMENU_USEYOURBLOCK
);
47 popup
.AppendMenuIcon(POPUPCOMMAND_USEYOURANDTHEIRBLOCK
, IDS_VIEWCONTEXTMENU_USEYOURANDTHEIRBLOCK
);
48 popup
.AppendMenuIcon(POPUPCOMMAND_USETHEIRANDYOURBLOCK
, IDS_VIEWCONTEXTMENU_USETHEIRANDYOURBLOCK
);
50 CBaseView::AddContextItems(popup
, state
);
54 void CBottomView::UseBlock(CBaseView
* pwndView
, int nFirstViewLine
, int nLastViewLine
)
56 if (!IsViewGood(pwndView
))
58 CUndo::GetInstance().BeginGrouping(); // start group undo
60 for (int viewLine
= nFirstViewLine
; viewLine
<= nLastViewLine
; viewLine
++)
62 viewdata lineData
= pwndView
->GetViewData(viewLine
);
63 if ((lineData
.ending
!= EOL_NOENDING
)||(viewLine
< (GetViewCount()-1)))
64 lineData
.ending
= lineendings
;
65 lineData
.state
= ResolveState(lineData
.state
);
66 SetViewData(viewLine
, lineData
);
69 // make sure previous (non empty) line have EOL set
70 for (int nCheckViewLine
= nFirstViewLine
-1; nCheckViewLine
> 0; nCheckViewLine
--)
72 if (!IsViewLineEmpty(nCheckViewLine
))
74 if (GetViewLineEnding(nCheckViewLine
) == EOL_NOENDING
)
76 SetViewLineEnding(nCheckViewLine
, lineendings
);
82 int nRemovedLines
= CleanEmptyLines();
84 UpdateViewLineNumbers();
87 CUndo::GetInstance().EndGrouping();
91 SetupAllViewSelection(nFirstViewLine
, nLastViewLine
- nRemovedLines
);
92 BuildAllScreen2ViewVector();
97 void CBottomView::UseBothBlocks(CBaseView
* pwndFirst
, CBaseView
* pwndLast
)
99 if (!IsViewGood(pwndFirst
) || !IsViewGood(pwndLast
))
101 int nFirstViewLine
= 0; // first view line in selection
102 int nLastViewLine
= 0; // last view line in selection
104 if (!GetViewSelection(nFirstViewLine
, nLastViewLine
))
107 int nNextViewLine
= nLastViewLine
+ 1; // first view line after selected block
109 CUndo::GetInstance().BeginGrouping(); // start group undo
111 // use (copy) first block
112 for (int viewLine
= nFirstViewLine
; viewLine
<= nLastViewLine
; viewLine
++)
114 viewdata lineData
= pwndFirst
->GetViewData(viewLine
);
115 if ((lineData
.ending
!= EOL_NOENDING
)||(viewLine
< (GetViewCount()-1)))
116 lineData
.ending
= lineendings
;
117 lineData
.state
= ResolveState(lineData
.state
);
118 SetViewData(viewLine
, lineData
);
119 if (!IsStateEmpty(pwndFirst
->GetViewState(viewLine
)))
121 pwndFirst
->SetViewState(viewLine
, DIFFSTATE_YOURSADDED
); // this is improper (may be DIFFSTATE_THEIRSADDED) but seems not to produce any visible bug
124 // make sure previous (non empty) line have EOL set
125 for (int nCheckViewLine
= nFirstViewLine
-1; nCheckViewLine
> 0; nCheckViewLine
--)
127 if (!IsViewLineEmpty(nCheckViewLine
))
129 if (GetViewLineEnding(nCheckViewLine
) == EOL_NOENDING
)
131 SetViewLineEnding(nCheckViewLine
, lineendings
);
139 // use (insert) last block
140 int nViewIndex
= nNextViewLine
;
141 for (int viewLine
= nFirstViewLine
; viewLine
<= nLastViewLine
; viewLine
++, nViewIndex
++)
143 viewdata lineData
= pwndLast
->GetViewData(viewLine
);
144 lineData
.state
= ResolveState(lineData
.state
);
145 InsertViewData(nViewIndex
, lineData
);
146 if (!IsStateEmpty(pwndLast
->GetViewState(viewLine
)))
148 pwndLast
->SetViewState(viewLine
, DIFFSTATE_THEIRSADDED
); // this is improper but seems not to produce any visible bug
153 // adjust line numbers in target
154 // we fix all line numbers to handle exotic cases
155 UpdateViewLineNumbers();
158 // now insert an empty block in both first and last
159 int nCount
= nLastViewLine
- nFirstViewLine
+ 1;
160 pwndLast
->InsertViewEmptyLines(nFirstViewLine
, nCount
);
161 pwndFirst
->InsertViewEmptyLines(nNextViewLine
, nCount
);
164 int nRemovedLines
= CleanEmptyLines();
167 CUndo::GetInstance().EndGrouping();
171 SetupAllViewSelection(nFirstViewLine
, 2*nLastViewLine
- nFirstViewLine
- nRemovedLines
+ 1);
172 BuildAllScreen2ViewVector();
174 pwndLast
->SetModified();
175 pwndFirst
->SetModified();
179 void CBottomView::UseViewBlock(CBaseView
* pwndView
)
181 if (!IsViewGood(pwndView
))
183 int nFirstViewLine
= 0; // first view line in selection
184 int nLastViewLine
= 0; // last view line in selection
186 if (!GetViewSelection(nFirstViewLine
, nLastViewLine
))
189 return UseBlock(pwndView
, nFirstViewLine
, nLastViewLine
);
192 void CBottomView::UseViewFile(CBaseView
* pwndView
)
194 if (!IsViewGood(pwndView
))
196 int nFirstViewLine
= 0;
197 int nLastViewLine
= GetViewCount()-1;
199 return UseBlock(pwndView
, nFirstViewLine
, nLastViewLine
);