Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1619. buildTooltipWithFieldValue() => buildTooltipWithFieldText() #1638

Merged
merged 2 commits into from
Feb 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions blocks/loops.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,11 @@ Blockly.Extensions.registerMixin('contextMenu_newGetVariableBlock',
Blockly.Constants.Loops.CUSTOM_CONTEXT_MENU_CREATE_VARIABLES_GET_MIXIN);

Blockly.Extensions.register('controls_for_tooltip',
Blockly.Extensions.buildTooltipWithFieldValue(
Blockly.Extensions.buildTooltipWithFieldText(
'%{BKY_CONTROLS_FOR_TOOLTIP}', 'VAR'));

Blockly.Extensions.register('controls_forEach_tooltip',
Blockly.Extensions.buildTooltipWithFieldValue(
Blockly.Extensions.buildTooltipWithFieldText(
'%{BKY_CONTROLS_FOREACH_TOOLTIP}', 'VAR'));

/**
Expand Down
15 changes: 2 additions & 13 deletions blocks/math.js
Original file line number Diff line number Diff line change
Expand Up @@ -492,20 +492,9 @@ Blockly.Extensions.registerMutator('math_is_divisibleby_mutator',
Blockly.Constants.Math.IS_DIVISIBLEBY_MUTATOR_MIXIN,
Blockly.Constants.Math.IS_DIVISIBLE_MUTATOR_EXTENSION);

/**
* Update the tooltip of 'math_change' block to reference the variable.
* @this Blockly.Block
* @package
*/
Blockly.Constants.Math.CHANGE_TOOLTIP_EXTENSION = function() {
this.setTooltip(function() {
return Blockly.Msg.MATH_CHANGE_TOOLTIP.replace('%1',
this.getFieldValue('VAR'));
}.bind(this));
};

// Update the tooltip of 'math_change' block to reference the variable.
Blockly.Extensions.register('math_change_tooltip',
Blockly.Extensions.buildTooltipWithFieldValue(
Blockly.Extensions.buildTooltipWithFieldText(
'%{BKY_MATH_CHANGE_TOOLTIP}', 'VAR'));

/**
Expand Down
18 changes: 4 additions & 14 deletions blocks/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -773,17 +773,10 @@ Blockly.Constants.Text.TEXT_JOIN_EXTENSION = function() {
this.setMutator(new Blockly.Mutator(['text_create_join_item']));
};

Blockly.Constants.Text.TEXT_APPEND_TOOLTIP_EXTENSION = function() {
// Assign 'this' to a variable for use in the tooltip closure below.
var thisBlock = this;
this.setTooltip(function() {
if (Blockly.Msg.TEXT_APPEND_TOOLTIP) {
return Blockly.Msg.TEXT_APPEND_TOOLTIP.replace('%1',
thisBlock.getFieldValue('VAR'));
}
return '';
});
};
// Update the tooltip of 'text_append' block to reference the variable.
Blockly.Extensions.register('text_append_tooltip',
Blockly.Extensions.buildTooltipWithFieldText(
'%{BKY_TEXT_APPEND_TOOLTIP}', 'VAR'));

Blockly.Constants.Text.TEXT_INDEXOF_TOOLTIP_EXTENSION = function() {
// Assign 'this' to a variable for use in the tooltip closure below.
Expand Down Expand Up @@ -889,9 +882,6 @@ Blockly.Extensions.register('text_indexOf_tooltip',
Blockly.Extensions.register('text_quotes',
Blockly.Constants.Text.TEXT_QUOTES_EXTENSION);

Blockly.Extensions.register('text_append_tooltip',
Blockly.Constants.Text.TEXT_APPEND_TOOLTIP_EXTENSION);

Blockly.Extensions.registerMutator('text_join_mutator',
Blockly.Constants.Text.TEXT_JOIN_MUTATOR_MIXIN,
Blockly.Constants.Text.TEXT_JOIN_EXTENSION);
Expand Down
9 changes: 5 additions & 4 deletions core/extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,13 +397,13 @@ Blockly.Extensions.checkDropdownOptionsInTable_ = function(block, dropdownName,
/**
* Builds an extension function that will install a dynamic tooltip. The
* tooltip message should include the string '%1' and that string will be
* replaced with the value of the named field.
* replaced with the text of the named field.
* @param {string} msgTemplate The template form to of the message text, with
* %1 placeholder.
* @param {string} fieldName The field with the replacement value.
* @param {string} fieldName The field with the replacement text.
* @returns {Function} The extension function.
*/
Blockly.Extensions.buildTooltipWithFieldValue = function(msgTemplate,
Blockly.Extensions.buildTooltipWithFieldText = function(msgTemplate,
fieldName) {
// Check the tooltip string messages for invalid references.
// Wait for load, in case Blockly.Msg is not yet populated.
Expand All @@ -422,8 +422,9 @@ Blockly.Extensions.buildTooltipWithFieldValue = function(msgTemplate,
*/
var extensionFn = function() {
this.setTooltip(function() {
var field = this.getField(fieldName);
return Blockly.utils.replaceMessageReferences(msgTemplate)
.replace('%1', this.getFieldValue(fieldName));
.replace('%1', field ? field.getText() : '');
}.bind(this));
};
return extensionFn;
Expand Down