1mod toggle_dock_button;
2
3use collections::HashMap;
4use gpui::{
5 actions,
6 elements::{ChildView, Empty, MouseEventHandler, ParentElement, Side, Stack},
7 geometry::vector::Vector2F,
8 platform::{CursorStyle, MouseButton},
9 AnyElement, AppContext, Border, Element, SizeConstraint, ViewContext, ViewHandle,
10};
11use settings::{DockAnchor, Settings};
12use theme::Theme;
13
14use crate::{sidebar::SidebarSide, BackgroundActions, ItemHandle, Pane, Workspace};
15pub use toggle_dock_button::ToggleDockButton;
16
17actions!(
18 dock,
19 [
20 FocusDock,
21 HideDock,
22 AnchorDockRight,
23 AnchorDockBottom,
24 ExpandDock,
25 AddTabToDock,
26 RemoveTabFromDock,
27 ]
28);
29
30pub fn init(cx: &mut AppContext) {
31 cx.add_action(Dock::focus_dock);
32 cx.add_action(Dock::hide_dock);
33 cx.add_action(
34 |workspace: &mut Workspace, _: &AnchorDockRight, cx: &mut ViewContext<Workspace>| {
35 Dock::move_dock(workspace, DockAnchor::Right, true, cx);
36 },
37 );
38 cx.add_action(
39 |workspace: &mut Workspace, _: &AnchorDockBottom, cx: &mut ViewContext<Workspace>| {
40 Dock::move_dock(workspace, DockAnchor::Bottom, true, cx)
41 },
42 );
43 cx.add_action(
44 |workspace: &mut Workspace, _: &ExpandDock, cx: &mut ViewContext<Workspace>| {
45 Dock::move_dock(workspace, DockAnchor::Expanded, true, cx)
46 },
47 );
48 cx.add_action(
49 |workspace: &mut Workspace, _: &AddTabToDock, cx: &mut ViewContext<Workspace>| {
50 if let Some(active_item) = workspace.active_item(cx) {
51 let item_id = active_item.id();
52
53 let from = workspace.active_pane();
54 let to = workspace.dock_pane();
55 if from.id() == to.id() {
56 return;
57 }
58
59 let destination_index = to.read(cx).items_len() + 1;
60
61 Pane::move_item(
62 workspace,
63 from.clone(),
64 to.clone(),
65 item_id,
66 destination_index,
67 cx,
68 );
69 }
70 },
71 );
72 cx.add_action(
73 |workspace: &mut Workspace, _: &RemoveTabFromDock, cx: &mut ViewContext<Workspace>| {
74 if let Some(active_item) = workspace.active_item(cx) {
75 let item_id = active_item.id();
76
77 let from = workspace.dock_pane();
78 let to = workspace
79 .last_active_center_pane
80 .as_ref()
81 .and_then(|pane| pane.upgrade(cx))
82 .unwrap_or_else(|| {
83 workspace
84 .panes
85 .first()
86 .expect("There must be a pane")
87 .clone()
88 });
89
90 if from.id() == to.id() {
91 return;
92 }
93
94 let destination_index = to.read(cx).items_len() + 1;
95
96 Pane::move_item(
97 workspace,
98 from.clone(),
99 to.clone(),
100 item_id,
101 destination_index,
102 cx,
103 );
104 }
105 },
106 );
107}
108
109#[derive(Copy, Clone, PartialEq, Eq, Debug)]
110pub enum DockPosition {
111 Shown(DockAnchor),
112 Hidden(DockAnchor),
113}
114
115impl Default for DockPosition {
116 fn default() -> Self {
117 DockPosition::Hidden(Default::default())
118 }
119}
120
121pub fn icon_for_dock_anchor(anchor: DockAnchor) -> &'static str {
122 match anchor {
123 DockAnchor::Right => "icons/dock_right_12.svg",
124 DockAnchor::Bottom => "icons/dock_bottom_12.svg",
125 DockAnchor::Expanded => "icons/dock_modal_12.svg",
126 }
127}
128
129impl DockPosition {
130 pub fn is_visible(&self) -> bool {
131 match self {
132 DockPosition::Shown(_) => true,
133 DockPosition::Hidden(_) => false,
134 }
135 }
136
137 pub fn anchor(&self) -> DockAnchor {
138 match self {
139 DockPosition::Shown(anchor) | DockPosition::Hidden(anchor) => *anchor,
140 }
141 }
142
143 fn hide(self) -> Self {
144 match self {
145 DockPosition::Shown(anchor) => DockPosition::Hidden(anchor),
146 DockPosition::Hidden(_) => self,
147 }
148 }
149
150 fn show(self) -> Self {
151 match self {
152 DockPosition::Hidden(anchor) => DockPosition::Shown(anchor),
153 DockPosition::Shown(_) => self,
154 }
155 }
156}
157
158pub type DockDefaultItemFactory =
159 fn(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) -> Option<Box<dyn ItemHandle>>;
160
161pub struct Dock {
162 position: DockPosition,
163 panel_sizes: HashMap<DockAnchor, f32>,
164 pane: ViewHandle<Pane>,
165 default_item_factory: DockDefaultItemFactory,
166}
167
168impl Dock {
169 pub fn new(
170 default_item_factory: DockDefaultItemFactory,
171 background_actions: BackgroundActions,
172 cx: &mut ViewContext<Workspace>,
173 ) -> Self {
174 let position = DockPosition::Hidden(cx.global::<Settings>().default_dock_anchor);
175 let workspace = cx.weak_handle();
176 let pane =
177 cx.add_view(|cx| Pane::new(workspace, Some(position.anchor()), background_actions, cx));
178 pane.update(cx, |pane, cx| {
179 pane.set_active(false, cx);
180 });
181 let pane_id = pane.id();
182 cx.subscribe(&pane, move |workspace, _, event, cx| {
183 workspace.handle_pane_event(pane_id, event, cx);
184 })
185 .detach();
186
187 Self {
188 pane,
189 panel_sizes: Default::default(),
190 position,
191 default_item_factory,
192 }
193 }
194
195 pub fn pane(&self) -> &ViewHandle<Pane> {
196 &self.pane
197 }
198
199 pub fn visible_pane(&self) -> Option<&ViewHandle<Pane>> {
200 self.position.is_visible().then(|| self.pane())
201 }
202
203 pub fn is_anchored_at(&self, anchor: DockAnchor) -> bool {
204 self.position.is_visible() && self.position.anchor() == anchor
205 }
206
207 pub(crate) fn set_dock_position(
208 workspace: &mut Workspace,
209 new_position: DockPosition,
210 focus: bool,
211 cx: &mut ViewContext<Workspace>,
212 ) {
213 workspace.dock.position = new_position;
214 // Tell the pane about the new anchor position
215 workspace.dock.pane.update(cx, |pane, cx| {
216 pane.set_docked(Some(new_position.anchor()), cx)
217 });
218
219 if workspace.dock.position.is_visible() {
220 // Close the right sidebar if the dock is on the right side and the right sidebar is open
221 if workspace.dock.position.anchor() == DockAnchor::Right {
222 if workspace.right_sidebar().read(cx).is_open() {
223 workspace.toggle_sidebar(SidebarSide::Right, cx);
224 }
225 }
226
227 // Ensure that the pane has at least one item or construct a default item to put in it
228 let pane = workspace.dock.pane.clone();
229 if pane.read(cx).items().next().is_none() {
230 if let Some(item_to_add) = (workspace.dock.default_item_factory)(workspace, cx) {
231 Pane::add_item(workspace, &pane, item_to_add, focus, focus, None, cx);
232 } else {
233 workspace.dock.position = workspace.dock.position.hide();
234 }
235 } else {
236 if focus {
237 cx.focus(&pane);
238 }
239 }
240 } else if let Some(last_active_center_pane) = workspace
241 .last_active_center_pane
242 .as_ref()
243 .and_then(|pane| pane.upgrade(cx))
244 {
245 if focus {
246 cx.focus(&last_active_center_pane);
247 }
248 }
249 cx.emit(crate::Event::DockAnchorChanged);
250 workspace.serialize_workspace(cx);
251 cx.notify();
252 }
253
254 pub fn hide(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) {
255 Self::set_dock_position(workspace, workspace.dock.position.hide(), true, cx);
256 }
257
258 pub fn show(workspace: &mut Workspace, focus: bool, cx: &mut ViewContext<Workspace>) {
259 Self::set_dock_position(workspace, workspace.dock.position.show(), focus, cx);
260 }
261
262 pub fn hide_on_sidebar_shown(
263 workspace: &mut Workspace,
264 sidebar_side: SidebarSide,
265 cx: &mut ViewContext<Workspace>,
266 ) {
267 if (sidebar_side == SidebarSide::Right && workspace.dock.is_anchored_at(DockAnchor::Right))
268 || workspace.dock.is_anchored_at(DockAnchor::Expanded)
269 {
270 Self::hide(workspace, cx);
271 }
272 }
273
274 fn focus_dock(workspace: &mut Workspace, _: &FocusDock, cx: &mut ViewContext<Workspace>) {
275 Self::set_dock_position(workspace, workspace.dock.position.show(), true, cx);
276 }
277
278 fn hide_dock(workspace: &mut Workspace, _: &HideDock, cx: &mut ViewContext<Workspace>) {
279 Self::set_dock_position(workspace, workspace.dock.position.hide(), true, cx);
280 }
281
282 pub fn move_dock(
283 workspace: &mut Workspace,
284 new_anchor: DockAnchor,
285 focus: bool,
286 cx: &mut ViewContext<Workspace>,
287 ) {
288 Self::set_dock_position(workspace, DockPosition::Shown(new_anchor), focus, cx);
289 }
290
291 pub fn render(
292 &self,
293 theme: &Theme,
294 anchor: DockAnchor,
295 cx: &mut ViewContext<Workspace>,
296 ) -> Option<AnyElement<Workspace>> {
297 let style = &theme.workspace.dock;
298
299 self.position
300 .is_visible()
301 .then(|| self.position.anchor())
302 .filter(|current_anchor| *current_anchor == anchor)
303 .map(|anchor| match anchor {
304 DockAnchor::Bottom | DockAnchor::Right => {
305 let mut panel_style = style.panel.clone();
306 let (resize_side, initial_size) = if anchor == DockAnchor::Bottom {
307 panel_style.border = Border {
308 top: true,
309 bottom: false,
310 left: false,
311 right: false,
312 ..panel_style.border
313 };
314
315 (Side::Top, style.initial_size_bottom)
316 } else {
317 panel_style.border = Border {
318 top: false,
319 bottom: false,
320 left: true,
321 right: false,
322 ..panel_style.border
323 };
324 (Side::Left, style.initial_size_right)
325 };
326
327 enum DockResizeHandle {}
328
329 let resizable = ChildView::new(&self.pane, cx)
330 .contained()
331 .with_style(panel_style)
332 .with_resize_handle::<DockResizeHandle>(
333 resize_side as usize,
334 resize_side,
335 4.,
336 self.panel_sizes
337 .get(&anchor)
338 .copied()
339 .unwrap_or(initial_size),
340 cx,
341 );
342
343 let size = resizable.current_size();
344 cx.defer(move |workspace, _| {
345 workspace.dock.panel_sizes.insert(anchor, size);
346 });
347
348 if anchor == DockAnchor::Right {
349 resizable.constrained().dynamically(|constraint, _, cx| {
350 SizeConstraint::new(
351 Vector2F::new(20., constraint.min.y()),
352 Vector2F::new(cx.window_size().x() * 0.8, constraint.max.y()),
353 )
354 })
355 } else {
356 resizable.constrained().dynamically(|constraint, _, cx| {
357 SizeConstraint::new(
358 Vector2F::new(constraint.min.x(), 50.),
359 Vector2F::new(constraint.max.x(), cx.window_size().y() * 0.8),
360 )
361 })
362 }
363 .into_any()
364 }
365 DockAnchor::Expanded => {
366 enum ExpandedDockWash {}
367 enum ExpandedDockPane {}
368 Stack::new()
369 .with_child(
370 // Render wash under the dock which when clicked hides it
371 MouseEventHandler::<ExpandedDockWash, _>::new(0, cx, |_, _| {
372 Empty::new()
373 .contained()
374 .with_background_color(style.wash_color)
375 })
376 .capture_all()
377 .on_down(MouseButton::Left, |_, _, cx| {
378 cx.dispatch_action(HideDock);
379 })
380 .with_cursor_style(CursorStyle::Arrow),
381 )
382 .with_child(
383 MouseEventHandler::<ExpandedDockPane, _>::new(0, cx, |_state, cx| {
384 ChildView::new(&self.pane, cx)
385 })
386 // Make sure all events directly under the dock pane
387 // are captured
388 .capture_all()
389 .contained()
390 .with_style(style.maximized),
391 )
392 .into_any()
393 }
394 })
395 }
396
397 pub fn position(&self) -> DockPosition {
398 self.position
399 }
400}
401
402#[cfg(test)]
403mod tests {
404 use std::{
405 ops::{Deref, DerefMut},
406 path::PathBuf,
407 };
408
409 use gpui::{AppContext, BorrowWindowContext, TestAppContext, ViewContext, WindowContext};
410 use project::{FakeFs, Project};
411 use settings::Settings;
412
413 use super::*;
414 use crate::{
415 dock,
416 item::{self, test::TestItem},
417 persistence::model::{
418 SerializedItem, SerializedPane, SerializedPaneGroup, SerializedWorkspace,
419 },
420 register_deserializable_item,
421 sidebar::Sidebar,
422 ItemHandle, Workspace,
423 };
424
425 pub fn default_item_factory(
426 _workspace: &mut Workspace,
427 cx: &mut ViewContext<Workspace>,
428 ) -> Option<Box<dyn ItemHandle>> {
429 Some(Box::new(cx.add_view(|_| TestItem::new())))
430 }
431
432 #[gpui::test]
433 async fn test_dock_workspace_infinite_loop(cx: &mut TestAppContext) {
434 cx.foreground().forbid_parking();
435 Settings::test_async(cx);
436
437 cx.update(|cx| {
438 register_deserializable_item::<item::test::TestItem>(cx);
439 });
440
441 let serialized_workspace = SerializedWorkspace {
442 id: 0,
443 location: Vec::<PathBuf>::new().into(),
444 dock_position: dock::DockPosition::Shown(DockAnchor::Expanded),
445 center_group: SerializedPaneGroup::Pane(SerializedPane {
446 active: false,
447 children: vec![],
448 }),
449 dock_pane: SerializedPane {
450 active: true,
451 children: vec![SerializedItem {
452 active: true,
453 item_id: 0,
454 kind: "TestItem".into(),
455 }],
456 },
457 left_sidebar_open: false,
458 bounds: Default::default(),
459 display: Default::default(),
460 };
461
462 let fs = FakeFs::new(cx.background());
463 let project = Project::test(fs, [], cx).await;
464
465 let (_, _workspace) = cx.add_window(|cx| {
466 Workspace::new(
467 Some(serialized_workspace),
468 0,
469 project.clone(),
470 default_item_factory,
471 || &[],
472 cx,
473 )
474 });
475
476 cx.foreground().run_until_parked();
477 //Should terminate
478 }
479
480 #[gpui::test]
481 async fn test_dock_hides_when_pane_empty(cx: &mut TestAppContext) {
482 let mut cx = DockTestContext::new(cx).await;
483
484 // Closing the last item in the dock hides the dock
485 cx.move_dock(DockAnchor::Right);
486 let old_items = cx.dock_items();
487 assert!(!old_items.is_empty());
488 cx.close_dock_items().await;
489 cx.assert_dock_position(DockPosition::Hidden(DockAnchor::Right));
490
491 // Reopening the dock adds a new item
492 cx.move_dock(DockAnchor::Right);
493 let new_items = cx.dock_items();
494 assert!(!new_items.is_empty());
495 assert!(new_items
496 .into_iter()
497 .all(|new_item| !old_items.contains(&new_item)));
498 }
499
500 #[gpui::test]
501 async fn test_dock_panel_collisions(cx: &mut TestAppContext) {
502 let mut cx = DockTestContext::new(cx).await;
503
504 // Dock closes when expanded for either panel
505 cx.move_dock(DockAnchor::Expanded);
506 cx.open_sidebar(SidebarSide::Left);
507 cx.assert_dock_position(DockPosition::Hidden(DockAnchor::Expanded));
508 cx.close_sidebar(SidebarSide::Left);
509 cx.move_dock(DockAnchor::Expanded);
510 cx.open_sidebar(SidebarSide::Right);
511 cx.assert_dock_position(DockPosition::Hidden(DockAnchor::Expanded));
512
513 // Dock closes in the right position if the right sidebar is opened
514 cx.move_dock(DockAnchor::Right);
515 cx.open_sidebar(SidebarSide::Left);
516 cx.assert_dock_position(DockPosition::Shown(DockAnchor::Right));
517 cx.open_sidebar(SidebarSide::Right);
518 cx.assert_dock_position(DockPosition::Hidden(DockAnchor::Right));
519 cx.close_sidebar(SidebarSide::Right);
520
521 // Dock in bottom position ignores sidebars
522 cx.move_dock(DockAnchor::Bottom);
523 cx.open_sidebar(SidebarSide::Left);
524 cx.open_sidebar(SidebarSide::Right);
525 cx.assert_dock_position(DockPosition::Shown(DockAnchor::Bottom));
526
527 // Opening the dock in the right position closes the right sidebar
528 cx.move_dock(DockAnchor::Right);
529 cx.assert_sidebar_closed(SidebarSide::Right);
530 }
531
532 #[gpui::test]
533 async fn test_focusing_panes_shows_and_hides_dock(cx: &mut TestAppContext) {
534 let mut cx = DockTestContext::new(cx).await;
535
536 // Focusing an item not in the dock when expanded hides the dock
537 let center_item = cx.add_item_to_center_pane();
538 cx.move_dock(DockAnchor::Expanded);
539 let dock_item = cx
540 .dock_items()
541 .get(0)
542 .cloned()
543 .expect("Dock should have an item at this point");
544 center_item.update(&mut cx, |_, cx| cx.focus_self());
545 cx.assert_dock_position(DockPosition::Hidden(DockAnchor::Expanded));
546
547 // Focusing an item not in the dock when not expanded, leaves the dock open but inactive
548 cx.move_dock(DockAnchor::Right);
549 center_item.update(&mut cx, |_, cx| cx.focus_self());
550 cx.assert_dock_position(DockPosition::Shown(DockAnchor::Right));
551 cx.assert_dock_pane_inactive();
552 cx.assert_workspace_pane_active();
553
554 // Focusing an item in the dock activates it's pane
555 dock_item.update(&mut cx, |_, cx| cx.focus_self());
556 cx.assert_dock_position(DockPosition::Shown(DockAnchor::Right));
557 cx.assert_dock_pane_active();
558 cx.assert_workspace_pane_inactive();
559 }
560
561 #[gpui::test]
562 async fn test_toggle_dock_focus(cx: &mut TestAppContext) {
563 let mut cx = DockTestContext::new(cx).await;
564
565 cx.move_dock(DockAnchor::Right);
566 cx.assert_dock_pane_active();
567 cx.hide_dock();
568 cx.move_dock(DockAnchor::Right);
569 cx.assert_dock_pane_active();
570 }
571
572 #[gpui::test]
573 async fn test_activate_next_and_prev_pane(cx: &mut TestAppContext) {
574 let mut cx = DockTestContext::new(cx).await;
575
576 cx.move_dock(DockAnchor::Right);
577 cx.assert_dock_pane_active();
578
579 cx.update_workspace(|workspace, cx| workspace.activate_next_pane(cx));
580 cx.assert_dock_pane_active();
581
582 cx.update_workspace(|workspace, cx| workspace.activate_previous_pane(cx));
583 cx.assert_dock_pane_active();
584 }
585
586 struct DockTestContext<'a> {
587 pub cx: &'a mut TestAppContext,
588 pub window_id: usize,
589 pub workspace: ViewHandle<Workspace>,
590 }
591
592 impl<'a> DockTestContext<'a> {
593 pub async fn new(cx: &'a mut TestAppContext) -> DockTestContext<'a> {
594 Settings::test_async(cx);
595 let fs = FakeFs::new(cx.background());
596
597 cx.update(|cx| init(cx));
598 let project = Project::test(fs, [], cx).await;
599 let (window_id, workspace) = cx.add_window(|cx| {
600 Workspace::new(
601 Default::default(),
602 0,
603 project,
604 default_item_factory,
605 || &[],
606 cx,
607 )
608 });
609
610 workspace.update(cx, |workspace, cx| {
611 let left_panel = cx.add_view(|_| TestItem::new());
612 workspace.left_sidebar().update(cx, |sidebar, cx| {
613 sidebar.add_item(
614 "icons/folder_tree_16.svg",
615 "Left Test Panel".to_string(),
616 left_panel.clone(),
617 cx,
618 );
619 });
620
621 let right_panel = cx.add_view(|_| TestItem::new());
622 workspace.right_sidebar().update(cx, |sidebar, cx| {
623 sidebar.add_item(
624 "icons/folder_tree_16.svg",
625 "Right Test Panel".to_string(),
626 right_panel.clone(),
627 cx,
628 );
629 });
630 });
631
632 Self {
633 cx,
634 window_id,
635 workspace,
636 }
637 }
638
639 pub fn workspace<F, T>(&self, read: F) -> T
640 where
641 F: FnOnce(&Workspace, &ViewContext<Workspace>) -> T,
642 {
643 self.workspace.read_with(self.cx, read)
644 }
645
646 pub fn update_workspace<F, T>(&mut self, update: F) -> T
647 where
648 F: FnOnce(&mut Workspace, &mut ViewContext<Workspace>) -> T,
649 {
650 self.workspace.update(self.cx, update)
651 }
652
653 pub fn sidebar<F, T>(&self, sidebar_side: SidebarSide, read: F) -> T
654 where
655 F: FnOnce(&Sidebar, &AppContext) -> T,
656 {
657 self.workspace(|workspace, cx| {
658 let sidebar = match sidebar_side {
659 SidebarSide::Left => workspace.left_sidebar(),
660 SidebarSide::Right => workspace.right_sidebar(),
661 }
662 .read(cx);
663
664 read(sidebar, cx)
665 })
666 }
667
668 pub fn center_pane_handle(&self) -> ViewHandle<Pane> {
669 self.workspace(|workspace, cx| {
670 workspace
671 .last_active_center_pane
672 .clone()
673 .and_then(|pane| pane.upgrade(cx))
674 .unwrap_or_else(|| workspace.center.panes()[0].clone())
675 })
676 }
677
678 pub fn add_item_to_center_pane(&mut self) -> ViewHandle<TestItem> {
679 self.update_workspace(|workspace, cx| {
680 let item = cx.add_view(|_| TestItem::new());
681 let pane = workspace
682 .last_active_center_pane
683 .clone()
684 .and_then(|pane| pane.upgrade(cx))
685 .unwrap_or_else(|| workspace.center.panes()[0].clone());
686 Pane::add_item(
687 workspace,
688 &pane,
689 Box::new(item.clone()),
690 true,
691 true,
692 None,
693 cx,
694 );
695 item
696 })
697 }
698
699 pub fn dock_pane<F, T>(&self, read: F) -> T
700 where
701 F: FnOnce(&Pane, &AppContext) -> T,
702 {
703 self.workspace(|workspace, cx| {
704 let dock_pane = workspace.dock_pane().read(cx);
705 read(dock_pane, cx)
706 })
707 }
708
709 pub fn move_dock(&mut self, anchor: DockAnchor) {
710 self.update_workspace(|workspace, cx| Dock::move_dock(workspace, anchor, true, cx));
711 }
712
713 pub fn hide_dock(&self) {
714 self.cx.dispatch_action(self.window_id, HideDock);
715 }
716
717 pub fn open_sidebar(&mut self, sidebar_side: SidebarSide) {
718 if !self.sidebar(sidebar_side, |sidebar, _| sidebar.is_open()) {
719 self.update_workspace(|workspace, cx| workspace.toggle_sidebar(sidebar_side, cx));
720 }
721 }
722
723 pub fn close_sidebar(&mut self, sidebar_side: SidebarSide) {
724 if self.sidebar(sidebar_side, |sidebar, _| sidebar.is_open()) {
725 self.update_workspace(|workspace, cx| workspace.toggle_sidebar(sidebar_side, cx));
726 }
727 }
728
729 pub fn dock_items(&self) -> Vec<ViewHandle<TestItem>> {
730 self.dock_pane(|pane, cx| {
731 pane.items()
732 .map(|item| {
733 item.act_as::<TestItem>(cx)
734 .expect("Dock Test Context uses TestItems in the dock")
735 })
736 .collect()
737 })
738 }
739
740 pub async fn close_dock_items(&mut self) {
741 self.update_workspace(|workspace, cx| {
742 Pane::close_items(workspace, workspace.dock_pane().clone(), cx, |_| true)
743 })
744 .await
745 .expect("Could not close dock items")
746 }
747
748 pub fn assert_dock_position(&self, expected_position: DockPosition) {
749 self.workspace(|workspace, _| assert_eq!(workspace.dock.position, expected_position));
750 }
751
752 pub fn assert_sidebar_closed(&self, sidebar_side: SidebarSide) {
753 assert!(!self.sidebar(sidebar_side, |sidebar, _| sidebar.is_open()));
754 }
755
756 pub fn assert_workspace_pane_active(&self) {
757 assert!(self
758 .center_pane_handle()
759 .read_with(self.cx, |pane, _| pane.is_active()));
760 }
761
762 pub fn assert_workspace_pane_inactive(&self) {
763 assert!(!self
764 .center_pane_handle()
765 .read_with(self.cx, |pane, _| pane.is_active()));
766 }
767
768 pub fn assert_dock_pane_active(&self) {
769 assert!(self.dock_pane(|pane, _| pane.is_active()))
770 }
771
772 pub fn assert_dock_pane_inactive(&self) {
773 assert!(!self.dock_pane(|pane, _| pane.is_active()))
774 }
775 }
776
777 impl<'a> Deref for DockTestContext<'a> {
778 type Target = gpui::TestAppContext;
779
780 fn deref(&self) -> &Self::Target {
781 self.cx
782 }
783 }
784
785 impl<'a> DerefMut for DockTestContext<'a> {
786 fn deref_mut(&mut self) -> &mut Self::Target {
787 &mut self.cx
788 }
789 }
790
791 impl BorrowWindowContext for DockTestContext<'_> {
792 fn read_with<T, F: FnOnce(&WindowContext) -> T>(&self, window_id: usize, f: F) -> T {
793 BorrowWindowContext::read_with(self.cx, window_id, f)
794 }
795
796 fn update<T, F: FnOnce(&mut WindowContext) -> T>(&mut self, window_id: usize, f: F) -> T {
797 BorrowWindowContext::update(self.cx, window_id, f)
798 }
799 }
800}