Skip to content
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
56 changes: 56 additions & 0 deletions src/Files.App/Actions/FileSystem/CopyItemPathAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright (c) 2024 Files Community
// Licensed under the MIT License. See the LICENSE.

using Windows.ApplicationModel.DataTransfer;

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

public string Label
=> Strings.CopyPath.GetLocalizedResource();

public string Description
=> Strings.CopyItemPathDescription.GetLocalizedResource();

public RichGlyph Glyph
=> new RichGlyph(themedIconStyle: "App.ThemedIcons.CopyAsPath");

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

public bool IsExecutable
=> context.HasSelection;

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

public Task ExecuteAsync(object? parameter = null)
{
if (context.ShellPage?.SlimContentPage is not null)
{
var path = context.ShellPage.SlimContentPage.SelectedItems is not null
? context.ShellPage.SlimContentPage.SelectedItems.Select(x => x.ItemPath).Aggregate((accum, current) => accum + "\n" + current)
: context.ShellPage.ShellViewModel.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;
}
}
}
57 changes: 57 additions & 0 deletions src/Files.App/Actions/FileSystem/CopyItemPathWithQuotesAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright (c) 2024 Files Community
// Licensed under the MIT License. See the LICENSE.

using Windows.ApplicationModel.DataTransfer;

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

public string Label
=> Strings.CopyItemPathWithQuotes.GetLocalizedResource();

public string Description
=> Strings.CopyItemPathWithQuotesDescription.GetLocalizedResource();

public RichGlyph Glyph
=> new RichGlyph(themedIconStyle: "App.ThemedIcons.CopyAsPath");

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

public bool IsExecutable
=> context.HasSelection;

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

public Task ExecuteAsync(object? parameter = null)
{
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.ShellViewModel.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;
}
}
}
13 changes: 4 additions & 9 deletions src/Files.App/Actions/FileSystem/CopyPathAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,16 @@ internal sealed class CopyPathAction : IAction
private readonly IContentPageContext context;

public string Label
=> "CopyPath".GetLocalizedResource();
=> Strings.CopyPath.GetLocalizedResource();

public string Description
=> "CopyPathDescription".GetLocalizedResource();
=> Strings.CopyPathDescription.GetLocalizedResource();

public RichGlyph Glyph
=> new RichGlyph(themedIconStyle: "App.ThemedIcons.CopyAsPath");

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

public bool IsExecutable
=> context.HasSelection;
=> context.PageType != ContentPageTypes.Home && context.PageType != ContentPageTypes.RecycleBin;

public CopyPathAction()
{
Expand All @@ -33,9 +30,7 @@ public Task ExecuteAsync(object? parameter = null)
{
if (context.ShellPage?.SlimContentPage is not null)
{
var path = context.ShellPage.SlimContentPage.SelectedItems is not null
? context.ShellPage.SlimContentPage.SelectedItems.Select(x => x.ItemPath).Aggregate((accum, current) => accum + "\n" + current)
: context.ShellPage.ShellViewModel.WorkingDirectory;
var path = context.ShellPage.ShellViewModel.WorkingDirectory;

if (FtpHelpers.IsFtpPath(path))
path = path.Replace("\\", "/", StringComparison.Ordinal);
Expand Down
14 changes: 4 additions & 10 deletions src/Files.App/Actions/FileSystem/CopyPathWithQuotesAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,16 @@ internal sealed class CopyPathWithQuotesAction : IAction
private readonly IContentPageContext context;

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

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

public RichGlyph Glyph
=> new RichGlyph(themedIconStyle: "App.ThemedIcons.CopyAsPath");

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

public bool IsExecutable
=> context.HasSelection;
=> context.PageType != ContentPageTypes.Home && context.PageType != ContentPageTypes.RecycleBin;

public CopyPathWithQuotesAction()
{
Expand All @@ -33,10 +30,7 @@ public Task ExecuteAsync(object? parameter = null)
{
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.ShellViewModel.WorkingDirectory;
var path = "\"" + context.ShellPage.ShellViewModel.WorkingDirectory + "\"";

if (FtpHelpers.IsFtpPath(path))
path = path.Replace("\\", "/", StringComparison.Ordinal);
Expand Down
2 changes: 2 additions & 0 deletions src/Files.App/Data/Commands/Manager/CommandCodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ public enum CommandCodes

// File System
CopyItem,
CopyItemPath,
CopyPath,
CopyItemPathWithQuotes,
CopyPathWithQuotes,
CutItem,
PasteItem,
Expand Down
4 changes: 4 additions & 0 deletions src/Files.App/Data/Commands/Manager/CommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ public IRichCommand this[HotKey hotKey]
public IRichCommand SetAsLockscreenBackground => commands[CommandCodes.SetAsLockscreenBackground];
public IRichCommand SetAsAppBackground => commands[CommandCodes.SetAsAppBackground];
public IRichCommand CopyItem => commands[CommandCodes.CopyItem];
public IRichCommand CopyItemPath => commands[CommandCodes.CopyItemPath];
public IRichCommand CopyPath => commands[CommandCodes.CopyPath];
public IRichCommand CopyItemPathWithQuotes => commands[CommandCodes.CopyItemPathWithQuotes];
public IRichCommand CopyPathWithQuotes => commands[CommandCodes.CopyPathWithQuotes];
public IRichCommand CutItem => commands[CommandCodes.CutItem];
public IRichCommand PasteItem => commands[CommandCodes.PasteItem];
Expand Down Expand Up @@ -273,7 +275,9 @@ public IEnumerator<IRichCommand> GetEnumerator() =>
[CommandCodes.SetAsLockscreenBackground] = new SetAsLockscreenBackgroundAction(),
[CommandCodes.SetAsAppBackground] = new SetAsAppBackgroundAction(),
[CommandCodes.CopyItem] = new CopyItemAction(),
[CommandCodes.CopyItemPath] = new CopyItemPathAction(),
[CommandCodes.CopyPath] = new CopyPathAction(),
[CommandCodes.CopyItemPathWithQuotes] = new CopyItemPathWithQuotesAction(),
[CommandCodes.CopyPathWithQuotes] = new CopyPathWithQuotesAction(),
[CommandCodes.CutItem] = new CutItemAction(),
[CommandCodes.PasteItem] = new PasteItemAction(),
Expand Down
2 changes: 2 additions & 0 deletions src/Files.App/Data/Commands/Manager/ICommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ public interface ICommandManager : IEnumerable<IRichCommand>
IRichCommand ToggleToolbar { get; }

IRichCommand CopyItem { get; }
IRichCommand CopyItemPath { get; }
IRichCommand CopyPath { get; }
IRichCommand CopyItemPathWithQuotes { get; }
IRichCommand CopyPathWithQuotes { get; }
IRichCommand CutItem { get; }
IRichCommand PasteItem { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
IsPrimary = true,
IsVisible = true,
}.Build(),
new ContextMenuFlyoutItemViewModelBuilder(Commands.CopyPath)
new ContextMenuFlyoutItemViewModelBuilder(Commands.CopyItemPath)
{
IsVisible = UserSettingsService.GeneralSettingsService.ShowCopyPath
&& itemsSelected
Expand Down
11 changes: 10 additions & 1 deletion src/Files.App/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@
<data name="CopyPathWithQuotes" xml:space="preserve">
<value>Copy path with quotes</value>
</data>
<data name="CopyItemPathWithQuotes" xml:space="preserve">
<value>Copy selected item path with quotes</value>
</data>
<data name="Browse" xml:space="preserve">
<value>Browse</value>
</data>
Expand Down Expand Up @@ -2391,11 +2394,17 @@
<value>Copy item(s) to clipboard</value>
</data>
<data name="CopyPathDescription" xml:space="preserve">
<value>Copy path of the current directory to the clipboard</value>
</data>
<data name="CopyItemPathDescription" xml:space="preserve">
<value>Copy path of selected items to the clipboard</value>
</data>
<data name="CopyPathWithQuotesDescription" xml:space="preserve">
<data name="CopyItemPathWithQuotesDescription" xml:space="preserve">
<value>Copy path of selected items with quotes to the clipboard</value>
</data>
<data name="CopyPathWithQuotesDescription" xml:space="preserve">
<value>Copy path of the current directory with quotes to the clipboard</value>
</data>
<data name="CutItemDescription" xml:space="preserve">
<value>Cut item(s) to clipboard</value>
</data>
Expand Down