PathPresenter, File type item
This commit is contained in:
@@ -14,6 +14,8 @@ public static class Startup
|
|||||||
.AddTransient<ITabViewModel, TabViewModel>()
|
.AddTransient<ITabViewModel, TabViewModel>()
|
||||||
.AddTransient<IContainerViewModel, ContainerViewModel>()
|
.AddTransient<IContainerViewModel, ContainerViewModel>()
|
||||||
.AddTransient<IElementViewModel, ElementViewModel>()
|
.AddTransient<IElementViewModel, ElementViewModel>()
|
||||||
|
.AddTransient<IFileViewModel, FileViewModel>()
|
||||||
|
.AddTransient<IContainerSizeContainerViewModel, ContainerSizeContainerViewModel>()
|
||||||
.AddTransient<IItemNameConverterService, ItemNameConverterService>()
|
.AddTransient<IItemNameConverterService, ItemNameConverterService>()
|
||||||
.AddSingleton<IUserCommandHandlerService, UserCommandHandlerService>()
|
.AddSingleton<IUserCommandHandlerService, UserCommandHandlerService>()
|
||||||
.AddSingleton<IClipboardService, ClipboardService>()
|
.AddSingleton<IClipboardService, ClipboardService>()
|
||||||
|
|||||||
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -31,4 +31,5 @@
|
|||||||
<converters:ExceptionToStringConverter x:Key="ExceptionToStringConverter" />
|
<converters:ExceptionToStringConverter x:Key="ExceptionToStringConverter" />
|
||||||
<converters:CommandToCommandNameConverter x:Key="CommandToCommandNameConverter" />
|
<converters:CommandToCommandNameConverter x:Key="CommandToCommandNameConverter" />
|
||||||
<converters:ItemToImageConverter x:Key="ItemToImageConverter" />
|
<converters:ItemToImageConverter x:Key="ItemToImageConverter" />
|
||||||
|
<converters:StringReplaceConverter x:Key="PathPreformatter" OldValue="://" NewValue="/"/>
|
||||||
</ResourceDictionary>
|
</ResourceDictionary>
|
||||||
@@ -47,7 +47,7 @@
|
|||||||
<StackPanel
|
<StackPanel
|
||||||
Margin="20,10"
|
Margin="20,10"
|
||||||
Orientation="Horizontal">
|
Orientation="Horizontal">
|
||||||
<!-- local:PathPresenter DataContext="{Binding AppState.SelectedTab^.CurrentLocation^.FullName.Path,Converter={StaticResource PathPreformatter}}"/ -->
|
<local:PathPresenter DataContext="{Binding AppState.SelectedTab^.CurrentLocation^.FullName.Path,Converter={StaticResource PathPreformatter}}"/>
|
||||||
<TextBlock
|
<TextBlock
|
||||||
Foreground="{StaticResource AccentBrush}"
|
Foreground="{StaticResource AccentBrush}"
|
||||||
Text="{Binding AppState.SelectedTab^.CurrentSelectedItem^.DisplayNameText}" />
|
Text="{Binding AppState.SelectedTab^.CurrentSelectedItem^.DisplayNameText}" />
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<UserControl xmlns="https://github.com/avaloniaui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
|
xmlns:coremodels="using:FileTime.Core.Models"
|
||||||
|
x:Class="FileTime.GuiApp.Views.PathPresenter">
|
||||||
|
<ItemsControl Items="{Binding Converter={StaticResource SplitStringConverter}, ConverterParameter={x:Static coremodels:Constants.SeparatorChar}}">
|
||||||
|
<ItemsControl.ItemsPanel>
|
||||||
|
<ItemsPanelTemplate>
|
||||||
|
<StackPanel Orientation="Horizontal" />
|
||||||
|
</ItemsPanelTemplate>
|
||||||
|
</ItemsControl.ItemsPanel>
|
||||||
|
<ItemsControl.ItemTemplate>
|
||||||
|
<DataTemplate>
|
||||||
|
<StackPanel Orientation="Horizontal">
|
||||||
|
<TextBlock Text="{Binding}"/>
|
||||||
|
<TextBlock Text="/" Margin="5,0,5,0" Foreground="{DynamicResource LightForegroundBrush}"/>
|
||||||
|
</StackPanel>
|
||||||
|
</DataTemplate>
|
||||||
|
</ItemsControl.ItemTemplate>
|
||||||
|
</ItemsControl>
|
||||||
|
</UserControl>
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,6 +12,7 @@ public sealed partial class LocalContentProvider : ContentProviderBase, ILocalCo
|
|||||||
{
|
{
|
||||||
private readonly SourceList<IAbsolutePath> _rootDirectories = new();
|
private readonly SourceList<IAbsolutePath> _rootDirectories = new();
|
||||||
private readonly bool _isCaseInsensitive;
|
private readonly bool _isCaseInsensitive;
|
||||||
|
|
||||||
public LocalContentProvider() : base("local")
|
public LocalContentProvider() : base("local")
|
||||||
{
|
{
|
||||||
_isCaseInsensitive = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
|
_isCaseInsensitive = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
|
||||||
@@ -53,15 +54,15 @@ public sealed partial class LocalContentProvider : ContentProviderBase, ILocalCo
|
|||||||
{
|
{
|
||||||
if ((path?.Length ?? 0) == 0)
|
if ((path?.Length ?? 0) == 0)
|
||||||
{
|
{
|
||||||
return Task.FromResult((IItem)this);
|
return Task.FromResult((IItem) this);
|
||||||
}
|
}
|
||||||
else if (Directory.Exists(path))
|
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))
|
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
|
var type = forceResolvePathType switch
|
||||||
@@ -85,7 +86,7 @@ public sealed partial class LocalContentProvider : ContentProviderBase, ILocalCo
|
|||||||
|
|
||||||
return forceResolvePathType switch
|
return forceResolvePathType switch
|
||||||
{
|
{
|
||||||
AbsolutePathType.Container => Task.FromResult((IItem)CreateEmptyContainer(nativePath, Observable.Return(new List<Exception>() { innerException }))),
|
AbsolutePathType.Container => Task.FromResult((IItem) CreateEmptyContainer(nativePath, Observable.Return(new List<Exception>() {innerException}))),
|
||||||
AbsolutePathType.Element => Task.FromResult(CreateEmptyElement(nativePath)),
|
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)
|
_ => 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<IAbsolutePath>? result = null;
|
SourceList<IAbsolutePath>? result = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var items = initializeChildren ? (List<IAbsolutePath>?)GetItemsByContainer(directoryInfo) : null;
|
var items = initializeChildren ? (List<IAbsolutePath>?) GetItemsByContainer(directoryInfo) : null;
|
||||||
if (items != null)
|
if (items != null)
|
||||||
{
|
{
|
||||||
result = new SourceList<IAbsolutePath>();
|
result = new SourceList<IAbsolutePath>();
|
||||||
@@ -183,7 +184,7 @@ public sealed partial class LocalContentProvider : ContentProviderBase, ILocalCo
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
exceptions.OnNext(new List<Exception>() { e });
|
exceptions.OnNext(new List<Exception>() {e});
|
||||||
}
|
}
|
||||||
|
|
||||||
return Task.FromResult(result?.Connect());
|
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 parentFullName = fullName.GetParent() ?? throw new Exception($"Path does not have parent: '{fileInfo.FullName}'");
|
||||||
var parent = new AbsolutePath(this, parentFullName, AbsolutePathType.Container);
|
var parent = new AbsolutePath(this, parentFullName, AbsolutePathType.Container);
|
||||||
|
|
||||||
return new(
|
return new FileElement(
|
||||||
fileInfo.Name,
|
fileInfo.Name,
|
||||||
fileInfo.Name,
|
fileInfo.Name,
|
||||||
fullName,
|
fullName,
|
||||||
@@ -209,7 +210,8 @@ public sealed partial class LocalContentProvider : ContentProviderBase, ILocalCo
|
|||||||
true,
|
true,
|
||||||
GetFileAttributes(fileInfo),
|
GetFileAttributes(fileInfo),
|
||||||
this,
|
this,
|
||||||
Observable.Return(Enumerable.Empty<Exception>())
|
Observable.Return(Enumerable.Empty<Exception>()),
|
||||||
|
fileInfo.Length
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user