Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 83610bf

Browse files
committed
Only show command when in context of git repo
Since `Open from clipboard` requires a repository to navigate, we only want to advertise the command when in the context of a repository.
1 parent b26b2a9 commit 83610bf

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/GitHub.VisualStudio/Commands/OpenFromClipboardCommand.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using GitHub.Exports;
55
using GitHub.Services;
66
using GitHub.Services.Vssdk.Commands;
7+
using Microsoft.VisualStudio.Shell;
78
using Task = System.Threading.Tasks.Task;
89

910
namespace GitHub.VisualStudio.Commands
@@ -22,6 +23,7 @@ public class OpenFromClipboardCommand : VsCommand<string>, IOpenFromClipboardCom
2223
readonly Lazy<IGitHubContextService> gitHubContextService;
2324
readonly Lazy<ITeamExplorerContext> teamExplorerContext;
2425
readonly Lazy<IVSServices> vsServices;
26+
readonly UIContext uiContext;
2527

2628
/// <summary>
2729
/// Gets the GUID of the group the command belongs to.
@@ -46,6 +48,9 @@ public OpenFromClipboardCommand(
4648

4749
// See https://code.msdn.microsoft.com/windowsdesktop/AllowParams-2005-9442298f
4850
ParametersDescription = "u"; // accept a single url
51+
52+
// This command is only visible when in the context of a Git repository
53+
uiContext = UIContext.FromUIContextGuid(new Guid(Guids.UIContext_Git));
4954
}
5055

5156
public override async Task Execute(string url)
@@ -109,5 +114,10 @@ public override async Task Execute(string url)
109114

110115
gitHubContextService.Value.TryOpenFile(repositoryDir, context);
111116
}
117+
118+
protected override void QueryStatus()
119+
{
120+
Visible = uiContext.IsActive;
121+
}
112122
}
113123
}

src/GitHub.VisualStudio/GitHub.VisualStudio.vsct

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@
127127
<Icon guid="guidImages" id="logo" />
128128
<CommandFlag>IconIsMoniker</CommandFlag>
129129
<CommandFlag>AllowParams</CommandFlag>
130+
<CommandFlag>DefaultInvisible</CommandFlag>
131+
<CommandFlag>DynamicVisibility</CommandFlag>
130132
<Strings>
131133
<ButtonText>Open from clipboard</ButtonText>
132134
<CanonicalName>.GitHub.OpenFromClipboard</CanonicalName>

0 commit comments

Comments
 (0)