Skip to content

Commit 01bf961

Browse files
committed
grid - towards GroupIdentifier over Position in IEditor
1 parent b0cd496 commit 01bf961

36 files changed

Lines changed: 206 additions & 250 deletions

File tree

src/vs/editor/standalone/browser/simpleServices.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import URI from 'vs/base/common/uri';
1010
import { TPromise } from 'vs/base/common/winjs.base';
1111
import { IConfigurationService, IConfigurationChangeEvent, IConfigurationOverrides, IConfigurationData } from 'vs/platform/configuration/common/configuration';
1212
import { ISingleFolderWorkspaceIdentifier, IWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces';
13-
import { IEditor, IEditorInput, IEditorOptions, IEditorService, IResourceInput, Position } from 'vs/platform/editor/common/editor';
13+
import { IEditor, IEditorInput, IEditorOptions, IEditorService, IResourceInput, GroupIdentifier } from 'vs/platform/editor/common/editor';
1414
import { ICommandService, ICommand, ICommandEvent, ICommandHandler, CommandsRegistry } from 'vs/platform/commands/common/commands';
1515
import { AbstractKeybindingService } from 'vs/platform/keybinding/common/abstractKeybindingService';
1616
import { USLayoutResolvedKeybinding } from 'vs/platform/keybinding/common/usLayoutResolvedKeybinding';
@@ -52,7 +52,7 @@ export class SimpleEditor implements IEditor {
5252

5353
public input: IEditorInput;
5454
public options: IEditorOptions;
55-
public position: Position;
55+
public group: GroupIdentifier;
5656

5757
public _widget: editorCommon.IEditor;
5858

src/vs/platform/editor/common/editor.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ export interface IEditorService {
2424

2525
export interface IEditorModel {
2626

27+
/**
28+
* Emitted when the model is disposed.
29+
*/
2730
onDispose: Event<void>;
2831

2932
/**
@@ -122,9 +125,12 @@ export interface IResourceSideBySideInput extends IBaseResourceInput {
122125
detailResource: URI;
123126
}
124127

125-
export interface IEditorControl {
128+
/**
129+
* Marker interface for the editor control
130+
*/
131+
export interface IEditorControl { }
126132

127-
}
133+
export type GroupIdentifier = number;
128134

129135
export interface IEditor {
130136

@@ -139,9 +145,9 @@ export interface IEditor {
139145
options: IEditorOptions;
140146

141147
/**
142-
* The assigned position of this editor.
148+
* The assigned group this editor is showing in.
143149
*/
144-
position: Position;
150+
group: GroupIdentifier;
145151

146152
/**
147153
* Returns the unique identifier of this editor.

src/vs/workbench/api/electron-browser/mainThreadDocumentsAndEditors.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,14 +422,14 @@ export class MainThreadDocumentsAndEditors {
422422
options: props.options,
423423
selections: props.selections,
424424
visibleRanges: props.visibleRanges,
425-
editorPosition: this._findEditorPosition(textEditor)
425+
editorPosition: this._findEditorPosition(textEditor) // TODO@grid [EXTENSIONS] adopt in extension host
426426
};
427427
}
428428

429429
private _findEditorPosition(editor: MainThreadTextEditor): EditorPosition {
430430
for (let workbenchEditor of this._workbenchEditorService.getVisibleEditors()) {
431431
if (editor.matches(workbenchEditor)) {
432-
return workbenchEditor.position;
432+
return workbenchEditor.group;
433433
}
434434
}
435435
return undefined;

src/vs/workbench/api/electron-browser/mainThreadEditors.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export class MainThreadTextEditors implements MainThreadTextEditorsShape {
9999
for (let workbenchEditor of this._workbenchEditorService.getVisibleEditors()) {
100100
const id = this._documentsAndEditors.findTextEditorIdFor(workbenchEditor);
101101
if (id) {
102-
result[id] = workbenchEditor.position;
102+
result[id] = workbenchEditor.group; // TODO@grid [EXTENSIONS] adopt in extension host
103103
}
104104
}
105105
return result;
@@ -147,7 +147,7 @@ export class MainThreadTextEditors implements MainThreadTextEditorsShape {
147147
let editors = this._workbenchEditorService.getVisibleEditors();
148148
for (let editor of editors) {
149149
if (mainThreadEditor.matches(editor)) {
150-
return this._workbenchEditorService.closeEditor(editor.position, editor.input).then(() => { return; });
150+
return this._workbenchEditorService.closeEditor(editor.group, editor.input).then(() => { return; });
151151
}
152152
}
153153
}

src/vs/workbench/api/electron-browser/mainThreadWebview.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviv
136136
this._webviews.set(handle, webview);
137137
webview._events = this.createWebviewEventDelegate(handle);
138138

139-
return this._proxy.$deserializeWebviewPanel(handle, webview.state.viewType, webview.getTitle(), webview.state.state, webview.position, webview.options)
139+
return this._proxy.$deserializeWebviewPanel(handle, webview.state.viewType, webview.getTitle(), webview.state.state, webview.group, webview.options) // TODO@grid [EXTENSIONS] adopt group identifier
140140
.then(undefined, () => {
141141
webview.html = MainThreadWebviews.getDeserializationFailedContents(viewType);
142142
});
@@ -217,21 +217,21 @@ export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviv
217217

218218
if (newActiveWebview && newActiveWebview.handle === this._activeWebview) {
219219
// Webview itself unchanged but position may have changed
220-
this._proxy.$onDidChangeWebviewPanelViewState(newActiveWebview.handle, true, newActiveWebview.input.position);
220+
this._proxy.$onDidChangeWebviewPanelViewState(newActiveWebview.handle, true, newActiveWebview.input.group); // TODO@grid [EXTENSIONS] adopt group identifier
221221
return;
222222
}
223223

224224
// Broadcast view state update for currently active
225225
if (typeof this._activeWebview !== 'undefined') {
226226
const oldActiveWebview = this._webviews.get(this._activeWebview);
227227
if (oldActiveWebview) {
228-
this._proxy.$onDidChangeWebviewPanelViewState(this._activeWebview, false, oldActiveWebview.position);
228+
this._proxy.$onDidChangeWebviewPanelViewState(this._activeWebview, false, oldActiveWebview.group); // TODO@grid [EXTENSIONS] adopt group identifier
229229
}
230230
}
231231

232232
// Then for newly active
233233
if (newActiveWebview) {
234-
this._proxy.$onDidChangeWebviewPanelViewState(newActiveWebview.handle, true, activeEditor.position);
234+
this._proxy.$onDidChangeWebviewPanelViewState(newActiveWebview.handle, true, activeEditor.group); // TODO@grid [EXTENSIONS] adopt in extension host
235235
this._activeWebview = newActiveWebview.handle;
236236
} else {
237237
this._activeWebview = undefined;
@@ -245,9 +245,9 @@ export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviv
245245
}
246246

247247
this._webviews.forEach((input, handle) => {
248-
if (workbenchEditor.input.matches(input) && input.position !== workbenchEditor.position) {
249-
input.updatePosition(workbenchEditor.position);
250-
this._proxy.$onDidChangeWebviewPanelViewState(handle, handle === this._activeWebview, workbenchEditor.position);
248+
if (workbenchEditor.input.matches(input) && input.group !== workbenchEditor.group) { // TODO@grid [EXTENSIONS] adopt group identifier
249+
input.updateGroup(workbenchEditor.group);
250+
this._proxy.$onDidChangeWebviewPanelViewState(handle, handle === this._activeWebview, workbenchEditor.group);
251251
}
252252
});
253253
}

src/vs/workbench/browser/parts/editor/baseEditor.ts

Lines changed: 43 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@
66

77
import { TPromise } from 'vs/base/common/winjs.base';
88
import { 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';
1111
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
1212
import { 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
*/
2627
export 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

Comments
 (0)