提交 db472f9a 编写于 作者: B Benjamin Pasero

context key - a bit of bufferChangeEvents when changing many context keys at once

上级 9e17e6de
......@@ -998,7 +998,6 @@ export interface IContextKeyService {
onDidChangeContext: Event<IContextKeyChangeEvent>;
bufferChangeEvents(callback: Function): void;
createKey<T>(key: string, defaultValue: T | undefined): IContextKey<T>;
contextMatchesRules(rules: ContextKeyExpression | undefined): boolean;
getContextKeyValue<T>(key: string): T | undefined;
......
......@@ -255,9 +255,11 @@ export class WorkbenchList<T> extends List<T> {
const selection = this.getSelection();
const focus = this.getFocus();
this.listHasSelectionOrFocus.set(selection.length > 0 || focus.length > 0);
this.listMultiSelection.set(selection.length > 1);
this.listDoubleSelection.set(selection.length === 2);
this.contextKeyService.bufferChangeEvents(() => {
this.listHasSelectionOrFocus.set(selection.length > 0 || focus.length > 0);
this.listMultiSelection.set(selection.length > 1);
this.listDoubleSelection.set(selection.length === 2);
});
}));
this.disposables.add(this.onDidChangeFocus(() => {
const selection = this.getSelection();
......@@ -906,9 +908,11 @@ class WorkbenchTreeInternals<TInput, T, TFilterData> {
const selection = tree.getSelection();
const focus = tree.getFocus();
this.hasSelectionOrFocus.set(selection.length > 0 || focus.length > 0);
this.hasMultiSelection.set(selection.length > 1);
this.hasDoubleSelection.set(selection.length === 2);
this.contextKeyService.bufferChangeEvents(() => {
this.hasSelectionOrFocus.set(selection.length > 0 || focus.length > 0);
this.hasMultiSelection.set(selection.length > 1);
this.hasDoubleSelection.set(selection.length === 2);
});
}),
tree.onDidChangeFocus(() => {
const selection = tree.getSelection();
......
......@@ -223,9 +223,11 @@ export abstract class TitleControl extends Themable {
this.editorToolBarMenuDisposables.clear();
// Update contexts
this.resourceContext.set(this.group.activeEditor ? withUndefinedAsNull(toResource(this.group.activeEditor, { supportSideBySide: SideBySideEditor.PRIMARY })) : null);
this.editorPinnedContext.set(this.group.activeEditor ? this.group.isPinned(this.group.activeEditor) : false);
this.editorStickyContext.set(this.group.activeEditor ? this.group.isSticky(this.group.activeEditor) : false);
this.contextKeyService.bufferChangeEvents(() => {
this.resourceContext.set(this.group.activeEditor ? withUndefinedAsNull(toResource(this.group.activeEditor, { supportSideBySide: SideBySideEditor.PRIMARY })) : null);
this.editorPinnedContext.set(this.group.activeEditor ? this.group.isPinned(this.group.activeEditor) : false);
this.editorStickyContext.set(this.group.activeEditor ? this.group.isSticky(this.group.activeEditor) : false);
});
// Editor actions require the editor control to be there, so we retrieve it via service
const activeEditorPane = this.group.activeEditorPane;
......
......@@ -39,19 +39,19 @@ export class ResourceContextKey extends Disposable implements IContextKey<URI> {
private readonly _isFileSystemResource: IContextKey<boolean>;
constructor(
@IContextKeyService contextKeyService: IContextKeyService,
@IContextKeyService private readonly _contextKeyService: IContextKeyService,
@IFileService private readonly _fileService: IFileService,
@IModeService private readonly _modeService: IModeService
) {
super();
this._schemeKey = ResourceContextKey.Scheme.bindTo(contextKeyService);
this._filenameKey = ResourceContextKey.Filename.bindTo(contextKeyService);
this._langIdKey = ResourceContextKey.LangId.bindTo(contextKeyService);
this._resourceKey = ResourceContextKey.Resource.bindTo(contextKeyService);
this._extensionKey = ResourceContextKey.Extension.bindTo(contextKeyService);
this._hasResource = ResourceContextKey.HasResource.bindTo(contextKeyService);
this._isFileSystemResource = ResourceContextKey.IsFileSystemResource.bindTo(contextKeyService);
this._schemeKey = ResourceContextKey.Scheme.bindTo(this._contextKeyService);
this._filenameKey = ResourceContextKey.Filename.bindTo(this._contextKeyService);
this._langIdKey = ResourceContextKey.LangId.bindTo(this._contextKeyService);
this._resourceKey = ResourceContextKey.Resource.bindTo(this._contextKeyService);
this._extensionKey = ResourceContextKey.Extension.bindTo(this._contextKeyService);
this._hasResource = ResourceContextKey.HasResource.bindTo(this._contextKeyService);
this._isFileSystemResource = ResourceContextKey.IsFileSystemResource.bindTo(this._contextKeyService);
this._register(_fileService.onDidChangeFileSystemProviderRegistrations(() => {
const resource = this._resourceKey.get();
......@@ -66,24 +66,28 @@ export class ResourceContextKey extends Disposable implements IContextKey<URI> {
set(value: URI | null) {
if (!ResourceContextKey._uriEquals(this._resourceKey.get(), value)) {
this._resourceKey.set(value);
this._schemeKey.set(value ? value.scheme : null);
this._filenameKey.set(value ? basename(value) : null);
this._langIdKey.set(value ? this._modeService.getModeIdByFilepathOrFirstLine(value) : null);
this._extensionKey.set(value ? extname(value) : null);
this._hasResource.set(!!value);
this._isFileSystemResource.set(value ? this._fileService.canHandleResource(value) : false);
this._contextKeyService.bufferChangeEvents(() => {
this._resourceKey.set(value);
this._schemeKey.set(value ? value.scheme : null);
this._filenameKey.set(value ? basename(value) : null);
this._langIdKey.set(value ? this._modeService.getModeIdByFilepathOrFirstLine(value) : null);
this._extensionKey.set(value ? extname(value) : null);
this._hasResource.set(!!value);
this._isFileSystemResource.set(value ? this._fileService.canHandleResource(value) : false);
});
}
}
reset(): void {
this._schemeKey.reset();
this._langIdKey.reset();
this._resourceKey.reset();
this._langIdKey.reset();
this._extensionKey.reset();
this._hasResource.reset();
this._isFileSystemResource.reset();
this._contextKeyService.bufferChangeEvents(() => {
this._schemeKey.reset();
this._langIdKey.reset();
this._resourceKey.reset();
this._langIdKey.reset();
this._extensionKey.reset();
this._hasResource.reset();
this._isFileSystemResource.reset();
});
}
get(): URI | undefined {
......
......@@ -755,10 +755,12 @@ export class HistoryService extends Disposable implements IHistoryService {
private readonly canReopenClosedEditorContextKey = (new RawContextKey<boolean>('canReopenClosedEditor', false)).bindTo(this.contextKeyService);
private updateContextKeys(): void {
this.canNavigateBackContextKey.set(this.navigationStack.length > 0 && this.navigationStackIndex > 0);
this.canNavigateForwardContextKey.set(this.navigationStack.length > 0 && this.navigationStackIndex < this.navigationStack.length - 1);
this.canNavigateToLastEditLocationContextKey.set(!!this.lastEditLocation);
this.canReopenClosedEditorContextKey.set(this.recentlyClosedEditors.length > 0);
this.contextKeyService.bufferChangeEvents(() => {
this.canNavigateBackContextKey.set(this.navigationStack.length > 0 && this.navigationStackIndex > 0);
this.canNavigateForwardContextKey.set(this.navigationStack.length > 0 && this.navigationStackIndex < this.navigationStack.length - 1);
this.canNavigateToLastEditLocationContextKey.set(!!this.lastEditLocation);
this.canReopenClosedEditorContextKey.set(this.recentlyClosedEditors.length > 0);
});
}
//#endregion
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册