packageDocumentation module import { BeUiEvent , Logger } from "@itwin/core-bentley" ; import { ConditionalBooleanValue } from "@itwin/appui-abstract" ; import { UiCore } from "../UiCore" ; public export interface SettingsTabEntry { /** unique id for entry */ readonly tabId : string ; /** localized display label */ readonly label : string ; /** Setting page content to display when tab item is selected. */ readonly page : JSX . Element ; /** Setting to true if page will register to watch for stage closing event so it can save any dirty settings. Page component should register and handle the events:
     * `settingsManager.onProcessSettingsTabActivation` and `settingsManager.onProcessSettingsContainerClose` */ readonly pageWillHandleCloseRequest ? : boolean ; /** used to determine position in tablist */ readonly itemPriority : number ; /** Optional Subtitle to show below label. */ readonly subLabel ? : string ; /** Icon specification */ readonly icon ? : string | JSX . Element ; /** Tooltip. Allows JSX|Element to support react-tooltip component */ readonly tooltip ? : string | JSX . Element ; /** Allows Settings entry to be disabled */ readonly isDisabled ? : boolean | ConditionalBooleanValue ; } public export class SettingsProvidersChangedEvent extends BeUiEvent < SettingsProvidersChangedEventArgs > { } public export interface SettingsProvidersChangedEventArgs { readonly providers : ReadonlyArray < SettingsTabsProvider > ; } public export class ProcessSettingsTabActivationEvent extends BeUiEvent < ProcessSettingsTabActivationEventArgs > { } public export interface ProcessSettingsTabActivationEventArgs { readonly tabSelectionFunc : ( tabId : string ) => void ; readonly requestedSettingsTabId : string ; } public export class ProcessSettingsContainerCloseEvent extends BeUiEvent < ProcessSettingsContainerCloseEventArgs > { } internal export class CloseSettingsContainerEvent extends BeUiEvent < ProcessSettingsContainerCloseEventArgs > { } public export interface ProcessSettingsContainerCloseEventArgs { readonly closeFunc : ( args : any ) => void ; readonly closeFuncArgs ? : any ; } public export class ActivateSettingsTabEvent extends BeUiEvent < ActivateSettingsTabEventArgs > { } public export interface ActivateSettingsTabEventArgs { readonly settingsTabId : string ; } public export interface SettingsTabsProvider { /** Id of provider, used to remove registration. */ readonly id : string ; getSettingEntries ( stageId , stageUsage ) : ReadonlyArray < SettingsTabEntry > | undefined ; } public export class SettingsManager { private _providers : ReadonlyArray < SettingsTabsProvider > = [ ] ; /** Event raised when SettingsProviders are changed.
     */ public readonly 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`.
     */ public readonly 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`.
     */ public readonly onProcessSettingsContainerClose = new ProcessSettingsContainerCloseEvent ( ) ; internal public readonly onActivateSettingsTab = new ActivateSettingsTabEvent ( ) ; internal public readonly onCloseSettingsContainer = new CloseSettingsContainerEvent ( ) ; public public get providers ( ) : ReadonlyArray < SettingsTabsProvider > { return this . _providers ; } public 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.
     */ public 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.
     */ public closeSettingsContainer ( closeFunc , closeFuncArgs ? ) { this . onCloseSettingsContainer . emit ( { closeFunc , closeFuncArgs } ) ; } public 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 ( this ) , `Settings Provider with id of ${ settingsProvider . id } has already been registered` ) ; } } public 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. */ public getSettingEntries ( stageId , stageUsage ) { const allSettingEntries = [ ] ; this . _providers . forEach ( ( p ) => { const entries = p . getSettingEntries ( stageId , stageUsage ) ; entries && allSettingEntries . push ( ... entries ) ; } ) ; return allSettingEntries ; } }