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

grid - adopt delegating editor service

上级 540a57ef
......@@ -13,7 +13,7 @@ import { Action, IAction } from 'vs/base/common/actions';
import { onUnexpectedError } from 'vs/base/common/errors';
import * as types from 'vs/base/common/types';
import { IDiffEditor } from 'vs/editor/browser/editorBrowser';
import { IDiffEditorOptions, IEditorOptions } from 'vs/editor/common/config/editorOptions';
import { IDiffEditorOptions, IEditorOptions as ICodeEditorOptions } from 'vs/editor/common/config/editorOptions';
import { BaseTextEditor, IEditorConfiguration } from 'vs/workbench/browser/parts/editor/textEditor';
import { TextEditorOptions, EditorInput, EditorOptions, TEXT_DIFF_EDITOR_ID, IEditorInputFactoryRegistry, Extensions as EditorInputExtensions } from 'vs/workbench/common/editor';
import { ResourceEditorInput } from 'vs/workbench/common/editor/resourceEditorInput';
......@@ -27,7 +27,7 @@ import { IStorageService } from 'vs/platform/storage/common/storage';
import { ITextResourceConfigurationService } from 'vs/editor/common/services/resourceConfiguration';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
import { IWorkbenchEditorService, DelegatingWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService';
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
......@@ -38,6 +38,8 @@ import { Registry } from 'vs/platform/registry/common/platform';
import URI from 'vs/base/common/uri';
import { getCodeOrDiffEditor } from 'vs/editor/browser/services/codeEditorService';
import { once } from 'vs/base/common/event';
import { DelegatingWorkbenchEditorService } from 'vs/workbench/services/editor/browser/nextEditorService';
import { INextEditorGroup } from 'vs/workbench/services/group/common/nextEditorGroupsService';
/**
* The text editor that leverages the diff text editor for the editing experience.
......@@ -81,7 +83,7 @@ export class TextDiffEditor extends BaseTextEditor {
return nls.localize('textDiffEditor', "Text Diff Editor");
}
public createEditorControl(parent: HTMLElement, configuration: IEditorOptions): IDiffEditor {
public createEditorControl(parent: HTMLElement, configuration: ICodeEditorOptions): IDiffEditor {
// Actions
this.nextDiffAction = new NavigateAction(this, true);
......@@ -91,10 +93,10 @@ export class TextDiffEditor extends BaseTextEditor {
// Support navigation within the diff editor by overriding the editor service within
const delegatingEditorService = this.instantiationService.createInstance(DelegatingWorkbenchEditorService);
delegatingEditorService.setEditorOpenHandler((input: EditorInput, options?: EditorOptions, arg3?: any) => {
delegatingEditorService.setEditorOpenHandler((group: INextEditorGroup, input: EditorInput, options?: EditorOptions) => {
// Check if arg4 is a position argument that differs from this editors position
if (types.isUndefinedOrNull(arg3) || arg3 === false || arg3 === this.position) {
// Check if target group is same as this editor ones
if (group.id === this.position) {
const activeDiffInput = <DiffEditorInput>this.input;
if (input && options && activeDiffInput) {
......@@ -251,7 +253,7 @@ export class TextDiffEditor extends BaseTextEditor {
return false;
}
protected computeConfiguration(configuration: IEditorConfiguration): IEditorOptions {
protected computeConfiguration(configuration: IEditorConfiguration): ICodeEditorOptions {
const editorConfiguration = super.computeConfiguration(configuration);
// Handle diff editor specially by merging in diffEditor configuration
......@@ -262,7 +264,7 @@ export class TextDiffEditor extends BaseTextEditor {
return editorConfiguration;
}
protected getConfigurationOverrides(): IEditorOptions {
protected getConfigurationOverrides(): ICodeEditorOptions {
const options: IDiffEditorOptions = super.getConfigurationOverrides();
options.readOnly = this.isReadOnly();
......
......@@ -532,6 +532,10 @@ export class NextEditorGroupView extends Themable implements INextEditorGroupVie
return this._group.activeEditor;
}
get previewEditor(): EditorInput {
return this._group.previewEditor;
}
isPinned(editor: EditorInput): boolean {
return this._group.isPinned(editor);
}
......
......@@ -23,10 +23,8 @@ import { IExtensionService } from 'vs/workbench/services/extensions/common/exten
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
import { EditorInput, EditorOptions } from 'vs/workbench/common/editor';
import { BaseEditor } from 'vs/workbench/browser/parts/editor/baseEditor';
import { IWorkbenchEditorService, DelegatingWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { ViewsRegistry, ViewLocation, IViewDescriptor } from 'vs/workbench/common/views';
......@@ -34,6 +32,10 @@ import { IContextMenuService } from 'vs/platform/contextview/browser/contextView
import { Disposable } from 'vs/base/common/lifecycle';
import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
import { IPartService } from 'vs/workbench/services/part/common/partService';
import { DelegatingWorkbenchEditorService } from 'vs/workbench/services/editor/browser/nextEditorService';
import { INextEditorGroup, INextEditorGroupsService } from 'vs/workbench/services/group/common/nextEditorGroupsService';
import { INextEditorService } from 'vs/workbench/services/editor/common/nextEditorService';
import { IEditorInput, IEditorOptions } from 'vs/platform/editor/common/editor';
export class ExplorerViewletViewsContribution extends Disposable implements IWorkbenchContribution {
......@@ -153,8 +155,8 @@ export class ExplorerViewlet extends PersistentViewsViewlet implements IExplorer
@ITelemetryService telemetryService: ITelemetryService,
@IWorkspaceContextService protected contextService: IWorkspaceContextService,
@IStorageService protected storageService: IStorageService,
@IEditorGroupService private editorGroupService: IEditorGroupService,
@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
@INextEditorService private nextEditorService: INextEditorService,
@INextEditorGroupsService private nextEditorGroupService: INextEditorGroupsService,
@IConfigurationService private configurationService: IConfigurationService,
@IInstantiationService protected instantiationService: IInstantiationService,
@IContextKeyService contextKeyService: IContextKeyService,
......@@ -188,20 +190,17 @@ export class ExplorerViewlet extends PersistentViewsViewlet implements IExplorer
// We try to be smart and only use the delay if we recognize that the user action is likely to cause
// a new entry in the opened editors view.
const delegatingEditorService = this.instantiationService.createInstance(DelegatingWorkbenchEditorService);
delegatingEditorService.setEditorOpenHandler((input: EditorInput, options?: EditorOptions, arg3?: any) => {
delegatingEditorService.setEditorOpenHandler((group: INextEditorGroup, editor: IEditorInput, options?: IEditorOptions) => {
let openEditorsView = this.getOpenEditorsView();
if (openEditorsView) {
let delay = 0;
const config = this.configurationService.getValue<IFilesConfiguration>();
// No need to delay if preview is disabled
const delayEditorOpeningInOpenedEditors = !!config.workbench.editor.enablePreview;
if (delayEditorOpeningInOpenedEditors && (arg3 === false /* not side by side */ || typeof arg3 !== 'number' /* no explicit position */)) {
const activeGroup = this.editorGroupService.getStacksModel().activeGroup;
if (!activeGroup || !activeGroup.previewEditor) {
delay = 250; // a new editor entry is likely because there is either no group or no preview in group
}
const delayEditorOpeningInOpenedEditors = !!config.workbench.editor.enablePreview; // No need to delay if preview is disabled
const activeGroup = this.nextEditorGroupService.activeGroup;
if (delayEditorOpeningInOpenedEditors && group === activeGroup && !activeGroup.previewEditor) {
delay = 250; // a new editor entry is likely because there is either no group or no preview in group
}
openEditorsView.setStructuralRefreshDelay(delay);
......@@ -216,7 +215,7 @@ export class ExplorerViewlet extends PersistentViewsViewlet implements IExplorer
return editor;
};
return this.editorService.openEditor(input, options, arg3).then(onSuccessOrError, onSuccessOrError);
return this.nextEditorService.openEditor(editor, options, group).then(onSuccessOrError, onSuccessOrError);
});
const explorerInstantiator = this.instantiationService.createChild(new ServiceCollection([IWorkbenchEditorService, delegatingEditorService]));
......
......@@ -172,7 +172,7 @@ export class NextEditorService extends Disposable implements INextEditorService
const editorOptions = this.toOptions(optionsOrGroup as IEditorOptions);
const targetGroup = this.findTargetGroup(editor, editorOptions, group);
return targetGroup.openEditor(editor, editorOptions).then(() => targetGroup.activeControl);
return this.doOpenEditor(targetGroup, editor, editorOptions);
}
// Throw error for well known foreign resources (such as a http link) (TODO@ben remove me after this has been adopted)
......@@ -191,12 +191,16 @@ export class NextEditorService extends Disposable implements INextEditorService
const editorOptions = TextEditorOptions.from(textInput);
const targetGroup = this.findTargetGroup(typedInput, editorOptions, optionsOrGroup as INextEditorGroup | GroupIdentifier);
return targetGroup.openEditor(typedInput, editorOptions).then(() => targetGroup.activeControl);
return this.doOpenEditor(targetGroup, typedInput, editorOptions);
}
return TPromise.wrap<IEditor>(null);
}
protected doOpenEditor(group: INextEditorGroup, editor: IEditorInput, options?: IEditorOptions): Thenable<IEditor> {
return group.openEditor(editor, options).then(() => group.activeControl);
}
private findTargetGroup(input: IEditorInput, options?: IEditorOptions, group?: INextEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): INextEditorGroup {
let targetGroup: INextEditorGroup;
......@@ -475,4 +479,52 @@ export class NextEditorService extends Disposable implements INextEditorService
}
//#endregion
}
export interface IEditorOpenHandler {
(group: INextEditorGroup, editor: IEditorInput, options?: IEditorOptions): Thenable<IEditor>;
}
/**
* The delegating workbench editor service can be used to override the behaviour of the openEditor()
* method by providing a IEditorOpenHandler.
*/
export class DelegatingWorkbenchEditorService extends NextEditorService {
private editorOpenHandler: IEditorOpenHandler;
constructor(
@INextEditorGroupsService nextEditorGroupsService: INextEditorGroupsService,
@IUntitledEditorService untitledEditorService: IUntitledEditorService,
@IWorkspaceContextService workspaceContextService: IWorkspaceContextService,
@IInstantiationService instantiationService: IInstantiationService,
@IEnvironmentService environmentService: IEnvironmentService,
@IFileService fileService: IFileService,
@IConfigurationService configurationService: IConfigurationService
) {
super(
nextEditorGroupsService,
untitledEditorService,
workspaceContextService,
instantiationService,
environmentService,
fileService,
configurationService
);
}
setEditorOpenHandler(handler: IEditorOpenHandler): void {
this.editorOpenHandler = handler;
}
protected doOpenEditor(group: INextEditorGroup, editor: IEditorInput, options?: IEditorOptions): Thenable<IEditor> {
const handleOpen = this.editorOpenHandler ? this.editorOpenHandler(group, editor, options) : TPromise.as(void 0);
return handleOpen.then(control => {
if (control) {
return TPromise.as<IEditor>(control); // the opening was handled, so return early
}
return super.doOpenEditor(group, editor, options);
});
}
}
\ No newline at end of file
......@@ -226,6 +226,12 @@ export interface INextEditorGroup {
*/
readonly activeEditor: IEditorInput;
/**
* The editor in the group that is in preview mode if any. There can
* only ever be one editor in preview mode.
*/
readonly previewEditor: IEditorInput;
/**
* The number of opend editors in this group.
*/
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册