Commit 544cdb94 authored by carlosperate's avatar carlosperate

Update Blockly to allow easy replacement of window.prompt by async version.

parent b26b7884
...@@ -15,6 +15,11 @@ It adds the following features: ...@@ -15,6 +15,11 @@ It adds the following features:
* Procedures core class modified to include the Arduino setup() and loop() functions * Procedures core class modified to include the Arduino setup() and loop() functions
* Minor visual changes to the zoom icons positioning * Minor visual changes to the zoom icons positioning
The following features are planned to be push upstream (list will be updated as PR get accepted):
* Fix toolbox XML nodes injected into blockly under IE (works on Chrome and Firefox)
* Replaces window.prompt uses to a local version that can easily be replaced by an asynchronous HTML version
All other changes and fixes have been submitted to the original Blockly repository for inclusion into the upstream master branch. All other changes and fixes have been submitted to the original Blockly repository for inclusion into the upstream master branch.
This fork gets frequent upstream pulls to maintain it up to date. This fork gets frequent upstream pulls to maintain it up to date.
......
...@@ -113,7 +113,7 @@ Blockly.FieldTextInput.prototype.showEditor_ = function(opt_quietInput) { ...@@ -113,7 +113,7 @@ Blockly.FieldTextInput.prototype.showEditor_ = function(opt_quietInput) {
if (!quietInput && (goog.userAgent.MOBILE || goog.userAgent.ANDROID || if (!quietInput && (goog.userAgent.MOBILE || goog.userAgent.ANDROID ||
goog.userAgent.IPAD)) { goog.userAgent.IPAD)) {
// Mobile browsers have issues with in-line textareas (focus & keyboards). // Mobile browsers have issues with in-line textareas (focus & keyboards).
var newValue = window.prompt(Blockly.Msg.CHANGE_VALUE_TITLE, this.text_); var newValue = Blockly.prompt(Blockly.Msg.CHANGE_VALUE_TITLE,this.text_);
if (this.sourceBlock_ && this.changeHandler_) { if (this.sourceBlock_ && this.changeHandler_) {
var override = this.changeHandler_(newValue); var override = this.changeHandler_(newValue);
if (override !== undefined) { if (override !== undefined) {
......
...@@ -29,6 +29,7 @@ goog.provide('Blockly.FieldVariable'); ...@@ -29,6 +29,7 @@ goog.provide('Blockly.FieldVariable');
goog.require('Blockly.FieldDropdown'); goog.require('Blockly.FieldDropdown');
goog.require('Blockly.Msg'); goog.require('Blockly.Msg');
goog.require('Blockly.Variables'); goog.require('Blockly.Variables');
goog.require('Blockly.utils');
goog.require('goog.string'); goog.require('goog.string');
...@@ -159,39 +160,43 @@ Blockly.FieldVariable.dropdownCreate = function() { ...@@ -159,39 +160,43 @@ Blockly.FieldVariable.dropdownCreate = function() {
* @this {!Blockly.FieldVariable} * @this {!Blockly.FieldVariable}
*/ */
Blockly.FieldVariable.dropdownChange = function(text) { Blockly.FieldVariable.dropdownChange = function(text) {
function promptName(promptText, defaultText) { function promptName(promptText, defaultText, callback) {
Blockly.hideChaff(); Blockly.hideChaff();
var newVar = window.prompt(promptText, defaultText); var newVar = Blockly.prompt(promptText, defaultText, function(newVar) {
// Merge runs of whitespace. Strip leading and trailing whitespace. // Merge runs of whitespace. Strip leading and trailing whitespace.
// Beyond this, all names are legal. // Beyond this, all names are legal.
if (newVar) { if (newVar) {
newVar = newVar.replace(/[\s\xa0]+/g, ' ').replace(/^ | $/g, ''); newVar = newVar.replace(/[\s\xa0]+/g, ' ').replace(/^ | $/g, '');
if (newVar == Blockly.Msg.RENAME_VARIABLE || if (newVar == Blockly.Msg.RENAME_VARIABLE ||
newVar == Blockly.Msg.NEW_VARIABLE) { newVar == Blockly.Msg.NEW_VARIABLE) {
// Ok, not ALL names are legal... // Ok, not ALL names are legal...
newVar = null; newVar = null;
}
} }
} callback(newVar);
return newVar; });
} }
var workspace = this.sourceBlock_.workspace; var workspace = this.sourceBlock_.workspace;
if (text == Blockly.Msg.RENAME_VARIABLE) { if (text == Blockly.Msg.RENAME_VARIABLE) {
var oldVar = this.getText(); var oldVar = this.getText();
text = promptName(Blockly.Msg.RENAME_VARIABLE_TITLE.replace('%1', oldVar), promptName(Blockly.Msg.RENAME_VARIABLE_TITLE.replace('%1', oldVar),
oldVar); oldVar, function(text) {
if (text) { if (text) {
Blockly.Variables.renameVariable(oldVar, text, workspace); Blockly.Variables.renameVariable(oldVar, text, workspace);
} }
});
return null; return null;
} else if (text == Blockly.Msg.NEW_VARIABLE) { } else if (text == Blockly.Msg.NEW_VARIABLE) {
text = promptName(Blockly.Msg.NEW_VARIABLE_TITLE, ''); /*promptName(Blockly.Msg.NEW_VARIABLE_TITLE, '', function(text) {
// Since variables are case-insensitive, ensure that if the new variable // Since variables are case-insensitive, ensure that if the new variable
// matches with an existing variable, the new case prevails throughout. // matches with an existing variable, the new case prevails throughout.
if (text) { if (text) {
Blockly.Variables.renameVariable(text, text, workspace); Blockly.Variables.renameVariable(text, text, workspace);
return text; //TODO: need to add here what too do with the newly created variable
} }
return null; });*/
//TODO: this return variable needs to be made redundant
return Blockly.Variables.generateUniqueName(workspace);
} }
return undefined; return undefined;
}; };
...@@ -591,3 +591,31 @@ Blockly.genUid.crypto_ = this.crypto; ...@@ -591,3 +591,31 @@ Blockly.genUid.crypto_ = this.crypto;
*/ */
Blockly.genUid.soup_ = '!#$%()*+,-./:;=?@[]^_`{|}~' + Blockly.genUid.soup_ = '!#$%()*+,-./:;=?@[]^_`{|}~' +
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
/**
* Local prompt function created to allow blockly developers to overwrite it
* with a customised version. This version uses the default window.prompt
* functionality, but it has been designed to be easily replaced by an
* asynchronous HTML based prompt.
* @param {string} message Main text message for the window prompt.
* @param {string=} opt_defaultInput Input string to be displayed by default.
* @param {function=} opt_callback Optional function callback to process the
* user input.
* @return {undefined|null|string} If no callback is provided it returns the
* value directly from window.prompt (null or string), otherwise it
* returns undefined.
*/
Blockly.prompt = function(message, opt_defaultInput, opt_callback) {
if (opt_callback === undefined) {
// If no callback provided to revert back to the normal blockly prompt
return window.prompt(message, opt_defaultInput);
} else {
// window.prompt still a blocking function, but returns value via callback
if (typeof opt_callback == 'function') {
opt_callback(window.prompt(message, opt_defaultInput));
} else {
console.log('Blocky prompt callback needs to be a callable function.');
}
}
return undefined;
};
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment