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:
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 
65  virtual void execute(DocumentThread&, GUIBase&) override;
66  virtual void revert(DocumentThread&, GUIBase&) override;
67 
68  private:
69  // Keep track of the location where this cell is inserted into
70  // the notebook.
71 
73  DTree::iterator newref;
75  int child_num;
76  };
77 
78 
83 
85  public:
86  enum class Position { in, next, previous };
87 
89 
90  virtual void execute(DocumentThread&, GUIBase&) override;
91  virtual void revert(DocumentThread&, GUIBase&) override;
92 
93  private:
95  DTree::iterator newref;
97  };
98 
102 
104  public:
105  ActionSetRunStatus(DataCell::id_t ref_id_, bool running);
106 
107  virtual void execute(DocumentThread&, GUIBase&) override;
108  virtual void revert(DocumentThread&, GUIBase&) override;
109 
110  virtual bool undoable() const override;
111  private:
112  DTree::iterator this_cell;
114  };
115 
116 
120 
121  class ActionRemoveCell : public ActionBase {
122  public:
125 
126  virtual void execute(DocumentThread&, GUIBase&) override;
127  virtual void revert(DocumentThread&, GUIBase&) override;
128 
129  private:
130  // Keep track of the location where this cell (and its child
131  // cells) was in the notebook. We keep a reference to the
132  // parent cell and the index of the current cell as child of
133  // that parent.
134 
136  DTree::iterator reference_parent_cell;
138  };
139 
143 
144  class ActionSplitCell : public ActionBase {
145  public:
148 
149  virtual void execute(DocumentThread&, GUIBase&) override;
150  virtual void revert(DocumentThread&, GUIBase&) override;
151 
152  private:
153  DTree::iterator newref; // the newly created cell
154  };
155 
156 
165 
166  class ActionInsertText : public ActionBase {
167  public:
168  ActionInsertText(DataCell::id_t ref_id, int pos, const std::string&);
169 
170  virtual void execute(DocumentThread&, GUIBase&) override;
171  virtual void revert(DocumentThread&, GUIBase&) override;
172 
173  private:
174  DTree::iterator this_cell;
176  std::string text;
177  };
178 
187 
188  class ActionEraseText : public ActionBase {
189  public:
191 
192  virtual void execute(DocumentThread&, GUIBase&) override;
193  virtual void revert(DocumentThread&, GUIBase&) override;
194 
195  private:
196  DTree::iterator this_cell;
198  std::string removed_text;
199  };
200 
201 }
202 
203 
204 //
205 // class ActionMergeCells
206 
207 
208 
~ActionRemoveCell()
Definition: Actions.cc:152
virtual bool undoable() const override
Can this action be undone?
Definition: Actions.cc:230
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition: Actions.cc:245
std::string text
Definition: Actions.hh:176
bool was_running_
Definition: Actions.hh:113
bool new_running_
Definition: Actions.hh:113
Update the running status of the indicated cell.
Definition: Actions.hh:103
Position pos
Definition: Actions.hh:96
DataCells are the basic building blocks for a document.
Definition: DataCell.hh:27
ActionEraseText(DataCell::id_t ref_id, int, int)
Definition: Actions.cc:269
A base class with all the logic to manipulate a Cadabra notebook document.
Definition: DocumentThread.hh:38
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:74
Split a cell into two separate cells, at the point of the cursor.
Definition: Actions.hh:144
virtual bool undoable() const
Can this action be undone?
Definition: Actions.cc:17
bool needed_new_cell
Definition: Actions.hh:94
virtual void execute(DocumentThread &, GUIBase &)
Perform the action.
Definition: Actions.cc:22
DTree removed_tree
Definition: Actions.hh:135
int from_pos
Definition: Actions.hh:197
DTree::iterator ref
Definition: Actions.hh:52
DTree::iterator newref
Definition: Actions.hh:95
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:196
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition: Actions.cc:168
Remove a cell and all its child cells from the document.
Definition: Actions.hh:121
std::string removed_text
Definition: Actions.hh:198
Each cell is identified by a serial number 'id' which is used to keep track of it across network call...
Definition: DataCell.hh:51
DTree::iterator this_cell
Definition: Actions.hh:112
Add a text string (can be just a single character) at the point of the cursor.
Definition: Actions.hh:166
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:262
DTree::iterator newref
Definition: Actions.hh:73
Abstract base class with methods that need to be implemented by any GUI.
Definition: GUIBase.hh:16
int child_num
Definition: Actions.hh:75
ActionSplitCell(DataCell::id_t ref_id)
Definition: Actions.cc:186
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition: Actions.cc:77
~ActionSplitCell()
Definition: Actions.cc:191
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition: Actions.cc:235
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition: Actions.cc:218
size_t reference_child_index
Definition: Actions.hh:137
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:283
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition: Actions.cc:255
Position the cursor relative to the indicated cell.
Definition: Actions.hh:84
DataCell newcell
Definition: Actions.hh:72
Add a cell to the notebook.
Definition: Actions.hh:59
int to_pos
Definition: Actions.hh:197
DTree::iterator this_cell
Definition: Actions.hh:174
DTree::iterator newref
Definition: Actions.hh:153
int insert_pos
Definition: Actions.hh:175
DataCell::id_t ref_id
Definition: Actions.hh:51
tree< DataCell > DTree
Definition: DataCell.hh:106
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition: Actions.cc:156
ActionSetRunStatus(DataCell::id_t ref_id_, bool running)
Definition: Actions.cc:225
ActionInsertText(DataCell::id_t ref_id, int pos, const std::string &)
Definition: Actions.cc:250
ActionAddCell(DataCell, DataCell::id_t ref_, Position pos_)
Definition: Actions.cc:35
DTree::iterator reference_parent_cell
Definition: Actions.hh:136
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition: Actions.cc:60
Position
Definition: Actions.hh:86
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition: Actions.cc:195
Remove a text string starting at the indicated position, and with the indicated length, from the indicated cell.
Definition: Actions.hh:188
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition: Actions.cc:274
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition: Actions.cc:137