Batch Update
This commit is contained in:
parent
693d12b61c
commit
4c2b5cca93
32 changed files with 483 additions and 332 deletions
|
|
@ -1,11 +1,48 @@
|
|||
using Avalonia;
|
||||
|
||||
using Dock.Model.Core;
|
||||
|
||||
using InkForge.Desktop.Models;
|
||||
using InkForge.Desktop.ViewModels.Documents;
|
||||
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
using ReactiveUI;
|
||||
|
||||
namespace InkForge.Desktop.Managers;
|
||||
|
||||
public class DocumentManager
|
||||
{
|
||||
private readonly IDock _documents;
|
||||
private readonly InkForgeFactory _factory;
|
||||
private readonly WelcomePageDocumentViewModel _welcomePage;
|
||||
private readonly WorkspaceManager _workspaceManager;
|
||||
|
||||
public DocumentManager(WorkspaceManager workspaceManager)
|
||||
public DocumentManager(WorkspaceManager workspaceManager, InkForgeFactory factory)
|
||||
{
|
||||
_workspaceManager = workspaceManager;
|
||||
_factory = factory;
|
||||
_documents = factory.GetDockable<IDock>("Documents")!;
|
||||
_welcomePage = CreateWelcomePageDocumentViewModel();
|
||||
workspaceManager.WhenAnyValue(v => v.Workspace).Subscribe(OnWorkspaceChanged);
|
||||
}
|
||||
|
||||
private void OnWorkspaceChanged(Workspace? workspace)
|
||||
{
|
||||
if (workspace is null)
|
||||
{
|
||||
_factory.AddDockable(_documents, _welcomePage);
|
||||
}
|
||||
else
|
||||
{
|
||||
_factory.RemoveDockable(_welcomePage, false);
|
||||
}
|
||||
}
|
||||
|
||||
private static WelcomePageDocumentViewModel CreateWelcomePageDocumentViewModel()
|
||||
{
|
||||
return ActivatorUtilities.CreateInstance<WelcomePageDocumentViewModel>(
|
||||
Application.Current!.GetValue(App.ServiceProviderProperty)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,14 +20,14 @@ public class WorkspaceManager(IServiceProvider serviceProvider) : ReactiveObject
|
|||
private set => this.RaiseAndSetIfChanged(ref _workspace, value);
|
||||
}
|
||||
|
||||
public Task CloseWorkspace()
|
||||
public ValueTask CloseWorkspace()
|
||||
{
|
||||
_workspace?.Dispose();
|
||||
Workspace = null;
|
||||
return Task.CompletedTask;
|
||||
return ValueTask.CompletedTask;
|
||||
}
|
||||
|
||||
public async Task OpenWorkspace(string path, bool createFile = false)
|
||||
public async ValueTask OpenWorkspace(string path, bool createFile = false)
|
||||
{
|
||||
await CloseWorkspace().ConfigureAwait(false);
|
||||
if (await CreateLocalWorkspace(path, createFile).ConfigureAwait(false) is { } workspace)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue