Container refresh, delete multiple, preview fix

This commit is contained in:
2023-07-11 16:32:04 +02:00
parent ed5d5806ae
commit b1898e1120
6 changed files with 46 additions and 7 deletions

View File

@@ -434,6 +434,10 @@ public class ItemManipulationUserCommandHandlerService : UserCommandHandlerServi
shouldDelete = true;
}
}
else
{
shouldDelete = true;
}
if (itemsToDelete.Count == 0) return;

View File

@@ -10,11 +10,11 @@ namespace FileTime.App.Core.ViewModels.ItemPreview;
public partial class ElementPreviewViewModel : IItemPreviewViewModel, IAsyncInitable<IElement>
{
private const int MaxTextPreviewSize = 1024 * 1024;
public ItemPreviewMode Mode { get; private set; }
[Property] private string? _textContent;
public async Task InitAsync(IElement element)
{
try
@@ -23,9 +23,9 @@ public partial class ElementPreviewViewModel : IItemPreviewViewModel, IAsyncInit
TextContent = content is null
? "Could not read any data from file " + element.Name
: Encoding.UTF8.GetString(content);
: GetNormalizedText(Encoding.UTF8.GetString(content));
}
catch(Exception ex)
catch (Exception ex)
{
TextContent = $"Error while getting content of {element.FullName}. " + ex.ToString();
}
@@ -35,5 +35,15 @@ public partial class ElementPreviewViewModel : IItemPreviewViewModel, IAsyncInit
0 => ItemPreviewMode.Empty,
_ => ItemPreviewMode.Text
};
string GetNormalizedText(string text)
{
foreach (var c in text)
{
if (c < 32 && c != 9 && c != 10 && c != 13) return $"Binary data, contains '{(int) c}'";
}
return text;
}
}
}

View File

@@ -7,13 +7,20 @@ namespace FileTime.Core.Command.CreateContainer;
public class CreateContainerCommand : CreateItemBase
{
public CreateContainerCommand(ITimelessContentProvider timelessContentProvider, IContentAccessorFactory contentAccessorFactory)
private readonly ICommandSchedulerNotifier _commandSchedulerNotifier;
public CreateContainerCommand(
ITimelessContentProvider timelessContentProvider,
IContentAccessorFactory contentAccessorFactory,
ICommandSchedulerNotifier commandSchedulerNotifier)
: base(timelessContentProvider, contentAccessorFactory)
{
_commandSchedulerNotifier = commandSchedulerNotifier;
}
protected override async Task CreateItem(IItemCreator itemCreator, IItem resolvedParent)
{
await itemCreator.CreateContainerAsync(resolvedParent.Provider, Parent!.GetChild(NewItemName!));
await _commandSchedulerNotifier.RefreshContainer(Parent);
}
}

View File

@@ -7,13 +7,20 @@ namespace FileTime.Core.Command.CreateElement;
public class CreateElementCommand : CreateItemBase
{
public CreateElementCommand(ITimelessContentProvider timelessContentProvider, IContentAccessorFactory contentAccessorFactory)
private readonly ICommandSchedulerNotifier _commandSchedulerNotifier;
public CreateElementCommand(
ITimelessContentProvider timelessContentProvider,
IContentAccessorFactory contentAccessorFactory,
ICommandSchedulerNotifier commandSchedulerNotifier)
: base(timelessContentProvider, contentAccessorFactory)
{
_commandSchedulerNotifier = commandSchedulerNotifier;
}
protected override async Task CreateItem(IItemCreator itemCreator, IItem resolvedParent)
{
await itemCreator.CreateElementAsync(resolvedParent.Provider, Parent!.GetChild(NewItemName!));
await _commandSchedulerNotifier.RefreshContainer(Parent);
}
}

View File

@@ -8,16 +8,19 @@ public class DeleteCommand : CommandBase, IExecutableCommand
{
private readonly IContentAccessorFactory _contentAccessorFactory;
private readonly ITimelessContentProvider _timelessContentProvider;
private readonly ICommandSchedulerNotifier _commandSchedulerNotifier;
public bool HardDelete { get; set; }
public List<FullName> ItemsToDelete { get; } = new();
public DeleteCommand(
IContentAccessorFactory contentAccessorFactory,
ITimelessContentProvider timelessContentProvider)
ITimelessContentProvider timelessContentProvider,
ICommandSchedulerNotifier commandSchedulerNotifier)
: base("Delete")
{
_contentAccessorFactory = contentAccessorFactory;
_timelessContentProvider = timelessContentProvider;
_commandSchedulerNotifier = commandSchedulerNotifier;
}
public override Task<CanCommandRun> CanRun(PointInTime currentTime)
@@ -74,6 +77,11 @@ public class DeleteCommand : CommandBase, IExecutableCommand
itemDeleters,
deleteStrategy
);
if (container.FullName is not null)
{
await _commandSchedulerNotifier.RefreshContainer(container.FullName);
}
}
await itemDeleter.DeleteAsync(itemToDelete.Provider, itemToDelete.FullName!);

View File

@@ -67,6 +67,9 @@ public class MoveCommand : CommandBase, IExecutableCommand
var sourceItem = await _timelessContentProvider.GetItemByFullNameAsync(itemToMove.Source, PointInTime.Present);
var itemMover = GetOrAddItemMover(sourceItem.Provider);
// Note: this is currently used for rename, so Target will be always the source container too
// If this will be used for move between different containers, ContentProvider should be checked
// And it should fall back to a copy+delete if the content providers are different
await itemMover.RenameAsync(sourceItem.Provider, itemToMove.Source, itemToMove.Target);
if (itemToMove.Source.GetParent() is { } parent)