diff --git a/src/Files.App/Actions/FileSystem/CopyPathAction.cs b/src/Files.App/Actions/FileSystem/CopyPathAction.cs new file mode 100644 index 000000000000..891309008275 --- /dev/null +++ b/src/Files.App/Actions/FileSystem/CopyPathAction.cs @@ -0,0 +1,43 @@ +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.DependencyInjection; +using Files.App.Commands; +using Files.App.Contexts; +using Files.App.Extensions; +using Files.App.Helpers; +using System; +using System.Threading.Tasks; +using Windows.ApplicationModel.DataTransfer; +using Windows.System; + +namespace Files.App.Actions +{ + internal class CopyPathAction : IAction + { + private readonly IContentPageContext context = Ioc.Default.GetRequiredService(); + + public string Label { get; } = "CopyLocation".GetLocalizedResource(); + + public RichGlyph Glyph { get; } = new RichGlyph(opacityStyle: "ColorIconCopyLocation"); + + public HotKey HotKey { get; } = new(VirtualKey.C, VirtualKeyModifiers.Control | VirtualKeyModifiers.Shift); + + public async Task ExecuteAsync() + { + if (context.ShellPage?.SlimContentPage is not null) + { + var path = context.ShellPage.SlimContentPage.SelectedItem is not null + ? context.ShellPage.SlimContentPage.SelectedItem.ItemPath + : context.ShellPage.FilesystemViewModel.WorkingDirectory; + + if (FtpHelpers.IsFtpPath(path)) + path = path.Replace("\\", "/", StringComparison.Ordinal); + + DataPackage data = new(); + data.SetText(path); + + Clipboard.SetContent(data); + Clipboard.Flush(); + } + } + } +} diff --git a/src/Files.App/Commands/CommandCodes.cs b/src/Files.App/Commands/CommandCodes.cs index 7aee0fa2d03b..a78513bd7517 100644 --- a/src/Files.App/Commands/CommandCodes.cs +++ b/src/Files.App/Commands/CommandCodes.cs @@ -15,6 +15,7 @@ public enum CommandCodes // File System CopyItem, + CopyPath, CutItem, PasteItem, PasteItemToSelection, diff --git a/src/Files.App/Commands/Manager/CommandManager.cs b/src/Files.App/Commands/Manager/CommandManager.cs index f9bba07ace6b..e0f895459b89 100644 --- a/src/Files.App/Commands/Manager/CommandManager.cs +++ b/src/Files.App/Commands/Manager/CommandManager.cs @@ -51,6 +51,7 @@ internal class CommandManager : ICommandManager public IRichCommand SetAsSlideshowBackground => commands[CommandCodes.SetAsSlideshowBackground]; public IRichCommand SetAsLockscreenBackground => commands[CommandCodes.SetAsLockscreenBackground]; public IRichCommand CopyItem => commands[CommandCodes.CopyItem]; + public IRichCommand CopyPath => commands[CommandCodes.CopyPath]; public IRichCommand CutItem => commands[CommandCodes.CutItem]; public IRichCommand PasteItem => commands[CommandCodes.PasteItem]; public IRichCommand PasteItemToSelection => commands[CommandCodes.PasteItemToSelection]; @@ -154,6 +155,7 @@ public CommandManager() [CommandCodes.SetAsSlideshowBackground] = new SetAsSlideshowBackgroundAction(), [CommandCodes.SetAsLockscreenBackground] = new SetAsLockscreenBackgroundAction(), [CommandCodes.CopyItem] = new CopyItemAction(), + [CommandCodes.CopyPath] = new CopyPathAction(), [CommandCodes.CutItem] = new CutItemAction(), [CommandCodes.PasteItem] = new PasteItemAction(), [CommandCodes.PasteItemToSelection] = new PasteItemToSelectionAction(), diff --git a/src/Files.App/Commands/Manager/ICommandManager.cs b/src/Files.App/Commands/Manager/ICommandManager.cs index 26918cb0b1e6..e8fef4a9e279 100644 --- a/src/Files.App/Commands/Manager/ICommandManager.cs +++ b/src/Files.App/Commands/Manager/ICommandManager.cs @@ -18,6 +18,7 @@ public interface ICommandManager : IEnumerable IRichCommand TogglePreviewPane { get; } IRichCommand CopyItem { get; } + IRichCommand CopyPath { get; } IRichCommand CutItem { get; } IRichCommand PasteItem { get; } IRichCommand PasteItemToSelection { get; } diff --git a/src/Files.App/Helpers/ContextFlyoutItemHelper.cs b/src/Files.App/Helpers/ContextFlyoutItemHelper.cs index f0a14c1d954b..0042979d84b4 100644 --- a/src/Files.App/Helpers/ContextFlyoutItemHelper.cs +++ b/src/Files.App/Helpers/ContextFlyoutItemHelper.cs @@ -391,20 +391,10 @@ public static List GetBaseItemMenuItems( IsPrimary = true, IsVisible = true, }.Build(), - new ContextMenuFlyoutItemViewModel() + new ContextMenuFlyoutItemViewModelBuilder(commands.CopyPath) { - Text = "CopyLocation".GetLocalizedResource(), - OpacityIcon = new OpacityIconModel() - { - OpacityIconStyle = "ColorIconCopyLocation", - }, - Command = commandsViewModel.CopyPathOfSelectedItemCommand, - SingleItemOnly = true, - ShowInSearchPage = true, - ShowInFtpPage = true, - ShowInZipPage = true, - ShowItem = itemsSelected - }, + IsVisible = itemsSelected && selectedItems.Count == 1 && !currentInstanceViewModel.IsPageTypeRecycleBin, + }.Build(), new ContextMenuFlyoutItemViewModel() { Text = "BaseLayoutItemContextFlyoutCreateFolderWithSelection/Text".GetLocalizedResource(), diff --git a/src/Files.App/Interacts/BaseLayoutCommandImplementationModel.cs b/src/Files.App/Interacts/BaseLayoutCommandImplementationModel.cs index 8516788330a1..52d0dccb4f01 100644 --- a/src/Files.App/Interacts/BaseLayoutCommandImplementationModel.cs +++ b/src/Files.App/Interacts/BaseLayoutCommandImplementationModel.cs @@ -2,7 +2,6 @@ using CommunityToolkit.Mvvm.DependencyInjection; using CommunityToolkit.WinUI; -using Files.App.Dialogs; using Files.App.Extensions; using Files.App.Filesystem; using Files.App.Filesystem.StorageItems; @@ -10,21 +9,16 @@ using Files.App.ServicesImplementation; using Files.App.Shell; using Files.App.ViewModels; -using Files.App.ViewModels.Dialogs; using Files.App.Views; using Files.Backend.Enums; using Files.Shared; using Files.Shared.Enums; using Microsoft.UI.Xaml; -using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Input; using System; using System.Collections.Generic; -using System.Diagnostics; using System.IO; using System.Linq; -using System.Text; -using System.Threading; using System.Threading.Tasks; using Windows.ApplicationModel.DataTransfer; using Windows.ApplicationModel.DataTransfer.DragDrop; @@ -195,28 +189,6 @@ public virtual void CreateNewFile(ShellNewEntry f) UIFilesystemHelpers.CreateFileFromDialogResultType(AddItemDialogItemType.File, f, associatedInstance); } - public virtual void CopyPathOfSelectedItem(RoutedEventArgs e) - { - try - { - if (SlimContentPage is not null) - { - var path = SlimContentPage.SelectedItem is not null ? SlimContentPage.SelectedItem.ItemPath : associatedInstance.FilesystemViewModel.WorkingDirectory; - if (FtpHelpers.IsFtpPath(path)) - path = path.Replace("\\", "/", StringComparison.Ordinal); - DataPackage data = new(); - data.SetText(path); - - Clipboard.SetContent(data); - Clipboard.Flush(); - } - } - catch (Exception) - { - Debugger.Break(); - } - } - public virtual void ShareItem(RoutedEventArgs e) { var interop = DataTransferManager.As(); diff --git a/src/Files.App/Interacts/BaseLayoutCommandsViewModel.cs b/src/Files.App/Interacts/BaseLayoutCommandsViewModel.cs index fa60bc89da0d..88b4a1ab3acb 100644 --- a/src/Files.App/Interacts/BaseLayoutCommandsViewModel.cs +++ b/src/Files.App/Interacts/BaseLayoutCommandsViewModel.cs @@ -37,7 +37,6 @@ private void InitializeCommands() OpenDirectoryInNewPaneCommand = new RelayCommand(CommandsModel.OpenDirectoryInNewPane); OpenInNewWindowItemCommand = new RelayCommand(CommandsModel.OpenInNewWindowItem); CreateNewFileCommand = new RelayCommand(CommandsModel.CreateNewFile); - CopyPathOfSelectedItemCommand = new RelayCommand(CommandsModel.CopyPathOfSelectedItem); ShareItemCommand = new RelayCommand(CommandsModel.ShareItem); ItemPointerPressedCommand = new RelayCommand(CommandsModel.ItemPointerPressed); PointerWheelChangedCommand = new RelayCommand(CommandsModel.PointerWheelChanged); @@ -76,8 +75,6 @@ private void InitializeCommands() public ICommand CreateNewFileCommand { get; private set; } - public ICommand CopyPathOfSelectedItemCommand { get; private set; } - public ICommand ShareItemCommand { get; private set; } public ICommand ItemPointerPressedCommand { get; private set; } diff --git a/src/Files.App/Interacts/IBaseLayoutCommandImplementationModel.cs b/src/Files.App/Interacts/IBaseLayoutCommandImplementationModel.cs index 07c830742f1c..eff8169395d0 100644 --- a/src/Files.App/Interacts/IBaseLayoutCommandImplementationModel.cs +++ b/src/Files.App/Interacts/IBaseLayoutCommandImplementationModel.cs @@ -29,8 +29,6 @@ public interface IBaseLayoutCommandImplementationModel : IDisposable void CreateNewFile(ShellNewEntry e); - void CopyPathOfSelectedItem(RoutedEventArgs e); - void ShareItem(RoutedEventArgs e); void ItemPointerPressed(PointerRoutedEventArgs e); diff --git a/src/Files.App/Views/ColumnShellPage.xaml.cs b/src/Files.App/Views/ColumnShellPage.xaml.cs index 4d1ee3a0cdf0..2bf2c42ee0a3 100644 --- a/src/Files.App/Views/ColumnShellPage.xaml.cs +++ b/src/Files.App/Views/ColumnShellPage.xaml.cs @@ -144,10 +144,6 @@ private async void KeyboardAccelerator_Invoked(KeyboardAccelerator sender, Keybo await storageHistoryHelpers.TryRedo(); break; - case (true, true, false, true, VirtualKey.C): - SlimContentPage?.CommandsViewModel.CopyPathOfSelectedItemCommand.Execute(null); - break; - case (false, false, false, true, VirtualKey.F3): //f3 case (true, false, false, true, VirtualKey.F): // ctrl + f ToolbarViewModel.SwitchSearchBoxVisibility(); diff --git a/src/Files.App/Views/ModernShellPage.xaml.cs b/src/Files.App/Views/ModernShellPage.xaml.cs index 812db0211597..75accc9a1911 100644 --- a/src/Files.App/Views/ModernShellPage.xaml.cs +++ b/src/Files.App/Views/ModernShellPage.xaml.cs @@ -202,10 +202,6 @@ private async void KeyboardAccelerator_Invoked(KeyboardAccelerator sender, Keybo break; - case (true, true, false, true, VirtualKey.C): - SlimContentPage?.CommandsViewModel.CopyPathOfSelectedItemCommand.Execute(null); - break; - case (false, false, false, _, VirtualKey.F3): //f3 case (true, false, false, _, VirtualKey.F): // ctrl + f if (tabInstance || CurrentPageType == typeof(WidgetsPage))