ModifiedAt for items, use it by default

This commit is contained in:
2023-08-03 12:00:33 +02:00
parent fe0003e55f
commit 5f1ad922dc
18 changed files with 64 additions and 22 deletions

View File

@@ -23,10 +23,11 @@ public record SizeScanContainer : ISizeScanContainer
public required NativePath? NativePath { get; init; } public required NativePath? NativePath { get; init; }
public required AbsolutePath? Parent { get; init; } public required AbsolutePath? Parent { get; init; }
public required IContentProvider Provider { get; init; } public required IContentProvider Provider { get; init; }
public required DateTime? CreatedAt { get; init; } = DateTime.Now;
public required DateTime? ModifiedAt { get; init;} = DateTime.Now;
public required SupportsDelete CanDelete { get; init; }
public bool IsHidden => false; public bool IsHidden => false;
public bool IsExists => true; public bool IsExists => true;
public DateTime? CreatedAt { get; } = DateTime.Now;
public SupportsDelete CanDelete => SupportsDelete.True;
public bool CanRename => false; public bool CanRename => false;
public string? Attributes => null; public string? Attributes => null;
public AbsolutePathType Type => AbsolutePathType.Container; public AbsolutePathType Type => AbsolutePathType.Container;

View File

@@ -13,12 +13,13 @@ public record SizeScanElement : ISizeScanElement
public required string DisplayName { get; init; } public required string DisplayName { get; init; }
public required FullName FullName { get; init; } public required FullName FullName { get; init; }
public required NativePath NativePath { get; init; } public required NativePath NativePath { get; init; }
public AbsolutePath? Parent { get; init; } public required AbsolutePath? Parent { get; init; }
public required DateTime? CreatedAt { get; init; }
public required DateTime? ModifiedAt { get; init;}
public required IDeclarativeProperty<long> Size { get; init; } public required IDeclarativeProperty<long> Size { get; init; }
public bool IsHidden => false; public bool IsHidden => false;
public bool IsExists => true; public bool IsExists => true;
public DateTime? CreatedAt { get; } = DateTime.Now;
public SupportsDelete CanDelete => SupportsDelete.False; public SupportsDelete CanDelete => SupportsDelete.False;
public bool CanRename => false; public bool CanRename => false;
public string? Attributes => ""; public string? Attributes => "";

View File

@@ -1,4 +1,5 @@
using DeclarativeProperty; using DeclarativeProperty;
using FileTime.Core.Enums;
using FileTime.Core.Models; using FileTime.Core.Models;
using FileTime.Core.Models.Extensions; using FileTime.Core.Models.Extensions;
using FileTime.Core.Timeline; using FileTime.Core.Timeline;
@@ -48,7 +49,10 @@ public class SizeScanTask : ISizeScanTask
RealContainer = scanSizeOf, RealContainer = scanSizeOf,
Provider = _containerSizeScanProvider, Provider = _containerSizeScanProvider,
Status = _containerStatusDebounced, Status = _containerStatusDebounced,
SizeScanTask = this SizeScanTask = this,
CreatedAt = scanSizeOf.CreatedAt,
ModifiedAt = scanSizeOf.ModifiedAt,
CanDelete = SupportsDelete.True
}; };
} }
@@ -114,7 +118,9 @@ public class SizeScanTask : ISizeScanTask
NativePath = new NativePath(childName), NativePath = new NativePath(childName),
Parent = new AbsolutePath(_timelessContentProvider, sizeScanContainer), Parent = new AbsolutePath(_timelessContentProvider, sizeScanContainer),
Provider = _containerSizeScanProvider, Provider = _containerSizeScanProvider,
Size = sizeProperty Size = sizeProperty,
CreatedAt = element.CreatedAt,
ModifiedAt = element.ModifiedAt,
}; };
await sizeScanContainer.AddSizeChildAsync(childElement); await sizeScanContainer.AddSizeChildAsync(childElement);
@@ -137,7 +143,10 @@ public class SizeScanTask : ISizeScanTask
RealContainer = childContainer, RealContainer = childContainer,
Provider = _containerSizeScanProvider, Provider = _containerSizeScanProvider,
Status = _containerStatusDebounced, Status = _containerStatusDebounced,
SizeScanTask = this SizeScanTask = this,
CreatedAt = childContainer.CreatedAt,
ModifiedAt = childContainer.ModifiedAt,
CanDelete = SupportsDelete.False
}; };
await sizeScanContainer.AddSizeChildAsync(childSearchContainer); await sizeScanContainer.AddSizeChildAsync(childSearchContainer);

View File

@@ -4,6 +4,8 @@ public enum ItemOrdering
{ {
Name, Name,
NameDesc, NameDesc,
CreationDate,
CreationDateDesc,
LastModifyDate, LastModifyDate,
LastModifyDateDesc, LastModifyDateDesc,
} }

View File

@@ -6,8 +6,10 @@ public sealed class SortItemsCommand : IIdentifiableUserCommand
{ {
public const string OrderByNameCommandName = "order_by_name"; public const string OrderByNameCommandName = "order_by_name";
public const string OrderByNameDescCommandName = "order_by_name_desc"; public const string OrderByNameDescCommandName = "order_by_name_desc";
public const string OrderByDateCommandName = "order_by_date"; public const string OrderByCreatedAtCommandName = "order_by_created_at";
public const string OrderByDateDescCommandName = "order_by_date_desc"; public const string OrderByCreatedAtDescCommandName = "order_by_created_at_desc";
public const string OrderByModifiedAtCommandName = "order_by_modified_at";
public const string OrderByModifiedAtDescCommandName = "order_by_modified_at_desc";
public static readonly SortItemsCommand OrderByNameCommand = public static readonly SortItemsCommand OrderByNameCommand =
new(OrderByNameCommandName, ItemOrdering.Name, "Order by name"); new(OrderByNameCommandName, ItemOrdering.Name, "Order by name");
@@ -15,11 +17,17 @@ public sealed class SortItemsCommand : IIdentifiableUserCommand
public static readonly SortItemsCommand OrderByNameDescCommand = public static readonly SortItemsCommand OrderByNameDescCommand =
new(OrderByNameDescCommandName, ItemOrdering.NameDesc, "Order by name (descending)"); new(OrderByNameDescCommandName, ItemOrdering.NameDesc, "Order by name (descending)");
public static readonly SortItemsCommand OrderByDateCommand = public static readonly SortItemsCommand OrderByCreatedAtCommand =
new(OrderByDateCommandName, ItemOrdering.LastModifyDate, "Order by date"); new(OrderByCreatedAtCommandName, ItemOrdering.CreationDate, "Order by created");
public static readonly SortItemsCommand OrderByDateDescCommand = public static readonly SortItemsCommand OrderByCreatedAtDescCommand =
new(OrderByDateDescCommandName, ItemOrdering.LastModifyDateDesc, "Order by date (descending)"); new(OrderByCreatedAtDescCommandName, ItemOrdering.CreationDateDesc, "Order by created (descending)");
public static readonly SortItemsCommand OrderByLastModifiedCommand =
new(OrderByModifiedAtCommandName, ItemOrdering.LastModifyDate, "Order by last modified");
public static readonly SortItemsCommand OrderByLastModifiedDescCommand =
new(OrderByModifiedAtDescCommandName, ItemOrdering.LastModifyDateDesc, "Order by last modified (descending)");
private SortItemsCommand(string userCommandId, ItemOrdering ordering, string title) private SortItemsCommand(string userCommandId, ItemOrdering ordering, string title)
{ {

View File

@@ -15,6 +15,7 @@ public interface IItemViewModel : IInitable<IItem, ITabViewModel, ItemViewModelT
IDeclarativeProperty<bool> IsAlternative { get; } IDeclarativeProperty<bool> IsAlternative { get; }
IDeclarativeProperty<ItemViewMode> ViewMode { get; set; } IDeclarativeProperty<ItemViewMode> ViewMode { get; set; }
DateTime? CreatedAt { get; set; } DateTime? CreatedAt { get; set; }
DateTime? ModifiedAt { get; set; }
string? Attributes { get; set; } string? Attributes { get; set; }
bool EqualsTo(IItemViewModel? itemViewModel); bool EqualsTo(IItemViewModel? itemViewModel);
} }

View File

@@ -52,8 +52,10 @@ public class DefaultIdentifiableCommandHandlerRegister : IStartupHandler
AddUserCommand(StartCommandSchedulerCommand.Instance); AddUserCommand(StartCommandSchedulerCommand.Instance);
AddUserCommand(SortItemsCommand.OrderByNameCommand); AddUserCommand(SortItemsCommand.OrderByNameCommand);
AddUserCommand(SortItemsCommand.OrderByNameDescCommand); AddUserCommand(SortItemsCommand.OrderByNameDescCommand);
AddUserCommand(SortItemsCommand.OrderByDateCommand); AddUserCommand(SortItemsCommand.OrderByCreatedAtCommand);
AddUserCommand(SortItemsCommand.OrderByDateDescCommand); AddUserCommand(SortItemsCommand.OrderByCreatedAtDescCommand);
AddUserCommand(SortItemsCommand.OrderByLastModifiedCommand);
AddUserCommand(SortItemsCommand.OrderByLastModifiedDescCommand);
AddUserCommand(IdentifiableSearchCommand.SearchByNameContains); AddUserCommand(IdentifiableSearchCommand.SearchByNameContains);
AddUserCommand(IdentifiableSearchCommand.SearchByRegex); AddUserCommand(IdentifiableSearchCommand.SearchByRegex);
AddUserCommand(SwitchToTabCommand.SwitchToLastTab); AddUserCommand(SwitchToTabCommand.SwitchToLastTab);

View File

@@ -31,6 +31,7 @@ public abstract partial class ItemViewModel : IItemViewModel
[Property] private IDeclarativeProperty<ItemViewMode> _viewMode; [Property] private IDeclarativeProperty<ItemViewMode> _viewMode;
[Property] private DateTime? _createdAt; [Property] private DateTime? _createdAt;
[Property] private DateTime? _modifiedAt;
[Property] private string? _attributes; [Property] private string? _attributes;
@@ -88,6 +89,7 @@ public abstract partial class ItemViewModel : IItemViewModel
.Debounce(TimeSpan.FromMilliseconds(100)); .Debounce(TimeSpan.FromMilliseconds(100));
Attributes = item.Attributes; Attributes = item.Attributes;
CreatedAt = item.CreatedAt; CreatedAt = item.CreatedAt;
ModifiedAt = item.ModifiedAt;
} }
private Task<ItemViewMode> GenerateViewMode(bool isMarked, bool isSelected, bool isAlternative) private Task<ItemViewMode> GenerateViewMode(bool isMarked, bool isSelected, bool isAlternative)

View File

@@ -93,18 +93,24 @@ public partial class TabViewModel : ITabViewModel
{ {
ItemOrdering.Name => ItemOrdering.Name =>
items items
.Ordering(i => i.BaseItem.Type) .Ordering(i => i.BaseItem!.Type)
.ThenOrdering(i => i.DisplayNameText), .ThenOrdering(i => i.DisplayNameText),
ItemOrdering.NameDesc => ItemOrdering.NameDesc =>
items items
.Ordering(i => i.BaseItem.Type) .Ordering(i => i.BaseItem!.Type)
.ThenOrdering(i => i.DisplayNameText, ListSortDirection.Descending), .ThenOrdering(i => i.DisplayNameText, ListSortDirection.Descending),
ItemOrdering.LastModifyDate => ItemOrdering.CreationDate =>
items items
.Ordering(i => i.CreatedAt), .Ordering(i => i.CreatedAt),
ItemOrdering.LastModifyDateDesc => ItemOrdering.CreationDateDesc =>
items items
.Ordering(i => i.CreatedAt, ListSortDirection.Descending), .Ordering(i => i.CreatedAt, ListSortDirection.Descending),
ItemOrdering.LastModifyDate =>
items
.Ordering(i => i.ModifiedAt),
ItemOrdering.LastModifyDateDesc =>
items
.Ordering(i => i.ModifiedAt, ListSortDirection.Descending),
_ => throw new NotImplementedException() _ => throw new NotImplementedException()
}; };

View File

@@ -51,6 +51,7 @@ public class SearchTask : ISearchTask
false, false,
true, true,
null, null,
null,
SupportsDelete.False, SupportsDelete.False,
false, false,
null, null,

View File

@@ -15,6 +15,7 @@ public interface IItem
bool IsHidden { get; } bool IsHidden { get; }
bool IsExists { get; } bool IsExists { get; }
DateTime? CreatedAt { get; } DateTime? CreatedAt { get; }
DateTime? ModifiedAt { get; }
SupportsDelete CanDelete { get; } SupportsDelete CanDelete { get; }
bool CanRename { get; } bool CanRename { get; }
IContentProvider Provider { get; } IContentProvider Provider { get; }

View File

@@ -34,6 +34,7 @@ public abstract class ContentProviderBase : IContentProvider
public AbsolutePath? Parent { get; } public AbsolutePath? Parent { get; }
public DateTime? CreatedAt => null; public DateTime? CreatedAt => null;
public DateTime? ModifiedAt => null;
public string? Attributes => null; public string? Attributes => null;

View File

@@ -18,6 +18,7 @@ public class RootContentProvider : IRootContentProvider
public bool IsHidden => false; public bool IsHidden => false;
public bool IsExists => true; public bool IsExists => true;
public DateTime? CreatedAt => null; public DateTime? CreatedAt => null;
public DateTime? ModifiedAt => null;
public SupportsDelete CanDelete => SupportsDelete.False; public SupportsDelete CanDelete => SupportsDelete.False;
public bool CanRename => false; public bool CanRename => false;
public IContentProvider Provider => this; public IContentProvider Provider => this;

View File

@@ -16,6 +16,7 @@ public record Container(
bool IsHidden, bool IsHidden,
bool IsExists, bool IsExists,
DateTime? CreatedAt, DateTime? CreatedAt,
DateTime? ModifiedAt,
SupportsDelete CanDelete, SupportsDelete CanDelete,
bool CanRename, bool CanRename,
string? Attributes, string? Attributes,

View File

@@ -14,6 +14,7 @@ public record Element(
bool IsHidden, bool IsHidden,
bool IsExists, bool IsExists,
DateTime? CreatedAt, DateTime? CreatedAt,
DateTime? ModifiedAt,
SupportsDelete CanDelete, SupportsDelete CanDelete,
bool CanRename, bool CanRename,
string? Attributes, string? Attributes,

View File

@@ -27,6 +27,7 @@ public class ItemPreview
false, false,
true, true,
DateTime.Now, DateTime.Now,
DateTime.Now,
SupportsDelete.True, SupportsDelete.True,
true, true,
"attr", "attr",
@@ -54,6 +55,7 @@ public class ItemPreview
false, false,
true, true,
DateTime.Now, DateTime.Now,
DateTime.Now,
SupportsDelete.True, SupportsDelete.True,
true, true,
"attr", "attr",

View File

@@ -11,7 +11,6 @@
x:Name="ItemRoot" x:Name="ItemRoot"
xmlns="https://github.com/avaloniaui" xmlns="https://github.com/avaloniaui"
xmlns:appcore="using:FileTime.App.Core.ViewModels" xmlns:appcore="using:FileTime.App.Core.ViewModels"
xmlns:appcoreenums="using:FileTime.App.Core.Models.Enums"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:guiappvm="using:FileTime.GuiApp.ViewModels" xmlns:guiappvm="using:FileTime.GuiApp.ViewModels"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
@@ -88,12 +87,12 @@
</Grid> </Grid>
<TextBlock <TextBlock
Classes="SmallText" Classes="SmallText"
Text="{Binding CreatedAt, Converter={StaticResource DateTimeConverter}, ConverterParameter=yyyy-MM-dd}" Text="{Binding ModifiedAt, Converter={StaticResource DateTimeConverter}, ConverterParameter=yyyy-MM-dd}"
TextAlignment="Right" TextAlignment="Right"
Width="95" /> Width="95" />
<TextBlock <TextBlock
Classes="SmallText" Classes="SmallText"
Text="{Binding CreatedAt, Converter={StaticResource DateTimeConverter}, ConverterParameter=hh:mm}" Text="{Binding ModifiedAt, Converter={StaticResource DateTimeConverter}, ConverterParameter=hh:mm}"
TextAlignment="Right" TextAlignment="Right"
Width="35" /> Width="35" />
<TextBlock <TextBlock

View File

@@ -164,6 +164,7 @@ public sealed partial class LocalContentProvider : ContentProviderBase, ILocalCo
false, false,
true, true,
DateTime.MinValue, DateTime.MinValue,
DateTime.MinValue,
SupportsDelete.False, SupportsDelete.False,
false, false,
"???", "???",
@@ -222,6 +223,7 @@ public sealed partial class LocalContentProvider : ContentProviderBase, ILocalCo
(directoryInfo.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden, (directoryInfo.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden,
directoryInfo.Exists, directoryInfo.Exists,
directoryInfo.CreationTime, directoryInfo.CreationTime,
directoryInfo.LastWriteTime,
SupportsDelete.True, SupportsDelete.True,
true, true,
GetDirectoryAttributes(directoryInfo), GetDirectoryAttributes(directoryInfo),
@@ -351,6 +353,7 @@ public sealed partial class LocalContentProvider : ContentProviderBase, ILocalCo
(fileInfo.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden, (fileInfo.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden,
fileInfo.Exists, fileInfo.Exists,
fileInfo.CreationTime, fileInfo.CreationTime,
fileInfo.LastWriteTime,
SupportsDelete.True, SupportsDelete.True,
true, true,
GetFileAttributes(fileInfo), GetFileAttributes(fileInfo),