提交 8bb8f214 编写于 作者: M Matt Bierner

Use a customEditors context key that lists custom editors

This allows commands/contributions to enable/disable themselves based matching against the list of custom editors
上级 eb354fa8
......@@ -17,7 +17,7 @@ import { EditorViewColumn, viewColumnToEditorGroup } from 'vs/workbench/api/comm
import { IEditorCommandsContext } from 'vs/workbench/common/editor';
import { CustomEditorInput } from 'vs/workbench/contrib/customEditor/browser/customEditorInput';
import { defaultEditorId } from 'vs/workbench/contrib/customEditor/browser/customEditors';
import { CONTEXT_FOCUSED_CUSTOM_EDITOR_IS_EDITABLE, CONTEXT_HAS_CUSTOM_EDITORS, ICustomEditorService } from 'vs/workbench/contrib/customEditor/common/customEditor';
import { CONTEXT_FOCUSED_CUSTOM_EDITOR_IS_EDITABLE, CONTEXT_CUSTOM_EDITORS, ICustomEditorService } from 'vs/workbench/contrib/customEditor/common/customEditor';
import { IEditorGroup, IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import type { ITextEditorOptions } from 'vs/platform/editor/common/editor';
......@@ -80,7 +80,7 @@ MenuRegistry.appendMenuItem(MenuId.CommandPalette, {
title: REOPEN_WITH_TITLE,
category: viewCategory,
},
when: CONTEXT_HAS_CUSTOM_EDITORS,
when: CONTEXT_CUSTOM_EDITORS.notEqualsTo(''),
});
MenuRegistry.appendMenuItem(MenuId.EditorTitle, {
......@@ -91,7 +91,7 @@ MenuRegistry.appendMenuItem(MenuId.EditorTitle, {
},
group: '6_reopen',
order: 20,
when: CONTEXT_HAS_CUSTOM_EDITORS,
when: CONTEXT_CUSTOM_EDITORS.notEqualsTo(''),
});
// #endregion
......@@ -155,7 +155,7 @@ MenuRegistry.appendMenuItem(MenuId.EditorTitle, {
constructor() {
super({
id: ToggleCustomEditorCommand.ID,
precondition: CONTEXT_HAS_CUSTOM_EDITORS,
precondition: CONTEXT_CUSTOM_EDITORS,
});
}
......
......@@ -25,7 +25,7 @@ import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
import { EditorInput, EditorOptions, IEditor, IEditorInput } from 'vs/workbench/common/editor';
import { DiffEditorInput } from 'vs/workbench/common/editor/diffEditorInput';
import { webviewEditorsExtensionPoint } from 'vs/workbench/contrib/customEditor/browser/extensionPoint';
import { CONTEXT_FOCUSED_CUSTOM_EDITOR_IS_EDITABLE, CONTEXT_HAS_CUSTOM_EDITORS, CustomEditorInfo, CustomEditorInfoCollection, CustomEditorPriority, CustomEditorSelector, ICustomEditor, ICustomEditorService } from 'vs/workbench/contrib/customEditor/common/customEditor';
import { CONTEXT_FOCUSED_CUSTOM_EDITOR_IS_EDITABLE, CONTEXT_CUSTOM_EDITORS, CustomEditorInfo, CustomEditorInfoCollection, CustomEditorPriority, CustomEditorSelector, ICustomEditor, ICustomEditorService } from 'vs/workbench/contrib/customEditor/common/customEditor';
import { CustomEditorModelManager } from 'vs/workbench/contrib/customEditor/common/customEditorModelManager';
import { IWebviewService, webviewHasOwnEditFunctionsContext } from 'vs/workbench/contrib/webview/browser/webview';
import { IEditorGroup, IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
......@@ -98,7 +98,7 @@ export class CustomEditorService extends Disposable implements ICustomEditorServ
private readonly _models: CustomEditorModelManager;
private readonly _hasCustomEditor: IContextKey<boolean>;
private readonly _customEditorContextKey: IContextKey<string>;
private readonly _focusedCustomEditorIsEditable: IContextKey<boolean>;
private readonly _webviewHasOwnEditFunctions: IContextKey<boolean>;
......@@ -118,7 +118,7 @@ export class CustomEditorService extends Disposable implements ICustomEditorServ
this._models = new CustomEditorModelManager(workingCopyService, labelService);
this._hasCustomEditor = CONTEXT_HAS_CUSTOM_EDITORS.bindTo(contextKeyService);
this._customEditorContextKey = CONTEXT_CUSTOM_EDITORS.bindTo(contextKeyService);
this._focusedCustomEditorIsEditable = CONTEXT_FOCUSED_CUSTOM_EDITOR_IS_EDITABLE.bindTo(contextKeyService);
this._webviewHasOwnEditFunctions = webviewHasOwnEditFunctionsContext.bindTo(contextKeyService);
......@@ -310,7 +310,7 @@ export class CustomEditorService extends Disposable implements ICustomEditorServ
const activeControl = this.editorService.activeControl;
const resource = activeControl?.input.resource;
if (!resource) {
this._hasCustomEditor.reset();
this._customEditorContextKey.reset();
this._focusedCustomEditorIsEditable.reset();
this._webviewHasOwnEditFunctions.reset();
return;
......@@ -320,7 +320,7 @@ export class CustomEditorService extends Disposable implements ICustomEditorServ
...this.getContributedCustomEditors(resource).allEditors,
...this.getUserConfiguredCustomEditors(resource).allEditors,
];
this._hasCustomEditor.set(possibleEditors.length > 0);
this._customEditorContextKey.set(possibleEditors.map(x => x.id).join(','));
this._focusedCustomEditorIsEditable.set(activeControl?.input instanceof CustomEditorInput);
this._webviewHasOwnEditFunctions.set(possibleEditors.length > 0);
}
......
......@@ -18,7 +18,7 @@ import { IWorkingCopy } from 'vs/workbench/services/workingCopy/common/workingCo
export const ICustomEditorService = createDecorator<ICustomEditorService>('customEditorService');
export const CONTEXT_HAS_CUSTOM_EDITORS = new RawContextKey<boolean>('hasCustomEditors', false);
export const CONTEXT_CUSTOM_EDITORS = new RawContextKey<string>('customEditors', '');
export const CONTEXT_FOCUSED_CUSTOM_EDITOR_IS_EDITABLE = new RawContextKey<boolean>('focusedCustomEditorIsEditable', false);
export interface ICustomEditor {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册