Cadabra
Computer algebra system for field theory problems
Loading...
Searching...
No Matches
Actions.hh
Go to the documentation of this file.
1
2#pragma once
3
4#include "DataCell.hh"
5#include "DocumentThread.hh"
6
7#include <memory>
8
9namespace cadabra {
10
11 class DocumentThread;
12 class GUIBase;
13
30
31
32 class ActionBase {
33 public:
35
40
41 virtual void execute(DocumentThread&, GUIBase&);
42
44
45 virtual void revert(DocumentThread&, GUIBase&)=0;
46
48 virtual bool undoable() const;
49
51 protected:
52 DTree::iterator ref;
53 };
54
58
59 class ActionAddCell : public ActionBase {
60 public:
61 enum class Position { before, after, child };
62
64 virtual ~ActionAddCell() {};
65
66 virtual void execute(DocumentThread&, GUIBase&) override;
67 virtual void revert(DocumentThread&, GUIBase&) override;
68
70 virtual bool undoable() const override;
71 private:
72 // Keep track of the location where this cell is inserted into
73 // the notebook.
74
76 DTree::iterator newref;
79
80 // If we are replacing a cell, keep track of that so we
81 // report that we are not undoable.
83 };
84
85
90
92 public:
93 enum class Position { in, next, previous };
94
97
98 virtual void execute(DocumentThread&, GUIBase&) override;
99 virtual void revert(DocumentThread&, GUIBase&) override;
100
101 private:
103 DTree::iterator newref;
105 };
106
110
112 public:
113 ActionSetRunStatus(DataCell::id_t ref_id_, bool running);
115
116 virtual void execute(DocumentThread&, GUIBase&) override;
117 virtual void revert(DocumentThread&, GUIBase&) override;
118
119 virtual bool undoable() const override;
120 private:
121 DTree::iterator this_cell;
123 };
124
125
129
131 public:
133 virtual ~ActionRemoveCell();
134
135 virtual void execute(DocumentThread&, GUIBase&) override;
136 virtual void revert(DocumentThread&, GUIBase&) override;
137
138 private:
139 // Keep track of the location where this cell (and its child
140 // cells) was in the notebook. We keep a reference to the
141 // parent cell and the index of the current cell as child of
142 // that parent.
143
145 DTree::iterator reference_parent_cell;
147 };
148
152
154 public:
156 virtual ~ActionReplaceCell();
157
158 virtual void execute(DocumentThread&, GUIBase&) override;
159 virtual void revert(DocumentThread&, GUIBase&) override;
160
161 virtual bool undoable() const override;
162 private:
163 };
164
168
170 public:
172 virtual ~ActionSplitCell();
173
174 virtual void execute(DocumentThread&, GUIBase&) override;
175 virtual void revert(DocumentThread&, GUIBase&) override;
176
177 private:
178 DTree::iterator newref; // the newly created cell
179 };
180
181
190
192 public:
193 ActionInsertText(DataCell::id_t ref_id, int pos, const std::string&);
194 virtual ~ActionInsertText() {};
195
196 virtual void execute(DocumentThread&, GUIBase&) override;
197 virtual void revert(DocumentThread&, GUIBase&) override;
198
199 private:
200 DTree::iterator this_cell;
202 std::string text;
203 };
204
212
214 public:
215 ActionCompleteText(DataCell::id_t ref_id, int pos, const std::string&, int alternative);
217
218 virtual void execute(DocumentThread&, GUIBase&) override;
219 virtual void revert(DocumentThread&, GUIBase&) override;
220
221 int length() const;
222 int alternative() const;
223
224 private:
225 DTree::iterator this_cell;
227 std::string text;
228 int alternative_; // in case there is more than one completion alternative
229 };
230
239
241 public:
243 virtual ~ActionEraseText() {};
244
245 virtual void execute(DocumentThread&, GUIBase&) override;
246 virtual void revert(DocumentThread&, GUIBase&) override;
247
248 private:
249 DTree::iterator this_cell;
251 std::string removed_text;
252 };
253
254 }
255
256
257//
258// class ActionMergeCells
259
260
261
Add a cell to the notebook.
Definition Actions.hh:59
Position pos
Definition Actions.hh:77
virtual ~ActionAddCell()
Definition Actions.hh:64
int child_num
Definition Actions.hh:78
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition Actions.cc:42
DTree::iterator newref
Definition Actions.hh:76
bool is_replacement
Definition Actions.hh:82
Position
Definition Actions.hh:61
DataCell newcell
Definition Actions.hh:75
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition Actions.cc:79
ActionAddCell(DataCell, DataCell::id_t ref_, Position pos_)
Definition Actions.cc:37
virtual bool undoable() const override
Can this action be undone?
Definition Actions.cc:90
All actions derive from the ActionBase object, which defines the interface they need to implement.
Definition Actions.hh:32
DTree::iterator ref
Definition Actions.hh:52
virtual void execute(DocumentThread &, GUIBase &)
Perform the action.
Definition Actions.cc:23
ActionBase(DataCell::id_t ref_id)
Definition Actions.cc:13
virtual bool undoable() const
Can this action be undone?
Definition Actions.cc:18
DataCell::id_t ref_id
Definition Actions.hh:50
virtual void revert(DocumentThread &, GUIBase &)=0
Revert the change to the DTree document and the GUI.
Complete text at a point in a GUI cell with one or more alternative.
Definition Actions.hh:213
int alternative() const
Definition Actions.cc:343
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition Actions.cc:321
std::string text
Definition Actions.hh:227
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition Actions.cc:331
virtual ~ActionCompleteText()
Definition Actions.hh:216
int alternative_
Definition Actions.hh:228
ActionCompleteText(DataCell::id_t ref_id, int pos, const std::string &, int alternative)
Definition Actions.cc:316
int length() const
Definition Actions.cc:338
DTree::iterator this_cell
Definition Actions.hh:225
int insert_pos
Definition Actions.hh:226
Remove a text string starting at the indicated position, and with the indicated length,...
Definition Actions.hh:240
int to_pos
Definition Actions.hh:250
std::string removed_text
Definition Actions.hh:251
virtual ~ActionEraseText()
Definition Actions.hh:243
int from_pos
Definition Actions.hh:250
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition Actions.cc:353
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition Actions.cc:362
DTree::iterator this_cell
Definition Actions.hh:249
ActionEraseText(DataCell::id_t ref_id, int, int)
Definition Actions.cc:348
Add a text string (can be just a single character) at the point of the cursor.
Definition Actions.hh:191
virtual ~ActionInsertText()
Definition Actions.hh:194
std::string text
Definition Actions.hh:202
ActionInsertText(DataCell::id_t ref_id, int pos, const std::string &)
Definition Actions.cc:296
int insert_pos
Definition Actions.hh:201
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition Actions.cc:309
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition Actions.cc:301
DTree::iterator this_cell
Definition Actions.hh:200
Position the cursor relative to the indicated cell.
Definition Actions.hh:91
virtual ~ActionPositionCursor()
Definition Actions.hh:96
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition Actions.cc:160
ActionPositionCursor(DataCell::id_t ref_id_, Position pos_)
Definition Actions.cc:95
DTree::iterator newref
Definition Actions.hh:103
Position pos
Definition Actions.hh:104
Position
Definition Actions.hh:93
bool needed_new_cell
Definition Actions.hh:102
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition Actions.cc:100
Remove a cell and all its child cells from the document.
Definition Actions.hh:130
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition Actions.cc:192
DTree::iterator reference_parent_cell
Definition Actions.hh:145
size_t reference_child_index
Definition Actions.hh:146
ActionRemoveCell(DataCell::id_t ref_id_)
Definition Actions.cc:170
DTree removed_tree
Definition Actions.hh:144
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition Actions.cc:179
virtual ~ActionRemoveCell()
Definition Actions.cc:175
Replace the contents of a cell.
Definition Actions.hh:153
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition Actions.cc:223
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition Actions.cc:219
ActionReplaceCell(DataCell::id_t ref_id_)
Definition Actions.cc:210
virtual bool undoable() const override
Can this action be undone?
Definition Actions.cc:227
virtual ~ActionReplaceCell()
Definition Actions.cc:215
Update the running status of the indicated cell.
Definition Actions.hh:111
DTree::iterator this_cell
Definition Actions.hh:121
bool was_running_
Definition Actions.hh:122
virtual ~ActionSetRunStatus()
Definition Actions.hh:114
virtual bool undoable() const override
Can this action be undone?
Definition Actions.cc:276
bool new_running_
Definition Actions.hh:122
ActionSetRunStatus(DataCell::id_t ref_id_, bool running)
Definition Actions.cc:271
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition Actions.cc:281
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition Actions.cc:291
Split a cell into two separate cells, at the point of the cursor.
Definition Actions.hh:169
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition Actions.cc:264
ActionSplitCell(DataCell::id_t ref_id)
Definition Actions.cc:232
virtual ~ActionSplitCell()
Definition Actions.cc:237
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition Actions.cc:241
DTree::iterator newref
Definition Actions.hh:178
Each cell is identified by a serial number 'id' which is used to keep track of it across network call...
Definition DataCell.hh:52
DataCells are the basic building blocks for a document.
Definition DataCell.hh:27
A base class with all the logic to manipulate a Cadabra notebook document.
Definition DocumentThread.hh:40
Abstract base class with methods that need to be implemented by any GUI.
Definition GUIBase.hh:16
Functions to handle the exchange properties of two or more symbols in a product.
Definition Adjform.cc:83
tree< DataCell > DTree
Definition DataCell.hh:109