scratch-blocks/core/rendered_connection.js

390 lines
13 KiB
JavaScript
Raw Normal View History

/**
* @license
* Visual Blocks Editor
*
* Copyright 2016 Google Inc.
* https://developers.google.com/blockly/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @fileoverview Components for creating connections between blocks.
* @author fenichel@google.com (Rachel Fenichel)
*/
'use strict';
goog.provide('Blockly.RenderedConnection');
goog.require('Blockly.Connection');
2016-05-10 16:36:40 -07:00
/**
* Class for a connection between blocks that may be rendered on screen.
* @param {!Blockly.Block} source The block establishing this connection.
* @param {number} type The type of the connection.
Merge google/develop June 22 (#441) * Localisation updates from https://translatewiki.net. * test page that creates random blocks and randomly drags them around the page * Localisation updates from https://translatewiki.net. * add missing return in fake drag * get rid of drag_tests file: * Generated JS helper functions should be camelCase. Complying with Google style guide. * Localisation updates from https://translatewiki.net. * Fix extra category error. Clean up code, rename variables, reduce line lengths, fix lint issues. * Remove claim that good.string.quote should be used. * Change the blockly workspace resizing strategy. (#386) * Add a new method to be called when the contents of the workspace change and the scrollbars need to be adjusted but the the chrome (trash, toolbox, etc) are expected to stay in the same place. Change a bunch of calls to svgResize to either be removed or call the new method instead. This is a nice performance win since the offsetHeight/Width call in svgResize can be expensive, especially when called as often as we do - there was some layout thrashing. This also paves the way for moving calls to recordDeleteAreas (which is also expensive) to a more cacheable spot than on every mouse down/touch event. of things (namely the scrollbars) * Fix size of graph demo when it first loads by calling svgResize. The graph starts with fixed width and was relying on a resize event to fire (which I believe was removed in commit 217c681b86b0f2df76c479c9efae62e6e). * Fix the resizing of the code demo. The demo's tab min-width used to match the toolbox's width was only being set on a resize event, but commit 217c681b86b0f2df76c479c9efae62e6e changed how that worked. * Fix up some comments. * Use specific workspaces rather than Blockly.getMainWorkspace(). * Make workspace required for resizeSvgContents and update some calls to send real workspaces rather than ones that are null. Remove the private tag on terminateDrag_ because it is only actually called from outside the BlockSvg object. * Remove a rogue period. * Recategorize BlockSvg.terminateDrag_ to @package instead of @private so that other developers don't use it, but it still can be used by other Blockly classes. * Add a TODO to fix issue #307. * Add @package to workspace resizeContents. * Routine recompile * Fix unit tests. * Fix inheritance on rendered connection. Closure compiler on maximum compression breaks badly due to lack of @extends attribute. * Add toolbox location and toolbox mode options to playground. * Increase commonality between playgrounds. * Properly deal with shadow statement blocks in stacks. * Localisation updates from https://translatewiki.net. * Use a comment block for function comments in generated JS, Python and Dart. * Fix typo in flyout.js (#403) * Fix typo in flyout.js (#402) * Line wrap comments in generated code. * Remove reference to undefined variable (#413) REASON_MUST_DISCONNECT was removed by a refactor in 2a1ffa1. * Fix airstrike by grabbing the correct toolbox element. (#411) Probably broken in 266e2ffa9a017d21d7ca2f151730d6ecfcecf173. * Localisation updates from https://translatewiki.net. * Fix issue #406 by calling resize from the keypress handler on text inputs. (#408) * Remove shadow blocks from Accessible Blockly demo. Update README. * Generate for loops on one line. * Introduce a common translation pipe; remove local stringMap attributes. Fix variable name error in paste functions. Minor linting. * Fix precedence on isIndex blocks. * Add indexing setting for JavaScript Generation (#419) Adding setting to allow for switching between zero and one based indexing for Blockly Blocks such that the generated code will use this flag to determine whether one based or zero based indexing should be used. One based indexing is enabled by default. * Remove unused functions and dependencies. * Remove the unnecessary construction of new services. * Fix sort block in JS to satisfy tests. * Trigger a contents resize in block's moveBy. (#422) This fixes #420 but and it also fixes some other similar problems with copy/paste and other users of moveBy. * Consolidate the usages of the 'blockly-disabled' label. * Fix error when undoing a shadow block replacement. Issue #415. * Unify setActiveDesc() and updateSelectedNode() in the TreeService. Move function calls made directly within the template to the correct hooks. * Standardize naming of components. * Prevent collisions between user functions and helper functions. * Localisation updates from https://translatewiki.net. * Fix #425. Attash the resize handler to the workspace so it can be removed (#429) when workspace.dispose() is called. * Change the TreeService to a singleton. * Remove unneeded generated parens around function calls in indexOf blocks. * Fix #423 by calling workspace's resize when the flyout reflows. (#430) * Updating URLs to reflect new docs. (#418) * Updating URLs to reflect new docs. Removing -blockly in URLs. * Rebuilt. * Routine recompile * Prevent selected block from ending up underneath a bumped block. * Fix undo on fields with validators with side effects. * Don't fire change event on fields that haven't been named yet. * Localisation updates from https://translatewiki.net. * Fix tree focus issues. * Fix remaining focus issues on block deletion. * cache delete areas instead of recalculating them onMouseDown * Cache screen CTM for performance improvement. * Call svgResizeContents from block_svg's dipose so that deleting blocks (#434) from the context menu (or anywhere really) causes the workspace to recalculate its size. Remove the call to svgResizeContents from onMouseUp's logic for determining whether the block is being dropped in the trash since it calls dispose. One side effect of this is that when you delete multiple blocks resize gets called for each of them and the scrollbars move during the operation. This is most obviously seen by doing an airstrike in the playground and then deleting all the blocks at once. * Allow terminal blocks to replace other terminal blocks (#433) * Allow terminal blocks to replace other terminal blocks * Updated test to allow replacing terminal blocks * Refactor how activeDescendant is set. Introduce helper functions to ensure that calls like pasteAbove() preserve the focus. * Localisation updates from https://translatewiki.net. * Remove unnecessary logging. * Reduce unneeded parentheses in JS and Python. * Start using field_number. * Make it easy to disable unconnected blocks. * Routine recompile. * Check if matrix is null in mouseToSvg * Remove js/ localizations pre-merge * Fix change to block_render_svg * Fix error in xml.js * Playground merge * Add simple toolboxes to playgrounds * Fix flyout reference in events listener * Move tokenizeIntepolation into Blockly.utils namespace. * Use simpler message interpolation in Code demo. * Create console stub for IE 9. * Don't output blockId if not set (e.g., toolbox category event). (#443) * Fix block in multi-playground * Increase commonality between playgrounds. # Conflicts: # tests/multi_playground.html # tests/playground.html * Remove "show flyouts" button * Recompile for merge June 22
2016-06-22 17:50:16 -04:00
* @extends {Blockly.Connection}
* @constructor
*/
Blockly.RenderedConnection = function(source, type) {
Blockly.RenderedConnection.superClass_.constructor.call(this, source, type);
this.offsetInBlock_ = new goog.math.Coordinate(0, 0);
};
goog.inherits(Blockly.RenderedConnection, Blockly.Connection);
/**
* Returns the distance between this connection and another connection.
* @param {!Blockly.Connection} otherConnection The other connection to measure
* the distance to.
* @return {number} The distance between connections.
*/
Blockly.RenderedConnection.prototype.distanceFrom = function(otherConnection) {
var xDiff = this.x_ - otherConnection.x_;
var yDiff = this.y_ - otherConnection.y_;
return Math.sqrt(xDiff * xDiff + yDiff * yDiff);
};
/**
* Move the block(s) belonging to the connection to a point where they don't
* visually interfere with the specified connection.
* @param {!Blockly.Connection} staticConnection The connection to move away
* from.
* @private
*/
Blockly.RenderedConnection.prototype.bumpAwayFrom_ = function(staticConnection) {
if (Blockly.dragMode_ != Blockly.DRAG_NONE) {
// Don't move blocks around while the user is doing the same.
return;
}
// Move the root block.
var rootBlock = this.sourceBlock_.getRootBlock();
if (rootBlock.isInFlyout) {
// Don't move blocks around in a flyout.
return;
}
var reverse = false;
if (!rootBlock.isMovable()) {
// Can't bump an uneditable block away.
// Check to see if the other block is movable.
rootBlock = staticConnection.getSourceBlock().getRootBlock();
if (!rootBlock.isMovable()) {
return;
}
// Swap the connections and move the 'static' connection instead.
staticConnection = this;
reverse = true;
}
// Raise it to the top for extra visibility.
Merge google/develop June 22 (#441) * Localisation updates from https://translatewiki.net. * test page that creates random blocks and randomly drags them around the page * Localisation updates from https://translatewiki.net. * add missing return in fake drag * get rid of drag_tests file: * Generated JS helper functions should be camelCase. Complying with Google style guide. * Localisation updates from https://translatewiki.net. * Fix extra category error. Clean up code, rename variables, reduce line lengths, fix lint issues. * Remove claim that good.string.quote should be used. * Change the blockly workspace resizing strategy. (#386) * Add a new method to be called when the contents of the workspace change and the scrollbars need to be adjusted but the the chrome (trash, toolbox, etc) are expected to stay in the same place. Change a bunch of calls to svgResize to either be removed or call the new method instead. This is a nice performance win since the offsetHeight/Width call in svgResize can be expensive, especially when called as often as we do - there was some layout thrashing. This also paves the way for moving calls to recordDeleteAreas (which is also expensive) to a more cacheable spot than on every mouse down/touch event. of things (namely the scrollbars) * Fix size of graph demo when it first loads by calling svgResize. The graph starts with fixed width and was relying on a resize event to fire (which I believe was removed in commit 217c681b86b0f2df76c479c9efae62e6e). * Fix the resizing of the code demo. The demo's tab min-width used to match the toolbox's width was only being set on a resize event, but commit 217c681b86b0f2df76c479c9efae62e6e changed how that worked. * Fix up some comments. * Use specific workspaces rather than Blockly.getMainWorkspace(). * Make workspace required for resizeSvgContents and update some calls to send real workspaces rather than ones that are null. Remove the private tag on terminateDrag_ because it is only actually called from outside the BlockSvg object. * Remove a rogue period. * Recategorize BlockSvg.terminateDrag_ to @package instead of @private so that other developers don't use it, but it still can be used by other Blockly classes. * Add a TODO to fix issue #307. * Add @package to workspace resizeContents. * Routine recompile * Fix unit tests. * Fix inheritance on rendered connection. Closure compiler on maximum compression breaks badly due to lack of @extends attribute. * Add toolbox location and toolbox mode options to playground. * Increase commonality between playgrounds. * Properly deal with shadow statement blocks in stacks. * Localisation updates from https://translatewiki.net. * Use a comment block for function comments in generated JS, Python and Dart. * Fix typo in flyout.js (#403) * Fix typo in flyout.js (#402) * Line wrap comments in generated code. * Remove reference to undefined variable (#413) REASON_MUST_DISCONNECT was removed by a refactor in 2a1ffa1. * Fix airstrike by grabbing the correct toolbox element. (#411) Probably broken in 266e2ffa9a017d21d7ca2f151730d6ecfcecf173. * Localisation updates from https://translatewiki.net. * Fix issue #406 by calling resize from the keypress handler on text inputs. (#408) * Remove shadow blocks from Accessible Blockly demo. Update README. * Generate for loops on one line. * Introduce a common translation pipe; remove local stringMap attributes. Fix variable name error in paste functions. Minor linting. * Fix precedence on isIndex blocks. * Add indexing setting for JavaScript Generation (#419) Adding setting to allow for switching between zero and one based indexing for Blockly Blocks such that the generated code will use this flag to determine whether one based or zero based indexing should be used. One based indexing is enabled by default. * Remove unused functions and dependencies. * Remove the unnecessary construction of new services. * Fix sort block in JS to satisfy tests. * Trigger a contents resize in block's moveBy. (#422) This fixes #420 but and it also fixes some other similar problems with copy/paste and other users of moveBy. * Consolidate the usages of the 'blockly-disabled' label. * Fix error when undoing a shadow block replacement. Issue #415. * Unify setActiveDesc() and updateSelectedNode() in the TreeService. Move function calls made directly within the template to the correct hooks. * Standardize naming of components. * Prevent collisions between user functions and helper functions. * Localisation updates from https://translatewiki.net. * Fix #425. Attash the resize handler to the workspace so it can be removed (#429) when workspace.dispose() is called. * Change the TreeService to a singleton. * Remove unneeded generated parens around function calls in indexOf blocks. * Fix #423 by calling workspace's resize when the flyout reflows. (#430) * Updating URLs to reflect new docs. (#418) * Updating URLs to reflect new docs. Removing -blockly in URLs. * Rebuilt. * Routine recompile * Prevent selected block from ending up underneath a bumped block. * Fix undo on fields with validators with side effects. * Don't fire change event on fields that haven't been named yet. * Localisation updates from https://translatewiki.net. * Fix tree focus issues. * Fix remaining focus issues on block deletion. * cache delete areas instead of recalculating them onMouseDown * Cache screen CTM for performance improvement. * Call svgResizeContents from block_svg's dipose so that deleting blocks (#434) from the context menu (or anywhere really) causes the workspace to recalculate its size. Remove the call to svgResizeContents from onMouseUp's logic for determining whether the block is being dropped in the trash since it calls dispose. One side effect of this is that when you delete multiple blocks resize gets called for each of them and the scrollbars move during the operation. This is most obviously seen by doing an airstrike in the playground and then deleting all the blocks at once. * Allow terminal blocks to replace other terminal blocks (#433) * Allow terminal blocks to replace other terminal blocks * Updated test to allow replacing terminal blocks * Refactor how activeDescendant is set. Introduce helper functions to ensure that calls like pasteAbove() preserve the focus. * Localisation updates from https://translatewiki.net. * Remove unnecessary logging. * Reduce unneeded parentheses in JS and Python. * Start using field_number. * Make it easy to disable unconnected blocks. * Routine recompile. * Check if matrix is null in mouseToSvg * Remove js/ localizations pre-merge * Fix change to block_render_svg * Fix error in xml.js * Playground merge * Add simple toolboxes to playgrounds * Fix flyout reference in events listener * Move tokenizeIntepolation into Blockly.utils namespace. * Use simpler message interpolation in Code demo. * Create console stub for IE 9. * Don't output blockId if not set (e.g., toolbox category event). (#443) * Fix block in multi-playground * Increase commonality between playgrounds. # Conflicts: # tests/multi_playground.html # tests/playground.html * Remove "show flyouts" button * Recompile for merge June 22
2016-06-22 17:50:16 -04:00
var selected = Blockly.selected == rootBlock;
selected || rootBlock.addSelect();
var dx = (staticConnection.x_ + Blockly.SNAP_RADIUS) - this.x_;
var dy = (staticConnection.y_ + Blockly.SNAP_RADIUS) - this.y_;
if (reverse) {
// When reversing a bump due to an uneditable block, bump up.
dy = -dy;
}
if (rootBlock.RTL) {
dx = -dx;
}
rootBlock.moveBy(dx, dy);
selected || rootBlock.removeSelect();
};
/**
* Change the connection's coordinates.
* @param {number} x New absolute x coordinate.
* @param {number} y New absolute y coordinate.
*/
Blockly.RenderedConnection.prototype.moveTo = function(x, y) {
// Remove it from its old location in the database (if already present)
if (this.inDB_) {
this.db_.removeConnection_(this);
}
this.x_ = x;
this.y_ = y;
// Insert it into its new location in the database.
if (!this.hidden_) {
this.db_.addConnection(this);
}
};
/**
* Change the connection's coordinates.
* @param {number} dx Change to x coordinate.
* @param {number} dy Change to y coordinate.
*/
Blockly.RenderedConnection.prototype.moveBy = function(dx, dy) {
this.moveTo(this.x_ + dx, this.y_ + dy);
};
/**
* Move this connection to the location given by its offset within the block and
* the coordinate of the block's top left corner.
2016-06-01 15:31:43 -07:00
* @param {!goog.math.Coordinate} blockTL The coordinate of the top left corner
* of the block.
*/
Blockly.RenderedConnection.prototype.moveToOffset = function(blockTL) {
this.moveTo(blockTL.x + this.offsetInBlock_.x,
blockTL.y + this.offsetInBlock_.y);
};
/**
* Set the offset of this connection relative to the top left of its block.
* @param {number} x The new relative x.
* @param {number} y The new relative y.
*/
Blockly.RenderedConnection.prototype.setOffsetInBlock = function(x, y) {
this.offsetInBlock_.x = x;
this.offsetInBlock_.y = y;
};
/**
* Move the blocks on either side of this connection right next to each other.
* @private
*/
Blockly.RenderedConnection.prototype.tighten_ = function() {
var dx = this.targetConnection.x_ - this.x_;
var dy = this.targetConnection.y_ - this.y_;
if (dx != 0 || dy != 0) {
var block = this.targetBlock();
var svgRoot = block.getSvgRoot();
if (!svgRoot) {
throw 'block is not rendered.';
}
var xy = Blockly.utils.getRelativeXY(svgRoot);
block.getSvgRoot().setAttribute('transform',
'translate(' + (xy.x - dx) + ',' + (xy.y - dy) + ')');
block.moveConnections_(-dx, -dy);
}
};
/**
* Find the closest compatible connection to this connection.
* @param {number} maxLimit The maximum radius to another connection.
2016-05-13 11:35:12 -07:00
* @param {!goog.math.Coordinate} dxy Offset between this connection's location
* in the database and the current location (as a result of dragging).
* @return {!{connection: ?Blockly.Connection, radius: number}} Contains two
2016-05-10 16:36:40 -07:00
* properties: 'connection' which is either another connection or null,
* and 'radius' which is the distance.
*/
2016-05-13 11:35:12 -07:00
Blockly.RenderedConnection.prototype.closest = function(maxLimit, dxy) {
return this.dbOpposite_.searchForClosest(this, maxLimit, dxy);
};
/**
* Add highlighting around this connection.
*/
Blockly.RenderedConnection.prototype.highlight = function() {
var steps;
Vertical shapes pass (#362) * Add if, if-else, equals; remove old if-elses * Naming fixes and removal of a dummy input for if-else * Fix spacing constants; add correct notches. * Fixing inner notches and connections on vertical statements * Fix size of extra row after last statement input * Add minimum block width * Vertical hat shape to spec * Larger vertical minimum block width * Remove INLINE_PADDING_Y and increase MIN_BLOCK_X INLINE_PADDING_Y, a fixed padding for the internal inputs, shouldn't be necessary in Scratch Blocks. Instead, we'll attempt to center the inputs vertically, and give a padding eventually not for inline inputs but rather for non-shadow blocks in inputs... * Remove code for horizontal puzzle tabs * Remove code for "external naked fields" * Start hats are always on in Scratch Blocks * Update vertical playground to start at 75% * Vertical field alignment in vertical rendering * Increase size of vertical green flag icon * Minimum width for blocks with C- or E-. * Remove unused field alignment code * Fix up inner spacing on statement input * Fix overhang to avoid clobbering height calculation * Subtract correct height in getHeightWidth * Subtract notch height in drawing statement bay * Add MIN_STATEMENT_INPUT_HEIGHT * Update size of extra row after statement input * Don't add extra pixel on statement input connection * Fix psuedo-height for blocks with no next connection * Rows after a statement input take the same size as EXTRA_STATEMENT_ROW_Y * Simplify height management to never include notches * Consolidate inputRows.rightEdge calculation * Clean up tab removal * Fix domToWorkspace in vertical_playground.html * Render constant newlines * Updating NOTCH_LEFT_PADDING to NOTCH_START_PADDING * Update comments about vertical field centering; spacing * Remove old comment about baseline * Simplify logic for positioning inline inputs * Ensure inputs in the first row don't overlap with notch
2016-05-27 13:21:40 -04:00
steps = 'm -20,0 h 5 ' + Blockly.BlockSvg.NOTCH_PATH_LEFT + ' h 5';
var xy = this.sourceBlock_.getRelativeToSurfaceXY();
var x = this.x_ - xy.x;
var y = this.y_ - xy.y;
Blockly.Connection.highlightedPath_ = Blockly.utils.createSvgElement('path',
{'class': 'blocklyHighlightedConnectionPath',
'd': steps,
transform: 'translate(' + x + ',' + y + ')' +
(this.sourceBlock_.RTL ? ' scale(-1 1)' : '')},
this.sourceBlock_.getSvgRoot());
};
/**
* Unhide this connection, as well as all down-stream connections on any block
* attached to this connection. This happens when a block is expanded.
* Also unhides down-stream comments.
* @return {!Array.<!Blockly.Block>} List of blocks to render.
*/
Blockly.RenderedConnection.prototype.unhideAll = function() {
this.setHidden(false);
// All blocks that need unhiding must be unhidden before any rendering takes
// place, since rendering requires knowing the dimensions of lower blocks.
// Also, since rendering a block renders all its parents, we only need to
// render the leaf nodes.
var renderList = [];
if (this.type != Blockly.INPUT_VALUE && this.type != Blockly.NEXT_STATEMENT) {
// Only spider down.
return renderList;
}
var block = this.targetBlock();
if (block) {
var connections;
if (block.isCollapsed()) {
// This block should only be partially revealed since it is collapsed.
connections = [];
block.outputConnection && connections.push(block.outputConnection);
block.nextConnection && connections.push(block.nextConnection);
block.previousConnection && connections.push(block.previousConnection);
} else {
// Show all connections of this block.
connections = block.getConnections_(true);
}
Adding indexing settings, tests and fixing bugs (#464) * Add indexing setting for JavaScript Generation Adding setting to allow for switching between zero and one based indexing for Blockly Blocks such that the generated code will use this flag to determine whether one based or zero based indexing should be used. One based indexing is enabled by default. * Updating js lists to do zero and one based index Updated generated JavaScript to change depending on whether one based indexing is enabled or not. * Updating js text to do zero and one based index Change so that JavaScript generated for text blocks either assumes blocks use zero or one based index based on setting. * Start of python indexing Start of work on allowing one and zero indexing for generated python for lists. * Fixing bug and lint fixed Fixing bug caused by not setting the return of concat when concatenating lines for sublist and substring functions. Also renamed these functions to be getSubsequece. Fixed lint errors with spacing * Converting from if to switch statements Comverting if statements to switch statements when appropriate and adding spacing. * Modified sublist JavaScript generation Added case so that helper function is not generated if not necessary. Helper function is not generated if list length is not needed or if list is a simple block (such as a variable, as oppossed to a function call or list create). * Stripping unecessary ids Removing ids from xml file. * Localisation updates from https://translatewiki.net. * Fix typo in flyout.js (#403) * Fix typo in flyout.js (#402) * Localisation updates from https://translatewiki.net. * Add indexing setting for JavaScript Generation Adding setting to allow for switching between zero and one based indexing for Blockly Blocks such that the generated code will use this flag to determine whether one based or zero based indexing should be used. One based indexing is enabled by default. * Updating js lists to do zero and one based index Updated generated JavaScript to change depending on whether one based indexing is enabled or not. * Updating js text to do zero and one based index Change so that JavaScript generated for text blocks either assumes blocks use zero or one based index based on setting. * Fixing bug and lint fixed Fixing bug caused by not setting the return of concat when concatenating lines for sublist and substring functions. Also renamed these functions to be getSubsequece. Fixed lint errors with spacing * Converting from if to switch statements Comverting if statements to switch statements when appropriate and adding spacing. * Modified sublist JavaScript generation Added case so that helper function is not generated if not necessary. Helper function is not generated if list length is not needed or if list is a simple block (such as a variable, as oppossed to a function call or list create). * Stripping unecessary ids Removing ids from xml file. * Updating generator test Modifying sublist test and re-formatting spacing between blocks. * Updating js lists to do zero and one based index Updated generated JavaScript to change depending on whether one based indexing is enabled or not. * Updating js text to do zero and one based index Change so that JavaScript generated for text blocks either assumes blocks use zero or one based index based on setting. * Fixing bug and lint fixed Fixing bug caused by not setting the return of concat when concatenating lines for sublist and substring functions. Also renamed these functions to be getSubsequece. Fixed lint errors with spacing * Converting from if to switch statements Comverting if statements to switch statements when appropriate and adding spacing. * Modified sublist JavaScript generation Added case so that helper function is not generated if not necessary. Helper function is not generated if list length is not needed or if list is a simple block (such as a variable, as oppossed to a function call or list create). * Stripping unecessary ids Removing ids from xml file. * Localisation updates from https://translatewiki.net. * Localisation updates from https://translatewiki.net. * Updating js lists to do zero and one based index Updated generated JavaScript to change depending on whether one based indexing is enabled or not. * Fixing bug and lint fixed Fixing bug caused by not setting the return of concat when concatenating lines for sublist and substring functions. Also renamed these functions to be getSubsequece. Fixed lint errors with spacing * Modified sublist JavaScript generation Added case so that helper function is not generated if not necessary. Helper function is not generated if list length is not needed or if list is a simple block (such as a variable, as oppossed to a function call or list create). * Stripping unecessary ids Removing ids from xml file. * Updating generator test Modifying sublist test and re-formatting spacing between blocks. * Adding tests for indexing and extra cases Adding tests for indexing with custom block to adjust number based on what indexing is being generated. * Adding tests and renaming tests Adding tests for sublist and renaming tests. * Fixes for order for sublists Fixes so that parenthesis are generated properly for index for sublist * Cleaning up test generated code Changing order returned for unit test adjust index function to generate less unecessary parenthesis. * Adding tests for order Adding tests for order, relevant for methods that use index from start (because 1 is added) * Fixing JS order for getIndex and setIndex Changing to the correct order type when calling valueToCode in JS generation for getIndex and setIndex. * Fixed unittest adjustIndex Fixed uninttest adjustindex to also check whether the ONE_BASED_INDEXING variable has been defined to ensure proper behaviour. * Fixing lint and formatting for JS/lists Making line fixes and changing an if/elseif to case statement. * Tests added to include case for bug found Added tests with sublist combinations of different where's for the two indices after bug for this found in python. * Adding and renaming tests Adding test case for creating a sublist that encompasses the whole list but uses # and #-end instead of first last (applicable for python). Also, renaming tests. * Adding contant and fixing python lists bugs Adding contant for ONE_BASED_INDEXING and fixing bugs in python for lists. * Fixing test get random Fixing test get random to take into account indexing for return value. * Adding indexing checkbox to test page Adding checkbos on test page so that code can be generated for one and zero based indexing. Languages that are generated with zero based indexing that do not have it implemented will fail tests as expected. * Fixing unittest getremove random Fixing unittest getremove random to take into account the return value based on indexing. * Change comparison for getremove random test Fixed comparison to equal for the return value for getremove random. * Fixing bugs with lists zero-indexing Fixing getIndex and getSublist methods to pass for zero-indexed tests. * Adding test cases and formatting Adding test cases to text tests, reordering a couple list test, and formatting block spacing. * Fixing unittest expected value Fixing expected value fore unit tests for sublist. * Cleanup Removing obvious comments, formatting fixes, and naming in generated code in JS. * Helper function for Python lists Adding helper function for casting to int for indices. * Expanding helper to reduce duplicated code Expanding helper method to also get the property with the correct order and check indexing to reduce duplicated code. * Cleaning up JS indexing with helper function Adding helper function for indexing and used it in lists and text. * Moving helper function and formatting fixes Moving helper function, formatting fixes, and changing some generated code variable names. * Fixing python generation for text Fixing all failinng tests for python and using new helper method. * Lint fixes and order in indexOf Making lint fixes and correcting returned order in indexOf. * Python variable renaming Renaming a few generated variables. * Fixing comment and order Fixing comment to list Blockly.Block type and fixing order because it could be higher. * Switching back to if Switching switch back to if statements because there weren't enough cases to warrant for a switch. * Adding order and fixing lists for Dart Adding if null operator to operator precedence for Dart. Also, fixing lists implementation to pass unit tests and adding zero-indexing functionality. * Formatting and lint fixes Formatting and lint fixes * Dart text fixed Fixing Dart text generation to pass unit tests. * Changing back to variable Changing switch condition back to variable. * Fixing ORDER_OVERRIDES Inner and outer order was switched . * Adding bug with order caused by generator change Flooring order before comparision because of how the order constants were modified. * Adding list tests Adding tests for additional cases for lists/ * Adding comment for dart order Adding comment for Dart ORDER_IF_NULL operator. * Formatting fixes Formatting fixes for line indentation. * Fixing PHP order and lists generation Fixing PHP order constants and fixing lists so that they pass unit tests. * Fixing tests Removing duplicate unit test * Adding text tests Adding tests for text. * Renaming variable and removing unused variable Renaming variables from exceptionIndex to errorIndex and removing unused at variable. * Adding missing function call to test Adding missing funciton call to test that was causing tests to fail when they shouldn't. * Fixing PHP text generation Fixing PHP text code generation so it passes unit tests. * Formatting fixes Cleaning up code, renamiing a variable. * Fixing failing subsequence tests Fixing JS code that failed for sublist/substring tests. * Fixing intentation Fixing indentation. * Fixing Dart sublist/substring Fixing sublist/substring to include condiiton where FROM_START (and not throw error by mistake) when zero-indexed. * Adding order subtraction test Adding test for checking order for subtraction x- (y - z) x - (y + z). * Updating to new PHP power operator Updating from pow function to ** operator to clean up code. * Updating to new removeWhere Updating removeMatching to removeWhere because new version of Dart now use removeWhere. * Fix for lua rounding assertequals Adding check for number in equlity check for comparing number for floats. * Adding test for copy of list Adding test that checks the list is copied when a sublist is made first-last. * Formatting and order fixes Fixing formatting such as indentation and order fixes. * Adding comment for clarity Adding comment about how Lua code generation is not supporting zero indexing. * Changed variable names in code Changed variable names to follow style guide and changed for loop variable from n to i as is typical. * Reducing unecessarily generated functions and renaming variables Reducing number of generated functions using gensym_ by adding parameters to provided function. Renaming variables to make functions more readble. * Fixing sublist order and sort variable Fixing order used for valueToCode for sublist and renaming list variable in sort to match rest of code.. * Fixing order constant order Removing operator () that was incorrect and addiung ~, * Fixing order and indentation Fixing order return fro create lists blocks and fixing indentationn for string array. * Fixing order and renaming variables Fixing order to be the correct strength and renaming variables to be more readable/ * Changing assert blocks for unit tests Changing assert blocks to have a value input instead of a field so there is more flexibility in writing tests. * Cleaning up and adding missing order tests Adding tests for order for paramters for list blocks that weren't being tested to uncover bugs. Test were also cleaned up/reorganized/renamed to be more readable and shorter vertically (but lines wider horizontally). * Compile error fix and order in Dart generation. Fixing compile error in generated code and incorrect order in get sublist for Dart. * Fixing typo in getIndex and invalid parameter name Fixing type in getIndex where list code should have been appended but instead an undefined variable was added. The parameter in lists_sort was changed to my_list because list is a reserved word in python. * Fixing order, parenthesis bug, and variable declaration in Lua Fixing incorrect order in Lua. Fixing bug caused by missing parenthesis around ternary operator in code. Variable code was declared with JavaScript syntax, this was fixed to be valid in Lua. * Adding tests and formatting tests Adding missing test for order in text/lists. Changing spacing/order of tests and updating comments. * Fixing error in code Changing to correct function call in empy tests and changing test name that was duplicated to be more clear. * Renamed test helper function * Fixing order and renaming variable in JS generator Fixing order for charAt and renaming variable in code list_sort from listCode to list to be consistent with rest of code. * Fixing order for dart text Fixing roder for dart charAt * Cleaning up generated code for Dart getIndex Cleaning up generated code for Dart getIndex so that helper functions aren't generated unecessarily and adding comments. * Fixing Dart remove random error Fixing error caused by remove random implementation in Dart. index should have been x but instead was length - x. * Fixing unit test blocks Fixing Lua unit test block that should have just returned the number and removing unecessary checks in other blocks because the constant was defined. * Fixing Lua assert equals block string.format was throwing an error if one of the values happened to be a boolean. * Adding tests for create text with number Adding test for create text with numbers as parameters * Fixing lua unit test block Lua unit test block should have added 1 * Removing indexing setting for Lua tests Removing setting index setting for Lua generation because it is always one-indexed. * Fixing order and create text Fixing failing test caused by improper order and fixed create text to properly convert to string when there is one element. * Running linter on generator code Running linter on generator code and fixing spacing/indentation problems. * Editing comments and removing uneeded parenthesis Editing and adding comments and removing uneeded parenthesis around ternary operator condition. * Fixing order and changing variable names Fixing orders that were incorrect and changing variable names to be more descriptive and consistent across code. * Adding comment about list support and fixes for PHP Adding comment about how lists are not fully supported for PHP. Adding missing order to PHP and fixing order errors throughout. Fixing regex for variable matching in lists. Cleaning up variable names to be more readable and consistent with other parts of code. * Reducing complexity for getremove/remove in JS Reducing complexity in generated code for getremove/remove in JavaScript by replacing unecessary helper function. * Fixing spacing before inline comments Ensuring there are two spaces before inline comments. * Changing JS list copy for clarity Changing JavaScript list copy to use slice(0) instead of concat for clarity and to use the same pattern as the other sublist methods. * Changing generated variable name tmp_x Changing tmp_x to tmpX to follow closer to the correct style for JavaScript. * Prefixing empy lines between comment text Prior to this change, comments with an empty line between text did not have a comment prefix before it, resulting in comment blocks that seemed disjoined although they were for the same block. This change affects how the prefix line function works so that those lines will have the prefix (if applicable) while still taking into account the trailing newline character. * Changing for loops variable names Changing most for loops to use i as the variable name (or j if applicable) or changing name to be more readable. * Simplifying provided subsequence function Simplifying subsequence function to generate a simpler function depending on where combination instead of a larger complex function that works for all where combinations. * Style fixes Fixing indentation, comments, and other formatting-type changes based on pull request comments. * Fixing indentation Fixing indentation and removing an extra newline. * Fixing PHP mode implementation Fixing PHP mode implementation to properlyu return multiple modes if applicable. * Fixing line too long Wrapping lines in php/math.js with lines longer than 80 characters. * Wrapping long lines Wrapping lines that are too long. * Changing boolean casing Changing boolean casing to be lowercase.
2016-07-08 11:43:48 -07:00
for (var i = 0; i < connections.length; i++) {
renderList.push.apply(renderList, connections[i].unhideAll());
}
if (!renderList.length) {
// Leaf block.
renderList[0] = block;
}
}
return renderList;
};
/**
* Remove the highlighting around this connection.
*/
Blockly.RenderedConnection.prototype.unhighlight = function() {
goog.dom.removeNode(Blockly.Connection.highlightedPath_);
delete Blockly.Connection.highlightedPath_;
};
/**
* Set whether this connections is hidden (not tracked in a database) or not.
* @param {boolean} hidden True if connection is hidden.
*/
Blockly.RenderedConnection.prototype.setHidden = function(hidden) {
this.hidden_ = hidden;
if (hidden && this.inDB_) {
this.db_.removeConnection_(this);
} else if (!hidden && !this.inDB_) {
this.db_.addConnection(this);
}
};
/**
* Hide this connection, as well as all down-stream connections on any block
* attached to this connection. This happens when a block is collapsed.
* Also hides down-stream comments.
*/
Blockly.RenderedConnection.prototype.hideAll = function() {
this.setHidden(true);
if (this.targetConnection) {
var blocks = this.targetBlock().getDescendants();
Adding indexing settings, tests and fixing bugs (#464) * Add indexing setting for JavaScript Generation Adding setting to allow for switching between zero and one based indexing for Blockly Blocks such that the generated code will use this flag to determine whether one based or zero based indexing should be used. One based indexing is enabled by default. * Updating js lists to do zero and one based index Updated generated JavaScript to change depending on whether one based indexing is enabled or not. * Updating js text to do zero and one based index Change so that JavaScript generated for text blocks either assumes blocks use zero or one based index based on setting. * Start of python indexing Start of work on allowing one and zero indexing for generated python for lists. * Fixing bug and lint fixed Fixing bug caused by not setting the return of concat when concatenating lines for sublist and substring functions. Also renamed these functions to be getSubsequece. Fixed lint errors with spacing * Converting from if to switch statements Comverting if statements to switch statements when appropriate and adding spacing. * Modified sublist JavaScript generation Added case so that helper function is not generated if not necessary. Helper function is not generated if list length is not needed or if list is a simple block (such as a variable, as oppossed to a function call or list create). * Stripping unecessary ids Removing ids from xml file. * Localisation updates from https://translatewiki.net. * Fix typo in flyout.js (#403) * Fix typo in flyout.js (#402) * Localisation updates from https://translatewiki.net. * Add indexing setting for JavaScript Generation Adding setting to allow for switching between zero and one based indexing for Blockly Blocks such that the generated code will use this flag to determine whether one based or zero based indexing should be used. One based indexing is enabled by default. * Updating js lists to do zero and one based index Updated generated JavaScript to change depending on whether one based indexing is enabled or not. * Updating js text to do zero and one based index Change so that JavaScript generated for text blocks either assumes blocks use zero or one based index based on setting. * Fixing bug and lint fixed Fixing bug caused by not setting the return of concat when concatenating lines for sublist and substring functions. Also renamed these functions to be getSubsequece. Fixed lint errors with spacing * Converting from if to switch statements Comverting if statements to switch statements when appropriate and adding spacing. * Modified sublist JavaScript generation Added case so that helper function is not generated if not necessary. Helper function is not generated if list length is not needed or if list is a simple block (such as a variable, as oppossed to a function call or list create). * Stripping unecessary ids Removing ids from xml file. * Updating generator test Modifying sublist test and re-formatting spacing between blocks. * Updating js lists to do zero and one based index Updated generated JavaScript to change depending on whether one based indexing is enabled or not. * Updating js text to do zero and one based index Change so that JavaScript generated for text blocks either assumes blocks use zero or one based index based on setting. * Fixing bug and lint fixed Fixing bug caused by not setting the return of concat when concatenating lines for sublist and substring functions. Also renamed these functions to be getSubsequece. Fixed lint errors with spacing * Converting from if to switch statements Comverting if statements to switch statements when appropriate and adding spacing. * Modified sublist JavaScript generation Added case so that helper function is not generated if not necessary. Helper function is not generated if list length is not needed or if list is a simple block (such as a variable, as oppossed to a function call or list create). * Stripping unecessary ids Removing ids from xml file. * Localisation updates from https://translatewiki.net. * Localisation updates from https://translatewiki.net. * Updating js lists to do zero and one based index Updated generated JavaScript to change depending on whether one based indexing is enabled or not. * Fixing bug and lint fixed Fixing bug caused by not setting the return of concat when concatenating lines for sublist and substring functions. Also renamed these functions to be getSubsequece. Fixed lint errors with spacing * Modified sublist JavaScript generation Added case so that helper function is not generated if not necessary. Helper function is not generated if list length is not needed or if list is a simple block (such as a variable, as oppossed to a function call or list create). * Stripping unecessary ids Removing ids from xml file. * Updating generator test Modifying sublist test and re-formatting spacing between blocks. * Adding tests for indexing and extra cases Adding tests for indexing with custom block to adjust number based on what indexing is being generated. * Adding tests and renaming tests Adding tests for sublist and renaming tests. * Fixes for order for sublists Fixes so that parenthesis are generated properly for index for sublist * Cleaning up test generated code Changing order returned for unit test adjust index function to generate less unecessary parenthesis. * Adding tests for order Adding tests for order, relevant for methods that use index from start (because 1 is added) * Fixing JS order for getIndex and setIndex Changing to the correct order type when calling valueToCode in JS generation for getIndex and setIndex. * Fixed unittest adjustIndex Fixed uninttest adjustindex to also check whether the ONE_BASED_INDEXING variable has been defined to ensure proper behaviour. * Fixing lint and formatting for JS/lists Making line fixes and changing an if/elseif to case statement. * Tests added to include case for bug found Added tests with sublist combinations of different where's for the two indices after bug for this found in python. * Adding and renaming tests Adding test case for creating a sublist that encompasses the whole list but uses # and #-end instead of first last (applicable for python). Also, renaming tests. * Adding contant and fixing python lists bugs Adding contant for ONE_BASED_INDEXING and fixing bugs in python for lists. * Fixing test get random Fixing test get random to take into account indexing for return value. * Adding indexing checkbox to test page Adding checkbos on test page so that code can be generated for one and zero based indexing. Languages that are generated with zero based indexing that do not have it implemented will fail tests as expected. * Fixing unittest getremove random Fixing unittest getremove random to take into account the return value based on indexing. * Change comparison for getremove random test Fixed comparison to equal for the return value for getremove random. * Fixing bugs with lists zero-indexing Fixing getIndex and getSublist methods to pass for zero-indexed tests. * Adding test cases and formatting Adding test cases to text tests, reordering a couple list test, and formatting block spacing. * Fixing unittest expected value Fixing expected value fore unit tests for sublist. * Cleanup Removing obvious comments, formatting fixes, and naming in generated code in JS. * Helper function for Python lists Adding helper function for casting to int for indices. * Expanding helper to reduce duplicated code Expanding helper method to also get the property with the correct order and check indexing to reduce duplicated code. * Cleaning up JS indexing with helper function Adding helper function for indexing and used it in lists and text. * Moving helper function and formatting fixes Moving helper function, formatting fixes, and changing some generated code variable names. * Fixing python generation for text Fixing all failinng tests for python and using new helper method. * Lint fixes and order in indexOf Making lint fixes and correcting returned order in indexOf. * Python variable renaming Renaming a few generated variables. * Fixing comment and order Fixing comment to list Blockly.Block type and fixing order because it could be higher. * Switching back to if Switching switch back to if statements because there weren't enough cases to warrant for a switch. * Adding order and fixing lists for Dart Adding if null operator to operator precedence for Dart. Also, fixing lists implementation to pass unit tests and adding zero-indexing functionality. * Formatting and lint fixes Formatting and lint fixes * Dart text fixed Fixing Dart text generation to pass unit tests. * Changing back to variable Changing switch condition back to variable. * Fixing ORDER_OVERRIDES Inner and outer order was switched . * Adding bug with order caused by generator change Flooring order before comparision because of how the order constants were modified. * Adding list tests Adding tests for additional cases for lists/ * Adding comment for dart order Adding comment for Dart ORDER_IF_NULL operator. * Formatting fixes Formatting fixes for line indentation. * Fixing PHP order and lists generation Fixing PHP order constants and fixing lists so that they pass unit tests. * Fixing tests Removing duplicate unit test * Adding text tests Adding tests for text. * Renaming variable and removing unused variable Renaming variables from exceptionIndex to errorIndex and removing unused at variable. * Adding missing function call to test Adding missing funciton call to test that was causing tests to fail when they shouldn't. * Fixing PHP text generation Fixing PHP text code generation so it passes unit tests. * Formatting fixes Cleaning up code, renamiing a variable. * Fixing failing subsequence tests Fixing JS code that failed for sublist/substring tests. * Fixing intentation Fixing indentation. * Fixing Dart sublist/substring Fixing sublist/substring to include condiiton where FROM_START (and not throw error by mistake) when zero-indexed. * Adding order subtraction test Adding test for checking order for subtraction x- (y - z) x - (y + z). * Updating to new PHP power operator Updating from pow function to ** operator to clean up code. * Updating to new removeWhere Updating removeMatching to removeWhere because new version of Dart now use removeWhere. * Fix for lua rounding assertequals Adding check for number in equlity check for comparing number for floats. * Adding test for copy of list Adding test that checks the list is copied when a sublist is made first-last. * Formatting and order fixes Fixing formatting such as indentation and order fixes. * Adding comment for clarity Adding comment about how Lua code generation is not supporting zero indexing. * Changed variable names in code Changed variable names to follow style guide and changed for loop variable from n to i as is typical. * Reducing unecessarily generated functions and renaming variables Reducing number of generated functions using gensym_ by adding parameters to provided function. Renaming variables to make functions more readble. * Fixing sublist order and sort variable Fixing order used for valueToCode for sublist and renaming list variable in sort to match rest of code.. * Fixing order constant order Removing operator () that was incorrect and addiung ~, * Fixing order and indentation Fixing order return fro create lists blocks and fixing indentationn for string array. * Fixing order and renaming variables Fixing order to be the correct strength and renaming variables to be more readable/ * Changing assert blocks for unit tests Changing assert blocks to have a value input instead of a field so there is more flexibility in writing tests. * Cleaning up and adding missing order tests Adding tests for order for paramters for list blocks that weren't being tested to uncover bugs. Test were also cleaned up/reorganized/renamed to be more readable and shorter vertically (but lines wider horizontally). * Compile error fix and order in Dart generation. Fixing compile error in generated code and incorrect order in get sublist for Dart. * Fixing typo in getIndex and invalid parameter name Fixing type in getIndex where list code should have been appended but instead an undefined variable was added. The parameter in lists_sort was changed to my_list because list is a reserved word in python. * Fixing order, parenthesis bug, and variable declaration in Lua Fixing incorrect order in Lua. Fixing bug caused by missing parenthesis around ternary operator in code. Variable code was declared with JavaScript syntax, this was fixed to be valid in Lua. * Adding tests and formatting tests Adding missing test for order in text/lists. Changing spacing/order of tests and updating comments. * Fixing error in code Changing to correct function call in empy tests and changing test name that was duplicated to be more clear. * Renamed test helper function * Fixing order and renaming variable in JS generator Fixing order for charAt and renaming variable in code list_sort from listCode to list to be consistent with rest of code. * Fixing order for dart text Fixing roder for dart charAt * Cleaning up generated code for Dart getIndex Cleaning up generated code for Dart getIndex so that helper functions aren't generated unecessarily and adding comments. * Fixing Dart remove random error Fixing error caused by remove random implementation in Dart. index should have been x but instead was length - x. * Fixing unit test blocks Fixing Lua unit test block that should have just returned the number and removing unecessary checks in other blocks because the constant was defined. * Fixing Lua assert equals block string.format was throwing an error if one of the values happened to be a boolean. * Adding tests for create text with number Adding test for create text with numbers as parameters * Fixing lua unit test block Lua unit test block should have added 1 * Removing indexing setting for Lua tests Removing setting index setting for Lua generation because it is always one-indexed. * Fixing order and create text Fixing failing test caused by improper order and fixed create text to properly convert to string when there is one element. * Running linter on generator code Running linter on generator code and fixing spacing/indentation problems. * Editing comments and removing uneeded parenthesis Editing and adding comments and removing uneeded parenthesis around ternary operator condition. * Fixing order and changing variable names Fixing orders that were incorrect and changing variable names to be more descriptive and consistent across code. * Adding comment about list support and fixes for PHP Adding comment about how lists are not fully supported for PHP. Adding missing order to PHP and fixing order errors throughout. Fixing regex for variable matching in lists. Cleaning up variable names to be more readable and consistent with other parts of code. * Reducing complexity for getremove/remove in JS Reducing complexity in generated code for getremove/remove in JavaScript by replacing unecessary helper function. * Fixing spacing before inline comments Ensuring there are two spaces before inline comments. * Changing JS list copy for clarity Changing JavaScript list copy to use slice(0) instead of concat for clarity and to use the same pattern as the other sublist methods. * Changing generated variable name tmp_x Changing tmp_x to tmpX to follow closer to the correct style for JavaScript. * Prefixing empy lines between comment text Prior to this change, comments with an empty line between text did not have a comment prefix before it, resulting in comment blocks that seemed disjoined although they were for the same block. This change affects how the prefix line function works so that those lines will have the prefix (if applicable) while still taking into account the trailing newline character. * Changing for loops variable names Changing most for loops to use i as the variable name (or j if applicable) or changing name to be more readable. * Simplifying provided subsequence function Simplifying subsequence function to generate a simpler function depending on where combination instead of a larger complex function that works for all where combinations. * Style fixes Fixing indentation, comments, and other formatting-type changes based on pull request comments. * Fixing indentation Fixing indentation and removing an extra newline. * Fixing PHP mode implementation Fixing PHP mode implementation to properlyu return multiple modes if applicable. * Fixing line too long Wrapping lines in php/math.js with lines longer than 80 characters. * Wrapping long lines Wrapping lines that are too long. * Changing boolean casing Changing boolean casing to be lowercase.
2016-07-08 11:43:48 -07:00
for (var i = 0; i < blocks.length; i++) {
var block = blocks[i];
// Hide all connections of all children.
var connections = block.getConnections_(true);
Adding indexing settings, tests and fixing bugs (#464) * Add indexing setting for JavaScript Generation Adding setting to allow for switching between zero and one based indexing for Blockly Blocks such that the generated code will use this flag to determine whether one based or zero based indexing should be used. One based indexing is enabled by default. * Updating js lists to do zero and one based index Updated generated JavaScript to change depending on whether one based indexing is enabled or not. * Updating js text to do zero and one based index Change so that JavaScript generated for text blocks either assumes blocks use zero or one based index based on setting. * Start of python indexing Start of work on allowing one and zero indexing for generated python for lists. * Fixing bug and lint fixed Fixing bug caused by not setting the return of concat when concatenating lines for sublist and substring functions. Also renamed these functions to be getSubsequece. Fixed lint errors with spacing * Converting from if to switch statements Comverting if statements to switch statements when appropriate and adding spacing. * Modified sublist JavaScript generation Added case so that helper function is not generated if not necessary. Helper function is not generated if list length is not needed or if list is a simple block (such as a variable, as oppossed to a function call or list create). * Stripping unecessary ids Removing ids from xml file. * Localisation updates from https://translatewiki.net. * Fix typo in flyout.js (#403) * Fix typo in flyout.js (#402) * Localisation updates from https://translatewiki.net. * Add indexing setting for JavaScript Generation Adding setting to allow for switching between zero and one based indexing for Blockly Blocks such that the generated code will use this flag to determine whether one based or zero based indexing should be used. One based indexing is enabled by default. * Updating js lists to do zero and one based index Updated generated JavaScript to change depending on whether one based indexing is enabled or not. * Updating js text to do zero and one based index Change so that JavaScript generated for text blocks either assumes blocks use zero or one based index based on setting. * Fixing bug and lint fixed Fixing bug caused by not setting the return of concat when concatenating lines for sublist and substring functions. Also renamed these functions to be getSubsequece. Fixed lint errors with spacing * Converting from if to switch statements Comverting if statements to switch statements when appropriate and adding spacing. * Modified sublist JavaScript generation Added case so that helper function is not generated if not necessary. Helper function is not generated if list length is not needed or if list is a simple block (such as a variable, as oppossed to a function call or list create). * Stripping unecessary ids Removing ids from xml file. * Updating generator test Modifying sublist test and re-formatting spacing between blocks. * Updating js lists to do zero and one based index Updated generated JavaScript to change depending on whether one based indexing is enabled or not. * Updating js text to do zero and one based index Change so that JavaScript generated for text blocks either assumes blocks use zero or one based index based on setting. * Fixing bug and lint fixed Fixing bug caused by not setting the return of concat when concatenating lines for sublist and substring functions. Also renamed these functions to be getSubsequece. Fixed lint errors with spacing * Converting from if to switch statements Comverting if statements to switch statements when appropriate and adding spacing. * Modified sublist JavaScript generation Added case so that helper function is not generated if not necessary. Helper function is not generated if list length is not needed or if list is a simple block (such as a variable, as oppossed to a function call or list create). * Stripping unecessary ids Removing ids from xml file. * Localisation updates from https://translatewiki.net. * Localisation updates from https://translatewiki.net. * Updating js lists to do zero and one based index Updated generated JavaScript to change depending on whether one based indexing is enabled or not. * Fixing bug and lint fixed Fixing bug caused by not setting the return of concat when concatenating lines for sublist and substring functions. Also renamed these functions to be getSubsequece. Fixed lint errors with spacing * Modified sublist JavaScript generation Added case so that helper function is not generated if not necessary. Helper function is not generated if list length is not needed or if list is a simple block (such as a variable, as oppossed to a function call or list create). * Stripping unecessary ids Removing ids from xml file. * Updating generator test Modifying sublist test and re-formatting spacing between blocks. * Adding tests for indexing and extra cases Adding tests for indexing with custom block to adjust number based on what indexing is being generated. * Adding tests and renaming tests Adding tests for sublist and renaming tests. * Fixes for order for sublists Fixes so that parenthesis are generated properly for index for sublist * Cleaning up test generated code Changing order returned for unit test adjust index function to generate less unecessary parenthesis. * Adding tests for order Adding tests for order, relevant for methods that use index from start (because 1 is added) * Fixing JS order for getIndex and setIndex Changing to the correct order type when calling valueToCode in JS generation for getIndex and setIndex. * Fixed unittest adjustIndex Fixed uninttest adjustindex to also check whether the ONE_BASED_INDEXING variable has been defined to ensure proper behaviour. * Fixing lint and formatting for JS/lists Making line fixes and changing an if/elseif to case statement. * Tests added to include case for bug found Added tests with sublist combinations of different where's for the two indices after bug for this found in python. * Adding and renaming tests Adding test case for creating a sublist that encompasses the whole list but uses # and #-end instead of first last (applicable for python). Also, renaming tests. * Adding contant and fixing python lists bugs Adding contant for ONE_BASED_INDEXING and fixing bugs in python for lists. * Fixing test get random Fixing test get random to take into account indexing for return value. * Adding indexing checkbox to test page Adding checkbos on test page so that code can be generated for one and zero based indexing. Languages that are generated with zero based indexing that do not have it implemented will fail tests as expected. * Fixing unittest getremove random Fixing unittest getremove random to take into account the return value based on indexing. * Change comparison for getremove random test Fixed comparison to equal for the return value for getremove random. * Fixing bugs with lists zero-indexing Fixing getIndex and getSublist methods to pass for zero-indexed tests. * Adding test cases and formatting Adding test cases to text tests, reordering a couple list test, and formatting block spacing. * Fixing unittest expected value Fixing expected value fore unit tests for sublist. * Cleanup Removing obvious comments, formatting fixes, and naming in generated code in JS. * Helper function for Python lists Adding helper function for casting to int for indices. * Expanding helper to reduce duplicated code Expanding helper method to also get the property with the correct order and check indexing to reduce duplicated code. * Cleaning up JS indexing with helper function Adding helper function for indexing and used it in lists and text. * Moving helper function and formatting fixes Moving helper function, formatting fixes, and changing some generated code variable names. * Fixing python generation for text Fixing all failinng tests for python and using new helper method. * Lint fixes and order in indexOf Making lint fixes and correcting returned order in indexOf. * Python variable renaming Renaming a few generated variables. * Fixing comment and order Fixing comment to list Blockly.Block type and fixing order because it could be higher. * Switching back to if Switching switch back to if statements because there weren't enough cases to warrant for a switch. * Adding order and fixing lists for Dart Adding if null operator to operator precedence for Dart. Also, fixing lists implementation to pass unit tests and adding zero-indexing functionality. * Formatting and lint fixes Formatting and lint fixes * Dart text fixed Fixing Dart text generation to pass unit tests. * Changing back to variable Changing switch condition back to variable. * Fixing ORDER_OVERRIDES Inner and outer order was switched . * Adding bug with order caused by generator change Flooring order before comparision because of how the order constants were modified. * Adding list tests Adding tests for additional cases for lists/ * Adding comment for dart order Adding comment for Dart ORDER_IF_NULL operator. * Formatting fixes Formatting fixes for line indentation. * Fixing PHP order and lists generation Fixing PHP order constants and fixing lists so that they pass unit tests. * Fixing tests Removing duplicate unit test * Adding text tests Adding tests for text. * Renaming variable and removing unused variable Renaming variables from exceptionIndex to errorIndex and removing unused at variable. * Adding missing function call to test Adding missing funciton call to test that was causing tests to fail when they shouldn't. * Fixing PHP text generation Fixing PHP text code generation so it passes unit tests. * Formatting fixes Cleaning up code, renamiing a variable. * Fixing failing subsequence tests Fixing JS code that failed for sublist/substring tests. * Fixing intentation Fixing indentation. * Fixing Dart sublist/substring Fixing sublist/substring to include condiiton where FROM_START (and not throw error by mistake) when zero-indexed. * Adding order subtraction test Adding test for checking order for subtraction x- (y - z) x - (y + z). * Updating to new PHP power operator Updating from pow function to ** operator to clean up code. * Updating to new removeWhere Updating removeMatching to removeWhere because new version of Dart now use removeWhere. * Fix for lua rounding assertequals Adding check for number in equlity check for comparing number for floats. * Adding test for copy of list Adding test that checks the list is copied when a sublist is made first-last. * Formatting and order fixes Fixing formatting such as indentation and order fixes. * Adding comment for clarity Adding comment about how Lua code generation is not supporting zero indexing. * Changed variable names in code Changed variable names to follow style guide and changed for loop variable from n to i as is typical. * Reducing unecessarily generated functions and renaming variables Reducing number of generated functions using gensym_ by adding parameters to provided function. Renaming variables to make functions more readble. * Fixing sublist order and sort variable Fixing order used for valueToCode for sublist and renaming list variable in sort to match rest of code.. * Fixing order constant order Removing operator () that was incorrect and addiung ~, * Fixing order and indentation Fixing order return fro create lists blocks and fixing indentationn for string array. * Fixing order and renaming variables Fixing order to be the correct strength and renaming variables to be more readable/ * Changing assert blocks for unit tests Changing assert blocks to have a value input instead of a field so there is more flexibility in writing tests. * Cleaning up and adding missing order tests Adding tests for order for paramters for list blocks that weren't being tested to uncover bugs. Test were also cleaned up/reorganized/renamed to be more readable and shorter vertically (but lines wider horizontally). * Compile error fix and order in Dart generation. Fixing compile error in generated code and incorrect order in get sublist for Dart. * Fixing typo in getIndex and invalid parameter name Fixing type in getIndex where list code should have been appended but instead an undefined variable was added. The parameter in lists_sort was changed to my_list because list is a reserved word in python. * Fixing order, parenthesis bug, and variable declaration in Lua Fixing incorrect order in Lua. Fixing bug caused by missing parenthesis around ternary operator in code. Variable code was declared with JavaScript syntax, this was fixed to be valid in Lua. * Adding tests and formatting tests Adding missing test for order in text/lists. Changing spacing/order of tests and updating comments. * Fixing error in code Changing to correct function call in empy tests and changing test name that was duplicated to be more clear. * Renamed test helper function * Fixing order and renaming variable in JS generator Fixing order for charAt and renaming variable in code list_sort from listCode to list to be consistent with rest of code. * Fixing order for dart text Fixing roder for dart charAt * Cleaning up generated code for Dart getIndex Cleaning up generated code for Dart getIndex so that helper functions aren't generated unecessarily and adding comments. * Fixing Dart remove random error Fixing error caused by remove random implementation in Dart. index should have been x but instead was length - x. * Fixing unit test blocks Fixing Lua unit test block that should have just returned the number and removing unecessary checks in other blocks because the constant was defined. * Fixing Lua assert equals block string.format was throwing an error if one of the values happened to be a boolean. * Adding tests for create text with number Adding test for create text with numbers as parameters * Fixing lua unit test block Lua unit test block should have added 1 * Removing indexing setting for Lua tests Removing setting index setting for Lua generation because it is always one-indexed. * Fixing order and create text Fixing failing test caused by improper order and fixed create text to properly convert to string when there is one element. * Running linter on generator code Running linter on generator code and fixing spacing/indentation problems. * Editing comments and removing uneeded parenthesis Editing and adding comments and removing uneeded parenthesis around ternary operator condition. * Fixing order and changing variable names Fixing orders that were incorrect and changing variable names to be more descriptive and consistent across code. * Adding comment about list support and fixes for PHP Adding comment about how lists are not fully supported for PHP. Adding missing order to PHP and fixing order errors throughout. Fixing regex for variable matching in lists. Cleaning up variable names to be more readable and consistent with other parts of code. * Reducing complexity for getremove/remove in JS Reducing complexity in generated code for getremove/remove in JavaScript by replacing unecessary helper function. * Fixing spacing before inline comments Ensuring there are two spaces before inline comments. * Changing JS list copy for clarity Changing JavaScript list copy to use slice(0) instead of concat for clarity and to use the same pattern as the other sublist methods. * Changing generated variable name tmp_x Changing tmp_x to tmpX to follow closer to the correct style for JavaScript. * Prefixing empy lines between comment text Prior to this change, comments with an empty line between text did not have a comment prefix before it, resulting in comment blocks that seemed disjoined although they were for the same block. This change affects how the prefix line function works so that those lines will have the prefix (if applicable) while still taking into account the trailing newline character. * Changing for loops variable names Changing most for loops to use i as the variable name (or j if applicable) or changing name to be more readable. * Simplifying provided subsequence function Simplifying subsequence function to generate a simpler function depending on where combination instead of a larger complex function that works for all where combinations. * Style fixes Fixing indentation, comments, and other formatting-type changes based on pull request comments. * Fixing indentation Fixing indentation and removing an extra newline. * Fixing PHP mode implementation Fixing PHP mode implementation to properlyu return multiple modes if applicable. * Fixing line too long Wrapping lines in php/math.js with lines longer than 80 characters. * Wrapping long lines Wrapping lines that are too long. * Changing boolean casing Changing boolean casing to be lowercase.
2016-07-08 11:43:48 -07:00
for (var j = 0; j < connections.length; j++) {
connections[j].setHidden(true);
}
// Close all bubbles of all children.
var icons = block.getIcons();
Adding indexing settings, tests and fixing bugs (#464) * Add indexing setting for JavaScript Generation Adding setting to allow for switching between zero and one based indexing for Blockly Blocks such that the generated code will use this flag to determine whether one based or zero based indexing should be used. One based indexing is enabled by default. * Updating js lists to do zero and one based index Updated generated JavaScript to change depending on whether one based indexing is enabled or not. * Updating js text to do zero and one based index Change so that JavaScript generated for text blocks either assumes blocks use zero or one based index based on setting. * Start of python indexing Start of work on allowing one and zero indexing for generated python for lists. * Fixing bug and lint fixed Fixing bug caused by not setting the return of concat when concatenating lines for sublist and substring functions. Also renamed these functions to be getSubsequece. Fixed lint errors with spacing * Converting from if to switch statements Comverting if statements to switch statements when appropriate and adding spacing. * Modified sublist JavaScript generation Added case so that helper function is not generated if not necessary. Helper function is not generated if list length is not needed or if list is a simple block (such as a variable, as oppossed to a function call or list create). * Stripping unecessary ids Removing ids from xml file. * Localisation updates from https://translatewiki.net. * Fix typo in flyout.js (#403) * Fix typo in flyout.js (#402) * Localisation updates from https://translatewiki.net. * Add indexing setting for JavaScript Generation Adding setting to allow for switching between zero and one based indexing for Blockly Blocks such that the generated code will use this flag to determine whether one based or zero based indexing should be used. One based indexing is enabled by default. * Updating js lists to do zero and one based index Updated generated JavaScript to change depending on whether one based indexing is enabled or not. * Updating js text to do zero and one based index Change so that JavaScript generated for text blocks either assumes blocks use zero or one based index based on setting. * Fixing bug and lint fixed Fixing bug caused by not setting the return of concat when concatenating lines for sublist and substring functions. Also renamed these functions to be getSubsequece. Fixed lint errors with spacing * Converting from if to switch statements Comverting if statements to switch statements when appropriate and adding spacing. * Modified sublist JavaScript generation Added case so that helper function is not generated if not necessary. Helper function is not generated if list length is not needed or if list is a simple block (such as a variable, as oppossed to a function call or list create). * Stripping unecessary ids Removing ids from xml file. * Updating generator test Modifying sublist test and re-formatting spacing between blocks. * Updating js lists to do zero and one based index Updated generated JavaScript to change depending on whether one based indexing is enabled or not. * Updating js text to do zero and one based index Change so that JavaScript generated for text blocks either assumes blocks use zero or one based index based on setting. * Fixing bug and lint fixed Fixing bug caused by not setting the return of concat when concatenating lines for sublist and substring functions. Also renamed these functions to be getSubsequece. Fixed lint errors with spacing * Converting from if to switch statements Comverting if statements to switch statements when appropriate and adding spacing. * Modified sublist JavaScript generation Added case so that helper function is not generated if not necessary. Helper function is not generated if list length is not needed or if list is a simple block (such as a variable, as oppossed to a function call or list create). * Stripping unecessary ids Removing ids from xml file. * Localisation updates from https://translatewiki.net. * Localisation updates from https://translatewiki.net. * Updating js lists to do zero and one based index Updated generated JavaScript to change depending on whether one based indexing is enabled or not. * Fixing bug and lint fixed Fixing bug caused by not setting the return of concat when concatenating lines for sublist and substring functions. Also renamed these functions to be getSubsequece. Fixed lint errors with spacing * Modified sublist JavaScript generation Added case so that helper function is not generated if not necessary. Helper function is not generated if list length is not needed or if list is a simple block (such as a variable, as oppossed to a function call or list create). * Stripping unecessary ids Removing ids from xml file. * Updating generator test Modifying sublist test and re-formatting spacing between blocks. * Adding tests for indexing and extra cases Adding tests for indexing with custom block to adjust number based on what indexing is being generated. * Adding tests and renaming tests Adding tests for sublist and renaming tests. * Fixes for order for sublists Fixes so that parenthesis are generated properly for index for sublist * Cleaning up test generated code Changing order returned for unit test adjust index function to generate less unecessary parenthesis. * Adding tests for order Adding tests for order, relevant for methods that use index from start (because 1 is added) * Fixing JS order for getIndex and setIndex Changing to the correct order type when calling valueToCode in JS generation for getIndex and setIndex. * Fixed unittest adjustIndex Fixed uninttest adjustindex to also check whether the ONE_BASED_INDEXING variable has been defined to ensure proper behaviour. * Fixing lint and formatting for JS/lists Making line fixes and changing an if/elseif to case statement. * Tests added to include case for bug found Added tests with sublist combinations of different where's for the two indices after bug for this found in python. * Adding and renaming tests Adding test case for creating a sublist that encompasses the whole list but uses # and #-end instead of first last (applicable for python). Also, renaming tests. * Adding contant and fixing python lists bugs Adding contant for ONE_BASED_INDEXING and fixing bugs in python for lists. * Fixing test get random Fixing test get random to take into account indexing for return value. * Adding indexing checkbox to test page Adding checkbos on test page so that code can be generated for one and zero based indexing. Languages that are generated with zero based indexing that do not have it implemented will fail tests as expected. * Fixing unittest getremove random Fixing unittest getremove random to take into account the return value based on indexing. * Change comparison for getremove random test Fixed comparison to equal for the return value for getremove random. * Fixing bugs with lists zero-indexing Fixing getIndex and getSublist methods to pass for zero-indexed tests. * Adding test cases and formatting Adding test cases to text tests, reordering a couple list test, and formatting block spacing. * Fixing unittest expected value Fixing expected value fore unit tests for sublist. * Cleanup Removing obvious comments, formatting fixes, and naming in generated code in JS. * Helper function for Python lists Adding helper function for casting to int for indices. * Expanding helper to reduce duplicated code Expanding helper method to also get the property with the correct order and check indexing to reduce duplicated code. * Cleaning up JS indexing with helper function Adding helper function for indexing and used it in lists and text. * Moving helper function and formatting fixes Moving helper function, formatting fixes, and changing some generated code variable names. * Fixing python generation for text Fixing all failinng tests for python and using new helper method. * Lint fixes and order in indexOf Making lint fixes and correcting returned order in indexOf. * Python variable renaming Renaming a few generated variables. * Fixing comment and order Fixing comment to list Blockly.Block type and fixing order because it could be higher. * Switching back to if Switching switch back to if statements because there weren't enough cases to warrant for a switch. * Adding order and fixing lists for Dart Adding if null operator to operator precedence for Dart. Also, fixing lists implementation to pass unit tests and adding zero-indexing functionality. * Formatting and lint fixes Formatting and lint fixes * Dart text fixed Fixing Dart text generation to pass unit tests. * Changing back to variable Changing switch condition back to variable. * Fixing ORDER_OVERRIDES Inner and outer order was switched . * Adding bug with order caused by generator change Flooring order before comparision because of how the order constants were modified. * Adding list tests Adding tests for additional cases for lists/ * Adding comment for dart order Adding comment for Dart ORDER_IF_NULL operator. * Formatting fixes Formatting fixes for line indentation. * Fixing PHP order and lists generation Fixing PHP order constants and fixing lists so that they pass unit tests. * Fixing tests Removing duplicate unit test * Adding text tests Adding tests for text. * Renaming variable and removing unused variable Renaming variables from exceptionIndex to errorIndex and removing unused at variable. * Adding missing function call to test Adding missing funciton call to test that was causing tests to fail when they shouldn't. * Fixing PHP text generation Fixing PHP text code generation so it passes unit tests. * Formatting fixes Cleaning up code, renamiing a variable. * Fixing failing subsequence tests Fixing JS code that failed for sublist/substring tests. * Fixing intentation Fixing indentation. * Fixing Dart sublist/substring Fixing sublist/substring to include condiiton where FROM_START (and not throw error by mistake) when zero-indexed. * Adding order subtraction test Adding test for checking order for subtraction x- (y - z) x - (y + z). * Updating to new PHP power operator Updating from pow function to ** operator to clean up code. * Updating to new removeWhere Updating removeMatching to removeWhere because new version of Dart now use removeWhere. * Fix for lua rounding assertequals Adding check for number in equlity check for comparing number for floats. * Adding test for copy of list Adding test that checks the list is copied when a sublist is made first-last. * Formatting and order fixes Fixing formatting such as indentation and order fixes. * Adding comment for clarity Adding comment about how Lua code generation is not supporting zero indexing. * Changed variable names in code Changed variable names to follow style guide and changed for loop variable from n to i as is typical. * Reducing unecessarily generated functions and renaming variables Reducing number of generated functions using gensym_ by adding parameters to provided function. Renaming variables to make functions more readble. * Fixing sublist order and sort variable Fixing order used for valueToCode for sublist and renaming list variable in sort to match rest of code.. * Fixing order constant order Removing operator () that was incorrect and addiung ~, * Fixing order and indentation Fixing order return fro create lists blocks and fixing indentationn for string array. * Fixing order and renaming variables Fixing order to be the correct strength and renaming variables to be more readable/ * Changing assert blocks for unit tests Changing assert blocks to have a value input instead of a field so there is more flexibility in writing tests. * Cleaning up and adding missing order tests Adding tests for order for paramters for list blocks that weren't being tested to uncover bugs. Test were also cleaned up/reorganized/renamed to be more readable and shorter vertically (but lines wider horizontally). * Compile error fix and order in Dart generation. Fixing compile error in generated code and incorrect order in get sublist for Dart. * Fixing typo in getIndex and invalid parameter name Fixing type in getIndex where list code should have been appended but instead an undefined variable was added. The parameter in lists_sort was changed to my_list because list is a reserved word in python. * Fixing order, parenthesis bug, and variable declaration in Lua Fixing incorrect order in Lua. Fixing bug caused by missing parenthesis around ternary operator in code. Variable code was declared with JavaScript syntax, this was fixed to be valid in Lua. * Adding tests and formatting tests Adding missing test for order in text/lists. Changing spacing/order of tests and updating comments. * Fixing error in code Changing to correct function call in empy tests and changing test name that was duplicated to be more clear. * Renamed test helper function * Fixing order and renaming variable in JS generator Fixing order for charAt and renaming variable in code list_sort from listCode to list to be consistent with rest of code. * Fixing order for dart text Fixing roder for dart charAt * Cleaning up generated code for Dart getIndex Cleaning up generated code for Dart getIndex so that helper functions aren't generated unecessarily and adding comments. * Fixing Dart remove random error Fixing error caused by remove random implementation in Dart. index should have been x but instead was length - x. * Fixing unit test blocks Fixing Lua unit test block that should have just returned the number and removing unecessary checks in other blocks because the constant was defined. * Fixing Lua assert equals block string.format was throwing an error if one of the values happened to be a boolean. * Adding tests for create text with number Adding test for create text with numbers as parameters * Fixing lua unit test block Lua unit test block should have added 1 * Removing indexing setting for Lua tests Removing setting index setting for Lua generation because it is always one-indexed. * Fixing order and create text Fixing failing test caused by improper order and fixed create text to properly convert to string when there is one element. * Running linter on generator code Running linter on generator code and fixing spacing/indentation problems. * Editing comments and removing uneeded parenthesis Editing and adding comments and removing uneeded parenthesis around ternary operator condition. * Fixing order and changing variable names Fixing orders that were incorrect and changing variable names to be more descriptive and consistent across code. * Adding comment about list support and fixes for PHP Adding comment about how lists are not fully supported for PHP. Adding missing order to PHP and fixing order errors throughout. Fixing regex for variable matching in lists. Cleaning up variable names to be more readable and consistent with other parts of code. * Reducing complexity for getremove/remove in JS Reducing complexity in generated code for getremove/remove in JavaScript by replacing unecessary helper function. * Fixing spacing before inline comments Ensuring there are two spaces before inline comments. * Changing JS list copy for clarity Changing JavaScript list copy to use slice(0) instead of concat for clarity and to use the same pattern as the other sublist methods. * Changing generated variable name tmp_x Changing tmp_x to tmpX to follow closer to the correct style for JavaScript. * Prefixing empy lines between comment text Prior to this change, comments with an empty line between text did not have a comment prefix before it, resulting in comment blocks that seemed disjoined although they were for the same block. This change affects how the prefix line function works so that those lines will have the prefix (if applicable) while still taking into account the trailing newline character. * Changing for loops variable names Changing most for loops to use i as the variable name (or j if applicable) or changing name to be more readable. * Simplifying provided subsequence function Simplifying subsequence function to generate a simpler function depending on where combination instead of a larger complex function that works for all where combinations. * Style fixes Fixing indentation, comments, and other formatting-type changes based on pull request comments. * Fixing indentation Fixing indentation and removing an extra newline. * Fixing PHP mode implementation Fixing PHP mode implementation to properlyu return multiple modes if applicable. * Fixing line too long Wrapping lines in php/math.js with lines longer than 80 characters. * Wrapping long lines Wrapping lines that are too long. * Changing boolean casing Changing boolean casing to be lowercase.
2016-07-08 11:43:48 -07:00
for (var j = 0; j < icons.length; j++) {
icons[j].setVisible(false);
}
}
}
};
/**
* Check if the two connections can be dragged to connect to each other.
* @param {!Blockly.Connection} candidate A nearby connection to check.
* @param {number} maxRadius The maximum radius allowed for connections.
* @return {boolean} True if the connection is allowed, false otherwise.
*/
Blockly.RenderedConnection.prototype.isConnectionAllowed = function(candidate,
maxRadius) {
if (this.distanceFrom(candidate) > maxRadius) {
return false;
}
return Blockly.RenderedConnection.superClass_.isConnectionAllowed.call(this,
candidate);
};
2016-05-10 15:39:37 -07:00
/**
* Disconnect two blocks that are connected by this connection.
* @param {!Blockly.Block} parentBlock The superior block.
* @param {!Blockly.Block} childBlock The inferior block.
* @private
*/
Blockly.RenderedConnection.prototype.disconnectInternal_ = function(parentBlock,
childBlock) {
Blockly.RenderedConnection.superClass_.disconnectInternal_.call(this,
parentBlock, childBlock);
// Rerender the parent so that it may reflow.
if (parentBlock.rendered) {
parentBlock.render();
}
if (childBlock.rendered) {
childBlock.updateDisabled();
childBlock.render();
}
};
2016-05-10 15:39:37 -07:00
/**
* Respawn the shadow block if there was one connected to the this connection.
* Render/rerender blocks as needed.
* @private
*/
Blockly.RenderedConnection.prototype.respawnShadow_ = function() {
var parentBlock = this.getSourceBlock();
// Respawn the shadow block if there is one.
2016-05-10 15:39:37 -07:00
var shadow = this.getShadowDom();
if (parentBlock.workspace && shadow && Blockly.Events.recordUndo) {
Merge google/develop June 22 (#441) * Localisation updates from https://translatewiki.net. * test page that creates random blocks and randomly drags them around the page * Localisation updates from https://translatewiki.net. * add missing return in fake drag * get rid of drag_tests file: * Generated JS helper functions should be camelCase. Complying with Google style guide. * Localisation updates from https://translatewiki.net. * Fix extra category error. Clean up code, rename variables, reduce line lengths, fix lint issues. * Remove claim that good.string.quote should be used. * Change the blockly workspace resizing strategy. (#386) * Add a new method to be called when the contents of the workspace change and the scrollbars need to be adjusted but the the chrome (trash, toolbox, etc) are expected to stay in the same place. Change a bunch of calls to svgResize to either be removed or call the new method instead. This is a nice performance win since the offsetHeight/Width call in svgResize can be expensive, especially when called as often as we do - there was some layout thrashing. This also paves the way for moving calls to recordDeleteAreas (which is also expensive) to a more cacheable spot than on every mouse down/touch event. of things (namely the scrollbars) * Fix size of graph demo when it first loads by calling svgResize. The graph starts with fixed width and was relying on a resize event to fire (which I believe was removed in commit 217c681b86b0f2df76c479c9efae62e6e). * Fix the resizing of the code demo. The demo's tab min-width used to match the toolbox's width was only being set on a resize event, but commit 217c681b86b0f2df76c479c9efae62e6e changed how that worked. * Fix up some comments. * Use specific workspaces rather than Blockly.getMainWorkspace(). * Make workspace required for resizeSvgContents and update some calls to send real workspaces rather than ones that are null. Remove the private tag on terminateDrag_ because it is only actually called from outside the BlockSvg object. * Remove a rogue period. * Recategorize BlockSvg.terminateDrag_ to @package instead of @private so that other developers don't use it, but it still can be used by other Blockly classes. * Add a TODO to fix issue #307. * Add @package to workspace resizeContents. * Routine recompile * Fix unit tests. * Fix inheritance on rendered connection. Closure compiler on maximum compression breaks badly due to lack of @extends attribute. * Add toolbox location and toolbox mode options to playground. * Increase commonality between playgrounds. * Properly deal with shadow statement blocks in stacks. * Localisation updates from https://translatewiki.net. * Use a comment block for function comments in generated JS, Python and Dart. * Fix typo in flyout.js (#403) * Fix typo in flyout.js (#402) * Line wrap comments in generated code. * Remove reference to undefined variable (#413) REASON_MUST_DISCONNECT was removed by a refactor in 2a1ffa1. * Fix airstrike by grabbing the correct toolbox element. (#411) Probably broken in 266e2ffa9a017d21d7ca2f151730d6ecfcecf173. * Localisation updates from https://translatewiki.net. * Fix issue #406 by calling resize from the keypress handler on text inputs. (#408) * Remove shadow blocks from Accessible Blockly demo. Update README. * Generate for loops on one line. * Introduce a common translation pipe; remove local stringMap attributes. Fix variable name error in paste functions. Minor linting. * Fix precedence on isIndex blocks. * Add indexing setting for JavaScript Generation (#419) Adding setting to allow for switching between zero and one based indexing for Blockly Blocks such that the generated code will use this flag to determine whether one based or zero based indexing should be used. One based indexing is enabled by default. * Remove unused functions and dependencies. * Remove the unnecessary construction of new services. * Fix sort block in JS to satisfy tests. * Trigger a contents resize in block's moveBy. (#422) This fixes #420 but and it also fixes some other similar problems with copy/paste and other users of moveBy. * Consolidate the usages of the 'blockly-disabled' label. * Fix error when undoing a shadow block replacement. Issue #415. * Unify setActiveDesc() and updateSelectedNode() in the TreeService. Move function calls made directly within the template to the correct hooks. * Standardize naming of components. * Prevent collisions between user functions and helper functions. * Localisation updates from https://translatewiki.net. * Fix #425. Attash the resize handler to the workspace so it can be removed (#429) when workspace.dispose() is called. * Change the TreeService to a singleton. * Remove unneeded generated parens around function calls in indexOf blocks. * Fix #423 by calling workspace's resize when the flyout reflows. (#430) * Updating URLs to reflect new docs. (#418) * Updating URLs to reflect new docs. Removing -blockly in URLs. * Rebuilt. * Routine recompile * Prevent selected block from ending up underneath a bumped block. * Fix undo on fields with validators with side effects. * Don't fire change event on fields that haven't been named yet. * Localisation updates from https://translatewiki.net. * Fix tree focus issues. * Fix remaining focus issues on block deletion. * cache delete areas instead of recalculating them onMouseDown * Cache screen CTM for performance improvement. * Call svgResizeContents from block_svg's dipose so that deleting blocks (#434) from the context menu (or anywhere really) causes the workspace to recalculate its size. Remove the call to svgResizeContents from onMouseUp's logic for determining whether the block is being dropped in the trash since it calls dispose. One side effect of this is that when you delete multiple blocks resize gets called for each of them and the scrollbars move during the operation. This is most obviously seen by doing an airstrike in the playground and then deleting all the blocks at once. * Allow terminal blocks to replace other terminal blocks (#433) * Allow terminal blocks to replace other terminal blocks * Updated test to allow replacing terminal blocks * Refactor how activeDescendant is set. Introduce helper functions to ensure that calls like pasteAbove() preserve the focus. * Localisation updates from https://translatewiki.net. * Remove unnecessary logging. * Reduce unneeded parentheses in JS and Python. * Start using field_number. * Make it easy to disable unconnected blocks. * Routine recompile. * Check if matrix is null in mouseToSvg * Remove js/ localizations pre-merge * Fix change to block_render_svg * Fix error in xml.js * Playground merge * Add simple toolboxes to playgrounds * Fix flyout reference in events listener * Move tokenizeIntepolation into Blockly.utils namespace. * Use simpler message interpolation in Code demo. * Create console stub for IE 9. * Don't output blockId if not set (e.g., toolbox category event). (#443) * Fix block in multi-playground * Increase commonality between playgrounds. # Conflicts: # tests/multi_playground.html # tests/playground.html * Remove "show flyouts" button * Recompile for merge June 22
2016-06-22 17:50:16 -04:00
Blockly.RenderedConnection.superClass_.respawnShadow_.call(this);
var blockShadow = this.targetBlock();
2016-05-10 15:39:37 -07:00
if (!blockShadow) {
throw 'Couldn\'t respawn the shadow block that should exist here.';
}
blockShadow.initSvg();
blockShadow.render(false);
2016-05-10 15:39:37 -07:00
if (parentBlock.rendered) {
parentBlock.render();
}
}
};
/**
* Find all nearby compatible connections to this connection.
* Type checking does not apply, since this function is used for bumping.
* @param {number} maxLimit The maximum radius to another connection.
2016-05-10 16:36:40 -07:00
* @return {!Array.<!Blockly.Connection>} List of connections.
* @private
*/
Blockly.RenderedConnection.prototype.neighbours_ = function(maxLimit) {
return this.dbOpposite_.getNeighbours(this, maxLimit);
};
2016-05-10 15:39:37 -07:00
/**
* Connect two connections together. This is the connection on the superior
* block. Rerender blocks as needed.
* @param {!Blockly.Connection} childConnection Connection on inferior block.
* @private
*/
Blockly.RenderedConnection.prototype.connect_ = function(childConnection) {
Blockly.RenderedConnection.superClass_.connect_.call(this, childConnection);
var parentConnection = this;
var parentBlock = parentConnection.getSourceBlock();
var childBlock = childConnection.getSourceBlock();
if (parentBlock.rendered) {
parentBlock.updateDisabled();
}
if (childBlock.rendered) {
childBlock.updateDisabled();
}
if (parentBlock.rendered && childBlock.rendered) {
if (parentConnection.type == Blockly.NEXT_STATEMENT ||
parentConnection.type == Blockly.PREVIOUS_STATEMENT) {
// Child block may need to square off its corners if it is in a stack.
// Rendering a child will render its parent.
childBlock.render();
} else {
// Child block does not change shape. Rendering the parent node will
// move its connected children into position.
parentBlock.render();
}
}
};