mirror of
https://github.com/google/blockly.git
synced 2026-01-09 10:00:09 +01:00
Refactor getBlockDescription() into a separate method in UtilsService.
This commit is contained in:
@@ -24,12 +24,13 @@
|
||||
|
||||
blocklyApp.ClipboardService = ng.core
|
||||
.Class({
|
||||
constructor: function() {
|
||||
constructor: [blocklyApp.UtilsService, function(_utilsService) {
|
||||
this.clipboardBlockXml_ = null;
|
||||
this.clipboardBlockSuperiorConnection_ = null;
|
||||
this.clipboardBlockNextConnection_ = null;
|
||||
this.markedConnection_ = null;
|
||||
},
|
||||
this.utilsService = _utilsService;
|
||||
}],
|
||||
areConnectionsCompatible_: function(blockConnection, connection) {
|
||||
// Check that both connections exist, that it's the right kind of
|
||||
// connection, and that the types match.
|
||||
@@ -85,18 +86,19 @@ blocklyApp.ClipboardService = ng.core
|
||||
alert(Blockly.Msg.MARKED_SPOT_MSG);
|
||||
},
|
||||
cut: function(block) {
|
||||
var blockSummary = block.toString();
|
||||
this.copy(block, false);
|
||||
block.dispose(true);
|
||||
alert(Blockly.Msg.CUT_BLOCK_MSG + blockSummary);
|
||||
},
|
||||
copy: function(block, announce) {
|
||||
this.clipboardBlockXml_ = Blockly.Xml.blockToDom(block);
|
||||
this.clipboardBlockSuperiorConnection_ = block.outputConnection ||
|
||||
block.previousConnection;
|
||||
this.clipboardBlockNextConnection_ = block.nextConnection;
|
||||
|
||||
if (announce) {
|
||||
alert(Blockly.Msg.COPIED_BLOCK_MSG + block.toString());
|
||||
alert(
|
||||
Blockly.Msg.COPIED_BLOCK_MSG +
|
||||
utilsService.getBlockDescription(block));
|
||||
}
|
||||
},
|
||||
pasteFromClipboard: function(connection) {
|
||||
@@ -114,7 +116,7 @@ blocklyApp.ClipboardService = ng.core
|
||||
}
|
||||
alert(
|
||||
Blockly.Msg.PASTED_BLOCK_FROM_CLIPBOARD_MSG +
|
||||
reconstitutedBlock.toString());
|
||||
utilsService.getBlockDescription(reconstitutedBlock));
|
||||
return reconstitutedBlock.id;
|
||||
},
|
||||
pasteToMarkedConnection: function(block) {
|
||||
|
||||
@@ -32,7 +32,7 @@ blocklyApp.ToolboxTreeComponent = ng.core
|
||||
[ngClass]="{blocklyHasChildren: displayBlockMenu || block.inputList.length > 0, blocklyActiveDescendant: index == 0 && noCategories}"
|
||||
[attr.aria-labelledBy]="generateAriaLabelledByAttr('blockly-block-summary', idMap['blockSummaryLabel'])"
|
||||
[attr.aria-level]="level">
|
||||
<label #blockSummaryLabel [id]="idMap['blockSummaryLabel']">{{block.toString()}}</label>
|
||||
<label #blockSummaryLabel [id]="idMap['blockSummaryLabel']">{{getBlockDescription()}}</label>
|
||||
<ol role="group" *ngIf="displayBlockMenu || block.inputList.length > 0">
|
||||
<li #listItem class="blocklyHasChildren" [id]="idMap['listItem']"
|
||||
[attr.aria-labelledBy]="generateAriaLabelledByAttr('blockly-block-menu', idMap['blockSummaryLabel'])"
|
||||
@@ -132,6 +132,9 @@ blocklyApp.ToolboxTreeComponent = ng.core
|
||||
this.idMap['parentList'] = this.utilsService.generateUniqueId();
|
||||
}
|
||||
},
|
||||
getBlockDescription: function() {
|
||||
return this.utilsService.getBlockDescription(this.block);
|
||||
},
|
||||
generateAriaLabelledByAttr: function(mainLabel, secondLabel, isDisabled) {
|
||||
return this.utilsService.generateAriaLabelledByAttr(
|
||||
mainLabel, secondLabel, isDisabled);
|
||||
@@ -142,7 +145,7 @@ blocklyApp.ToolboxTreeComponent = ng.core
|
||||
copyToWorkspace: function() {
|
||||
var xml = Blockly.Xml.blockToDom(this.block);
|
||||
Blockly.Xml.domToBlock(blocklyApp.workspace, xml);
|
||||
alert('Added block to workspace: ' + this.block.toString());
|
||||
alert('Added block to workspace: ' + this.getBlockDescription());
|
||||
},
|
||||
copyToClipboard: function() {
|
||||
this.clipboardService.copy(this.block, true);
|
||||
@@ -152,7 +155,7 @@ blocklyApp.ToolboxTreeComponent = ng.core
|
||||
// - Put the block on the destination tree.
|
||||
// - Change the current tree-level focus to the destination tree, and the
|
||||
// screenreader focus for the destination tree to the block just moved.
|
||||
var blockDescription = this.block.toString();
|
||||
var blockDescription = this.getBlockDescription();
|
||||
|
||||
var newBlockId = this.clipboardService.pasteToMarkedConnection(
|
||||
this.block);
|
||||
|
||||
@@ -65,5 +65,8 @@ blocklyApp.UtilsService = ng.core
|
||||
} else {
|
||||
return Blockly.Msg.VALUE;
|
||||
}
|
||||
},
|
||||
getBlockDescription: function(block) {
|
||||
return block.toString();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -31,7 +31,7 @@ blocklyApp.WorkspaceTreeComponent = ng.core
|
||||
<li [id]="idMap['blockRoot']" role="treeitem" class="blocklyHasChildren"
|
||||
[attr.aria-labelledBy]="generateAriaLabelledByAttr('blockly-block-summary', idMap['blockSummary'])"
|
||||
[attr.aria-level]="level">
|
||||
<label [id]="idMap['blockSummary']">{{block.toString()}}</label>
|
||||
<label [id]="idMap['blockSummary']">{{getBlockDescription()}}</label>
|
||||
|
||||
<ol role="group">
|
||||
<li [id]="idMap['listItem']" class="blocklyHasChildren" role="treeitem"
|
||||
@@ -100,6 +100,9 @@ blocklyApp.WorkspaceTreeComponent = ng.core
|
||||
this.treeService = _treeService;
|
||||
this.utilsService = _utilsService;
|
||||
}],
|
||||
getBlockDescription: function() {
|
||||
return this.utilsService.getBlockDescription(this.block);
|
||||
},
|
||||
isIsolatedTopLevelBlock_: function(block) {
|
||||
// Returns whether the given block is at the top level, and has no
|
||||
// siblings.
|
||||
@@ -136,13 +139,17 @@ blocklyApp.WorkspaceTreeComponent = ng.core
|
||||
}
|
||||
},
|
||||
cutBlock_: function() {
|
||||
var blockDescription = this.getBlockDescription();
|
||||
|
||||
var that = this;
|
||||
this.removeBlockAndSetFocus_(this.block, function() {
|
||||
that.clipboardService.cut(that.block);
|
||||
});
|
||||
|
||||
alert(Blockly.Msg.CUT_BLOCK_MSG + blockDescription);
|
||||
},
|
||||
deleteBlock_: function() {
|
||||
var blockDescription = this.block.toString();
|
||||
var blockDescription = this.getBlockDescription();
|
||||
|
||||
var that = this;
|
||||
this.removeBlockAndSetFocus_(this.block, function() {
|
||||
@@ -187,7 +194,7 @@ blocklyApp.WorkspaceTreeComponent = ng.core
|
||||
// screenreader focus for that tree.
|
||||
// - Change the current tree-level focus to the destination tree, and the
|
||||
// screenreader focus for the destination tree to the block just moved.
|
||||
var blockDescription = this.block.toString();
|
||||
var blockDescription = this.getBlockDescription();
|
||||
|
||||
var newBlockId = this.clipboardService.pasteToMarkedConnection(
|
||||
this.block);
|
||||
|
||||
Reference in New Issue
Block a user