Fix crash with empty fullname path
This commit is contained in:
@@ -7,11 +7,18 @@ public record FullName(string Path)
|
||||
var pathParts = Path.TrimEnd(Constants.SeparatorChar).Split(Constants.SeparatorChar);
|
||||
return pathParts.Length switch
|
||||
{
|
||||
> 1 => new(string.Join(Constants.SeparatorChar, pathParts.SkipLast(1))),
|
||||
> 1 => CreateSafe(string.Join(Constants.SeparatorChar, pathParts.SkipLast(1))),
|
||||
_ => null
|
||||
};
|
||||
}
|
||||
|
||||
public static FullName? CreateSafe(string? path)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(path))
|
||||
return null;
|
||||
return new(path);
|
||||
}
|
||||
|
||||
public string GetName()
|
||||
=> Path.Split(Constants.SeparatorChar).Last();
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ public abstract class ContentProviderBase : IContentProvider
|
||||
protected ContentProviderBase(string name)
|
||||
{
|
||||
DisplayName = Name = name;
|
||||
FullName = new FullName(name);
|
||||
FullName = FullName.CreateSafe(name);
|
||||
Extensions = new ExtensionCollection();
|
||||
_extensions = Extensions.AsReadOnly();
|
||||
}
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Reactive.Linq;
|
||||
using System.Reactive.Subjects;
|
||||
using DynamicData;
|
||||
using FileTime.Core.ContentAccess;
|
||||
using FileTime.Core.Enums;
|
||||
using FileTime.Core.Services;
|
||||
using FileTime.Core.Timeline;
|
||||
|
||||
namespace FileTime.Core.Models;
|
||||
@@ -28,7 +26,7 @@ public record Container(
|
||||
ReadOnlyExtensionCollection Extensions,
|
||||
IObservable<IObservable<IChangeSet<AbsolutePath, string>>?> Items) : IContainer
|
||||
{
|
||||
BehaviorSubject<bool> IsLoading { get; } = new BehaviorSubject<bool>(false);
|
||||
BehaviorSubject<bool> IsLoading { get; } = new(false);
|
||||
IObservable<bool> IContainer.IsLoading => IsLoading.AsObservable();
|
||||
public AbsolutePathType Type => AbsolutePathType.Container;
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using FileTime.Core.ContentAccess;
|
||||
using FileTime.Core.Enums;
|
||||
using FileTime.Core.Services;
|
||||
using FileTime.Core.Timeline;
|
||||
|
||||
namespace FileTime.Core.Models;
|
||||
|
||||
@@ -37,7 +37,7 @@ public class Tab : ITab
|
||||
{
|
||||
if (_currentSelectedItemCached is not null)
|
||||
{
|
||||
LastDeepestSelectedPath = new FullName(PathHelper.GetLongerPath(LastDeepestSelectedPath?.Path, _currentSelectedItemCached.Path.Path));
|
||||
LastDeepestSelectedPath = FullName.CreateSafe(PathHelper.GetLongerPath(LastDeepestSelectedPath?.Path, _currentSelectedItemCached.Path.Path));
|
||||
}
|
||||
})
|
||||
.Publish(null)
|
||||
@@ -57,7 +57,7 @@ public class Tab : ITab
|
||||
.Where(c => c is null)
|
||||
.Select(_ => (IObservable<IChangeSet<IItem, string>>?)null)
|
||||
)
|
||||
.Publish((IObservable<IChangeSet<IItem, string>>?)null)
|
||||
.Publish(null)
|
||||
.RefCount();
|
||||
|
||||
CurrentSelectedItem =
|
||||
@@ -96,7 +96,7 @@ public class Tab : ITab
|
||||
_currentLocation.OnNext(currentLocation);
|
||||
}
|
||||
|
||||
private AbsolutePath? GetSelectedItemByItems(IEnumerable<IItem> items)
|
||||
private AbsolutePath? GetSelectedItemByItems(IReadOnlyCollection<IItem> items)
|
||||
{
|
||||
if (!items.Any()) return null;
|
||||
|
||||
@@ -109,7 +109,7 @@ public class Tab : ITab
|
||||
{
|
||||
var itemNameToSelect = LastDeepestSelectedPath.Path
|
||||
.Split(Constants.SeparatorChar)
|
||||
.Skip((parentPath?.Split(Constants.SeparatorChar).Length) ?? 0)
|
||||
.Skip(parentPath.Split(Constants.SeparatorChar).Length)
|
||||
.FirstOrDefault();
|
||||
|
||||
var itemToSelect = items.FirstOrDefault(i => i.FullName?.GetName() == itemNameToSelect);
|
||||
@@ -121,7 +121,7 @@ public class Tab : ITab
|
||||
}
|
||||
}
|
||||
|
||||
LastDeepestSelectedPath = new FullName(PathHelper.GetLongerPath(LastDeepestSelectedPath?.Path, newSelectedItem.Path.Path));
|
||||
LastDeepestSelectedPath = FullName.CreateSafe(PathHelper.GetLongerPath(LastDeepestSelectedPath?.Path, newSelectedItem.Path.Path));
|
||||
|
||||
return newSelectedItem;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user