Fix compilation warnings
[TortoiseGit.git] / src / TortoiseMerge / Undo.h
blob7fc7b86f85a71aaaa678f90f684b5017887a8667
1 // TortoiseGitMerge - a Diff/Patch program
3 // Copyright (C) 2006-2007,2009-2012 - TortoiseSVN
4 // Copyright (C) 2011 Sven Strickroth <email@cs-ware.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #pragma once
21 #include "ViewData.h"
22 #include <map>
23 #include <list>
25 class CBaseView;
27 /**
28 * \ingroup TortoiseMerge
29 * this struct holds all the information of a single change in TortoiseMerge.
31 typedef struct viewstate
33 std::map<int, CString> difflines;
34 std::map<int, DWORD> linestates;
35 std::map<int, DWORD> linelines;
36 std::map<int, EOL> linesEOL;
37 std::list<int> addedlines;
39 std::map<int, viewdata> removedlines;
40 std::map<int, viewdata> replacedlines;
42 void AddViewLineFromView(CBaseView *pView, int nViewLine, bool bAddEmptyLine);
43 void Clear();
44 bool IsEmpty() { return difflines.empty() && linestates.empty() && linelines.empty() && linesEOL.empty() && addedlines.empty() && removedlines.empty() && replacedlines.empty(); }
45 } viewstate;
47 /**
48 * \ingroup TortoiseMerge
49 * this struct holds all the information of a single change in TortoiseMerge for all(3) views.
51 struct allviewstate
53 viewstate right;
54 viewstate bottom;
55 viewstate left;
57 void Clear() { right.Clear(); bottom.Clear(); left.Clear(); }
58 bool IsEmpty() { return right.IsEmpty() && bottom.IsEmpty() && left.IsEmpty(); }
61 /**
62 * \ingroup TortoiseMerge
63 * Holds all the information of previous changes made to a view content.
64 * Of course, can undo those changes.
66 class CUndo
68 public:
69 static CUndo& GetInstance();
71 bool Undo(CBaseView * pLeft, CBaseView * pRight, CBaseView * pBottom);
72 void AddState(const allviewstate& allstate, POINT pt);
73 bool CanUndo() {return !m_viewstates.empty();}
75 bool IsGrouping() { return m_groups.size() % 2 == 1; }
76 void BeginGrouping() { if (m_groupCount==0) m_groups.push_back(m_caretpoints.size()); m_groupCount++; }
77 void EndGrouping(){ m_groupCount--; if (m_groupCount==0) m_groups.push_back(m_caretpoints.size()); }
78 void Clear();
79 void MarkAsOriginalState() { m_originalstate = m_viewstates.size(); }
80 protected:
81 void Undo(const viewstate& state, CBaseView * pView, const POINT& pt);
82 void UndoOne(CBaseView * pLeft, CBaseView * pRight, CBaseView * pBottom);
83 std::list<allviewstate> m_viewstates;
84 std::list<POINT> m_caretpoints;
85 std::list< std::list<int>::size_type > m_groups;
86 size_t m_originalstate;
87 int m_groupCount;
88 private:
89 CUndo();
90 ~CUndo();