-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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: Added support for opening all tagged items from the Tags widget #12972
Changes from 7 commits
b6176dc
c322fbe
384c46c
5a8a5fc
66cbdcb
3c3fa51
7d58a3b
64bc94c
53c22bb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright (c) 2023 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 | ||
=> "OpenAllItems".GetLocalizedResource(); | ||
|
||
public string Description | ||
=> "OpenAllItemsDescription".GetLocalizedResource(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
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 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!))); | ||
|
||
folders.ForEach(async folder => await NavigationHelpers.OpenPathInNewTab(folder.Path)); | ||
} | ||
|
||
private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e) | ||
{ | ||
switch (e.PropertyName) | ||
{ | ||
case nameof(IContentPageContext.ShellPage): | ||
case nameof(ITagsContext.TaggedItems): | ||
OnPropertyChanged(nameof(IsExecutable)); | ||
break; | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -190,5 +190,8 @@ public enum CommandCodes | |
GitPull, | ||
GitPush, | ||
GitSync, | ||
|
||
// Tags | ||
OpenAllTaggedItems, | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// 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; } | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright (c) 2023 Files Community | ||
// Licensed under the MIT License. See the LICENSE. | ||
|
||
using Files.App.ViewModels.Widgets; | ||
using System.Collections.Immutable; | ||
|
||
namespace Files.App.Data.Contexts | ||
{ | ||
sealed class TagsContext : ITagsContext | ||
{ | ||
private static readonly IReadOnlyList<FileTagsItemViewModel> _emptyTaggedItemsList | ||
= Enumerable.Empty<FileTagsItemViewModel>().ToImmutableList(); | ||
|
||
public event PropertyChangedEventHandler? PropertyChanged; | ||
|
||
private IEnumerable<FileTagsItemViewModel> _TaggedItems = _emptyTaggedItemsList; | ||
public IEnumerable<FileTagsItemViewModel> TaggedItems | ||
{ | ||
get => _TaggedItems; | ||
set | ||
{ | ||
_TaggedItems = value is not null | ||
? value | ||
: _emptyTaggedItemsList; | ||
|
||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(TaggedItems))); | ||
} | ||
} | ||
|
||
public TagsContext() | ||
{ | ||
FileTagsContainerViewModel.SelectedTagsChanged += FileTagsContainerViewModel_SelectedTagsChanged; | ||
} | ||
|
||
private void FileTagsContainerViewModel_SelectedTagsChanged(object sender, IEnumerable<FileTagsItemViewModel> items) | ||
{ | ||
TaggedItems = items; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3398,4 +3398,10 @@ | |
<data name="OpenInNewWindowDescription" xml:space="preserve"> | ||
<value>Open directory in new window</value> | ||
</data> | ||
<data name="OpenAllItems" xml:space="preserve"> | ||
<value>Open all</value> | ||
</data> | ||
<data name="OpenAllItemsDescription" xml:space="preserve"> | ||
<value>Open all tagged items</value> | ||
</data> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
</root> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:helpers="using:Files.App.Helpers" | ||
xmlns:local="using:Files.App.UserControls.Widgets" | ||
xmlns:localcontrols="using:Files.App.UserControls" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:vm="using:Files.App.ViewModels.Widgets" | ||
d:DesignHeight="300" | ||
|
@@ -51,39 +52,44 @@ | |
</Grid.RowDefinitions> | ||
|
||
<!-- Title --> | ||
<Grid BorderBrush="{ThemeResource CardStrokeColorDefaultBrush}" BorderThickness="0,0,0,1"> | ||
<Grid | ||
Background="Transparent" | ||
BorderBrush="{ThemeResource CardStrokeColorDefaultBrush}" | ||
BorderThickness="0,0,0,1"> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="Auto" /> | ||
<ColumnDefinition Width="*" /> | ||
<ColumnDefinition Width="Auto" /> | ||
</Grid.ColumnDefinitions> | ||
|
||
<StackPanel | ||
Padding="12,8,12,8" | ||
Orientation="Horizontal" | ||
Spacing="8"> | ||
<!-- Tag Color --> | ||
<PathIcon Data="{StaticResource ColorIconFilledTag}" Foreground="{x:Bind Color, Mode=OneWay, Converter={StaticResource StringToBrushConverter}}" /> | ||
|
||
<!-- Tag Name --> | ||
<TextBlock | ||
Margin="0,-2,0,0" | ||
FontWeight="SemiBold" | ||
Text="{x:Bind Name, Mode=OneWay}" /> | ||
</StackPanel> | ||
|
||
<!-- View More --> | ||
<HyperlinkButton | ||
Grid.Column="2" | ||
Margin="4" | ||
AutomationProperties.Name="{helpers:ResourceString Name=ViewMore}" | ||
Command="{x:Bind ViewMoreCommand}" | ||
ToolTipService.ToolTip="{helpers:ResourceString Name=ViewMore}"> | ||
<HyperlinkButton.Content> | ||
<FontIcon | ||
FontSize="12" | ||
<StackPanel Orientation="Horizontal" Spacing="8"> | ||
<!-- Tag Color --> | ||
<PathIcon Data="{StaticResource ColorIconFilledTag}" Foreground="{x:Bind Color, Mode=OneWay, Converter={StaticResource StringToBrushConverter}}" /> | ||
|
||
<!-- Tag Name --> | ||
<TextBlock | ||
Margin="0,-2,0,0" | ||
FontWeight="SemiBold" | ||
Glyph="" /> | ||
Foreground="{ThemeResource TextFillColorPrimaryBrush}" | ||
Text="{x:Bind Name, Mode=OneWay}" /> | ||
</StackPanel> | ||
</HyperlinkButton> | ||
|
||
<!-- Open All Items --> | ||
<HyperlinkButton | ||
Grid.Column="2" | ||
Margin="4" | ||
AutomationProperties.Name="{helpers:ResourceString Name=OpenAllItems}" | ||
Command="{x:Bind OpenAllCommand}" | ||
ToolTipService.ToolTip="{helpers:ResourceString Name=OpenAllItems}"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the resources strings are indeed renamed as proposed, these entries will need to be renamed as well. |
||
<HyperlinkButton.Content> | ||
<localcontrols:OpacityIcon Style="{StaticResource ColorIconOpen}" /> | ||
</HyperlinkButton.Content> | ||
</HyperlinkButton> | ||
</Grid> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The label should be
OpenAllTaggedItems
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought this as well but then I realized this string might be useful outside of tags.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I revert it then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's fine either way