From cc1eef5dff361ee89ab8c1d5155b36fc915a0d81 Mon Sep 17 00:00:00 2001 From: Kelvin Schoofs Date: Mon, 25 Feb 2019 22:22:53 +0100 Subject: [PATCH] Working on configuration webview --- package.json | 17 ++++++++++++++++- resources/settings.html | 14 ++++++++++++++ resources/settings.js | 4 ++++ src/extension.ts | 3 +++ src/settings.ts | 31 +++++++++++++++++++++++++++++++ 5 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 resources/settings.html create mode 100644 resources/settings.js create mode 100644 src/settings.ts diff --git a/package.json b/package.json index e7ee03c..2fdb0e1 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,9 @@ "onCommand:sshfs.reconnect", "onCommand:sshfs.disconnect", "onCommand:sshfs.configure", - "onCommand:sshfs.delete" + "onCommand:sshfs.delete", + "onCommand:sshfs.reload", + "onCommand:sshfs.settings" ], "main": "./out/extension.js", "author": { @@ -76,6 +78,11 @@ "command": "sshfs.reload", "title": "Reload configurations", "category": "SSH FS" + }, + { + "command": "sshfs.settings", + "title": "Open settings and edit configurations", + "category": "SSH FS" } ], "menus": { @@ -106,6 +113,14 @@ "command": "sshfs.delete", "group": "SSH FS@6", "when": "view == 'DISABLED'" + }, + { + "command": "sshfs.reload", + "group": "SSH FS@7" + }, + { + "command": "sshfs.settings", + "group": "SSH FS@8" } ], "view/item/context": [ diff --git a/resources/settings.html b/resources/settings.html new file mode 100644 index 0000000..e40655a --- /dev/null +++ b/resources/settings.html @@ -0,0 +1,14 @@ + + + + + + + Cat Coding + + + + + + + \ No newline at end of file diff --git a/resources/settings.js b/resources/settings.js new file mode 100644 index 0000000..a94ea02 --- /dev/null +++ b/resources/settings.js @@ -0,0 +1,4 @@ + +const body = document.body; +body.append('ABC'); +console.log('ok'); diff --git a/src/extension.ts b/src/extension.ts index ecec456..13b0969 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -4,6 +4,7 @@ import { invalidConfigName, loadConfigs } from './config'; import { FileSystemConfig } from './fileSystemConfig'; import * as Logging from './logging'; import { Manager } from './manager'; +import * as settings from './settings'; function generateDetail(config: FileSystemConfig): string | undefined { const { username, host, putty } = config; @@ -66,5 +67,7 @@ export function activate(context: vscode.ExtensionContext) { registerCommand('sshfs.reload', loadConfigs); + registerCommand('sshfs.settings', () => settings.open(context.extensionPath)); + vscode.window.createTreeView('sshfs-configs', { treeDataProvider: manager }); } diff --git a/src/settings.ts b/src/settings.ts new file mode 100644 index 0000000..88be0ac --- /dev/null +++ b/src/settings.ts @@ -0,0 +1,31 @@ + +import * as fs from 'fs'; +import * as path from 'path'; +import * as vscode from 'vscode'; +import { loadConfigs } from './config'; + +let webviewPanel: vscode.WebviewPanel | undefined; + +export function open(extensionPath: string) { + if (!webviewPanel) { + webviewPanel = vscode.window.createWebviewPanel('sshfs-settings', 'SSH-FS Settings', vscode.ViewColumn.One, { enableScripts: true }); + webviewPanel.onDidDispose(() => webviewPanel = undefined); + webviewPanel.webview.onDidReceiveMessage(handleMessage); + const content = fs.readFileSync(path.resolve(extensionPath, 'resources/settings.html')).toString(); + webviewPanel.webview.html = content.replace(/\$ROOT/g, vscode.Uri.file(path.join(extensionPath, 'resources')).with({ scheme: 'vscode-resource' }).toString()); + } + webviewPanel.reveal(); +} + +interface RequestDataMessage { + type: 'requestData'; +} +type Message = { type: 'requestData' } | RequestDataMessage; + +async function handleMessage(message: Message): Promise { + switch (message.type) { + case 'requestData': { + return webviewPanel!.webview.postMessage(await loadConfigs()); + } + } +}