Files
blockly/core/events/events_comment_delete.js
Aaron Dodson 4751eea529 Migrate core/events/ws_comment_events.js to goog.module syntax (#5380)
* Split provides in core/events/ws_comment_events.js into individual files

* Migrate core/events/events_comment_* to ES6 const/let

* Migrate core/events/events_comment_* to goog.module

* Migrate core/events/events_comment_* to named requires

* clang-format core/events/events_comment_*

* Revert now-unnecessary changes to tests/mocha/event_test.js

* Update fileoverview comments for separated comment event classes
2021-08-24 08:00:27 -07:00

76 lines
1.9 KiB
JavaScript

/**
* @license
* Copyright 2018 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @fileoverview Class for comment deletion event.
* @author fenichel@google.com (Rachel Fenichel)
*/
'use strict';
goog.module('Blockly.Events.CommentDelete');
goog.module.declareLegacyNamespace();
const CommentBase = goog.require('Blockly.Events.CommentBase');
const Events = goog.require('Blockly.Events');
/* eslint-disable-next-line no-unused-vars */
const WorkspaceComment = goog.requireType('Blockly.WorkspaceComment');
const object = goog.require('Blockly.utils.object');
const registry = goog.require('Blockly.registry');
/**
* Class for a comment deletion event.
* @param {!WorkspaceComment=} opt_comment The deleted comment.
* Undefined for a blank event.
* @extends {CommentBase}
* @constructor
*/
const CommentDelete = function(opt_comment) {
CommentDelete.superClass_.constructor.call(this, opt_comment);
if (!opt_comment) {
return; // Blank event to be populated by fromJson.
}
this.xml = opt_comment.toXmlWithXY();
};
object.inherits(CommentDelete, CommentBase);
/**
* Type of this event.
* @type {string}
*/
CommentDelete.prototype.type = Events.COMMENT_DELETE;
/**
* Encode the event as JSON.
* @return {!Object} JSON representation.
*/
// TODO (#1266): "Full" and "minimal" serialization.
CommentDelete.prototype.toJson = function() {
const json = CommentDelete.superClass_.toJson.call(this);
return json;
};
/**
* Decode the JSON event.
* @param {!Object} json JSON representation.
*/
CommentDelete.prototype.fromJson = function(json) {
CommentDelete.superClass_.fromJson.call(this, json);
};
/**
* Run a creation event.
* @param {boolean} forward True if run forward, false if run backward (undo).
*/
CommentDelete.prototype.run = function(forward) {
CommentBase.CommentCreateDeleteHelper(this, !forward);
};
registry.register(registry.Type.EVENT, Events.COMMENT_DELETE, CommentDelete);
exports = CommentDelete;