Minor improvements

This commit is contained in:
2023-08-17 22:14:10 +02:00
parent b1c2454ed9
commit fd9a20e888
17 changed files with 99 additions and 17 deletions

View File

@@ -42,9 +42,14 @@ public class CommandPaletteViewModel : FuzzyPanelViewModel<ICommandPaletteEntryV
FilteredMatches = _commandPaletteService FilteredMatches = _commandPaletteService
.GetCommands() .GetCommands()
.Where(c => .Where(c =>
c.Title.Contains(SearchText, StringComparison.OrdinalIgnoreCase) {
|| c.Identifier.Contains(SearchText, StringComparison.OrdinalIgnoreCase) var searchTerms = SearchText.Split(' ');
) return searchTerms
.All(s =>
c.Title.Contains(s, StringComparison.OrdinalIgnoreCase)
|| c.Identifier.Contains(s, StringComparison.OrdinalIgnoreCase)
);
})
.Select(c => .Select(c =>
(ICommandPaletteEntryViewModel) new CommandPaletteEntryViewModel(c.Identifier, c.Title, _commandKeysHelperService.GetKeyConfigsString(c.Identifier)) (ICommandPaletteEntryViewModel) new CommandPaletteEntryViewModel(c.Identifier, c.Title, _commandKeysHelperService.GetKeyConfigsString(c.Identifier))
) )

View File

@@ -0,0 +1,7 @@
namespace FileTime.App.Core.Configuration;
public class TabPersistenceSettings
{
public bool LoadState { get; set; } = true;
public bool SaveState { get; set; } = true;
}

View File

@@ -1,4 +1,5 @@
using FileTime.App.Core.Models; using FileTime.App.Core.Models;
using FileTime.Core.Models;
namespace FileTime.App.Core.UserCommand; namespace FileTime.App.Core.UserCommand;
@@ -10,6 +11,8 @@ public sealed class SortItemsCommand : IIdentifiableUserCommand
public const string OrderByCreatedAtDescCommandName = "order_by_created_at_desc"; public const string OrderByCreatedAtDescCommandName = "order_by_created_at_desc";
public const string OrderByModifiedAtCommandName = "order_by_modified_at"; public const string OrderByModifiedAtCommandName = "order_by_modified_at";
public const string OrderByModifiedAtDescCommandName = "order_by_modified_at_desc"; public const string OrderByModifiedAtDescCommandName = "order_by_modified_at_desc";
public const string OrderBySizeCommandName = "order_by_size";
public const string OrderBySizeDescCommandName = "order_by_size_desc";
public static readonly SortItemsCommand OrderByNameCommand = public static readonly SortItemsCommand OrderByNameCommand =
new(OrderByNameCommandName, ItemOrdering.Name, "Order by name"); new(OrderByNameCommandName, ItemOrdering.Name, "Order by name");
@@ -29,6 +32,12 @@ public sealed class SortItemsCommand : IIdentifiableUserCommand
public static readonly SortItemsCommand OrderByLastModifiedDescCommand = public static readonly SortItemsCommand OrderByLastModifiedDescCommand =
new(OrderByModifiedAtDescCommandName, ItemOrdering.LastModifyDateDesc, "Order by last modified (descending)"); new(OrderByModifiedAtDescCommandName, ItemOrdering.LastModifyDateDesc, "Order by last modified (descending)");
public static readonly SortItemsCommand OrderBySizeCommand =
new(OrderBySizeCommandName, ItemOrdering.Size, "Order by size");
public static readonly SortItemsCommand OrderBySizeDescCommand =
new(OrderBySizeDescCommandName, ItemOrdering.SizeDesc, "Order by size (descending)");
private SortItemsCommand(string userCommandId, ItemOrdering ordering, string title) private SortItemsCommand(string userCommandId, ItemOrdering ordering, string title)
{ {
UserCommandID = userCommandId; UserCommandID = userCommandId;

View File

@@ -1,4 +1,5 @@
using System.Text.Json; using System.Text.Json;
using FileTime.App.Core.Configuration;
using FileTime.App.Core.Models; using FileTime.App.Core.Models;
using FileTime.App.Core.ViewModels; using FileTime.App.Core.ViewModels;
using FileTime.Core.Models; using FileTime.Core.Models;
@@ -34,6 +35,7 @@ public class TabPersistenceService : ITabPersistenceService
private readonly ITimelessContentProvider _timelessContentProvider; private readonly ITimelessContentProvider _timelessContentProvider;
private readonly IServiceProvider _serviceProvider; private readonly IServiceProvider _serviceProvider;
private readonly ILocalContentProvider _localContentProvider; private readonly ILocalContentProvider _localContentProvider;
private readonly TabPersistenceSettings _tabPersistenceSettings;
public TabPersistenceService( public TabPersistenceService(
IApplicationSettings applicationSettings, IApplicationSettings applicationSettings,
@@ -41,6 +43,7 @@ public class TabPersistenceService : ITabPersistenceService
ITimelessContentProvider timelessContentProvider, ITimelessContentProvider timelessContentProvider,
IServiceProvider serviceProvider, IServiceProvider serviceProvider,
ILocalContentProvider localContentProvider, ILocalContentProvider localContentProvider,
TabPersistenceSettings tabPersistenceSettings,
ILogger<TabPersistenceService> logger) ILogger<TabPersistenceService> logger)
{ {
_appState = appState; _appState = appState;
@@ -49,6 +52,7 @@ public class TabPersistenceService : ITabPersistenceService
_timelessContentProvider = timelessContentProvider; _timelessContentProvider = timelessContentProvider;
_serviceProvider = serviceProvider; _serviceProvider = serviceProvider;
_localContentProvider = localContentProvider; _localContentProvider = localContentProvider;
_tabPersistenceSettings = tabPersistenceSettings;
_jsonOptions = new JsonSerializerOptions _jsonOptions = new JsonSerializerOptions
{ {
@@ -62,6 +66,7 @@ public class TabPersistenceService : ITabPersistenceService
public Task ExitAsync(CancellationToken token = default) public Task ExitAsync(CancellationToken token = default)
{ {
if(!_tabPersistenceSettings.SaveState) return Task.CompletedTask;
SaveStates(token); SaveStates(token);
return Task.CompletedTask; return Task.CompletedTask;
@@ -69,7 +74,7 @@ public class TabPersistenceService : ITabPersistenceService
private async Task LoadStatesAsync(CancellationToken token = default) private async Task LoadStatesAsync(CancellationToken token = default)
{ {
if (!File.Exists(_settingsPath)) if (!File.Exists(_settingsPath) || !_tabPersistenceSettings.LoadState)
{ {
await CreateEmptyTab(); await CreateEmptyTab();
return; return;

View File

@@ -58,6 +58,8 @@ public class DefaultIdentifiableCommandHandlerRegister : IStartupHandler
AddUserCommand(SortItemsCommand.OrderByCreatedAtDescCommand); AddUserCommand(SortItemsCommand.OrderByCreatedAtDescCommand);
AddUserCommand(SortItemsCommand.OrderByLastModifiedCommand); AddUserCommand(SortItemsCommand.OrderByLastModifiedCommand);
AddUserCommand(SortItemsCommand.OrderByLastModifiedDescCommand); AddUserCommand(SortItemsCommand.OrderByLastModifiedDescCommand);
AddUserCommand(SortItemsCommand.OrderBySizeCommand);
AddUserCommand(SortItemsCommand.OrderBySizeDescCommand);
AddUserCommand(IdentifiableSearchCommand.SearchByNameContains); AddUserCommand(IdentifiableSearchCommand.SearchByNameContains);
AddUserCommand(IdentifiableSearchCommand.SearchByRegex); AddUserCommand(IdentifiableSearchCommand.SearchByRegex);
AddUserCommand(SwitchToTabCommand.SwitchToLastTab); AddUserCommand(SwitchToTabCommand.SwitchToLastTab);

View File

@@ -153,7 +153,11 @@ public partial class FrequencyNavigationService : IFrequencyNavigationService, I
try try
{ {
return _containerScores return _containerScores
.Where(c => c.Key.Contains(searchText, StringComparison.OrdinalIgnoreCase)) .Where(c =>
{
var searchTerms = searchText.Split(' ');
return searchTerms.All(s => c.Key.Contains(s, StringComparison.OrdinalIgnoreCase));
})
.OrderByDescending(c => GetWeightedScore(c.Value.Score, c.Value.LastAccessed)) .OrderByDescending(c => GetWeightedScore(c.Value.Score, c.Value.LastAccessed))
.Select(c => c.Key) .Select(c => c.Key)
.ToList(); .ToList();

View File

@@ -1,6 +1,7 @@
using FileTime.App.FrequencyNavigation.Services; using FileTime.App.FrequencyNavigation.Services;
using FileTime.ConsoleUI.App.Styling; using FileTime.ConsoleUI.App.Styling;
using GeneralInputKey; using GeneralInputKey;
using TerminalUI.Color;
using TerminalUI.Controls; using TerminalUI.Controls;
using TerminalUI.Extensions; using TerminalUI.Extensions;
using TerminalUI.Models; using TerminalUI.Models;
@@ -58,6 +59,7 @@ public class FrequencyNavigation
Margin = 5, Margin = 5,
Padding = 1, Padding = 1,
MaxWidth = 50, MaxWidth = 50,
Fill = SpecialColor.None,
Content = new Grid<IRootViewModel> Content = new Grid<IRootViewModel>
{ {
RowDefinitionsObject = "Auto *", RowDefinitionsObject = "Auto *",

View File

@@ -32,6 +32,12 @@ public static class Startup
return services; return services;
} }
public static IServiceCollection AddSettings(this IServiceCollection services)
{
services.TryAddSingleton(new TabPersistenceSettings {LoadState = false, SaveState = false});
return services;
}
public static IServiceCollection AddConsoleViews(this IServiceCollection services) public static IServiceCollection AddConsoleViews(this IServiceCollection services)
{ {
services.TryAddSingleton<MainWindow>(); services.TryAddSingleton<MainWindow>();

View File

@@ -24,6 +24,7 @@ public static class DI
.RegisterDefaultServices(configuration: configuration) .RegisterDefaultServices(configuration: configuration)
.AddConsoleServices(configuration) .AddConsoleServices(configuration)
.AddConsoleViews() .AddConsoleViews()
.AddSettings()
.AddTerminalUi() .AddTerminalUi()
.AddLocalProviderServices() .AddLocalProviderServices()
.AddServerCoreServices() .AddServerCoreServices()

View File

@@ -1,4 +1,4 @@
namespace FileTime.App.Core.Models; namespace FileTime.Core.Models;
public enum ItemOrdering public enum ItemOrdering
{ {
@@ -8,4 +8,6 @@ public enum ItemOrdering
CreationDateDesc, CreationDateDesc,
LastModifyDate, LastModifyDate,
LastModifyDateDesc, LastModifyDateDesc,
Size,
SizeDesc
} }

View File

@@ -1,6 +1,5 @@
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using DeclarativeProperty; using DeclarativeProperty;
using FileTime.App.Core.Models;
using FileTime.Core.Models; using FileTime.Core.Models;
using InitableService; using InitableService;

View File

@@ -3,9 +3,9 @@ using System.ComponentModel;
using CircularBuffer; using CircularBuffer;
using DeclarativeProperty; using DeclarativeProperty;
using DynamicData; using DynamicData;
using FileTime.App.Core.Models;
using FileTime.Core.Helper; using FileTime.Core.Helper;
using FileTime.Core.Models; using FileTime.Core.Models;
using FileTime.Core.Models.Extensions;
using FileTime.Core.Timeline; using FileTime.Core.Timeline;
using ObservableComputations; using ObservableComputations;
using IContainer = FileTime.Core.Models.IContainer; using IContainer = FileTime.Core.Models.IContainer;
@@ -98,16 +98,28 @@ public class Tab : ITab
.ThenOrdering(i => i.DisplayName, ListSortDirection.Descending), .ThenOrdering(i => i.DisplayName, ListSortDirection.Descending),
ItemOrdering.CreationDate => ItemOrdering.CreationDate =>
items items
.Ordering(i => i.CreatedAt), .Ordering(i => i.Type)
.ThenOrdering(i => i.CreatedAt),
ItemOrdering.CreationDateDesc => ItemOrdering.CreationDateDesc =>
items items
.Ordering(i => i.CreatedAt, ListSortDirection.Descending), .Ordering(i => i.Type)
.ThenOrdering(i => i.CreatedAt, ListSortDirection.Descending),
ItemOrdering.LastModifyDate => ItemOrdering.LastModifyDate =>
items items
.Ordering(i => i.ModifiedAt), .Ordering(i => i.Type)
.ThenOrdering(i => i.ModifiedAt),
ItemOrdering.LastModifyDateDesc => ItemOrdering.LastModifyDateDesc =>
items items
.Ordering(i => i.ModifiedAt, ListSortDirection.Descending), .Ordering(i => i.Type)
.ThenOrdering(i => i.ModifiedAt, ListSortDirection.Descending),
ItemOrdering.Size =>
items
.Ordering(i => i.Type)
.ThenOrdering(i => GetSize(i)),
ItemOrdering.SizeDesc =>
items
.Ordering(i => i.Type)
.ThenOrdering(i => GetSize(i), ListSortDirection.Descending),
_ => throw new NotImplementedException() _ => throw new NotImplementedException()
}; };
@@ -115,7 +127,6 @@ public class Tab : ITab
} }
); );
CurrentSelectedItem = DeclarativePropertyHelpers.CombineLatest( CurrentSelectedItem = DeclarativePropertyHelpers.CombineLatest(
CurrentItems.Watch<ObservableCollection<IItem>, IItem>(), CurrentItems.Watch<ObservableCollection<IItem>, IItem>(),
_currentRequestItem.DistinctUntilChanged(), _currentRequestItem.DistinctUntilChanged(),
@@ -134,6 +145,16 @@ public class Tab : ITab
}); });
} }
private static long GetSize(IItem item)
{
if (item is IElement element && element.GetExtension<FileExtension>() is { } fileExtension)
{
return fileExtension.Size ?? -1;
}
return -2;
}
private static IItem MapItem(AbsolutePath item) private static IItem MapItem(AbsolutePath item)
{ {
var t = Task.Run(async () => await item.ResolveAsync(true)); var t = Task.Run(async () => await item.ResolveAsync(true));
@@ -242,7 +263,7 @@ public class Tab : ITab
public async Task SetSelectedItem(AbsolutePath newSelectedItem) public async Task SetSelectedItem(AbsolutePath newSelectedItem)
{ {
if (_currentRequestItem.Value is {} v && v.Path == newSelectedItem.Path) return; if (_currentRequestItem.Value is { } v && v.Path == newSelectedItem.Path) return;
await _currentRequestItem.SetValue(newSelectedItem); await _currentRequestItem.SetValue(newSelectedItem);
} }

View File

@@ -32,6 +32,7 @@ public class Application : Avalonia.Application
.ConfigureFont(configuration) .ConfigureFont(configuration)
.RegisterLogging() .RegisterLogging()
.RegisterServices() .RegisterServices()
.AddSettings()
.AddViewModels() .AddViewModels()
.BuildServiceProvider(); .BuildServiceProvider();

View File

@@ -50,6 +50,12 @@ public static class Startup
return serviceCollection; return serviceCollection;
} }
internal static IServiceCollection AddSettings(this IServiceCollection serviceCollection)
{
serviceCollection.TryAddSingleton(new TabPersistenceSettings());
return serviceCollection;
}
internal static IServiceCollection RegisterServices(this IServiceCollection serviceCollection) internal static IServiceCollection RegisterServices(this IServiceCollection serviceCollection)
{ {
serviceCollection.TryAddSingleton<IRxSchedulerService, AvaloniaRxSchedulerService>(); serviceCollection.TryAddSingleton<IRxSchedulerService, AvaloniaRxSchedulerService>();

View File

@@ -17,6 +17,7 @@ public class CompressCommand : CommandBase, IExecutableCommand, ITransportationC
private readonly IUserCommunicationService _userCommunicationService; private readonly IUserCommunicationService _userCommunicationService;
private readonly ITimelessContentProvider _timelessContentProvider; private readonly ITimelessContentProvider _timelessContentProvider;
private readonly IContentAccessorFactory _contentAccessorFactory; private readonly IContentAccessorFactory _contentAccessorFactory;
private readonly ICommandSchedulerNotifier _commandSchedulerNotifier;
private readonly OptionsInputElement<CompressionType> _compressionType; private readonly OptionsInputElement<CompressionType> _compressionType;
private readonly CancellationTokenSource _cancellationTokenSource = new(); private readonly CancellationTokenSource _cancellationTokenSource = new();
private readonly TextInputElement _targetFileName; private readonly TextInputElement _targetFileName;
@@ -29,6 +30,7 @@ public class CompressCommand : CommandBase, IExecutableCommand, ITransportationC
IUserCommunicationService userCommunicationService, IUserCommunicationService userCommunicationService,
ITimelessContentProvider timelessContentProvider, ITimelessContentProvider timelessContentProvider,
IContentAccessorFactory contentAccessorFactory, IContentAccessorFactory contentAccessorFactory,
ICommandSchedulerNotifier commandSchedulerNotifier,
IReadOnlyCollection<FullName> sources, IReadOnlyCollection<FullName> sources,
TransportMode mode, TransportMode mode,
FullName targetFullName) FullName targetFullName)
@@ -36,6 +38,7 @@ public class CompressCommand : CommandBase, IExecutableCommand, ITransportationC
_userCommunicationService = userCommunicationService; _userCommunicationService = userCommunicationService;
_timelessContentProvider = timelessContentProvider; _timelessContentProvider = timelessContentProvider;
_contentAccessorFactory = contentAccessorFactory; _contentAccessorFactory = contentAccessorFactory;
_commandSchedulerNotifier = commandSchedulerNotifier;
ArgumentNullException.ThrowIfNull(sources); ArgumentNullException.ThrowIfNull(sources);
ArgumentNullException.ThrowIfNull(mode); ArgumentNullException.ThrowIfNull(mode);
ArgumentNullException.ThrowIfNull(targetFullName); ArgumentNullException.ThrowIfNull(targetFullName);
@@ -49,7 +52,10 @@ public class CompressCommand : CommandBase, IExecutableCommand, ITransportationC
"CompressionMethod", "CompressionMethod",
Enum.GetValues<CompressionType>() Enum.GetValues<CompressionType>()
.Select(t => new OptionElement<CompressionType>(t.ToString(), t)) .Select(t => new OptionElement<CompressionType>(t.ToString(), t))
); )
{
Value = CompressionType.Zip
};
_inputs = new List<IInputElement> _inputs = new List<IInputElement>
{ {
@@ -121,6 +127,8 @@ public class CompressCommand : CommandBase, IExecutableCommand, ITransportationC
disposable.Dispose(); disposable.Dispose();
} }
} }
await _commandSchedulerNotifier.RefreshContainer(Target);
} }
private async Task<IEnumerable<IDisposable>> TraverseTree( private async Task<IEnumerable<IDisposable>> TraverseTree(

View File

@@ -11,15 +11,18 @@ public class CompressCommandFactory : ITransportationCommandFactory<CompressComm
private readonly IUserCommunicationService _userCommunicationService; private readonly IUserCommunicationService _userCommunicationService;
private readonly ITimelessContentProvider _timelessContentProvider; private readonly ITimelessContentProvider _timelessContentProvider;
private readonly IContentAccessorFactory _contentAccessorFactory; private readonly IContentAccessorFactory _contentAccessorFactory;
private readonly ICommandSchedulerNotifier _commandSchedulerNotifier;
public CompressCommandFactory( public CompressCommandFactory(
IUserCommunicationService userCommunicationService, IUserCommunicationService userCommunicationService,
ITimelessContentProvider timelessContentProvider, ITimelessContentProvider timelessContentProvider,
IContentAccessorFactory contentAccessorFactory) IContentAccessorFactory contentAccessorFactory,
ICommandSchedulerNotifier commandSchedulerNotifier)
{ {
_userCommunicationService = userCommunicationService; _userCommunicationService = userCommunicationService;
_timelessContentProvider = timelessContentProvider; _timelessContentProvider = timelessContentProvider;
_contentAccessorFactory = contentAccessorFactory; _contentAccessorFactory = contentAccessorFactory;
_commandSchedulerNotifier = commandSchedulerNotifier;
} }
public CompressCommand GenerateCommand(IReadOnlyCollection<FullName> sources, TransportMode mode, FullName targetFullName) public CompressCommand GenerateCommand(IReadOnlyCollection<FullName> sources, TransportMode mode, FullName targetFullName)
@@ -27,6 +30,7 @@ public class CompressCommandFactory : ITransportationCommandFactory<CompressComm
_userCommunicationService, _userCommunicationService,
_timelessContentProvider, _timelessContentProvider,
_contentAccessorFactory, _contentAccessorFactory,
_commandSchedulerNotifier,
sources, sources,
mode, mode,
targetFullName targetFullName

View File

@@ -11,5 +11,5 @@ public class CompressUserCommand : IIdentifiableUserCommand
} }
public string UserCommandID => CommandName; public string UserCommandID => CommandName;
public string Title => "Compress"; public string Title => "Select for compression";
} }