dock.rs

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