支持 Unix 上 wave 的显示
This commit is contained in:
parent
473207b78b
commit
57d63f3b05
@ -3,6 +3,8 @@ import * as vscode from 'vscode';
|
|||||||
import * as url from 'url';
|
import * as url from 'url';
|
||||||
import { BSON } from 'bson';
|
import { BSON } from 'bson';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
import * as os from 'os';
|
||||||
|
import { getIconConfig } from '../../hdlFs/icons';
|
||||||
|
|
||||||
export interface SaveViewData {
|
export interface SaveViewData {
|
||||||
originVcdFile: string,
|
originVcdFile: string,
|
||||||
@ -34,9 +36,11 @@ function extractFilepath(webviewUri: string) {
|
|||||||
}
|
}
|
||||||
const parsedUrl = new url.URL(webviewUri);
|
const parsedUrl = new url.URL(webviewUri);
|
||||||
const pathname = decodeURIComponent(parsedUrl.pathname);
|
const pathname = decodeURIComponent(parsedUrl.pathname);
|
||||||
if (pathname.startsWith('/')) {
|
const platform = os.platform();
|
||||||
|
if (platform === 'win32' && pathname.startsWith('/')) {
|
||||||
return pathname.slice(1);
|
return pathname.slice(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return pathname;
|
return pathname;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,6 +110,9 @@ export async function saveViewAs(data: any, uri: vscode.Uri, panel: vscode.Webvi
|
|||||||
const buffer = BSON.serialize(originPayload);
|
const buffer = BSON.serialize(originPayload);
|
||||||
fs.writeFileSync(savePath, buffer);
|
fs.writeFileSync(savePath, buffer);
|
||||||
|
|
||||||
|
panel.title = path.basename(savePath);
|
||||||
|
panel.iconPath = getIconConfig('view');
|
||||||
|
|
||||||
// 创建新的缓存 savePath 会成为新的 originVcdViewFile
|
// 创建新的缓存 savePath 会成为新的 originVcdViewFile
|
||||||
mergePayloadCache(savePath, payload);
|
mergePayloadCache(savePath, payload);
|
||||||
|
|
||||||
@ -153,6 +160,9 @@ export async function loadView(data: any, uri: vscode.Uri, panel: vscode.Webview
|
|||||||
if (viewUri) {
|
if (viewUri) {
|
||||||
const viewPath = viewUri[0].fsPath;
|
const viewPath = viewUri[0].fsPath;
|
||||||
const buffer = fs.readFileSync(viewPath);
|
const buffer = fs.readFileSync(viewPath);
|
||||||
|
panel.title = path.basename(viewPath);
|
||||||
|
panel.iconPath = getIconConfig('view');
|
||||||
|
|
||||||
const recoverJson = BSON.deserialize(buffer);
|
const recoverJson = BSON.deserialize(buffer);
|
||||||
panel.webview.postMessage({
|
panel.webview.postMessage({
|
||||||
command: 'load-view',
|
command: 'load-view',
|
||||||
|
@ -6,6 +6,7 @@ import { hdlFile, hdlPath } from '../../hdlFs';
|
|||||||
import { opeParam, ReportType, WaveViewOutput } from '../../global';
|
import { opeParam, ReportType, WaveViewOutput } from '../../global';
|
||||||
import { LaunchFiles, loadView, saveView, saveViewAs } from './api';
|
import { LaunchFiles, loadView, saveView, saveViewAs } from './api';
|
||||||
import { BSON } from 'bson';
|
import { BSON } from 'bson';
|
||||||
|
import { getIconConfig } from '../../hdlFs/icons';
|
||||||
|
|
||||||
function getWebviewContent(context: vscode.ExtensionContext, panel?: vscode.WebviewPanel): string | undefined {
|
function getWebviewContent(context: vscode.ExtensionContext, panel?: vscode.WebviewPanel): string | undefined {
|
||||||
const dideviewerPath = hdlPath.join(context.extensionPath, 'resources', 'dide-viewer', 'view');
|
const dideviewerPath = hdlPath.join(context.extensionPath, 'resources', 'dide-viewer', 'view');
|
||||||
@ -49,10 +50,6 @@ class WaveViewer {
|
|||||||
this.panel = undefined;
|
this.panel = undefined;
|
||||||
}, null, this.context.subscriptions);
|
}, null, this.context.subscriptions);
|
||||||
|
|
||||||
this.panel.webview.onDidReceiveMessage(message => {
|
|
||||||
console.log(message);
|
|
||||||
}, null, this.context.subscriptions);
|
|
||||||
|
|
||||||
const context = this.context;
|
const context = this.context;
|
||||||
const previewHtml = getWebviewContent(context, this.panel);
|
const previewHtml = getWebviewContent(context, this.panel);
|
||||||
if (this.panel && previewHtml) {
|
if (this.panel && previewHtml) {
|
||||||
@ -69,9 +66,7 @@ class WaveViewer {
|
|||||||
.replace('worker.js', worker)
|
.replace('worker.js', worker)
|
||||||
.replace('<root>', root);
|
.replace('<root>', root);
|
||||||
this.panel.webview.html = preprocessHtml;
|
this.panel.webview.html = preprocessHtml;
|
||||||
|
this.panel.iconPath = getIconConfig('view');
|
||||||
const iconPath = hdlPath.join(context.extensionPath, 'images', 'icon.svg');
|
|
||||||
this.panel.iconPath = vscode.Uri.file(iconPath);
|
|
||||||
registerMessageEvent(this.panel, uri);
|
registerMessageEvent(this.panel, uri);
|
||||||
} else {
|
} else {
|
||||||
WaveViewOutput.report('preview html in <WaveViewer.create> is empty', ReportType.Warn);
|
WaveViewOutput.report('preview html in <WaveViewer.create> is empty', ReportType.Warn);
|
||||||
@ -137,9 +132,7 @@ class VcdViewerProvider implements vscode.CustomEditorProvider {
|
|||||||
.replace('worker.js', worker)
|
.replace('worker.js', worker)
|
||||||
.replace('<root>', root);
|
.replace('<root>', root);
|
||||||
webviewPanel.webview.html = preprocessHtml;
|
webviewPanel.webview.html = preprocessHtml;
|
||||||
|
webviewPanel.iconPath = getIconConfig('view');
|
||||||
const iconPath = hdlPath.join(context.extensionPath, 'images', 'icon.svg');
|
|
||||||
webviewPanel.iconPath = vscode.Uri.file(iconPath);
|
|
||||||
} else {
|
} else {
|
||||||
WaveViewOutput.report('preview html in <WaveViewer.create> is empty', ReportType.Warn);
|
WaveViewOutput.report('preview html in <WaveViewer.create> is empty', ReportType.Warn);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user