Cadabra
Computer algebra system for field theory problems
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Actions.hh
Go to the documentation of this file.
1 
2 #pragma once
3 
4 // All modifications to the document are done by calling 'perform' with an
5 // action object. This enables us to implement an undo stack. This method
6 // will take care of making the actual change to the DTree document, and
7 // call back on the 'change' methods above to inform the derived class
8 // that a change has been made.
9 
10 #include "DataCell.hh"
11 #include "DocumentThread.hh"
12 
13 #include <memory>
14 
15 namespace cadabra {
16 
17  class DocumentThread;
18  class GUIBase;
19 
30 
31 
32  class ActionBase {
33  public:
38 
39  virtual void execute(DocumentThread&, GUIBase&)=0;
40 
42 
43  virtual void revert(DocumentThread&, GUIBase&)=0;
44 
46  virtual bool undoable() const;
47  };
48 
52 
53  class ActionAddCell : public ActionBase {
54  public:
55  enum class Position { before, after, child };
56 
57  ActionAddCell(DataCell, DTree::iterator ref_, Position pos_);
58 
59  virtual void execute(DocumentThread&, GUIBase&) override;
60  virtual void revert(DocumentThread&, GUIBase&) override;
61 
62  private:
63  // Keep track of the location where this cell is inserted into
64  // the notebook.
65 
67  DTree::iterator ref, newref;
69  int child_num;
70  };
71 
72 
77 
79  public:
80  enum class Position { in, next, previous };
81 
82  ActionPositionCursor(DTree::iterator ref_, Position pos_);
83 
84  virtual void execute(DocumentThread&, GUIBase&) override;
85  virtual void revert(DocumentThread&, GUIBase&) override;
86 
87  private:
89  DTree::iterator ref, newref;
91  };
92 
96 
97  class ActionSetRunStatus : public ActionBase {
98  public:
99  ActionSetRunStatus(DTree::iterator ref_, bool running);
100 
101  virtual void execute(DocumentThread&, GUIBase&) override;
102  virtual void revert(DocumentThread&, GUIBase&) override;
103 
104  virtual bool undoable() const override;
105  private:
106  DTree::iterator this_cell;
108  };
109 
110 
114 
115  class ActionRemoveCell : public ActionBase {
116  public:
117  ActionRemoveCell(DTree::iterator ref_);
119 
120  virtual void execute(DocumentThread&, GUIBase&) override;
121  virtual void revert(DocumentThread&, GUIBase&) override;
122 
123  private:
124  // Keep track of the location where this cell (and its child
125  // cells) was in the notebook. We keep a reference to the
126  // parent cell and the index of the current cell as child of
127  // that parent.
128 
132  };
133 
137 
138  class ActionSplitCell : public ActionBase {
139  public:
140  ActionSplitCell(DTree::iterator ref_);
142 
143  virtual void execute(DocumentThread&, GUIBase&) override;
144  virtual void revert(DocumentThread&, GUIBase&) override;
145 
146  private:
147  DTree::iterator this_cell, newref; // the newly created cell
148  };
149 
150 
159 
160  class ActionInsertText : public ActionBase {
161  public:
162  ActionInsertText(DTree::iterator, int pos, const std::string&);
163 
164  virtual void execute(DocumentThread&, GUIBase&) override;
165  virtual void revert(DocumentThread&, GUIBase&) override;
166 
167  private:
168  DTree::iterator this_cell;
170  std::string text;
171  };
172 
181 
182  class ActionEraseText : public ActionBase {
183  public:
184  ActionEraseText(DTree::iterator, int, int);
185 
186  virtual void execute(DocumentThread&, GUIBase&) override;
187  virtual void revert(DocumentThread&, GUIBase&) override;
188 
189  private:
190  DTree::iterator this_cell;
192  std::string removed_text;
193  };
194 
195 }
196 
197 
198 //
199 // class ActionMergeCells
200 
201 
202 
~ActionRemoveCell()
Definition: Actions.cc:138
virtual bool undoable() const override
Can this action be undone?
Definition: Actions.cc:214
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition: Actions.cc:227
std::string text
Definition: Actions.hh:170
bool was_running_
Definition: Actions.hh:107
bool new_running_
Definition: Actions.hh:107
Update the running status of the indicated cell.
Definition: Actions.hh:97
ActionPositionCursor(DTree::iterator ref_, Position pos_)
Definition: Actions.cc:56
Position pos
Definition: Actions.hh:90
DataCells are the basic building blocks for a document.
Definition: DataCell.hh:27
virtual void execute(DocumentThread &, GUIBase &)=0
Perform the action.
A base class with all the logic to manipulate a Cadabra notebook document.
Definition: DocumentThread.hh:38
Position
Definition: Actions.hh:55
ActionSetRunStatus(DTree::iterator ref_, bool running)
Definition: Actions.cc:209
ActionAddCell(DataCell, DTree::iterator ref_, Position pos_)
Definition: Actions.cc:17
All actions derive from the ActionBase object, which defines the interface they need to implement...
Definition: Actions.hh:32
Position pos
Definition: Actions.hh:68
Split a cell into two separate cells, at the point of the cursor.
Definition: Actions.hh:138
virtual bool undoable() const
Can this action be undone?
Definition: Actions.cc:12
bool needed_new_cell
Definition: Actions.hh:88
DTree removed_tree
Definition: Actions.hh:129
int from_pos
Definition: Actions.hh:191
DTree::iterator newref
Definition: Actions.hh:89
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition: Actions.cc:22
DTree::iterator this_cell
Definition: Actions.hh:190
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition: Actions.cc:152
Remove a cell and all its child cells from the document.
Definition: Actions.hh:115
DTree::iterator ref
Definition: Actions.hh:67
std::string removed_text
Definition: Actions.hh:192
DTree::iterator this_cell
Definition: Actions.hh:106
Add a text string (can be just a single character) at the point of the cursor.
Definition: Actions.hh:160
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:242
DTree::iterator newref
Definition: Actions.hh:67
Abstract base class with methods that need to be implemented by any GUI.
Definition: GUIBase.hh:16
int child_num
Definition: Actions.hh:69
ActionInsertText(DTree::iterator, int pos, const std::string &)
Definition: Actions.cc:232
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition: Actions.cc:61
~ActionSplitCell()
Definition: Actions.cc:175
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition: Actions.cc:219
ActionSplitCell(DTree::iterator ref_)
Definition: Actions.cc:170
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition: Actions.cc:202
size_t reference_child_index
Definition: Actions.hh:131
DTree::iterator this_cell
Definition: Actions.hh:147
DTree::iterator this_cell
Definition: Actions.hh:130
DTree::iterator ref
Definition: Actions.hh:89
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition: Actions.cc:261
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition: Actions.cc:237
Position the cursor relative to the indicated cell.
Definition: Actions.hh:78
ActionRemoveCell(DTree::iterator ref_)
Definition: Actions.cc:133
DataCell newcell
Definition: Actions.hh:66
Add a cell to the notebook.
Definition: Actions.hh:53
int to_pos
Definition: Actions.hh:191
DTree::iterator this_cell
Definition: Actions.hh:168
DTree::iterator newref
Definition: Actions.hh:147
int insert_pos
Definition: Actions.hh:169
tree< DataCell > DTree
Definition: DataCell.hh:105
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition: Actions.cc:142
DTree::iterator reference_parent_cell
Definition: Actions.hh:130
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition: Actions.cc:44
Position
Definition: Actions.hh:80
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition: Actions.cc:179
Remove a text string starting at the indicated position, and with the indicated length, from the indicated cell.
Definition: Actions.hh:182
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition: Actions.cc:254
ActionEraseText(DTree::iterator, int, int)
Definition: Actions.cc:249
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition: Actions.cc:123