Modern UI, Loading screen CanRunMessages
This commit is contained in:
@@ -22,6 +22,7 @@ namespace FileTime.Core.Command
|
||||
public AsyncEventHandler ProgressChanged { get; } = new();
|
||||
|
||||
public string DisplayLabel { get; } = "Copy";
|
||||
public IReadOnlyList<string> CanRunMessages { get; } = new List<string>().AsReadOnly();
|
||||
|
||||
private async Task UpdateProgress()
|
||||
{
|
||||
@@ -73,7 +74,7 @@ namespace FileTime.Core.Command
|
||||
return (IContainer)(await newContainerDiff.AbsolutePath.Resolve())!;
|
||||
};
|
||||
|
||||
await DoCopy(Sources, Target, TransportMode.Value);
|
||||
await TraverseTree(Sources, Target, TransportMode.Value);
|
||||
|
||||
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()
|
||||
@@ -136,11 +137,11 @@ namespace FileTime.Core.Command
|
||||
return Task.CompletedTask;
|
||||
};
|
||||
|
||||
await DoCopy(Sources, Target, TransportMode.Value);
|
||||
await TraverseTree(Sources, Target, TransportMode.Value);
|
||||
_operationStatuses = operationStatuses;
|
||||
}
|
||||
|
||||
private async Task DoCopy(
|
||||
private async Task TraverseTree(
|
||||
IEnumerable<AbsolutePath> sources,
|
||||
IContainer target,
|
||||
TransportMode transportMode)
|
||||
@@ -159,7 +160,7 @@ namespace FileTime.Core.Command
|
||||
var childDirectories = (await container.GetContainers())!.Select(d => new AbsolutePath(d));
|
||||
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));
|
||||
}
|
||||
else if (item is IElement element)
|
||||
|
||||
@@ -13,6 +13,7 @@ namespace FileTime.Core.Command
|
||||
|
||||
public AsyncEventHandler ProgressChanged { get; } = new();
|
||||
public string DisplayLabel { get; } = "CreateContainer";
|
||||
public IReadOnlyList<string> CanRunMessages { get; } = new List<string>().AsReadOnly();
|
||||
|
||||
public CreateContainerCommand(AbsolutePath container, string newContainerName)
|
||||
{
|
||||
|
||||
@@ -12,6 +12,7 @@ namespace FileTime.Core.Command
|
||||
public int Progress => 100;
|
||||
public AsyncEventHandler ProgressChanged { get; } = new();
|
||||
public string DisplayLabel { get; } = "CreateElement";
|
||||
public IReadOnlyList<string> CanRunMessages { get; } = new List<string>().AsReadOnly();
|
||||
|
||||
public CreateElementCommand(AbsolutePath container, string newElementName)
|
||||
{
|
||||
|
||||
@@ -7,6 +7,9 @@ namespace FileTime.Core.Command
|
||||
{
|
||||
public class DeleteCommand : IExecutableCommand
|
||||
{
|
||||
private Func<IContainer, Task>? _deleteContainer;
|
||||
private Func<IElement, Task>? _deleteElement;
|
||||
|
||||
public int Progress => 100;
|
||||
|
||||
public AsyncEventHandler ProgressChanged { get; } = new();
|
||||
@@ -14,46 +17,79 @@ namespace FileTime.Core.Command
|
||||
public IList<AbsolutePath> ItemsToDelete { get; } = new List<AbsolutePath>();
|
||||
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)
|
||||
{
|
||||
var newDifferences = new List<Difference>();
|
||||
|
||||
foreach (var itemToDelete in ItemsToDelete)
|
||||
_deleteContainer = (c) =>
|
||||
{
|
||||
var item = await itemToDelete.Resolve();
|
||||
newDifferences.Add(new Difference(
|
||||
item.ToDifferenceItemType(),
|
||||
DifferenceItemType.Container,
|
||||
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);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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 (!HardDelete && container.SupportsDirectoryLevelSoftDelete)
|
||||
{
|
||||
if (_deleteContainer != null) await _deleteContainer.Invoke(container);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var child in (await container.GetItems())!)
|
||||
{
|
||||
await DoDelete(child, timeRunner);
|
||||
await child.Delete();
|
||||
await TraverseTree(child);
|
||||
}
|
||||
|
||||
if (_deleteContainer != null) await _deleteContainer.Invoke(container);
|
||||
}
|
||||
|
||||
await item.Delete();
|
||||
await timeRunner.RefreshContainer.InvokeAsync(this, new AbsolutePath(container));
|
||||
}
|
||||
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)
|
||||
{
|
||||
var resolvedItem = await itemPath.Resolve();
|
||||
if (!(resolvedItem?.CanDelete ?? true))
|
||||
if (resolvedItem != null
|
||||
&& (
|
||||
resolvedItem.CanDelete == SupportsDelete.False
|
||||
|| (resolvedItem.CanDelete == SupportsDelete.HardDeleteOnly && !HardDelete)
|
||||
)
|
||||
)
|
||||
{
|
||||
result = CanCommandRun.Forceable;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ namespace FileTime.Core.Command
|
||||
public interface ICommand
|
||||
{
|
||||
string DisplayLabel { get; }
|
||||
IReadOnlyList<string> CanRunMessages { get; }
|
||||
Task<CanCommandRun> CanRun(PointInTime startPoint);
|
||||
Task<PointInTime> SimulateCommand(PointInTime startPoint);
|
||||
int Progress { get; }
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace FileTime.Core.Command
|
||||
public int Progress => 100;
|
||||
public AsyncEventHandler ProgressChanged { get; } = new();
|
||||
public string DisplayLabel { get; } = "MoveCommand";
|
||||
public IReadOnlyList<string> CanRunMessages { get; } = new List<string>().AsReadOnly();
|
||||
|
||||
public Task<CanCommandRun> CanRun(PointInTime startPoint)
|
||||
{
|
||||
|
||||
@@ -13,6 +13,7 @@ namespace FileTime.Core.Command
|
||||
public int Progress => 100;
|
||||
public AsyncEventHandler ProgressChanged { get; } = new();
|
||||
public string DisplayLabel { get; } = "RenameCommand";
|
||||
public IReadOnlyList<string> CanRunMessages { get; } = new List<string>().AsReadOnly();
|
||||
|
||||
public RenameCommand(AbsolutePath source, string target)
|
||||
{
|
||||
|
||||
@@ -20,6 +20,7 @@ namespace FileTime.Core.Models
|
||||
Task<bool> CanOpen();
|
||||
|
||||
bool IsLoaded { get; }
|
||||
bool SupportsDirectoryLevelSoftDelete { get; }
|
||||
|
||||
AsyncEventHandler Refreshed { get; }
|
||||
}
|
||||
|
||||
@@ -7,10 +7,10 @@ namespace FileTime.Core.Models
|
||||
string Name { get; }
|
||||
string? FullName { get; }
|
||||
bool IsHidden { get; }
|
||||
bool CanDelete { get; }
|
||||
SupportsDelete CanDelete { get; }
|
||||
bool CanRename { get; }
|
||||
IContentProvider Provider { get; }
|
||||
Task Delete();
|
||||
Task Delete(bool hardDelete = false);
|
||||
Task Rename(string newName);
|
||||
IContainer? GetParent();
|
||||
}
|
||||
|
||||
9
src/Core/FileTime.Core/Models/SupportsDelete.cs
Normal file
9
src/Core/FileTime.Core/Models/SupportsDelete.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace FileTime.Core.Models
|
||||
{
|
||||
public enum SupportsDelete
|
||||
{
|
||||
True,
|
||||
HardDeleteOnly,
|
||||
False
|
||||
}
|
||||
}
|
||||
@@ -25,12 +25,14 @@ namespace FileTime.Core.Models
|
||||
|
||||
public bool IsHidden => BaseContainer.IsHidden;
|
||||
public bool IsLoaded => BaseContainer.IsLoaded;
|
||||
public bool CanDelete => BaseContainer.CanDelete;
|
||||
public SupportsDelete CanDelete => BaseContainer.CanDelete;
|
||||
public bool CanRename => BaseContainer.CanRename;
|
||||
|
||||
public IContentProvider Provider => BaseContainer.Provider;
|
||||
public IReadOnlyList<Exception> Exceptions => BaseContainer.Exceptions;
|
||||
|
||||
public bool SupportsDirectoryLevelSoftDelete => BaseContainer.SupportsDirectoryLevelSoftDelete;
|
||||
|
||||
public AsyncEventHandler Refreshed { get; }
|
||||
|
||||
private void RefreshAddBase(Func<object?, AsyncEventArgs, Task> handler)
|
||||
@@ -151,7 +153,7 @@ namespace FileTime.Core.Models
|
||||
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()
|
||||
{
|
||||
return new VirtualContainer(
|
||||
|
||||
@@ -24,13 +24,15 @@ namespace FileTime.Core.Providers
|
||||
#pragma warning disable CS8603 // Possible null reference return.
|
||||
public IContentProvider Provider => null;
|
||||
#pragma warning restore CS8603 // Possible null reference return.
|
||||
public bool CanDelete => false;
|
||||
public SupportsDelete CanDelete => SupportsDelete.False;
|
||||
public bool CanRename => false;
|
||||
|
||||
public AsyncEventHandler Refreshed { get; } = new();
|
||||
|
||||
public IReadOnlyList<Exception> Exceptions { get; } = new List<Exception>().AsReadOnly();
|
||||
|
||||
public bool SupportsDirectoryLevelSoftDelete => false;
|
||||
|
||||
public TopContainer(IEnumerable<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 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();
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace FileTime.Core.Timeline
|
||||
|
||||
public bool IsHidden => false;
|
||||
|
||||
public bool CanDelete => true;
|
||||
public SupportsDelete CanDelete => SupportsDelete.True;
|
||||
|
||||
public bool CanRename => true;
|
||||
|
||||
@@ -27,6 +27,8 @@ namespace FileTime.Core.Timeline
|
||||
public IContentProvider VirtualProvider { get; }
|
||||
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)
|
||||
{
|
||||
_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 Delete() => Task.CompletedTask;
|
||||
public Task Delete(bool hardDelete = false) => Task.CompletedTask;
|
||||
|
||||
public async Task<IItem?> GetByPath(string path, bool acceptDeepestMatch = false)
|
||||
{
|
||||
|
||||
@@ -24,14 +24,14 @@ namespace FileTime.Core.Timeline
|
||||
|
||||
public bool IsHidden => false;
|
||||
|
||||
public bool CanDelete => true;
|
||||
public SupportsDelete CanDelete => SupportsDelete.True;
|
||||
|
||||
public bool CanRename => true;
|
||||
|
||||
public IContentProvider Provider { get; }
|
||||
public IContentProvider VirtualProvider { get; }
|
||||
|
||||
public Task Delete() => Task.CompletedTask;
|
||||
public Task Delete(bool hardDelete = false) => Task.CompletedTask;
|
||||
|
||||
public IContainer? GetParent() => _parent;
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace FileTime.Core.Timeline
|
||||
|
||||
public bool IsHidden => false;
|
||||
|
||||
public bool CanDelete => false;
|
||||
public SupportsDelete CanDelete => SupportsDelete.False;
|
||||
|
||||
public bool CanRename => false;
|
||||
|
||||
@@ -26,6 +26,8 @@ namespace FileTime.Core.Timeline
|
||||
|
||||
public IReadOnlyList<Exception> Exceptions { get; } = new List<Exception>().AsReadOnly();
|
||||
|
||||
public bool SupportsDirectoryLevelSoftDelete => false;
|
||||
|
||||
public TimeProvider(PointInTime pointInTime)
|
||||
{
|
||||
_pointInTime = pointInTime;
|
||||
@@ -48,7 +50,7 @@ namespace FileTime.Core.Timeline
|
||||
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)
|
||||
{
|
||||
|
||||
Binary file not shown.
@@ -9,7 +9,7 @@
|
||||
|
||||
<Application.Resources>
|
||||
<ResourceDictionary>
|
||||
<Color x:Key="AppBackgroundColor">#073642</Color>
|
||||
<Color x:Key="AppBackgroundColor">#E7073642</Color>
|
||||
<Color x:Key="ContainerBackgroundColor">#083e4c</Color>
|
||||
<Color x:Key="TransparentContainerBackgroundColor">#D0083e4c</Color>
|
||||
|
||||
@@ -127,12 +127,13 @@
|
||||
<converters:IsEmptyConverter x:Key="IsEmptyConverter"/>
|
||||
<converters:IsEmptyConverter x:Key="IsNotEmptyConverter" Inverse="true"/>
|
||||
<converters:ExceptionToStringConverter x:Key="ExceptionToStringConverter"/>
|
||||
<converters:BoolInverter x:Key="BoolInverter"/>
|
||||
|
||||
</ResourceDictionary>
|
||||
</Application.Resources>
|
||||
|
||||
<Application.Styles>
|
||||
<FluentTheme Mode="Light"/>
|
||||
<FluentTheme Mode="Dark"/>
|
||||
|
||||
<Style Selector="TextBlock">
|
||||
<Setter Property="Foreground" Value="{DynamicResource ForegroundBrush}"/>
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace FileTime.Avalonia
|
||||
{
|
||||
desktop.MainWindow = new MainWindow
|
||||
{
|
||||
ViewModel = ServiceProvider.GetService<MainPageViewModel>(),
|
||||
DataContext = new MainPageLoadingViewModel(),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
16
src/GuiApp/FileTime.Avalonia/Converters/BoolInverter.cs
Normal file
16
src/GuiApp/FileTime.Avalonia/Converters/BoolInverter.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,6 +46,8 @@ namespace FileTime.Avalonia.Services
|
||||
{
|
||||
if (!File.Exists(_settingsPath)) return;
|
||||
|
||||
try
|
||||
{
|
||||
using var stateReader = File.OpenRead(_settingsPath);
|
||||
var state = await JsonSerializer.DeserializeAsync<PersistenceRoot>(stateReader);
|
||||
if (state != null)
|
||||
@@ -53,8 +55,10 @@ namespace FileTime.Avalonia.Services
|
||||
await RestoreTabs(state.TabStates);
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
public async Task SaveStatesAsync()
|
||||
public void SaveStatesAsync()
|
||||
{
|
||||
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]));
|
||||
if (!settingsDirectory.Exists) settingsDirectory.Create();
|
||||
using var stateWriter = File.OpenWrite(_settingsPath);
|
||||
await JsonSerializer.SerializeAsync(stateWriter, state, _jsonOptions);
|
||||
var serializedData = JsonSerializer.Serialize(state, _jsonOptions);
|
||||
File.WriteAllText(_settingsPath, serializedData);
|
||||
}
|
||||
|
||||
private TabStates SerializeTabStates()
|
||||
@@ -82,6 +86,8 @@ namespace FileTime.Avalonia.Services
|
||||
}
|
||||
|
||||
private async Task<bool> RestoreTabs(TabStates? tabStates)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (tabStates == null
|
||||
|| tabStates.Tabs == null)
|
||||
@@ -127,5 +133,8 @@ namespace FileTime.Avalonia.Services
|
||||
|
||||
return true;
|
||||
}
|
||||
catch { }
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace FileTime.Avalonia.ViewModels
|
||||
{
|
||||
public interface IMainPageViewModelBase
|
||||
{
|
||||
bool Loading { get; }
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -34,14 +34,14 @@ namespace FileTime.Avalonia.ViewModels
|
||||
[Inject(typeof(AppState), PropertyAccessModifier = AccessModifier.Public)]
|
||||
[Inject(typeof(StatePersistenceService), PropertyName = "StatePersistence", PropertyAccessModifier = AccessModifier.Public)]
|
||||
[Inject(typeof(ItemNameConverterService))]
|
||||
public partial class MainPageViewModel
|
||||
public partial class MainPageViewModel : IMainPageViewModelBase
|
||||
{
|
||||
const string RAPIDTRAVEL = "rapidTravel";
|
||||
|
||||
private readonly List<KeyWithModifiers> _previousKeys = new List<KeyWithModifiers>();
|
||||
private readonly List<KeyWithModifiers[]> _keysToSkip = new List<KeyWithModifiers[]>();
|
||||
private List<CommandBinding> _commandBindings = new();
|
||||
private List<CommandBinding> _universalCommandBindings = new();
|
||||
private readonly List<KeyWithModifiers> _previousKeys = new();
|
||||
private readonly List<KeyWithModifiers[]> _keysToSkip = new();
|
||||
private readonly List<CommandBinding> _commandBindings = new();
|
||||
private readonly List<CommandBinding> _universalCommandBindings = new();
|
||||
|
||||
private IClipboard _clipboard;
|
||||
private TimeRunner _timeRunner;
|
||||
@@ -80,6 +80,9 @@ namespace FileTime.Avalonia.ViewModels
|
||||
[Property]
|
||||
private List<CommandBinding> _allShortcut;
|
||||
|
||||
[Property]
|
||||
private bool _loading = true;
|
||||
|
||||
public ObservableCollection<ParallelCommandsViewModel> TimelineCommands { get; } = new();
|
||||
|
||||
async partial void OnInitialize()
|
||||
@@ -192,6 +195,8 @@ namespace FileTime.Avalonia.ViewModels
|
||||
throw new Exception("TODO linux places");
|
||||
}
|
||||
Places = places;
|
||||
await Task.Delay(100);
|
||||
Loading = false;
|
||||
}
|
||||
|
||||
private void UpdateParalellCommands(object? sender, EventArgs e)
|
||||
@@ -229,7 +234,7 @@ namespace FileTime.Avalonia.ViewModels
|
||||
return await LocalContentProvider.GetByPath(drive.Name) as IContainer;
|
||||
}
|
||||
|
||||
public async Task OpenContainer()
|
||||
private async Task OpenContainer()
|
||||
{
|
||||
AppState.RapidTravelText = "";
|
||||
await AppState.SelectedTab.Open();
|
||||
@@ -241,7 +246,7 @@ namespace FileTime.Avalonia.ViewModels
|
||||
await AppState.SelectedTab.OpenContainer(container);
|
||||
}
|
||||
|
||||
public async Task OpenOrRun()
|
||||
private async Task OpenOrRun()
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
public async Task MoveCursorUp()
|
||||
private async Task MoveCursorUp()
|
||||
{
|
||||
await AppState.SelectedTab.MoveCursorUp();
|
||||
}
|
||||
|
||||
public async Task MoveCursorDown()
|
||||
private async Task MoveCursorDown()
|
||||
{
|
||||
await AppState.SelectedTab.MoveCursorDown();
|
||||
}
|
||||
|
||||
public async Task MoveCursorUpPage()
|
||||
private async Task MoveCursorUpPage()
|
||||
{
|
||||
await AppState.SelectedTab.MoveCursorUpPage();
|
||||
}
|
||||
|
||||
public async Task MoveCursorDownPage()
|
||||
private async Task MoveCursorDownPage()
|
||||
{
|
||||
await AppState.SelectedTab.MoveCursorDownPage();
|
||||
}
|
||||
|
||||
public async Task MoveToFirst()
|
||||
private async Task MoveToFirst()
|
||||
{
|
||||
await AppState.SelectedTab.MoveCursorToFirst();
|
||||
}
|
||||
|
||||
public async Task MoveToLast()
|
||||
private async Task MoveToLast()
|
||||
{
|
||||
await AppState.SelectedTab.MoveCursorToLast();
|
||||
}
|
||||
|
||||
public async Task GotToProvider()
|
||||
private async Task GotToProvider()
|
||||
{
|
||||
await AppState.SelectedTab.GotToProvider();
|
||||
}
|
||||
|
||||
public async Task GotToRoot()
|
||||
private async Task GotToRoot()
|
||||
{
|
||||
await AppState.SelectedTab.GotToRoot();
|
||||
}
|
||||
|
||||
public async Task GotToHome()
|
||||
private async Task GotToHome()
|
||||
{
|
||||
await AppState.SelectedTab.GotToHome();
|
||||
}
|
||||
|
||||
public Task EnterRapidTravelMode()
|
||||
private Task EnterRapidTravelMode()
|
||||
{
|
||||
AppState.ViewMode = ViewMode.RapidTravel;
|
||||
|
||||
@@ -318,7 +323,7 @@ namespace FileTime.Avalonia.ViewModels
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public async Task ExitRapidTravelMode()
|
||||
private async Task ExitRapidTravelMode()
|
||||
{
|
||||
AppState.ViewMode = ViewMode.Default;
|
||||
|
||||
@@ -329,7 +334,7 @@ namespace FileTime.Avalonia.ViewModels
|
||||
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);
|
||||
|
||||
@@ -364,7 +369,7 @@ namespace FileTime.Avalonia.ViewModels
|
||||
AppState.SelectedTab = tabContainer;
|
||||
}
|
||||
|
||||
public async Task CloseTab()
|
||||
private async Task CloseTab()
|
||||
{
|
||||
var tabs = AppState.Tabs;
|
||||
if (tabs.Count > 1)
|
||||
@@ -385,7 +390,7 @@ namespace FileTime.Avalonia.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
public Task CreateContainer()
|
||||
private Task CreateContainer()
|
||||
{
|
||||
var handler = async () =>
|
||||
{
|
||||
@@ -403,7 +408,7 @@ namespace FileTime.Avalonia.ViewModels
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task CreateElement()
|
||||
private Task CreateElement()
|
||||
{
|
||||
var handler = async () =>
|
||||
{
|
||||
@@ -421,12 +426,12 @@ namespace FileTime.Avalonia.ViewModels
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public async Task MarkCurrentItem()
|
||||
private async Task MarkCurrentItem()
|
||||
{
|
||||
await AppState.SelectedTab.MarkCurrentItem();
|
||||
}
|
||||
|
||||
public async Task Copy()
|
||||
private async Task Copy()
|
||||
{
|
||||
_clipboard.Clear();
|
||||
_clipboard.SetCommand<CopyCommand>();
|
||||
@@ -450,7 +455,7 @@ namespace FileTime.Avalonia.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
public Task Cut()
|
||||
private Task Cut()
|
||||
{
|
||||
_clipboard.Clear();
|
||||
_clipboard.SetCommand<MoveCommand>();
|
||||
@@ -458,7 +463,11 @@ namespace FileTime.Avalonia.ViewModels
|
||||
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;
|
||||
var askForDelete = false;
|
||||
@@ -524,6 +533,7 @@ namespace FileTime.Avalonia.ViewModels
|
||||
async Task HandleDelete()
|
||||
{
|
||||
var deleteCommand = new DeleteCommand();
|
||||
deleteCommand.HardDelete = hardDelete;
|
||||
|
||||
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);
|
||||
}
|
||||
public async Task PasteOverwrite()
|
||||
private async Task PasteOverwrite()
|
||||
{
|
||||
await Paste(TransportMode.Overwrite);
|
||||
}
|
||||
|
||||
public async Task PasteSkip()
|
||||
private async Task PasteSkip()
|
||||
{
|
||||
await Paste(TransportMode.Skip);
|
||||
}
|
||||
@@ -688,7 +698,7 @@ namespace FileTime.Avalonia.ViewModels
|
||||
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);
|
||||
}
|
||||
@@ -1053,7 +1063,12 @@ namespace FileTime.Avalonia.ViewModels
|
||||
"delete",
|
||||
FileTime.App.Core.Command.Commands.Delete,
|
||||
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(
|
||||
"paste merge",
|
||||
FileTime.App.Core.Command.Commands.PasteMerge,
|
||||
|
||||
@@ -12,25 +12,34 @@
|
||||
Icon="/Assets/filetime.ico"
|
||||
InputElement.KeyDown="OnKeyDown"
|
||||
InputElement.KeyUp="OnKeyUp"
|
||||
TransparencyLevelHint="Blur"
|
||||
Background="Transparent"
|
||||
ExtendClientAreaToDecorationsHint="True"
|
||||
Opened="OnWindowOpened"
|
||||
Closed="OnWindowClosed"
|
||||
|
||||
mc:Ignorable="d">
|
||||
<Grid
|
||||
x:Name="RootContainer"
|
||||
Background="{DynamicResource AppBackgroundBrush}">
|
||||
|
||||
<Grid Background="{DynamicResource AppBackgroundBrush}">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="250" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid ColumnDefinitions="250,*" RowDefinitions="Auto,*" IsVisible="{Binding Loading, Converter={StaticResource BoolInverter}}">
|
||||
|
||||
<Grid PointerPressed="HeaderPointerPressed">
|
||||
<Rectangle Fill="#01000000"/>
|
||||
<TextBlock Margin="15,10" Text="FileTime"/>
|
||||
</Grid>
|
||||
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid Grid.Column="1" PointerPressed="HeaderPointerPressed">
|
||||
<Rectangle Fill="#01000000"/>
|
||||
|
||||
<StackPanel Margin="20,10" Orientation="Horizontal">
|
||||
<!--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">
|
||||
<Grid RowDefinitions="Auto,Auto">
|
||||
@@ -131,7 +140,7 @@
|
||||
</Border>
|
||||
</Grid>
|
||||
|
||||
<Grid Grid.Column="2" RowDefinitions="Auto,40,*,Auto">
|
||||
<Grid Grid.Column="1" Grid.Row="1" RowDefinitions="Auto,40,*,Auto">
|
||||
<Grid>
|
||||
<ItemsControl Items="{Binding TimelineCommands}">
|
||||
<ItemsControl.ItemsPanel>
|
||||
@@ -158,23 +167,8 @@
|
||||
</ItemsControl>
|
||||
</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
|
||||
Grid.Column="1"
|
||||
HorizontalAlignment="Right"
|
||||
Grid.Row="1"
|
||||
Items="{Binding AppState.Tabs}">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
@@ -200,7 +194,6 @@
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
</Grid>
|
||||
|
||||
<Grid
|
||||
Grid.Row="2"
|
||||
@@ -523,4 +516,12 @@
|
||||
</Grid>
|
||||
</Border>
|
||||
</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>
|
||||
|
||||
@@ -6,6 +6,7 @@ using Avalonia.Markup.Xaml;
|
||||
using FileTime.Avalonia.Misc;
|
||||
using FileTime.Avalonia.Models;
|
||||
using FileTime.Avalonia.ViewModels;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
@@ -98,7 +99,7 @@ namespace FileTime.Avalonia.Views
|
||||
|
||||
private void OnPlacePointerPressed(object sender, PointerPressedEventArgs e)
|
||||
{
|
||||
if(!e.Handled
|
||||
if (!e.Handled
|
||||
&& ViewModel != null
|
||||
&& e.GetCurrentPoint(this).Properties.IsLeftButtonPressed
|
||||
&& sender is StyledElement control
|
||||
@@ -111,7 +112,38 @@ namespace FileTime.Avalonia.Views
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
157
src/Providers/FileTime.Providers.Local/Interop/WindowsInterop.cs
Normal file
157
src/Providers/FileTime.Providers.Local/Interop/WindowsInterop.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,10 +27,12 @@ namespace FileTime.Providers.Local
|
||||
public AsyncEventHandler Refreshed { get; } = new();
|
||||
|
||||
public bool IsCaseInsensitive { get; }
|
||||
public bool CanDelete => false;
|
||||
public SupportsDelete CanDelete => SupportsDelete.False;
|
||||
public bool CanRename => false;
|
||||
public IReadOnlyList<Exception> Exceptions { get; } = new List<Exception>().AsReadOnly();
|
||||
|
||||
public bool SupportsDirectoryLevelSoftDelete => false;
|
||||
|
||||
public LocalContentProvider(ILogger<LocalContentProvider> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
@@ -76,7 +78,7 @@ namespace FileTime.Providers.Local
|
||||
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 Delete() => throw new NotSupportedException();
|
||||
public Task Delete(bool hardDelete = false) => throw new NotSupportedException();
|
||||
|
||||
internal string NormalizePath(string path) => IsCaseInsensitive ? path.ToLower() : path;
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ using System.Runtime.InteropServices;
|
||||
using FileTime.Core.Models;
|
||||
using FileTime.Core.Providers;
|
||||
using FileTime.Providers.Local.Extensions;
|
||||
using FileTime.Providers.Local.Interop;
|
||||
using Mono.Unix;
|
||||
|
||||
namespace FileTime.Providers.Local
|
||||
@@ -24,7 +25,7 @@ namespace FileTime.Providers.Local
|
||||
public string Attributes => GetAttributes();
|
||||
|
||||
public DateTime CreatedAt => File.CreationTime;
|
||||
public bool CanDelete => true;
|
||||
public SupportsDelete CanDelete => SupportsDelete.True;
|
||||
public bool CanRename => true;
|
||||
|
||||
private readonly LocalFolder _parent;
|
||||
@@ -41,9 +42,16 @@ namespace FileTime.Providers.Local
|
||||
|
||||
public string GetPrimaryAttributeText() => File.Length.ToSizeString();
|
||||
|
||||
public Task Delete()
|
||||
public Task Delete(bool hardDelete = false)
|
||||
{
|
||||
if (hardDelete)
|
||||
{
|
||||
File.Delete();
|
||||
}
|
||||
else
|
||||
{
|
||||
WindowsInterop.MoveToRecycleBin(File.FullName);
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
public async Task Rename(string newName)
|
||||
|
||||
@@ -2,6 +2,7 @@ using System.Runtime.InteropServices;
|
||||
using AsyncEvent;
|
||||
using FileTime.Core.Models;
|
||||
using FileTime.Core.Providers;
|
||||
using FileTime.Providers.Local.Interop;
|
||||
|
||||
namespace FileTime.Providers.Local
|
||||
{
|
||||
@@ -23,7 +24,7 @@ namespace FileTime.Providers.Local
|
||||
public string FullName { get; }
|
||||
|
||||
public bool IsLoaded => _items != null;
|
||||
public bool CanDelete => true;
|
||||
public SupportsDelete CanDelete { get; }
|
||||
public bool CanRename => true;
|
||||
|
||||
public AsyncEventHandler Refreshed { get; } = new();
|
||||
@@ -33,6 +34,8 @@ namespace FileTime.Providers.Local
|
||||
public DateTime CreatedAt => Directory.CreationTime;
|
||||
public IReadOnlyList<Exception> Exceptions { get; }
|
||||
|
||||
public bool SupportsDirectoryLevelSoftDelete { get; }
|
||||
|
||||
public LocalFolder(DirectoryInfo directory, LocalContentProvider contentProvider, IContainer? parent)
|
||||
{
|
||||
Directory = directory;
|
||||
@@ -44,6 +47,12 @@ namespace FileTime.Providers.Local
|
||||
Name = directory.Name.TrimEnd(Path.DirectorySeparatorChar);
|
||||
FullName = parent?.FullName == null ? Name : parent.FullName + Constants.SeparatorChar + Name;
|
||||
Provider = contentProvider;
|
||||
|
||||
//TODO: Linux soft delete
|
||||
SupportsDirectoryLevelSoftDelete = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
|
||||
CanDelete = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
|
||||
? SupportsDelete.True
|
||||
: SupportsDelete.HardDeleteOnly;
|
||||
}
|
||||
|
||||
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 Task Delete()
|
||||
public Task Delete(bool hardDelete = false)
|
||||
{
|
||||
if (hardDelete)
|
||||
{
|
||||
Directory.Delete(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
WindowsInterop.MoveToRecycleBin(Directory.FullName);
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
public async Task Rename(string newName)
|
||||
|
||||
@@ -23,12 +23,14 @@ namespace FileTime.Providers.Smb
|
||||
public bool IsLoaded => true;
|
||||
|
||||
public IContentProvider Provider => this;
|
||||
public bool CanDelete => false;
|
||||
public SupportsDelete CanDelete => SupportsDelete.False;
|
||||
public bool CanRename => false;
|
||||
public IReadOnlyList<Exception> Exceptions { get; } = new List<Exception>().AsReadOnly();
|
||||
|
||||
public AsyncEventHandler Refreshed { get; } = new();
|
||||
|
||||
public bool SupportsDirectoryLevelSoftDelete => false;
|
||||
|
||||
public SmbContentProvider(IInputInterface inputInterface)
|
||||
{
|
||||
_rootContainers = new List<IContainer>();
|
||||
@@ -59,7 +61,7 @@ namespace FileTime.Providers.Smb
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public Task Delete()
|
||||
public Task Delete(bool hardDelete = false)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace FileTime.Providers.Smb
|
||||
public string? FullName { get; }
|
||||
|
||||
public bool IsHidden => false;
|
||||
public bool CanDelete => true;
|
||||
public SupportsDelete CanDelete => SupportsDelete.True;
|
||||
public bool CanRename => true;
|
||||
|
||||
public IContentProvider Provider { get; }
|
||||
@@ -28,7 +28,7 @@ namespace FileTime.Providers.Smb
|
||||
_parent = parent;
|
||||
}
|
||||
|
||||
public Task Delete()
|
||||
public Task Delete(bool hardDelete = false)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -23,12 +23,14 @@ namespace FileTime.Providers.Smb
|
||||
|
||||
public SmbContentProvider Provider { get; }
|
||||
IContentProvider IItem.Provider => Provider;
|
||||
public bool CanDelete => true;
|
||||
public SupportsDelete CanDelete => SupportsDelete.True;
|
||||
public bool CanRename => true;
|
||||
|
||||
public AsyncEventHandler Refreshed { get; } = new();
|
||||
public IReadOnlyList<Exception> Exceptions { get; } = new List<Exception>().AsReadOnly();
|
||||
|
||||
public bool SupportsDirectoryLevelSoftDelete => false;
|
||||
|
||||
public SmbFolder(string name, SmbContentProvider contentProvider, SmbShare smbShare, IContainer parent)
|
||||
{
|
||||
_parent = parent;
|
||||
@@ -77,7 +79,7 @@ namespace FileTime.Providers.Smb
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task Delete()
|
||||
public Task Delete(bool hardDelete = false)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -32,12 +32,14 @@ namespace FileTime.Providers.Smb
|
||||
public SmbContentProvider Provider { get; }
|
||||
|
||||
IContentProvider IItem.Provider => Provider;
|
||||
public bool CanDelete => true;
|
||||
public SupportsDelete CanDelete => SupportsDelete.True;
|
||||
public bool CanRename => false;
|
||||
public IReadOnlyList<Exception> Exceptions { get; } = new List<Exception>().AsReadOnly();
|
||||
|
||||
public AsyncEventHandler Refreshed { get; } = new();
|
||||
|
||||
public bool SupportsDirectoryLevelSoftDelete => false;
|
||||
|
||||
public SmbServer(string path, SmbContentProvider contentProvider, IInputInterface inputInterface)
|
||||
{
|
||||
_inputInterface = inputInterface;
|
||||
@@ -72,7 +74,7 @@ namespace FileTime.Providers.Smb
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public Task Delete()
|
||||
public Task Delete(bool hardDelete = false)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
@@ -23,12 +23,14 @@ namespace FileTime.Providers.Smb
|
||||
|
||||
public SmbContentProvider Provider { get; }
|
||||
IContentProvider IItem.Provider => Provider;
|
||||
public bool CanDelete => false;
|
||||
public SupportsDelete CanDelete => SupportsDelete.False;
|
||||
public bool CanRename => false;
|
||||
|
||||
public AsyncEventHandler Refreshed { get; } = new();
|
||||
public IReadOnlyList<Exception> Exceptions { get; } = new List<Exception>().AsReadOnly();
|
||||
|
||||
public bool SupportsDirectoryLevelSoftDelete => false;
|
||||
|
||||
public SmbShare(string name, SmbContentProvider contentProvider, IContainer parent, SmbClientContext smbClientContext)
|
||||
{
|
||||
_parent = parent;
|
||||
@@ -65,7 +67,7 @@ namespace FileTime.Providers.Smb
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task Delete()
|
||||
public Task Delete(bool hardDelete = false)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user