|
|
Donner 0.5.1
Embeddable browser-grade SVG2 engine
|
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. | |
| AsyncSVGDocument & | document () |
| Direct access to the wrapped AsyncSVGDocument. Used by the main loop for flushFrame() and currentFrameVersion(), and by tests. | |
| const AsyncSVGDocument & | document () 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. | |
| 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(). | |
| 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. | |
| 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. | |
| void | clearSelection () |
| Drop every entry from the selection. Equivalent to setSelection(std::nullopt) but reads better at clear sites. | |
| std::optional< svg::SVGGeometryElement > | hitTest (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::SVGGeometryElement > | hitTestRect (const Box2d &documentRect) |
| Find every geometry element whose world-space bounding box 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. | |
| UndoTimeline & | undoTimeline () |
| 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 UndoTimeline & | undoTimeline () const |
| bool | canUndo () const |
| Whether there is an entry to undo. | |
| 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 false — the flag is flipped after the fuzzing soak (M8 in the design doc). | |
| 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. New entries overwrite any still-pending writeback — coalescing is fine because the latest transform value is always the one we want. | |
| std::optional< CompletedTransformWriteback > | consumeTransformWriteback () |
| Drain the most recently queued transform writeback, if any. Called once per frame by main.cc. The writeback payload is stable across frames — callers latch it themselves if they need to retry on a busy frame. | |
| void | enqueueElementRemoveWriteback (CompletedElementRemoveWriteback writeback) |
| Queue an element-removal writeback that main.cc will splice into the source on its next drain. | |
| std::vector< CompletedElementRemoveWriteback > | consumeElementRemoveWritebacks () |
| Drain any queued element-removal writebacks. | |
Top-level editor shell.
Lifetime: typically one per window. All public methods are UI-thread only.
| 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.
| Class Members | ||
|---|---|---|
| bool | restoreSourceTransformAttributeValue = false | |
| optional< RcString > | sourceTransformAttributeValue | |
| AttributeWritebackTarget | target | |
| Transform2d | transform | |
| struct donner::editor::EditorApp::CompletedElementRemoveWriteback |
| Class Members | ||
|---|---|---|
| AttributeWritebackTarget | target | |
| void donner::editor::EditorApp::redo | ( | ) |
Redo the most recently undone entry.
In the non-destructive UndoTimeline model, "redo" is mechanically identical to "undo the most recent undo-entry": breaking the current undo chain and then calling undo() again pops the undo-entry the previous undo() call appended, which restores the post-drag state.
Like undo(), the restored transform is routed through the command queue so the mutation seam is preserved.