Optimization, UI improvements, Run command
This commit is contained in:
@@ -27,7 +27,7 @@ namespace FileTime.Core.Command
|
||||
if (itemToRename != null)
|
||||
{
|
||||
await itemToRename.Rename(Target);
|
||||
timeRunner.RefreshContainer?.InvokeAsync(this, new AbsolutePath(itemToRename.GetParent()!));
|
||||
if(timeRunner.RefreshContainer != null) await timeRunner.RefreshContainer.InvokeAsync(this, new AbsolutePath(itemToRename.GetParent()!));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,9 @@ namespace FileTime.Core.Components
|
||||
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
|
||||
private string? _lastPath;
|
||||
|
||||
private readonly object _guardSetCurrentSelectedItemCTS = new object();
|
||||
private bool _currentlySelecting = false;
|
||||
|
||||
private readonly object _guardSetCurrentSelectedItemCTS = new();
|
||||
private CancellationTokenSource? _setCurrentSelectedItemCTS;
|
||||
|
||||
public int CurrentSelectedIndex { get; private set; }
|
||||
@@ -54,6 +56,8 @@ namespace FileTime.Core.Components
|
||||
|
||||
public async Task SetCurrentSelectedItem(IItem? value, bool secondary = false)
|
||||
{
|
||||
if (_currentlySelecting) return;
|
||||
|
||||
if (_currentSelectedItem != value)
|
||||
{
|
||||
IItem? itemToSelect = null;
|
||||
@@ -190,11 +194,13 @@ namespace FileTime.Core.Components
|
||||
{
|
||||
if (!currentPossibleItems.Any()) return;
|
||||
|
||||
var currentLocationItems = (await (await GetCurrentLocation()).GetItems())!;
|
||||
var currentLocation = await GetCurrentLocation();
|
||||
var currentLocationItems = (await currentLocation.GetItems())!;
|
||||
|
||||
if (await GetCurrentSelectedItem() != null)
|
||||
{
|
||||
(await GetCurrentLocation())?.RefreshAsync();
|
||||
_currentlySelecting = true;
|
||||
currentLocation?.RefreshAsync();
|
||||
|
||||
IItem? newSelectedItem = null;
|
||||
foreach (var item in currentPossibleItems)
|
||||
@@ -212,6 +218,7 @@ namespace FileTime.Core.Components
|
||||
newSelectedItem = (await (await GetCurrentLocation()).GetItems())?.FirstOrDefault(i => i.Name == newSelectedItem.Name);
|
||||
}
|
||||
|
||||
_currentlySelecting = false;
|
||||
await SetCurrentSelectedItem(newSelectedItem ?? (currentLocationItems.Count > 0 ? currentLocationItems[0] : null));
|
||||
}
|
||||
else
|
||||
@@ -261,6 +268,11 @@ namespace FileTime.Core.Components
|
||||
var newCurrentLocation = (await (await GetCurrentLocation()).GetItems())?.FirstOrDefault(i => i.Name == lastCurrentLocation.Name);
|
||||
await SetCurrentSelectedItem(newCurrentLocation);
|
||||
}
|
||||
|
||||
foreach(var lastLocationItem in currentLocationItems.OfType<IContainer>())
|
||||
{
|
||||
lastLocationItem.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,5 +4,7 @@ namespace FileTime.Core.Models
|
||||
{
|
||||
bool IsSpecial { get; }
|
||||
string GetPrimaryAttributeText();
|
||||
Task<string> GetContent(CancellationToken token = default);
|
||||
Task<long> GetElementSize(CancellationToken token = default);
|
||||
}
|
||||
}
|
||||
@@ -2,11 +2,12 @@ using FileTime.Core.Providers;
|
||||
|
||||
namespace FileTime.Core.Models
|
||||
{
|
||||
public interface IItem
|
||||
public interface IItem : IDisposable
|
||||
{
|
||||
string Name { get; }
|
||||
string? FullName { get; }
|
||||
bool IsHidden { get; }
|
||||
bool IsDisposed { get; }
|
||||
SupportsDelete CanDelete { get; }
|
||||
bool CanRename { get; }
|
||||
IContentProvider Provider { get; }
|
||||
|
||||
@@ -35,6 +35,8 @@ namespace FileTime.Core.Models
|
||||
|
||||
public AsyncEventHandler Refreshed { get; }
|
||||
|
||||
public bool IsDisposed => BaseContainer.IsDisposed;
|
||||
|
||||
private void RefreshAddBase(Func<object?, AsyncEventArgs, CancellationToken, Task> handler)
|
||||
{
|
||||
BaseContainer.Refreshed.Add(handler);
|
||||
@@ -168,5 +170,10 @@ namespace FileTime.Core.Models
|
||||
|
||||
public async Task Rename(string newName) => await BaseContainer.Rename(newName);
|
||||
public async Task<bool> CanOpen() => await BaseContainer.CanOpen();
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
BaseContainer.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,6 +33,8 @@ namespace FileTime.Core.Providers
|
||||
|
||||
public bool SupportsDirectoryLevelSoftDelete => false;
|
||||
|
||||
public bool IsDisposed => false;
|
||||
|
||||
public TopContainer(IEnumerable<IContentProvider> contentProviders)
|
||||
{
|
||||
_contentProviders = new List<IContentProvider>(contentProviders);
|
||||
@@ -57,7 +59,7 @@ namespace FileTime.Core.Providers
|
||||
|
||||
public Task<bool> IsExists(string name) => throw new NotImplementedException();
|
||||
|
||||
public async Task RefreshAsync(CancellationToken token = default) => await Refreshed.InvokeAsync(this, AsyncEventArgs.Empty);
|
||||
public async Task RefreshAsync(CancellationToken token = default) => await Refreshed.InvokeAsync(this, AsyncEventArgs.Empty, token);
|
||||
|
||||
public Task<IReadOnlyList<IItem>?> GetItems(CancellationToken token = default) => Task.FromResult(_items);
|
||||
public Task<IReadOnlyList<IContainer>?> GetContainers(CancellationToken token = default) => Task.FromResult(_containers);
|
||||
@@ -68,5 +70,7 @@ namespace FileTime.Core.Providers
|
||||
public Task Rename(string newName) => throw new NotSupportedException();
|
||||
|
||||
public Task<bool> CanOpen() => Task.FromResult(true);
|
||||
|
||||
public void Dispose() { }
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,8 @@ namespace FileTime.Core.Timeline
|
||||
|
||||
public bool SupportsDirectoryLevelSoftDelete => false;
|
||||
|
||||
public bool IsDisposed { get; private set; }
|
||||
|
||||
public TimeContainer(string name, IContainer parent, IContentProvider contentProvider, IContentProvider virtualContentProvider, PointInTime pointInTime)
|
||||
{
|
||||
_parent = parent;
|
||||
@@ -121,5 +123,7 @@ namespace FileTime.Core.Timeline
|
||||
return new TimeElement(elementDiff.Name, this, Provider, elementDiff.AbsolutePath.VirtualContentProvider ?? elementDiff.AbsolutePath.ContentProvider);
|
||||
}
|
||||
public Task<bool> CanOpen() => Task.FromResult(true);
|
||||
|
||||
public void Dispose() => IsDisposed = true;
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,8 @@ namespace FileTime.Core.Timeline
|
||||
public IContentProvider Provider { get; }
|
||||
public IContentProvider VirtualProvider { get; }
|
||||
|
||||
public bool IsDisposed { get; private set; }
|
||||
|
||||
public Task Delete(bool hardDelete = false) => Task.CompletedTask;
|
||||
|
||||
public IContainer? GetParent() => _parent;
|
||||
@@ -38,5 +40,10 @@ namespace FileTime.Core.Timeline
|
||||
public string GetPrimaryAttributeText() => "";
|
||||
|
||||
public Task Rename(string newName) => Task.CompletedTask;
|
||||
|
||||
public Task<string> GetContent(CancellationToken token = default) => Task.FromResult("");
|
||||
public Task<long> GetElementSize(CancellationToken token = default) => Task.FromResult(-1L);
|
||||
|
||||
public void Dispose() => IsDisposed = true;
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,8 @@ namespace FileTime.Core.Timeline
|
||||
|
||||
public bool SupportsDirectoryLevelSoftDelete => false;
|
||||
|
||||
public bool IsDisposed => false;
|
||||
|
||||
public TimeProvider(PointInTime pointInTime)
|
||||
{
|
||||
_pointInTime = pointInTime;
|
||||
@@ -90,5 +92,7 @@ namespace FileTime.Core.Timeline
|
||||
|
||||
public void SetParent(IContainer container) { }
|
||||
public Task<bool> CanOpen() => Task.FromResult(true);
|
||||
|
||||
public void Dispose() { }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user