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