editors - use link widget in placeholders (#130971)

This commit is contained in:
Benjamin Pasero
2021-08-18 09:22:59 +02:00
parent 50730d166f
commit 0afc6fa148
5 changed files with 47 additions and 30 deletions
@@ -14,13 +14,15 @@ 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, append, addDisposableListener, EventType, $ } from 'vs/base/browser/dom';
import { Dimension, size, clearNode, append } 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 { ByteSize } from 'vs/platform/files/common/files';
import { IEditorOptions } from 'vs/platform/editor/common/editor';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { Link } from 'vs/platform/opener/browser/link';
export interface IOpenCallbacks {
openInternal: (input: EditorInput, options: IEditorOptions | undefined) => Promise<void>;
@@ -47,7 +49,8 @@ export abstract class BaseBinaryResourceEditor extends EditorPane {
private readonly callbacks: IOpenCallbacks,
telemetryService: ITelemetryService,
themeService: IThemeService,
@IStorageService storageService: IStorageService
@IStorageService storageService: IStorageService,
@IInstantiationService private readonly instantiationService: IInstantiationService
) {
super(id, telemetryService, themeService, storageService);
}
@@ -98,17 +101,22 @@ export abstract class BaseBinaryResourceEditor extends EditorPane {
label.textContent = localize('nativeBinaryError', "The file is not displayed in the editor because it is either binary or uses an unsupported text encoding.");
binaryContainer.appendChild(label);
const link = append(label, $('a.embedded-link'));
link.setAttribute('role', 'button');
link.textContent = localize('openAsText', "Do you want to open it anyway?");
const link = this._register(this.instantiationService.createInstance(Link, {
label: localize('openAsText', "Do you want to open it anyway?"),
href: ''
}, {
opener: async () => {
disposables.add(addDisposableListener(link, EventType.CLICK, async () => {
await this.callbacks.openInternal(input, options);
// Open in place
await this.callbacks.openInternal(input, options);
// Signal to listeners that the binary editor has been opened in-place
this._onDidOpenInPlace.fire();
// Signal to listeners that the binary editor has been opened in-place
this._onDidOpenInPlace.fire();
}
}));
append(label, link.el);
scrollbar.scanDomNode();
// Update metadata
@@ -12,7 +12,7 @@ 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, append, addDisposableListener, EventType, $ } from 'vs/base/browser/dom';
import { Dimension, size, clearNode, append } 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';
@@ -22,6 +22,8 @@ import { isSingleFolderWorkspaceIdentifier, toWorkspaceIdentifier } from 'vs/pla
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { IEditorOptions } from 'vs/platform/editor/common/editor';
import { EditorPaneDescriptor } from 'vs/workbench/browser/editor';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { Link } from 'vs/platform/opener/browser/link';
abstract class EditorPanePlaceholder extends EditorPane {
@@ -130,7 +132,8 @@ export class WorkspaceTrustRequiredEditor extends EditorPanePlaceholder {
@IThemeService themeService: IThemeService,
@ICommandService private readonly commandService: ICommandService,
@IWorkspaceContextService private readonly workspaceService: IWorkspaceContextService,
@IStorageService storageService: IStorageService
@IStorageService storageService: IStorageService,
@IInstantiationService private readonly instantiationService: IInstantiationService
) {
super(WorkspaceTrustRequiredEditor.ID, WorkspaceTrustRequiredEditor.LABEL, telemetryService, themeService, storageService);
}
@@ -141,13 +144,14 @@ export class WorkspaceTrustRequiredEditor extends EditorPanePlaceholder {
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.");
const link = append(label, $('a.embedded-link'));
link.setAttribute('role', 'button');
link.textContent = localize('manageTrust', "Manage Workspace Trust");
disposables.add(addDisposableListener(link, EventType.CLICK, async () => {
await this.commandService.executeCommand('workbench.trust.manage');
const link = this._register(this.instantiationService.createInstance(Link, {
label: localize('manageTrust', "Manage Workspace Trust"),
href: ''
}, {
opener: () => this.commandService.executeCommand('workbench.trust.manage')
}));
append(label, link.el);
}
}
@@ -160,7 +164,8 @@ export class UnavailableEditor extends EditorPanePlaceholder {
constructor(
@ITelemetryService telemetryService: ITelemetryService,
@IThemeService themeService: IThemeService,
@IStorageService storageService: IStorageService
@IStorageService storageService: IStorageService,
@IInstantiationService private readonly instantiationService: IInstantiationService
) {
super(UnavailableEditor.ID, UnavailableEditor.LABEL, telemetryService, themeService, storageService);
}
@@ -173,13 +178,14 @@ export class UnavailableEditor extends EditorPanePlaceholder {
const group = this.group;
const input = this.input;
if (group && input) {
const link = append(label, $('a.embedded-link'));
link.setAttribute('role', 'button');
link.textContent = localize('retry', "Try Again");
disposables.add(addDisposableListener(link, EventType.CLICK, () => {
group.openEditor(input, this.options);
const link = this._register(this.instantiationService.createInstance(Link, {
label: localize('retry', "Try Again"),
href: ''
}, {
opener: () => group.openEditor(input, this.options)
}));
append(label, link.el);
}
}
}
@@ -12,8 +12,8 @@
box-sizing: border-box;
}
.monaco-binary-resource-editor .embedded-link,
.monaco-binary-resource-editor .embedded-link:hover {
.monaco-binary-resource-editor .monaco-link,
.monaco-binary-resource-editor .monaco-link:hover {
cursor: pointer;
text-decoration: underline;
margin-left: 5px;
@@ -12,8 +12,8 @@
box-sizing: border-box;
}
.monaco-editor-pane-placeholder .embedded-link,
.monaco-editor-pane-placeholder .embedded-link:hover {
.monaco-editor-pane-placeholder .monaco-link,
.monaco-editor-pane-placeholder .monaco-link:hover {
cursor: pointer;
text-decoration: underline;
margin-left: 5px;
@@ -16,6 +16,7 @@ import { EditorResolution, IEditorOptions } from 'vs/platform/editor/common/edit
import { IEditorResolverService, ResolvedStatus, ResolvedEditor } from 'vs/workbench/services/editor/common/editorResolverService';
import { isEditorInputWithOptions } from 'vs/workbench/common/editor';
import { DiffEditorInput } from 'vs/workbench/common/editor/diffEditorInput';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
/**
* An implementation of editor for binary files that cannot be displayed.
@@ -29,7 +30,8 @@ export class BinaryFileEditor extends BaseBinaryResourceEditor {
@IThemeService themeService: IThemeService,
@IEditorService private readonly editorService: IEditorService,
@IEditorResolverService private readonly editorResolverService: IEditorResolverService,
@IStorageService storageService: IStorageService
@IStorageService storageService: IStorageService,
@IInstantiationService instantiationService: IInstantiationService
) {
super(
BinaryFileEditor.ID,
@@ -38,7 +40,8 @@ export class BinaryFileEditor extends BaseBinaryResourceEditor {
},
telemetryService,
themeService,
storageService
storageService,
instantiationService
);
}