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

grid - NextEditorViewer wip

上级 3157d842
......@@ -21,6 +21,9 @@ import { attachProgressBarStyler } from 'vs/platform/theme/common/styler';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { editorBackground, contrastBorder } from 'vs/platform/theme/common/colorRegistry';
import { Themable, EDITOR_GROUP_HEADER_TABS_BORDER, EDITOR_GROUP_HEADER_TABS_BACKGROUND } from 'vs/workbench/common/theme';
import { NextEditorViewer } from 'vs/workbench/browser/parts/editor2/nextEditorViewer';
import { TPromise } from 'vs/base/common/winjs.base';
import { BaseEditor } from 'vs/workbench/browser/parts/editor/baseEditor';
export class NextEditorGroupView extends Themable implements IView {
......@@ -39,7 +42,7 @@ export class NextEditorGroupView extends Themable implements IView {
private titleAreaControl: ITitleAreaControl;
private progressBar: ProgressBar;
private editorContainer: HTMLElement;
private editorViewer: NextEditorViewer;
constructor(
@IInstantiationService private instantiationService: IInstantiationService,
......@@ -53,10 +56,22 @@ export class NextEditorGroupView extends Themable implements IView {
this.create();
}
openEditor(input: EditorInput, options?: EditorOptions): void {
openEditor(input: EditorInput, options?: EditorOptions): TPromise<BaseEditor> {
// Update model
// TODO@grid massage options based on context
this._group.openEditor(input, options);
this.render(this.container, Orientation.HORIZONTAL);
// Show in editor viewer
// TODO@grid only when active!
const editorOpenPromise = this.editorViewer.openEditor(input, options);
// Update title control
// TODO@grid also, wouldn't it be better if the title widget would register as listener to changes to the group and just
// refresh itself instead of having to do this from the outside?
this.titleAreaControl.refresh();
return editorOpenPromise;
}
get element(): HTMLElement {
......@@ -91,6 +106,7 @@ export class NextEditorGroupView extends Themable implements IView {
this.container.appendChild(titleContainer);
// Title widget
// TODO@grid if editor group is always bound to same context, simplify usage by passing over title container and group via ctor?
this.titleAreaControl = this._register(instantiationService.createInstance<ITitleAreaControl>(TabsTitleControl)); // TODO@grid title control choice (tabs vs no tabs)
this.titleAreaControl.create(titleContainer);
this.titleAreaControl.setContext(this._group);
......@@ -102,10 +118,13 @@ export class NextEditorGroupView extends Themable implements IView {
this.progressBar.hide();
// Editor container
this.editorContainer = document.createElement('div');
addClass(this.editorContainer, 'editor-container');
this.editorContainer.setAttribute('role', 'tabpanel');
this.container.appendChild(this.editorContainer);
const editorContainer = document.createElement('div');
addClass(editorContainer, 'editor-container');
editorContainer.setAttribute('role', 'tabpanel');
this.container.appendChild(editorContainer);
// Editor viewer
this.editorViewer = this._register(instantiationService.createInstance(NextEditorViewer, editorContainer, this._group));
// Update styles
this.updateStyles();
......@@ -130,7 +149,7 @@ export class NextEditorGroupView extends Themable implements IView {
}
render(container: HTMLElement, orientation: Orientation): void {
this.titleAreaControl.refresh(true /* instant */);
// TODO@grid implement
}
layout(size: number, orientation: Orientation): void {
......
......@@ -19,6 +19,7 @@ import { INextEditorPartService } from 'vs/workbench/services/editor/common/next
import { EditorInput, EditorOptions } from 'vs/workbench/common/editor';
import { NextEditorGroupsViewer, EditorGroupsOrientation } from 'vs/workbench/browser/parts/editor2/nextEditorGroupsViewer';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { BaseEditor } from 'vs/workbench/browser/parts/editor/baseEditor';
export class NextEditorPart extends Part implements INextEditorPartService {
......@@ -49,7 +50,7 @@ export class NextEditorPart extends Part implements INextEditorPartService {
this.initStyles();
}
openEditor(input: EditorInput, options?: EditorOptions): TPromise<void> {
openEditor(input: EditorInput, options?: EditorOptions): TPromise<BaseEditor> {
// TODO@grid arguments validation
// TODO@grid editor opening event and prevention
......@@ -60,9 +61,8 @@ export class NextEditorPart extends Part implements INextEditorPartService {
editorGroup = this.viewer.split([], EditorGroupsOrientation.HORIZONTAL);
}
editorGroup.openEditor(input, options);
return TPromise.as(void 0);
// TODO@grid should this return type offer more helper methods (close, move, whenInputSet, etc?)
return editorGroup.openEditor(input, options);
}
private initStyles(): void {
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import { Disposable } from 'vs/base/common/lifecycle';
import { EditorGroup } from 'vs/workbench/common/editor/editorStacksModel';
import { EditorInput, EditorOptions } from 'vs/workbench/common/editor';
import { TPromise } from 'vs/base/common/winjs.base';
import { BaseEditor } from 'vs/workbench/browser/parts/editor/baseEditor';
import { Registry } from 'vs/platform/registry/common/platform';
import { IEditorRegistry, Extensions as EditorExtensions } from 'vs/workbench/browser/editor';
import { format } from 'vs/base/common/strings';
import { IPartService } from 'vs/workbench/services/part/common/partService';
// import { ProgressState } from 'vs/workbench/browser/parts/editor/editorGroupsControl';
// import { INotificationActions } from 'vs/platform/notification/common/notification';
// import { isErrorWithActions } from 'vs/base/common/errors';
// import { toErrorMessage } from 'vs/base/common/errorMessage';
class ProgressMonitor {
constructor(private _token: number, private progressPromise: TPromise<void>) { }
public get token(): number {
return this._token;
}
public cancel(): void {
this.progressPromise.cancel();
}
}
export class NextEditorViewer extends Disposable {
private editorOpenToken: number;
private visibleEditor: BaseEditor;
constructor(
private container: HTMLElement,
private group: EditorGroup,
@IPartService private partService: IPartService
) {
super();
this.editorOpenToken = 0;
}
openEditor(input: EditorInput, options?: EditorOptions): TPromise<BaseEditor> {
// We need an editor descriptor for the input
const descriptor = Registry.as<IEditorRegistry>(EditorExtensions.Editors).getEditor(input);
if (!descriptor) {
return TPromise.wrapError<BaseEditor>(new Error(format('Can not find a registered editor for the input {0}', input)));
}
// Progress Monitor & Ref Counting
this.editorOpenToken++;
const editorOpenToken = this.editorOpenToken;
const monitor = new ProgressMonitor(editorOpenToken, TPromise.timeout(this.partService.isCreated() ? 800 : 3200 /* less ugly initial startup */).then(() => {
// TODO@grid progress
// this.editorGroupsControl.updateProgress(position, ProgressState.INFINITE);
}));
// Show editor
// const editor = this.doShowEditor(descriptor, input, options, [] /* ratio */, monitor);
// if (!editor) {
// return TPromise.wrap<BaseEditor>(null); // canceled or other error
// }
// // Set input to editor
// const inputPromise = this.doSetInput(editor, input, options, monitor);
return TPromise.as(void 0); /* inputPromise;*/
}
}
\ No newline at end of file
......@@ -8,6 +8,7 @@
import { createDecorator, ServiceIdentifier } from 'vs/platform/instantiation/common/instantiation';
import { EditorInput, EditorOptions } from 'vs/workbench/common/editor';
import { TPromise } from 'vs/base/common/winjs.base';
import { BaseEditor } from 'vs/workbench/browser/parts/editor/baseEditor';
export const INextEditorPartService = createDecorator<INextEditorPartService>('nextEditorPartService');
......@@ -15,5 +16,5 @@ export interface INextEditorPartService {
_serviceBrand: ServiceIdentifier<any>;
openEditor(input: EditorInput, options?: EditorOptions): TPromise<void>;
openEditor(input: EditorInput, options?: EditorOptions): TPromise<BaseEditor>;
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册