Modern UI, Loading screen CanRunMessages

This commit is contained in:
2022-02-03 16:49:45 +01:00
parent 1319d0bb98
commit 2ff1aa366e
34 changed files with 913 additions and 563 deletions

View File

@@ -22,6 +22,7 @@ namespace FileTime.Core.Command
public AsyncEventHandler ProgressChanged { get; } = new(); public AsyncEventHandler ProgressChanged { get; } = new();
public string DisplayLabel { get; } = "Copy"; public string DisplayLabel { get; } = "Copy";
public IReadOnlyList<string> CanRunMessages { get; } = new List<string>().AsReadOnly();
private async Task UpdateProgress() private async Task UpdateProgress()
{ {
@@ -73,7 +74,7 @@ namespace FileTime.Core.Command
return (IContainer)(await newContainerDiff.AbsolutePath.Resolve())!; return (IContainer)(await newContainerDiff.AbsolutePath.Resolve())!;
}; };
await DoCopy(Sources, Target, TransportMode.Value); await TraverseTree(Sources, Target, TransportMode.Value);
return startPoint.WithDifferences(newDiffs); return startPoint.WithDifferences(newDiffs);
} }
@@ -107,7 +108,7 @@ namespace FileTime.Core.Command
} }
}; };
await DoCopy(Sources, Target, TransportMode.Value); await TraverseTree(Sources, Target, TransportMode.Value);
} }
private async Task CalculateProgress() private async Task CalculateProgress()
@@ -136,11 +137,11 @@ namespace FileTime.Core.Command
return Task.CompletedTask; return Task.CompletedTask;
}; };
await DoCopy(Sources, Target, TransportMode.Value); await TraverseTree(Sources, Target, TransportMode.Value);
_operationStatuses = operationStatuses; _operationStatuses = operationStatuses;
} }
private async Task DoCopy( private async Task TraverseTree(
IEnumerable<AbsolutePath> sources, IEnumerable<AbsolutePath> sources,
IContainer target, IContainer target,
TransportMode transportMode) TransportMode transportMode)
@@ -159,7 +160,7 @@ namespace FileTime.Core.Command
var childDirectories = (await container.GetContainers())!.Select(d => new AbsolutePath(d)); var childDirectories = (await container.GetContainers())!.Select(d => new AbsolutePath(d));
var childFiles = (await container.GetElements())!.Select(f => new AbsolutePath(f)); var childFiles = (await container.GetElements())!.Select(f => new AbsolutePath(f));
await DoCopy(childDirectories.Concat(childFiles), targetContainer, transportMode); await TraverseTree(childDirectories.Concat(childFiles), targetContainer, transportMode);
if (_containerCopyDone != null) await _containerCopyDone.Invoke(new AbsolutePath(container)); if (_containerCopyDone != null) await _containerCopyDone.Invoke(new AbsolutePath(container));
} }
else if (item is IElement element) else if (item is IElement element)

View File

@@ -13,6 +13,7 @@ namespace FileTime.Core.Command
public AsyncEventHandler ProgressChanged { get; } = new(); public AsyncEventHandler ProgressChanged { get; } = new();
public string DisplayLabel { get; } = "CreateContainer"; public string DisplayLabel { get; } = "CreateContainer";
public IReadOnlyList<string> CanRunMessages { get; } = new List<string>().AsReadOnly();
public CreateContainerCommand(AbsolutePath container, string newContainerName) public CreateContainerCommand(AbsolutePath container, string newContainerName)
{ {

View File

@@ -12,6 +12,7 @@ namespace FileTime.Core.Command
public int Progress => 100; public int Progress => 100;
public AsyncEventHandler ProgressChanged { get; } = new(); public AsyncEventHandler ProgressChanged { get; } = new();
public string DisplayLabel { get; } = "CreateElement"; public string DisplayLabel { get; } = "CreateElement";
public IReadOnlyList<string> CanRunMessages { get; } = new List<string>().AsReadOnly();
public CreateElementCommand(AbsolutePath container, string newElementName) public CreateElementCommand(AbsolutePath container, string newElementName)
{ {

View File

@@ -7,6 +7,9 @@ namespace FileTime.Core.Command
{ {
public class DeleteCommand : IExecutableCommand public class DeleteCommand : IExecutableCommand
{ {
private Func<IContainer, Task>? _deleteContainer;
private Func<IElement, Task>? _deleteElement;
public int Progress => 100; public int Progress => 100;
public AsyncEventHandler ProgressChanged { get; } = new(); public AsyncEventHandler ProgressChanged { get; } = new();
@@ -14,46 +17,79 @@ namespace FileTime.Core.Command
public IList<AbsolutePath> ItemsToDelete { get; } = new List<AbsolutePath>(); public IList<AbsolutePath> ItemsToDelete { get; } = new List<AbsolutePath>();
public string DisplayLabel { get; } = "DeleteCommand"; public string DisplayLabel { get; } = "DeleteCommand";
public bool HardDelete { get; set; }
public IReadOnlyList<string> CanRunMessages { get; } = new List<string>().AsReadOnly();
public async Task<PointInTime> SimulateCommand(PointInTime startPoint) public async Task<PointInTime> SimulateCommand(PointInTime startPoint)
{ {
var newDifferences = new List<Difference>(); var newDifferences = new List<Difference>();
foreach (var itemToDelete in ItemsToDelete) _deleteContainer = (c) =>
{ {
var item = await itemToDelete.Resolve();
newDifferences.Add(new Difference( newDifferences.Add(new Difference(
item.ToDifferenceItemType(), DifferenceItemType.Container,
DifferenceActionType.Delete, DifferenceActionType.Delete,
itemToDelete new AbsolutePath(c)
)); ));
return Task.CompletedTask;
};
_deleteElement = (e) =>
{
newDifferences.Add(new Difference(
DifferenceItemType.Element,
DifferenceActionType.Delete,
new AbsolutePath(e)
));
return Task.CompletedTask;
};
foreach (var item in ItemsToDelete)
{
await TraverseTree((await item.Resolve())!);
} }
return startPoint.WithDifferences(newDifferences); return startPoint.WithDifferences(newDifferences);
} }
public async Task Execute(TimeRunner timeRunner) public async Task Execute(TimeRunner timeRunner)
{ {
_deleteContainer = async (c) =>
{
await c.Delete(HardDelete);
await timeRunner.RefreshContainer.InvokeAsync(this, new AbsolutePath(c));
};
_deleteElement = async (e) => await e.Delete(HardDelete);
foreach (var item in ItemsToDelete) foreach (var item in ItemsToDelete)
{ {
await DoDelete((await item.Resolve())!, timeRunner); await TraverseTree((await item.Resolve())!);
} }
} }
private async Task DoDelete(IItem item, TimeRunner timeRunner) private async Task TraverseTree(IItem item)
{ {
if (item is IContainer container) if (item is IContainer container)
{
if (!HardDelete && container.SupportsDirectoryLevelSoftDelete)
{
if (_deleteContainer != null) await _deleteContainer.Invoke(container);
}
else
{ {
foreach (var child in (await container.GetItems())!) foreach (var child in (await container.GetItems())!)
{ {
await DoDelete(child, timeRunner); await TraverseTree(child);
await child.Delete(); }
if (_deleteContainer != null) await _deleteContainer.Invoke(container);
} }
await item.Delete();
await timeRunner.RefreshContainer.InvokeAsync(this, new AbsolutePath(container));
} }
else if (item is IElement element) else if (item is IElement element)
{ {
await element.Delete(); if (_deleteElement != null) await _deleteElement.Invoke(element);
} }
} }
@@ -63,7 +99,12 @@ namespace FileTime.Core.Command
foreach (var itemPath in ItemsToDelete) foreach (var itemPath in ItemsToDelete)
{ {
var resolvedItem = await itemPath.Resolve(); var resolvedItem = await itemPath.Resolve();
if (!(resolvedItem?.CanDelete ?? true)) if (resolvedItem != null
&& (
resolvedItem.CanDelete == SupportsDelete.False
|| (resolvedItem.CanDelete == SupportsDelete.HardDeleteOnly && !HardDelete)
)
)
{ {
result = CanCommandRun.Forceable; result = CanCommandRun.Forceable;
} }

View File

@@ -6,6 +6,7 @@ namespace FileTime.Core.Command
public interface ICommand public interface ICommand
{ {
string DisplayLabel { get; } string DisplayLabel { get; }
IReadOnlyList<string> CanRunMessages { get; }
Task<CanCommandRun> CanRun(PointInTime startPoint); Task<CanCommandRun> CanRun(PointInTime startPoint);
Task<PointInTime> SimulateCommand(PointInTime startPoint); Task<PointInTime> SimulateCommand(PointInTime startPoint);
int Progress { get; } int Progress { get; }

View File

@@ -14,6 +14,7 @@ namespace FileTime.Core.Command
public int Progress => 100; public int Progress => 100;
public AsyncEventHandler ProgressChanged { get; } = new(); public AsyncEventHandler ProgressChanged { get; } = new();
public string DisplayLabel { get; } = "MoveCommand"; public string DisplayLabel { get; } = "MoveCommand";
public IReadOnlyList<string> CanRunMessages { get; } = new List<string>().AsReadOnly();
public Task<CanCommandRun> CanRun(PointInTime startPoint) public Task<CanCommandRun> CanRun(PointInTime startPoint)
{ {

View File

@@ -13,6 +13,7 @@ namespace FileTime.Core.Command
public int Progress => 100; public int Progress => 100;
public AsyncEventHandler ProgressChanged { get; } = new(); public AsyncEventHandler ProgressChanged { get; } = new();
public string DisplayLabel { get; } = "RenameCommand"; public string DisplayLabel { get; } = "RenameCommand";
public IReadOnlyList<string> CanRunMessages { get; } = new List<string>().AsReadOnly();
public RenameCommand(AbsolutePath source, string target) public RenameCommand(AbsolutePath source, string target)
{ {

View File

@@ -20,6 +20,7 @@ namespace FileTime.Core.Models
Task<bool> CanOpen(); Task<bool> CanOpen();
bool IsLoaded { get; } bool IsLoaded { get; }
bool SupportsDirectoryLevelSoftDelete { get; }
AsyncEventHandler Refreshed { get; } AsyncEventHandler Refreshed { get; }
} }

View File

@@ -7,10 +7,10 @@ namespace FileTime.Core.Models
string Name { get; } string Name { get; }
string? FullName { get; } string? FullName { get; }
bool IsHidden { get; } bool IsHidden { get; }
bool CanDelete { get; } SupportsDelete CanDelete { get; }
bool CanRename { get; } bool CanRename { get; }
IContentProvider Provider { get; } IContentProvider Provider { get; }
Task Delete(); Task Delete(bool hardDelete = false);
Task Rename(string newName); Task Rename(string newName);
IContainer? GetParent(); IContainer? GetParent();
} }

View File

@@ -0,0 +1,9 @@
namespace FileTime.Core.Models
{
public enum SupportsDelete
{
True,
HardDeleteOnly,
False
}
}

View File

@@ -25,12 +25,14 @@ namespace FileTime.Core.Models
public bool IsHidden => BaseContainer.IsHidden; public bool IsHidden => BaseContainer.IsHidden;
public bool IsLoaded => BaseContainer.IsLoaded; public bool IsLoaded => BaseContainer.IsLoaded;
public bool CanDelete => BaseContainer.CanDelete; public SupportsDelete CanDelete => BaseContainer.CanDelete;
public bool CanRename => BaseContainer.CanRename; public bool CanRename => BaseContainer.CanRename;
public IContentProvider Provider => BaseContainer.Provider; public IContentProvider Provider => BaseContainer.Provider;
public IReadOnlyList<Exception> Exceptions => BaseContainer.Exceptions; public IReadOnlyList<Exception> Exceptions => BaseContainer.Exceptions;
public bool SupportsDirectoryLevelSoftDelete => BaseContainer.SupportsDirectoryLevelSoftDelete;
public AsyncEventHandler Refreshed { get; } public AsyncEventHandler Refreshed { get; }
private void RefreshAddBase(Func<object?, AsyncEventArgs, Task> handler) private void RefreshAddBase(Func<object?, AsyncEventArgs, Task> handler)
@@ -151,7 +153,7 @@ namespace FileTime.Core.Models
return Task.FromResult(Elements); return Task.FromResult(Elements);
} }
public async Task Delete() => await BaseContainer.Delete(); public async Task Delete(bool hardDelete = false) => await BaseContainer.Delete();
public async Task<IContainer> Clone() public async Task<IContainer> Clone()
{ {
return new VirtualContainer( return new VirtualContainer(

View File

@@ -24,13 +24,15 @@ namespace FileTime.Core.Providers
#pragma warning disable CS8603 // Possible null reference return. #pragma warning disable CS8603 // Possible null reference return.
public IContentProvider Provider => null; public IContentProvider Provider => null;
#pragma warning restore CS8603 // Possible null reference return. #pragma warning restore CS8603 // Possible null reference return.
public bool CanDelete => false; public SupportsDelete CanDelete => SupportsDelete.False;
public bool CanRename => false; public bool CanRename => false;
public AsyncEventHandler Refreshed { get; } = new(); public AsyncEventHandler Refreshed { get; } = new();
public IReadOnlyList<Exception> Exceptions { get; } = new List<Exception>().AsReadOnly(); public IReadOnlyList<Exception> Exceptions { get; } = new List<Exception>().AsReadOnly();
public bool SupportsDirectoryLevelSoftDelete => false;
public TopContainer(IEnumerable<IContentProvider> contentProviders) public TopContainer(IEnumerable<IContentProvider> contentProviders)
{ {
_contentProviders = new List<IContentProvider>(contentProviders); _contentProviders = new List<IContentProvider>(contentProviders);
@@ -47,7 +49,7 @@ namespace FileTime.Core.Providers
public Task<IElement> CreateElement(string name) => throw new NotImplementedException(); public Task<IElement> CreateElement(string name) => throw new NotImplementedException();
public Task Delete() => throw new NotImplementedException(); public Task Delete(bool hardDelete = false) => throw new NotImplementedException();
public Task<IItem?> GetByPath(string path, bool acceptDeepestMatch = false) => throw new NotImplementedException(); public Task<IItem?> GetByPath(string path, bool acceptDeepestMatch = false) => throw new NotImplementedException();

View File

@@ -19,7 +19,7 @@ namespace FileTime.Core.Timeline
public bool IsHidden => false; public bool IsHidden => false;
public bool CanDelete => true; public SupportsDelete CanDelete => SupportsDelete.True;
public bool CanRename => true; public bool CanRename => true;
@@ -27,6 +27,8 @@ namespace FileTime.Core.Timeline
public IContentProvider VirtualProvider { get; } public IContentProvider VirtualProvider { get; }
public IReadOnlyList<Exception> Exceptions { get; } = new List<Exception>().AsReadOnly(); public IReadOnlyList<Exception> Exceptions { get; } = new List<Exception>().AsReadOnly();
public bool SupportsDirectoryLevelSoftDelete => false;
public TimeContainer(string name, IContainer parent, IContentProvider contentProvider, IContentProvider virtualContentProvider, PointInTime pointInTime) public TimeContainer(string name, IContainer parent, IContentProvider contentProvider, IContentProvider virtualContentProvider, PointInTime pointInTime)
{ {
_parent = parent; _parent = parent;
@@ -44,7 +46,7 @@ namespace FileTime.Core.Timeline
public Task<IElement> CreateElement(string name) => Task.FromResult((IElement)new TimeElement(name, this, Provider, VirtualProvider)); public Task<IElement> CreateElement(string name) => Task.FromResult((IElement)new TimeElement(name, this, Provider, VirtualProvider));
public Task Delete() => Task.CompletedTask; public Task Delete(bool hardDelete = false) => Task.CompletedTask;
public async Task<IItem?> GetByPath(string path, bool acceptDeepestMatch = false) public async Task<IItem?> GetByPath(string path, bool acceptDeepestMatch = false)
{ {

View File

@@ -24,14 +24,14 @@ namespace FileTime.Core.Timeline
public bool IsHidden => false; public bool IsHidden => false;
public bool CanDelete => true; public SupportsDelete CanDelete => SupportsDelete.True;
public bool CanRename => true; public bool CanRename => true;
public IContentProvider Provider { get; } public IContentProvider Provider { get; }
public IContentProvider VirtualProvider { get; } public IContentProvider VirtualProvider { get; }
public Task Delete() => Task.CompletedTask; public Task Delete(bool hardDelete = false) => Task.CompletedTask;
public IContainer? GetParent() => _parent; public IContainer? GetParent() => _parent;

View File

@@ -18,7 +18,7 @@ namespace FileTime.Core.Timeline
public bool IsHidden => false; public bool IsHidden => false;
public bool CanDelete => false; public SupportsDelete CanDelete => SupportsDelete.False;
public bool CanRename => false; public bool CanRename => false;
@@ -26,6 +26,8 @@ namespace FileTime.Core.Timeline
public IReadOnlyList<Exception> Exceptions { get; } = new List<Exception>().AsReadOnly(); public IReadOnlyList<Exception> Exceptions { get; } = new List<Exception>().AsReadOnly();
public bool SupportsDirectoryLevelSoftDelete => false;
public TimeProvider(PointInTime pointInTime) public TimeProvider(PointInTime pointInTime)
{ {
_pointInTime = pointInTime; _pointInTime = pointInTime;
@@ -48,7 +50,7 @@ namespace FileTime.Core.Timeline
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task Delete() => throw new NotSupportedException(); public Task Delete(bool hardDelete = false) => throw new NotSupportedException();
public Task<IItem?> GetByPath(string path, bool acceptDeepestMatch = false) public Task<IItem?> GetByPath(string path, bool acceptDeepestMatch = false)
{ {

Binary file not shown.

View File

@@ -9,7 +9,7 @@
<Application.Resources> <Application.Resources>
<ResourceDictionary> <ResourceDictionary>
<Color x:Key="AppBackgroundColor">#073642</Color> <Color x:Key="AppBackgroundColor">#E7073642</Color>
<Color x:Key="ContainerBackgroundColor">#083e4c</Color> <Color x:Key="ContainerBackgroundColor">#083e4c</Color>
<Color x:Key="TransparentContainerBackgroundColor">#D0083e4c</Color> <Color x:Key="TransparentContainerBackgroundColor">#D0083e4c</Color>
@@ -127,12 +127,13 @@
<converters:IsEmptyConverter x:Key="IsEmptyConverter"/> <converters:IsEmptyConverter x:Key="IsEmptyConverter"/>
<converters:IsEmptyConverter x:Key="IsNotEmptyConverter" Inverse="true"/> <converters:IsEmptyConverter x:Key="IsNotEmptyConverter" Inverse="true"/>
<converters:ExceptionToStringConverter x:Key="ExceptionToStringConverter"/> <converters:ExceptionToStringConverter x:Key="ExceptionToStringConverter"/>
<converters:BoolInverter x:Key="BoolInverter"/>
</ResourceDictionary> </ResourceDictionary>
</Application.Resources> </Application.Resources>
<Application.Styles> <Application.Styles>
<FluentTheme Mode="Light"/> <FluentTheme Mode="Dark"/>
<Style Selector="TextBlock"> <Style Selector="TextBlock">
<Setter Property="Foreground" Value="{DynamicResource ForegroundBrush}"/> <Setter Property="Foreground" Value="{DynamicResource ForegroundBrush}"/>

View File

@@ -34,7 +34,7 @@ namespace FileTime.Avalonia
{ {
desktop.MainWindow = new MainWindow desktop.MainWindow = new MainWindow
{ {
ViewModel = ServiceProvider.GetService<MainPageViewModel>(), DataContext = new MainPageLoadingViewModel(),
}; };
} }

View File

@@ -0,0 +1,16 @@
using System;
using System.Globalization;
using Avalonia.Data.Converters;
namespace FileTime.Avalonia.Converters
{
public class BoolInverter : IValueConverter
{
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) => value is bool b ? !b : value;
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

View File

@@ -46,6 +46,8 @@ namespace FileTime.Avalonia.Services
{ {
if (!File.Exists(_settingsPath)) return; if (!File.Exists(_settingsPath)) return;
try
{
using var stateReader = File.OpenRead(_settingsPath); using var stateReader = File.OpenRead(_settingsPath);
var state = await JsonSerializer.DeserializeAsync<PersistenceRoot>(stateReader); var state = await JsonSerializer.DeserializeAsync<PersistenceRoot>(stateReader);
if (state != null) if (state != null)
@@ -53,8 +55,10 @@ namespace FileTime.Avalonia.Services
await RestoreTabs(state.TabStates); await RestoreTabs(state.TabStates);
} }
} }
catch { }
}
public async Task SaveStatesAsync() public void SaveStatesAsync()
{ {
var state = new PersistenceRoot var state = new PersistenceRoot
{ {
@@ -62,8 +66,8 @@ namespace FileTime.Avalonia.Services
}; };
var settingsDirectory = new DirectoryInfo(string.Join(Path.DirectorySeparatorChar, _settingsPath.Split(Path.DirectorySeparatorChar)[0..^1])); var settingsDirectory = new DirectoryInfo(string.Join(Path.DirectorySeparatorChar, _settingsPath.Split(Path.DirectorySeparatorChar)[0..^1]));
if (!settingsDirectory.Exists) settingsDirectory.Create(); if (!settingsDirectory.Exists) settingsDirectory.Create();
using var stateWriter = File.OpenWrite(_settingsPath); var serializedData = JsonSerializer.Serialize(state, _jsonOptions);
await JsonSerializer.SerializeAsync(stateWriter, state, _jsonOptions); File.WriteAllText(_settingsPath, serializedData);
} }
private TabStates SerializeTabStates() private TabStates SerializeTabStates()
@@ -82,6 +86,8 @@ namespace FileTime.Avalonia.Services
} }
private async Task<bool> RestoreTabs(TabStates? tabStates) private async Task<bool> RestoreTabs(TabStates? tabStates)
{
try
{ {
if (tabStates == null if (tabStates == null
|| tabStates.Tabs == null) || tabStates.Tabs == null)
@@ -127,5 +133,8 @@ namespace FileTime.Avalonia.Services
return true; return true;
} }
catch { }
return false;
}
} }
} }

View File

@@ -0,0 +1,7 @@
namespace FileTime.Avalonia.ViewModels
{
public interface IMainPageViewModelBase
{
bool Loading { get; }
}
}

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FileTime.Avalonia.ViewModels
{
public class MainPageLoadingViewModel : IMainPageViewModelBase
{
public bool Loading => true;
}
}

View File

@@ -34,14 +34,14 @@ namespace FileTime.Avalonia.ViewModels
[Inject(typeof(AppState), PropertyAccessModifier = AccessModifier.Public)] [Inject(typeof(AppState), PropertyAccessModifier = AccessModifier.Public)]
[Inject(typeof(StatePersistenceService), PropertyName = "StatePersistence", PropertyAccessModifier = AccessModifier.Public)] [Inject(typeof(StatePersistenceService), PropertyName = "StatePersistence", PropertyAccessModifier = AccessModifier.Public)]
[Inject(typeof(ItemNameConverterService))] [Inject(typeof(ItemNameConverterService))]
public partial class MainPageViewModel public partial class MainPageViewModel : IMainPageViewModelBase
{ {
const string RAPIDTRAVEL = "rapidTravel"; const string RAPIDTRAVEL = "rapidTravel";
private readonly List<KeyWithModifiers> _previousKeys = new List<KeyWithModifiers>(); private readonly List<KeyWithModifiers> _previousKeys = new();
private readonly List<KeyWithModifiers[]> _keysToSkip = new List<KeyWithModifiers[]>(); private readonly List<KeyWithModifiers[]> _keysToSkip = new();
private List<CommandBinding> _commandBindings = new(); private readonly List<CommandBinding> _commandBindings = new();
private List<CommandBinding> _universalCommandBindings = new(); private readonly List<CommandBinding> _universalCommandBindings = new();
private IClipboard _clipboard; private IClipboard _clipboard;
private TimeRunner _timeRunner; private TimeRunner _timeRunner;
@@ -80,6 +80,9 @@ namespace FileTime.Avalonia.ViewModels
[Property] [Property]
private List<CommandBinding> _allShortcut; private List<CommandBinding> _allShortcut;
[Property]
private bool _loading = true;
public ObservableCollection<ParallelCommandsViewModel> TimelineCommands { get; } = new(); public ObservableCollection<ParallelCommandsViewModel> TimelineCommands { get; } = new();
async partial void OnInitialize() async partial void OnInitialize()
@@ -192,6 +195,8 @@ namespace FileTime.Avalonia.ViewModels
throw new Exception("TODO linux places"); throw new Exception("TODO linux places");
} }
Places = places; Places = places;
await Task.Delay(100);
Loading = false;
} }
private void UpdateParalellCommands(object? sender, EventArgs e) private void UpdateParalellCommands(object? sender, EventArgs e)
@@ -229,7 +234,7 @@ namespace FileTime.Avalonia.ViewModels
return await LocalContentProvider.GetByPath(drive.Name) as IContainer; return await LocalContentProvider.GetByPath(drive.Name) as IContainer;
} }
public async Task OpenContainer() private async Task OpenContainer()
{ {
AppState.RapidTravelText = ""; AppState.RapidTravelText = "";
await AppState.SelectedTab.Open(); await AppState.SelectedTab.Open();
@@ -241,7 +246,7 @@ namespace FileTime.Avalonia.ViewModels
await AppState.SelectedTab.OpenContainer(container); await AppState.SelectedTab.OpenContainer(container);
} }
public async Task OpenOrRun() private async Task OpenOrRun()
{ {
if (AppState.SelectedTab.SelectedItem is ContainerViewModel) if (AppState.SelectedTab.SelectedItem is ContainerViewModel)
{ {
@@ -258,57 +263,57 @@ namespace FileTime.Avalonia.ViewModels
} }
} }
public async Task GoUp() private async Task GoUp()
{ {
await AppState.SelectedTab.GoUp(); await AppState.SelectedTab.GoUp();
} }
public async Task MoveCursorUp() private async Task MoveCursorUp()
{ {
await AppState.SelectedTab.MoveCursorUp(); await AppState.SelectedTab.MoveCursorUp();
} }
public async Task MoveCursorDown() private async Task MoveCursorDown()
{ {
await AppState.SelectedTab.MoveCursorDown(); await AppState.SelectedTab.MoveCursorDown();
} }
public async Task MoveCursorUpPage() private async Task MoveCursorUpPage()
{ {
await AppState.SelectedTab.MoveCursorUpPage(); await AppState.SelectedTab.MoveCursorUpPage();
} }
public async Task MoveCursorDownPage() private async Task MoveCursorDownPage()
{ {
await AppState.SelectedTab.MoveCursorDownPage(); await AppState.SelectedTab.MoveCursorDownPage();
} }
public async Task MoveToFirst() private async Task MoveToFirst()
{ {
await AppState.SelectedTab.MoveCursorToFirst(); await AppState.SelectedTab.MoveCursorToFirst();
} }
public async Task MoveToLast() private async Task MoveToLast()
{ {
await AppState.SelectedTab.MoveCursorToLast(); await AppState.SelectedTab.MoveCursorToLast();
} }
public async Task GotToProvider() private async Task GotToProvider()
{ {
await AppState.SelectedTab.GotToProvider(); await AppState.SelectedTab.GotToProvider();
} }
public async Task GotToRoot() private async Task GotToRoot()
{ {
await AppState.SelectedTab.GotToRoot(); await AppState.SelectedTab.GotToRoot();
} }
public async Task GotToHome() private async Task GotToHome()
{ {
await AppState.SelectedTab.GotToHome(); await AppState.SelectedTab.GotToHome();
} }
public Task EnterRapidTravelMode() private Task EnterRapidTravelMode()
{ {
AppState.ViewMode = ViewMode.RapidTravel; AppState.ViewMode = ViewMode.RapidTravel;
@@ -318,7 +323,7 @@ namespace FileTime.Avalonia.ViewModels
return Task.CompletedTask; return Task.CompletedTask;
} }
public async Task ExitRapidTravelMode() private async Task ExitRapidTravelMode()
{ {
AppState.ViewMode = ViewMode.Default; AppState.ViewMode = ViewMode.Default;
@@ -329,7 +334,7 @@ namespace FileTime.Avalonia.ViewModels
await AppState.SelectedTab.OpenContainer(await AppState.SelectedTab.CurrentLocation.Container.WithoutVirtualContainer(RAPIDTRAVEL)); await AppState.SelectedTab.OpenContainer(await AppState.SelectedTab.CurrentLocation.Container.WithoutVirtualContainer(RAPIDTRAVEL));
} }
public async Task SwitchToTab(int number) private async Task SwitchToTab(int number)
{ {
var tabContainer = AppState.Tabs.FirstOrDefault(t => t.TabNumber == number); var tabContainer = AppState.Tabs.FirstOrDefault(t => t.TabNumber == number);
@@ -364,7 +369,7 @@ namespace FileTime.Avalonia.ViewModels
AppState.SelectedTab = tabContainer; AppState.SelectedTab = tabContainer;
} }
public async Task CloseTab() private async Task CloseTab()
{ {
var tabs = AppState.Tabs; var tabs = AppState.Tabs;
if (tabs.Count > 1) if (tabs.Count > 1)
@@ -385,7 +390,7 @@ namespace FileTime.Avalonia.ViewModels
} }
} }
public Task CreateContainer() private Task CreateContainer()
{ {
var handler = async () => var handler = async () =>
{ {
@@ -403,7 +408,7 @@ namespace FileTime.Avalonia.ViewModels
return Task.CompletedTask; return Task.CompletedTask;
} }
public Task CreateElement() private Task CreateElement()
{ {
var handler = async () => var handler = async () =>
{ {
@@ -421,12 +426,12 @@ namespace FileTime.Avalonia.ViewModels
return Task.CompletedTask; return Task.CompletedTask;
} }
public async Task MarkCurrentItem() private async Task MarkCurrentItem()
{ {
await AppState.SelectedTab.MarkCurrentItem(); await AppState.SelectedTab.MarkCurrentItem();
} }
public async Task Copy() private async Task Copy()
{ {
_clipboard.Clear(); _clipboard.Clear();
_clipboard.SetCommand<CopyCommand>(); _clipboard.SetCommand<CopyCommand>();
@@ -450,7 +455,7 @@ namespace FileTime.Avalonia.ViewModels
} }
} }
public Task Cut() private Task Cut()
{ {
_clipboard.Clear(); _clipboard.Clear();
_clipboard.SetCommand<MoveCommand>(); _clipboard.SetCommand<MoveCommand>();
@@ -458,7 +463,11 @@ namespace FileTime.Avalonia.ViewModels
return Task.CompletedTask; return Task.CompletedTask;
} }
public async Task Delete() private async Task SoftDelete() => await Delete(false);
private async Task HardDelete() => await Delete(true);
public async Task Delete(bool hardDelete = false)
{ {
IList<AbsolutePath>? itemsToDelete = null; IList<AbsolutePath>? itemsToDelete = null;
var askForDelete = false; var askForDelete = false;
@@ -524,6 +533,7 @@ namespace FileTime.Avalonia.ViewModels
async Task HandleDelete() async Task HandleDelete()
{ {
var deleteCommand = new DeleteCommand(); var deleteCommand = new DeleteCommand();
deleteCommand.HardDelete = hardDelete;
foreach (var itemToDelete in itemsToDelete!) foreach (var itemToDelete in itemsToDelete!)
{ {
@@ -535,16 +545,16 @@ namespace FileTime.Avalonia.ViewModels
} }
} }
public async Task PasteMerge() private async Task PasteMerge()
{ {
await Paste(TransportMode.Merge); await Paste(TransportMode.Merge);
} }
public async Task PasteOverwrite() private async Task PasteOverwrite()
{ {
await Paste(TransportMode.Overwrite); await Paste(TransportMode.Overwrite);
} }
public async Task PasteSkip() private async Task PasteSkip()
{ {
await Paste(TransportMode.Skip); await Paste(TransportMode.Skip);
} }
@@ -688,7 +698,7 @@ namespace FileTime.Avalonia.ViewModels
textToCopy = fullName; textToCopy = fullName;
} }
if(textToCopy != null && global::Avalonia.Application.Current?.Clipboard is not null) if (textToCopy != null && global::Avalonia.Application.Current?.Clipboard is not null)
{ {
await global::Avalonia.Application.Current.Clipboard.SetTextAsync(textToCopy); await global::Avalonia.Application.Current.Clipboard.SetTextAsync(textToCopy);
} }
@@ -1053,7 +1063,12 @@ namespace FileTime.Avalonia.ViewModels
"delete", "delete",
FileTime.App.Core.Command.Commands.Delete, FileTime.App.Core.Command.Commands.Delete,
new KeyWithModifiers[]{new KeyWithModifiers(Key.D),new KeyWithModifiers(Key.D, shift: true)}, new KeyWithModifiers[]{new KeyWithModifiers(Key.D),new KeyWithModifiers(Key.D, shift: true)},
Delete), SoftDelete),
new CommandBinding(
"hard delete",
FileTime.App.Core.Command.Commands.Delete,
new KeyWithModifiers[]{new KeyWithModifiers(Key.D, shift: true),new KeyWithModifiers(Key.D, shift: true)},
HardDelete),
new CommandBinding( new CommandBinding(
"paste merge", "paste merge",
FileTime.App.Core.Command.Commands.PasteMerge, FileTime.App.Core.Command.Commands.PasteMerge,

View File

@@ -12,25 +12,34 @@
Icon="/Assets/filetime.ico" Icon="/Assets/filetime.ico"
InputElement.KeyDown="OnKeyDown" InputElement.KeyDown="OnKeyDown"
InputElement.KeyUp="OnKeyUp" InputElement.KeyUp="OnKeyUp"
TransparencyLevelHint="Blur"
Background="Transparent"
ExtendClientAreaToDecorationsHint="True"
Opened="OnWindowOpened"
Closed="OnWindowClosed" Closed="OnWindowClosed"
mc:Ignorable="d"> mc:Ignorable="d">
<Grid
x:Name="RootContainer"
Background="{DynamicResource AppBackgroundBrush}">
<Grid Background="{DynamicResource AppBackgroundBrush}">
<Grid> <Grid>
<Grid.ColumnDefinitions> <Grid ColumnDefinitions="250,*" RowDefinitions="Auto,*" IsVisible="{Binding Loading, Converter={StaticResource BoolInverter}}">
<ColumnDefinition Width="250" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid PointerPressed="HeaderPointerPressed">
<Rectangle Fill="#01000000"/>
<TextBlock Margin="15,10" Text="FileTime"/>
</Grid>
<Grid> <Grid Grid.Column="1" PointerPressed="HeaderPointerPressed">
<Grid.RowDefinitions> <Rectangle Fill="#01000000"/>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" /> <StackPanel Margin="20,10" Orientation="Horizontal">
</Grid.RowDefinitions> <!--TextBlock Text="{Binding AppState.SelectedTab.TabNumber,StringFormat=({0})}" /-->
<local:PathPresenter DataContext="{Binding AppState.SelectedTab.CurrentLocation.Container.FullName}"/>
<TextBlock
Text="{Binding AppState.SelectedTab.SelectedItem.Item.Name}" Foreground="{StaticResource AccentForegroundBrush}" />
</StackPanel>
</Grid>
<Grid Grid.Row="1" RowDefinitions="Auto,Auto">
<Border CornerRadius="10" Background="{DynamicResource ContainerBackgroundBrush}" Padding="10" Margin="10"> <Border CornerRadius="10" Background="{DynamicResource ContainerBackgroundBrush}" Padding="10" Margin="10">
<Grid RowDefinitions="Auto,Auto"> <Grid RowDefinitions="Auto,Auto">
@@ -131,7 +140,7 @@
</Border> </Border>
</Grid> </Grid>
<Grid Grid.Column="2" RowDefinitions="Auto,40,*,Auto"> <Grid Grid.Column="1" Grid.Row="1" RowDefinitions="Auto,40,*,Auto">
<Grid> <Grid>
<ItemsControl Items="{Binding TimelineCommands}"> <ItemsControl Items="{Binding TimelineCommands}">
<ItemsControl.ItemsPanel> <ItemsControl.ItemsPanel>
@@ -158,23 +167,8 @@
</ItemsControl> </ItemsControl>
</Grid> </Grid>
<Grid Grid.Row="1" ColumnDefinitions="*,Auto">
<StackPanel Orientation="Horizontal">
<TextBlock
Margin="10,5"
Text="{Binding AppState.SelectedTab.TabNumber,StringFormat=({0})}" />
<local:PathPresenter Margin="10,5,0,5" DataContext="{Binding AppState.SelectedTab.CurrentLocation.Container.FullName}"/>
<TextBlock
Margin="0,5,10,5"
Text="{Binding AppState.SelectedTab.SelectedItem.Item.Name}" Foreground="{StaticResource AccentForegroundBrush}" />
</StackPanel>
<ItemsControl <ItemsControl
Grid.Column="1" Grid.Row="1"
HorizontalAlignment="Right"
Items="{Binding AppState.Tabs}"> Items="{Binding AppState.Tabs}">
<ItemsControl.ItemsPanel> <ItemsControl.ItemsPanel>
<ItemsPanelTemplate> <ItemsPanelTemplate>
@@ -200,7 +194,6 @@
</DataTemplate> </DataTemplate>
</ItemsControl.ItemTemplate> </ItemsControl.ItemTemplate>
</ItemsControl> </ItemsControl>
</Grid>
<Grid <Grid
Grid.Row="2" Grid.Row="2"
@@ -523,4 +516,12 @@
</Grid> </Grid>
</Border> </Border>
</Grid> </Grid>
<Grid IsVisible="{Binding Loading}">
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<Image Source="/Assets/filetime.ico" Width="128" Height="128"/>
<TextBlock Text="Loading..." HorizontalAlignment="Center" Margin="50"/>
</StackPanel>
</Grid>
</Grid>
</Window> </Window>

View File

@@ -6,6 +6,7 @@ using Avalonia.Markup.Xaml;
using FileTime.Avalonia.Misc; using FileTime.Avalonia.Misc;
using FileTime.Avalonia.Models; using FileTime.Avalonia.Models;
using FileTime.Avalonia.ViewModels; using FileTime.Avalonia.ViewModels;
using Microsoft.Extensions.DependencyInjection;
using System; using System;
using System.Linq; using System.Linq;
@@ -98,7 +99,7 @@ namespace FileTime.Avalonia.Views
private void OnPlacePointerPressed(object sender, PointerPressedEventArgs e) private void OnPlacePointerPressed(object sender, PointerPressedEventArgs e)
{ {
if(!e.Handled if (!e.Handled
&& ViewModel != null && ViewModel != null
&& e.GetCurrentPoint(this).Properties.IsLeftButtonPressed && e.GetCurrentPoint(this).Properties.IsLeftButtonPressed
&& sender is StyledElement control && sender is StyledElement control
@@ -111,7 +112,38 @@ namespace FileTime.Avalonia.Views
private void OnWindowClosed(object sender, EventArgs e) private void OnWindowClosed(object sender, EventArgs e)
{ {
ViewModel?.StatePersistence.SaveStatesAsync().Wait(); try
{
ViewModel?.StatePersistence.SaveStatesAsync();
}
catch { }
}
private void OnWindowOpened(object sender, EventArgs e)
{
if (ViewModel is not MainPageViewModel)
{
ViewModel = App.ServiceProvider.GetService<MainPageViewModel>();
}
}
private void HeaderPointerPressed(object sender, PointerPressedEventArgs e)
{
if (e.ClickCount == 2)
{
if (WindowState == WindowState.Maximized)
{
WindowState = WindowState.Normal;
}
else
{
WindowState = WindowState.Maximized;
}
}
else
{
BeginMoveDrag(e);
}
} }
} }
} }

View File

@@ -0,0 +1,157 @@
using System.Runtime.InteropServices;
namespace FileTime.Providers.Local.Interop
{
//https://stackoverflow.com/questions/3282418/send-a-file-to-the-recycle-bin
public static class WindowsInterop
{
/// <summary>
/// Possible flags for the SHFileOperation method.
/// </summary>
[Flags]
public enum FileOperationFlags : ushort
{
/// <summary>
/// Do not show a dialog during the process
/// </summary>
FOF_SILENT = 0x0004,
/// <summary>
/// Do not ask the user to confirm selection
/// </summary>
FOF_NOCONFIRMATION = 0x0010,
/// <summary>
/// Delete the file to the recycle bin. (Required flag to send a file to the bin
/// </summary>
FOF_ALLOWUNDO = 0x0040,
/// <summary>
/// Do not show the names of the files or folders that are being recycled.
/// </summary>
FOF_SIMPLEPROGRESS = 0x0100,
/// <summary>
/// Surpress errors, if any occur during the process.
/// </summary>
FOF_NOERRORUI = 0x0400,
/// <summary>
/// Warn if files are too big to fit in the recycle bin and will need
/// to be deleted completely.
/// </summary>
FOF_WANTNUKEWARNING = 0x4000,
}
/// <summary>
/// File Operation Function Type for SHFileOperation
/// </summary>
public enum FileOperationType : uint
{
/// <summary>
/// Move the objects
/// </summary>
FO_MOVE = 0x0001,
/// <summary>
/// Copy the objects
/// </summary>
FO_COPY = 0x0002,
/// <summary>
/// Delete (or recycle) the objects
/// </summary>
FO_DELETE = 0x0003,
/// <summary>
/// Rename the object(s)
/// </summary>
FO_RENAME = 0x0004,
}
/// <summary>
/// SHFILEOPSTRUCT for SHFileOperation from COM
/// </summary>
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
private struct SHFILEOPSTRUCT
{
public IntPtr hwnd;
[MarshalAs(UnmanagedType.U4)]
public FileOperationType wFunc;
public string pFrom;
public string pTo;
public FileOperationFlags fFlags;
[MarshalAs(UnmanagedType.Bool)]
public bool fAnyOperationsAborted;
public IntPtr hNameMappings;
public string lpszProgressTitle;
}
[DllImport("shell32.dll", CharSet = CharSet.Auto)]
private static extern int SHFileOperation(ref SHFILEOPSTRUCT FileOp);
/// <summary>
/// Send file to recycle bin
/// </summary>
/// <param name="path">Location of directory or file to recycle</param>
/// <param name="flags">FileOperationFlags to add in addition to FOF_ALLOWUNDO</param>
public static bool Send(string path, FileOperationFlags flags)
{
try
{
var fs = new SHFILEOPSTRUCT
{
wFunc = FileOperationType.FO_DELETE,
pFrom = path + '\0' + '\0',
fFlags = FileOperationFlags.FOF_ALLOWUNDO | flags
};
SHFileOperation(ref fs);
return true;
}
catch (Exception)
{
return false;
}
}
/// <summary>
/// Send file to recycle bin. Display dialog, display warning if files are too big to fit (FOF_WANTNUKEWARNING)
/// </summary>
/// <param name="path">Location of directory or file to recycle</param>
public static bool Send(string path)
{
return Send(path, FileOperationFlags.FOF_NOCONFIRMATION | FileOperationFlags.FOF_WANTNUKEWARNING);
}
/// <summary>
/// Send file silently to recycle bin. Surpress dialog, surpress errors, delete if too large.
/// </summary>
/// <param name="path">Location of directory or file to recycle</param>
public static bool MoveToRecycleBin(string path)
{
return Send(path, FileOperationFlags.FOF_NOCONFIRMATION | FileOperationFlags.FOF_NOERRORUI | FileOperationFlags.FOF_SILENT);
}
private static bool deleteFile(string path, FileOperationFlags flags)
{
try
{
var fs = new SHFILEOPSTRUCT
{
wFunc = FileOperationType.FO_DELETE,
pFrom = path + '\0' + '\0',
fFlags = flags
};
SHFileOperation(ref fs);
return true;
}
catch (Exception)
{
return false;
}
}
public static bool DeleteCompletelySilent(string path)
{
return deleteFile(path,
FileOperationFlags.FOF_NOCONFIRMATION | FileOperationFlags.FOF_NOERRORUI |
FileOperationFlags.FOF_SILENT);
}
}
}

View File

@@ -27,10 +27,12 @@ namespace FileTime.Providers.Local
public AsyncEventHandler Refreshed { get; } = new(); public AsyncEventHandler Refreshed { get; } = new();
public bool IsCaseInsensitive { get; } public bool IsCaseInsensitive { get; }
public bool CanDelete => false; public SupportsDelete CanDelete => SupportsDelete.False;
public bool CanRename => false; public bool CanRename => false;
public IReadOnlyList<Exception> Exceptions { get; } = new List<Exception>().AsReadOnly(); public IReadOnlyList<Exception> Exceptions { get; } = new List<Exception>().AsReadOnly();
public bool SupportsDirectoryLevelSoftDelete => false;
public LocalContentProvider(ILogger<LocalContentProvider> logger) public LocalContentProvider(ILogger<LocalContentProvider> logger)
{ {
_logger = logger; _logger = logger;
@@ -76,7 +78,7 @@ namespace FileTime.Providers.Local
public Task<IElement> CreateElement(string name) => throw new NotSupportedException(); public Task<IElement> CreateElement(string name) => throw new NotSupportedException();
public Task<bool> IsExists(string name) => Task.FromResult(_rootContainers.Any(i => i.Name == name)); public Task<bool> IsExists(string name) => Task.FromResult(_rootContainers.Any(i => i.Name == name));
public Task Delete() => throw new NotSupportedException(); public Task Delete(bool hardDelete = false) => throw new NotSupportedException();
internal string NormalizePath(string path) => IsCaseInsensitive ? path.ToLower() : path; internal string NormalizePath(string path) => IsCaseInsensitive ? path.ToLower() : path;

View File

@@ -2,6 +2,7 @@ using System.Runtime.InteropServices;
using FileTime.Core.Models; using FileTime.Core.Models;
using FileTime.Core.Providers; using FileTime.Core.Providers;
using FileTime.Providers.Local.Extensions; using FileTime.Providers.Local.Extensions;
using FileTime.Providers.Local.Interop;
using Mono.Unix; using Mono.Unix;
namespace FileTime.Providers.Local namespace FileTime.Providers.Local
@@ -24,7 +25,7 @@ namespace FileTime.Providers.Local
public string Attributes => GetAttributes(); public string Attributes => GetAttributes();
public DateTime CreatedAt => File.CreationTime; public DateTime CreatedAt => File.CreationTime;
public bool CanDelete => true; public SupportsDelete CanDelete => SupportsDelete.True;
public bool CanRename => true; public bool CanRename => true;
private readonly LocalFolder _parent; private readonly LocalFolder _parent;
@@ -41,9 +42,16 @@ namespace FileTime.Providers.Local
public string GetPrimaryAttributeText() => File.Length.ToSizeString(); public string GetPrimaryAttributeText() => File.Length.ToSizeString();
public Task Delete() public Task Delete(bool hardDelete = false)
{
if (hardDelete)
{ {
File.Delete(); File.Delete();
}
else
{
WindowsInterop.MoveToRecycleBin(File.FullName);
}
return Task.CompletedTask; return Task.CompletedTask;
} }
public async Task Rename(string newName) public async Task Rename(string newName)

View File

@@ -2,6 +2,7 @@ using System.Runtime.InteropServices;
using AsyncEvent; using AsyncEvent;
using FileTime.Core.Models; using FileTime.Core.Models;
using FileTime.Core.Providers; using FileTime.Core.Providers;
using FileTime.Providers.Local.Interop;
namespace FileTime.Providers.Local namespace FileTime.Providers.Local
{ {
@@ -23,7 +24,7 @@ namespace FileTime.Providers.Local
public string FullName { get; } public string FullName { get; }
public bool IsLoaded => _items != null; public bool IsLoaded => _items != null;
public bool CanDelete => true; public SupportsDelete CanDelete { get; }
public bool CanRename => true; public bool CanRename => true;
public AsyncEventHandler Refreshed { get; } = new(); public AsyncEventHandler Refreshed { get; } = new();
@@ -33,6 +34,8 @@ namespace FileTime.Providers.Local
public DateTime CreatedAt => Directory.CreationTime; public DateTime CreatedAt => Directory.CreationTime;
public IReadOnlyList<Exception> Exceptions { get; } public IReadOnlyList<Exception> Exceptions { get; }
public bool SupportsDirectoryLevelSoftDelete { get; }
public LocalFolder(DirectoryInfo directory, LocalContentProvider contentProvider, IContainer? parent) public LocalFolder(DirectoryInfo directory, LocalContentProvider contentProvider, IContainer? parent)
{ {
Directory = directory; Directory = directory;
@@ -44,6 +47,12 @@ namespace FileTime.Providers.Local
Name = directory.Name.TrimEnd(Path.DirectorySeparatorChar); Name = directory.Name.TrimEnd(Path.DirectorySeparatorChar);
FullName = parent?.FullName == null ? Name : parent.FullName + Constants.SeparatorChar + Name; FullName = parent?.FullName == null ? Name : parent.FullName + Constants.SeparatorChar + Name;
Provider = contentProvider; Provider = contentProvider;
//TODO: Linux soft delete
SupportsDirectoryLevelSoftDelete = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
CanDelete = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
? SupportsDelete.True
: SupportsDelete.HardDeleteOnly;
} }
public IContainer? GetParent() => _parent; public IContainer? GetParent() => _parent;
@@ -124,9 +133,16 @@ namespace FileTime.Providers.Local
public async Task<bool> IsExists(string name) => (await GetItems())?.Any(i => Provider.NormalizePath(i.Name) == Provider.NormalizePath(name)) ?? false; public async Task<bool> IsExists(string name) => (await GetItems())?.Any(i => Provider.NormalizePath(i.Name) == Provider.NormalizePath(name)) ?? false;
public Task Delete() public Task Delete(bool hardDelete = false)
{
if (hardDelete)
{ {
Directory.Delete(true); Directory.Delete(true);
}
else
{
WindowsInterop.MoveToRecycleBin(Directory.FullName);
}
return Task.CompletedTask; return Task.CompletedTask;
} }
public async Task Rename(string newName) public async Task Rename(string newName)

View File

@@ -23,12 +23,14 @@ namespace FileTime.Providers.Smb
public bool IsLoaded => true; public bool IsLoaded => true;
public IContentProvider Provider => this; public IContentProvider Provider => this;
public bool CanDelete => false; public SupportsDelete CanDelete => SupportsDelete.False;
public bool CanRename => false; public bool CanRename => false;
public IReadOnlyList<Exception> Exceptions { get; } = new List<Exception>().AsReadOnly(); public IReadOnlyList<Exception> Exceptions { get; } = new List<Exception>().AsReadOnly();
public AsyncEventHandler Refreshed { get; } = new(); public AsyncEventHandler Refreshed { get; } = new();
public bool SupportsDirectoryLevelSoftDelete => false;
public SmbContentProvider(IInputInterface inputInterface) public SmbContentProvider(IInputInterface inputInterface)
{ {
_rootContainers = new List<IContainer>(); _rootContainers = new List<IContainer>();
@@ -59,7 +61,7 @@ namespace FileTime.Providers.Smb
throw new NotSupportedException(); throw new NotSupportedException();
} }
public Task Delete() public Task Delete(bool hardDelete = false)
{ {
throw new NotSupportedException(); throw new NotSupportedException();
} }

View File

@@ -13,7 +13,7 @@ namespace FileTime.Providers.Smb
public string? FullName { get; } public string? FullName { get; }
public bool IsHidden => false; public bool IsHidden => false;
public bool CanDelete => true; public SupportsDelete CanDelete => SupportsDelete.True;
public bool CanRename => true; public bool CanRename => true;
public IContentProvider Provider { get; } public IContentProvider Provider { get; }
@@ -28,7 +28,7 @@ namespace FileTime.Providers.Smb
_parent = parent; _parent = parent;
} }
public Task Delete() public Task Delete(bool hardDelete = false)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }

View File

@@ -23,12 +23,14 @@ namespace FileTime.Providers.Smb
public SmbContentProvider Provider { get; } public SmbContentProvider Provider { get; }
IContentProvider IItem.Provider => Provider; IContentProvider IItem.Provider => Provider;
public bool CanDelete => true; public SupportsDelete CanDelete => SupportsDelete.True;
public bool CanRename => true; public bool CanRename => true;
public AsyncEventHandler Refreshed { get; } = new(); public AsyncEventHandler Refreshed { get; } = new();
public IReadOnlyList<Exception> Exceptions { get; } = new List<Exception>().AsReadOnly(); public IReadOnlyList<Exception> Exceptions { get; } = new List<Exception>().AsReadOnly();
public bool SupportsDirectoryLevelSoftDelete => false;
public SmbFolder(string name, SmbContentProvider contentProvider, SmbShare smbShare, IContainer parent) public SmbFolder(string name, SmbContentProvider contentProvider, SmbShare smbShare, IContainer parent)
{ {
_parent = parent; _parent = parent;
@@ -77,7 +79,7 @@ namespace FileTime.Providers.Smb
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task Delete() public Task Delete(bool hardDelete = false)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }

View File

@@ -32,12 +32,14 @@ namespace FileTime.Providers.Smb
public SmbContentProvider Provider { get; } public SmbContentProvider Provider { get; }
IContentProvider IItem.Provider => Provider; IContentProvider IItem.Provider => Provider;
public bool CanDelete => true; public SupportsDelete CanDelete => SupportsDelete.True;
public bool CanRename => false; public bool CanRename => false;
public IReadOnlyList<Exception> Exceptions { get; } = new List<Exception>().AsReadOnly(); public IReadOnlyList<Exception> Exceptions { get; } = new List<Exception>().AsReadOnly();
public AsyncEventHandler Refreshed { get; } = new(); public AsyncEventHandler Refreshed { get; } = new();
public bool SupportsDirectoryLevelSoftDelete => false;
public SmbServer(string path, SmbContentProvider contentProvider, IInputInterface inputInterface) public SmbServer(string path, SmbContentProvider contentProvider, IInputInterface inputInterface)
{ {
_inputInterface = inputInterface; _inputInterface = inputInterface;
@@ -72,7 +74,7 @@ namespace FileTime.Providers.Smb
throw new NotSupportedException(); throw new NotSupportedException();
} }
public Task Delete() public Task Delete(bool hardDelete = false)
{ {
return Task.CompletedTask; return Task.CompletedTask;
} }

View File

@@ -23,12 +23,14 @@ namespace FileTime.Providers.Smb
public SmbContentProvider Provider { get; } public SmbContentProvider Provider { get; }
IContentProvider IItem.Provider => Provider; IContentProvider IItem.Provider => Provider;
public bool CanDelete => false; public SupportsDelete CanDelete => SupportsDelete.False;
public bool CanRename => false; public bool CanRename => false;
public AsyncEventHandler Refreshed { get; } = new(); public AsyncEventHandler Refreshed { get; } = new();
public IReadOnlyList<Exception> Exceptions { get; } = new List<Exception>().AsReadOnly(); public IReadOnlyList<Exception> Exceptions { get; } = new List<Exception>().AsReadOnly();
public bool SupportsDirectoryLevelSoftDelete => false;
public SmbShare(string name, SmbContentProvider contentProvider, IContainer parent, SmbClientContext smbClientContext) public SmbShare(string name, SmbContentProvider contentProvider, IContainer parent, SmbClientContext smbClientContext)
{ {
_parent = parent; _parent = parent;
@@ -65,7 +67,7 @@ namespace FileTime.Providers.Smb
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task Delete() public Task Delete(bool hardDelete = false)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }