Donner 0.8.0-pre
Embeddable browser-grade SVG2 engine
Loading...
Searching...
No Matches
donner::editor::EditorApp Class Reference

Top-level editor shell. More...

#include "donner/editor/EditorApp.h"

Classes

struct  CompletedTransformWriteback
 Payload describing a completed DOM-side transform mutation that needs to be spliced into the source text. target is a stable path-based reference captured while the source was still in sync with the DOM; transform is the local (parent-space) transform that should appear in the element's transform= attribute. More...
struct  CompletedElementRemoveWriteback

Public Member Functions

 EditorApp (const EditorApp &)=delete
EditorApp & operator= (const EditorApp &)=delete
 EditorApp (EditorApp &&)=delete
EditorApp & operator= (EditorApp &&)=delete
bool loadFromString (std::string_view svgBytes)
 Load an SVG document from a string. Replaces any current document and clears the current selection. Returns true on parse success.
bool hasDocument () const
 Whether a document has been loaded.
AsyncSVGDocumentdocument ()
 Direct access to the wrapped AsyncSVGDocument. Used by the main loop for flushFrame() and currentFrameVersion(), and by tests.
const AsyncSVGDocumentdocument () const
const std::optional< std::string > & currentFilePath () const
 The file path this document was loaded from, or std::nullopt if it was created from scratch. Populated by the main loop via setCurrentFilePath after a successful File → Open / argv load.
void setCurrentFilePath (std::string path)
 Set the path associated with the current document. Called by the main loop when a file is loaded. Clears the dirty flag.
bool isDirty () const
 Whether the document has unsaved changes. Set automatically on every mutation via applyMutation; cleared by setCurrentFilePath / markClean.
void markClean ()
 Mark the document as clean (e.g. after a successful save).
void markDirty ()
 Mark the document as dirty. The main loop calls this when the user types in the source pane, since text-pane edits don't go through applyMutation.
void setCleanSourceText (std::string_view sourceText)
 Record the current source text as the "clean" baseline. Used after loading or saving a document so later source edits can determine whether the in-memory text has diverged from the last persisted bytes.
std::string_view cleanSourceText () const
 The last source text known to be in sync with the DOM.
bool revertToCleanSource ()
 Reload the last clean source baseline and clear transient document state.
void syncDirtyFromSource (std::string_view currentSourceText)
 Recompute the dirty flag from the current source text. This allows the editor to clear the dirty indicator when the user undoes or edits back to the last clean baseline.
void applyMutation (EditorCommand command)
 The single entry point for editor-initiated DOM writes. Tools and the text pane both flow through here. Pushes the command onto the document's command queue; nothing is applied until flushFrame().
void restoreSelectionAfterNextDocumentReplace (std::vector< AttributeWritebackTarget > targets)
 Restore these selection targets after the next source-backed document replacement.
bool flushFrame ()
 Drain and apply any pending mutations. Called once per frame at the start of the main loop. Returns true if any commands were applied.
bool deleteSelectionWithUndo (std::string_view currentSourceText)
 Delete the current selection and record a source-level undo entry.
const std::vector< svg::SVGElement > & selectedElements () const
 All currently-selected elements, in selection order. Empty when nothing is selected. Multi-element selections come from shift+click and marquee-drag (Milestone 4 of the editor UX design doc).
const std::optional< svg::SVGElement > & selectedElement () const
 Single-element accessor for back-compat with single-select call sites (overlay chrome, source-pane highlight, drag writeback, inspector, etc.). Returns the first selected element, or std::nullopt if nothing is selected. Cached so the const optional& reference stays stable across calls.
bool hasSelection () const
 Whether anything is selected.
void setSelection (std::optional< svg::SVGElement > element)
 Replace the current selection with a single element. Pass std::nullopt to clear.
void setSelection (std::vector< svg::SVGElement > elements)
 Replace the current selection with the given list. Use this for marquee-resolved multi-selects.
void toggleInSelection (const svg::SVGElement &element)
 Add element to the current selection if it isn't already selected; remove it if it is. The natural Shift+click handler.
void addToSelection (const svg::SVGElement &element)
 Append element to the current selection without disturbing existing entries. No-op if element is already selected.
bool setAttributeOnSelection (std::string_view attrName, std::string_view attrValue)
 Queue an attribute write for every selected element.
bool setStylePropertyOnSelection (std::string_view propertyName, std::string_view propertyValue)
 Merge a single CSS declaration into each selected element's style attribute.
bool setStrokeWidthOnSelection (double strokeWidth)
 Queue a stroke-width style-property write for every selected element.
const ActivePaintStyleactivePaintStyle () const
 Active paint settings used by path-authoring tools for newly-created elements.
void setActiveFill (std::string_view fill)
 Set the active fill attribute for newly-created elements.
void setActiveStroke (std::string_view stroke)
 Set the active stroke attribute for newly-created elements.
void setActiveStrokeWidth (double strokeWidth)
 Set the active stroke width for newly-created elements.
void clearSelection ()
 Drop every entry from the selection. Equivalent to setSelection(std::nullopt) but reads better at clear sites.
PathOperationAvailability pathOperationAvailability (PathOperationKind operation) const
 Return whether a path operation is available for the current selection.
bool applyPathOperation (PathOperationKind operation)
 Queue a destructive path operation over the current selection.
PathOperationAvailability compoundPathUnbundleAvailability (std::optional< svg::SVGElement > target=std::nullopt) const
 Return whether a compound path can be unbundled into separate path elements.
bool unbundleCompoundPath (std::optional< svg::SVGElement > target=std::nullopt)
 Queue an unbundle operation for one compound path.
std::optional< svg::SVGGeometryElementhitTest (const Vector2d &documentPoint)
 Find the topmost geometry element at the given document-space point, or std::nullopt if no element is hit. Coordinates are in the SVG canvas space (the same space as the root <svg> viewBox).
std::vector< svg::SVGGeometryElementhitTestRect (const Box2d &documentRect)
 Find every geometry element whose painted shape intersects documentRect. Used by marquee selection. Returns elements in document order (root-to-leaf depth-first), so callers that care about z-order can rely on a stable sequence.
UndoTimelineundoTimeline ()
 Access the underlying UndoTimeline. Tools record begin/commit transactions on it directly; EditorApp::undo() below is the canonical way to apply undo entries because it routes them through the command queue so the mutation seam is preserved.
const UndoTimelineundoTimeline () const
bool canUndo () const
 Whether there is an entry to undo.
bool canRedo () const
 Whether the most recently undone entry can be redone.
void undo ()
 Undo the most recent entry. Pops the timeline's next entry and pushes the restored transform onto the command queue as a SetTransformCommand — the actual DOM mutation happens on the next flushFrame(), keeping every DOM write on the same path. No-op if there is nothing to undo.
void redo ()
 Redo the most recently undone entry.
void setStructuredEditingEnabled (bool enabled)
 Enable or disable the structured-editing incremental path (M5). When enabled, text edits that land inside a known attribute value dispatch to SetAttributeCommand instead of ReplaceDocumentCommand, preserving tree identity. Defaults to true; the flag remains as a runtime escape hatch while the structured-editing rollout settles.
bool structuredEditingEnabled () const
 Whether the structured-editing incremental path is active.
void enqueueTransformWriteback (CompletedTransformWriteback writeback)
 Queue a transform writeback that main.cc will splice into the source on its next applyPendingTransformWriteback() call. SelectTool calls this when a drag completes; undo() / redo() call it so undoing a canvas drag restores both the DOM transform and the source text in lock-step. Multiple entries are preserved so grouped multi-selection undo/redo updates every participant.
std::optional< CompletedTransformWritebackconsumeTransformWriteback ()
 Drain the oldest queued transform writeback, if any.
std::vector< CompletedTransformWritebackconsumeTransformWritebacks ()
 Drain all queued transform writebacks. Called once per frame by DocumentSyncController.
void enqueueElementRemoveWriteback (CompletedElementRemoveWriteback writeback)
 Queue an element-removal writeback that main.cc will splice into the source on its next drain.
std::vector< CompletedElementRemoveWritebackconsumeElementRemoveWritebacks ()
 Drain any queued element-removal writebacks.

Detailed Description

Top-level editor shell.

Lifetime: typically one per window. All public methods are UI-thread only.


Class Documentation

◆ donner::editor::EditorApp::CompletedTransformWriteback

struct donner::editor::EditorApp::CompletedTransformWriteback

Payload describing a completed DOM-side transform mutation that needs to be spliced into the source text. target is a stable path-based reference captured while the source was still in sync with the DOM; transform is the local (parent-space) transform that should appear in the element's transform= attribute.

Collaboration diagram for donner::editor::EditorApp::CompletedTransformWriteback:
[legend]
Class Members
bool restoreSourceTransformAttributeValue = false
optional< RcString > sourceTransformAttributeValue
AttributeWritebackTarget target
Transform2d transform

◆ donner::editor::EditorApp::CompletedElementRemoveWriteback

struct donner::editor::EditorApp::CompletedElementRemoveWriteback
Collaboration diagram for donner::editor::EditorApp::CompletedElementRemoveWriteback:
[legend]
Class Members
AttributeWritebackTarget target

Member Function Documentation

◆ applyPathOperation()

bool donner::editor::EditorApp::applyPathOperation ( PathOperationKind operation)

Queue a destructive path operation over the current selection.

Inputs are sorted by SVG paint order before dispatching to PathOps so selection click order cannot change Subtract Front / Subtract Back semantics. The result is rejected if the operation is over the editor's complexity limits or produces geometry outside the selected inputs' union bounds.

Parameters
operationOperation to apply.
Returns
true if commands were queued.

◆ compoundPathUnbundleAvailability()

PathOperationAvailability donner::editor::EditorApp::compoundPathUnbundleAvailability ( std::optional< svg::SVGElement > target = std::nullopt) const
nodiscard

Return whether a compound path can be unbundled into separate path elements.

If target is provided, availability is checked for that element. Otherwise the current single-element selection is used.

Parameters
targetOptional explicit path element to inspect.
Returns
Availability and a user-facing disabled reason.

◆ deleteSelectionWithUndo()

bool donner::editor::EditorApp::deleteSelectionWithUndo ( std::string_view currentSourceText)

Delete the current selection and record a source-level undo entry.

Parameters
currentSourceTextThe source-pane text that is in sync with the current document.
Returns
true if there was a selection to delete.

◆ pathOperationAvailability()

PathOperationAvailability donner::editor::EditorApp::pathOperationAvailability ( PathOperationKind operation) const
nodiscard

Return whether a path operation is available for the current selection.

Parameters
operationOperation to test.
Returns
Availability and a user-facing disabled reason.

◆ redo()

void donner::editor::EditorApp::redo ( )

Redo the most recently undone entry.

Like undo(), the restored transform is routed through the command queue so the mutation seam is preserved. No-op unless the most recent timeline action was an undo.

◆ setActiveFill()

void donner::editor::EditorApp::setActiveFill ( std::string_view fill)
inline

Set the active fill attribute for newly-created elements.

Parameters
fillSVG fill attribute value.

◆ setActiveStroke()

void donner::editor::EditorApp::setActiveStroke ( std::string_view stroke)
inline

Set the active stroke attribute for newly-created elements.

Parameters
strokeSVG stroke attribute value.

◆ setActiveStrokeWidth()

void donner::editor::EditorApp::setActiveStrokeWidth ( double strokeWidth)

Set the active stroke width for newly-created elements.

Parameters
strokeWidthStroke width in user units. Negative values clamp to zero.

◆ setAttributeOnSelection()

bool donner::editor::EditorApp::setAttributeOnSelection ( std::string_view attrName,
std::string_view attrValue )

Queue an attribute write for every selected element.

Parameters
attrNameAttribute name to set, e.g. "fill".
attrValueAttribute value to write.
Returns
true if commands were queued.

◆ setStrokeWidthOnSelection()

bool donner::editor::EditorApp::setStrokeWidthOnSelection ( double strokeWidth)

Queue a stroke-width style-property write for every selected element.

Parameters
strokeWidthStroke width in user units. Negative values clamp to zero.
Returns
true if commands were queued.

◆ setStylePropertyOnSelection()

bool donner::editor::EditorApp::setStylePropertyOnSelection ( std::string_view propertyName,
std::string_view propertyValue )

Merge a single CSS declaration into each selected element's style attribute.

Parameters
propertyNameCSS property name, e.g. "fill".
propertyValueCSS property value, e.g. "#112233".
Returns
true if commands were queued.

◆ unbundleCompoundPath()

bool donner::editor::EditorApp::unbundleCompoundPath ( std::optional< svg::SVGElement > target = std::nullopt)

Queue an unbundle operation for one compound path.

The source path is split into one path per contour, including hole/counter contours such as the center of a letter D. New path elements inherit the original path's non-geometry attributes except id, and the original path is removed after the replacement paths are inserted at the same paint-order position.

Parameters
targetOptional explicit path element to unbundle. If omitted, the current single-element selection is used.
Returns
true if commands were queued.

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