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