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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
|
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import 'vs/css!./media/editorplaceholder';
import { localize } from 'vs/nls';
import { IEditorOpenContext } from 'vs/workbench/common/editor';
import { EditorInput } from 'vs/workbench/common/editor/editorInput';
import { EditorPane } from 'vs/workbench/browser/parts/editor/editorPane';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { DomScrollableElement } from 'vs/base/browser/ui/scrollbar/scrollableElement';
import { ScrollbarVisibility } from 'vs/base/common/scrollable';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { Dimension, size, clearNode } from 'vs/base/browser/dom';
import { CancellationToken } from 'vs/base/common/cancellation';
import { DisposableStore, IDisposable, MutableDisposable } from 'vs/base/common/lifecycle';
import { IStorageService } from 'vs/platform/storage/common/storage';
import { assertIsDefined, assertAllDefined } from 'vs/base/common/types';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { IWorkspaceContextService, isSingleFolderWorkspaceIdentifier, toWorkspaceIdentifier } from 'vs/platform/workspace/common/workspace';
import { EditorOpenSource, IEditorOptions } from 'vs/platform/editor/common/editor';
import { computeEditorAriaLabel, EditorPaneDescriptor } from 'vs/workbench/browser/editor';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { Link } from 'vs/platform/opener/browser/link';
abstract class EditorPlaceholderPane extends EditorPane {
private container: HTMLElement | undefined;
private scrollbar: DomScrollableElement | undefined;
private inputDisposable = this._register(new MutableDisposable());
constructor(
id: string,
private readonly title: string,
@ITelemetryService telemetryService: ITelemetryService,
@IThemeService themeService: IThemeService,
@IStorageService storageService: IStorageService
) {
super(id, telemetryService, themeService, storageService);
}
override getTitle(): string {
return this.title;
}
protected createEditor(parent: HTMLElement): void {
// Container
this.container = document.createElement('div');
this.container.className = 'monaco-editor-pane-placeholder';
this.container.style.outline = 'none';
this.container.tabIndex = 0; // enable focus support from the editor part (do not remove)
// Custom Scrollbars
this.scrollbar = this._register(new DomScrollableElement(this.container, { horizontal: ScrollbarVisibility.Auto, vertical: ScrollbarVisibility.Auto }));
parent.appendChild(this.scrollbar.getDomNode());
}
override async setInput(input: EditorInput, options: IEditorOptions | undefined, context: IEditorOpenContext, token: CancellationToken): Promise<void> {
await super.setInput(input, options, context, token);
// Check for cancellation
if (token.isCancellationRequested) {
return;
}
// Render Input
this.inputDisposable.value = this.renderInput(input);
}
private renderInput(input: EditorInput): IDisposable {
const [container, scrollbar] = assertAllDefined(this.container, this.scrollbar);
// Reset any previous contents
clearNode(container);
// Update ARIA label
container.setAttribute('aria-label', computeEditorAriaLabel(input, undefined, this.group, undefined));
// Delegate to implementation
const disposables = new DisposableStore();
this.renderBody(container, disposables);
// Adjust scrollbar
scrollbar.scanDomNode();
return disposables;
}
protected abstract renderBody(container: HTMLElement, disposables: DisposableStore): void;
override clearInput(): void {
if (this.container) {
clearNode(this.container);
}
this.inputDisposable.clear();
super.clearInput();
}
layout(dimension: Dimension): void {
const [container, scrollbar] = assertAllDefined(this.container, this.scrollbar);
// Pass on to Container
size(container, dimension.width, dimension.height);
// Adjust scrollbar
scrollbar.scanDomNode();
}
override focus(): void {
const container = assertIsDefined(this.container);
container.focus();
}
override dispose(): void {
this.container?.remove();
super.dispose();
}
}
export class WorkspaceTrustRequiredEditor extends EditorPlaceholderPane {
static readonly ID = 'workbench.editors.workspaceTrustRequiredEditor';
static readonly LABEL = localize('trustRequiredEditor', "Workspace Trust Required");
static readonly DESCRIPTOR = EditorPaneDescriptor.create(WorkspaceTrustRequiredEditor, WorkspaceTrustRequiredEditor.ID, WorkspaceTrustRequiredEditor.LABEL);
constructor(
@ITelemetryService telemetryService: ITelemetryService,
@IThemeService themeService: IThemeService,
@ICommandService private readonly commandService: ICommandService,
@IWorkspaceContextService private readonly workspaceService: IWorkspaceContextService,
@IStorageService storageService: IStorageService,
@IInstantiationService private readonly instantiationService: IInstantiationService
) {
super(WorkspaceTrustRequiredEditor.ID, WorkspaceTrustRequiredEditor.LABEL, telemetryService, themeService, storageService);
}
protected renderBody(container: HTMLElement, disposables: DisposableStore): void {
const label = container.appendChild(document.createElement('p'));
label.textContent = isSingleFolderWorkspaceIdentifier(toWorkspaceIdentifier(this.workspaceService.getWorkspace())) ?
localize('requiresFolderTrustText', "The file is not displayed in the editor because trust has not been granted to the folder.") :
localize('requiresWorkspaceTrustText', "The file is not displayed in the editor because trust has not been granted to the workspace.");
disposables.add(this.instantiationService.createInstance(Link, label, {
label: localize('manageTrust', "Manage Workspace Trust"),
href: ''
}, {
opener: () => this.commandService.executeCommand('workbench.trust.manage')
}));
}
}
abstract class AbstractErrorEditor extends EditorPlaceholderPane {
constructor(
id: string,
label: string,
@ITelemetryService telemetryService: ITelemetryService,
@IThemeService themeService: IThemeService,
@IStorageService storageService: IStorageService,
@IInstantiationService private readonly instantiationService: IInstantiationService
) {
super(id, label, telemetryService, themeService, storageService);
}
protected abstract getErrorMessage(): string;
protected renderBody(container: HTMLElement, disposables: DisposableStore): void {
const label = container.appendChild(document.createElement('p'));
label.textContent = this.getErrorMessage();
// Offer to re-open
const group = this.group;
const input = this.input;
if (group && input) {
disposables.add(this.instantiationService.createInstance(Link, label, {
label: localize('retry', "Try Again"),
href: ''
}, {
opener: () => group.openEditor(input, { ...this.options, source: EditorOpenSource.USER /* explicit user gesture */ })
}));
}
}
}
export class UnknownErrorEditor extends AbstractErrorEditor {
static readonly ID = 'workbench.editors.unknownErrorEditor';
static readonly LABEL = localize('unknownErrorEditor', "Unknown Error Editor");
static readonly DESCRIPTOR = EditorPaneDescriptor.create(UnknownErrorEditor, UnknownErrorEditor.ID, UnknownErrorEditor.LABEL);
constructor(
@ITelemetryService telemetryService: ITelemetryService,
@IThemeService themeService: IThemeService,
@IStorageService storageService: IStorageService,
@IInstantiationService instantiationService: IInstantiationService
) {
super(UnknownErrorEditor.ID, UnknownErrorEditor.LABEL, telemetryService, themeService, storageService, instantiationService);
}
protected override getErrorMessage(): string {
return localize('unknownErrorEditorText', "The editor could not be opened due to an unexpected error.");
}
}
export class UnavailableResourceErrorEditor extends AbstractErrorEditor {
static readonly ID = 'workbench.editors.unavailableResourceErrorEditor';
static readonly LABEL = localize('unavailableResourceErrorEditor', "Unavailable Resource Error Editor");
static readonly DESCRIPTOR = EditorPaneDescriptor.create(UnavailableResourceErrorEditor, UnavailableResourceErrorEditor.ID, UnavailableResourceErrorEditor.LABEL);
constructor(
@ITelemetryService telemetryService: ITelemetryService,
@IThemeService themeService: IThemeService,
@IStorageService storageService: IStorageService,
@IInstantiationService instantiationService: IInstantiationService
) {
super(UnavailableResourceErrorEditor.ID, UnavailableResourceErrorEditor.LABEL, telemetryService, themeService, storageService, instantiationService);
}
protected override getErrorMessage(): string {
return localize('unavailableResourceErrorEditorText', "The editor could not be opened because the file was not found.");
}
}
|