Don't create the tooltips as topmost, and don't position them as topmost either but...
[TortoiseGit.git] / src / TortoiseMerge / BottomView.cpp
blob9fe4a1e3dc8b192fd57f93f56a98591f00882611
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.
19 #include "stdafx.h"
20 #include "resource.h"
21 #include "AppUtils.h"
23 #include "BottomView.h"
25 IMPLEMENT_DYNCREATE(CBottomView, CBaseView)
27 CBottomView::CBottomView(void)
29 m_pwndBottom = this;
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);
42 if (!bShow)
43 return;
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))
57 return;
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 = m_lineendings;
65 lineData.state = ResolveState(lineData.state);
66 SetViewData(viewLine, lineData);
67 SetModified();
70 // make sure previous (non empty) line have EOL set
71 for (int nCheckViewLine = nFirstViewLine-1; nCheckViewLine > 0; nCheckViewLine--)
73 if (!IsViewLineEmpty(nCheckViewLine))
75 if (GetViewLineEnding(nCheckViewLine) == EOL_NOENDING)
77 SetViewLineEnding(nCheckViewLine, m_lineendings);
78 SetModified();
80 break;
84 int nRemovedLines = CleanEmptyLines();
85 SaveUndoStep();
86 UpdateViewLineNumbers();
87 SaveUndoStep();
89 CUndo::GetInstance().EndGrouping();
91 // final clean up
92 ClearSelection();
93 SetupAllViewSelection(nFirstViewLine, nLastViewLine - nRemovedLines);
94 BuildAllScreen2ViewVector();
95 RefreshViews();
98 void CBottomView::UseBothBlocks(CBaseView * pwndFirst, CBaseView * pwndLast)
100 if (!IsViewGood(pwndFirst) || !IsViewGood(pwndLast))
101 return;
102 int nFirstViewLine = 0; // first view line in selection
103 int nLastViewLine = 0; // last view line in selection
105 if (!GetViewSelection(nFirstViewLine, nLastViewLine))
106 return;
108 int nNextViewLine = nLastViewLine + 1; // first view line after selected block
110 CUndo::GetInstance().BeginGrouping(); // start group undo
112 // use (copy) first block
113 for (int viewLine = nFirstViewLine; viewLine <= nLastViewLine; viewLine++)
115 viewdata lineData = pwndFirst->GetViewData(viewLine);
116 if ((lineData.ending != EOL_NOENDING)||(viewLine < (GetViewCount()-1)))
117 lineData.ending = m_lineendings;
118 lineData.state = ResolveState(lineData.state);
119 SetViewData(viewLine, lineData);
120 if (!IsStateEmpty(pwndFirst->GetViewState(viewLine)))
122 pwndFirst->SetViewState(viewLine, DIFFSTATE_YOURSADDED); // this is improper (may be DIFFSTATE_THEIRSADDED) but seems not to produce any visible bug
125 // make sure previous (non empty) line have EOL set
126 for (int nCheckViewLine = nFirstViewLine-1; nCheckViewLine > 0; nCheckViewLine--)
128 if (!IsViewLineEmpty(nCheckViewLine))
130 if (GetViewLineEnding(nCheckViewLine) == EOL_NOENDING)
132 SetViewLineEnding(nCheckViewLine, m_lineendings);
134 break;
138 SaveUndoStep();
140 // use (insert) last block
141 int nViewIndex = nNextViewLine;
142 for (int viewLine = nFirstViewLine; viewLine <= nLastViewLine; viewLine++, nViewIndex++)
144 viewdata lineData = pwndLast->GetViewData(viewLine);
145 lineData.state = ResolveState(lineData.state);
146 InsertViewData(nViewIndex, lineData);
147 if (!IsStateEmpty(pwndLast->GetViewState(viewLine)))
149 pwndLast->SetViewState(viewLine, DIFFSTATE_THEIRSADDED); // this is improper but seems not to produce any visible bug
152 SaveUndoStep();
154 // adjust line numbers in target
155 // we fix all line numbers to handle exotic cases
156 UpdateViewLineNumbers();
157 SaveUndoStep();
159 // now insert an empty block in both first and last
160 int nCount = nLastViewLine - nFirstViewLine + 1;
161 pwndLast->InsertViewEmptyLines(nFirstViewLine, nCount);
162 pwndFirst->InsertViewEmptyLines(nNextViewLine, nCount);
163 SaveUndoStep();
165 int nRemovedLines = CleanEmptyLines();
166 SaveUndoStep();
168 CUndo::GetInstance().EndGrouping();
170 // final clean up
171 ClearSelection();
172 SetupAllViewSelection(nFirstViewLine, 2*nLastViewLine - nFirstViewLine - nRemovedLines + 1);
173 BuildAllScreen2ViewVector();
174 SetModified();
175 RefreshViews();
178 void CBottomView::UseViewBlock(CBaseView * pwndView)
180 if (!IsViewGood(pwndView))
181 return;
182 int nFirstViewLine = 0; // first view line in selection
183 int nLastViewLine = 0; // last view line in selection
185 if (!GetViewSelection(nFirstViewLine, nLastViewLine))
186 return;
188 return UseBlock(pwndView, nFirstViewLine, nLastViewLine);
191 void CBottomView::UseViewFile(CBaseView * pwndView)
193 if (!IsViewGood(pwndView))
194 return;
195 int nFirstViewLine = 0;
196 int nLastViewLine = GetViewCount()-1;
198 return UseBlock(pwndView, nFirstViewLine, nLastViewLine);