wxMaxima
Loading...
Searching...
No Matches
TreeUndoAction.h
Go to the documentation of this file.
1// -*- mode: c++; c-file-style: "linux"; c-basic-offset: 2; indent-tabs-mode: nil -*-
2//
3// Copyright (C) 2004-2015 Andrej Vodopivec <andrej.vodopivec@gmail.com>
4// (C) 2014-2018 Gunter Königsmann <wxMaxima@physikbuch.de>
5//
6// This program is free software; you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation; either version 2 of the License, or
9// (at your option) any later version.
10//
11// This program is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15//
16//
17// You should have received a copy of the GNU General Public License
18// along with this program; if not, write to the Free Software
19// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20//
21// SPDX-License-Identifier: GPL-2.0+
22
31#ifndef TREEUNDOACTION_H
32#define TREEUNDOACTION_H
33
34#include "cells/CellPtr.h"
35#include "cells/GroupCell.h"
36#include <wx/string.h>
37#include <list>
38#include <memory>
39#include <optional>
40
45{
46public:
47 TreeUndoAction(GroupCell *start, const wxString &oldText,
48 long long oldSelStart = -1, long long oldSelEnd = -1) :
49 m_start(start), m_oldText(oldText),
50 m_oldSelStart(oldSelStart), m_oldSelEnd(oldSelEnd)
51 {
52 wxASSERT_MSG(start, _("Bug: Trying to record a cell contents change for undo without a cell."));
53 }
54 TreeUndoAction(GroupCell *start, GroupCell *end) :
55 m_start(start), m_newCellsEnd(end)
56 {
57 wxASSERT_MSG(start, _("Bug: Trying to record a cell contents change for undo without a cell."));
58 }
59 TreeUndoAction(GroupCell *start, GroupCell *end, GroupCell *oldCells) :
60 m_start(start), m_newCellsEnd(end), m_oldCells(oldCells)
61 {
62 }
63
65 enum class FoldDirection {
66 Folded,
68 };
69
70 TreeUndoAction(GroupCell *start, FoldDirection direction) :
71 m_start(start), m_fold(direction)
72 {
73 wxASSERT_MSG(start, _("Bug: Trying to record a fold/unfold for undo without a cell."));
74 }
75
82
94
100 const wxString m_oldText;
101
108 const long long m_oldSelStart = -1;
109 const long long m_oldSelEnd = -1;
110
121
129 std::unique_ptr<GroupCell> m_oldCells;
130
137 const std::optional<FoldDirection> m_fold;
138};
139
141using UndoActions = std::list<TreeUndoAction>;
142
143#endif // TREEUNDOACTION_H
Implementation of an observing weak Cell pointer.
This file defines the class GroupCell that bundles input and output in the worksheet.
std::list< TreeUndoAction > UndoActions
The type of the list of tree actions that can be undone.
Definition: TreeUndoAction.h:141
A weak non-owning pointer that becomes null whenever the observed object is destroyed.
Definition: CellPtr.h:539
A cell grouping input (and, if there is one, also the output) cell to a foldable item.
Definition: GroupCell.h:88
The description of one action for the undo (or redo) command.
Definition: TreeUndoAction.h:45
const wxString m_oldText
The old contents of the cell start.
Definition: TreeUndoAction.h:100
const std::optional< FoldDirection > m_fold
Set only for fold/unfold actions (see FoldDirection): whether this action folded or unfolded the subt...
Definition: TreeUndoAction.h:137
FoldDirection
Which way a fold/unfold undo action (see m_fold) goes.
Definition: TreeUndoAction.h:65
@ Unfolded
This action unfolded start's subtree; undoing it folds it.
@ Folded
This action folded start's subtree; undoing it unfolds it.
const long long m_oldSelStart
The old cursor/selection range in the EditorCell pointed to by m_start.
Definition: TreeUndoAction.h:108
CellPtr< GroupCell > m_start
The position this action started at.
Definition: TreeUndoAction.h:93
std::unique_ptr< GroupCell > m_oldCells
Cells that were deleted in this action.
Definition: TreeUndoAction.h:129
CellPtr< GroupCell > m_newCellsEnd
This action inserted all cells from start to newCellsEnd.
Definition: TreeUndoAction.h:120
bool m_partOfAtomicAction
True = This undo action is only part of an atomic undo action.
Definition: TreeUndoAction.h:81