MCPcopy
hub / github.com/RaspberryPiFoundation/blockly / loadWorkspaceComment

Function loadWorkspaceComment

packages/blockly/core/xml.ts:517–545  ·  view source on GitHub ↗
(
  elem: Element,
  workspace: Workspace,
)

Source from the content-addressed store, hash-verified

515
516/** Deserializes the given comment state into the given workspace. */
517export function loadWorkspaceComment(
518 elem: Element,
519 workspace: Workspace,
520): WorkspaceComment {
521 const id = elem.getAttribute('id') ?? undefined;
522 const comment = workspace.rendered
523 ? new RenderedWorkspaceComment(workspace as WorkspaceSvg, id)
524 : new WorkspaceComment(workspace, id);
525
526 comment.setText(elem.textContent ?? '');
527
528 let x = parseInt(elem.getAttribute('x') ?? '', 10);
529 const y = parseInt(elem.getAttribute('y') ?? '', 10);
530 if (!isNaN(x) && !isNaN(y)) {
531 x = workspace.RTL ? workspace.getWidth() - x : x;
532 comment.moveTo(new Coordinate(x, y));
533 }
534
535 const w = parseInt(elem.getAttribute('w') ?? '', 10);
536 const h = parseInt(elem.getAttribute('h') ?? '', 10);
537 if (!isNaN(w) && !isNaN(h)) comment.setSize(new Size(w, h));
538
539 if (elem.getAttribute('collapsed') === 'true') comment.setCollapsed(true);
540 if (elem.getAttribute('editable') === 'false') comment.setEditable(false);
541 if (elem.getAttribute('movable') === 'false') comment.setMovable(false);
542 if (elem.getAttribute('deletable') === 'false') comment.setDeletable(false);
543
544 return comment;
545}
546
547/**
548 * Decode an XML DOM and create blocks on the workspace. Position the new

Callers 1

domToWorkspaceFunction · 0.85

Calls 8

setTextMethod · 0.65
getWidthMethod · 0.65
moveToMethod · 0.65
setSizeMethod · 0.45
setCollapsedMethod · 0.45
setEditableMethod · 0.45
setMovableMethod · 0.45
setDeletableMethod · 0.45

Tested by

no test coverage detected