Error handling, better path remembrance

This commit is contained in:
2022-05-24 19:16:37 +02:00
parent c08e345c2f
commit 518cc350ad
5 changed files with 64 additions and 31 deletions

View File

@@ -4,6 +4,7 @@ using DynamicData;
using FileTime.App.Core.Models;
using FileTime.App.Core.Models.Enums;
using FileTime.App.Core.Services;
using FileTime.Core.Helper;
using FileTime.Core.Models;
using MoreLinq;
using MvvmGen;
@@ -15,6 +16,8 @@ namespace FileTime.App.Core.ViewModels;
[Inject(typeof(IItemNameConverterService), "_itemNameConverterService")]
public abstract partial class ItemViewModel : IItemViewModel
{
private ITabViewModel? _parentTab;
[Property]
private IItem? _baseItem;
@@ -44,6 +47,8 @@ public abstract partial class ItemViewModel : IItemViewModel
public void Init(IItem item, ITabViewModel parentTab, ItemViewModelType itemViewModelType)
{
_parentTab = parentTab;
var sourceCollection = itemViewModelType switch
{
ItemViewModelType.Main => parentTab.CurrentItemsCollectionObservable,
@@ -51,21 +56,21 @@ public abstract partial class ItemViewModel : IItemViewModel
ItemViewModelType.SelectedChild => parentTab.SelectedsChildrenCollectionObservable,
_ => throw new InvalidEnumArgumentException()
};
BaseItem = item;
DisplayName = _appState.SearchText.Select(s => _itemNameConverterService.GetDisplayName(item.DisplayName, s));
DisplayNameText = item.DisplayName;
IsMarked = itemViewModelType is ItemViewModelType.Main
IsMarked = itemViewModelType is ItemViewModelType.Main
? parentTab.MarkedItems.ToCollection().Select(m => m.Any(i => i.Path == item.FullName?.Path))
: Observable.Return(false);
IsSelected = itemViewModelType is ItemViewModelType.Main
? parentTab.CurrentSelectedItem.Select(EqualsTo)
: Observable.Return(false);
: Observable.Return(IsInDeespestPath());
IsAlternative = sourceCollection.Select(c => c?.Index().FirstOrDefault(i => EqualsTo(i.Value)).Key % 2 == 0);
ViewMode = Observable.CombineLatest(IsMarked, IsSelected, IsAlternative, GenerateViewMode).Throttle(TimeSpan.FromMilliseconds(10));
Attributes = item.Attributes;
CreatedAt = item.CreatedAt;
@@ -86,4 +91,19 @@ public abstract partial class ItemViewModel : IItemViewModel
{
return BaseItem?.FullName?.Path is string path && path == itemViewModel?.BaseItem?.FullName?.Path;
}
private bool IsInDeespestPath()
{
if (_parentTab?.Tab?.LastDeepestSelectedPath is null
|| BaseItem?.FullName is null)
{
return false;
}
var ownFullName = BaseItem.FullName;
var deepestPath = _parentTab.Tab.LastDeepestSelectedPath;
var commonPath = new FullName(PathHelper.GetCommonPath(ownFullName.Path, deepestPath.Path));
return commonPath.Path == ownFullName.Path;
}
}