123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- "use strict";
- var __extends = (this && this.__extends) || (function () {
- var extendStatics = function (d, b) {
- extendStatics = Object.setPrototypeOf ||
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
- return extendStatics(d, b);
- };
- return function (d, b) {
- extendStatics(d, b);
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- };
- })();
- Object.defineProperty(exports, "__esModule", { value: true });
- exports.SUndoStack = void 0;
- var SObject_1 = require("../SObject");
- var SUndoStack = (function (_super) {
- __extends(SUndoStack, _super);
- function SUndoStack() {
- var _this = _super !== null && _super.apply(this, arguments) || this;
- _this.cmdStack = Array();
- _this._index = -1;
- _this.isChange = false;
- return _this;
- }
- Object.defineProperty(SUndoStack.prototype, "index", {
- get: function () {
- return this._index;
- },
- enumerable: false,
- configurable: true
- });
- Object.defineProperty(SUndoStack.prototype, "isEmpty", {
- get: function () {
- return this.cmdStack.length <= 0;
- },
- enumerable: false,
- configurable: true
- });
- SUndoStack.prototype.redo = function () {
- if (!this.canRedo()) {
- return;
- }
- this._index++;
- this.cmdStack[this._index].redo();
- this.isChange = true;
- };
- SUndoStack.prototype.undo = function () {
- if (!this.canUndo()) {
- return;
- }
- this.cmdStack[this._index].undo();
- this._index--;
- this.isChange = true;
- };
- SUndoStack.prototype.canRedo = function () {
- return this.index + 1 < this.cmdStack.length;
- };
- SUndoStack.prototype.canUndo = function () {
- return this.index >= 0;
- };
- SUndoStack.prototype.clear = function () {
- this.cmdStack.length = 0;
- this._index = -1;
- this.isChange = true;
- };
- SUndoStack.prototype.command = function (index) {
- if (index < 0 || index >= this.cmdStack.length) {
- return null;
- }
- return this.cmdStack[index];
- };
- SUndoStack.prototype.count = function () {
- return this.cmdStack.length;
- };
- SUndoStack.prototype.push = function (cmd) {
- this.cmdStack.length = this._index + 1;
- if (this._index >= 0 && cmd.mergeWith(this.cmdStack[this._index])) {
- return;
- }
- this.cmdStack.push(cmd);
- this._index = this.cmdStack.length - 1;
- this.isChange = true;
- };
- SUndoStack.prototype.toLog = function () {
- var stackList = [];
- for (var i = 0; i <= this.index; i++) {
- stackList.push({
- command: this.cmdStack[i].command,
- desc: this.cmdStack[i].desc,
- detail: this.cmdStack[i].toString()
- });
- }
- return stackList;
- };
- return SUndoStack;
- }(SObject_1.SObject));
- exports.SUndoStack = SUndoStack;
|