Allow comments in flyouts.

This commit is contained in:
Neil Fraser 2015-12-17 14:16:04 -08:00
parent 26828d6c08
commit a5ea93a1db
5 changed files with 23 additions and 25 deletions

View file

@ -40,8 +40,6 @@ Blockly.Blocks['procedures_defnoreturn'] = {
* @this Blockly.Block * @this Blockly.Block
*/ */
init: function() { init: function() {
this.setHelpUrl(Blockly.Msg.PROCEDURES_DEFNORETURN_HELPURL);
this.setColour(Blockly.Blocks.procedures.HUE);
var nameField = new Blockly.FieldTextInput( var nameField = new Blockly.FieldTextInput(
Blockly.Msg.PROCEDURES_DEFNORETURN_PROCEDURE, Blockly.Msg.PROCEDURES_DEFNORETURN_PROCEDURE,
Blockly.Procedures.rename); Blockly.Procedures.rename);
@ -51,7 +49,10 @@ Blockly.Blocks['procedures_defnoreturn'] = {
.appendField(nameField, 'NAME') .appendField(nameField, 'NAME')
.appendField('', 'PARAMS'); .appendField('', 'PARAMS');
this.setMutator(new Blockly.Mutator(['procedures_mutatorarg'])); 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.setTooltip(Blockly.Msg.PROCEDURES_DEFNORETURN_TOOLTIP);
this.setHelpUrl(Blockly.Msg.PROCEDURES_DEFNORETURN_HELPURL);
this.arguments_ = []; this.arguments_ = [];
this.setStatements_(true); this.setStatements_(true);
this.statementConnection_ = null; this.statementConnection_ = null;
@ -343,8 +344,6 @@ Blockly.Blocks['procedures_defreturn'] = {
* @this Blockly.Block * @this Blockly.Block
*/ */
init: function() { init: function() {
this.setHelpUrl(Blockly.Msg.PROCEDURES_DEFRETURN_HELPURL);
this.setColour(Blockly.Blocks.procedures.HUE);
var nameField = new Blockly.FieldTextInput( var nameField = new Blockly.FieldTextInput(
Blockly.Msg.PROCEDURES_DEFRETURN_PROCEDURE, Blockly.Msg.PROCEDURES_DEFRETURN_PROCEDURE,
Blockly.Procedures.rename); Blockly.Procedures.rename);
@ -357,7 +356,10 @@ Blockly.Blocks['procedures_defreturn'] = {
.setAlign(Blockly.ALIGN_RIGHT) .setAlign(Blockly.ALIGN_RIGHT)
.appendField(Blockly.Msg.PROCEDURES_DEFRETURN_RETURN); .appendField(Blockly.Msg.PROCEDURES_DEFRETURN_RETURN);
this.setMutator(new Blockly.Mutator(['procedures_mutatorarg'])); 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.setTooltip(Blockly.Msg.PROCEDURES_DEFRETURN_TOOLTIP);
this.setHelpUrl(Blockly.Msg.PROCEDURES_DEFRETURN_HELPURL);
this.arguments_ = []; this.arguments_ = [];
this.setStatements_(true); this.setStatements_(true);
this.statementConnection_ = null; this.statementConnection_ = null;
@ -393,13 +395,13 @@ Blockly.Blocks['procedures_mutatorcontainer'] = {
* @this Blockly.Block * @this Blockly.Block
*/ */
init: function() { init: function() {
this.setColour(Blockly.Blocks.procedures.HUE);
this.appendDummyInput() this.appendDummyInput()
.appendField(Blockly.Msg.PROCEDURES_MUTATORCONTAINER_TITLE); .appendField(Blockly.Msg.PROCEDURES_MUTATORCONTAINER_TITLE);
this.appendStatementInput('STACK'); this.appendStatementInput('STACK');
this.appendDummyInput('STATEMENT_INPUT') this.appendDummyInput('STATEMENT_INPUT')
.appendField(Blockly.Msg.PROCEDURES_ALLOW_STATEMENTS) .appendField(Blockly.Msg.PROCEDURES_ALLOW_STATEMENTS)
.appendField(new Blockly.FieldCheckbox('TRUE'), 'STATEMENTS'); .appendField(new Blockly.FieldCheckbox('TRUE'), 'STATEMENTS');
this.setColour(Blockly.Blocks.procedures.HUE);
this.setTooltip(Blockly.Msg.PROCEDURES_MUTATORCONTAINER_TOOLTIP); this.setTooltip(Blockly.Msg.PROCEDURES_MUTATORCONTAINER_TOOLTIP);
this.contextMenu = false; this.contextMenu = false;
} }
@ -411,12 +413,12 @@ Blockly.Blocks['procedures_mutatorarg'] = {
* @this Blockly.Block * @this Blockly.Block
*/ */
init: function() { init: function() {
this.setColour(Blockly.Blocks.procedures.HUE);
this.appendDummyInput() this.appendDummyInput()
.appendField(Blockly.Msg.PROCEDURES_MUTATORARG_TITLE) .appendField(Blockly.Msg.PROCEDURES_MUTATORARG_TITLE)
.appendField(new Blockly.FieldTextInput('x', this.validator_), 'NAME'); .appendField(new Blockly.FieldTextInput('x', this.validator_), 'NAME');
this.setPreviousStatement(true); this.setPreviousStatement(true);
this.setNextStatement(true); this.setNextStatement(true);
this.setColour(Blockly.Blocks.procedures.HUE);
this.setTooltip(Blockly.Msg.PROCEDURES_MUTATORARG_TOOLTIP); this.setTooltip(Blockly.Msg.PROCEDURES_MUTATORARG_TOOLTIP);
this.contextMenu = false; this.contextMenu = false;
}, },
@ -441,14 +443,14 @@ Blockly.Blocks['procedures_callnoreturn'] = {
* @this Blockly.Block * @this Blockly.Block
*/ */
init: function() { init: function() {
this.setHelpUrl(Blockly.Msg.PROCEDURES_CALLNORETURN_HELPURL);
this.setColour(Blockly.Blocks.procedures.HUE);
this.appendDummyInput('TOPROW') this.appendDummyInput('TOPROW')
.appendField(Blockly.Msg.PROCEDURES_CALLNORETURN_CALL) .appendField(Blockly.Msg.PROCEDURES_CALLNORETURN_CALL)
.appendField('', 'NAME'); .appendField('', 'NAME');
this.setPreviousStatement(true); this.setPreviousStatement(true);
this.setNextStatement(true); this.setNextStatement(true);
this.setColour(Blockly.Blocks.procedures.HUE);
// Tooltip is set in domToMutation. // Tooltip is set in domToMutation.
this.setHelpUrl(Blockly.Msg.PROCEDURES_CALLNORETURN_HELPURL);
this.arguments_ = []; this.arguments_ = [];
this.quarkConnections_ = {}; this.quarkConnections_ = {};
this.quarkArguments_ = null; this.quarkArguments_ = null;
@ -670,13 +672,13 @@ Blockly.Blocks['procedures_callreturn'] = {
* @this Blockly.Block * @this Blockly.Block
*/ */
init: function() { init: function() {
this.setHelpUrl(Blockly.Msg.PROCEDURES_CALLRETURN_HELPURL);
this.setColour(Blockly.Blocks.procedures.HUE);
this.appendDummyInput('TOPROW') this.appendDummyInput('TOPROW')
.appendField(Blockly.Msg.PROCEDURES_CALLRETURN_CALL) .appendField(Blockly.Msg.PROCEDURES_CALLRETURN_CALL)
.appendField('', 'NAME'); .appendField('', 'NAME');
this.setOutput(true); this.setOutput(true);
this.setColour(Blockly.Blocks.procedures.HUE);
// Tooltip is set in domToMutation. // Tooltip is set in domToMutation.
this.setHelpUrl(Blockly.Msg.PROCEDURES_CALLRETURN_HELPURL);
this.arguments_ = []; this.arguments_ = [];
this.quarkConnections_ = {}; this.quarkConnections_ = {};
this.quarkArguments_ = null; this.quarkArguments_ = null;
@ -698,8 +700,6 @@ Blockly.Blocks['procedures_ifreturn'] = {
* @this Blockly.Block * @this Blockly.Block
*/ */
init: function() { init: function() {
this.setHelpUrl('http://c2.com/cgi/wiki?GuardClause');
this.setColour(Blockly.Blocks.procedures.HUE);
this.appendValueInput('CONDITION') this.appendValueInput('CONDITION')
.setCheck('Boolean') .setCheck('Boolean')
.appendField(Blockly.Msg.CONTROLS_IF_MSG_IF); .appendField(Blockly.Msg.CONTROLS_IF_MSG_IF);
@ -708,7 +708,9 @@ Blockly.Blocks['procedures_ifreturn'] = {
this.setInputsInline(true); this.setInputsInline(true);
this.setPreviousStatement(true); this.setPreviousStatement(true);
this.setNextStatement(true); this.setNextStatement(true);
this.setColour(Blockly.Blocks.procedures.HUE);
this.setTooltip(Blockly.Msg.PROCEDURES_IFRETURN_TOOLTIP); this.setTooltip(Blockly.Msg.PROCEDURES_IFRETURN_TOOLTIP);
this.setHelpUrl('http://c2.com/cgi/wiki?GuardClause'); // TODO: Extract.
this.hasReturnValue_ = true; this.hasReturnValue_ = true;
}, },
/** /**

View file

@ -46,8 +46,6 @@ goog.require('goog.math.Coordinate');
* @constructor * @constructor
*/ */
Blockly.BlockSvg = function(workspace, prototypeName, opt_id) { Blockly.BlockSvg = function(workspace, prototypeName, opt_id) {
Blockly.BlockSvg.superClass_.constructor.call(this,
workspace, prototypeName, opt_id);
// Create core elements for the block. // Create core elements for the block.
/** @type {SVGElement} */ /** @type {SVGElement} */
this.svgGroup_ = Blockly.createSvgElement('g', {}, null); this.svgGroup_ = Blockly.createSvgElement('g', {}, null);
@ -63,6 +61,8 @@ Blockly.BlockSvg = function(workspace, prototypeName, opt_id) {
{'class': 'blocklyPathLight'}, this.svgGroup_); {'class': 'blocklyPathLight'}, this.svgGroup_);
this.svgPath_.tooltip = this; this.svgPath_.tooltip = this;
Blockly.Tooltip.bindMouseEvents(this.svgPath_); Blockly.Tooltip.bindMouseEvents(this.svgPath_);
Blockly.BlockSvg.superClass_.constructor.call(this,
workspace, prototypeName, opt_id);
}; };
goog.inherits(Blockly.BlockSvg, Blockly.Block); 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++) { for (var i = 0, input; input = this.inputList[i]; i++) {
input.init(); input.init();
} }
if (this.mutator) { var icons = this.getIcons();
this.mutator.createIcon(); for (var i = 0; i < icons.length; i++) {
icons[i].createIcon();
} }
this.updateColour(); this.updateColour();
this.updateMovable(); this.updateMovable();
@ -439,6 +440,7 @@ Blockly.BlockSvg.prototype.tab = function(start, forward) {
*/ */
Blockly.BlockSvg.prototype.onMouseDown_ = function(e) { Blockly.BlockSvg.prototype.onMouseDown_ = function(e) {
if (this.isInFlyout) { if (this.isInFlyout) {
e.stopPropagation();
return; return;
} }
this.workspace.markFocused(); this.workspace.markFocused();
@ -1505,9 +1507,7 @@ Blockly.BlockSvg.prototype.setMutator = function(mutator) {
if (mutator) { if (mutator) {
mutator.block_ = this; mutator.block_ = this;
this.mutator = mutator; this.mutator = mutator;
if (this.rendered) { mutator.createIcon();
mutator.createIcon();
}
} }
}; };

View file

@ -401,10 +401,6 @@ Blockly.Flyout.prototype.show = function(xmlList) {
// prevent the closure of the flyout if the user right-clicks on such a // prevent the closure of the flyout if the user right-clicks on such a
// block. // block.
child.isInFlyout = true; 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(); block.render();
var root = block.getSvgRoot(); var root = block.getSvgRoot();

View file

@ -702,7 +702,7 @@ Blockly.WorkspaceSvg.prototype.cleanUp_ = function() {
* @private * @private
*/ */
Blockly.WorkspaceSvg.prototype.showContextMenu_ = function(e) { Blockly.WorkspaceSvg.prototype.showContextMenu_ = function(e) {
if (this.options.readOnly) { if (this.options.readOnly || this.isFlyout) {
return; return;
} }
var menuOptions = []; var menuOptions = [];

View file

@ -386,7 +386,7 @@ Blockly.Xml.domToBlockHeadless_ = function(workspace, xmlBlock) {
case 'comment': case 'comment':
block.setCommentText(xmlChild.textContent); block.setCommentText(xmlChild.textContent);
var visible = xmlChild.getAttribute('pinned'); var visible = xmlChild.getAttribute('pinned');
if (visible) { if (visible && !block.isInFlyout) {
// Give the renderer a millisecond to render and position the block // Give the renderer a millisecond to render and position the block
// before positioning the comment bubble. // before positioning the comment bubble.
setTimeout(function() { setTimeout(function() {