Commit ba67c9a7 authored by Evan W. Patton's avatar Evan W. Patton Committed by Jeffrey Schiller

Enhancement/remove from backpack#911 (#1273)

* Add menu option to remove block stack from Backpack

Change-Id: Iada620f2d8a425367faf5a05d15f43236fede95d
parent 112a65a0
...@@ -371,6 +371,35 @@ Blockly.Backpack.prototype.addToBackpack = function(block, store) { ...@@ -371,6 +371,35 @@ Blockly.Backpack.prototype.addToBackpack = function(block, store) {
}; };
/**
* Remove the top-level blocks with the given IDs from the backpack.
* @param {!Array.<string>} ids The block IDs to be removed
*/
Blockly.Backpack.prototype.removeFromBackpack = function(ids) {
var p = this;
this.getContents(function(/** @type {string[]} */ contents) {
if (contents && contents.length) {
for (var i = 0; i < contents.length; i++) {
var xml = Blockly.Xml.textToDom(contents[i]);
var blockID = xml.firstElementChild.getAttribute("id");
if (ids.indexOf(blockID) >= 0) {
contents.splice(i, 1);
i--;
}
}
p.setContents(contents, true);
if (contents.length === 0) {
p.shrink();
}
if (p.flyout_.isVisible()) {
p.isAdded = true;
p.openBackpack();
p.isAdded = false;
}
}
});
};
Blockly.Backpack.prototype.hide = function() { Blockly.Backpack.prototype.hide = function() {
this.flyout_.hide(); this.flyout_.hide();
}; };
...@@ -576,6 +605,7 @@ Blockly.Backpack.prototype.count = function() { ...@@ -576,6 +605,7 @@ Blockly.Backpack.prototype.count = function() {
/** /**
* Get the contents of the Backpack. * Get the contents of the Backpack.
* @param {function(string[])} callback The callback to asynchronously receive the backpack contents
* @returns {string[]} Backpack contents encoded as an array of XML strings. * @returns {string[]} Backpack contents encoded as an array of XML strings.
*/ */
Blockly.Backpack.prototype.getContents = function(callback) { Blockly.Backpack.prototype.getContents = function(callback) {
......
...@@ -107,6 +107,20 @@ Blockly.Block.prototype.customContextMenu = function(options) { ...@@ -107,6 +107,20 @@ Blockly.Block.prototype.customContextMenu = function(options) {
} }
}; };
Blockly.Block.prototype.flyoutCustomContextMenu = function(menuOptions) {
// Option for the backpack.
if (this.workspace.isBackpack) {
var id = this.id;
var removeOption = {enabled: true};
removeOption.text = Blockly.Msg.REMOVE_FROM_BACKPACK;
var backpack = this.workspace.targetWorkspace.backpack_;
removeOption.callback = function() {
backpack.removeFromBackpack([id]);
};
menuOptions.splice(menuOptions.length - 1, 0, removeOption);
}
};
/* [Added by paulmw in patch 15] /* [Added by paulmw in patch 15]
There are three ways that you can change how lexical variables There are three ways that you can change how lexical variables
are handled: are handled:
......
...@@ -71,6 +71,7 @@ Blockly.Msg.en.switch_language_to_english = { ...@@ -71,6 +71,7 @@ Blockly.Msg.en.switch_language_to_english = {
Blockly.Msg.SORT_C = 'Sort Blocks by Category'; Blockly.Msg.SORT_C = 'Sort Blocks by Category';
Blockly.Msg.COPY_TO_BACKPACK = 'Add to Backpack'; Blockly.Msg.COPY_TO_BACKPACK = 'Add to Backpack';
Blockly.Msg.COPY_ALLBLOCKS = 'Copy All Blocks to Backpack'; Blockly.Msg.COPY_ALLBLOCKS = 'Copy All Blocks to Backpack';
Blockly.Msg.REMOVE_FROM_BACKPACK = 'Remove from Backpack';
Blockly.Msg.BACKPACK_GET = 'Paste All Blocks from Backpack'; Blockly.Msg.BACKPACK_GET = 'Paste All Blocks from Backpack';
Blockly.Msg.BACKPACK_EMPTY = 'Empty the Backpack'; Blockly.Msg.BACKPACK_EMPTY = 'Empty the Backpack';
Blockly.Msg.BACKPACK_CONFIRM_EMPTY = 'Are you sure you want to empty the backpack?'; Blockly.Msg.BACKPACK_CONFIRM_EMPTY = 'Are you sure you want to empty the backpack?';
......
Subproject commit 5f6bfe0a92a85aba32d3ed6d03c9c24cfe38fd1b Subproject commit 4ac45d5cd608e7c25c6ab9fb2549096cbb870e98
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment