提交 74caa412 编写于 作者: B Benjamin Pasero

💄

上级 0b3457a4
......@@ -117,7 +117,7 @@ export class WorkbenchLayout extends Disposable implements IVerticalSashLayoutPr
private registerListeners(): void {
this._register(this.themeService.onThemeChange(_ => this.layout()));
this._register(this.parts.editor.onDidChange(() => this.onDidEditorChange()));
this._register(this.parts.editor.onDidSizeConstraintsChange(() => this.onDidEditorChange()));
this.registerSashListeners();
}
......
......@@ -33,6 +33,13 @@ import { DEFAULT_EDITOR_MIN_DIMENSIONS, DEFAULT_EDITOR_MAX_DIMENSIONS } from 'vs
*/
export abstract class BaseEditor extends Panel implements IEditor {
readonly minimumWidth = DEFAULT_EDITOR_MIN_DIMENSIONS.width;
readonly maximumWidth = DEFAULT_EDITOR_MAX_DIMENSIONS.width;
readonly minimumHeight = DEFAULT_EDITOR_MIN_DIMENSIONS.height;
readonly maximumHeight = DEFAULT_EDITOR_MAX_DIMENSIONS.height;
readonly onDidSizeConstraintsChange: Event<{ width: number; height: number; }> = Event.None;
private static readonly EDITOR_MEMENTOS: Map<string, EditorMemento<any>> = new Map<string, EditorMemento<any>>();
protected _input: EditorInput;
......@@ -40,12 +47,6 @@ export abstract class BaseEditor extends Panel implements IEditor {
private _options: EditorOptions;
private _group: IEditorGroup;
readonly minimumWidth: number = DEFAULT_EDITOR_MIN_DIMENSIONS.width;
readonly maximumWidth: number = DEFAULT_EDITOR_MAX_DIMENSIONS.width;
readonly minimumHeight: number = DEFAULT_EDITOR_MIN_DIMENSIONS.height;
readonly maximumHeight: number = DEFAULT_EDITOR_MAX_DIMENSIONS.height;
readonly onDidChange: Event<{ width: number; height: number; }> = Event.None;
constructor(
id: string,
telemetryService: ITelemetryService,
......
......@@ -26,22 +26,20 @@ export interface IOpenEditorResult {
export class EditorControl extends Disposable {
get minimumWidth() { return this._activeControl ? this._activeControl.minimumWidth : DEFAULT_EDITOR_MIN_DIMENSIONS.width; }
get minimumHeight() { return this._activeControl ? this._activeControl.minimumHeight : DEFAULT_EDITOR_MIN_DIMENSIONS.height; }
get maximumWidth() { return this._activeControl ? this._activeControl.maximumWidth : DEFAULT_EDITOR_MAX_DIMENSIONS.width; }
get maximumHeight() { return this._activeControl ? this._activeControl.maximumHeight : DEFAULT_EDITOR_MAX_DIMENSIONS.height; }
private _onDidFocus: Emitter<void> = this._register(new Emitter<void>());
get onDidFocus(): Event<void> { return this._onDidFocus.event; }
private activeControlFocusListener: IDisposable;
private _onDidSizeConstraintsChange = this._register(new Emitter<{ width: number; height: number; }>());
get onDidSizeConstraintsChange(): Event<{ width: number; height: number; }> { return this._onDidSizeConstraintsChange.event; }
private activeControlFocusListener: IDisposable;
private dimension: Dimension;
private editorOperation: LongRunningOperation;
get minimumWidth(): number { return this._activeControl ? this._activeControl.minimumWidth : DEFAULT_EDITOR_MIN_DIMENSIONS.width; }
get minimumHeight(): number { return this._activeControl ? this._activeControl.minimumHeight : DEFAULT_EDITOR_MIN_DIMENSIONS.height; }
get maximumWidth(): number { return this._activeControl ? this._activeControl.maximumWidth : DEFAULT_EDITOR_MAX_DIMENSIONS.width; }
get maximumHeight(): number { return this._activeControl ? this._activeControl.maximumHeight : DEFAULT_EDITOR_MAX_DIMENSIONS.height; }
private _onDidChange = new Emitter<{ width: number; height: number; }>();
readonly onDidChange: Event<{ width: number; height: number; }> = this._onDidChange.event;
private _activeControl: BaseEditor;
private activeControlDisposable: IDisposable = EmptyDisposable;
private controls: BaseEditor[] = [];
......@@ -58,17 +56,6 @@ export class EditorControl extends Disposable {
this.editorOperation = this._register(new LongRunningOperation(progressService));
}
private setActiveControl(activeControl: BaseEditor) {
this.activeControlDisposable.dispose();
this._activeControl = activeControl;
if (activeControl) {
this.activeControlDisposable = activeControl.onDidChange(e => this._onDidChange.fire(e));
}
this._onDidChange.fire();
}
get activeControl(): BaseEditor {
return this._activeControl;
}
......@@ -97,7 +84,7 @@ export class EditorControl extends Disposable {
const control = this.doCreateEditorControl(descriptor);
// Remember editor as active
this.setActiveControl(control);
this.doSetActiveControl(control);
// Show editor
this.parent.appendChild(control.getContainer());
......@@ -149,6 +136,17 @@ export class EditorControl extends Disposable {
return control;
}
private doSetActiveControl(control: BaseEditor) {
this.activeControlDisposable.dispose();
this._activeControl = control;
if (control) {
this.activeControlDisposable = control.onDidSizeConstraintsChange(e => this._onDidSizeConstraintsChange.fire(e));
}
this._onDidSizeConstraintsChange.fire();
}
private doSetInput(control: BaseEditor, editor: EditorInput, options: EditorOptions): TPromise<boolean> {
// If the input did not change, return early and only apply the options
......@@ -216,7 +214,7 @@ export class EditorControl extends Disposable {
this._activeControl.setVisible(false, this.groupView);
// Clear active control
this.setActiveControl(null);
this.doSetActiveControl(null);
// Clear focus listener
this.activeControlFocusListener = dispose(this.activeControlFocusListener);
......
......@@ -197,7 +197,7 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
// Editor control
this.editorControl = this._register(this.scopedInstantiationService.createInstance(EditorControl, this.editorContainer, this));
this._onDidChange.input = this.editorControl.onDidChange;
this._onDidChange.input = this.editorControl.onDidSizeConstraintsChange;
// Track Focus
this.doTrackFocus();
......
......@@ -64,14 +64,9 @@ export class EditorPart extends Part implements EditorGroupsServiceImpl, IEditor
private _onDidMoveGroup: Emitter<IEditorGroupView> = this._register(new Emitter<IEditorGroupView>());
get onDidMoveGroup(): Event<IEditorGroupView> { return this._onDidMoveGroup.event; }
get minimumWidth(): number { return this.gridWidget ? this.gridWidget.minimumWidth : 0; }
get maximumWidth(): number { return this.gridWidget ? this.gridWidget.maximumWidth : Number.POSITIVE_INFINITY; }
get minimumHeight(): number { return this.gridWidget ? this.gridWidget.minimumHeight : 0; }
get maximumHeight(): number { return this.gridWidget ? this.gridWidget.maximumHeight : Number.POSITIVE_INFINITY; }
private _onDidSetGridWidget = new Emitter<{ width: number; height: number; }>();
private _onDidChange = new Relay<{ width: number; height: number; }>();
readonly onDidChange: Event<{ width: number; height: number; }> = anyEvent(this._onDidSetGridWidget.event, this._onDidChange.event);
private onDidSetGridWidget = this._register(new Emitter<{ width: number; height: number; }>());
private _onDidSizeConstraintsChange = this._register(new Relay<{ width: number; height: number; }>());
get onDidSizeConstraintsChange(): Event<{ width: number; height: number; }> { return anyEvent(this.onDidSetGridWidget.event, this._onDidSizeConstraintsChange.event); }
private _onDidPreferredSizeChange: Emitter<void> = this._register(new Emitter<void>());
get onDidPreferredSizeChange(): Event<void> { return this._onDidPreferredSizeChange.event; }
......@@ -674,6 +669,11 @@ export class EditorPart extends Part implements EditorGroupsServiceImpl, IEditor
//#region Part
get minimumWidth(): number { return this.gridWidget ? this.gridWidget.minimumWidth : 0; }
get maximumWidth(): number { return this.gridWidget ? this.gridWidget.maximumWidth : Number.POSITIVE_INFINITY; }
get minimumHeight(): number { return this.gridWidget ? this.gridWidget.minimumHeight : 0; }
get maximumHeight(): number { return this.gridWidget ? this.gridWidget.maximumHeight : Number.POSITIVE_INFINITY; }
get preferredSize(): Dimension {
if (!this._preferredSize) {
this._preferredSize = new Dimension(this.gridWidget.minimumWidth, this.gridWidget.minimumHeight);
......@@ -727,7 +727,7 @@ export class EditorPart extends Part implements EditorGroupsServiceImpl, IEditor
// Grid Widget (no previous UI state or failed to restore)
if (!this.gridWidget) {
const initialGroup = this.doCreateGroupView();
this.setGridWidget(new SerializableGrid(initialGroup));
this.doSetGridWidget(new SerializableGrid(initialGroup));
// Ensure a group is active
this.doSetGroupActive(initialGroup);
......@@ -758,7 +758,7 @@ export class EditorPart extends Part implements EditorGroupsServiceImpl, IEditor
if (this.gridWidget) {
clearNode(this.gridWidget.element);
this.gridWidget.dispose();
this.setGridWidget();
this.doSetGridWidget();
}
this.groupViews.forEach(group => group.dispose());
......@@ -787,7 +787,7 @@ export class EditorPart extends Part implements EditorGroupsServiceImpl, IEditor
}
// Create new
this.setGridWidget(SerializableGrid.deserialize(serializedGrid, {
this.doSetGridWidget(SerializableGrid.deserialize(serializedGrid, {
fromJSON: (serializedEditorGroup: ISerializedEditorGroup) => {
let groupView: IEditorGroupView;
if (reuseGroupViews.length > 0) {
......@@ -805,6 +805,16 @@ export class EditorPart extends Part implements EditorGroupsServiceImpl, IEditor
}, { styles: { separatorBorder: this.gridSeparatorBorder } }));
}
private doSetGridWidget(gridWidget?: SerializableGrid<IEditorGroupView>): void {
this.gridWidget = gridWidget;
if (gridWidget) {
this._onDidSizeConstraintsChange.input = gridWidget.onDidChange;
}
this.onDidSetGridWidget.fire();
}
private doGetPreviousState(): IEditorPartUIState {
const legacyState = this.doGetPreviousLegacyState();
if (legacyState) {
......@@ -922,16 +932,6 @@ export class EditorPart extends Part implements EditorGroupsServiceImpl, IEditor
return void 0;
}
private setGridWidget(grid?: SerializableGrid<IEditorGroupView>): void {
this.gridWidget = grid;
if (grid) {
this._onDidChange.input = grid.onDidChange;
}
this._onDidSetGridWidget.fire();
}
private updateContainer(): void {
toggleClass(this.gridWidget.element, 'empty', this.isEmpty());
}
......@@ -1004,9 +1004,6 @@ export class EditorPart extends Part implements EditorGroupsServiceImpl, IEditor
this.groupViews.forEach(group => group.dispose());
this.groupViews.clear();
this._onDidSetGridWidget.dispose();
this._onDidChange.dispose();
// Grid widget
if (this.gridWidget) {
this.gridWidget = dispose(this.gridWidget);
......
......@@ -55,7 +55,7 @@ export class SideBySideEditor extends BaseEditor {
private _onDidCreateEditors = new Emitter<{ width: number; height: number; }>();
private _onDidChange = new Relay<{ width: number; height: number; }>();
readonly onDidChange: Event<{ width: number; height: number; }> = anyEvent(this._onDidCreateEditors.event, this._onDidChange.event);
readonly onDidSizeConstraintsChange: Event<{ width: number; height: number; }> = anyEvent(this._onDidCreateEditors.event, this._onDidChange.event);
constructor(
@ITelemetryService telemetryService: ITelemetryService,
......@@ -190,8 +190,8 @@ export class SideBySideEditor extends BaseEditor {
this.masterEditor = master;
this._onDidChange.input = anyEvent(
mapEvent(details.onDidChange, () => undefined),
mapEvent(master.onDidChange, () => undefined)
mapEvent(details.onDidSizeConstraintsChange, () => undefined),
mapEvent(master.onDidSizeConstraintsChange, () => undefined)
);
this._onDidCreateEditors.fire();
......
......@@ -81,7 +81,7 @@ export interface IEditor {
/**
* An event to notify whenever minimum/maximum width/height changes.
*/
readonly onDidChange: Event<{ width: number; height: number; }>;
readonly onDidSizeConstraintsChange: Event<{ width: number; height: number; }>;
/**
* Returns the unique identifier of this editor.
......
......@@ -83,7 +83,7 @@ export class PreferencesEditor extends BaseEditor {
set maximumWidth(value: number) { /*noop*/ }
private _onDidCreateWidget = new Emitter<{ width: number; height: number; }>();
readonly onDidChange: Event<{ width: number; height: number; }> = this._onDidCreateWidget.event;
readonly onDidSizeConstraintsChange: Event<{ width: number; height: number; }> = this._onDidCreateWidget.event;
constructor(
@IPreferencesService private preferencesService: IPreferencesService,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册