/// <summary> /// Injects a workspace containing the block into the block option's preview div. /// </summary> public void showPreviewBlock() { // Get ID of preview workspace. var blockOptPreviewID = this.dom.Id + "_workspace"; // Inject preview block. var workspace = Blockly.Core.inject(blockOptPreviewID, new Dictionary <string, object> { { "readOnly", true } }); Blockly.Xml.domToWorkspace(this.previewBlockXml, workspace); this.previewWorkspace = workspace; // Center the preview block in the workspace. this.centerBlock(); }
/// <summary> /// BlockOption Class /// A block option includes checkbox, label, and div element that shows a preview /// of the block. /// </summary> /// <param name="blockSelector"> Scrollable div that will contain the /// block options for the selector.</param> /// <param name="blockType"> Type of block for which to create an option.</param> /// <param name="=" previewBlockXml XML element containing the preview block. public BlockOption(Element blockSelector, string blockType, Element previewBlockXml) { // The div to contain the block option. this.blockSelector = blockSelector; // The type of block represented by the option. this.blockType = blockType; // The checkbox for the option. Set in createDom. this.checkbox = null; // The dom for the option. Set in createDom. this.dom = null; // Xml element containing the preview block. this.previewBlockXml = previewBlockXml; // Workspace containing preview of block. Set upon injection of workspace in // showPreviewBlock. this.previewWorkspace = null; // Whether or not block the option is selected. this.selected = false; // Using this.selected rather than this.checkbox.Checked allows for proper // handling of click events on the block option; Without this, clicking // directly on the checkbox does not toggle selection. }