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