Working on configuration webview

feature/search
Kelvin Schoofs 6 years ago
parent 4c96f7ed21
commit cc1eef5dff

@ -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": [

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Cat Coding</title>
</head>
<body>
<script src="$ROOT/settings.js"></script>
</body>
</html>

@ -0,0 +1,4 @@
const body = document.body;
body.append('ABC');
console.log('ok');

@ -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 });
}

@ -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<any> {
switch (message.type) {
case 'requestData': {
return webviewPanel!.webview.postMessage(await loadConfigs());
}
}
}
Loading…
Cancel
Save