GUI async refactor

This commit is contained in:
2022-01-20 23:31:57 +01:00
parent 215503a4e3
commit 031d07613b
12 changed files with 204 additions and 200 deletions

View File

@@ -42,8 +42,8 @@ namespace FileTime.Core.Components
} */
public int CurrentSelectedIndex { get; private set; }
public event EventHandler CurrentLocationChanged;
public event EventHandler CurrentSelectedItemChanged;
public AsyncEventHandler CurrentLocationChanged = new();
public AsyncEventHandler CurrentSelectedItemChanged = new();
public async Task Init(IContainer currentPath)
{
@@ -65,7 +65,7 @@ namespace FileTime.Core.Components
}
_currentLocation = value;
CurrentLocationChanged?.Invoke(this, EventArgs.Empty);
await CurrentLocationChanged?.InvokeAsync(this, AsyncEventArgs.Empty);
var currentLocationItems = (await (await GetCurrentLocation()).GetItems())!;
await SetCurrentSelectedItem(currentLocationItems.Count > 0 ? currentLocationItems[0] : null);
@@ -87,7 +87,7 @@ namespace FileTime.Core.Components
_currentSelectedItem = value;
CurrentSelectedIndex = await GetItemIndex(value);
CurrentSelectedItemChanged?.Invoke(this, EventArgs.Empty);
await CurrentSelectedItemChanged?.InvokeAsync(this, AsyncEventArgs.Empty);
}
}

View File

@@ -45,22 +45,10 @@ namespace FileTime.Core.Providers
public Task<bool> IsExists(string name) => throw new NotImplementedException();
public Task Refresh()
{
return Task.CompletedTask;
}
public async Task Refresh() => await Refreshed.InvokeAsync(this, AsyncEventArgs.Empty);
public Task<IReadOnlyList<IItem>?> GetItems(CancellationToken token = default)
{
return Task.FromResult(_items);
}
public Task<IReadOnlyList<IContainer>?> GetContainers(CancellationToken token = default)
{
return Task.FromResult(_containers);
}
public Task<IReadOnlyList<IElement>?> GetElements(CancellationToken token = default)
{
return Task.FromResult(_elements);
}
public Task<IReadOnlyList<IItem>?> GetItems(CancellationToken token = default) => Task.FromResult(_items);
public Task<IReadOnlyList<IContainer>?> GetContainers(CancellationToken token = default) => Task.FromResult(_containers);
public Task<IReadOnlyList<IElement>?> GetElements(CancellationToken token = default) => Task.FromResult(_elements);
}
}