Skip to content

Commit

Permalink
feat(demo): demo new editor panes features
Browse files Browse the repository at this point in the history
  • Loading branch information
Loïc Mangeonjean committed Nov 13, 2023
1 parent 8aaf75e commit 3e1d43e
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 19 deletions.
68 changes: 62 additions & 6 deletions demo/src/features/customView.ts
Original file line number Diff line number Diff line change
@@ -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({
Expand Down Expand Up @@ -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<br />You can render anything you want here'
return container
}

async renderInput (input: EditorInput): Promise<monaco.IDisposable> {
if (input.resource != null) {
this.container.innerHTML = 'Opened file: ' + input.resource.path
} else {
this.container.innerHTML = 'This is a custom editor pane<br />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<ConfirmResult> {
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 }
4 changes: 4 additions & 0 deletions demo/src/features/filesystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 3 additions & 13 deletions demo/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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'
Expand Down

0 comments on commit 3e1d43e

Please sign in to comment.