1
1
// Copyright (c) 2023 Files Community
2
2
// Licensed under the MIT License. See the LICENSE.
3
3
4
- using CommunityToolkit . Mvvm . DependencyInjection ;
5
- using CommunityToolkit . Mvvm . Input ;
6
4
using CommunityToolkit . WinUI . UI ;
7
- using Files . App . Data . Commands ;
8
- using Files . App . Data . Items ;
9
- using Files . App . Data . Models ;
10
- using Files . App . Extensions ;
11
5
using Files . App . Helpers . ContextFlyouts ;
12
6
using Files . App . Services ;
13
- using Files . App . Utils . Shell ;
14
- using Files . App . ViewModels ;
15
7
using Files . App . ViewModels . Dialogs ;
16
- using Files . Core . Services ;
17
- using Files . Core . Services . Settings ;
18
- using Files . Shared . Extensions ;
8
+ using Files . Core . Storage ;
9
+ using Files . Core . Storage . Extensions ;
19
10
using Microsoft . UI . Input ;
20
11
using Microsoft . UI . Xaml ;
21
12
using Microsoft . UI . Xaml . Controls ;
22
13
using Microsoft . UI . Xaml . Controls . Primitives ;
23
14
using Microsoft . UI . Xaml . Input ;
24
- using System ;
25
- using System . Collections . Generic ;
26
- using System . ComponentModel ;
27
- using System . Linq ;
28
15
using System . Runtime . CompilerServices ;
29
- using System . Threading . Tasks ;
30
16
using System . Windows . Input ;
31
17
using Windows . ApplicationModel . DataTransfer ;
32
18
using Windows . ApplicationModel . DataTransfer . DragDrop ;
@@ -38,10 +24,16 @@ namespace Files.App.UserControls
38
24
{
39
25
public sealed partial class SidebarControl : NavigationView , INotifyPropertyChanged
40
26
{
41
- private readonly IUserSettingsService userSettingsService = Ioc . Default . GetRequiredService < IUserSettingsService > ( ) ;
42
- private readonly ICommandManager commands = Ioc . Default . GetRequiredService < ICommandManager > ( ) ;
27
+ private readonly IUserSettingsService userSettingsService ;
43
28
44
- public IQuickAccessService QuickAccessService { get ; } = Ioc . Default . GetRequiredService < IQuickAccessService > ( ) ;
29
+ private readonly ICommandManager commands ;
30
+
31
+ private readonly IFileTagsService _fileTagsService ;
32
+ public IQuickAccessService QuickAccessService { get ; }
33
+
34
+ public delegate void SelectedTagChangedEventHandler ( object sender , SelectedTagChangedEventArgs e ) ;
35
+
36
+ public static event SelectedTagChangedEventHandler ? SelectedTagChanged ;
45
37
46
38
public delegate void SidebarItemInvokedEventHandler ( object sender , SidebarItemInvokedEventArgs e ) ;
47
39
@@ -130,6 +122,11 @@ public UIElement TabContent
130
122
131
123
public SidebarControl ( )
132
124
{
125
+ userSettingsService = Ioc . Default . GetRequiredService < IUserSettingsService > ( ) ;
126
+ commands = Ioc . Default . GetRequiredService < ICommandManager > ( ) ;
127
+ _fileTagsService = Ioc . Default . GetRequiredService < IFileTagsService > ( ) ;
128
+ QuickAccessService = Ioc . Default . GetRequiredService < IQuickAccessService > ( ) ;
129
+
133
130
InitializeComponent ( ) ;
134
131
135
132
dragOverSectionTimer = DispatcherQueue . CreateTimer ( ) ;
@@ -190,6 +187,8 @@ private List<ContextMenuFlyoutItemViewModel> GetLocationItemMenuItems(INavigatio
190
187
var isDriveItem = item is DriveItem ;
191
188
var isDriveItemPinned = isDriveItem && ( ( DriveItem ) item ) . IsPinned ;
192
189
190
+ var isTagItem = item is FileTagItem ;
191
+
193
192
return new List < ContextMenuFlyoutItemViewModel > ( )
194
193
{
195
194
new ContextMenuFlyoutItemViewModel ( )
@@ -240,6 +239,10 @@ private List<ContextMenuFlyoutItemViewModel> GetLocationItemMenuItems(INavigatio
240
239
Command = OpenInNewPaneCommand ,
241
240
ShowItem = options . IsLocationItem && userSettingsService . GeneralSettingsService . ShowOpenInNewPane
242
241
} ,
242
+ new ContextMenuFlyoutItemViewModelBuilder ( commands . OpenAllTaggedItems )
243
+ {
244
+ IsVisible = isTagItem
245
+ } . Build ( ) ,
243
246
new ContextMenuFlyoutItemViewModel ( )
244
247
{
245
248
Text = "PinToFavorites" . GetLocalizedResource ( ) ,
@@ -456,14 +459,29 @@ private void PaneRoot_RightTapped(object sender, RightTappedRoutedEventArgs e)
456
459
e . Handled = true ;
457
460
}
458
461
459
- private void NavigationViewItem_RightTapped ( object sender , RightTappedRoutedEventArgs e )
462
+ private async void NavigationViewItem_RightTapped ( object sender , RightTappedRoutedEventArgs e )
460
463
{
461
464
var itemContextMenuFlyout = new CommandBarFlyout { Placement = FlyoutPlacementMode . Full } ;
462
465
itemContextMenuFlyout . Opening += ( sender , e ) => App . LastOpenedFlyout = sender as CommandBarFlyout ;
463
466
if ( sender is not NavigationViewItem sidebarItem ||
464
467
sidebarItem . DataContext is not INavigationControlItem item )
465
468
return ;
466
469
470
+ if ( item is FileTagItem tagItem )
471
+ {
472
+ var cts = new CancellationTokenSource ( ) ;
473
+ var items = new List < ( string path , bool isFolder ) > ( ) ;
474
+
475
+ await foreach ( var taggedItem in _fileTagsService . GetItemsForTagAsync ( tagItem . FileTag . Uid , cts . Token ) )
476
+ {
477
+ items . Add ( (
478
+ taggedItem . Storable . TryGetPath ( ) ?? string . Empty ,
479
+ taggedItem . Storable is IFolder ) ) ;
480
+ }
481
+
482
+ SelectedTagChanged ? . Invoke ( this , new SelectedTagChangedEventArgs ( items ) ) ;
483
+ }
484
+
467
485
rightClickedItem = item ;
468
486
469
487
var menuItems = GetLocationItemMenuItems ( item , itemContextMenuFlyout ) ;
@@ -626,7 +644,7 @@ private async void NavigationViewLocationItem_DragOver(object sender, DragEventA
626
644
}
627
645
CompleteDragEventArgs ( e , captionText , operationType ) ;
628
646
}
629
- }
647
+ }
630
648
631
649
deferral . Complete ( ) ;
632
650
}
@@ -665,7 +683,7 @@ private async void NavigationViewLocationItem_Drop(object sender, DragEventArgs
665
683
foreach ( var item in storageItems )
666
684
{
667
685
if ( item . ItemType == FilesystemItemType . Directory && ! SidebarPinnedModel . FavoriteItems . Contains ( item . Path ) )
668
- QuickAccessService . PinToSidebar ( item . Path ) ;
686
+ await QuickAccessService . PinToSidebar ( item . Path ) ;
669
687
}
670
688
}
671
689
else
0 commit comments