UNPKG

theia-sprotty

Version:

Glue code for sprotty diagrams in a Theia IDE

64 lines 3.18 kB
"use strict"; /* * Copyright (C) 2017 TypeFox and others. * * Licensed under the Apache License, Version 2.0 (the "License") you may not use this file except in compliance with the License. * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-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); }; var __param = (this && this.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; Object.defineProperty(exports, "__esModule", { value: true }); var inversify_1 = require("inversify"); var common_1 = require("@theia/filesystem/lib/common"); var common_2 = require("@theia/core/lib/common"); var TheiaFileSaver = /** @class */ (function () { function TheiaFileSaver(fileSystem, messageService) { this.fileSystem = fileSystem; this.messageService = messageService; } TheiaFileSaver.prototype.save = function (sourceUri, action) { var _this = this; this.getNextFileName(sourceUri).then(function (fileName) { return _this.fileSystem.createFile(fileName, { content: action.svg }) .then(function () { return _this.messageService.info("Diagram exported to '" + fileName + "'"); }) .catch(function (error) { return _this.messageService.error("Error exporting diagram '" + error); }); }); }; TheiaFileSaver.prototype.getNextFileName = function (sourceUri) { var _this = this; return new Promise(function (resolve) { return _this.tryNextFileName(sourceUri, 0, resolve); }); }; TheiaFileSaver.prototype.tryNextFileName = function (sourceURI, count, resolve) { var _this = this; var currentName = sourceURI + (count === 0 ? '' : count) + '.svg'; this.fileSystem.exists(currentName).then(function (exists) { if (!exists) resolve(currentName); else _this.tryNextFileName(sourceURI, ++count, resolve); }); }; TheiaFileSaver = __decorate([ inversify_1.injectable(), __param(0, inversify_1.inject(common_1.FileSystem)), __param(1, inversify_1.inject(common_2.MessageService)), __metadata("design:paramtypes", [Object, common_2.MessageService]) ], TheiaFileSaver); return TheiaFileSaver; }()); exports.TheiaFileSaver = TheiaFileSaver; //# sourceMappingURL=theia-file-saver.js.map