wxMaxima
Loading...
Searching...
No Matches
WorksheetDocument.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) 2026 Gunter Königsmann <wxMaxima@physikbuch.de>
4//
5// This program is free software; you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation; either version 2 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15//
16// You should have received a copy of the GNU General Public License
17// along with this program; if not, write to the Free Software
18// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19//
20// SPDX-License-Identifier: GPL-2.0+
21
41#ifndef WORKSHEETDOCUMENT_H
42#define WORKSHEETDOCUMENT_H
43
44#include "CellPointers.h"
45#include "EvaluationQueue.h"
46#include "TreeUndoManager.h"
47#include "WorksheetCursor.h"
48#include "cells/CellPtr.h"
49#include "cells/GroupCell.h"
50#include <memory>
51#include <wx/string.h>
52
54
61public:
63 EvaluationQueue &GetEvaluationQueue() { return m_evaluationQueue; }
65 const EvaluationQueue &GetEvaluationQueue() const { return m_evaluationQueue; }
66
68 TreeUndoManager &GetTreeUndo() { return m_treeUndo; }
70 const TreeUndoManager &GetTreeUndo() const { return m_treeUndo; }
71
73 WorksheetCursor &GetCursor() { return m_hCaret; }
75 const WorksheetCursor &GetCursor() const { return m_hCaret; }
76
78 GroupCell *GetTree() const { return m_tree.get(); }
86 std::unique_ptr<GroupCell> &TreeOwner() { return m_tree; }
92 CellPtr<GroupCell> &LastCache() const { return m_last; }
93
95 void SetDocumentView(WorksheetDocumentView *view) { m_view = view; }
96
98 GroupCell *GetLastCell() const;
99
101 void NumberSections() const;
102
111 GroupCell *InsertCells(std::unique_ptr<GroupCell> &&cells, GroupCell *where);
112
114 const wxString &GetCurrentFile() const { return m_currentFile; }
116 void SetCurrentFile(const wxString &file) { m_currentFile = file; }
117
119 const wxString &GetLastQuestion() const { return m_lastQuestion; }
121 void SetLastQuestion(const wxString &lastQuestion) {
122 m_lastQuestion = lastQuestion;
123 }
124
126 bool QuestionPending() const { return m_questionPrompt; }
128 void SetQuestionPending(bool pending) { m_questionPrompt = pending; }
129
132 DocumentCellPointers &GetCellPointers() { return m_cellPointers; }
134 const DocumentCellPointers &GetCellPointers() const { return m_cellPointers; }
135
137 bool IsSaved() const { return m_saved; }
145 void SetSaved(bool saved);
153 if (m_currentFile.EndsWith(wxS(".wxmx")))
154 m_saved = false;
155 }
156
157private:
159 EvaluationQueue m_evaluationQueue;
161 TreeUndoManager m_treeUndo;
163 WorksheetCursor m_hCaret;
166 std::unique_ptr<GroupCell> m_tree;
168 mutable CellPtr<GroupCell> m_last;
170 WorksheetDocumentView *m_view = nullptr;
172 wxString m_currentFile;
174 wxString m_lastQuestion;
176 bool m_questionPrompt = false;
178 bool m_saved = true;
180 DocumentCellPointers m_cellPointers;
181};
182
183#endif // WORKSHEETDOCUMENT_H
Implementation of an observing weak Cell pointer.
The evaluation queue.
This file defines the class GroupCell that bundles input and output in the worksheet.
Declares TreeUndoManager: the owner of the cell-tree undo/redo state.
The worksheet's "between the cells" cursor (the horizontally drawn caret).
A weak non-owning pointer that becomes null whenever the observed object is destroyed.
Definition: CellPtr.h:511
The document-model half of the cell-pointer registry.
Definition: CellPointers.h:50
A simple FIFO queue with manual removal of elements.
Definition: EvaluationQueue.h:43
A cell grouping input (and, if there is one, also the output) cell to a foldable item.
Definition: GroupCell.h:87
Owns the cell-tree undo/redo stacks and the active-cell snapshot.
Definition: TreeUndoManager.h:51
The between-the-cells cursor: active flag, position, selection anchors.
Definition: WorksheetCursor.h:49
The view notifications a WorksheetDocument emits when it edits itself.
Definition: WorksheetDocumentView.h:50
The view-independent state and commands of an edited worksheet document.
Definition: WorksheetDocument.h:60
CellPtr< GroupCell > & LastCache() const
The cached pointer to the document's last GroupCell (<0 = unknown).
Definition: WorksheetDocument.h:92
const WorksheetCursor & GetCursor() const
The between-cells cursor (read-only view).
Definition: WorksheetDocument.h:75
void SetSaved(bool saved)
Record whether the document is in its saved state.
Definition: WorksheetDocument.cpp:33
bool QuestionPending() const
Is Maxima currently waiting for an answer to a question?
Definition: WorksheetDocument.h:126
GroupCell * GetLastCell() const
The document's last GroupCell, memoised in m_last (null if empty).
Definition: WorksheetDocument.cpp:41
bool IsSaved() const
True while the document has no unsaved changes.
Definition: WorksheetDocument.h:137
void SetCurrentFile(const wxString &file)
Record the file this document is associated with.
Definition: WorksheetDocument.h:116
EvaluationQueue & GetEvaluationQueue()
The list of cells scheduled to be sent to Maxima for evaluation.
Definition: WorksheetDocument.h:63
DocumentCellPointers & GetCellPointers()
The document-model half of the cell-pointer registry (selection, the active/answer/current-text cell,...
Definition: WorksheetDocument.h:132
GroupCell * InsertCells(std::unique_ptr< GroupCell > &&cells, GroupCell *where)
Insert a list of group cells into the document after where.
Definition: WorksheetDocument.cpp:58
const TreeUndoManager & GetTreeUndo() const
The document's tree-edit undo/redo history (read-only view).
Definition: WorksheetDocument.h:70
void NumberSections() const
Renumber all sectioning cells (titles, sections, ...) from the top.
Definition: WorksheetDocument.cpp:51
TreeUndoManager & GetTreeUndo()
The document's undo/redo history of tree-structure edits.
Definition: WorksheetDocument.h:68
const EvaluationQueue & GetEvaluationQueue() const
The list of cells scheduled for evaluation (read-only view).
Definition: WorksheetDocument.h:65
const wxString & GetCurrentFile() const
The file this document was last loaded from / saved to (empty if none).
Definition: WorksheetDocument.h:114
void SetDocumentView(WorksheetDocumentView *view)
Register the view the document notifies when it edits its own structure.
Definition: WorksheetDocument.h:95
std::unique_ptr< GroupCell > & TreeOwner()
Mutable access to the owning pointer of the cell tree.
Definition: WorksheetDocument.h:86
const wxString & GetLastQuestion() const
The text of the Maxima question the user is currently being asked.
Definition: WorksheetDocument.h:119
void SetQuestionPending(bool pending)
Record whether Maxima is waiting for an answer to a question.
Definition: WorksheetDocument.h:128
WorksheetCursor & GetCursor()
The between-cells cursor (the h-caret) and its group-level selection.
Definition: WorksheetDocument.h:73
GroupCell * GetTree() const
The first GroupCell of the document (null when the document is empty).
Definition: WorksheetDocument.h:78
void SetLastQuestion(const wxString &lastQuestion)
Remember the text of the question Maxima is currently asking.
Definition: WorksheetDocument.h:121
void OutputChanged()
Note that a cell's output changed.
Definition: WorksheetDocument.h:152
const DocumentCellPointers & GetCellPointers() const
The document-model half of the cell-pointer registry (read-only view).
Definition: WorksheetDocument.h:134