@wcardinal/wcardinal-geditor
Version:
WebGL-based graphic editor, tester and viewer for supervisory systems
87 lines • 3.35 kB
JavaScript
import { __extends } from "tslib";
import { DCommandBase } from "@wcardinal/wcardinal-ui";
import { EShapeButtonLayer } from "./e-shape-button-layer";
var ECommandShapeButtonLayerValueReplace = /** @class */ (function (_super) {
__extends(ECommandShapeButtonLayerValueReplace, _super);
function ECommandShapeButtonLayerValueReplace(oldValue, newValue, selection, list) {
var _this = _super.call(this) || this;
_this._selection = selection;
_this._oldValue = oldValue;
_this._newValue = newValue;
_this._list = list;
var indices = [];
var oldValues = [];
var shapes = _this._selection.get();
for (var i = 0, imax = shapes.length; i < imax; ++i) {
var shape = shapes[i];
if (shape instanceof EShapeButtonLayer) {
var index = shape.button.indexOf(oldValue);
indices.push(index);
if (0 <= index) {
oldValues.push(shape.button.get(index));
shape.button.set(index, newValue);
}
else {
oldValues.push(newValue);
}
}
else {
indices.push(-1);
oldValues.push(newValue);
}
}
_this._indices = indices;
_this._oldValues = oldValues;
if (list.data.selection.contains(oldValue)) {
list.data.selection.clearAndAdd(newValue);
}
_this._selection.update("PROPERTY");
return _this;
}
ECommandShapeButtonLayerValueReplace.prototype.execute = function () {
return true;
};
ECommandShapeButtonLayerValueReplace.prototype.redo = function () {
var newValue = this._newValue;
var indices = this._indices;
var shapes = this._selection.get();
for (var i = 0, imax = shapes.length; i < imax; ++i) {
var shape = shapes[i];
if (shape instanceof EShapeButtonLayer) {
var index = indices[i];
if (0 <= index) {
shape.button.set(index, newValue);
}
}
}
var list = this._list;
if (list.data.selection.contains(this._oldValue)) {
list.data.selection.clearAndAdd(newValue);
}
this._selection.update("PROPERTY");
return true;
};
ECommandShapeButtonLayerValueReplace.prototype.undo = function () {
var indices = this._indices;
var oldValues = this._oldValues;
var shapes = this._selection.get();
for (var i = 0, imax = shapes.length; i < imax; ++i) {
var shape = shapes[i];
if (shape instanceof EShapeButtonLayer) {
var index = indices[i];
if (0 <= index) {
shape.button.set(index, oldValues[i]);
}
}
}
var list = this._list;
if (list.data.selection.contains(this._newValue)) {
list.data.selection.clearAndAdd(this._oldValue);
}
this._selection.update("PROPERTY");
return true;
};
return ECommandShapeButtonLayerValueReplace;
}(DCommandBase));
export { ECommandShapeButtonLayerValueReplace };
//# sourceMappingURL=e-command-shape-button-layer-value-replace.js.map