/
dockpanel.ts
1721 lines (1493 loc) · 44.6 KB
/
dockpanel.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
/*-----------------------------------------------------------------------------
| Copyright (c) 2014-2017, PhosphorJS Contributors
|
| Distributed under the terms of the BSD 3-Clause License.
|
| The full license is in the file LICENSE, distributed with this software.
|----------------------------------------------------------------------------*/
import { find } from '@lumino/algorithm';
import { MimeData } from '@lumino/coreutils';
import { IDisposable } from '@lumino/disposable';
import { ElementExt, Platform } from '@lumino/domutils';
import { Drag } from '@lumino/dragdrop';
import { ConflatableMessage, Message, MessageLoop } from '@lumino/messaging';
import { AttachedProperty } from '@lumino/properties';
import { ISignal, Signal } from '@lumino/signaling';
import { DockLayout } from './docklayout';
import { TabBar } from './tabbar';
import { Widget } from './widget';
/**
* A widget which provides a flexible docking area for widgets.
*/
export class DockPanel extends Widget {
/**
* Construct a new dock panel.
*
* @param options - The options for initializing the panel.
*/
constructor(options: DockPanel.IOptions = {}) {
super();
this.addClass('lm-DockPanel');
this._document = options.document || document;
this._mode = options.mode || 'multiple-document';
this._renderer = options.renderer || DockPanel.defaultRenderer;
this._edges = options.edges || Private.DEFAULT_EDGES;
if (options.tabsMovable !== undefined) {
this._tabsMovable = options.tabsMovable;
}
if (options.tabsConstrained !== undefined) {
this._tabsConstrained = options.tabsConstrained;
}
if (options.addButtonEnabled !== undefined) {
this._addButtonEnabled = options.addButtonEnabled;
}
// Toggle the CSS mode attribute.
this.dataset['mode'] = this._mode;
// Create the delegate renderer for the layout.
let renderer: DockPanel.IRenderer = {
createTabBar: () => this._createTabBar(),
createHandle: () => this._createHandle()
};
// Set up the dock layout for the panel.
this.layout = new DockLayout({
document: this._document,
renderer,
spacing: options.spacing,
hiddenMode: options.hiddenMode
});
// Set up the overlay drop indicator.
this.overlay = options.overlay || new DockPanel.Overlay();
this.node.appendChild(this.overlay.node);
}
/**
* Dispose of the resources held by the panel.
*/
dispose(): void {
// Ensure the mouse is released.
this._releaseMouse();
// Hide the overlay.
this.overlay.hide(0);
// Cancel a drag if one is in progress.
if (this._drag) {
this._drag.dispose();
}
// Dispose of the base class.
super.dispose();
}
/**
* The method for hiding widgets.
*/
get hiddenMode(): Widget.HiddenMode {
return (this.layout as DockLayout).hiddenMode;
}
/**
* Set the method for hiding widgets.
*/
set hiddenMode(v: Widget.HiddenMode) {
(this.layout as DockLayout).hiddenMode = v;
}
/**
* A signal emitted when the layout configuration is modified.
*
* #### Notes
* This signal is emitted whenever the current layout configuration
* may have changed.
*
* This signal is emitted asynchronously in a collapsed fashion, so
* that multiple synchronous modifications results in only a single
* emit of the signal.
*/
get layoutModified(): ISignal<this, void> {
return this._layoutModified;
}
/**
* A signal emitted when the add button on a tab bar is clicked.
*
*/
get addRequested(): ISignal<this, TabBar<Widget>> {
return this._addRequested;
}
/**
* The overlay used by the dock panel.
*/
readonly overlay: DockPanel.IOverlay;
/**
* The renderer used by the dock panel.
*/
get renderer(): DockPanel.IRenderer {
return (this.layout as DockLayout).renderer;
}
/**
* Get the spacing between the widgets.
*/
get spacing(): number {
return (this.layout as DockLayout).spacing;
}
/**
* Set the spacing between the widgets.
*/
set spacing(value: number) {
(this.layout as DockLayout).spacing = value;
}
/**
* Get the mode for the dock panel.
*/
get mode(): DockPanel.Mode {
return this._mode;
}
/**
* Set the mode for the dock panel.
*
* #### Notes
* Changing the mode is a destructive operation with respect to the
* panel's layout configuration. If layout state must be preserved,
* save the current layout config before changing the mode.
*/
set mode(value: DockPanel.Mode) {
// Bail early if the mode does not change.
if (this._mode === value) {
return;
}
// Update the internal mode.
this._mode = value;
// Toggle the CSS mode attribute.
this.dataset['mode'] = value;
// Get the layout for the panel.
let layout = this.layout as DockLayout;
// Configure the layout for the specified mode.
switch (value) {
case 'multiple-document':
for (const tabBar of layout.tabBars()) {
tabBar.show();
}
break;
case 'single-document':
layout.restoreLayout(Private.createSingleDocumentConfig(this));
break;
default:
throw 'unreachable';
}
// Schedule an emit of the layout modified signal.
MessageLoop.postMessage(this, Private.LayoutModified);
}
/**
* Whether the tabs can be dragged / moved at runtime.
*/
get tabsMovable(): boolean {
return this._tabsMovable;
}
/**
* Enable / Disable draggable / movable tabs.
*/
set tabsMovable(value: boolean) {
this._tabsMovable = value;
for (const tabBar of this.tabBars()) {
tabBar.tabsMovable = value;
}
}
/**
* Whether the tabs are constrained to their source dock panel
*/
get tabsConstrained(): boolean {
return this._tabsConstrained;
}
/**
* Constrain/Allow tabs to be dragged outside of this dock panel
*/
set tabsConstrained(value: boolean) {
this._tabsConstrained = value;
}
/**
* Whether the add buttons for each tab bar are enabled.
*/
get addButtonEnabled(): boolean {
return this._addButtonEnabled;
}
/**
* Set whether the add buttons for each tab bar are enabled.
*/
set addButtonEnabled(value: boolean) {
this._addButtonEnabled = value;
for (const tabBar of this.tabBars()) {
tabBar.addButtonEnabled = value;
}
}
/**
* Whether the dock panel is empty.
*/
get isEmpty(): boolean {
return (this.layout as DockLayout).isEmpty;
}
/**
* Create an iterator over the user widgets in the panel.
*
* @returns A new iterator over the user widgets in the panel.
*
* #### Notes
* This iterator does not include the generated tab bars.
*/
*widgets(): IterableIterator<Widget> {
yield* (this.layout as DockLayout).widgets();
}
/**
* Create an iterator over the selected widgets in the panel.
*
* @returns A new iterator over the selected user widgets.
*
* #### Notes
* This iterator yields the widgets corresponding to the current tab
* of each tab bar in the panel.
*/
*selectedWidgets(): IterableIterator<Widget> {
yield* (this.layout as DockLayout).selectedWidgets();
}
/**
* Create an iterator over the tab bars in the panel.
*
* @returns A new iterator over the tab bars in the panel.
*
* #### Notes
* This iterator does not include the user widgets.
*/
*tabBars(): IterableIterator<TabBar<Widget>> {
yield* (this.layout as DockLayout).tabBars();
}
/**
* Create an iterator over the handles in the panel.
*
* @returns A new iterator over the handles in the panel.
*/
*handles(): IterableIterator<HTMLDivElement> {
yield* (this.layout as DockLayout).handles();
}
/**
* Select a specific widget in the dock panel.
*
* @param widget - The widget of interest.
*
* #### Notes
* This will make the widget the current widget in its tab area.
*/
selectWidget(widget: Widget): void {
// Find the tab bar which contains the widget.
let tabBar = find(this.tabBars(), bar => {
return bar.titles.indexOf(widget.title) !== -1;
});
// Throw an error if no tab bar is found.
if (!tabBar) {
throw new Error('Widget is not contained in the dock panel.');
}
// Ensure the widget is the current widget.
tabBar.currentTitle = widget.title;
}
/**
* Activate a specified widget in the dock panel.
*
* @param widget - The widget of interest.
*
* #### Notes
* This will select and activate the given widget.
*/
activateWidget(widget: Widget): void {
this.selectWidget(widget);
widget.activate();
}
/**
* Save the current layout configuration of the dock panel.
*
* @returns A new config object for the current layout state.
*
* #### Notes
* The return value can be provided to the `restoreLayout` method
* in order to restore the layout to its current configuration.
*/
saveLayout(): DockPanel.ILayoutConfig {
return (this.layout as DockLayout).saveLayout();
}
/**
* Restore the layout to a previously saved configuration.
*
* @param config - The layout configuration to restore.
*
* #### Notes
* Widgets which currently belong to the layout but which are not
* contained in the config will be unparented.
*
* The dock panel automatically reverts to `'multiple-document'`
* mode when a layout config is restored.
*/
restoreLayout(config: DockPanel.ILayoutConfig): void {
// Reset the mode.
this._mode = 'multiple-document';
// Restore the layout.
(this.layout as DockLayout).restoreLayout(config);
// Flush the message loop on IE and Edge to prevent flicker.
if (Platform.IS_EDGE || Platform.IS_IE) {
MessageLoop.flush();
}
// Schedule an emit of the layout modified signal.
MessageLoop.postMessage(this, Private.LayoutModified);
}
/**
* Add a widget to the dock panel.
*
* @param widget - The widget to add to the dock panel.
*
* @param options - The additional options for adding the widget.
*
* #### Notes
* If the panel is in single document mode, the options are ignored
* and the widget is always added as tab in the hidden tab bar.
*/
addWidget(widget: Widget, options: DockPanel.IAddOptions = {}): void {
// Add the widget to the layout.
if (this._mode === 'single-document') {
(this.layout as DockLayout).addWidget(widget);
} else {
(this.layout as DockLayout).addWidget(widget, options);
}
// Schedule an emit of the layout modified signal.
MessageLoop.postMessage(this, Private.LayoutModified);
}
/**
* Process a message sent to the widget.
*
* @param msg - The message sent to the widget.
*/
processMessage(msg: Message): void {
if (msg.type === 'layout-modified') {
this._layoutModified.emit(undefined);
} else {
super.processMessage(msg);
}
}
/**
* Handle the DOM events for the dock panel.
*
* @param event - The DOM event sent to the panel.
*
* #### Notes
* This method implements the DOM `EventListener` interface and is
* called in response to events on the panel's DOM node. It should
* not be called directly by user code.
*/
handleEvent(event: Event): void {
switch (event.type) {
case 'lm-dragenter':
this._evtDragEnter(event as Drag.Event);
break;
case 'lm-dragleave':
this._evtDragLeave(event as Drag.Event);
break;
case 'lm-dragover':
this._evtDragOver(event as Drag.Event);
break;
case 'lm-drop':
this._evtDrop(event as Drag.Event);
break;
case 'pointerdown':
this._evtPointerDown(event as PointerEvent);
break;
case 'pointermove':
this._evtPointerMove(event as PointerEvent);
break;
case 'pointerup':
this._evtPointerUp(event as PointerEvent);
break;
case 'keydown':
this._evtKeyDown(event as KeyboardEvent);
break;
case 'contextmenu':
event.preventDefault();
event.stopPropagation();
break;
}
}
/**
* A message handler invoked on a `'before-attach'` message.
*/
protected onBeforeAttach(msg: Message): void {
this.node.addEventListener('lm-dragenter', this);
this.node.addEventListener('lm-dragleave', this);
this.node.addEventListener('lm-dragover', this);
this.node.addEventListener('lm-drop', this);
this.node.addEventListener('pointerdown', this);
}
/**
* A message handler invoked on an `'after-detach'` message.
*/
protected onAfterDetach(msg: Message): void {
this.node.removeEventListener('lm-dragenter', this);
this.node.removeEventListener('lm-dragleave', this);
this.node.removeEventListener('lm-dragover', this);
this.node.removeEventListener('lm-drop', this);
this.node.removeEventListener('pointerdown', this);
this._releaseMouse();
}
/**
* A message handler invoked on a `'child-added'` message.
*/
protected onChildAdded(msg: Widget.ChildMessage): void {
// Ignore the generated tab bars.
if (Private.isGeneratedTabBarProperty.get(msg.child)) {
return;
}
// Add the widget class to the child.
msg.child.addClass('lm-DockPanel-widget');
}
/**
* A message handler invoked on a `'child-removed'` message.
*/
protected onChildRemoved(msg: Widget.ChildMessage): void {
// Ignore the generated tab bars.
if (Private.isGeneratedTabBarProperty.get(msg.child)) {
return;
}
// Remove the widget class from the child.
msg.child.removeClass('lm-DockPanel-widget');
// Schedule an emit of the layout modified signal.
MessageLoop.postMessage(this, Private.LayoutModified);
}
/**
* Handle the `'lm-dragenter'` event for the dock panel.
*/
private _evtDragEnter(event: Drag.Event): void {
// If the factory mime type is present, mark the event as
// handled in order to get the rest of the drag events.
if (event.mimeData.hasData('application/vnd.lumino.widget-factory')) {
event.preventDefault();
event.stopPropagation();
}
}
/**
* Handle the `'lm-dragleave'` event for the dock panel.
*/
private _evtDragLeave(event: Drag.Event): void {
// Mark the event as handled.
event.preventDefault();
if (this._tabsConstrained && event.source !== this) return;
event.stopPropagation();
// The new target might be a descendant, so we might still handle the drop.
// Hide asynchronously so that if a lm-dragover event bubbles up to us, the
// hide is cancelled by the lm-dragover handler's show overlay logic.
this.overlay.hide(1);
}
/**
* Handle the `'lm-dragover'` event for the dock panel.
*/
private _evtDragOver(event: Drag.Event): void {
// Mark the event as handled.
event.preventDefault();
// Show the drop indicator overlay and update the drop
// action based on the drop target zone under the mouse.
if (
(this._tabsConstrained && event.source !== this) ||
this._showOverlay(event.clientX, event.clientY) === 'invalid'
) {
event.dropAction = 'none';
} else {
event.stopPropagation();
event.dropAction = event.proposedAction;
}
}
/**
* Handle the `'lm-drop'` event for the dock panel.
*/
private _evtDrop(event: Drag.Event): void {
// Mark the event as handled.
event.preventDefault();
// Hide the drop indicator overlay.
this.overlay.hide(0);
// Bail if the proposed action is to do nothing.
if (event.proposedAction === 'none') {
event.dropAction = 'none';
return;
}
// Find the drop target under the mouse.
let { clientX, clientY } = event;
let { zone, target } = Private.findDropTarget(
this,
clientX,
clientY,
this._edges
);
// Bail if the drop zone is invalid.
if (
(this._tabsConstrained && event.source !== this) ||
zone === 'invalid'
) {
event.dropAction = 'none';
return;
}
// Bail if the factory mime type has invalid data.
let mimeData = event.mimeData;
let factory = mimeData.getData('application/vnd.lumino.widget-factory');
if (typeof factory !== 'function') {
event.dropAction = 'none';
return;
}
// Bail if the factory does not produce a widget.
let widget = factory();
if (!(widget instanceof Widget)) {
event.dropAction = 'none';
return;
}
// Bail if the widget is an ancestor of the dock panel.
if (widget.contains(this)) {
event.dropAction = 'none';
return;
}
// Find the reference widget for the drop target.
let ref = target ? Private.getDropRef(target.tabBar) : null;
// Add the widget according to the indicated drop zone.
switch (zone) {
case 'root-all':
this.addWidget(widget);
break;
case 'root-top':
this.addWidget(widget, { mode: 'split-top' });
break;
case 'root-left':
this.addWidget(widget, { mode: 'split-left' });
break;
case 'root-right':
this.addWidget(widget, { mode: 'split-right' });
break;
case 'root-bottom':
this.addWidget(widget, { mode: 'split-bottom' });
break;
case 'widget-all':
this.addWidget(widget, { mode: 'tab-after', ref });
break;
case 'widget-top':
this.addWidget(widget, { mode: 'split-top', ref });
break;
case 'widget-left':
this.addWidget(widget, { mode: 'split-left', ref });
break;
case 'widget-right':
this.addWidget(widget, { mode: 'split-right', ref });
break;
case 'widget-bottom':
this.addWidget(widget, { mode: 'split-bottom', ref });
break;
case 'widget-tab':
this.addWidget(widget, { mode: 'tab-after', ref });
break;
default:
throw 'unreachable';
}
// Accept the proposed drop action.
event.dropAction = event.proposedAction;
// Stop propagation if we have not bailed so far.
event.stopPropagation();
// Activate the dropped widget.
this.activateWidget(widget);
}
/**
* Handle the `'keydown'` event for the dock panel.
*/
private _evtKeyDown(event: KeyboardEvent): void {
// Stop input events during drag.
event.preventDefault();
event.stopPropagation();
// Release the mouse if `Escape` is pressed.
if (event.keyCode === 27) {
// Finalize the mouse release.
this._releaseMouse();
// Schedule an emit of the layout modified signal.
MessageLoop.postMessage(this, Private.LayoutModified);
}
}
/**
* Handle the `'pointerdown'` event for the dock panel.
*/
private _evtPointerDown(event: PointerEvent): void {
// Do nothing if the left mouse button is not pressed.
if (event.button !== 0) {
return;
}
// Find the handle which contains the mouse target, if any.
let layout = this.layout as DockLayout;
let target = event.target as HTMLElement;
let handle = find(layout.handles(), handle => handle.contains(target));
if (!handle) {
return;
}
// Stop the event when a handle is pressed.
event.preventDefault();
event.stopPropagation();
// Add the extra document listeners.
this._document.addEventListener('keydown', this, true);
this._document.addEventListener('pointerup', this, true);
this._document.addEventListener('pointermove', this, true);
this._document.addEventListener('contextmenu', this, true);
// Compute the offset deltas for the handle press.
let rect = handle.getBoundingClientRect();
let deltaX = event.clientX - rect.left;
let deltaY = event.clientY - rect.top;
// Override the cursor and store the press data.
let style = window.getComputedStyle(handle);
let override = Drag.overrideCursor(style.cursor!, this._document);
this._pressData = { handle, deltaX, deltaY, override };
}
/**
* Handle the `'pointermove'` event for the dock panel.
*/
private _evtPointerMove(event: PointerEvent): void {
// Bail early if no drag is in progress.
if (!this._pressData) {
return;
}
// Stop the event when dragging a handle.
event.preventDefault();
event.stopPropagation();
// Compute the desired offset position for the handle.
let rect = this.node.getBoundingClientRect();
let xPos = event.clientX - rect.left - this._pressData.deltaX;
let yPos = event.clientY - rect.top - this._pressData.deltaY;
// Set the handle as close to the desired position as possible.
let layout = this.layout as DockLayout;
layout.moveHandle(this._pressData.handle, xPos, yPos);
}
/**
* Handle the `'pointerup'` event for the dock panel.
*/
private _evtPointerUp(event: PointerEvent): void {
// Do nothing if the left mouse button is not released.
if (event.button !== 0) {
return;
}
// Stop the event when releasing a handle.
event.preventDefault();
event.stopPropagation();
// Finalize the mouse release.
this._releaseMouse();
// Schedule an emit of the layout modified signal.
MessageLoop.postMessage(this, Private.LayoutModified);
}
/**
* Release the mouse grab for the dock panel.
*/
private _releaseMouse(): void {
// Bail early if no drag is in progress.
if (!this._pressData) {
return;
}
// Clear the override cursor.
this._pressData.override.dispose();
this._pressData = null;
// Remove the extra document listeners.
this._document.removeEventListener('keydown', this, true);
this._document.removeEventListener('pointerup', this, true);
this._document.removeEventListener('pointermove', this, true);
this._document.removeEventListener('contextmenu', this, true);
}
/**
* Show the overlay indicator at the given client position.
*
* Returns the drop zone at the specified client position.
*
* #### Notes
* If the position is not over a valid zone, the overlay is hidden.
*/
private _showOverlay(clientX: number, clientY: number): Private.DropZone {
// Find the dock target for the given client position.
let { zone, target } = Private.findDropTarget(
this,
clientX,
clientY,
this._edges
);
// If the drop zone is invalid, hide the overlay and bail.
if (zone === 'invalid') {
this.overlay.hide(100);
return zone;
}
// Setup the variables needed to compute the overlay geometry.
let top: number;
let left: number;
let right: number;
let bottom: number;
let box = ElementExt.boxSizing(this.node); // TODO cache this?
let rect = this.node.getBoundingClientRect();
// Compute the overlay geometry based on the dock zone.
switch (zone) {
case 'root-all':
top = box.paddingTop;
left = box.paddingLeft;
right = box.paddingRight;
bottom = box.paddingBottom;
break;
case 'root-top':
top = box.paddingTop;
left = box.paddingLeft;
right = box.paddingRight;
bottom = rect.height * Private.GOLDEN_RATIO;
break;
case 'root-left':
top = box.paddingTop;
left = box.paddingLeft;
right = rect.width * Private.GOLDEN_RATIO;
bottom = box.paddingBottom;
break;
case 'root-right':
top = box.paddingTop;
left = rect.width * Private.GOLDEN_RATIO;
right = box.paddingRight;
bottom = box.paddingBottom;
break;
case 'root-bottom':
top = rect.height * Private.GOLDEN_RATIO;
left = box.paddingLeft;
right = box.paddingRight;
bottom = box.paddingBottom;
break;
case 'widget-all':
top = target!.top;
left = target!.left;
right = target!.right;
bottom = target!.bottom;
break;
case 'widget-top':
top = target!.top;
left = target!.left;
right = target!.right;
bottom = target!.bottom + target!.height / 2;
break;
case 'widget-left':
top = target!.top;
left = target!.left;
right = target!.right + target!.width / 2;
bottom = target!.bottom;
break;
case 'widget-right':
top = target!.top;
left = target!.left + target!.width / 2;
right = target!.right;
bottom = target!.bottom;
break;
case 'widget-bottom':
top = target!.top + target!.height / 2;
left = target!.left;
right = target!.right;
bottom = target!.bottom;
break;
case 'widget-tab': {
const tabHeight = target!.tabBar.node.getBoundingClientRect().height;
top = target!.top;
left = target!.left;
right = target!.right;
bottom = target!.bottom + target!.height - tabHeight;
break;
}
default:
throw 'unreachable';
}
// Show the overlay with the computed geometry.
this.overlay.show({ top, left, right, bottom });
// Finally, return the computed drop zone.
return zone;
}
/**
* Create a new tab bar for use by the panel.
*/
private _createTabBar(): TabBar<Widget> {
// Create the tab bar.
let tabBar = this._renderer.createTabBar(this._document);
// Set the generated tab bar property for the tab bar.
Private.isGeneratedTabBarProperty.set(tabBar, true);
// Hide the tab bar when in single document mode.
if (this._mode === 'single-document') {
tabBar.hide();
}
// Enforce necessary tab bar behavior.
// TODO do we really want to enforce *all* of these?
tabBar.tabsMovable = this._tabsMovable;
tabBar.allowDeselect = false;
tabBar.addButtonEnabled = this._addButtonEnabled;
tabBar.removeBehavior = 'select-previous-tab';
tabBar.insertBehavior = 'select-tab-if-needed';
// Connect the signal handlers for the tab bar.
tabBar.tabMoved.connect(this._onTabMoved, this);
tabBar.currentChanged.connect(this._onCurrentChanged, this);
tabBar.tabCloseRequested.connect(this._onTabCloseRequested, this);
tabBar.tabDetachRequested.connect(this._onTabDetachRequested, this);
tabBar.tabActivateRequested.connect(this._onTabActivateRequested, this);
tabBar.addRequested.connect(this._onTabAddRequested, this);
// Return the initialized tab bar.
return tabBar;
}
/**
* Create a new handle for use by the panel.
*/
private _createHandle(): HTMLDivElement {
return this._renderer.createHandle();
}
/**
* Handle the `tabMoved` signal from a tab bar.
*/
private _onTabMoved(): void {
MessageLoop.postMessage(this, Private.LayoutModified);
}
/**
* Handle the `currentChanged` signal from a tab bar.
*/
private _onCurrentChanged(
sender: TabBar<Widget>,
args: TabBar.ICurrentChangedArgs<Widget>
): void {
// Extract the previous and current title from the args.
let { previousTitle, currentTitle } = args;
// Hide the previous widget.
if (previousTitle) {
previousTitle.owner.hide();
}
// Show the current widget.
if (currentTitle) {
currentTitle.owner.show();
}
// Flush the message loop on IE and Edge to prevent flicker.
if (Platform.IS_EDGE || Platform.IS_IE) {
MessageLoop.flush();
}
// Schedule an emit of the layout modified signal.
MessageLoop.postMessage(this, Private.LayoutModified);
}
/**
* Handle the `addRequested` signal from a tab bar.
*/
private _onTabAddRequested(sender: TabBar<Widget>): void {
this._addRequested.emit(sender);
}
/**
* Handle the `tabActivateRequested` signal from a tab bar.
*/
private _onTabActivateRequested(
sender: TabBar<Widget>,
args: TabBar.ITabActivateRequestedArgs<Widget>
): void {
args.title.owner.activate();
}