Skip to content

Feature: Added ctrl + alt + c shortcut to copy path with quotes #13398

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

Merged
merged 6 commits into from
Nov 28, 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
57 changes: 57 additions & 0 deletions src/Files.App/Actions/FileSystem/CopyPathWithQuotesAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Windows.ApplicationModel.DataTransfer;

namespace Files.App.Actions
{
internal class CopyPathWithQuotesAction : IAction
{
private readonly IContentPageContext context;

public string Label
=> "CopyPathWithQuotes".GetLocalizedResource();

public string Description
=> "CopyPathWithQuotesDescription".GetLocalizedResource();

public RichGlyph Glyph
=> new RichGlyph(opacityStyle: "ColorIconCopyPath");

public HotKey HotKey
=> new(Keys.C, KeyModifiers.MenuCtrl);

public bool IsExecutable
=> context.HasSelection;

public CopyPathWithQuotesAction()
{
context = Ioc.Default.GetRequiredService<IContentPageContext>();
}

public Task ExecuteAsync()
{
if (context.ShellPage?.SlimContentPage is not null)
{
var selectedItems = context.ShellPage.SlimContentPage.SelectedItems;
var path = selectedItems is not null
? string.Join("\n", selectedItems.Select(item => $"\"{item.ItemPath}\""))
: context.ShellPage.FilesystemViewModel.WorkingDirectory;

if (FtpHelpers.IsFtpPath(path))
path = path.Replace("\\", "/", StringComparison.Ordinal);

SafetyExtensions.IgnoreExceptions(() =>
{
DataPackage data = new();
data.SetText(path);

Clipboard.SetContent(data);
Clipboard.Flush();
});
}

return Task.CompletedTask;
}
}
}
1 change: 1 addition & 0 deletions src/Files.App/Data/Commands/CommandCodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public enum CommandCodes
// File System
CopyItem,
CopyPath,
CopyPathWithQuotes,
CutItem,
PasteItem,
PasteItemToSelection,
Expand Down
2 changes: 2 additions & 0 deletions src/Files.App/Data/Commands/Manager/CommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public IRichCommand this[HotKey hotKey]
public IRichCommand SetAsLockscreenBackground => commands[CommandCodes.SetAsLockscreenBackground];
public IRichCommand CopyItem => commands[CommandCodes.CopyItem];
public IRichCommand CopyPath => commands[CommandCodes.CopyPath];
public IRichCommand CopyPathWithQuotes => commands[CommandCodes.CopyPathWithQuotes];
public IRichCommand CutItem => commands[CommandCodes.CutItem];
public IRichCommand PasteItem => commands[CommandCodes.PasteItem];
public IRichCommand PasteItemToSelection => commands[CommandCodes.PasteItemToSelection];
Expand Down Expand Up @@ -240,6 +241,7 @@ public CommandManager()
[CommandCodes.SetAsLockscreenBackground] = new SetAsLockscreenBackgroundAction(),
[CommandCodes.CopyItem] = new CopyItemAction(),
[CommandCodes.CopyPath] = new CopyPathAction(),
[CommandCodes.CopyPathWithQuotes] = new CopyPathWithQuotesAction(),
[CommandCodes.CutItem] = new CutItemAction(),
[CommandCodes.PasteItem] = new PasteItemAction(),
[CommandCodes.PasteItemToSelection] = new PasteItemToSelectionAction(),
Expand Down
1 change: 1 addition & 0 deletions src/Files.App/Data/Commands/Manager/ICommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public interface ICommandManager : IEnumerable<IRichCommand>

IRichCommand CopyItem { get; }
IRichCommand CopyPath { get; }
IRichCommand CopyPathWithQuotes { get; }
IRichCommand CutItem { get; }
IRichCommand PasteItem { get; }
IRichCommand PasteItemToSelection { get; }
Expand Down
8 changes: 7 additions & 1 deletion src/Files.App/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@
<data name="CopyPath" xml:space="preserve">
<value>Copy path</value>
</data>
<data name="CopyPathWithQuotes" xml:space="preserve">
<value>Copy path with quotes</value>
</data>
<data name="Browse" xml:space="preserve">
<value>Browse</value>
</data>
Expand Down Expand Up @@ -2419,7 +2422,10 @@
<value>Copy item(s) to clipboard</value>
</data>
<data name="CopyPathDescription" xml:space="preserve">
<value>Copy path of item to clipboard</value>
<value>Copy path of selected items to the clipboard</value>
</data>
<data name="CopyPathWithQuotesDescription" xml:space="preserve">
<value>Copy path of selected items with quotes to the clipboard</value>
</data>
<data name="CutItemDescription" xml:space="preserve">
<value>Cut item(s) to clipboard</value>
Expand Down