Migrate to CommunityToolkit.Mvvm and ReactiveMarbles.PropertyChanged

This commit is contained in:
Wiesław Šoltés 2022-08-21 22:56:34 +02:00
Родитель deb383c050
Коммит d30242234e
12 изменённых файлов: 55 добавлений и 58 удалений

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

@ -45,7 +45,6 @@ ProjectSection(SolutionItems) = preProject
build\Avalonia.Desktop.props = build\Avalonia.Desktop.props build\Avalonia.Desktop.props = build\Avalonia.Desktop.props
build\Avalonia.Diagnostics.props = build\Avalonia.Diagnostics.props build\Avalonia.Diagnostics.props = build\Avalonia.Diagnostics.props
build\Avalonia.props = build\Avalonia.props build\Avalonia.props = build\Avalonia.props
build\Avalonia.ReactiveUI.props = build\Avalonia.ReactiveUI.props
build\Avalonia.Skia.props = build\Avalonia.Skia.props build\Avalonia.Skia.props = build\Avalonia.Skia.props
build\Base.props = build\Base.props build\Base.props = build\Base.props
build\ReferenceAssemblies.props = build\ReferenceAssemblies.props build\ReferenceAssemblies.props = build\ReferenceAssemblies.props
@ -62,6 +61,8 @@ ProjectSection(SolutionItems) = preProject
build\System.Text.Json.props = build\System.Text.Json.props build\System.Text.Json.props = build\System.Text.Json.props
build\Avalonia.Web.Blazor.props = build\Avalonia.Web.Blazor.props build\Avalonia.Web.Blazor.props = build\Avalonia.Web.Blazor.props
build\Avalonia.Themes.Fluent.props = build\Avalonia.Themes.Fluent.props build\Avalonia.Themes.Fluent.props = build\Avalonia.Themes.Fluent.props
build\CommunityToolkit.Mvvm.props = build\CommunityToolkit.Mvvm.props
build\ReactiveMarbles.PropertyChanged.props = build\ReactiveMarbles.PropertyChanged.props
EndProjectSection EndProjectSection
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "_build", "build\build\_build.csproj", "{E9A88CB0-B853-44C3-8A7E-F67DAD2A7F9B}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "_build", "build\build\_build.csproj", "{E9A88CB0-B853-44C3-8A7E-F67DAD2A7F9B}"

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

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup> <ItemGroup>
<PackageReference Include="Avalonia.ReactiveUI" Version="11.0.0-preview1" /> <PackageReference Include="CommunityToolkit.Mvvm" Version="8.0.0" />
</ItemGroup> </ItemGroup>
</Project> </Project>

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

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<PackageReference Include="ReactiveMarbles.PropertyChanged" Version="2.0.27" />
</ItemGroup>
</Project>

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

@ -26,7 +26,6 @@
<Import Project="..\..\build\Avalonia.props" /> <Import Project="..\..\build\Avalonia.props" />
<Import Project="..\..\build\Avalonia.Themes.Fluent.props" /> <Import Project="..\..\build\Avalonia.Themes.Fluent.props" />
<Import Project="..\..\build\Avalonia.Diagnostics.props" /> <Import Project="..\..\build\Avalonia.Diagnostics.props" />
<Import Project="..\..\build\Avalonia.ReactiveUI.props" />
<Import Project="..\..\build\Avalonia.Markup.Xaml.Loader.props" /> <Import Project="..\..\build\Avalonia.Markup.Xaml.Loader.props" />
<Import Project="..\..\build\Avalonia.Xaml.Behaviors.props" /> <Import Project="..\..\build\Avalonia.Xaml.Behaviors.props" />
<Import Project="..\..\build\Avalonia.Controls.Skia.props" /> <Import Project="..\..\build\Avalonia.Controls.Skia.props" />
@ -34,6 +33,8 @@
<Import Project="..\..\build\SkiaSharp.Linux.props" /> <Import Project="..\..\build\SkiaSharp.Linux.props" />
<Import Project="..\..\build\Svg.Skia.props" /> <Import Project="..\..\build\Svg.Skia.props" />
<Import Project="..\..\build\System.Text.Json.props" /> <Import Project="..\..\build\System.Text.Json.props" />
<Import Project="..\..\build\CommunityToolkit.Mvvm.props" />
<Import Project="..\..\build\ReactiveMarbles.PropertyChanged.props" />
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\SvgToXamlConverter\SvgToXamlConverter.csproj" /> <ProjectReference Include="..\SvgToXamlConverter\SvgToXamlConverter.csproj" />

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

@ -2,7 +2,7 @@
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Input; using System.Windows.Input;
using ReactiveUI; using CommunityToolkit.Mvvm.Input;
using Svg.Model; using Svg.Model;
namespace SvgToXaml.ViewModels; namespace SvgToXaml.ViewModels;
@ -19,28 +19,28 @@ public class FileItemViewModel : ViewModelBase
public string Name public string Name
{ {
get => _name; get => _name;
private set => this.RaiseAndSetIfChanged(ref _name, value); private set => SetProperty(ref _name, value);
} }
[JsonInclude] [JsonInclude]
public string Path public string Path
{ {
get => _path; get => _path;
private set => this.RaiseAndSetIfChanged(ref _path, value); private set => SetProperty(ref _path, value);
} }
[JsonIgnore] [JsonIgnore]
public SvgViewModel? Svg public SvgViewModel? Svg
{ {
get => _svg; get => _svg;
private set => this.RaiseAndSetIfChanged(ref _svg, value); private set => SetProperty(ref _svg, value);
} }
[JsonIgnore] [JsonIgnore]
public SkiaSharp.SKPicture? Picture public SkiaSharp.SKPicture? Picture
{ {
get => _picture; get => _picture;
private set => this.RaiseAndSetIfChanged(ref _picture, value); private set => SetProperty(ref _picture, value);
} }
[JsonIgnore] [JsonIgnore]
@ -64,9 +64,9 @@ public class FileItemViewModel : ViewModelBase
public void Initialize(Func<FileItemViewModel, Task> preview, Func<FileItemViewModel, Task> remove) public void Initialize(Func<FileItemViewModel, Task> preview, Func<FileItemViewModel, Task> remove)
{ {
PreviewCommand = ReactiveCommand.CreateFromTask(async () => await preview(this)); PreviewCommand = new AsyncRelayCommand(async () => await preview(this));
RemoveCommand = ReactiveCommand.Create(async () => await remove(this)); RemoveCommand = new AsyncRelayCommand(async () => await remove(this));
} }
public async Task Load(DrawAttributes ignoreAttribute) public async Task Load(DrawAttributes ignoreAttribute)
@ -100,4 +100,4 @@ public class FileItemViewModel : ViewModelBase
Svg = null; Svg = null;
} }
} }
} }

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

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Reactive.Linq;
using System.Text; using System.Text;
using System.Text.Json; using System.Text.Json;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
@ -14,7 +15,8 @@ using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml; using Avalonia.Markup.Xaml;
using Avalonia.Platform.Storage; using Avalonia.Platform.Storage;
using Avalonia.Threading; using Avalonia.Threading;
using ReactiveUI; using CommunityToolkit.Mvvm.Input;
using ReactiveMarbles.PropertyChanged;
using SvgToXaml.Views; using SvgToXaml.Views;
using ResourceDictionary = SvgToXamlConverter.Model.Resources.ResourceDictionary; using ResourceDictionary = SvgToXamlConverter.Model.Resources.ResourceDictionary;
@ -28,7 +30,7 @@ public class MainWindowViewModel : ViewModelBase
public ProjectViewModel Project public ProjectViewModel Project
{ {
get => _project; get => _project;
set => this.RaiseAndSetIfChanged(ref _project, value); set => SetProperty(ref _project, value);
} }
[JsonIgnore] [JsonIgnore]
@ -63,26 +65,26 @@ public class MainWindowViewModel : ViewModelBase
{ {
_project = new ProjectViewModel(); _project = new ProjectViewModel();
ClearCommand = ReactiveCommand.Create(Clear); ClearCommand = new RelayCommand(Clear);
OpenCommand = ReactiveCommand.CreateFromTask(async () => await Open()); OpenCommand = new AsyncRelayCommand(async () => await Open());
SaveCommand = ReactiveCommand.CreateFromTask(async () => await Save()); SaveCommand = new AsyncRelayCommand(async () => await Save());
AddCommand = ReactiveCommand.CreateFromTask(async () => await Add()); AddCommand = new AsyncRelayCommand(async () => await Add());
CopySelectedCommand = ReactiveCommand.CreateFromTask<string>(async format => await CopySelected(format)); CopySelectedCommand = new AsyncRelayCommand<string>(async format => await CopySelected(format));
CopyAllCommand = ReactiveCommand.CreateFromTask<string>(async format => await CopyAll(format)); CopyAllCommand = new AsyncRelayCommand<string>(async format => await CopyAll(format));
ExportSelectedCommand = ReactiveCommand.CreateFromTask<string>(async format => await ExportSelected(format)); ExportSelectedCommand = new AsyncRelayCommand<string>(async format => await ExportSelected(format));
ExportAllCommand = ReactiveCommand.CreateFromTask<string>(async format => await ExportAll(format)); ExportAllCommand = new AsyncRelayCommand<string>(async format => await ExportAll(format));
ClipboardCommand = ReactiveCommand.CreateFromTask<string>(async format => await Clipboard(format)); ClipboardCommand = new AsyncRelayCommand<string>(async format => await Clipboard(format));
// ReSharper disable once AsyncVoidLambda // ReSharper disable once AsyncVoidLambda
this.WhenAnyValue(x => x.Project.SelectedItem).Subscribe(async x => this.WhenChanged(x => x.Project.SelectedItem).DistinctUntilChanged().Subscribe(async x =>
{ {
if (x is { }) if (x is { })
{ {
@ -91,31 +93,31 @@ public class MainWindowViewModel : ViewModelBase
}); });
// ReSharper disable once AsyncVoidLambda // ReSharper disable once AsyncVoidLambda
this.WhenAnyValue(x => x.Project.Settings.UseCompatMode).Subscribe(async _ => this.WhenChanged(x => x.Project.Settings.UseCompatMode).DistinctUntilChanged().Subscribe(async _ =>
{ {
await Reload(); await Reload();
}); });
// ReSharper disable once AsyncVoidLambda // ReSharper disable once AsyncVoidLambda
this.WhenAnyValue(x => x.Project.Settings.IgnoreOpacity).Subscribe(async _ => this.WhenChanged(x => x.Project.Settings.IgnoreOpacity).DistinctUntilChanged().Subscribe(async _ =>
{ {
await Reload(); await Reload();
}); });
// ReSharper disable once AsyncVoidLambda // ReSharper disable once AsyncVoidLambda
this.WhenAnyValue(x => x.Project.Settings.IgnoreFilter).Subscribe(async _ => this.WhenChanged(x => x.Project.Settings.IgnoreFilter).DistinctUntilChanged().Subscribe(async _ =>
{ {
await Reload(); await Reload();
}); });
// ReSharper disable once AsyncVoidLambda // ReSharper disable once AsyncVoidLambda
this.WhenAnyValue(x => x.Project.Settings.IgnoreClipPath).Subscribe(async _ => this.WhenChanged(x => x.Project.Settings.IgnoreClipPath).DistinctUntilChanged().Subscribe(async _ =>
{ {
await Reload(); await Reload();
}); });
// ReSharper disable once AsyncVoidLambda // ReSharper disable once AsyncVoidLambda
this.WhenAnyValue(x => x.Project.Settings.IgnoreMask).Subscribe(async _ => this.WhenChanged(x => x.Project.Settings.IgnoreMask).DistinctUntilChanged().Subscribe(async _ =>
{ {
await Reload(); await Reload();
}); });

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

@ -1,6 +1,5 @@
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using ReactiveUI;
using Svg.Model; using Svg.Model;
namespace SvgToXaml.ViewModels; namespace SvgToXaml.ViewModels;
@ -15,21 +14,21 @@ public class ProjectViewModel : ViewModelBase
public FileItemViewModel? SelectedItem public FileItemViewModel? SelectedItem
{ {
get => _selectedItem; get => _selectedItem;
set => this.RaiseAndSetIfChanged(ref _selectedItem, value); set => SetProperty(ref _selectedItem, value);
} }
[JsonInclude] [JsonInclude]
public ObservableCollection<FileItemViewModel> Items public ObservableCollection<FileItemViewModel> Items
{ {
get => _items; get => _items;
set => this.RaiseAndSetIfChanged(ref _items, value); set => SetProperty(ref _items, value);
} }
[JsonInclude] [JsonInclude]
public SettingsViewModel Settings public SettingsViewModel Settings
{ {
get => _settings; get => _settings;
set => this.RaiseAndSetIfChanged(ref _settings, value); set => SetProperty(ref _settings, value);
} }
[JsonConstructor] [JsonConstructor]

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

@ -1,5 +1,4 @@
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using ReactiveUI;
namespace SvgToXaml.ViewModels; namespace SvgToXaml.ViewModels;
@ -20,70 +19,70 @@ public class SettingsViewModel : ViewModelBase
public bool EnableGenerateImage public bool EnableGenerateImage
{ {
get => _enableGenerateImage; get => _enableGenerateImage;
set => this.RaiseAndSetIfChanged(ref _enableGenerateImage, value); set => SetProperty(ref _enableGenerateImage, value);
} }
[JsonInclude] [JsonInclude]
public bool EnableGeneratePreview public bool EnableGeneratePreview
{ {
get => _enableGeneratePreview; get => _enableGeneratePreview;
set => this.RaiseAndSetIfChanged(ref _enableGeneratePreview, value); set => SetProperty(ref _enableGeneratePreview, value);
} }
[JsonInclude] [JsonInclude]
public bool UseResources public bool UseResources
{ {
get => _useResources; get => _useResources;
set => this.RaiseAndSetIfChanged(ref _useResources, value); set => SetProperty(ref _useResources, value);
} }
[JsonInclude] [JsonInclude]
public bool ReuseExistingResources public bool ReuseExistingResources
{ {
get => _reuseExistingResources; get => _reuseExistingResources;
set => this.RaiseAndSetIfChanged(ref _reuseExistingResources, value); set => SetProperty(ref _reuseExistingResources, value);
} }
[JsonInclude] [JsonInclude]
public bool UseCompatMode public bool UseCompatMode
{ {
get => _useCompatMode; get => _useCompatMode;
set => this.RaiseAndSetIfChanged(ref _useCompatMode, value); set => SetProperty(ref _useCompatMode, value);
} }
[JsonInclude] [JsonInclude]
public bool AddTransparentBackground public bool AddTransparentBackground
{ {
get => _addTransparentBackground; get => _addTransparentBackground;
set => this.RaiseAndSetIfChanged(ref _addTransparentBackground, value); set => SetProperty(ref _addTransparentBackground, value);
} }
[JsonInclude] [JsonInclude]
public bool IgnoreOpacity public bool IgnoreOpacity
{ {
get => _ignoreOpacity; get => _ignoreOpacity;
set => this.RaiseAndSetIfChanged(ref _ignoreOpacity, value); set => SetProperty(ref _ignoreOpacity, value);
} }
[JsonInclude] [JsonInclude]
public bool IgnoreFilter public bool IgnoreFilter
{ {
get => _ignoreFilter; get => _ignoreFilter;
set => this.RaiseAndSetIfChanged(ref _ignoreFilter, value); set => SetProperty(ref _ignoreFilter, value);
} }
[JsonInclude] [JsonInclude]
public bool IgnoreClipPath public bool IgnoreClipPath
{ {
get => _ignoreClipPath; get => _ignoreClipPath;
set => this.RaiseAndSetIfChanged(ref _ignoreClipPath, value); set => SetProperty(ref _ignoreClipPath, value);
} }
[JsonInclude] [JsonInclude]
public bool IgnoreMask public bool IgnoreMask
{ {
get => _ignoreMask; get => _ignoreMask;
set => this.RaiseAndSetIfChanged(ref _ignoreMask, value); set => SetProperty(ref _ignoreMask, value);
} }
[JsonConstructor] [JsonConstructor]

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

@ -1,7 +1,7 @@
using ReactiveUI; using CommunityToolkit.Mvvm.ComponentModel;
namespace SvgToXaml.ViewModels; namespace SvgToXaml.ViewModels;
public class ViewModelBase : ReactiveObject public class ViewModelBase : ObservableObject
{ {
} }

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

@ -1,7 +1,6 @@
using System; using System;
using Avalonia; using Avalonia;
using Avalonia.Controls.Skia; using Avalonia.Controls.Skia;
using Avalonia.ReactiveUI;
using Avalonia.Xaml.Interactions.Core; using Avalonia.Xaml.Interactions.Core;
using Avalonia.Xaml.Interactivity; using Avalonia.Xaml.Interactivity;
@ -25,21 +24,14 @@ class Program
.UsePlatformDetect() .UsePlatformDetect()
.LogToTrace() .LogToTrace()
.UseSkia() .UseSkia()
//.UseDirect2D1()
.With(new Win32PlatformOptions() .With(new Win32PlatformOptions()
{ {
UseDeferredRendering = true,
AllowEglInitialization = true,
UseWindowsUIComposition = true
}) })
.With(new X11PlatformOptions() .With(new X11PlatformOptions()
{ {
UseDeferredRendering = true
}) })
.With(new AvaloniaNativePlatformOptions() .With(new AvaloniaNativePlatformOptions()
{ {
UseDeferredRendering = true });
})
.UseReactiveUI();
} }
} }

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

@ -25,7 +25,6 @@
<Import Project="..\..\build\Avalonia.props" /> <Import Project="..\..\build\Avalonia.props" />
<Import Project="..\..\build\Avalonia.Desktop.props" /> <Import Project="..\..\build\Avalonia.Desktop.props" />
<Import Project="..\..\build\Avalonia.Diagnostics.props" /> <Import Project="..\..\build\Avalonia.Diagnostics.props" />
<Import Project="..\..\build\Avalonia.ReactiveUI.props" />
<Import Project="..\..\build\Avalonia.Markup.Xaml.Loader.props" /> <Import Project="..\..\build\Avalonia.Markup.Xaml.Loader.props" />
<Import Project="..\..\build\Avalonia.Xaml.Behaviors.props" /> <Import Project="..\..\build\Avalonia.Xaml.Behaviors.props" />
<Import Project="..\..\build\Avalonia.Controls.Skia.props" /> <Import Project="..\..\build\Avalonia.Controls.Skia.props" />

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

@ -1,4 +1,3 @@
using Avalonia.ReactiveUI;
using Avalonia.Web.Blazor; using Avalonia.Web.Blazor;
namespace SvgToXaml.Web; namespace SvgToXaml.Web;
@ -10,7 +9,6 @@ public partial class App
base.OnParametersSet(); base.OnParametersSet();
WebAppBuilder.Configure<SvgToXaml.App>() WebAppBuilder.Configure<SvgToXaml.App>()
.UseReactiveUI()
.SetupWithSingleViewLifetime(); .SetupWithSingleViewLifetime();
} }
} }