Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 1 addition & 54 deletions samples/DockSimplifiedSample/App.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
using System.Collections.Generic;
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
using Dock.Avalonia.Controls;
using Dock.Model.Avalonia;
using Dock.Model.Avalonia.Controls;
using Dock.Model.Controls;
using Dock.Model.Core;

namespace DockSimplifiedSample;

Expand All @@ -25,7 +20,7 @@ public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
var factory = new Factory(CreateLayout);
var factory = new DockFactory();
var layout = factory.CreateLayout();

var mainWindow = new MainWindow
Expand All @@ -44,52 +39,4 @@ public override void OnFrameworkInitializationCompleted()

base.OnFrameworkInitializationCompleted();
}

private static IRootDock CreateLayout()
{
var document = new Document { Id = "Document1", Title = "Document 1" };
var tool = new Tool { Id = "Tool1", Title = "Tool 1" };

var documentDock = new DocumentDock
{
Id = "Documents",
Title = "Documents",
VisibleDockables = new List<IDockable> { document },
ActiveDockable = document
};

var toolDock = new ToolDock
{
Id = "Tools",
Title = "Tools",
VisibleDockables = new List<IDockable> { tool },
ActiveDockable = tool,
Alignment = Alignment.Left
};

var mainLayout = new ProportionalDock
{
Id = "MainLayout",
Orientation = Orientation.Horizontal,
VisibleDockables = new List<IDockable>
{
toolDock,
new ProportionalDockSplitter { CanResize = true },
documentDock
}
};

toolDock.Proportion = 0.25;
documentDock.Proportion = 0.75;

var rootDock = new RootDock
{
Id = "Root",
Title = "Root",
VisibleDockables = new List<IDockable> { mainLayout },
ActiveDockable = mainLayout
};

return rootDock;
}
}
56 changes: 56 additions & 0 deletions samples/DockSimplifiedSample/DockFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using Dock.Model.Avalonia;
using Dock.Model.Avalonia.Controls;
using Dock.Model.Controls;
using Dock.Model.Core;

namespace DockSimplifiedSample;

/// <summary>
/// Creates the observable docking layout used by the simplified sample.
/// </summary>
public sealed class DockFactory : Factory
{
/// <inheritdoc />
public override IRootDock CreateLayout()
{
var document = new Document { Id = "Document1", Title = "Document 1" };
var tool = new Tool { Id = "Tool1", Title = "Tool 1" };

var documentDock = new DocumentDock
{
Id = "Documents",
Title = "Documents",
VisibleDockables = CreateList<IDockable>(document),
ActiveDockable = document,
Proportion = 0.75
};

var toolDock = new ToolDock
{
Id = "Tools",
Title = "Tools",
VisibleDockables = CreateList<IDockable>(tool),
ActiveDockable = tool,
Alignment = Alignment.Left,
Proportion = 0.25
};

var mainLayout = new ProportionalDock
{
Id = "MainLayout",
Orientation = Orientation.Horizontal,
VisibleDockables = CreateList<IDockable>(
toolDock,
new ProportionalDockSplitter { CanResize = true },
documentDock)
};

return new RootDock
{
Id = "Root",
Title = "Root",
VisibleDockables = CreateList<IDockable>(mainLayout),
ActiveDockable = mainLayout
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<ProjectReference Include="..\..\src\Dock.Model\Dock.Model.csproj" />
<ProjectReference Include="..\..\src\Dock.Avalonia\Dock.Avalonia.csproj" />
<ProjectReference Include="..\..\src\Dock.Model.Avalonia\Dock.Model.Avalonia.csproj" />
<ProjectReference Include="..\..\samples\DockSimplifiedSample\DockSimplifiedSample.csproj" />
<ProjectReference Include="..\..\samples\DockMvvmSample\DockMvvmSample.csproj" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System.Collections.Specialized;
using System.Linq;
using Avalonia.Headless.XUnit;
using Dock.Model;
using Dock.Model.Controls;
using Dock.Model.Core;
using DockSimplifiedSample;
using Xunit;

namespace Dock.Avalonia.HeadlessTests;

public class DockSimplifiedSampleLayoutTests
{
[AvaloniaFact]
public void Tool_CanFloatAndRedock_WithObservableLayoutUpdates()
{
var factory = new DockFactory();
var root = factory.CreateLayout();
factory.InitLayout(root);

var mainLayout = Assert.IsAssignableFrom<IProportionalDock>(
Assert.Single(root.VisibleDockables!));
var documentDock = Assert.Single(mainLayout.VisibleDockables!.OfType<IDocumentDock>());
var tool = Assert.IsAssignableFrom<ITool>(
Assert.Single(factory.Find(root, dockable => dockable.Id == "Tool1")));
var layoutChanges = 0;
var observableLayout = Assert.IsAssignableFrom<INotifyCollectionChanged>(mainLayout.VisibleDockables);
observableLayout.CollectionChanged += (_, _) => layoutChanges++;

factory.FloatDockable(tool);

Assert.NotEqual(0, layoutChanges);
Assert.Single(root.Windows!);
Assert.NotSame(root, factory.FindRoot(tool, _ => true));

var dockManager = new DockManager(new DockService());
var redocked = dockManager.ValidateTool(
tool,
documentDock,
DragAction.Move,
DockOperation.Right,
bExecute: true);

Assert.True(redocked);
Assert.Same(root, factory.FindRoot(tool, _ => true));
Assert.Empty(root.Windows!);
Assert.Same(tool, Assert.Single(factory.Find(root, dockable => dockable.Id == "Tool1")));
Assert.Single(factory.Find(root, dockable => dockable.Id == "Document1"));
}
}
Loading