wxMaxima
Loading...
Searching...
No Matches
Public Types | Public Member Functions
WorksheetDocument Class Reference

The view-independent state and commands of an edited worksheet document. More...

#include <WorksheetDocument.h>

Public Types

enum class  TextUndoResult { CellGone , NoOpSkipped , Applied }
 What UndoTextChange() did with the action it was given. More...
 

Public Member Functions

EvaluationQueueGetEvaluationQueue ()
 The list of cells scheduled to be sent to Maxima for evaluation.
 
const EvaluationQueueGetEvaluationQueue () const
 The list of cells scheduled for evaluation (read-only view).
 
TreeUndoManagerGetTreeUndo ()
 The document's undo/redo history of tree-structure edits.
 
const TreeUndoManagerGetTreeUndo () const
 The document's tree-edit undo/redo history (read-only view).
 
WorksheetCursorGetCursor ()
 The between-cells cursor (the h-caret) and its group-level selection.
 
const WorksheetCursorGetCursor () const
 The between-cells cursor (read-only view).
 
GroupCellGetTree () const
 The first GroupCell of the document (null when the document is empty).
 
std::unique_ptr< GroupCell > & TreeOwner ()
 Mutable access to the owning pointer of the cell tree.
 
CellPtr< GroupCell > & LastCache () const
 The cached pointer to the document's last GroupCell (<0 = unknown).
 
void SetDocumentView (WorksheetDocumentView *view)
 Register the view the document notifies when it edits its own structure.
 
bool CanApplyTreeAction (const UndoActions &actions) const
 Can the tree-undo/redo at the front of the given stack be applied now?
 
TextUndoResult UndoTextChange (const TreeUndoAction &action, UndoActions *undoForThisOperation)
 Apply a pending text-change undo/redo action.
 
GroupCellGetLastCell () const
 The document's last GroupCell, memoised in m_last (null if empty).
 
void NumberSections () const
 Renumber all sectioning cells (titles, sections, ...) from the top.
 
GroupCellFold (GroupCell *which)
 Fold which; see GroupCell::Fold().
 
GroupCellUnfold (GroupCell *which)
 Unfold which; see GroupCell::Unfold(). Mirrors Fold().
 
GroupCellToggleFold (GroupCell *which)
 Fold or unfold which, whichever it currently isn't; see GroupCell::Fold()/Unfold().
 
GroupCellToggleFoldAll (GroupCell *which)
 Like ToggleFold(), but folds/unfolds which's whole subtree.
 
void FoldAll ()
 Recursively folds every foldable cell in the document.
 
void UnfoldAll ()
 Recursively unfolds every folded cell in the document.
 
bool CanEdit () const
 Is exactly one cell selected, and does it directly follow Maxima's own input prompt (as opposed to being e.g. a text or section cell)?
 
bool CanDeleteSelection () const
 Can the current selection be deleted right now (see CanRemoveCells())?
 
bool CanMergeSelection () const
 Can the current selection (of more than one cell) be merged into one?
 
bool IsSelected (CellType type) const
 Is the selection exactly one cell of the given type?
 
bool IsSelectionInWorkingGroup () const
 Is the selection start inside the group Maxima is currently evaluating?
 
bool CanUndoInsideCell () const
 Can the active cell's own (intra-cell) undo be invoked right now?
 
bool CanRedoInsideCell () const
 Can the active cell's own (intra-cell) redo be invoked right now?
 
GroupCellInsertCells (std::unique_ptr< GroupCell > &&cells, GroupCell *where)
 Insert a list of group cells into the document after where.
 
bool CanRemoveCells (GroupCell *start, const GroupCell *end) const
 Can the range [start,end] (inclusive) be safely removed from the tree?
 
std::unique_ptr< GroupCellRemoveCells (GroupCell *start, GroupCell *end)
 Remove the range [start,end] (inclusive) from the tree.
 
const wxString & GetCurrentFile () const
 The file this document was last loaded from / saved to (empty if none).
 
void SetCurrentFile (const wxString &file)
 Record the file this document is associated with.
 
const wxString & GetLastQuestion () const
 The text of the Maxima question the user is currently being asked.
 
void SetLastQuestion (const wxString &lastQuestion)
 Remember the text of the question Maxima is currently asking.
 
bool QuestionPending () const
 Is Maxima currently waiting for an answer to a question?
 
void SetQuestionPending (bool pending)
 Record whether Maxima is waiting for an answer to a question.
 
DocumentCellPointersGetCellPointers ()
 The document-model half of the cell-pointer registry (selection, the active/answer/current-text cell, working group and error list).
 
const DocumentCellPointersGetCellPointers () const
 The document-model half of the cell-pointer registry (read-only view).
 
bool IsSaved () const
 True while the document has no unsaved changes.
 
void SetSaved (bool saved)
 Record whether the document is in its saved state.
 
void OutputChanged ()
 Note that a cell's output changed.
 

Detailed Description

The view-independent state and commands of an edited worksheet document.

Currently a small aggregate that Worksheet delegates to; it grows as further document state is migrated off Worksheet. Held by value by Worksheet.

Member Enumeration Documentation

◆ TextUndoResult

What UndoTextChange() did with the action it was given.

Enumerator
CellGone 

The cell no longer exists; the caller should drop the action.

NoOpSkipped 

The cell's text already matched the target state (a later, since reverted edit reproduced it); nothing to apply, try the next action.

Applied 

The cell's text/selection were reverted to the recorded old state.

Member Function Documentation

◆ CanRemoveCells()

bool WorksheetDocument::CanRemoveCells ( GroupCell start,
const GroupCell end 
) const

Can the range [start,end] (inclusive) be safely removed from the tree?

Refuses if either end is null, or if the range contains the cell Maxima is currently evaluating.

◆ Fold()

GroupCell * WorksheetDocument::Fold ( GroupCell which)

Fold which; see GroupCell::Fold().

Returns the cell if it was actually folded, null if which is null, not foldable, or already folded. Records an undo action (GH #266) and clears the redo list; the caller still has to schedule a recalculation - every existing caller already does.

◆ InsertCells()

GroupCell * WorksheetDocument::InsertCells ( std::unique_ptr< GroupCell > &&  cells,
GroupCell where 
)

Insert a list of group cells into the document after where.

where == null inserts at the very top. Splices the cells into the tree, renumbers sections if needed and notifies the view (recalc/redraw/adjust size/modified) through the registered WorksheetDocumentView. Returns the last inserted cell. The caller (Worksheet) records the undo action, which needs a Configuration and so stays on the view side.

◆ LastCache()

CellPtr< GroupCell > & WorksheetDocument::LastCache ( ) const
inline

The cached pointer to the document's last GroupCell (<0 = unknown).

Mutable so the const "find the last cell" lookup can memoise its result; the surgery code also updates it directly when it reseats the tail.

◆ OutputChanged()

void WorksheetDocument::OutputChanged ( )
inline

Note that a cell's output changed.

For a .wxmx (which caches output on disk) changed output means the file is no longer saved. Sets the flag directly, without a control refresh, to match the historical behaviour: this is called often during evaluation and must stay cheap.

◆ RemoveCells()

std::unique_ptr< GroupCell > WorksheetDocument::RemoveCells ( GroupCell start,
GroupCell end 
)

Remove the range [start,end] (inclusive) from the tree.

Pure structural surgery plus the document-side bookkeeping it implies: dequeues the removed cells from the evaluation queue, clears their cached output bitmaps, splices them out of the tree, renumbers sections if a foldable or image cell left, and notifies the view (recalc/redraw/ modified) through the registered WorksheetDocumentView. Returns the removed cells (still linked to each other) so the caller can push them onto its undo buffer, or null if start / end don't form a removable range (see CanRemoveCells()). The caller (Worksheet) still handles the cursor/selection housekeeping around the deletion (moving the cursor to a sane place before cells vanish out from under it) and the layout-position refresh, both view concerns.

◆ SetSaved()

void WorksheetDocument::SetSaved ( bool  saved)

Record whether the document is in its saved state.

On an actual change of the flag the view is told via WorksheetDocumentView::NotifySavedStateChanged() so it can refresh the controls that depend on the saved-state. Defined in the .cpp because it needs the complete WorksheetDocumentView type.

◆ ToggleFold()

GroupCell * WorksheetDocument::ToggleFold ( GroupCell which)

Fold or unfold which, whichever it currently isn't; see GroupCell::Fold()/Unfold().

Returns the cell if something actually changed, null if which is null or not foldable. The caller still has to schedule a recalculation - every existing caller already does.

◆ TreeOwner()

std::unique_ptr< GroupCell > & WorksheetDocument::TreeOwner ( )
inline

Mutable access to the owning pointer of the cell tree.

Transitional: while the tree-editing surgery still lives in Worksheet, it reseats the head of the list (moves a new tree in, resets it, splices), so it needs the unique_ptr itself, not just GetTree(). Moves onto WorksheetDocument with the tree-surgery methods in a later increment.

◆ UndoTextChange()

WorksheetDocument::TextUndoResult WorksheetDocument::UndoTextChange ( const TreeUndoAction action,
UndoActions undoForThisOperation 
)

Apply a pending text-change undo/redo action.

Pure part of Worksheet::TreeUndoTextChange(): checks the target cell is still part of the tree, detects a no-op (the text to restore is already there), records the cell's CURRENT state into undoForThisOperation (so this undo can itself be redone) and reverts the cell's text/selection to the recorded old state. The caller still has to move the cursor to the affected cell and schedule its recalculation/redraw on Applied, or retry the next action on NoOpSkipped - both view/cursor concerns.


The documentation for this class was generated from the following files: