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

grid - maintain ViewColumn API compatibility (webview)

上级 dd5afa5b
......@@ -119,7 +119,7 @@ export class MainThreadTextEditors implements MainThreadTextEditorsShape {
options: editorOptions
};
return this._editorService.openEditor(input, this._findEditorGroup(options.position)).then(editor => {
return this._editorService.openEditor(input, findEditorGroup(this._editorGroupService, options.position)).then(editor => {
if (!editor) {
return undefined;
}
......@@ -134,31 +134,11 @@ export class MainThreadTextEditors implements MainThreadTextEditorsShape {
return this._editorService.openEditor({
resource: model.uri,
options: { preserveFocus: false }
}, this._findEditorGroup(position)).then(() => { return; });
}, findEditorGroup(this._editorGroupService, position)).then(() => { return; });
}
return undefined;
}
private _findEditorGroup(position?: EditorPosition): GroupIdentifier {
if (typeof position !== 'number') {
return ACTIVE_GROUP; // prefer active group when position is undefined
}
const groups = this._editorGroupService.groups;
let candidate = groups[position];
if (candidate) {
return candidate.id; // found direct match
}
let firstGroup = groups[0];
if (groups.length === 1 && firstGroup.count === 0) {
return firstGroup.id; // first editor should always open in first group
}
return SIDE_GROUP; // open to the side if group not found
}
$tryHideEditor(id: string): TPromise<void> {
let mainThreadEditor = this._documentsAndEditors.getEditor(id);
if (mainThreadEditor) {
......@@ -260,3 +240,23 @@ export class MainThreadTextEditors implements MainThreadTextEditorsShape {
return TPromise.as(diffEditor.getLineChanges());
}
}
export function findEditorGroup(editorGroupService: INextEditorGroupsService, position?: EditorPosition): GroupIdentifier {
if (typeof position !== 'number') {
return ACTIVE_GROUP; // prefer active group when position is undefined
}
const groups = editorGroupService.groups;
let candidate = groups[position];
if (candidate) {
return candidate.id; // found direct match
}
let firstGroup = groups[0];
if (groups.length === 1 && firstGroup.count === 0) {
return firstGroup.id; // first editor should always open in first group
}
return SIDE_GROUP; // open to the side if group not found
}
\ No newline at end of file
......@@ -14,11 +14,13 @@ import { IOpenerService } from 'vs/platform/opener/common/opener';
import { ExtHostContext, ExtHostWebviewsShape, IExtHostContext, MainContext, MainThreadWebviewsShape, WebviewPanelHandle } from 'vs/workbench/api/node/extHost.protocol';
import { WebviewEditor } from 'vs/workbench/parts/webview/electron-browser/webviewEditor';
import { WebviewEditorInput } from 'vs/workbench/parts/webview/electron-browser/webviewEditorInput';
import { IWebviewEditorService, WebviewInputOptions, WebviewReviver } from 'vs/workbench/parts/webview/electron-browser/webviewEditorService';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IWebviewEditorService, WebviewInputOptions, WebviewReviver, ICreateWebViewShowOptions } from 'vs/workbench/parts/webview/electron-browser/webviewEditorService';
import { INextEditorService } from 'vs/workbench/services/editor/common/nextEditorService';
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService';
import { INextEditorGroupsService } from 'vs/workbench/services/group/common/nextEditorGroupsService';
import { extHostNamedCustomer } from './extHostCustomers';
import { findEditorGroup } from 'vs/workbench/api/electron-browser/mainThreadEditors';
import { GroupIdentifier } from 'vs/workbench/common/editor';
@extHostNamedCustomer(MainContext.MainThreadWebviews)
export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviver {
......@@ -40,17 +42,17 @@ export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviv
constructor(
context: IExtHostContext,
@IContextKeyService contextKeyService: IContextKeyService,
@IEditorGroupService editorGroupService: IEditorGroupService,
@INextEditorGroupsService private readonly _editorGroupService: INextEditorGroupsService,
@ILifecycleService lifecycleService: ILifecycleService,
@IWorkbenchEditorService private readonly _editorService: IWorkbenchEditorService,
@INextEditorService private readonly _editorService: INextEditorService,
@IWebviewEditorService private readonly _webviewService: IWebviewEditorService,
@IOpenerService private readonly _openerService: IOpenerService,
@IExtensionService private readonly _extensionService: IExtensionService,
) {
this._proxy = context.getProxy(ExtHostContext.ExtHostWebviews);
editorGroupService.onEditorsChanged(this.onEditorsChanged, this, this._toDispose);
editorGroupService.onEditorGroupMoved(this.onEditorGroupMoved, this, this._toDispose);
_editorService.onDidActiveEditorChange(this.onActiveEditorChanged, this, this._toDispose);
_editorService.onDidVisibleEditorsChange(this.onVisibleEditorsChanged, this, this._toDispose);
this._toDispose.push(_webviewService.registerReviver(MainThreadWebviews.viewType, this));
......@@ -71,7 +73,13 @@ export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviv
options: WebviewInputOptions,
extensionLocation: UriComponents
): void {
const webview = this._webviewService.createWebview(MainThreadWebviews.viewType, title, showOptions, options, URI.revive(extensionLocation), this.createWebviewEventDelegate(handle));
const mainThreadShowOptions: ICreateWebViewShowOptions = Object.create(null);
if (showOptions) {
mainThreadShowOptions.preserveFocus = showOptions.preserveFocus;
mainThreadShowOptions.group = findEditorGroup(this._editorGroupService, showOptions.viewColumn);
}
const webview = this._webviewService.createWebview(MainThreadWebviews.viewType, title, mainThreadShowOptions, options, URI.revive(extensionLocation), this.createWebviewEventDelegate(handle));
webview.state = {
viewType: viewType,
state: undefined
......@@ -102,12 +110,14 @@ export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviv
return;
}
this._webviewService.revealWebview(webview, viewColumn, preserveFocus);
const targetGroup = this._editorGroupService.getGroup(findEditorGroup(this._editorGroupService, viewColumn));
this._webviewService.revealWebview(webview, targetGroup || this._editorGroupService.activeGroup, preserveFocus);
}
async $postMessage(handle: WebviewPanelHandle, message: any): TPromise<boolean> {
const webview = this.getWebview(handle);
const editors = this._editorService.getVisibleEditors()
const editors = this._editorService.visibleControls
.filter(e => e instanceof WebviewEditor)
.map(e => e as WebviewEditor)
.filter(e => e.input.matches(webview));
......@@ -141,7 +151,7 @@ export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviv
state = {};
}
return this._proxy.$deserializeWebviewPanel(handle, webview.state.viewType, webview.getTitle(), state, webview.group, webview.options) // TODO@grid [EXTENSIONS] adopt group identifier
return this._proxy.$deserializeWebviewPanel(handle, webview.state.viewType, webview.getTitle(), state, this.positionOfGroup(webview.group), webview.options)
.then(undefined, () => {
webview.html = MainThreadWebviews.getDeserializationFailedContents(viewType);
});
......@@ -187,8 +197,8 @@ export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviv
return webview;
}
private onEditorsChanged() {
const activeEditor = this._editorService.getActiveEditor();
private onActiveEditorChanged() {
const activeEditor = this._editorService.activeControl;
let newActiveWebview: { input: WebviewEditorInput, handle: WebviewPanelHandle } | undefined = undefined;
if (activeEditor && activeEditor.input instanceof WebviewEditorInput) {
for (const handle of map.keys(this._webviews)) {
......@@ -202,7 +212,7 @@ export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviv
if (newActiveWebview && newActiveWebview.handle === this._activeWebview) {
// Webview itself unchanged but position may have changed
this._proxy.$onDidChangeWebviewPanelViewState(newActiveWebview.handle, true, newActiveWebview.input.group); // TODO@grid [EXTENSIONS] adopt group identifier
this._proxy.$onDidChangeWebviewPanelViewState(newActiveWebview.handle, true, this.positionOfGroup(newActiveWebview.input.group));
return;
}
......@@ -210,29 +220,38 @@ export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviv
if (typeof this._activeWebview !== 'undefined') {
const oldActiveWebview = this._webviews.get(this._activeWebview);
if (oldActiveWebview) {
this._proxy.$onDidChangeWebviewPanelViewState(this._activeWebview, false, oldActiveWebview.group); // TODO@grid [EXTENSIONS] adopt group identifier
this._proxy.$onDidChangeWebviewPanelViewState(this._activeWebview, false, this.positionOfGroup(oldActiveWebview.group));
}
}
// Then for newly active
if (newActiveWebview) {
this._proxy.$onDidChangeWebviewPanelViewState(newActiveWebview.handle, true, activeEditor.group.id); // TODO@grid [EXTENSIONS] adopt in extension host
this._proxy.$onDidChangeWebviewPanelViewState(newActiveWebview.handle, true, this.positionOfGroup(activeEditor.group.id));
this._activeWebview = newActiveWebview.handle;
} else {
this._activeWebview = undefined;
}
}
private onEditorGroupMoved(): void {
for (const workbenchEditor of this._editorService.getVisibleEditors()) {
private positionOfGroup(groupId: GroupIdentifier): number {
const group = this._editorGroupService.getGroup(groupId);
return this._editorGroupService.groups.indexOf(group);
}
private onVisibleEditorsChanged(): void {
for (const workbenchEditor of this._editorService.visibleControls) {
if (!workbenchEditor.input) {
return;
}
this._webviews.forEach((input, handle) => {
if (workbenchEditor.input.matches(input) && input.group !== workbenchEditor.group.id) { // TODO@grid [EXTENSIONS] adopt group identifier
const inputPosition = this.positionOfGroup(input.group);
const editorPosition = this.positionOfGroup(workbenchEditor.group.id);
if (workbenchEditor.input.matches(input) && inputPosition !== editorPosition) {
input.updateGroup(workbenchEditor.group.id);
this._proxy.$onDidChangeWebviewPanelViewState(handle, handle === this._activeWebview, workbenchEditor.group.id);
this._proxy.$onDidChangeWebviewPanelViewState(handle, handle === this._activeWebview, editorPosition);
}
});
}
......
......@@ -8,19 +8,20 @@ import URI from 'vs/base/common/uri';
import { localize } from 'vs/nls';
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { INextEditorService } from 'vs/workbench/services/editor/common/nextEditorService';
import { Position as EditorPosition } from 'vs/platform/editor/common/editor';
import { HtmlInput, HtmlInputOptions } from '../common/htmlInput';
import { HtmlPreviewPart } from './htmlPreviewPart';
import { Registry } from 'vs/platform/registry/common/platform';
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService';
import { INextEditorGroupsService } from 'vs/workbench/services/group/common/nextEditorGroupsService';
import { IExtensionsWorkbenchService } from 'vs/workbench/parts/extensions/common/extensions';
import { IEditorRegistry, EditorDescriptor, Extensions as EditorExtensions } from 'vs/workbench/browser/editor';
import { findEditorGroup } from 'vs/workbench/api/electron-browser/mainThreadEditors';
function getActivePreviewsForResource(accessor: ServicesAccessor, resource: URI | string) {
const uri = resource instanceof URI ? resource : URI.parse(resource);
return accessor.get(IWorkbenchEditorService).getVisibleEditors()
return accessor.get(INextEditorService).visibleControls
.filter(c => c instanceof HtmlPreviewPart && c.model)
.map(e => e as HtmlPreviewPart)
.filter(e => e.model.uri.scheme === uri.scheme && e.model.uri.toString() === uri.toString());
......@@ -47,13 +48,20 @@ CommandsRegistry.registerCommand('_workbench.previewHtml', function (
let input: HtmlInput;
const editorGroupService = accessor.get(INextEditorGroupsService);
const groups = editorGroupService.groups;
// Find already opened HTML input if any
const stacks = accessor.get(IEditorGroupService).getStacksModel();
const targetGroup = stacks.groupAt(position) || stacks.activeGroup;
const targetGroup = groups[position] || editorGroupService.activeGroup;
if (targetGroup) {
const existingInput = targetGroup.getEditor(uri);
if (existingInput instanceof HtmlInput) {
input = existingInput;
const editors = targetGroup.editors;
for (let i = 0; i < editors.length; i++) {
const editor = editors[i];
const editorResource = editor.getResource();
if (editor instanceof HtmlInput && editorResource && editorResource.toString() === resource.toString()) {
input = editor;
break;
}
}
}
......@@ -72,8 +80,8 @@ CommandsRegistry.registerCommand('_workbench.previewHtml', function (
input.setName(label); // make sure to use passed in label
}
return accessor.get(IWorkbenchEditorService)
.openEditor(input, { pinned: true }, position)
return accessor.get(INextEditorService)
.openEditor(input, { pinned: true }, findEditorGroup(editorGroupService, position))
.then(editor => true);
});
......
......@@ -24,9 +24,8 @@ import { IRequestService } from 'vs/platform/request/node/request';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { addGAParameters } from 'vs/platform/telemetry/node/telemetryNodeUtils';
import { IWebviewEditorService } from 'vs/workbench/parts/webview/electron-browser/webviewEditorService';
import { INextEditorService } from 'vs/workbench/services/editor/common/nextEditorService';
import { INextEditorService, ACTIVE_GROUP } from 'vs/workbench/services/editor/common/nextEditorService';
import { KeybindingIO } from 'vs/workbench/services/keybinding/common/keybindingIO';
import { Position } from 'vs/platform/editor/common/editor';
import { WebviewEditorInput } from 'vs/workbench/parts/webview/electron-browser/webviewEditorInput';
function renderBody(
......@@ -76,12 +75,12 @@ export class ReleaseNotesManager {
if (this._currentReleaseNotes) {
this._currentReleaseNotes.setName(title);
this._currentReleaseNotes.html = html;
this._webviewEditorService.revealWebview(this._currentReleaseNotes, activeControl ? activeControl.group.id : undefined, false); // TODO@grid [EXTENSIONS] adopt group identifier
this._webviewEditorService.revealWebview(this._currentReleaseNotes, activeControl ? activeControl.group : undefined, false);
} else {
this._currentReleaseNotes = this._webviewEditorService.createWebview(
'releaseNotes',
title,
{ viewColumn: activeControl ? activeControl.group.id : Position.ONE, preserveFocus: false }, // TODO@grid [EXTENSIONS] adopt group identifier
{ group: ACTIVE_GROUP, preserveFocus: false },
{ tryRestoreScrollPosition: true, enableFindWidget: true },
undefined, {
onDidClickLink: uri => this.onDidClickLink(uri),
......
......@@ -8,20 +8,26 @@ import URI from 'vs/base/common/uri';
import { TPromise } from 'vs/base/common/winjs.base';
import { Position } from 'vs/platform/editor/common/editor';
import { IInstantiationService, createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService';
import { INextEditorService, ACTIVE_GROUP_TYPE, SIDE_GROUP_TYPE } from 'vs/workbench/services/editor/common/nextEditorService';
import { INextEditorGroupsService, IEditorGroup } from 'vs/workbench/services/group/common/nextEditorGroupsService';
import * as vscode from 'vscode';
import { WebviewEditorInput } from './webviewEditorInput';
import { GroupIdentifier } from 'vs/workbench/common/editor';
export const IWebviewEditorService = createDecorator<IWebviewEditorService>('webviewEditorService');
export interface ICreateWebViewShowOptions {
group: IEditorGroup | GroupIdentifier | ACTIVE_GROUP_TYPE | SIDE_GROUP_TYPE;
preserveFocus: boolean;
}
export interface IWebviewEditorService {
_serviceBrand: any;
createWebview(
viewType: string,
title: string,
showOptions: { viewColumn: Position, preserveFocus: boolean },
showOptions: ICreateWebViewShowOptions,
options: WebviewInputOptions,
extensionLocation: URI,
events: WebviewEvents
......@@ -37,7 +43,7 @@ export interface IWebviewEditorService {
revealWebview(
webview: WebviewEditorInput,
column: Position | null,
group: IEditorGroup,
preserveFocus: boolean
): void;
......@@ -79,33 +85,33 @@ export class WebviewEditorService implements IWebviewEditorService {
private _awaitingRevival: { input: WebviewEditorInput, resolve: (x: any) => void }[] = [];
constructor(
@IWorkbenchEditorService private readonly _editorService: IWorkbenchEditorService,
@INextEditorService private readonly _editorService: INextEditorService,
@IInstantiationService private readonly _instantiationService: IInstantiationService,
@IEditorGroupService private readonly _editorGroupService: IEditorGroupService,
@INextEditorGroupsService private readonly _editorGroupService: INextEditorGroupsService,
) { }
createWebview(
viewType: string,
title: string,
showOptions: { viewColumn: Position, preserveFocus: boolean },
showOptions: ICreateWebViewShowOptions,
options: vscode.WebviewOptions,
extensionLocation: URI,
events: WebviewEvents
): WebviewEditorInput {
const webviewInput = this._instantiationService.createInstance(WebviewEditorInput, viewType, title, options, {}, events, extensionLocation, undefined);
this._editorService.openEditor(webviewInput, { pinned: true, preserveFocus: showOptions.preserveFocus }, showOptions.viewColumn);
this._editorService.openEditor(webviewInput, { pinned: true, preserveFocus: showOptions.preserveFocus }, showOptions.group);
return webviewInput;
}
revealWebview(
webview: WebviewEditorInput,
column: Position | null,
group: IEditorGroup,
preserveFocus: boolean
): void {
if (!column || webview.group === column) { // TODO@grid [EXTENSIONS] adopt group identifier
this._editorService.openEditor(webview, { preserveFocus }, column || webview.group);
if (webview.group === group.id) {
this._editorService.openEditor(webview, { preserveFocus }, webview.group);
} else {
this._editorGroupService.moveEditor(webview, webview.group, column, { preserveFocus });
this._editorGroupService.getGroup(webview.group).moveEditor(webview, group, { preserveFocus });
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册