diff --git a/src/Files.App/UserControls/Widgets/RecentFilesWidget.xaml.cs b/src/Files.App/UserControls/Widgets/RecentFilesWidget.xaml.cs index a31639c4d49c..37b33b038968 100644 --- a/src/Files.App/UserControls/Widgets/RecentFilesWidget.xaml.cs +++ b/src/Files.App/UserControls/Widgets/RecentFilesWidget.xaml.cs @@ -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; @@ -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(); @@ -99,12 +115,13 @@ public RecentFilesWidget() RemoveRecentItemCommand = new RelayCommand(RemoveRecentItem); ClearAllItemsCommand = new RelayCommand(ClearRecentItems); OpenFileLocationCommand = new RelayCommand(OpenFileLocation); + OpenPropertiesCommand = new RelayCommand(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; @@ -114,10 +131,10 @@ private void Grid_RightTapped(object sender, RightTappedRoutedEventArgs e) secondaryElements.OfType() .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; } @@ -161,6 +178,16 @@ public override List 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", @@ -201,6 +228,18 @@ private void OpenFileLocation(RecentItem item) }); } + private void OpenProperties(RecentItem item) + { + EventHandler 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 diff --git a/src/Files.App/Views/HomePage.xaml.cs b/src/Files.App/Views/HomePage.xaml.cs index d8d4b70d3f08..54edd010b3f0 100644 --- a/src/Files.App/Views/HomePage.xaml.cs +++ b/src/Files.App/Views/HomePage.xaml.cs @@ -121,6 +121,7 @@ public void ReloadWidgets() { Widgets.ViewModel.InsertWidget(new(recentFilesWidget, (value) => UserSettingsService.PreferencesSettingsService.RecentFilesWidgetExpanded = value, () => UserSettingsService.PreferencesSettingsService.RecentFilesWidgetExpanded), 4); + recentFilesWidget.AppInstance = AppInstance; recentFilesWidget.RecentFilesOpenLocationInvoked -= WidgetOpenLocationInvoked; recentFilesWidget.RecentFileInvoked -= RecentFilesWidget_RecentFileInvoked; recentFilesWidget.RecentFilesOpenLocationInvoked += WidgetOpenLocationInvoked;