Doc: Fix broken link
[TortoiseGit.git] / src / TortoiseMerge / ViewData.h
blob538c79956d67aa913a1c67629e8f9fc4189ca77b
1 // TortoiseGitMerge - a Diff/Patch program
3 // Copyright (C) 2007-2011, 2013-2014 - 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.
19 #pragma once
20 #include "DiffStates.h"
21 #include "EOL.h"
23 #include <vector>
25 enum HIDESTATE
27 HIDESTATE_SHOWN,
28 HIDESTATE_HIDDEN,
29 HIDESTATE_MARKER,
32 /**
33 * \ingroup TortoiseMerge
34 * Holds the information which is required to define a single line of text.
36 class viewdata
38 public:
39 viewdata()
40 : state(DIFFSTATE_UNKNOWN)
41 , linenumber(-1)
42 , movedIndex(-1)
43 , movedFrom(true)
44 , ending(EOL_AUTOLINE)
45 , hidestate(HIDESTATE_HIDDEN)
46 , marked(false)
50 viewdata(
51 const CString& sLineInit,
52 DiffStates stateInit,
53 int linenumberInit,
54 EOL endingInit,
55 HIDESTATE hideInit,
56 bool markedInit = false)
57 : state(stateInit)
58 , linenumber(linenumberInit)
59 , movedIndex(-1)
60 , movedFrom(true)
61 , ending(endingInit)
62 , hidestate(hideInit)
63 , marked(markedInit)
65 sLine=sLineInit;
68 CString sLine;
69 DiffStates state;
70 int linenumber;
71 int movedIndex;
72 bool movedFrom;
73 EOL ending;
74 HIDESTATE hidestate;
75 bool marked;
78 /**
79 * \ingroup TortoiseMerge
80 * Handles the view and diff data a TortoiseMerge view needs.
82 class CViewData
84 public:
85 CViewData(void);
86 ~CViewData(void);
88 void AddData(const CString& sLine, DiffStates state, int linenumber, EOL ending, HIDESTATE hide, int movedline);
89 void AddData(const viewdata& data);
90 void AddEmpty() {AddData(CString(), DIFFSTATE_EMPTY, -1, EOL_NOENDING, HIDESTATE_SHOWN, -1);}
91 void InsertData(int index, const CString& sLine, DiffStates state, int linenumber, EOL ending, HIDESTATE hide, int movedline);
92 void InsertData(int index, const viewdata& data);
93 void RemoveData(int index) {m_data.erase(m_data.begin() + index);}
95 const viewdata& GetData(int index) const {return m_data[index];}
96 const CString& GetLine(int index) const {return m_data[index].sLine;}
97 DiffStates GetState(int index) const {return m_data[index].state;}
98 HIDESTATE GetHideState(int index) const {return m_data[index].hidestate;}
99 int GetLineNumber(int index) const {return m_data.size() ? m_data[index].linenumber : 0;}
100 int GetMovedIndex(int index) const {return m_data.size() ? m_data[index].movedIndex: 0;}
101 bool IsMoved(int index) const {return m_data.size() ? m_data[index].movedIndex >= 0 : false;}
102 bool IsMovedFrom(int index) const {return m_data.size() ? m_data[index].movedFrom : true;}
103 int FindLineNumber(int number) const;
104 EOL GetLineEnding(int index) const {return m_data[index].ending;}
105 bool GetMarked(int index) const {return m_data[index].marked;}
107 int GetCount() const { return (int)m_data.size();}
109 void SetData(int index, const viewdata& data)
111 bool oldmarked = m_data[index].marked;
112 bool marked = data.marked;
113 if (oldmarked && !marked && m_nMarkedBlocks > 0)
114 m_nMarkedBlocks--;
115 else if (!oldmarked && marked)
116 m_nMarkedBlocks++;
117 m_data[index] = data;
119 void SetState(int index, DiffStates state) {m_data[index].state = state;}
120 void SetLine(int index, const CString& sLine) {m_data[index].sLine = sLine;}
121 void SetLineNumber(int index, int linenumber) {m_data[index].linenumber = linenumber;}
122 void SetLineEnding(int index, EOL ending) {m_data[index].ending = ending;}
123 void SetMovedIndex(int index, int movedIndex, bool movedFrom) {m_data[index].movedIndex = movedIndex; m_data[index].movedFrom = movedFrom;}
124 void SetLineHideState(int index, HIDESTATE state) {m_data[index].hidestate = state;}
125 void SetMarked(int index, bool marked)
127 bool oldmarked = m_data[index].marked;
128 if (oldmarked && !marked && m_nMarkedBlocks > 0)
129 m_nMarkedBlocks--;
130 else if (!oldmarked && marked)
131 m_nMarkedBlocks++;
132 m_data[index].marked = marked;
134 bool HasMarkedBlocks() { return m_nMarkedBlocks > 0; }
136 void Clear() { m_data.clear(); m_nMarkedBlocks = 0; }
137 void Reserve(int length) {m_data.reserve(length);}
139 protected:
140 std::vector<viewdata> m_data;
141 int m_nMarkedBlocks;