UNPKG

3.41 kBJavaScriptView Raw
1"use strict";
2/********************************************************************************
3 * Copyright (C) 2022 Arm and others.
4 *
5 * This program and the accompanying materials are made available under the
6 * terms of the Eclipse Public License v. 2.0 which is available at
7 * http://www.eclipse.org/legal/epl-2.0.
8 *
9 * This Source Code may also be made available under the following Secondary
10 * Licenses when the conditions for such availability set forth in the Eclipse
11 * Public License v. 2.0 are satisfied: GNU General Public License, version 2
12 * with the GNU Classpath Exception which is available at
13 * https://www.gnu.org/software/classpath/license.html.
14 *
15 * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16 ********************************************************************************/
17var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
18 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
19 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
20 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;
21 return c > 3 && r && Object.defineProperty(target, key, r), r;
22};
23var __metadata = (this && this.__metadata) || function (k, v) {
24 if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
25};
26Object.defineProperty(exports, "__esModule", { value: true });
27exports.SaveResourceService = void 0;
28const inversify_1 = require("inversify");
29const common_1 = require("../common");
30const navigatable_types_1 = require("./navigatable-types");
31const saveable_1 = require("./saveable");
32let SaveResourceService = class SaveResourceService {
33 /**
34 * Indicate if the document can be saved ('Save' command should be disable if not).
35 */
36 canSave(widget) {
37 return saveable_1.Saveable.isDirty(widget) && (this.canSaveNotSaveAs(widget) || this.canSaveAs(widget));
38 }
39 canSaveNotSaveAs(widget) {
40 var _a;
41 // By default, we never allow a document to be saved if it is untitled.
42 return Boolean(widget && ((_a = navigatable_types_1.NavigatableWidget.getUri(widget)) === null || _a === void 0 ? void 0 : _a.scheme) !== common_1.UNTITLED_SCHEME);
43 }
44 /**
45 * Saves the document
46 *
47 * No op if the widget is not saveable.
48 */
49 async save(widget, options) {
50 if (this.canSaveNotSaveAs(widget)) {
51 await saveable_1.Saveable.save(widget, options);
52 }
53 else if (this.canSaveAs(widget)) {
54 await this.saveAs(widget, options);
55 }
56 }
57 canSaveAs(saveable) {
58 return false;
59 }
60 saveAs(sourceWidget, options) {
61 return Promise.reject('Unsupported: The base SaveResourceService does not support saveAs action.');
62 }
63};
64__decorate([
65 (0, inversify_1.inject)(common_1.MessageService),
66 __metadata("design:type", common_1.MessageService)
67], SaveResourceService.prototype, "messageService", void 0);
68SaveResourceService = __decorate([
69 (0, inversify_1.injectable)()
70], SaveResourceService);
71exports.SaveResourceService = SaveResourceService;
72//# sourceMappingURL=save-resource-service.js.map
\No newline at end of file