UNPKG

3.98 kBJavaScriptView Raw
1"use strict";
2// *****************************************************************************
3// Copyright (C) 2021 SAP SE or an SAP affiliate company 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 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};
26var QuickViewService_1;
27Object.defineProperty(exports, "__esModule", { value: true });
28exports.QuickViewService = void 0;
29const inversify_1 = require("inversify");
30const common_1 = require("../../common");
31const context_key_service_1 = require("../context-key-service");
32const quick_access_1 = require("./quick-access");
33const quick_input_service_1 = require("./quick-input-service");
34let QuickViewService = QuickViewService_1 = class QuickViewService {
35 constructor() {
36 this.items = [];
37 this.hiddenItemLabels = new Set();
38 }
39 registerItem(item) {
40 const quickOpenItem = {
41 label: item.label,
42 execute: () => item.open(),
43 when: item.when
44 };
45 this.items.push(quickOpenItem);
46 this.items.sort((a, b) => a.label.localeCompare(b.label));
47 return common_1.Disposable.create(() => {
48 const index = this.items.indexOf(quickOpenItem);
49 if (index !== -1) {
50 this.items.splice(index, 1);
51 }
52 });
53 }
54 hideItem(label) {
55 this.hiddenItemLabels.add(label);
56 }
57 showItem(label) {
58 this.hiddenItemLabels.delete(label);
59 }
60 registerQuickAccessProvider() {
61 this.quickAccessRegistry.registerQuickAccessProvider({
62 getInstance: () => this,
63 prefix: QuickViewService_1.PREFIX,
64 placeholder: '',
65 helpEntries: [{ description: 'Open View', needsEditor: false }]
66 });
67 }
68 getPicks(filter, token) {
69 const items = this.items.filter(item => (item.when === undefined || this.contextKexService.match(item.when)) &&
70 (!this.hiddenItemLabels.has(item.label)));
71 return (0, quick_input_service_1.filterItems)(items, filter);
72 }
73};
74QuickViewService.PREFIX = 'view ';
75__decorate([
76 (0, inversify_1.inject)(quick_access_1.QuickAccessRegistry),
77 __metadata("design:type", Object)
78], QuickViewService.prototype, "quickAccessRegistry", void 0);
79__decorate([
80 (0, inversify_1.inject)(context_key_service_1.ContextKeyService),
81 __metadata("design:type", Object)
82], QuickViewService.prototype, "contextKexService", void 0);
83QuickViewService = QuickViewService_1 = __decorate([
84 (0, inversify_1.injectable)()
85], QuickViewService);
86exports.QuickViewService = QuickViewService;
87//# sourceMappingURL=quick-view-service.js.map
\No newline at end of file