Skip to content

[MPQEditor] Implement open and other commands #1536

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 26, 2023
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
76 changes: 75 additions & 1 deletion src/MPQEditor/MPQCircleSelector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,26 @@ export type MPQSelectionCmdOpenArgs = {
panel: vscode.WebviewPanel;
};

export type MPQSelectionCmdCloseArgs = {
modelPath: string;
document: vscode.TextDocument;
};

export type MPQSelectionCmdLayersChangedArgs = {
modelPath: string;
document: vscode.TextDocument;
names: any;
};

export class MPQSelectionPanel
extends CircleGraphCtrl
implements CircleGraphEvent
{
public static readonly viewType = "one.viewer.mpq";
public static readonly cmdOpen = "one.viewer.mpq.openGraphSelector";
public static readonly cmdClose = "one.viewer.mpq.closeGraphSelector";
public static readonly cmdChanged = "one.viewer.mpq.layersChangedByOwner";

public static panels: MPQSelectionPanel[] = [];

private _panel: vscode.WebviewPanel;
Expand All @@ -52,7 +67,33 @@ export class MPQSelectionPanel
private _lastSelected: string[];
private _closedByOwner: boolean = false;

public static register(_context: vscode.ExtensionContext): void {}
public static register(context: vscode.ExtensionContext): void {
const registrations = [
vscode.commands.registerCommand(
MPQSelectionPanel.cmdOpen,
(args: MPQSelectionCmdOpenArgs, handler: MPQSelectionEvent) => {
MPQSelectionPanel.createOrShow(context.extensionUri, args, handler);
}
),
vscode.commands.registerCommand(
MPQSelectionPanel.cmdClose,
(args: MPQSelectionCmdCloseArgs) => {
MPQSelectionPanel.closeByOwner(context.extensionUri, args);
}
),
vscode.commands.registerCommand(
MPQSelectionPanel.cmdChanged,
(args: MPQSelectionCmdLayersChangedArgs) => {
MPQSelectionPanel.forwardSelectionByOwner(context.extensionUri, args);
}
),
// TODO add more commands
];

registrations.forEach((disposable) =>
context.subscriptions.push(disposable)
);
}

public static createOrShow(
extensionUri: vscode.Uri,
Expand Down Expand Up @@ -111,6 +152,39 @@ export class MPQSelectionPanel
return result;
}

/**
* @brief called when owner is closing
*/
public static closeByOwner(
extensionUri: vscode.Uri,
args: MPQSelectionCmdCloseArgs
) {
let selPanel = MPQSelectionPanel.findSelPanel(
args.modelPath,
args.document.uri.toString()
);
if (selPanel) {
selPanel._closedByOwner = true;
selPanel.dispose();
}
}

/**
* @brief called when owner selection state of nodes has changed
*/
public static forwardSelectionByOwner(
extensionUri: vscode.Uri,
args: MPQSelectionCmdLayersChangedArgs
) {
let selPanel = MPQSelectionPanel.findSelPanel(
args.modelPath,
args.document.uri.toString()
);
if (selPanel) {
selPanel.onForwardSelection(args.names);
}
}

private constructor(
panel: vscode.WebviewPanel,
extensionUri: vscode.Uri,
Expand Down