Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 69 additions & 1 deletion src/MPQEditor/MPQCircleSelector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

import * as path from "path";
import * as vscode from "vscode";

import {
Expand All @@ -39,7 +40,6 @@ export class MPQSelectionPanel
implements CircleGraphEvent
{
public static readonly viewType = "one.viewer.mpq";

public static panels: MPQSelectionPanel[] = [];

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

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

public static createOrShow(
extensionUri: vscode.Uri,
args: MPQSelectionCmdOpenArgs,
handler: MPQSelectionEvent | undefined
) {
let column = args.panel.viewColumn;
if (column) {
if (column >= vscode.ViewColumn.One) {
column = column + 1;
}
}

// search for existing panel
const oldPanel = MPQSelectionPanel.findSelPanel(
args.modelPath,
args.document.uri.toString()
);
if (oldPanel) {
oldPanel._panel.reveal(column);
return;
}

// Otherwise, create a new panel.
const lastSlash = args.modelPath.lastIndexOf(path.sep) + 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 By using this, we can expect that it will work on Windows too. (Otherwise, seperator differs on OS so it won't work). But it wouldn't harm to check the functionality on Windows.

const fileNameExt = args.modelPath.substring(lastSlash);
const panel = vscode.window.createWebviewPanel(
MPQSelectionPanel.viewType,
fileNameExt,
column || vscode.ViewColumn.Two,
{ retainContextWhenHidden: true }
);

const graphSelPanel = new MPQSelectionPanel(
panel,
extensionUri,
args,
handler
);

MPQSelectionPanel.panels.push(graphSelPanel);
graphSelPanel.loadContent();
graphSelPanel.onForwardSelection(args.names);
}

private static findSelPanel(
docPath: string,
id: string
): MPQSelectionPanel | undefined {
let result = undefined;
MPQSelectionPanel.panels.forEach((selpan) => {
if (docPath === selpan._modelPath && id === selpan._ownerId) {
result = selpan;
}
});
return result;
}

private constructor(
panel: vscode.WebviewPanel,
extensionUri: vscode.Uri,
Expand Down Expand Up @@ -91,4 +148,15 @@ export class MPQSelectionPanel
public onViewMessage(_message: any) {
// TODO
}

public onForwardSelection(selection: any) {
let selections: string[] = [];
let items = selection as Array<string>;
for (let i = 0; i < items.length; i++) {
if (items[i].length > 0) {
selections.push(items[i]);
}
}
this.setSelection(selections);
}
}