提交 2ec11ee0 编写于 作者: J Joao Moreno

BaseEditor with dimension constraints

上级 1d9150ca
......@@ -363,7 +363,7 @@ class LeafNode implements ISplitView, IDisposable {
}
get onDidChange(): Event<number> {
return mapEvent(this.view.onDidChange, this.orientation === Orientation.HORIZONTAL ? ({ width }) => width : ({ height }) => height);
return mapEvent(this.view.onDidChange, this.orientation === Orientation.HORIZONTAL ? e => e && e.width : e => e && e.height);
}
set orthogonalStartSash(sash: Sash) {
......
......@@ -16,6 +16,7 @@ import { LRUCache } from 'vs/base/common/map';
import URI from 'vs/base/common/uri';
import { once } from 'vs/base/common/event';
import { isEmptyObject } from 'vs/base/common/types';
import { DEFAULT_EDITOR_MIN_DIMENSIONS, DEFAULT_EDITOR_MAX_DIMENSIONS } from 'vs/workbench/browser/parts/editor/editor';
/**
* The base class of editors in the workbench. Editors register themselves for specific editor inputs.
......@@ -39,6 +40,11 @@ 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;
constructor(
id: string,
telemetryService: ITelemetryService,
......
......@@ -21,8 +21,8 @@ import { IEditorService } from 'vs/workbench/services/editor/common/editorServic
export const EDITOR_TITLE_HEIGHT = 35;
export const EDITOR_MIN_DIMENSIONS = new Dimension(220, 70);
export const EDITOR_MAX_DIMENSIONS = new Dimension(Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY);
export const DEFAULT_EDITOR_MIN_DIMENSIONS = new Dimension(220, 70);
export const DEFAULT_EDITOR_MAX_DIMENSIONS = new Dimension(Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY);
export interface IEditorPartOptions extends IWorkbenchEditorPartConfiguration {
iconTheme?: string;
......
......@@ -34,6 +34,14 @@ export class EditorControl extends Disposable {
private dimension: Dimension;
private editorOperation: LongRunningOperation;
get minimumWidth(): number { return this._activeControl ? this._activeControl.minimumWidth : 0; }
get minimumHeight(): number { return this._activeControl ? this._activeControl.minimumHeight : 0; }
get maximumWidth(): number { return this._activeControl ? this._activeControl.maximumWidth : Number.POSITIVE_INFINITY; }
get maximumHeight(): number { return this._activeControl ? this._activeControl.maximumHeight : Number.POSITIVE_INFINITY; }
private _onDidChange = new Emitter<{ width: number; height: number; }>();
readonly onDidChange: Event<{ width: number; height: number; }> = this._onDidChange.event;
private _activeControl: BaseEditor;
private controls: BaseEditor[] = [];
......@@ -49,6 +57,11 @@ export class EditorControl extends Disposable {
this.editorOperation = this._register(new LongRunningOperation(progressService));
}
private setActiveControl(activeControl: BaseEditor) {
this._activeControl = activeControl;
this._onDidChange.fire();
}
get activeControl(): BaseEditor {
return this._activeControl;
}
......@@ -77,7 +90,7 @@ export class EditorControl extends Disposable {
const control = this.doCreateEditorControl(descriptor);
// Remember editor as active
this._activeControl = control;
this.setActiveControl(control);
// Show editor
this.parent.appendChild(control.getContainer());
......@@ -196,7 +209,7 @@ export class EditorControl extends Disposable {
this._activeControl.setVisible(false, this.groupView);
// Clear active control
this._activeControl = null;
this.setActiveControl(null);
// Clear focus listener
this.activeControlFocusListener = dispose(this.activeControlFocusListener);
......
......@@ -9,7 +9,7 @@ import 'vs/css!./media/editorgroupview';
import { TPromise } from 'vs/base/common/winjs.base';
import { EditorGroup, IEditorOpenOptions, EditorCloseEvent, ISerializedEditorGroup, isSerializedEditorGroup } from 'vs/workbench/common/editor/editorGroup';
import { EditorInput, EditorOptions, GroupIdentifier, ConfirmResult, SideBySideEditorInput, CloseDirection, IEditorCloseEvent, EditorGroupActiveEditorDirtyContext } from 'vs/workbench/common/editor';
import { Event, Emitter, once } from 'vs/base/common/event';
import { Event, Emitter, once, Relay } from 'vs/base/common/event';
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { addClass, addClasses, Dimension, trackFocus, toggleClass, removeClass, addDisposableListener, EventType, EventHelper, findParentWithClass, clearNode, isAncestor } from 'vs/base/browser/dom';
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
......@@ -34,7 +34,7 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { RunOnceWorker } from 'vs/base/common/async';
import { EventType as TouchEventType, GestureEvent } from 'vs/base/browser/touch';
import { TitleControl } from 'vs/workbench/browser/parts/editor/titleControl';
import { IEditorGroupsAccessor, IEditorGroupView, IEditorPartOptionsChangeEvent, EDITOR_TITLE_HEIGHT, EDITOR_MIN_DIMENSIONS, EDITOR_MAX_DIMENSIONS, getActiveTextEditorOptions, IEditorOpeningEvent } from 'vs/workbench/browser/parts/editor/editor';
import { IEditorGroupsAccessor, IEditorGroupView, IEditorPartOptionsChangeEvent, EDITOR_TITLE_HEIGHT, getActiveTextEditorOptions, IEditorOpeningEvent } from 'vs/workbench/browser/parts/editor/editor';
import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService';
import { join } from 'vs/base/common/paths';
import { ActionBar } from 'vs/base/browser/ui/actionbar/actionbar';
......@@ -197,6 +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;
// Track Focus
this.doTrackFocus();
......@@ -1330,12 +1331,13 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
readonly element: HTMLElement = document.createElement('div');
readonly minimumWidth = EDITOR_MIN_DIMENSIONS.width;
readonly minimumHeight = EDITOR_MIN_DIMENSIONS.height;
readonly maximumWidth = EDITOR_MAX_DIMENSIONS.width;
readonly maximumHeight = EDITOR_MAX_DIMENSIONS.height;
get minimumWidth(): number { return this.editorControl.minimumWidth; }
get minimumHeight(): number { return this.editorControl.minimumHeight; }
get maximumWidth(): number { return this.editorControl.maximumWidth; }
get maximumHeight(): number { return this.editorControl.maximumHeight; }
get onDidChange() { return Event.None; } // only needed if minimum sizes ever change
private _onDidChange = new Relay<{ width: number; height: number; }>();
readonly onDidChange: Event<{ width: number; height: number; }> = this._onDidChange.event;
layout(width: number, height: number): void {
this.dimension = new Dimension(width, height);
......
......@@ -58,6 +58,26 @@ export interface IEditor {
*/
group: IEditorGroup;
/**
* The minimum width of this editor.
*/
readonly minimumWidth: number;
/**
* The maximum width of this editor.
*/
readonly maximumWidth: number;
/**
* The minimum height of this editor.
*/
readonly minimumHeight: number;
/**
* The maximum height of this editor.
*/
readonly maximumHeight: number;
/**
* Returns the unique identifier of this editor.
*/
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册