@kieler/klighd-core
Version:
Core KLighD diagram visualization with Sprotty
99 lines • 4.33 kB
JavaScript
;
/*
* KIELER - Kiel Integrated Environment for Layout Eclipse RichClient
*
* http://rtsys.informatik.uni-kiel.de/kieler
*
* Copyright 2021 by
* + Kiel University
* + Department of Computer Science
* + Real-Time and Embedded Systems Group
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*/
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.OptionsPersistence = void 0;
const inversify_1 = require("inversify");
const sprotty_1 = require("sprotty");
const services_1 = require("../services");
const actions_1 = require("./actions");
/**
* {@link IActionHandler} that handles update actions for various options.
* This handler persists the updates so they will still be available when a user
* closes and reopens the diagram view.
*/
let OptionsPersistence = class OptionsPersistence {
init() {
this.storage.onClear(this.handleClear.bind(this));
}
initialize(registry) {
registry.register(actions_1.SetRenderOptionAction.KIND, this);
registry.register(actions_1.SetLayoutOptionsAction.KIND, this);
registry.register(actions_1.SetSynthesisOptionsAction.KIND, this);
}
handle(action) {
if (actions_1.SetRenderOptionAction.isThisAction(action)) {
this.storage.setItem('render', (prev) => {
const obj = prev !== null && prev !== void 0 ? prev : {};
obj[action.id] = action.value;
return obj;
});
}
else if (actions_1.SetLayoutOptionsAction.isThisAction(action)) {
this.storage.setItem('layout', (prev) => {
const obj = prev !== null && prev !== void 0 ? prev : {};
for (const option of action.options) {
obj[option.optionId] = option.value;
}
return obj;
});
}
else if (actions_1.SetSynthesisOptionsAction.isThisAction(action)) {
this.storage.setItem('synthesis', (prev) => {
const obj = prev !== null && prev !== void 0 ? prev : {};
for (const option of action.options) {
obj[option.id] = option.currentValue;
}
return obj;
});
}
}
/** Reset all stored options when the storage gets cleared from outside. */
handleClear() {
this.dispatcher.dispatch(actions_1.ResetRenderOptionsAction.create());
this.dispatcher.dispatch(actions_1.ResetSynthesisOptionsAction.create());
this.dispatcher.dispatch(actions_1.ResetLayoutOptionsAction.create());
}
};
exports.OptionsPersistence = OptionsPersistence;
__decorate([
(0, inversify_1.inject)(services_1.ServiceTypes.PersistenceStorage),
__metadata("design:type", Object)
], OptionsPersistence.prototype, "storage", void 0);
__decorate([
(0, inversify_1.inject)(sprotty_1.TYPES.IActionDispatcher),
__metadata("design:type", Object)
], OptionsPersistence.prototype, "dispatcher", void 0);
__decorate([
(0, inversify_1.postConstruct)(),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], OptionsPersistence.prototype, "init", null);
exports.OptionsPersistence = OptionsPersistence = __decorate([
(0, inversify_1.injectable)()
], OptionsPersistence);
//# sourceMappingURL=options-persistence.js.map