From becca2b62f63303a27df930f681cd5fd65dc7777 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81d=C3=A1m=20Kov=C3=A1cs?= Date: Mon, 16 May 2022 22:12:21 +0200 Subject: [PATCH] PathPresenter, File type item --- src/AppCommon/FileTime.App.Core/Startup.cs | 2 ++ .../Converters/StringReplaceConverter.cs | 18 +++++++++++++++ .../Resources/Converters.axaml | 1 + .../FileTime.GuiApp/Views/MainWindow.axaml | 2 +- .../FileTime.GuiApp/Views/PathPresenter.axaml | 23 +++++++++++++++++++ .../Views/PathPresenter.axaml.cs | 18 +++++++++++++++ .../LocalContentProvider.cs | 18 ++++++++------- 7 files changed, 73 insertions(+), 9 deletions(-) create mode 100644 src/GuiApp/Avalonia/FileTime.GuiApp/Converters/StringReplaceConverter.cs create mode 100644 src/GuiApp/Avalonia/FileTime.GuiApp/Views/PathPresenter.axaml create mode 100644 src/GuiApp/Avalonia/FileTime.GuiApp/Views/PathPresenter.axaml.cs diff --git a/src/AppCommon/FileTime.App.Core/Startup.cs b/src/AppCommon/FileTime.App.Core/Startup.cs index 79e2853..c7f0a6e 100644 --- a/src/AppCommon/FileTime.App.Core/Startup.cs +++ b/src/AppCommon/FileTime.App.Core/Startup.cs @@ -14,6 +14,8 @@ public static class Startup .AddTransient() .AddTransient() .AddTransient() + .AddTransient() + .AddTransient() .AddTransient() .AddSingleton() .AddSingleton() diff --git a/src/GuiApp/Avalonia/FileTime.GuiApp/Converters/StringReplaceConverter.cs b/src/GuiApp/Avalonia/FileTime.GuiApp/Converters/StringReplaceConverter.cs new file mode 100644 index 0000000..e60e3bd --- /dev/null +++ b/src/GuiApp/Avalonia/FileTime.GuiApp/Converters/StringReplaceConverter.cs @@ -0,0 +1,18 @@ +using System.Globalization; +using Avalonia.Data.Converters; + +namespace FileTime.GuiApp.Converters; + +public class StringReplaceConverter : IValueConverter +{ + public string? OldValue { get; set; } + public string? NewValue { get; set; } + + public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) + => value is string s && OldValue != null && NewValue != null ? s.Replace(OldValue, NewValue) : value; + + public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } +} \ No newline at end of file diff --git a/src/GuiApp/Avalonia/FileTime.GuiApp/Resources/Converters.axaml b/src/GuiApp/Avalonia/FileTime.GuiApp/Resources/Converters.axaml index 6dadfa1..5804180 100644 --- a/src/GuiApp/Avalonia/FileTime.GuiApp/Resources/Converters.axaml +++ b/src/GuiApp/Avalonia/FileTime.GuiApp/Resources/Converters.axaml @@ -31,4 +31,5 @@ + \ No newline at end of file diff --git a/src/GuiApp/Avalonia/FileTime.GuiApp/Views/MainWindow.axaml b/src/GuiApp/Avalonia/FileTime.GuiApp/Views/MainWindow.axaml index 02815c7..d2c9bf3 100644 --- a/src/GuiApp/Avalonia/FileTime.GuiApp/Views/MainWindow.axaml +++ b/src/GuiApp/Avalonia/FileTime.GuiApp/Views/MainWindow.axaml @@ -47,7 +47,7 @@ - + diff --git a/src/GuiApp/Avalonia/FileTime.GuiApp/Views/PathPresenter.axaml b/src/GuiApp/Avalonia/FileTime.GuiApp/Views/PathPresenter.axaml new file mode 100644 index 0000000..a853a93 --- /dev/null +++ b/src/GuiApp/Avalonia/FileTime.GuiApp/Views/PathPresenter.axaml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + diff --git a/src/GuiApp/Avalonia/FileTime.GuiApp/Views/PathPresenter.axaml.cs b/src/GuiApp/Avalonia/FileTime.GuiApp/Views/PathPresenter.axaml.cs new file mode 100644 index 0000000..2f8439f --- /dev/null +++ b/src/GuiApp/Avalonia/FileTime.GuiApp/Views/PathPresenter.axaml.cs @@ -0,0 +1,18 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Markup.Xaml; + +namespace FileTime.GuiApp.Views; + +public partial class PathPresenter : UserControl +{ + public PathPresenter() + { + InitializeComponent(); + } + + private void InitializeComponent() + { + AvaloniaXamlLoader.Load(this); + } +} \ No newline at end of file diff --git a/src/Providers/FileTime.Providers.Local/LocalContentProvider.cs b/src/Providers/FileTime.Providers.Local/LocalContentProvider.cs index 67c744a..1b45b6f 100644 --- a/src/Providers/FileTime.Providers.Local/LocalContentProvider.cs +++ b/src/Providers/FileTime.Providers.Local/LocalContentProvider.cs @@ -12,6 +12,7 @@ public sealed partial class LocalContentProvider : ContentProviderBase, ILocalCo { private readonly SourceList _rootDirectories = new(); private readonly bool _isCaseInsensitive; + public LocalContentProvider() : base("local") { _isCaseInsensitive = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); @@ -53,15 +54,15 @@ public sealed partial class LocalContentProvider : ContentProviderBase, ILocalCo { if ((path?.Length ?? 0) == 0) { - return Task.FromResult((IItem)this); + return Task.FromResult((IItem) this); } else if (Directory.Exists(path)) { - return Task.FromResult((IItem)DirectoryToContainer(new DirectoryInfo(path!.TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar), !itemInitializationSettings.SkipChildInitialization)); + return Task.FromResult((IItem) DirectoryToContainer(new DirectoryInfo(path!.TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar), !itemInitializationSettings.SkipChildInitialization)); } else if (File.Exists(path)) { - return Task.FromResult((IItem)FileToElement(new FileInfo(path))); + return Task.FromResult((IItem) FileToElement(new FileInfo(path))); } var type = forceResolvePathType switch @@ -85,7 +86,7 @@ public sealed partial class LocalContentProvider : ContentProviderBase, ILocalCo return forceResolvePathType switch { - AbsolutePathType.Container => Task.FromResult((IItem)CreateEmptyContainer(nativePath, Observable.Return(new List() { innerException }))), + AbsolutePathType.Container => Task.FromResult((IItem) CreateEmptyContainer(nativePath, Observable.Return(new List() {innerException}))), AbsolutePathType.Element => Task.FromResult(CreateEmptyElement(nativePath)), _ => throw new Exception($"Could not resolve path '{nativePath.Path}' and could not force create, because {nameof(forceResolvePathType)} is {nameof(AbsolutePathType.Unknown)}.", innerException) }; @@ -174,7 +175,7 @@ public sealed partial class LocalContentProvider : ContentProviderBase, ILocalCo SourceList? result = null; try { - var items = initializeChildren ? (List?)GetItemsByContainer(directoryInfo) : null; + var items = initializeChildren ? (List?) GetItemsByContainer(directoryInfo) : null; if (items != null) { result = new SourceList(); @@ -183,7 +184,7 @@ public sealed partial class LocalContentProvider : ContentProviderBase, ILocalCo } catch (Exception e) { - exceptions.OnNext(new List() { e }); + exceptions.OnNext(new List() {e}); } return Task.FromResult(result?.Connect()); @@ -196,7 +197,7 @@ public sealed partial class LocalContentProvider : ContentProviderBase, ILocalCo var parentFullName = fullName.GetParent() ?? throw new Exception($"Path does not have parent: '{fileInfo.FullName}'"); var parent = new AbsolutePath(this, parentFullName, AbsolutePathType.Container); - return new( + return new FileElement( fileInfo.Name, fileInfo.Name, fullName, @@ -209,7 +210,8 @@ public sealed partial class LocalContentProvider : ContentProviderBase, ILocalCo true, GetFileAttributes(fileInfo), this, - Observable.Return(Enumerable.Empty()) + Observable.Return(Enumerable.Empty()), + fileInfo.Length ); }