Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added FinishedLoading Event #2235

Merged
merged 5 commits into from
Jan 28, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions blockly_uncompressed.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions core/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
91 changes: 91 additions & 0 deletions core/workspace_events.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/**
* @license
* Visual Blocks Editor
*
* Copyright 2019 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() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update this and line 88 to be Blockly.Events.FinishedLoading instead of Blockly.Events.Ui

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'];
};
1 change: 1 addition & 0 deletions core/xml.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ Blockly.Xml.domToWorkspace = function(xml, workspace) {
if (workspace.setResizesEnabled) {
workspace.setResizesEnabled(true);
}
Blockly.Events.fire(new Blockly.Events.FinishedLoading(workspace));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a goog.require for Blockly.Events.FinishedLoading at the top of this file.

return newBlockIds;
};

Expand Down