11import { DockManager } from "./DockManager.js" ;
22import { DockNode } from "./DockNode.js" ;
33import { DraggableContainer } from "./DraggableContainer.js" ;
4- import { EventHandler } from "./EventHandler .js" ;
4+ import { FloatingPanel } from "./FloatingPanel .js" ;
55import { PanelContainer } from "./PanelContainer.js" ;
66import { Point } from "./Point.js" ;
77import { ResizableContainer } from "./ResizableContainer.js" ;
88import { Utils } from "./Utils.js" ;
99import { ResizeDirection } from "./enums/ResizeDirection.js" ;
1010import { Localizer } from "./i18n/Localizer.js" ;
11- import { IContextMenuProvider } from "./interfaces/IContextMenuProvider.js" ;
1211
13- export class Dialog implements IContextMenuProvider {
14- elementDialog : HTMLDivElement & { floatingDialog : Dialog } ;
12+ export class Dialog extends FloatingPanel {
1513 draggable : DraggableContainer ;
16- panel : PanelContainer ;
17- dockManager : DockManager ;
18- eventListener : DockManager ;
19- position : Point ;
2014 resizable : ResizableContainer ;
21- disableResize : boolean ;
22- mouseDownHandler : any ;
23- onKeyPressBound : any ;
15+ eventListener : DockManager ;
2416 noDocking : boolean ;
25- isHidden : boolean ;
26- keyPressHandler : EventHandler ;
27- focusHandler : EventHandler ;
2817 grayoutParent : PanelContainer ;
2918
30- constructor ( panel : PanelContainer , dockManager : DockManager , grayoutParent ?: PanelContainer , disableResize ?: boolean ) {
31- this . panel = panel ;
32- this . dockManager = dockManager ;
33- this . eventListener = dockManager ;
19+ constructor (
20+ panel : PanelContainer ,
21+ dockManager : DockManager ,
22+ grayoutParent ?: PanelContainer ,
23+ disableResize ?: boolean
24+ ) {
25+ super ( panel , dockManager ) ;
3426 this . grayoutParent = grayoutParent ;
35- this . disableResize = disableResize ;
36- this . _initialize ( ) ;
37- this . dockManager . context . model . dialogs . push ( this ) ;
38- this . position = dockManager . defaultDialogPosition ;
39- this . dockManager . notifyOnCreateDialog ( this ) ;
40- panel . isDialog = true ;
41- }
42-
43- saveState ( x : number , y : number ) {
44- this . position = new Point ( x , y ) ;
45- this . dockManager . notifyOnChangeDialogPosition ( this , x , y ) ;
46- }
47-
48- static fromElement ( id : string , dockManager : DockManager ) {
49- return new Dialog ( new PanelContainer ( < HTMLElement > document . getElementById ( id ) , dockManager ) , dockManager , null ) ;
50- }
27+ this . eventListener = dockManager ;
5128
52- _initialize ( ) {
53- this . panel . floatingDialog = this ;
54- this . elementDialog = Object . assign ( document . createElement ( 'div' ) , { floatingDialog : this } ) ;
55- this . elementDialog . tabIndex = 0 ;
56- this . elementDialog . appendChild ( this . panel . elementPanel ) ;
57- this . draggable = new DraggableContainer ( this , this . panel , this . elementDialog , this . panel . elementTitle ) ;
29+ this . draggable = new DraggableContainer (
30+ this ,
31+ panel ,
32+ this . element ,
33+ panel . elementTitle ) ;
5834
59- const resizeDirection : ResizeDirection = this . disableResize
35+ const resizeDirection : ResizeDirection = disableResize
6036 ? ResizeDirection . None
6137 : ResizeDirection . All & ~ ResizeDirection . NorthEast ;
62-
63- this . resizable = new ResizableContainer ( this , this . draggable , this . draggable . topLevelElement , resizeDirection ) ;
6438
65- this . dockManager . config . dialogRootElement . appendChild ( this . elementDialog ) ;
66- this . elementDialog . classList . add ( 'dialog-floating' ) ;
39+ this . resizable = new ResizableContainer (
40+ this ,
41+ this . draggable ,
42+ this . draggable . topLevelElement ,
43+ resizeDirection ) ;
6744
68- this . focusHandler = new EventHandler ( this . elementDialog , 'focus' , this . onFocus . bind ( this ) , true ) ;
69- this . mouseDownHandler = new EventHandler ( this . elementDialog , 'pointerdown' , this . onMouseDown . bind ( this ) , true ) ;
70- this . keyPressHandler = new EventHandler ( this . elementDialog , 'keypress' , this . dockManager . onKeyPressBound , true ) ;
45+ this . decoratedContainer = this . resizable ;
46+ }
7147
72- this . resize ( this . panel . elementPanel . clientWidth , this . panel . elementPanel . clientHeight ) ;
73- this . isHidden = false ;
48+ public override initialize ( ) : void {
49+ this . grayoutParent ?. grayOut ( true ) ;
7450
75- if ( this . grayoutParent != null ) {
76- this . grayoutParent . grayOut ( true ) ;
77- }
78- this . bringToFront ( ) ;
51+ super . initialize ( ) ;
52+
53+ this . dockManager . context . model . dialogs . push ( this ) ;
54+ this . position = this . dockManager . defaultDialogPosition ;
55+ this . dockManager . notifyOnCreateDialog ( this ) ;
7956 }
8057
81- setPosition ( x : number , y : number ) {
82- let rect = this . dockManager . config . dialogRootElement . getBoundingClientRect ( ) ;
83- this . position = new Point ( x - rect . left , y - rect . top ) ;
84- this . elementDialog . style . left = ( x - rect . left ) + 'px' ;
85- this . elementDialog . style . top = ( y - rect . top ) + 'px' ;
86- this . panel . setDialogPosition ( x , y ) ;
58+ public saveState ( x : number , y : number ) : void {
59+ this . position = new Point ( x , y ) ;
8760 this . dockManager . notifyOnChangeDialogPosition ( this , x , y ) ;
8861 }
8962
90- getPosition ( ) : Point {
91- return new Point ( this . position ? this . position . x : 0 , this . position ? this . position . y : 0 ) ;
63+ public override setPosition ( x : number , y : number ) : void {
64+ super . setPosition ( x , y ) ;
65+ this . dockManager . notifyOnChangeDialogPosition ( this , x , y ) ;
9266 }
9367
94- onFocus ( ) {
95- if ( this . dockManager . activePanel != this . panel )
96- this . dockManager . activePanel = this . panel ;
68+ public getPosition ( ) : Point {
69+ return new Point ( this . position ? this . position . x : 0 , this . position ? this . position . y : 0 ) ;
9770 }
9871
99- onMouseDown ( e : PointerEvent ) {
100- if ( e . button != 2 )
101- this . bringToFront ( ) ;
72+ public override hide ( ) : void {
73+ super . hide ( ) ;
74+ this . grayoutParent ?. grayOut ( false ) ;
10275 }
10376
104- destroy ( ) {
105- this . panel . lastDialogSize = { width : this . resizable . width , height : this . resizable . height } ;
77+ public override destroy ( ) : void {
78+ super . destroy ( ) ;
10679
107- if ( this . focusHandler ) {
108- this . focusHandler . cancel ( ) ;
109- delete this . focusHandler ;
110- }
111- if ( this . mouseDownHandler ) {
112- this . mouseDownHandler . cancel ( ) ;
113- delete this . mouseDownHandler ;
114- }
115- if ( this . keyPressHandler ) {
116- this . keyPressHandler . cancel ( ) ;
117- delete this . keyPressHandler ;
118- }
119-
120- Utils . removeNode ( this . elementDialog ) ;
12180 this . draggable . removeDecorator ( ) ;
122- Utils . removeNode ( this . panel . elementPanel ) ;
81+ this . resizable . removeDecorator ( ) ;
12382 Utils . arrayRemove ( this . dockManager . context . model . dialogs , this ) ;
124- this . panel . floatingDialog = undefined ;
125-
126- if ( this . grayoutParent ) {
127- this . grayoutParent . grayOut ( false ) ;
128- }
129- }
130-
131- resize ( width : number , height : number ) {
132- this . resizable . resize ( width , height ) ;
133- }
134-
135- setTitle ( title : string ) {
136- this . panel . setTitle ( title ) ;
137- }
138-
139- setTitleIcon ( iconName : string ) {
140- this . panel . setTitleIcon ( iconName ) ;
141- }
142-
143- bringToFront ( ) {
144- this . panel . elementContentContainer . style . zIndex = < any > this . dockManager . zIndexDialogCounter ++ ;
145- this . elementDialog . style . zIndex = < any > this . dockManager . zIndexDialogCounter ++ ;
146- this . dockManager . activePanel = this . panel ;
147- }
148-
149- hide ( ) {
150- this . elementDialog . style . zIndex = '0' ;
151- this . panel . elementContentContainer . style . zIndex = '' ;
152- this . elementDialog . style . display = 'none' ;
153- if ( ! this . isHidden ) {
154- this . isHidden = true ;
155- this . dockManager . notifyOnHideDialog ( this ) ;
156- }
157- if ( this . grayoutParent ) {
158- this . grayoutParent . grayOut ( false ) ;
159- }
16083 }
16184
162- close ( ) {
163- this . hide ( ) ;
164- this . remove ( ) ;
165- this . dockManager . notifyOnClosePanel ( this . panel ) ;
166- this . destroy ( ) ;
167- }
85+ public static fromElement ( id : string , dockManager : DockManager ) : Dialog {
86+ const dialog : Dialog = new Dialog (
87+ new PanelContainer ( < HTMLElement > document . getElementById ( id ) , dockManager ) ,
88+ dockManager ,
89+ null ) ;
16890
169- remove ( ) {
170- this . elementDialog . parentNode . removeChild ( this . elementDialog ) ;
171- }
91+ dialog . initialize ( ) ;
17292
173- show ( ) {
174- this . panel . elementContentContainer . style . zIndex = < any > this . dockManager . zIndexDialogCounter ++ ;
175- this . elementDialog . style . zIndex = < any > this . dockManager . zIndexDialogCounter ++ ;
176- this . elementDialog . style . display = 'block' ;
177- if ( this . isHidden ) {
178- this . isHidden = false ;
179- this . dockManager . notifyOnShowDialog ( this ) ;
180- }
93+ return dialog ;
18194 }
18295
183- static createContextMenuContentCallback = ( dialog : Dialog , documentMangerNodes : DockNode [ ] ) : Node [ ] => {
96+ public static createContextMenuContentCallback = ( dialog : Dialog , documentMangerNodes : DockNode [ ] ) : Node [ ] => {
18497 if ( ! dialog . panel . _hideCloseButton ) {
18598 return [ ] ;
18699 }
@@ -212,7 +125,19 @@ export class Dialog implements IContextMenuProvider {
212125
213126 public createContextMenuItems ( ) : Node [ ] {
214127 return Dialog . createContextMenuContentCallback (
215- this ,
128+ this ,
216129 this . dockManager . context . model . documentManagerNode . children ) ;
217130 }
218- }
131+
132+ protected override onShow ( ) : void {
133+ this . dockManager . notifyOnShowDialog ( this ) ;
134+ }
135+
136+ protected override onHide ( ) : void {
137+ this . dockManager . notifyOnHideDialog ( this ) ;
138+ }
139+
140+ public get elementDialog ( ) : HTMLDivElement & { floatingPanel : FloatingPanel } {
141+ return this . element ;
142+ }
143+ }
0 commit comments