OSDN Git Service

Rewrite patch parser for git created patch.
[tortoisegit/TortoiseGitJp.git] / src / TortoiseMerge / Undo.h
1 // TortoiseMerge - a Diff/Patch program\r
2 \r
3 // Copyright (C) 2006-2007 - TortoiseSVN\r
4 \r
5 // This program is free software; you can redistribute it and/or\r
6 // modify it under the terms of the GNU General Public License\r
7 // as published by the Free Software Foundation; either version 2\r
8 // of the License, or (at your option) any later version.\r
9 \r
10 // This program is distributed in the hope that it will be useful,\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13 // GNU General Public License for more details.\r
14 \r
15 // You should have received a copy of the GNU General Public License\r
16 // along with this program; if not, write to the Free Software Foundation,\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\r
18 //\r
19 #pragma once\r
20 #include "ViewData.h"\r
21 #include <map>\r
22 #include <list>\r
23 \r
24 class CBaseView;\r
25 \r
26 /**\r
27  * \ingroup TortoiseMerge\r
28  * this struct holds all the information of a single change in TortoiseMerge.\r
29  */\r
30 typedef struct viewstate\r
31 {\r
32         std::map<int, CString> difflines;\r
33         std::map<int, DWORD> linestates;\r
34         std::map<int, DWORD> linelines;\r
35         std::list<int> addedlines;\r
36 \r
37         std::map<int, viewdata> removedlines;\r
38 \r
39         void    AddLineFormView(CBaseView *pView, int nLine, bool bAddEmptyLine);\r
40 } viewstate;\r
41 \r
42 /**\r
43  * \ingroup TortoiseMerge\r
44  * Holds all the information of previous changes made to a view content.\r
45  * Of course, can undo those changes.\r
46  */\r
47 class CUndo\r
48 {\r
49 public:\r
50         static CUndo& GetInstance();\r
51 \r
52         bool Undo(CBaseView * pLeft, CBaseView * pRight, CBaseView * pBottom);\r
53         void AddState(const viewstate& leftstate, const viewstate& rightstate, const viewstate& bottomstate, POINT pt);\r
54         bool CanUndo() {return (m_viewstates.size() > 0);}\r
55 \r
56         bool IsGrouping() { return m_groups.size() % 2 == 1; }\r
57         void BeginGrouping() { ASSERT(!IsGrouping()); m_groups.push_back(m_caretpoints.size()); }\r
58         void EndGrouping(){ ASSERT(IsGrouping()); m_groups.push_back(m_caretpoints.size()); }\r
59         void Clear();\r
60         void MarkAsOriginalState() { m_originalstate = m_viewstates.size(); }\r
61 protected:\r
62         void Undo(const viewstate& state, CBaseView * pView);\r
63         void UndoOne(CBaseView * pLeft, CBaseView * pRight, CBaseView * pBottom);\r
64         std::list<viewstate> m_viewstates;\r
65         std::list<POINT> m_caretpoints;\r
66         std::list< std::list<int>::size_type > m_groups;\r
67         unsigned int m_originalstate;\r
68 private:\r
69         CUndo();\r
70         ~CUndo();\r
71 };\r