diff --git a/src/tdmlEditor/media/codicon.css b/src/tdmlEditor/media/codicon.css new file mode 100644 index 000000000..5225ece13 --- /dev/null +++ b/src/tdmlEditor/media/codicon.css @@ -0,0 +1,31 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +@font-face { + font-family: "codicon"; + font-display: block; + src: url("./codicon.ttf?2ab61cbaefbdf4c7c5589068100bee0c") format("truetype"); +} + +.codicon[class*='codicon-'] { + font: normal normal normal 16px/1 codicon; + display: inline-block; + text-decoration: none; + text-rendering: auto; + text-align: center; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; + user-select: none; + -webkit-user-select: none; + -ms-user-select: none; +} + +/*--------------------- + * Icons + *-------------------*/ + +.codicon-add:before { + content: "\ea60" +} \ No newline at end of file diff --git a/src/tdmlEditor/media/codicon.ttf b/src/tdmlEditor/media/codicon.ttf new file mode 100644 index 000000000..ea2309d11 Binary files /dev/null and b/src/tdmlEditor/media/codicon.ttf differ diff --git a/src/tdmlEditor/src/TDMLProvider.ts b/src/tdmlEditor/src/TDMLProvider.ts index 97c0f5131..be4788003 100644 --- a/src/tdmlEditor/src/TDMLProvider.ts +++ b/src/tdmlEditor/src/TDMLProvider.ts @@ -1,133 +1,150 @@ -import * as vscode from 'vscode'; -import { getNonce } from './utilities/getNonce'; -import { printChannelOutput } from './extension'; -import { newTestCaseInput } from './addNewTest'; -import { AppConstants } from './utilities/constants'; +import * as vscode from 'vscode' +import { getNonce } from './utilities/getNonce' +import { printChannelOutput } from './extension' +import { newTestCaseInput } from './addNewTest' +import { AppConstants } from './utilities/constants' export class TDMLProvider implements vscode.CustomTextEditorProvider { - public static register(context: vscode.ExtensionContext): vscode.Disposable { - const provider = new TDMLProvider(context); - const providerRegistration = vscode.window.registerCustomEditorProvider(TDMLProvider.viewType, provider); - printChannelOutput("ResX Editor custom editor provider registered.", true); - return providerRegistration; + const provider = new TDMLProvider(context) + const providerRegistration = vscode.window.registerCustomEditorProvider( + TDMLProvider.viewType, + provider + ) + printChannelOutput('TDML Editor custom editor provider registered.', true) + return providerRegistration } - private static readonly viewType = AppConstants.viewTypeId; - private registered = false; - private currentPanel: vscode.WebviewPanel | undefined = undefined; + private static readonly viewType = AppConstants.viewTypeId + private registered = false + private currentPanel: vscode.WebviewPanel | undefined = undefined - constructor( - private readonly context: vscode.ExtensionContext - ) { } + constructor(private readonly context: vscode.ExtensionContext) {} public async resolveCustomTextEditor( document: vscode.TextDocument, webviewPanel: vscode.WebviewPanel, _token: vscode.CancellationToken ): Promise { - this.currentPanel = webviewPanel; + this.currentPanel = webviewPanel webviewPanel.webview.options = { enableScripts: true, - localResourceRoots: [vscode.Uri.joinPath(this.context.extensionUri, 'out'), vscode.Uri.joinPath(this.context.extensionUri, 'media')] - }; - webviewPanel.webview.html = this._getWebviewContent(webviewPanel.webview); - webviewPanel.onDidChangeViewState(e => { - this.currentPanel = e.webviewPanel; - }); + localResourceRoots: [ + vscode.Uri.joinPath(this.context.extensionUri, 'out'), + vscode.Uri.joinPath(this.context.extensionUri, 'media'), + ], + } + webviewPanel.webview.html = this._getWebviewContent(webviewPanel.webview) + webviewPanel.onDidChangeViewState((e) => { + this.currentPanel = e.webviewPanel + }) try { - printChannelOutput(document.uri.toString(), true); + printChannelOutput(document.uri.toString(), true) if (!this.registered) { - this.registered = true; - let deleteCommand = vscode.commands.registerCommand(AppConstants.deleteTestCommand, () => { - - this.currentPanel?.webview.postMessage({ - type: 'delete' - }); - }); - - let addCommand = vscode.commands.registerCommand(AppConstants.addNewTestCommand, () => { - // get all the inputs we need - const inputs = newTestCaseInput(this.context); - // then do something with them - inputs.then((result) => { + this.registered = true + let deleteCommand = vscode.commands.registerCommand( + AppConstants.deleteTestCommand, + () => { this.currentPanel?.webview.postMessage({ - type: 'add', - key: result.key, - value: result.value, - comment: result.comment - }); - }); - }); - - let openInTextEditorCommand = vscode.commands.registerCommand(AppConstants.openInTextEditorCommand, () => { - printChannelOutput("openInTextEditor command called", true); - vscode.commands.executeCommand('workbench.action.reopenTextEditor', document?.uri); - }); - - this.context.subscriptions.push(openInTextEditorCommand); - this.context.subscriptions.push(deleteCommand); - this.context.subscriptions.push(addCommand); + type: 'delete', + }) + } + ) + + let addCommand = vscode.commands.registerCommand( + AppConstants.addNewTestCommand, + () => { + // get all the inputs we need + const inputs = newTestCaseInput(this.context) + // then do something with them + inputs.then((result) => { + this.currentPanel?.webview.postMessage({ + type: 'add', + key: result.key, + value: result.value, + comment: result.comment, + }) + }) + } + ) + + let openInTextEditorCommand = vscode.commands.registerCommand( + AppConstants.openInTextEditorCommand, + () => { + printChannelOutput('openInTextEditor command called', true) + vscode.commands.executeCommand( + 'workbench.action.reopenTextEditor', + document?.uri + ) + } + ) + + this.context.subscriptions.push(openInTextEditorCommand) + this.context.subscriptions.push(deleteCommand) + this.context.subscriptions.push(addCommand) } - } - catch (e) { - console.log(e); + } catch (e) { + console.log(e) } async function updateWebview() { webviewPanel.webview.postMessage({ type: 'update', - }); + }) } - const changeDocumentSubscription = vscode.workspace.onDidChangeTextDocument(e => { - if (e.document.uri.toString() === document.uri.toString()) { - updateWebview(); + const changeDocumentSubscription = vscode.workspace.onDidChangeTextDocument( + (e) => { + if (e.document.uri.toString() === document.uri.toString()) { + updateWebview() + } } - }); + ) webviewPanel.onDidDispose(() => { - changeDocumentSubscription.dispose(); - }); + changeDocumentSubscription.dispose() + }) - webviewPanel.webview.onDidReceiveMessage(e => { + webviewPanel.webview.onDidReceiveMessage((e) => { switch (e.type) { case 'update': - this.updateTextDocument(document, e.json); - return; + this.updateTextDocument(document, e.json) + return case 'log': - printChannelOutput(e.message, true); - return; + printChannelOutput(e.message, true) + return case 'error': - printChannelOutput(e.message, true); - vscode.window.showErrorMessage(e.message); - return; + printChannelOutput(e.message, true) + vscode.window.showErrorMessage(e.message) + return case 'info': - printChannelOutput(e.message, true); - vscode.window.showInformationMessage(e.message); - return; + printChannelOutput(e.message, true) + vscode.window.showInformationMessage(e.message) + return case 'add': - vscode.commands.executeCommand(AppConstants.addNewTestCommand); - return; - + vscode.commands.executeCommand(AppConstants.addNewTestCommand) + return } - }); + }) - updateWebview(); + updateWebview() } private async updateTextDocument(document: vscode.TextDocument, json: any) { + const edit = new vscode.WorkspaceEdit() - const edit = new vscode.WorkspaceEdit(); - - return vscode.workspace.applyEdit(edit); + return vscode.workspace.applyEdit(edit) } private _getWebviewContent(webview: vscode.Webview) { - const webviewUri = webview.asWebviewUri(vscode.Uri.joinPath(this.context.extensionUri, 'out', 'webview.js')); - const nonce = getNonce(); - const codiconsUri = webview.asWebviewUri(vscode.Uri.joinPath(this.context.extensionUri, 'media', 'codicon.css')); + const webviewUri = webview.asWebviewUri( + vscode.Uri.joinPath(this.context.extensionUri, 'out', 'webview.js') + ) + const nonce = getNonce() + const codiconsUri = webview.asWebviewUri( + vscode.Uri.joinPath(this.context.extensionUri, 'media', 'codicon.css') + ) return /*html*/ ` @@ -151,6 +168,6 @@ export class TDMLProvider implements vscode.CustomTextEditorProvider { - `; + ` } -} \ No newline at end of file +} diff --git a/src/tdmlEditor/src/webview/webview.js b/src/tdmlEditor/src/webview/webview.js index 07d26c92c..383e72740 100644 --- a/src/tdmlEditor/src/webview/webview.js +++ b/src/tdmlEditor/src/webview/webview.js @@ -203,16 +203,15 @@ let currentRowData = null //I believe that text here is the full text string of the document function updateContent(/** @type {string} **/ text) { if (text) { - let [suiteName,tdmlXmlParseed] = getTestCaseDisplayData(text) + let [suiteName, tdmlXmlParseed] = getTestCaseDisplayData(text) for (const testCase in tdmlXmlParseed || []) { if (testCase) { - let test = // eslint-disable-next-line @typescript-eslint/naming-convention var test = { - Key: testCase[0], - Value: testCase[1] || '', - Comment: testCase[2] || '', + Key: testCase.testCaseName, + Value: testCase.testCaseModel, + Comment: testCase.testCaseDescription, } tdmlValues.push(test) } else {