66
77import { TPromise } from 'vs/base/common/winjs.base' ;
88import { Panel } from 'vs/workbench/browser/panel' ;
9- import { EditorInput , EditorOptions } from 'vs/workbench/common/editor' ;
10- import { IEditor , Position } from 'vs/platform/editor/common/editor' ;
9+ import { EditorInput , EditorOptions , GroupIdentifier } from 'vs/workbench/common/editor' ;
10+ import { IEditor } from 'vs/platform/editor/common/editor' ;
1111import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry' ;
1212import { IThemeService } from 'vs/platform/theme/common/themeService' ;
1313
1414/**
1515 * The base class of editors in the workbench. Editors register themselves for specific editor inputs.
16- * Editors are layed out in the editor part of the workbench. Only one editor can be open at a time.
17- * Each editor has a minimized representation that is good enough to provide some information about the
18- * state of the editor data.
16+ * Editors are layed out in the editor part of the workbench in editor groups. Multiple editors can be
17+ * open at the same time. Each editor has a minimized representation that is good enough to provide some
18+ * information about the state of the editor data.
19+ *
1920 * The workbench will keep an editor alive after it has been created and show/hide it based on
2021 * user interaction. The lifecycle of a editor goes in the order create(), setVisible(true|false),
2122 * layout(), setInput(), focus(), dispose(). During use of the workbench, a editor will often receive a
@@ -24,48 +25,58 @@ import { IThemeService } from 'vs/platform/theme/common/themeService';
2425 * This class is only intended to be subclassed and not instantiated.
2526 */
2627export abstract class BaseEditor extends Panel implements IEditor {
28+
2729 protected _input : EditorInput ;
30+
2831 private _options : EditorOptions ;
29- private _position : Position ; // TODO @grid change to GroupIdentifier and revisit if methods make sense (changePosition, setVisible, etc.)
32+ private _group : GroupIdentifier ;
3033
31- constructor ( id : string , telemetryService : ITelemetryService , themeService : IThemeService ) {
34+ constructor (
35+ id : string ,
36+ telemetryService : ITelemetryService ,
37+ themeService : IThemeService
38+ ) {
3239 super ( id , telemetryService , themeService ) ;
3340 }
3441
35- public get input ( ) : EditorInput {
42+ get input ( ) : EditorInput {
3643 return this . _input ;
3744 }
3845
39- public get options ( ) : EditorOptions {
46+ get options ( ) : EditorOptions {
4047 return this . _options ;
4148 }
4249
50+ get group ( ) : GroupIdentifier {
51+ return this . _group ;
52+ }
53+
4354 /**
4455 * Note: Clients should not call this method, the workbench calls this
4556 * method. Calling it otherwise may result in unexpected behavior.
4657 *
4758 * Sets the given input with the options to the part. An editor has to deal with the
4859 * situation that the same input is being set with different options.
4960 */
50- public setInput ( input : EditorInput , options ?: EditorOptions ) : TPromise < void > {
61+ setInput ( input : EditorInput , options ?: EditorOptions ) : TPromise < void > {
5162 this . _input = input ;
5263 this . _options = options ;
5364
5465 return TPromise . wrap < void > ( null ) ;
5566 }
5667
5768 /**
58- * Called to indicate to the editor that the input should be cleared and resources associated with the
59- * input should be freed.
69+ * Called to indicate to the editor that the input should be cleared and
70+ * resources associated with the input should be freed.
6071 */
61- public clearInput ( ) : void {
72+ clearInput ( ) : void {
6273 this . _input = null ;
6374 this . _options = null ;
6475 }
6576
66- public create ( parent : HTMLElement ) : void ; // create is sync for editors
67- public create ( parent : HTMLElement ) : TPromise < void > ;
68- public create ( parent : HTMLElement ) : TPromise < void > {
77+ create ( parent : HTMLElement ) : void ; // create is sync for editors
78+ create ( parent : HTMLElement ) : TPromise < void > ;
79+ create ( parent : HTMLElement ) : TPromise < void > {
6980 const res = super . create ( parent ) ;
7081
7182 // Create Editor
@@ -79,46 +90,37 @@ export abstract class BaseEditor extends Panel implements IEditor {
7990 */
8091 protected abstract createEditor ( parent : HTMLElement ) : void ;
8192
82- /**
83- * Subclasses can set this to false if it does not make sense to center editor input.
84- */
85- public supportsCenteredLayout ( ) : boolean {
86- return true ;
87- }
88-
89- /**
90- * Overload this function to allow for passing in a position argument.
91- */
92- public setVisible ( visible : boolean , position ?: Position ) : void ; // setVisible is sync for editors
93- public setVisible ( visible : boolean , position ?: Position ) : TPromise < void > ;
94- public setVisible ( visible : boolean , position : Position = null ) : TPromise < void > {
93+ setVisible ( visible : boolean , group ?: GroupIdentifier ) : void ; // setVisible is sync for editors
94+ setVisible ( visible : boolean , group ?: GroupIdentifier ) : TPromise < void > ;
95+ setVisible ( visible : boolean , group ?: GroupIdentifier ) : TPromise < void > {
9596 const promise = super . setVisible ( visible ) ;
9697
9798 // Propagate to Editor
98- this . setEditorVisible ( visible , position ) ;
99+ this . setEditorVisible ( visible , group ) ;
99100
100101 return promise ;
101102 }
102103
103- protected setEditorVisible ( visible : boolean , position : Position = null ) : void {
104- this . _position = position ;
105- }
106-
107104 /**
108- * Called when the position of the editor changes while it is visible.
105+ * Indicates that the editor control got visible or hidden in a specific group. A
106+ * editor instance will only ever be visible in one editor group.
107+ *
108+ * @param visible the state of visibility of this editor
109+ * @param group the identifier of the editor group this editor is currently
110+ * positioned.
109111 */
110- public changePosition ( position : Position ) : void {
111- this . _position = position ;
112+ protected setEditorVisible ( visible : boolean , group : GroupIdentifier ) : void {
113+ this . _group = group ;
112114 }
113115
114116 /**
115- * The position this editor is showing in or null if none .
117+ * Subclasses can set this to false if it does not make sense to center editor input .
116118 */
117- public get position ( ) : Position {
118- return this . _position ;
119+ supportsCenteredLayout ( ) : boolean {
120+ return true ;
119121 }
120122
121- public dispose ( ) : void {
123+ dispose ( ) : void {
122124 this . _input = null ;
123125 this . _options = null ;
124126
0 commit comments