Skip to content
Snippets Groups Projects
Commit 1a10c85d authored by Smit, P.J.M. (Peter, Student M-CS)'s avatar Smit, P.J.M. (Peter, Student M-CS)
Browse files

Added save and copy Dot buttons to dotview

parent f873126d
No related branches found
No related tags found
No related merge requests found
......@@ -87,7 +87,7 @@ svgContainer.onmousewheel = (e) => {
};
svgContainer.onmousedown = (e) => {
if (svgImage !== null) {
if (svgImage !== null && e.button !== 1) {
lastPoint = { x: e.x, y: e.y };
document.onmousemove = (e) => {
......
......@@ -129,6 +129,14 @@
{
"command": "modest.dotCopySvg",
"title": "Copy svg to clipboard"
},
{
"command": "modest.dotSaveDot",
"title": "Save to .dot file"
},
{
"command": "modest.dotCopyDot",
"title": "Copy dot to clipboard"
}
],
"menus": {
......@@ -233,6 +241,14 @@
{
"when": "modest:dotViewFocused",
"command": "modest.dotCopySvg"
},
{
"when": "modest:dotViewFocused",
"command": "modest.dotSaveDot"
},
{
"when": "modest:dotViewFocused",
"command": "modest.dotCopyDot"
}
]
},
......
......@@ -48,6 +48,14 @@ export namespace ModestCommands {
LiveDotView.currentDotView?.copySvg();
});
export let dotSaveDot = vscode.commands.registerCommand('modest.dotSaveDot', async () => {
LiveDotView.currentDotView?.saveDot();
});
export let dotCopyDot = vscode.commands.registerCommand('modest.dotCopyDot', async () => {
LiveDotView.currentDotView?.copyDot();
});
class LiveDotView {
public static currentDotView: LiveDotView | undefined;
......@@ -56,7 +64,7 @@ export namespace ModestCommands {
private fileUri: vscode.Uri;
private panel: vscode.WebviewPanel;
private webview: vscode.Webview;
private lastSvgStr: string | undefined;
private lastDotInfo: DotInformation | undefined;
public constructor(fileUri: vscode.Uri, sameColumn = false) {
this.fileUri = fileUri;
......@@ -91,10 +99,10 @@ export namespace ModestCommands {
if (e.webviewPanel.active) {
LiveDotView.currentDotView = this;
}
if (this.lastSvgStr) {
if (this.lastDotInfo) {
this.webview.postMessage({
type: 'svg',
svg: this.lastSvgStr
svg: this.lastDotInfo.svg
});
}
},
......@@ -127,13 +135,13 @@ export namespace ModestCommands {
}
public saveSvg() {
if (this.lastSvgStr) {
if (this.lastDotInfo) {
const defaultUri = vscode.workspace.workspaceFolders
? vscode.Uri.parse(`{vscode.workspace.workspaceFolders[0].uri.fsPath}/analysis/${this.fileUri.path.split("/").pop()?.slice(0, -1 * '.modest'.length)}.svg`)
: undefined;
vscode.window.showSaveDialog({ defaultUri: defaultUri }).then(f => {
if (f) {
fs.writeFileSync(f.fsPath, this.lastSvgStr);
fs.writeFileSync(f.fsPath, this.lastDotInfo?.svg);
}
});
} else {
......@@ -142,8 +150,31 @@ export namespace ModestCommands {
}
public copySvg() {
if (this.lastSvgStr) {
vscode.env.clipboard.writeText(this.lastSvgStr);
if (this.lastDotInfo) {
vscode.env.clipboard.writeText(this.lastDotInfo.svg);
} else {
vscode.window.showErrorMessage("There are no analysis results to be exported.");
}
}
public saveDot() {
if (this.lastDotInfo) {
const defaultUri = vscode.workspace.workspaceFolders
? vscode.Uri.parse(`{vscode.workspace.workspaceFolders[0].uri.fsPath}/analysis/${this.fileUri.path.split("/").pop()?.slice(0, -1 * '.modest'.length)}.dot`)
: undefined;
vscode.window.showSaveDialog({ defaultUri: defaultUri }).then(f => {
if (f) {
fs.writeFileSync(f.fsPath, this.lastDotInfo?.dot);
}
});
} else {
vscode.window.showErrorMessage("There are no analysis results to be exported.");
}
}
public copyDot() {
if (this.lastDotInfo) {
vscode.env.clipboard.writeText(this.lastDotInfo.dot);
} else {
vscode.window.showErrorMessage("There are no analysis results to be exported.");
}
......@@ -151,12 +182,12 @@ export namespace ModestCommands {
private updateDot() {
let jsonObject = { "textDocument": TextDocumentIdentifier.create(this.fileUri.toString()) };
client?.sendRequest<string>("modest/dot", jsonObject).then(data => {
client?.sendRequest<DotInformation>("modest/dot", jsonObject).then(data => {
if (data !== null) {
this.lastSvgStr = data;
this.lastDotInfo = data;
this.webview.postMessage({
type: 'svg',
svg: data
svg: data.svg
});
}
});
......@@ -192,4 +223,8 @@ export namespace ModestCommands {
`;
}
}
interface DotInformation {
dot: string,
svg: string,
}
}
\ No newline at end of file
......@@ -140,6 +140,8 @@ export function activate(context: ExtensionContext) {
context.subscriptions.push(ModestCommands.resetDotPosition);
context.subscriptions.push(ModestCommands.dotSaveSvg);
context.subscriptions.push(ModestCommands.dotCopySvg);
context.subscriptions.push(ModestCommands.dotSaveDot);
context.subscriptions.push(ModestCommands.dotCopyDot);
extensionUri = context.extensionUri;
//#region listeners
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment