Vixen
dd8b0a81

IEditableDocument

interface Core/Vixen.Ui/Documents.cs:36
csharp
public interface IEditableDocument

Something a user has open, has changed, and expects to be asked about before losing.

Read the guide page for this →

Remarks

Three signals and two verbs, and the signals are what make it worth having. Every surface that shows a document's state — a window title's asterisk, a greyed Save item, a tab's close button, a prompt on quit — reads one of these, and reads it through the reactive graph, so there is no "raise the changed event" for a control to forget. That is the whole difference from a bool IsDirty with a Changed event beside it, which is what the editor's own document had and what every consumer of it had to subscribe to by hand.

⚠ Deliberately smaller than NSDocument and than EditorDocument. There is no undo stack here (an element finds one with FindUndoManager, and a document that wants to be the one that hosts it sets it there), no file watching, no asset database and no project. Editor/Vixen.Editor.Core/EditorDocument.cs has all of that and cannot be the framework's model for the reason its own README now records: its only constructor demands an EditorProject and registers with it, so no document exists without a project directory and an asset database behind it. A text editor with one file open would have to invent a project to hold it.

⚠ An interface rather than only the base class, because the thing an application already has is usually a document — a scene, a buffer, a session — and asking it to inherit from a UI type is asking it to reorganise around the window. EditableDocument is the implementation for everything that does not already have one.

Fields and properties (3)

  • IReadOnlySignal<string> Name

    What to call it: a file name, or something like "Untitled 2".

  • IReadOnlySignal<string?> Location

    Where it lives, or if it has never been saved.

  • IReadOnlySignal<bool> IsDirty

    Whether it has changes that saving would write.

Methods (2)

  • bool Save()

    Writes it out.

  • bool Revert()

    Throws the changes away and reloads what is on disk.

Used by (6)

  • DocumentClosePromptVixen.Ui.Controls
  • DocumentCommandsVixen.Ui
  • EditableDocumentVixen.Ui
  • UiDocumentVixen.Ui
  • UiElementVixen.Ui
  • UiWindowTitleVixen.Ui