@@ -16,6 +16,7 @@ use crate::{
16
16
} ;
17
17
18
18
use crate :: popup:: popup_under_widget;
19
+ use crate :: tab_viewer:: OnCloseResponse ;
19
20
20
21
impl < Tab > DockArea < ' _ , Tab > {
21
22
pub ( super ) fn show_leaf (
@@ -205,7 +206,7 @@ impl<Tab> DockArea<'_, Tab> {
205
206
let disabled = if let Node :: Leaf { tabs, .. } =
206
207
& mut self . dock_state [ surface_index] [ node_index]
207
208
{
208
- !tabs. iter_mut ( ) . all ( |tab| tab_viewer. closeable ( tab) )
209
+ !tabs. iter_mut ( ) . all ( |tab| tab_viewer. is_closeable ( tab) )
209
210
} else {
210
211
unreachable ! ( )
211
212
} ;
@@ -214,7 +215,7 @@ impl<Tab> DockArea<'_, Tab> {
214
215
let close_window_disabled = disabled
215
216
|| !self . dock_state [ surface_index] . iter_mut ( ) . all ( |node| {
216
217
if let Node :: Leaf { tabs, .. } = node {
217
- tabs. iter_mut ( ) . all ( |tab| tab_viewer. closeable ( tab) )
218
+ tabs. iter_mut ( ) . all ( |tab| tab_viewer. is_closeable ( tab) )
218
219
} else {
219
220
true
220
221
}
@@ -307,7 +308,7 @@ impl<Tab> DockArea<'_, Tab> {
307
308
* active == tab_index || is_being_dragged,
308
309
tab_viewer. title ( & mut tabs[ tab_index. 0 ] ) ,
309
310
tab_style. unwrap_or ( style. tab . clone ( ) ) ,
310
- tab_viewer. closeable ( & mut tabs[ tab_index. 0 ] ) ,
311
+ tab_viewer. is_closeable ( & mut tabs[ tab_index. 0 ] ) ,
311
312
)
312
313
} ;
313
314
@@ -392,14 +393,14 @@ impl<Tab> DockArea<'_, Tab> {
392
393
let close_button =
393
394
Button :: new ( & self . dock_state . translations . tab_context_menu . close_button ) ;
394
395
395
- let Node :: Leaf { tabs, active, .. } =
396
- & mut self . dock_state [ surface_index] [ node_index]
397
- else {
398
- unreachable ! ( )
399
- } ;
400
- let tab = & mut tabs[ tab_index. 0 ] ;
401
-
402
396
response. context_menu ( |ui| {
397
+ let Node :: Leaf { tabs, .. } =
398
+ & mut self . dock_state [ surface_index] [ node_index]
399
+ else {
400
+ unreachable ! ( )
401
+ } ;
402
+ let tab = & mut tabs[ tab_index. 0 ] ;
403
+
403
404
tab_viewer. context_menu ( ui, tab, surface_index, node_index) ;
404
405
if ( surface_index. is_main ( ) || !is_lonely_tab)
405
406
&& tab_viewer. allowed_in_windows ( tab)
@@ -409,33 +410,14 @@ impl<Tab> DockArea<'_, Tab> {
409
410
ui. close_menu ( ) ;
410
411
}
411
412
if show_close_button && ui. add ( close_button) . clicked ( ) {
412
- if tab_viewer. on_close ( tab) {
413
- self . to_remove
414
- . push ( ( surface_index, node_index, tab_index) . into ( ) ) ;
415
- } else {
416
- * active = tab_index;
417
- self . new_focused = Some ( ( surface_index, node_index) ) ;
418
- }
413
+ self . close_tab ( tab_viewer, surface_index, node_index, tab_index) ;
419
414
ui. close_menu ( ) ;
420
415
}
421
416
} ) ;
422
417
}
423
418
424
419
if close_clicked {
425
- let Node :: Leaf { tabs, active, .. } =
426
- & mut self . dock_state [ surface_index] [ node_index]
427
- else {
428
- unreachable ! ( )
429
- } ;
430
- let tab = & mut tabs[ tab_index. 0 ] ;
431
-
432
- if tab_viewer. on_close ( tab) {
433
- self . to_remove
434
- . push ( ( surface_index, node_index, tab_index) . into ( ) ) ;
435
- } else {
436
- * active = tab_index;
437
- self . new_focused = Some ( ( surface_index, node_index) ) ;
438
- }
420
+ self . close_tab ( tab_viewer, surface_index, node_index, tab_index) ;
439
421
}
440
422
441
423
if let Some ( pos) = state. last_hover_pos {
@@ -477,17 +459,40 @@ impl<Tab> DockArea<'_, Tab> {
477
459
self . new_focused = Some ( ( surface_index, node_index) ) ;
478
460
}
479
461
480
- if self . show_close_buttons && tab_viewer. closeable ( tab) && response. middle_clicked ( ) {
481
- if tab_viewer. on_close ( tab) {
482
- self . to_remove
483
- . push ( ( surface_index, node_index, tab_index) . into ( ) ) ;
484
- } else {
485
- * active = tab_index;
486
- self . new_focused = Some ( ( surface_index, node_index) ) ;
487
- }
462
+ tab_viewer. on_tab_button ( tab, & response) ;
463
+
464
+ if self . show_close_buttons && tab_viewer. is_closeable ( tab) && response. middle_clicked ( )
465
+ {
466
+ self . close_tab ( tab_viewer, surface_index, node_index, tab_index) ;
488
467
}
468
+ }
469
+ }
489
470
490
- tab_viewer. on_tab_button ( tab, & response) ;
471
+ fn close_tab (
472
+ & mut self ,
473
+ tab_viewer : & mut impl TabViewer < Tab = Tab > ,
474
+ surface_index : SurfaceIndex ,
475
+ node_index : NodeIndex ,
476
+ tab_index : TabIndex ,
477
+ ) {
478
+ let Node :: Leaf { tabs, active, .. } = & mut self . dock_state [ surface_index] [ node_index]
479
+ else {
480
+ unreachable ! ( )
481
+ } ;
482
+ let tab = & mut tabs[ tab_index. 0 ] ;
483
+
484
+ match tab_viewer. on_close ( tab) {
485
+ OnCloseResponse :: Close => {
486
+ self . to_remove
487
+ . push ( ( surface_index, node_index, tab_index) . into ( ) ) ;
488
+ }
489
+ OnCloseResponse :: Focus => {
490
+ * active = tab_index;
491
+ self . new_focused = Some ( ( surface_index, node_index) ) ;
492
+ }
493
+ OnCloseResponse :: Ignore => {
494
+ // no-op
495
+ }
491
496
}
492
497
}
493
498
0 commit comments