Skip to content

Commit f78a5eb

Browse files
committed
Reveal graph if it already exist instead of opening a new panel every time the a command is executed.
1 parent 0d9e2ea commit f78a5eb

File tree

1 file changed

+49
-33
lines changed

1 file changed

+49
-33
lines changed

src/extension.ts

Lines changed: 49 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -47,53 +47,69 @@ export function activate(context: vscode.ExtensionContext) {
4747
});
4848
context.subscriptions.push(componentHierarchyMarkdownDisposable);
4949

50+
let componentHierarchyPanel: vscode.WebviewPanel | undefined = undefined;
5051
const showComponentHierarchyDisposable = vscode.commands.registerCommand(`${cmdPrefix}.${ShowComponentHierarchy.commandName}`, () => {
51-
const componentHierarchyPanel = vscode.window.createWebviewPanel(
52-
'angularTools_showComponentHierarchy',
53-
'Angular component hierarchy',
54-
vscode.ViewColumn.One,
55-
{
56-
enableScripts: true
57-
}
58-
);
59-
componentHierarchyPanel.onDidDispose(() => {
60-
}, null, context.subscriptions);
52+
if (componentHierarchyPanel !== undefined) {
53+
componentHierarchyPanel.reveal(vscode.ViewColumn.One);
54+
} else {
55+
componentHierarchyPanel = vscode.window.createWebviewPanel(
56+
'angularTools_showComponentHierarchy',
57+
'Angular component hierarchy',
58+
vscode.ViewColumn.One,
59+
{
60+
enableScripts: true
61+
}
62+
);
63+
componentHierarchyPanel.onDidDispose(() => {
64+
}, null, context.subscriptions);
65+
}
6166
const command = new ShowComponentHierarchy(context);
6267
command.execute(componentHierarchyPanel.webview);
6368
});
6469
context.subscriptions.push(showComponentHierarchyDisposable);
65-
70+
71+
let moduleHierarchyPanel: vscode.WebviewPanel | undefined = undefined;
6672
const showModuleHierarchyDisposable = vscode.commands.registerCommand(`${cmdPrefix}.${ShowModuleHierarchy.commandName}`, () => {
67-
const moduleHierarchyPanel = vscode.window.createWebviewPanel(
68-
'angularTools_showModuleHierarchy',
69-
'Angular module hierarchy',
70-
vscode.ViewColumn.One,
71-
{
72-
enableScripts: true
73-
}
74-
);
75-
moduleHierarchyPanel.onDidDispose(() => {
76-
}, null, context.subscriptions);
73+
if (moduleHierarchyPanel !== undefined) {
74+
moduleHierarchyPanel.reveal(vscode.ViewColumn.One);
75+
} else {
76+
moduleHierarchyPanel = vscode.window.createWebviewPanel(
77+
'angularTools_showModuleHierarchy',
78+
'Angular module hierarchy',
79+
vscode.ViewColumn.One,
80+
{
81+
enableScripts: true
82+
}
83+
);
84+
moduleHierarchyPanel.onDidDispose(() => {
85+
}, null, context.subscriptions);
86+
}
7787
const command = new ShowModuleHierarchy(context);
7888
command.execute(moduleHierarchyPanel.webview);
7989
});
8090
context.subscriptions.push(showModuleHierarchyDisposable);
81-
91+
92+
let dependencyInjectionGraphPanel: vscode.WebviewPanel | undefined = undefined;
8293
const generateDependencyInjectionGraphDisposable = vscode.commands.registerCommand(`${cmdPrefix}.${GenerateDependencyInjectionGraph.commandName}`, () => {
83-
const dependencyInjectionGraphPanel = vscode.window.createWebviewPanel(
84-
'angularTools_generateDependencyInjectionGraph',
85-
'Angular dependency injection graph',
86-
vscode.ViewColumn.One,
87-
{
88-
enableScripts: true
89-
}
90-
);
91-
dependencyInjectionGraphPanel.onDidDispose(() => {
92-
}, null, context.subscriptions);
94+
if (dependencyInjectionGraphPanel !== undefined) {
95+
dependencyInjectionGraphPanel.reveal(vscode.ViewColumn.One);
96+
} else {
97+
dependencyInjectionGraphPanel = vscode.window.createWebviewPanel(
98+
'angularTools_generateDependencyInjectionGraph',
99+
'Angular dependency injection graph',
100+
vscode.ViewColumn.One,
101+
{
102+
enableScripts: true
103+
}
104+
);
105+
dependencyInjectionGraphPanel.onDidDispose(() => {
106+
}, null, context.subscriptions);
107+
}
93108
const command = new GenerateDependencyInjectionGraph(context);
94109
command.execute(dependencyInjectionGraphPanel.webview);
95110
});
96-
context.subscriptions.push(generateDependencyInjectionGraphDisposable);}
111+
context.subscriptions.push(generateDependencyInjectionGraphDisposable);
112+
}
97113

98114
// this method is called when your extension is deactivated
99115
export function deactivate() { }

0 commit comments

Comments
 (0)