-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Added an action to copy the path of the current directory (#…
- Loading branch information
Showing
9 changed files
with
140 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
57
src/Files.App/Actions/FileSystem/CopyItemPathWithQuotesAction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters