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

RichCommand: Copy path #11774

Merged
merged 1 commit into from
Mar 20, 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
43 changes: 43 additions & 0 deletions src/Files.App/Actions/FileSystem/CopyPathAction.cs
Original file line number Diff line number Diff line change
@@ -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<IContentPageContext>();

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();
}
}
}
}
1 change: 1 addition & 0 deletions src/Files.App/Commands/CommandCodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public enum CommandCodes

// File System
CopyItem,
CopyPath,
CutItem,
PasteItem,
PasteItemToSelection,
Expand Down
2 changes: 2 additions & 0 deletions src/Files.App/Commands/Manager/CommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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(),
Expand Down
1 change: 1 addition & 0 deletions src/Files.App/Commands/Manager/ICommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public interface ICommandManager : IEnumerable<IRichCommand>
IRichCommand TogglePreviewPane { get; }

IRichCommand CopyItem { get; }
IRichCommand CopyPath { get; }
IRichCommand CutItem { get; }
IRichCommand PasteItem { get; }
IRichCommand PasteItemToSelection { get; }
Expand Down
16 changes: 3 additions & 13 deletions src/Files.App/Helpers/ContextFlyoutItemHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -391,20 +391,10 @@ public static List<ContextMenuFlyoutItemViewModel> 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(),
Expand Down
28 changes: 0 additions & 28 deletions src/Files.App/Interacts/BaseLayoutCommandImplementationModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,23 @@

using CommunityToolkit.Mvvm.DependencyInjection;
using CommunityToolkit.WinUI;
using Files.App.Dialogs;
using Files.App.Extensions;
using Files.App.Filesystem;
using Files.App.Filesystem.StorageItems;
using Files.App.Helpers;
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;
Expand Down Expand Up @@ -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<UWPToWinAppSDKUpgradeHelpers.IDataTransferManagerInterop>();
Expand Down
3 changes: 0 additions & 3 deletions src/Files.App/Interacts/BaseLayoutCommandsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ private void InitializeCommands()
OpenDirectoryInNewPaneCommand = new RelayCommand<RoutedEventArgs>(CommandsModel.OpenDirectoryInNewPane);
OpenInNewWindowItemCommand = new RelayCommand<RoutedEventArgs>(CommandsModel.OpenInNewWindowItem);
CreateNewFileCommand = new RelayCommand<ShellNewEntry>(CommandsModel.CreateNewFile);
CopyPathOfSelectedItemCommand = new RelayCommand<RoutedEventArgs>(CommandsModel.CopyPathOfSelectedItem);
ShareItemCommand = new RelayCommand<RoutedEventArgs>(CommandsModel.ShareItem);
ItemPointerPressedCommand = new RelayCommand<PointerRoutedEventArgs>(CommandsModel.ItemPointerPressed);
PointerWheelChangedCommand = new RelayCommand<PointerRoutedEventArgs>(CommandsModel.PointerWheelChanged);
Expand Down Expand Up @@ -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; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ public interface IBaseLayoutCommandImplementationModel : IDisposable

void CreateNewFile(ShellNewEntry e);

void CopyPathOfSelectedItem(RoutedEventArgs e);

void ShareItem(RoutedEventArgs e);

void ItemPointerPressed(PointerRoutedEventArgs e);
Expand Down
4 changes: 0 additions & 4 deletions src/Files.App/Views/ColumnShellPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 0 additions & 4 deletions src/Files.App/Views/ModernShellPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down