From bf6220cb42bddedc2ffff4e69f9dbba07233f808 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Mon, 8 Aug 2016 16:51:54 -0700 Subject: [PATCH 1/3] Ask user for confirmation when deleting multiple uses of a variable. --- blockly_compressed.js | 11 ++-- core/variables.js | 125 ++++++++++++++++++++++-------------------- 2 files changed, 71 insertions(+), 65 deletions(-) diff --git a/blockly_compressed.js b/blockly_compressed.js index 48cd34200..4fb027b86 100644 --- a/blockly_compressed.js +++ b/blockly_compressed.js @@ -1280,12 +1280,13 @@ var a=this.rectElement_||this.imageElement_;a.tooltip=this.sourceBlock_;Blockly. Blockly.FieldImage.prototype.setValue=function(a){null!==a&&(this.src_=a,this.imageElement_&&this.imageElement_.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",goog.isString(a)?a:""))};Blockly.FieldImage.prototype.setText=function(a){null!==a&&(this.text_=a)};Blockly.FieldImage.prototype.render_=function(){};Blockly.FieldNumber=function(a,b,c,d,e){a=String(a);Blockly.FieldNumber.superClass_.constructor.call(this,a,e);this.setConstraints(b,c,d)};goog.inherits(Blockly.FieldNumber,Blockly.FieldTextInput);Blockly.FieldNumber.prototype.setConstraints=function(a,b,c){c=parseFloat(c);this.precision_=isNaN(c)?0:c;a=parseFloat(a);this.min_=isNaN(a)?-Infinity:a;b=parseFloat(b);this.max_=isNaN(b)?Infinity:b;this.setValue(this.callValidator(this.getValue()))}; Blockly.FieldNumber.prototype.classValidator=function(a){if(null===a)return null;a=String(a);a=a.replace(/O/ig,"0");a=a.replace(/,/g,"");a=parseFloat(a||0);if(isNaN(a))return null;this.precision_&&Number.isFinite(a)&&(a=Math.round(a/this.precision_)*this.precision_);a=goog.math.clamp(a,this.min_,this.max_);return String(a)};Blockly.Variables={};Blockly.Variables.NAME_TYPE="VARIABLE";Blockly.Variables.allUsedVariables=function(a){var b;if(a instanceof Blockly.Block)b=a.getDescendants();else if(a.getAllBlocks)b=a.getAllBlocks();else throw"Not Block or Workspace: "+a;a=Object.create(null);for(var c=0;c - // item - // - var block = goog.dom.createDom('block'); - block.setAttribute('type', 'variables_set'); - if (Blockly.Blocks['math_change']) { - block.setAttribute('gap', 8); - } else { - block.setAttribute('gap', 24); - } - var field = goog.dom.createDom('field', null, variableList[0]); - field.setAttribute('name', 'VAR'); - block.appendChild(field); - xmlList.push(block); - } - if (Blockly.Blocks['math_change']) { - // - // - // - // 1 - // - // - // - var block = goog.dom.createDom('block'); - block.setAttribute('type', 'math_change'); - if (Blockly.Blocks['variables_get']) { - block.setAttribute('gap', 20); - } - var value = goog.dom.createDom('value'); - value.setAttribute('name', 'DELTA'); - block.appendChild(value); - - var shadowBlock = goog.dom.createDom('shadow'); - shadowBlock.setAttribute('type', 'math_number'); - value.appendChild(shadowBlock); - - var field = goog.dom.createDom('field', null, '1'); - field.setAttribute('name', 'NUM'); - shadowBlock.appendChild(field); - - xmlList.push(block); - } - - for (var i = 0; i < variableList.length; i++) { - if (Blockly.Blocks['variables_get']) { - // + if (variableList.length > 0) { + if (Blockly.Blocks['variables_set']) { + // // item // var block = goog.dom.createDom('block'); - block.setAttribute('type', 'variables_get'); - if (Blockly.Blocks['variables_set']) { + block.setAttribute('type', 'variables_set'); + if (Blockly.Blocks['math_change']) { block.setAttribute('gap', 8); + } else { + block.setAttribute('gap', 24); } - var field = goog.dom.createDom('field', null, variableList[i]); + var field = goog.dom.createDom('field', null, variableList[0]); field.setAttribute('name', 'VAR'); block.appendChild(field); xmlList.push(block); } + if (Blockly.Blocks['math_change']) { + // + // + // + // 1 + // + // + // + var block = goog.dom.createDom('block'); + block.setAttribute('type', 'math_change'); + if (Blockly.Blocks['variables_get']) { + block.setAttribute('gap', 20); + } + var value = goog.dom.createDom('value'); + value.setAttribute('name', 'DELTA'); + block.appendChild(value); + + var field = goog.dom.createDom('field', null, variableList[0]); + field.setAttribute('name', 'VAR'); + block.appendChild(field); + + var shadowBlock = goog.dom.createDom('shadow'); + shadowBlock.setAttribute('type', 'math_number'); + value.appendChild(shadowBlock); + + var numberField = goog.dom.createDom('field', null, '1'); + numberField.setAttribute('name', 'NUM'); + shadowBlock.appendChild(numberField); + + xmlList.push(block); + } + + for (var i = 0; i < variableList.length; i++) { + if (Blockly.Blocks['variables_get']) { + // + // item + // + var block = goog.dom.createDom('block'); + block.setAttribute('type', 'variables_get'); + if (Blockly.Blocks['variables_set']) { + block.setAttribute('gap', 8); + } + var field = goog.dom.createDom('field', null, variableList[i]); + field.setAttribute('name', 'VAR'); + block.appendChild(field); + xmlList.push(block); + } + } } return xmlList; }; @@ -267,11 +268,9 @@ Blockly.Variables.getUses = function(name, workspace) { /** * When a variable is deleted, find and dispose of all uses of it. - * @param {string} name Name of deleted variable. - * @param {!Blockly.Workspace} workspace The workspace to delete uses from. + * @param {!Array.} uses An array of blocks using the variable. */ -Blockly.Variables.disposeUses = function(name, workspace) { - var uses = Blockly.Variables.getUses(name, workspace); +Blockly.Variables.disposeUses = function(uses) { Blockly.Events.setGroup(true); for (var i = 0; i < uses.length; i++) { uses[i].dispose(true, false); @@ -287,10 +286,16 @@ Blockly.Variables.disposeUses = function(name, workspace) { Blockly.Variables.delete = function(name, workspace) { var variableIndex = workspace.variableList.indexOf(name); if (variableIndex != -1) { + var uses = Blockly.Variables.getUses(name, workspace); + if (uses.length > 1) { + window.confirm( + Blockly.Msg.DELETE_VARIABLE_CONFIRMATION.replace('%1', uses.length). + replace('%2', name)); + } + Blockly.Variables.disposeUses(uses); workspace.variableList.splice(variableIndex, 1); } - Blockly.Variables.disposeUses(name, workspace); }; /** From cdbfce87de22eacf6a3a135ac70c85b6023c0e53 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Tue, 9 Aug 2016 11:30:32 -0700 Subject: [PATCH 2/3] Make disposeUses private --- core/variables.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/variables.js b/core/variables.js index e512d1c93..29f5afe47 100644 --- a/core/variables.js +++ b/core/variables.js @@ -269,8 +269,9 @@ Blockly.Variables.getUses = function(name, workspace) { /** * When a variable is deleted, find and dispose of all uses of it. * @param {!Array.} uses An array of blocks using the variable. + * @private */ -Blockly.Variables.disposeUses = function(uses) { +Blockly.Variables.disposeUses_ = function(uses) { Blockly.Events.setGroup(true); for (var i = 0; i < uses.length; i++) { uses[i].dispose(true, false); @@ -292,7 +293,7 @@ Blockly.Variables.delete = function(name, workspace) { Blockly.Msg.DELETE_VARIABLE_CONFIRMATION.replace('%1', uses.length). replace('%2', name)); } - Blockly.Variables.disposeUses(uses); + Blockly.Variables.disposeUses_(uses); workspace.variableList.splice(variableIndex, 1); } From 65d785a86df3be01f06123e06b90180c816bd221 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Tue, 9 Aug 2016 17:17:08 -0700 Subject: [PATCH 3/3] New message for deletion; block dispose is a noop if it's already been deleted --- blockly_compressed.js | 4 ++-- core/block.js | 4 ++++ core/block_svg.js | 4 ++++ msg/js/ar.js | 1 + msg/js/az.js | 1 + msg/js/ba.js | 1 + msg/js/bcc.js | 1 + msg/js/be-tarask.js | 1 + msg/js/bg.js | 1 + msg/js/bn.js | 1 + msg/js/br.js | 1 + msg/js/ca.js | 1 + msg/js/cs.js | 1 + msg/js/da.js | 1 + msg/js/de.js | 1 + msg/js/diq.js | 1 + msg/js/el.js | 1 + msg/js/en.js | 1 + msg/js/es.js | 1 + msg/js/fa.js | 1 + msg/js/fi.js | 1 + msg/js/fr.js | 1 + msg/js/he.js | 1 + msg/js/hi.js | 1 + msg/js/hrx.js | 1 + msg/js/hu.js | 1 + msg/js/ia.js | 1 + msg/js/id.js | 1 + msg/js/is.js | 1 + msg/js/it.js | 1 + msg/js/ja.js | 1 + msg/js/ko.js | 1 + msg/js/lb.js | 1 + msg/js/lki.js | 1 + msg/js/lrc.js | 1 + msg/js/lt.js | 1 + msg/js/mk.js | 1 + msg/js/ms.js | 1 + msg/js/nb.js | 1 + msg/js/nl.js | 1 + msg/js/oc.js | 1 + msg/js/pl.js | 1 + msg/js/pms.js | 1 + msg/js/pt-br.js | 1 + msg/js/pt.js | 1 + msg/js/ro.js | 1 + msg/js/ru.js | 1 + msg/js/sc.js | 1 + msg/js/sd.js | 1 + msg/js/shn.js | 1 + msg/js/sk.js | 1 + msg/js/sl.js | 1 + msg/js/sq.js | 1 + msg/js/sr.js | 1 + msg/js/sv.js | 1 + msg/js/ta.js | 1 + msg/js/tcy.js | 1 + msg/js/th.js | 1 + msg/js/tl.js | 1 + msg/js/tlh.js | 1 + msg/js/tr.js | 1 + msg/js/uk.js | 1 + msg/js/vi.js | 1 + msg/js/zh-hans.js | 1 + msg/js/zh-hant.js | 1 + msg/json/en.json | 3 ++- msg/json/qqq.json | 1 + msg/messages.js | 2 ++ 68 files changed, 77 insertions(+), 3 deletions(-) diff --git a/blockly_compressed.js b/blockly_compressed.js index 4fb027b86..c62d70dd0 100644 --- a/blockly_compressed.js +++ b/blockly_compressed.js @@ -1284,8 +1284,8 @@ Blockly.Variables.flyoutCategory=function(a){a=a.variableList;a.sort(goog.string goog.dom.createDom("block");c.setAttribute("type","math_change");Blockly.Blocks.variables_get&&c.setAttribute("gap",20);var e=goog.dom.createDom("value");e.setAttribute("name","DELTA");c.appendChild(e);d=goog.dom.createDom("field",null,a[0]);d.setAttribute("name","VAR");c.appendChild(d);d=goog.dom.createDom("shadow");d.setAttribute("type","math_number");e.appendChild(d);e=goog.dom.createDom("field",null,"1");e.setAttribute("name","NUM");d.appendChild(e);b.push(c)}for(e=0;e", - "lastupdated": "2016-08-08 16:58:55.342181", + "lastupdated": "2016-08-09 17:07:03.957507", "locale": "en", "messagedocumentation" : "qqq" }, @@ -31,6 +31,7 @@ "NEW_VARIABLE_TITLE": "New variable name:", "RENAME_VARIABLE": "Rename variable...", "RENAME_VARIABLE_TITLE": "Rename all '%1' variables to:", + "DELETE_VARIABLE_CONFIRMATION": "Delete %1 uses of the %2 variable?", "COLOUR_PICKER_HELPURL": "https://en.wikipedia.org/wiki/Color", "COLOUR_PICKER_TOOLTIP": "Choose a colour from the palette.", "COLOUR_RANDOM_HELPURL": "http://randomcolour.com", diff --git a/msg/json/qqq.json b/msg/json/qqq.json index 763fa60cd..aaf24b357 100644 --- a/msg/json/qqq.json +++ b/msg/json/qqq.json @@ -25,6 +25,7 @@ "NEW_VARIABLE_TITLE": "prompt - Prompts the user to enter the name for a new variable. See [https://github.com/google/blockly/wiki/Variables#dropdown-menu https://github.com/google/blockly/wiki/Variables#dropdown-menu].", "RENAME_VARIABLE": "dropdown choice - When the user clicks on a variable block, this is one of the dropdown menu choices. It is used to rename the current variable. See [https://github.com/google/blockly/wiki/Variables#dropdown-menu https://github.com/google/blockly/wiki/Variables#dropdown-menu].", "RENAME_VARIABLE_TITLE": "prompt - Prompts the user to enter the new name for the selected variable. See [https://github.com/google/blockly/wiki/Variables#dropdown-menu https://github.com/google/blockly/wiki/Variables#dropdown-menu].\n\nParameters:\n* %1 - the name of the variable to be renamed.", + "DELETE_VARIABLE_CONFIRMATION": "confirm - Ask the user to confirm their deletion of multiple uses of a variable.", "COLOUR_PICKER_HELPURL": "url - Information about colour.", "COLOUR_PICKER_TOOLTIP": "tooltip - See [https://github.com/google/blockly/wiki/Colour#picking-a-colour-from-a-palette https://github.com/google/blockly/wiki/Colour#picking-a-colour-from-a-palette].", "COLOUR_RANDOM_HELPURL": "url - A link that displays a random colour each time you visit it.", diff --git a/msg/messages.js b/msg/messages.js index 2649a5c39..36535c70e 100644 --- a/msg/messages.js +++ b/msg/messages.js @@ -106,6 +106,8 @@ Blockly.Msg.NEW_VARIABLE_TITLE = 'New variable name:'; Blockly.Msg.RENAME_VARIABLE = 'Rename variable...'; /// prompt - Prompts the user to enter the new name for the selected variable. See [https://github.com/google/blockly/wiki/Variables#dropdown-menu https://github.com/google/blockly/wiki/Variables#dropdown-menu].\n\nParameters:\n* %1 - the name of the variable to be renamed. Blockly.Msg.RENAME_VARIABLE_TITLE = 'Rename all "%1" variables to:'; +/// confirm - Ask the user to confirm their deletion of multiple uses of a variable. +Blockly.Msg.DELETE_VARIABLE_CONFIRMATION = 'Delete %1 uses of the %2 variable?'; // Colour Blocks. /// url - Information about colour.