public abstract class EditorDocumentOne thing open for editing, with its own undo history.
No guide page documents this yet — the page shows what the code says about itself.
Remarks
A scene, a material, a prefab, a settings asset. What it holds and how it writes itself back are the deriving type's business; what is here is the part every open document has — a title, an undo stack, and an honest answer to whether it differs from disk.
Unsaved has two sources, and since #656 they are two signals. IsDirty is the stack's own position — the edits made in this document, which undoing back to the save point takes away. ExternallyModified is a change that arrived from outside it — a global rename that rewrote a reference this document holds — which no amount of undoing inside the document can take back. HasUnsavedChanges is the two together, and it is what Save All, the project's close question and the tab markers read. Save and Reload clear both.
IsStale is the opposite question and is deliberately not part of that answer. Dirty is memory ahead of disk; stale is disk ahead of memory. Folding the two together would make SaveAll write this document over the edit somebody else made to its file. ExternalEdits is what sets it.
It is Vixen.Ui's IEditableDocument (#656), explicitly, so a panel hosting one answers document.save, its tab can be asked about on close and a window title can follow it — the framework surfaces, with no editor copy of each. Name is Title; Revert is Reload, including the promise that leaves the document dirty and covers both "cannot" and "tried and declined".
⚠ A failed save is reported, not swallowed — the decision on #656. Save keeps its void-and-throw contract, because "a subscriber that cannot write its file is a failed save, and the caller's own error handling is what turns that into a notification". The interface's is reached by catching a write failure, handing it to SaveFailed and answering ; with nobody subscribed it is thrown on, because a failure with nobody to hear it is exactly the swallow that remark forbids.
The location is the asset database's path, or else the file the document says it writes (#1493). Asset is immutable, and EditorApplication opens its scenes as new SceneDocument(project, world, AssetId.Empty, …) with the real path held by a Writer — because Save As moves that path under the document — so a deriving type names the file with WritesTo and the location follows it. ⚠ Only once the file exists: IEditableDocument's null means "never saved", and a scene whose writer points at a file nothing has written yet is exactly that.
⚠ And IsStale is not ExternallyModified: stale is disk ahead of memory, which saving would overwrite; externally modified is memory ahead of disk, which saving writes.
Fields and properties (11)
public EditorProject ProjectThe project it belongs to.
public EditorContext ContextWhat commands on this document's stack are handed.
public CommandStack StackThis document's undo history.
public AssetId AssetThe asset it edits, or Empty for one not saved anywhere yet.
public IReadOnlySignal<string> TitleWhat the tab says.
public IReadOnlySignal<bool> IsDirtyWhether it has edits of its own that are not on disk: the stack's position.
public IReadOnlySignal<bool> ExternallyModifiedWhether a command on another stack changed it — a global rename that rewrote a reference in it.
public IReadOnlySignal<bool> HasUnsavedChangesWhether it differs from what is on disk for either reason: IsDirty or ExternallyModified.
public IReadOnlySignal<bool> IsStaleWhether its file changed underneath it and it has not caught up.
public bool IsOpenWhether it is still open in the project.
public virtual bool CanReloadWhether this document knows how to read its file again.
Events (1)
public Action<EditorDocument>? SavedRaised after the document has written itself back, before it is marked clean.
Methods (10)
protected EditorDocument(EditorProject project, AssetId asset, string title)Opens a document in a project.
public void SetTitle(string value)Changes what the tab says.
public void Save()Writes it back and records that this is now what is on disk.
protected void WritesTo(string? path)Names the file this document writes when no asset names it, and asks its location again.
public bool Reload()Reads the file again, discarding what was in memory, and forgets the history over it.
protected virtual bool ReloadCore()Reads the file again. Overridden by a document that knows how.
public bool Close()Closes it, which is Close on this document.
protected abstract void SaveCore()Writes the document back to wherever it came from.
protected internal virtual void OnClosed()Called once when the document leaves the project.
protected internal virtual void OnProjectFileChanged(string? path)Something in the project changed on disk, whoever it belongs to.
Used by (277, showing 40)
- ActiveDocumentUndoVixen.Editor.App
- ActiveSceneTestsVixen.Editor.App.Tests
- AddCommentCommandVixen.Editor.NodeGraph
- AddGroupCommandVixen.Editor.NodeGraph
- AddNodeCommandVixen.Editor.NodeGraph
- AddressableGroupDocumentVixen.Editor.AssetEditors
- AddressableGroupDocumentTestsVixen.Editor.AssetEditors.Tests
- AddressableGroupEditorFactoryVixen.Editor.AssetEditors
- AddressableGroupEditorViewVixen.Editor.AssetEditors
- AddressableGroupsViewVixen.Editor.AssetEditors
- AnimationBinderVixen.Editor.AssetEditors
- AnimationClipDocumentVixen.Editor.AssetEditors
- AnimationClipEditorFactoryVixen.Editor.AssetEditors
- AnimationGraphDocumentVixen.Editor.AssetEditors
- AnimationGraphEditorFactoryVixen.Editor.AssetEditors
- AnimationWiringTestsVixen.Editor.App.Tests
- AssetEditorsModuleVixen.Editor.AssetEditors
- AssetPickerTestsVixen.Editor.App.Tests
- AssetTabsVixen.Editor.App
- AudioMixerDocumentVixen.Editor.AssetEditors
- AudioMixerEditorFactoryVixen.Editor.AssetEditors
- AudioMixerViewTestsVixen.Editor.AssetEditors.Tests
- AuthoringContextTestsVixen.Editor.AssetEditors.Tests
- AuthoringTestsVixen.Editor.AssetEditors.Tests
- BehaviorTreeDocumentVixen.Editor.AssetEditors
- BehaviorTreeDocumentTestsVixen.Editor.AssetEditors.Tests
- BehaviorTreeEditorFactoryVixen.Editor.AssetEditors
- BlankDocumentVixen.Editor.App.Tests
- BlockoutBooleanVixen.Editor.Blockout
- BlockoutBooleanTestsVixen.Editor.Blockout.Tests
- BlockoutCreateVixen.Editor.Blockout
- BlockoutCreateTestsVixen.Editor.Blockout.Tests
- BlockoutCubeGridVixen.Editor.Blockout
- BlockoutGeometryVixen.Editor.Blockout
- BlockoutGeometryTestsVixen.Editor.Blockout.Tests
- BlockoutHandoffVixen.Editor.Blockout
- BlockoutHistoryTestsVixen.Editor.Blockout.Tests
- BlockoutKnifeTestsVixen.Editor.Blockout.Tests
- BlockoutRetopologyVixen.Editor.Blockout
- BlockoutRetopologyTestsVixen.Editor.Blockout.Tests