Cadabra
Computer algebra system for field theory problems
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 
9 namespace 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 
50  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 
69  private:
70  // Keep track of the location where this cell is inserted into
71  // the notebook.
72 
74  DTree::iterator newref;
76  int child_num;
77  };
78 
79 
84 
86  public:
87  enum class Position { in, next, previous };
88 
90  virtual ~ActionPositionCursor() {};
91 
92  virtual void execute(DocumentThread&, GUIBase&) override;
93  virtual void revert(DocumentThread&, GUIBase&) override;
94 
95  private:
97  DTree::iterator newref;
99  };
100 
104 
106  public:
107  ActionSetRunStatus(DataCell::id_t ref_id_, bool running);
108  virtual ~ActionSetRunStatus() {};
109 
110  virtual void execute(DocumentThread&, GUIBase&) override;
111  virtual void revert(DocumentThread&, GUIBase&) override;
112 
113  virtual bool undoable() const override;
114  private:
115  DTree::iterator this_cell;
117  };
118 
119 
123 
124  class ActionRemoveCell : public ActionBase {
125  public:
127  virtual ~ActionRemoveCell();
128 
129  virtual void execute(DocumentThread&, GUIBase&) override;
130  virtual void revert(DocumentThread&, GUIBase&) override;
131 
132  private:
133  // Keep track of the location where this cell (and its child
134  // cells) was in the notebook. We keep a reference to the
135  // parent cell and the index of the current cell as child of
136  // that parent.
137 
139  DTree::iterator reference_parent_cell;
141  };
142 
146 
147  class ActionSplitCell : public ActionBase {
148  public:
150  virtual ~ActionSplitCell();
151 
152  virtual void execute(DocumentThread&, GUIBase&) override;
153  virtual void revert(DocumentThread&, GUIBase&) override;
154 
155  private:
156  DTree::iterator newref; // the newly created cell
157  };
158 
159 
168 
169  class ActionInsertText : public ActionBase {
170  public:
171  ActionInsertText(DataCell::id_t ref_id, int pos, const std::string&);
172  virtual ~ActionInsertText() {};
173 
174  virtual void execute(DocumentThread&, GUIBase&) override;
175  virtual void revert(DocumentThread&, GUIBase&) override;
176 
177  private:
178  DTree::iterator this_cell;
180  std::string text;
181  };
182 
191 
192  class ActionEraseText : public ActionBase {
193  public:
195  virtual ~ActionEraseText() {};
196 
197  virtual void execute(DocumentThread&, GUIBase&) override;
198  virtual void revert(DocumentThread&, GUIBase&) override;
199 
200  private:
201  DTree::iterator this_cell;
203  std::string removed_text;
204  };
205 
206  }
207 
208 
209 //
210 // class ActionMergeCells
211 
212 
213 
virtual ~ActionRemoveCell()
Definition: Actions.cc:152
virtual bool undoable() const override
Can this action be undone?
Definition: Actions.cc:231
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition: Actions.cc:246
std::string text
Definition: Actions.hh:180
bool was_running_
Definition: Actions.hh:116
bool new_running_
Definition: Actions.hh:116
Update the running status of the indicated cell.
Definition: Actions.hh:105
Position pos
Definition: Actions.hh:98
DataCells are the basic building blocks for a document.
Definition: DataCell.hh:27
ActionEraseText(DataCell::id_t ref_id, int, int)
Definition: Actions.cc:270
A base class with all the logic to manipulate a Cadabra notebook document.
Definition: DocumentThread.hh:39
Position
Definition: Actions.hh:61
ActionRemoveCell(DataCell::id_t ref_id_)
Definition: Actions.cc:147
All actions derive from the ActionBase object, which defines the interface they need to implement...
Definition: Actions.hh:32
Position pos
Definition: Actions.hh:75
Split a cell into two separate cells, at the point of the cursor.
Definition: Actions.hh:147
virtual ~ActionAddCell()
Definition: Actions.hh:64
bool needed_new_cell
Definition: Actions.hh:96
virtual void execute(DocumentThread &, GUIBase &)
Perform the action.
Definition: Actions.cc:22
virtual bool undoable() const
Can this action be undone?
Definition: Actions.cc:17
DTree removed_tree
Definition: Actions.hh:138
int from_pos
Definition: Actions.hh:202
DTree::iterator ref
Definition: Actions.hh:52
DTree::iterator newref
Definition: Actions.hh:97
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition: Actions.cc:40
ActionBase(DataCell::id_t ref_id)
Definition: Actions.cc:12
DTree::iterator this_cell
Definition: Actions.hh:201
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition: Actions.cc:169
Remove a cell and all its child cells from the document.
Definition: Actions.hh:124
std::string removed_text
Definition: Actions.hh:203
Each cell is identified by a serial number &#39;id&#39; which is used to keep track of it across network call...
Definition: DataCell.hh:51
DTree::iterator this_cell
Definition: Actions.hh:115
Add a text string (can be just a single character) at the point of the cursor.
Definition: Actions.hh:169
virtual void revert(DocumentThread &, GUIBase &)=0
Revert the change to the DTree document and the GUI.
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition: Actions.cc:263
DTree::iterator newref
Definition: Actions.hh:74
virtual ~ActionInsertText()
Definition: Actions.hh:172
Abstract base class with methods that need to be implemented by any GUI.
Definition: GUIBase.hh:16
int child_num
Definition: Actions.hh:76
ActionSplitCell(DataCell::id_t ref_id)
Definition: Actions.cc:187
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition: Actions.cc:77
virtual ~ActionSplitCell()
Definition: Actions.cc:192
Functions to handle the exchange properties of two or more symbols in a product.
Definition: Algorithm.cc:1045
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition: Actions.cc:236
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition: Actions.cc:219
size_t reference_child_index
Definition: Actions.hh:140
virtual ~ActionEraseText()
Definition: Actions.hh:195
ActionPositionCursor(DataCell::id_t ref_id_, Position pos_)
Definition: Actions.cc:72
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition: Actions.cc:284
virtual ~ActionPositionCursor()
Definition: Actions.hh:90
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition: Actions.cc:256
Position the cursor relative to the indicated cell.
Definition: Actions.hh:85
DataCell newcell
Definition: Actions.hh:73
Add a cell to the notebook.
Definition: Actions.hh:59
int to_pos
Definition: Actions.hh:202
DTree::iterator this_cell
Definition: Actions.hh:178
DTree::iterator newref
Definition: Actions.hh:156
int insert_pos
Definition: Actions.hh:179
DataCell::id_t ref_id
Definition: Actions.hh:51
tree< DataCell > DTree
Definition: DataCell.hh:103
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition: Actions.cc:156
virtual ~ActionSetRunStatus()
Definition: Actions.hh:108
ActionSetRunStatus(DataCell::id_t ref_id_, bool running)
Definition: Actions.cc:226
ActionInsertText(DataCell::id_t ref_id, int pos, const std::string &)
Definition: Actions.cc:251
ActionAddCell(DataCell, DataCell::id_t ref_, Position pos_)
Definition: Actions.cc:35
DTree::iterator reference_parent_cell
Definition: Actions.hh:139
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition: Actions.cc:60
Position
Definition: Actions.hh:87
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition: Actions.cc:196
Remove a text string starting at the indicated position, and with the indicated length, from the indicated cell.
Definition: Actions.hh:192
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition: Actions.cc:275
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition: Actions.cc:137