-
Notifications
You must be signed in to change notification settings - Fork 29.3k
/
multiRowEditorTabsControl.ts
198 lines (157 loc) · 7.63 KB
/
multiRowEditorTabsControl.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Dimension } from 'vs/base/browser/dom';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IEditorGroupsView, IEditorGroupView, IEditorPartsView, IInternalEditorOpenOptions } from 'vs/workbench/browser/parts/editor/editor';
import { IEditorTabsControl } from 'vs/workbench/browser/parts/editor/editorTabsControl';
import { MultiEditorTabsControl } from 'vs/workbench/browser/parts/editor/multiEditorTabsControl';
import { IEditorPartOptions } from 'vs/workbench/common/editor';
import { EditorInput } from 'vs/workbench/common/editor/editorInput';
import { Disposable } from 'vs/base/common/lifecycle';
import { StickyEditorGroupModel, UnstickyEditorGroupModel } from 'vs/workbench/common/editor/filteredEditorGroupModel';
import { IEditorTitleControlDimensions } from 'vs/workbench/browser/parts/editor/editorTitleControl';
import { IReadonlyEditorGroupModel } from 'vs/workbench/common/editor/editorGroupModel';
export class MultiRowEditorControl extends Disposable implements IEditorTabsControl {
private readonly stickyEditorTabsControl: IEditorTabsControl;
private readonly unstickyEditorTabsControl: IEditorTabsControl;
constructor(
private readonly parent: HTMLElement,
editorPartsView: IEditorPartsView,
private readonly groupsView: IEditorGroupsView,
private readonly groupView: IEditorGroupView,
private readonly model: IReadonlyEditorGroupModel,
@IInstantiationService private readonly instantiationService: IInstantiationService
) {
super();
const stickyModel = this._register(new StickyEditorGroupModel(this.model));
const unstickyModel = this._register(new UnstickyEditorGroupModel(this.model));
this.stickyEditorTabsControl = this._register(this.instantiationService.createInstance(MultiEditorTabsControl, this.parent, editorPartsView, this.groupsView, this.groupView, stickyModel));
this.unstickyEditorTabsControl = this._register(this.instantiationService.createInstance(MultiEditorTabsControl, this.parent, editorPartsView, this.groupsView, this.groupView, unstickyModel));
this.handlePinnedTabsSeparateRowToolbars();
}
private handlePinnedTabsSeparateRowToolbars(): void {
if (this.groupView.count === 0) {
// Do nothing as no tab bar is visible
return;
}
// Ensure action toolbar is only visible once
if (this.groupView.count === this.groupView.stickyCount) {
this.parent.classList.toggle('two-tab-bars', false);
} else {
this.parent.classList.toggle('two-tab-bars', true);
}
}
private getEditorTabsController(editor: EditorInput): IEditorTabsControl {
return this.model.isSticky(editor) ? this.stickyEditorTabsControl : this.unstickyEditorTabsControl;
}
openEditor(editor: EditorInput, options: IInternalEditorOpenOptions): boolean {
const [editorTabController, otherTabController] = this.model.isSticky(editor) ? [this.stickyEditorTabsControl, this.unstickyEditorTabsControl] : [this.unstickyEditorTabsControl, this.stickyEditorTabsControl];
const didChange = editorTabController.openEditor(editor, options);
if (didChange) {
// HACK: To render all editor tabs on startup, otherwise only one row gets rendered
otherTabController.openEditors([]);
this.handleOpenedEditors();
}
return didChange;
}
openEditors(editors: EditorInput[]): boolean {
const stickyEditors = editors.filter(e => this.model.isSticky(e));
const unstickyEditors = editors.filter(e => !this.model.isSticky(e));
const didChangeOpenEditorsSticky = this.stickyEditorTabsControl.openEditors(stickyEditors);
const didChangeOpenEditorsUnSticky = this.unstickyEditorTabsControl.openEditors(unstickyEditors);
const didChange = didChangeOpenEditorsSticky || didChangeOpenEditorsUnSticky;
if (didChange) {
this.handleOpenedEditors();
}
return didChange;
}
private handleOpenedEditors(): void {
this.handlePinnedTabsSeparateRowToolbars();
}
beforeCloseEditor(editor: EditorInput): void {
this.getEditorTabsController(editor).beforeCloseEditor(editor);
}
closeEditor(editor: EditorInput): void {
// Has to be called on both tab bars as the editor could be either sticky or not
this.stickyEditorTabsControl.closeEditor(editor);
this.unstickyEditorTabsControl.closeEditor(editor);
this.handleClosedEditors();
}
closeEditors(editors: EditorInput[]): void {
const stickyEditors = editors.filter(e => this.model.isSticky(e));
const unstickyEditors = editors.filter(e => !this.model.isSticky(e));
this.stickyEditorTabsControl.closeEditors(stickyEditors);
this.unstickyEditorTabsControl.closeEditors(unstickyEditors);
this.handleClosedEditors();
}
private handleClosedEditors(): void {
this.handlePinnedTabsSeparateRowToolbars();
}
moveEditor(editor: EditorInput, fromIndex: number, targetIndex: number, stickyStateChange: boolean): void {
if (stickyStateChange) {
// If sticky state changes, move editor between tab bars
if (this.model.isSticky(editor)) {
this.stickyEditorTabsControl.openEditor(editor);
this.unstickyEditorTabsControl.closeEditor(editor);
} else {
this.stickyEditorTabsControl.closeEditor(editor);
this.unstickyEditorTabsControl.openEditor(editor);
}
this.handlePinnedTabsSeparateRowToolbars();
} else {
if (this.model.isSticky(editor)) {
this.stickyEditorTabsControl.moveEditor(editor, fromIndex, targetIndex, stickyStateChange);
} else {
this.unstickyEditorTabsControl.moveEditor(editor, fromIndex - this.model.stickyCount, targetIndex - this.model.stickyCount, stickyStateChange);
}
}
}
pinEditor(editor: EditorInput): void {
this.getEditorTabsController(editor).pinEditor(editor);
}
stickEditor(editor: EditorInput): void {
this.unstickyEditorTabsControl.closeEditor(editor);
this.stickyEditorTabsControl.openEditor(editor);
this.handlePinnedTabsSeparateRowToolbars();
}
unstickEditor(editor: EditorInput): void {
this.stickyEditorTabsControl.closeEditor(editor);
this.unstickyEditorTabsControl.openEditor(editor);
this.handlePinnedTabsSeparateRowToolbars();
}
setActive(isActive: boolean): void {
this.stickyEditorTabsControl.setActive(isActive);
this.unstickyEditorTabsControl.setActive(isActive);
}
updateEditorLabel(editor: EditorInput): void {
this.getEditorTabsController(editor).updateEditorLabel(editor);
}
updateEditorDirty(editor: EditorInput): void {
this.getEditorTabsController(editor).updateEditorDirty(editor);
}
updateOptions(oldOptions: IEditorPartOptions, newOptions: IEditorPartOptions): void {
this.stickyEditorTabsControl.updateOptions(oldOptions, newOptions);
this.unstickyEditorTabsControl.updateOptions(oldOptions, newOptions);
}
layout(dimensions: IEditorTitleControlDimensions): Dimension {
const stickyDimensions = this.stickyEditorTabsControl.layout(dimensions);
const unstickyAvailableDimensions = {
container: dimensions.container,
available: new Dimension(dimensions.available.width, dimensions.available.height - stickyDimensions.height)
};
const unstickyDimensions = this.unstickyEditorTabsControl.layout(unstickyAvailableDimensions);
return new Dimension(
dimensions.container.width,
stickyDimensions.height + unstickyDimensions.height
);
}
getHeight(): number {
return this.stickyEditorTabsControl.getHeight() + this.unstickyEditorTabsControl.getHeight();
}
public override dispose(): void {
this.parent.classList.toggle('two-tab-bars', false);
super.dispose();
}
}