Skip to content
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

Feature: Option to open all items in a tag #11598

Closed
Show file tree
Hide file tree
Changes from 4 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
3 changes: 3 additions & 0 deletions src/Files.App/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -2604,4 +2604,7 @@
<data name="MultiSelect" xml:space="preserve">
<value>Multiselect</value>
</data>
<data name="OpenAllItems" xml:space="preserve">
<value>Open all items</value>
</data>
QuaintMako marked this conversation as resolved.
Show resolved Hide resolved
</root>
30 changes: 21 additions & 9 deletions src/Files.App/UserControls/Widgets/FileTagsWidget.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,29 @@
</Grid.RowDefinitions>

<!-- Title -->
<StackPanel
<Grid
Grid.Row="0"
Padding="12,8"
BorderBrush="{ThemeResource CardStrokeColorDefaultBrush}"
BorderThickness="0,0,0,1"
Orientation="Horizontal"
Spacing="8">
ColumnSpacing="8"
RightTapped="TagTitle_RightTapped">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>

<Ellipse
Width="12"
Height="12"
Fill="{x:Bind Color, Mode=OneWay, Converter={StaticResource StringToBrushConverter}}" />
<TextBlock
Grid.Column="1"
Margin="0,-2,0,0"
HorizontalAlignment="Stretch"
FontWeight="SemiBold"
Text="{x:Bind Name, Mode=OneWay}" />
</StackPanel>
</Grid>

<!-- Contents -->
<controls:AdaptiveGridView
Expand All @@ -89,11 +96,15 @@

<controls:AdaptiveGridView.ItemTemplate>
<DataTemplate x:DataType="vm:FileTagsItemViewModel">
<StackPanel
<Grid
ColumnSpacing="8"
DataContext="{x:Bind}"
Orientation="Horizontal"
RightTapped="Item_RightTapped"
Spacing="8">
RightTapped="Item_RightTapped">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>

<!-- Icon -->
<Image
Width="20"
Expand All @@ -103,10 +114,11 @@

<!-- Name -->
<TextBlock
Grid.Column="1"
VerticalAlignment="Center"
Text="{x:Bind Name, Mode=OneWay}"
TextTrimming="CharacterEllipsis" />
</StackPanel>
</Grid>
</DataTemplate>
</controls:AdaptiveGridView.ItemTemplate>
</controls:AdaptiveGridView>
Expand Down
86 changes: 73 additions & 13 deletions src/Files.App/UserControls/Widgets/FileTagsWidget.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
using CommunityToolkit.Mvvm.DependencyInjection;
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.WinUI.UI;
using CommunityToolkit.WinUI.UI.Controls;
using Files.App.Extensions;
using Files.App.Filesystem;
using Files.App.Helpers;
using Files.App.Helpers.ContextFlyouts;
using Files.App.ViewModels;
using Files.App.ViewModels.Widgets;
using Files.App.Views;
using Files.Backend.Services.Settings;
using Files.Shared.Extensions;
using Microsoft.UI.Input;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
Expand All @@ -22,8 +20,6 @@
using System.Threading.Tasks;
using System.Windows.Input;
using Windows.Storage;
using Windows.System;
using Windows.UI.Core;

// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236

Expand Down Expand Up @@ -62,6 +58,8 @@ public FileTagsWidgetViewModel ViewModel

private ICommand OpenInNewPaneCommand;

private ICommand OpenAllItems;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this could be moved to a rich command directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cinqmilleans can you check if I implemented the RichCommand properly?


public FileTagsWidget()
{
InitializeComponent();
Expand All @@ -76,6 +74,7 @@ public FileTagsWidget()
PinToFavoritesCommand = new RelayCommand<WidgetCardItem>(PinToFavorites);
UnpinFromFavoritesCommand = new RelayCommand<WidgetCardItem>(UnpinFromFavorites);
OpenPropertiesCommand = new RelayCommand<WidgetCardItem>(OpenProperties);
OpenAllItems = new RelayCommand<IEnumerable<FileTagsItemViewModel>>(OpenAllTaggedItems);
}

private void OpenProperties(WidgetCardItem? item)
Expand Down Expand Up @@ -110,16 +109,48 @@ private async void FileTagItem_ItemClick(object sender, ItemClickEventArgs e)
await itemViewModel.ClickCommand.ExecuteAsync(null);
}

private async void Item_RightTapped(object sender, RightTappedRoutedEventArgs e)
private void TagTitle_RightTapped(object sender, RightTappedRoutedEventArgs e)
{
App.Logger.Warn("rightTapped");
if (sender is not Grid grid || grid.Parent is not Grid parent)
return;

LoadContextMenuItem(parent, e, true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to create the menu in xaml?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, anyway I'll mark this as Draft and I'll change this once we have a final context, to avoid working twice

}

private void Item_RightTapped(object sender, RightTappedRoutedEventArgs e)
{
if (sender is not Grid tagsItemsGrid)
return;

LoadContextMenuItem(tagsItemsGrid, e);
}

private async void LoadContextMenuItem(Grid contextGrid, RightTappedRoutedEventArgs e, bool isWidgetMenu = false)
{
List<ContextMenuFlyoutItemViewModel> menuItems;
FileTagsItemViewModel? selectedItem = null;

if (isWidgetMenu)
{
if (contextGrid.Children[1] is not AdaptiveGridView gridView)
return;

var items = gridView.Items.Select(item => (FileTagsItemViewModel)item);
menuItems = GetWidgetMenuItems(items);
}
else
{
if (contextGrid.DataContext is not FileTagsItemViewModel item)
return;

selectedItem = item;
menuItems = GetItemMenuItems(item, QuickAccessService.IsItemPinned(item.Path), item.IsFolder);
}


var itemContextMenuFlyout = new CommandBarFlyout { Placement = FlyoutPlacementMode.Full };
itemContextMenuFlyout.Opening += (sender, e) => App.LastOpenedFlyout = sender as CommandBarFlyout;
if (sender is not StackPanel tagsItemsStackPanel || tagsItemsStackPanel.DataContext is not FileTagsItemViewModel item)
return;

App.Logger.Warn("Item path: " + item.Path + " widgetcarditem.path = " + (item as WidgetCardItem)?.Path);
var menuItems = GetItemMenuItems(item, QuickAccessService.IsItemPinned(item.Path), item.IsFolder);
var (_, secondaryElements) = ItemModelListToContextFlyoutHelper.GetAppBarItemsFromModel(menuItems);

if (!UserSettingsService.PreferencesSettingsService.MoveShellExtensionsToSubMenu)
Expand All @@ -128,9 +159,11 @@ private async void Item_RightTapped(object sender, RightTappedRoutedEventArgs e)

secondaryElements.ForEach(i => itemContextMenuFlyout.SecondaryCommands.Add(i));
ItemContextMenuFlyout = itemContextMenuFlyout;
itemContextMenuFlyout.ShowAt(tagsItemsStackPanel, new FlyoutShowOptions { Position = e.GetPosition(tagsItemsStackPanel) });
itemContextMenuFlyout.ShowAt(contextGrid, new FlyoutShowOptions { Position = e.GetPosition(contextGrid) });

if (selectedItem is not null)
await ShellContextmenuHelper.LoadShellMenuItems(selectedItem.Path, itemContextMenuFlyout, showOpenWithMenu: true, showSendToMenu: true);

await ShellContextmenuHelper.LoadShellMenuItems(item.Path, itemContextMenuFlyout, showOpenWithMenu: true, showSendToMenu: true);
e.Handled = true;
}

Expand Down Expand Up @@ -240,6 +273,24 @@ public override List<ContextMenuFlyoutItemViewModel> GetItemMenuItems(WidgetCard
}.Where(x => x.ShowItem).ToList();
}

public List<ContextMenuFlyoutItemViewModel> GetWidgetMenuItems(IEnumerable<FileTagsItemViewModel> items)
{
return new List<ContextMenuFlyoutItemViewModel>()
{
new ContextMenuFlyoutItemViewModel()
{
Text = "OpenAllItems".GetLocalizedResource(),
Glyph = "\uE8E5",
//OpacityIcon = new OpacityIconModel()
//{
// OpacityIconStyle = "ColorIconOpenWith"
//},
Command = OpenAllItems,
CommandParameter = items
}
};
}

public void OpenFileLocation(WidgetCardItem? item)
{
FileTagsOpenLocationInvoked?.Invoke(this, new PathNavigationEventArgs()
Expand All @@ -249,6 +300,15 @@ public void OpenFileLocation(WidgetCardItem? item)
});
}

private async void OpenAllTaggedItems(IEnumerable<FileTagsItemViewModel> items)
{
var files = items.Where(taggedItem => !taggedItem.IsFolder);
var folders = items.Where(taggedItem => taggedItem.IsFolder);

await Task.WhenAll(files.Select(file => file.ClickCommand.ExecuteAsync(null)));
folders.ForEach(folder => OpenInNewTab(folder));
}

public Task RefreshWidget()
{
return Task.CompletedTask;
Expand Down