Ordering improvements

This commit is contained in:
2023-08-28 22:09:33 +02:00
parent c7b29abca4
commit 53a97e2a42
7 changed files with 37 additions and 26 deletions

View File

@@ -26,4 +26,5 @@
</ItemGroup>
</Project>

View File

@@ -0,0 +1,8 @@
using DeclarativeProperty;
namespace FileTime.Core.Traits;
public interface ISizeProvider
{
IDeclarativeProperty<long> Size { get; }
}

View File

@@ -7,6 +7,7 @@ using DynamicData;
using FileTime.Core.Helper;
using FileTime.Core.Models;
using FileTime.Core.Timeline;
using FileTime.Core.Traits;
using ObservableComputations;
using IContainer = FileTime.Core.Models.IContainer;
@@ -100,18 +101,22 @@ public class Tab : ITab
_ => throw new NotImplementedException()
};
return (itemComparer, order);
return (itemComparer, order, ordering is not ItemOrdering.Name and not ItemOrdering.NameDesc);
}),
(items, ordering) =>
{
if (items is null) return Task.FromResult<ObservableCollection<IItem>?>(null);
var (itemComparer, order) = ordering;
var (itemComparer, order, addName) = ordering;
ObservableCollection<IItem>? orderedItems = items
var primaryOrderedItems = items
.Ordering(i => i.Type)
.ThenOrdering(itemComparer, order);
ObservableCollection<IItem>? orderedItems = addName
? primaryOrderedItems.ThenOrdering(i => i.DisplayName)
: primaryOrderedItems;
return Task.FromResult(orderedItems);
}
);
@@ -124,7 +129,7 @@ public class Tab : ITab
var itemSelectingContext = new LastItemSelectingContext(CurrentLocation.Value);
var lastItemSelectingContext = _lastItemSelectingContext;
if (items == null || items.Count == 0) return Task.FromResult<AbsolutePath?>(null);
_lastItemSelectingContext = itemSelectingContext;
if (selected != null)
{
@@ -153,23 +158,23 @@ public class Tab : ITab
});
DeclarativePropertyHelpers.CombineLatest(
CurrentItems,
CurrentSelectedItem,
(items, selected) =>
{
if(items is null || selected is null) return Task.FromResult<IEnumerable<AbsolutePath>?>(null);
var primaryCandidates = items.SkipWhile(i => i.FullName is {Path: var p} && p != selected.Path.Path).Skip(1);
var secondaryCandidates = items.TakeWhile(i => i.FullName is {Path: var p} && p != selected.Path.Path).Reverse();
var candidates = primaryCandidates
.Concat(secondaryCandidates)
.Select(c => new AbsolutePath(_timelessContentProvider, c));
CurrentItems,
CurrentSelectedItem,
(items, selected) =>
{
if (items is null || selected is null) return Task.FromResult<IEnumerable<AbsolutePath>?>(null);
var primaryCandidates = items.SkipWhile(i => i.FullName is {Path: var p} && p != selected.Path.Path).Skip(1);
var secondaryCandidates = items.TakeWhile(i => i.FullName is {Path: var p} && p != selected.Path.Path).Reverse();
var candidates = primaryCandidates
.Concat(secondaryCandidates)
.Select(c => new AbsolutePath(_timelessContentProvider, c));
return Task.FromResult(candidates);
})
return Task.FromResult(candidates);
})
.Subscribe(candidates =>
{
if(candidates is null) return;
if (candidates is null) return;
_selectedItemCandidates.Clear();
_selectedItemCandidates.AddRange(candidates);
});
@@ -181,6 +186,10 @@ public class Tab : ITab
{
return element.Size;
}
else if (item is ISizeProvider sizeProvider)
{
return sizeProvider.Size.Value;
}
return -1;
}