RapidTravel display name

This commit is contained in:
2023-07-28 02:21:29 +02:00
parent 0db7949037
commit 12c9aa039a
8 changed files with 27 additions and 27 deletions

View File

@@ -1,4 +1,5 @@
using System.Collections.ObjectModel;
using DeclarativeProperty;
using FileTime.App.Core.Models.Enums;
using FileTime.App.Core.ViewModels.Timeline;
@@ -10,7 +11,7 @@ public interface IAppState
IObservable<ITabViewModel?> SelectedTab { get; }
IObservable<string?> SearchText { get; }
IObservable<ViewMode> ViewMode { get; }
string RapidTravelText { get; set; }
DeclarativeProperty<string?> RapidTravelText { get; }
ITabViewModel? CurrentSelectedTab { get; }
ITimelineViewModel TimelineViewModel { get; }

View File

@@ -9,7 +9,7 @@ namespace FileTime.App.Core.ViewModels;
public interface IItemViewModel : IInitable<IItem, ITabViewModel, ItemViewModelType>
{
IItem? BaseItem { get; set; }
IObservable<IReadOnlyList<ItemNamePart>>? DisplayName { get; set; }
IDeclarativeProperty<IReadOnlyList<ItemNamePart>>? DisplayName { get; }
string? DisplayNameText { get; set; }
IDeclarativeProperty<bool> IsSelected { get; set; }
IObservable<bool>? IsMarked { get; set; }

View File

@@ -225,7 +225,7 @@ public class NavigationUserCommandHandlerService : UserCommandHandlerServiceBase
if (_currentSelectedItem?.Value is not IContainerViewModel containerViewModel || containerViewModel.Container is null)
return;
_appState.RapidTravelText = "";
await _appState.RapidTravelText.SetValue("");
if (_selectedTab?.Tab is { } tab)
{
await tab.SetCurrentLocation(containerViewModel.Container);
@@ -240,7 +240,7 @@ public class NavigationUserCommandHandlerService : UserCommandHandlerServiceBase
return;
}
_appState.RapidTravelText = "";
await _appState.RapidTravelText.SetValue("");
if (_selectedTab?.Tab is { } tab)
{
await tab.SetCurrentLocation(newContainer);

View File

@@ -1,6 +1,7 @@
using System.Collections.ObjectModel;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using DeclarativeProperty;
using DynamicData;
using FileTime.App.Core.Models.Enums;
using FileTime.App.Core.ViewModels.Timeline;
@@ -25,11 +26,11 @@ public abstract partial class AppStateBase : IAppState
public IObservable<ITabViewModel?> SelectedTab { get; private set; }
public ITabViewModel? CurrentSelectedTab { get; private set; }
[Property] private string _rapidTravelText = "";
public DeclarativeProperty<string?> RapidTravelText { get; private set; }
partial void OnInitialize()
{
RapidTravelText = new("");
ViewMode = _viewMode.AsObservable();
var tabsObservable = _tabs.Connect();

View File

@@ -21,8 +21,6 @@ public abstract partial class ItemViewModel : IItemViewModel
[Property] private IItem? _baseItem;
[Property] private IObservable<IReadOnlyList<ItemNamePart>>? _displayName;
[Property] private string? _displayNameText;
[Property] private IDeclarativeProperty<bool> _isSelected;
@@ -37,6 +35,8 @@ public abstract partial class ItemViewModel : IItemViewModel
[Property] private IDeclarativeProperty<bool> _isAlternative;
public IDeclarativeProperty<IReadOnlyList<ItemNamePart>>? DisplayName { get; private set; }
public void Init(IItem item, ITabViewModel parentTab, ItemViewModelType itemViewModelType)
{
_parentTab = parentTab;
@@ -49,8 +49,14 @@ public abstract partial class ItemViewModel : IItemViewModel
_ => throw new InvalidEnumArgumentException()
};
var displayName = itemViewModelType switch
{
ItemViewModelType.Main => _appState.RapidTravelText.Map(s => (IReadOnlyList<ItemNamePart>) _itemNameConverterService.GetDisplayName(item.DisplayName, s)),
_ => new DeclarativeProperty<IReadOnlyList<ItemNamePart>>(new List<ItemNamePart> {new (item.DisplayName)}),
};
BaseItem = item;
DisplayName = _appState.SearchText.Select(s => _itemNameConverterService.GetDisplayName(item.DisplayName, s));
DisplayName = displayName;
DisplayNameText = item.DisplayName;
IsMarked = itemViewModelType is ItemViewModelType.Main
@@ -79,6 +85,7 @@ public abstract partial class ItemViewModel : IItemViewModel
_ => ItemViewMode.Default
};
public bool EqualsTo(IItemViewModel? itemViewModel)
{
return BaseItem?.FullName?.Path is string path && path == itemViewModel?.BaseItem?.FullName?.Path;

View File

@@ -88,19 +88,6 @@ public partial class TabViewModel : ITabViewModel
(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
{