Update document handling
This commit is contained in:
Родитель
0484ca7740
Коммит
af4438dbaf
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Avalonia.Data;
|
||||
using AvaloniaDockApplication.Models.Documents;
|
||||
using AvaloniaDockApplication.Models.Tools;
|
||||
|
@ -11,12 +12,14 @@ using Dock.Model.Controls;
|
|||
using Dock.Model.Core;
|
||||
using Dock.Model.ReactiveUI;
|
||||
using Dock.Model.ReactiveUI.Controls;
|
||||
using ReactiveUI;
|
||||
|
||||
namespace AvaloniaDockApplication
|
||||
{
|
||||
public class MainDockFactory : Factory
|
||||
{
|
||||
private object _context;
|
||||
private IDocumentDock _documentDock;
|
||||
private readonly object _context;
|
||||
|
||||
public MainDockFactory(object context)
|
||||
{
|
||||
|
@ -25,13 +28,13 @@ namespace AvaloniaDockApplication
|
|||
|
||||
public override IRootDock CreateLayout()
|
||||
{
|
||||
var document1 = new Document1ViewModel
|
||||
var document1 = new TestDocumentViewModel
|
||||
{
|
||||
Id = "Document1",
|
||||
Title = "Document1"
|
||||
};
|
||||
|
||||
var document2 = new Document2ViewModel
|
||||
var document2 = new TestDocumentViewModel
|
||||
{
|
||||
Id = "Document2",
|
||||
Title = "Document2"
|
||||
|
@ -85,6 +88,29 @@ namespace AvaloniaDockApplication
|
|||
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
|
||||
{
|
||||
Id = "MainLayout",
|
||||
|
@ -143,18 +169,7 @@ namespace AvaloniaDockApplication
|
|||
Id = "LeftSplitter",
|
||||
Title = "LeftSplitter"
|
||||
},
|
||||
new DocumentDock
|
||||
{
|
||||
Id = "DocumentsPane",
|
||||
Title = "DocumentsPane",
|
||||
Proportion = double.NaN,
|
||||
ActiveDockable = document1,
|
||||
VisibleDockables = CreateList<IDockable>
|
||||
(
|
||||
document1,
|
||||
document2
|
||||
)
|
||||
},
|
||||
documentDock,
|
||||
new SplitterDockable()
|
||||
{
|
||||
Id = "RightSplitter",
|
||||
|
@ -223,6 +238,8 @@ namespace AvaloniaDockApplication
|
|||
root.DefaultDockable = mainView;
|
||||
root.VisibleDockables = CreateList<IDockable>(mainView);
|
||||
|
||||
_documentDock = documentDock;
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
|
@ -238,8 +255,8 @@ namespace AvaloniaDockApplication
|
|||
[nameof(IDockWindow)] = () => _context,
|
||||
[nameof(IDocument)] = () => _context,
|
||||
[nameof(ITool)] = () => _context,
|
||||
["Document1"] = () => new Document1(),
|
||||
["Document2"] = () => new Document2(),
|
||||
["Document1"] = () => new TestDocument(),
|
||||
["Document2"] = () => new TestDocument(),
|
||||
["LeftTop1"] = () => new LeftTopTool1(),
|
||||
["LeftTop2"] = () => new LeftTopTool2(),
|
||||
["LeftBottom1"] = () => new LeftBottomTool1(),
|
||||
|
@ -281,6 +298,9 @@ namespace AvaloniaDockApplication
|
|||
};
|
||||
|
||||
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
|
||||
{
|
||||
public class Document1
|
||||
public class TestDocument
|
||||
{
|
||||
}
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
using Dock.Model.ReactiveUI.Controls;
|
||||
|
||||
namespace AvaloniaDockApplication.ViewModels.Documents
|
||||
{
|
||||
public class Document2ViewModel : Document
|
||||
{
|
||||
}
|
||||
}
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
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:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
|
@ -3,9 +3,9 @@ using Avalonia.Markup.Xaml;
|
|||
|
||||
namespace AvaloniaDockApplication.Views.Documents
|
||||
{
|
||||
public class Document1View : UserControl
|
||||
public class TestDocumentView : UserControl
|
||||
{
|
||||
public Document1View()
|
||||
public TestDocumentView()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
}
|
Загрузка…
Ссылка в новой задаче