From d1886572d087a47deb6e3668b2f15dc014c5bdb1 Mon Sep 17 00:00:00 2001 From: picklesrus Date: Mon, 4 Dec 2017 10:36:47 -0800 Subject: [PATCH] =?UTF-8?q?Fix=20#1487=20and=20only=20add=20the=20delete?= =?UTF-8?q?=20cursor=20if=20the=20block=20is=20not=20deletabl=E2=80=A6=20(?= =?UTF-8?q?#1491)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix #1487 and only add the delete cursor if the block is not deletable. Also add a grab cursor when it is not deletable so the cursor keeps the grab hand when over the toolbox. This changes the toolbox api slightly, but the methods it touches are @package so it should be okay. --- core/block_dragger.js | 8 ++++++-- core/css.js | 6 ++++++ core/toolbox.js | 14 ++++++++------ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/core/block_dragger.js b/core/block_dragger.js index 0ba1749f0..c6a0a3b1a 100644 --- a/core/block_dragger.js +++ b/core/block_dragger.js @@ -168,7 +168,9 @@ Blockly.BlockDragger.prototype.startBlockDrag = function(currentDragDeltaXY) { this.draggingBlock_.moveToDragSurface_(); if (this.workspace_.toolbox_) { - this.workspace_.toolbox_.addDeleteStyle(); + var style = this.draggingBlock_.isDeletable() ? 'blocklyToolboxDelete' : + 'blocklyToolboxGrab'; + this.workspace_.toolbox_.addStyle(style); } }; @@ -224,7 +226,9 @@ Blockly.BlockDragger.prototype.endBlockDrag = function(e, currentDragDeltaXY) { this.workspace_.setResizesEnabled(true); if (this.workspace_.toolbox_) { - this.workspace_.toolbox_.removeDeleteStyle(); + var style = this.draggingBlock_.isDeletable() ? 'blocklyToolboxDelete' : + 'blocklyToolboxGrab'; + this.workspace_.toolbox_.removeStyle(style); } Blockly.Events.setGroup(false); }; diff --git a/core/css.js b/core/css.js index d5074b0e3..21fd9805e 100644 --- a/core/css.js +++ b/core/css.js @@ -253,6 +253,12 @@ Blockly.Css.CONTENT = [ 'cursor: url("<<>>/handdelete.cur"), auto;', '}', + '.blocklyToolboxGrab {', + 'cursor: url("<<>>/handclosed.cur"), auto;', + 'cursor: grabbing;', + 'cursor: -webkit-grabbing;', + '}', + '.blocklyDragging>.blocklyPath,', '.blocklyDragging>.blocklyPathLight {', 'fill-opacity: .8;', diff --git a/core/toolbox.js b/core/toolbox.js index 5531f1c4a..0a07fddba 100644 --- a/core/toolbox.js +++ b/core/toolbox.js @@ -422,21 +422,23 @@ Blockly.Toolbox.prototype.clearSelection = function() { }; /** - * Adds styles on the toolbox indicating blocks will be deleted. + * Adds a style on the toolbox. Usually used to change the cursor. + * @param {string} style The name of the class to add. * @package */ -Blockly.Toolbox.prototype.addDeleteStyle = function() { +Blockly.Toolbox.prototype.addStyle = function(style) { Blockly.utils.addClass(/** @type {!Element} */ (this.HtmlDiv), - 'blocklyToolboxDelete'); + style); }; /** - * Remove styles from the toolbox that indicate blocks will be deleted. + * Removes a style from the toolbox. Usually used to change the cursor. + * @param {string} style The name of the class to remove. * @package */ -Blockly.Toolbox.prototype.removeDeleteStyle = function() { +Blockly.Toolbox.prototype.removeStyle = function(style) { Blockly.utils.removeClass(/** @type {!Element} */ (this.HtmlDiv), - 'blocklyToolboxDelete'); + style); }; /**