From a5ea93a1dbef4fe194402e6927155572bc4e03c7 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Thu, 17 Dec 2015 14:16:04 -0800 Subject: [PATCH] Allow comments in flyouts. --- blocks/procedures.js | 26 ++++++++++++++------------ core/block_svg.js | 14 +++++++------- core/flyout.js | 4 ---- core/workspace_svg.js | 2 +- core/xml.js | 2 +- 5 files changed, 23 insertions(+), 25 deletions(-) diff --git a/blocks/procedures.js b/blocks/procedures.js index 492ca7d749a..9b1f35778ea 100644 --- a/blocks/procedures.js +++ b/blocks/procedures.js @@ -40,8 +40,6 @@ Blockly.Blocks['procedures_defnoreturn'] = { * @this Blockly.Block */ init: function() { - this.setHelpUrl(Blockly.Msg.PROCEDURES_DEFNORETURN_HELPURL); - this.setColour(Blockly.Blocks.procedures.HUE); var nameField = new Blockly.FieldTextInput( Blockly.Msg.PROCEDURES_DEFNORETURN_PROCEDURE, Blockly.Procedures.rename); @@ -51,7 +49,10 @@ Blockly.Blocks['procedures_defnoreturn'] = { .appendField(nameField, 'NAME') .appendField('', 'PARAMS'); this.setMutator(new Blockly.Mutator(['procedures_mutatorarg'])); + this.setCommentText(''); // TODO: Add 'Describe this function...' + this.setColour(Blockly.Blocks.procedures.HUE); this.setTooltip(Blockly.Msg.PROCEDURES_DEFNORETURN_TOOLTIP); + this.setHelpUrl(Blockly.Msg.PROCEDURES_DEFNORETURN_HELPURL); this.arguments_ = []; this.setStatements_(true); this.statementConnection_ = null; @@ -343,8 +344,6 @@ Blockly.Blocks['procedures_defreturn'] = { * @this Blockly.Block */ init: function() { - this.setHelpUrl(Blockly.Msg.PROCEDURES_DEFRETURN_HELPURL); - this.setColour(Blockly.Blocks.procedures.HUE); var nameField = new Blockly.FieldTextInput( Blockly.Msg.PROCEDURES_DEFRETURN_PROCEDURE, Blockly.Procedures.rename); @@ -357,7 +356,10 @@ Blockly.Blocks['procedures_defreturn'] = { .setAlign(Blockly.ALIGN_RIGHT) .appendField(Blockly.Msg.PROCEDURES_DEFRETURN_RETURN); this.setMutator(new Blockly.Mutator(['procedures_mutatorarg'])); + this.setCommentText(''); // TODO: Add 'Describe this function...' + this.setColour(Blockly.Blocks.procedures.HUE); this.setTooltip(Blockly.Msg.PROCEDURES_DEFRETURN_TOOLTIP); + this.setHelpUrl(Blockly.Msg.PROCEDURES_DEFRETURN_HELPURL); this.arguments_ = []; this.setStatements_(true); this.statementConnection_ = null; @@ -393,13 +395,13 @@ Blockly.Blocks['procedures_mutatorcontainer'] = { * @this Blockly.Block */ init: function() { - this.setColour(Blockly.Blocks.procedures.HUE); this.appendDummyInput() .appendField(Blockly.Msg.PROCEDURES_MUTATORCONTAINER_TITLE); this.appendStatementInput('STACK'); this.appendDummyInput('STATEMENT_INPUT') .appendField(Blockly.Msg.PROCEDURES_ALLOW_STATEMENTS) .appendField(new Blockly.FieldCheckbox('TRUE'), 'STATEMENTS'); + this.setColour(Blockly.Blocks.procedures.HUE); this.setTooltip(Blockly.Msg.PROCEDURES_MUTATORCONTAINER_TOOLTIP); this.contextMenu = false; } @@ -411,12 +413,12 @@ Blockly.Blocks['procedures_mutatorarg'] = { * @this Blockly.Block */ init: function() { - this.setColour(Blockly.Blocks.procedures.HUE); this.appendDummyInput() .appendField(Blockly.Msg.PROCEDURES_MUTATORARG_TITLE) .appendField(new Blockly.FieldTextInput('x', this.validator_), 'NAME'); this.setPreviousStatement(true); this.setNextStatement(true); + this.setColour(Blockly.Blocks.procedures.HUE); this.setTooltip(Blockly.Msg.PROCEDURES_MUTATORARG_TOOLTIP); this.contextMenu = false; }, @@ -441,14 +443,14 @@ Blockly.Blocks['procedures_callnoreturn'] = { * @this Blockly.Block */ init: function() { - this.setHelpUrl(Blockly.Msg.PROCEDURES_CALLNORETURN_HELPURL); - this.setColour(Blockly.Blocks.procedures.HUE); this.appendDummyInput('TOPROW') .appendField(Blockly.Msg.PROCEDURES_CALLNORETURN_CALL) .appendField('', 'NAME'); this.setPreviousStatement(true); this.setNextStatement(true); + this.setColour(Blockly.Blocks.procedures.HUE); // Tooltip is set in domToMutation. + this.setHelpUrl(Blockly.Msg.PROCEDURES_CALLNORETURN_HELPURL); this.arguments_ = []; this.quarkConnections_ = {}; this.quarkArguments_ = null; @@ -670,13 +672,13 @@ Blockly.Blocks['procedures_callreturn'] = { * @this Blockly.Block */ init: function() { - this.setHelpUrl(Blockly.Msg.PROCEDURES_CALLRETURN_HELPURL); - this.setColour(Blockly.Blocks.procedures.HUE); this.appendDummyInput('TOPROW') .appendField(Blockly.Msg.PROCEDURES_CALLRETURN_CALL) .appendField('', 'NAME'); this.setOutput(true); + this.setColour(Blockly.Blocks.procedures.HUE); // Tooltip is set in domToMutation. + this.setHelpUrl(Blockly.Msg.PROCEDURES_CALLRETURN_HELPURL); this.arguments_ = []; this.quarkConnections_ = {}; this.quarkArguments_ = null; @@ -698,8 +700,6 @@ Blockly.Blocks['procedures_ifreturn'] = { * @this Blockly.Block */ init: function() { - this.setHelpUrl('http://c2.com/cgi/wiki?GuardClause'); - this.setColour(Blockly.Blocks.procedures.HUE); this.appendValueInput('CONDITION') .setCheck('Boolean') .appendField(Blockly.Msg.CONTROLS_IF_MSG_IF); @@ -708,7 +708,9 @@ Blockly.Blocks['procedures_ifreturn'] = { this.setInputsInline(true); this.setPreviousStatement(true); this.setNextStatement(true); + this.setColour(Blockly.Blocks.procedures.HUE); this.setTooltip(Blockly.Msg.PROCEDURES_IFRETURN_TOOLTIP); + this.setHelpUrl('http://c2.com/cgi/wiki?GuardClause'); // TODO: Extract. this.hasReturnValue_ = true; }, /** diff --git a/core/block_svg.js b/core/block_svg.js index 8894d6df7c1..13da0580b56 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -46,8 +46,6 @@ goog.require('goog.math.Coordinate'); * @constructor */ Blockly.BlockSvg = function(workspace, prototypeName, opt_id) { - Blockly.BlockSvg.superClass_.constructor.call(this, - workspace, prototypeName, opt_id); // Create core elements for the block. /** @type {SVGElement} */ this.svgGroup_ = Blockly.createSvgElement('g', {}, null); @@ -63,6 +61,8 @@ Blockly.BlockSvg = function(workspace, prototypeName, opt_id) { {'class': 'blocklyPathLight'}, this.svgGroup_); this.svgPath_.tooltip = this; Blockly.Tooltip.bindMouseEvents(this.svgPath_); + Blockly.BlockSvg.superClass_.constructor.call(this, + workspace, prototypeName, opt_id); }; goog.inherits(Blockly.BlockSvg, Blockly.Block); @@ -98,8 +98,9 @@ Blockly.BlockSvg.prototype.initSvg = function() { for (var i = 0, input; input = this.inputList[i]; i++) { input.init(); } - if (this.mutator) { - this.mutator.createIcon(); + var icons = this.getIcons(); + for (var i = 0; i < icons.length; i++) { + icons[i].createIcon(); } this.updateColour(); this.updateMovable(); @@ -439,6 +440,7 @@ Blockly.BlockSvg.prototype.tab = function(start, forward) { */ Blockly.BlockSvg.prototype.onMouseDown_ = function(e) { if (this.isInFlyout) { + e.stopPropagation(); return; } this.workspace.markFocused(); @@ -1505,9 +1507,7 @@ Blockly.BlockSvg.prototype.setMutator = function(mutator) { if (mutator) { mutator.block_ = this; this.mutator = mutator; - if (this.rendered) { - mutator.createIcon(); - } + mutator.createIcon(); } }; diff --git a/core/flyout.js b/core/flyout.js index 83d2e919b13..251e6854c72 100644 --- a/core/flyout.js +++ b/core/flyout.js @@ -401,10 +401,6 @@ Blockly.Flyout.prototype.show = function(xmlList) { // prevent the closure of the flyout if the user right-clicks on such a // block. child.isInFlyout = true; - // There is no good way to handle comment bubbles inside the flyout. - // Blocks shouldn't come with predefined comments, but someone will - // try this, I'm sure. Kill the comment. - child.setCommentText(null); } block.render(); var root = block.getSvgRoot(); diff --git a/core/workspace_svg.js b/core/workspace_svg.js index 73f2ada764b..906e35df264 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -702,7 +702,7 @@ Blockly.WorkspaceSvg.prototype.cleanUp_ = function() { * @private */ Blockly.WorkspaceSvg.prototype.showContextMenu_ = function(e) { - if (this.options.readOnly) { + if (this.options.readOnly || this.isFlyout) { return; } var menuOptions = []; diff --git a/core/xml.js b/core/xml.js index db9e0e49730..05aa0f6b3c0 100644 --- a/core/xml.js +++ b/core/xml.js @@ -386,7 +386,7 @@ Blockly.Xml.domToBlockHeadless_ = function(workspace, xmlBlock) { case 'comment': block.setCommentText(xmlChild.textContent); var visible = xmlChild.getAttribute('pinned'); - if (visible) { + if (visible && !block.isInFlyout) { // Give the renderer a millisecond to render and position the block // before positioning the comment bubble. setTimeout(function() {