Repository navigation
Expand file tree
/
Copy pathCompressionUserCommandHandler.cs
More file actions
73 lines (63 loc) · 2.29 KB
/
Copy pathCompressionUserCommandHandler.cs
File metadata and controls
73 lines (63 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System.Collections.ObjectModel;
using DeclarativeProperty;
using FileTime.App.Core.Services;
using FileTime.App.Core.Services.UserCommandHandler;
using FileTime.App.Core.ViewModels;
using FileTime.Core.Models;
using FileTime.Tools.Compression.Compress;
using FileTime.Tools.Compression.Decompress;
namespace FileTime.Tools.Compression;
public class CompressionUserCommandHandler : AggregatedUserCommandHandler
{
private readonly IClipboardService _clipboardService;
private readonly IDeclarativeProperty<ObservableCollection<FullName>?> _markedItems;
private readonly IDeclarativeProperty<IItemViewModel?> _selectedItem;
public CompressionUserCommandHandler(
IAppState appState,
IClipboardService clipboardService)
{
_clipboardService = clipboardService;
_markedItems = appState.SelectedTab.Map(t => t?.MarkedItems)!.Switch();
_selectedItem = appState.SelectedTab.Map(t => t?.CurrentSelectedItem).Switch();
AddCommandHandler(new IUserCommandHandler[]
{
new TypeUserCommandHandler<CompressUserCommand>(Compress),
new TypeUserCommandHandler<DecompressUserCommand>(Decompress)
});
}
private Task Decompress()
{
_clipboardService.Clear();
_clipboardService.SetCommand<DecompressCommandFactory>();
if (_markedItems.Value is {Count: > 0} markedItems)
{
foreach (var markedItem in markedItems)
{
_clipboardService.AddContent(markedItem);
}
}
else if (_selectedItem.Value?.BaseItem?.FullName is { } fullname)
{
//TODO: check if file is decompressable
_clipboardService.AddContent(fullname);
}
return Task.CompletedTask;
}
private Task Compress()
{
_clipboardService.Clear();
_clipboardService.SetCommand<CompressCommandFactory>();
if (_markedItems.Value is {Count: > 0} markedItems)
{
foreach (var markedItem in markedItems)
{
_clipboardService.AddContent(markedItem);
}
}
else if (_selectedItem.Value?.BaseItem?.FullName is { } fullname)
{
_clipboardService.AddContent(fullname);
}
return Task.CompletedTask;
}
}