Replace ReactiveUI
This commit is contained in:
parent
43b4d50e43
commit
5584ab4ec8
41 changed files with 472 additions and 1013 deletions
|
|
@ -0,0 +1,30 @@
|
|||
using System.Reactive.Linq;
|
||||
|
||||
using AvaloniaEdit.Document;
|
||||
|
||||
using Dock.Model.Mvvm.Controls;
|
||||
|
||||
using DynamicData.Binding;
|
||||
|
||||
using InkForge.Desktop.Models;
|
||||
|
||||
namespace InkForge.Desktop.ViewModels.Documents;
|
||||
|
||||
public class NoteEditDocumentViewModel : Document
|
||||
{
|
||||
public Note Note { get; }
|
||||
|
||||
public TextDocument Document { get; }
|
||||
|
||||
public NoteEditDocumentViewModel(Note note, TextDocument textDocument)
|
||||
{
|
||||
Note = note;
|
||||
Document = textDocument;
|
||||
|
||||
Observable.CombineLatest(
|
||||
this.WhenValueChanged(v => v.Note.Name),
|
||||
this.WhenValueChanged(v => v.Document.UndoStack.IsOriginalFile),
|
||||
(name, original) => original ? name : $"{name} *"
|
||||
).Subscribe(title => Title = title!);
|
||||
}
|
||||
}
|
||||
|
|
@ -2,33 +2,28 @@ using System.Reactive;
|
|||
|
||||
using Avalonia.Platform.Storage;
|
||||
|
||||
using Dock.Model.ReactiveUI.Controls;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
|
||||
using Dock.Model.Mvvm.Controls;
|
||||
|
||||
using InkForge.Desktop.Managers;
|
||||
using InkForge.Desktop.Services;
|
||||
|
||||
using ReactiveUI;
|
||||
|
||||
namespace InkForge.Desktop.ViewModels.Documents;
|
||||
|
||||
public class WelcomePageDocumentViewModel : Document
|
||||
public partial class WelcomePageDocumentViewModel : Document
|
||||
{
|
||||
private readonly WorkspaceManager _workspaceController;
|
||||
|
||||
public ReactiveCommand<Unit, Unit> CreateNew { get; }
|
||||
|
||||
public ReactiveCommand<Unit, Unit> OpenNew { get; }
|
||||
|
||||
public WelcomePageDocumentViewModel(WorkspaceManager workspaceController)
|
||||
{
|
||||
CanClose = false;
|
||||
Title = "Welcome";
|
||||
|
||||
_workspaceController = workspaceController;
|
||||
CreateNew = ReactiveCommand.CreateFromTask(OnCreateNew);
|
||||
OpenNew = ReactiveCommand.CreateFromTask(OnOpenNew);
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private async Task OnCreateNew()
|
||||
{
|
||||
var storageProvider = this.GetStorageProvider()!;
|
||||
|
|
@ -56,6 +51,7 @@ public class WelcomePageDocumentViewModel : Document
|
|||
await _workspaceController.OpenWorkspace(filePath, true);
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private async Task OnOpenNew()
|
||||
{
|
||||
var storageProvider = this.GetStorageProvider()!;
|
||||
|
|
|
|||
|
|
@ -1,13 +0,0 @@
|
|||
using Dock.Model.Core;
|
||||
using Dock.Model.ReactiveUI.Controls;
|
||||
|
||||
namespace InkForge.Desktop.ViewModels;
|
||||
|
||||
public class InkForgeDocumentDock : DocumentDock, IDock
|
||||
{
|
||||
bool IDock.IsEmpty
|
||||
{
|
||||
get => false;
|
||||
set { }
|
||||
}
|
||||
}
|
||||
|
|
@ -1,32 +1,16 @@
|
|||
using Avalonia;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
||||
using Dock.Model.Core;
|
||||
|
||||
using InkForge.Desktop.Managers;
|
||||
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
using ReactiveUI;
|
||||
|
||||
namespace InkForge.Desktop.ViewModels;
|
||||
|
||||
public class MainViewModel : ReactiveObject
|
||||
public class MainViewModel : ObservableObject
|
||||
{
|
||||
private readonly DocumentManager _documentManager;
|
||||
public IDock Layout { get; }
|
||||
|
||||
public MainViewModel(InkForgeFactory factory)
|
||||
{
|
||||
Layout = factory.CreateLayout();
|
||||
factory.InitLayout(Layout);
|
||||
|
||||
_documentManager = CreateDocumentManager();
|
||||
}
|
||||
|
||||
private static DocumentManager CreateDocumentManager()
|
||||
{
|
||||
return ActivatorUtilities.CreateInstance<DocumentManager>(
|
||||
Application.Current!.GetValue(App.ServiceProviderProperty)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,14 @@
|
|||
using ReactiveUI;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
||||
namespace InkForge.Desktop.ViewModels;
|
||||
|
||||
public record class RecentItemViewModel(
|
||||
DateTimeOffset Created,
|
||||
string Name,
|
||||
DateTimeOffset LastUsed
|
||||
) : ReactiveRecord;
|
||||
public partial class RecentItemViewModel(
|
||||
DateTimeOffset created,
|
||||
string name,
|
||||
DateTimeOffset lastUsed
|
||||
) : ObservableObject
|
||||
{
|
||||
[ObservableProperty] private DateTimeOffset _created = created;
|
||||
[ObservableProperty] private string _name = name;
|
||||
[ObservableProperty] private DateTimeOffset _lastUsed = lastUsed;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,32 +1,40 @@
|
|||
using Dock.Model.ReactiveUI.Controls;
|
||||
using System.Reactive.Linq;
|
||||
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
||||
using Dock.Model.Mvvm.Controls;
|
||||
|
||||
using DynamicData.Binding;
|
||||
|
||||
using InkForge.Desktop.Managers;
|
||||
using InkForge.Desktop.Models;
|
||||
using InkForge.Desktop.ViewModels.Workspaces;
|
||||
|
||||
using ReactiveUI;
|
||||
|
||||
namespace InkForge.Desktop.ViewModels.Tools;
|
||||
|
||||
public class WorkspaceTool : Tool
|
||||
public partial class WorkspaceTool : Tool
|
||||
{
|
||||
private WorkspaceViewModel? _workspace;
|
||||
|
||||
public WorkspaceViewModel? Workspace
|
||||
{
|
||||
get => _workspace;
|
||||
private set => this.RaiseAndSetIfChanged(ref _workspace, value);
|
||||
}
|
||||
private readonly IWorkspaceViewModelFactory _workspaceViewModelFactory;
|
||||
[ObservableProperty] private WorkspaceViewModel? _workspace;
|
||||
|
||||
public WorkspaceTool(WorkspaceManager workspaceManager, IWorkspaceViewModelFactory workspaceViewModelFactory)
|
||||
{
|
||||
Title = "Workspace";
|
||||
_workspaceViewModelFactory = workspaceViewModelFactory;
|
||||
|
||||
Title = "Explorer";
|
||||
CanClose = false;
|
||||
CanFloat = false;
|
||||
CanPin = false;
|
||||
|
||||
workspaceManager.WhenAnyValue(v => v.Workspace,
|
||||
v => v switch
|
||||
{
|
||||
{ } => workspaceViewModelFactory.Create(v),
|
||||
_ => null
|
||||
}).BindTo(this, v => v.Workspace);
|
||||
workspaceManager.WhenValueChanged(v => v.Workspace).Subscribe(OnWorkspaceManagerWorkspaceChanged);
|
||||
}
|
||||
|
||||
private void OnWorkspaceManagerWorkspaceChanged(Workspace? workspace)
|
||||
{
|
||||
Workspace = workspace switch
|
||||
{
|
||||
{ } v => _workspaceViewModelFactory.Create(v),
|
||||
_ => null
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,9 @@
|
|||
using System.Collections.ObjectModel;
|
||||
|
||||
using Avalonia;
|
||||
|
||||
using DynamicData;
|
||||
|
||||
using InkForge.Desktop.Models;
|
||||
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
|
@ -6,30 +12,24 @@ namespace InkForge.Desktop.ViewModels.Workspaces
|
|||
{
|
||||
public class WorkspaceViewModel
|
||||
{
|
||||
private readonly Workspace _workspace;
|
||||
private readonly NoteStore _noteStore;
|
||||
// private readonly ObservableAsPropertyHelper<string> _workspaceNameProperty;
|
||||
private readonly ReadOnlyObservableCollection<Node<Note, int>> _notes;
|
||||
|
||||
// public string WorkspaceName => _workspaceNameProperty.Value;
|
||||
public string Name => _workspace.Name;
|
||||
|
||||
// public ReactiveCommand<Unit, Unit> AddDocument { get; }
|
||||
public ReadOnlyObservableCollection<Node<Note, int>> Notes => _notes;
|
||||
|
||||
public WorkspaceViewModel(NoteStore noteStore)
|
||||
public WorkspaceViewModel(Workspace workspace, NoteStore noteStore)
|
||||
{
|
||||
_workspace = workspace;
|
||||
_noteStore = noteStore;
|
||||
noteStore.Notes
|
||||
.AsObservableChangeSet(m => m.Key)
|
||||
.Transform(m => m.Value, true)
|
||||
.TransformToTree(m => m.Id)
|
||||
.Bind(out _notes).Subscribe();
|
||||
}
|
||||
|
||||
// public WorkspacesViewModel(Workspace workspace)
|
||||
// {
|
||||
// _workspace = workspace;
|
||||
// _workspaceNameProperty = this.WhenAnyValue(v => v._workspace.Name).ToProperty(this, nameof(WorkspaceName));
|
||||
|
||||
// AddDocument = ReactiveCommand.Create(OnAddDocument);
|
||||
// }
|
||||
|
||||
// private void OnAddDocument()
|
||||
// {
|
||||
|
||||
// }
|
||||
}
|
||||
|
||||
public interface IWorkspaceViewModelFactory
|
||||
|
|
@ -39,14 +39,14 @@ namespace InkForge.Desktop.ViewModels.Workspaces
|
|||
|
||||
namespace Internal
|
||||
{
|
||||
internal class WorkspaceViewModelFactory(IServiceProvider services) : IWorkspaceViewModelFactory
|
||||
internal class WorkspaceViewModelFactory : IWorkspaceViewModelFactory
|
||||
{
|
||||
private static ObjectFactory<WorkspaceViewModel>? s_workspaceViewModelFactory;
|
||||
|
||||
public WorkspaceViewModel Create(Workspace workspace)
|
||||
public static WorkspaceViewModel Create(Workspace workspace)
|
||||
{
|
||||
s_workspaceViewModelFactory ??= ActivatorUtilities.CreateFactory<WorkspaceViewModel>([typeof(Workspace)]);
|
||||
return s_workspaceViewModelFactory(services, [workspace]);
|
||||
return s_workspaceViewModelFactory(workspace.Services, [workspace]);
|
||||
}
|
||||
|
||||
WorkspaceViewModel IWorkspaceViewModelFactory.Create(Workspace workspace) => Create(workspace);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue