Rename FollowedItem -> FollowableItem
Co-Authored-By: Antonio Scandurra <me@as-cii.com>
This commit is contained in:
parent
f4520d4184
commit
2c53175566
1 changed files with 16 additions and 16 deletions
|
@ -50,17 +50,17 @@ type ProjectItemBuilders = HashMap<
|
||||||
fn(usize, ModelHandle<Project>, AnyModelHandle, &mut MutableAppContext) -> Box<dyn ItemHandle>,
|
fn(usize, ModelHandle<Project>, AnyModelHandle, &mut MutableAppContext) -> Box<dyn ItemHandle>,
|
||||||
>;
|
>;
|
||||||
|
|
||||||
type FollowedItemBuilder = fn(
|
type FollowableItemBuilder = fn(
|
||||||
ViewHandle<Pane>,
|
ViewHandle<Pane>,
|
||||||
ModelHandle<Project>,
|
ModelHandle<Project>,
|
||||||
&mut Option<proto::view::Variant>,
|
&mut Option<proto::view::Variant>,
|
||||||
&mut MutableAppContext,
|
&mut MutableAppContext,
|
||||||
) -> Option<Task<Result<Box<dyn ItemHandle>>>>;
|
) -> Option<Task<Result<Box<dyn ItemHandle>>>>;
|
||||||
type FollowedItemBuilders = HashMap<
|
type FollowableItemBuilders = HashMap<
|
||||||
TypeId,
|
TypeId,
|
||||||
(
|
(
|
||||||
FollowedItemBuilder,
|
FollowableItemBuilder,
|
||||||
fn(AnyViewHandle) -> Box<dyn FollowedItemHandle>,
|
fn(AnyViewHandle) -> Box<dyn FollowableItemHandle>,
|
||||||
),
|
),
|
||||||
>;
|
>;
|
||||||
|
|
||||||
|
@ -132,7 +132,7 @@ pub fn register_project_item<I: ProjectItem>(cx: &mut MutableAppContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn register_followable_item<I: FollowableItem>(cx: &mut MutableAppContext) {
|
pub fn register_followable_item<I: FollowableItem>(cx: &mut MutableAppContext) {
|
||||||
cx.update_default_global(|builders: &mut FollowedItemBuilders, _| {
|
cx.update_default_global(|builders: &mut FollowableItemBuilders, _| {
|
||||||
builders.insert(
|
builders.insert(
|
||||||
TypeId::of::<I>(),
|
TypeId::of::<I>(),
|
||||||
(I::for_state_message, |this| {
|
(I::for_state_message, |this| {
|
||||||
|
@ -251,7 +251,7 @@ pub trait FollowableItem: Item {
|
||||||
) -> Option<proto::update_followers::update_view::Variant>;
|
) -> Option<proto::update_followers::update_view::Variant>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait FollowedItemHandle {
|
pub trait FollowableItemHandle {
|
||||||
fn id(&self) -> usize;
|
fn id(&self) -> usize;
|
||||||
fn to_state_message(&self, cx: &AppContext) -> proto::view::Variant;
|
fn to_state_message(&self, cx: &AppContext) -> proto::view::Variant;
|
||||||
fn to_update_message(
|
fn to_update_message(
|
||||||
|
@ -261,7 +261,7 @@ pub trait FollowedItemHandle {
|
||||||
) -> Option<proto::update_followers::update_view::Variant>;
|
) -> Option<proto::update_followers::update_view::Variant>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: FollowableItem> FollowedItemHandle for ViewHandle<T> {
|
impl<T: FollowableItem> FollowableItemHandle for ViewHandle<T> {
|
||||||
fn id(&self) -> usize {
|
fn id(&self) -> usize {
|
||||||
self.id()
|
self.id()
|
||||||
}
|
}
|
||||||
|
@ -308,7 +308,7 @@ pub trait ItemHandle: 'static {
|
||||||
cx: &mut MutableAppContext,
|
cx: &mut MutableAppContext,
|
||||||
) -> Task<Result<()>>;
|
) -> Task<Result<()>>;
|
||||||
fn act_as_type(&self, type_id: TypeId, cx: &AppContext) -> Option<AnyViewHandle>;
|
fn act_as_type(&self, type_id: TypeId, cx: &AppContext) -> Option<AnyViewHandle>;
|
||||||
fn to_followed_item_handle(&self, cx: &AppContext) -> Option<Box<dyn FollowedItemHandle>>;
|
fn to_followable_item_handle(&self, cx: &AppContext) -> Option<Box<dyn FollowableItemHandle>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait WeakItemHandle {
|
pub trait WeakItemHandle {
|
||||||
|
@ -363,7 +363,7 @@ impl<T: Item> ItemHandle for ViewHandle<T> {
|
||||||
pane: ViewHandle<Pane>,
|
pane: ViewHandle<Pane>,
|
||||||
cx: &mut ViewContext<Workspace>,
|
cx: &mut ViewContext<Workspace>,
|
||||||
) {
|
) {
|
||||||
if let Some(followed_item) = self.to_followed_item_handle(cx) {
|
if let Some(followed_item) = self.to_followable_item_handle(cx) {
|
||||||
workspace.update_followers(
|
workspace.update_followers(
|
||||||
proto::update_followers::Variant::CreateView(proto::View {
|
proto::update_followers::Variant::CreateView(proto::View {
|
||||||
id: followed_item.id() as u64,
|
id: followed_item.id() as u64,
|
||||||
|
@ -401,7 +401,7 @@ impl<T: Item> ItemHandle for ViewHandle<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(message) = item
|
if let Some(message) = item
|
||||||
.to_followed_item_handle(cx)
|
.to_followable_item_handle(cx)
|
||||||
.and_then(|i| i.to_update_message(event, cx))
|
.and_then(|i| i.to_update_message(event, cx))
|
||||||
{
|
{
|
||||||
workspace.update_followers(
|
workspace.update_followers(
|
||||||
|
@ -467,9 +467,9 @@ impl<T: Item> ItemHandle for ViewHandle<T> {
|
||||||
self.read(cx).act_as_type(type_id, self, cx)
|
self.read(cx).act_as_type(type_id, self, cx)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn to_followed_item_handle(&self, cx: &AppContext) -> Option<Box<dyn FollowedItemHandle>> {
|
fn to_followable_item_handle(&self, cx: &AppContext) -> Option<Box<dyn FollowableItemHandle>> {
|
||||||
if cx.has_global::<FollowedItemBuilders>() {
|
if cx.has_global::<FollowableItemBuilders>() {
|
||||||
let builders = cx.global::<FollowedItemBuilders>();
|
let builders = cx.global::<FollowableItemBuilders>();
|
||||||
let item = self.to_any();
|
let item = self.to_any();
|
||||||
Some(builders.get(&item.view_type())?.1(item))
|
Some(builders.get(&item.view_type())?.1(item))
|
||||||
} else {
|
} else {
|
||||||
|
@ -1186,7 +1186,7 @@ impl Workspace {
|
||||||
(this.project.clone(), this.active_pane().clone())
|
(this.project.clone(), this.active_pane().clone())
|
||||||
});
|
});
|
||||||
let item_builders = cx.update(|cx| {
|
let item_builders = cx.update(|cx| {
|
||||||
cx.default_global::<FollowedItemBuilders>()
|
cx.default_global::<FollowableItemBuilders>()
|
||||||
.values()
|
.values()
|
||||||
.map(|b| b.0)
|
.map(|b| b.0)
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
|
@ -1477,7 +1477,7 @@ impl Workspace {
|
||||||
|
|
||||||
let active_view_id = this
|
let active_view_id = this
|
||||||
.active_item(cx)
|
.active_item(cx)
|
||||||
.and_then(|i| i.to_followed_item_handle(cx))
|
.and_then(|i| i.to_followable_item_handle(cx))
|
||||||
.map(|i| i.id() as u64);
|
.map(|i| i.id() as u64);
|
||||||
Ok(proto::FollowResponse {
|
Ok(proto::FollowResponse {
|
||||||
active_view_id,
|
active_view_id,
|
||||||
|
@ -1485,7 +1485,7 @@ impl Workspace {
|
||||||
.items(cx)
|
.items(cx)
|
||||||
.filter_map(|item| {
|
.filter_map(|item| {
|
||||||
let id = item.id() as u64;
|
let id = item.id() as u64;
|
||||||
let item = item.to_followed_item_handle(cx)?;
|
let item = item.to_followable_item_handle(cx)?;
|
||||||
let variant = item.to_state_message(cx);
|
let variant = item.to_state_message(cx);
|
||||||
Some(proto::View {
|
Some(proto::View {
|
||||||
id,
|
id,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue