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)
{ {
foreach (var child in (await container.GetItems())!) if (!HardDelete && container.SupportsDirectoryLevelSoftDelete)
{ {
await DoDelete(child, timeRunner); if (_deleteContainer != null) await _deleteContainer.Invoke(container);
await child.Delete(); }
else
{
foreach (var child in (await container.GetItems())!)
{
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) 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,15 +46,19 @@ namespace FileTime.Avalonia.Services
{ {
if (!File.Exists(_settingsPath)) return; if (!File.Exists(_settingsPath)) return;
using var stateReader = File.OpenRead(_settingsPath); try
var state = await JsonSerializer.DeserializeAsync<PersistenceRoot>(stateReader);
if (state != null)
{ {
await RestoreTabs(state.TabStates); using var stateReader = File.OpenRead(_settingsPath);
var state = await JsonSerializer.DeserializeAsync<PersistenceRoot>(stateReader);
if (state != null)
{
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()
@@ -83,49 +87,54 @@ namespace FileTime.Avalonia.Services
private async Task<bool> RestoreTabs(TabStates? tabStates) private async Task<bool> RestoreTabs(TabStates? tabStates)
{ {
if (tabStates == null try
|| tabStates.Tabs == null)
{ {
return false; if (tabStates == null
} || tabStates.Tabs == null)
foreach (var tab in tabStates.Tabs)
{
if (tab.Path == null) continue;
IItem? pathItem = null;
foreach (var contentProvider in _contentProviders)
{ {
if (contentProvider.CanHandlePath(tab.Path)) return false;
{
pathItem = await contentProvider.GetByPath(tab.Path, true);
if (pathItem != null) break;
}
} }
var container = pathItem switch foreach (var tab in tabStates.Tabs)
{ {
IContainer c => c, if (tab.Path == null) continue;
IElement e => e.GetParent(),
_ => null
};
if (container == null) continue; IItem? pathItem = null;
foreach (var contentProvider in _contentProviders)
{
if (contentProvider.CanHandlePath(tab.Path))
{
pathItem = await contentProvider.GetByPath(tab.Path, true);
if (pathItem != null) break;
}
}
var newTab = new Tab(); var container = pathItem switch
await newTab.Init(container); {
IContainer c => c,
IElement e => e.GetParent(),
_ => null
};
var newTabContainer = new TabContainer(newTab, _localContentProvider, _itemNameConverterService); if (container == null) continue;
await newTabContainer.Init(tab.Number);
_appState.Tabs.Add(newTabContainer); var newTab = new Tab();
await newTab.Init(container);
var newTabContainer = new TabContainer(newTab, _localContentProvider, _itemNameConverterService);
await newTabContainer.Init(tab.Number);
_appState.Tabs.Add(newTabContainer);
}
if (_appState.Tabs.FirstOrDefault(t => t.TabNumber == tabStates.ActiveTabNumber) is TabContainer tabContainer)
{
_appState.SelectedTab = tabContainer;
}
return true;
} }
catch { }
if (_appState.Tabs.FirstOrDefault(t => t.TabNumber == tabStates.ActiveTabNumber) is TabContainer tabContainer) return false;
{
_appState.SelectedTab = tabContainer;
}
return true;
} }
} }
} }

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,169 +12,163 @@
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">
<Grid> <Rectangle Fill="#01000000"/>
<Grid.RowDefinitions> <TextBlock Margin="15,10" Text="FileTime"/>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Border CornerRadius="10" Background="{DynamicResource ContainerBackgroundBrush}" Padding="10" Margin="10">
<Grid RowDefinitions="Auto,Auto">
<TextBlock
Margin="0,0,0,10"
Text="Drives" />
<ItemsRepeater
Grid.Row="1"
Items="{Binding RootDriveInfos}">
<ItemsRepeater.ItemTemplate>
<DataTemplate>
<Grid Margin="0,5" ColumnDefinitions="20,*,Auto" RowDefinitions="Auto,Auto">
<Image
Grid.RowSpan="2"
Width="20"
Height="20"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Source="{SvgImage /Assets/material/folder.svg}" />
<StackPanel
Grid.Column="1"
VerticalAlignment="Center"
HorizontalAlignment="Stretch"
Orientation="Horizontal">
<TextBlock
VerticalAlignment="Center"
Text="{Binding FullName}" />
<TextBlock
Margin="5,0,0,0"
VerticalAlignment="Center"
Classes="SmallText"
Text="{Binding Label}" IsVisible="{Binding Label,Converter={StaticResource IsNotEmptyConverter}}" />
</StackPanel>
<StackPanel HorizontalAlignment="Right"
Grid.Column="2"
Orientation="Horizontal"
VerticalAlignment="Center">
<TextBlock Classes="SmallText" VerticalAlignment="Center" Text="{Binding Free, Converter={StaticResource FormatSizeConverter}, ConverterParameter=0}">
</TextBlock>
<TextBlock Classes="SmallText" VerticalAlignment="Center" Text=" / ">
</TextBlock>
<TextBlock Classes="SmallText" VerticalAlignment="Center" Text="{Binding Size, Converter={StaticResource FormatSizeConverter}, ConverterParameter=0}">
</TextBlock>
</StackPanel>
<ProgressBar
Grid.Column="1"
Grid.ColumnSpan="2"
Grid.Row="2"
Maximum="100"
Value="{Binding UsedPercentage}" />
</Grid>
</DataTemplate>
</ItemsRepeater.ItemTemplate>
</ItemsRepeater>
</Grid>
</Border>
<Border Grid.Row="1" CornerRadius="10" Background="{DynamicResource ContainerBackgroundBrush}" Padding="0,10" Margin="10">
<Grid RowDefinitions="Auto,Auto">
<TextBlock
Margin="10,0,10,10"
Text="Places" />
<ItemsRepeater
Grid.Row="1"
Items="{Binding Places}">
<ItemsRepeater.ItemTemplate>
<DataTemplate>
<Grid Classes="PlacesItem" PointerPressed="OnPlacePointerPressed" Cursor="Hand">
<StackPanel Orientation="Horizontal" Margin="10,5" HorizontalAlignment="Stretch">
<Image
Width="20"
Height="20"
VerticalAlignment="Center"
Source="{Binding Container,Converter={StaticResource ItemToImageConverter}}" />
<TextBlock
Margin="5,0,0,0"
VerticalAlignment="Center"
Text="{Binding Name}" />
</StackPanel>
</Grid>
</DataTemplate>
</ItemsRepeater.ItemTemplate>
</ItemsRepeater>
</Grid>
</Border>
</Grid>
<Grid Grid.Column="2" RowDefinitions="Auto,40,*,Auto">
<Grid>
<ItemsControl Items="{Binding TimelineCommands}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border Background="{DynamicResource ContainerBackgroundColor}" Padding="5">
<ItemsControl Items="{Binding ParallelCommands}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Name}"/>
<ProgressBar Margin="0,5,0,0" Maximum="100" Value="{Binding Progress}"/>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid> </Grid>
<Grid Grid.Row="1" ColumnDefinitions="*,Auto"> <Grid Grid.Column="1" PointerPressed="HeaderPointerPressed">
<Rectangle Fill="#01000000"/>
<StackPanel Orientation="Horizontal"> <StackPanel Margin="20,10" Orientation="Horizontal">
<!--TextBlock Text="{Binding AppState.SelectedTab.TabNumber,StringFormat=({0})}" /-->
<local:PathPresenter DataContext="{Binding AppState.SelectedTab.CurrentLocation.Container.FullName}"/>
<TextBlock <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}" /> Text="{Binding AppState.SelectedTab.SelectedItem.Item.Name}" Foreground="{StaticResource AccentForegroundBrush}" />
</StackPanel> </StackPanel>
</Grid>
<Grid Grid.Row="1" RowDefinitions="Auto,Auto">
<Border CornerRadius="10" Background="{DynamicResource ContainerBackgroundBrush}" Padding="10" Margin="10">
<Grid RowDefinitions="Auto,Auto">
<TextBlock
Margin="0,0,0,10"
Text="Drives" />
<ItemsRepeater
Grid.Row="1"
Items="{Binding RootDriveInfos}">
<ItemsRepeater.ItemTemplate>
<DataTemplate>
<Grid Margin="0,5" ColumnDefinitions="20,*,Auto" RowDefinitions="Auto,Auto">
<Image
Grid.RowSpan="2"
Width="20"
Height="20"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Source="{SvgImage /Assets/material/folder.svg}" />
<StackPanel
Grid.Column="1"
VerticalAlignment="Center"
HorizontalAlignment="Stretch"
Orientation="Horizontal">
<TextBlock
VerticalAlignment="Center"
Text="{Binding FullName}" />
<TextBlock
Margin="5,0,0,0"
VerticalAlignment="Center"
Classes="SmallText"
Text="{Binding Label}" IsVisible="{Binding Label,Converter={StaticResource IsNotEmptyConverter}}" />
</StackPanel>
<StackPanel HorizontalAlignment="Right"
Grid.Column="2"
Orientation="Horizontal"
VerticalAlignment="Center">
<TextBlock Classes="SmallText" VerticalAlignment="Center" Text="{Binding Free, Converter={StaticResource FormatSizeConverter}, ConverterParameter=0}">
</TextBlock>
<TextBlock Classes="SmallText" VerticalAlignment="Center" Text=" / ">
</TextBlock>
<TextBlock Classes="SmallText" VerticalAlignment="Center" Text="{Binding Size, Converter={StaticResource FormatSizeConverter}, ConverterParameter=0}">
</TextBlock>
</StackPanel>
<ProgressBar
Grid.Column="1"
Grid.ColumnSpan="2"
Grid.Row="2"
Maximum="100"
Value="{Binding UsedPercentage}" />
</Grid>
</DataTemplate>
</ItemsRepeater.ItemTemplate>
</ItemsRepeater>
</Grid>
</Border>
<Border Grid.Row="1" CornerRadius="10" Background="{DynamicResource ContainerBackgroundBrush}" Padding="0,10" Margin="10">
<Grid RowDefinitions="Auto,Auto">
<TextBlock
Margin="10,0,10,10"
Text="Places" />
<ItemsRepeater
Grid.Row="1"
Items="{Binding Places}">
<ItemsRepeater.ItemTemplate>
<DataTemplate>
<Grid Classes="PlacesItem" PointerPressed="OnPlacePointerPressed" Cursor="Hand">
<StackPanel Orientation="Horizontal" Margin="10,5" HorizontalAlignment="Stretch">
<Image
Width="20"
Height="20"
VerticalAlignment="Center"
Source="{Binding Container,Converter={StaticResource ItemToImageConverter}}" />
<TextBlock
Margin="5,0,0,0"
VerticalAlignment="Center"
Text="{Binding Name}" />
</StackPanel>
</Grid>
</DataTemplate>
</ItemsRepeater.ItemTemplate>
</ItemsRepeater>
</Grid>
</Border>
</Grid>
<Grid Grid.Column="1" Grid.Row="1" RowDefinitions="Auto,40,*,Auto">
<Grid>
<ItemsControl Items="{Binding TimelineCommands}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border Background="{DynamicResource ContainerBackgroundColor}" Padding="5">
<ItemsControl Items="{Binding ParallelCommands}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Name}"/>
<ProgressBar Margin="0,5,0,0" Maximum="100" Value="{Binding Progress}"/>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
<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,287 +194,313 @@
</DataTemplate> </DataTemplate>
</ItemsControl.ItemTemplate> </ItemsControl.ItemTemplate>
</ItemsControl> </ItemsControl>
</Grid>
<Grid
Grid.Row="2"
Margin="20,0,0,0">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="15*" />
<ColumnDefinition Width="10" />
<ColumnDefinition Width="40*" />
<ColumnDefinition Width="10" />
<ColumnDefinition Width="45*" />
</Grid.ColumnDefinitions>
<Grid
Grid.Row="2"
Margin="20,0,0,0">
<Grid> <Grid>
<ListBox <Grid.ColumnDefinitions>
Classes="ContentListView" <ColumnDefinition Width="15*" />
IsEnabled="False" <ColumnDefinition Width="10" />
Items="{Binding AppState.SelectedTab.Parent.Items}"> <ColumnDefinition Width="40*" />
<ListBox.ItemTemplate> <ColumnDefinition Width="10" />
<DataTemplate> <ColumnDefinition Width="45*" />
<local:ItemView ShowAttributes="False"/> </Grid.ColumnDefinitions>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
<Rectangle <Grid>
Grid.Column="1" <ListBox
Width="1" Classes="ContentListView"
Margin="0,10,0,10" IsEnabled="False"
HorizontalAlignment="Center" Items="{Binding AppState.SelectedTab.Parent.Items}">
VerticalAlignment="Stretch" <ListBox.ItemTemplate>
Fill="{DynamicResource ContentSeparatorBrush}" /> <DataTemplate>
<local:ItemView ShowAttributes="False"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
<Grid Grid.Column="2"> <Rectangle
<ListBox Grid.Column="1"
x:Name="CurrentItems" Width="1"
IsTabStop="True" Margin="0,10,0,10"
Items="{Binding AppState.SelectedTab.CurrentLocation.Items}"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ScrollViewer.VerticalScrollBarVisibility="Hidden"
SelectedItem="{Binding AppState.SelectedTab.SelectedItem, Mode=TwoWay}"
Classes="ContentListView">
<ListBox.ItemTemplate>
<DataTemplate>
<local:ItemView/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<TextBlock
x:Name="CurrentEmpty"
Margin="10"
HorizontalAlignment="Center" HorizontalAlignment="Center"
FontWeight="Bold" VerticalAlignment="Stretch"
Foreground="{DynamicResource ErrorBrush}" Fill="{DynamicResource ContentSeparatorBrush}" />
IsVisible="{Binding AppState.SelectedTab.CurrentLocation.Items.Count, Converter={StaticResource EqualityConverter}, ConverterParameter=0}">
Empty
</TextBlock>
</Grid>
<Rectangle <Grid Grid.Column="2">
Grid.Column="3" <ListBox
Width="1" x:Name="CurrentItems"
Margin="0,10,0,10" IsTabStop="True"
HorizontalAlignment="Center" Items="{Binding AppState.SelectedTab.CurrentLocation.Items}"
VerticalAlignment="Stretch" ScrollViewer.HorizontalScrollBarVisibility="Disabled"
Fill="{DynamicResource ContentSeparatorBrush}" /> ScrollViewer.VerticalScrollBarVisibility="Hidden"
SelectedItem="{Binding AppState.SelectedTab.SelectedItem, Mode=TwoWay}"
<Grid Grid.Column="4" IsVisible="{Binding AppState.SelectedTab.ChildContainer,Converter={StaticResource IsNotNullConverter}}"> Classes="ContentListView">
<ListBox <ListBox.ItemTemplate>
Classes="ContentListView" <DataTemplate>
IsEnabled="False" <local:ItemView/>
x:Name="ChildItems" </DataTemplate>
Items="{Binding AppState.SelectedTab.ChildContainer.Items}" </ListBox.ItemTemplate>
IsVisible="{Binding AppState.SelectedTab.ChildContainer.Items.Count, Converter={StaticResource NotEqualsConverter}, ConverterParameter=0}"> </ListBox>
<ListBox.ItemTemplate>
<DataTemplate>
<local:ItemView/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<Grid
IsVisible="{Binding AppState.SelectedTab.ChildContainer.Items.Count, Converter={StaticResource EqualityConverter}, ConverterParameter=0}">
<TextBlock <TextBlock
x:Name="ChildEmpty" x:Name="CurrentEmpty"
Margin="10" Margin="10"
HorizontalAlignment="Center" HorizontalAlignment="Center"
FontWeight="Bold" FontWeight="Bold"
Foreground="{DynamicResource ErrorBrush}" Foreground="{DynamicResource ErrorBrush}"
IsVisible="{Binding AppState.SelectedTab.ChildContainer.Exceptions.Count, Converter={StaticResource EqualityConverter}, ConverterParameter=0}"> IsVisible="{Binding AppState.SelectedTab.CurrentLocation.Items.Count, Converter={StaticResource EqualityConverter}, ConverterParameter=0}">
Empty Empty
</TextBlock> </TextBlock>
</Grid>
<Rectangle
Grid.Column="3"
Width="1"
Margin="0,10,0,10"
HorizontalAlignment="Center"
VerticalAlignment="Stretch"
Fill="{DynamicResource ContentSeparatorBrush}" />
<Grid Grid.Column="4" IsVisible="{Binding AppState.SelectedTab.ChildContainer,Converter={StaticResource IsNotNullConverter}}">
<ListBox
Classes="ContentListView"
IsEnabled="False"
x:Name="ChildItems"
Items="{Binding AppState.SelectedTab.ChildContainer.Items}"
IsVisible="{Binding AppState.SelectedTab.ChildContainer.Items.Count, Converter={StaticResource NotEqualsConverter}, ConverterParameter=0}">
<ListBox.ItemTemplate>
<DataTemplate>
<local:ItemView/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<Grid <Grid
RowDefinitions="Auto, Auto" IsVisible="{Binding AppState.SelectedTab.ChildContainer.Items.Count, Converter={StaticResource EqualityConverter}, ConverterParameter=0}">
IsVisible="{Binding AppState.SelectedTab.ChildContainer.Exceptions.Count, Converter={StaticResource NotEqualsConverter}, ConverterParameter=0}">
<TextBlock <TextBlock
Margin="0,0,0,10" x:Name="ChildEmpty"
Margin="10"
HorizontalAlignment="Center" HorizontalAlignment="Center"
TextWrapping="Wrap" FontWeight="Bold"
Text="There were some errors while opening container." Foreground="{DynamicResource ErrorBrush}"
Foreground="{DynamicResource ErrorBrush}" /> IsVisible="{Binding AppState.SelectedTab.ChildContainer.Exceptions.Count, Converter={StaticResource EqualityConverter}, ConverterParameter=0}">
Empty
</TextBlock>
<ItemsRepeater Grid.Row="1" Items="{Binding AppState.SelectedTab.ChildContainer.Exceptions}"> <Grid
<ItemsRepeater.ItemTemplate> RowDefinitions="Auto, Auto"
<DataTemplate> IsVisible="{Binding AppState.SelectedTab.ChildContainer.Exceptions.Count, Converter={StaticResource NotEqualsConverter}, ConverterParameter=0}">
<TextBlock Text="{Binding, Converter={StaticResource ExceptionToStringConverter}}"/>
</DataTemplate> <TextBlock
</ItemsRepeater.ItemTemplate> Margin="0,0,0,10"
</ItemsRepeater> HorizontalAlignment="Center"
TextWrapping="Wrap"
Text="There were some errors while opening container."
Foreground="{DynamicResource ErrorBrush}" />
<ItemsRepeater Grid.Row="1" Items="{Binding AppState.SelectedTab.ChildContainer.Exceptions}">
<ItemsRepeater.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding, Converter={StaticResource ExceptionToStringConverter}}"/>
</DataTemplate>
</ItemsRepeater.ItemTemplate>
</ItemsRepeater>
</Grid>
</Grid> </Grid>
</Grid> </Grid>
</Grid> </Grid>
</Grid>
<Grid <Grid
HorizontalAlignment="Center"
VerticalAlignment="Center"
IsVisible="{Binding Inputs, Converter={StaticResource IsNotNullConverter}}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<ItemsControl
x:Name="InputList"
Items="{Binding Inputs}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid MinWidth="400">
<Grid.ColumnDefinitions>
<ColumnDefinition MinWidth="200" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock
HorizontalAlignment="Left"
VerticalAlignment="Center"
Text="{Binding InputElement.Text}" />
<TextBox
AttachedToVisualTree="InputText_AttachedToVisualTree"
Grid.Column="1"
GotFocus="InputText_GotFocus"
LostFocus="InputText_LostFocus"
KeyDown="InputText_KeyDown"
Text="{Binding Value, Mode=TwoWay}" />
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<StackPanel
Grid.Row="1"
Orientation="Horizontal">
<Button
Command="{Binding ProcessInputsCommand}"
Content="Ok" />
<Button
Command="{Binding CancelInputsCommand}"
Content="Cancel" />
</StackPanel>
</Grid>
<Grid
HorizontalAlignment="Center"
VerticalAlignment="Center"
IsVisible="{Binding MessageBoxText, Converter={StaticResource IsNotNullConverter}}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Text="{Binding MessageBoxText}"/>
<StackPanel
Grid.Row="1"
Orientation="Horizontal">
<Button
Command="{Binding ProcessMessageBoxCommand}"
Content="Yes" />
<Button
Command="{Binding CancelMessageBoxCommand}"
Content="No" />
</StackPanel>
</Grid>
<ItemsRepeater Items="{Binding PopupTexts}" Margin="0,0,0,20" HorizontalAlignment="Center" VerticalAlignment="Bottom" IsVisible="{Binding PopupTexts.Count,Converter={StaticResource NotEqualsConverter}, ConverterParameter=0}">
<ItemsRepeater.Styles>
<Style Selector="TextBlock">
<Style.Animations>
<Animation Duration="0:0:1">
<KeyFrame Cue="0%">
<Setter Property="Opacity" Value="0.0"/>
</KeyFrame>
<KeyFrame Cue="100%">
<Setter Property="Opacity" Value="1.0"/>
</KeyFrame>
</Animation>
</Style.Animations>
</Style>
</ItemsRepeater.Styles>
<ItemsRepeater.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" HorizontalAlignment="Center"/>
</DataTemplate>
</ItemsRepeater.ItemTemplate>
</ItemsRepeater>
</Grid>
<Grid Grid.Row="3">
<Grid IsVisible="{Binding AppState.ViewMode, Converter={StaticResource EqualityConverter}, ConverterParameter=RapidTravel}">
<Grid.RowDefinitions>
<RowDefinition Height="1" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Rectangle
Height="1"
Margin="10,0"
HorizontalAlignment="Stretch"
VerticalAlignment="Center"
Fill="{DynamicResource ContentSeparatorBrush}" />
<StackPanel
Grid.Row="1"
Margin="30,10,10,10"
Orientation="Horizontal">
<TextBlock
Margin="0,0,30,0"
Text="Rapid travel mode" />
<TextBlock Text="Filter " />
<TextBlock Text="{Binding AppState.RapidTravelText}" />
</StackPanel>
</Grid>
<Grid IsVisible="{Binding NoCommandFound}">
<Grid.RowDefinitions>
<RowDefinition Height="1" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Rectangle
Height="1"
Margin="10,0"
HorizontalAlignment="Stretch"
VerticalAlignment="Center"
Fill="{DynamicResource ContentSeparatorBrush}" />
<TextBlock
Grid.Row="1"
Margin="10"
HorizontalAlignment="Center" HorizontalAlignment="Center"
Foreground="{DynamicResource ErrorBrush}"
Text="No command found" />
</Grid>
<Grid IsVisible="{Binding PossibleCommands.Count, Converter={StaticResource NotEqualsConverter}, ConverterParameter=0}">
<Grid.RowDefinitions>
<RowDefinition Height="1" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Rectangle
Height="1"
Margin="10,0"
HorizontalAlignment="Stretch"
VerticalAlignment="Center" VerticalAlignment="Center"
Fill="{DynamicResource ContentSeparatorBrush}" /> IsVisible="{Binding Inputs, Converter={StaticResource IsNotNullConverter}}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<ItemsRepeater <ItemsControl
Grid.Row="1" x:Name="InputList"
Items="{Binding PossibleCommands}"> Items="{Binding Inputs}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid MinWidth="400">
<Grid.ColumnDefinitions>
<ColumnDefinition MinWidth="200" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock
HorizontalAlignment="Left"
VerticalAlignment="Center"
Text="{Binding InputElement.Text}" />
<TextBox
AttachedToVisualTree="InputText_AttachedToVisualTree"
Grid.Column="1"
GotFocus="InputText_GotFocus"
LostFocus="InputText_LostFocus"
KeyDown="InputText_KeyDown"
Text="{Binding Value, Mode=TwoWay}" />
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<StackPanel
Grid.Row="1"
Orientation="Horizontal">
<Button
Command="{Binding ProcessInputsCommand}"
Content="Ok" />
<Button
Command="{Binding CancelInputsCommand}"
Content="Cancel" />
</StackPanel>
</Grid>
<Grid
HorizontalAlignment="Center"
VerticalAlignment="Center"
IsVisible="{Binding MessageBoxText, Converter={StaticResource IsNotNullConverter}}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Text="{Binding MessageBoxText}"/>
<StackPanel
Grid.Row="1"
Orientation="Horizontal">
<Button
Command="{Binding ProcessMessageBoxCommand}"
Content="Yes" />
<Button
Command="{Binding CancelMessageBoxCommand}"
Content="No" />
</StackPanel>
</Grid>
<ItemsRepeater Items="{Binding PopupTexts}" Margin="0,0,0,20" HorizontalAlignment="Center" VerticalAlignment="Bottom" IsVisible="{Binding PopupTexts.Count,Converter={StaticResource NotEqualsConverter}, ConverterParameter=0}">
<ItemsRepeater.Styles>
<Style Selector="TextBlock">
<Style.Animations>
<Animation Duration="0:0:1">
<KeyFrame Cue="0%">
<Setter Property="Opacity" Value="0.0"/>
</KeyFrame>
<KeyFrame Cue="100%">
<Setter Property="Opacity" Value="1.0"/>
</KeyFrame>
</Animation>
</Style.Animations>
</Style>
</ItemsRepeater.Styles>
<ItemsRepeater.ItemTemplate> <ItemsRepeater.ItemTemplate>
<DataTemplate> <DataTemplate>
<Grid> <TextBlock Text="{Binding}" HorizontalAlignment="Center"/>
</DataTemplate>
</ItemsRepeater.ItemTemplate>
</ItemsRepeater>
</Grid>
<Grid Grid.Row="3">
<Grid IsVisible="{Binding AppState.ViewMode, Converter={StaticResource EqualityConverter}, ConverterParameter=RapidTravel}">
<Grid.RowDefinitions>
<RowDefinition Height="1" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Rectangle
Height="1"
Margin="10,0"
HorizontalAlignment="Stretch"
VerticalAlignment="Center"
Fill="{DynamicResource ContentSeparatorBrush}" />
<StackPanel
Grid.Row="1"
Margin="30,10,10,10"
Orientation="Horizontal">
<TextBlock
Margin="0,0,30,0"
Text="Rapid travel mode" />
<TextBlock Text="Filter " />
<TextBlock Text="{Binding AppState.RapidTravelText}" />
</StackPanel>
</Grid>
<Grid IsVisible="{Binding NoCommandFound}">
<Grid.RowDefinitions>
<RowDefinition Height="1" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Rectangle
Height="1"
Margin="10,0"
HorizontalAlignment="Stretch"
VerticalAlignment="Center"
Fill="{DynamicResource ContentSeparatorBrush}" />
<TextBlock
Grid.Row="1"
Margin="10"
HorizontalAlignment="Center"
Foreground="{DynamicResource ErrorBrush}"
Text="No command found" />
</Grid>
<Grid IsVisible="{Binding PossibleCommands.Count, Converter={StaticResource NotEqualsConverter}, ConverterParameter=0}">
<Grid.RowDefinitions>
<RowDefinition Height="1" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Rectangle
Height="1"
Margin="10,0"
HorizontalAlignment="Stretch"
VerticalAlignment="Center"
Fill="{DynamicResource ContentSeparatorBrush}" />
<ItemsRepeater
Grid.Row="1"
Items="{Binding PossibleCommands}">
<ItemsRepeater.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding KeysDisplayText}" />
<TextBlock Grid.Column="1" Text="{Binding Name}" />
</Grid>
</DataTemplate>
</ItemsRepeater.ItemTemplate>
</ItemsRepeater>
</Grid>
</Grid>
</Grid>
</Grid>
<Border Background="{DynamicResource TransparentContainerBackgroundBrush}" Margin="20" HorizontalAlignment="Center" IsVisible="{Binding ShowAllShortcut}">
<Grid RowDefinitions="Auto, *" Margin="30,10">
<TextBlock Text="Shortcuts" Margin="0,0,0,20"/>
<ScrollViewer
Grid.Row="1"
HorizontalScrollBarVisibility="Disabled">
<ItemsControl
Items="{Binding AllShortcut}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid Margin="0,5,10,5">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="200" /> <ColumnDefinition Width="200" />
<ColumnDefinition Width="*" /> <ColumnDefinition Width="*" />
@@ -490,37 +510,18 @@
<TextBlock Grid.Column="1" Text="{Binding Name}" /> <TextBlock Grid.Column="1" Text="{Binding Name}" />
</Grid> </Grid>
</DataTemplate> </DataTemplate>
</ItemsRepeater.ItemTemplate> </ItemsControl.ItemTemplate>
</ItemsRepeater> </ItemsControl>
</Grid> </ScrollViewer>
</Grid> </Grid>
</Grid> </Border>
</Grid> </Grid>
<Border Background="{DynamicResource TransparentContainerBackgroundBrush}" Margin="20" HorizontalAlignment="Center" IsVisible="{Binding ShowAllShortcut}"> <Grid IsVisible="{Binding Loading}">
<Grid RowDefinitions="Auto, *" Margin="30,10"> <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock Text="Shortcuts" Margin="0,0,0,20"/> <Image Source="/Assets/filetime.ico" Width="128" Height="128"/>
<ScrollViewer <TextBlock Text="Loading..." HorizontalAlignment="Center" Margin="50"/>
Grid.Row="1" </StackPanel>
HorizontalScrollBarVisibility="Disabled"> </Grid>
<ItemsControl
Items="{Binding AllShortcut}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid Margin="0,5,10,5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding KeysDisplayText}" />
<TextBlock Grid.Column="1" Text="{Binding Name}" />
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
</Grid>
</Border>
</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)
{ {
File.Delete(); if (hardDelete)
{
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)
{ {
Directory.Delete(true); if (hardDelete)
{
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();
} }