Set up logic for starting following

Co-Authored-By: Antonio Scandurra <me@as-cii.com>
This commit is contained in:
Max Brunsfeld 2022-03-17 10:46:54 -07:00
parent 2b4738d82d
commit 9716ff7964
4 changed files with 142 additions and 28 deletions

View file

@ -1,5 +1,7 @@
use super::{ItemHandle, SplitDirection};
use crate::{Item, Settings, WeakItemHandle, Workspace};
use anyhow::{anyhow, Result};
use client::PeerId;
use collections::{HashMap, VecDeque};
use gpui::{
action,
@ -105,6 +107,13 @@ pub struct Pane {
active_toolbar_visible: bool,
}
pub(crate) struct FollowerState {
pub(crate) leader_id: PeerId,
pub(crate) current_view_id: usize,
pub(crate) items_by_leader_view_id:
HashMap<usize, (Option<ProjectEntryId>, Box<dyn ItemHandle>)>,
}
pub trait Toolbar: View {
fn active_item_changed(
&mut self,
@ -313,6 +322,21 @@ impl Pane {
cx.notify();
}
pub(crate) fn set_follow_state(
&mut self,
follower_state: FollowerState,
cx: &mut ViewContext<Self>,
) -> Result<()> {
let current_view_id = follower_state.current_view_id as usize;
let (project_entry_id, item) = follower_state
.items_by_leader_view_id
.get(&current_view_id)
.ok_or_else(|| anyhow!("invalid current view id"))?
.clone();
self.add_item(project_entry_id, item, cx);
Ok(())
}
pub fn items(&self) -> impl Iterator<Item = &Box<dyn ItemHandle>> {
self.items.iter().map(|(_, view)| view)
}