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
.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))
)

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.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)
{

View File

@@ -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;

View File

@@ -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);

View File

@@ -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();