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 // For input-form cells, we want no undo, as they will go
85 // when the owner cell will be reverted.
87 };
88
89
94
96 public:
97 enum class Position { in, next, previous };
98
101
102 virtual void execute(DocumentThread&, GUIBase&) override;
103 virtual void revert(DocumentThread&, GUIBase&) override;
104
105 private:
107 DTree::iterator newref;
109 };
110
114
116 public:
117 ActionSetRunStatus(DataCell::id_t ref_id_, bool running);
119
120 virtual void execute(DocumentThread&, GUIBase&) override;
121 virtual void revert(DocumentThread&, GUIBase&) override;
122
123 virtual bool undoable() const override;
124 private:
125 DTree::iterator this_cell;
127 };
128
132
134 public:
135 ActionSetVariableList(DataCell::id_t ref_id_, std::set<std::string>);
137
138 virtual void execute(DocumentThread&, GUIBase&) override;
139 virtual void revert(DocumentThread&, GUIBase&) override;
140
141 virtual bool undoable() const override;
142 private:
143 DTree::iterator this_cell;
144 std::set<std::string> new_variables_;
145 };
146
147
151
153 public:
155 virtual ~ActionRemoveCell();
156
157 virtual void execute(DocumentThread&, GUIBase&) override;
158 virtual void revert(DocumentThread&, GUIBase&) override;
159
160 private:
161 // Keep track of the location where this cell (and its child
162 // cells) was in the notebook. We keep a reference to the
163 // parent cell and the index of the current cell as child of
164 // that parent.
165
167 DTree::iterator reference_parent_cell;
169 };
170
174
176 public:
178 virtual ~ActionReplaceCell();
179
180 virtual void execute(DocumentThread&, GUIBase&) override;
181 virtual void revert(DocumentThread&, GUIBase&) override;
182
183 virtual bool undoable() const override;
184 private:
185 };
186
190
192 public:
194 virtual ~ActionSplitCell();
195
196 virtual void execute(DocumentThread&, GUIBase&) override;
197 virtual void revert(DocumentThread&, GUIBase&) override;
198
199 private:
200 DTree::iterator newref; // the newly created cell
201 };
202
203
212
214 public:
215 ActionInsertText(DataCell::id_t ref_id, int pos, const std::string&);
216 virtual ~ActionInsertText() {};
217
218 virtual void execute(DocumentThread&, GUIBase&) override;
219 virtual void revert(DocumentThread&, GUIBase&) override;
220
221 private:
222 DTree::iterator this_cell;
224 std::string text;
225 };
226
234
236 public:
237 ActionCompleteText(DataCell::id_t ref_id, int pos, const std::string&, int alternative);
239
240 virtual void execute(DocumentThread&, GUIBase&) override;
241 virtual void revert(DocumentThread&, GUIBase&) override;
242
243 int length() const;
244 int alternative() const;
245
246 private:
247 DTree::iterator this_cell;
249 std::string text;
250 int alternative_; // in case there is more than one completion alternative
251 };
252
261
263 public:
265 virtual ~ActionEraseText() {};
266
267 virtual void execute(DocumentThread&, GUIBase&) override;
268 virtual void revert(DocumentThread&, GUIBase&) override;
269
270 private:
271 DTree::iterator this_cell;
273 std::string removed_text;
274 };
275
276 }
277
278
279//
280// class ActionMergeCells
281
282
283
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
bool is_input_form
Definition Actions.hh:86
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition Actions.cc:46
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:93
virtual bool undoable() const override
Can this action be undone?
Definition Actions.cc:121
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:27
virtual bool undoable() const
Can this action be undone?
Definition Actions.cc:22
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:235
int alternative() const
Definition Actions.cc:408
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition Actions.cc:386
std::string text
Definition Actions.hh:249
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition Actions.cc:396
virtual ~ActionCompleteText()
Definition Actions.hh:238
int alternative_
Definition Actions.hh:250
int length() const
Definition Actions.cc:403
DTree::iterator this_cell
Definition Actions.hh:247
int insert_pos
Definition Actions.hh:248
Remove a text string starting at the indicated position, and with the indicated length,...
Definition Actions.hh:262
int to_pos
Definition Actions.hh:272
std::string removed_text
Definition Actions.hh:273
virtual ~ActionEraseText()
Definition Actions.hh:265
int from_pos
Definition Actions.hh:272
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition Actions.cc:418
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition Actions.cc:427
DTree::iterator this_cell
Definition Actions.hh:271
Add a text string (can be just a single character) at the point of the cursor.
Definition Actions.hh:213
virtual ~ActionInsertText()
Definition Actions.hh:216
std::string text
Definition Actions.hh:224
int insert_pos
Definition Actions.hh:223
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition Actions.cc:373
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition Actions.cc:364
DTree::iterator this_cell
Definition Actions.hh:222
Position the cursor relative to the indicated cell.
Definition Actions.hh:95
virtual ~ActionPositionCursor()
Definition Actions.hh:100
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition Actions.cc:202
DTree::iterator newref
Definition Actions.hh:107
Position pos
Definition Actions.hh:108
Position
Definition Actions.hh:97
uint64_t needed_new_cell_with_id
Definition Actions.hh:106
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition Actions.cc:131
Remove a cell and all its child cells from the document.
Definition Actions.hh:152
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition Actions.cc:234
DTree::iterator reference_parent_cell
Definition Actions.hh:167
size_t reference_child_index
Definition Actions.hh:168
DTree removed_tree
Definition Actions.hh:166
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition Actions.cc:221
virtual ~ActionRemoveCell()
Definition Actions.cc:217
Replace the contents of a cell.
Definition Actions.hh:175
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition Actions.cc:265
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition Actions.cc:261
virtual bool undoable() const override
Can this action be undone?
Definition Actions.cc:269
virtual ~ActionReplaceCell()
Definition Actions.cc:257
Update the running status of the indicated cell.
Definition Actions.hh:115
DTree::iterator this_cell
Definition Actions.hh:125
bool was_running_
Definition Actions.hh:126
virtual ~ActionSetRunStatus()
Definition Actions.hh:118
virtual bool undoable() const override
Can this action be undone?
Definition Actions.cc:318
bool new_running_
Definition Actions.hh:126
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition Actions.cc:323
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition Actions.cc:333
Update the list of referenced variables in this cell.
Definition Actions.hh:133
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition Actions.cc:354
virtual ~ActionSetVariableList()
Definition Actions.hh:136
virtual bool undoable() const override
Can this action be undone?
Definition Actions.cc:342
std::set< std::string > new_variables_
Definition Actions.hh:144
DTree::iterator this_cell
Definition Actions.hh:143
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition Actions.cc:347
Split a cell into two separate cells, at the point of the cursor.
Definition Actions.hh:191
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition Actions.cc:306
virtual ~ActionSplitCell()
Definition Actions.cc:279
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition Actions.cc:283
DTree::iterator newref
Definition Actions.hh:200
Each cell is identified by a serial number 'id' which is used to keep track of it across network call...
Definition DataCell.hh:53
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:41
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:116
void set(rset_t::iterator &num, multiplier_t fac)
Definition Storage.cc:1064