Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Adjust the type arrangement on ManagedViews
Mikayla01d9d53f4a66
diff --git a/crates/command_palette2/src/command_palette.rs b/crates/command_palette2/src/command_palette.rsindex 9463cab68ca..ddb54e1505d 100644--- a/crates/command_palette2/src/command_palette.rs+++ b/crates/command_palette2/src/command_palette.rs@@ -1,8 +1,9 @@use collections::{CommandPaletteFilter, HashMap};use fuzzy::{StringMatch, StringMatchCandidate};use gpui::{- actions, div, prelude::*, Action, AppContext, Component, Dismiss, Div, FocusHandle, Keystroke,- ManagedView, ParentComponent, Render, Styled, View, ViewContext, VisualContext, WeakView,+ actions, div, prelude::*, Action, AppContext, Component, Div, EventEmitter, FocusHandle,+ FocusableView, Keystroke, ManagedView, ParentComponent, Render, Styled, View, ViewContext,+ VisualContext, WeakView,};use picker::{Picker, PickerDelegate};use std::{@@ -68,7 +69,9 @@ impl CommandPalette {}}-impl ManagedView for CommandPalette {+impl EventEmitter<ManagedView> for CommandPalette {}++impl FocusableView for CommandPalette {fn focus_handle(&self, cx: &AppContext) -> FocusHandle {self.picker.focus_handle(cx)}@@ -265,7 +268,7 @@ impl PickerDelegate for CommandPaletteDelegate {fn dismissed(&mut self, cx: &mut ViewContext<Picker<Self>>) {self.command_palette- .update(cx, |_, cx| cx.emit(Dismiss))+ .update(cx, |_, cx| cx.emit(ManagedView::Dismiss)).log_err();}diff --git a/crates/file_finder2/src/file_finder.rs b/crates/file_finder2/src/file_finder.rsindex 0fee5102e6d..5312152f9f9 100644--- a/crates/file_finder2/src/file_finder.rs+++ b/crates/file_finder2/src/file_finder.rs@@ -2,9 +2,9 @@ use collections::HashMap;use editor::{scroll::autoscroll::Autoscroll, Bias, Editor};use fuzzy::{CharBag, PathMatch, PathMatchCandidate};use gpui::{- actions, div, AppContext, Component, Dismiss, Div, FocusHandle, InteractiveComponent,- ManagedView, Model, ParentComponent, Render, Styled, Task, View, ViewContext, VisualContext,- WeakView,+ actions, div, AppContext, Component, Div, EventEmitter, FocusHandle, FocusableView,+ InteractiveComponent, ManagedView, Model, ParentComponent, Render, Styled, Task, View,+ ViewContext, VisualContext, WeakView,};use picker::{Picker, PickerDelegate};use project::{PathMatchCandidateSet, Project, ProjectPath, WorktreeId};@@ -111,7 +111,8 @@ impl FileFinder {}}-impl ManagedView for FileFinder {+impl EventEmitter<ManagedView> for FileFinder {}+impl FocusableView for FileFinder {fn focus_handle(&self, cx: &AppContext) -> FocusHandle {self.picker.focus_handle(cx)}@@ -688,7 +689,9 @@ impl PickerDelegate for FileFinderDelegate {.log_err();}}- finder.update(&mut cx, |_, cx| cx.emit(Dismiss)).ok()?;+ finder+ .update(&mut cx, |_, cx| cx.emit(ManagedView::Dismiss))+ .ok()?;Some(())})@@ -699,7 +702,7 @@ impl PickerDelegate for FileFinderDelegate {fn dismissed(&mut self, cx: &mut ViewContext<Picker<FileFinderDelegate>>) {self.file_finder- .update(cx, |_, cx| cx.emit(Dismiss))+ .update(cx, |_, cx| cx.emit(ManagedView::Dismiss)).log_err();}diff --git a/crates/go_to_line2/src/go_to_line.rs b/crates/go_to_line2/src/go_to_line.rsindex 565afb5e939..04c3f744736 100644--- a/crates/go_to_line2/src/go_to_line.rs+++ b/crates/go_to_line2/src/go_to_line.rs@@ -1,7 +1,8 @@use editor::{display_map::ToDisplayPoint, scroll::autoscroll::Autoscroll, Editor};use gpui::{- actions, div, prelude::*, AppContext, Dismiss, Div, FocusHandle, ManagedView, ParentComponent,- Render, SharedString, Styled, Subscription, View, ViewContext, VisualContext, WindowContext,+ actions, div, prelude::*, AppContext, Div, EventEmitter, FocusHandle, FocusableView,+ ManagedView, ParentComponent, Render, SharedString, Styled, Subscription, View, ViewContext,+ VisualContext, WindowContext,};use text::{Bias, Point};use theme::ActiveTheme;@@ -23,11 +24,12 @@ pub struct GoToLine {_subscriptions: Vec<Subscription>,}-impl ManagedView for GoToLine {+impl FocusableView for GoToLine {fn focus_handle(&self, cx: &AppContext) -> FocusHandle {- self.line_editor.focus_handle(cx)+ self.active_editor.focus_handle(cx)}}+impl EventEmitter<ManagedView> for GoToLine {}impl GoToLine {fn register(workspace: &mut Workspace, _: &mut ViewContext<Workspace>) {@@ -87,7 +89,7 @@ impl GoToLine {) {match event {// todo!() this isn't working...- editor::Event::Blurred => cx.emit(Dismiss),+ editor::Event::Blurred => cx.emit(ManagedView::Dismiss),editor::Event::BufferEdited { .. } => self.highlight_current_line(cx),_ => {}}@@ -122,7 +124,7 @@ impl GoToLine {}fn cancel(&mut self, _: &menu::Cancel, cx: &mut ViewContext<Self>) {- cx.emit(Dismiss);+ cx.emit(ManagedView::Dismiss);}fn confirm(&mut self, _: &menu::Confirm, cx: &mut ViewContext<Self>) {@@ -139,7 +141,7 @@ impl GoToLine {self.prev_scroll_position.take();}- cx.emit(Dismiss);+ cx.emit(ManagedView::Dismiss);}}diff --git a/crates/gpui2/src/window.rs b/crates/gpui2/src/window.rsindex 6d07f06d944..5234049943d 100644--- a/crates/gpui2/src/window.rs+++ b/crates/gpui2/src/window.rs@@ -193,17 +193,12 @@ pub trait FocusableView: Render {/// ManagedView is a view (like a Modal, Popover, Menu, etc.)/// where the lifecycle of the view is handled by another view.-pub trait ManagedView: Render {- fn focus_handle(&self, cx: &AppContext) -> FocusHandle;-}+pub trait Managed: FocusableView + EventEmitter<ManagedView> {}-pub struct Dismiss;-impl<T: ManagedView> EventEmitter<Dismiss> for T {}+impl<M: FocusableView + EventEmitter<ManagedView>> Managed for M {}-impl<T: ManagedView> FocusableView for T {- fn focus_handle(&self, cx: &AppContext) -> FocusHandle {- self.focus_handle(cx)- }+pub enum ManagedView {+ Dismiss,}// Holds the state for a specific window.diff --git a/crates/ui2/src/components/context_menu.rs b/crates/ui2/src/components/context_menu.rsindex d3214cbff1b..c6a0d9689a5 100644--- a/crates/ui2/src/components/context_menu.rs+++ b/crates/ui2/src/components/context_menu.rs@@ -4,8 +4,9 @@ use std::rc::Rc;use crate::prelude::*;use crate::{v_stack, Label, List, ListEntry, ListItem, ListSeparator, ListSubHeader};use gpui::{- overlay, px, Action, AnchorCorner, AnyElement, Bounds, Dismiss, DispatchPhase, Div,- FocusHandle, LayoutId, ManagedView, MouseButton, MouseDownEvent, Pixels, Point, Render, View,+ overlay, px, Action, AnchorCorner, AnyElement, AppContext, Bounds, DispatchPhase, Div,+ EventEmitter, FocusHandle, FocusableView, LayoutId, Managed, ManagedView, MouseButton,+ MouseDownEvent, Pixels, Point, Render, View,};pub struct ContextMenu {@@ -13,12 +14,14 @@ pub struct ContextMenu {focus_handle: FocusHandle,}-impl ManagedView for ContextMenu {- fn focus_handle(&self, cx: &gpui::AppContext) -> FocusHandle {+impl FocusableView for ContextMenu {+ fn focus_handle(&self, _cx: &AppContext) -> FocusHandle {self.focus_handle.clone()}}+impl EventEmitter<ManagedView> for ContextMenu {}+impl ContextMenu {pub fn new(cx: &mut WindowContext) -> Self {Self {@@ -44,11 +47,11 @@ impl ContextMenu {pub fn confirm(&mut self, _: &menu::Confirm, cx: &mut ViewContext<Self>) {// todo!()- cx.emit(Dismiss);+ cx.emit(ManagedView::Dismiss);}pub fn cancel(&mut self, _: &menu::Cancel, cx: &mut ViewContext<Self>) {- cx.emit(Dismiss);+ cx.emit(ManagedView::Dismiss);}}@@ -76,7 +79,7 @@ impl Render for ContextMenu {}}-pub struct MenuHandle<V: 'static, M: ManagedView> {+pub struct MenuHandle<V: 'static, M: Managed> {id: Option<ElementId>,child_builder: Option<Box<dyn FnOnce(bool) -> AnyElement<V> + 'static>>,menu_builder: Option<Rc<dyn Fn(&mut V, &mut ViewContext<V>) -> View<M> + 'static>>,@@ -85,7 +88,7 @@ pub struct MenuHandle<V: 'static, M: ManagedView> {attach: Option<AnchorCorner>,}-impl<V: 'static, M: ManagedView> MenuHandle<V, M> {+impl<V: 'static, M: Managed> MenuHandle<V, M> {pub fn id(mut self, id: impl Into<ElementId>) -> Self {self.id = Some(id.into());self@@ -115,7 +118,7 @@ impl<V: 'static, M: ManagedView> MenuHandle<V, M> {}}-pub fn menu_handle<V: 'static, M: ManagedView>() -> MenuHandle<V, M> {+pub fn menu_handle<V: 'static, M: Managed>() -> MenuHandle<V, M> {MenuHandle {id: None,child_builder: None,@@ -132,7 +135,7 @@ pub struct MenuHandleState<V, M> {child_element: Option<AnyElement<V>>,menu_element: Option<AnyElement<V>>,}-impl<V: 'static, M: ManagedView> Element<V> for MenuHandle<V, M> {+impl<V: 'static, M: Managed> Element<V> for MenuHandle<V, M> {type ElementState = MenuHandleState<V, M>;fn element_id(&self) -> Option<gpui::ElementId> {@@ -226,7 +229,7 @@ impl<V: 'static, M: ManagedView> Element<V> for MenuHandle<V, M> {let new_menu = (builder)(view_state, cx);let menu2 = menu.clone();cx.subscribe(&new_menu, move |this, modal, e, cx| match e {- &Dismiss => {+ &ManagedView::Dismiss => {*menu2.borrow_mut() = None;cx.notify();}@@ -247,7 +250,7 @@ impl<V: 'static, M: ManagedView> Element<V> for MenuHandle<V, M> {}}-impl<V: 'static, M: ManagedView> Component<V> for MenuHandle<V, M> {+impl<V: 'static, M: Managed> Component<V> for MenuHandle<V, M> {fn render(self) -> AnyElement<V> {AnyElement::new(self)}diff --git a/crates/workspace2/src/modal_layer.rs b/crates/workspace2/src/modal_layer.rsindex 8afd8317f94..3ed50fefdf2 100644--- a/crates/workspace2/src/modal_layer.rs+++ b/crates/workspace2/src/modal_layer.rs@@ -1,5 +1,5 @@use gpui::{- div, prelude::*, px, AnyView, Div, FocusHandle, ManagedView, Render, Subscription, View,+ div, prelude::*, px, AnyView, Div, FocusHandle, Managed, Render, Subscription, View,ViewContext,};use ui::{h_stack, v_stack};@@ -22,7 +22,7 @@ impl ModalLayer {pub fn toggle_modal<V, B>(&mut self, cx: &mut ViewContext<Self>, build_view: B)where- V: ManagedView,+ V: Managed,B: FnOnce(&mut ViewContext<V>) -> V,{if let Some(active_modal) = &self.active_modal {@@ -38,7 +38,7 @@ impl ModalLayer {pub fn show_modal<V>(&mut self, new_modal: View<V>, cx: &mut ViewContext<Self>)where- V: ManagedView,+ V: Managed,{self.active_modal = Some(ActiveModal {modal: new_modal.clone().into(),diff --git a/crates/workspace2/src/workspace2.rs b/crates/workspace2/src/workspace2.rsindex 08d248f6f2a..34ebdbd3e22 100644--- a/crates/workspace2/src/workspace2.rs+++ b/crates/workspace2/src/workspace2.rs@@ -31,10 +31,10 @@ use futures::{use gpui::{actions, div, point, size, Action, AnyModel, AnyView, AnyWeakView, AppContext, AsyncAppContext,AsyncWindowContext, Bounds, Context, Div, Entity, EntityId, EventEmitter, FocusHandle,- FocusableView, GlobalPixels, InteractiveComponent, KeyContext, ManagedView, Model,- ModelContext, ParentComponent, PathPromptOptions, Point, PromptLevel, Render, Size, Styled,- Subscription, Task, View, ViewContext, VisualContext, WeakView, WindowBounds, WindowContext,- WindowHandle, WindowOptions,+ FocusableView, GlobalPixels, InteractiveComponent, KeyContext, Managed, Model, ModelContext,+ ParentComponent, PathPromptOptions, Point, PromptLevel, Render, Size, Styled, Subscription,+ Task, View, ViewContext, VisualContext, WeakView, WindowBounds, WindowContext, WindowHandle,+ WindowOptions,};use item::{FollowableItem, FollowableItemHandle, Item, ItemHandle, ItemSettings, ProjectItem};use itertools::Itertools;@@ -3364,14 +3364,14 @@ impl Workspace {div}- pub fn active_modal<V: ManagedView + 'static>(+ pub fn active_modal<V: Managed + 'static>(&mut self,cx: &ViewContext<Self>,) -> Option<View<V>> {self.modal_layer.read(cx).active_modal()}- pub fn toggle_modal<V: ManagedView, B>(&mut self, cx: &mut ViewContext<Self>, build: B)+ pub fn toggle_modal<V: Managed, B>(&mut self, cx: &mut ViewContext<Self>, build: B)whereB: FnOnce(&mut ViewContext<V>) -> V,{