dock.rs

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