2013-10-30 14:46:03 -07:00
|
|
|
/**
|
2014-01-28 03:00:09 -08:00
|
|
|
* @license
|
2013-10-30 14:46:03 -07:00
|
|
|
* Visual Blocks Editor
|
|
|
|
*
|
|
|
|
* Copyright 2011 Google Inc.
|
2014-10-07 13:09:55 -07:00
|
|
|
* https://developers.google.com/blockly/
|
2013-10-30 14:46:03 -07:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2016-09-09 12:44:33 -07:00
|
|
|
* @fileoverview Base class for a file tray containing blocks that may be
|
|
|
|
* dragged into the workspace. Defines basic interactions that are shared
|
|
|
|
* between vertical and horizontal flyouts.
|
2013-10-30 14:46:03 -07:00
|
|
|
* @author fraser@google.com (Neil Fraser)
|
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
goog.provide('Blockly.Flyout');
|
|
|
|
|
|
|
|
goog.require('Blockly.Block');
|
|
|
|
goog.require('Blockly.Comment');
|
2016-04-20 16:44:13 -07:00
|
|
|
goog.require('Blockly.Events');
|
2016-06-21 13:42:03 -07:00
|
|
|
goog.require('Blockly.FlyoutButton');
|
2016-10-04 14:40:10 -07:00
|
|
|
goog.require('Blockly.Touch');
|
2014-12-23 11:22:02 -08:00
|
|
|
goog.require('Blockly.WorkspaceSvg');
|
2015-02-06 15:27:25 -08:00
|
|
|
goog.require('goog.dom');
|
|
|
|
goog.require('goog.events');
|
2014-11-28 21:43:39 -08:00
|
|
|
goog.require('goog.math.Rect');
|
2015-01-22 15:58:10 -08:00
|
|
|
goog.require('goog.userAgent');
|
2013-10-30 14:46:03 -07:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class for a flyout.
|
2015-04-28 13:51:25 -07:00
|
|
|
* @param {!Object} workspaceOptions Dictionary of options for the workspace.
|
2013-10-30 14:46:03 -07:00
|
|
|
* @constructor
|
|
|
|
*/
|
2015-04-28 13:51:25 -07:00
|
|
|
Blockly.Flyout = function(workspaceOptions) {
|
2016-01-08 13:03:22 -08:00
|
|
|
workspaceOptions.getMetrics = this.getMetrics_.bind(this);
|
|
|
|
workspaceOptions.setMetrics = this.setMetrics_.bind(this);
|
2013-10-30 14:46:03 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {!Blockly.Workspace}
|
|
|
|
* @private
|
|
|
|
*/
|
2015-04-28 13:51:25 -07:00
|
|
|
this.workspace_ = new Blockly.WorkspaceSvg(workspaceOptions);
|
2013-10-30 14:46:03 -07:00
|
|
|
this.workspace_.isFlyout = true;
|
|
|
|
|
2015-04-28 13:51:25 -07:00
|
|
|
/**
|
|
|
|
* Is RTL vs LTR.
|
|
|
|
* @type {boolean}
|
|
|
|
*/
|
|
|
|
this.RTL = !!workspaceOptions.RTL;
|
|
|
|
|
2016-02-08 13:56:57 -08:00
|
|
|
/**
|
|
|
|
* Flyout should be laid out horizontally vs vertically.
|
|
|
|
* @type {boolean}
|
2016-04-08 15:34:08 -07:00
|
|
|
* @private
|
2016-02-08 13:56:57 -08:00
|
|
|
*/
|
2016-02-11 14:46:51 -08:00
|
|
|
this.horizontalLayout_ = workspaceOptions.horizontalLayout;
|
2016-02-08 13:56:57 -08:00
|
|
|
|
2016-02-12 14:48:13 -08:00
|
|
|
/**
|
2016-02-17 16:19:40 -08:00
|
|
|
* Position of the toolbox and flyout relative to the workspace.
|
|
|
|
* @type {number}
|
2016-02-12 14:48:13 -08:00
|
|
|
* @private
|
|
|
|
*/
|
2016-03-17 15:46:22 -07:00
|
|
|
this.toolboxPosition_ = workspaceOptions.toolboxPosition;
|
2016-02-12 10:57:33 -08:00
|
|
|
|
2013-10-30 14:46:03 -07:00
|
|
|
/**
|
2015-08-20 15:46:44 -07:00
|
|
|
* Opaque data that can be passed to Blockly.unbindEvent_.
|
2015-09-12 19:31:22 -07:00
|
|
|
* @type {!Array.<!Array>}
|
2013-10-30 14:46:03 -07:00
|
|
|
* @private
|
|
|
|
*/
|
2014-09-08 14:26:52 -07:00
|
|
|
this.eventWrappers_ = [];
|
2013-10-30 14:46:03 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* List of background buttons that lurk behind each block to catch clicks
|
|
|
|
* landing in the blocks' lakes and bays.
|
|
|
|
* @type {!Array.<!Element>}
|
|
|
|
* @private
|
|
|
|
*/
|
2016-06-21 13:42:03 -07:00
|
|
|
this.backgroundButtons_ = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* List of visible buttons.
|
2016-09-08 13:45:47 -07:00
|
|
|
* @type {!Array.<!Blockly.FlyoutButton>}
|
|
|
|
* @private
|
2016-06-21 13:42:03 -07:00
|
|
|
*/
|
2013-10-30 14:46:03 -07:00
|
|
|
this.buttons_ = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* List of event listeners.
|
|
|
|
* @type {!Array.<!Array>}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this.listeners_ = [];
|
2016-02-02 19:53:52 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* List of blocks that should always be disabled.
|
|
|
|
* @type {!Array.<!Blockly.Block>}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this.permanentlyDisabled_ = [];
|
2016-07-19 11:00:37 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* y coordinate of mousedown - used to calculate scroll distances.
|
2016-11-01 18:00:26 -07:00
|
|
|
* @type {number}
|
|
|
|
* @private
|
2016-07-19 11:00:37 +02:00
|
|
|
*/
|
|
|
|
this.startDragMouseY_ = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* x coordinate of mousedown - used to calculate scroll distances.
|
2016-11-01 18:00:26 -07:00
|
|
|
* @type {number}
|
|
|
|
* @private
|
2016-07-19 11:00:37 +02:00
|
|
|
*/
|
|
|
|
this.startDragMouseX_ = 0;
|
2016-09-08 16:54:10 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The toolbox that this flyout belongs to, or none if tihs is a simple
|
|
|
|
* workspace.
|
2016-11-01 18:00:26 -07:00
|
|
|
* @type {Blockly.Toolbox}
|
|
|
|
* @private
|
2016-09-08 16:54:10 -07:00
|
|
|
*/
|
|
|
|
this.parentToolbox_ = null;
|
2013-10-30 14:46:03 -07:00
|
|
|
};
|
|
|
|
|
2016-07-19 11:00:37 +02:00
|
|
|
/**
|
|
|
|
* When a flyout drag is in progress, this is a reference to the flyout being
|
|
|
|
* dragged. This is used by Flyout.terminateDrag_ to reset dragMode_.
|
2016-11-01 18:00:26 -07:00
|
|
|
* @type {Blockly.Flyout}
|
|
|
|
* @private
|
2016-07-19 11:00:37 +02:00
|
|
|
*/
|
|
|
|
Blockly.Flyout.startFlyout_ = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event that started a drag. Used to determine the drag distance/direction and
|
|
|
|
* also passed to BlockSvg.onMouseDown_() after creating a new block.
|
2016-11-01 18:00:26 -07:00
|
|
|
* @type {Event}
|
|
|
|
* @private
|
2016-07-19 11:00:37 +02:00
|
|
|
*/
|
|
|
|
Blockly.Flyout.startDownEvent_ = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Flyout block where the drag/click was initiated. Used to fire click events or
|
|
|
|
* create a new block.
|
2016-11-01 18:00:26 -07:00
|
|
|
* @type {Blockly.Block}
|
|
|
|
* @private
|
2016-07-19 11:00:37 +02:00
|
|
|
*/
|
|
|
|
Blockly.Flyout.startBlock_ = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Wrapper function called when a mouseup occurs during a background or block
|
|
|
|
* drag operation.
|
2016-11-01 18:00:26 -07:00
|
|
|
* @type {function}
|
|
|
|
* private
|
2016-07-19 11:00:37 +02:00
|
|
|
*/
|
|
|
|
Blockly.Flyout.onMouseUpWrapper_ = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Wrapper function called when a mousemove occurs during a background drag.
|
2016-11-01 18:00:26 -07:00
|
|
|
* @type {function}
|
|
|
|
* @private
|
2016-07-19 11:00:37 +02:00
|
|
|
*/
|
|
|
|
Blockly.Flyout.onMouseMoveWrapper_ = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Wrapper function called when a mousemove occurs during a block drag.
|
|
|
|
* @private {Array.<!Array>}
|
|
|
|
*/
|
|
|
|
Blockly.Flyout.onMouseMoveBlockWrapper_ = null;
|
|
|
|
|
2013-10-30 14:46:03 -07:00
|
|
|
/**
|
|
|
|
* Does the flyout automatically close when a block is created?
|
|
|
|
* @type {boolean}
|
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.autoClose = true;
|
|
|
|
|
2017-02-02 14:17:43 -05:00
|
|
|
/**
|
|
|
|
* Whether the flyout is visible.
|
|
|
|
* @type {boolean}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.isVisible_ = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether the workspace containing this flyout is visible.
|
|
|
|
* @type {boolean}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.containerVisible_ = true;
|
|
|
|
|
2013-10-30 14:46:03 -07:00
|
|
|
/**
|
|
|
|
* Corner radius of the flyout background.
|
|
|
|
* @type {number}
|
|
|
|
* @const
|
|
|
|
*/
|
2016-04-14 17:58:39 -04:00
|
|
|
Blockly.Flyout.prototype.CORNER_RADIUS = 0;
|
|
|
|
|
2016-06-09 15:19:23 +02:00
|
|
|
/**
|
|
|
|
* Number of pixels the mouse must move before a drag/scroll starts. Because the
|
|
|
|
* drag-intention is determined when this is reached, it is larger than
|
|
|
|
* Blockly.DRAG_RADIUS so that the drag-direction is clearer.
|
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.DRAG_RADIUS = 10;
|
|
|
|
|
2016-04-14 17:58:39 -04:00
|
|
|
/**
|
2016-04-18 17:29:48 -07:00
|
|
|
* Margin around the edges of the blocks in the flyout.
|
2016-04-14 17:58:39 -04:00
|
|
|
* @type {number}
|
|
|
|
* @const
|
|
|
|
*/
|
2016-06-24 14:32:58 -07:00
|
|
|
Blockly.Flyout.prototype.MARGIN = 12;
|
2013-10-30 14:46:03 -07:00
|
|
|
|
2016-09-08 13:45:47 -07:00
|
|
|
/**
|
|
|
|
* Gap between items in horizontal flyouts. Can be overridden with the "sep"
|
|
|
|
* element.
|
|
|
|
* @const {number}
|
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.GAP_X = Blockly.Flyout.prototype.MARGIN * 3;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gap between items in vertical flyouts. Can be overridden with the "sep"
|
|
|
|
* element.
|
|
|
|
* @const {number}
|
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.GAP_Y = Blockly.Flyout.prototype.MARGIN * 3;
|
|
|
|
|
2015-08-19 17:21:05 -07:00
|
|
|
/**
|
|
|
|
* Top/bottom padding between scrollbar and edge of flyout background.
|
|
|
|
* @type {number}
|
|
|
|
* @const
|
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.SCROLLBAR_PADDING = 2;
|
2013-10-30 14:46:03 -07:00
|
|
|
|
2015-09-12 19:31:22 -07:00
|
|
|
/**
|
|
|
|
* Width of flyout.
|
|
|
|
* @type {number}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.width_ = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Height of flyout.
|
|
|
|
* @type {number}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.height_ = 0;
|
|
|
|
|
2016-04-12 15:50:07 +02:00
|
|
|
/**
|
|
|
|
* Width of flyout contents.
|
|
|
|
* @type {number}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.contentWidth_ = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Height of flyout contents.
|
|
|
|
* @type {number}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.contentHeight_ = 0;
|
|
|
|
|
2016-01-26 12:35:50 -08:00
|
|
|
/**
|
|
|
|
* Vertical offset of flyout.
|
|
|
|
* @type {number}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.verticalOffset_ = 0;
|
|
|
|
|
2016-04-11 14:21:55 -04:00
|
|
|
/**
|
2016-06-29 12:26:11 +02:00
|
|
|
* Range of a drag angle from a flyout considered "dragging toward workspace".
|
2016-04-11 14:21:55 -04:00
|
|
|
* Drags that are within the bounds of this many degrees from the orthogonal
|
2016-06-29 12:26:11 +02:00
|
|
|
* line to the flyout edge are considered to be "drags toward the workspace".
|
2016-04-11 14:21:55 -04:00
|
|
|
* Example:
|
|
|
|
* Flyout Edge Workspace
|
|
|
|
* [block] / <-within this angle, drags "toward workspace" |
|
|
|
|
* [block] ---- orthogonal to flyout boundary ---- |
|
|
|
|
* [block] \ |
|
|
|
|
* The angle is given in degrees from the orthogonal.
|
2016-06-29 12:26:11 +02:00
|
|
|
*
|
|
|
|
* This is used to know when to create a new block and when to scroll the
|
|
|
|
* flyout. Setting it to 360 means that all drags create a new block.
|
2016-04-11 14:21:55 -04:00
|
|
|
* @type {number}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.dragAngleRange_ = 70;
|
|
|
|
|
2016-04-23 12:59:38 -04:00
|
|
|
/**
|
|
|
|
* Is the flyout dragging (scrolling)?
|
|
|
|
* 0 - DRAG_NONE - no drag is ongoing or state is undetermined
|
|
|
|
* 1 - DRAG_STICKY - still within the sticky drag radius
|
|
|
|
* 2 - DRAG_FREE - in scroll mode (never create a new block)
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.dragMode_ = Blockly.DRAG_NONE;
|
|
|
|
|
|
|
|
|
2013-10-30 14:46:03 -07:00
|
|
|
/**
|
2017-02-02 14:17:43 -05:00
|
|
|
* Creates the flyout's DOM. Only needs to be called once. The flyout can
|
|
|
|
* either exist as its own <svg> element or be a <g> nested inside a separate
|
|
|
|
* <svg> element.
|
|
|
|
* @param {string} tagName The type of tag to put the flyout in. This
|
|
|
|
* should be <svg> or <g>.
|
2013-10-30 14:46:03 -07:00
|
|
|
* @return {!Element} The flyout's SVG group.
|
|
|
|
*/
|
2017-02-02 14:17:43 -05:00
|
|
|
Blockly.Flyout.prototype.createDom = function(tagName) {
|
2013-10-30 14:46:03 -07:00
|
|
|
/*
|
2017-02-02 14:17:43 -05:00
|
|
|
<svg | g>
|
2013-10-30 14:46:03 -07:00
|
|
|
<path class="blocklyFlyoutBackground"/>
|
2015-07-14 23:13:09 -07:00
|
|
|
<g class="blocklyFlyout"></g>
|
2017-02-02 14:17:43 -05:00
|
|
|
</ svg | g>
|
2013-10-30 14:46:03 -07:00
|
|
|
*/
|
2017-02-02 14:17:43 -05:00
|
|
|
// Setting style to display:none to start. The toolbox and flyout
|
|
|
|
// hide/show code will set up proper visibility and size later.
|
|
|
|
this.svgGroup_ = Blockly.utils.createSvgElement(tagName,
|
|
|
|
{'class': 'blocklyFlyout', 'style' : 'display: none'}, null);
|
|
|
|
this.svgBackground_ = Blockly.utils.createSvgElement('path',
|
2013-10-30 14:46:03 -07:00
|
|
|
{'class': 'blocklyFlyoutBackground'}, this.svgGroup_);
|
|
|
|
this.svgGroup_.appendChild(this.workspace_.createDom());
|
|
|
|
return this.svgGroup_;
|
|
|
|
};
|
|
|
|
|
2015-04-28 13:51:25 -07:00
|
|
|
/**
|
|
|
|
* Initializes the flyout.
|
2015-08-19 17:21:05 -07:00
|
|
|
* @param {!Blockly.Workspace} targetWorkspace The workspace in which to create
|
|
|
|
* new blocks.
|
2015-04-28 13:51:25 -07:00
|
|
|
*/
|
2015-08-19 17:21:05 -07:00
|
|
|
Blockly.Flyout.prototype.init = function(targetWorkspace) {
|
|
|
|
this.targetWorkspace_ = targetWorkspace;
|
|
|
|
this.workspace_.targetWorkspace = targetWorkspace;
|
2015-04-28 13:51:25 -07:00
|
|
|
// Add scrollbar.
|
2016-03-17 15:46:22 -07:00
|
|
|
this.scrollbar_ = new Blockly.Scrollbar(this.workspace_,
|
|
|
|
this.horizontalLayout_, false);
|
2015-04-28 13:51:25 -07:00
|
|
|
|
2016-10-06 14:49:15 -07:00
|
|
|
this.position();
|
2015-04-28 13:51:25 -07:00
|
|
|
|
2015-08-20 15:46:44 -07:00
|
|
|
Array.prototype.push.apply(this.eventWrappers_,
|
|
|
|
Blockly.bindEvent_(this.svgGroup_, 'wheel', this, this.wheel_));
|
2016-02-08 13:56:57 -08:00
|
|
|
// Dragging the flyout up and down (or left and right).
|
2015-08-20 15:46:44 -07:00
|
|
|
Array.prototype.push.apply(this.eventWrappers_,
|
|
|
|
Blockly.bindEvent_(this.svgGroup_, 'mousedown', this, this.onMouseDown_));
|
2015-04-28 13:51:25 -07:00
|
|
|
};
|
|
|
|
|
2013-10-30 14:46:03 -07:00
|
|
|
/**
|
|
|
|
* Dispose of this flyout.
|
|
|
|
* Unlink from all DOM elements to prevent memory leaks.
|
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.dispose = function() {
|
|
|
|
this.hide();
|
2014-09-08 14:26:52 -07:00
|
|
|
Blockly.unbindEvent_(this.eventWrappers_);
|
2013-10-30 14:46:03 -07:00
|
|
|
if (this.scrollbar_) {
|
|
|
|
this.scrollbar_.dispose();
|
|
|
|
this.scrollbar_ = null;
|
|
|
|
}
|
2015-08-20 15:46:44 -07:00
|
|
|
if (this.workspace_) {
|
|
|
|
this.workspace_.targetWorkspace = null;
|
|
|
|
this.workspace_.dispose();
|
|
|
|
this.workspace_ = null;
|
|
|
|
}
|
2013-10-30 14:46:03 -07:00
|
|
|
if (this.svgGroup_) {
|
|
|
|
goog.dom.removeNode(this.svgGroup_);
|
|
|
|
this.svgGroup_ = null;
|
|
|
|
}
|
2016-10-06 14:49:15 -07:00
|
|
|
this.parentToolbox_ = null;
|
2013-10-30 14:46:03 -07:00
|
|
|
this.svgBackground_ = null;
|
|
|
|
this.targetWorkspace_ = null;
|
|
|
|
};
|
|
|
|
|
2016-09-08 16:54:10 -07:00
|
|
|
/**
|
2016-10-07 10:15:41 -07:00
|
|
|
* Set the parent toolbox of this flyout.
|
|
|
|
* @param {!Blockly.Toolbox} toolbox The toolbox that owns this flyout.
|
2016-09-08 16:54:10 -07:00
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.setParentToolbox = function(toolbox) {
|
|
|
|
this.parentToolbox_ = toolbox;
|
|
|
|
};
|
|
|
|
|
2016-04-13 15:30:11 -07:00
|
|
|
/**
|
|
|
|
* Get the width of the flyout.
|
2016-05-13 15:30:47 -07:00
|
|
|
* @return {number} The width of the flyout.
|
2016-04-13 15:30:11 -07:00
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.getWidth = function() {
|
2016-09-08 16:54:10 -07:00
|
|
|
return this.parentToolbox_ ? this.parentToolbox_.getWidth() :
|
|
|
|
this.DEFAULT_WIDTH;
|
2016-04-13 15:30:11 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the height of the flyout.
|
2016-05-13 15:30:47 -07:00
|
|
|
* @return {number} The width of the flyout.
|
2016-04-13 15:30:11 -07:00
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.getHeight = function() {
|
|
|
|
return this.height_;
|
|
|
|
};
|
|
|
|
|
2016-06-23 18:17:36 -04:00
|
|
|
/**
|
|
|
|
* Get the flyout's workspace.
|
|
|
|
* @return {!Blockly.Workspace} Workspace on which this flyout's blocks are placed.
|
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.getWorkspace = function() {
|
|
|
|
return this.workspace_;
|
|
|
|
};
|
|
|
|
|
2013-10-30 14:46:03 -07:00
|
|
|
/**
|
|
|
|
* Is the flyout visible?
|
|
|
|
* @return {boolean} True if visible.
|
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.isVisible = function() {
|
2017-02-02 14:17:43 -05:00
|
|
|
return this.isVisible_;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set whether the flyout is visible. A value of true does not necessarily mean
|
|
|
|
* that the flyout is shown. It could be hidden because its container is hidden.
|
|
|
|
* @param {boolean} visible True if visible.
|
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.setVisible = function(visible) {
|
|
|
|
var visibilityChanged = (visible != this.isVisible());
|
|
|
|
|
|
|
|
this.isVisible_ = visible;
|
|
|
|
if (visibilityChanged) {
|
|
|
|
this.updateDisplay_();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set whether this flyout's container is visible.
|
|
|
|
* @param {boolean} visible Whether the container is visible.
|
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.setContainerVisible = function(visible) {
|
|
|
|
var visibilityChanged = (visible != this.containerVisible_);
|
|
|
|
this.containerVisible_ = visible;
|
|
|
|
if (visibilityChanged) {
|
|
|
|
this.updateDisplay_();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the display property of the flyout based whether it thinks it should
|
|
|
|
* be visible and whether its containing workspace is visible.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.updateDisplay_ = function() {
|
|
|
|
var show = true;
|
|
|
|
if (!this.containerVisible_) {
|
|
|
|
show = false;
|
|
|
|
} else {
|
|
|
|
show = this.isVisible();
|
|
|
|
}
|
|
|
|
this.svgGroup_.style.display = show ? 'block' : 'none';
|
|
|
|
// Update the scrollbar's visiblity too since it should mimic the
|
|
|
|
// flyout's visibility.
|
|
|
|
this.scrollbar_.setContainerVisible(show);
|
2013-10-30 14:46:03 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hide and empty the flyout.
|
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.hide = function() {
|
|
|
|
if (!this.isVisible()) {
|
|
|
|
return;
|
|
|
|
}
|
2017-02-02 14:17:43 -05:00
|
|
|
this.setVisible(false);
|
2013-10-30 14:46:03 -07:00
|
|
|
// Delete all the event listeners.
|
|
|
|
for (var x = 0, listen; listen = this.listeners_[x]; x++) {
|
|
|
|
Blockly.unbindEvent_(listen);
|
|
|
|
}
|
2014-09-08 14:26:52 -07:00
|
|
|
this.listeners_.length = 0;
|
2013-10-30 14:46:03 -07:00
|
|
|
if (this.reflowWrapper_) {
|
2016-02-11 21:40:33 -08:00
|
|
|
this.workspace_.removeChangeListener(this.reflowWrapper_);
|
2013-10-30 14:46:03 -07:00
|
|
|
this.reflowWrapper_ = null;
|
|
|
|
}
|
2014-09-08 14:26:52 -07:00
|
|
|
// Do NOT delete the blocks here. Wait until Flyout.show.
|
|
|
|
// https://neil.fraser.name/news/2014/08/09/
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show and populate the flyout.
|
|
|
|
* @param {!Array|string} xmlList List of blocks to show.
|
|
|
|
* Variables and procedures have a custom set of blocks.
|
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.show = function(xmlList) {
|
2017-02-02 14:17:43 -05:00
|
|
|
this.workspace_.setResizesEnabled(false);
|
2014-09-08 14:26:52 -07:00
|
|
|
this.hide();
|
2016-04-20 14:14:53 -07:00
|
|
|
this.clearOldBlocks_();
|
2013-10-30 14:46:03 -07:00
|
|
|
|
2015-10-25 22:20:08 -04:00
|
|
|
if (xmlList == Blockly.Variables.NAME_TYPE) {
|
|
|
|
// Special category for variables.
|
|
|
|
xmlList =
|
|
|
|
Blockly.Variables.flyoutCategory(this.workspace_.targetWorkspace);
|
|
|
|
} else if (xmlList == Blockly.Procedures.NAME_TYPE) {
|
|
|
|
// Special category for procedures.
|
|
|
|
xmlList =
|
|
|
|
Blockly.Procedures.flyoutCategory(this.workspace_.targetWorkspace);
|
|
|
|
}
|
|
|
|
|
2017-02-02 14:17:43 -05:00
|
|
|
this.setVisible(true);
|
2013-10-30 14:46:03 -07:00
|
|
|
// Create the blocks to be shown in this flyout.
|
2016-07-01 13:36:20 -07:00
|
|
|
var contents = [];
|
2013-10-30 14:46:03 -07:00
|
|
|
var gaps = [];
|
2016-02-02 19:53:52 -08:00
|
|
|
this.permanentlyDisabled_.length = 0;
|
2015-10-25 22:20:08 -04:00
|
|
|
for (var i = 0, xml; xml = xmlList[i]; i++) {
|
2016-06-21 13:42:03 -07:00
|
|
|
if (xml.tagName) {
|
|
|
|
var tagName = xml.tagName.toUpperCase();
|
2016-09-08 13:45:47 -07:00
|
|
|
var default_gap = this.horizontalLayout_ ? this.GAP_X : this.GAP_Y;
|
2016-06-21 13:42:03 -07:00
|
|
|
if (tagName == 'BLOCK') {
|
|
|
|
var curBlock = Blockly.Xml.domToBlock(xml, this.workspace_);
|
|
|
|
if (curBlock.disabled) {
|
|
|
|
// Record blocks that were initially disabled.
|
|
|
|
// Do not enable these blocks as a result of capacity filtering.
|
|
|
|
this.permanentlyDisabled_.push(curBlock);
|
|
|
|
}
|
2016-07-01 13:36:20 -07:00
|
|
|
contents.push({type: 'block', block: curBlock});
|
2016-06-21 13:42:03 -07:00
|
|
|
var gap = parseInt(xml.getAttribute('gap'), 10);
|
2016-09-08 13:45:47 -07:00
|
|
|
gaps.push(isNaN(gap) ? default_gap : gap);
|
2016-08-09 16:34:59 -07:00
|
|
|
} else if (xml.tagName.toUpperCase() == 'SEP') {
|
|
|
|
// Change the gap between two blocks.
|
|
|
|
// <sep gap="36"></sep>
|
|
|
|
// The default gap is 24, can be set larger or smaller.
|
2016-08-09 17:51:50 -07:00
|
|
|
// This overwrites the gap attribute on the previous block.
|
2016-08-09 16:34:59 -07:00
|
|
|
// Note that a deprecated method is to add a gap to a block.
|
|
|
|
// <block type="math_arithmetic" gap="8"></block>
|
|
|
|
var newGap = parseInt(xml.getAttribute('gap'), 10);
|
|
|
|
// Ignore gaps before the first block.
|
2016-08-09 17:51:50 -07:00
|
|
|
if (!isNaN(newGap) && gaps.length > 0) {
|
|
|
|
gaps[gaps.length - 1] = newGap;
|
2016-08-09 16:34:59 -07:00
|
|
|
} else {
|
2016-09-08 13:45:47 -07:00
|
|
|
gaps.push(default_gap);
|
2016-08-09 16:34:59 -07:00
|
|
|
}
|
2016-11-01 18:00:26 -07:00
|
|
|
} else if (tagName == 'BUTTON' || tagName == 'LABEL') {
|
|
|
|
// Labels behave the same as buttons, but are styled differently.
|
|
|
|
var isLabel = tagName == 'LABEL';
|
2016-07-01 15:51:59 -07:00
|
|
|
var curButton = new Blockly.FlyoutButton(this.workspace_,
|
2017-02-02 14:17:43 -05:00
|
|
|
this.targetWorkspace_, xml, isLabel);
|
2016-07-01 13:42:17 -07:00
|
|
|
contents.push({type: 'button', button: curButton});
|
2016-09-08 13:45:47 -07:00
|
|
|
gaps.push(default_gap);
|
2016-02-02 19:53:52 -08:00
|
|
|
}
|
2013-10-30 14:46:03 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-01 13:36:20 -07:00
|
|
|
this.layout_(contents, gaps);
|
2016-04-20 14:14:53 -07:00
|
|
|
|
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
|
|
|
// IE 11 is an incompetent browser that fails to fire mouseout events.
|
2016-04-20 14:14:53 -07:00
|
|
|
// When the mouse is over the background, deselect all blocks.
|
2016-05-25 12:53:42 -07:00
|
|
|
var deselectAll = function() {
|
2016-05-14 03:50:35 -07:00
|
|
|
var topBlocks = this.workspace_.getTopBlocks(false);
|
|
|
|
for (var i = 0, block; block = topBlocks[i]; i++) {
|
2016-04-20 14:14:53 -07:00
|
|
|
block.removeSelect();
|
|
|
|
}
|
|
|
|
};
|
2016-05-25 12:53:42 -07:00
|
|
|
|
2016-04-20 14:14:53 -07:00
|
|
|
this.listeners_.push(Blockly.bindEvent_(this.svgBackground_, 'mouseover',
|
|
|
|
this, deselectAll));
|
2013-10-30 14:46:03 -07:00
|
|
|
|
2016-04-20 14:14:53 -07:00
|
|
|
this.reflow();
|
|
|
|
|
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
|
|
|
// Correctly position the flyout's scrollbar when it opens.
|
|
|
|
this.position();
|
|
|
|
|
2016-04-20 14:14:53 -07:00
|
|
|
this.reflowWrapper_ = this.reflow.bind(this);
|
|
|
|
this.workspace_.addChangeListener(this.reflowWrapper_);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete blocks and background buttons from a previous showing of the flyout.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.clearOldBlocks_ = function() {
|
|
|
|
// Delete any blocks from a previous showing.
|
2016-04-14 13:21:35 -07:00
|
|
|
var oldBlocks = this.workspace_.getTopBlocks(false);
|
|
|
|
for (var i = 0, block; block = oldBlocks[i]; i++) {
|
2016-04-20 14:14:53 -07:00
|
|
|
if (block.workspace == this.workspace_) {
|
|
|
|
block.dispose(false, false);
|
2014-09-08 14:26:52 -07:00
|
|
|
}
|
2016-02-08 13:56:57 -08:00
|
|
|
}
|
2016-04-20 14:14:53 -07:00
|
|
|
// Delete any background buttons from a previous showing.
|
2016-06-21 13:42:03 -07:00
|
|
|
for (var j = 0, rect; rect = this.backgroundButtons_[j]; j++) {
|
2016-04-20 14:14:53 -07:00
|
|
|
goog.dom.removeNode(rect);
|
|
|
|
}
|
2016-06-21 13:42:03 -07:00
|
|
|
this.backgroundButtons_.length = 0;
|
|
|
|
|
|
|
|
for (var i = 0, button; button = this.buttons_[i]; i++) {
|
|
|
|
button.dispose();
|
|
|
|
}
|
2016-04-20 14:14:53 -07:00
|
|
|
this.buttons_.length = 0;
|
2013-10-30 14:46:03 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2016-02-08 13:56:57 -08:00
|
|
|
* Add listeners to a block that has been added to the flyout.
|
|
|
|
* @param {Element} root The root node of the SVG group the block is in.
|
|
|
|
* @param {!Blockly.Block} block The block to add listeners for.
|
|
|
|
* @param {!Element} rect The invisible rectangle under the block that acts as
|
|
|
|
* a button for that block.
|
|
|
|
* @private
|
2013-10-30 14:46:03 -07:00
|
|
|
*/
|
2016-02-08 13:56:57 -08:00
|
|
|
Blockly.Flyout.prototype.addBlockListeners_ = function(root, block, rect) {
|
2016-07-12 15:34:20 -07:00
|
|
|
if (this.autoClose) {
|
2016-11-01 18:00:26 -07:00
|
|
|
this.listeners_.push(Blockly.bindEventWithChecks_(root, 'mousedown', null,
|
2016-07-12 15:34:20 -07:00
|
|
|
this.createBlockFunc_(block)));
|
2016-11-01 18:00:26 -07:00
|
|
|
this.listeners_.push(Blockly.bindEventWithChecks_(rect, 'mousedown', null,
|
2016-07-12 15:34:20 -07:00
|
|
|
this.createBlockFunc_(block)));
|
|
|
|
} else {
|
2016-11-01 18:00:26 -07:00
|
|
|
this.listeners_.push(Blockly.bindEventWithChecks_(root, 'mousedown', null,
|
2016-07-12 15:34:20 -07:00
|
|
|
this.blockMouseDown_(block)));
|
2016-11-01 18:00:26 -07:00
|
|
|
this.listeners_.push(Blockly.bindEventWithChecks_(rect, 'mousedown', null,
|
2016-07-12 15:34:20 -07:00
|
|
|
this.blockMouseDown_(block)));
|
|
|
|
}
|
2016-04-20 14:14:53 -07:00
|
|
|
this.listeners_.push(Blockly.bindEvent_(root, 'mouseover', block,
|
|
|
|
block.addSelect));
|
|
|
|
this.listeners_.push(Blockly.bindEvent_(root, 'mouseout', block,
|
|
|
|
block.removeSelect));
|
|
|
|
this.listeners_.push(Blockly.bindEvent_(rect, 'mouseover', block,
|
|
|
|
block.addSelect));
|
|
|
|
this.listeners_.push(Blockly.bindEvent_(rect, 'mouseout', block,
|
|
|
|
block.removeSelect));
|
2013-10-30 14:46:03 -07:00
|
|
|
};
|
|
|
|
|
2016-10-04 14:40:10 -07:00
|
|
|
/**
|
|
|
|
* Actions to take when a block in the flyout is right-clicked.
|
|
|
|
* @param {!Event} e Event that triggered the right-click. Could originate from
|
|
|
|
* a long-press in a touch environment.
|
|
|
|
* @param {Blockly.BlockSvg} block The block that was clicked.
|
|
|
|
*/
|
|
|
|
Blockly.Flyout.blockRightClick_ = function(e, block) {
|
|
|
|
Blockly.terminateDrag_();
|
|
|
|
Blockly.WidgetDiv.hide(true);
|
|
|
|
Blockly.DropDownDiv.hideWithoutAnimation();
|
|
|
|
Blockly.hideChaff(true);
|
|
|
|
block.showContextMenu_(e);
|
|
|
|
// This was a right-click, so end the gesture immediately.
|
|
|
|
Blockly.Touch.clearTouchIdentifier();
|
|
|
|
};
|
|
|
|
|
2013-10-30 14:46:03 -07:00
|
|
|
/**
|
|
|
|
* Handle a mouse-down on an SVG block in a non-closing flyout.
|
2014-09-08 14:26:52 -07:00
|
|
|
* @param {!Blockly.Block} block The flyout block to copy.
|
2013-10-30 14:46:03 -07:00
|
|
|
* @return {!Function} Function to call when block is clicked.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.blockMouseDown_ = function(block) {
|
|
|
|
var flyout = this;
|
|
|
|
return function(e) {
|
2017-02-02 14:17:43 -05:00
|
|
|
if (Blockly.utils.isRightButton(e)) {
|
2016-10-04 14:40:10 -07:00
|
|
|
Blockly.Flyout.blockRightClick_(e, block);
|
2013-10-30 14:46:03 -07:00
|
|
|
} else {
|
2016-10-04 14:40:10 -07:00
|
|
|
flyout.dragMode_ = Blockly.DRAG_NONE;
|
|
|
|
Blockly.terminateDrag_();
|
|
|
|
Blockly.WidgetDiv.hide(true);
|
|
|
|
Blockly.DropDownDiv.hideWithoutAnimation();
|
|
|
|
Blockly.hideChaff();
|
2013-10-30 14:46:03 -07:00
|
|
|
// Left-click (or middle click)
|
|
|
|
// Record the current mouse position.
|
2016-04-11 14:21:55 -04:00
|
|
|
flyout.startDragMouseY_ = e.clientY;
|
|
|
|
flyout.startDragMouseX_ = e.clientX;
|
2014-01-15 03:00:09 -08:00
|
|
|
Blockly.Flyout.startDownEvent_ = e;
|
2013-10-30 14:46:03 -07:00
|
|
|
Blockly.Flyout.startBlock_ = block;
|
2016-08-16 14:27:21 -07:00
|
|
|
Blockly.Flyout.startFlyout_ = flyout;
|
2013-10-30 14:46:03 -07:00
|
|
|
Blockly.Flyout.onMouseUpWrapper_ = Blockly.bindEvent_(document,
|
2016-06-09 15:19:23 +02:00
|
|
|
'mouseup', flyout, flyout.onMouseUp_);
|
2014-09-08 14:26:52 -07:00
|
|
|
Blockly.Flyout.onMouseMoveBlockWrapper_ = Blockly.bindEvent_(document,
|
2016-06-09 15:19:23 +02:00
|
|
|
'mousemove', flyout, flyout.onMouseMoveBlock_);
|
2013-10-30 14:46:03 -07:00
|
|
|
}
|
|
|
|
// This event has been handled. No need to bubble up to the document.
|
|
|
|
e.stopPropagation();
|
2016-06-09 15:19:23 +02:00
|
|
|
e.preventDefault();
|
2013-10-30 14:46:03 -07:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2014-09-08 14:26:52 -07:00
|
|
|
/**
|
2016-02-08 13:56:57 -08:00
|
|
|
* Mouse down on the flyout background. Start a scroll drag.
|
2014-09-08 14:26:52 -07:00
|
|
|
* @param {!Event} e Mouse down event.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.onMouseDown_ = function(e) {
|
2016-04-23 12:59:38 -04:00
|
|
|
this.dragMode_ = Blockly.DRAG_FREE;
|
2017-02-02 14:17:43 -05:00
|
|
|
if (Blockly.utils.isRightButton(e)) {
|
2016-10-04 14:40:10 -07:00
|
|
|
// Don't start drags with right clicks.
|
|
|
|
Blockly.Touch.clearTouchIdentifier();
|
2014-09-08 14:26:52 -07:00
|
|
|
return;
|
|
|
|
}
|
2016-05-09 09:02:25 -07:00
|
|
|
Blockly.WidgetDiv.hide(true);
|
|
|
|
Blockly.DropDownDiv.hideWithoutAnimation();
|
2014-09-08 14:26:52 -07:00
|
|
|
Blockly.hideChaff(true);
|
2016-06-09 15:19:23 +02:00
|
|
|
this.dragMode_ = Blockly.DRAG_FREE;
|
2014-09-08 14:26:52 -07:00
|
|
|
this.startDragMouseY_ = e.clientY;
|
2016-02-08 13:56:57 -08:00
|
|
|
this.startDragMouseX_ = e.clientX;
|
2016-07-15 10:35:45 +02:00
|
|
|
Blockly.Flyout.startFlyout_ = this;
|
2014-09-08 14:26:52 -07:00
|
|
|
Blockly.Flyout.onMouseMoveWrapper_ = Blockly.bindEvent_(document, 'mousemove',
|
|
|
|
this, this.onMouseMove_);
|
|
|
|
Blockly.Flyout.onMouseUpWrapper_ = Blockly.bindEvent_(document, 'mouseup',
|
|
|
|
this, Blockly.Flyout.terminateDrag_);
|
|
|
|
// This event has been handled. No need to bubble up to the document.
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2016-05-03 15:43:29 -04:00
|
|
|
* Handle a mouse-up anywhere in the SVG pane. Is only registered when a
|
|
|
|
* block is clicked. We can't use mouseUp on the block since a fast-moving
|
|
|
|
* cursor can briefly escape the block before it catches up.
|
|
|
|
* @param {!Event} e Mouse up event.
|
|
|
|
* @private
|
|
|
|
*/
|
2016-09-08 13:45:47 -07:00
|
|
|
Blockly.Flyout.prototype.onMouseUp_ = function(/*e*/) {
|
2016-06-09 15:19:23 +02:00
|
|
|
if (!this.workspace_.isDragging()) {
|
2016-10-04 14:40:10 -07:00
|
|
|
// This was a click, not a drag. End the gesture.
|
|
|
|
Blockly.Touch.clearTouchIdentifier();
|
2016-11-07 14:10:36 -05:00
|
|
|
// A field is being edited if either the WidgetDiv or DropDownDiv is currently open.
|
|
|
|
// If a field is being edited, don't fire any click events.
|
|
|
|
var fieldEditing = Blockly.WidgetDiv.isVisible() || Blockly.DropDownDiv.isVisible();
|
2016-06-09 15:19:23 +02:00
|
|
|
if (this.autoClose) {
|
|
|
|
this.createBlockFunc_(Blockly.Flyout.startBlock_)(
|
|
|
|
Blockly.Flyout.startDownEvent_);
|
2016-11-07 14:10:36 -05:00
|
|
|
} else if (!fieldEditing) {
|
2016-06-09 15:19:23 +02:00
|
|
|
Blockly.Events.fire(
|
|
|
|
new Blockly.Events.Ui(Blockly.Flyout.startBlock_, 'click',
|
|
|
|
undefined, undefined));
|
2016-10-13 17:09:41 -04:00
|
|
|
Blockly.Events.fire(
|
|
|
|
new Blockly.Events.Ui(Blockly.Flyout.startBlock_, 'stackclick',
|
|
|
|
undefined, undefined));
|
2016-06-09 15:19:23 +02:00
|
|
|
}
|
2016-05-03 15:43:29 -04:00
|
|
|
}
|
|
|
|
Blockly.terminateDrag_();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle a mouse-move to vertically drag the flyout.
|
2014-09-08 14:26:52 -07:00
|
|
|
* @param {!Event} e Mouse move event.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.onMouseMove_ = function(e) {
|
2016-04-08 15:34:08 -07:00
|
|
|
var metrics = this.getMetrics_();
|
2016-02-08 13:56:57 -08:00
|
|
|
if (this.horizontalLayout_) {
|
2016-04-08 15:34:08 -07:00
|
|
|
if (metrics.contentWidth - metrics.viewWidth < 0) {
|
|
|
|
return;
|
|
|
|
}
|
2016-02-08 13:56:57 -08:00
|
|
|
var dx = e.clientX - this.startDragMouseX_;
|
|
|
|
this.startDragMouseX_ = e.clientX;
|
|
|
|
var x = metrics.viewLeft - dx;
|
2016-03-30 12:59:29 -07:00
|
|
|
x = goog.math.clamp(x, 0, metrics.contentWidth - metrics.viewWidth);
|
2016-02-08 13:56:57 -08:00
|
|
|
this.scrollbar_.set(x);
|
|
|
|
} else {
|
2016-04-08 15:34:08 -07:00
|
|
|
if (metrics.contentHeight - metrics.viewHeight < 0) {
|
|
|
|
return;
|
|
|
|
}
|
2016-02-08 13:56:57 -08:00
|
|
|
var dy = e.clientY - this.startDragMouseY_;
|
|
|
|
this.startDragMouseY_ = e.clientY;
|
|
|
|
var y = metrics.viewTop - dy;
|
2016-03-31 13:05:21 -07:00
|
|
|
y = goog.math.clamp(y, 0, metrics.contentHeight - metrics.viewHeight);
|
2016-02-08 13:56:57 -08:00
|
|
|
this.scrollbar_.set(y);
|
|
|
|
}
|
2014-09-08 14:26:52 -07:00
|
|
|
};
|
|
|
|
|
2013-10-30 14:46:03 -07:00
|
|
|
/**
|
|
|
|
* Mouse button is down on a block in a non-closing flyout. Create the block
|
|
|
|
* if the mouse moves beyond a small radius. This allows one to play with
|
|
|
|
* fields without instantiating blocks that instantly self-destruct.
|
|
|
|
* @param {!Event} e Mouse move event.
|
|
|
|
* @private
|
|
|
|
*/
|
2014-09-08 14:26:52 -07:00
|
|
|
Blockly.Flyout.prototype.onMouseMoveBlock_ = function(e) {
|
2013-10-30 14:46:03 -07:00
|
|
|
if (e.type == 'mousemove' && e.clientX <= 1 && e.clientY == 0 &&
|
|
|
|
e.button == 0) {
|
|
|
|
/* HACK:
|
|
|
|
Safari Mobile 6.0 and Chrome for Android 18.0 fire rogue mousemove events
|
|
|
|
on certain touch actions. Ignore events with these signatures.
|
|
|
|
This may result in a one-pixel blind spot in other browsers,
|
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
|
|
|
but this shouldn't be noticeable. */
|
2013-10-30 14:46:03 -07:00
|
|
|
e.stopPropagation();
|
|
|
|
return;
|
|
|
|
}
|
2016-10-13 17:09:41 -04:00
|
|
|
Blockly.Css.setCursor(Blockly.Css.Cursor.CLOSED);
|
2014-01-15 03:00:09 -08:00
|
|
|
var dx = e.clientX - Blockly.Flyout.startDownEvent_.clientX;
|
|
|
|
var dy = e.clientY - Blockly.Flyout.startDownEvent_.clientY;
|
2016-06-09 15:19:23 +02:00
|
|
|
var createBlock = this.determineDragIntention_(dx, dy);
|
2016-10-04 14:40:10 -07:00
|
|
|
Blockly.longStop_();
|
2016-04-23 12:59:38 -04:00
|
|
|
if (createBlock) {
|
2016-06-09 15:19:23 +02:00
|
|
|
this.createBlockFunc_(Blockly.Flyout.startBlock_)(
|
2014-09-08 14:26:52 -07:00
|
|
|
Blockly.Flyout.startDownEvent_);
|
2016-06-09 15:19:23 +02:00
|
|
|
} else if (this.dragMode_ == Blockly.DRAG_FREE) {
|
2016-06-29 12:26:11 +02:00
|
|
|
// Do a scroll.
|
2016-06-09 15:19:23 +02:00
|
|
|
this.onMouseMove_(e);
|
2016-04-11 14:21:55 -04:00
|
|
|
}
|
|
|
|
e.stopPropagation();
|
|
|
|
};
|
|
|
|
|
2016-04-23 12:59:38 -04:00
|
|
|
/**
|
|
|
|
* Determine the intention of a drag.
|
|
|
|
* Updates dragMode_ based on a drag delta and the current mode,
|
|
|
|
* and returns true if we should create a new block.
|
2016-06-29 12:26:11 +02:00
|
|
|
* @param {number} dx X delta of the drag.
|
|
|
|
* @param {number} dy Y delta of the drag.
|
2016-04-23 12:59:38 -04:00
|
|
|
* @return {boolean} True if a new block should be created.
|
2016-06-29 12:26:11 +02:00
|
|
|
* @private
|
2016-04-23 12:59:38 -04:00
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.determineDragIntention_ = function(dx, dy) {
|
|
|
|
if (this.dragMode_ == Blockly.DRAG_FREE) {
|
|
|
|
// Once in free mode, always stay in free mode and never create a block.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
var dragDistance = Math.sqrt(dx * dx + dy * dy);
|
2016-06-09 15:19:23 +02:00
|
|
|
if (dragDistance < this.DRAG_RADIUS) {
|
2016-06-29 12:26:11 +02:00
|
|
|
// Still within the sticky drag radius.
|
2016-04-23 12:59:38 -04:00
|
|
|
this.dragMode_ = Blockly.DRAG_STICKY;
|
|
|
|
return false;
|
|
|
|
} else {
|
2016-06-09 15:19:23 +02:00
|
|
|
if (this.isDragTowardWorkspace_(dx, dy) || !this.scrollbar_.isVisible()) {
|
2016-06-29 12:26:11 +02:00
|
|
|
// Immediately create a block.
|
2016-04-23 12:59:38 -04:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
// Immediately move to free mode - the drag is away from the workspace.
|
|
|
|
this.dragMode_ = Blockly.DRAG_FREE;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-10-30 14:46:03 -07:00
|
|
|
/**
|
|
|
|
* Create a copy of this block on the workspace.
|
|
|
|
* @param {!Blockly.Block} originBlock The flyout block to copy.
|
|
|
|
* @return {!Function} Function to call when block is clicked.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.createBlockFunc_ = function(originBlock) {
|
|
|
|
var flyout = this;
|
|
|
|
return function(e) {
|
2016-04-25 15:38:10 -04:00
|
|
|
// Hide drop-downs and animating WidgetDiv immediately
|
|
|
|
Blockly.WidgetDiv.hide(true);
|
|
|
|
Blockly.DropDownDiv.hideWithoutAnimation();
|
2017-02-02 14:17:43 -05:00
|
|
|
if (Blockly.utils.isRightButton(e)) {
|
2013-10-30 14:46:03 -07:00
|
|
|
// Right-click. Don't create a block, let the context menu show.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (originBlock.disabled) {
|
|
|
|
// Beyond capacity.
|
|
|
|
return;
|
|
|
|
}
|
2016-02-16 21:57:22 -08:00
|
|
|
Blockly.Events.disable();
|
2017-02-02 14:17:43 -05:00
|
|
|
// Disable workspace resizing. Reenable at the end of the drag. This avoids
|
|
|
|
// a spurious resize between creating the new block and placing it in the
|
|
|
|
// workspace.
|
|
|
|
flyout.targetWorkspace_.setResizesEnabled(false);
|
2016-04-27 14:21:22 +02:00
|
|
|
try {
|
|
|
|
var block = flyout.placeNewBlock_(originBlock);
|
|
|
|
} finally {
|
|
|
|
Blockly.Events.enable();
|
|
|
|
}
|
2016-03-03 17:48:54 -08:00
|
|
|
if (Blockly.Events.isEnabled()) {
|
|
|
|
Blockly.Events.setGroup(true);
|
2016-02-16 21:57:22 -08:00
|
|
|
Blockly.Events.fire(new Blockly.Events.Create(block));
|
|
|
|
}
|
2013-10-30 14:46:03 -07:00
|
|
|
if (flyout.autoClose) {
|
|
|
|
flyout.hide();
|
|
|
|
}
|
|
|
|
// Start a dragging operation on the new block.
|
|
|
|
block.onMouseDown_(e);
|
2016-03-29 08:36:11 -07:00
|
|
|
Blockly.dragMode_ = Blockly.DRAG_FREE;
|
|
|
|
block.setDragging_(true);
|
2016-04-07 22:58:05 -04:00
|
|
|
block.moveToDragSurface_();
|
2013-10-30 14:46:03 -07:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stop binding to the global mouseup and mousemove events.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Blockly.Flyout.terminateDrag_ = function() {
|
2016-08-16 14:27:21 -07:00
|
|
|
if (Blockly.Flyout.startFlyout_) {
|
2016-10-04 14:40:10 -07:00
|
|
|
// User was dragging the flyout background, and has stopped.
|
|
|
|
if (Blockly.Flyout.startFlyout_.dragMode_ == Blockly.DRAG_FREE) {
|
|
|
|
Blockly.Touch.clearTouchIdentifier();
|
|
|
|
}
|
2016-08-16 14:27:21 -07:00
|
|
|
Blockly.Flyout.startFlyout_.dragMode_ = Blockly.DRAG_NONE;
|
2016-10-04 14:40:10 -07:00
|
|
|
Blockly.Flyout.startFlyout_ = null;
|
2016-08-16 14:27:21 -07:00
|
|
|
}
|
2013-10-30 14:46:03 -07:00
|
|
|
if (Blockly.Flyout.onMouseUpWrapper_) {
|
|
|
|
Blockly.unbindEvent_(Blockly.Flyout.onMouseUpWrapper_);
|
|
|
|
Blockly.Flyout.onMouseUpWrapper_ = null;
|
|
|
|
}
|
2014-09-08 14:26:52 -07:00
|
|
|
if (Blockly.Flyout.onMouseMoveBlockWrapper_) {
|
|
|
|
Blockly.unbindEvent_(Blockly.Flyout.onMouseMoveBlockWrapper_);
|
|
|
|
Blockly.Flyout.onMouseMoveBlockWrapper_ = null;
|
|
|
|
}
|
2013-10-30 14:46:03 -07:00
|
|
|
if (Blockly.Flyout.onMouseMoveWrapper_) {
|
|
|
|
Blockly.unbindEvent_(Blockly.Flyout.onMouseMoveWrapper_);
|
|
|
|
Blockly.Flyout.onMouseMoveWrapper_ = null;
|
|
|
|
}
|
2014-01-15 03:00:09 -08:00
|
|
|
Blockly.Flyout.startDownEvent_ = null;
|
2013-10-30 14:46:03 -07:00
|
|
|
Blockly.Flyout.startBlock_ = null;
|
|
|
|
};
|
2016-02-08 13:56:57 -08:00
|
|
|
|
2016-04-18 17:29:48 -07:00
|
|
|
/**
|
|
|
|
* Reflow blocks and their buttons.
|
|
|
|
*/
|
2016-02-08 13:56:57 -08:00
|
|
|
Blockly.Flyout.prototype.reflow = function() {
|
2016-06-27 17:27:08 -07:00
|
|
|
if (this.reflowWrapper_) {
|
|
|
|
this.workspace_.removeChangeListener(this.reflowWrapper_);
|
|
|
|
}
|
2016-04-18 17:29:48 -07:00
|
|
|
var blocks = this.workspace_.getTopBlocks(false);
|
2016-09-08 16:54:10 -07:00
|
|
|
|
|
|
|
this.reflowInternal_(blocks);
|
2016-06-27 17:27:08 -07:00
|
|
|
if (this.reflowWrapper_) {
|
|
|
|
this.workspace_.addChangeListener(this.reflowWrapper_);
|
2016-02-08 13:56:57 -08:00
|
|
|
}
|
2016-04-27 11:33:09 -07:00
|
|
|
};
|