Skip to content

Commit 8d8fed5

Browse files
authored
[MPQEditor] Implement message processing (#1526)
This commit implements message processing. ONE-vscode-DCO-1.0-Signed-off-by: s.malakhov <[email protected]>
1 parent cc00550 commit 8d8fed5

File tree

1 file changed

+104
-1
lines changed

1 file changed

+104
-1
lines changed

src/MPQEditor/MPQEditor.ts

+104-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,110 @@ export class MPQEditorProvider implements vscode.CustomTextEditorProvider {
268268
html = html.replace(/\${codiconUri}/g, `${codiconUri}`);
269269
webview.html = html;
270270

271-
//TODO process messages
271+
// Receive message from the webview.
272+
webview.onDidReceiveMessage((e) => {
273+
switch (e.type) {
274+
case "requestDisplayMPQ":
275+
this.updateWebview(document, webview);
276+
break;
277+
case "addSpecificLayerFromDialog":
278+
this.hadleAddSpecificLayerFromDialog(document);
279+
break;
280+
case "updateLayers":
281+
this._mpqDataMap[document.uri.toString()].setLayersSections(
282+
e.names,
283+
e.quantization,
284+
e.granularity
285+
);
286+
break;
287+
case "updateSpecificQuantization":
288+
this._mpqDataMap[document.uri.toString()].updateSectionOfLayer(
289+
e.name,
290+
"dtype",
291+
e.value
292+
);
293+
break;
294+
case "updateSpecificGranularity":
295+
this._mpqDataMap[document.uri.toString()].updateSectionOfLayer(
296+
e.name,
297+
"granularity",
298+
e.value
299+
);
300+
break;
301+
case "requestModelNodes":
302+
this.handleRequestModelNodes(document, webview);
303+
break;
304+
case "updateSection":
305+
this._mpqDataMap[document.uri.toString()].setSection(
306+
e.section,
307+
e.value
308+
);
309+
break;
310+
case "updateDocument":
311+
this.updateDocument(document);
312+
break;
313+
case "removeLayer":
314+
this.handleRemoveLayerFromLayers(e.name, document);
315+
break;
316+
default:
317+
break;
318+
}
319+
});
320+
}
321+
322+
/**
323+
* @brief Update document
324+
*/
325+
private async updateDocument(document: vscode.TextDocument) {
326+
if (
327+
this._mpqDataMap[document.uri.toString()].getAsString() !==
328+
document.getText()
329+
) {
330+
MPQEditorProvider.updateDocumentBy(
331+
document,
332+
this._mpqDataMap[document.uri.toString()].getAsString()
333+
);
334+
}
335+
}
336+
337+
/**
338+
* @brief Add layers to edit their quantization parameters
339+
*/
340+
private hadleAddSpecificLayerFromDialog(document: vscode.TextDocument) {
341+
const nodes =
342+
this._mpqDataMap[document.uri.toString()].getDefaultModelLayers();
343+
const pickOptions = {
344+
title: "Add specific layers to edit their quantization parameters",
345+
matchOnDescription: true,
346+
matchOnDetail: true,
347+
placeHolder: "Select layers",
348+
ignoreFocusOut: true,
349+
canPickMany: true,
350+
};
351+
352+
vscode.window
353+
.showQuickPick(nodes, pickOptions)
354+
.then((values: string | undefined) => {
355+
if (!values) {
356+
return;
357+
}
358+
359+
this._mpqDataMap[document.uri.toString()].addLayers(values);
360+
this.updateDocument(document);
361+
});
362+
}
363+
364+
/**
365+
* @brief Remove layer from specif layers (add it to 'default' layers)
366+
*/
367+
private handleRemoveLayerFromLayers(
368+
name: string,
369+
document: vscode.TextDocument
370+
) {
371+
let curConf = this._mpqDataMap[document.uri.toString()];
372+
curConf.setLayersToDefault([name]);
373+
374+
this.updateDocument(document);
272375
}
273376

274377
private initWebviewPanel(

0 commit comments

Comments
 (0)