Generate helpURL and tooltip for Javascript block definition

This commit is contained in:
Rachel Fenichel
2016-12-08 14:41:40 -08:00
parent 4871ff9fda
commit 99c30007a7
2 changed files with 38 additions and 18 deletions

View File

@@ -250,20 +250,10 @@ FactoryUtils.formatJson_ = function(blockType, rootBlock) {
var hue = parseInt(colourBlock.getFieldValue('HUE'), 10);
JS.colour = hue;
}
// Tooltip.
var tooltipBlock = rootBlock.getInputTargetBlock('TOOLTIP');
if (tooltipBlock && !tooltipBlock.disabled) {
JS.tooltip = tooltipBlock.getFieldValue('TEXT');
} else {
JS.tooltip = '';
}
// Help URL.
var helpUrlBlock = rootBlock.getInputTargetBlock('HELPURL');
if (helpUrlBlock && !helpUrlBlock.disabled) {
JS.helpUrl = helpUrlBlock.getFieldValue('TEXT');
} else {
JS.helpUrl = 'http://www.example.com/';
}
JS.tooltip = FactoryUtils.getTooltipFromRootBlock_(rootBlock);
JS.helpUrl = FactoryUtils.getHelpUrlFromRootBlock_(rootBlock);
return JSON.stringify(JS, null, ' ');
};
@@ -346,9 +336,11 @@ FactoryUtils.formatJavaScript_ = function(blockType, rootBlock, workspace) {
code.push(' this.setColour(' + hue + ');');
}
}
// TODO: Rachel: tooltip and helpurl
code.push(" this.setTooltip('');");
code.push(" this.setHelpUrl('http://www.example.com/');");
var tooltip = FactoryUtils.getTooltipFromRootBlock_(rootBlock);
var helpUrl = FactoryUtils.getHelpUrlFromRootBlock_(rootBlock);
code.push(" this.setTooltip('" + tooltip + "');");
code.push(" this.setHelpUrl('" + helpUrl + "');");
code.push(' }');
code.push('};');
return code.join('\n');
@@ -964,3 +956,31 @@ FactoryUtils.savedBlockChanges = function(blockLibraryController) {
}
return false;
};
/**
* Given the root block of the factory, return the tooltip specified by the user
* or the empty string if no tooltip is found.
* @param {!Blockly.Block} rootBlock Factory_base block.
* @return {string} The tooltip for the generated block, or the empty string.
*/
FactoryUtils.getTooltipFromRootBlock_ = function(rootBlock) {
var tooltipBlock = rootBlock.getInputTargetBlock('TOOLTIP');
if (tooltipBlock && !tooltipBlock.disabled) {
return tooltipBlock.getFieldValue('TEXT');
}
return '';
};
/**
* Given the root block of the factory, return the help url specified by the
* user or the empty string if no tooltip is found.
* @param {!Blockly.Block} rootBlock Factory_base block.
* @return {string} The help url for the generated block, or the empty string.
*/
FactoryUtils.getHelpUrlFromRootBlock_ = function(rootBlock) {
var helpUrlBlock = rootBlock.getInputTargetBlock('HELPURL');
if (helpUrlBlock && !helpUrlBlock.disabled) {
return helpUrlBlock.getFieldValue('TEXT');
}
return '';
};