mirror of
https://github.com/google/blockly.git
synced 2026-01-09 18:10:08 +01:00
Make warnings bubble up to collapsed parents.
This commit is contained in:
@@ -873,11 +873,11 @@ Blockly.Bubble.prototype.renderArrow_=function(){var a=[],b=this.width_/2,c=this
|
||||
q*d,e=c+q*e,q=b+h*l,m=c+h*k,b=b-h*l,c=c-h*k,k=g+this.arrow_radians_;k>2*Math.PI&&(k-=2*Math.PI);g=Math.sin(k)*f/Blockly.Bubble.ARROW_BEND;f=Math.cos(k)*f/Blockly.Bubble.ARROW_BEND;a.push("M"+q+","+m);a.push("C"+(q+f)+","+(m+g)+" "+d+","+e+" "+d+","+e);a.push("C"+d+","+e+" "+(b+f)+","+(c+g)+" "+b+","+c)}a.push("z");this.bubbleArrow_.setAttribute("d",a.join(" "))};Blockly.Bubble.prototype.setColour=function(a){this.bubbleBack_.setAttribute("fill",a);this.bubbleArrow_.setAttribute("fill",a)};
|
||||
Blockly.Bubble.prototype.dispose=function(){Blockly.Bubble.unbindDragEvents_();goog.dom.removeNode(this.bubbleGroup_);this.shape_=this.content_=this.workspace_=this.bubbleGroup_=null};
|
||||
// Copyright 2013 Google Inc. Apache License 2.0
|
||||
Blockly.Icon=function(a){this.block_=a};Blockly.Icon.prototype.png_="";Blockly.Icon.prototype.SIZE=17;Blockly.Icon.prototype.bubble_=null;Blockly.Icon.prototype.iconX_=0;Blockly.Icon.prototype.iconY_=0;
|
||||
Blockly.Icon=function(a){this.block_=a};Blockly.Icon.prototype.collapseHidden=!0;Blockly.Icon.prototype.SIZE=17;Blockly.Icon.prototype.png_="";Blockly.Icon.prototype.bubble_=null;Blockly.Icon.prototype.iconX_=0;Blockly.Icon.prototype.iconY_=0;
|
||||
Blockly.Icon.prototype.createIcon=function(){this.iconGroup_||(this.iconGroup_=Blockly.createSvgElement("g",{"class":"blocklyIconGroup"},null),Blockly.createSvgElement("image",{width:this.SIZE,height:this.SIZE},this.iconGroup_).setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",this.png_),this.block_.getSvgRoot().appendChild(this.iconGroup_),Blockly.bindEvent_(this.iconGroup_,"mouseup",this,this.iconClick_),this.updateEditable())};
|
||||
Blockly.Icon.prototype.dispose=function(){goog.dom.removeNode(this.iconGroup_);this.iconGroup_=null;this.setVisible(!1);this.block_=null};Blockly.Icon.prototype.updateEditable=function(){this.block_.isInFlyout||!this.block_.isEditable()?Blockly.addClass_(this.iconGroup_,"blocklyIconGroupReadonly"):Blockly.removeClass_(this.iconGroup_,"blocklyIconGroupReadonly")};Blockly.Icon.prototype.isVisible=function(){return!!this.bubble_};
|
||||
Blockly.Icon.prototype.iconClick_=function(a){this.block_.isInFlyout||Blockly.isRightButton(a)||this.setVisible(!this.isVisible())};Blockly.Icon.prototype.updateColour=function(){if(this.isVisible()){var a=Blockly.makeColour(this.block_.getColour());this.bubble_.setColour(a)}};
|
||||
Blockly.Icon.prototype.renderIcon=function(a){if(this.block_.isCollapsed())return this.iconGroup_.setAttribute("display","none"),a;this.iconGroup_.setAttribute("display","block");var b=this.SIZE;this.block_.RTL&&(a-=b);this.iconGroup_.setAttribute("transform","translate("+a+", 5)");this.computeIconLocation();return a=this.block_.RTL?a-Blockly.BlockSvg.SEP_SPACE_X:a+(b+Blockly.BlockSvg.SEP_SPACE_X)};
|
||||
Blockly.Icon.prototype.renderIcon=function(a){if(this.collapseHidden&&this.block_.isCollapsed())return this.iconGroup_.setAttribute("display","none"),a;this.iconGroup_.setAttribute("display","block");var b=this.SIZE;this.block_.RTL&&(a-=b);this.iconGroup_.setAttribute("transform","translate("+a+", 5)");this.computeIconLocation();return a=this.block_.RTL?a-Blockly.BlockSvg.SEP_SPACE_X:a+(b+Blockly.BlockSvg.SEP_SPACE_X)};
|
||||
Blockly.Icon.prototype.setIconLocation=function(a,b){this.iconX_=a;this.iconY_=b;this.isVisible()&&this.bubble_.setAnchorLocation(a,b)};Blockly.Icon.prototype.computeIconLocation=function(){var a=this.block_.getRelativeToSurfaceXY(),b=Blockly.getRelativeXY_(this.iconGroup_),c=a.x+b.x+this.SIZE/2,a=a.y+b.y+this.SIZE/2;c===this.iconX_&&a===this.iconY_||this.setIconLocation(c,a)};Blockly.Icon.prototype.getIconLocation=function(){return{x:this.iconX_,y:this.iconY_}};
|
||||
// Copyright 2011 Google Inc. Apache License 2.0
|
||||
Blockly.Comment=function(a){Blockly.Comment.superClass_.constructor.call(this,a);this.createIcon()};goog.inherits(Blockly.Comment,Blockly.Icon);Blockly.Comment.prototype.png_="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAARCAYAAAA7bUf6AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAANyAAADcgBffIlqAAAAAd0SU1FB98DGgAnBf0Xj5sAAAIBSURBVDjLjZO9SxxRFMXPrFkWl2UFYSOIRtF210YtAiH/gGATRNZFgo19IBaB9Ipgk3SiEoKQgI19JIVgGaOIgpWJEAV1kZk3b1ad0V+KRYIzk5ALh1ecc88978tRSgHPg0Bjvq/BbFalMNR5oaBv+bzWHMfZjOudWPOg6+pDva6elRXlt7fVcnYmPX4sDQ3pdmpKQXu7frS16aXjON8T06OIMWOwtRp3jgNSEpkMTE5y5/v4UcSLePxnroutVNKb4xgYANfFAk/vDbLG8Gtk5P8M7jE6CsZwDDwSMLm5iYmLlpbg4ABOTmBjA4aHk0ZbWxigposLvlarScH5OSwvw9oaABwdJTW1GtTrfJHnUe/uTgqKxeZaKEAUgTEQP/CeHvA8LhRFhLlc+r6zWVhfbyaZn0/yuRxEEaGCAK9USjdZWGgarK5CS0uS7+gAa3EzjYaOy2WlludJi4vSzIx0e5vky2Xp6ko/M4WCPleruk4zsVa6vJSur9OHTEzoqljUJwEdQYDf25uMe3jY3E5fX5Lr7wdr8YGSJCkIeL23h9/a+lA4Pg7T039u6h75POzv4wcBrx5Ec11Wd3bwOzv//VK7umB3F991+Zj2/R1reWstdnaWm3L5YXOlAnNz3FiLbTR4Azj6WwFPjOG953EahoT1On4YEnoep8bwDuiO9/wG1sM4kG8A4fUAAAAASUVORK5CYII=";
|
||||
@@ -1028,10 +1028,10 @@ function(){b.workspaceChanged_()});this.updateColour()}else this.svgDialog_=null
|
||||
Blockly.Mutator.prototype.workspaceChanged_=function(){if(0==Blockly.dragMode_)for(var a=this.workspace_.getTopBlocks(!1),b=0,c;c=a[b];b++){var d=c.getRelativeToSurfaceXY(),e=c.getHeightWidth();20>d.y+e.height&&c.moveBy(0,20-e.height-d.y)}this.rootBlock_.workspace==this.workspace_&&(a=this.block_.rendered,this.block_.rendered=!1,this.block_.compose(this.rootBlock_),this.block_.rendered=a,this.block_.initSvg(),this.block_.rendered&&this.block_.render(),this.resizeBubble_(),this.block_.workspace.fireChangeEvent(),
|
||||
goog.Timer.callOnce(this.block_.bumpNeighbours_,Blockly.BUMP_DELAY,this.block_))};Blockly.Mutator.prototype.getFlyoutMetrics_=function(){return{viewHeight:this.workspaceHeight_,viewWidth:this.workspaceWidth_,absoluteTop:0,absoluteLeft:0}};Blockly.Mutator.prototype.dispose=function(){this.block_.mutator=null;Blockly.Icon.prototype.dispose.call(this)};
|
||||
// Copyright 2012 Google Inc. Apache License 2.0
|
||||
Blockly.Warning=function(a){Blockly.Warning.superClass_.constructor.call(this,a);this.createIcon()};goog.inherits(Blockly.Warning,Blockly.Icon);Blockly.Warning.prototype.png_="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAARCAYAAAA7bUf6AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAANyAAADcgBffIlqAAAAAd0SU1FB98DGgApDBpIGrEAAAGfSURBVDjLnZM9S2NREIbfc2P8AF27BXshpIzK5g9ssUj8C2tnYyUoiBGSyk4sbCLs1vkRgoW1jYWFICwsMV2Se3JPboLe+FhcNCZcjXFgOMzHeec9M2ekDwTIAEUgo68IsOQczdNTIudoAksTg/g+5+UyDxKUyzz4PueTsvhZr+NmZkCC6Wmo1QiAX58FmLKWf4VCDPCiGxtgLf+B9FiQXo+9y0ucBIUCnJ3B+noMdHGBC0P2xrH4HoYEmUx8qVQCgMPD2F5ehjDEjTbZe2s4p5NKRenb2+Qid3dSpaK0tTp+j8VKq0VncXHQh2IxZrK/P/AtLECjQQf4McQEMNbq786O5qwdANfr8Xl/P/AFgbS7qzlr9Qcwr4EoYvPmBud5wxPJ5+HqCtbWhv3GwPU1Lor4/fKMeedo5vPDiRKsrsLWFuRyybFOhxbwTd0upWqVcDQpaTqjWq0SdruU5PvUkiol/ZNRzeXA96mp3aaRzSYnjdNsFtptGiYI2PY8HaVSmu33xWf3K5WS6ffVe3rSgXnzT+YlpSfY00djjJOkZ/wpr41bQMIsAAAAAElFTkSuQmCC";
|
||||
Blockly.Warning.textToDom_=function(a){var b=Blockly.createSvgElement("text",{"class":"blocklyText blocklyBubbleText",y:Blockly.Bubble.BORDER_WIDTH},null);a=a.split("\n");for(var c=0;c<a.length;c++){var d=Blockly.createSvgElement("tspan",{dy:"1em",x:Blockly.Bubble.BORDER_WIDTH},b),e=document.createTextNode(a[c]);d.appendChild(e)}return b};Blockly.Warning.prototype.text_="";
|
||||
Blockly.Warning.prototype.setVisible=function(a){if(a!=this.isVisible())if(a){a=Blockly.Warning.textToDom_(this.text_);this.bubble_=new Blockly.Bubble(this.block_.workspace,a,this.block_.svgPath_,this.iconX_,this.iconY_,null,null);if(this.block_.RTL)for(var b=a.getBBox().width,c=0,d;d=a.childNodes[c];c++)d.setAttribute("text-anchor","end"),d.setAttribute("x",b+Blockly.Bubble.BORDER_WIDTH);this.updateColour();a=this.bubble_.getBubbleSize();this.bubble_.setBubbleSize(a.width,a.height)}else this.bubble_.dispose(),
|
||||
this.body_=this.bubble_=null};Blockly.Warning.prototype.bodyFocus_=function(a){this.bubble_.promote_()};Blockly.Warning.prototype.setText=function(a){this.text_!=a&&(this.text_=a,this.isVisible()&&(this.setVisible(!1),this.setVisible(!0)))};Blockly.Warning.prototype.dispose=function(){this.block_.warning=null;Blockly.Icon.prototype.dispose.call(this)};
|
||||
Blockly.Warning=function(a){Blockly.Warning.superClass_.constructor.call(this,a);this.createIcon();this.text_={}};goog.inherits(Blockly.Warning,Blockly.Icon);Blockly.Warning.prototype.collapseHidden=!1;Blockly.Warning.prototype.png_="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAARCAYAAAA7bUf6AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAANyAAADcgBffIlqAAAAAd0SU1FB98DGgApDBpIGrEAAAGfSURBVDjLnZM9S2NREIbfc2P8AF27BXshpIzK5g9ssUj8C2tnYyUoiBGSyk4sbCLs1vkRgoW1jYWFICwsMV2Se3JPboLe+FhcNCZcjXFgOMzHeec9M2ekDwTIAEUgo68IsOQczdNTIudoAksTg/g+5+UyDxKUyzz4PueTsvhZr+NmZkCC6Wmo1QiAX58FmLKWf4VCDPCiGxtgLf+B9FiQXo+9y0ucBIUCnJ3B+noMdHGBC0P2xrH4HoYEmUx8qVQCgMPD2F5ehjDEjTbZe2s4p5NKRenb2+Qid3dSpaK0tTp+j8VKq0VncXHQh2IxZrK/P/AtLECjQQf4McQEMNbq786O5qwdANfr8Xl/P/AFgbS7qzlr9Qcwr4EoYvPmBud5wxPJ5+HqCtbWhv3GwPU1Lor4/fKMeedo5vPDiRKsrsLWFuRyybFOhxbwTd0upWqVcDQpaTqjWq0SdruU5PvUkiol/ZNRzeXA96mp3aaRzSYnjdNsFtptGiYI2PY8HaVSmu33xWf3K5WS6ffVe3rSgXnzT+YlpSfY00djjJOkZ/wpr41bQMIsAAAAAElFTkSuQmCC";
|
||||
Blockly.Warning.textToDom_=function(a){var b=Blockly.createSvgElement("text",{"class":"blocklyText blocklyBubbleText",y:Blockly.Bubble.BORDER_WIDTH},null);a=a.split("\n");for(var c=0;c<a.length;c++){var d=Blockly.createSvgElement("tspan",{dy:"1em",x:Blockly.Bubble.BORDER_WIDTH},b),e=document.createTextNode(a[c]);d.appendChild(e)}return b};
|
||||
Blockly.Warning.prototype.setVisible=function(a){if(a!=this.isVisible())if(a){a=Blockly.Warning.textToDom_(this.getAllText());this.bubble_=new Blockly.Bubble(this.block_.workspace,a,this.block_.svgPath_,this.iconX_,this.iconY_,null,null);if(this.block_.RTL)for(var b=a.getBBox().width,c=0,d;d=a.childNodes[c];c++)d.setAttribute("text-anchor","end"),d.setAttribute("x",b+Blockly.Bubble.BORDER_WIDTH);this.updateColour();a=this.bubble_.getBubbleSize();this.bubble_.setBubbleSize(a.width,a.height)}else this.bubble_.dispose(),
|
||||
this.body_=this.bubble_=null};Blockly.Warning.prototype.bodyFocus_=function(a){this.bubble_.promote_()};Blockly.Warning.prototype.setText=function(a,b){this.text_[b]!=a&&(a?this.text_[b]=a:delete this.text_[b],this.isVisible()&&(this.setVisible(!1),this.setVisible(!0)))};Blockly.Warning.prototype.getAllText=function(){var a=[],b;for(b in this.text_)a.push(this.text_[b]);return a.join("\n")};Blockly.Warning.prototype.dispose=function(){this.block_.warning=null;Blockly.Icon.prototype.dispose.call(this)};
|
||||
// Copyright 2011 Google Inc. Apache License 2.0
|
||||
Blockly.Block=function(){goog.asserts.assert(0==arguments.length,"Please use Blockly.Block.obtain.")};Blockly.Block.obtain=function(a,b){if(Blockly.Realtime.isEnabled())return Blockly.Realtime.obtainBlock(a,b);var c=a.rendered?new Blockly.BlockSvg:new Blockly.Block;c.initialize(a,b);return c};Blockly.Block.prototype.initialize=function(a,b){this.id=Blockly.Blocks.genUid();a.addTopBlock(this);this.fill(a,b)};
|
||||
Blockly.Block.prototype.fill=function(a,b){this.previousConnection=this.nextConnection=this.outputConnection=null;this.inputList=[];this.inputsInline=void 0;this.disabled=this.rendered=!1;this.tooltip="";this.contextMenu=!0;this.parentBlock_=null;this.childBlocks_=[];this.editable_=this.movable_=this.deletable_=!0;this.collapsed_=!1;this.comment=null;this.xy_=new goog.math.Coordinate(0,0);this.workspace=a;this.isInFlyout=a.isFlyout;this.RTL=a.RTL;if(b){this.type=b;var c=Blockly.Blocks[b];goog.asserts.assertObject(c,
|
||||
@@ -1087,8 +1087,9 @@ a.render();a.workspace&&a.workspace.options.gridOptions&&a.workspace.options.gri
|
||||
Blockly.BlockSvg.prototype.setParent=function(a){var b=this.getSvgRoot();if(this.parentBlock_&&b){var c=this.getRelativeToSurfaceXY();this.workspace.getCanvas().appendChild(b);b.setAttribute("transform","translate("+c.x+", "+c.y+")")}Blockly.BlockSvg.superClass_.setParent.call(this,a);a&&(c=this.getRelativeToSurfaceXY(),a.getSvgRoot().appendChild(b),a=this.getRelativeToSurfaceXY(),this.moveConnections_(a.x-c.x,a.y-c.y))};
|
||||
Blockly.BlockSvg.prototype.getRelativeToSurfaceXY=function(){var a=0,b=0,c=this.getSvgRoot();if(c){do var d=Blockly.getRelativeXY_(c),a=a+d.x,b=b+d.y,c=c.parentNode;while(c&&c!=this.workspace.getCanvas())}return new goog.math.Coordinate(a,b)};Blockly.BlockSvg.prototype.moveBy=function(a,b){var c=this.getRelativeToSurfaceXY();this.getSvgRoot().setAttribute("transform","translate("+(c.x+a)+", "+(c.y+b)+")");this.moveConnections_(a,b);Blockly.Realtime.blockChanged(this)};
|
||||
Blockly.BlockSvg.prototype.snapToGrid_=function(){if(this.workspace&&0==Blockly.dragMode_&&!this.getParent()&&!this.isInFlyout){var a=this.workspace.options.gridOptions.spacing,b=a/2,c=this.getRelativeToSurfaceXY(),d=Math.round((c.x-b)/a)*a+b-c.x,a=Math.round((c.y-b)/a)*a+b-c.y,d=Math.round(d),a=Math.round(a);0==d&&0==a||this.moveBy(d,a)}};
|
||||
Blockly.BlockSvg.prototype.getHeightWidth=function(){var a=this.height,b=this.width,c=this.getNextBlock();c&&(c=c.getHeightWidth(),a+=c.height-4,b=Math.max(b,c.width));return{height:a,width:b}};
|
||||
Blockly.BlockSvg.prototype.setCollapsed=function(a){if(this.collapsed_!=a){for(var b=[],c=0,d;d=this.inputList[c];c++)b.push.apply(b,d.setVisible(!a));if(a){d=this.getIcons();for(c=0;c<d.length;c++)d[c].setVisible(!1);c=this.toString(Blockly.COLLAPSE_CHARS);this.appendDummyInput("_TEMP_COLLAPSED_INPUT").appendField(c).init()}else this.removeInput("_TEMP_COLLAPSED_INPUT");Blockly.BlockSvg.superClass_.setCollapsed.call(this,a);b.length||(b[0]=this);if(this.rendered)for(c=0;a=b[c];c++)a.render()}};
|
||||
Blockly.BlockSvg.prototype.getHeightWidth=function(){var a=this.height,b=this.width,c=this.getNextBlock();c?(c=c.getHeightWidth(),a+=c.height-4,b=Math.max(b,c.width)):this.nextConnection||this.outputConnection||(a+=2);return{height:a,width:b}};
|
||||
Blockly.BlockSvg.prototype.setCollapsed=function(a){if(this.collapsed_!=a){for(var b=[],c=0,d;d=this.inputList[c];c++)b.push.apply(b,d.setVisible(!a));if(a){d=this.getIcons();for(c=0;c<d.length;c++)d[c].setVisible(!1);c=this.toString(Blockly.COLLAPSE_CHARS);this.appendDummyInput("_TEMP_COLLAPSED_INPUT").appendField(c).init()}else this.removeInput("_TEMP_COLLAPSED_INPUT"),this.setWarningText(null);Blockly.BlockSvg.superClass_.setCollapsed.call(this,a);b.length||(b[0]=this);if(this.rendered)for(c=0;a=
|
||||
b[c];c++)a.render();this.workspace.fireChangeEvent()}};
|
||||
Blockly.BlockSvg.prototype.onMouseDown_=function(a){if(!this.isInFlyout){Blockly.svgResize(this.workspace);Blockly.terminateDrag_();this.select();Blockly.hideChaff();if(Blockly.isRightButton(a))this.showContextMenu_(a);else if(this.isMovable()){Blockly.removeAllRanges();Blockly.Css.setCursor(Blockly.Css.Cursor.CLOSED);var b=this.getRelativeToSurfaceXY();this.startDragX=b.x;this.startDragY=b.y;this.startDragMouseX=a.clientX;this.startDragMouseY=a.clientY;Blockly.dragMode_=1;Blockly.BlockSvg.onMouseUpWrapper_=
|
||||
Blockly.bindEvent_(document,"mouseup",this,this.onMouseUp_);Blockly.BlockSvg.onMouseMoveWrapper_=Blockly.bindEvent_(document,"mousemove",this,this.onMouseMove_);this.draggedBubbles_=[];for(var b=this.getDescendants(),c=0,d;d=b[c];c++){d=d.getIcons();for(var e=0;e<d.length;e++){var f=d[e].getIconLocation();f.bubble=d[e];this.draggedBubbles_.push(f)}}}else return;a.stopPropagation()}};
|
||||
Blockly.BlockSvg.prototype.onMouseUp_=function(a){var b=this;Blockly.doCommand(function(){Blockly.terminateDrag_();if(Blockly.selected&&Blockly.highlightedConnection_)Blockly.localConnection_.connect(Blockly.highlightedConnection_),b.rendered&&(Blockly.localConnection_.isSuperior()?Blockly.highlightedConnection_:Blockly.localConnection_).sourceBlock_.connectionUiEffect(),b.workspace.trashcan&&b.workspace.trashcan.close();else if(Blockly.selected.isDeletable()&&b.workspace.isDeleteArea(a)){var c=b.workspace.trashcan;
|
||||
@@ -1113,11 +1114,12 @@ this.svgPath_=this.svgGroup_=null};Blockly.BlockSvg.prototype.disposeUiEffect=fu
|
||||
Blockly.BlockSvg.disposeUiStep_=function(a,b){var c=(new Date-a.startDate_)/150;1<c?goog.dom.removeNode(a):(a.setAttribute("transform","translate("+(a.translateX_+(b?-1:1)*a.bBox_.width/2*c+", "+(a.translateY_+a.bBox_.height*c))+") scale("+(1-c)+")"),setTimeout(function(){Blockly.BlockSvg.disposeUiStep_(a,b)},10))};
|
||||
Blockly.BlockSvg.prototype.connectionUiEffect=function(){this.workspace.playAudio("click");var a=Blockly.getSvgXY_(this.svgGroup_);this.outputConnection?(a.x+=this.RTL?3:-3,a.y+=13):this.previousConnection&&(a.x+=this.RTL?-23:23,a.y+=3);a=Blockly.createSvgElement("circle",{cx:a.x,cy:a.y,r:0,fill:"none",stroke:"#888","stroke-width":10},this.workspace.options.svg);a.startDate_=new Date;Blockly.BlockSvg.connectionUiStep_(a)};
|
||||
Blockly.BlockSvg.connectionUiStep_=function(a){var b=(new Date-a.startDate_)/150;1<b?goog.dom.removeNode(a):(a.setAttribute("r",25*b),a.style.opacity=1-b,setTimeout(function(){Blockly.BlockSvg.connectionUiStep_(a)},10))};
|
||||
Blockly.BlockSvg.prototype.updateColour=function(){if(!this.disabled){var a=Blockly.makeColour(this.getColour()),b=goog.color.hexToRgb(a),c=goog.color.lighten(b,.3),b=goog.color.darken(b,.2);this.svgPathLight_.setAttribute("stroke",goog.color.rgbArrayToHex(c));this.svgPathDark_.setAttribute("fill",goog.color.rgbArrayToHex(b));this.svgPath_.setAttribute("fill",a);c=this.getIcons();for(a=0;a<c.length;a++)c[a].updateColour();for(a=0;c=this.inputList[a];a++)for(var b=0,d;d=c.fieldRow[b];b++)d.setText(null)}};
|
||||
Blockly.BlockSvg.prototype.updateColour=function(){if(!this.disabled){var a=Blockly.makeColour(this.getColour()),b=goog.color.hexToRgb(a),c=goog.color.lighten(b,.3),b=goog.color.darken(b,.2);this.svgPathLight_.setAttribute("stroke",goog.color.rgbArrayToHex(c));this.svgPathDark_.setAttribute("fill",goog.color.rgbArrayToHex(b));this.svgPath_.setAttribute("fill",a);a=this.getIcons();for(c=0;c<a.length;c++)a[c].updateColour();for(a=0;c=this.inputList[a];a++)for(var b=0,d;d=c.fieldRow[b];b++)d.setText(null)}};
|
||||
Blockly.BlockSvg.prototype.updateDisabled=function(){var a=Blockly.hasClass_(this.svgGroup_,"blocklyDisabled");this.disabled||this.getInheritedDisabled()?a||(Blockly.addClass_(this.svgGroup_,"blocklyDisabled"),this.svgPath_.setAttribute("fill","url(#blocklyDisabledPattern)")):a&&(Blockly.removeClass_(this.svgGroup_,"blocklyDisabled"),this.updateColour());for(var a=this.getChildren(),b=0,c;c=a[b];b++)c.updateDisabled()};
|
||||
Blockly.BlockSvg.prototype.getCommentText=function(){return this.comment?this.comment.getText().replace(/\s+$/,"").replace(/ +\n/g,"\n"):""};Blockly.BlockSvg.prototype.setCommentText=function(a){var b=!1;goog.isString(a)?(this.comment||(this.comment=new Blockly.Comment(this),b=!0),this.comment.setText(a)):this.comment&&(this.comment.dispose(),b=!0);b&&this.rendered&&(this.render(),this.bumpNeighbours_())};
|
||||
Blockly.BlockSvg.prototype.setWarningText=function(a){this.setWarningText.pid_&&(clearTimeout(this.setWarningText.pid_),this.setWarningText.pid_=0);if(2==Blockly.dragMode_){var b=this;this.setWarningText.pid_=setTimeout(function(){b.setWarningText.pid_=0;b.setWarningText(a)},100)}else{this.isInFlyout&&(a=null);var c=!1;goog.isString(a)?(this.warning||(this.warning=new Blockly.Warning(this),c=!0),this.warning.setText(a)):this.warning&&(this.warning.dispose(),c=!0);c&&this.rendered&&(this.render(),
|
||||
this.bumpNeighbours_())}};Blockly.BlockSvg.prototype.setMutator=function(a){this.mutator&&this.mutator!==a&&this.mutator.dispose();a&&(a.block_=this,this.mutator=a,this.rendered&&a.createIcon())};Blockly.BlockSvg.prototype.setDisabled=function(a){this.disabled!=a&&(Blockly.BlockSvg.superClass_.setDisabled.call(this,a),this.rendered&&this.updateDisabled(),this.workspace.fireChangeEvent())};Blockly.BlockSvg.prototype.addSelect=function(){Blockly.addClass_(this.svgGroup_,"blocklySelected");this.svgGroup_.parentNode.appendChild(this.svgGroup_)};
|
||||
Blockly.BlockSvg.prototype.setWarningText=function(a,b){this.setWarningText.pid_||(this.setWarningText.pid_=Object.create(null));var c=b||"";if(c)this.setWarningText.pid_[c]&&(clearTimeout(this.setWarningText.pid_[c]),delete this.setWarningText.pid_[c]);else for(var d in this.setWarningText.pid_)clearTimeout(this.setWarningText.pid_[d]),delete this.setWarningText.pid_[d];if(2==Blockly.dragMode_){var e=this;this.setWarningText.pid_[c]=setTimeout(function(){delete e.setWarningText.pid_[c];e.setWarningText(a,
|
||||
c)},100)}else{this.isInFlyout&&(a=null);for(d=this.getParent();d;)d.isCollapsed()&&d.setWarningText(a,this.id),d=d.getParent();d=!1;if(goog.isString(a))this.warning||(this.warning=new Blockly.Warning(this),d=!0),this.warning.setText(a,c);else if(this.warning&&!c)this.warning.dispose(),d=!0;else if(this.warning){d=this.warning.getAllText();this.warning.setText("",c);var f=this.warning.getAllText();f||this.warning.dispose();d=d==f}d&&this.rendered&&(this.render(),this.bumpNeighbours_())}};
|
||||
Blockly.BlockSvg.prototype.setMutator=function(a){this.mutator&&this.mutator!==a&&this.mutator.dispose();a&&(a.block_=this,this.mutator=a,this.rendered&&a.createIcon())};Blockly.BlockSvg.prototype.setDisabled=function(a){this.disabled!=a&&(Blockly.BlockSvg.superClass_.setDisabled.call(this,a),this.rendered&&this.updateDisabled(),this.workspace.fireChangeEvent())};Blockly.BlockSvg.prototype.addSelect=function(){Blockly.addClass_(this.svgGroup_,"blocklySelected");this.svgGroup_.parentNode.appendChild(this.svgGroup_)};
|
||||
Blockly.BlockSvg.prototype.removeSelect=function(){Blockly.removeClass_(this.svgGroup_,"blocklySelected")};Blockly.BlockSvg.prototype.addDragging=function(){Blockly.addClass_(this.svgGroup_,"blocklyDragging")};Blockly.BlockSvg.prototype.removeDragging=function(){Blockly.removeClass_(this.svgGroup_,"blocklyDragging")};
|
||||
Blockly.BlockSvg.prototype.render=function(a){this.rendered=!0;var b=Blockly.BlockSvg.SEP_SPACE_X;this.RTL&&(b=-b);for(var c=this.getIcons(),d=0;d<c.length;d++)b=c[d].renderIcon(b);b+=this.RTL?Blockly.BlockSvg.SEP_SPACE_X:-Blockly.BlockSvg.SEP_SPACE_X;c=this.renderCompute_(b);this.renderDraw_(b,c);!1!==a&&((a=this.getParent())?a.render(!0):Blockly.fireUiEvent(window,"resize"));Blockly.Realtime.blockChanged(this)};
|
||||
Blockly.BlockSvg.prototype.renderFields_=function(a,b,c){this.RTL&&(b=-b);for(var d=0,e;e=a[d];d++){var f=e.getSvgRoot();f&&(this.RTL?(b-=e.renderSep+e.renderWidth,f.setAttribute("transform","translate("+b+", "+c+")"),e.renderWidth&&(b-=Blockly.BlockSvg.SEP_SPACE_X)):(f.setAttribute("transform","translate("+(b+e.renderSep)+", "+c+")"),e.renderWidth&&(b+=e.renderSep+e.renderWidth+Blockly.BlockSvg.SEP_SPACE_X)))}return this.RTL?-b:b};
|
||||
|
||||
@@ -76,7 +76,7 @@ Blockly.BlockSvg.INLINE = -1;
|
||||
*/
|
||||
Blockly.BlockSvg.prototype.initSvg = function() {
|
||||
goog.asserts.assert(this.workspace.rendered, 'Workspace is headless.');
|
||||
for (var x = 0, input; input = this.inputList[x]; x++) {
|
||||
for (var i = 0, input; input = this.inputList[i]; i++) {
|
||||
input.init();
|
||||
}
|
||||
if (this.mutator) {
|
||||
@@ -319,6 +319,9 @@ Blockly.BlockSvg.prototype.getHeightWidth = function() {
|
||||
var nextHeightWidth = nextBlock.getHeightWidth();
|
||||
height += nextHeightWidth.height - 4; // Height of tab.
|
||||
width = Math.max(width, nextHeightWidth.width);
|
||||
} else if (!this.nextConnection && !this.outputConnection) {
|
||||
// Add a bit of margin under blocks with no bottom tab.
|
||||
height += 2;
|
||||
}
|
||||
return {height: height, width: width};
|
||||
};
|
||||
@@ -333,20 +336,22 @@ Blockly.BlockSvg.prototype.setCollapsed = function(collapsed) {
|
||||
}
|
||||
var renderList = [];
|
||||
// Show/hide the inputs.
|
||||
for (var x = 0, input; input = this.inputList[x]; x++) {
|
||||
for (var i = 0, input; input = this.inputList[i]; i++) {
|
||||
renderList.push.apply(renderList, input.setVisible(!collapsed));
|
||||
}
|
||||
|
||||
var COLLAPSED_INPUT_NAME = '_TEMP_COLLAPSED_INPUT';
|
||||
if (collapsed) {
|
||||
var icons = this.getIcons();
|
||||
for (var x = 0; x < icons.length; x++) {
|
||||
icons[x].setVisible(false);
|
||||
for (var i = 0; i < icons.length; i++) {
|
||||
icons[i].setVisible(false);
|
||||
}
|
||||
var text = this.toString(Blockly.COLLAPSE_CHARS);
|
||||
this.appendDummyInput(COLLAPSED_INPUT_NAME).appendField(text).init();
|
||||
} else {
|
||||
this.removeInput(COLLAPSED_INPUT_NAME);
|
||||
// Clear any warnings inherited from enclosed blocks.
|
||||
this.setWarningText(null);
|
||||
}
|
||||
Blockly.BlockSvg.superClass_.setCollapsed.call(this, collapsed);
|
||||
|
||||
@@ -355,7 +360,7 @@ Blockly.BlockSvg.prototype.setCollapsed = function(collapsed) {
|
||||
renderList[0] = this;
|
||||
}
|
||||
if (this.rendered) {
|
||||
for (var x = 0, block; block = renderList[x]; x++) {
|
||||
for (var i = 0, block; block = renderList[i]; i++) {
|
||||
block.render();
|
||||
}
|
||||
// Don't bump neighbours.
|
||||
@@ -363,6 +368,7 @@ Blockly.BlockSvg.prototype.setCollapsed = function(collapsed) {
|
||||
// all their functions and store them next to each other. Expanding and
|
||||
// bumping causes all their definitions to go out of alignment.
|
||||
}
|
||||
this.workspace.fireChangeEvent();
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -406,11 +412,11 @@ Blockly.BlockSvg.prototype.onMouseDown_ = function(e) {
|
||||
// Build a list of bubbles that need to be moved and where they started.
|
||||
this.draggedBubbles_ = [];
|
||||
var descendants = this.getDescendants();
|
||||
for (var x = 0, descendant; descendant = descendants[x]; x++) {
|
||||
for (var i = 0, descendant; descendant = descendants[i]; i++) {
|
||||
var icons = descendant.getIcons();
|
||||
for (var y = 0; y < icons.length; y++) {
|
||||
var data = icons[y].getIconLocation();
|
||||
data.bubble = icons[y];
|
||||
for (var j = 0; j < icons.length; j++) {
|
||||
var data = icons[j].getIconLocation();
|
||||
data.bubble = icons[j];
|
||||
this.draggedBubbles_.push(data);
|
||||
}
|
||||
}
|
||||
@@ -627,17 +633,17 @@ Blockly.BlockSvg.prototype.moveConnections_ = function(dx, dy) {
|
||||
return;
|
||||
}
|
||||
var myConnections = this.getConnections_(false);
|
||||
for (var x = 0; x < myConnections.length; x++) {
|
||||
myConnections[x].moveBy(dx, dy);
|
||||
for (var i = 0; i < myConnections.length; i++) {
|
||||
myConnections[i].moveBy(dx, dy);
|
||||
}
|
||||
var icons = this.getIcons();
|
||||
for (var x = 0; x < icons.length; x++) {
|
||||
icons[x].computeIconLocation();
|
||||
for (var i = 0; i < icons.length; i++) {
|
||||
icons[i].computeIconLocation();
|
||||
}
|
||||
|
||||
// Recurse through all blocks attached under this one.
|
||||
for (var x = 0; x < this.childBlocks_.length; x++) {
|
||||
this.childBlocks_[x].moveConnections_(dx, dy);
|
||||
for (var i = 0; i < this.childBlocks_.length; i++) {
|
||||
this.childBlocks_[i].moveConnections_(dx, dy);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -653,8 +659,8 @@ Blockly.BlockSvg.prototype.setDragging_ = function(adding) {
|
||||
this.removeDragging();
|
||||
}
|
||||
// Recurse through all blocks attached under this one.
|
||||
for (var x = 0; x < this.childBlocks_.length; x++) {
|
||||
this.childBlocks_[x].setDragging_(adding);
|
||||
for (var i = 0; i < this.childBlocks_.length; i++) {
|
||||
this.childBlocks_[i].setDragging_(adding);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1009,8 +1015,8 @@ Blockly.BlockSvg.prototype.dispose = function(healStack, animate,
|
||||
this.rendered = false;
|
||||
|
||||
var icons = this.getIcons();
|
||||
for (var x = 0; x < icons.length; x++) {
|
||||
icons[x].dispose();
|
||||
for (var i = 0; i < icons.length; i++) {
|
||||
icons[i].dispose();
|
||||
}
|
||||
|
||||
Blockly.BlockSvg.superClass_.dispose.call(this, healStack);
|
||||
@@ -1131,8 +1137,8 @@ Blockly.BlockSvg.prototype.updateColour = function() {
|
||||
this.svgPath_.setAttribute('fill', hexColour);
|
||||
|
||||
var icons = this.getIcons();
|
||||
for (var x = 0; x < icons.length; x++) {
|
||||
icons[x].updateColour();
|
||||
for (var i = 0; i < icons.length; i++) {
|
||||
icons[i].updateColour();
|
||||
}
|
||||
|
||||
// Bump every dropdown to change its colour.
|
||||
@@ -1213,39 +1219,66 @@ Blockly.BlockSvg.prototype.setCommentText = function(text) {
|
||||
* maintain multiple warnings.
|
||||
*/
|
||||
Blockly.BlockSvg.prototype.setWarningText = function(text, opt_id) {
|
||||
if (this.setWarningText.pid_) {
|
||||
if (!this.setWarningText.pid_) {
|
||||
// Create a database of warning PIDs.
|
||||
// Only runs once per block (and only those with warnings).
|
||||
this.setWarningText.pid_ = Object.create(null);
|
||||
}
|
||||
var id = opt_id || '';
|
||||
if (!id) {
|
||||
// Kill all previous pending processes, this edit supercedes them all.
|
||||
for (var n in this.setWarningText.pid_) {
|
||||
clearTimeout(this.setWarningText.pid_[n]);
|
||||
delete this.setWarningText.pid_[n];
|
||||
}
|
||||
} else if (this.setWarningText.pid_[id]) {
|
||||
// Only queue up the latest change. Kill any earlier pending process.
|
||||
clearTimeout(this.setWarningText.pid_);
|
||||
this.setWarningText.pid_ = 0;
|
||||
clearTimeout(this.setWarningText.pid_[id]);
|
||||
delete this.setWarningText.pid_[id];
|
||||
}
|
||||
if (Blockly.dragMode_ == 2) {
|
||||
// Don't change the warning text during a drag.
|
||||
// Wait until the drag finishes.
|
||||
var thisBlock = this;
|
||||
this.setWarningText.pid_ = setTimeout(function() {
|
||||
thisBlock.setWarningText.pid_ = 0;
|
||||
thisBlock.setWarningText(text, opt_id);
|
||||
this.setWarningText.pid_[id] = setTimeout(function() {
|
||||
delete thisBlock.setWarningText.pid_[id];
|
||||
thisBlock.setWarningText(text, id);
|
||||
}, 100);
|
||||
return;
|
||||
}
|
||||
if (this.isInFlyout) {
|
||||
text = null;
|
||||
}
|
||||
|
||||
// Bubble up through block's parents to add a warning on any collapsed block.
|
||||
var parent = this.getParent();
|
||||
while (parent) {
|
||||
if (parent.isCollapsed()) {
|
||||
parent.setWarningText(text, this.id);
|
||||
}
|
||||
parent = parent.getParent();
|
||||
}
|
||||
|
||||
var changedState = false;
|
||||
if (goog.isString(text)) {
|
||||
if (!this.warning) {
|
||||
this.warning = new Blockly.Warning(this);
|
||||
changedState = true;
|
||||
}
|
||||
this.warning.setText(/** @type {string} */ (text), opt_id);
|
||||
this.warning.setText(/** @type {string} */ (text), id);
|
||||
} else {
|
||||
// Dispose all warnings if no id is given
|
||||
if (this.warning && opt_id === undefined) {
|
||||
// Dispose all warnings if no id is given.
|
||||
if (this.warning && !id) {
|
||||
this.warning.dispose();
|
||||
changedState = true;
|
||||
} else if (this.warning) {
|
||||
this.warning.removeText(opt_id);
|
||||
changedState = true;
|
||||
var oldText = this.warning.getAllText();
|
||||
this.warning.setText('', id);
|
||||
var newText = this.warning.getAllText();
|
||||
if (!newText) {
|
||||
this.warning.dispose();
|
||||
}
|
||||
changedState = oldText == newText;
|
||||
}
|
||||
}
|
||||
if (changedState && this.rendered) {
|
||||
@@ -1337,8 +1370,8 @@ Blockly.BlockSvg.prototype.render = function(opt_bubble) {
|
||||
}
|
||||
// Move the icons into position.
|
||||
var icons = this.getIcons();
|
||||
for (var x = 0; x < icons.length; x++) {
|
||||
cursorX = icons[x].renderIcon(cursorX);
|
||||
for (var i = 0; i < icons.length; i++) {
|
||||
cursorX = icons[i].renderIcon(cursorX);
|
||||
}
|
||||
cursorX += this.RTL ?
|
||||
Blockly.BlockSvg.SEP_SPACE_X : -Blockly.BlockSvg.SEP_SPACE_X;
|
||||
|
||||
13
core/icon.js
13
core/icon.js
@@ -39,16 +39,21 @@ Blockly.Icon = function(block) {
|
||||
};
|
||||
|
||||
/**
|
||||
* Icon in base64 format.
|
||||
* @private
|
||||
* Does this icon get hidden when the block is collapsed.
|
||||
*/
|
||||
Blockly.Icon.prototype.png_ = '';
|
||||
Blockly.Icon.prototype.collapseHidden = true;
|
||||
|
||||
/**
|
||||
* Height and width of icons.
|
||||
*/
|
||||
Blockly.Icon.prototype.SIZE = 17;
|
||||
|
||||
/**
|
||||
* Icon in base64 format.
|
||||
* @private
|
||||
*/
|
||||
Blockly.Icon.prototype.png_ = '';
|
||||
|
||||
/**
|
||||
* Bubble UI (if visible).
|
||||
* @type {Blockly.Bubble}
|
||||
@@ -154,7 +159,7 @@ Blockly.Icon.prototype.updateColour = function() {
|
||||
* @return {number} Horizontal offset for next item to draw.
|
||||
*/
|
||||
Blockly.Icon.prototype.renderIcon = function(cursorX) {
|
||||
if (this.block_.isCollapsed()) {
|
||||
if (this.collapseHidden && this.block_.isCollapsed()) {
|
||||
this.iconGroup_.setAttribute('display', 'none');
|
||||
return cursorX;
|
||||
}
|
||||
|
||||
@@ -39,11 +39,16 @@ goog.require('Blockly.Icon');
|
||||
Blockly.Warning = function(block) {
|
||||
Blockly.Warning.superClass_.constructor.call(this, block);
|
||||
this.createIcon();
|
||||
// The text_ object can contain multiple warnings
|
||||
this.text_ = { default_: '' };
|
||||
// The text_ object can contain multiple warnings.
|
||||
this.text_ = {};
|
||||
};
|
||||
goog.inherits(Blockly.Warning, Blockly.Icon);
|
||||
|
||||
/**
|
||||
* Does this icon get hidden when the block is collapsed.
|
||||
*/
|
||||
Blockly.Warning.prototype.collapseHidden = false;
|
||||
|
||||
/**
|
||||
* Icon in base64 format.
|
||||
* @private
|
||||
@@ -83,11 +88,7 @@ Blockly.Warning.prototype.setVisible = function(visible) {
|
||||
}
|
||||
if (visible) {
|
||||
// Create the bubble to display all warnings.
|
||||
var allWarnings = [];
|
||||
for (var id_ in this.text_) {
|
||||
allWarnings.push(this.text_[id_]);
|
||||
}
|
||||
var paragraph = Blockly.Warning.textToDom_(allWarnings.join('\n'));
|
||||
var paragraph = Blockly.Warning.textToDom_(this.getAllText());
|
||||
this.bubble_ = new Blockly.Bubble(
|
||||
/** @type {!Blockly.Workspace} */ (this.block_.workspace),
|
||||
paragraph, this.block_.svgPath_,
|
||||
@@ -96,7 +97,7 @@ Blockly.Warning.prototype.setVisible = function(visible) {
|
||||
// Right-align the paragraph.
|
||||
// This cannot be done until the bubble is rendered on screen.
|
||||
var maxWidth = paragraph.getBBox().width;
|
||||
for (var x = 0, textElement; textElement = paragraph.childNodes[x]; x++) {
|
||||
for (var i = 0, textElement; textElement = paragraph.childNodes[i]; i++) {
|
||||
textElement.setAttribute('text-anchor', 'end');
|
||||
textElement.setAttribute('x', maxWidth + Blockly.Bubble.BORDER_WIDTH);
|
||||
}
|
||||
@@ -124,21 +125,18 @@ Blockly.Warning.prototype.bodyFocus_ = function(e) {
|
||||
|
||||
/**
|
||||
* Set this warning's text.
|
||||
* @param {string} text Warning text.
|
||||
* @param {string=} opt_id An optional ID for this text entry to be able to
|
||||
* maintain multiple warnings.
|
||||
* @param {string} text Warning text (or '' to delete).
|
||||
* @param {string} id An ID for this text entry to be able to maintain
|
||||
* multiple warnings.
|
||||
*/
|
||||
Blockly.Warning.prototype.setText = function(text, opt_id) {
|
||||
if (opt_id !== undefined) {
|
||||
if (this.text_[opt_id] == text) {
|
||||
return;
|
||||
}
|
||||
this.text_[opt_id] = text;
|
||||
Blockly.Warning.prototype.setText = function(text, id) {
|
||||
if (this.text_[id] == text) {
|
||||
return;
|
||||
}
|
||||
if (text) {
|
||||
this.text_[id] = text;
|
||||
} else {
|
||||
if (this.text_.default_ == text) {
|
||||
return;
|
||||
}
|
||||
this.text_.default_ = text;
|
||||
delete this.text_[id];
|
||||
}
|
||||
if (this.isVisible()) {
|
||||
this.setVisible(false);
|
||||
@@ -147,23 +145,15 @@ Blockly.Warning.prototype.setText = function(text, opt_id) {
|
||||
};
|
||||
|
||||
/**
|
||||
* Removes the specified warning text.
|
||||
* @param {string} textId ID of the warning to be removed.
|
||||
* Get this warning's texts.
|
||||
* @return {string} All texts concatenated into one string.
|
||||
*/
|
||||
Blockly.Warning.prototype.removeText = function(textId) {
|
||||
if (this.text_[textId] === undefined) {
|
||||
return; // ID not found, no change.
|
||||
}
|
||||
delete this.text_[textId];
|
||||
if (Object.keys(this.text_).length === 0 ||
|
||||
(Object.keys(this.text_).length === 1 && !this.text_.default_)) {
|
||||
this.dispose();
|
||||
} else {
|
||||
if (this.isVisible()) {
|
||||
this.setVisible(false);
|
||||
this.setVisible(true);
|
||||
}
|
||||
Blockly.Warning.prototype.getAllText = function() {
|
||||
var allWarnings = [];
|
||||
for (var id in this.text_) {
|
||||
allWarnings.push(this.text_[id]);
|
||||
}
|
||||
return allWarnings.join('\n');
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -312,7 +312,7 @@ Blockly.WorkspaceSvg.prototype.setVisible = function(isVisible) {
|
||||
*/
|
||||
Blockly.WorkspaceSvg.prototype.render = function() {
|
||||
var renderList = this.getAllBlocks();
|
||||
for (var x = 0, block; block = renderList[x]; x++) {
|
||||
for (var i = 0, block; block = renderList[i]; i++) {
|
||||
if (!block.getChildren().length) {
|
||||
block.render();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user