Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Merge branch 'main' into window_context_2

Antonio Scandurra33bc47dbe267
diff --cc crates/gpui/src/app.rs
index 1a90e2f2da7,534f77a3490..96472f79513
--- a/crates/gpui/src/app.rs
+++ b/crates/gpui/src/app.rs
@@@ -2093,44 -2625,167 +2093,44 @@@ impl UpgradeModelHandle for AppContext
}
}
- fn model_handle_is_upgradable<T: Entity>(&self, handle: &WeakModelHandle<T>) -> bool {
- self.ref_counts.lock().is_entity_alive(handle.model_id)
- }
-
- fn upgrade_any_model_handle(&self, handle: &AnyWeakModelHandle) -> Option<AnyModelHandle> {
- if self.ref_counts.lock().is_entity_alive(handle.model_id) {
- Some(AnyModelHandle::new(
- handle.model_id,
- handle.model_type,
- self.ref_counts.clone(),
- ))
- } else {
- None
- }
- }
-}
-
-impl UpgradeViewHandle for AppContext {
- fn upgrade_view_handle<T: View>(&self, handle: &WeakViewHandle<T>) -> Option<ViewHandle<T>> {
- if self.ref_counts.lock().is_entity_alive(handle.view_id) {
- Some(ViewHandle::new(
- handle.window_id,
- handle.view_id,
- &self.ref_counts,
- ))
- } else {
- None
- }
- }
-
- fn upgrade_any_view_handle(&self, handle: &AnyWeakViewHandle) -> Option<AnyViewHandle> {
- if self.ref_counts.lock().is_entity_alive(handle.view_id) {
- Some(AnyViewHandle::new(
- handle.window_id,
- handle.view_id,
- handle.view_type,
- self.ref_counts.clone(),
- ))
- } else {
- None
- }
- }
-}
-
-impl ReadView for AppContext {
- fn read_view<T: View>(&self, handle: &ViewHandle<T>) -> &T {
- if let Some(view) = self.views.get(&(handle.window_id, handle.view_id)) {
- view.as_any().downcast_ref().expect("downcast is type safe")
- } else {
- panic!("circular view reference for type {}", type_name::<T>());
- }
- }
-}
-
-impl UpdateView for AppContext {
- fn update_view<T, S>(
- &mut self,
- handle: &ViewHandle<T>,
- update: &mut dyn FnMut(&mut T, &mut ViewContext<T>) -> S,
- ) -> S
- where
- T: View,
- {
- self.update(|this| {
- let mut view = this
- .views
- .remove(&(handle.window_id, handle.view_id))
- .expect("circular view update");
-
- let mut cx = ViewContext::new(this, handle.window_id, handle.view_id);
- let result = update(
- view.as_any_mut()
- .downcast_mut()
- .expect("downcast is type safe"),
- &mut cx,
- );
- this.views.insert((handle.window_id, handle.view_id), view);
- result
- })
- }
-}
-
-#[derive(Debug)]
-pub enum ParentId {
- View(usize),
- Root,
-}
-
-impl AppContext {
- pub fn root_view(&self, window_id: usize) -> Option<AnyViewHandle> {
- self.windows
- .get(&window_id)
- .map(|window| window.root_view.clone())
- }
-
- pub fn root_view_id(&self, window_id: usize) -> Option<usize> {
- self.windows
- .get(&window_id)
- .map(|window| window.root_view.id())
- }
-
- pub fn focused_view_id(&self, window_id: usize) -> Option<usize> {
- self.windows
- .get(&window_id)
- .and_then(|window| window.focused_view_id)
- }
-
- pub fn view_ui_name(&self, window_id: usize, view_id: usize) -> Option<&'static str> {
- Some(self.views.get(&(window_id, view_id))?.ui_name())
- }
-
- pub fn view_type_id(&self, window_id: usize, view_id: usize) -> Option<TypeId> {
- self.views
- .get(&(window_id, view_id))
- .map(|view| view.as_any().type_id())
- }
-
- pub fn background(&self) -> &Arc<executor::Background> {
- &self.background
- }
-
- pub fn font_cache(&self) -> &Arc<FontCache> {
- &self.font_cache
- }
-
- pub fn platform(&self) -> &Arc<dyn Platform> {
- &self.platform
- }
-
- pub fn has_global<T: 'static>(&self) -> bool {
- self.globals.contains_key(&TypeId::of::<T>())
+ fn model_handle_is_upgradable<T: Entity>(&self, handle: &WeakModelHandle<T>) -> bool {
- self.models.contains_key(&handle.model_id)
++ self.ref_counts.lock().is_entity_alive(handle.model_id)
}
- pub fn global<T: 'static>(&self) -> &T {
- if let Some(global) = self.globals.get(&TypeId::of::<T>()) {
- global.downcast_ref().unwrap()
+ fn upgrade_any_model_handle(&self, handle: &AnyWeakModelHandle) -> Option<AnyModelHandle> {
- if self.models.contains_key(&handle.model_id) {
++ if self.ref_counts.lock().is_entity_alive(handle.model_id) {
+ Some(AnyModelHandle::new(
+ handle.model_id,
+ handle.model_type,
+ self.ref_counts.clone(),
+ ))
} else {
- panic!("no global has been added for {}", type_name::<T>());
+ None
}
}
+}
- /// Returns an iterator over all of the view ids from the passed view up to the root of the window
- /// Includes the passed view itself
- fn ancestors(&self, window_id: usize, mut view_id: usize) -> impl Iterator<Item = usize> + '_ {
- std::iter::once(view_id)
- .into_iter()
- .chain(std::iter::from_fn(move || {
- if let Some(ParentId::View(parent_id)) = self.parents.get(&(window_id, view_id)) {
- view_id = *parent_id;
- Some(view_id)
- } else {
- None
- }
- }))
+impl UpgradeViewHandle for AppContext {
+ fn upgrade_view_handle<T: View>(&self, handle: &WeakViewHandle<T>) -> Option<ViewHandle<T>> {
+ if self.ref_counts.lock().is_entity_alive(handle.view_id) {
+ Some(ViewHandle::new(
+ handle.window_id,
+ handle.view_id,
+ &self.ref_counts,
+ ))
+ } else {
+ None
+ }
}
- /// Returns the id of the parent of the given view, or none if the given
- /// view is the root.
- pub fn parent(&self, window_id: usize, view_id: usize) -> Option<usize> {
- if let Some(ParentId::View(view_id)) = self.parents.get(&(window_id, view_id)) {
- Some(*view_id)
+ fn upgrade_any_view_handle(&self, handle: &AnyWeakViewHandle) -> Option<AnyViewHandle> {
+ if self.ref_counts.lock().is_entity_alive(handle.view_id) {
+ Some(AnyViewHandle::new(
+ handle.window_id,
+ handle.view_id,
+ handle.view_type,
+ self.ref_counts.clone(),
+ ))
} else {
None
}
diff --cc crates/workspace/src/pane.rs
index 1cad5a426f1,a54aed96f46..9bdcacb91ca
--- a/crates/workspace/src/pane.rs
+++ b/crates/workspace/src/pane.rs
@@@ -23,8 -23,9 +23,8 @@@ use gpui::
impl_actions, impl_internal_actions,
keymap_matcher::KeymapContext,
platform::{CursorStyle, MouseButton, NavigationDirection, PromptLevel},
-- Action, AnyViewHandle, AnyWeakViewHandle, AppContext, AsyncAppContext, Entity, EventContext,
- ModelHandle, MouseRegion, Quad, Task, View, ViewContext, ViewHandle, WeakViewHandle,
- ModelHandle, MouseRegion, Quad, RenderContext, Task, View, ViewContext, ViewHandle,
- WeakViewHandle,
++ Action, AnyViewHandle, AnyWeakViewHandle, AppContext, AsyncAppContext, Entity, ModelHandle,
++ MouseRegion, Quad, Task, View, ViewContext, ViewHandle, WeakViewHandle,
};
use project::{Project, ProjectEntryId, ProjectPath};
use serde::Deserialize;
@@@ -1276,13 -1409,22 +1408,22 @@@ impl Pane
})
.on_click(MouseButton::Middle, {
let item = item.clone();
- move |_, _, cx: &mut EventContext<Self>| {
- cx.dispatch_action(CloseItem {
+ let pane = pane.clone();
- move |_, cx: &mut EventContext| {
++ move |_, _, cx| {
+ cx.dispatch_action(CloseItemById {
item_id: item.id(),
pane: pane.clone(),
})
}
})
- .on_down(MouseButton::Right, move |e, cx| {
++ .on_down(MouseButton::Right, move |e, _, cx| {
+ let item = item.clone();
+ cx.dispatch_action(DeployTabContextMenu {
+ position: e.position,
+ item_id: item.id(),
+ pane: pane.clone(),
+ });
+ })
.boxed()
}
});
@@@ -1456,8 -1594,8 +1597,8 @@@
.with_cursor_style(CursorStyle::PointingHand)
.on_click(MouseButton::Left, {
let pane = pane.clone();
- move |_, cx| {
+ move |_, _, cx| {
- cx.dispatch_action(CloseItem {
+ cx.dispatch_action(CloseItemById {
item_id,
pane: pane.clone(),
})
@@@ -1532,11 -1670,7 +1673,7 @@@
.boxed()
}
- fn render_blank_pane(
- &mut self,
- theme: &Theme,
- _cx: &mut ViewContext<Self>,
- ) -> Element<Self> {
- fn render_blank_pane(&mut self, theme: &Theme, _cx: &mut RenderContext<Self>) -> ElementBox {
++ fn render_blank_pane(&mut self, theme: &Theme, _cx: &mut ViewContext<Self>) -> Element<Self> {
let background = theme.workspace.background;
Empty::new()
.contained()