diff --git a/demo/src/features/customView.ts b/demo/src/features/customView.ts index 5809235c..8e5a4d49 100644 --- a/demo/src/features/customView.ts +++ b/demo/src/features/customView.ts @@ -1,5 +1,5 @@ -import { IDialogService } from 'vscode/services' -import { registerCustomView, registerEditorPane, ViewContainerLocation } from '@codingame/monaco-vscode-views-service-override' +import { IDialogService, EditorInput, ITelemetryService, IThemeService, IStorageService, createInstance } from 'vscode/services' +import { registerCustomView, registerEditorPane, registerEditor, ViewContainerLocation, SimpleEditorPane, SimpleEditorInput, RegisteredEditorPriority, IEditorCloseHandler, ConfirmResult } from '@codingame/monaco-vscode-views-service-override' import * as monaco from 'monaco-editor' registerCustomView({ @@ -42,20 +42,76 @@ registerCustomView({ }] }) -const { CustomEditorInput } = registerEditorPane({ - id: 'custom-editor-pane', - name: 'Custom editor pane', - renderBody (container) { +class CustomEditorPane extends SimpleEditorPane { + static readonly ID = 'workbench.editors.customEditor' + + constructor ( + @ITelemetryService telemetryService: ITelemetryService, @IThemeService themeService: IThemeService, @IStorageService storageService: IStorageService + ) { + super(CustomEditorPane.ID, telemetryService, themeService, storageService) + } + + initialize (): HTMLElement { + const container = document.createElement('div') container.style.display = 'flex' container.style.alignItems = 'center' container.style.justifyContent = 'center' container.innerHTML = 'This is a custom editor pane
You can render anything you want here' + return container + } + + async renderInput (input: EditorInput): Promise { + if (input.resource != null) { + this.container.innerHTML = 'Opened file: ' + input.resource.path + } else { + this.container.innerHTML = 'This is a custom editor pane
You can render anything you want here' + } return { dispose () { } } } +} +class CustomEditorInput extends SimpleEditorInput implements IEditorCloseHandler { + constructor (resource: monaco.Uri | undefined, @IDialogService private dialogService: IDialogService) { + super(resource) + + this.closeHandler = this + + this.setName('Custom editor pane input') + } + + async confirm (): Promise { + const { confirmed } = await this.dialogService.confirm({ + message: 'Are you sure you want to close this INCREDIBLE editor pane?' + }) + return confirmed ? ConfirmResult.DONT_SAVE : ConfirmResult.CANCEL + } + + showConfirm (): boolean { + return true + } + + get typeId (): string { + return CustomEditorPane.ID + } +} + +registerEditorPane('custom-editor-pane', 'Custom editor pane', CustomEditorPane, [CustomEditorInput]) + +registerEditor('*.customeditor', { + id: CustomEditorPane.ID, + label: 'Custom editor pane input', + priority: RegisteredEditorPriority.default +}, { + singlePerResource: true +}, { + async createEditorInput (editorInput) { + return { + editor: await createInstance(CustomEditorInput, editorInput.resource) + } + } }) export { CustomEditorInput } diff --git a/demo/src/features/filesystem.ts b/demo/src/features/filesystem.ts index 5993d5ba..22974d98 100644 --- a/demo/src/features/filesystem.ts +++ b/demo/src/features/filesystem.ts @@ -49,6 +49,10 @@ $$ $$` )) +fileSystemProvider.registerFile(new RegisteredMemoryFile(vscode.Uri.file('/tmp/test.customeditor'), ` +Custom Editor!` +)) + fileSystemProvider.registerFile(new RegisteredMemoryFile(vscode.Uri.file('/tmp/test.css'), ` h1 { color: DeepSkyBlue; diff --git a/demo/src/main.ts b/demo/src/main.ts index 58019148..513619e5 100644 --- a/demo/src/main.ts +++ b/demo/src/main.ts @@ -3,8 +3,8 @@ import * as monaco from 'monaco-editor' import { createConfiguredEditor, createModelReference } from 'vscode/monaco' import { registerFileSystemOverlay, HTMLFileSystemProvider } from '@codingame/monaco-vscode-files-service-override' import * as vscode from 'vscode' -import { ILogService, StandaloneServices, IPreferencesService, IEditorService, IDialogService, getService } from 'vscode/services' -import { ConfirmResult, Parts, isPartVisibile, setPartVisibility } from '@codingame/monaco-vscode-views-service-override' +import { ILogService, StandaloneServices, IPreferencesService, IEditorService, IDialogService, getService, createInstance } from 'vscode/services' +import { Parts, isPartVisibile, setPartVisibility } from '@codingame/monaco-vscode-views-service-override' import { defaultUserConfigurationFile } from '@codingame/monaco-vscode-configuration-service-override' import { defaultUserKeybindindsFile } from '@codingame/monaco-vscode-keybindings-service-override' import { clearStorage, remoteAuthority } from './setup' @@ -151,17 +151,7 @@ document.querySelector('#keybindingsui')!.addEventListener('click', async () => }) document.querySelector('#customEditorPanel')!.addEventListener('click', async () => { - const input = new CustomEditorInput({ - async confirm () { - const { confirmed } = await StandaloneServices.get(IDialogService).confirm({ - message: 'Are you sure you want to close this INCREDIBLE editor pane?' - }) - return confirmed ? ConfirmResult.DONT_SAVE : ConfirmResult.CANCEL - }, - showConfirm () { - return true - } - }) + const input = await createInstance(CustomEditorInput, undefined) let toggle = false const interval = window.setInterval(() => { const title = toggle ? 'Awesome editor pane' : 'Incredible editor pane'