Skip to content

Commit

Permalink
Allow comments in flyouts.
Browse files Browse the repository at this point in the history
  • Loading branch information
NeilFraser committed Dec 17, 2015
1 parent 26828d6 commit a5ea93a
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 25 deletions.
26 changes: 14 additions & 12 deletions blocks/procedures.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
},
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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;
},
/**
Expand Down
14 changes: 7 additions & 7 deletions core/block_svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}
};

Expand Down
4 changes: 0 additions & 4 deletions core/flyout.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion core/workspace_svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down
2 changes: 1 addition & 1 deletion core/xml.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit a5ea93a

Please sign in to comment.