This commit is contained in:
wieslawsoltes 2019-12-15 08:50:47 +00:00
Родитель 7b94102e10
Коммит 7052e90b7c
16 изменённых файлов: 119 добавлений и 88 удалений

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

@ -1,5 +1,10 @@
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
using AvaloniaDockApplication.Models;
using AvaloniaDockApplication.ViewModels;
using AvaloniaDockApplication.Views;
using Dock.Model;
namespace AvaloniaDockApplication
{
@ -9,5 +14,55 @@ namespace AvaloniaDockApplication
{
AvaloniaXamlLoader.Load(this);
}
public override void OnFrameworkInitializationCompleted()
{
var factory = new MainDockFactory(new DemoData());
var layout = factory.CreateLayout();
factory.InitLayout(layout);
var mainWindowViewModel = new MainWindowViewModel()
{
Factory = factory,
Layout = layout
};
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktopLifetime)
{
var mainWindow = new MainWindow
{
DataContext = mainWindowViewModel
};
mainWindow.Closing += (sender, e) =>
{
if (layout is IDock dock)
{
dock.Close();
}
};
desktopLifetime.MainWindow = mainWindow;
desktopLifetime.Exit += (sennder, e) =>
{
if (layout is IDock dock)
{
dock.Close();
}
};
}
else if (ApplicationLifetime is ISingleViewApplicationLifetime singleViewLifetime)
{
var mainView = new MainView()
{
DataContext = mainWindowViewModel
};
singleViewLifetime.MainView = mainView;
}
base.OnFrameworkInitializationCompleted();
}
}
}

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

@ -12,7 +12,7 @@ using Dock.Model.Controls;
namespace AvaloniaDockApplication
{
public class MainDockFactory : DockFactory
public class MainDockFactory : Factory
{
private object _context;
@ -83,31 +83,31 @@ namespace AvaloniaDockApplication
Title = "RightBottom2"
};
var mainLayout = new LayoutDock
var mainLayout = new ProportionalDock
{
Id = "MainLayout",
Title = "MainLayout",
Proportion = double.NaN,
Orientation = Orientation.Horizontal,
CurrentView = null,
Views = CreateList<IView>
ActiveDockable = null,
VisibleDockables = CreateList<IDockable>
(
new LayoutDock
new ProportionalDock
{
Id = "LeftPane",
Title = "LeftPane",
Proportion = double.NaN,
Orientation = Orientation.Vertical,
CurrentView = null,
Views = CreateList<IView>
ActiveDockable = null,
VisibleDockables = CreateList<IDockable>
(
new ToolDock
{
Id = "LeftPaneTop",
Title = "LeftPaneTop",
Proportion = double.NaN,
CurrentView = leftTopTool1,
Views = CreateList<IView>
ActiveDockable = leftTopTool1,
VisibleDockables = CreateList<IDockable>
(
leftTopTool1,
leftTopTool2
@ -123,8 +123,8 @@ namespace AvaloniaDockApplication
Id = "LeftPaneBottom",
Title = "LeftPaneBottom",
Proportion = double.NaN,
CurrentView = leftBottomTool1,
Views = CreateList<IView>
ActiveDockable = leftBottomTool1,
VisibleDockables = CreateList<IDockable>
(
leftBottomTool1,
leftBottomTool2
@ -142,8 +142,8 @@ namespace AvaloniaDockApplication
Id = "DocumentsPane",
Title = "DocumentsPane",
Proportion = double.NaN,
CurrentView = document1,
Views = CreateList<IView>
ActiveDockable = document1,
VisibleDockables = CreateList<IDockable>
(
document1,
document2
@ -154,22 +154,22 @@ namespace AvaloniaDockApplication
Id = "RightSplitter",
Title = "RightSplitter"
},
new LayoutDock
new ProportionalDock
{
Id = "RightPane",
Title = "RightPane",
Proportion = double.NaN,
Orientation = Orientation.Vertical,
CurrentView = null,
Views = CreateList<IView>
ActiveDockable = null,
VisibleDockables = CreateList<IDockable>
(
new ToolDock
{
Id = "RightPaneTop",
Title = "RightPaneTop",
Proportion = double.NaN,
CurrentView = rightTopTool1,
Views = CreateList<IView>
ActiveDockable = rightTopTool1,
VisibleDockables = CreateList<IDockable>
(
rightTopTool1,
rightTopTool2
@ -185,8 +185,8 @@ namespace AvaloniaDockApplication
Id = "RightPaneBottom",
Title = "RightPaneBottom",
Proportion = double.NaN,
CurrentView = rightBottomTool1,
Views = CreateList<IView>
ActiveDockable = rightBottomTool1,
VisibleDockables = CreateList<IDockable>
(
rightBottomTool1,
rightBottomTool2
@ -201,17 +201,17 @@ namespace AvaloniaDockApplication
{
Id = "Main",
Title = "Main",
CurrentView = mainLayout,
Views = CreateList<IView>(mainLayout)
ActiveDockable = mainLayout,
VisibleDockables = CreateList<IDockable>(mainLayout)
};
var root = CreateRootDock();
root.Id = "Root";
root.Title = "Root";
root.CurrentView = mainView;
root.DefaultView = mainView;
root.Views = CreateList<IView>(mainView);
root.ActiveDockable = mainView;
root.DefaultDockable = mainView;
root.VisibleDockables = CreateList<IDockable>(mainView);
root.Top = CreatePinDock();
root.Top.Alignment = Alignment.Top;
root.Bottom = CreatePinDock();
@ -224,19 +224,19 @@ namespace AvaloniaDockApplication
return root;
}
public override void InitLayout(IView layout)
public override void InitLayout(IDockable layout)
{
this.ContextLocator = new Dictionary<string, Func<object>>
{
[nameof(IRootDock)] = () => _context,
[nameof(IPinDock)] = () => _context,
[nameof(ILayoutDock)] = () => _context,
[nameof(IProportionalDock)] = () => _context,
[nameof(IDocumentDock)] = () => _context,
[nameof(IToolDock)] = () => _context,
[nameof(ISplitterDock)] = () => _context,
[nameof(IDockWindow)] = () => _context,
[nameof(IDocumentTab)] = () => _context,
[nameof(IToolTab)] = () => _context,
[nameof(IDocument)] = () => _context,
[nameof(ITool)] = () => _context,
["Document1"] = () => new Document1(),
["Document2"] = () => new Document2(),
["LeftTop1"] = () => new LeftTopTool1(),
@ -263,24 +263,22 @@ namespace AvaloniaDockApplication
["Main"] = () => _context,
};
this.HostLocator = new Dictionary<string, Func<IDockHost>>
this.HostWindowLocator = new Dictionary<string, Func<IHostWindow>>
{
[nameof(IDockWindow)] = () =>
{
var hostWindow = new HostWindow()
{
[!HostWindow.TitleProperty] = new Binding("CurrentView.Title")
[!HostWindow.TitleProperty] = new Binding("ActiveDockable.Title")
};
hostWindow.Content = new DockControl()
{
[!DockControl.LayoutProperty] = hostWindow[!HostWindow.DataContextProperty]
};
return hostWindow;
}
};
this.DockableLocator = new Dictionary<string, Func<IDockable>>
{
};
base.InitLayout(layout);
}
}

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

@ -1,49 +1,16 @@
using System;
using Avalonia;
using Avalonia.Logging.Serilog;
using AvaloniaDockApplication.Models;
using AvaloniaDockApplication.ViewModels;
using AvaloniaDockApplication.Views;
using Dock.Model;
namespace AvaloniaDockApplication
{
class Program
{
// Initialization code. Don't use any Avalonia, third-party APIs or any
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
// yet and stuff might break.
public static void Main(string[] args) => BuildAvaloniaApp().Start(AppMain, args);
public static void Main(string[] args) => BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
// Avalonia configuration, don't remove; also used by visual designer.
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
.LogToDebug();
// Your application's entry point. Here you can initialize your MVVM framework, DI
// container, etc.
private static void AppMain(Application app, string[] args)
{
var factory = new MainDockFactory(new DemoData());
var layout = factory.CreateLayout();
factory.InitLayout(layout);
var window = new MainWindow
{
DataContext = new MainWindowViewModel()
{
Factory = factory,
Layout = layout
}
};
app.Run(window);
if (layout is IDock dock)
{
dock.Close();
}
}
}
}

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

@ -27,7 +27,7 @@ namespace AvaloniaDockApplication
public bool Match(object data)
{
return data is ViewModelBase || data is IView;
return data is ViewModelBase || data is IDockable;
}
}
}

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

@ -2,7 +2,7 @@
namespace AvaloniaDockApplication.ViewModels.Documents
{
public class Document1ViewModel : DocumentTab
public class Document1ViewModel : Document
{
}
}

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

@ -2,7 +2,7 @@
namespace AvaloniaDockApplication.ViewModels.Documents
{
public class Document2ViewModel : DocumentTab
public class Document2ViewModel : Document
{
}
}

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

@ -1,8 +1,19 @@
using Dock.Model;
using System;
using Dock.Model;
using Dock.Model.Controls;
namespace AvaloniaDockApplication.ViewModels
{
public class MainViewModel : DockBase
public class MainViewModel : RootDock
{
public override IDockable Clone()
{
var mainViewModel = new MainViewModel();
CloneHelper.CloneDockProperties(this, mainViewModel);
CloneHelper.CloneRootDockProperties(this, mainViewModel);
return mainViewModel;
}
}
}

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

@ -5,17 +5,17 @@ namespace AvaloniaDockApplication.ViewModels
{
public class MainWindowViewModel : ViewModelBase
{
private IDockFactory _factory;
private IView _layout;
private IFactory _factory;
private IDock _layout;
private string _currentView;
public IDockFactory Factory
public IFactory Factory
{
get => _factory;
set => this.RaiseAndSetIfChanged(ref _factory, value);
}
public IView Layout
public IDock Layout
{
get => _layout;
set => this.RaiseAndSetIfChanged(ref _layout, value);

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

@ -2,7 +2,7 @@
namespace AvaloniaDockApplication.ViewModels.Tools
{
public class LeftBottomTool1ViewModel : ToolTab
public class LeftBottomTool1ViewModel : Tool
{
}
}

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

@ -2,7 +2,7 @@
namespace AvaloniaDockApplication.ViewModels.Tools
{
public class LeftBottomTool2ViewModel : ToolTab
public class LeftBottomTool2ViewModel : Tool
{
}
}

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

@ -2,7 +2,7 @@
namespace AvaloniaDockApplication.ViewModels.Tools
{
public class LeftTopTool1ViewModel : ToolTab
public class LeftTopTool1ViewModel : Tool
{
}
}

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

@ -2,7 +2,7 @@
namespace AvaloniaDockApplication.ViewModels.Tools
{
public class LeftTopTool2ViewModel : ToolTab
public class LeftTopTool2ViewModel : Tool
{
}
}

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

@ -2,7 +2,7 @@
namespace AvaloniaDockApplication.ViewModels.Tools
{
public class RightBottomTool1ViewModel : ToolTab
public class RightBottomTool1ViewModel : Tool
{
}
}

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

@ -2,7 +2,7 @@
namespace AvaloniaDockApplication.ViewModels.Tools
{
public class RightBottomTool2ViewModel : ToolTab
public class RightBottomTool2ViewModel : Tool
{
}
}

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

@ -2,7 +2,7 @@
namespace AvaloniaDockApplication.ViewModels.Tools
{
public class RightTopTool1ViewModel : ToolTab
public class RightTopTool1ViewModel : Tool
{
}
}

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

@ -2,7 +2,7 @@
namespace AvaloniaDockApplication.ViewModels.Tools
{
public class RightTopTool2ViewModel : ToolTab
public class RightTopTool2ViewModel : Tool
{
}
}