UNPKG

2.81 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 ********************************************************************************/
17Object.defineProperty(exports, "__esModule", { value: true });
18exports.SaveResourceService = void 0;
19const tslib_1 = require("tslib");
20const inversify_1 = require("inversify");
21const common_1 = require("../common");
22const navigatable_types_1 = require("./navigatable-types");
23const saveable_1 = require("./saveable");
24let SaveResourceService = class SaveResourceService {
25 /**
26 * Indicate if the document can be saved ('Save' command should be disable if not).
27 */
28 canSave(widget) {
29 return saveable_1.Saveable.isDirty(widget) && (this.canSaveNotSaveAs(widget) || this.canSaveAs(widget));
30 }
31 canSaveNotSaveAs(widget) {
32 var _a;
33 // By default, we never allow a document to be saved if it is untitled.
34 return Boolean(widget && ((_a = navigatable_types_1.NavigatableWidget.getUri(widget)) === null || _a === void 0 ? void 0 : _a.scheme) !== common_1.UNTITLED_SCHEME);
35 }
36 /**
37 * Saves the document
38 *
39 * No op if the widget is not saveable.
40 */
41 async save(widget, options) {
42 if (this.canSaveNotSaveAs(widget)) {
43 await saveable_1.Saveable.save(widget, options);
44 return navigatable_types_1.NavigatableWidget.getUri(widget);
45 }
46 else if (this.canSaveAs(widget)) {
47 return this.saveAs(widget, options);
48 }
49 }
50 canSaveAs(saveable) {
51 return false;
52 }
53 saveAs(sourceWidget, options) {
54 return Promise.reject('Unsupported: The base SaveResourceService does not support saveAs action.');
55 }
56};
57(0, tslib_1.__decorate)([
58 (0, inversify_1.inject)(common_1.MessageService),
59 (0, tslib_1.__metadata)("design:type", common_1.MessageService)
60], SaveResourceService.prototype, "messageService", void 0);
61SaveResourceService = (0, tslib_1.__decorate)([
62 (0, inversify_1.injectable)()
63], SaveResourceService);
64exports.SaveResourceService = SaveResourceService;
65//# sourceMappingURL=save-resource-service.js.map
\No newline at end of file