Update editorconfig
[TortoiseGit.git] / src / TortoiseMerge / Undo.h
blobe0443531295044534ec5cf2c4d871cfe2afbd676
1 // TortoiseGitMerge - a Diff/Patch program
3 // Copyright (C) 2006-2007,2009-2015 - 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 class viewstate
33 public:
34 viewstate()
35 : modifies(false)
38 std::map<int, CString> difflines;
39 std::map<int, DWORD> linestates;
40 std::map<int, DWORD> linelines;
41 std::map<int, EOL> linesEOL;
42 std::map<int, bool> markedlines;
43 std::list<int> addedlines;
45 std::map<int, viewdata> removedlines;
46 std::map<int, viewdata> replacedlines;
47 bool modifies; ///< this step modifies view (save before and after save differs)
49 void AddViewLineFromView(CBaseView *pView, int nViewLine, bool bAddEmptyLine);
50 void Clear();
51 bool IsEmpty() const { return difflines.empty() && linestates.empty() && linelines.empty() && linesEOL.empty() && markedlines.empty() && addedlines.empty() && removedlines.empty() && replacedlines.empty(); }
54 /**
55 * \ingroup TortoiseMerge
56 * this struct holds all the information of a single change in TortoiseMerge for all(3) views.
58 struct allviewstate
60 viewstate right;
61 viewstate bottom;
62 viewstate left;
64 void Clear() { right.Clear(); bottom.Clear(); left.Clear(); }
65 bool IsEmpty() const { return right.IsEmpty() && bottom.IsEmpty() && left.IsEmpty(); }
68 /**
69 * \ingroup TortoiseMerge
70 * Holds all the information of previous changes made to a view content.
71 * Of course, can undo those changes.
73 class CUndo
75 public:
76 static CUndo& GetInstance();
78 bool Undo(CBaseView * pLeft, CBaseView * pRight, CBaseView * pBottom);
79 bool Redo(CBaseView * pLeft, CBaseView * pRight, CBaseView * pBottom);
80 void AddState(const allviewstate& allstate, POINT pt);
81 bool CanUndo() const {return !m_viewstates.empty();}
82 bool CanRedo() const { return !m_redoviewstates.empty(); }
84 bool IsGrouping() const { return m_groups.size() % 2 == 1; }
85 bool IsRedoGrouping() const { return m_redogroups.size() % 2 == 1; }
86 void BeginGrouping() { if (m_groupCount==0) m_groups.push_back(m_caretpoints.size()); m_groupCount++; }
87 void EndGrouping(){ m_groupCount--; if (m_groupCount==0) m_groups.push_back(m_caretpoints.size()); }
88 void Clear();
89 void MarkAllAsOriginalState() { MarkAsOriginalState(true, true, true); }
90 void MarkAsOriginalState(bool Left, bool Right, bool Bottom);
91 protected:
92 viewstate Do(const viewstate& state, CBaseView * pView, const POINT& pt);
93 void UndoOne(CBaseView * pLeft, CBaseView * pRight, CBaseView * pBottom);
94 void RedoOne(CBaseView * pLeft, CBaseView * pRight, CBaseView * pBottom);
95 std::list<allviewstate> m_viewstates;
96 std::list<POINT> m_caretpoints;
97 std::list< std::list<int>::size_type > m_groups;
98 size_t m_originalstateLeft;
99 size_t m_originalstateRight;
100 size_t m_originalstateBottom;
101 int m_groupCount;
103 std::list<allviewstate> m_redoviewstates;
104 std::list<POINT> m_redocaretpoints;
105 std::list< std::list<int>::size_type > m_redogroups;
107 private:
108 CUndo();
109 ~CUndo();