mirror of
https://github.com/microsoft/vscode.git
synced 2026-09-26 09:45:54 +01:00
always create a new menu for the current context service, always create a new context service when creating an editor, #10075
This commit is contained in:
@@ -76,7 +76,7 @@ export class StandaloneEditor extends CodeEditorWidget implements IStandaloneCod
|
||||
@IContextViewService contextViewService: IContextViewService
|
||||
) {
|
||||
options = options || {};
|
||||
super(domElement, options, instantiationService, codeEditorService, commandService, contextKeyService.createScoped(domElement), telemetryService);
|
||||
super(domElement, options, instantiationService, codeEditorService, commandService, contextKeyService, telemetryService);
|
||||
|
||||
if (keybindingService instanceof StandaloneKeybindingService) {
|
||||
this._standaloneKeybindingService = keybindingService;
|
||||
|
||||
@@ -15,7 +15,6 @@ import {StyleMutator} from 'vs/base/browser/styleMutator';
|
||||
import {ISashEvent, IVerticalSashLayoutProvider, Sash} from 'vs/base/browser/ui/sash/sash';
|
||||
import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation';
|
||||
import {IContextKeyService} from 'vs/platform/contextkey/common/contextkey';
|
||||
import {ServiceCollection} from 'vs/platform/instantiation/common/serviceCollection';
|
||||
import {DefaultConfig} from 'vs/editor/common/config/defaultConfig';
|
||||
import {Range} from 'vs/editor/common/core/range';
|
||||
import * as editorCommon from 'vs/editor/common/editorCommon';
|
||||
@@ -357,7 +356,6 @@ export class DiffEditorWidget extends EventEmitter implements editorBrowser.IDif
|
||||
}
|
||||
|
||||
private _createLeftHandSideEditor(options: editorCommon.IDiffEditorOptions, instantiationService: IInstantiationService): void {
|
||||
instantiationService = instantiationService.createChild(new ServiceCollection([IContextKeyService, this._contextKeyService.createScoped(this._originalDomNode)]));
|
||||
this.originalEditor = instantiationService.createInstance(CodeEditorWidget, this._originalDomNode, this._adjustOptionsForLeftHandSide(options, this._originalIsEditable));
|
||||
this._toDispose.push(this.originalEditor.addBulkListener2((events) => this._onOriginalEditorEvents(events)));
|
||||
this._toDispose.push(this.addEmitter2(this.originalEditor));
|
||||
|
||||
@@ -29,7 +29,7 @@ export class EmbeddedCodeEditorWidget extends CodeEditorWidget {
|
||||
@IContextKeyService contextKeyService: IContextKeyService,
|
||||
@ITelemetryService telemetryService: ITelemetryService
|
||||
) {
|
||||
super(domElement, parentEditor.getRawConfiguration(), instantiationService, codeEditorService, commandService, contextKeyService.createScoped(domElement), telemetryService);
|
||||
super(domElement, parentEditor.getRawConfiguration(), instantiationService, codeEditorService, commandService, contextKeyService, telemetryService);
|
||||
|
||||
this._parentEditor = parentEditor;
|
||||
this._overwriteOptions = options;
|
||||
|
||||
@@ -125,7 +125,7 @@ export abstract class CommonCodeEditor extends EventEmitter implements editorCom
|
||||
|
||||
constructor(
|
||||
domElement: IContextKeyServiceTarget,
|
||||
options:editorCommon.IEditorOptions,
|
||||
options: editorCommon.IEditorOptions,
|
||||
instantiationService: IInstantiationService,
|
||||
codeEditorService: ICodeEditorService,
|
||||
commandService: ICommandService,
|
||||
@@ -145,7 +145,7 @@ export abstract class CommonCodeEditor extends EventEmitter implements editorCom
|
||||
this._lifetimeDispose = [];
|
||||
|
||||
this._commandService = commandService;
|
||||
this._contextKeyService = contextKeyService;
|
||||
this._contextKeyService = contextKeyService.createScoped(this.domElement);
|
||||
this._editorIdContextKey = this._contextKeyService.createKey('editorId', this.getId());
|
||||
this._editorFocusContextKey = EditorContextKeys.Focus.bindTo(this._contextKeyService);
|
||||
this._editorTabMovesFocusKey = EditorContextKeys.TabMovesFocus.bindTo(this._contextKeyService);
|
||||
|
||||
@@ -4164,6 +4164,28 @@ export var EditorType = {
|
||||
IDiffEditor: 'vs.editor.IDiffEditor'
|
||||
};
|
||||
|
||||
/**
|
||||
*@internal
|
||||
*/
|
||||
export function isCommonCodeEditor(thing: any): thing is ICommonCodeEditor {
|
||||
if (thing && typeof (<ICommonCodeEditor>thing).getEditorType === 'function') {
|
||||
return (<ICommonCodeEditor>thing).getEditorType() === EditorType.ICodeEditor;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*@internal
|
||||
*/
|
||||
export function isCommonDiffEditor(thing: any): thing is ICommonDiffEditor {
|
||||
if (thing && typeof (<ICommonDiffEditor>thing).getEditorType === 'function') {
|
||||
return (<ICommonDiffEditor>thing).getEditorType() === EditorType.ICodeEditor;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
|
||||
@@ -15,6 +15,7 @@ import DOM = require('vs/base/browser/dom');
|
||||
import {TPromise} from 'vs/base/common/winjs.base';
|
||||
import {BaseEditor, IEditorInputActionContext} from 'vs/workbench/browser/parts/editor/baseEditor';
|
||||
import {RunOnceScheduler} from 'vs/base/common/async';
|
||||
import {isCommonCodeEditor, isCommonDiffEditor} from 'vs/editor/common/editorCommon';
|
||||
import arrays = require('vs/base/common/arrays');
|
||||
import {IEditorStacksModel, IEditorGroup, IEditorIdentifier, EditorInput, IWorkbenchEditorConfiguration, IStacksModelChangeEvent, getResource} from 'vs/workbench/common/editor';
|
||||
import {EventType as BaseEventType} from 'vs/base/common/events';
|
||||
@@ -34,7 +35,7 @@ import {IContextKeyService} from 'vs/platform/contextkey/common/contextkey';
|
||||
import {CloseEditorsInGroupAction, SplitEditorAction, CloseEditorAction, KeepEditorAction, CloseOtherEditorsInGroupAction, CloseRightEditorsInGroupAction, ShowEditorsInGroupAction} from 'vs/workbench/browser/parts/editor/editorActions';
|
||||
import {IDisposable, dispose} from 'vs/base/common/lifecycle';
|
||||
import {createActionItem, fillInActions} from 'vs/platform/actions/browser/menuItemActionItem';
|
||||
import {IMenuService, IMenu, MenuId} from 'vs/platform/actions/common/actions';
|
||||
import {IMenuService, MenuId} from 'vs/platform/actions/common/actions';
|
||||
import {ResourceContextKey} from 'vs/platform/actions/common/resourceContextKey';
|
||||
|
||||
export interface IToolbarActions {
|
||||
@@ -86,8 +87,7 @@ export abstract class TitleControl implements ITitleAreaControl {
|
||||
private refreshScheduled: boolean;
|
||||
|
||||
private resourceContext: ResourceContextKey;
|
||||
|
||||
private contributedTitleBarMenu: IMenu;
|
||||
private disposeOnEditorActions: IDisposable[] = [];
|
||||
|
||||
constructor(
|
||||
@IContextMenuService protected contextMenuService: IContextMenuService,
|
||||
@@ -113,10 +113,6 @@ export abstract class TitleControl implements ITitleAreaControl {
|
||||
|
||||
this.resourceContext = instantiationService.createInstance(ResourceContextKey);
|
||||
|
||||
this.contributedTitleBarMenu = this.menuService.createMenu(MenuId.EditorTitle, this.contextKeyService);
|
||||
this.toDispose.push(this.contributedTitleBarMenu);
|
||||
this.toDispose.push(this.contributedTitleBarMenu.onDidChange(e => this.update()));
|
||||
|
||||
this.initActions();
|
||||
this.registerListeners();
|
||||
}
|
||||
@@ -319,7 +315,17 @@ export abstract class TitleControl implements ITitleAreaControl {
|
||||
secondary.push(...editorInputActions.secondary);
|
||||
|
||||
// MenuItems
|
||||
fillInActions(this.contributedTitleBarMenu, { primary, secondary });
|
||||
// TODO This isn't very proper but needed as we have failed to
|
||||
// use the correct context key service per editor only once. Don't
|
||||
// take this code as sample of how to work with menus
|
||||
this.disposeOnEditorActions = dispose(this.disposeOnEditorActions);
|
||||
const widget = control.getControl();
|
||||
const codeEditor = isCommonCodeEditor(widget) && widget || isCommonDiffEditor(widget) && widget.getModifiedEditor();
|
||||
const scopedContextKeyService = codeEditor && codeEditor.invokeWithinContext(accessor => accessor.get(IContextKeyService)) || this.contextKeyService;
|
||||
const titleBarMenu = this.menuService.createMenu(MenuId.EditorTitle, scopedContextKeyService);
|
||||
this.disposeOnEditorActions.push(titleBarMenu, titleBarMenu.onDidChange(_ => this.update()));
|
||||
|
||||
fillInActions(titleBarMenu, { primary, secondary });
|
||||
}
|
||||
|
||||
return { primary, secondary };
|
||||
|
||||
Reference in New Issue
Block a user