packageDocumentation module import { BeEvent , Logger } from "@itwin/core-bentley" ; import { BackstageItem } from "./backstage/BackstageItem" ; import { CommonStatusBarItem } from "./statusbar/StatusBarItem" ; import { CommonToolbarItem , ToolbarOrientation , ToolbarUsage } from "./toolbars/ToolbarItem" ; import { AbstractWidgetProps } from "./widget/AbstractWidgetProps" ; import { AbstractZoneLocation , StagePanelLocation , StagePanelSection } from "./widget/StagePanel" ; import { loggerCategory } from "./utils/misc" ; import { StageUsage } from "./items/StageUsage" ; public export enum UiItemsApplicationAction { /** Allow the change to the item */ Allow , /** Disallow the change to the item */ Disallow , /** Update the item during the change */ Update } public export interface UiItemsProvider { /** id of provider */ readonly id : string ; /** UiItemsManager calls following method to get items to populate specific toolbars */ provideToolbarButtonItems ? : ( stageId : string , stageUsage : string , toolbarUsage : ToolbarUsage , toolbarOrientation : ToolbarOrientation , stageAppData ? : any ) => CommonToolbarItem [ ] ; /** UiItemsManager calls following method to augment base statusbar for stages that allow it. */ provideStatusBarItems ? : ( stageId : string , stageUsage : string , stageAppData ? : any ) => CommonStatusBarItem [ ] ; /** UiItemsManager calls following method to augment backstage items. */ provideBackstageItems ? : ( ) => BackstageItem [ ] ; note provideWidgets ? : ( stageId : string , stageUsage : string , location : StagePanelLocation , section ? : StagePanelSection , zoneLocation ? : AbstractZoneLocation , stageAppData ? : any ) => ReadonlyArray < AbstractWidgetProps > ; /** Function called when the provider is unregistered via `ItemsManager.unregister` to allow provider to do cleanup. */ onUnregister ? : ( ) => void ; } public export class BaseUiItemsProvider implements UiItemsProvider { constructor ( protected _providerId , public isSupportedStage ? ) { } public get id ( ) : string { return this . _providerId ; } public onUnregister ( ) { } public unregister ( ) { UiItemsManager . unregister ( this . _providerId ) ; } /** Backstage items are not stage specific so no callback is used */ public provideBackstageItems ( ) { return [ ] ; } public provideToolbarButtonItemsInternal ( _stageId , _stageUsage , _toolbarUsage , _toolbarOrientation , _stageAppData ? ) { return [ ] ; } public provideToolbarButtonItems ( stageId , stageUsage , toolbarUsage , toolbarOrientation , stageAppData ? ) { let provideToStage = false ; if ( this . isSupportedStage ) { provideToStage = this . isSupportedStage ( stageId , stageUsage , stageAppData ) ; } else { provideToStage = ( stageUsage === StageUsage . General ) ; } return provideToStage ? this . provideToolbarButtonItemsInternal ( stageId , stageUsage , toolbarUsage , toolbarOrientation , stageAppData ) : [ ] ; } public provideStatusBarItemsInternal ( _stageId , _stageUsage , _stageAppData ? ) { return [ ] ; } public provideStatusBarItems ( stageId , stageUsage , stageAppData ? ) { let provideToStage = false ; if ( this . isSupportedStage ) { provideToStage = this . isSupportedStage ( stageId , stageUsage , stageAppData ) ; } else { provideToStage = ( stageUsage === StageUsage . General ) ; } return provideToStage ? this . provideStatusBarItemsInternal ( stageId , stageUsage , stageAppData ) : [ ] ; } public provideWidgetsInternal ( _stageId , _stageUsage , _location , _section ? , _stageAppData ? ) { return [ ] ; } public provideWidgets ( stageId , stageUsage , location , section ? , _zoneLocation ? , stageAppData ? ) { let provideToStage = false ; if ( this . isSupportedStage ) { provideToStage = this . isSupportedStage ( stageId , stageUsage , stageAppData ) ; } else { provideToStage = ( stageUsage === StageUsage . General ) ; } return provideToStage ? this . provideWidgetsInternal ( stageId , stageUsage , location , section , stageAppData ) : [ ] ; } } public export interface UiItemProviderRegisteredEventArgs { providerId : string ; } public export class UiItemsManager { private static _registeredUiItemsProviders : Map < string , UiItemsProvider > = new Map < string , UiItemsProvider > ( ) ; /** Event raised any time a UiProvider is registered or unregistered. */ public static readonly onUiProviderRegisteredEvent = new BeEvent < ( ev : UiItemProviderRegisteredEventArgs ) => void > ( ) ; /** Return number of registered UiProvider. */ public static get registeredProviderIds ( ) { const ids = [ ... UiItemsManager . _registeredUiItemsProviders . keys ( ) ] ; return ids ; } /** Return true if there is any registered UiProvider. */ public static get hasRegisteredProviders ( ) : boolean { return this . _registeredUiItemsProviders . size > 0 ; } param providerId public static getUiItemsProvider ( providerId ) { return UiItemsManager . _registeredUiItemsProviders . get ( providerId ) ; } private static sendRegisteredEvent ( ev ) { UiItemsManager . onUiProviderRegisteredEvent . raiseEvent ( ev ) ; } param uiProvider public static register ( uiProvider ) { if ( UiItemsManager . getUiItemsProvider ( uiProvider . id ) ) { Logger . logInfo ( loggerCategory ( this ) , `UiItemsProvider (${ uiProvider . id }) is already loaded` ) ; } else { UiItemsManager . _registeredUiItemsProviders . set ( uiProvider . id , uiProvider ) ; Logger . logInfo ( loggerCategory ( this ) , `UiItemsProvider (${ uiProvider . id }) loaded` ) ; UiItemsManager . sendRegisteredEvent ( { providerId : uiProvider . id } as UiItemProviderRegisteredEventArgs ) ; } } /** Remove a specific UiItemsProvider from the list of available providers. */ public static unregister ( uiProviderId ) { const provider = UiItemsManager . getUiItemsProvider ( uiProviderId ) ; if ( ! provider ) return ; provider . onUnregister && provider . onUnregister ( ) ; UiItemsManager . _registeredUiItemsProviders . delete ( uiProviderId ) ; Logger . logInfo ( loggerCategory ( this ) , `UiItemsProvider (${ uiProviderId }) unloaded` ) ; UiItemsManager . sendRegisteredEvent ( { providerId : uiProviderId } as UiItemProviderRegisteredEventArgs ) ; } param stageId param stageUsage param toolbarUsage param toolbarOrientation returns public static getToolbarButtonItems ( stageId , stageUsage , toolbarUsage , toolbarOrientation , stageAppData ? ) { const buttonItems = [ ] ; if ( 0 === UiItemsManager . _registeredUiItemsProviders . size ) return buttonItems ; UiItemsManager . _registeredUiItemsProviders . forEach ( ( uiProvider ) => { if ( uiProvider . provideToolbarButtonItems ) { uiProvider . provideToolbarButtonItems ( stageId , stageUsage , toolbarUsage , toolbarOrientation , stageAppData ) . forEach ( ( spec ) => buttonItems . push ( { ... spec , providerId : uiProvider . id } ) ) ; } } ) ; return buttonItems ; } param stageId param stageUsage returns public static getStatusBarItems ( stageId , stageUsage , stageAppData ? ) { const statusBarItems = [ ] ; if ( 0 === UiItemsManager . _registeredUiItemsProviders . size ) return statusBarItems ; UiItemsManager . _registeredUiItemsProviders . forEach ( ( uiProvider ) => { if ( uiProvider . provideStatusBarItems ) { uiProvider . provideStatusBarItems ( stageId , stageUsage , stageAppData ) . forEach ( ( item ) => statusBarItems . push ( { ... item , providerId : uiProvider . id } ) ) ; } } ) ; return statusBarItems ; } returns public static getBackstageItems ( ) { const backstageItems = [ ] ; if ( 0 === UiItemsManager . _registeredUiItemsProviders . size ) return backstageItems ; UiItemsManager . _registeredUiItemsProviders . forEach ( ( uiProvider ) => { if ( uiProvider . provideBackstageItems ) { uiProvider . provideBackstageItems ( ) . forEach ( ( item ) => backstageItems . push ( { ... item , providerId : uiProvider . id } ) ) ; } } ) ; return backstageItems ; } param stageId param stageUsage param location param section returns public static getWidgets ( stageId , stageUsage , location , section ? , zoneLocation ? , stageAppData ? ) { const widgets = [ ] ; if ( 0 === UiItemsManager . _registeredUiItemsProviders . size ) return widgets ; UiItemsManager . _registeredUiItemsProviders . forEach ( ( uiProvider ) => { if ( uiProvider . provideWidgets ) { uiProvider . provideWidgets ( stageId , stageUsage , location , section , zoneLocation , stageAppData ) . forEach ( ( widget ) => widgets . push ( { ... widget , providerId : uiProvider . id } ) ) ; } } ) ; return widgets ; } }