From bb2260fd91c92e2fd8026e6549373c7b30a9d19c Mon Sep 17 00:00:00 2001 From: Beka Westberg Date: Thu, 24 Jan 2019 19:32:48 -0800 Subject: [PATCH 1/5] Added a Finished Loading event. --- core/events.js | 5 +++ core/workspace_events.js | 92 ++++++++++++++++++++++++++++++++++++++++ core/xml.js | 1 + 3 files changed, 98 insertions(+) create mode 100644 core/workspace_events.js diff --git a/core/events.js b/core/events.js index 8fac89902..4dd4158ee 100644 --- a/core/events.js +++ b/core/events.js @@ -149,6 +149,11 @@ Blockly.Events.COMMENT_CHANGE = 'comment_change'; */ Blockly.Events.COMMENT_MOVE = 'comment_move'; +/** + * Name of event that records a workspace load. + */ +Blockly.Events.FINISHED_LOADING = 'finished_loading'; + /** * List of events queued for firing. * @private diff --git a/core/workspace_events.js b/core/workspace_events.js new file mode 100644 index 000000000..eb4a007aa --- /dev/null +++ b/core/workspace_events.js @@ -0,0 +1,92 @@ +/** + * @license + * Visual Blocks Editor + * + * TODO: 2019 instead of 2018??? + * Copyright 2018 Google Inc. + * https://developers.google.com/blockly/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @fileoverview Class for a finished loading workspace event. + * @author BeksOmega + */ +'use strict'; + +goog.provide(Blockly.Events.FinishedLoading); + +goog.require('Blockly.Events'); +goog.require('Blockly.Events.Abstract'); + +/** + * Class for a finished loading event. + * Used to notify the developer when the workspace has finished loading (i.e + * domToWorkspace). + * Finished loading events do not record undo or redo. + * @param {!Blockly.Workspace} workspace The workspace that has finished + * loading. + * @constructor + */ +Blockly.Events.FinishedLoading = function(workspace) { + /** + * The workspace identifier for this event. + * @type {string} + */ + this.workspaceId = workspace.id; + + /** + * The event group id for the group this event belongs to. Groups define + * events that should be treated as an single action from the user's + * perspective, and should be undone together. + * @type {string} + */ + this.group = Blockly.Events.group_; + + // Workspace events do not undo or redo. + this.recordUndo = false; +}; +goog.inherits(Blockly.Events.FinishedLoading, Blockly.Events.Abstract); + +/** + * Type of this event. + * @type {string} + */ +Blockly.Events.FinishedLoading.prototype.type = Blockly.Events.FINISHED_LOADING; + +/** + * Encode the event as JSON. + * @return {!Object} JSON representation. + */ +Blockly.Events.Ui.prototype.toJson = function() { + var json = { + 'type': this.type, + }; + if (this.group) { + json['group'] = this.group; + } + if (this.workspaceId) { + json['workspaceId'] = this.workspaceId; + } + return json; +}; + +/** + * Decode the JSON event. + * @param {!Object} json JSON representation. + */ +Blockly.Events.Ui.prototype.fromJson = function(json) { + this.workspaceId = json['workspaceId']; + this.group = json['group']; +}; diff --git a/core/xml.js b/core/xml.js index 6a8ba6e15..da4a6db3c 100644 --- a/core/xml.js +++ b/core/xml.js @@ -467,6 +467,7 @@ Blockly.Xml.domToWorkspace = function(xml, workspace) { if (workspace.setResizesEnabled) { workspace.setResizesEnabled(true); } + Blockly.Events.fire(new Blockly.Events.FinishedLoading(workspace)); return newBlockIds; }; From 47cbb3b1b85df3432c2b1a581271438183366f78 Mon Sep 17 00:00:00 2001 From: Beka Westberg Date: Fri, 25 Jan 2019 16:11:16 -0800 Subject: [PATCH 2/5] Updated blockly_uncompressed file. --- blockly_uncompressed.js | 2 ++ core/workspace_events.js | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/blockly_uncompressed.js b/blockly_uncompressed.js index 9e02bac48..01dae3b71 100644 --- a/blockly_uncompressed.js +++ b/blockly_uncompressed.js @@ -111,6 +111,7 @@ goog.addDependency("../../../" + dir + "/core/workspace_comment_render_svg.js", goog.addDependency("../../../" + dir + "/core/workspace_comment_svg.js", ['Blockly.WorkspaceCommentSvg'], ['Blockly.Events.CommentCreate', 'Blockly.Events.CommentDelete', 'Blockly.Events.CommentMove', 'Blockly.utils', 'Blockly.WorkspaceComment', 'goog.math.Coordinate']); goog.addDependency("../../../" + dir + "/core/workspace_drag_surface_svg.js", ['Blockly.WorkspaceDragSurfaceSvg'], ['Blockly.utils']); goog.addDependency("../../../" + dir + "/core/workspace_dragger.js", ['Blockly.WorkspaceDragger'], ['goog.math.Coordinate']); +goog.addDependency("../../../" + dir + "/core/workspace_events.js", ['Blockly.Events.FinishedLoading'], ['Blockly.Events', 'Blockly.Events.Abstract']); goog.addDependency("../../../" + dir + "/core/workspace_svg.js", ['Blockly.WorkspaceSvg'], ['Blockly.ConnectionDB', 'Blockly.constants', 'Blockly.Events.BlockCreate', 'Blockly.Gesture', 'Blockly.Grid', 'Blockly.Options', 'Blockly.ScrollbarPair', 'Blockly.Touch', 'Blockly.TouchGesture', 'Blockly.Trashcan', 'Blockly.utils', 'Blockly.VariablesDynamic', 'Blockly.Workspace', 'Blockly.WorkspaceAudio', 'Blockly.WorkspaceComment', 'Blockly.WorkspaceCommentSvg', 'Blockly.WorkspaceCommentSvg.render', 'Blockly.WorkspaceDragSurfaceSvg', 'Blockly.Xml', 'Blockly.ZoomControls', 'goog.dom', 'goog.math.Coordinate']); goog.addDependency("../../../" + dir + "/core/ws_comment_events.js", ['Blockly.Events.CommentBase', 'Blockly.Events.CommentChange', 'Blockly.Events.CommentCreate', 'Blockly.Events.CommentDelete', 'Blockly.Events.CommentMove'], ['Blockly.Events', 'Blockly.Events.Abstract', 'Blockly.Xml', 'Blockly.Xml.utils', 'goog.math.Coordinate']); goog.addDependency("../../../" + dir + "/core/xml.js", ['Blockly.Xml'], ['Blockly.Events.BlockCreate', 'Blockly.Events.VarCreate', 'Blockly.Xml.utils']); @@ -1764,6 +1765,7 @@ goog.require('Blockly.Events.CommentDelete'); goog.require('Blockly.Events.CommentMove'); goog.require('Blockly.Events.Create'); goog.require('Blockly.Events.Delete'); +goog.require('Blockly.Events.FinishedLoading'); goog.require('Blockly.Events.Move'); goog.require('Blockly.Events.Ui'); goog.require('Blockly.Events.VarBase'); diff --git a/core/workspace_events.js b/core/workspace_events.js index eb4a007aa..3f3751c63 100644 --- a/core/workspace_events.js +++ b/core/workspace_events.js @@ -25,7 +25,7 @@ */ 'use strict'; -goog.provide(Blockly.Events.FinishedLoading); +goog.provide('Blockly.Events.FinishedLoading'); goog.require('Blockly.Events'); goog.require('Blockly.Events.Abstract'); From 22f11b937ea1baf214c1bf3735913eaac64143fd Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 25 Jan 2019 16:45:51 -0800 Subject: [PATCH 3/5] Update copyright year --- core/workspace_events.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/workspace_events.js b/core/workspace_events.js index 3f3751c63..9c689557d 100644 --- a/core/workspace_events.js +++ b/core/workspace_events.js @@ -2,8 +2,7 @@ * @license * Visual Blocks Editor * - * TODO: 2019 instead of 2018??? - * Copyright 2018 Google Inc. + * Copyright 2019 Google Inc. * https://developers.google.com/blockly/ * * Licensed under the Apache License, Version 2.0 (the "License"); From b4e643f22e24c2a7b340bfc62325214bb4abc837 Mon Sep 17 00:00:00 2001 From: Beka Westberg Date: Fri, 25 Jan 2019 17:08:30 -0800 Subject: [PATCH 4/5] Fixed Xml goog.require's. Changed Blockly.Events.Ui functions to Blockly.Events.FinishedLoading. --- core/workspace_events.js | 4 ++-- core/xml.js | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/core/workspace_events.js b/core/workspace_events.js index 9c689557d..b4c78e2de 100644 --- a/core/workspace_events.js +++ b/core/workspace_events.js @@ -68,7 +68,7 @@ Blockly.Events.FinishedLoading.prototype.type = Blockly.Events.FINISHED_LOADING; * Encode the event as JSON. * @return {!Object} JSON representation. */ -Blockly.Events.Ui.prototype.toJson = function() { +Blockly.Events.FinishedLoading.prototype.toJson = function() { var json = { 'type': this.type, }; @@ -85,7 +85,7 @@ Blockly.Events.Ui.prototype.toJson = function() { * Decode the JSON event. * @param {!Object} json JSON representation. */ -Blockly.Events.Ui.prototype.fromJson = function(json) { +Blockly.Events.FinishedLoading.prototype.fromJson = function(json) { this.workspaceId = json['workspaceId']; this.group = json['group']; }; diff --git a/core/xml.js b/core/xml.js index da4a6db3c..ecabc500e 100644 --- a/core/xml.js +++ b/core/xml.js @@ -33,6 +33,7 @@ goog.provide('Blockly.Xml'); goog.require('Blockly.Events.BlockCreate'); goog.require('Blockly.Events.VarCreate'); goog.require('Blockly.Xml.utils'); +goog.require('Blockly.Events.FinishedLoading'); /** From bad1b39502da2f45de7f66bc70c0f518b0a4eed8 Mon Sep 17 00:00:00 2001 From: Beka Westberg Date: Sat, 26 Jan 2019 07:03:47 -0800 Subject: [PATCH 5/5] Changed require's to be in correct lexicographical order. --- core/xml.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/xml.js b/core/xml.js index ecabc500e..9941ddbeb 100644 --- a/core/xml.js +++ b/core/xml.js @@ -31,9 +31,9 @@ goog.provide('Blockly.Xml'); goog.require('Blockly.Events.BlockCreate'); +goog.require('Blockly.Events.FinishedLoading'); goog.require('Blockly.Events.VarCreate'); goog.require('Blockly.Xml.utils'); -goog.require('Blockly.Events.FinishedLoading'); /**