/
githubmirror
/
Files
Обзор
Документация
Войти
/
githubmirror
/
Files
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/Files.App/UserControls/Pane/ShelfPane.xaml.cs
206 строк
6 KB
yair100
Fix: Fixed issue where no error was displayed when opening corrupted exe (#18721)
15 июл 2026, 23:06
Не верифицирован
15 июл 2026, 23:06
8674d76
Код
Авторство
О чём код?
// Copyright (c) Files Community // Licensed under the MIT License. using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using System.Windows.Input; using Vanara.PInvoke; using Vanara.Windows.Shell; using Windows.ApplicationModel.DataTransfer; using Microsoft.UI.Xaml.Input; using WinRT; using DragEventArgs = Microsoft.UI.Xaml.DragEventArgs; using Visibility = Microsoft.UI.Xaml.Visibility; namespace Files.App.UserControls { public sealed partial class ShelfPane : UserControl { public ICommandManager Commands { get; } = Ioc.Default.GetRequiredService<ICommandManager>(); public ShelfPane() { InitializeComponent(); Unloaded += ShelfPane_Unloaded; } private void Shelf_DragOver(object sender, DragEventArgs e) { if (!FilesystemHelpers.HasDraggedStorageItems(e.DataView)) return; e.Handled = true; e.DragUIOverride.Caption = Strings.AddToShelf.GetLocalizedResource(); e.AcceptedOperation = DataPackageOperation.Link; } private async void Shelf_Drop(object sender, DragEventArgs e) { if (ItemsSource is null) return; // Get items var storageService = Ioc.Default.GetRequiredService<IStorageService>(); var storageItems = (await FilesystemHelpers.GetDraggedStorageItems(e.DataView)).ToArray(); // Add to list foreach (var item in storageItems) { // Avoid adding duplicates if (ItemsSource.Any(x => x.Inner.Id == item.Path)) continue; var storable = item switch { StorageFileWithPath => (IStorableChild?)await storageService.TryGetFileAsync(item.Path), StorageFolderWithPath => (IStorableChild?)await storageService.TryGetFolderAsync(item.Path), _ => null }; if (storable is null) continue; var shelfItem = new ShelfItem(storable, ItemsSource); _ = shelfItem.InitAsync(); ItemsSource.Add(shelfItem); } } private void ListView_DragItemsStarting(object sender, DragItemsStartingEventArgs e) { var apidl = SafetyExtensions.IgnoreExceptions(() => e.Items .Cast<ShelfItem>() .Select(x => new ShellItem(x.Inner.Id).PIDL) .ToArray()); if (apidl is null) return; if (!Shell32.SHGetDesktopFolder(out var pDesktop).Succeeded) return; if (!Shell32.SHGetIDListFromObject(pDesktop, out var pDesktopPidl).Succeeded) return; e.Data.Properties["Files_ActionBinder"] = "Files_ShelfBinder"; if (!Shell32.SHCreateDataObject(pDesktopPidl, apidl, null, out var ppDataObject).Succeeded) return; var dataObjectProvider = e.Data.As<Shell32.IDataObjectProvider>(); dataObjectProvider.SetDataObject(ppDataObject); } private void ShelfItemsList_RightTapped(object sender, Microsoft.UI.Xaml.Input.RightTappedRoutedEventArgs e) { if (e.OriginalSource is not Microsoft.UI.Xaml.FrameworkElement { DataContext: ShelfItem item } widgetCardItem || item.Path is null) return; // If the right-clicked item isn't already part of the selection, select just it if (!ShelfItemsList.SelectedItems.Contains(item)) ShelfItemsList.SelectedItem = item; var menuFlyout = new MenuFlyout { Placement = Microsoft.UI.Xaml.Controls.Primitives.FlyoutPlacementMode.Bottom }; // Batch actions (operate on the current shelf selection via IShelfContext) menuFlyout.Items.Add(new MenuFlyoutItemWithThemedIcon { Text = Commands.CopyItemFromShelf.Label, Command = Commands.CopyItemFromShelf, ThemedIconStyle = Commands.CopyItemFromShelf.ThemedIconStyle }); menuFlyout.Items.Add(new MenuFlyoutItemWithThemedIcon { Text = Commands.CutItemFromShelf.Label, Command = Commands.CutItemFromShelf, ThemedIconStyle = Commands.CutItemFromShelf.ThemedIconStyle }); menuFlyout.Items.Add(new MenuFlyoutItemWithThemedIcon { Text = Commands.DeleteItemFromShelf.Label, Command = Commands.DeleteItemFromShelf, ThemedIconStyle = Commands.DeleteItemFromShelf.ThemedIconStyle }); menuFlyout.Items.Add(new MenuFlyoutSeparator()); // Per-item actions if (ShelfItemsList.SelectedItems.Count is 1) { menuFlyout.Items.Add(new MenuFlyoutItem { Text = Strings.BaseLayoutItemContextFlyoutOpenParentFolderText.GetLocalizedResource(), Icon = new FontIcon() { Glyph = "\uE838" }, Command = item.ViewInFolderCommand }); } menuFlyout.Items.Add(new MenuFlyoutItem { Text = Strings.RemoveFromShelf.GetLocalizedResource(), Icon = new FontIcon { Glyph = "\uE738" }, Command = item.RemoveCommand }); menuFlyout.ShowAt(widgetCardItem); e.Handled = true; } private void ShelfItemsList_GotFocus(object sender, RoutedEventArgs e) { ItemFocusedCommand?.Execute(null); } private void HyperlinkBatch_Click(object sender, RoutedEventArgs e) { if (sender is not FrameworkElement element) return; BatchFlyout.ShowAt(element); } private void ShelfItemsList_SelectionChanged(object sender, SelectionChangedEventArgs e) { var selected = ShelfItemsList.SelectedItems.OfType<ShelfItem>().ToArray(); BatchActionsButton.Visibility = selected.Length is 0 ? Visibility.Collapsed : Visibility.Visible; ShelfViewModel.RaiseSelectedItemsChanged(selected); } private void Pane_Tapped(object sender, TappedRoutedEventArgs e) { ShelfItemsList.SelectedItems.Clear(); } private void ShelfPane_Unloaded(object sender, RoutedEventArgs e) { // Drop the shelf context's selection so actions don't operate on stale items ShelfViewModel.RaiseSelectedItemsChanged([]); } public ObservableCollection<ShelfItem>? ItemsSource { get => (ObservableCollection<ShelfItem>?)GetValue(ItemsSourceProperty); set => SetValue(ItemsSourceProperty, value); } public static readonly DependencyProperty ItemsSourceProperty = DependencyProperty.Register(nameof(ItemsSource), typeof(ObservableCollection<ShelfItem>), typeof(ShelfPane), new PropertyMetadata(null)); public ICommand? ClearCommand { get => (ICommand?)GetValue(ClearCommandProperty); set => SetValue(ClearCommandProperty, value); } public static readonly DependencyProperty ClearCommandProperty = DependencyProperty.Register(nameof(ClearCommand), typeof(ICommand), typeof(ShelfPane), new PropertyMetadata(null)); public ICommand? ItemFocusedCommand { get => (ICommand?)GetValue(ItemFocusedCommandProperty); set => SetValue(ItemFocusedCommandProperty, value); } public static readonly DependencyProperty ItemFocusedCommandProperty = DependencyProperty.Register(nameof(ItemFocusedCommand), typeof(ICommand), typeof(ShelfPane), new PropertyMetadata(null)); } }