Replace ReactiveUI
This commit is contained in:
parent
43b4d50e43
commit
5584ab4ec8
41 changed files with 472 additions and 1013 deletions
|
|
@ -1,84 +1,67 @@
|
|||
using Dock.Model.ReactiveUI;
|
||||
using Avalonia;
|
||||
|
||||
using Dock.Model.Controls;
|
||||
using Dock.Model.Core;
|
||||
using Dock.Model.ReactiveUI.Controls;
|
||||
using Dock.Avalonia.Controls;
|
||||
using Dock.Model.Mvvm;
|
||||
using Dock.Model.Mvvm.Controls;
|
||||
|
||||
using DynamicData.Binding;
|
||||
|
||||
using InkForge.Desktop.Managers;
|
||||
using InkForge.Desktop.Models;
|
||||
using InkForge.Desktop.ViewModels.Documents;
|
||||
using InkForge.Desktop.ViewModels.Tools;
|
||||
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Avalonia;
|
||||
using InkForge.Desktop.ViewModels;
|
||||
|
||||
namespace InkForge.Desktop;
|
||||
|
||||
public class InkForgeFactory : Factory
|
||||
{
|
||||
private readonly IDocumentDock _documentDock;
|
||||
private readonly IDock _mainDock;
|
||||
private readonly IRootDock _rootDock;
|
||||
private readonly ViewModels.Tools.WorkspaceTool _workspaceTool;
|
||||
private readonly WelcomePageDocumentViewModel _welcomePage;
|
||||
private readonly WorkspaceTool _workspaceTool;
|
||||
|
||||
public InkForgeFactory()
|
||||
public InkForgeFactory(WorkspaceManager workspace)
|
||||
{
|
||||
_rootDock = new RootDock
|
||||
{
|
||||
IsCollapsable = false,
|
||||
};
|
||||
|
||||
_documentDock = new DocumentDock
|
||||
{
|
||||
Id = "Documents",
|
||||
Title = "Documents",
|
||||
CanCreateDocument = false,
|
||||
IsCollapsable = false,
|
||||
Proportion = double.NaN,
|
||||
};
|
||||
_rootDock = CreateRootDock();
|
||||
_mainDock = CreateDockDock();
|
||||
_mainDock.IsCollapsable = false;
|
||||
_mainDock.CanClose = false;
|
||||
|
||||
_welcomePage = CreateWelcomePageDocumentViewModel();
|
||||
_workspaceTool = CreateWorkspaceTool();
|
||||
|
||||
workspace.WhenValueChanged(m => m.Workspace).Subscribe(OnWorkspaceChanged);
|
||||
}
|
||||
|
||||
public override IRootDock CreateLayout()
|
||||
{
|
||||
ProportionalDock workspaceLayout = new()
|
||||
ToolDock toolDock = new()
|
||||
{
|
||||
Proportion = 0.3,
|
||||
Alignment = Alignment.Left,
|
||||
Proportion = 0.25,
|
||||
VisibleDockables = [_workspaceTool],
|
||||
};
|
||||
|
||||
ProportionalDock windowLayoutContent = new()
|
||||
{
|
||||
Orientation = Orientation.Horizontal,
|
||||
IsCollapsable = false,
|
||||
VisibleDockables = [workspaceLayout, new ProportionalDockSplitter(), _documentDock]
|
||||
VisibleDockables = [toolDock, new ProportionalDockSplitter(), _mainDock]
|
||||
};
|
||||
|
||||
RootDock windowLayout = new()
|
||||
{
|
||||
Title = "Default",
|
||||
IsCollapsable = false,
|
||||
VisibleDockables = [windowLayoutContent],
|
||||
ActiveDockable = windowLayoutContent,
|
||||
};
|
||||
|
||||
_rootDock.VisibleDockables = [windowLayout];
|
||||
_rootDock.ActiveDockable = windowLayout;
|
||||
_rootDock.DefaultDockable = windowLayout;
|
||||
_rootDock.VisibleDockables = [windowLayoutContent];
|
||||
_rootDock.DefaultDockable = windowLayoutContent;
|
||||
|
||||
return _rootDock;
|
||||
}
|
||||
|
||||
public override void InitLayout(IDockable layout)
|
||||
private static WelcomePageDocumentViewModel CreateWelcomePageDocumentViewModel()
|
||||
{
|
||||
DockableLocator = new Dictionary<string, Func<IDockable?>>
|
||||
{
|
||||
["Root"] = () => _rootDock,
|
||||
["Documents"] = () => _documentDock,
|
||||
["Workspace"] = () => _workspaceTool,
|
||||
};
|
||||
|
||||
HostWindowLocator = new Dictionary<string, Func<IHostWindow?>>
|
||||
{
|
||||
[nameof(IDockWindow)] = () => new HostWindow()
|
||||
};
|
||||
|
||||
base.InitLayout(layout);
|
||||
return ActivatorUtilities.CreateInstance<WelcomePageDocumentViewModel>(
|
||||
Application.Current!.GetValue(App.ServiceProviderProperty)
|
||||
);
|
||||
}
|
||||
|
||||
private static ViewModels.Tools.WorkspaceTool CreateWorkspaceTool()
|
||||
|
|
@ -87,4 +70,16 @@ public class InkForgeFactory : Factory
|
|||
Application.Current!.GetValue(App.ServiceProviderProperty)
|
||||
);
|
||||
}
|
||||
|
||||
private void OnWorkspaceChanged(Workspace? workspace)
|
||||
{
|
||||
IDockable dock = workspace switch
|
||||
{
|
||||
null => _welcomePage,
|
||||
_ => workspace.Services.GetRequiredService<DocumentManager>().Dock,
|
||||
};
|
||||
|
||||
AddDockable(_mainDock, dock);
|
||||
CloseOtherDockables(dock);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue