From ab8a11784da0eaf968fa36fbba389884cebe614c Mon Sep 17 00:00:00 2001 From: Sam El-Husseini Date: Thu, 25 Feb 2021 17:28:11 -0500 Subject: [PATCH] Fix event related missing requires (#4656) * Fix event related missing requires --- core/block.js | 16 +++++++++------- core/block_dragger.js | 11 ++++++----- core/block_svg.js | 9 ++++++--- core/blockly.js | 3 +++ core/bubble_dragger.js | 2 +- core/comment.js | 10 ++++++---- core/connection.js | 4 ++-- core/contextmenu.js | 3 ++- core/contextmenu_items.js | 1 + core/events/block_events.js | 5 ++--- core/events/events.js | 13 +++++++++++-- core/events/ws_comment_events.js | 3 +-- core/field.js | 2 +- core/field_dropdown.js | 1 - core/field_textinput.js | 2 +- core/flyout_base.js | 7 +++++-- core/gesture.js | 6 +++--- core/inject.js | 1 + core/keyboard_nav/basic_cursor.js | 1 + core/keyboard_nav/cursor.js | 1 + core/metrics_manager.js | 1 + core/mutator.js | 6 +++--- core/procedures.js | 2 +- core/renderers/common/marker_svg.js | 3 ++- core/scrollbar.js | 1 + core/toolbox/toolbox.js | 2 +- core/trashcan.js | 5 +++-- core/utils/toolbox.js | 1 + core/variable_map.js | 9 ++++++--- core/variable_model.js | 3 ++- core/warning.js | 4 ++-- core/workspace.js | 1 + core/workspace_comment.js | 12 +++++++----- core/workspace_comment_svg.js | 11 +++++++---- core/workspace_svg.js | 9 ++++++--- core/xml.js | 12 ++++++------ core/zoom_controls.js | 4 +++- 37 files changed, 116 insertions(+), 71 deletions(-) diff --git a/core/block.js b/core/block.js index a00cc911d..65f4664d9 100644 --- a/core/block.js +++ b/core/block.js @@ -226,7 +226,8 @@ Blockly.Block = function(workspace, prototypeName, opt_id) { // Fire a create event. if (Blockly.Events.isEnabled()) { - Blockly.Events.fire(new Blockly.Events.BlockCreate(this)); + Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.BLOCK_CREATE))( + this)); } } finally { @@ -365,7 +366,8 @@ Blockly.Block.prototype.dispose = function(healStack) { this.unplug(healStack); if (Blockly.Events.isEnabled()) { - Blockly.Events.fire(new Blockly.Events.BlockDelete(this)); + Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.BLOCK_DELETE))( + this)); } Blockly.Events.disable(); @@ -1217,7 +1219,7 @@ Blockly.Block.prototype.setOutput = function(newBoolean, opt_check) { */ Blockly.Block.prototype.setInputsInline = function(newBoolean) { if (this.inputsInline != newBoolean) { - Blockly.Events.fire(new Blockly.Events.BlockChange( + Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.BLOCK_CHANGE))( this, 'inline', null, this.inputsInline, newBoolean)); this.inputsInline = newBoolean; } @@ -1280,7 +1282,7 @@ Blockly.Block.prototype.isEnabled = function() { */ Blockly.Block.prototype.setEnabled = function(enabled) { if (this.isEnabled() != enabled) { - Blockly.Events.fire(new Blockly.Events.BlockChange( + Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.BLOCK_CHANGE))( this, 'disabled', null, this.disabled, !enabled)); this.disabled = !enabled; } @@ -1317,7 +1319,7 @@ Blockly.Block.prototype.isCollapsed = function() { */ Blockly.Block.prototype.setCollapsed = function(collapsed) { if (this.collapsed_ != collapsed) { - Blockly.Events.fire(new Blockly.Events.BlockChange( + Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.BLOCK_CHANGE))( this, 'collapsed', null, this.collapsed_, collapsed)); this.collapsed_ = collapsed; } @@ -1984,7 +1986,7 @@ Blockly.Block.prototype.setCommentText = function(text) { if (this.commentModel.text == text) { return; } - Blockly.Events.fire(new Blockly.Events.BlockChange( + Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.BLOCK_CHANGE))( this, 'comment', null, this.commentModel.text, text)); this.commentModel.text = text; this.comment = text; // For backwards compatibility. @@ -2027,7 +2029,7 @@ Blockly.Block.prototype.moveBy = function(dx, dy) { if (this.parentBlock_) { throw Error('Block has parent.'); } - var event = new Blockly.Events.BlockMove(this); + var event = new (Blockly.Events.get(Blockly.Events.BLOCK_MOVE))(this); this.xy_.translate(dx, dy); event.recordNew(); Blockly.Events.fire(event); diff --git a/core/block_dragger.js b/core/block_dragger.js index 1b110e955..d7a539d4d 100644 --- a/core/block_dragger.js +++ b/core/block_dragger.js @@ -187,8 +187,8 @@ Blockly.BlockDragger.prototype.startBlockDrag = function(currentDragDeltaXY, * @private */ Blockly.BlockDragger.prototype.fireDragStartEvent_ = function() { - var event = new Blockly.Events.BlockDrag(this.draggingBlock_, true, - this.draggingBlock_.getDescendants(false)); + var event = new (Blockly.Events.get(Blockly.Events.BLOCK_DRAG))( + this.draggingBlock_, true, this.draggingBlock_.getDescendants(false)); Blockly.Events.fire(event); }; @@ -264,8 +264,8 @@ Blockly.BlockDragger.prototype.endBlockDrag = function(e, currentDragDeltaXY) { * @private */ Blockly.BlockDragger.prototype.fireDragEndEvent_ = function() { - var event = new Blockly.Events.BlockDrag(this.draggingBlock_, false, - this.draggingBlock_.getDescendants(false)); + var event = new (Blockly.Events.get(Blockly.Events.BLOCK_DRAG))( + this.draggingBlock_, false, this.draggingBlock_.getDescendants(false)); Blockly.Events.fire(event); }; @@ -274,7 +274,8 @@ Blockly.BlockDragger.prototype.fireDragEndEvent_ = function() { * @private */ Blockly.BlockDragger.prototype.fireMoveEvent_ = function() { - var event = new Blockly.Events.BlockMove(this.draggingBlock_); + var event = new (Blockly.Events.get(Blockly.Events.BLOCK_MOVE))( + this.draggingBlock_); event.oldCoordinate = this.startXY_; event.recordNew(); Blockly.Events.fire(event); diff --git a/core/block_svg.js b/core/block_svg.js index 55c8673df..49b68ff23 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -35,6 +35,7 @@ goog.require('Blockly.utils.dom'); goog.require('Blockly.utils.object'); goog.require('Blockly.utils.Rect'); goog.require('Blockly.utils.userAgent'); +goog.require('Blockly.Xml'); goog.requireType('Blockly.blockRendering.Debug'); goog.requireType('Blockly.Comment'); @@ -310,7 +311,8 @@ Blockly.BlockSvg.prototype.select = function() { Blockly.Events.enable(); } } - var event = new Blockly.Events.Selected(oldId, this.id, this.workspace.id); + var event = new (Blockly.Events.get(Blockly.Events.SELECTED))(oldId, this.id, + this.workspace.id); Blockly.Events.fire(event); Blockly.selected = this; this.addSelect(); @@ -323,7 +325,8 @@ Blockly.BlockSvg.prototype.unselect = function() { if (Blockly.selected != this) { return; } - var event = new Blockly.Events.Selected(this.id, null, this.workspace.id); + var event = new (Blockly.Events.get(Blockly.Events.SELECTED))(this.id, null, + this.workspace.id); event.workspaceId = this.workspace.id; Blockly.Events.fire(event); Blockly.selected = null; @@ -464,7 +467,7 @@ Blockly.BlockSvg.prototype.moveBy = function(dx, dy) { } var eventsEnabled = Blockly.Events.isEnabled(); if (eventsEnabled) { - var event = new Blockly.Events.BlockMove(this); + var event = new (Blockly.Events.get(Blockly.Events.BLOCK_MOVE))(this); } var xy = this.getRelativeToSurfaceXY(); this.translate(xy.x + dx, xy.y + dy); diff --git a/core/blockly.js b/core/blockly.js index bcc24671a..36902a643 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -19,6 +19,9 @@ goog.provide('Blockly'); goog.require('Blockly.constants'); goog.require('Blockly.browserEvents'); goog.require('Blockly.Events'); +goog.require('Blockly.Events.BlockCreate'); +goog.require('Blockly.Events.FinishedLoading'); +goog.require('Blockly.Events.VarCreate'); goog.require('Blockly.Events.Ui'); goog.require('Blockly.Events.UiBase'); goog.require('Blockly.inject'); diff --git a/core/bubble_dragger.js b/core/bubble_dragger.js index 8caf7c8cb..17d59f8be 100644 --- a/core/bubble_dragger.js +++ b/core/bubble_dragger.js @@ -229,7 +229,7 @@ Blockly.BubbleDragger.prototype.endBubbleDrag = function( */ Blockly.BubbleDragger.prototype.fireMoveEvent_ = function() { if (this.draggingBubble_.isComment) { - var event = new Blockly.Events.CommentMove( + var event = new (Blockly.Events.get(Blockly.Events.COMMENT_MOVE))( /** @type {!Blockly.WorkspaceCommentSvg} */ (this.draggingBubble_)); event.setOldCoordinate(this.startXY_); event.recordNew(); diff --git a/core/comment.js b/core/comment.js index b8063d158..6330f1d10 100644 --- a/core/comment.js +++ b/core/comment.js @@ -178,8 +178,10 @@ Blockly.Comment.prototype.createEditor_ = function() { this.onChangeWrapper_ = Blockly.browserEvents.conditionalBind( textarea, 'change', this, function(_e) { if (this.cachedText_ != this.model_.text) { - Blockly.Events.fire(new Blockly.Events.BlockChange( - this.block_, 'comment', null, this.cachedText_, this.model_.text)); + Blockly.Events.fire( + new (Blockly.Events.get(Blockly.Events.BLOCK_CHANGE))( + this.block_, 'comment', null, this.cachedText_, + this.model_.text)); } }); this.onInputWrapper_ = Blockly.browserEvents.conditionalBind( @@ -242,8 +244,8 @@ Blockly.Comment.prototype.setVisible = function(visible) { if (visible == this.isVisible()) { return; } - Blockly.Events.fire( - new Blockly.Events.BubbleOpen(this.block_, visible, 'comment')); + Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.BUBBLE_OPEN))( + this.block_, visible, 'comment')); this.model_.pinned = visible; if (visible) { this.createBubble_(); diff --git a/core/connection.js b/core/connection.js index 249e434e6..988f48b34 100644 --- a/core/connection.js +++ b/core/connection.js @@ -188,7 +188,7 @@ Blockly.Connection.prototype.connect_ = function(childConnection) { var event; if (Blockly.Events.isEnabled()) { - event = new Blockly.Events.BlockMove(childBlock); + event = new (Blockly.Events.get(Blockly.Events.BLOCK_MOVE))(childBlock); } // Establish the connections. Blockly.Connection.connectReciprocally_(parentConnection, childConnection); @@ -466,7 +466,7 @@ Blockly.Connection.prototype.disconnectInternal_ = function(parentBlock, childBlock) { var event; if (Blockly.Events.isEnabled()) { - event = new Blockly.Events.BlockMove(childBlock); + event = new (Blockly.Events.get(Blockly.Events.BLOCK_MOVE))(childBlock); } var otherConnection = this.targetConnection; otherConnection.targetConnection = null; diff --git a/core/contextmenu.js b/core/contextmenu.js index 16d711154..74501de62 100644 --- a/core/contextmenu.js +++ b/core/contextmenu.js @@ -203,7 +203,8 @@ Blockly.ContextMenu.callbackFactory = function(block, xml) { Blockly.Events.enable(); } if (Blockly.Events.isEnabled() && !newBlock.isShadow()) { - Blockly.Events.fire(new Blockly.Events.BlockCreate(newBlock)); + Blockly.Events.fire( + new (Blockly.Events.get(Blockly.Events.BLOCK_CREATE))(newBlock)); } newBlock.select(); }; diff --git a/core/contextmenu_items.js b/core/contextmenu_items.js index a33126d02..11a8332bb 100644 --- a/core/contextmenu_items.js +++ b/core/contextmenu_items.js @@ -17,6 +17,7 @@ goog.provide('Blockly.ContextMenuItems'); goog.require('Blockly.constants'); +goog.require('Blockly.Events'); goog.requireType('Blockly.BlockSvg'); diff --git a/core/events/block_events.js b/core/events/block_events.js index d6b9f80c5..cbc608f3e 100644 --- a/core/events/block_events.js +++ b/core/events/block_events.js @@ -26,8 +26,7 @@ goog.require('Blockly.registry'); goog.require('Blockly.utils.Coordinate'); goog.require('Blockly.utils.object'); goog.require('Blockly.utils.xml'); -// TODO: Fix recursive dependency. -// goog.require('Blockly.Xml'); +goog.require('Blockly.Xml'); goog.requireType('Blockly.Block'); @@ -202,7 +201,7 @@ Blockly.Events.Change.prototype.run = function(forward) { var dom = Blockly.Xml.textToDom(/** @type {string} */ (value) || ''); block.domToMutation(dom); } - Blockly.Events.fire(new Blockly.Events.Change( + Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.CHANGE))( block, 'mutation', null, oldMutation, value)); break; default: diff --git a/core/events/events.js b/core/events/events.js index c1991692c..70b1365c6 100644 --- a/core/events/events.js +++ b/core/events/events.js @@ -399,8 +399,7 @@ Blockly.Events.getDescendantIds = function(block) { * @throws {Error} if an event type is not found in the registry. */ Blockly.Events.fromJson = function(json, workspace) { - var eventClass = Blockly.registry.getClass(Blockly.registry.Type.EVENT, - json.type); + var eventClass = Blockly.Events.get(json.type); if (!eventClass) { throw Error('Unknown event type.'); } @@ -410,6 +409,16 @@ Blockly.Events.fromJson = function(json, workspace) { return event; }; +/** + * Gets the class for a specific event type from the registry. + * @param {string} eventType The type of the event to get. + * @return {?function(new:Blockly.Events.Abstract, ...?)} The event class with + * the given type or null if none exists. + */ +Blockly.Events.get = function(eventType) { + return Blockly.registry.getClass(Blockly.registry.Type.EVENT, eventType); +}; + /** * Enable/disable a block depending on whether it is properly connected. * Use this on applications where all blocks should be connected to a top block. diff --git a/core/events/ws_comment_events.js b/core/events/ws_comment_events.js index 6a5d0b4f2..5bcfa4758 100644 --- a/core/events/ws_comment_events.js +++ b/core/events/ws_comment_events.js @@ -22,8 +22,7 @@ goog.require('Blockly.registry'); goog.require('Blockly.utils.Coordinate'); goog.require('Blockly.utils.object'); goog.require('Blockly.utils.xml'); -// TODO: Fix recursive dependency. -// goog.require('Blockly.Xml'); +goog.require('Blockly.Xml'); /** diff --git a/core/field.js b/core/field.js index f9c30937f..d179aba85 100644 --- a/core/field.js +++ b/core/field.js @@ -831,7 +831,7 @@ Blockly.Field.prototype.setValue = function(newValue) { } if (source && Blockly.Events.isEnabled()) { - Blockly.Events.fire(new Blockly.Events.BlockChange( + Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.BLOCK_CHANGE))( source, 'field', this.name || null, oldValue, newValue)); } this.doValueUpdate_(newValue); diff --git a/core/field_dropdown.js b/core/field_dropdown.js index d877f6cab..38758c3b1 100644 --- a/core/field_dropdown.js +++ b/core/field_dropdown.js @@ -15,7 +15,6 @@ goog.provide('Blockly.FieldDropdown'); goog.require('Blockly.Events'); -goog.require('Blockly.Events.BlockChange'); goog.require('Blockly.Field'); goog.require('Blockly.fieldRegistry'); goog.require('Blockly.Menu'); diff --git a/core/field_textinput.js b/core/field_textinput.js index 9e1cb8d9f..4ee8673ba 100644 --- a/core/field_textinput.js +++ b/core/field_textinput.js @@ -203,7 +203,7 @@ Blockly.FieldTextInput.prototype.doValueInvalid_ = function(_invalidValue) { // Revert value when the text becomes invalid. this.value_ = this.htmlInput_.untypedDefaultValue_; if (this.sourceBlock_ && Blockly.Events.isEnabled()) { - Blockly.Events.fire(new Blockly.Events.BlockChange( + Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.BLOCK_CHANGE))( this.sourceBlock_, 'field', this.name || null, oldValue, this.value_)); } } diff --git a/core/flyout_base.js b/core/flyout_base.js index 16c0266ad..acd067cff 100644 --- a/core/flyout_base.js +++ b/core/flyout_base.js @@ -28,6 +28,7 @@ goog.require('Blockly.utils.Coordinate'); goog.require('Blockly.utils.dom'); goog.require('Blockly.utils.Svg'); goog.require('Blockly.utils.toolbox'); +goog.require('Blockly.utils.xml'); goog.require('Blockly.WorkspaceSvg'); goog.require('Blockly.Xml'); @@ -800,12 +801,14 @@ Blockly.Flyout.prototype.createBlock = function(originalBlock) { // Fire a VarCreate event for each (if any) new variable created. for (var i = 0; i < newVariables.length; i++) { var thisVariable = newVariables[i]; - Blockly.Events.fire(new Blockly.Events.VarCreate(thisVariable)); + Blockly.Events.fire( + new (Blockly.Events.get(Blockly.Events.VAR_CREATE))(thisVariable)); } // Block events come after var events, in case they refer to newly created // variables. - Blockly.Events.fire(new Blockly.Events.Create(newBlock)); + Blockly.Events.fire( + new (Blockly.Events.get(Blockly.Events.BLOCK_CREATE))(newBlock)); } if (this.autoClose) { this.hide(); diff --git a/core/gesture.js b/core/gesture.js index edbbba096..ab80c0cf8 100644 --- a/core/gesture.js +++ b/core/gesture.js @@ -654,8 +654,8 @@ Blockly.Gesture.prototype.handleWsStart = function(e, ws) { * @private */ Blockly.Gesture.prototype.fireWorkspaceClick_ = function(ws) { - var clickEvent = new Blockly.Events.Click(null, ws.id, 'workspace'); - Blockly.Events.fire(clickEvent); + Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.CLICK))( + null, ws.id, 'workspace')); }; /** @@ -745,7 +745,7 @@ Blockly.Gesture.prototype.doBlockClick_ = function() { } } else { // Clicks events are on the start block, even if it was a shadow. - var event = new Blockly.Events.Click( + var event = new (Blockly.Events.get(Blockly.Events.CLICK))( this.startBlock_, this.startWorkspace_.id, 'block'); Blockly.Events.fire(event); } diff --git a/core/inject.js b/core/inject.js index 581e69e32..e15f49f6c 100644 --- a/core/inject.js +++ b/core/inject.js @@ -23,6 +23,7 @@ goog.require('Blockly.Options'); goog.require('Blockly.ScrollbarPair'); goog.require('Blockly.Tooltip'); goog.require('Blockly.utils'); +goog.require('Blockly.utils.aria'); goog.require('Blockly.utils.dom'); goog.require('Blockly.utils.Svg'); goog.require('Blockly.utils.userAgent'); diff --git a/core/keyboard_nav/basic_cursor.js b/core/keyboard_nav/basic_cursor.js index c853fd9d9..e38031321 100644 --- a/core/keyboard_nav/basic_cursor.js +++ b/core/keyboard_nav/basic_cursor.js @@ -15,6 +15,7 @@ goog.provide('Blockly.BasicCursor'); goog.require('Blockly.ASTNode'); goog.require('Blockly.Cursor'); +goog.require('Blockly.registry'); /** diff --git a/core/keyboard_nav/cursor.js b/core/keyboard_nav/cursor.js index 2ef225b90..de9b0b11c 100644 --- a/core/keyboard_nav/cursor.js +++ b/core/keyboard_nav/cursor.js @@ -15,6 +15,7 @@ goog.provide('Blockly.Cursor'); goog.require('Blockly.ASTNode'); goog.require('Blockly.Marker'); +goog.require('Blockly.registry'); goog.require('Blockly.utils.object'); goog.requireType('Blockly.ShortcutRegistry'); diff --git a/core/metrics_manager.js b/core/metrics_manager.js index 6e135ac6e..9ca3fed0c 100644 --- a/core/metrics_manager.js +++ b/core/metrics_manager.js @@ -13,6 +13,7 @@ goog.provide('Blockly.MetricsManager'); goog.require('Blockly.IMetricsManager'); +goog.require('Blockly.registry'); goog.require('Blockly.utils.Size'); goog.requireType('Blockly.IFlyout'); diff --git a/core/mutator.js b/core/mutator.js index 70c0bc111..416f77870 100644 --- a/core/mutator.js +++ b/core/mutator.js @@ -290,8 +290,8 @@ Blockly.Mutator.prototype.setVisible = function(visible) { // No change. return; } - Blockly.Events.fire( - new Blockly.Events.BubbleOpen(this.block_, visible, 'mutator')); + Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.BUBBLE_OPEN))( + this.block_, visible, 'mutator')); if (visible) { // Create the bubble. this.bubble_ = new Blockly.Bubble( @@ -426,7 +426,7 @@ Blockly.Mutator.prototype.workspaceChanged_ = function(e) { var newMutationDom = block.mutationToDom(); var newMutation = newMutationDom && Blockly.Xml.domToText(newMutationDom); if (oldMutation != newMutation) { - Blockly.Events.fire(new Blockly.Events.BlockChange( + Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.BLOCK_CHANGE))( block, 'mutation', null, oldMutation, newMutation)); // Ensure that any bump is part of this mutation's event group. var group = Blockly.Events.getGroup(); diff --git a/core/procedures.js b/core/procedures.js index 2fbd13134..890a2e3f8 100644 --- a/core/procedures.js +++ b/core/procedures.js @@ -378,7 +378,7 @@ Blockly.Procedures.mutateCallers = function(defBlock) { // undo action since it is deterministically tied to the procedure's // definition mutation. Blockly.Events.recordUndo = false; - Blockly.Events.fire(new Blockly.Events.BlockChange( + Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.BLOCK_CHANGE))( caller, 'mutation', null, oldMutation, newMutation)); Blockly.Events.recordUndo = oldRecordUndo; } diff --git a/core/renderers/common/marker_svg.js b/core/renderers/common/marker_svg.js index 2d1f40560..8cee6f5e5 100644 --- a/core/renderers/common/marker_svg.js +++ b/core/renderers/common/marker_svg.js @@ -15,6 +15,7 @@ goog.provide('Blockly.blockRendering.MarkerSvg'); goog.require('Blockly.ASTNode'); goog.require('Blockly.constants'); +goog.require('Blockly.Events'); goog.require('Blockly.Events.MarkerMove'); goog.require('Blockly.utils.dom'); goog.require('Blockly.utils.Svg'); @@ -561,7 +562,7 @@ Blockly.blockRendering.MarkerSvg.prototype.hide = function() { Blockly.blockRendering.MarkerSvg.prototype.fireMarkerEvent_ = function( oldNode, curNode) { var curBlock = curNode.getSourceBlock(); - var event = new Blockly.Events.MarkerMove( + var event = new (Blockly.Events.get(Blockly.Events.MARKER_MOVE))( curBlock, this.isCursor(), oldNode, curNode); Blockly.Events.fire(event); }; diff --git a/core/scrollbar.js b/core/scrollbar.js index 9b91f50ae..ba752a053 100644 --- a/core/scrollbar.js +++ b/core/scrollbar.js @@ -14,6 +14,7 @@ goog.provide('Blockly.Scrollbar'); goog.provide('Blockly.ScrollbarPair'); goog.require('Blockly.browserEvents'); +goog.require('Blockly.Events'); goog.require('Blockly.Touch'); goog.require('Blockly.utils'); goog.require('Blockly.utils.Coordinate'); diff --git a/core/toolbox/toolbox.js b/core/toolbox/toolbox.js index 8201812b7..775f2e937 100644 --- a/core/toolbox/toolbox.js +++ b/core/toolbox/toolbox.js @@ -818,7 +818,7 @@ Blockly.Toolbox.prototype.fireSelectEvent_ = function(oldItem, newItem) { if (oldItem == newItem) { newElement = null; } - var event = new Blockly.Events.ToolboxItemSelect( + var event = new (Blockly.Events.get(Blockly.Events.TOOLBOX_ITEM_SELECT))( oldElement, newElement, this.workspace_.id); Blockly.Events.fire(event); }; diff --git a/core/trashcan.js b/core/trashcan.js index 9231eab52..e47571145 100644 --- a/core/trashcan.js +++ b/core/trashcan.js @@ -14,6 +14,7 @@ goog.provide('Blockly.Trashcan'); goog.require('Blockly.browserEvents'); goog.require('Blockly.constants'); +goog.require('Blockly.Events'); goog.require('Blockly.Events.TrashcanOpen'); goog.require('Blockly.Scrollbar'); goog.require('Blockly.utils.dom'); @@ -568,8 +569,8 @@ Blockly.Trashcan.prototype.click = function() { * @private */ Blockly.Trashcan.prototype.fireUiEvent_ = function(trashcanOpen) { - var uiEvent = - new Blockly.Events.TrashcanOpen(trashcanOpen,this.workspace_.id); + var uiEvent = new (Blockly.Events.get(Blockly.Events.TRASHCAN_OPEN))( + trashcanOpen,this.workspace_.id); Blockly.Events.fire(uiEvent); }; diff --git a/core/utils/toolbox.js b/core/utils/toolbox.js index 563e6eb53..5340562a0 100644 --- a/core/utils/toolbox.js +++ b/core/utils/toolbox.js @@ -13,6 +13,7 @@ goog.provide('Blockly.utils.toolbox'); goog.require('Blockly.constants'); +goog.require('Blockly.Xml'); goog.requireType('Blockly.ToolboxCategory'); goog.requireType('Blockly.ToolboxSeparator'); diff --git a/core/variable_map.js b/core/variable_map.js index c05f74b86..5b01af204 100644 --- a/core/variable_map.js +++ b/core/variable_map.js @@ -106,7 +106,8 @@ Blockly.VariableMap.prototype.renameVariableById = function(id, newName) { */ Blockly.VariableMap.prototype.renameVariableAndUses_ = function(variable, newName, blocks) { - Blockly.Events.fire(new Blockly.Events.VarRename(variable, newName)); + Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.VAR_RENAME))( + variable, newName)); variable.name = newName; for (var i = 0; i < blocks.length; i++) { blocks[i].updateVarName(variable); @@ -143,7 +144,8 @@ Blockly.VariableMap.prototype.renameVariableWithConflict_ = function(variable, } // Finally delete the original variable, which is now unreferenced. - Blockly.Events.fire(new Blockly.Events.VarDelete(variable)); + Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.VAR_DELETE))( + variable)); // And remove it from the list. var variableList = this.getVariablesOfType(type); var variableIndex = variableList.indexOf(variable); @@ -205,7 +207,8 @@ Blockly.VariableMap.prototype.deleteVariable = function(variable) { for (var i = 0, tempVar; (tempVar = variableList[i]); i++) { if (tempVar.getId() == variable.getId()) { variableList.splice(i, 1); - Blockly.Events.fire(new Blockly.Events.VarDelete(variable)); + Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.VAR_DELETE))( + variable)); return; } } diff --git a/core/variable_model.js b/core/variable_model.js index c92ed85a0..036c99e5c 100644 --- a/core/variable_model.js +++ b/core/variable_model.js @@ -66,7 +66,8 @@ Blockly.VariableModel = function(workspace, name, opt_type, opt_id) { */ this.id_ = opt_id || Blockly.utils.genUid(); - Blockly.Events.fire(new Blockly.Events.VarCreate(this)); + Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.VAR_CREATE))( + this)); }; /** diff --git a/core/warning.js b/core/warning.js index ca5385bea..1adfae2e7 100644 --- a/core/warning.js +++ b/core/warning.js @@ -86,8 +86,8 @@ Blockly.Warning.prototype.setVisible = function(visible) { if (visible == this.isVisible()) { return; } - Blockly.Events.fire( - new Blockly.Events.BubbleOpen(this.block_, visible, 'warning')); + Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.BUBBLE_OPEN))( + this.block_, visible, 'warning')); if (visible) { this.createBubble_(); } else { diff --git a/core/workspace.js b/core/workspace.js index ec89c0078..7d3fa4e47 100644 --- a/core/workspace.js +++ b/core/workspace.js @@ -15,6 +15,7 @@ goog.provide('Blockly.Workspace'); goog.require('Blockly.ConnectionChecker'); goog.require('Blockly.Events'); goog.require('Blockly.Options'); +goog.require('Blockly.registry'); goog.require('Blockly.utils'); goog.require('Blockly.utils.math'); goog.require('Blockly.VariableMap'); diff --git a/core/workspace_comment.js b/core/workspace_comment.js index 3edaa4814..76934473b 100644 --- a/core/workspace_comment.js +++ b/core/workspace_comment.js @@ -116,7 +116,8 @@ Blockly.WorkspaceComment.prototype.dispose = function() { } if (Blockly.Events.isEnabled()) { - Blockly.Events.fire(new Blockly.Events.CommentDelete(this)); + Blockly.Events.fire( + new (Blockly.Events.get(Blockly.Events.COMMENT_DELETE))(this)); } // Remove from the list of top comments and the comment database. @@ -180,7 +181,7 @@ Blockly.WorkspaceComment.prototype.getXY = function() { * @package */ Blockly.WorkspaceComment.prototype.moveBy = function(dx, dy) { - var event = new Blockly.Events.CommentMove(this); + var event = new (Blockly.Events.get(Blockly.Events.COMMENT_MOVE))(this); this.xy_.translate(dx, dy); event.recordNew(); Blockly.Events.fire(event); @@ -257,8 +258,8 @@ Blockly.WorkspaceComment.prototype.getContent = function() { */ Blockly.WorkspaceComment.prototype.setContent = function(content) { if (this.content_ != content) { - Blockly.Events.fire( - new Blockly.Events.CommentChange(this, this.content_, content)); + Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.COMMENT_CHANGE))( + this, this.content_, content)); this.content_ = content; } }; @@ -307,7 +308,8 @@ Blockly.WorkspaceComment.fireCreateEvent = function(comment) { Blockly.Events.setGroup(true); } try { - Blockly.Events.fire(new Blockly.Events.CommentCreate(comment)); + Blockly.Events.fire( + new (Blockly.Events.get(Blockly.Events.COMMENT_CREATE))(comment)); } finally { if (!existingGroup) { Blockly.Events.setGroup(false); diff --git a/core/workspace_comment_svg.js b/core/workspace_comment_svg.js index 68e100fc8..8b828d958 100644 --- a/core/workspace_comment_svg.js +++ b/core/workspace_comment_svg.js @@ -127,7 +127,8 @@ Blockly.WorkspaceCommentSvg.prototype.dispose = function() { } if (Blockly.Events.isEnabled()) { - Blockly.Events.fire(new Blockly.Events.CommentDelete(this)); + Blockly.Events.fire( + new (Blockly.Events.get(Blockly.Events.COMMENT_DELETE))(this)); } Blockly.utils.dom.removeNode(this.svgGroup_); @@ -224,7 +225,8 @@ Blockly.WorkspaceCommentSvg.prototype.select = function() { Blockly.Events.enable(); } } - var event = new Blockly.Events.Selected(oldId, this.id, this.workspace.id); + var event = new (Blockly.Events.get(Blockly.Events.SELECTED))(oldId, this.id, + this.workspace.id); Blockly.Events.fire(event); Blockly.selected = this; this.addSelect(); @@ -238,7 +240,8 @@ Blockly.WorkspaceCommentSvg.prototype.unselect = function() { if (Blockly.selected != this) { return; } - var event = new Blockly.Events.Selected(this.id, null, this.workspace.id); + var event = new (Blockly.Events.get(Blockly.Events.SELECTED))(this.id, null, + this.workspace.id); Blockly.Events.fire(event); Blockly.selected = null; this.removeSelect(); @@ -331,7 +334,7 @@ Blockly.WorkspaceCommentSvg.prototype.getRelativeToSurfaceXY = function() { * @package */ Blockly.WorkspaceCommentSvg.prototype.moveBy = function(dx, dy) { - var event = new Blockly.Events.CommentMove(this); + var event = new (Blockly.Events.get(Blockly.Events.COMMENT_MOVE))(this); // TODO: Do I need to look up the relative to surface XY position here? var xy = this.getRelativeToSurfaceXY(); this.translate(xy.x + dx, xy.y + dy); diff --git a/core/workspace_svg.js b/core/workspace_svg.js index 9e3023cd7..5a4401465 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -618,7 +618,8 @@ Blockly.WorkspaceSvg.prototype.refreshTheme = function() { this.setVisible(true); } - var event = new Blockly.Events.ThemeChange(this.getTheme().name, this.id); + var event = new (Blockly.Events.get(Blockly.Events.THEME_CHANGE))( + this.getTheme().name, this.id); Blockly.Events.fire(event); }; @@ -1163,7 +1164,8 @@ Blockly.WorkspaceSvg.prototype.maybeFireViewportChangeEvent = function() { this.oldScale_ = scale; this.oldTop_ = top; this.oldLeft_ = left; - var event = new Blockly.Events.ViewportChange(top, left, scale, this.id); + var event = new (Blockly.Events.get(Blockly.Events.VIEWPORT_CHANGE))(top, + left, scale, this.id); Blockly.Events.fire(event); }; @@ -1446,7 +1448,8 @@ Blockly.WorkspaceSvg.prototype.pasteBlock_ = function(xmlBlock) { Blockly.Events.enable(); } if (Blockly.Events.isEnabled() && !block.isShadow()) { - Blockly.Events.fire(new Blockly.Events.BlockCreate(block)); + Blockly.Events.fire( + new (Blockly.Events.get(Blockly.Events.BLOCK_CREATE))(block)); } block.select(); }; diff --git a/core/xml.js b/core/xml.js index d8c382a9c..5aadaa894 100644 --- a/core/xml.js +++ b/core/xml.js @@ -18,9 +18,6 @@ goog.provide('Blockly.Xml'); goog.require('Blockly.constants'); goog.require('Blockly.Events'); -goog.require('Blockly.Events.BlockCreate'); -goog.require('Blockly.Events.FinishedLoading'); -goog.require('Blockly.Events.VarCreate'); goog.require('Blockly.utils'); goog.require('Blockly.utils.dom'); goog.require('Blockly.utils.global'); @@ -481,7 +478,8 @@ Blockly.Xml.domToWorkspace = function(xml, workspace) { if (workspace.setResizesEnabled) { workspace.setResizesEnabled(true); } - Blockly.Events.fire(new Blockly.Events.FinishedLoading(workspace)); + Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.FINISHED_LOADING))( + workspace)); return newBlockIds; }; @@ -593,11 +591,13 @@ Blockly.Xml.domToBlock = function(xmlBlock, workspace) { // Fire a VarCreate event for each (if any) new variable created. for (var i = 0; i < newVariables.length; i++) { var thisVariable = newVariables[i]; - Blockly.Events.fire(new Blockly.Events.VarCreate(thisVariable)); + Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.VAR_CREATE))( + thisVariable)); } // Block events come after var events, in case they refer to newly created // variables. - Blockly.Events.fire(new Blockly.Events.BlockCreate(topBlock)); + Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.CREATE))( + topBlock)); } return topBlock; }; diff --git a/core/zoom_controls.js b/core/zoom_controls.js index f7e829e12..7383855c1 100644 --- a/core/zoom_controls.js +++ b/core/zoom_controls.js @@ -15,6 +15,8 @@ goog.provide('Blockly.ZoomControls'); goog.require('Blockly.browserEvents'); goog.require('Blockly.constants'); goog.require('Blockly.Css'); +goog.require('Blockly.Events'); +goog.require('Blockly.Events.Click'); goog.require('Blockly.Scrollbar'); goog.require('Blockly.Touch'); goog.require('Blockly.utils.dom'); @@ -424,7 +426,7 @@ Blockly.ZoomControls.prototype.resetZoom_ = function(e) { * @private */ Blockly.ZoomControls.prototype.fireZoomEvent_ = function() { - var uiEvent = new Blockly.Events.Click( + var uiEvent = new (Blockly.Events.get(Blockly.Events.CLICK))( null, this.workspace_.id, 'zoom_controls'); Blockly.Events.fire(uiEvent); };