This commit is contained in:
Wiesław Šoltés 2021-05-10 21:24:25 +02:00
Родитель 0484ca7740
Коммит af4438dbaf
9 изменённых файлов: 56 добавлений и 83 удалений

Просмотреть файл

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using Avalonia.Data; using Avalonia.Data;
using AvaloniaDockApplication.Models.Documents; using AvaloniaDockApplication.Models.Documents;
using AvaloniaDockApplication.Models.Tools; using AvaloniaDockApplication.Models.Tools;
@ -11,27 +12,29 @@ using Dock.Model.Controls;
using Dock.Model.Core; using Dock.Model.Core;
using Dock.Model.ReactiveUI; using Dock.Model.ReactiveUI;
using Dock.Model.ReactiveUI.Controls; using Dock.Model.ReactiveUI.Controls;
using ReactiveUI;
namespace AvaloniaDockApplication namespace AvaloniaDockApplication
{ {
public class MainDockFactory : Factory public class MainDockFactory : Factory
{ {
private object _context; private IDocumentDock _documentDock;
private readonly object _context;
public MainDockFactory(object context) public MainDockFactory(object context)
{ {
_context = context; _context = context;
} }
public override IRootDock CreateLayout() public override IRootDock CreateLayout()
{ {
var document1 = new Document1ViewModel var document1 = new TestDocumentViewModel
{ {
Id = "Document1", Id = "Document1",
Title = "Document1" Title = "Document1"
}; };
var document2 = new Document2ViewModel var document2 = new TestDocumentViewModel
{ {
Id = "Document2", Id = "Document2",
Title = "Document2" Title = "Document2"
@ -85,6 +88,29 @@ namespace AvaloniaDockApplication
Title = "RightBottom2" Title = "RightBottom2"
}; };
var documentDock = new DocumentDock
{
Id = "DocumentsPane",
Title = "DocumentsPane",
Proportion = double.NaN,
ActiveDockable = document1,
VisibleDockables = CreateList<IDockable>
(
document1,
document2
)
};
documentDock.CanCreateDocument = true;
documentDock.CreateDocument = ReactiveCommand.Create(() =>
{
var index = documentDock.VisibleDockables?.Count + 1;
var document = new TestDocumentViewModel {Id = $"Document{index}", Title = $"Document{index}"};
this.AddDockable(documentDock, document);
this.SetActiveDockable(document);
this.SetFocusedDockable(documentDock, document);
});
var mainLayout = new ProportionalDock var mainLayout = new ProportionalDock
{ {
Id = "MainLayout", Id = "MainLayout",
@ -143,18 +169,7 @@ namespace AvaloniaDockApplication
Id = "LeftSplitter", Id = "LeftSplitter",
Title = "LeftSplitter" Title = "LeftSplitter"
}, },
new DocumentDock documentDock,
{
Id = "DocumentsPane",
Title = "DocumentsPane",
Proportion = double.NaN,
ActiveDockable = document1,
VisibleDockables = CreateList<IDockable>
(
document1,
document2
)
},
new SplitterDockable() new SplitterDockable()
{ {
Id = "RightSplitter", Id = "RightSplitter",
@ -223,6 +238,8 @@ namespace AvaloniaDockApplication
root.DefaultDockable = mainView; root.DefaultDockable = mainView;
root.VisibleDockables = CreateList<IDockable>(mainView); root.VisibleDockables = CreateList<IDockable>(mainView);
_documentDock = documentDock;
return root; return root;
} }
@ -238,8 +255,8 @@ namespace AvaloniaDockApplication
[nameof(IDockWindow)] = () => _context, [nameof(IDockWindow)] = () => _context,
[nameof(IDocument)] = () => _context, [nameof(IDocument)] = () => _context,
[nameof(ITool)] = () => _context, [nameof(ITool)] = () => _context,
["Document1"] = () => new Document1(), ["Document1"] = () => new TestDocument(),
["Document2"] = () => new Document2(), ["Document2"] = () => new TestDocument(),
["LeftTop1"] = () => new LeftTopTool1(), ["LeftTop1"] = () => new LeftTopTool1(),
["LeftTop2"] = () => new LeftTopTool2(), ["LeftTop2"] = () => new LeftTopTool2(),
["LeftBottom1"] = () => new LeftBottomTool1(), ["LeftBottom1"] = () => new LeftBottomTool1(),
@ -281,6 +298,9 @@ namespace AvaloniaDockApplication
}; };
base.InitLayout(layout); base.InitLayout(layout);
this.SetActiveDockable(_documentDock);
this.SetFocusedDockable(_documentDock, _documentDock.VisibleDockables?.FirstOrDefault());
} }
} }
} }

Просмотреть файл

@ -1,7 +0,0 @@

namespace AvaloniaDockApplication.Models.Documents
{
public class Document2
{
}
}

Просмотреть файл

@ -1,7 +1,7 @@
 
namespace AvaloniaDockApplication.Models.Documents namespace AvaloniaDockApplication.Models.Documents
{ {
public class Document1 public class TestDocument
{ {
} }
} }

Просмотреть файл

@ -1,8 +0,0 @@
using Dock.Model.ReactiveUI.Controls;
namespace AvaloniaDockApplication.ViewModels.Documents
{
public class Document2ViewModel : Document
{
}
}

Просмотреть файл

@ -1,8 +1,8 @@
using Dock.Model.ReactiveUI.Controls; using Dock.Model.ReactiveUI.Controls;
namespace AvaloniaDockApplication.ViewModels.Documents namespace AvaloniaDockApplication.ViewModels.Documents
{ {
public class Document1ViewModel : Document public class TestDocumentViewModel : Document
{ {
} }
} }

Просмотреть файл

@ -1,14 +0,0 @@
<UserControl x:Class="AvaloniaDockApplication.Views.Documents.Document2View"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d" d:DesignWidth="300" d:DesignHeight="400">
<Grid Focusable="True" Background="Gray">
<StackPanel>
<TextBlock Text="{Binding Id}"/>
<TextBlock Text="{Binding Title}"/>
<TextBlock Text="{Binding Context}"/>
</StackPanel>
</Grid>
</UserControl>

Просмотреть файл

@ -1,18 +0,0 @@
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
namespace AvaloniaDockApplication.Views.Documents
{
public class Document2View : UserControl
{
public Document2View()
{
this.InitializeComponent();
}
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
}
}

Просмотреть файл

@ -1,4 +1,4 @@
<UserControl x:Class="AvaloniaDockApplication.Views.Documents.Document1View" <UserControl x:Class="AvaloniaDockApplication.Views.Documents.TestDocumentView"
xmlns="https://github.com/avaloniaui" xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

Просмотреть файл

@ -3,9 +3,9 @@ using Avalonia.Markup.Xaml;
namespace AvaloniaDockApplication.Views.Documents namespace AvaloniaDockApplication.Views.Documents
{ {
public class Document1View : UserControl public class TestDocumentView : UserControl
{ {
public Document1View() public TestDocumentView()
{ {
this.InitializeComponent(); this.InitializeComponent();
} }