Skip to content

Commit f6d82d6

Browse files
authored
Add callback for setting checkbox state (#908)
* Demo of hack for checkbox state * Fix jsdoc * Move getCheckboxState into flyout * Remove other reference to default checkbox state * Add public to getCheckedState
1 parent 58901f2 commit f6d82d6

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

core/flyout_vertical.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,7 @@ Blockly.VerticalFlyout.prototype.createRect_ = function(block, x, y,
504504
*/
505505
Blockly.VerticalFlyout.prototype.createCheckbox_ = function(block, cursorX,
506506
cursorY, blockHW) {
507+
var checkboxState = Blockly.VerticalFlyout.getCheckboxState(block.id);
507508
var svgRoot = block.getSvgRoot();
508509
var extraSpace = this.CHECKBOX_SIZE + this.CHECKBOX_MARGIN;
509510
var width = this.RTL ? this.getWidth() / this.workspace_.scale - extraSpace : cursorX;
@@ -525,7 +526,12 @@ Blockly.VerticalFlyout.prototype.createCheckbox_ = function(block, cursorX,
525526
'class': 'blocklyFlyoutCheckboxPath',
526527
'd': this.CHECKMARK_PATH
527528
}, checkboxGroup);
528-
var checkboxObj = {svgRoot: checkboxGroup, clicked: false, block: block};
529+
var checkboxObj = {svgRoot: checkboxGroup, clicked: checkboxState, block: block};
530+
531+
if (checkboxState) {
532+
Blockly.utils.addClass((checkboxObj.svgRoot), 'checked');
533+
}
534+
529535
block.flyoutCheckbox = checkboxObj;
530536
this.workspace_.getCanvas().insertBefore(checkboxGroup, svgRoot);
531537
this.checkboxes_.push(checkboxObj);
@@ -717,3 +723,13 @@ Blockly.VerticalFlyout.prototype.reflowInternal_ = function(/* blocks */) {
717723
// This is a no-op because the flyout is a fixed size.
718724
return;
719725
};
726+
727+
/**
728+
* Gets the checkbox state for a block
729+
* @param {string} blockId The ID of the block in question.
730+
* @return {boolean} Whether the block is checked.
731+
* @public
732+
*/
733+
Blockly.VerticalFlyout.getCheckboxState = function(/* blockId */) {
734+
return false;
735+
};

0 commit comments

Comments
 (0)