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()); + } + } +}