dock.rs

  1use crate::DraggedDock;
  2use crate::{status_bar::StatusItemView, Workspace};
  3use gpui::{
  4    div, px, Action, AnchorCorner, AnyView, AppContext, Axis, ClickEvent, Entity, EntityId,
  5    EventEmitter, FocusHandle, FocusableView, IntoElement, MouseButton, ParentElement, Render,
  6    SharedString, Styled, Subscription, View, ViewContext, VisualContext, WeakView, WindowContext,
  7};
  8use schemars::JsonSchema;
  9use serde::{Deserialize, Serialize};
 10use std::sync::Arc;
 11use ui::{h_stack, ContextMenu, IconButton, Tooltip};
 12use ui::{prelude::*, right_click_menu};
 13
 14const RESIZE_HANDLE_SIZE: Pixels = Pixels(6.);
 15
 16pub enum PanelEvent {
 17    ChangePosition,
 18    ZoomIn,
 19    ZoomOut,
 20    Activate,
 21    Close,
 22}
 23
 24pub trait Panel: FocusableView + EventEmitter<PanelEvent> {
 25    fn persistent_name() -> &'static str;
 26    fn position(&self, cx: &WindowContext) -> DockPosition;
 27    fn position_is_valid(&self, position: DockPosition) -> bool;
 28    fn set_position(&mut self, position: DockPosition, cx: &mut ViewContext<Self>);
 29    fn size(&self, cx: &WindowContext) -> Pixels;
 30    fn set_size(&mut self, size: Option<Pixels>, cx: &mut ViewContext<Self>);
 31    fn icon(&self, cx: &WindowContext) -> Option<ui::IconName>;
 32    fn icon_tooltip(&self, cx: &WindowContext) -> Option<&'static str>;
 33    fn toggle_action(&self) -> Box<dyn Action>;
 34    fn icon_label(&self, _: &WindowContext) -> Option<String> {
 35        None
 36    }
 37    fn is_zoomed(&self, _cx: &WindowContext) -> bool {
 38        false
 39    }
 40    fn set_zoomed(&mut self, _zoomed: bool, _cx: &mut ViewContext<Self>) {}
 41    fn set_active(&mut self, _active: bool, _cx: &mut ViewContext<Self>) {}
 42}
 43
 44pub trait PanelHandle: Send + Sync {
 45    fn panel_id(&self) -> EntityId;
 46    fn persistent_name(&self) -> &'static str;
 47    fn position(&self, cx: &WindowContext) -> DockPosition;
 48    fn position_is_valid(&self, position: DockPosition, cx: &WindowContext) -> bool;
 49    fn set_position(&self, position: DockPosition, cx: &mut WindowContext);
 50    fn is_zoomed(&self, cx: &WindowContext) -> bool;
 51    fn set_zoomed(&self, zoomed: bool, cx: &mut WindowContext);
 52    fn set_active(&self, active: bool, cx: &mut WindowContext);
 53    fn size(&self, cx: &WindowContext) -> Pixels;
 54    fn set_size(&self, size: Option<Pixels>, cx: &mut WindowContext);
 55    fn icon(&self, cx: &WindowContext) -> Option<ui::IconName>;
 56    fn icon_tooltip(&self, cx: &WindowContext) -> Option<&'static str>;
 57    fn toggle_action(&self, cx: &WindowContext) -> Box<dyn Action>;
 58    fn icon_label(&self, cx: &WindowContext) -> Option<String>;
 59    fn focus_handle(&self, cx: &AppContext) -> FocusHandle;
 60    fn to_any(&self) -> AnyView;
 61}
 62
 63impl<T> PanelHandle for View<T>
 64where
 65    T: Panel,
 66{
 67    fn panel_id(&self) -> EntityId {
 68        Entity::entity_id(self)
 69    }
 70
 71    fn persistent_name(&self) -> &'static str {
 72        T::persistent_name()
 73    }
 74
 75    fn position(&self, cx: &WindowContext) -> DockPosition {
 76        self.read(cx).position(cx)
 77    }
 78
 79    fn position_is_valid(&self, position: DockPosition, cx: &WindowContext) -> bool {
 80        self.read(cx).position_is_valid(position)
 81    }
 82
 83    fn set_position(&self, position: DockPosition, cx: &mut WindowContext) {
 84        self.update(cx, |this, cx| this.set_position(position, cx))
 85    }
 86
 87    fn is_zoomed(&self, cx: &WindowContext) -> bool {
 88        self.read(cx).is_zoomed(cx)
 89    }
 90
 91    fn set_zoomed(&self, zoomed: bool, cx: &mut WindowContext) {
 92        self.update(cx, |this, cx| this.set_zoomed(zoomed, cx))
 93    }
 94
 95    fn set_active(&self, active: bool, cx: &mut WindowContext) {
 96        self.update(cx, |this, cx| this.set_active(active, cx))
 97    }
 98
 99    fn size(&self, cx: &WindowContext) -> Pixels {
100        self.read(cx).size(cx)
101    }
102
103    fn set_size(&self, size: Option<Pixels>, cx: &mut WindowContext) {
104        self.update(cx, |this, cx| this.set_size(size, cx))
105    }
106
107    fn icon(&self, cx: &WindowContext) -> Option<ui::IconName> {
108        self.read(cx).icon(cx)
109    }
110
111    fn icon_tooltip(&self, cx: &WindowContext) -> Option<&'static str> {
112        self.read(cx).icon_tooltip(cx)
113    }
114
115    fn toggle_action(&self, cx: &WindowContext) -> Box<dyn Action> {
116        self.read(cx).toggle_action()
117    }
118
119    fn icon_label(&self, cx: &WindowContext) -> Option<String> {
120        self.read(cx).icon_label(cx)
121    }
122
123    fn to_any(&self) -> AnyView {
124        self.clone().into()
125    }
126
127    fn focus_handle(&self, cx: &AppContext) -> FocusHandle {
128        self.read(cx).focus_handle(cx).clone()
129    }
130}
131
132impl From<&dyn PanelHandle> for AnyView {
133    fn from(val: &dyn PanelHandle) -> Self {
134        val.to_any()
135    }
136}
137
138pub struct Dock {
139    position: DockPosition,
140    panel_entries: Vec<PanelEntry>,
141    is_open: bool,
142    active_panel_index: usize,
143    focus_handle: FocusHandle,
144    _focus_subscription: Subscription,
145}
146
147impl FocusableView for Dock {
148    fn focus_handle(&self, _: &AppContext) -> FocusHandle {
149        self.focus_handle.clone()
150    }
151}
152
153#[derive(Clone, Copy, Debug, Serialize, Deserialize, JsonSchema, PartialEq)]
154#[serde(rename_all = "lowercase")]
155pub enum DockPosition {
156    Left,
157    Bottom,
158    Right,
159}
160
161impl DockPosition {
162    fn to_label(&self) -> &'static str {
163        match self {
164            Self::Left => "left",
165            Self::Bottom => "bottom",
166            Self::Right => "right",
167        }
168    }
169
170    pub fn axis(&self) -> Axis {
171        match self {
172            Self::Left | Self::Right => Axis::Horizontal,
173            Self::Bottom => Axis::Vertical,
174        }
175    }
176}
177
178struct PanelEntry {
179    panel: Arc<dyn PanelHandle>,
180    _subscriptions: [Subscription; 2],
181}
182
183pub struct PanelButtons {
184    dock: View<Dock>,
185}
186
187impl Dock {
188    pub fn new(position: DockPosition, cx: &mut ViewContext<Workspace>) -> View<Self> {
189        let focus_handle = cx.focus_handle();
190
191        let dock = cx.new_view(|cx: &mut ViewContext<Self>| {
192            let focus_subscription = cx.on_focus(&focus_handle, |dock, cx| {
193                if let Some(active_entry) = dock.panel_entries.get(dock.active_panel_index) {
194                    active_entry.panel.focus_handle(cx).focus(cx)
195                }
196            });
197            Self {
198                position,
199                panel_entries: Default::default(),
200                active_panel_index: 0,
201                is_open: false,
202                focus_handle: focus_handle.clone(),
203                _focus_subscription: focus_subscription,
204            }
205        });
206
207        cx.on_focus_in(&focus_handle, {
208            let dock = dock.downgrade();
209            move |workspace, cx| {
210                let Some(dock) = dock.upgrade() else {
211                    return;
212                };
213                let Some(panel) = dock.read(cx).active_panel() else {
214                    return;
215                };
216                if panel.is_zoomed(cx) {
217                    workspace.zoomed = Some(panel.to_any().downgrade().into());
218                    workspace.zoomed_position = Some(position);
219                } else {
220                    workspace.zoomed = None;
221                    workspace.zoomed_position = None;
222                }
223                workspace.dismiss_zoomed_items_to_reveal(Some(position), cx);
224                workspace.update_active_view_for_followers(cx)
225            }
226        })
227        .detach();
228
229        cx.observe(&dock, move |workspace, dock, cx| {
230            if dock.read(cx).is_open() {
231                if let Some(panel) = dock.read(cx).active_panel() {
232                    if panel.is_zoomed(cx) {
233                        workspace.zoomed = Some(panel.to_any().downgrade());
234                        workspace.zoomed_position = Some(position);
235                        return;
236                    }
237                }
238            }
239            if workspace.zoomed_position == Some(position) {
240                workspace.zoomed = None;
241                workspace.zoomed_position = None;
242            }
243        })
244        .detach();
245
246        dock
247    }
248
249    pub fn position(&self) -> DockPosition {
250        self.position
251    }
252
253    pub fn is_open(&self) -> bool {
254        self.is_open
255    }
256
257    pub fn panel<T: Panel>(&self) -> Option<View<T>> {
258        self.panel_entries
259            .iter()
260            .find_map(|entry| entry.panel.to_any().clone().downcast().ok())
261    }
262
263    pub fn panel_index_for_type<T: Panel>(&self) -> Option<usize> {
264        self.panel_entries
265            .iter()
266            .position(|entry| entry.panel.to_any().downcast::<T>().is_ok())
267    }
268
269    pub fn panel_index_for_persistent_name(
270        &self,
271        ui_name: &str,
272        _cx: &AppContext,
273    ) -> Option<usize> {
274        self.panel_entries
275            .iter()
276            .position(|entry| entry.panel.persistent_name() == ui_name)
277    }
278
279    pub fn active_panel_index(&self) -> usize {
280        self.active_panel_index
281    }
282
283    pub(crate) fn set_open(&mut self, open: bool, cx: &mut ViewContext<Self>) {
284        if open != self.is_open {
285            self.is_open = open;
286            if let Some(active_panel) = self.panel_entries.get(self.active_panel_index) {
287                active_panel.panel.set_active(open, cx);
288            }
289
290            cx.notify();
291        }
292    }
293
294    pub fn set_panel_zoomed(&mut self, panel: &AnyView, zoomed: bool, cx: &mut ViewContext<Self>) {
295        for entry in &mut self.panel_entries {
296            if entry.panel.panel_id() == panel.entity_id() {
297                if zoomed != entry.panel.is_zoomed(cx) {
298                    entry.panel.set_zoomed(zoomed, cx);
299                }
300            } else if entry.panel.is_zoomed(cx) {
301                entry.panel.set_zoomed(false, cx);
302            }
303        }
304
305        cx.notify();
306    }
307
308    pub fn zoom_out(&mut self, cx: &mut ViewContext<Self>) {
309        for entry in &mut self.panel_entries {
310            if entry.panel.is_zoomed(cx) {
311                entry.panel.set_zoomed(false, cx);
312            }
313        }
314    }
315
316    pub(crate) fn add_panel<T: Panel>(
317        &mut self,
318        panel: View<T>,
319        workspace: WeakView<Workspace>,
320        cx: &mut ViewContext<Self>,
321    ) {
322        let subscriptions = [
323            cx.observe(&panel, |_, _, cx| cx.notify()),
324            cx.subscribe(&panel, move |this, panel, event, cx| match event {
325                PanelEvent::ChangePosition => {
326                    let new_position = panel.read(cx).position(cx);
327
328                    let Ok(new_dock) = workspace.update(cx, |workspace, cx| {
329                        if panel.is_zoomed(cx) {
330                            workspace.zoomed_position = Some(new_position);
331                        }
332                        match new_position {
333                            DockPosition::Left => &workspace.left_dock,
334                            DockPosition::Bottom => &workspace.bottom_dock,
335                            DockPosition::Right => &workspace.right_dock,
336                        }
337                        .clone()
338                    }) else {
339                        return;
340                    };
341
342                    let was_visible = this.is_open()
343                        && this.visible_panel().map_or(false, |active_panel| {
344                            active_panel.panel_id() == Entity::entity_id(&panel)
345                        });
346
347                    this.remove_panel(&panel, cx);
348
349                    new_dock.update(cx, |new_dock, cx| {
350                        new_dock.add_panel(panel.clone(), workspace.clone(), cx);
351                        if was_visible {
352                            new_dock.set_open(true, cx);
353                            new_dock.activate_panel(new_dock.panels_len() - 1, cx);
354                        }
355                    });
356                }
357                PanelEvent::ZoomIn => {
358                    this.set_panel_zoomed(&panel.to_any(), true, cx);
359                    if !panel.focus_handle(cx).contains_focused(cx) {
360                        cx.focus_view(&panel);
361                    }
362                    workspace
363                        .update(cx, |workspace, cx| {
364                            workspace.zoomed = Some(panel.downgrade().into());
365                            workspace.zoomed_position = Some(panel.read(cx).position(cx));
366                        })
367                        .ok();
368                }
369                PanelEvent::ZoomOut => {
370                    this.set_panel_zoomed(&panel.to_any(), false, cx);
371                    workspace
372                        .update(cx, |workspace, cx| {
373                            if workspace.zoomed_position == Some(this.position) {
374                                workspace.zoomed = None;
375                                workspace.zoomed_position = None;
376                            }
377                            cx.notify();
378                        })
379                        .ok();
380                }
381                PanelEvent::Activate => {
382                    if let Some(ix) = this
383                        .panel_entries
384                        .iter()
385                        .position(|entry| entry.panel.panel_id() == Entity::entity_id(&panel))
386                    {
387                        this.set_open(true, cx);
388                        this.activate_panel(ix, cx);
389                        cx.focus_view(&panel);
390                    }
391                }
392                PanelEvent::Close => {
393                    if this
394                        .visible_panel()
395                        .map_or(false, |p| p.panel_id() == Entity::entity_id(&panel))
396                    {
397                        this.set_open(false, cx);
398                    }
399                }
400            }),
401        ];
402
403        self.panel_entries.push(PanelEntry {
404            panel: Arc::new(panel),
405            _subscriptions: subscriptions,
406        });
407        cx.notify()
408    }
409
410    pub fn remove_panel<T: Panel>(&mut self, panel: &View<T>, cx: &mut ViewContext<Self>) {
411        if let Some(panel_ix) = self
412            .panel_entries
413            .iter()
414            .position(|entry| entry.panel.panel_id() == Entity::entity_id(panel))
415        {
416            if panel_ix == self.active_panel_index {
417                self.active_panel_index = 0;
418                self.set_open(false, cx);
419            } else if panel_ix < self.active_panel_index {
420                self.active_panel_index -= 1;
421            }
422            self.panel_entries.remove(panel_ix);
423            cx.notify();
424        }
425    }
426
427    pub fn panels_len(&self) -> usize {
428        self.panel_entries.len()
429    }
430
431    pub fn activate_panel(&mut self, panel_ix: usize, cx: &mut ViewContext<Self>) {
432        if panel_ix != self.active_panel_index {
433            if let Some(active_panel) = self.panel_entries.get(self.active_panel_index) {
434                active_panel.panel.set_active(false, cx);
435            }
436
437            self.active_panel_index = panel_ix;
438            if let Some(active_panel) = self.panel_entries.get(self.active_panel_index) {
439                active_panel.panel.set_active(true, cx);
440            }
441
442            cx.notify();
443        }
444    }
445
446    pub fn visible_panel(&self) -> Option<&Arc<dyn PanelHandle>> {
447        let entry = self.visible_entry()?;
448        Some(&entry.panel)
449    }
450
451    pub fn active_panel(&self) -> Option<&Arc<dyn PanelHandle>> {
452        Some(&self.panel_entries.get(self.active_panel_index)?.panel)
453    }
454
455    fn visible_entry(&self) -> Option<&PanelEntry> {
456        if self.is_open {
457            self.panel_entries.get(self.active_panel_index)
458        } else {
459            None
460        }
461    }
462
463    pub fn zoomed_panel(&self, cx: &WindowContext) -> Option<Arc<dyn PanelHandle>> {
464        let entry = self.visible_entry()?;
465        if entry.panel.is_zoomed(cx) {
466            Some(entry.panel.clone())
467        } else {
468            None
469        }
470    }
471
472    pub fn panel_size(&self, panel: &dyn PanelHandle, cx: &WindowContext) -> Option<Pixels> {
473        self.panel_entries
474            .iter()
475            .find(|entry| entry.panel.panel_id() == panel.panel_id())
476            .map(|entry| entry.panel.size(cx))
477    }
478
479    pub fn active_panel_size(&self, cx: &WindowContext) -> Option<Pixels> {
480        if self.is_open {
481            self.panel_entries
482                .get(self.active_panel_index)
483                .map(|entry| entry.panel.size(cx))
484        } else {
485            None
486        }
487    }
488
489    pub fn resize_active_panel(&mut self, size: Option<Pixels>, cx: &mut ViewContext<Self>) {
490        if let Some(entry) = self.panel_entries.get_mut(self.active_panel_index) {
491            let size = size.map(|size| size.max(RESIZE_HANDLE_SIZE));
492            entry.panel.set_size(size, cx);
493            cx.notify();
494        }
495    }
496
497    pub fn toggle_action(&self) -> Box<dyn Action> {
498        match self.position {
499            DockPosition::Left => crate::ToggleLeftDock.boxed_clone(),
500            DockPosition::Bottom => crate::ToggleBottomDock.boxed_clone(),
501            DockPosition::Right => crate::ToggleRightDock.boxed_clone(),
502        }
503    }
504}
505
506impl Render for Dock {
507    fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
508        if let Some(entry) = self.visible_entry() {
509            let size = entry.panel.size(cx);
510
511            let position = self.position;
512            let mut handle = div()
513                .id("resize-handle")
514                .on_drag(DraggedDock(position), |dock, cx| {
515                    cx.stop_propagation();
516                    cx.new_view(|_| dock.clone())
517                })
518                .on_click(cx.listener(|v, e: &ClickEvent, cx| {
519                    if e.down.button == MouseButton::Left && e.down.click_count == 2 {
520                        v.resize_active_panel(None, cx);
521                        cx.stop_propagation();
522                    }
523                }))
524                .z_index(1)
525                .block_mouse();
526
527            match self.position() {
528                DockPosition::Left => {
529                    handle = handle
530                        .absolute()
531                        .right(px(0.))
532                        .top(px(0.))
533                        .h_full()
534                        .w(RESIZE_HANDLE_SIZE)
535                        .cursor_col_resize();
536                }
537                DockPosition::Bottom => {
538                    handle = handle
539                        .absolute()
540                        .top(px(0.))
541                        .left(px(0.))
542                        .w_full()
543                        .h(RESIZE_HANDLE_SIZE)
544                        .cursor_row_resize();
545                }
546                DockPosition::Right => {
547                    handle = handle
548                        .absolute()
549                        .top(px(0.))
550                        .left(px(0.))
551                        .h_full()
552                        .w(RESIZE_HANDLE_SIZE)
553                        .cursor_col_resize();
554                }
555            }
556
557            div()
558                .track_focus(&self.focus_handle)
559                .flex()
560                .bg(cx.theme().colors().panel_background)
561                .border_color(cx.theme().colors().border)
562                .overflow_hidden()
563                .map(|this| match self.position().axis() {
564                    Axis::Horizontal => this.w(size).h_full().flex_row(),
565                    Axis::Vertical => this.h(size).w_full().flex_col(),
566                })
567                .map(|this| match self.position() {
568                    DockPosition::Left => this.border_r(),
569                    DockPosition::Right => this.border_l(),
570                    DockPosition::Bottom => this.border_t(),
571                })
572                .child(
573                    div()
574                        .map(|this| match self.position().axis() {
575                            Axis::Horizontal => this.min_w(size).h_full(),
576                            Axis::Vertical => this.min_h(size).w_full(),
577                        })
578                        .child(entry.panel.to_any()),
579                )
580                .child(handle)
581        } else {
582            div().track_focus(&self.focus_handle)
583        }
584    }
585}
586
587impl PanelButtons {
588    pub fn new(dock: View<Dock>, cx: &mut ViewContext<Self>) -> Self {
589        cx.observe(&dock, |_, _, cx| cx.notify()).detach();
590        Self { dock }
591    }
592}
593
594impl Render for PanelButtons {
595    fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
596        let dock = self.dock.read(cx);
597        let active_index = dock.active_panel_index;
598        let is_open = dock.is_open;
599        let dock_position = dock.position;
600
601        let (menu_anchor, menu_attach) = match dock.position {
602            DockPosition::Left => (AnchorCorner::BottomLeft, AnchorCorner::TopLeft),
603            DockPosition::Bottom | DockPosition::Right => {
604                (AnchorCorner::BottomRight, AnchorCorner::TopRight)
605            }
606        };
607
608        let buttons = dock
609            .panel_entries
610            .iter()
611            .enumerate()
612            .filter_map(|(i, entry)| {
613                let icon = entry.panel.icon(cx)?;
614                let icon_tooltip = entry.panel.icon_tooltip(cx)?;
615                let name = entry.panel.persistent_name();
616                let panel = entry.panel.clone();
617
618                let is_active_button = i == active_index && is_open;
619
620                let (action, tooltip) = if is_active_button {
621                    let action = dock.toggle_action();
622
623                    let tooltip: SharedString =
624                        format!("Close {} dock", dock.position.to_label()).into();
625
626                    (action, tooltip)
627                } else {
628                    let action = entry.panel.toggle_action(cx);
629
630                    (action, icon_tooltip.into())
631                };
632
633                Some(
634                    right_click_menu(name)
635                        .menu(move |cx| {
636                            const POSITIONS: [DockPosition; 3] = [
637                                DockPosition::Left,
638                                DockPosition::Right,
639                                DockPosition::Bottom,
640                            ];
641
642                            ContextMenu::build(cx, |mut menu, cx| {
643                                for position in POSITIONS {
644                                    if position != dock_position
645                                        && panel.position_is_valid(position, cx)
646                                    {
647                                        let panel = panel.clone();
648                                        menu = menu.entry(
649                                            format!("Dock {}", position.to_label()),
650                                            None,
651                                            move |cx| {
652                                                panel.set_position(position, cx);
653                                            },
654                                        )
655                                    }
656                                }
657                                menu
658                            })
659                        })
660                        .anchor(menu_anchor)
661                        .attach(menu_attach)
662                        .trigger(
663                            IconButton::new(name, icon)
664                                .icon_size(IconSize::Small)
665                                .selected(is_active_button)
666                                .on_click({
667                                    let action = action.boxed_clone();
668                                    move |_, cx| cx.dispatch_action(action.boxed_clone())
669                                })
670                                .tooltip(move |cx| {
671                                    Tooltip::for_action(tooltip.clone(), &*action, cx)
672                                }),
673                        ),
674                )
675            });
676
677        h_stack().gap_0p5().children(buttons)
678    }
679}
680
681impl StatusItemView for PanelButtons {
682    fn set_active_pane_item(
683        &mut self,
684        _active_pane_item: Option<&dyn crate::ItemHandle>,
685        _cx: &mut ViewContext<Self>,
686    ) {
687        // Nothing to do, panel buttons don't depend on the active center item
688    }
689}
690
691#[cfg(any(test, feature = "test-support"))]
692pub mod test {
693    use super::*;
694    use gpui::{actions, div, ViewContext, WindowContext};
695
696    pub struct TestPanel {
697        pub position: DockPosition,
698        pub zoomed: bool,
699        pub active: bool,
700        pub focus_handle: FocusHandle,
701        pub size: Pixels,
702    }
703    actions!(test, [ToggleTestPanel]);
704
705    impl EventEmitter<PanelEvent> for TestPanel {}
706
707    impl TestPanel {
708        pub fn new(position: DockPosition, cx: &mut WindowContext) -> Self {
709            Self {
710                position,
711                zoomed: false,
712                active: false,
713                focus_handle: cx.focus_handle(),
714                size: px(300.),
715            }
716        }
717    }
718
719    impl Render for TestPanel {
720        fn render(&mut self, _cx: &mut ViewContext<Self>) -> impl IntoElement {
721            div().id("test").track_focus(&self.focus_handle)
722        }
723    }
724
725    impl Panel for TestPanel {
726        fn persistent_name() -> &'static str {
727            "TestPanel"
728        }
729
730        fn position(&self, _: &gpui::WindowContext) -> super::DockPosition {
731            self.position
732        }
733
734        fn position_is_valid(&self, _: super::DockPosition) -> bool {
735            true
736        }
737
738        fn set_position(&mut self, position: DockPosition, cx: &mut ViewContext<Self>) {
739            self.position = position;
740            cx.emit(PanelEvent::ChangePosition);
741        }
742
743        fn size(&self, _: &WindowContext) -> Pixels {
744            self.size
745        }
746
747        fn set_size(&mut self, size: Option<Pixels>, _: &mut ViewContext<Self>) {
748            self.size = size.unwrap_or(px(300.));
749        }
750
751        fn icon(&self, _: &WindowContext) -> Option<ui::IconName> {
752            None
753        }
754
755        fn icon_tooltip(&self, _cx: &WindowContext) -> Option<&'static str> {
756            None
757        }
758
759        fn toggle_action(&self) -> Box<dyn Action> {
760            ToggleTestPanel.boxed_clone()
761        }
762
763        fn is_zoomed(&self, _: &WindowContext) -> bool {
764            self.zoomed
765        }
766
767        fn set_zoomed(&mut self, zoomed: bool, _cx: &mut ViewContext<Self>) {
768            self.zoomed = zoomed;
769        }
770
771        fn set_active(&mut self, active: bool, _cx: &mut ViewContext<Self>) {
772            self.active = active;
773        }
774    }
775
776    impl FocusableView for TestPanel {
777        fn focus_handle(&self, _cx: &AppContext) -> FocusHandle {
778            self.focus_handle.clone()
779        }
780    }
781}