New controls, main view

This commit is contained in:
2023-08-09 20:40:54 +02:00
parent d549733b71
commit 7dcca6363b
41 changed files with 668 additions and 234 deletions

View File

@@ -12,7 +12,7 @@ public interface IAppState
IDeclarativeProperty<ITabViewModel?> SelectedTab { get; }
IObservable<string?> SearchText { get; }
IDeclarativeProperty<ViewMode> ViewMode { get; }
DeclarativeProperty<string?> RapidTravelText { get; }
IDeclarativeProperty<string?> RapidTravelText { get; }
IDeclarativeProperty<string?> RapidTravelTextDebounced { get; }
IDeclarativeProperty<string?> ContainerStatus { get; }
List<KeyConfig> PreviousKeys { get; }
@@ -24,4 +24,5 @@ public interface IAppState
void SetSearchText(string? searchText);
Task SwitchViewModeAsync(ViewMode newViewMode);
Task SetSelectedTabAsync(ITabViewModel tabToSelect);
Task SetRapidTravelTextAsync(string? text);
}

View File

@@ -75,7 +75,7 @@ public class RapidTravelModeKeyInputHandler : IRapidTravelModeKeyInputHandler
if (_appState.RapidTravelText.Value!.Length > 0)
{
args.Handled = true;
await _appState.RapidTravelText.SetValue(
await _appState.SetRapidTravelTextAsync(
_appState.RapidTravelText.Value![..^1]
);
}
@@ -83,7 +83,7 @@ public class RapidTravelModeKeyInputHandler : IRapidTravelModeKeyInputHandler
else if (keyString.Length == 1)
{
args.Handled = true;
await _appState.RapidTravelText.SetValue(
await _appState.SetRapidTravelTextAsync(
_appState.RapidTravelText.Value + keyString.ToLower()
);
}

View File

@@ -251,7 +251,7 @@ public class NavigationUserCommandHandlerService : UserCommandHandlerServiceBase
if (_currentSelectedItem?.Value is not IContainerViewModel containerViewModel || containerViewModel.Container is null)
return;
await _appState.RapidTravelText.SetValue("");
await _appState.SetRapidTravelTextAsync("");
if (_selectedTab?.Tab is { } tab)
{
await tab.SetCurrentLocation(containerViewModel.Container);
@@ -260,13 +260,13 @@ public class NavigationUserCommandHandlerService : UserCommandHandlerServiceBase
private async Task GoUp()
{
if (_currentLocation?.Value?.Parent is not AbsolutePath parentPath ||
if (_currentLocation?.Value?.Parent is not { } parentPath ||
await parentPath.ResolveAsyncSafe() is not IContainer newContainer)
{
return;
}
await _appState.RapidTravelText.SetValue("");
await _appState.SetRapidTravelTextAsync("");
if (_selectedTab?.Tab is { } tab)
{
await tab.SetCurrentLocation(newContainer);

View File

@@ -18,6 +18,7 @@ public abstract partial class AppStateBase : IAppState
private readonly DeclarativeProperty<ITabViewModel?> _selectedTab = new();
private readonly DeclarativeProperty<ViewMode> _viewMode = new(Models.Enums.ViewMode.Default);
private readonly ObservableCollection<ITabViewModel> _tabs = new();
private readonly DeclarativeProperty<string?> _rapidTravelText;
public IDeclarativeProperty<ViewMode> ViewMode { get; }
@@ -25,7 +26,7 @@ public abstract partial class AppStateBase : IAppState
public IObservable<string?> SearchText { get; }
public IDeclarativeProperty<ITabViewModel?> SelectedTab { get; }
public DeclarativeProperty<string?> RapidTravelText { get; }
public IDeclarativeProperty<string?> RapidTravelText { get; }
public IDeclarativeProperty<string?> RapidTravelTextDebounced { get; }
public IDeclarativeProperty<string?> ContainerStatus { get; }
@@ -35,7 +36,8 @@ public abstract partial class AppStateBase : IAppState
protected AppStateBase()
{
RapidTravelText = new("");
_rapidTravelText = new ("");
RapidTravelText = _rapidTravelText.DistinctUntilChanged();
RapidTravelTextDebounced = RapidTravelText
.Debounce(v =>
string.IsNullOrEmpty(v)
@@ -83,6 +85,7 @@ public abstract partial class AppStateBase : IAppState
public async Task SwitchViewModeAsync(ViewMode newViewMode) => await _viewMode.SetValue(newViewMode);
public async Task SetSelectedTabAsync(ITabViewModel tabToSelect) => await _selectedTab.SetValue(tabToSelect);
public async Task SetRapidTravelTextAsync(string? text) => await _rapidTravelText.SetValue(text);
private ITabViewModel? GetSelectedTab(IEnumerable<ITabViewModel> tabs, ITabViewModel? expectedSelectedTab)
{

View File

@@ -1,11 +1,9 @@
using FileTime.App.Core.Models.Enums;
using FileTime.App.Core.Services;
using FileTime.Core.Models;
using MvvmGen;
namespace FileTime.App.Core.ViewModels;
[ViewModel(GenerateConstructor = false)]
public partial class ContainerViewModel : ItemViewModel, IContainerViewModel
{
public IContainer? Container => BaseItem as IContainer;

View File

@@ -2,11 +2,9 @@ using DeclarativeProperty;
using FileTime.App.Core.Models.Enums;
using FileTime.App.Core.Services;
using FileTime.Core.Models;
using MvvmGen;
namespace FileTime.App.Core.ViewModels;
[ViewModel(GenerateConstructor = false)]
public partial class ElementViewModel : ItemViewModel, IElementViewModel
{
public IElement? Element => BaseItem as Element;

View File

@@ -3,11 +3,9 @@ using FileTime.App.Core.Models.Enums;
using FileTime.App.Core.Services;
using FileTime.Core.Models;
using FileTime.Core.Models.Extensions;
using MvvmGen;
namespace FileTime.App.Core.ViewModels;
[ViewModel(GenerateConstructor = false)]
public partial class FileViewModel : ElementViewModel, IFileViewModel
{
public FileViewModel(IItemNameConverterService itemNameConverterService, IAppState appState) : base(itemNameConverterService, appState)

View File

@@ -74,7 +74,7 @@ public abstract partial class ItemViewModel : IItemViewModel
? parentTab.CurrentSelectedItem
.Map(EqualsTo)
.DistinctUntilChanged()
.Debounce(TimeSpan.FromMilliseconds(10))
.Debounce(TimeSpan.FromMilliseconds(1))
: new DeclarativeProperty<bool>(IsInDeepestPath());
IsAlternative = sourceCollection
@@ -86,7 +86,7 @@ public abstract partial class ItemViewModel : IItemViewModel
ViewMode = DeclarativePropertyHelpers
.CombineLatest(IsMarked, IsSelected, IsAlternative, GenerateViewMode)
.DistinctUntilChanged()
.Debounce(TimeSpan.FromMilliseconds(100));
.Debounce(TimeSpan.FromMilliseconds(1));
Attributes = item.Attributes;
CreatedAt = item.CreatedAt;
ModifiedAt = item.ModifiedAt;