Top navigation, search delete
This commit is contained in:
@@ -15,32 +15,17 @@ public class TabPersistenceService : ITabPersistenceService
|
||||
private readonly IAppState _appState;
|
||||
private readonly ILogger<TabPersistenceService> _logger;
|
||||
|
||||
private class PersistenceRoot
|
||||
//TODO: make this a configuration maybe?
|
||||
private readonly List<string> _contentProvidersNotToRestore = new()
|
||||
{
|
||||
public TabStates? TabStates { get; set; }
|
||||
}
|
||||
"search"
|
||||
};
|
||||
|
||||
private class TabStates
|
||||
{
|
||||
public List<TabState>? Tabs { get; set; }
|
||||
public int? ActiveTabNumber { get; set; }
|
||||
}
|
||||
private record PersistenceRoot(TabStates? TabStates);
|
||||
|
||||
private class TabState
|
||||
{
|
||||
public string? Path { get; set; }
|
||||
public int Number { get; set; }
|
||||
private record TabStates(List<TabState>? Tabs, int? ActiveTabNumber);
|
||||
|
||||
public TabState()
|
||||
{
|
||||
}
|
||||
|
||||
public TabState(FullName path, int number)
|
||||
{
|
||||
Path = path.Path;
|
||||
Number = number;
|
||||
}
|
||||
}
|
||||
private record TabState(string? Path, int Number);
|
||||
|
||||
private readonly string _settingsPath;
|
||||
private readonly JsonSerializerOptions _jsonOptions;
|
||||
@@ -149,7 +134,7 @@ public class TabPersistenceService : ITabPersistenceService
|
||||
}
|
||||
catch
|
||||
{
|
||||
path = path.GetParent();
|
||||
path = path?.GetParent();
|
||||
if (path == null)
|
||||
{
|
||||
throw new Exception($"Could not find an initializable path along {tab.Path}");
|
||||
@@ -159,6 +144,8 @@ public class TabPersistenceService : ITabPersistenceService
|
||||
|
||||
if (container == null) continue;
|
||||
|
||||
if (_contentProvidersNotToRestore.Contains(container.Provider.Name)) continue;
|
||||
|
||||
var tabToLoad = await _serviceProvider.GetAsyncInitableResolver(container)
|
||||
.GetRequiredServiceAsync<ITab>();
|
||||
var tabViewModel = _serviceProvider.GetInitableResolver(tabToLoad, tab.Number)
|
||||
@@ -181,7 +168,15 @@ public class TabPersistenceService : ITabPersistenceService
|
||||
|
||||
if (_appState.Tabs.Count == 0) return false;
|
||||
|
||||
var tabToActivate = _appState.Tabs.FirstOrDefault(t => t.TabNumber == tabStates.ActiveTabNumber);
|
||||
var optimalTabs = _appState
|
||||
.Tabs
|
||||
.TakeWhile(t => t.TabNumber <= tabStates.ActiveTabNumber)
|
||||
.Reverse();
|
||||
var suboptimalTabs = _appState
|
||||
.Tabs
|
||||
.SkipWhile(t => t.TabNumber <= tabStates.ActiveTabNumber);
|
||||
|
||||
var tabToActivate = optimalTabs.Concat(suboptimalTabs).FirstOrDefault();
|
||||
if (tabToActivate is not null) _appState.SetSelectedTab(tabToActivate);
|
||||
|
||||
return true;
|
||||
@@ -189,10 +184,8 @@ public class TabPersistenceService : ITabPersistenceService
|
||||
|
||||
public void SaveStates(CancellationToken token = default)
|
||||
{
|
||||
var state = new PersistenceRoot
|
||||
{
|
||||
TabStates = SerializeTabStates()
|
||||
};
|
||||
var state = new PersistenceRoot(SerializeTabStates());
|
||||
|
||||
var settingsDirectory = new DirectoryInfo(string.Join(Path.DirectorySeparatorChar,
|
||||
_settingsPath.Split(Path.DirectorySeparatorChar)[0..^1]));
|
||||
if (!settingsDirectory.Exists) settingsDirectory.Create();
|
||||
@@ -207,16 +200,15 @@ public class TabPersistenceService : ITabPersistenceService
|
||||
{
|
||||
var currentLocation = tab.CurrentLocation.Value;
|
||||
if (currentLocation is null) continue;
|
||||
tabStates.Add(new TabState(currentLocation.FullName!, tab.TabNumber));
|
||||
tabStates.Add(new TabState(currentLocation.FullName!.Path, tab.TabNumber));
|
||||
}
|
||||
|
||||
return new TabStates
|
||||
{
|
||||
Tabs = tabStates,
|
||||
ActiveTabNumber = _appState.CurrentSelectedTab?.TabNumber
|
||||
};
|
||||
return new TabStates(
|
||||
tabStates,
|
||||
_appState.CurrentSelectedTab?.TabNumber
|
||||
);
|
||||
}
|
||||
|
||||
public async Task InitAsync()
|
||||
public async Task InitAsync()
|
||||
=> await LoadStatesAsync();
|
||||
}
|
||||
@@ -10,7 +10,6 @@ using FileTime.App.Core.UserCommand;
|
||||
using FileTime.App.Core.ViewModels;
|
||||
using FileTime.Core.Command;
|
||||
using FileTime.Core.Command.CreateContainer;
|
||||
using FileTime.Core.Command.CreateElement;
|
||||
using FileTime.Core.Command.Move;
|
||||
using FileTime.Core.Extensions;
|
||||
using FileTime.Core.Interactions;
|
||||
|
||||
@@ -15,7 +15,7 @@ public class ToolUserCommandHandlerService : UserCommandHandlerServiceBase
|
||||
{
|
||||
private readonly ISystemClipboardService _systemClipboardService;
|
||||
private readonly IUserCommunicationService _userCommunicationService;
|
||||
private readonly ISearchManager _searchManager;
|
||||
private readonly ISearchContentProvider _searchContentProvider;
|
||||
private readonly IItemNameConverterService _itemNameConverterService;
|
||||
private readonly ITimelessContentProvider _timelessContentProvider;
|
||||
private readonly IUserCommandHandlerService _userCommandHandlerService;
|
||||
@@ -28,7 +28,7 @@ public class ToolUserCommandHandlerService : UserCommandHandlerServiceBase
|
||||
IAppState appState,
|
||||
ISystemClipboardService systemClipboardService,
|
||||
IUserCommunicationService userCommunicationService,
|
||||
ISearchManager searchManager,
|
||||
ISearchContentProvider searchContentProvider,
|
||||
IItemNameConverterService itemNameConverterService,
|
||||
ITimelessContentProvider timelessContentProvider,
|
||||
IUserCommandHandlerService userCommandHandlerService,
|
||||
@@ -36,7 +36,7 @@ public class ToolUserCommandHandlerService : UserCommandHandlerServiceBase
|
||||
{
|
||||
_systemClipboardService = systemClipboardService;
|
||||
_userCommunicationService = userCommunicationService;
|
||||
_searchManager = searchManager;
|
||||
_searchContentProvider = searchContentProvider;
|
||||
_itemNameConverterService = itemNameConverterService;
|
||||
_timelessContentProvider = timelessContentProvider;
|
||||
_userCommandHandlerService = userCommandHandlerService;
|
||||
@@ -113,7 +113,7 @@ public class ToolUserCommandHandlerService : UserCommandHandlerServiceBase
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
};
|
||||
|
||||
var searchTask = await _searchManager.StartSearchAsync(searchMatcher, _currentLocation.Value);
|
||||
var searchTask = await _searchContentProvider.StartSearchAsync(searchMatcher, _currentLocation.Value);
|
||||
var openContainerCommand = new OpenContainerCommand(new AbsolutePath(_timelessContentProvider, searchTask.SearchContainer));
|
||||
await _userCommandHandlerService.HandleCommandAsync(openContainerCommand);
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ public abstract partial class ItemViewModel : IItemViewModel
|
||||
var displayName = itemViewModelType switch
|
||||
{
|
||||
ItemViewModelType.Main => _appState.RapidTravelText.Map(s => (IReadOnlyList<ItemNamePart>) _itemNameConverterService.GetDisplayName(item.DisplayName, s)),
|
||||
_ => new DeclarativeProperty<IReadOnlyList<ItemNamePart>>(new List<ItemNamePart> {new (item.DisplayName)}),
|
||||
_ => new DeclarativeProperty<IReadOnlyList<ItemNamePart>>(new List<ItemNamePart> {new(item.DisplayName)}),
|
||||
};
|
||||
|
||||
BaseItem = item;
|
||||
@@ -103,6 +103,6 @@ public abstract partial class ItemViewModel : IItemViewModel
|
||||
var deepestPath = _parentTab.Tab.LastDeepestSelectedPath;
|
||||
var commonPath = FullName.CreateSafe(PathHelper.GetCommonPath(ownFullName.Path, deepestPath.Path));
|
||||
|
||||
return commonPath.Path == ownFullName.Path;
|
||||
return commonPath is not null && commonPath.Path == ownFullName.Path;
|
||||
}
|
||||
}
|
||||
@@ -198,7 +198,7 @@ public partial class TabViewModel : ITabViewModel
|
||||
|
||||
private static async Task<IItem> MapItemAsync(AbsolutePath item)
|
||||
=> await item.ResolveAsync(forceResolve: true,
|
||||
itemInitializationSettings: new ItemInitializationSettings(true));
|
||||
itemInitializationSettings: new ItemInitializationSettings {SkipChildInitialization = true});
|
||||
|
||||
private IItemViewModel MapItemToViewModel(IItem item, ItemViewModelType type)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user