Item Attributes
This commit is contained in:
@@ -2,6 +2,6 @@ namespace FileTime.App.Core.ViewModels
|
||||
{
|
||||
public interface IContainerSizeContainerViewModel : IItemViewModel
|
||||
{
|
||||
|
||||
long Size { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,5 @@ namespace FileTime.App.Core.ViewModels
|
||||
{
|
||||
public interface IContainerViewModel : IItemViewModel
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,6 @@ namespace FileTime.App.Core.ViewModels
|
||||
{
|
||||
public interface IElementViewModel : IItemViewModel
|
||||
{
|
||||
|
||||
long? Size { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,5 @@ namespace FileTime.App.Core.ViewModels
|
||||
{
|
||||
public interface IFileViewModel : IElementViewModel
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Reactive.Subjects;
|
||||
using FileTime.App.Core.Models;
|
||||
using FileTime.App.Core.Models.Enums;
|
||||
using FileTime.Core.Models;
|
||||
@@ -6,10 +7,13 @@ namespace FileTime.App.Core.ViewModels
|
||||
{
|
||||
public interface IItemViewModel
|
||||
{
|
||||
IItem? Item { get; set; }
|
||||
IItem? BaseItem { get; set; }
|
||||
IObservable<IReadOnlyList<ItemNamePart>>? DisplayName { get; set; }
|
||||
IObservable<bool>? IsSelected { get; set; }
|
||||
IObservable<bool>? IsMarked { get; set; }
|
||||
ItemViewMode ViewMode { get; set; }
|
||||
BehaviorSubject<bool> IsAlternative { get; }
|
||||
IObservable<ItemViewMode> ViewMode { get; set; }
|
||||
DateTime? CreatedAt { get; set; }
|
||||
string? Attributes { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,11 @@
|
||||
using MvvmGen;
|
||||
|
||||
namespace FileTime.App.Core.ViewModels
|
||||
{
|
||||
public class ContainerSizeContainerViewModel : ItemViewModel, IContainerSizeContainerViewModel
|
||||
[ViewModel]
|
||||
public partial class ContainerSizeContainerViewModel : ItemViewModel, IContainerSizeContainerViewModel
|
||||
{
|
||||
|
||||
[Property]
|
||||
private long _size;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,11 @@
|
||||
using MvvmGen;
|
||||
|
||||
namespace FileTime.App.Core.ViewModels
|
||||
{
|
||||
public class ElementViewModel : ItemViewModel, IElementViewModel
|
||||
[ViewModel]
|
||||
public partial class ElementViewModel : ItemViewModel, IElementViewModel
|
||||
{
|
||||
|
||||
[Property]
|
||||
private long? _size;
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,5 @@ namespace FileTime.App.Core.ViewModels
|
||||
{
|
||||
public class FileViewModel : ElementViewModel, IFileViewModel
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Reactive.Subjects;
|
||||
using FileTime.App.Core.Models;
|
||||
using FileTime.App.Core.Models.Enums;
|
||||
using FileTime.Core.Models;
|
||||
@@ -9,7 +10,7 @@ namespace FileTime.App.Core.ViewModels
|
||||
public abstract partial class ItemViewModel : IItemViewModel
|
||||
{
|
||||
[Property]
|
||||
private IItem? _item;
|
||||
private IItem? _baseItem;
|
||||
|
||||
[Property]
|
||||
private IObservable<IReadOnlyList<ItemNamePart>>? _displayName;
|
||||
@@ -21,6 +22,15 @@ namespace FileTime.App.Core.ViewModels
|
||||
private IObservable<bool>? _isMarked;
|
||||
|
||||
[Property]
|
||||
private ItemViewMode _viewMode;
|
||||
private IObservable<ItemViewMode> _viewMode;
|
||||
|
||||
[Property]
|
||||
private DateTime? _createdAt;
|
||||
|
||||
[Property]
|
||||
private string? _attributes;
|
||||
|
||||
[Property]
|
||||
private BehaviorSubject<bool> _isAlternative = new(false);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Reactive.Linq;
|
||||
using System.Reactive.Subjects;
|
||||
using FileTime.App.Core.Models.Enums;
|
||||
using FileTime.App.Core.Services;
|
||||
using FileTime.Core.Models;
|
||||
using FileTime.Core.Services;
|
||||
@@ -39,15 +40,16 @@ namespace FileTime.App.Core.ViewModels
|
||||
{
|
||||
CurrentLocation = tab.CurrentLocation.AsObservable();
|
||||
CurrentItems = tab.CurrentItems.Select(items => items.Select(MapItemToViewModel).ToList());
|
||||
CurrentSelectedItem = CurrentItems.CombineLatest(
|
||||
CurrentSelectedItem = Observable.CombineLatest(
|
||||
CurrentItems,
|
||||
tab.CurrentSelectedItem,
|
||||
(currentItems, currentSelectedItemPath) => currentItems.FirstOrDefault(i => i.Item?.FullName == currentSelectedItemPath?.Path));
|
||||
(currentItems, currentSelectedItemPath) => currentItems.FirstOrDefault(i => i.BaseItem?.FullName == currentSelectedItemPath?.Path));
|
||||
tab.CurrentLocation.Subscribe((_) => _markedItems.OnNext(Enumerable.Empty<FullName>()));
|
||||
|
||||
Tab = tab;
|
||||
}
|
||||
|
||||
private IItemViewModel MapItemToViewModel(IItem item)
|
||||
private IItemViewModel MapItemToViewModel(IItem item, int index)
|
||||
{
|
||||
if (item is IContainer container)
|
||||
{
|
||||
@@ -56,6 +58,14 @@ namespace FileTime.App.Core.ViewModels
|
||||
|
||||
return containerViewModel;
|
||||
}
|
||||
else if (item is IFileElement fileElement)
|
||||
{
|
||||
var fileViewModel = _serviceProvider.GetRequiredService<IFileViewModel>();
|
||||
InitIItemViewModel(fileViewModel, item);
|
||||
fileViewModel.Size = fileElement.Size;
|
||||
|
||||
return fileViewModel;
|
||||
}
|
||||
else if (item is IElement element)
|
||||
{
|
||||
var elementViewModel = _serviceProvider.GetRequiredService<IElementViewModel>();
|
||||
@@ -68,17 +78,29 @@ namespace FileTime.App.Core.ViewModels
|
||||
|
||||
void InitIItemViewModel(IItemViewModel itemViewModel, IItem item)
|
||||
{
|
||||
itemViewModel.Item = item;
|
||||
itemViewModel.BaseItem = item;
|
||||
itemViewModel.DisplayName = _appState.SearchText.Select(s => _itemNameConverterService.GetDisplayName(item.DisplayName, s));
|
||||
itemViewModel.IsMarked = MarkedItems.Select(m => m.Contains(item.FullName));
|
||||
itemViewModel.IsSelected = MarkedItems.Select(m => m.Contains(item.FullName));
|
||||
itemViewModel.IsAlternative.OnNext(index % 2 == 0);
|
||||
itemViewModel.ViewMode = Observable.CombineLatest(itemViewModel.IsMarked, itemViewModel.IsSelected, itemViewModel.IsAlternative, GenerateViewMode);
|
||||
itemViewModel.Attributes = item.Attributes;
|
||||
itemViewModel.CreatedAt = item.CreatedAt;
|
||||
}
|
||||
}
|
||||
|
||||
~TabViewModel()
|
||||
private ItemViewMode GenerateViewMode(bool isMarked, bool isSelected, bool sAlternative)
|
||||
=> (isMarked, isSelected, sAlternative) switch
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
(true, true, _) => ItemViewMode.MarkedSelected,
|
||||
(true, false, true) => ItemViewMode.MarkedAlternative,
|
||||
(false, true, _) => ItemViewMode.Selected,
|
||||
(false, false, true) => ItemViewMode.Alternative,
|
||||
(true, false, false) => ItemViewMode.Marked,
|
||||
_ => ItemViewMode.Default
|
||||
};
|
||||
|
||||
~TabViewModel() => Dispose(false);
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
|
||||
@@ -2,6 +2,6 @@ namespace FileTime.Core.Models
|
||||
{
|
||||
public interface IFileElement : IElement
|
||||
{
|
||||
|
||||
long Size { get; }
|
||||
}
|
||||
}
|
||||
@@ -12,8 +12,10 @@ namespace FileTime.Core.Models
|
||||
FullName? Parent { get; }
|
||||
bool IsHidden { get; }
|
||||
bool IsExists { get; }
|
||||
DateTime? CreatedAt { get; }
|
||||
SupportsDelete CanDelete { get; }
|
||||
bool CanRename { get; }
|
||||
IContentProvider Provider { get; }
|
||||
string? Attributes { get; }
|
||||
}
|
||||
}
|
||||
@@ -3,16 +3,18 @@ using FileTime.Core.Services;
|
||||
|
||||
namespace FileTime.Core.Models
|
||||
{
|
||||
public record Container
|
||||
(string Name,
|
||||
public record Container(
|
||||
string Name,
|
||||
string DisplayName,
|
||||
FullName FullName,
|
||||
NativePath NativePath,
|
||||
FullName Parent,
|
||||
bool IsHidden,
|
||||
bool IsExists,
|
||||
DateTime? CreatedAt,
|
||||
SupportsDelete CanDelete,
|
||||
bool CanRename,
|
||||
string? Attributes,
|
||||
IContentProvider Provider,
|
||||
IReadOnlyList<IAbsolutePath> Items) : IContainer;
|
||||
}
|
||||
@@ -3,15 +3,17 @@ using FileTime.Core.Services;
|
||||
|
||||
namespace FileTime.Core.Models
|
||||
{
|
||||
public record Element
|
||||
(string Name,
|
||||
public record Element(
|
||||
string Name,
|
||||
string DisplayName,
|
||||
FullName FullName,
|
||||
NativePath NativePath,
|
||||
FullName Parent,
|
||||
bool IsHidden,
|
||||
bool IsExists,
|
||||
DateTime? CreatedAt,
|
||||
SupportsDelete CanDelete,
|
||||
bool CanRename,
|
||||
string? Attributes,
|
||||
IContentProvider Provider) : IElement;
|
||||
}
|
||||
34
src/Core/FileTime.Core.Models/FileElement.cs
Normal file
34
src/Core/FileTime.Core.Models/FileElement.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using FileTime.Core.Enums;
|
||||
using FileTime.Core.Services;
|
||||
|
||||
namespace FileTime.Core.Models
|
||||
{
|
||||
public record FileElement(
|
||||
string Name,
|
||||
string DisplayName,
|
||||
FullName FullName,
|
||||
NativePath NativePath,
|
||||
FullName Parent,
|
||||
bool IsHidden,
|
||||
bool IsExists,
|
||||
DateTime? CreatedAt,
|
||||
SupportsDelete CanDelete,
|
||||
bool CanRename,
|
||||
string? Attributes,
|
||||
IContentProvider Provider,
|
||||
long Size)
|
||||
: Element(
|
||||
Name,
|
||||
DisplayName,
|
||||
FullName,
|
||||
NativePath,
|
||||
Parent,
|
||||
IsHidden,
|
||||
IsExists,
|
||||
CreatedAt,
|
||||
CanDelete,
|
||||
CanRename,
|
||||
Attributes,
|
||||
Provider
|
||||
), IFileElement;
|
||||
}
|
||||
@@ -29,6 +29,10 @@ namespace FileTime.Core.Services
|
||||
|
||||
public FullName? Parent => null;
|
||||
|
||||
public DateTime? CreatedAt => null;
|
||||
|
||||
public string? Attributes => null;
|
||||
|
||||
protected ContentProviderBase(string name)
|
||||
{
|
||||
DisplayName = Name = name;
|
||||
|
||||
@@ -40,11 +40,6 @@ namespace FileTime.Core.Services
|
||||
)
|
||||
.Merge(Constants.MaximumObservableMergeOperations);
|
||||
CurrentSelectedItem = CurrentLocation.Select(GetSelectedItemByLocation).Merge(_currentSelectedItem).Throttle(TimeSpan.FromMilliseconds(500));
|
||||
|
||||
CurrentItems.Subscribe(c =>
|
||||
{
|
||||
;
|
||||
});
|
||||
}
|
||||
|
||||
public void Init(IContainer currentLocation)
|
||||
|
||||
@@ -79,7 +79,7 @@ namespace FileTime.GuiApp.Converters
|
||||
if (trimmed) break;
|
||||
}
|
||||
|
||||
return newNameParts.OfType<ItemNamePart>().ToList();
|
||||
return newNameParts.Where(f => f is not null).ToList()!;
|
||||
}
|
||||
|
||||
private static List<ItemNamePart> GetNamePartsForWidthPessimistic(IList<ItemNamePart> nameParts, double maxWidth)
|
||||
|
||||
@@ -2,17 +2,21 @@
|
||||
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"
|
||||
xmlns:appcore="using:FileTime.App.Core.ViewModels"
|
||||
xmlns:appcoreenums="using:FileTime.App.Core.Models.Enums"
|
||||
xmlns:guiappvm="using:FileTime.GuiApp.ViewModels"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="FileTime.GuiApp.Views.ItemView"
|
||||
x:Name="ItemRoot"
|
||||
HorizontalContentAlignment="Stretch"
|
||||
HorizontalAlignment="Stretch"
|
||||
Background="{Binding ViewMode,Converter={StaticResource ItemViewModeToBackgroundConverter}}">
|
||||
Background="{Binding ViewMode^,Converter={StaticResource ItemViewModeToBackgroundConverter}}"
|
||||
x:CompileBindings="True"
|
||||
x:DataType="appcore:IItemViewModel">
|
||||
<Grid ColumnDefinitions="20,*,Auto" Margin="3" x:Name="RootGrid">
|
||||
<Grid.Styles>
|
||||
<Style Selector="TextBlock">
|
||||
<Setter Property="Foreground" Value="{Binding DataContext.ViewMode,Converter={StaticResource ItemViewModeToForegroundConverter},ElementName=ItemRoot}"/>
|
||||
<Setter x:CompileBindings="False" Property="Foreground" Value="{Binding DataContext.ViewMode^,Converter={StaticResource ItemViewModeToForegroundConverter},ElementName=ItemRoot}"/>
|
||||
</Style>
|
||||
</Grid.Styles>
|
||||
<!--Image
|
||||
@@ -42,7 +46,7 @@
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<DataTemplate x:DataType="guiappvm:ItemNamePartViewModel">
|
||||
<Grid>
|
||||
<TextBlock
|
||||
Text="{Binding Text}"
|
||||
@@ -55,7 +59,8 @@
|
||||
<Grid Grid.Column="2" IsVisible="{Binding ShowAttributes,ElementName=ItemRoot}">
|
||||
<Grid ColumnDefinitions="50,50,90,40,45"
|
||||
HorizontalAlignment="Right"
|
||||
IsVisible="{Binding Converter={StaticResource ItemViewModelIsAttributeTypeConverter},ConverterParameter={x:Static appcoreenums:ItemAttributeType.File}}">
|
||||
IsVisible="{Binding Converter={StaticResource ItemViewModelIsAttributeTypeConverter},ConverterParameter={x:Static appcoreenums:ItemAttributeType.File}}"
|
||||
x:DataType="appcore:IFileViewModel">
|
||||
|
||||
<TextBlock HorizontalAlignment="Right" Classes="SmallText" Text="{Binding BaseItem.DisplayName, Converter={StaticResource GetFileExtensionConverter}}"/>
|
||||
<TextBlock HorizontalAlignment="Right" Classes="SmallText" Grid.Column="1" Text="{Binding Size, Converter={StaticResource FormatSizeConverter}, ConverterParameter=0}"/>
|
||||
@@ -65,21 +70,24 @@
|
||||
</Grid>
|
||||
<Grid ColumnDefinitions="90,40,45"
|
||||
HorizontalAlignment="Right"
|
||||
IsVisible="{Binding Converter={StaticResource ItemViewModelIsAttributeTypeConverter},ConverterParameter={x:Static appcoreenums:ItemAttributeType.Container}}">
|
||||
IsVisible="{Binding Converter={StaticResource ItemViewModelIsAttributeTypeConverter},ConverterParameter={x:Static appcoreenums:ItemAttributeType.Container}}"
|
||||
x:DataType="appcore:IContainerViewModel">
|
||||
|
||||
<TextBlock HorizontalAlignment="Right" Classes="SmallText" Text="{Binding Item.CreatedAt, Converter={StaticResource DateTimeConverter}, ConverterParameter=yyyy-MM-dd}"/>
|
||||
<TextBlock HorizontalAlignment="Right" Classes="SmallText" Text="{Binding CreatedAt, Converter={StaticResource DateTimeConverter}, ConverterParameter=yyyy-MM-dd}"/>
|
||||
<TextBlock HorizontalAlignment="Right" Classes="SmallText" Grid.Column="1" Text="{Binding BaseItem.CreatedAt, Converter={StaticResource DateTimeConverter}, ConverterParameter=hh:mm}"/>
|
||||
<TextBlock HorizontalAlignment="Right" Classes="SmallText" Grid.Column="2" Text="{Binding BaseItem.Attributes}"/>
|
||||
</Grid>
|
||||
<Grid ColumnDefinitions="50,90,40,45"
|
||||
HorizontalAlignment="Right"
|
||||
IsVisible="{Binding Converter={StaticResource ItemViewModelIsAttributeTypeConverter},ConverterParameter={x:Static appcoreenums:ItemAttributeType.SizeContainer}}">
|
||||
IsVisible="{Binding Converter={StaticResource ItemViewModelIsAttributeTypeConverter},ConverterParameter={x:Static appcoreenums:ItemAttributeType.SizeContainer}}"
|
||||
x:DataType="appcore:IContainerSizeContainerViewModel">
|
||||
|
||||
<TextBlock HorizontalAlignment="Right" Classes="SmallText" Text="{Binding Size, Converter={StaticResource FormatSizeConverter}, ConverterParameter=0}"/>
|
||||
</Grid>
|
||||
<Grid ColumnDefinitions="50,50"
|
||||
HorizontalAlignment="Right"
|
||||
IsVisible="{Binding Converter={StaticResource ItemViewModelIsAttributeTypeConverter},ConverterParameter={x:Static appcoreenums:ItemAttributeType.Element}}">
|
||||
IsVisible="{Binding Converter={StaticResource ItemViewModelIsAttributeTypeConverter},ConverterParameter={x:Static appcoreenums:ItemAttributeType.Element}}"
|
||||
x:DataType="appcore:IElementViewModel">
|
||||
|
||||
<TextBlock HorizontalAlignment="Right" Classes="SmallText" Text="{Binding BaseItem.DisplayName, Converter={StaticResource GetFileExtensionConverter}}"/>
|
||||
<TextBlock HorizontalAlignment="Right" Classes="SmallText" Grid.Column="1" Text="{Binding Size, Converter={StaticResource FormatSizeConverter}, ConverterParameter=0}"/>
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace FileTime.Providers.Local
|
||||
{
|
||||
partial class LocalContentProvider
|
||||
{
|
||||
private static string GetDirectoryAttributes(DirectoryInfo directoryInfo)
|
||||
{
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
{
|
||||
return "";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "d"
|
||||
+ ((directoryInfo.Attributes & FileAttributes.Archive) == FileAttributes.Archive ? "a" : "-")
|
||||
+ ((directoryInfo.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly ? "r" : "-")
|
||||
+ ((directoryInfo.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden ? "h" : "-")
|
||||
+ ((directoryInfo.Attributes & FileAttributes.System) == FileAttributes.System ? "s" : "-");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace FileTime.Providers.Local
|
||||
{
|
||||
partial class LocalContentProvider
|
||||
{
|
||||
private static string GetFileAttributes(FileInfo fileInfo)
|
||||
{
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
{
|
||||
return "";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "-"
|
||||
+ ((fileInfo.Attributes & FileAttributes.Archive) == FileAttributes.Archive ? "a" : "-")
|
||||
+ ((fileInfo.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly ? "r" : "-")
|
||||
+ ((fileInfo.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden ? "h" : "-")
|
||||
+ ((fileInfo.Attributes & FileAttributes.System) == FileAttributes.System ? "s" : "-");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ using FileTime.Core.Services;
|
||||
|
||||
namespace FileTime.Providers.Local
|
||||
{
|
||||
public class LocalContentProvider : ContentProviderBase, ILocalContentProvider
|
||||
public partial class LocalContentProvider : ContentProviderBase, ILocalContentProvider
|
||||
{
|
||||
protected bool IsCaseInsensitive { get; init; }
|
||||
public LocalContentProvider() : base("local")
|
||||
@@ -73,8 +73,10 @@ namespace FileTime.Providers.Local
|
||||
fullName.GetParent()!,
|
||||
(directoryInfo.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden,
|
||||
directoryInfo.Exists,
|
||||
directoryInfo.CreationTime,
|
||||
SupportsDelete.True,
|
||||
true,
|
||||
GetDirectoryAttributes(directoryInfo),
|
||||
this,
|
||||
GetItemsByContainer(directoryInfo)
|
||||
);
|
||||
@@ -91,8 +93,10 @@ namespace FileTime.Providers.Local
|
||||
fullName.GetParent()!,
|
||||
(fileInfo.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden,
|
||||
fileInfo.Exists,
|
||||
fileInfo.CreationTime,
|
||||
SupportsDelete.True,
|
||||
true,
|
||||
GetFileAttributes(fileInfo),
|
||||
this
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user