@wcardinal/wcardinal-geditor
Version:
WebGL-based graphic editor, tester and viewer for supervisory systems
137 lines • 4.98 kB
JavaScript
import { __extends } from "tslib";
import { DCommandBase, EShapeCapabilities, EShapeCapability } from "@wcardinal/wcardinal-ui";
var ECommandShapeDataMappingValueReplace = /** @class */ (function (_super) {
__extends(ECommandShapeDataMappingValueReplace, _super);
function ECommandShapeDataMappingValueReplace(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 (EShapeCapabilities.contains(shape, EShapeCapability.DATA_MAPPING)) {
var mapping = shape.data.getMapping();
if (mapping) {
var index = mapping.indexOf(oldValue);
indices.push(index);
if (0 <= index) {
oldValues.push(mapping.get(index));
mapping.set(index, newValue);
}
else {
oldValues.push(newValue);
}
}
else {
indices.push(-1);
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;
}
Object.defineProperty(ECommandShapeDataMappingValueReplace.prototype, "selection", {
get: function () {
return this._selection;
},
enumerable: false,
configurable: true
});
Object.defineProperty(ECommandShapeDataMappingValueReplace.prototype, "oldValue", {
get: function () {
return this._oldValue;
},
enumerable: false,
configurable: true
});
Object.defineProperty(ECommandShapeDataMappingValueReplace.prototype, "newValue", {
get: function () {
return this._newValue;
},
enumerable: false,
configurable: true
});
Object.defineProperty(ECommandShapeDataMappingValueReplace.prototype, "indices", {
get: function () {
return this._indices;
},
enumerable: false,
configurable: true
});
Object.defineProperty(ECommandShapeDataMappingValueReplace.prototype, "oldValues", {
get: function () {
return this._oldValues;
},
enumerable: false,
configurable: true
});
Object.defineProperty(ECommandShapeDataMappingValueReplace.prototype, "list", {
get: function () {
return this._list;
},
enumerable: false,
configurable: true
});
ECommandShapeDataMappingValueReplace.prototype.execute = function () {
return true;
};
ECommandShapeDataMappingValueReplace.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];
var index = indices[i];
if (0 <= index) {
var mapping = shape.data.getMapping();
if (mapping) {
mapping.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;
};
ECommandShapeDataMappingValueReplace.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];
var index = indices[i];
if (0 <= index) {
var mapping = shape.data.getMapping();
if (mapping) {
mapping.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 ECommandShapeDataMappingValueReplace;
}(DCommandBase));
export { ECommandShapeDataMappingValueReplace };
//# sourceMappingURL=e-command-shape-data-mapping-value-replace.js.map