1 // TortoiseGitMerge - a Diff/Patch program
3 // Copyright (C) 2006-2007, 2010-2011 - 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.
25 void viewstate::AddViewLineFromView(CBaseView
*pView
, int nViewLine
, bool bAddEmptyLine
)
27 // is undo good place for this ?
28 if (!pView
|| !pView
->m_pViewData
)
30 replacedlines
[nViewLine
] = pView
->m_pViewData
->GetData(nViewLine
);
33 addedlines
.push_back(nViewLine
+ 1);
34 pView
->AddEmptyViewLine(nViewLine
);
38 void viewstate::Clear()
47 replacedlines
.clear();
50 CUndo
& CUndo::GetInstance()
52 static CUndo instance
;
66 void CUndo::AddState(const allviewstate
& allstate
, POINT pt
)
68 m_viewstates
.push_back(allstate
);
69 m_caretpoints
.push_back(pt
);
72 bool CUndo::Undo(CBaseView
* pLeft
, CBaseView
* pRight
, CBaseView
* pBottom
)
77 if (m_groups
.size() && m_groups
.back() == m_caretpoints
.size())
80 std::list
<int>::size_type b
= m_groups
.back();
82 while (b
< m_caretpoints
.size())
83 UndoOne(pLeft
, pRight
, pBottom
);
86 UndoOne(pLeft
, pRight
, pBottom
);
88 CBaseView
* pActiveView
= NULL
;
90 if (pBottom
&& pBottom
->IsTarget())
92 pActiveView
= pBottom
;
95 if (pRight
&& pRight
->IsTarget())
100 //if (pLeft && pLeft->IsTarget())
107 pActiveView
->ClearSelection();
108 pActiveView
->BuildAllScreen2ViewVector();
109 pActiveView
->RecalcAllVertScrollBars();
110 pActiveView
->RecalcAllHorzScrollBars();
111 pActiveView
->EnsureCaretVisible();
112 pActiveView
->UpdateCaret();
113 bool bModified
= m_viewstates
.size() != m_originalstate
;
115 pLeft
->SetModified(bModified
);
117 pRight
->SetModified(bModified
);
119 pBottom
->SetModified(bModified
);
120 pActiveView
->RefreshViews();
123 if (m_viewstates
.size() < m_originalstate
)
124 // Can never get back to original state now
125 m_originalstate
= (size_t)-1;
130 void CUndo::UndoOne(CBaseView
* pLeft
, CBaseView
* pRight
, CBaseView
* pBottom
)
132 allviewstate allstate
= m_viewstates
.back();
133 POINT pt
= m_caretpoints
.back();
135 Undo(allstate
.left
, pLeft
, pt
);
136 Undo(allstate
.right
, pRight
, pt
);
137 Undo(allstate
.bottom
, pBottom
, pt
);
139 m_viewstates
.pop_back();
140 m_caretpoints
.pop_back();
143 void CUndo::Undo(const viewstate
& state
, CBaseView
* pView
, const POINT
& pt
)
148 CViewData
* viewData
= pView
->m_pViewData
;
152 for (std::list
<int>::const_reverse_iterator it
= state
.addedlines
.rbegin(); it
!= state
.addedlines
.rend(); ++it
)
154 viewData
->RemoveData(*it
);
156 for (std::map
<int, DWORD
>::const_iterator it
= state
.linelines
.begin(); it
!= state
.linelines
.end(); ++it
)
158 viewData
->SetLineNumber(it
->first
, it
->second
);
160 for (std::map
<int, DWORD
>::const_iterator it
= state
.linestates
.begin(); it
!= state
.linestates
.end(); ++it
)
162 viewData
->SetState(it
->first
, (DiffStates
)it
->second
);
164 for (std::map
<int, EOL
>::const_iterator it
= state
.linesEOL
.begin(); it
!= state
.linesEOL
.end(); ++it
)
166 viewData
->SetLineEnding(it
->first
, (EOL
)it
->second
);
168 for (std::map
<int, CString
>::const_iterator it
= state
.difflines
.begin(); it
!= state
.difflines
.end(); ++it
)
170 viewData
->SetLine(it
->first
, it
->second
);
172 for (std::map
<int, viewdata
>::const_iterator it
= state
.removedlines
.begin(); it
!= state
.removedlines
.end(); ++it
)
174 viewData
->InsertData(it
->first
, it
->second
);
176 for (std::map
<int, viewdata
>::const_iterator it
= state
.replacedlines
.begin(); it
!= state
.replacedlines
.end(); ++it
)
178 viewData
->SetData(it
->first
, it
->second
);
181 if (pView
->IsTarget())
183 pView
->SetCaretViewPosition(pt
);
184 pView
->EnsureCaretVisible();
192 m_viewstates
.clear();
193 m_caretpoints
.clear();