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)
initialDocuments (params Document[])

Properties

All

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

Count

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

Current

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

Unsaved

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

Indexers

this[]

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

Methods

Contains

#
public bool Contains(string filePath)
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.
filePath (string)

CreateLastChanceSaveDialog

#
public Dialog 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().

FlushModifiedAutoSavesForShutdown

#
public void 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.

Index

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

Index

#
public int Index(string filePath)
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.
filePath (string)

PathSequence

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

Pop

#
public bool Pop(Document doc, bool accept = true)
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.
doc (Document)Document to pop.
accept (bool = true)Accept/Reject state for stacked documents.

Push

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

Queue

#
public bool Queue(Document doc, Document parent = null)
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.
doc (Document)
parent (Document = null)

RegisterAcceptHandler

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

RegisterRejectHandler

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

SuspendEvents

#
public IDisposable 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.

TryOpenDocument

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

Events

Changed

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

DocumentModified

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