@@ -12,11 +12,13 @@ import {
1212 updateAppState ,
1313 deletePanelFromWindow ,
1414 deleteHiddenPanel ,
15+ activePanel ,
1516} from '../lib/store' ;
1617import { theme , Theme } from '../lib/theme' ;
1718import { isOutside , keyBy , exclude } from '../lib/utils' ;
1819import { MenuItem , openContextMenu } from './menu' ;
1920import { GemPanelWindowElement , windowTagName } from './window' ;
21+ import { Side } from './window-handle' ;
2022import './menu' ;
2123
2224@customElement ( 'gem-panel' )
@@ -55,17 +57,22 @@ export class GemPanelElement extends GemElement {
5557 #save = ( ) => this . #cacheAs( ) ;
5658
5759 #queryPanel = ( arg : string | Panel , panels : Panel [ ] ) => {
58- const title = typeof arg === 'string' ? arg : arg . name ;
59- return panels . find ( ( e ) => e . name === title ) ;
60+ const panelName = typeof arg === 'string' ? arg : arg . name ;
61+ return panels . find ( ( e ) => e . name === panelName ) ;
6062 } ;
6163
62- #queryWindow = ( panel : Panel ) => {
63- return store . layout . windows . find ( ( w ) => w . panels . includes ( panel . name ) ) ;
64+ #queryWindow = ( arg : string | Panel ) => {
65+ const panelName = typeof arg === 'string' ? arg : arg . name ;
66+ return store . layout . windows . find ( ( w ) => w . panels . includes ( panelName ) ) ;
67+ } ;
68+
69+ #getAllWindowElement = ( ) => {
70+ return [ ...this . shadowRoot ! . querySelectorAll < GemPanelWindowElement > ( windowTagName ) ] ;
6471 } ;
6572
6673 #cleanOutsideWindow = ( ) => {
6774 const rect = this . getBoundingClientRect ( ) ;
68- this . shadowRoot ?. querySelectorAll < GemPanelWindowElement > ( windowTagName ) . forEach ( ( ele ) => {
75+ this . #getAllWindowElement ( ) . forEach ( ( ele ) => {
6976 if ( ele . window . isGridWindow ( ) ) return ;
7077 const targetRect = ele . getBoundingClientRect ( ) ;
7178 if ( isOutside ( rect , targetRect ) ) {
@@ -177,16 +184,39 @@ export class GemPanelElement extends GemElement {
177184 return Object . values ( exclude ( { ...store . panels } , 'name' , this . showPanels ) ) ;
178185 }
179186
180- openHiddenPanel ( arg : string | Panel ) {
181- const panel = this . #queryPanel( arg , this . hiddenPanels ) ;
187+ getWindow ( arg : string | Panel ) {
188+ const panel = this . #queryPanel( arg , this . showPanels ) ;
182189 if ( ! panel ) return ;
183- openHiddenPanel ( panel . name ) ;
190+ return this . #queryWindow ( panel ) ;
184191 }
185192
186- openPanelInWindow ( arg : string | Panel , window : Window ) {
187- const panel = this . #queryPanel( arg , this . hiddenPanels ) ;
193+ activePanel ( arg : string | Panel ) {
194+ const panel = this . #queryPanel( arg , this . showPanels ) ;
188195 if ( ! panel ) return ;
189- openPanelInWindow ( window , panel . name ) ;
196+ const window = this . #queryWindow( arg ) ;
197+ if ( ! window ) return ;
198+ activePanel ( window , panel . name ) ;
199+ this . #getAllWindowElement( )
200+ . find ( ( ele ) => ele . window === window )
201+ ?. focus ( ) ;
202+ }
203+
204+ openPanel ( arg : string | Panel ) {
205+ const panel = this . #queryPanel( arg , this . hiddenPanels ) ;
206+ if ( ! panel ) {
207+ this . activePanel ( arg ) ;
208+ } else {
209+ openHiddenPanel ( panel . name ) ;
210+ }
211+ }
212+
213+ openPanelInWindow ( arg : string | Panel , window : Window , side ?: Side ) {
214+ const panel = this . #queryPanel( arg , this . hiddenPanels ) ;
215+ if ( ! panel ) {
216+ this . activePanel ( arg ) ;
217+ } else {
218+ openPanelInWindow ( window , panel . name , side ) ;
219+ }
190220 }
191221
192222 closePanel ( arg : string | Panel ) {
0 commit comments