Minor improvements
This commit is contained in:
@@ -42,9 +42,14 @@ public class CommandPaletteViewModel : FuzzyPanelViewModel<ICommandPaletteEntryV
|
||||
FilteredMatches = _commandPaletteService
|
||||
.GetCommands()
|
||||
.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 =>
|
||||
(ICommandPaletteEntryViewModel) new CommandPaletteEntryViewModel(c.Identifier, c.Title, _commandKeysHelperService.GetKeyConfigsString(c.Identifier))
|
||||
)
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace FileTime.App.Core.Configuration;
|
||||
|
||||
public class TabPersistenceSettings
|
||||
{
|
||||
public bool LoadState { get; set; } = true;
|
||||
public bool SaveState { get; set; } = true;
|
||||
}
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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<TabPersistenceService> 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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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<IRootViewModel>
|
||||
{
|
||||
RowDefinitionsObject = "Auto *",
|
||||
|
||||
@@ -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<MainWindow>();
|
||||
|
||||
@@ -24,6 +24,7 @@ public static class DI
|
||||
.RegisterDefaultServices(configuration: configuration)
|
||||
.AddConsoleServices(configuration)
|
||||
.AddConsoleViews()
|
||||
.AddSettings()
|
||||
.AddTerminalUi()
|
||||
.AddLocalProviderServices()
|
||||
.AddServerCoreServices()
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using DeclarativeProperty;
|
||||
using FileTime.App.Core.Models;
|
||||
using FileTime.Core.Models;
|
||||
using InitableService;
|
||||
|
||||
|
||||
@@ -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<ObservableCollection<IItem>, IItem>(),
|
||||
_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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ public class Application : Avalonia.Application
|
||||
.ConfigureFont(configuration)
|
||||
.RegisterLogging()
|
||||
.RegisterServices()
|
||||
.AddSettings()
|
||||
.AddViewModels()
|
||||
.BuildServiceProvider();
|
||||
|
||||
|
||||
@@ -49,6 +49,12 @@ public static class Startup
|
||||
serviceCollection.TryAddSingleton<IGuiAppState>(s => s.GetRequiredService<GuiAppState>());
|
||||
return serviceCollection;
|
||||
}
|
||||
|
||||
internal static IServiceCollection AddSettings(this IServiceCollection serviceCollection)
|
||||
{
|
||||
serviceCollection.TryAddSingleton(new TabPersistenceSettings());
|
||||
return serviceCollection;
|
||||
}
|
||||
|
||||
internal static IServiceCollection RegisterServices(this IServiceCollection serviceCollection)
|
||||
{
|
||||
|
||||
@@ -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> _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<FullName> 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<CompressionType>()
|
||||
.Select(t => new OptionElement<CompressionType>(t.ToString(), t))
|
||||
);
|
||||
)
|
||||
{
|
||||
Value = CompressionType.Zip
|
||||
};
|
||||
|
||||
_inputs = new List<IInputElement>
|
||||
{
|
||||
@@ -121,6 +127,8 @@ public class CompressCommand : CommandBase, IExecutableCommand, ITransportationC
|
||||
disposable.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
await _commandSchedulerNotifier.RefreshContainer(Target);
|
||||
}
|
||||
|
||||
private async Task<IEnumerable<IDisposable>> TraverseTree(
|
||||
|
||||
@@ -11,15 +11,18 @@ public class CompressCommandFactory : ITransportationCommandFactory<CompressComm
|
||||
private readonly IUserCommunicationService _userCommunicationService;
|
||||
private readonly ITimelessContentProvider _timelessContentProvider;
|
||||
private readonly IContentAccessorFactory _contentAccessorFactory;
|
||||
private readonly ICommandSchedulerNotifier _commandSchedulerNotifier;
|
||||
|
||||
public CompressCommandFactory(
|
||||
IUserCommunicationService userCommunicationService,
|
||||
ITimelessContentProvider timelessContentProvider,
|
||||
IContentAccessorFactory contentAccessorFactory)
|
||||
IContentAccessorFactory contentAccessorFactory,
|
||||
ICommandSchedulerNotifier commandSchedulerNotifier)
|
||||
{
|
||||
_userCommunicationService = userCommunicationService;
|
||||
_timelessContentProvider = timelessContentProvider;
|
||||
_contentAccessorFactory = contentAccessorFactory;
|
||||
_commandSchedulerNotifier = commandSchedulerNotifier;
|
||||
}
|
||||
|
||||
public CompressCommand GenerateCommand(IReadOnlyCollection<FullName> sources, TransportMode mode, FullName targetFullName)
|
||||
@@ -27,6 +30,7 @@ public class CompressCommandFactory : ITransportationCommandFactory<CompressComm
|
||||
_userCommunicationService,
|
||||
_timelessContentProvider,
|
||||
_contentAccessorFactory,
|
||||
_commandSchedulerNotifier,
|
||||
sources,
|
||||
mode,
|
||||
targetFullName
|
||||
|
||||
@@ -11,5 +11,5 @@ public class CompressUserCommand : IIdentifiableUserCommand
|
||||
}
|
||||
|
||||
public string UserCommandID => CommandName;
|
||||
public string Title => "Compress";
|
||||
public string Title => "Select for compression";
|
||||
}
|
||||
Reference in New Issue
Block a user