UNPKG

@itwin/core-react

Version:

A react component library of iTwin.js UI general purpose components

112 lines 5.61 kB
/*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ /** @packageDocumentation * @module Settings */ import { BeUiEvent, Logger } from "@itwin/core-bentley"; import { UiCore } from "../UiCore.js"; /** Event class for [[this.onSettingsProvidersChanged]] which is emitted when a new SettingsTabsProvider is added or removed. * @public * @deprecated in 4.13.0. This class should not be used by applications to instantiate objects. */ export class SettingsProvidersChangedEvent extends BeUiEvent { } /** Event class for [[this.onProcessSettingsTabActivation]] which is emitted when a new Tab needs to be activated. This allows the current * settings page to save its settings before activating the new SettingTab. * @public * @deprecated in 4.13.0. This class should not be used by applications to instantiate objects. */ export class ProcessSettingsTabActivationEvent extends BeUiEvent { } /** Event class for [[this.onProcessSettingsContainerClose]] which is emitted when the settings container will be closed. This allows the current * settings page to save its settings before calling the function to close the container. * @public * @deprecated in 4.13.0. This class should not be used by applications to instantiate objects. */ export class ProcessSettingsContainerCloseEvent extends BeUiEvent { } /** Event class for [[this.onActivateSettingsTab]] which is emitted when API call needs to set the active settings tab (ie via Tool key-in). * @public * @deprecated in 4.13.0. This class should not be used by applications to instantiate objects. */ export class ActivateSettingsTabEvent extends BeUiEvent { } /** Settings Manager class. Hold registration of settings providers and supplies events for the provided settings pages to listen. * @public * @deprecated in 4.16.0. Use {@link @itwin/appui-react#SettingsManager} instead. */ export class SettingsManager { constructor() { this._providers = []; /** Event raised when SettingsProviders are changed. */ this.onSettingsProvidersChanged = new SettingsProvidersChangedEvent(); /** Event raised solely for a settings page to monitor so it can save its settings before continuing tab activation. * See React hook function `useSaveBeforeActivatingNewSettingsTab`. */ this.onProcessSettingsTabActivation = new ProcessSettingsTabActivationEvent(); /** Event raised when the settings container will be closed. Any setting page component that is 'modal' should register to * listen to this event so that it can save its state before closing. See React hook function `useSaveBeforeClosingSettingsContainer`. */ this.onProcessSettingsContainerClose = new ProcessSettingsContainerCloseEvent(); /** Event raised to change the active settings tab shown in UI. Monitored by the SettingsContainer. * @internal */ this.onActivateSettingsTab = new BeUiEvent(); /** Event monitored by SettingsContainer to process request to close the settings container. * @internal */ this.onCloseSettingsContainer = new BeUiEvent(); } get providers() { return this._providers; } set providers(p) { this._providers = p; this.onSettingsProvidersChanged.emit({ providers: p }); } /** Called by application when an tool, keyin, or other process want to change the active settings tab/page giving the current tab/page and opportunity * to save its state. */ activateSettingsTab(settingsTabId) { this.onActivateSettingsTab.emit({ settingsTabId }); } /** Called by application when the Settings Container is to be closed. The function to invoke to actually close the Settings Container is * passed in and executed once the active settings tab/page has a chance to save its settings. */ closeSettingsContainer(closeFunc, closeFuncArgs) { this.onCloseSettingsContainer.emit({ closeFunc, closeFuncArgs }); } addSettingsProvider(settingsProvider) { const foundProvider = this._providers.find((p) => p.id === settingsProvider.id); if (!foundProvider) { const updatedProviders = [...this.providers, settingsProvider]; this.providers = updatedProviders; } else { Logger.logInfo(UiCore.loggerCategory("SettingsManager"), `Settings Provider with id of ${settingsProvider.id} has already been registered`); } } removeSettingsProvider(providerId) { let result = false; const updatedProviders = this._providers.filter((p) => p.id !== providerId); if (updatedProviders.length !== this._providers.length) { this.providers = updatedProviders; result = true; } return result; } /** Get an array of SettingsTabEntry objects to populate the settings container. */ getSettingEntries(stageId, stageUsage) { const allSettingEntries = []; // Consult the registered SettingsProviders this._providers.forEach((p) => { const entries = p.getSettingEntries(stageId, stageUsage); entries && allSettingEntries.push(...entries); }); return allSettingEntries; } } //# sourceMappingURL=SettingsManager.js.map