Skip to content

Feature: Added "open all" when right clicking a tag in the sidebar #12991

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Files.App/Actions/Content/Tags/OpenAllTaggedActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ public OpenAllTaggedActions()

public async Task ExecuteAsync()
{
var files = _tagsContext.TaggedItems.Where(item => !item.IsFolder);
var folders = _tagsContext.TaggedItems.Where(item => item.IsFolder);
var files = _tagsContext.TaggedItems.Where(item => !item.isFolder);
var folders = _tagsContext.TaggedItems.Where(item => item.isFolder);

await Task.WhenAll(files.Select(file
=> NavigationHelpers.OpenPath(file.Path, _pageContext.ShellPage!)));
=> NavigationHelpers.OpenPath(file.path, _pageContext.ShellPage!)));

folders.ForEach(async folder => await NavigationHelpers.OpenPathInNewTab(folder.Path));
folders.ForEach(async folder => await NavigationHelpers.OpenPathInNewTab(folder.path));
}

private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
Expand Down
4 changes: 1 addition & 3 deletions src/Files.App/Data/Contexts/Tags/ITagsContext.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.ViewModels.Widgets;

namespace Files.App.Data.Contexts
{
interface ITagsContext: INotifyPropertyChanged
{
IEnumerable<FileTagsItemViewModel> TaggedItems { get; }
IEnumerable<(string path, bool isFolder)> TaggedItems { get; }
}
}
15 changes: 8 additions & 7 deletions src/Files.App/Data/Contexts/Tags/TagsContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ namespace Files.App.Data.Contexts
{
sealed class TagsContext : ITagsContext
{
private static readonly IReadOnlyList<FileTagsItemViewModel> _emptyTaggedItemsList
= Enumerable.Empty<FileTagsItemViewModel>().ToImmutableList();
private static readonly IReadOnlyList<(string path, bool isFolder)> _emptyTaggedItemsList
= Enumerable.Empty<(string path, bool isFolder)>().ToImmutableList();

public event PropertyChangedEventHandler? PropertyChanged;

private IEnumerable<FileTagsItemViewModel> _TaggedItems = _emptyTaggedItemsList;
public IEnumerable<FileTagsItemViewModel> TaggedItems
private IEnumerable<(string path, bool isFolder)> _TaggedItems = _emptyTaggedItemsList;
public IEnumerable<(string path, bool isFolder)> TaggedItems
{
get => _TaggedItems;
set
Expand All @@ -29,12 +29,13 @@ public IEnumerable<FileTagsItemViewModel> TaggedItems

public TagsContext()
{
FileTagsContainerViewModel.SelectedTagsChanged += FileTagsContainerViewModel_SelectedTagsChanged;
FileTagsContainerViewModel.SelectedTagChanged += SelectedTagsChanged;
SidebarControl.SelectedTagChanged += SelectedTagsChanged;
}

private void FileTagsContainerViewModel_SelectedTagsChanged(object sender, IEnumerable<FileTagsItemViewModel> items)
private void SelectedTagsChanged(object _, SelectedTagChangedEventArgs e)
{
TaggedItems = items;
TaggedItems = e.Items;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

namespace Files.App.Data.EventArguments
{
public record SelectedTagChangedEventArgs(IEnumerable<(string path, bool isFolder)> Items);
}
62 changes: 40 additions & 22 deletions src/Files.App/UserControls/SidebarControl.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,32 +1,18 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using CommunityToolkit.Mvvm.DependencyInjection;
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.WinUI.UI;
using Files.App.Data.Commands;
using Files.App.Data.Items;
using Files.App.Data.Models;
using Files.App.Extensions;
using Files.App.Helpers.ContextFlyouts;
using Files.App.Services;
using Files.App.Utils.Shell;
using Files.App.ViewModels;
using Files.App.ViewModels.Dialogs;
using Files.Core.Services;
using Files.Core.Services.Settings;
using Files.Shared.Extensions;
using Files.Core.Storage;
using Files.Core.Storage.Extensions;
using Microsoft.UI.Input;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Input;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using System.Windows.Input;
using Windows.ApplicationModel.DataTransfer;
using Windows.ApplicationModel.DataTransfer.DragDrop;
Expand All @@ -38,10 +24,16 @@ namespace Files.App.UserControls
{
public sealed partial class SidebarControl : NavigationView, INotifyPropertyChanged
{
private readonly IUserSettingsService userSettingsService = Ioc.Default.GetRequiredService<IUserSettingsService>();
private readonly ICommandManager commands = Ioc.Default.GetRequiredService<ICommandManager>();
private readonly IUserSettingsService userSettingsService;

public IQuickAccessService QuickAccessService { get; } = Ioc.Default.GetRequiredService<IQuickAccessService>();
private readonly ICommandManager commands;

private readonly IFileTagsService _fileTagsService;
public IQuickAccessService QuickAccessService { get; }

public delegate void SelectedTagChangedEventHandler(object sender, SelectedTagChangedEventArgs e);

public static event SelectedTagChangedEventHandler? SelectedTagChanged;

public delegate void SidebarItemInvokedEventHandler(object sender, SidebarItemInvokedEventArgs e);

Expand Down Expand Up @@ -130,6 +122,11 @@ public UIElement TabContent

public SidebarControl()
{
userSettingsService = Ioc.Default.GetRequiredService<IUserSettingsService>();
commands = Ioc.Default.GetRequiredService<ICommandManager>();
_fileTagsService = Ioc.Default.GetRequiredService<IFileTagsService>();
QuickAccessService = Ioc.Default.GetRequiredService<IQuickAccessService>();

InitializeComponent();

dragOverSectionTimer = DispatcherQueue.CreateTimer();
Expand Down Expand Up @@ -190,6 +187,8 @@ private List<ContextMenuFlyoutItemViewModel> GetLocationItemMenuItems(INavigatio
var isDriveItem = item is DriveItem;
var isDriveItemPinned = isDriveItem && ((DriveItem)item).IsPinned;

var isTagItem = item is FileTagItem;

return new List<ContextMenuFlyoutItemViewModel>()
{
new ContextMenuFlyoutItemViewModel()
Expand Down Expand Up @@ -240,6 +239,10 @@ private List<ContextMenuFlyoutItemViewModel> GetLocationItemMenuItems(INavigatio
Command = OpenInNewPaneCommand,
ShowItem = options.IsLocationItem && userSettingsService.GeneralSettingsService.ShowOpenInNewPane
},
new ContextMenuFlyoutItemViewModelBuilder(commands.OpenAllTaggedItems)
{
IsVisible = isTagItem
}.Build(),
new ContextMenuFlyoutItemViewModel()
{
Text = "PinToFavorites".GetLocalizedResource(),
Expand Down Expand Up @@ -456,14 +459,29 @@ private void PaneRoot_RightTapped(object sender, RightTappedRoutedEventArgs e)
e.Handled = true;
}

private void NavigationViewItem_RightTapped(object sender, RightTappedRoutedEventArgs e)
private async void NavigationViewItem_RightTapped(object sender, RightTappedRoutedEventArgs e)
{
var itemContextMenuFlyout = new CommandBarFlyout { Placement = FlyoutPlacementMode.Full };
itemContextMenuFlyout.Opening += (sender, e) => App.LastOpenedFlyout = sender as CommandBarFlyout;
if (sender is not NavigationViewItem sidebarItem ||
sidebarItem.DataContext is not INavigationControlItem item)
return;

if (item is FileTagItem tagItem)
{
var cts = new CancellationTokenSource();
var items = new List<(string path, bool isFolder)>();

await foreach (var taggedItem in _fileTagsService.GetItemsForTagAsync(tagItem.FileTag.Uid, cts.Token))
{
items.Add((
taggedItem.Storable.TryGetPath() ?? string.Empty,
taggedItem.Storable is IFolder));
}

SelectedTagChanged?.Invoke(this, new SelectedTagChangedEventArgs(items));
}

rightClickedItem = item;

var menuItems = GetLocationItemMenuItems(item, itemContextMenuFlyout);
Expand Down Expand Up @@ -626,7 +644,7 @@ private async void NavigationViewLocationItem_DragOver(object sender, DragEventA
}
CompleteDragEventArgs(e, captionText, operationType);
}
}
}

deferral.Complete();
}
Expand Down Expand Up @@ -665,7 +683,7 @@ private async void NavigationViewLocationItem_Drop(object sender, DragEventArgs
foreach (var item in storageItems)
{
if (item.ItemType == FilesystemItemType.Directory && !SidebarPinnedModel.FavoriteItems.Contains(item.Path))
QuickAccessService.PinToSidebar(item.Path);
await QuickAccessService.PinToSidebar(item.Path);
}
}
else
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.Core.Services;
using Files.Core.Storage;
using Files.Shared.Utils;

namespace Files.App.ViewModels.Widgets
Expand All @@ -18,9 +18,9 @@ public sealed partial class FileTagsContainerViewModel : ObservableObject, IAsyn

private readonly ICommandManager _commands;

public delegate void SelectedTagsChangedEventHandler(object sender, IEnumerable<FileTagsItemViewModel> items);
public delegate void SelectedTagChangedEventHandler(object sender, SelectedTagChangedEventArgs e);

public static event SelectedTagsChangedEventHandler? SelectedTagsChanged;
public static event SelectedTagChangedEventHandler? SelectedTagChanged;

public ObservableCollection<FileTagsItemViewModel> Tags { get; }

Expand Down Expand Up @@ -60,7 +60,7 @@ private Task ViewMore(CancellationToken cancellationToken)
[RelayCommand]
private Task OpenAll(CancellationToken cancellationToken)
{
SelectedTagsChanged?.Invoke(this, Tags);
SelectedTagChanged?.Invoke(this, new SelectedTagChangedEventArgs(Tags.Select(tag => (tag.Path, tag.IsFolder))));

return _commands.OpenAllTaggedItems.ExecuteAsync();
}
Expand Down