VisibilityContraint for the Diff Service / Editor? #370
Replies: 1 comment 1 reply
-
I added this code to work out what contexts become active while the diff editor is open: protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress) {
await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
IVsUIContextMonitor monitor = await VS.GetServiceAsync<SVsUIContextMonitor, IVsUIContextMonitor>();
monitor.AdviseContextEvents(this); // "this" is my package, which implements IVsUIContextEvents.
}
public void OnContextChanged(Guid uiContext, bool active) {
System.Diagnostics.Debug.WriteLine(uiContext.ToString() + " : " + active);
} From the results, it looks like the GUID for the diff editor is I added this to the <VisibilityConstraints>
<VisibilityItem guid="TestExtension" id="MyCommand" context="CodeButNotDiffContext" />
</VisibilityConstraints>
<Symbols>
<GuidSymbol name="CodeButNotDiffContext" value="{9254612C-DC95-43F3-B310-82320EC34775}" /> <!-- The GUID is unimportant here - it just needs to match the GUID in the `ProvideUIContextRule` attribute). -->
</Symbols> I couldn't get the visibility to work for all "standard code editors", but this worked for most of them. It wasn't active for XML-like files ( [ProvideUIContextRule("{9254612C-DC95-43F3-B310-82320EC34775}",
name: "CustomContext",
expression: "TextEditor & !DiffEditor",
termNames: new[] { "TextEditor", "DiffEditor" },
termValues: new[] { VsEditorFactoryGuid.TextEditor_string, "{282DEB30-FC73-43D9-A9E9-41F1F6D33F30}" }
)] Another approach that seemed to work was to be active when a document window is open, but not when a property page designer is open (because they are also "document windows"): [ProvideUIContextRule("{9254612C-DC95-43F3-B310-82320EC34775}",
name: "CodeButNotDiffContext",
expression: "DocumentWindowActive & !PropertyPageDesigner & !DiffEditor",
termNames: new[] { "DocumentWindowActive", "PropertyPageDesigner", "DiffEditor" },
termValues: new[] { UICONTEXT.DocumentWindowActive_string, UICONTEXT.PropertyPageDesigner_string, "{282DEB30-FC73-43D9-A9E9-41F1F6D33F30}" }
)]
[ProvideUIContextRule("{9254612C-DC95-43F3-B310-82320EC34775}",
name: "CodeButNotDiffContext",
expression: "IsDocument & (!DiffEditor)",
termNames: new[] { "IsDocument", "DiffEditor" },
termValues: new[] { VSConstants.UICONTEXT.DocumentWindowActive_string, "{282DEB30-FC73-43D9-A9E9-41F1F6D33F30}" }
)] It's also worth noting that using [ProvideUIContextRule("{9254612C-DC95-43F3-B310-82320EC34775}",
name: "CodeButNotDiffContext",
expression: "IsCode & !IsDiff",
termNames: new[] { "IsCode", "IsDiff" },
termValues: new[] { "ActiveEditorContentType:code", "ActiveEditorContentType:diff" }
// "ActiveEditorContentType:code" doesn't seem to work :(
)] |
Beta Was this translation helpful? Give feedback.
-
Is there any way to toggle the visibility of a button / right-click context menu item (defined in the VSCT file) to be visible in the "standard" code editor, but not the "diff" view editor/window?
I was thinking this might be possible with VisibilityContraints, but I can't seem to find enough info on 'context' to be certain. If that isn't possible, any other ideas?
Thanks
Beta Was this translation helpful? Give feedback.
All reactions