RebaseDlg: Correctly remember commits for rewriting on Squash after (Edit|Squash...
[TortoiseGit.git] / src / TortoiseMerge / ViewData.h
blob6eb1ea853f5912fac72569c0cfd776f9c7766799
1 // TortoiseGitMerge - a Diff/Patch program
3 // Copyright (C) 2023 - TortoiseGit
4 // Copyright (C) 2007-2011, 2013-2014 - TortoiseSVN
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 "DiffStates.h"
22 #include "EOL.h"
24 #include <vector>
26 enum class HideState
28 Shown,
29 Hidden,
30 Marker,
33 /**
34 * \ingroup TortoiseMerge
35 * Holds the information which is required to define a single line of text.
37 class viewdata
39 public:
40 viewdata() = default;
42 viewdata(
43 const CString& sLineInit,
44 DiffState stateInit,
45 int linenumberInit,
46 EOL endingInit,
47 HideState hideInit,
48 bool markedInit = false)
49 : state(stateInit)
50 , linenumber(linenumberInit)
51 , ending(endingInit)
52 , hidestate(hideInit)
53 , marked(markedInit)
54 , sLine(sLineInit)
58 CString sLine;
59 DiffState state = DiffState::Unknown;
60 int linenumber = -1;
61 int movedIndex = -1;
62 bool movedFrom = true;
63 EOL ending = EOL::AutoLine;
64 HideState hidestate = HideState::Hidden;
65 bool marked = false;
68 /**
69 * \ingroup TortoiseMerge
70 * Handles the view and diff data a TortoiseMerge view needs.
72 class CViewData
74 public:
75 CViewData();
76 ~CViewData();
78 void AddData(const CString& sLine, DiffState state, int linenumber, EOL ending, HideState hide, int movedline);
79 void AddData(const viewdata& data);
80 void AddEmpty() {AddData(CString(), DiffState::Empty, -1, EOL::NoEnding, HideState::Shown, -1);}
81 void InsertData(int index, const CString& sLine, DiffState state, int linenumber, EOL ending, HideState hide, int movedline);
82 void InsertData(int index, const viewdata& data);
83 void RemoveData(int index) {m_data.erase(m_data.begin() + index);}
85 const viewdata& GetData(int index) const {return m_data[index];}
86 const CString& GetLine(int index) const {return m_data[index].sLine;}
87 DiffState GetState(int index) const {return m_data[index].state;}
88 HideState GetHideState(int index) const {return m_data[index].hidestate;}
89 int GetLineNumber(int index) const {return m_data.size() ? m_data[index].linenumber : 0;}
90 int GetMovedIndex(int index) const {return m_data.size() ? m_data[index].movedIndex: 0;}
91 bool IsMoved(int index) const {return m_data.size() ? m_data[index].movedIndex >= 0 : false;}
92 bool IsMovedFrom(int index) const {return m_data.size() ? m_data[index].movedFrom : true;}
93 int FindLineNumber(int number) const;
94 EOL GetLineEnding(int index) const {return m_data[index].ending;}
95 bool GetMarked(int index) const {return m_data[index].marked;}
97 int GetCount() const { return static_cast<int>(m_data.size()); }
99 void SetData(int index, const viewdata& data)
101 bool oldmarked = m_data[index].marked;
102 bool marked = data.marked;
103 if (oldmarked && !marked && m_nMarkedBlocks > 0)
104 m_nMarkedBlocks--;
105 else if (!oldmarked && marked)
106 m_nMarkedBlocks++;
107 m_data[index] = data;
109 void SetState(int index, DiffState state) {m_data[index].state = state;}
110 void SetLine(int index, const CString& sLine) {m_data[index].sLine = sLine;}
111 void SetLineNumber(int index, int linenumber) {m_data[index].linenumber = linenumber;}
112 void SetLineEnding(int index, EOL ending) {m_data[index].ending = ending;}
113 void SetMovedIndex(int index, int movedIndex, bool movedFrom) {m_data[index].movedIndex = movedIndex; m_data[index].movedFrom = movedFrom;}
114 void SetLineHideState(int index, HideState state) {m_data[index].hidestate = state;}
115 void SetMarked(int index, bool marked)
117 bool oldmarked = m_data[index].marked;
118 if (oldmarked && !marked && m_nMarkedBlocks > 0)
119 m_nMarkedBlocks--;
120 else if (!oldmarked && marked)
121 m_nMarkedBlocks++;
122 m_data[index].marked = marked;
124 bool HasMarkedBlocks() const { return m_nMarkedBlocks > 0; }
126 void Clear() { m_data.clear(); m_nMarkedBlocks = 0; }
127 void Reserve(int length) {m_data.reserve(length);}
129 protected:
130 std::vector<viewdata> m_data;
131 int m_nMarkedBlocks = 0;