Skip to content

Commit 8cbbd83

Browse files
committed
- [new]: simple config ui supported
1 parent eddc682 commit 8cbbd83

10 files changed

Lines changed: 156 additions & 1 deletion

File tree

res/html/simple_config_ui/css/app.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
346 KB
Binary file not shown.
448 KB
Binary file not shown.
389 KB
Binary file not shown.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<!doctype html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>eide_config_ui</title><script type="module" src="js/vscode-webview-ui-toolkit.min.js"></script><style>body {
2+
margin: 12px 40px;
3+
}</style><script defer="defer" src="js/chunk-vendors.js"></script><script defer="defer" src="js/app.js"></script><link href="css/app.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but eide_config_ui doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div></body></html>

res/html/simple_config_ui/js/app.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

res/html/simple_config_ui/js/chunk-vendors.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

res/html/simple_config_ui/js/vscode-webview-ui-toolkit.min.js

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/SimpleUIDef.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
2+
export interface SimpleUIConfig {
3+
4+
title: string; // title for this config
5+
6+
readonly?: boolean;
7+
8+
iconName?: string;
9+
10+
items: {
11+
[key: string]: SimpleUIConfigItem;
12+
};
13+
};
14+
15+
export interface SimpleUIConfigData {
16+
17+
value: any;
18+
19+
default: any;
20+
}
21+
22+
export interface SimpleUIConfigItem {
23+
24+
type: 'input' | 'options' | 'table' | 'text';
25+
26+
typeDetail: { [key: string]: string | boolean | number };
27+
28+
name: string; // readable name
29+
30+
description?: string; // a description for this item
31+
32+
data: SimpleUIConfigData | SimpleUIConfigData_input | SimpleUIConfigData_options | SimpleUIConfigData_table;
33+
};
34+
35+
export interface SimpleUIConfigData_input extends SimpleUIConfigData {
36+
37+
value: string;
38+
39+
default: string;
40+
41+
placeHolder?: string;
42+
}
43+
44+
export interface SimpleUIConfigData_options extends SimpleUIConfigData {
45+
46+
value: number; // index of enum
47+
48+
default: number;
49+
50+
enum: string[];
51+
52+
enumDescriptions: string[];
53+
}
54+
55+
export interface SimpleUIConfigData_table extends SimpleUIConfigData {
56+
57+
value: { [col: string]: string }[];
58+
59+
default: { [col: string]: string }[];
60+
}
61+
62+
export interface SimpleUIConfigData_text extends SimpleUIConfigData {
63+
64+
value: string;
65+
}

src/WebPanelManager.ts

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import * as os from 'os'
3535
import * as platform from './Platform';
3636
import * as fs from 'fs';
3737
import { EncodingConverter } from "./EncodingConverter";
38+
import { SimpleUIConfig } from "./SimpleUIDef";
3839

3940
let _instance: WebPanelManager;
4041

@@ -43,13 +44,67 @@ export class WebPanelManager {
4344
private constructor() {
4445
}
4546

46-
static newInstance(): WebPanelManager {
47+
static instance(): WebPanelManager {
4748
if (_instance === undefined) {
4849
_instance = new WebPanelManager();
4950
}
5051
return _instance;
5152
}
5253

54+
showSimpleConfigUI(cfg: SimpleUIConfig, onSave: (newCfg: SimpleUIConfig) => void): Promise<void> {
55+
56+
const resManager = ResManager.GetInstance();
57+
58+
const panel = vscode.window.createWebviewPanel('eide.simple-cfg-ui',
59+
cfg.title, vscode.ViewColumn.One, { enableScripts: true, retainContextWhenHidden: true });
60+
61+
panel.iconPath = vscode.Uri.file(resManager.GetIconByName(cfg.iconName || 'Property_16x.svg').path);
62+
63+
return new Promise((resolve_) => {
64+
65+
panel.onDidDispose(() => {
66+
resolve_();
67+
});
68+
69+
panel.webview.onDidReceiveMessage((_data: any) => {
70+
71+
/* it's a message */
72+
if (typeof _data == 'string') {
73+
switch (_data) {
74+
case 'eide.simple-cfg-ui.launched': /* webview launched */
75+
panel.webview.postMessage(cfg);
76+
break;
77+
default:
78+
break;
79+
}
80+
}
81+
82+
/* it's obj data */
83+
else {
84+
try {
85+
onSave(_data);
86+
panel.webview.postMessage('eide.simple-cfg-ui.status.done');
87+
} catch (error) {
88+
GlobalEvent.emit('error', error);
89+
panel.webview.postMessage('eide.simple-cfg-ui.status.fail');
90+
}
91+
}
92+
});
93+
94+
const htmlFolder = File.fromArray([resManager.GetHTMLDir().path, 'simple_config_ui']);
95+
const htmlFile = File.fromArray([htmlFolder.path, 'index.html']);
96+
97+
panel.webview.html = htmlFile.Read()
98+
.replace(/"[\w\-\.\/]+?\.(?:css|js)"/ig, (str) => {
99+
const fileName = str.substr(1, str.length - 2); // remove '"'
100+
const absPath = File.normalize(htmlFolder.path + NodePath.sep + fileName);
101+
return `"${panel.webview.asWebviewUri(vscode.Uri.file(absPath)).toString()}"`;
102+
});
103+
104+
panel.reveal();
105+
});
106+
}
107+
53108
showStorageLayoutView(project: AbstractProject): void {
54109

55110
const resManager = ResManager.GetInstance();

0 commit comments

Comments
 (0)