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
55
58 std::function<void()> callback;
59
60 protected:
61 DTree::iterator ref;
62 };
63
67
68 class ActionAddCell : public ActionBase {
69 public:
70 enum class Position { before, after, child };
71
72 ActionAddCell(DataCell, DataCell::id_t ref_, Position pos_, bool activate=false);
73 virtual ~ActionAddCell() {};
74
75 virtual void execute(DocumentThread&, GUIBase&) override;
76 virtual void revert(DocumentThread&, GUIBase&) override;
77
79 virtual bool undoable() const override;
80 private:
81 // Keep track of the location where this cell is inserted into
82 // the notebook.
83
85 DTree::iterator newref;
89
90 // If we are replacing a cell, keep track of that so we
91 // report that we are not undoable.
93
94 // For input-form cells, we want no undo, as they will go
95 // when the owner cell will be reverted.
97 };
98
99
104
106 public:
107 enum class Position { in, next, previous };
108
111
112 virtual void execute(DocumentThread&, GUIBase&) override;
113 virtual void revert(DocumentThread&, GUIBase&) override;
114
115 private:
117 DTree::iterator newref;
119 };
120
124
126 public:
127 ActionSetRunStatus(DataCell::id_t ref_id_, bool running);
129
130 virtual void execute(DocumentThread&, GUIBase&) override;
131 virtual void revert(DocumentThread&, GUIBase&) override;
132
133 virtual bool undoable() const override;
134 private:
135 DTree::iterator this_cell;
137 };
138
142
144 public:
145 ActionSetVariableList(DataCell::id_t ref_id_, std::set<std::string>);
147
148 virtual void execute(DocumentThread&, GUIBase&) override;
149 virtual void revert(DocumentThread&, GUIBase&) override;
150
151 virtual bool undoable() const override;
152 private:
153 DTree::iterator this_cell;
154 std::set<std::string> new_variables_;
155 };
156
157
161
163 public:
165 virtual ~ActionRemoveCell();
166
167 virtual void execute(DocumentThread&, GUIBase&) override;
168 virtual void revert(DocumentThread&, GUIBase&) override;
169
170 private:
171 // Keep track of the location where this cell (and its child
172 // cells) was in the notebook. We keep a reference to the
173 // parent cell and the index of the current cell as child of
174 // that parent.
175
177 DTree::iterator reference_parent_cell;
179 };
180
184
186 public:
188 virtual ~ActionReplaceCell();
189
190 virtual void execute(DocumentThread&, GUIBase&) override;
191 virtual void revert(DocumentThread&, GUIBase&) override;
192
193 virtual bool undoable() const override;
194 private:
195 };
196
200
202 public:
204 virtual ~ActionSplitCell();
205
206 virtual void execute(DocumentThread&, GUIBase&) override;
207 virtual void revert(DocumentThread&, GUIBase&) override;
208
209 private:
210 DTree::iterator newref; // the newly created cell
211 };
212
213
217
218 class ActionRunCell : public ActionBase {
219 public:
220 // Run a particular cell.
222 // Run all cells.
224
225 virtual ~ActionRunCell();
226
227 virtual void execute(DocumentThread&, GUIBase&) override;
228 virtual void revert(DocumentThread&, GUIBase&) override;
229
230 virtual bool undoable() const override;
231 private:
233 };
234
238
239 class ActionOpen : public ActionBase {
240 public:
241 ActionOpen(const std::string&);
242 virtual ~ActionOpen();
243
244 virtual void execute(DocumentThread&, GUIBase&) override;
245 virtual void revert(DocumentThread&, GUIBase&) override;
246
247 virtual bool undoable() const override;
248 private:
249 std::string notebook_name;
250 };
251
252
261
263 public:
264 ActionInsertText(DataCell::id_t ref_id, int pos, const std::string&);
265 virtual ~ActionInsertText() {};
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 text;
274 };
275
283
285 public:
286 ActionCompleteText(DataCell::id_t ref_id, int pos, const std::string&, int alternative);
288
289 virtual void execute(DocumentThread&, GUIBase&) override;
290 virtual void revert(DocumentThread&, GUIBase&) override;
291
292 int length() const;
293 int alternative() const;
294
295 private:
296 DTree::iterator this_cell;
298 std::string text;
299 int alternative_; // in case there is more than one completion alternative
300 };
301
310
312 public:
314 virtual ~ActionEraseText() {};
315
316 virtual void execute(DocumentThread&, GUIBase&) override;
317 virtual void revert(DocumentThread&, GUIBase&) override;
318
319 private:
320 DTree::iterator this_cell;
322 std::string removed_text;
323 };
324
325 }
326
327
328//
329// class ActionMergeCells
330
331
332
Add a cell to the notebook.
Definition Actions.hh:68
Position pos
Definition Actions.hh:86
virtual ~ActionAddCell()
Definition Actions.hh:73
int child_num
Definition Actions.hh:87
bool activate
Definition Actions.hh:88
bool is_input_form
Definition Actions.hh:96
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition Actions.cc:62
DTree::iterator newref
Definition Actions.hh:85
bool is_replacement
Definition Actions.hh:92
Position
Definition Actions.hh:70
DataCell newcell
Definition Actions.hh:84
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition Actions.cc:111
virtual bool undoable() const override
Can this action be undone?
Definition Actions.cc:139
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:61
virtual void execute(DocumentThread &, GUIBase &)
Perform the action.
Definition Actions.cc:28
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:58
DataCell::id_t ref_id
Definition Actions.hh:54
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:284
int alternative() const
Definition Actions.cc:492
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition Actions.cc:470
std::string text
Definition Actions.hh:298
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition Actions.cc:480
virtual ~ActionCompleteText()
Definition Actions.hh:287
int alternative_
Definition Actions.hh:299
int length() const
Definition Actions.cc:487
DTree::iterator this_cell
Definition Actions.hh:296
int insert_pos
Definition Actions.hh:297
Remove a text string starting at the indicated position, and with the indicated length,...
Definition Actions.hh:311
int to_pos
Definition Actions.hh:321
std::string removed_text
Definition Actions.hh:322
virtual ~ActionEraseText()
Definition Actions.hh:314
int from_pos
Definition Actions.hh:321
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition Actions.cc:502
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition Actions.cc:511
DTree::iterator this_cell
Definition Actions.hh:320
Add a text string (can be just a single character) at the point of the cursor.
Definition Actions.hh:262
virtual ~ActionInsertText()
Definition Actions.hh:265
std::string text
Definition Actions.hh:273
int insert_pos
Definition Actions.hh:272
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition Actions.cc:457
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition Actions.cc:448
DTree::iterator this_cell
Definition Actions.hh:271
Open a notebook from a file, in the current window.
Definition Actions.hh:239
virtual ~ActionOpen()
Definition Actions.cc:396
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition Actions.cc:416
virtual bool undoable() const override
Can this action be undone?
Definition Actions.cc:400
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition Actions.cc:405
std::string notebook_name
Definition Actions.hh:249
Position the cursor relative to the indicated cell.
Definition Actions.hh:105
virtual ~ActionPositionCursor()
Definition Actions.hh:110
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition Actions.cc:220
DTree::iterator newref
Definition Actions.hh:117
Position pos
Definition Actions.hh:118
Position
Definition Actions.hh:107
uint64_t needed_new_cell_with_id
Definition Actions.hh:116
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition Actions.cc:149
Remove a cell and all its child cells from the document.
Definition Actions.hh:162
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition Actions.cc:252
DTree::iterator reference_parent_cell
Definition Actions.hh:177
size_t reference_child_index
Definition Actions.hh:178
DTree removed_tree
Definition Actions.hh:176
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition Actions.cc:239
virtual ~ActionRemoveCell()
Definition Actions.cc:235
Replace the contents of a cell.
Definition Actions.hh:185
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition Actions.cc:283
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition Actions.cc:279
virtual bool undoable() const override
Can this action be undone?
Definition Actions.cc:287
virtual ~ActionReplaceCell()
Definition Actions.cc:275
Run a cell or run all cells.
Definition Actions.hh:218
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition Actions.cc:375
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition Actions.cc:386
ActionRunCell()
Definition Actions.cc:361
bool run_all_cells
Definition Actions.hh:232
virtual bool undoable() const override
Can this action be undone?
Definition Actions.cc:370
virtual ~ActionRunCell()
Definition Actions.cc:366
Update the running status of the indicated cell.
Definition Actions.hh:125
DTree::iterator this_cell
Definition Actions.hh:135
bool was_running_
Definition Actions.hh:136
virtual ~ActionSetRunStatus()
Definition Actions.hh:128
virtual bool undoable() const override
Can this action be undone?
Definition Actions.cc:336
bool new_running_
Definition Actions.hh:136
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition Actions.cc:341
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition Actions.cc:351
Update the list of referenced variables in this cell.
Definition Actions.hh:143
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition Actions.cc:438
virtual ~ActionSetVariableList()
Definition Actions.hh:146
virtual bool undoable() const override
Can this action be undone?
Definition Actions.cc:426
std::set< std::string > new_variables_
Definition Actions.hh:154
DTree::iterator this_cell
Definition Actions.hh:153
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition Actions.cc:431
Split a cell into two separate cells, at the point of the cursor.
Definition Actions.hh:201
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition Actions.cc:324
virtual ~ActionSplitCell()
Definition Actions.cc:297
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition Actions.cc:301
DTree::iterator newref
Definition Actions.hh:210
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:1179