Skip to content

Commit 11c4d6b

Browse files
committed
jsdialog: use component type in builder options
Signed-off-by: Szymon Kłos <[email protected]> Change-Id: Ic9ceb91adb92e6066d43f3af2eddaee7c631a49e
1 parent 3baeefa commit 11c4d6b

File tree

2 files changed

+23
-41
lines changed

2 files changed

+23
-41
lines changed

browser/src/control/Control.ContextToolbar.ts

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@
1414
* This toolbar should appear over selection when related selection is done using mouse
1515
*/
1616

17-
class ContextToolbar {
17+
class ContextToolbar extends JSDialogComponent {
1818
container!: HTMLElement;
19-
builder: JSBuilder;
20-
map: any;
2119
initialized: boolean = false;
2220
lastIinputEvent?: any = {};
2321
pendingShow: boolean = false;
@@ -26,18 +24,22 @@ class ContextToolbar {
2624
additionalContextButtons: Array<WidgetJSON> = [];
2725

2826
constructor(map: any) {
29-
this.map = map;
27+
super(map, 'ContextToolbar', 'notebookbar');
28+
this.createBuilder();
29+
this.setupContainer(undefined);
30+
}
31+
32+
protected createBuilder() {
3033
this.builder = new window.L.control.notebookbarBuilder({
3134
windowId: -2,
3235
mobileWizard: this,
3336
map: this.map,
3437
cssClass: 'notebookbar',
3538
suffix: 'context-toolbar',
3639
} as JSBuilderOptions);
37-
this.createContextToolbarElement();
3840
}
3941

40-
createContextToolbarElement(): void {
42+
protected setupContainer(parentContainer?: HTMLElement /* ignored */): void {
4143
this.container = window.L.DomUtil.createWithId(
4244
'div',
4345
'context-toolbar',
@@ -47,7 +49,7 @@ class ContextToolbar {
4749
}
4850

4951
showContextToolbar(): void {
50-
const map = this.builder.map;
52+
const map = this.map;
5153
if (
5254
map.isReadOnlyMode() ||
5355
!window.mode.isDesktop() ||
@@ -72,32 +74,24 @@ class ContextToolbar {
7274
contextToolbarItems.push(item);
7375
}
7476

75-
this.builder.build(this.container, contextToolbarItems, false);
77+
this.builder?.build(this.container, contextToolbarItems, false);
7678

7779
this.initialized = true;
7880
}
7981

80-
this.builder.map.on('jsdialogaction', this.onJSAction, this);
81-
this.builder.map.on('jsdialogupdate', this.onJSUpdate, this);
82+
this.registerMessageHandlers();
83+
8284
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);
8886
this.changeOpacity(1);
8987
this.showHideToolbar(true);
9088
}
9189

9290
hideContextToolbar(): void {
93-
this.builder.map.off('jsdialogaction', this.onJSAction, this);
94-
this.builder.map.off('jsdialogupdate', this.onJSUpdate, this);
91+
this.unregisterMessageHandlers();
92+
9593
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);
10195
this.showHideToolbar(false);
10296
}
10397

@@ -130,7 +124,7 @@ class ContextToolbar {
130124

131125
getWriterTextContext(): WidgetJSON[] {
132126
const fontEntries = Object.keys(
133-
this.builder.map._docLayer._toolbarCommandValues['.uno:CharFontName'],
127+
this.map._docLayer._toolbarCommandValues['.uno:CharFontName'],
134128
);
135129
const sizeEntries = [
136130
'6',
@@ -336,22 +330,10 @@ class ContextToolbar {
336330

337331
// update context toolbar
338332
document.getElementById('context-toolbar')?.remove();
339-
this.createContextToolbarElement();
333+
this.setupContainer(undefined);
340334
this.initialized = false;
341335
}
342336

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-
355337
setLastInputEventType(e: any) {
356338
this.lastIinputEvent = e;
357339
if (e.type === 'buttonup' && e.input === 'mouse' && this.pendingShow) {

browser/src/control/jsdialog/Definitions.Types.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ interface JSBuilderOptions {
3333
cssClass: string; // class added to every widget root
3434
windowId: number; // window id to be sent with dialogevent
3535
map: any; // reference to map
36-
mobileWizard: any; // reference to the parent container FIXME: rename
37-
useSetTabs: boolean; // custom tabs placement handled by the parent container
38-
useScrollAnimation: boolean; // do we use animation for scrollIntoView
36+
mobileWizard: JSDialogComponent; // reference to the parent component FIXME: rename
37+
useSetTabs?: boolean; // custom tabs placement handled by the parent container
38+
useScrollAnimation?: boolean; // do we use animation for scrollIntoView
3939

4040
// modifiers
41-
noLabelsForUnoButtons: boolean; // create only icon without label
42-
useInLineLabelsForUnoButtons: boolean; // create labels next to the icon
41+
noLabelsForUnoButtons?: boolean; // create only icon without label
42+
useInLineLabelsForUnoButtons?: boolean; // create labels next to the icon
4343
suffix: string; // add a suffix to the element ID to make it unique among different builder instances.
4444
}
4545

0 commit comments

Comments
 (0)