14
14
* This toolbar should appear over selection when related selection is done using mouse
15
15
*/
16
16
17
- class ContextToolbar {
17
+ class ContextToolbar extends JSDialogComponent {
18
18
container ! : HTMLElement ;
19
- builder : JSBuilder ;
20
- map : any ;
21
19
initialized : boolean = false ;
22
20
lastIinputEvent ?: any = { } ;
23
21
pendingShow : boolean = false ;
@@ -26,18 +24,22 @@ class ContextToolbar {
26
24
additionalContextButtons : Array < WidgetJSON > = [ ] ;
27
25
28
26
constructor ( map : any ) {
29
- this . map = map ;
27
+ super ( map , 'ContextToolbar' , 'notebookbar' ) ;
28
+ this . createBuilder ( ) ;
29
+ this . setupContainer ( undefined ) ;
30
+ }
31
+
32
+ protected createBuilder ( ) {
30
33
this . builder = new window . L . control . notebookbarBuilder ( {
31
34
windowId : - 2 ,
32
35
mobileWizard : this ,
33
36
map : this . map ,
34
37
cssClass : 'notebookbar' ,
35
38
suffix : 'context-toolbar' ,
36
39
} as JSBuilderOptions ) ;
37
- this . createContextToolbarElement ( ) ;
38
40
}
39
41
40
- createContextToolbarElement ( ) : void {
42
+ protected setupContainer ( parentContainer ?: HTMLElement /* ignored */ ) : void {
41
43
this . container = window . L . DomUtil . createWithId (
42
44
'div' ,
43
45
'context-toolbar' ,
@@ -47,7 +49,7 @@ class ContextToolbar {
47
49
}
48
50
49
51
showContextToolbar ( ) : void {
50
- const map = this . builder . map ;
52
+ const map = this . map ;
51
53
if (
52
54
map . isReadOnlyMode ( ) ||
53
55
! window . mode . isDesktop ( ) ||
@@ -72,32 +74,24 @@ class ContextToolbar {
72
74
contextToolbarItems . push ( item ) ;
73
75
}
74
76
75
- this . builder . build ( this . container , contextToolbarItems , false ) ;
77
+ this . builder ? .build ( this . container , contextToolbarItems , false ) ;
76
78
77
79
this . initialized = true ;
78
80
}
79
81
80
- this . builder . map . on ( 'jsdialogaction' , this . onJSAction , this ) ;
81
- this . builder . map . on ( 'jsdialogupdate' , this . onJSUpdate , this ) ;
82
+ this . registerMessageHandlers ( ) ;
83
+
82
84
document . addEventListener ( 'pointermove' , this . pointerMove ) ;
83
- this . builder . map . on (
84
- 'commandstatechanged' ,
85
- this . onCommandStateChanged ,
86
- this ,
87
- ) ;
85
+ this . map . on ( 'commandstatechanged' , this . onCommandStateChanged , this ) ;
88
86
this . changeOpacity ( 1 ) ;
89
87
this . showHideToolbar ( true ) ;
90
88
}
91
89
92
90
hideContextToolbar ( ) : void {
93
- this . builder . map . off ( 'jsdialogaction' , this . onJSAction , this ) ;
94
- this . builder . map . off ( 'jsdialogupdate' , this . onJSUpdate , this ) ;
91
+ this . unregisterMessageHandlers ( ) ;
92
+
95
93
document . removeEventListener ( 'pointermove' , this . pointerMove ) ;
96
- this . builder . map . off (
97
- 'commandstatechanged' ,
98
- this . onCommandStateChanged ,
99
- this ,
100
- ) ;
94
+ this . map . off ( 'commandstatechanged' , this . onCommandStateChanged , this ) ;
101
95
this . showHideToolbar ( false ) ;
102
96
}
103
97
@@ -130,7 +124,7 @@ class ContextToolbar {
130
124
131
125
getWriterTextContext ( ) : WidgetJSON [ ] {
132
126
const fontEntries = Object . keys (
133
- this . builder . map . _docLayer . _toolbarCommandValues [ '.uno:CharFontName' ] ,
127
+ this . map . _docLayer . _toolbarCommandValues [ '.uno:CharFontName' ] ,
134
128
) ;
135
129
const sizeEntries = [
136
130
'6' ,
@@ -336,22 +330,10 @@ class ContextToolbar {
336
330
337
331
// update context toolbar
338
332
document . getElementById ( 'context-toolbar' ) ?. remove ( ) ;
339
- this . createContextToolbarElement ( ) ;
333
+ this . setupContainer ( undefined ) ;
340
334
this . initialized = false ;
341
335
}
342
336
343
- onJSAction ( e : any ) : any {
344
- if ( e . data . jsontype !== 'notebookbar' ) return ;
345
-
346
- this . builder . executeAction ( this . container , e . data . data ) ;
347
- }
348
-
349
- onJSUpdate ( e : any ) : any {
350
- if ( e . data . jsontype !== 'notebookbar' ) return ;
351
-
352
- this . builder . updateWidget ( this . container , e . data . control ) ;
353
- }
354
-
355
337
setLastInputEventType ( e : any ) {
356
338
this . lastIinputEvent = e ;
357
339
if ( e . type === 'buttonup' && e . input === 'mouse' && this . pendingShow ) {
0 commit comments