diff --git a/src/Core/FileTime.Core/Components/Tab.cs b/src/Core/FileTime.Core/Components/Tab.cs index b0565c9..7f4ed29 100644 --- a/src/Core/FileTime.Core/Components/Tab.cs +++ b/src/Core/FileTime.Core/Components/Tab.cs @@ -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); } } diff --git a/src/Core/FileTime.Core/Providers/TopContainer.cs b/src/Core/FileTime.Core/Providers/TopContainer.cs index f845ca6..28c8af5 100644 --- a/src/Core/FileTime.Core/Providers/TopContainer.cs +++ b/src/Core/FileTime.Core/Providers/TopContainer.cs @@ -45,22 +45,10 @@ namespace FileTime.Core.Providers public Task IsExists(string name) => throw new NotImplementedException(); - public Task Refresh() - { - return Task.CompletedTask; - } + public async Task Refresh() => await Refreshed.InvokeAsync(this, AsyncEventArgs.Empty); - public Task?> GetItems(CancellationToken token = default) - { - return Task.FromResult(_items); - } - public Task?> GetContainers(CancellationToken token = default) - { - return Task.FromResult(_containers); - } - public Task?> GetElements(CancellationToken token = default) - { - return Task.FromResult(_elements); - } + public Task?> GetItems(CancellationToken token = default) => Task.FromResult(_items); + public Task?> GetContainers(CancellationToken token = default) => Task.FromResult(_containers); + public Task?> GetElements(CancellationToken token = default) => Task.FromResult(_elements); } } \ No newline at end of file diff --git a/src/GuiApp/FileTime.Uno/FileTime.Uno.Shared/Application/TabContainer.cs b/src/GuiApp/FileTime.Uno/FileTime.Uno.Shared/Application/TabContainer.cs index daec184..4bb6437 100644 --- a/src/GuiApp/FileTime.Uno/FileTime.Uno.Shared/Application/TabContainer.cs +++ b/src/GuiApp/FileTime.Uno/FileTime.Uno.Shared/Application/TabContainer.cs @@ -1,4 +1,5 @@ -using FileTime.Core.Components; +using AsyncEvent; +using FileTime.Core.Components; using FileTime.Core.Models; using FileTime.Providers.Local; using FileTime.Uno.ViewModels; @@ -6,7 +7,9 @@ using MvvmGen; using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Text; +using System.Threading.Tasks; namespace FileTime.Uno.Application { @@ -28,32 +31,39 @@ namespace FileTime.Uno.Application [PropertyCallMethod(nameof(SelectedItemChanged))] private IItemViewModel _selectedItem; - partial void OnInitialize() + public async Task Init() { - Tab.CurrentLocationChanged += Tab_CurrentLocationChanged; - Tab.CurrentSelectedItemChanged += Tab_CurrentSelectedItemChanged; + Tab.CurrentLocationChanged.Add(Tab_CurrentLocationChanged); + Tab.CurrentSelectedItemChanged.Add(Tab_CurrentSelectedItemChanged); - CurrentLocation = new ContainerViewModel(Tab.CurrentLocation); - var parent = Tab.CurrentLocation.GetParent(); + CurrentLocation = new ContainerViewModel(await Tab.GetCurrentLocation()); + await CurrentLocation.Init(); + + var parent = (await Tab.GetCurrentLocation()).GetParent(); if (parent != null) { Parent = new ContainerViewModel(parent); + await Parent.Init(); } else { Parent = null; } - UpdateCurrentSelectedItem(); + await UpdateCurrentSelectedItem(); } - private void Tab_CurrentLocationChanged(object sender, EventArgs e) + private async Task Tab_CurrentLocationChanged(object sender, AsyncEventArgs e) { - CurrentLocation = new ContainerViewModel(Tab.CurrentLocation); - var parent = Tab.CurrentLocation.GetParent(); + var currentLocation = await Tab.GetCurrentLocation(); + CurrentLocation = new ContainerViewModel(currentLocation); + await CurrentLocation.Init(); + + var parent = currentLocation.GetParent(); if (parent != null) { Parent = new ContainerViewModel(parent); + await Parent.Init(); } else { @@ -61,30 +71,32 @@ namespace FileTime.Uno.Application } } - private void Tab_CurrentSelectedItemChanged(object sender, EventArgs e) + private async Task Tab_CurrentSelectedItemChanged(object sender, AsyncEventArgs e) { - UpdateCurrentSelectedItem(); + await UpdateCurrentSelectedItem(); } - private void UpdateCurrentSelectedItem() + private async Task UpdateCurrentSelectedItem() { + var tabCurrentSelectenItem = await Tab.GetCurrentSelectedItem(); IItemViewModel currentSelectenItem = null; - if (Tab.CurrentSelectedItem == null) + if (tabCurrentSelectenItem == null) { SelectedItem = null; ChildContainer = null; } else { - currentSelectenItem = _currentLocation.Items.Find(i => i.Item.Name == Tab.CurrentSelectedItem.Name); + currentSelectenItem = _currentLocation.Items.FirstOrDefault(i => i.Item.Name == tabCurrentSelectenItem.Name); if (currentSelectenItem is ContainerViewModel currentSelectedContainer) { - SelectedItem = ChildContainer = currentSelectedContainer; + SelectedItem = currentSelectedContainer; + ChildContainer = currentSelectedContainer; } else if (currentSelectenItem is ElementViewModel element) { - ChildContainer = null; SelectedItem = element; + ChildContainer = null; } else { @@ -99,79 +111,79 @@ namespace FileTime.Uno.Application } } - private void SelectedItemChanged() + private async void SelectedItemChanged() { - Tab.CurrentSelectedItem = SelectedItem?.Item; + await Tab.SetCurrentSelectedItem(SelectedItem?.Item); } - public void Open() + public async Task Open() { if (ChildContainer != null) { - Tab.Open(); - UpdateCurrentSelectedItem(); + await Tab.Open(); + await UpdateCurrentSelectedItem(); } } - public void GoUp() + public async Task GoUp() { - Tab.GoUp(); - UpdateCurrentSelectedItem(); + await Tab.GoUp(); + await UpdateCurrentSelectedItem(); } - public void MoveCursorDown() + public async Task MoveCursorDown() { - Tab.SelectNextItem(); + await Tab.SelectNextItem(); } - public void MoveCursorDownPage() + public async Task MoveCursorDownPage() { - Tab.SelectNextItem(10); + await Tab.SelectNextItem(10); } - public void MoveCursorUp() + public async Task MoveCursorUp() { - Tab.SelectPreviousItem(); + await Tab.SelectPreviousItem(); } - public void MoveCursorUpPage() + public async Task MoveCursorUpPage() { - Tab.SelectPreviousItem(10); + await Tab.SelectPreviousItem(10); } - public void MoveCursorToFirst() + public async Task MoveCursorToFirst() { - Tab.SelectFirstItem(); + await Tab.SelectFirstItem(); } - public void MoveCursorToLast() + public async Task MoveCursorToLast() { - Tab.SelectLastItem(); + await Tab.SelectLastItem(); } - public void GotToProvider() + public async Task GotToProvider() { - Tab.GoToProvider(); + await Tab.GoToProvider(); } - public void GotToRoot() + public async Task GotToRoot() { - Tab.GoToRoot(); + await Tab.GoToRoot(); } - public void GotToHome() + public async Task GotToHome() { var path = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile).Replace(Path.DirectorySeparatorChar, Constants.SeparatorChar); var resolvedPath = LocalContentProvider.GetByPath(path); - if(resolvedPath is IContainer homeFolder) + if (resolvedPath is IContainer homeFolder) { - Tab.OpenContainer(homeFolder); + await Tab.OpenContainer(homeFolder); } } - public void CreateContainer(string name) + public async Task CreateContainer(string name) { - Tab.CurrentLocation.CreateContainer(name); + (await Tab.GetCurrentLocation())?.CreateContainer(name); } } } diff --git a/src/GuiApp/FileTime.Uno/FileTime.Uno.Shared/Command/CommandBinding.cs b/src/GuiApp/FileTime.Uno/FileTime.Uno.Shared/Command/CommandBinding.cs index cd0191f..ce3b720 100644 --- a/src/GuiApp/FileTime.Uno/FileTime.Uno.Shared/Command/CommandBinding.cs +++ b/src/GuiApp/FileTime.Uno/FileTime.Uno.Shared/Command/CommandBinding.cs @@ -4,27 +4,28 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; +using System.Threading.Tasks; namespace FileTime.Uno.Command { public class CommandBinding { - private readonly Action _commandHandler; + private readonly Func _commandHandler; public string Name { get; } public Commands? Command { get; } public KeyWithModifiers[] Keys { get; } - public void Invoke() => _commandHandler(); public string KeysDisplayText => GetKeysDisplayText(); - public CommandBinding(string name, Commands? command, KeyWithModifiers[] keys, Action commandHandler) + public CommandBinding(string name, Commands? command, KeyWithModifiers[] keys, Func commandHandler) { _commandHandler = commandHandler; Name = name; Command = command; Keys = keys; } + public async Task InvokeAsync() => await _commandHandler(); public string GetKeysDisplayText() { diff --git a/src/GuiApp/FileTime.Uno/FileTime.Uno.Shared/MainPage.xaml.cs b/src/GuiApp/FileTime.Uno/FileTime.Uno.Shared/MainPage.xaml.cs index 407284b..275bf6a 100644 --- a/src/GuiApp/FileTime.Uno/FileTime.Uno.Shared/MainPage.xaml.cs +++ b/src/GuiApp/FileTime.Uno/FileTime.Uno.Shared/MainPage.xaml.cs @@ -62,9 +62,9 @@ namespace FileTime.Uno e.Handled = ViewModel.ProcessKeyDown(e.Key) || e.Handled; } - private void CurrentItems_KeyUp(object sender, KeyRoutedEventArgs e) + private async void CurrentItems_KeyUp(object sender, KeyRoutedEventArgs e) { - e.Handled = ViewModel.ProcessKeyUp(e.Key) || e.Handled; + e.Handled = await ViewModel.ProcessKeyUp(e.Key) || e.Handled; } private void InputText_KeyDown(object sender, KeyRoutedEventArgs e) diff --git a/src/GuiApp/FileTime.Uno/FileTime.Uno.Shared/ViewModels/ContainerViewModel.cs b/src/GuiApp/FileTime.Uno/FileTime.Uno.Shared/ViewModels/ContainerViewModel.cs index f8cef2f..f09c0e3 100644 --- a/src/GuiApp/FileTime.Uno/FileTime.Uno.Shared/ViewModels/ContainerViewModel.cs +++ b/src/GuiApp/FileTime.Uno/FileTime.Uno.Shared/ViewModels/ContainerViewModel.cs @@ -1,15 +1,20 @@ -using FileTime.Core.Models; +using AsyncEvent; +using FileTime.Core.Models; using MvvmGen; using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; using System.Text; +using System.Threading.Tasks; namespace FileTime.Uno.ViewModels { [ViewModel] public partial class ContainerViewModel : IItemViewModel { + private bool isRefreshing; + [Property] private IContainer _container; @@ -19,13 +24,13 @@ namespace FileTime.Uno.ViewModels public IItem Item => _container; //[Property] - private List _containers; + private readonly ObservableCollection _containers = new ObservableCollection(); //[Property] - private List _elements; + private readonly ObservableCollection _elements = new ObservableCollection(); //[Property] - private List _items; + private readonly ObservableCollection _items = new ObservableCollection(); [Property] private bool _isAlternative; @@ -40,77 +45,88 @@ namespace FileTime.Uno.ViewModels ? ItemViewMode.Alternative : ItemViewMode.Default; - public List Containers + public ObservableCollection Containers { get { - if(_containers == null) Refresh(); + if (_containers == null) Task.Run(Refresh); return _containers; } - set - { - if(_containers != value) - { - _containers = value; - OnPropertyChanged(nameof(_containers)); - } - } } - public List Elements + public ObservableCollection Elements { get { - if(_elements == null) Refresh(); + if (_elements == null) Task.Run(Refresh); return _elements; } - set - { - if(_elements != value) - { - _elements = value; - OnPropertyChanged(nameof(_elements)); - } - } } - public List Items + public ObservableCollection Items { get { - if(_items == null) Refresh(); + if (_items == null) Task.Run(Refresh); return _items; } - set - { - if(_items != value) - { - _items = value; - OnPropertyChanged(nameof(_items)); - } - } } - public ContainerViewModel(IContainer container) + public ContainerViewModel(IContainer container) : this() { Container = container; - Container.Refreshed += Container_Refreshed; + Container.Refreshed.Add(Container_Refreshed); } - private void Container_Refreshed(object sender, EventArgs e) + public async Task Init(bool initializeChildren = true) { - Refresh(); + await Refresh(initializeChildren); } - private void Refresh() + private async Task Container_Refreshed(object sender, AsyncEventArgs e) { - Containers = _container.Containers.Select(c => new ContainerViewModel(c)).ToList(); - Elements = _container.Elements.Select(e => new ElementViewModel(e)).ToList(); + await Refresh(false); + } - Items = Containers.Cast().Concat(Elements).ToList(); + private async Task Refresh() + { + await Refresh(true); + } + private async Task Refresh(bool initializeChildren) + { + if (isRefreshing) return; - for(var i = 0;i new ContainerViewModel(c)).ToList(); + var elements = (await _container.GetElements()).Select(e => new ElementViewModel(e)).ToList(); + + _containers.Clear(); + _elements.Clear(); + _items.Clear(); + + foreach (var container in containers) + { + if (initializeChildren) await container.Init(false); + + _containers.Add(container); + _items.Add(container); + } + + foreach (var element in elements) + { + _elements.Add(element); + _items.Add(element); + } + + for (var i = 0; i < _items.Count; i++) + { + _items[i].IsAlternative = i % 2 == 1; + } } + catch { } + + isRefreshing = false; } } } diff --git a/src/GuiApp/FileTime.Uno/FileTime.Uno.Shared/ViewModels/MainPageViewModel.cs b/src/GuiApp/FileTime.Uno/FileTime.Uno.Shared/ViewModels/MainPageViewModel.cs index eac3eb0..0b83209 100644 --- a/src/GuiApp/FileTime.Uno/FileTime.Uno.Shared/ViewModels/MainPageViewModel.cs +++ b/src/GuiApp/FileTime.Uno/FileTime.Uno.Shared/ViewModels/MainPageViewModel.cs @@ -10,6 +10,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; +using System.Threading.Tasks; using Windows.System; namespace FileTime.Uno.ViewModels @@ -20,6 +21,7 @@ namespace FileTime.Uno.ViewModels public partial class MainPageViewModel { private readonly List _previousKeys = new List(); + private readonly List _keysToSkip = new List(); private bool _isAltPressed = false; private bool _isShiftPressed = false; private bool _isCtrlPressed = false; @@ -46,19 +48,28 @@ namespace FileTime.Uno.ViewModels public Action FocusDefaultElement { get; set; } - partial void OnInitialize() + async partial void OnInitialize() { InitCommandBindings(); + _keysToSkip.Add(new KeyWithModifiers[] { new KeyWithModifiers(VirtualKey.Up) }); + _keysToSkip.Add(new KeyWithModifiers[] { new KeyWithModifiers(VirtualKey.Down) }); + _keysToSkip.Add(new KeyWithModifiers[] { new KeyWithModifiers(VirtualKey.Tab) }); + + var tab = new Tab(); + await tab.Init(LocalContentProvider); + + var tabContainer = new TabContainer(tab, LocalContentProvider); + await tabContainer.Init(); AppState.Tabs = new List() { - new TabContainer(new Tab(LocalContentProvider), LocalContentProvider) + tabContainer }; var driveInfos = new List(); foreach (var drive in DriveInfo.GetDrives()) { - var container = LocalContentProvider.RootContainers.FirstOrDefault(d => d.Name == drive.Name.TrimEnd(Path.DirectorySeparatorChar)); + var container = (await LocalContentProvider.GetRootContainers()).FirstOrDefault(d => d.Name == drive.Name.TrimEnd(Path.DirectorySeparatorChar)); if (container != null) { var driveInfo = new RootDriveInfo(drive, container); @@ -69,73 +80,75 @@ namespace FileTime.Uno.ViewModels RootDriveInfos = driveInfos; } - public void OpenContainer() + public async Task OpenContainer() { - AppState.SelectedTab.Open(); + await AppState.SelectedTab.Open(); } - public void GoUp() + public async Task GoUp() { - AppState.SelectedTab.GoUp(); + await AppState.SelectedTab.GoUp(); } - public void MoveCursorUp() + public async Task MoveCursorUp() { - AppState.SelectedTab.MoveCursorUp(); + await AppState.SelectedTab.MoveCursorUp(); } - public void MoveCursorDown() + public async Task MoveCursorDown() { - AppState.SelectedTab.MoveCursorDown(); + await AppState.SelectedTab.MoveCursorDown(); } - public void MoveCursorUpPage() + public async Task MoveCursorUpPage() { - AppState.SelectedTab.MoveCursorUpPage(); + await AppState.SelectedTab.MoveCursorUpPage(); } - public void MoveCursorDownPage() + public async Task MoveCursorDownPage() { - AppState.SelectedTab.MoveCursorDownPage(); + await AppState.SelectedTab.MoveCursorDownPage(); } - public void MoveToFirst() + public async Task MoveToFirst() { - AppState.SelectedTab.MoveCursorToFirst(); + await AppState.SelectedTab.MoveCursorToFirst(); } - public void MoveToLast() + public async Task MoveToLast() { - AppState.SelectedTab.MoveCursorToLast(); + await AppState.SelectedTab.MoveCursorToLast(); } - public void GotToProvider() + public async Task GotToProvider() { - AppState.SelectedTab.GotToProvider(); + await AppState.SelectedTab.GotToProvider(); } - public void GotToRoot() + public async Task GotToRoot() { - AppState.SelectedTab.GotToRoot(); + await AppState.SelectedTab.GotToRoot(); } - public void GotToHome() + public async Task GotToHome() { - AppState.SelectedTab.GotToHome(); + await AppState.SelectedTab.GotToHome(); } - public void CreateContainer() + public Task CreateContainer() { var handler = () => { if (Inputs != null) { - AppState.SelectedTab.CreateContainer(Inputs[0].Value); + AppState.SelectedTab.CreateContainer(Inputs[0].Value).Wait(); Inputs = null; } }; ReadInputs(new List() { new InputElement("Container name", InputType.Text) }, handler); + + return Task.CompletedTask; } [Command] @@ -172,7 +185,7 @@ namespace FileTime.Uno.ViewModels return false; } - public bool ProcessKeyUp(VirtualKey key) + public async Task ProcessKeyUp(VirtualKey key) { if (key == VirtualKey.Menu) { @@ -192,21 +205,15 @@ namespace FileTime.Uno.ViewModels _previousKeys.Add(keyWithModifiers); var selectedCommandBinding = _commandBindings.Find(c => AreKeysEqual(c.Keys, _previousKeys)); - + if (key == VirtualKey.Escape) { _previousKeys.Clear(); PossibleCommands = new(); } - else if (_previousKeys.Count == 2 && selectedCommandBinding == null) - { - NoCommandFound = true; - _previousKeys.Clear(); - PossibleCommands = new(); - } else if (selectedCommandBinding != null) { - selectedCommandBinding.Invoke(); + await selectedCommandBinding.InvokeAsync(); _previousKeys.Clear(); PossibleCommands = new(); @@ -215,6 +222,17 @@ namespace FileTime.Uno.ViewModels FocusDefaultElement?.Invoke(); } } + else if (_keysToSkip.Any(k => AreKeysEqual(k, _previousKeys))) + { + _previousKeys.Clear(); + PossibleCommands = new(); + } + else if (_previousKeys.Count == 2) + { + NoCommandFound = true; + _previousKeys.Clear(); + PossibleCommands = new(); + } else { var possibleCommands = _commandBindings.Where(c => AreKeysEqual(c.Keys[0], keyWithModifiers)).ToList(); @@ -275,11 +293,11 @@ namespace FileTime.Uno.ViewModels new CommandBinding("cursor down", FileTime.App.Core.Command.Commands.MoveCursorDown, new KeyWithModifiers[]{new KeyWithModifiers(VirtualKey.Down)}, MoveCursorDown), new CommandBinding("cursor page up", FileTime.App.Core.Command.Commands.MoveCursorUpPage, new KeyWithModifiers[]{new KeyWithModifiers(VirtualKey.PageUp)}, MoveCursorUpPage), new CommandBinding("cursor page down", FileTime.App.Core.Command.Commands.MoveCursorDownPage, new KeyWithModifiers[]{new KeyWithModifiers(VirtualKey.PageDown)}, MoveCursorDownPage),*/ - new CommandBinding("", null, new KeyWithModifiers[]{new KeyWithModifiers(VirtualKey.Up)}, () =>{ }), + /*new CommandBinding("", null, new KeyWithModifiers[]{new KeyWithModifiers(VirtualKey.Up)}, () =>{ }), new CommandBinding("", null, new KeyWithModifiers[]{new KeyWithModifiers(VirtualKey.Down)}, () =>{ }), new CommandBinding("", null, new KeyWithModifiers[]{new KeyWithModifiers(VirtualKey.PageUp)}, () =>{ }), new CommandBinding("", null, new KeyWithModifiers[]{new KeyWithModifiers(VirtualKey.PageDown)}, () =>{ }), - new CommandBinding("", null, new KeyWithModifiers[]{new KeyWithModifiers(VirtualKey.Tab)}, () =>{ }), + new CommandBinding("", null, new KeyWithModifiers[]{new KeyWithModifiers(VirtualKey.Tab)}, () =>{ }),*/ new CommandBinding( "create container", FileTime.App.Core.Command.Commands.CreateContainer, diff --git a/src/Providers/FileTime.Providers.Local/LocalContentProvider.cs b/src/Providers/FileTime.Providers.Local/LocalContentProvider.cs index dc8f7b8..118dc4a 100644 --- a/src/Providers/FileTime.Providers.Local/LocalContentProvider.cs +++ b/src/Providers/FileTime.Providers.Local/LocalContentProvider.cs @@ -64,8 +64,7 @@ namespace FileTime.Providers.Local return await rootContainer.GetByPath(string.Join(Constants.SeparatorChar, pathParts.Skip(1))); } - public Task Refresh() => Task.CompletedTask; - + public async Task Refresh() => await Refreshed.InvokeAsync(this, AsyncEventArgs.Empty); public IContainer? GetParent() => _parent; public Task CreateContainer(string name) => throw new NotSupportedException(); @@ -78,26 +77,11 @@ namespace FileTime.Providers.Local public bool CanHandlePath(string path) => _rootContainers.Any(r => path.StartsWith(r.Name)); - public void SetParent(IContainer container) - { - _parent = container; - } - public Task?> GetRootContainers(CancellationToken token = default) - { - return Task.FromResult(_rootContainers); - } + public void SetParent(IContainer container) => _parent = container; + public Task> GetRootContainers(CancellationToken token = default) => Task.FromResult(_rootContainers); - public Task?> GetItems(CancellationToken token = default) - { - return Task.FromResult(_items); - } - public Task?> GetContainers(CancellationToken token = default) - { - return Task.FromResult(_rootContainers); - } - public Task?> GetElements(CancellationToken token = default) - { - return Task.FromResult(_elements); - } + public Task?> GetItems(CancellationToken token = default) => Task.FromResult(_items); + public Task?> GetContainers(CancellationToken token = default) => Task.FromResult((IReadOnlyList?)_rootContainers); + public Task?> GetElements(CancellationToken token = default) => Task.FromResult(_elements); } } \ No newline at end of file diff --git a/src/Providers/FileTime.Providers.Smb/SmbContentProvider.cs b/src/Providers/FileTime.Providers.Smb/SmbContentProvider.cs index baf4bf2..d5a2153 100644 --- a/src/Providers/FileTime.Providers.Smb/SmbContentProvider.cs +++ b/src/Providers/FileTime.Providers.Smb/SmbContentProvider.cs @@ -7,7 +7,7 @@ namespace FileTime.Providers.Smb { public class SmbContentProvider : IContentProvider { - private IContainer _parent; + private IContainer? _parent; private readonly IInputInterface _inputInterface; private readonly List _rootContainers; private readonly IReadOnlyList _rootContainersReadOnly; @@ -64,32 +64,17 @@ namespace FileTime.Providers.Smb public IContainer? GetParent() => _parent; - public async Task IsExists(string name) => (await GetItems()).Any(i => i.Name == name); + public async Task IsExists(string name) => (await GetItems())?.Any(i => i.Name == name) ?? false; - public async Task Refresh() - { - await Refreshed?.InvokeAsync(this, AsyncEventArgs.Empty); - } + public async Task Refresh() => await Refreshed.InvokeAsync(this, AsyncEventArgs.Empty); public bool CanHandlePath(string path) => path.StartsWith("smb://") || path.StartsWith(@"\\"); public void SetParent(IContainer container) => _parent = container; - public Task?> GetRootContainers(CancellationToken token = default) - { - return Task.FromResult(_rootContainersReadOnly); - } + public Task> GetRootContainers(CancellationToken token = default) => Task.FromResult(_rootContainersReadOnly); - public Task?> GetItems(CancellationToken token = default) - { - return Task.FromResult(_items); - } - public Task?> GetContainers(CancellationToken token = default) - { - return Task.FromResult(_rootContainersReadOnly); - } - public Task?> GetElements(CancellationToken token = default) - { - return Task.FromResult(_elements); - } + public Task?> GetItems(CancellationToken token = default) => Task.FromResult(_items); + public Task?> GetContainers(CancellationToken token = default) => Task.FromResult((IReadOnlyList?)_rootContainersReadOnly); + public Task?> GetElements(CancellationToken token = default) => Task.FromResult(_elements); } } \ No newline at end of file diff --git a/src/Providers/FileTime.Providers.Smb/SmbFolder.cs b/src/Providers/FileTime.Providers.Smb/SmbFolder.cs index ba2471f..3662f84 100644 --- a/src/Providers/FileTime.Providers.Smb/SmbFolder.cs +++ b/src/Providers/FileTime.Providers.Smb/SmbFolder.cs @@ -92,7 +92,7 @@ namespace FileTime.Providers.Smb _elements = elements.AsReadOnly(); _items = _containers.Cast().Concat(_elements).ToList().AsReadOnly(); - await Refreshed?.InvokeAsync(this, AsyncEventArgs.Empty); + await Refreshed.InvokeAsync(this, AsyncEventArgs.Empty); } public async Task?> GetItems(CancellationToken token = default) diff --git a/src/Providers/FileTime.Providers.Smb/SmbServer.cs b/src/Providers/FileTime.Providers.Smb/SmbServer.cs index 9840f40..ea884c2 100644 --- a/src/Providers/FileTime.Providers.Smb/SmbServer.cs +++ b/src/Providers/FileTime.Providers.Smb/SmbServer.cs @@ -89,7 +89,7 @@ namespace FileTime.Providers.Smb _shares = shares.ConvertAll(s => new SmbShare(s, Provider, this, GetSmbClient)).AsReadOnly(); _items = _shares.Cast().ToList().AsReadOnly(); - await Refreshed?.InvokeAsync(this, AsyncEventArgs.Empty); + await Refreshed.InvokeAsync(this, AsyncEventArgs.Empty); } private async Task GetSmbClient() diff --git a/src/Providers/FileTime.Providers.Smb/SmbShare.cs b/src/Providers/FileTime.Providers.Smb/SmbShare.cs index dc3b1c3..7a33c73 100644 --- a/src/Providers/FileTime.Providers.Smb/SmbShare.cs +++ b/src/Providers/FileTime.Providers.Smb/SmbShare.cs @@ -108,7 +108,7 @@ namespace FileTime.Providers.Smb _elements = elements.AsReadOnly(); _items = _containers.Cast().Concat(_elements).ToList().AsReadOnly(); - await Refreshed?.InvokeAsync(this, AsyncEventArgs.Empty); + await Refreshed.InvokeAsync(this, AsyncEventArgs.Empty); } public async Task<(List containers, List elements)> ListFolder(IContainer parent, string shareName, string folderName)