Skip to content

Instantly share code, notes, and snippets.

@madskristensen
Last active January 15, 2021 00:58
Show Gist options
  • Save madskristensen/7981e3e746088b51f98c9efd13e68963 to your computer and use it in GitHub Desktop.
Save madskristensen/7981e3e746088b51f98c9efd13e68963 to your computer and use it in GitHub Desktop.
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
Copy link

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
Copy link

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