DocumentBag

References
public sealed class DocumentBag
A collection of documents, one of which is designated as the 'head'.

Constructors

DocumentBag

#
public DocumentBag(
params Document[]
initialDocuments
)

Properties

All

#
Iterate over the heads of all document stacks.
public IEnumerable<DocumentStack> All { get; }

Count

#
Gets the number of document stacks.
public int Count { get; }

Current

#
Gets the document at the head of the current stack. If no document is currently available, a new, inactive document will be created.
public Document Current { get; }

Unsaved

#
Iterate over all modified documents.
public IEnumerable<DocumentStack> Unsaved { get; }

Indexers

this[]

#
Gets the stack at the given index.
public DocumentStack this[
index
] { get; }

Methods

Contains

#
Test whether a specific file path is part of this stack. Note that only root files ought to have file paths which means only root files are checked, even if they are not at the head of the stack.
public bool Contains(
filePath
)

CreateLastChanceSaveDialog

#
Return a dialog which contains a list of unsaved documents that cannot be silently restored on next launch (currently: documents that have never been saved). Returns null if no such documents exist. Documents that have a file path are handled via the session record and the autosave flush in FlushModifiedAutoSavesForShutdown().
public Dialog CreateLastChanceSaveDialog()

FlushModifiedAutoSavesForShutdown

#
Force-flush an up-to-date autosave file to disk for every modified document in the bag that has been saved at least once. Intended to be called during shutdown so that the next launch can reinstate those documents from their autosave files via the session record.
public void FlushModifiedAutoSavesForShutdown()

Index

#
Gets the index of the stack containing the specified document.
public int Index()

Index

#
Gets the index of the document with the specified file path within this stack, or -1. Note that only root files ought to have file paths which means only root files are checked, even if they are not at the head of the stack.
public int Index(
filePath
)

PathSequence

#
Create a single string which sequences all the paths of all documents which have paths.
public string PathSequence(
separator,
omitHead
)

Pop

#
Remove a document from this stack. If the popped document is the current one, the next one will be made current. Only documents which are at the heads of their respective stacks can be popped.
public bool Pop(
doc,
Document to pop.
accept = true
Accept/Reject state for stacked documents.
)

Push

#
Push a document to this bag and make it current.
public bool Push(
doc,
parent = null
)

Queue

#
Push a document to the end of this stack. If the document is already in the stack, but not at the end, it will *not* be repositioned.
public bool Queue(
doc,
parent = null
)

RegisterAcceptHandler

#
Add a callback to a specific document for acceptance handling.
public bool RegisterAcceptHandler(
doc,
callback
)

RegisterRejectHandler

#
Add a callback to a specific document for rejection handling.
public bool RegisterRejectHandler(
doc,
callback
)

SuspendEvents

#
Suspend external firing of the Changed event for the lifetime of the returned scope. Internal bookkeeping (such as the active-head Document.ModifiedChanged subscription) still keeps up with the bag's state. When the outermost scope is disposed, a single DocumentBagEventType.Restored event is fired so subscribers that build state incrementally can re-sync from scratch. Nestable: only the outermost scope's disposal fires the Restored event.
public IDisposable SuspendEvents()

TryOpenDocument

#
Load a Grasshopper file into this canvas.
public bool TryOpenDocument()
True if the file was successfully loaded.

Events

Changed

#
Raised whenever there's a change to the bag.
public event EventHandler<DocumentBagEventArgs> Changed

DocumentModified

#
Raised when the currently floating document is modified.
public event EventHandler<DocumentModifiedEventArgs> DocumentModified