From b1898e11201458420865a535b4d7522d1d71ad13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81d=C3=A1m=20Kov=C3=A1cs?= Date: Tue, 11 Jul 2023 16:32:04 +0200 Subject: [PATCH] Container refresh, delete multiple, preview fix --- ...temManipulationUserCommandHandlerService.cs | 4 ++++ .../ItemPreview/ElementPreviewViewModel.cs | 18 ++++++++++++++---- .../CreateContainer/CreateContainerCommand.cs | 9 ++++++++- .../CreateElement/CreateElementCommand.cs | 9 ++++++++- .../Delete/DeleteCommand.cs | 10 +++++++++- .../FileTime.Core.Command/Move/MoveCommand.cs | 3 +++ 6 files changed, 46 insertions(+), 7 deletions(-) diff --git a/src/AppCommon/FileTime.App.Core/Services/UserCommandHandler/ItemManipulationUserCommandHandlerService.cs b/src/AppCommon/FileTime.App.Core/Services/UserCommandHandler/ItemManipulationUserCommandHandlerService.cs index 66697f6..b8a4aa9 100644 --- a/src/AppCommon/FileTime.App.Core/Services/UserCommandHandler/ItemManipulationUserCommandHandlerService.cs +++ b/src/AppCommon/FileTime.App.Core/Services/UserCommandHandler/ItemManipulationUserCommandHandlerService.cs @@ -434,6 +434,10 @@ public class ItemManipulationUserCommandHandlerService : UserCommandHandlerServi shouldDelete = true; } } + else + { + shouldDelete = true; + } if (itemsToDelete.Count == 0) return; diff --git a/src/AppCommon/FileTime.App.Core/ViewModels/ItemPreview/ElementPreviewViewModel.cs b/src/AppCommon/FileTime.App.Core/ViewModels/ItemPreview/ElementPreviewViewModel.cs index 2544c51..96891f7 100644 --- a/src/AppCommon/FileTime.App.Core/ViewModels/ItemPreview/ElementPreviewViewModel.cs +++ b/src/AppCommon/FileTime.App.Core/ViewModels/ItemPreview/ElementPreviewViewModel.cs @@ -10,11 +10,11 @@ namespace FileTime.App.Core.ViewModels.ItemPreview; public partial class ElementPreviewViewModel : IItemPreviewViewModel, IAsyncInitable { 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; + } } } \ No newline at end of file diff --git a/src/Core/FileTime.Core.Command/CreateContainer/CreateContainerCommand.cs b/src/Core/FileTime.Core.Command/CreateContainer/CreateContainerCommand.cs index 443b10d..89a5afb 100644 --- a/src/Core/FileTime.Core.Command/CreateContainer/CreateContainerCommand.cs +++ b/src/Core/FileTime.Core.Command/CreateContainer/CreateContainerCommand.cs @@ -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); } } \ No newline at end of file diff --git a/src/Core/FileTime.Core.Command/CreateElement/CreateElementCommand.cs b/src/Core/FileTime.Core.Command/CreateElement/CreateElementCommand.cs index cebd9c8..c72c6a8 100644 --- a/src/Core/FileTime.Core.Command/CreateElement/CreateElementCommand.cs +++ b/src/Core/FileTime.Core.Command/CreateElement/CreateElementCommand.cs @@ -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); } } \ No newline at end of file diff --git a/src/Core/FileTime.Core.Command/Delete/DeleteCommand.cs b/src/Core/FileTime.Core.Command/Delete/DeleteCommand.cs index fdd43d7..5f1243a 100644 --- a/src/Core/FileTime.Core.Command/Delete/DeleteCommand.cs +++ b/src/Core/FileTime.Core.Command/Delete/DeleteCommand.cs @@ -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 ItemsToDelete { get; } = new(); public DeleteCommand( IContentAccessorFactory contentAccessorFactory, - ITimelessContentProvider timelessContentProvider) + ITimelessContentProvider timelessContentProvider, + ICommandSchedulerNotifier commandSchedulerNotifier) : base("Delete") { _contentAccessorFactory = contentAccessorFactory; _timelessContentProvider = timelessContentProvider; + _commandSchedulerNotifier = commandSchedulerNotifier; } public override Task 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!); diff --git a/src/Core/FileTime.Core.Command/Move/MoveCommand.cs b/src/Core/FileTime.Core.Command/Move/MoveCommand.cs index 4082920..f67d8a3 100644 --- a/src/Core/FileTime.Core.Command/Move/MoveCommand.cs +++ b/src/Core/FileTime.Core.Command/Move/MoveCommand.cs @@ -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)