From 308ee40fe941f79ad1ec4f5bfd391fbd5a59fe76 Mon Sep 17 00:00:00 2001 From: erri120 Date: Wed, 4 Sep 2024 15:24:45 +0200 Subject: [PATCH] Temp fix Waiting for https://github.com/AvaloniaUI/Avalonia.Controls.TreeDataGrid/pull/304 --- .../Pages/LibraryPage/LibraryItemModel.cs | 11 +++++++---- .../LibraryPage/NexusModsModPageLibraryItemModel.cs | 4 ++-- src/NexusMods.App.UI/Pages/LocalFileDataProvider.cs | 4 ++-- src/NexusMods.App.UI/Pages/NexusModsDataProvider.cs | 2 +- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/NexusMods.App.UI/Pages/LibraryPage/LibraryItemModel.cs b/src/NexusMods.App.UI/Pages/LibraryPage/LibraryItemModel.cs index 7fb69a31e4..2bf17a2193 100644 --- a/src/NexusMods.App.UI/Pages/LibraryPage/LibraryItemModel.cs +++ b/src/NexusMods.App.UI/Pages/LibraryPage/LibraryItemModel.cs @@ -19,7 +19,10 @@ public class LibraryItemModel : TreeDataGridItemModel ItemSize { get; } = new(Size.Zero); + + // TODO: turn this back into a `Size` + // NOTE(erri120): requires https://github.com/AvaloniaUI/Avalonia.Controls.TreeDataGrid/pull/304 + public BindableReactiveProperty ItemSize { get; } = new(Size.Zero.ToString()); public BindableReactiveProperty Version { get; set; } = new("-"); public IObservable> LinkedLoadoutItemsObservable { get; init; } = System.Reactive.Linq.Observable.Empty>(); @@ -158,13 +161,13 @@ public static IColumn CreateVersionColumn() public static IColumn CreateSizeColumn() { - return new CustomTextColumn( + return new CustomTextColumn( header: "SIZE", getter: model => model.ItemSize.Value, options: new TextColumnOptions { - CompareAscending = static (a, b) => a is null ? -1 : a.ItemSize.Value.CompareTo(b?.ItemSize.Value ?? Size.Zero), - CompareDescending = static (a, b) => b is null ? -1 : b.ItemSize.Value.CompareTo(a?.ItemSize.Value ?? Size.Zero), + CompareAscending = static (a, b) => a is null ? -1 : a.ItemSize.Value.CompareTo(b?.ItemSize.Value ?? "0 B"), + CompareDescending = static (a, b) => b is null ? -1 : b.ItemSize.Value.CompareTo(a?.ItemSize.Value ?? "0 B"), IsTextSearchEnabled = false, CanUserResizeColumn = true, CanUserSortColumn = true, diff --git a/src/NexusMods.App.UI/Pages/LibraryPage/NexusModsModPageLibraryItemModel.cs b/src/NexusMods.App.UI/Pages/LibraryPage/NexusModsModPageLibraryItemModel.cs index edd68a3918..3c48db746d 100644 --- a/src/NexusMods.App.UI/Pages/LibraryPage/NexusModsModPageLibraryItemModel.cs +++ b/src/NexusMods.App.UI/Pages/LibraryPage/NexusModsModPageLibraryItemModel.cs @@ -21,12 +21,12 @@ public NexusModsModPageLibraryItemModel() : base(default(LibraryItemId)) // TODO: different selection, need to check with design if (model.LibraryItems.TryGetFirst(static x => x.ToLibraryFile().ToDownloadedFile().ToNexusModsLibraryFile().IsValid(), out var libraryItem)) { - model.ItemSize.Value = libraryItem.ToLibraryFile().Size; + model.ItemSize.Value = libraryItem.ToLibraryFile().Size.ToString(); model.Version.Value = libraryItem.ToLibraryFile().ToDownloadedFile().ToNexusModsLibraryFile().FileMetadata.Version; } else { - model.ItemSize.Value = Size.Zero; + model.ItemSize.Value = Size.Zero.ToString(); model.Version.Value = "-"; } }) diff --git a/src/NexusMods.App.UI/Pages/LocalFileDataProvider.cs b/src/NexusMods.App.UI/Pages/LocalFileDataProvider.cs index 339b612029..e1d015c84a 100644 --- a/src/NexusMods.App.UI/Pages/LocalFileDataProvider.cs +++ b/src/NexusMods.App.UI/Pages/LocalFileDataProvider.cs @@ -54,7 +54,7 @@ private LibraryItemModel ToLibraryItemModel(LibraryFile.ReadOnly libraryFile) LinkedLoadoutItemsObservable = linkedLoadoutItemsObservable, }; - model.ItemSize.Value = libraryFile.Size; + model.ItemSize.Value = libraryFile.Size.ToString(); return model; } @@ -96,7 +96,7 @@ public IObservable> ObserveNestedLibraryI LibraryItemsObservable = UIObservableExtensions.ReturnFactory(() => new ChangeSet([new Change(ChangeReason.Add, entityId, LibraryItem.Load(_connection.Db, entityId))])), }; - model.ItemSize.Value = libraryFile.Size; + model.ItemSize.Value = libraryFile.Size.ToString(); return (LibraryItemModel)model; }); } diff --git a/src/NexusMods.App.UI/Pages/NexusModsDataProvider.cs b/src/NexusMods.App.UI/Pages/NexusModsDataProvider.cs index 95499db61b..9435d4c08c 100644 --- a/src/NexusMods.App.UI/Pages/NexusModsDataProvider.cs +++ b/src/NexusMods.App.UI/Pages/NexusModsDataProvider.cs @@ -62,7 +62,7 @@ private LibraryItemModel ToLibraryItemModel(NexusModsLibraryFile.ReadOnly nexusM LinkedLoadoutItemsObservable = linkedLoadoutItemsObservable, }; - model.ItemSize.Value = nexusModsLibraryFile.AsDownloadedFile().AsLibraryFile().Size; + model.ItemSize.Value = nexusModsLibraryFile.AsDownloadedFile().AsLibraryFile().Size.ToString(); model.Version.Value = nexusModsLibraryFile.FileMetadata.Version; return model;