Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Shows how to add custom UIContexts
On the package
[ProvideAutoLoad(UIContexts.LoadContext)]
[ProvideUIContextRule(UIContexts.LoadContext,
"RightFileTypeOpen",
"(CSharpFileOpen | VBFileOpen)",
new[] { "CSharpFileOpen", "VBFileOpen" },
new[] { "ActiveEditorContentType:CSharp", "ActiveEditorContentType:Basic" })]
In the VSCT
<VisibilityConstraints>
<VisibilityItem guid="guidCmdSet" id="cmdidStuff" context=" guidLoadContext " />
</VisibilityConstraints>
<Symbols>
<GuidSymbol name="guidLoadContext" value="{C6216099-CA25-4821-A541-044E82B4DCF1}" />
</Symbols>
As a helper containing the GUIDs
namespace Foo
{
internal static class UIContexts
{
public const string LoadContext = "C6216099-CA25-4821-A541-044E82B4DCF1";
}
}
Bolded GUIDs must match
Docs on allowed conditions: https://msdn.microsoft.com/en-us/library/mt750411.aspx
@yannduran

This comment has been minimized.

Copy link

@yannduran yannduran commented Mar 24, 2019

What else can be used for ActiveEditorContentType, other than CSharp and Basic?

Is there a type that will detect any text-based files (like .vsct, .config files etc), without resorting to relying on the file suffix?

@SimpleSandman

This comment has been minimized.

Copy link

@SimpleSandman SimpleSandman commented Jan 15, 2021

What else can be used for ActiveEditorContentType, other than CSharp and Basic?

I think finding the limitations of this term type is "trial and error", but I was able to detect JSON with "ActiveEditorContentType:Json"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment