UNPKG

@theia/core

Version:

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

93 lines • 4.05 kB
// ***************************************************************************** // Copyright (C) 2026 JuliaHub 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 SidePanelItemVisibilityImpl_1; import { __decorate } from "tslib"; import { inject, injectable, postConstruct } from 'inversify'; import { Emitter } from '../../common/event.js'; import { Deferred } from '../../common/promise-util.js'; import { LocalStorageService } from '../storage-service.js'; export const SidePanelItemVisibility = Symbol('SidePanelItemVisibility'); /** * To keep the user's choices somewhere other than local storage, override `load()` and `save()` * rather than rebinding `LocalStorageService`, which every other consumer of it shares. */ let SidePanelItemVisibilityImpl = class SidePanelItemVisibilityImpl { constructor() { this.onDidChangeEmitter = new Emitter(); this.onDidChange = this.onDidChangeEmitter.event; this.onDidResetEmitter = new Emitter(); this.onDidReset = this.onDidResetEmitter.event; this.loaded = new Deferred(); this.ready = this.loaded.promise; /** Explicit user choices only, so items the user never touched follow `isHiddenByDefault`. */ this.overrides = {}; } static { SidePanelItemVisibilityImpl_1 = this; } static { this.STORAGE_KEY = 'sidePanel.hiddenItems'; } init() { this.load().finally(() => this.loaded.resolve()); } async load() { const stored = await this.storageService.getData(SidePanelItemVisibilityImpl_1.STORAGE_KEY); this.overrides = { ...stored, ...this.overrides }; } isHidden(widgetId) { return this.overrides[widgetId] ?? this.isHiddenByDefault(widgetId); } setHidden(widgetId, hidden) { if (this.isHidden(widgetId) === hidden) { return; } this.overrides[widgetId] = hidden; this.save(); this.onDidChangeEmitter.fire(widgetId); } reset() { if (Object.keys(this.overrides).length === 0) { return; } this.overrides = {}; this.save(); this.onDidResetEmitter.fire(); } /** * Whether an item the user has neither hidden nor shown starts hidden. Override this to * give an application its own defaults. * * Defaults are not limited to leaving one item visible per side the way the user's choices are, * so an application can start every item on a side hidden. Expanding a side panel without naming * a view can still open a hidden item, through the last active index or the first tab, and its * tab then shows while it is current, the same as opening it by command. */ isHiddenByDefault(widgetId) { return false; } save() { const data = Object.keys(this.overrides).length > 0 ? this.overrides : undefined; this.storageService.setData(SidePanelItemVisibilityImpl_1.STORAGE_KEY, data); } }; __decorate([ inject(LocalStorageService) ], SidePanelItemVisibilityImpl.prototype, "storageService", void 0); __decorate([ postConstruct() ], SidePanelItemVisibilityImpl.prototype, "init", null); SidePanelItemVisibilityImpl = SidePanelItemVisibilityImpl_1 = __decorate([ injectable() ], SidePanelItemVisibilityImpl); export { SidePanelItemVisibilityImpl }; //# sourceMappingURL=side-panel-item-visibility.js.map