Select previous/next item
This commit is contained in:
@@ -10,9 +10,9 @@ namespace FileTime.App.Core.ViewModels
|
|||||||
ITab? Tab { get; }
|
ITab? Tab { get; }
|
||||||
int TabNumber { get; }
|
int TabNumber { get; }
|
||||||
IObservable<bool> IsSelected { get; }
|
IObservable<bool> IsSelected { get; }
|
||||||
IObservable<IContainer?>? CurrentLocation { get; }
|
IObservable<IContainer?> CurrentLocation { get; }
|
||||||
IObservable<IItemViewModel?>? CurrentSelectedItem { get; }
|
IObservable<IItemViewModel?> CurrentSelectedItem { get; }
|
||||||
IObservable<IEnumerable<IItemViewModel>>? CurrentItems { get; }
|
IObservable<IEnumerable<IItemViewModel>> CurrentItems { get; }
|
||||||
IObservable<IEnumerable<FullName>> MarkedItems { get; }
|
IObservable<IEnumerable<FullName>> MarkedItems { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
using FileTime.App.Core.ViewModels;
|
||||||
|
using FileTime.Core.Models;
|
||||||
|
|
||||||
|
namespace FileTime.App.Core.Extensions
|
||||||
|
{
|
||||||
|
public static class ViewModelExtensions
|
||||||
|
{
|
||||||
|
public static IAbsolutePath ToAbsolutePath(this IItemViewModel itemViewModel)
|
||||||
|
{
|
||||||
|
var item = itemViewModel.BaseItem ?? throw new ArgumentException($"{nameof(itemViewModel)} does not have {nameof(IItemViewModel.BaseItem)}");
|
||||||
|
return new AbsolutePath(item.Provider, item.FullName ?? throw new ArgumentException($"Parameter does not have {nameof(IItem.FullName)}"), item.Type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\Core\FileTime.Core.Abstraction\FileTime.Core.Abstraction.csproj" />
|
<ProjectReference Include="..\..\Core\FileTime.Core.Abstraction\FileTime.Core.Abstraction.csproj" />
|
||||||
|
<ProjectReference Include="..\..\Core\FileTime.Core.Models\FileTime.Core.Models.csproj" />
|
||||||
<ProjectReference Include="..\FileTime.App.Core.Abstraction\FileTime.App.Core.Abstraction.csproj" />
|
<ProjectReference Include="..\FileTime.App.Core.Abstraction\FileTime.App.Core.Abstraction.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System.Reactive.Linq;
|
using System.Reactive.Linq;
|
||||||
using FileTime.App.Core.Command;
|
using FileTime.App.Core.Command;
|
||||||
|
using FileTime.App.Core.Extensions;
|
||||||
using FileTime.App.Core.ViewModels;
|
using FileTime.App.Core.ViewModels;
|
||||||
using FileTime.Core.Models;
|
using FileTime.Core.Models;
|
||||||
|
|
||||||
@@ -12,14 +13,16 @@ namespace FileTime.App.Core.Services
|
|||||||
private ITabViewModel? _selectedTab;
|
private ITabViewModel? _selectedTab;
|
||||||
private IContainer? _currentLocation;
|
private IContainer? _currentLocation;
|
||||||
private IItemViewModel? _currentSelectedItem;
|
private IItemViewModel? _currentSelectedItem;
|
||||||
|
private List<IItemViewModel> _currentItems = new();
|
||||||
|
|
||||||
public CommandHandlerService(IAppState appState)
|
public CommandHandlerService(IAppState appState)
|
||||||
{
|
{
|
||||||
_appState = appState;
|
_appState = appState;
|
||||||
|
|
||||||
_appState.SelectedTab.Subscribe(t => _selectedTab = t);
|
_appState.SelectedTab.Subscribe(t => _selectedTab = t);
|
||||||
_appState.SelectedTab.Select(t => t == null ? Observable.Return<IContainer?>(null) : t.CurrentLocation!).Switch().Subscribe(l => _currentLocation = l);
|
_appState.SelectedTab.Select(t => t == null ? Observable.Return<IContainer?>(null) : t.CurrentLocation).Switch().Subscribe(l => _currentLocation = l);
|
||||||
_appState.SelectedTab.Select(t => t == null ? Observable.Return<IItemViewModel?>(null) : t.CurrentSelectedItem!).Switch().Subscribe(l => _currentSelectedItem = l);
|
_appState.SelectedTab.Select(t => t == null ? Observable.Return<IItemViewModel?>(null) : t.CurrentSelectedItem).Switch().Subscribe(l => _currentSelectedItem = l);
|
||||||
|
_appState.SelectedTab.Select(t => t == null ? Observable.Return(Enumerable.Empty<IItemViewModel>()) : t.CurrentItems).Switch().Subscribe(i => _currentItems = i.ToList());
|
||||||
|
|
||||||
_commandHandlers = new Dictionary<Commands, Func<Task>>
|
_commandHandlers = new Dictionary<Commands, Func<Task>>
|
||||||
{
|
{
|
||||||
@@ -44,9 +47,9 @@ namespace FileTime.App.Core.Services
|
|||||||
{Commands.GoUp, GoUp},
|
{Commands.GoUp, GoUp},
|
||||||
//{Commands.HardDelete, HardDelete},
|
//{Commands.HardDelete, HardDelete},
|
||||||
//{Commands.Mark, MarkCurrentItem},
|
//{Commands.Mark, MarkCurrentItem},
|
||||||
//{Commands.MoveCursorDown, MoveCursorDown},
|
{Commands.MoveCursorDown, MoveCursorDown},
|
||||||
//{Commands.MoveCursorDownPage, MoveCursorDownPage},
|
//{Commands.MoveCursorDownPage, MoveCursorDownPage},
|
||||||
//{Commands.MoveCursorUp, MoveCursorUp},
|
{Commands.MoveCursorUp, MoveCursorUp},
|
||||||
//{Commands.MoveCursorUpPage, MoveCursorUpPage},
|
//{Commands.MoveCursorUpPage, MoveCursorUpPage},
|
||||||
//{Commands.MoveToFirst, MoveToFirst},
|
//{Commands.MoveToFirst, MoveToFirst},
|
||||||
//{Commands.MoveToLast, MoveToLast},
|
//{Commands.MoveToLast, MoveToLast},
|
||||||
@@ -100,5 +103,27 @@ namespace FileTime.App.Core.Services
|
|||||||
if (_currentLocation?.Parent is not IAbsolutePath parentPath || await parentPath.ResolveAsync() is not IContainer newContainer) return;
|
if (_currentLocation?.Parent is not IAbsolutePath parentPath || await parentPath.ResolveAsync() is not IContainer newContainer) return;
|
||||||
_selectedTab?.Tab?.SetCurrentLocation(newContainer);
|
_selectedTab?.Tab?.SetCurrentLocation(newContainer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Task MoveCursorDown()
|
||||||
|
{
|
||||||
|
SelectNewSelectedItem(i => i.SkipWhile(i => i != _currentSelectedItem).Skip(1).FirstOrDefault());
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Task MoveCursorUp()
|
||||||
|
{
|
||||||
|
SelectNewSelectedItem(i => i.TakeWhile(i => i != _currentSelectedItem).LastOrDefault());
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SelectNewSelectedItem(Func<IEnumerable<IItemViewModel>, IItemViewModel?> getNewSelected)
|
||||||
|
{
|
||||||
|
if (_selectedTab is null || _currentLocation is null) return;
|
||||||
|
|
||||||
|
var newSelectedItem = getNewSelected(_currentItems);
|
||||||
|
if (newSelectedItem == null) return;
|
||||||
|
|
||||||
|
_selectedTab.Tab?.SetSelectedItem(newSelectedItem.ToAbsolutePath());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -22,9 +22,9 @@ namespace FileTime.App.Core.ViewModels
|
|||||||
|
|
||||||
public IObservable<bool> IsSelected { get; }
|
public IObservable<bool> IsSelected { get; }
|
||||||
|
|
||||||
public IObservable<IContainer?>? CurrentLocation { get; private set; }
|
public IObservable<IContainer?> CurrentLocation { get; private set; } = null!;
|
||||||
public IObservable<IItemViewModel?>? CurrentSelectedItem { get; private set; }
|
public IObservable<IItemViewModel?> CurrentSelectedItem { get; private set; } = null!;
|
||||||
public IObservable<IEnumerable<IItemViewModel>>? CurrentItems { get; private set; }
|
public IObservable<IEnumerable<IItemViewModel>> CurrentItems { get; private set; } = null!;
|
||||||
public IObservable<IEnumerable<FullName>> MarkedItems { get; }
|
public IObservable<IEnumerable<FullName>> MarkedItems { get; }
|
||||||
|
|
||||||
public TabViewModel(
|
public TabViewModel(
|
||||||
|
|||||||
@@ -17,5 +17,6 @@ namespace FileTime.Core.Models
|
|||||||
bool CanRename { get; }
|
bool CanRename { get; }
|
||||||
IContentProvider Provider { get; }
|
IContentProvider Provider { get; }
|
||||||
string? Attributes { get; }
|
string? Attributes { get; }
|
||||||
|
AbsolutePathType Type { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -22,5 +22,6 @@ namespace FileTime.Core.Models
|
|||||||
{
|
{
|
||||||
BehaviorSubject<bool> IsLoading { get; } = new BehaviorSubject<bool>(false);
|
BehaviorSubject<bool> IsLoading { get; } = new BehaviorSubject<bool>(false);
|
||||||
IObservable<bool> IContainer.IsLoading => IsLoading.AsObservable();
|
IObservable<bool> IContainer.IsLoading => IsLoading.AsObservable();
|
||||||
|
public AbsolutePathType Type => AbsolutePathType.Container;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -15,5 +15,8 @@ namespace FileTime.Core.Models
|
|||||||
SupportsDelete CanDelete,
|
SupportsDelete CanDelete,
|
||||||
bool CanRename,
|
bool CanRename,
|
||||||
string? Attributes,
|
string? Attributes,
|
||||||
IContentProvider Provider) : IElement;
|
IContentProvider Provider) : IElement
|
||||||
|
{
|
||||||
|
public AbsolutePathType Type => AbsolutePathType.Element;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -39,6 +39,8 @@ namespace FileTime.Core.Services
|
|||||||
|
|
||||||
IObservable<bool> IContainer.IsLoading => IsLoading.AsObservable();
|
IObservable<bool> IContainer.IsLoading => IsLoading.AsObservable();
|
||||||
|
|
||||||
|
public AbsolutePathType Type => AbsolutePathType.Container;
|
||||||
|
|
||||||
protected ContentProviderBase(string name)
|
protected ContentProviderBase(string name)
|
||||||
{
|
{
|
||||||
DisplayName = Name = name;
|
DisplayName = Name = name;
|
||||||
|
|||||||
@@ -40,11 +40,7 @@ namespace FileTime.Core.Services
|
|||||||
.Publish(null)
|
.Publish(null)
|
||||||
.RefCount();
|
.RefCount();
|
||||||
|
|
||||||
CurrentSelectedItem.Subscribe(s =>
|
CurrentSelectedItem.Subscribe(s => _currentSelectedItemCached = s);
|
||||||
{
|
|
||||||
_currentSelectedItemCached = s;
|
|
||||||
_currentSelectedItem.OnNext(s);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<IEnumerable<IItem>> MapItems(IReadOnlyList<IAbsolutePath> items)
|
private async Task<IEnumerable<IItem>> MapItems(IReadOnlyList<IAbsolutePath> items)
|
||||||
@@ -83,7 +79,7 @@ namespace FileTime.Core.Services
|
|||||||
private IObservable<IAbsolutePath?> GetSelectedItemByLocation(IContainer? currentLocation)
|
private IObservable<IAbsolutePath?> GetSelectedItemByLocation(IContainer? currentLocation)
|
||||||
{
|
{
|
||||||
//TODO:
|
//TODO:
|
||||||
return currentLocation?.Items?.Select(i => i.FirstOrDefault()) ?? Observable.Never((IAbsolutePath?)null);
|
return currentLocation?.Items?.Select(i => i.Count == 0 ? null : i[0]) ?? Observable.Return((IAbsolutePath?)null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetCurrentLocation(IContainer newLocation) => _currentLocation.OnNext(newLocation);
|
public void SetCurrentLocation(IContainer newLocation) => _currentLocation.OnNext(newLocation);
|
||||||
|
|||||||
Reference in New Issue
Block a user