Item ordering
This commit is contained in:
@@ -22,6 +22,7 @@ public class ToolUserCommandHandlerService : UserCommandHandlerServiceBase
|
||||
private readonly IContentAccessorFactory _contentAccessorFactory;
|
||||
private IDeclarativeProperty<IContainer?>? _currentLocation;
|
||||
private IDeclarativeProperty<IItemViewModel?>? _currentSelectedItem;
|
||||
private ITabViewModel? _currentSelectedTab;
|
||||
|
||||
public ToolUserCommandHandlerService(
|
||||
IAppState appState,
|
||||
@@ -42,6 +43,7 @@ public class ToolUserCommandHandlerService : UserCommandHandlerServiceBase
|
||||
_contentAccessorFactory = contentAccessorFactory;
|
||||
SaveCurrentLocation(l => _currentLocation = l);
|
||||
SaveCurrentSelectedItem(i => _currentSelectedItem = i);
|
||||
SaveSelectedTab(t => _currentSelectedTab = t);
|
||||
|
||||
AddCommandHandlers(new IUserCommandHandler[]
|
||||
{
|
||||
@@ -49,9 +51,17 @@ public class ToolUserCommandHandlerService : UserCommandHandlerServiceBase
|
||||
new TypeUserCommandHandler<CopyNativePathCommand>(CopyNativePath),
|
||||
new TypeUserCommandHandler<CopyBase64Command>(CopyBase64),
|
||||
new TypeUserCommandHandler<SearchCommand>(Search),
|
||||
new TypeUserCommandHandler<SortItemsCommand>(SortItems),
|
||||
});
|
||||
}
|
||||
|
||||
private async Task SortItems(SortItemsCommand sortItemsCommand)
|
||||
{
|
||||
if (_currentSelectedTab is null) return;
|
||||
|
||||
await _currentSelectedTab.Ordering.SetValue(sortItemsCommand.Ordering);
|
||||
}
|
||||
|
||||
private async Task CopyBase64()
|
||||
{
|
||||
var item = _currentSelectedItem?.Value?.BaseItem;
|
||||
|
||||
@@ -49,6 +49,10 @@ public class DefaultIdentifiableCommandHandlerRegister : IStartupHandler
|
||||
AddUserCommand(RenameCommand.Instance);
|
||||
AddUserCommand(RunOrOpenCommand.Instance);
|
||||
AddUserCommand(StartCommandSchedulerCommand.Instance);
|
||||
AddUserCommand(SortItemsCommand.OrderByNameCommand);
|
||||
AddUserCommand(SortItemsCommand.OrderByNameDescCommand);
|
||||
AddUserCommand(SortItemsCommand.OrderByDateCommand);
|
||||
AddUserCommand(SortItemsCommand.OrderByDateDescCommand);
|
||||
AddUserCommand(IdentifiableSearchCommand.SearchByNameContains);
|
||||
AddUserCommand(SwitchToTabCommand.SwitchToLastTab);
|
||||
AddUserCommand(SwitchToTabCommand.SwitchToTab1);
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reactive.Linq;
|
||||
using DeclarativeProperty;
|
||||
using DynamicData;
|
||||
using DynamicData.Binding;
|
||||
using FileTime.App.Core.Extensions;
|
||||
using FileTime.App.Core.Models;
|
||||
using FileTime.App.Core.Models.Enums;
|
||||
using FileTime.App.Core.Services;
|
||||
using FileTime.Core.Enums;
|
||||
@@ -45,6 +48,7 @@ public partial class TabViewModel : ITabViewModel
|
||||
public IObservable<IChangeSet<FullName>> MarkedItems { get; }
|
||||
public IDeclarativeProperty<ObservableCollection<IItemViewModel>?> SelectedsChildren { get; private set; }
|
||||
public IDeclarativeProperty<ObservableCollection<IItemViewModel>?> ParentsChildren { get; private set; }
|
||||
public DeclarativeProperty<ItemOrdering?> Ordering { get; } = new(ItemOrdering.Name);
|
||||
|
||||
|
||||
public TabViewModel(
|
||||
@@ -71,14 +75,56 @@ public partial class TabViewModel : ITabViewModel
|
||||
|
||||
CurrentLocation = tab.CurrentLocation;
|
||||
|
||||
CurrentItems = tab.CurrentItems
|
||||
.Map((items, _) =>
|
||||
Task.FromResult<ObservableCollection<IItemViewModel>?>(
|
||||
items?.Selecting<IItem, IItemViewModel>(
|
||||
i => MapItemToViewModel(i, ItemViewModelType.Main)
|
||||
CurrentItems =
|
||||
tab.CurrentItems
|
||||
.Map((items, _) =>
|
||||
Task.FromResult<ObservableCollection<IItemViewModel>?>(
|
||||
items?.Selecting<IItem, IItemViewModel>(
|
||||
i => MapItemToViewModel(i, ItemViewModelType.Main)
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
).CombineLatest(
|
||||
Ordering,
|
||||
(items, ordering) =>
|
||||
{
|
||||
if (items is null) return Task.FromResult<ObservableCollection<IItemViewModel>?>(null);
|
||||
/*Expression<Func<IItemViewModel, object?>> orderExpression = ordering switch
|
||||
{
|
||||
ItemOrdering.Name or ItemOrdering.NameDesc => i => i.DisplayNameText,
|
||||
ItemOrdering.LastModifyDate or ItemOrdering.LastModifyDateDesc => i => i.CreatedAt,
|
||||
_ => throw new NotImplementedException()
|
||||
};
|
||||
Expression<Func<ListSortDirection>> direction = ordering switch
|
||||
{
|
||||
ItemOrdering.Name or ItemOrdering.LastModifyDate => () => ListSortDirection.Ascending,
|
||||
ItemOrdering.NameDesc or ItemOrdering.LastModifyDateDesc => () => ListSortDirection.Descending,
|
||||
_ => throw new NotImplementedException()
|
||||
};
|
||||
return Task.FromResult((ObservableCollection<IItemViewModel>?) items.Ordering(orderExpression, direction));*/
|
||||
|
||||
ObservableCollection<IItemViewModel>? orderedItems = ordering switch
|
||||
{
|
||||
ItemOrdering.Name =>
|
||||
items
|
||||
.Ordering(i => i.BaseItem.Type)
|
||||
.ThenOrdering(i => i.DisplayNameText),
|
||||
ItemOrdering.NameDesc =>
|
||||
items
|
||||
.Ordering(i => i.BaseItem.Type)
|
||||
.ThenOrdering(i => i.DisplayNameText, ListSortDirection.Descending),
|
||||
ItemOrdering.LastModifyDate =>
|
||||
items
|
||||
.Ordering(i => i.CreatedAt),
|
||||
ItemOrdering.LastModifyDateDesc =>
|
||||
items
|
||||
.Ordering(i => i.CreatedAt, ListSortDirection.Descending),
|
||||
_ => throw new NotImplementedException()
|
||||
};
|
||||
|
||||
return Task.FromResult(orderedItems);
|
||||
}
|
||||
);
|
||||
|
||||
using var _ = Defer(
|
||||
() => CurrentItems.Subscribe(c => UpdateConsumer(c, ref _currentItemsConsumer))
|
||||
);
|
||||
@@ -127,6 +173,8 @@ public partial class TabViewModel : ITabViewModel
|
||||
|
||||
var items = parent.Items
|
||||
.Selecting(i => MapItem(i))
|
||||
.Ordering(i => i.Type)
|
||||
.ThenOrdering(i => i.Name)
|
||||
.Selecting(i => MapItemToViewModel(i, ItemViewModelType.SelectedChild));
|
||||
|
||||
return items;
|
||||
@@ -222,7 +270,7 @@ public partial class TabViewModel : ITabViewModel
|
||||
}
|
||||
}
|
||||
|
||||
public void ClearMarkedItems()
|
||||
public void ClearMarkedItems()
|
||||
=> _markedItems.Clear();
|
||||
|
||||
~TabViewModel() => Dispose(false);
|
||||
|
||||
Reference in New Issue
Block a user