mirror of
https://github.com/google/blockly.git
synced 2026-01-10 02:17:09 +01:00
Clean up the sidebar file and remove unneeded code.
This commit is contained in:
@@ -28,33 +28,30 @@ blocklyApp.SidebarComponent = ng.core.Component({
|
||||
selector: 'blockly-sidebar',
|
||||
template: `
|
||||
<div class="blocklySidebarColumn">
|
||||
<div id="blockly-workspace-sidebar" (keydown)="onSidebarKeypress($event)">
|
||||
<span *ngFor="#buttonConfig of customSidebarButtons">
|
||||
<button id="{{buttonConfig.id || undefined}}"
|
||||
(click)="handleButtonClick(buttonConfig)"
|
||||
class="blocklySidebarButton">
|
||||
{{buttonConfig.text}}
|
||||
</button>
|
||||
</span>
|
||||
<button id="{{ID_FOR_ATTACH_TO_LINK_BUTTON}}"
|
||||
(click)="showToolboxModalForAttachToMarkedConnection()"
|
||||
[attr.disabled]="isAnyConnectionMarked() ? undefined : 'disabled'"
|
||||
[attr.aria-disabled]="!isAnyConnectionMarked()"
|
||||
class="blocklySidebarButton">
|
||||
{{'ATTACH_NEW_BLOCK_TO_LINK'|translate}}
|
||||
</button>
|
||||
<button id="{{ID_FOR_CREATE_NEW_GROUP_BUTTON}}"
|
||||
(click)="showToolboxModalForCreateNewGroup()"
|
||||
class="blocklySidebarButton">
|
||||
{{'CREATE_NEW_BLOCK_GROUP'|translate}}
|
||||
</button>
|
||||
<button id="clear-workspace" (click)="clearWorkspace()"
|
||||
[attr.disabled]="isWorkspaceEmpty() ? 'disabled' : undefined"
|
||||
[attr.aria-disabled]="isWorkspaceEmpty()"
|
||||
class="blocklySidebarButton">
|
||||
{{'ERASE_WORKSPACE'|translate}}
|
||||
</button>
|
||||
</div>
|
||||
<button *ngFor="#buttonConfig of customSidebarButtons"
|
||||
id="{{buttonConfig.id || undefined}}"
|
||||
(click)="buttonConfig.action()"
|
||||
class="blocklySidebarButton">
|
||||
{{buttonConfig.text}}
|
||||
</button>
|
||||
<button id="{{ID_FOR_ATTACH_TO_LINK_BUTTON}}"
|
||||
(click)="showToolboxModalForAttachToMarkedConnection()"
|
||||
[attr.disabled]="!isAnyConnectionMarked() ? 'disabled' : undefined"
|
||||
[attr.aria-disabled]="!isAnyConnectionMarked()"
|
||||
class="blocklySidebarButton">
|
||||
{{'ATTACH_NEW_BLOCK_TO_LINK'|translate}}
|
||||
</button>
|
||||
<button id="{{ID_FOR_CREATE_NEW_GROUP_BUTTON}}"
|
||||
(click)="showToolboxModalForCreateNewGroup()"
|
||||
class="blocklySidebarButton">
|
||||
{{'CREATE_NEW_BLOCK_GROUP'|translate}}
|
||||
</button>
|
||||
<button id="clear-workspace" (click)="clearWorkspace()"
|
||||
[attr.disabled]="isWorkspaceEmpty() ? 'disabled' : undefined"
|
||||
[attr.aria-disabled]="isWorkspaceEmpty()"
|
||||
class="blocklySidebarButton">
|
||||
{{'ERASE_WORKSPACE'|translate}}
|
||||
</button>
|
||||
</div>
|
||||
`,
|
||||
pipes: [blocklyApp.TranslatePipe]
|
||||
@@ -75,7 +72,6 @@ blocklyApp.SidebarComponent = ng.core.Component({
|
||||
this.customSidebarButtons =
|
||||
ACCESSIBLE_GLOBALS && ACCESSIBLE_GLOBALS.customSidebarButtons ?
|
||||
ACCESSIBLE_GLOBALS.customSidebarButtons : [];
|
||||
this.workspace = blocklyApp.workspace;
|
||||
|
||||
this.blockConnectionService = blockConnectionService;
|
||||
this.toolboxModalService = toolboxModalService;
|
||||
@@ -89,19 +85,13 @@ blocklyApp.SidebarComponent = ng.core.Component({
|
||||
isAnyConnectionMarked: function() {
|
||||
return this.blockConnectionService.isAnyConnectionMarked();
|
||||
},
|
||||
handleButtonClick: function(buttonConfig) {
|
||||
buttonConfig.action();
|
||||
},
|
||||
clearWorkspace: function() {
|
||||
this.workspace.clear();
|
||||
document.getElementById(this.ID_FOR_CREATE_NEW_GROUP_BUTTON).focus();
|
||||
},
|
||||
onSidebarKeypress: function(e) {
|
||||
this.treeService.onSidebarKeypress(e, document.activeElement.id);
|
||||
},
|
||||
isWorkspaceEmpty: function() {
|
||||
return this.utilsService.isWorkspaceEmpty();
|
||||
},
|
||||
clearWorkspace: function() {
|
||||
blocklyApp.workspace.clear();
|
||||
document.getElementById(this.ID_FOR_CREATE_NEW_GROUP_BUTTON).focus();
|
||||
},
|
||||
showToolboxModalForAttachToMarkedConnection: function() {
|
||||
this.toolboxModalService.showToolboxModalForAttachToMarkedConnection(
|
||||
this.ID_FOR_ATTACH_TO_LINK_BUTTON);
|
||||
|
||||
@@ -169,17 +169,6 @@ blocklyApp.TreeService = ng.core.Class({
|
||||
that.setActiveDesc(blockId + 'blockRoot', domNode.id);
|
||||
}, 100);
|
||||
},
|
||||
onSidebarKeypress: function(e, treeId) {
|
||||
if (e.keyCode == 9) {
|
||||
// Tab key.
|
||||
var destinationTreeId =
|
||||
e.shiftKey ? this.getIdOfPreviousTree_(treeId) :
|
||||
this.getIdOfNextTree_(treeId);
|
||||
if (destinationTreeId) {
|
||||
this.notifyUserAboutCurrentTree_(destinationTreeId);
|
||||
}
|
||||
}
|
||||
},
|
||||
getNextActiveDescWhenBlockIsDeleted: function(blockRootNode) {
|
||||
// Go up a level, if possible.
|
||||
var nextNode = blockRootNode.parentNode;
|
||||
|
||||
@@ -35,7 +35,8 @@ blocklyApp.WorkspaceComponent = ng.core.Component({
|
||||
tabindex="0" role="tree" class="blocklyTree blocklyWorkspaceFocusTarget"
|
||||
[attr.aria-activedescendant]="getActiveDescId(tree.id)"
|
||||
[attr.aria-labelledby]="workspaceTitle.id"
|
||||
(keydown)="onKeypress($event, tree)">
|
||||
(keydown)="onKeypress($event, tree)"
|
||||
(focus)="speakLocation(i)">
|
||||
<blockly-workspace-tree [level]="0" [block]="block" [tree]="tree" [isTopLevel]="true">
|
||||
</blockly-workspace-tree>
|
||||
</ol>
|
||||
@@ -58,12 +59,15 @@ blocklyApp.WorkspaceComponent = ng.core.Component({
|
||||
})
|
||||
.Class({
|
||||
constructor: [
|
||||
blocklyApp.TreeService, blocklyApp.ToolboxModalService,
|
||||
function(_treeService, _toolboxModalService) {
|
||||
this.treeService = _treeService;
|
||||
this.toolboxModalService = _toolboxModalService;
|
||||
this.workspace = blocklyApp.workspace;
|
||||
blocklyApp.NotificationsService,
|
||||
blocklyApp.ToolboxModalService,
|
||||
blocklyApp.TreeService,
|
||||
function(notificationsService, toolboxModalService, treeService) {
|
||||
this.notificationsService = notificationsService;
|
||||
this.toolboxModalService = toolboxModalService;
|
||||
this.treeService = treeService;
|
||||
|
||||
this.workspace = blocklyApp.workspace;
|
||||
this.ID_FOR_EMPTY_WORKSPACE_BTN = 'blocklyEmptyWorkspaceButton';
|
||||
}
|
||||
],
|
||||
@@ -76,5 +80,10 @@ blocklyApp.WorkspaceComponent = ng.core.Component({
|
||||
showToolboxModalForCreateNewGroup: function() {
|
||||
this.toolboxModalService.showToolboxModalForCreateNewGroup(
|
||||
this.ID_FOR_EMPTY_WORKSPACE_BTN);
|
||||
},
|
||||
speakLocation: function(index) {
|
||||
this.notificationsService.speak(
|
||||
'Now in workspace group ' + (index + 1) + ' of ' +
|
||||
this.workspace.topBlocks_.length);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user