forked from files-community/Files
/
OpenAllTaggedActions.cs
64 lines (51 loc) · 1.66 KB
/
OpenAllTaggedActions.cs
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
// Copyright (c) 2024 Files Community
// Licensed under the MIT License. See the LICENSE.
namespace Files.App.Actions
{
sealed class OpenAllTaggedActions: ObservableObject, IAction
{
private readonly IContentPageContext _pageContext;
private readonly ITagsContext _tagsContext;
public string Label
=> "OpenAllTaggedItems".GetLocalizedResource();
public string Description
=> "OpenAllTaggedItemsDescription".GetLocalizedResource();
public RichGlyph Glyph
=> new("\uE71D");
public bool IsExecutable =>
_pageContext.ShellPage is not null &&
_tagsContext.TaggedItems.Any();
public OpenAllTaggedActions()
{
_pageContext = Ioc.Default.GetRequiredService<IContentPageContext>();
_tagsContext = Ioc.Default.GetRequiredService<ITagsContext>();
_pageContext.PropertyChanged += Context_PropertyChanged;
_tagsContext.PropertyChanged += Context_PropertyChanged;
}
public async Task ExecuteAsync()
{
var filePaths = _tagsContext.TaggedItems
.Where(item => !item.isFolder)
.Select(f => f.path)
.ToList();
var folderPaths = _tagsContext
.TaggedItems
.Where(item => item.isFolder)
.Select(f => f.path)
.ToList();
await Task.WhenAll(filePaths.Select(path => NavigationHelpers.OpenPath(path, _pageContext.ShellPage!)));
foreach (var path in folderPaths)
await NavigationHelpers.OpenPathInNewTab(path, false);
}
private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case nameof(IContentPageContext.ShellPage):
case nameof(ITagsContext.TaggedItems):
OnPropertyChanged(nameof(IsExecutable));
break;
}
}
}
}