Add Parent to IItem
This commit is contained in:
@@ -3,6 +3,5 @@ namespace FileTime.Core.Models
|
|||||||
public static class Constants
|
public static class Constants
|
||||||
{
|
{
|
||||||
public const char SeparatorChar = '/';
|
public const char SeparatorChar = '/';
|
||||||
public const string ContentProviderProtocol = "ctp://";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,17 @@
|
|||||||
namespace FileTime.Core.Models
|
namespace FileTime.Core.Models
|
||||||
{
|
{
|
||||||
public record FullName(string Path);
|
public record FullName(string Path)
|
||||||
|
{
|
||||||
|
public FullName? GetParent()
|
||||||
|
{
|
||||||
|
if (Path is null) return null;
|
||||||
|
|
||||||
|
var pathParts = Path.Split(Constants.SeparatorChar);
|
||||||
|
return pathParts.Length switch
|
||||||
|
{
|
||||||
|
> 1 => new(string.Join(Constants.SeparatorChar, pathParts.SkipLast(1))),
|
||||||
|
_ => null
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -9,6 +9,7 @@ namespace FileTime.Core.Models
|
|||||||
string DisplayName { get; }
|
string DisplayName { get; }
|
||||||
FullName? FullName { get; }
|
FullName? FullName { get; }
|
||||||
NativePath? NativePath { get; }
|
NativePath? NativePath { get; }
|
||||||
|
FullName? Parent { get; }
|
||||||
bool IsHidden { get; }
|
bool IsHidden { get; }
|
||||||
bool IsExists { get; }
|
bool IsExists { get; }
|
||||||
SupportsDelete CanDelete { get; }
|
SupportsDelete CanDelete { get; }
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ namespace FileTime.Core.Models
|
|||||||
string DisplayName,
|
string DisplayName,
|
||||||
FullName FullName,
|
FullName FullName,
|
||||||
NativePath NativePath,
|
NativePath NativePath,
|
||||||
|
FullName Parent,
|
||||||
bool IsHidden,
|
bool IsHidden,
|
||||||
bool IsExists,
|
bool IsExists,
|
||||||
SupportsDelete CanDelete,
|
SupportsDelete CanDelete,
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ namespace FileTime.Core.Models
|
|||||||
string DisplayName,
|
string DisplayName,
|
||||||
FullName FullName,
|
FullName FullName,
|
||||||
NativePath NativePath,
|
NativePath NativePath,
|
||||||
|
FullName Parent,
|
||||||
bool IsHidden,
|
bool IsHidden,
|
||||||
bool IsExists,
|
bool IsExists,
|
||||||
SupportsDelete CanDelete,
|
SupportsDelete CanDelete,
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ namespace FileTime.Core.Services
|
|||||||
|
|
||||||
public IContentProvider Provider => this;
|
public IContentProvider Provider => this;
|
||||||
|
|
||||||
|
public FullName? Parent => null;
|
||||||
|
|
||||||
protected ContentProviderBase(string name)
|
protected ContentProviderBase(string name)
|
||||||
{
|
{
|
||||||
DisplayName = Name = name;
|
DisplayName = Name = name;
|
||||||
|
|||||||
@@ -62,12 +62,15 @@ namespace FileTime.Providers.Local
|
|||||||
return new AbsolutePath(this, fullName, AbsolutePathType.Element);
|
return new AbsolutePath(this, fullName, AbsolutePathType.Element);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Container DirectoryToContainer(DirectoryInfo directoryInfo) =>
|
private Container DirectoryToContainer(DirectoryInfo directoryInfo)
|
||||||
new(
|
{
|
||||||
|
var fullName = GetFullName(directoryInfo.FullName);
|
||||||
|
return new(
|
||||||
directoryInfo.Name,
|
directoryInfo.Name,
|
||||||
directoryInfo.Name,
|
directoryInfo.Name,
|
||||||
GetFullName(directoryInfo.FullName),
|
fullName,
|
||||||
new(directoryInfo.FullName),
|
new(directoryInfo.FullName),
|
||||||
|
fullName.GetParent()!,
|
||||||
(directoryInfo.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden,
|
(directoryInfo.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden,
|
||||||
directoryInfo.Exists,
|
directoryInfo.Exists,
|
||||||
SupportsDelete.True,
|
SupportsDelete.True,
|
||||||
@@ -75,19 +78,24 @@ namespace FileTime.Providers.Local
|
|||||||
this,
|
this,
|
||||||
GetItemsByContainer(directoryInfo)
|
GetItemsByContainer(directoryInfo)
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
private Element FileToElement(FileInfo fileInfo) =>
|
private Element FileToElement(FileInfo fileInfo)
|
||||||
new(
|
{
|
||||||
|
var fullName = GetFullName(fileInfo);
|
||||||
|
return new(
|
||||||
fileInfo.Name,
|
fileInfo.Name,
|
||||||
fileInfo.Name,
|
fileInfo.Name,
|
||||||
GetFullName(fileInfo),
|
fullName,
|
||||||
new(fileInfo.FullName),
|
new(fileInfo.FullName),
|
||||||
|
fullName.GetParent()!,
|
||||||
(fileInfo.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden,
|
(fileInfo.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden,
|
||||||
fileInfo.Exists,
|
fileInfo.Exists,
|
||||||
SupportsDelete.True,
|
SupportsDelete.True,
|
||||||
true,
|
true,
|
||||||
this
|
this
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
private FullName GetFullName(DirectoryInfo directoryInfo) => GetFullName(directoryInfo.FullName);
|
private FullName GetFullName(DirectoryInfo directoryInfo) => GetFullName(directoryInfo.FullName);
|
||||||
private FullName GetFullName(FileInfo fileInfo) => GetFullName(fileInfo.FullName);
|
private FullName GetFullName(FileInfo fileInfo) => GetFullName(fileInfo.FullName);
|
||||||
|
|||||||
Reference in New Issue
Block a user