UNPKG

@kieler/klighd-core

Version:

Core KLighD diagram visualization with Sprotty

102 lines 4.15 kB
"use strict"; /* * 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.BookmarkRegistry = void 0; const inversify_1 = require("inversify"); const registry_1 = require("../base/registry"); const di_symbols_1 = require("../di.symbols"); const render_options_registry_1 = require("../options/render-options-registry"); const bookmark_1 = require("./bookmark"); /** * A simple {@link Registry} that holds a list of all added Bookmarks * * Handles CreateBookmark and GoToBookmark actions * */ let BookmarkRegistry = class BookmarkRegistry extends registry_1.Registry { constructor() { super(...arguments); this._bookmarks = []; this.count = 0; } // eslint-disable-next-line consistent-return handle(action) { if (bookmark_1.GoToBookmarkAction.isThisAction(action)) { return new bookmark_1.GoToBookmarkCommand(action, this.renderOptionsRegistry.getValue(render_options_registry_1.AnimateGoToBookmark)); } if (bookmark_1.SetInitialBookmarkAction.isThisAction(action)) { this._initialBookmark = action.bookmark; this.addBookmark(this._initialBookmark); } else if (bookmark_1.DeleteBookmarkAction.isThisAction(action)) { this.deleteBookmark(action.bookmarkIndex); } else if (bookmark_1.RenameBookmarkAction.isThisAction(action)) { this.updateBookmarkName(action.bookmarkIndex, action.newName); } else if (bookmark_1.AddBookmarkAction.isThisAction(action)) { this.addBookmark(action.bookmark); } } addBookmark(bookmark) { bookmark.bookmarkIndex = this.count++; this._bookmarks.push(bookmark); this.notifyListeners(); } deleteBookmark(bookmarkIndex) { const index = this._bookmarks.findIndex((value) => value.bookmarkIndex === bookmarkIndex); this._bookmarks.splice(index, 1); this.notifyListeners(); } updateBookmarkName(bookmarkIndex, newName) { const bookmark = this._bookmarks.find((bm) => bm.bookmarkIndex === bookmarkIndex); if (bookmark) { if (newName === '') { bookmark.name = undefined; } else { bookmark.name = newName; } this.notifyListeners(); } } get initialBookmark() { return this._initialBookmark; } get bookmarks() { return this._bookmarks; } }; exports.BookmarkRegistry = BookmarkRegistry; __decorate([ (0, inversify_1.inject)(di_symbols_1.DISymbol.RenderOptionsRegistry), __metadata("design:type", render_options_registry_1.RenderOptionsRegistry) ], BookmarkRegistry.prototype, "renderOptionsRegistry", void 0); exports.BookmarkRegistry = BookmarkRegistry = __decorate([ (0, inversify_1.injectable)() ], BookmarkRegistry); //# sourceMappingURL=bookmark-registry.js.map