Skip to content

Comments

Fix document dock split#993

Merged
wieslawsoltes merged 3 commits intomasterfrom
fix/document-dock-split
Jan 21, 2026
Merged

Fix document dock split#993
wieslawsoltes merged 3 commits intomasterfrom
fix/document-dock-split

Conversation

@wieslawsoltes
Copy link
Owner

PR Summary: Document Dock Split Fixes (Issues #938, #940)

This summary captures the findings, implementation details, and usage guidance
for the fixes addressing:

Findings

  • The "New Horizontal/Vertical Document Dock" actions created a new document dock,
    but moved the document into that dock before inserting the dock into the layout.
    This left the new dock unattached (and the document "disappearing").
  • The new document dock did not carry over DocumentFactory, so create-document
    actions in the new dock did not work.

Implementation Details

1) Ensure the new document dock is inserted before moving documents

The split flow now inserts the new dock into the layout first and only then
moves the document into it. This mirrors normal docking behavior and keeps the
new dock attached in the layout tree.

Changes:

  • FactoryBase.Dockable.NewHorizontalDocumentDock
  • FactoryBase.Dockable.NewVerticalDocumentDock

Behavioral result:

  • The target dock is visible and part of the layout before documents move into it.
  • The "document disappears" issue is resolved.

2) Preserve DocumentFactory when splitting documents

Document-dock creation now copies DocumentFactory in addition to the existing
properties (Id, CanCreateDocument, EnableWindowDrag, LayoutMode,
DocumentTemplate).

Changes:

  • New IDocumentDockFactory interface to formalize DocumentFactory.
  • DocumentDock implementations now implement IDocumentDockFactory.
  • Copy logic added in:
    • DockService.SplitDocumentDockable
    • FactoryBase.Dockable.NewHorizontalDocumentDock
    • FactoryBase.Dockable.NewVerticalDocumentDock
    • FactoryBase.CreateWindowFrom (document windows now preserve factory as well)

Behavioral result:

  • Newly created document docks keep the same document factory.
  • The + button (or CreateDocument) works as expected after splitting.

3) Tests updated

  • Added coverage to ensure:
    • The new dock is attached to the layout tree.
    • DocumentFactory is preserved on split.

Tests:

  • tests/Dock.Avalonia.HeadlessTests/DocumentDockNewDockTests.cs

Usage Guide

Using DocumentFactory with document docks

Assign a factory delegate so new documents can be created from the + button
or the CreateDocument command:

var documents = new DocumentDock
{
    CanCreateDocument = true
};

documents.DocumentFactory = () =>
{
    return new Document
    {
        Title = "New Document",
        Content = new TextBox { Text = "Hello" }
    };
};

Splitting a document dock

When you invoke the split commands (context menu or factory methods), the new
dock now:

  • Attaches to the layout first.
  • Inherits DocumentFactory.
  • Preserves DocumentTemplate (Avalonia model).

Example:

// Assuming `doc` is an IDocument in a DocumentDock.
factory.NewHorizontalDocumentDock(doc);
// or
factory.NewVerticalDocumentDock(doc);

Behavior after splitting

  • The document is moved into the new dock, which is immediately visible.
  • The + button and CreateDocument command work because DocumentFactory
    was preserved on the new dock.

Files Changed (Key)

  • src/Dock.Model/Controls/IDocumentDockFactory.cs
  • src/Dock.Model/FactoryBase.Dockable.cs
  • src/Dock.Model/DockService.cs
  • src/Dock.Model/FactoryBase.cs
  • src/Dock.Model.*/*/DocumentDock.cs (implements IDocumentDockFactory)
  • tests/Dock.Avalonia.HeadlessTests/DocumentDockNewDockTests.cs

Notes

  • The new IDocumentDockFactory interface is intentionally small and focused
    to avoid changing IDocumentDock itself.
  • The document split behavior now matches general docking expectations and
    avoids temporary "orphaned" dock states.

Fixes #938
Fixes #940

Ensure new document docks attach before moving documents and\npropagate DocumentFactory across dock splits and window creation.
Cover DocumentFactory propagation and layout attachment on split.
Document IDocumentDockFactory usage and split behavior updates.
@wieslawsoltes wieslawsoltes merged commit 2048695 into master Jan 21, 2026
8 checks passed
@wieslawsoltes wieslawsoltes deleted the fix/document-dock-split branch January 21, 2026 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

1 participant