From fd9a20e888286ca5236b48889769990df881723b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81d=C3=A1m=20Kov=C3=A1cs?= Date: Thu, 17 Aug 2023 22:14:10 +0200 Subject: [PATCH] Minor improvements --- .../ViewModels/CommandPaletteViewModel.cs | 11 ++++-- .../Configuration/TabPersistenceSettings.cs | 7 ++++ .../UserCommand/SortItemsCommand.cs | 9 +++++ .../Persistence/TabPersistenceService.cs | 7 +++- ...faultIdentifiableCommandHandlerRegister.cs | 2 ++ .../Services/FrequencyNavigationService.cs | 6 +++- .../Controls/FrequencyNavigation.cs | 2 ++ .../FileTime.ConsoleUI.App/Startup.cs | 6 ++++ src/ConsoleApp/FileTime.ConsoleUI/DI.cs | 1 + .../Models/ItemOrdering.cs | 4 ++- .../Services/ITab.cs | 1 - src/Core/FileTime.Core.Services/Tab.cs | 35 +++++++++++++++---- .../Avalonia/FileTime.GuiApp/App.axaml.cs | 1 + .../Avalonia/FileTime.GuiApp/Startup.cs | 6 ++++ .../CompressCommand.cs | 10 +++++- .../CompressCommandFactory.cs | 6 +++- .../CompressUserCommand.cs | 2 +- 17 files changed, 99 insertions(+), 17 deletions(-) create mode 100644 src/AppCommon/FileTime.App.Core.Abstraction/Configuration/TabPersistenceSettings.cs diff --git a/src/AppCommon/FileTime.App.CommandPalette/ViewModels/CommandPaletteViewModel.cs b/src/AppCommon/FileTime.App.CommandPalette/ViewModels/CommandPaletteViewModel.cs index 3868c79..b9044ee 100644 --- a/src/AppCommon/FileTime.App.CommandPalette/ViewModels/CommandPaletteViewModel.cs +++ b/src/AppCommon/FileTime.App.CommandPalette/ViewModels/CommandPaletteViewModel.cs @@ -42,9 +42,14 @@ public class CommandPaletteViewModel : FuzzyPanelViewModel - 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 => (ICommandPaletteEntryViewModel) new CommandPaletteEntryViewModel(c.Identifier, c.Title, _commandKeysHelperService.GetKeyConfigsString(c.Identifier)) ) diff --git a/src/AppCommon/FileTime.App.Core.Abstraction/Configuration/TabPersistenceSettings.cs b/src/AppCommon/FileTime.App.Core.Abstraction/Configuration/TabPersistenceSettings.cs new file mode 100644 index 0000000..57fc5e0 --- /dev/null +++ b/src/AppCommon/FileTime.App.Core.Abstraction/Configuration/TabPersistenceSettings.cs @@ -0,0 +1,7 @@ +namespace FileTime.App.Core.Configuration; + +public class TabPersistenceSettings +{ + public bool LoadState { get; set; } = true; + public bool SaveState { get; set; } = true; +} \ No newline at end of file diff --git a/src/AppCommon/FileTime.App.Core.Abstraction/UserCommand/SortItemsCommand.cs b/src/AppCommon/FileTime.App.Core.Abstraction/UserCommand/SortItemsCommand.cs index b827d2f..6e7e558 100644 --- a/src/AppCommon/FileTime.App.Core.Abstraction/UserCommand/SortItemsCommand.cs +++ b/src/AppCommon/FileTime.App.Core.Abstraction/UserCommand/SortItemsCommand.cs @@ -1,4 +1,5 @@ using FileTime.App.Core.Models; +using FileTime.Core.Models; 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 OrderByModifiedAtCommandName = "order_by_modified_at"; 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 = new(OrderByNameCommandName, ItemOrdering.Name, "Order by name"); @@ -28,6 +31,12 @@ public sealed class SortItemsCommand : IIdentifiableUserCommand public static readonly SortItemsCommand OrderByLastModifiedDescCommand = 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) { diff --git a/src/AppCommon/FileTime.App.Core/Services/Persistence/TabPersistenceService.cs b/src/AppCommon/FileTime.App.Core/Services/Persistence/TabPersistenceService.cs index 265c782..e2fedd2 100644 --- a/src/AppCommon/FileTime.App.Core/Services/Persistence/TabPersistenceService.cs +++ b/src/AppCommon/FileTime.App.Core/Services/Persistence/TabPersistenceService.cs @@ -1,4 +1,5 @@ using System.Text.Json; +using FileTime.App.Core.Configuration; using FileTime.App.Core.Models; using FileTime.App.Core.ViewModels; using FileTime.Core.Models; @@ -34,6 +35,7 @@ public class TabPersistenceService : ITabPersistenceService private readonly ITimelessContentProvider _timelessContentProvider; private readonly IServiceProvider _serviceProvider; private readonly ILocalContentProvider _localContentProvider; + private readonly TabPersistenceSettings _tabPersistenceSettings; public TabPersistenceService( IApplicationSettings applicationSettings, @@ -41,6 +43,7 @@ public class TabPersistenceService : ITabPersistenceService ITimelessContentProvider timelessContentProvider, IServiceProvider serviceProvider, ILocalContentProvider localContentProvider, + TabPersistenceSettings tabPersistenceSettings, ILogger logger) { _appState = appState; @@ -49,6 +52,7 @@ public class TabPersistenceService : ITabPersistenceService _timelessContentProvider = timelessContentProvider; _serviceProvider = serviceProvider; _localContentProvider = localContentProvider; + _tabPersistenceSettings = tabPersistenceSettings; _jsonOptions = new JsonSerializerOptions { @@ -62,6 +66,7 @@ public class TabPersistenceService : ITabPersistenceService public Task ExitAsync(CancellationToken token = default) { + if(!_tabPersistenceSettings.SaveState) return Task.CompletedTask; SaveStates(token); return Task.CompletedTask; @@ -69,7 +74,7 @@ public class TabPersistenceService : ITabPersistenceService private async Task LoadStatesAsync(CancellationToken token = default) { - if (!File.Exists(_settingsPath)) + if (!File.Exists(_settingsPath) || !_tabPersistenceSettings.LoadState) { await CreateEmptyTab(); return; diff --git a/src/AppCommon/FileTime.App.Core/StartupServices/DefaultIdentifiableCommandHandlerRegister.cs b/src/AppCommon/FileTime.App.Core/StartupServices/DefaultIdentifiableCommandHandlerRegister.cs index 9aa7464..1fd97b2 100644 --- a/src/AppCommon/FileTime.App.Core/StartupServices/DefaultIdentifiableCommandHandlerRegister.cs +++ b/src/AppCommon/FileTime.App.Core/StartupServices/DefaultIdentifiableCommandHandlerRegister.cs @@ -58,6 +58,8 @@ public class DefaultIdentifiableCommandHandlerRegister : IStartupHandler AddUserCommand(SortItemsCommand.OrderByCreatedAtDescCommand); AddUserCommand(SortItemsCommand.OrderByLastModifiedCommand); AddUserCommand(SortItemsCommand.OrderByLastModifiedDescCommand); + AddUserCommand(SortItemsCommand.OrderBySizeCommand); + AddUserCommand(SortItemsCommand.OrderBySizeDescCommand); AddUserCommand(IdentifiableSearchCommand.SearchByNameContains); AddUserCommand(IdentifiableSearchCommand.SearchByRegex); AddUserCommand(SwitchToTabCommand.SwitchToLastTab); diff --git a/src/AppCommon/FileTime.App.FrequencyNavigation/Services/FrequencyNavigationService.cs b/src/AppCommon/FileTime.App.FrequencyNavigation/Services/FrequencyNavigationService.cs index d1e82c4..0f439f7 100644 --- a/src/AppCommon/FileTime.App.FrequencyNavigation/Services/FrequencyNavigationService.cs +++ b/src/AppCommon/FileTime.App.FrequencyNavigation/Services/FrequencyNavigationService.cs @@ -153,7 +153,11 @@ public partial class FrequencyNavigationService : IFrequencyNavigationService, I try { 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)) .Select(c => c.Key) .ToList(); diff --git a/src/ConsoleApp/FileTime.ConsoleUI.App/Controls/FrequencyNavigation.cs b/src/ConsoleApp/FileTime.ConsoleUI.App/Controls/FrequencyNavigation.cs index 2e2affd..9485674 100644 --- a/src/ConsoleApp/FileTime.ConsoleUI.App/Controls/FrequencyNavigation.cs +++ b/src/ConsoleApp/FileTime.ConsoleUI.App/Controls/FrequencyNavigation.cs @@ -1,6 +1,7 @@ using FileTime.App.FrequencyNavigation.Services; using FileTime.ConsoleUI.App.Styling; using GeneralInputKey; +using TerminalUI.Color; using TerminalUI.Controls; using TerminalUI.Extensions; using TerminalUI.Models; @@ -58,6 +59,7 @@ public class FrequencyNavigation Margin = 5, Padding = 1, MaxWidth = 50, + Fill = SpecialColor.None, Content = new Grid { RowDefinitionsObject = "Auto *", diff --git a/src/ConsoleApp/FileTime.ConsoleUI.App/Startup.cs b/src/ConsoleApp/FileTime.ConsoleUI.App/Startup.cs index 9a4db37..8c94625 100644 --- a/src/ConsoleApp/FileTime.ConsoleUI.App/Startup.cs +++ b/src/ConsoleApp/FileTime.ConsoleUI.App/Startup.cs @@ -32,6 +32,12 @@ public static class Startup 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) { services.TryAddSingleton(); diff --git a/src/ConsoleApp/FileTime.ConsoleUI/DI.cs b/src/ConsoleApp/FileTime.ConsoleUI/DI.cs index a7743e0..5904a0f 100644 --- a/src/ConsoleApp/FileTime.ConsoleUI/DI.cs +++ b/src/ConsoleApp/FileTime.ConsoleUI/DI.cs @@ -24,6 +24,7 @@ public static class DI .RegisterDefaultServices(configuration: configuration) .AddConsoleServices(configuration) .AddConsoleViews() + .AddSettings() .AddTerminalUi() .AddLocalProviderServices() .AddServerCoreServices() diff --git a/src/Core/FileTime.Core.Abstraction/Models/ItemOrdering.cs b/src/Core/FileTime.Core.Abstraction/Models/ItemOrdering.cs index 2b63cbc..d4adeb0 100644 --- a/src/Core/FileTime.Core.Abstraction/Models/ItemOrdering.cs +++ b/src/Core/FileTime.Core.Abstraction/Models/ItemOrdering.cs @@ -1,4 +1,4 @@ -namespace FileTime.App.Core.Models; +namespace FileTime.Core.Models; public enum ItemOrdering { @@ -8,4 +8,6 @@ public enum ItemOrdering CreationDateDesc, LastModifyDate, LastModifyDateDesc, + Size, + SizeDesc } \ No newline at end of file diff --git a/src/Core/FileTime.Core.Abstraction/Services/ITab.cs b/src/Core/FileTime.Core.Abstraction/Services/ITab.cs index 475b7aa..3f174f6 100644 --- a/src/Core/FileTime.Core.Abstraction/Services/ITab.cs +++ b/src/Core/FileTime.Core.Abstraction/Services/ITab.cs @@ -1,6 +1,5 @@ using System.Collections.ObjectModel; using DeclarativeProperty; -using FileTime.App.Core.Models; using FileTime.Core.Models; using InitableService; diff --git a/src/Core/FileTime.Core.Services/Tab.cs b/src/Core/FileTime.Core.Services/Tab.cs index 5307132..59ea1fa 100644 --- a/src/Core/FileTime.Core.Services/Tab.cs +++ b/src/Core/FileTime.Core.Services/Tab.cs @@ -3,9 +3,9 @@ using System.ComponentModel; using CircularBuffer; using DeclarativeProperty; using DynamicData; -using FileTime.App.Core.Models; using FileTime.Core.Helper; using FileTime.Core.Models; +using FileTime.Core.Models.Extensions; using FileTime.Core.Timeline; using ObservableComputations; using IContainer = FileTime.Core.Models.IContainer; @@ -98,16 +98,28 @@ public class Tab : ITab .ThenOrdering(i => i.DisplayName, ListSortDirection.Descending), ItemOrdering.CreationDate => items - .Ordering(i => i.CreatedAt), + .Ordering(i => i.Type) + .ThenOrdering(i => i.CreatedAt), ItemOrdering.CreationDateDesc => items - .Ordering(i => i.CreatedAt, ListSortDirection.Descending), + .Ordering(i => i.Type) + .ThenOrdering(i => i.CreatedAt, ListSortDirection.Descending), ItemOrdering.LastModifyDate => items - .Ordering(i => i.ModifiedAt), + .Ordering(i => i.Type) + .ThenOrdering(i => i.ModifiedAt), ItemOrdering.LastModifyDateDesc => 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() }; @@ -115,7 +127,6 @@ public class Tab : ITab } ); - CurrentSelectedItem = DeclarativePropertyHelpers.CombineLatest( CurrentItems.Watch, IItem>(), _currentRequestItem.DistinctUntilChanged(), @@ -134,6 +145,16 @@ public class Tab : ITab }); } + private static long GetSize(IItem item) + { + if (item is IElement element && element.GetExtension() is { } fileExtension) + { + return fileExtension.Size ?? -1; + } + + return -2; + } + private static IItem MapItem(AbsolutePath item) { var t = Task.Run(async () => await item.ResolveAsync(true)); @@ -242,7 +263,7 @@ public class Tab : ITab 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); } diff --git a/src/GuiApp/Avalonia/FileTime.GuiApp/App.axaml.cs b/src/GuiApp/Avalonia/FileTime.GuiApp/App.axaml.cs index 59a5d62..7d6fb00 100644 --- a/src/GuiApp/Avalonia/FileTime.GuiApp/App.axaml.cs +++ b/src/GuiApp/Avalonia/FileTime.GuiApp/App.axaml.cs @@ -32,6 +32,7 @@ public class Application : Avalonia.Application .ConfigureFont(configuration) .RegisterLogging() .RegisterServices() + .AddSettings() .AddViewModels() .BuildServiceProvider(); diff --git a/src/GuiApp/Avalonia/FileTime.GuiApp/Startup.cs b/src/GuiApp/Avalonia/FileTime.GuiApp/Startup.cs index 07b7a87..de2e7f7 100644 --- a/src/GuiApp/Avalonia/FileTime.GuiApp/Startup.cs +++ b/src/GuiApp/Avalonia/FileTime.GuiApp/Startup.cs @@ -49,6 +49,12 @@ public static class Startup serviceCollection.TryAddSingleton(s => s.GetRequiredService()); return serviceCollection; } + + internal static IServiceCollection AddSettings(this IServiceCollection serviceCollection) + { + serviceCollection.TryAddSingleton(new TabPersistenceSettings()); + return serviceCollection; + } internal static IServiceCollection RegisterServices(this IServiceCollection serviceCollection) { diff --git a/src/Tools/FileTime.Tools.Compression/CompressCommand.cs b/src/Tools/FileTime.Tools.Compression/CompressCommand.cs index 0f0baf2..b00f1fd 100644 --- a/src/Tools/FileTime.Tools.Compression/CompressCommand.cs +++ b/src/Tools/FileTime.Tools.Compression/CompressCommand.cs @@ -17,6 +17,7 @@ public class CompressCommand : CommandBase, IExecutableCommand, ITransportationC private readonly IUserCommunicationService _userCommunicationService; private readonly ITimelessContentProvider _timelessContentProvider; private readonly IContentAccessorFactory _contentAccessorFactory; + private readonly ICommandSchedulerNotifier _commandSchedulerNotifier; private readonly OptionsInputElement _compressionType; private readonly CancellationTokenSource _cancellationTokenSource = new(); private readonly TextInputElement _targetFileName; @@ -29,6 +30,7 @@ public class CompressCommand : CommandBase, IExecutableCommand, ITransportationC IUserCommunicationService userCommunicationService, ITimelessContentProvider timelessContentProvider, IContentAccessorFactory contentAccessorFactory, + ICommandSchedulerNotifier commandSchedulerNotifier, IReadOnlyCollection sources, TransportMode mode, FullName targetFullName) @@ -36,6 +38,7 @@ public class CompressCommand : CommandBase, IExecutableCommand, ITransportationC _userCommunicationService = userCommunicationService; _timelessContentProvider = timelessContentProvider; _contentAccessorFactory = contentAccessorFactory; + _commandSchedulerNotifier = commandSchedulerNotifier; ArgumentNullException.ThrowIfNull(sources); ArgumentNullException.ThrowIfNull(mode); ArgumentNullException.ThrowIfNull(targetFullName); @@ -49,7 +52,10 @@ public class CompressCommand : CommandBase, IExecutableCommand, ITransportationC "CompressionMethod", Enum.GetValues() .Select(t => new OptionElement(t.ToString(), t)) - ); + ) + { + Value = CompressionType.Zip + }; _inputs = new List { @@ -121,6 +127,8 @@ public class CompressCommand : CommandBase, IExecutableCommand, ITransportationC disposable.Dispose(); } } + + await _commandSchedulerNotifier.RefreshContainer(Target); } private async Task> TraverseTree( diff --git a/src/Tools/FileTime.Tools.Compression/CompressCommandFactory.cs b/src/Tools/FileTime.Tools.Compression/CompressCommandFactory.cs index f5e414f..30cdfee 100644 --- a/src/Tools/FileTime.Tools.Compression/CompressCommandFactory.cs +++ b/src/Tools/FileTime.Tools.Compression/CompressCommandFactory.cs @@ -11,15 +11,18 @@ public class CompressCommandFactory : ITransportationCommandFactory sources, TransportMode mode, FullName targetFullName) @@ -27,6 +30,7 @@ public class CompressCommandFactory : ITransportationCommandFactory CommandName; - public string Title => "Compress"; + public string Title => "Select for compression"; } \ No newline at end of file