UNPKG

@theia/core

Version:

Theia is a cloud & desktop IDE framework implemented in TypeScript.

80 lines • 3.24 kB
// ***************************************************************************** // Copyright (C) 2021 SAP SE or an SAP affiliate company 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-only WITH Classpath-exception-2.0 // ***************************************************************************** var QuickViewService_1; import { __decorate } from "tslib"; import { inject, injectable } from 'inversify'; import { Disposable } from '../../common/index.js'; import { ContextKeyService } from '../context-key-service.js'; import { QuickAccessRegistry } from './quick-access.js'; import { filterItems } from './quick-input-service.js'; let QuickViewService = class QuickViewService { constructor() { this.items = []; this.hiddenItemLabels = new Set(); } static { QuickViewService_1 = this; } static { this.PREFIX = 'view '; } registerItem(item) { const quickOpenItem = { label: item.label, description: item.description, execute: () => item.open(), when: item.when }; this.items.push(quickOpenItem); this.items.sort((a, b) => a.label.localeCompare(b.label)); return Disposable.create(() => { const index = this.items.indexOf(quickOpenItem); if (index !== -1) { this.items.splice(index, 1); } }); } hideItem(label) { this.hiddenItemLabels.add(label); } showItem(label) { this.hiddenItemLabels.delete(label); } registerQuickAccessProvider() { this.quickAccessRegistry.registerQuickAccessProvider({ getInstance: () => this, prefix: QuickViewService_1.PREFIX, placeholder: '', helpEntries: [{ description: 'Open View', needsEditor: false }] }); } getPicks(filter, token) { const items = this.items.filter(item => // Some contributions register entries without a label (e.g. an empty view name); // those would otherwise sort to the top and appear as a blank row. item.label.trim().length > 0 && (item.when === undefined || this.contextKexService.match(item.when)) && (!this.hiddenItemLabels.has(item.label))); return filterItems(items, filter); } }; __decorate([ inject(QuickAccessRegistry) ], QuickViewService.prototype, "quickAccessRegistry", void 0); __decorate([ inject(ContextKeyService) ], QuickViewService.prototype, "contextKexService", void 0); QuickViewService = QuickViewService_1 = __decorate([ injectable() ], QuickViewService); export { QuickViewService }; //# sourceMappingURL=quick-view-service.js.map