When the workspace is empty, make it easy for the user to add a new group of blocks to it.

This commit is contained in:
Sean Lip
2016-11-22 15:53:45 -08:00
parent a66d274169
commit 5c79d2f36f
4 changed files with 131 additions and 102 deletions

View File

@@ -98,63 +98,9 @@ blocklyApp.SidebarComponent = ng.core.Component({
return this.utilsService.isWorkspaceEmpty();
},
showToolboxModalForAttachToMarkedSpot: function() {
var that = this;
this.toolboxModalService.showModal(function(opt_block) {
if (!opt_block) {
return;
}
var block = opt_block;
var blockDescription = that.utilsService.getBlockDescription(block);
// Clean up the active desc for the destination tree.
var oldDestinationTreeId = that.treeService.getTreeIdForBlock(
that.clipboardService.getMarkedConnectionBlock().id);
that.treeService.clearActiveDesc(oldDestinationTreeId);
var newBlockId = that.clipboardService.pasteToMarkedConnection(block);
// Invoke a digest cycle, so that the DOM settles.
setTimeout(function() {
that.treeService.focusOnBlock(newBlockId);
var newDestinationTreeId = that.treeService.getTreeIdForBlock(
newBlockId);
if (newDestinationTreeId != oldDestinationTreeId) {
// It is possible for the tree ID for the pasted block to change
// after the paste operation, e.g. when inserting a block between two
// existing blocks that are joined together. In this case, we need to
// also reset the active desc for the old destination tree.
that.treeService.initActiveDesc(oldDestinationTreeId);
}
that.notificationsService.setStatusMessage(
blockDescription + ' connected. ' +
'Now on copied block in workspace.');
});
}, function(block) {
return that.clipboardService.canBeCopiedToMarkedConnection(block);
});
this.toolboxModalService.showToolboxModalForAttachToMarkedSpot();
},
showToolboxModalForCreateNewGroup: function() {
var that = this;
this.toolboxModalService.showModal(function(opt_block) {
if (!opt_block) {
return;
}
var block = opt_block;
var blockDescription = that.utilsService.getBlockDescription(block);
var xml = Blockly.Xml.blockToDom(block);
var newBlockId = Blockly.Xml.domToBlock(blocklyApp.workspace, xml).id;
setTimeout(function() {
that.treeService.focusOnBlock(newBlockId);
that.notificationsService.setStatusMessage(
blockDescription + ' added to workspace. ' +
'Now on added block in workspace.');
});
}, function(block) {
return true;
});
this.toolboxModalService.showToolboxModalForCreateNewGroup();
}
});