Skip to content

Commit

Permalink
Add icons and change up some small things
Browse files Browse the repository at this point in the history
  • Loading branch information
NolanMatt committed Nov 10, 2023
1 parent 3121b29 commit 689a722
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 92 deletions.
31 changes: 31 additions & 0 deletions src/tdmlEditor/media/codicon.css
Original file line number Diff line number Diff line change
@@ -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"
}
Binary file added src/tdmlEditor/media/codicon.ttf
Binary file not shown.
191 changes: 104 additions & 87 deletions src/tdmlEditor/src/TDMLProvider.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
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*/ `
<!DOCTYPE html>
Expand All @@ -151,6 +168,6 @@ export class TDMLProvider implements vscode.CustomTextEditorProvider {
<script type="module" nonce="${nonce}" src="${webviewUri}"></script>
</body>
</html>
`;
`
}
}
}
9 changes: 4 additions & 5 deletions src/tdmlEditor/src/webview/webview.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 689a722

Please sign in to comment.