Skip to content

Commit 85ce6a7

Browse files
committed
use singleton pattern for each views type
1 parent 0487168 commit 85ce6a7

1 file changed

Lines changed: 34 additions & 4 deletions

File tree

src/WebPanelManager.ts

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ let _instance: WebPanelManager;
4343

4444
export class WebPanelManager {
4545

46+
private builderOptionViewRef: Map<string, vscode.WebviewPanel> = new Map();
47+
private memoryLayoutViewRef: Map<string, vscode.WebviewPanel> = new Map();
48+
private cmsisHeaderViewRef: Map<string, vscode.WebviewPanel> = new Map();
49+
4650
private constructor() {
4751
}
4852

@@ -115,17 +119,25 @@ export class WebPanelManager {
115119

116120
showStorageLayoutView(project: AbstractProject): void {
117121

118-
const resManager = ResManager.GetInstance();
122+
const oldpanel = this.memoryLayoutViewRef.get(project.getUid());
123+
if (oldpanel) {
124+
oldpanel.reveal();
125+
return;
126+
}
119127

128+
const resManager = ResManager.GetInstance();
120129
const panel = vscode.window.createWebviewPanel('MemoryLayoutView',
121130
view_str$compile$storageLayout, vscode.ViewColumn.One,
122131
{ enableScripts: true, retainContextWhenHidden: true });
123132

133+
this.memoryLayoutViewRef.set(project.getUid(), panel);
134+
124135
// set web icon
125136
panel.iconPath = vscode.Uri.parse(resManager.GetIconByName('Memory_16x.svg').ToUri());
126137

127138
panel.onDidDispose(() => {
128-
//TODO
139+
console.log(`[eide] onDidDispose memoryLayoutView for ${project.getRootDir().path}`);
140+
this.memoryLayoutViewRef.delete(project.getUid());
129141
});
130142

131143
const compileModel = <ArmBaseCompileConfigModel>project.GetConfiguration().compileConfigModel;
@@ -174,6 +186,12 @@ export class WebPanelManager {
174186

175187
showBuilderOptions(project: AbstractProject): void {
176188

189+
const oldpanel = this.builderOptionViewRef.get(project.getUid());
190+
if (oldpanel) {
191+
oldpanel.reveal();
192+
return;
193+
}
194+
177195
const projectConfig = project.GetConfiguration();
178196
const resManager = ResManager.GetInstance();
179197
const htmlFolder = File.fromArray([resManager.GetHTMLDir().path, 'builder_options']);
@@ -191,6 +209,8 @@ export class WebPanelManager {
191209
panelOptions
192210
);
193211

212+
this.builderOptionViewRef.set(project.getUid(), panel);
213+
194214
// init panel data
195215
panel.iconPath = vscode.Uri.parse(resManager.GetIconByName('Property_16x.svg').ToUri());
196216

@@ -232,7 +252,8 @@ export class WebPanelManager {
232252
}
233253

234254
panel.onDidDispose(() => {
235-
// TODO
255+
console.log(`[eide] onDidDispose builderOptionView for ${project.getRootDir().path}`);
256+
this.builderOptionViewRef.delete(project.getUid());
236257
});
237258

238259
panel.webview.onDidReceiveMessage(async (data) => {
@@ -305,6 +326,12 @@ export class WebPanelManager {
305326

306327
showCmsisConfigWizard(uri: vscode.Uri): void {
307328

329+
const oldpanel = this.cmsisHeaderViewRef.get(uri.fsPath);
330+
if (oldpanel) {
331+
oldpanel.reveal();
332+
return;
333+
}
334+
308335
// get current encoding for this file
309336
const fencoding = vscode.workspace.getConfiguration(undefined, uri).get<string>('files.encoding') || 'utf8';
310337
const inputFile = new File(uri.fsPath);
@@ -348,6 +375,8 @@ export class WebPanelManager {
348375
panelOptions
349376
);
350377

378+
this.cmsisHeaderViewRef.set(uri.fsPath, panel);
379+
351380
// init panel data
352381
panel.iconPath = vscode.Uri.parse(resManager.GetIconByName('Property_16x.svg').ToUri());
353382

@@ -358,7 +387,8 @@ export class WebPanelManager {
358387
};
359388

360389
panel.onDidDispose(() => {
361-
// TODO
390+
console.log(`[eide] onDidDispose CmsisConfigWizard for ${uri.fsPath}`);
391+
this.cmsisHeaderViewRef.delete(uri.fsPath);
362392
});
363393

364394
panel.webview.onDidReceiveMessage((data) => {

0 commit comments

Comments
 (0)