Fixed issue #1507: Submodule Diff Dialog should show dirty state only on working...
[TortoiseGit.git] / src / TortoiseMerge / Undo.h
blob2c4b6473ea2bc0bf1dc26b06af3e074eb3d9198b
1 // TortoiseMerge - a Diff/Patch program
3 // Copyright (C) 2006-2007 - 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;
41 void AddLineFormView(CBaseView *pView, int nLine, bool bAddEmptyLine);
42 } viewstate;
44 /**
45 * \ingroup TortoiseMerge
46 * Holds all the information of previous changes made to a view content.
47 * Of course, can undo those changes.
49 class CUndo
51 public:
52 static CUndo& GetInstance();
54 bool Undo(CBaseView * pLeft, CBaseView * pRight, CBaseView * pBottom);
55 void AddState(const viewstate& leftstate, const viewstate& rightstate, const viewstate& bottomstate, POINT pt);
56 bool CanUndo() { return (!m_viewstates.empty()); }
58 bool IsGrouping() { return m_groups.size() % 2 == 1; }
59 void BeginGrouping() { ASSERT(!IsGrouping()); m_groups.push_back(m_caretpoints.size()); }
60 void EndGrouping(){ ASSERT(IsGrouping()); m_groups.push_back(m_caretpoints.size()); }
61 void Clear();
62 void MarkAsOriginalState() { m_originalstate = (unsigned int)m_viewstates.size(); }
63 protected:
64 void Undo(const viewstate& state, CBaseView * pView);
65 void UndoOne(CBaseView * pLeft, CBaseView * pRight, CBaseView * pBottom);
66 std::list<viewstate> m_viewstates;
67 std::list<POINT> m_caretpoints;
68 std::list< std::list<int>::size_type > m_groups;
69 unsigned int m_originalstate;
70 private:
71 CUndo();
72 ~CUndo();