1
1
// Copyright (c) 2024 Files Community
2
2
// Licensed under the MIT License. See the LICENSE.
3
3
4
- using Windows . Storage ;
4
+ using System . Collections . Specialized ;
5
5
6
6
namespace Files . App . Actions
7
7
{
8
8
internal sealed class PinFolderToSidebarAction : ObservableObject , IAction
9
9
{
10
- private readonly IContentPageContext context ;
11
- private readonly IQuickAccessService service ;
10
+ private readonly IContentPageContext context = Ioc . Default . GetRequiredService < IContentPageContext > ( ) ;
11
+ private readonly IQuickAccessService service = Ioc . Default . GetRequiredService < IQuickAccessService > ( ) ;
12
12
13
13
public string Label
14
14
=> "PinFolderToSidebar" . GetLocalizedResource ( ) ;
@@ -24,30 +24,25 @@ public bool IsExecutable
24
24
25
25
public PinFolderToSidebarAction ( )
26
26
{
27
- context = Ioc . Default . GetRequiredService < IContentPageContext > ( ) ;
28
- service = Ioc . Default . GetRequiredService < IQuickAccessService > ( ) ;
29
-
30
27
context . PropertyChanged += Context_PropertyChanged ;
31
- App . QuickAccessManager . UpdateQuickAccessWidget += QuickAccessManager_DataChanged ;
28
+ service . PinnedFoldersChanged += QuickAccessService_CollectionChanged ;
32
29
}
33
30
34
31
public async Task ExecuteAsync ( object ? parameter = null )
35
32
{
36
- if ( context . HasSelection )
37
- {
38
- var items = context . SelectedItems . Select ( x => x . ItemPath ) . ToArray ( ) ;
33
+ var items = context . HasSelection
34
+ ? context . SelectedItems . Select ( x => x . ItemPath ) . ToArray ( )
35
+ : context . Folder is not null
36
+ ? [ context . Folder . ItemPath ]
37
+ : null ;
39
38
40
- await service . PinToSidebarAsync ( items ) ;
41
- }
42
- else if ( context . Folder is not null )
43
- {
44
- await service . PinToSidebarAsync ( context . Folder . ItemPath ) ;
45
- }
39
+ if ( items is not null )
40
+ await service . PinFolderAsync ( items ) ;
46
41
}
47
42
48
43
private bool GetIsExecutable ( )
49
44
{
50
- string [ ] pinnedFolders = [ .. App . QuickAccessManager . Model . PinnedFolders ] ;
45
+ string [ ] pinnedFolders = [ .. service . PinnedFolders . Select ( x => x . Path ) ] ;
51
46
52
47
return context . HasSelection
53
48
? context . SelectedItems . All ( IsPinnable )
@@ -56,7 +51,7 @@ private bool GetIsExecutable()
56
51
bool IsPinnable ( ListedItem item )
57
52
{
58
53
return
59
- item . PrimaryItemAttribute is StorageItemTypes . Folder &&
54
+ item . PrimaryItemAttribute is Windows . Storage . StorageItemTypes . Folder &&
60
55
! pinnedFolders . Contains ( item . ItemPath ) ;
61
56
}
62
57
}
@@ -72,7 +67,7 @@ private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
72
67
}
73
68
}
74
69
75
- private void QuickAccessManager_DataChanged ( object ? sender , ModifyQuickAccessEventArgs e )
70
+ private void QuickAccessService_CollectionChanged ( object ? sender , NotifyCollectionChangedEventArgs e )
76
71
{
77
72
OnPropertyChanged ( nameof ( IsExecutable ) ) ;
78
73
}
0 commit comments