UNPKG

sprotty-theia

Version:

Glue code for Sprotty diagrams in a Theia IDE

68 lines 3.55 kB
"use strict"; /******************************************************************************** * Copyright (c) 2017-2018 TypeFox and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. * * This Source Code may also be made available under the following Secondary * Licenses when the conditions for such availability set forth in the Eclipse * Public License v. 2.0 are satisfied: GNU General Public License, version 2 * with the GNU Classpath Exception which is available at * https://www.gnu.org/software/classpath/license.html. * * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-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.TheiaFileSaver = void 0; const inversify_1 = require("inversify"); const uri_1 = require("@theia/core/lib/common/uri"); const file_service_1 = require("@theia/filesystem/lib/browser/file-service"); const common_1 = require("@theia/core/lib/common"); let TheiaFileSaver = /** @class */ (() => { let TheiaFileSaver = class TheiaFileSaver { save(sourceUri, action) { this.getNextFileName(sourceUri).then(fileName => { this.fileService.write(new uri_1.default(fileName), action.svg) .then(() => this.messageService.info(`Diagram exported to '${fileName}'`)) .catch((error) => this.messageService.error(`Error exporting diagram '${error}`)); }); } getNextFileName(sourceUri) { return new Promise(resolve => this.tryNextFileName(sourceUri, 0, resolve)); } tryNextFileName(sourceURI, count, resolve) { const currentName = sourceURI + (count === 0 ? '' : count) + '.svg'; this.fileService.exists(new uri_1.default(currentName)).then(exists => { if (!exists) resolve(currentName); else this.tryNextFileName(sourceURI, ++count, resolve); }); } }; __decorate([ inversify_1.inject(file_service_1.FileService), __metadata("design:type", file_service_1.FileService) ], TheiaFileSaver.prototype, "fileService", void 0); __decorate([ inversify_1.inject(common_1.MessageService), __metadata("design:type", common_1.MessageService) ], TheiaFileSaver.prototype, "messageService", void 0); TheiaFileSaver = __decorate([ inversify_1.injectable() ], TheiaFileSaver); return TheiaFileSaver; })(); exports.TheiaFileSaver = TheiaFileSaver; //# sourceMappingURL=theia-file-saver.js.map