Skip to content
This repository was archived by the owner on Apr 2, 2026. It is now read-only.

Commit 1badd59

Browse files
authored
refactor: converted to ReactiveUI, builds, let's see if it runs... (#5)
1 parent 031fba6 commit 1badd59

12 files changed

Lines changed: 809 additions & 449 deletions

.claude/settings.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"permissions": {
3+
"allow": [
4+
"mcp__serena__list_dir",
5+
"Bash(dotnet build:*)"
6+
]
7+
}
8+
}

src/AStar.Dev.File.App/AStar.Dev.File.App.csproj

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
<AvaloniaResource Include="Assets\**" />
1414
</ItemGroup>
1515

16+
<ItemGroup>
17+
<None Include="FodyWeavers.xml" />
18+
</ItemGroup>
19+
1620
<ItemGroup>
1721
<PackageReference Include="Microsoft.Extensions.Logging" Version="10.0.5" />
1822
<PackageReference Include="Serilog" Version="4.3.1" />
@@ -29,7 +33,8 @@
2933
<PrivateAssets Condition="'$(Configuration)' != 'Debug'">All</PrivateAssets>
3034
</PackageReference>
3135
<PackageReference Include="Avalonia.Controls.DataGrid" Version="11.3.13" />
32-
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.2" />
36+
<PackageReference Include="Avalonia.ReactiveUI" Version="11.3.9" />
37+
<PackageReference Include="ReactiveUI.Fody" Version="19.5.41" />
3338
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.5" />
3439
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="10.0.5">
3540
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
2+
<ReactiveUI />
3+
</Weavers>

src/AStar.Dev.File.App/Program.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Avalonia;
2+
using Avalonia.ReactiveUI;
23
using System;
34

45
namespace AStar.Dev.File.App;
@@ -17,5 +18,6 @@ public static AppBuilder BuildAvaloniaApp()
1718
=> AppBuilder.Configure<App>()
1819
.UsePlatformDetect()
1920
.WithInterFont()
20-
.LogToTrace();
21+
.LogToTrace()
22+
.UseReactiveUI();
2123
}

src/AStar.Dev.File.App/ViewModels/DeletePendingViewModel.cs

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,35 @@
11
using AStar.Dev.File.App.Data;
22
using AStar.Dev.File.App.Services;
3-
using CommunityToolkit.Mvvm.ComponentModel;
4-
using CommunityToolkit.Mvvm.Input;
53
using Microsoft.EntityFrameworkCore;
4+
using ReactiveUI;
5+
using ReactiveUI.Fody.Helpers;
66
using System;
77
using System.Collections.ObjectModel;
88
using System.Linq;
9+
using System.Reactive;
910
using System.Threading.Tasks;
1011

1112
namespace AStar.Dev.File.App.ViewModels;
1213

13-
public partial class DeletePendingViewModel : ViewModelBase
14+
public class DeletePendingViewModel : ViewModelBase
1415
{
1516
private readonly IDbContextFactory<FileAppDbContext> _dbContextFactory;
1617
private readonly IFileDeleteService _fileDeleteService;
1718
private readonly IFileViewerService _fileViewerService;
1819

19-
[ObservableProperty]
20-
private bool _isDeleting;
21-
22-
[ObservableProperty]
23-
private int _pendingDeleteCount;
24-
25-
[ObservableProperty]
26-
private string _statusMessage = string.Empty;
20+
[Reactive] public bool IsDeleting { get; set; }
21+
[Reactive] public int PendingDeleteCount { get; set; }
22+
[Reactive] public string StatusMessage { get; set; } = string.Empty;
2723

2824
public ObservableCollection<ScannedFileDisplayItem> PendingDeleteFiles { get; } = [];
2925

3026
public event Action<ScannedFileDisplayItem>? ViewFileRequested;
3127

28+
public ReactiveCommand<ScannedFileDisplayItem?, Unit> TogglePendingDeleteCommand { get; }
29+
public ReactiveCommand<Unit, Unit> DeleteAllCommand { get; }
30+
public ReactiveCommand<Unit, Unit> ClearMarkingsCommand { get; }
31+
public ReactiveCommand<ScannedFileDisplayItem?, Unit> ViewFileCommand { get; }
32+
3233
public DeletePendingViewModel(
3334
IDbContextFactory<FileAppDbContext> dbContextFactory,
3435
IFileDeleteService fileDeleteService,
@@ -39,10 +40,18 @@ public DeletePendingViewModel(
3940
_fileViewerService = fileViewerService;
4041
_fileViewerService.FileViewRequested += item => ViewFileRequested?.Invoke(item);
4142

43+
TogglePendingDeleteCommand = ReactiveCommand.CreateFromTask<ScannedFileDisplayItem?>(TogglePendingDelete);
44+
45+
var canDeleteAll = this.WhenAnyValue(x => x.IsDeleting, x => x.PendingDeleteCount,
46+
(deleting, count) => !deleting && count > 0);
47+
DeleteAllCommand = ReactiveCommand.CreateFromTask(DeleteAll, canDeleteAll);
48+
49+
ClearMarkingsCommand = ReactiveCommand.CreateFromTask(ClearMarkings);
50+
ViewFileCommand = ReactiveCommand.CreateFromTask<ScannedFileDisplayItem?>(ViewFile);
51+
4252
_ = LoadPendingFilesAsync();
4353
}
4454

45-
[RelayCommand]
4655
private async Task TogglePendingDelete(ScannedFileDisplayItem? item)
4756
{
4857
if (item is null) return;
@@ -58,7 +67,6 @@ private async Task TogglePendingDelete(ScannedFileDisplayItem? item)
5867
await LoadPendingFilesAsync();
5968
}
6069

61-
[RelayCommand(CanExecute = nameof(CanDeleteAll))]
6270
private async Task DeleteAll()
6371
{
6472
if (PendingDeleteFiles.Count == 0)
@@ -95,9 +103,6 @@ private async Task DeleteAll()
95103
}
96104
}
97105

98-
private bool CanDeleteAll() => !IsDeleting && PendingDeleteFiles.Count > 0;
99-
100-
[RelayCommand]
101106
private async Task ClearMarkings()
102107
{
103108
if (PendingDeleteFiles.Count == 0)
@@ -116,7 +121,6 @@ private async Task ClearMarkings()
116121
await LoadPendingFilesAsync();
117122
}
118123

119-
[RelayCommand]
120124
private async Task ViewFile(ScannedFileDisplayItem? item)
121125
{
122126
await _fileViewerService.ViewFileAsync(item);
@@ -137,7 +141,6 @@ private async Task LoadPendingFilesAsync()
137141
files.ForEach(file => PendingDeleteFiles.Add(new ScannedFileDisplayItem(file)));
138142

139143
PendingDeleteCount = PendingDeleteFiles.Count;
140-
DeleteAllCommand.NotifyCanExecuteChanged();
141144
}
142145
catch (Exception ex)
143146
{

0 commit comments

Comments
 (0)