Skip to content
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

[MPQEditor] Implement handleLoadVisqFile #1555

Merged
merged 3 commits into from
May 22, 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
61 changes: 57 additions & 4 deletions src/MPQEditor/MPQEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
MPQSelectionCmdCloseArgs,
MPQSelectionCmdOpenArgs,
MPQSelectionCmdLayersChangedArgs,
MPQVisqData,
} from "./MPQCircleSelector";

export class MPQEditorProvider
Expand Down Expand Up @@ -334,6 +335,9 @@ export class MPQEditorProvider
case "toggleCircleGraphIsShown":
this.toggleCircleGraphIsShown(e.show, document, webviewPanel);
break;
case "loadVisqFile":
this.handleLoadVisqFile(document, webviewPanel);
break;
case "removeVisqFile":
this.removeVisqFile(document, webviewPanel);
break;
Expand Down Expand Up @@ -673,11 +677,31 @@ export class MPQEditorProvider
* @brief Called when it's needed to show visq data in circle-graph
*/
private showVisqCircleModelGraph(
_visqPath: string,
_document: vscode.TextDocument,
_webviewPanel: vscode.WebviewPanel
visqPath: string,
document: vscode.TextDocument,
webviewPanel: vscode.WebviewPanel
) {
// TODO
const args: MPQSelectionCmdOpenArgs = {
modelPath: this.getModelFilePath(document),
document: document,
names: this._mpqDataMap[document.uri.toString()].getLayers(),
panel: webviewPanel,
};

const visqData: MPQVisqData = {
visqPath: visqPath,
};
vscode.commands.executeCommand(
MPQSelectionPanel.cmdOpenVisq,
args,
visqData,
this
);

webviewPanel.webview.postMessage({
type: "VisqFileLoaded",
visqFile: visqPath,
});
}

/**
Expand Down Expand Up @@ -716,4 +740,33 @@ export class MPQEditorProvider
this.showCircleModelGraph(document, webviewPanel);
}
}

/**
* @brief Called when user requests to load visq file from UI
*/
private handleLoadVisqFile(
document: vscode.TextDocument,
webviewPanel: vscode.WebviewPanel
) {
const dialogOptions = {
canSelectMany: false,
canSelectFolders: false,
openLabel: "Open",
filters: { "target files": ["visq.json"], "all files": ["*"] },
stamalakhov marked this conversation as resolved.
Show resolved Hide resolved
title: "Open VISQ File",
};

vscode.window.showOpenDialog(dialogOptions).then((fileUri) => {
if (fileUri && fileUri[0]) {
const visqPath = fileUri[0].fsPath.toString();

const docUri = document.uri.toString();
this._mpqDataMap[docUri].visqPath = visqPath;
// close previous view if any
this.closeModelGraphView(document);
// open new view
this.showVisqCircleModelGraph(visqPath, document, webviewPanel);
}
});
}
}