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
44
45 virtual void execute(DocumentThread&, GUIBase&);
46
48
49 virtual void revert(DocumentThread&, GUIBase&)=0;
50
52 virtual bool undoable() const;
53
57
59
62 std::function<void()> callback;
63
64 protected:
65 DTree::iterator ref;
66 };
67
71
72 class ActionAddCell : public ActionBase {
73 public:
74 enum class Position { before, after, child };
75
76 ActionAddCell(DataCell, DataCell::id_t ref_, Position pos_, bool activate=false);
77 virtual ~ActionAddCell() {};
78
79 virtual void execute(DocumentThread&, GUIBase&) override;
80 virtual void revert(DocumentThread&, GUIBase&) override;
81
83 virtual bool undoable() const override;
84 private:
85 // Keep track of the location where this cell is inserted into
86 // the notebook.
87
89 DTree::iterator newref;
93
94 // If we are replacing a cell, keep track of that so we
95 // report that we are not undoable.
97
98 // For input-form cells, we want no undo, as they will go
99 // when the owner cell will be reverted.
101 };
102
103
108
110 public:
111 enum class Position { in, next, previous };
112
115
116 virtual void execute(DocumentThread&, GUIBase&) override;
117 virtual void revert(DocumentThread&, GUIBase&) override;
118
119 private:
121 DTree::iterator newref;
123 };
124
128
130 public:
131 ActionSetRunStatus(DataCell::id_t ref_id_, bool running);
133
134 virtual void execute(DocumentThread&, GUIBase&) override;
135 virtual void revert(DocumentThread&, GUIBase&) override;
136
137 virtual bool undoable() const override;
138 private:
139 DTree::iterator this_cell;
141 };
142
146
148 public:
149 ActionSetVariableList(DataCell::id_t ref_id_, std::set<std::string>);
151
152 virtual void execute(DocumentThread&, GUIBase&) override;
153 virtual void revert(DocumentThread&, GUIBase&) override;
154
155 virtual bool undoable() const override;
156 private:
157 DTree::iterator this_cell;
158 std::set<std::string> new_variables_;
159 };
160
161
165
167 public:
169 virtual ~ActionRemoveCell();
170
171 virtual void execute(DocumentThread&, GUIBase&) override;
172 virtual void revert(DocumentThread&, GUIBase&) override;
173
174 private:
175 // Keep track of the location where this cell (and its child
176 // cells) was in the notebook. We keep a reference to the
177 // parent cell and the index of the current cell as child of
178 // that parent.
179
181 DTree::iterator reference_parent_cell;
183 };
184
188
190 public:
192 virtual ~ActionReplaceCell();
193
194 virtual void execute(DocumentThread&, GUIBase&) override;
195 virtual void revert(DocumentThread&, GUIBase&) override;
196
197 virtual bool undoable() const override;
198 private:
199 };
200
204
206 public:
208 virtual ~ActionSplitCell();
209
210 virtual void execute(DocumentThread&, GUIBase&) override;
211 virtual void revert(DocumentThread&, GUIBase&) override;
212
213 private:
214 DTree::iterator newref; // the newly created cell
215 };
216
217
221
222 class ActionRunCell : public ActionBase {
223 public:
224 // Run a particular cell.
226 // Run all cells.
228
229 virtual ~ActionRunCell();
230
231 virtual void execute(DocumentThread&, GUIBase&) override;
232 virtual void revert(DocumentThread&, GUIBase&) override;
233
234 virtual bool undoable() const override;
235 private:
237 };
238
242
243 class ActionOpen : public ActionBase {
244 public:
245 ActionOpen(const std::string&);
246 virtual ~ActionOpen();
247
248 virtual void execute(DocumentThread&, GUIBase&) override;
249 virtual void revert(DocumentThread&, GUIBase&) override;
250
251 virtual bool undoable() const override;
252 private:
253 std::string notebook_name;
254 };
255
256
265
267 public:
268 ActionInsertText(DataCell::id_t ref_id, int pos, const std::string&);
269 virtual ~ActionInsertText() {};
270
271 virtual void execute(DocumentThread&, GUIBase&) override;
272 virtual void revert(DocumentThread&, GUIBase&) override;
273
274 private:
275 DTree::iterator this_cell;
277 std::string text;
278 };
279
287
289 public:
290 ActionCompleteText(DataCell::id_t ref_id, int pos, const std::string&, int alternative);
292
293 virtual void execute(DocumentThread&, GUIBase&) override;
294 virtual void revert(DocumentThread&, GUIBase&) override;
295
296 int length() const;
297 int alternative() const;
298
299 private:
300 DTree::iterator this_cell;
302 std::string text;
303 int alternative_; // in case there is more than one completion alternative
304 };
305
314
316 public:
318 virtual ~ActionEraseText() {};
319
320 virtual void execute(DocumentThread&, GUIBase&) override;
321 virtual void revert(DocumentThread&, GUIBase&) override;
322
323 private:
324 DTree::iterator this_cell;
326 std::string removed_text;
327 };
328
329 }
330
331
332//
333// class ActionMergeCells
334
335
336
Add a cell to the notebook.
Definition Actions.hh:72
Position pos
Definition Actions.hh:90
virtual ~ActionAddCell()
Definition Actions.hh:77
int child_num
Definition Actions.hh:91
bool activate
Definition Actions.hh:92
bool is_input_form
Definition Actions.hh:100
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition Actions.cc:72
DTree::iterator newref
Definition Actions.hh:89
bool is_replacement
Definition Actions.hh:96
Position
Definition Actions.hh:74
DataCell newcell
Definition Actions.hh:88
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition Actions.cc:121
virtual bool undoable() const override
Can this action be undone?
Definition Actions.cc:149
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:65
DataCell::id_t ref_cell_id() const
The id of the cell this action acted on.
Definition Actions.cc:28
virtual void execute(DocumentThread &, GUIBase &)
Perform the action.
Definition Actions.cc:38
virtual bool undoable() const
Can this action be undone?
Definition Actions.cc:23
std::function< void()> callback
If you want a callback once this action has finished, set it here before queuing.
Definition Actions.hh:62
DataCell::id_t ref_id
Definition Actions.hh:58
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:288
int alternative() const
Definition Actions.cc:502
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition Actions.cc:480
std::string text
Definition Actions.hh:302
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition Actions.cc:490
virtual ~ActionCompleteText()
Definition Actions.hh:291
int alternative_
Definition Actions.hh:303
int length() const
Definition Actions.cc:497
DTree::iterator this_cell
Definition Actions.hh:300
int insert_pos
Definition Actions.hh:301
Remove a text string starting at the indicated position, and with the indicated length,...
Definition Actions.hh:315
int to_pos
Definition Actions.hh:325
std::string removed_text
Definition Actions.hh:326
virtual ~ActionEraseText()
Definition Actions.hh:318
int from_pos
Definition Actions.hh:325
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition Actions.cc:512
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition Actions.cc:521
DTree::iterator this_cell
Definition Actions.hh:324
Add a text string (can be just a single character) at the point of the cursor.
Definition Actions.hh:266
virtual ~ActionInsertText()
Definition Actions.hh:269
std::string text
Definition Actions.hh:277
int insert_pos
Definition Actions.hh:276
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition Actions.cc:467
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition Actions.cc:458
DTree::iterator this_cell
Definition Actions.hh:275
Open a notebook from a file, in the current window.
Definition Actions.hh:243
virtual ~ActionOpen()
Definition Actions.cc:406
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition Actions.cc:426
virtual bool undoable() const override
Can this action be undone?
Definition Actions.cc:410
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition Actions.cc:415
std::string notebook_name
Definition Actions.hh:253
Position the cursor relative to the indicated cell.
Definition Actions.hh:109
virtual ~ActionPositionCursor()
Definition Actions.hh:114
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition Actions.cc:230
DTree::iterator newref
Definition Actions.hh:121
Position pos
Definition Actions.hh:122
Position
Definition Actions.hh:111
uint64_t needed_new_cell_with_id
Definition Actions.hh:120
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition Actions.cc:159
Remove a cell and all its child cells from the document.
Definition Actions.hh:166
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition Actions.cc:262
DTree::iterator reference_parent_cell
Definition Actions.hh:181
size_t reference_child_index
Definition Actions.hh:182
DTree removed_tree
Definition Actions.hh:180
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition Actions.cc:249
virtual ~ActionRemoveCell()
Definition Actions.cc:245
Replace the contents of a cell.
Definition Actions.hh:189
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition Actions.cc:293
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition Actions.cc:289
virtual bool undoable() const override
Can this action be undone?
Definition Actions.cc:297
virtual ~ActionReplaceCell()
Definition Actions.cc:285
Run a cell or run all cells.
Definition Actions.hh:222
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition Actions.cc:385
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition Actions.cc:396
ActionRunCell()
Definition Actions.cc:371
bool run_all_cells
Definition Actions.hh:236
virtual bool undoable() const override
Can this action be undone?
Definition Actions.cc:380
virtual ~ActionRunCell()
Definition Actions.cc:376
Update the running status of the indicated cell.
Definition Actions.hh:129
DTree::iterator this_cell
Definition Actions.hh:139
bool was_running_
Definition Actions.hh:140
virtual ~ActionSetRunStatus()
Definition Actions.hh:132
virtual bool undoable() const override
Can this action be undone?
Definition Actions.cc:346
bool new_running_
Definition Actions.hh:140
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition Actions.cc:351
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition Actions.cc:361
Update the list of referenced variables in this cell.
Definition Actions.hh:147
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition Actions.cc:448
virtual ~ActionSetVariableList()
Definition Actions.hh:150
virtual bool undoable() const override
Can this action be undone?
Definition Actions.cc:436
std::set< std::string > new_variables_
Definition Actions.hh:158
DTree::iterator this_cell
Definition Actions.hh:157
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition Actions.cc:441
Split a cell into two separate cells, at the point of the cursor.
Definition Actions.hh:205
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition Actions.cc:334
virtual ~ActionSplitCell()
Definition Actions.cc:307
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition Actions.cc:311
DTree::iterator newref
Definition Actions.hh:214
Definition DataCell.hh:116
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
void set(rset_t::iterator &num, multiplier_t fac)
Definition Storage.cc:1180