| 1 | use gpui::{ |
| 2 | App, Context, EventEmitter, FocusHandle, Focusable, IntoElement, ParentElement as _, Render, |
| 3 | SharedString, Styled as _, Window, div, |
| 4 | }; |
| 5 | use gpui_base::dock::{PanelEvent, PanelState}; |
| 6 | |
| 7 | use crate::{ActiveTheme as _, dock::Panel}; |
| 8 | |
| 9 | /// Stands in for a panel this build cannot construct — one whose |
| 10 | /// `panel_name` no [`PanelRegistry`](gpui_base::dock::PanelRegistry) builder |
| 11 | /// answers to. |
| 12 | /// |
| 13 | /// It reports the original [`PanelState`] from |
| 14 | /// [`dump`](gpui_base::dock::Panel::dump), so a layout written by a build that |
| 15 | /// knows the panel survives a load and a save here rather than losing it. |
| 16 | pub(crate) struct InvalidPanel { |
| 17 | name: SharedString, |
| 18 | focus_handle: FocusHandle, |
| 19 | old_state: PanelState, |
| 20 | } |
| 21 | |
| 22 | impl InvalidPanel { |
| 23 | pub(crate) fn new( |
| 24 | name: impl Into<SharedString>, |
| 25 | state: PanelState, |
| 26 | cx: &mut Context<Self>, |
| 27 | ) -> Self { |
| 28 | Self { |
| 29 | focus_handle: cx.focus_handle(), |
| 30 | name: name.into(), |
| 31 | old_state: state, |
| 32 | } |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | impl gpui_base::dock::Panel for InvalidPanel { |
| 37 | fn panel_name(&self) -> &'static str { |
| 38 | "InvalidPanel" |
| 39 | } |
| 40 | |
| 41 | fn dump(&self, _: &App) -> PanelState { |
| 42 | self.old_state.clone() |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | impl Panel for InvalidPanel {} |
| 47 | |
| 48 | impl EventEmitter<PanelEvent> for InvalidPanel {} |
| 49 | |
| 50 | impl Focusable for InvalidPanel { |
| 51 | fn focus_handle(&self, _: &App) -> FocusHandle { |
| 52 | self.focus_handle.clone() |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | impl Render for InvalidPanel { |
| 57 | fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement { |
| 58 | div() |
| 59 | .size_full() |
| 60 | .my_6() |
| 61 | .flex() |
| 62 | .flex_col() |
| 63 | .items_center() |
| 64 | .justify_center() |
| 65 | .text_color(cx.theme().muted_foreground) |
| 66 | .child(format!( |
| 67 | "The `{}` panel type is not registered in PanelRegistry.", |
| 68 | self.name.clone() |
| 69 | )) |
| 70 | } |
| 71 | } |