@@ -8,6 +8,12 @@ import type {
88} from '@deephaven/golden-layout' ;
99import Log from '@deephaven/log' ;
1010import PanelEvent from './PanelEvent' ;
11+ import {
12+ listenForCycleToNextStack ,
13+ listenForCycleToPreviousStack ,
14+ listenForCycleToNextTab ,
15+ listenForCycleToPreviousTab ,
16+ } from './NavigationEvent' ;
1117import LayoutUtils , { isReactComponentConfig } from './layout/LayoutUtils' ;
1218import {
1319 isWrappedComponent ,
@@ -69,6 +75,8 @@ class PanelManager {
6975
7076 openedMap : OpenedPanelMap ;
7177
78+ navigationEventListenerRemovers : ( ( ) => void ) [ ] ;
79+
7280 /**
7381 * @param layout The GoldenLayout object to attach to
7482 * @param hydrateComponent Function to hydrate a panel from a dehydrated state
@@ -113,6 +121,9 @@ class PanelManager {
113121 // Closed panels are stored in their dehydrated state
114122 this . closed = [ ...closed ] ;
115123
124+ // Store the navigation event listener removers
125+ this . navigationEventListenerRemovers = [ ] ;
126+
116127 this . startListening ( ) ;
117128 }
118129
@@ -122,21 +133,24 @@ class PanelManager {
122133 eventHub . on ( PanelEvent . MOUNT , this . handleMount ) ;
123134 eventHub . on ( PanelEvent . UNMOUNT , this . handleUnmount ) ;
124135 eventHub . on ( PanelEvent . REOPEN , this . handleReopen ) ;
125- eventHub . on ( PanelEvent . CYCLE_TO_NEXT_STACK , this . handleCycleToNextStack ) ;
126- eventHub . on (
127- PanelEvent . CYCLE_TO_PREVIOUS_STACK ,
128- this . handleCycleToPreviousStack
129- ) ;
130- eventHub . on ( PanelEvent . CYCLE_TO_NEXT_TAB , this . handleCycleToNextTab ) ;
131- eventHub . on (
132- PanelEvent . CYCLE_TO_PREVIOUS_TAB ,
133- this . handleCycleToPreviousTab
134- ) ;
135136 eventHub . on ( PanelEvent . REOPEN_LAST , this . handleReopenLast ) ;
136137 eventHub . on ( PanelEvent . DELETE , this . handleDeleted ) ;
137138 eventHub . on ( PanelEvent . CLOSED , this . handleClosed ) ;
138139 eventHub . on ( PanelEvent . CLOSE , this . handleControlClose ) ;
139140 // PanelEvent.OPEN should be listened to by plugins to open a panel
141+
142+ this . navigationEventListenerRemovers . push (
143+ listenForCycleToNextStack ( eventHub , this . handleCycleToNextStack )
144+ ) ;
145+ this . navigationEventListenerRemovers . push (
146+ listenForCycleToPreviousStack ( eventHub , this . handleCycleToPreviousStack )
147+ ) ;
148+ this . navigationEventListenerRemovers . push (
149+ listenForCycleToNextTab ( eventHub , this . handleCycleToNextTab )
150+ ) ;
151+ this . navigationEventListenerRemovers . push (
152+ listenForCycleToPreviousTab ( eventHub , this . handleCycleToPreviousTab )
153+ ) ;
140154 }
141155
142156 stopListening ( ) : void {
@@ -145,20 +159,13 @@ class PanelManager {
145159 eventHub . off ( PanelEvent . MOUNT , this . handleMount ) ;
146160 eventHub . off ( PanelEvent . UNMOUNT , this . handleUnmount ) ;
147161 eventHub . off ( PanelEvent . REOPEN , this . handleReopen ) ;
148- eventHub . off ( PanelEvent . CYCLE_TO_NEXT_STACK , this . handleCycleToNextStack ) ;
149- eventHub . off (
150- PanelEvent . CYCLE_TO_PREVIOUS_STACK ,
151- this . handleCycleToPreviousStack
152- ) ;
153- eventHub . off ( PanelEvent . CYCLE_TO_NEXT_TAB , this . handleCycleToNextTab ) ;
154- eventHub . off (
155- PanelEvent . CYCLE_TO_PREVIOUS_TAB ,
156- this . handleCycleToPreviousTab
157- ) ;
158162 eventHub . off ( PanelEvent . REOPEN_LAST , this . handleReopenLast ) ;
159163 eventHub . off ( PanelEvent . DELETE , this . handleDeleted ) ;
160164 eventHub . off ( PanelEvent . CLOSED , this . handleClosed ) ;
161165 eventHub . off ( PanelEvent . CLOSE , this . handleControlClose ) ;
166+
167+ this . navigationEventListenerRemovers . forEach ( remover => remover ( ) ) ;
168+ this . navigationEventListenerRemovers = [ ] ;
162169 }
163170
164171 getClosedPanelConfigsOfType ( typeString : string ) : ClosedPanels {
@@ -301,13 +308,13 @@ class PanelManager {
301308 this . sendUpdate ( ) ;
302309 }
303310
304- handleCycleStack ( direction : CycleDirection ) : void {
311+ cycleStack ( direction : CycleDirection ) : void {
305312 const allStacks = LayoutUtils . getAllStackContainers ( this . layout ) ;
306313 if ( allStacks . length <= 1 ) {
307314 return ;
308315 }
309316
310- const focusedIndex = LayoutUtils . getFocusedStackIndex ( this . layout ) ;
317+ const focusedIndex = LayoutUtils . getFocusedStackIndex ( allStacks ) ;
311318
312319 // If no stack is focused, activate the first stack's content item
313320 if ( focusedIndex === - 1 ) {
@@ -338,14 +345,14 @@ class PanelManager {
338345 }
339346
340347 handleCycleToNextStack ( ) : void {
341- this . handleCycleStack ( CycleDirection . Next ) ;
348+ this . cycleStack ( CycleDirection . Next ) ;
342349 }
343350
344351 handleCycleToPreviousStack ( ) : void {
345- this . handleCycleStack ( CycleDirection . Previous ) ;
352+ this . cycleStack ( CycleDirection . Previous ) ;
346353 }
347354
348- handleCycleTab ( direction : CycleDirection ) : void {
355+ cycleTab ( direction : CycleDirection ) : void {
349356 const focusedStack = LayoutUtils . getFocusedStack ( this . layout ) ;
350357 if ( focusedStack === undefined ) {
351358 return ;
@@ -367,11 +374,11 @@ class PanelManager {
367374 }
368375
369376 handleCycleToNextTab ( ) : void {
370- this . handleCycleTab ( CycleDirection . Next ) ;
377+ this . cycleTab ( CycleDirection . Next ) ;
371378 }
372379
373380 handleCycleToPreviousTab ( ) : void {
374- this . handleCycleTab ( CycleDirection . Previous ) ;
381+ this . cycleTab ( CycleDirection . Previous ) ;
375382 }
376383
377384 /**
0 commit comments