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: Added properties option when right clicking recent files #11985

Merged
merged 1 commit into from
Apr 14, 2023
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
49 changes: 44 additions & 5 deletions src/Files.App/UserControls/Widgets/RecentFilesWidget.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using CommunityToolkit.WinUI;
using Files.App.Extensions;
using Files.App.Filesystem;
using Files.App.Filesystem.StorageEnumerators;
using Files.App.Filesystem.StorageItems;
using Files.App.Helpers;
using Files.App.Helpers.ContextFlyouts;
using Files.App.ViewModels;
Expand Down Expand Up @@ -84,6 +86,20 @@ internal set
}
}

private IShellPage associatedInstance;
public IShellPage AppInstance
{
get => associatedInstance;
set
{
if (value != associatedInstance)
{
associatedInstance = value;
NotifyPropertyChanged(nameof(AppInstance));
}
}
}

public RecentFilesWidget()
{
InitializeComponent();
Expand All @@ -99,12 +115,13 @@ public RecentFilesWidget()
RemoveRecentItemCommand = new RelayCommand<RecentItem>(RemoveRecentItem);
ClearAllItemsCommand = new RelayCommand(ClearRecentItems);
OpenFileLocationCommand = new RelayCommand<RecentItem>(OpenFileLocation);
OpenPropertiesCommand = new RelayCommand<RecentItem>(OpenProperties);
}

private void Grid_RightTapped(object sender, RightTappedRoutedEventArgs e)
{
var itemContextMenuFlyout = new CommandBarFlyout { Placement = FlyoutPlacementMode.Full };
itemContextMenuFlyout.Opening += (sender, e) => App.LastOpenedFlyout = sender as CommandBarFlyout;
ItemContextMenuFlyout = new CommandBarFlyout { Placement = FlyoutPlacementMode.Full };
ItemContextMenuFlyout.Opening += (sender, e) => App.LastOpenedFlyout = sender as CommandBarFlyout;
if (sender is not Grid recentItemsGrid || recentItemsGrid.DataContext is not RecentItem item)
return;

Expand All @@ -114,10 +131,10 @@ private void Grid_RightTapped(object sender, RightTappedRoutedEventArgs e)
secondaryElements.OfType<FrameworkElement>()
.ForEach(i => i.MinWidth = Constants.UI.ContextMenuItemsMaxWidth);

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

_ = ShellContextmenuHelper.LoadShellMenuItems(item.Path, itemContextMenuFlyout, showOpenWithMenu: true, showSendToMenu: true);
_ = ShellContextmenuHelper.LoadShellMenuItems(item.Path, ItemContextMenuFlyout, showOpenWithMenu: true, showSendToMenu: true);

e.Handled = true;
}
Expand Down Expand Up @@ -161,6 +178,16 @@ public override List<ContextMenuFlyoutItemViewModel> GetItemMenuItems(WidgetCard
CommandParameter = item
},
new ContextMenuFlyoutItemViewModel()
{
Text = "Properties".GetLocalizedResource(),
OpacityIcon = new OpacityIconModel()
{
OpacityIconStyle = "ColorIconProperties",
},
Command = OpenPropertiesCommand,
CommandParameter = item
},
new ContextMenuFlyoutItemViewModel()
{
ItemType = ItemType.Separator,
Tag = "OverflowSeparator",
Expand Down Expand Up @@ -201,6 +228,18 @@ private void OpenFileLocation(RecentItem item)
});
}

private void OpenProperties(RecentItem item)
{
EventHandler<object> flyoutClosed = null!;
flyoutClosed = async (s, e) =>
{
ItemContextMenuFlyout.Closed -= flyoutClosed;
var listedItem = await UniversalStorageEnumerator.AddFileAsync(await BaseStorageFile.GetFileFromPathAsync(item.Path), null, default);
await FilePropertiesHelpers.OpenPropertiesWindowAsync(listedItem, associatedInstance);
};
ItemContextMenuFlyout.Closed += flyoutClosed;
}

private async Task UpdateRecentsList(NotifyCollectionChangedEventArgs e)
{
try
Expand Down
1 change: 1 addition & 0 deletions src/Files.App/Views/HomePage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public void ReloadWidgets()
{
Widgets.ViewModel.InsertWidget(new(recentFilesWidget, (value) => UserSettingsService.PreferencesSettingsService.RecentFilesWidgetExpanded = value, () => UserSettingsService.PreferencesSettingsService.RecentFilesWidgetExpanded), 4);

recentFilesWidget.AppInstance = AppInstance;
Copy link
Member

Choose a reason for hiding this comment

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

This looks like the cause of #12160 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

I tested just after this PR was merged and the CPU usage is not high.
image

recentFilesWidget.RecentFilesOpenLocationInvoked -= WidgetOpenLocationInvoked;
recentFilesWidget.RecentFileInvoked -= RecentFilesWidget_RecentFileInvoked;
recentFilesWidget.RecentFilesOpenLocationInvoked += WidgetOpenLocationInvoked;
Expand Down