This repository was archived by the owner on Jun 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathCopyLinkCommand.cs
More file actions
61 lines (56 loc) · 1.97 KB
/
Copy pathCopyLinkCommand.cs
File metadata and controls
61 lines (56 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using System;
using System.ComponentModel.Composition;
using System.Threading.Tasks;
using System.Windows;
using GitHub.Commands;
using GitHub.Exports;
using GitHub.Services;
using GitHub.VisualStudio.UI;
namespace GitHub.VisualStudio.Commands
{
/// <summary>
/// Copies a link to the clipboard of the currently selected text on GitHub.com or an
/// Enterprise instance.
/// </summary>
[Export(typeof(ICopyLinkCommand))]
public class CopyLinkCommand : LinkCommandBase, ICopyLinkCommand
{
[ImportingConstructor]
protected CopyLinkCommand(IGitHubServiceProvider serviceProvider, Lazy<IGitService> gitService)
: base(CommandSet, CommandId, serviceProvider, gitService)
{
}
/// <summary>
/// Gets the GUID of the group the command belongs to.
/// </summary>
public static readonly Guid CommandSet = Guids.guidContextMenuSet;
/// <summary>
/// Gets the numeric identifier of the command.
/// </summary>
public const int CommandId = PkgCmdIDList.copyLinkCommand;
/// <summary>
/// Copies the link to the clipboard.
/// </summary>
public async override Task Execute()
{
var isgithub = await IsGitHubRepo();
if (!isgithub)
return;
var link = await GenerateLink(LinkType.Blob);
if (link == null)
return;
try
{
Clipboard.SetText(link);
var ns = ServiceProvider.TryGetService<IStatusBarNotificationService>();
ns?.ShowMessage(Resources.LinkCopiedToClipboardMessage);
await UsageTracker.IncrementCounter(x => x.NumberOfLinkToGitHub);
}
catch
{
var ns = ServiceProvider.TryGetService<IStatusBarNotificationService>();
ns?.ShowMessage(Resources.Error_FailedToCopyToClipboard);
}
}
}
}