From c550fc3f01c9fad44b0358c3949eb41cefda8851 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Mon, 21 Mar 2022 21:52:28 -0700 Subject: [PATCH] WIP - Start work on unfollowing automatically --- crates/editor/src/items.rs | 4 ++++ crates/workspace/src/workspace.rs | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/crates/editor/src/items.rs b/crates/editor/src/items.rs index 7afc79f8b384a15c8a9111c24e0e11629730970e..d0457eba5adb3b4a18f240bf8141a87c5719276e 100644 --- a/crates/editor/src/items.rs +++ b/crates/editor/src/items.rs @@ -158,6 +158,10 @@ impl FollowableItem for Editor { } Ok(()) } + + fn should_unfollow_on_event(event: &Self::Event, cx: &AppContext) -> bool { + false + } } fn serialize_selection(selection: &Selection) -> proto::Selection { diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index 387bfa9b6eff2b37403c3cf5df26d2476988711c..5ce61824e35a1f2fa13accf7ec430d6515b08d10 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -270,6 +270,7 @@ pub trait FollowableItem: Item { message: proto::update_view::Variant, cx: &mut ViewContext, ) -> Result<()>; + fn should_unfollow_on_event(event: &Self::Event, cx: &AppContext) -> bool; } pub trait FollowableItemHandle: ItemHandle { @@ -285,6 +286,7 @@ pub trait FollowableItemHandle: ItemHandle { message: proto::update_view::Variant, cx: &mut MutableAppContext, ) -> Result<()>; + fn should_unfollow_on_event(&self, event: &dyn Any, cx: &AppContext) -> bool; } impl FollowableItemHandle for ViewHandle { @@ -313,6 +315,14 @@ impl FollowableItemHandle for ViewHandle { ) -> Result<()> { self.update(cx, |this, cx| this.apply_update_message(message, cx)) } + + fn should_unfollow_on_event(&self, event: &dyn Any, cx: &AppContext) -> bool { + if let Some(event) = event.downcast_ref() { + T::should_unfollow_on_event(event, cx) + } else { + false + } + } } pub trait ItemHandle: 'static + fmt::Debug { @@ -421,6 +431,12 @@ impl ItemHandle for ViewHandle { return; }; + if let Some(item) = item.to_followable_item_handle(cx) { + if item.should_unfollow_on_event(event, cx) { + workspace.unfollow(&pane, cx); + } + } + if T::should_close_item_on_event(event) { pane.update(cx, |pane, cx| pane.close_item(item.id(), cx)); return;