Skip to content

Commit 8cc2184

Browse files
committed
support singleton pattern for SimpleUIConfig
1 parent 08b1300 commit 8cc2184

3 files changed

Lines changed: 26 additions & 2 deletions

File tree

src/EIDEProjectExplorer.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5074,6 +5074,7 @@ export class ProjectExplorer implements CustomConfigurationProvider {
50745074

50755075
const cfg: SimpleUIConfig = {
50765076
title: 'Project Variables',
5077+
ref_id: `<project-variables>:${prj.getUid()}`,
50775078
readonly: true,
50785079
btns: {
50795080
submit: {
@@ -5392,6 +5393,7 @@ export class ProjectExplorer implements CustomConfigurationProvider {
53925393
inheritedArgs = inheritedArgs.trim();
53935394

53945395
const ui_cfg: SimpleUIConfig = {
5396+
ref_id: `<file-options>:${fspath}`,
53955397
title: isChinese
53965398
? `修改编译选项(文件:${NodePath.basename(fspath)})`
53975399
: `Modify Compiler Options (file: ${NodePath.basename(fspath)})`,
@@ -5751,6 +5753,7 @@ export class ProjectExplorer implements CustomConfigurationProvider {
57515753
inheritedOptions = inheritedOptions.trim();
57525754

57535755
const ui_cfg: SimpleUIConfig = {
5756+
ref_id: `<folder-options>:${folderpath}`,
57545757
title: isChinese
57555758
? `修改编译选项(目录:${NodePath.basename(folderpath)})`
57565759
: `Modify Compiler Options (dir: ${NodePath.basename(folderpath)})`,
@@ -7349,6 +7352,7 @@ export class ProjectExplorer implements CustomConfigurationProvider {
73497352
let toolchainPath = setting.getConfiguration().get(toolchainPathSettingName) || '';
73507353

73517354
let cfg: SimpleUIConfig = {
7355+
ref_id: `<toolchain-config>:${project.getUid()}`,
73527356
title: 'Toolchain Configurations',
73537357
items: {
73547358
'path': {
@@ -7358,7 +7362,7 @@ export class ProjectExplorer implements CustomConfigurationProvider {
73587362
},
73597363
name: 'Toolchain Path',
73607364
data: <SimpleUIConfigData_input>{
7361-
placeHolder: 'toolchain dir, like: ${userRoot}/.eide/tools/<toolchain_id>',
7365+
placeHolder: 'toolchain dir, like: ${userHome}/.eide/tools/<toolchain_id>',
73627366
value: toolchainPath,
73637367
default: toolchainPath
73647368
}
@@ -7648,7 +7652,9 @@ export class ProjectExplorer implements CustomConfigurationProvider {
76487652

76497653
const isChinese = getLocalLanguageType() == LanguageIndexs.Chinese;
76507654
const ui: SimpleUIConfig = {
7651-
title: (isChinese ? '创建 Cortex-Debug ({}) 调试配置模板' : 'Create Cortex-Debug ({}) Configuration Template').replace('{}', type.toUpperCase()),
7655+
title: (isChinese
7656+
? '创建 Cortex-Debug ({}) 调试配置模板'
7657+
: 'Create Cortex-Debug ({}) Configuration Template').replace('{}', type.toUpperCase()),
76527658
viewColumn: vscode.ViewColumn.One,
76537659
notTakeFocus: false,
76547660
btns: {

src/SimpleUIDef.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ export interface SimpleUIConfig {
44

55
title: string; // title for this config
66

7+
ref_id?: string; // 用于唯一地标识该配置,避免重复打开两个完全一样的配置
8+
79
readonly?: boolean;
810

911
iconName?: string;

src/WebPanelManager.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export class WebPanelManager {
4646
private builderOptionViewRef: Map<string, vscode.WebviewPanel> = new Map();
4747
private memoryLayoutViewRef: Map<string, vscode.WebviewPanel> = new Map();
4848
private cmsisHeaderViewRef: Map<string, vscode.WebviewPanel> = new Map();
49+
private simpleConfigViewRef: Map<string, vscode.WebviewPanel> = new Map();
4950

5051
private constructor() {
5152
}
@@ -61,6 +62,12 @@ export class WebPanelManager {
6162
onSubmit: (newCfg: SimpleUIConfig, thisPanel: vscode.WebviewPanel) => Promise<void | 'canceled'>,
6263
onMsg?: (msg: string, thisPanel: vscode.WebviewPanel) => void): vscode.WebviewPanel {
6364

65+
const oldpanel = cfg.ref_id ? this.simpleConfigViewRef.get(cfg.ref_id) : undefined;
66+
if (oldpanel) {
67+
oldpanel.reveal();
68+
return oldpanel;
69+
}
70+
6471
const resManager = ResManager.GetInstance();
6572

6673
let ViewCol = cfg.viewColumn;
@@ -74,6 +81,15 @@ export class WebPanelManager {
7481
{ viewColumn: ViewCol, preserveFocus: cfg.notTakeFocus },
7582
{ enableScripts: true, retainContextWhenHidden: true });
7683

84+
if (cfg.ref_id) {
85+
const uid = cfg.ref_id;
86+
this.simpleConfigViewRef.set(uid, panel);
87+
panel.onDidDispose(() => {
88+
console.log(`[eide] onDidDispose simpleConfigView for ${uid}`);
89+
this.simpleConfigViewRef.delete(uid);
90+
});
91+
}
92+
7793
panel.iconPath = vscode.Uri.file(resManager.GetIconByName(cfg.iconName || 'Property_16x.svg').path);
7894

7995
panel.webview.onDidReceiveMessage(async (_data: any) => {

0 commit comments

Comments
 (0)