Skip to content

Commit 2f607d3

Browse files
authored
Feature: Added ctrl + alt + c shortcut to copy path with quotes (#13398)
1 parent d51fecc commit 2f607d3

File tree

5 files changed

+68
-1
lines changed

5 files changed

+68
-1
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright (c) 2023 Files Community
2+
// Licensed under the MIT License. See the LICENSE.
3+
4+
using Windows.ApplicationModel.DataTransfer;
5+
6+
namespace Files.App.Actions
7+
{
8+
internal class CopyPathWithQuotesAction : IAction
9+
{
10+
private readonly IContentPageContext context;
11+
12+
public string Label
13+
=> "CopyPathWithQuotes".GetLocalizedResource();
14+
15+
public string Description
16+
=> "CopyPathWithQuotesDescription".GetLocalizedResource();
17+
18+
public RichGlyph Glyph
19+
=> new RichGlyph(opacityStyle: "ColorIconCopyPath");
20+
21+
public HotKey HotKey
22+
=> new(Keys.C, KeyModifiers.MenuCtrl);
23+
24+
public bool IsExecutable
25+
=> context.HasSelection;
26+
27+
public CopyPathWithQuotesAction()
28+
{
29+
context = Ioc.Default.GetRequiredService<IContentPageContext>();
30+
}
31+
32+
public Task ExecuteAsync()
33+
{
34+
if (context.ShellPage?.SlimContentPage is not null)
35+
{
36+
var selectedItems = context.ShellPage.SlimContentPage.SelectedItems;
37+
var path = selectedItems is not null
38+
? string.Join("\n", selectedItems.Select(item => $"\"{item.ItemPath}\""))
39+
: context.ShellPage.FilesystemViewModel.WorkingDirectory;
40+
41+
if (FtpHelpers.IsFtpPath(path))
42+
path = path.Replace("\\", "/", StringComparison.Ordinal);
43+
44+
SafetyExtensions.IgnoreExceptions(() =>
45+
{
46+
DataPackage data = new();
47+
data.SetText(path);
48+
49+
Clipboard.SetContent(data);
50+
Clipboard.Flush();
51+
});
52+
}
53+
54+
return Task.CompletedTask;
55+
}
56+
}
57+
}

src/Files.App/Data/Commands/CommandCodes.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public enum CommandCodes
2929
// File System
3030
CopyItem,
3131
CopyPath,
32+
CopyPathWithQuotes,
3233
CutItem,
3334
PasteItem,
3435
PasteItemToSelection,

src/Files.App/Data/Commands/Manager/CommandManager.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public IRichCommand this[HotKey hotKey]
7777
public IRichCommand SetAsLockscreenBackground => commands[CommandCodes.SetAsLockscreenBackground];
7878
public IRichCommand CopyItem => commands[CommandCodes.CopyItem];
7979
public IRichCommand CopyPath => commands[CommandCodes.CopyPath];
80+
public IRichCommand CopyPathWithQuotes => commands[CommandCodes.CopyPathWithQuotes];
8081
public IRichCommand CutItem => commands[CommandCodes.CutItem];
8182
public IRichCommand PasteItem => commands[CommandCodes.PasteItem];
8283
public IRichCommand PasteItemToSelection => commands[CommandCodes.PasteItemToSelection];
@@ -240,6 +241,7 @@ public CommandManager()
240241
[CommandCodes.SetAsLockscreenBackground] = new SetAsLockscreenBackgroundAction(),
241242
[CommandCodes.CopyItem] = new CopyItemAction(),
242243
[CommandCodes.CopyPath] = new CopyPathAction(),
244+
[CommandCodes.CopyPathWithQuotes] = new CopyPathWithQuotesAction(),
243245
[CommandCodes.CutItem] = new CutItemAction(),
244246
[CommandCodes.PasteItem] = new PasteItemAction(),
245247
[CommandCodes.PasteItemToSelection] = new PasteItemToSelectionAction(),

src/Files.App/Data/Commands/Manager/ICommandManager.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public interface ICommandManager : IEnumerable<IRichCommand>
3030

3131
IRichCommand CopyItem { get; }
3232
IRichCommand CopyPath { get; }
33+
IRichCommand CopyPathWithQuotes { get; }
3334
IRichCommand CutItem { get; }
3435
IRichCommand PasteItem { get; }
3536
IRichCommand PasteItemToSelection { get; }

src/Files.App/Strings/en-US/Resources.resw

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@
123123
<data name="CopyPath" xml:space="preserve">
124124
<value>Copy path</value>
125125
</data>
126+
<data name="CopyPathWithQuotes" xml:space="preserve">
127+
<value>Copy path with quotes</value>
128+
</data>
126129
<data name="Browse" xml:space="preserve">
127130
<value>Browse</value>
128131
</data>
@@ -2419,7 +2422,10 @@
24192422
<value>Copy item(s) to clipboard</value>
24202423
</data>
24212424
<data name="CopyPathDescription" xml:space="preserve">
2422-
<value>Copy path of item to clipboard</value>
2425+
<value>Copy path of selected items to the clipboard</value>
2426+
</data>
2427+
<data name="CopyPathWithQuotesDescription" xml:space="preserve">
2428+
<value>Copy path of selected items with quotes to the clipboard</value>
24232429
</data>
24242430
<data name="CutItemDescription" xml:space="preserve">
24252431
<value>Cut item(s) to clipboard</value>

0 commit comments

Comments
 (0)