This commit is contained in:
Sandeep Somavarapu 2022-10-20 11:56:29 +02:00 committed by GitHub
parent 929c645c9a
commit 10bbedca57
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 39 deletions

View file

@ -21,7 +21,6 @@ const HistoryNavigationForwardsEnablementContext = 'historyNavigationForwardsEna
const HistoryNavigationBackwardsEnablementContext = 'historyNavigationBackwardsEnabled'; const HistoryNavigationBackwardsEnablementContext = 'historyNavigationBackwardsEnabled';
export interface IHistoryNavigationContext extends IDisposable { export interface IHistoryNavigationContext extends IDisposable {
scopedContextKeyService: IContextKeyService;
historyNavigationForwardsEnablement: IContextKey<boolean>; historyNavigationForwardsEnablement: IContextKey<boolean>;
historyNavigationBackwardsEnablement: IContextKey<boolean>; historyNavigationBackwardsEnablement: IContextKey<boolean>;
} }
@ -29,14 +28,13 @@ export interface IHistoryNavigationContext extends IDisposable {
let lastFocusedWidget: IHistoryNavigationWidget | undefined = undefined; let lastFocusedWidget: IHistoryNavigationWidget | undefined = undefined;
const widgets: IHistoryNavigationWidget[] = []; const widgets: IHistoryNavigationWidget[] = [];
export function registerAndCreateHistoryNavigationContext(contextKeyService: IContextKeyService, widget: IHistoryNavigationWidget): IHistoryNavigationContext { export function registerAndCreateHistoryNavigationContext(scopedContextKeyService: IContextKeyService, widget: IHistoryNavigationWidget): IHistoryNavigationContext {
if (widgets.includes(widget)) { if (widgets.includes(widget)) {
throw new Error('Cannot register the same widget multiple times'); throw new Error('Cannot register the same widget multiple times');
} }
widgets.push(widget); widgets.push(widget);
const disposableStore = new DisposableStore(); const disposableStore = new DisposableStore();
const scopedContextKeyService = disposableStore.add(contextKeyService.createScoped(widget.element));
const historyNavigationWidgetFocus = new RawContextKey<boolean>(HistoryNavigationWidgetFocusContext, false).bindTo(scopedContextKeyService); const historyNavigationWidgetFocus = new RawContextKey<boolean>(HistoryNavigationWidgetFocusContext, false).bindTo(scopedContextKeyService);
const historyNavigationForwardsEnablement = new RawContextKey<boolean>(HistoryNavigationForwardsEnablementContext, true).bindTo(scopedContextKeyService); const historyNavigationForwardsEnablement = new RawContextKey<boolean>(HistoryNavigationForwardsEnablementContext, true).bindTo(scopedContextKeyService);
const historyNavigationBackwardsEnablement = new RawContextKey<boolean>(HistoryNavigationBackwardsEnablementContext, true).bindTo(scopedContextKeyService); const historyNavigationBackwardsEnablement = new RawContextKey<boolean>(HistoryNavigationBackwardsEnablementContext, true).bindTo(scopedContextKeyService);
@ -66,7 +64,6 @@ export function registerAndCreateHistoryNavigationContext(contextKeyService: ICo
})); }));
return { return {
scopedContextKeyService,
historyNavigationForwardsEnablement, historyNavigationForwardsEnablement,
historyNavigationBackwardsEnablement, historyNavigationBackwardsEnablement,
dispose() { dispose() {
@ -81,7 +78,8 @@ export class ContextScopedHistoryInputBox extends HistoryInputBox {
@IContextKeyService contextKeyService: IContextKeyService @IContextKeyService contextKeyService: IContextKeyService
) { ) {
super(container, contextViewProvider, options); super(container, contextViewProvider, options);
this._register(registerAndCreateHistoryNavigationContext(contextKeyService, this)); const scopedContextKeyService = this._register(contextKeyService.createScoped(this.element));
this._register(registerAndCreateHistoryNavigationContext(scopedContextKeyService, this));
} }
} }
@ -92,7 +90,8 @@ export class ContextScopedFindInput extends FindInput {
@IContextKeyService contextKeyService: IContextKeyService @IContextKeyService contextKeyService: IContextKeyService
) { ) {
super(container, contextViewProvider, options); super(container, contextViewProvider, options);
this._register(registerAndCreateHistoryNavigationContext(contextKeyService, this.inputBox)); const scopedContextKeyService = this._register(contextKeyService.createScoped(this.inputBox.element));
this._register(registerAndCreateHistoryNavigationContext(scopedContextKeyService, this.inputBox));
} }
} }
@ -102,7 +101,8 @@ export class ContextScopedReplaceInput extends ReplaceInput {
@IContextKeyService contextKeyService: IContextKeyService, showReplaceOptions: boolean = false @IContextKeyService contextKeyService: IContextKeyService, showReplaceOptions: boolean = false
) { ) {
super(container, contextViewProvider, showReplaceOptions, options); super(container, contextViewProvider, showReplaceOptions, options);
this._register(registerAndCreateHistoryNavigationContext(contextKeyService, this.inputBox)); const scopedContextKeyService = this._register(contextKeyService.createScoped(this.inputBox.element));
this._register(registerAndCreateHistoryNavigationContext(scopedContextKeyService, this.inputBox));
} }
} }

View file

@ -24,7 +24,7 @@ import { Extensions as ViewContainerExtensions, IView, IViewDescriptorService, V
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { assertIsDefined } from 'vs/base/common/types'; import { assertIsDefined } from 'vs/base/common/types';
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { MenuId, Action2, IAction2Options, IMenuService, SubmenuItemAction } from 'vs/platform/actions/common/actions'; import { MenuId, Action2, IAction2Options, SubmenuItemAction } from 'vs/platform/actions/common/actions';
import { createActionViewItem } from 'vs/platform/actions/browser/menuEntryActionViewItem'; import { createActionViewItem } from 'vs/platform/actions/browser/menuEntryActionViewItem';
import { parseLinkedText } from 'vs/base/common/linkedText'; import { parseLinkedText } from 'vs/base/common/linkedText';
import { IOpenerService } from 'vs/platform/opener/common/opener'; import { IOpenerService } from 'vs/platform/opener/common/opener';
@ -149,27 +149,6 @@ class ViewWelcomeController {
} }
} }
class ViewMenuActions extends CompositeMenuActions {
constructor(
element: HTMLElement,
viewId: string,
menuId: MenuId,
contextMenuId: MenuId,
donotForwardArgs: boolean,
@IContextKeyService contextKeyService: IContextKeyService,
@IMenuService menuService: IMenuService,
@IViewDescriptorService viewDescriptorService: IViewDescriptorService,
) {
const scopedContextKeyService = contextKeyService.createScoped(element);
scopedContextKeyService.createKey('view', viewId);
const viewLocationKey = scopedContextKeyService.createKey('viewLocation', ViewContainerLocationToString(viewDescriptorService.getViewLocationById(viewId)!));
super(menuId, contextMenuId, { shouldForwardArgs: !donotForwardArgs }, scopedContextKeyService, menuService);
this._register(scopedContextKeyService);
this._register(Event.filter(viewDescriptorService.onDidChangeLocation, e => e.views.some(view => view.id === viewId))(() => viewLocationKey.set(ViewContainerLocationToString(viewDescriptorService.getViewLocationById(viewId)!))));
}
}
export abstract class ViewPane extends Pane implements IView { export abstract class ViewPane extends Pane implements IView {
private static readonly AlwaysShowActionsConfig = 'workbench.view.alwaysShowHeaderActions'; private static readonly AlwaysShowActionsConfig = 'workbench.view.alwaysShowHeaderActions';
@ -202,7 +181,7 @@ export abstract class ViewPane extends Pane implements IView {
return this._titleDescription; return this._titleDescription;
} }
readonly menuActions: ViewMenuActions; readonly menuActions: CompositeMenuActions;
private progressBar!: ProgressBar; private progressBar!: ProgressBar;
private progressIndicator!: IProgressIndicator; private progressIndicator!: IProgressIndicator;
@ -220,6 +199,8 @@ export abstract class ViewPane extends Pane implements IView {
private viewWelcomeDisposable: IDisposable = Disposable.None; private viewWelcomeDisposable: IDisposable = Disposable.None;
private viewWelcomeController: ViewWelcomeController; private viewWelcomeController: ViewWelcomeController;
protected readonly scopedContextKeyService: IContextKeyService;
constructor( constructor(
options: IViewPaneOptions, options: IViewPaneOptions,
@IKeybindingService protected keybindingService: IKeybindingService, @IKeybindingService protected keybindingService: IKeybindingService,
@ -239,7 +220,12 @@ export abstract class ViewPane extends Pane implements IView {
this._titleDescription = options.titleDescription; this._titleDescription = options.titleDescription;
this.showActionsAlways = !!options.showActionsAlways; this.showActionsAlways = !!options.showActionsAlways;
this.menuActions = this._register(this.instantiationService.createInstance(ViewMenuActions, this.element, this.id, options.titleMenuId || MenuId.ViewTitle, MenuId.ViewTitleContext, !!options.donotForwardArgs)); this.scopedContextKeyService = this._register(contextKeyService.createScoped(this.element));
this.scopedContextKeyService.createKey('view', this.id);
const viewLocationKey = this.scopedContextKeyService.createKey('viewLocation', ViewContainerLocationToString(viewDescriptorService.getViewLocationById(this.id)!));
this._register(Event.filter(viewDescriptorService.onDidChangeLocation, e => e.views.some(view => view.id === this.id))(() => viewLocationKey.set(ViewContainerLocationToString(viewDescriptorService.getViewLocationById(this.id)!))));
this.menuActions = this._register(this.instantiationService.createChild(new ServiceCollection([IContextKeyService, this.scopedContextKeyService])).createInstance(CompositeMenuActions, options.titleMenuId ?? MenuId.ViewTitle, MenuId.ViewTitleContext, { shouldForwardArgs: !options.donotForwardArgs }));
this._register(this.menuActions.onDidChange(() => this.updateActions())); this._register(this.menuActions.onDidChange(() => this.updateActions()));
this.viewWelcomeController = new ViewWelcomeController(this.id, contextKeyService); this.viewWelcomeController = new ViewWelcomeController(this.id, contextKeyService);
@ -680,9 +666,7 @@ export abstract class FilterViewPane extends ViewPane {
@ITelemetryService telemetryService: ITelemetryService, @ITelemetryService telemetryService: ITelemetryService,
) { ) {
super(options, keybindingService, contextMenuService, configurationService, contextKeyService, viewDescriptorService, instantiationService, openerService, themeService, telemetryService); super(options, keybindingService, contextMenuService, configurationService, contextKeyService, viewDescriptorService, instantiationService, openerService, themeService, telemetryService);
const scopedContextKeyService = this._register(contextKeyService.createScoped(this.element)); this.filterWidget = this._register(instantiationService.createChild(new ServiceCollection([IContextKeyService, this.scopedContextKeyService])).createInstance(FilterWidget, options.filterOptions));
scopedContextKeyService.createKey('view', options.id);
this.filterWidget = this._register(instantiationService.createChild(new ServiceCollection([IContextKeyService, scopedContextKeyService])).createInstance(FilterWidget, options.filterOptions));
} }
override getFilterWidget(): FilterWidget { override getFilterWidget(): FilterWidget {

View file

@ -418,12 +418,13 @@ export class ContextScopedSuggestEnabledInputWithHistory extends SuggestEnabledI
} }
protected override getScopedContextKeyService(contextKeyService: IContextKeyService) { protected override getScopedContextKeyService(contextKeyService: IContextKeyService) {
const scopedContextKeyService = this._register(contextKeyService.createScoped(this.element));
this.historyContext = this._register(registerAndCreateHistoryNavigationContext( this.historyContext = this._register(registerAndCreateHistoryNavigationContext(
contextKeyService, scopedContextKeyService,
this, this,
)); ));
return this.historyContext.scopedContextKeyService; return scopedContextKeyService;
} }
} }

View file

@ -623,14 +623,14 @@ export class Repl extends FilterViewPane implements IHistoryNavigationWidget {
this.replInputContainer = dom.append(container, $('.repl-input-wrapper')); this.replInputContainer = dom.append(container, $('.repl-input-wrapper'));
dom.append(this.replInputContainer, $('.repl-input-chevron' + ThemeIcon.asCSSSelector(debugConsoleEvaluationPrompt))); dom.append(this.replInputContainer, $('.repl-input-chevron' + ThemeIcon.asCSSSelector(debugConsoleEvaluationPrompt)));
const { scopedContextKeyService, historyNavigationBackwardsEnablement, historyNavigationForwardsEnablement } = this._register(registerAndCreateHistoryNavigationContext(this.contextKeyService, this)); const { historyNavigationBackwardsEnablement, historyNavigationForwardsEnablement } = this._register(registerAndCreateHistoryNavigationContext(this.scopedContextKeyService, this));
this.setHistoryNavigationEnablement = enabled => { this.setHistoryNavigationEnablement = enabled => {
historyNavigationBackwardsEnablement.set(enabled); historyNavigationBackwardsEnablement.set(enabled);
historyNavigationForwardsEnablement.set(enabled); historyNavigationForwardsEnablement.set(enabled);
}; };
CONTEXT_IN_DEBUG_REPL.bindTo(scopedContextKeyService).set(true); CONTEXT_IN_DEBUG_REPL.bindTo(this.scopedContextKeyService).set(true);
this.scopedInstantiationService = this.instantiationService.createChild(new ServiceCollection([IContextKeyService, scopedContextKeyService])); this.scopedInstantiationService = this.instantiationService.createChild(new ServiceCollection([IContextKeyService, this.scopedContextKeyService]));
const options = getSimpleEditorOptions(); const options = getSimpleEditorOptions();
options.readOnly = true; options.readOnly = true;
options.suggest = { showStatusBar: true }; options.suggest = { showStatusBar: true };