forked from eclipse-cdt-cloud/vscode-trace-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changes made: - Uses an theia independent react widget for Properties view from traceviewer-react-components - Proper signal handling between item properties webview and extension This will add the Item Properties View to the Trace Viewer. Fixes eclipse-cdt-cloud#62 Signed-off-by: Neel Gondalia ngondalia@blackberry.com
- Loading branch information
Showing
17 changed files
with
218 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
73 changes: 73 additions & 0 deletions
73
...xtension/src/trace-explorer/properties/trace-explorer-properties-view-webview-provider.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/*************************************************************************************** | ||
* Copyright (c) 2023 BlackBerry Limited and contributors. | ||
* | ||
* Licensed under the MIT license. See LICENSE file in the project root for details. | ||
***************************************************************************************/ | ||
import * as vscode from 'vscode'; | ||
import { getTraceServerUrl } from 'vscode-trace-extension/src/utils/tspClient'; | ||
|
||
export class TraceExplorerItemPropertiesProvider implements vscode.WebviewViewProvider { | ||
public static readonly viewType = 'traceExplorer.itemPropertiesView'; | ||
private _view?: vscode.WebviewView; | ||
constructor(private readonly _extensionUri: vscode.Uri) {} | ||
|
||
resolveWebviewView( | ||
webviewView: vscode.WebviewView, | ||
_context: vscode.WebviewViewResolveContext, | ||
_token: vscode.CancellationToken | ||
): void { | ||
this._view = webviewView; | ||
webviewView.webview.options = { | ||
// Allow scripts in the webview | ||
enableScripts: true, | ||
localResourceRoots: [vscode.Uri.joinPath(this._extensionUri, 'pack')], | ||
}; | ||
webviewView.webview.html = this._getHtmlForWebview(webviewView.webview); | ||
} | ||
|
||
postMessagetoWebview(_command: string, _data: unknown): void { | ||
if (this._view && _command && _data) { | ||
this._view.webview.postMessage({command: _command, data: _data}); | ||
} | ||
} | ||
|
||
/* eslint-disable max-len */ | ||
private _getHtmlForWebview(webview: vscode.Webview) { | ||
// Get the local path to main script run in the webview, then convert it to a uri we can use in the webview. | ||
const scriptUri = webview.asWebviewUri(vscode.Uri.joinPath(this._extensionUri, 'pack', 'propertiesPanel.js')); | ||
|
||
// Use a nonce to only allow a specific script to be run. | ||
const nonce = getNonce(); | ||
|
||
return `<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"> | ||
<meta name="theme-color" content="#000000"> | ||
<title>React App</title> | ||
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src vscode-resource: https:; script-src 'nonce-${nonce}' 'unsafe-eval';style-src vscode-resource: 'unsafe-inline' http: https: data:;connect-src ${getTraceServerUrl()};"> | ||
<base href="${vscode.Uri.joinPath(this._extensionUri, 'pack').with({ scheme: 'vscode-resource' })}/"> | ||
</head> | ||
<body> | ||
<noscript>You need to enable JavaScript to run this app.</noscript> | ||
<div id="root"></div> | ||
<script nonce="${nonce}"> | ||
const vscode = acquireVsCodeApi(); | ||
</script> | ||
<script nonce="${nonce}" src="${scriptUri}"></script> | ||
</body> | ||
</html>`; | ||
} | ||
} | ||
|
||
function getNonce() { | ||
let text = ''; | ||
const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; | ||
for (let i = 0; i < 32; i++) { | ||
text += possible.charAt(Math.floor(Math.random() * possible.length)); | ||
} | ||
return text; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions
5
vscode-trace-webviews/src/trace-explorer/properties/index.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
body { | ||
margin: 0; | ||
padding: 0; | ||
font-family: sans-serif; | ||
} |
14 changes: 14 additions & 0 deletions
14
vscode-trace-webviews/src/trace-explorer/properties/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/*************************************************************************************** | ||
* Copyright (c) 2023 BlackBerry Limited and contributors. | ||
* | ||
* Licensed under the MIT license. See LICENSE file in the project root for details. | ||
***************************************************************************************/ | ||
import * as React from 'react'; | ||
import * as ReactDOM from 'react-dom'; | ||
import './index.css'; | ||
import TraceExplorerProperties from './vscode-trace-explorer-properties-widget'; | ||
|
||
ReactDOM.render( | ||
<TraceExplorerProperties />, | ||
(document.getElementById('root') as HTMLElement) | ||
); |
64 changes: 64 additions & 0 deletions
64
...-trace-webviews/src/trace-explorer/properties/vscode-trace-explorer-properties-widget.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/*************************************************************************************** | ||
* Copyright (c) 2023 BlackBerry Limited and contributors. | ||
* | ||
* Licensed under the MIT license. See LICENSE file in the project root for details. | ||
***************************************************************************************/ | ||
/* eslint-disable @typescript-eslint/ban-types */ | ||
import React from 'react'; | ||
import { VsCodeMessageManager } from 'vscode-trace-webviews/src/common/vscode-message-manager'; | ||
import { ReactItemPropertiesWidget } from 'traceviewer-react-components/lib/trace-explorer/trace-explorer-properties-widget'; | ||
import { signalManager } from 'traceviewer-base/lib/signals/signal-manager'; | ||
|
||
interface PropertiesViewState { | ||
properties: { [key: string]: string }; | ||
} | ||
|
||
class TraceExplorerProperties extends React.Component<{}, PropertiesViewState> { | ||
static ID = 'trace-explorer-properties-widget'; | ||
static LABEL = 'Item Properties'; | ||
private _signalHandler: VsCodeMessageManager; | ||
|
||
constructor(props: {}) { | ||
super(props); | ||
this.state = { | ||
properties: {} | ||
}; | ||
this._signalHandler = new VsCodeMessageManager(); | ||
|
||
window.addEventListener('message', event => { | ||
const message = event.data; // The JSON data our extension sent | ||
switch (message.command) { | ||
case 'receivedProperties': | ||
signalManager().fireItemPropertiesSignalUpdated(message.data.properties); | ||
break; | ||
} | ||
}); | ||
} | ||
|
||
componentDidMount(): void { | ||
this._signalHandler.notifyReady(); | ||
} | ||
|
||
public render(): React.ReactNode { | ||
return ( | ||
<div> | ||
<ReactItemPropertiesWidget | ||
id={TraceExplorerProperties.ID} | ||
title={TraceExplorerProperties.LABEL} | ||
handleSourcecodeLookup={this.handleSourcecodeLookup} | ||
></ReactItemPropertiesWidget> | ||
</div> | ||
); | ||
} | ||
|
||
protected handleSourcecodeLookup = (e: React.MouseEvent<HTMLParagraphElement>): void => this.doHandleSourcecodeLookup(e); | ||
|
||
private doHandleSourcecodeLookup(e: React.MouseEvent<HTMLParagraphElement>) { | ||
const { fileLocation, line }: { fileLocation: string, line: string } = JSON.parse(`${e.currentTarget.getAttribute('data-id')}`); | ||
console.log('filename: ' + fileLocation + ':' + line); | ||
console.log('Source lookup method not implemented'); | ||
} | ||
|
||
} | ||
|
||
export default TraceExplorerProperties; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters