Skip to content

Commit 9c1f33b

Browse files
authored
[MPQEditor] Implement 'createOrShow' (#1535)
This commit implements 'createOrShow' along with needful functions for it. ONE-vscode-DCO-1.0-Signed-off-by: s.malakhov <[email protected]>
1 parent 58b6515 commit 9c1f33b

File tree

1 file changed

+69
-1
lines changed

1 file changed

+69
-1
lines changed

src/MPQEditor/MPQCircleSelector.ts

+69-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17+
import * as path from "path";
1718
import * as vscode from "vscode";
1819

1920
import {
@@ -39,7 +40,6 @@ export class MPQSelectionPanel
3940
implements CircleGraphEvent
4041
{
4142
public static readonly viewType = "one.viewer.mpq";
42-
4343
public static panels: MPQSelectionPanel[] = [];
4444

4545
private _panel: vscode.WebviewPanel;
@@ -54,6 +54,63 @@ export class MPQSelectionPanel
5454

5555
public static register(_context: vscode.ExtensionContext): void {}
5656

57+
public static createOrShow(
58+
extensionUri: vscode.Uri,
59+
args: MPQSelectionCmdOpenArgs,
60+
handler: MPQSelectionEvent | undefined
61+
) {
62+
let column = args.panel.viewColumn;
63+
if (column) {
64+
if (column >= vscode.ViewColumn.One) {
65+
column = column + 1;
66+
}
67+
}
68+
69+
// search for existing panel
70+
const oldPanel = MPQSelectionPanel.findSelPanel(
71+
args.modelPath,
72+
args.document.uri.toString()
73+
);
74+
if (oldPanel) {
75+
oldPanel._panel.reveal(column);
76+
return;
77+
}
78+
79+
// Otherwise, create a new panel.
80+
const lastSlash = args.modelPath.lastIndexOf(path.sep) + 1;
81+
const fileNameExt = args.modelPath.substring(lastSlash);
82+
const panel = vscode.window.createWebviewPanel(
83+
MPQSelectionPanel.viewType,
84+
fileNameExt,
85+
column || vscode.ViewColumn.Two,
86+
{ retainContextWhenHidden: true }
87+
);
88+
89+
const graphSelPanel = new MPQSelectionPanel(
90+
panel,
91+
extensionUri,
92+
args,
93+
handler
94+
);
95+
96+
MPQSelectionPanel.panels.push(graphSelPanel);
97+
graphSelPanel.loadContent();
98+
graphSelPanel.onForwardSelection(args.names);
99+
}
100+
101+
private static findSelPanel(
102+
docPath: string,
103+
id: string
104+
): MPQSelectionPanel | undefined {
105+
let result = undefined;
106+
MPQSelectionPanel.panels.forEach((selpan) => {
107+
if (docPath === selpan._modelPath && id === selpan._ownerId) {
108+
result = selpan;
109+
}
110+
});
111+
return result;
112+
}
113+
57114
private constructor(
58115
panel: vscode.WebviewPanel,
59116
extensionUri: vscode.Uri,
@@ -91,4 +148,15 @@ export class MPQSelectionPanel
91148
public onViewMessage(_message: any) {
92149
// TODO
93150
}
151+
152+
public onForwardSelection(selection: any) {
153+
let selections: string[] = [];
154+
let items = selection as Array<string>;
155+
for (let i = 0; i < items.length; i++) {
156+
if (items[i].length > 0) {
157+
selections.push(items[i]);
158+
}
159+
}
160+
this.setSelection(selections);
161+
}
94162
}

0 commit comments

Comments
 (0)