History

chore: use WindowContext in Workspace where it is a sufficient context type

Piotr Osiewicz committed 2 years ago

Commit c3102fe1 parent 29e74a61 file · +24 −30Browse files

Unified · Split

crates/workspace/src/workspace.rs+24−30
@@ -848,7 +848,7 @@ impl Workspace { · 847 unmodified lines
848848 self.window_edited
849849 }
850850
851− pub fn add_panel<T: Panel>(&mut self, panel: View<T>, cx: &mut ViewContext<Self>) {
851+ pub fn add_panel<T: Panel>(&mut self, panel: View<T>, cx: &mut WindowContext) {
852852 let dock = match panel.position(cx) {
853853 DockPosition::Left => &self.left_dock,
854854 DockPosition::Bottom => &self.bottom_dock,
@@ -1488,14 +1488,14 @@ impl Workspace { · 633 unmodified lines
14881488 item.to_any().downcast::<I>().ok()
14891489 }
14901490
1491− fn active_project_path(&self, cx: &ViewContext<Self>) -> Option<ProjectPath> {
1491+ fn active_project_path(&self, cx: &AppContext) -> Option<ProjectPath> {
14921492 self.active_item(cx).and_then(|item| item.project_path(cx))
14931493 }
14941494
14951495 pub fn save_active_item(
14961496 &mut self,
14971497 save_intent: SaveIntent,
1498− cx: &mut ViewContext<Self>,
1498+ cx: &mut WindowContext,
14991499 ) -> Task<Result<()>> {
15001500 let project = self.project.clone();
15011501 let pane = self.active_pane();
@@ -1503,7 +1503,7 @@ impl Workspace { · 1 unmodified line
15031503 let item = pane.read(cx).active_item();
15041504 let pane = pane.downgrade();
15051505
1506− cx.spawn(|_, mut cx| async move {
1506+ cx.spawn(|mut cx| async move {
15071507 if let Some(item) = item {
15081508 Pane::save_item(project, &pane, item_ix, item.as_ref(), save_intent, &mut cx)
15091509 .await
@@ -1764,7 +1764,7 @@ impl Workspace { · 254 unmodified lines
17641764 }
17651765 }
17661766
1767− pub fn add_item(&mut self, item: Box<dyn ItemHandle>, cx: &mut ViewContext<Self>) {
1767+ pub fn add_item(&mut self, item: Box<dyn ItemHandle>, cx: &mut WindowContext) {
17681768 if let Some(text) = item.telemetry_event_text(cx) {
17691769 self.client()
17701770 .telemetry()
@@ -1846,7 +1846,7 @@ impl Workspace { · 75 unmodified lines
18461846 path: impl Into<ProjectPath>,
18471847 pane: Option<WeakView<Pane>>,
18481848 focus_item: bool,
1849− cx: &mut ViewContext<Self>,
1849+ cx: &mut WindowContext,
18501850 ) -> Task<Result<Box<dyn ItemHandle>, anyhow::Error>> {
18511851 let pane = pane.unwrap_or_else(|| {
18521852 self.last_active_center_pane.clone().unwrap_or_else(|| {
@@ -1858,7 +1858,7 @@ impl Workspace { · 5 unmodified lines
18581858 });
18591859
18601860 let task = self.load_path(path.into(), cx);
1861− cx.spawn(move |_, mut cx| async move {
1861+ cx.spawn(move |mut cx| async move {
18621862 let (project_entry_id, build_item) = task.await?;
18631863 pane.update(&mut cx, |pane, cx| {
18641864 pane.open_item(project_entry_id, focus_item, cx, build_item)
@@ -1901,7 +1901,7 @@ impl Workspace { · 36 unmodified lines
19011901 fn load_path(
19021902 &mut self,
19031903 path: ProjectPath,
1904− cx: &mut ViewContext<Self>,
1904+ cx: &mut WindowContext,
19051905 ) -> Task<
19061906 Result<(
19071907 Option<ProjectEntryId>,
@@ -1910,7 +1910,7 @@ impl Workspace { · 2 unmodified lines
19101910 > {
19111911 let project = self.project().clone();
19121912 let project_item = project.update(cx, |project, cx| project.open_path(path, cx));
1913− cx.spawn(|_, mut cx| async move {
1913+ cx.spawn(|mut cx| async move {
19141914 let (project_entry_id, project_item) = project_item.await?;
19151915 let build_item = cx.update(|cx| {
19161916 cx.default_global::<ProjectItemBuilders>()
@@ -1980,7 +1980,7 @@ impl Workspace { · 63 unmodified lines
19801980 }
19811981 }
19821982
1983− pub fn activate_item(&mut self, item: &dyn ItemHandle, cx: &mut ViewContext<Self>) -> bool {
1983+ pub fn activate_item(&mut self, item: &dyn ItemHandle, cx: &mut WindowContext) -> bool {
19841984 let result = self.panes.iter().find_map(|pane| {
19851985 pane.read(cx)
19861986 .index_for_item(item)
@@ -2003,7 +2003,7 @@ impl Workspace { · 16 unmodified lines
20032003 }
20042004 }
20052005
2006− pub fn activate_next_pane(&mut self, cx: &mut ViewContext<Self>) {
2006+ pub fn activate_next_pane(&mut self, cx: &mut WindowContext) {
20072007 let panes = self.center.panes();
20082008 if let Some(ix) = panes.iter().position(|pane| **pane == self.active_pane) {
20092009 let next_ix = (ix + 1) % panes.len();
@@ -2012,7 +2012,7 @@ impl Workspace { · 2 unmodified lines
20122012 }
20132013 }
20142014
2015− pub fn activate_previous_pane(&mut self, cx: &mut ViewContext<Self>) {
2015+ pub fn activate_previous_pane(&mut self, cx: &mut WindowContext) {
20162016 let panes = self.center.panes();
20172017 if let Some(ix) = panes.iter().position(|pane| **pane == self.active_pane) {
20182018 let prev_ix = cmp::min(ix.wrapping_sub(1), panes.len() - 1);
@@ -2024,7 +2024,7 @@ impl Workspace { · 5 unmodified lines
20242024 pub fn activate_pane_in_direction(
20252025 &mut self,
20262026 direction: SplitDirection,
2027− cx: &mut ViewContext<Self>,
2027+ cx: &mut WindowContext,
20282028 ) {
20292029 if let Some(pane) = self.find_pane_in_direction(direction, cx) {
20302030 cx.focus_view(pane);
@@ -2048,7 +2048,7 @@ impl Workspace { · 17 unmodified lines
20482048 fn find_pane_in_direction(
20492049 &mut self,
20502050 direction: SplitDirection,
2051− cx: &mut ViewContext<Self>,
2051+ cx: &AppContext,
20522052 ) -> Option<&View<Pane>> {
20532053 let Some(bounding_box) = self.center.bounding_box_for_pane(&self.active_pane) else {
20542054 return None;
@@ -2483,14 +2483,14 @@ impl Workspace { · 428 unmodified lines
24832483 .any(|state| state.leader_id == peer_id)
24842484 }
24852485
2486− fn active_item_path_changed(&mut self, cx: &mut ViewContext<Self>) {
2486+ fn active_item_path_changed(&mut self, cx: &mut WindowContext) {
24872487 let active_entry = self.active_project_path(cx);
24882488 self.project
24892489 .update(cx, |project, cx| project.set_active_path(active_entry, cx));
24902490 self.update_window_title(cx);
24912491 }
24922492
2493− fn update_window_title(&mut self, cx: &mut ViewContext<Self>) {
2493+ fn update_window_title(&mut self, cx: &mut WindowContext) {
24942494 let project = self.project().read(cx);
24952495 let mut title = String::new();
24962496
@@ -2534,7 +2534,7 @@ impl Workspace { · 37 unmodified lines
25342534 cx.set_window_title(&title);
25352535 }
25362536
2537− fn update_window_edited(&mut self, cx: &mut ViewContext<Self>) {
2537+ fn update_window_edited(&mut self, cx: &mut WindowContext) {
25382538 let is_edited = !self.project.read(cx).is_disconnected()
25392539 && self
25402540 .items(cx)
@@ -2759,7 +2759,7 @@ impl Workspace { · 218 unmodified lines
27592759 Ok(())
27602760 }
27612761
2762− fn update_active_view_for_followers(&mut self, cx: &mut ViewContext<Self>) {
2762+ fn update_active_view_for_followers(&mut self, cx: &mut WindowContext) {
27632763 let mut is_project_item = true;
27642764 let mut update = proto::UpdateActiveView::default();
27652765
@@ -2876,7 +2876,7 @@ impl Workspace { · 110 unmodified lines
28762876 &self,
28772877 peer_id: PeerId,
28782878 pane: &View<Pane>,
2879− cx: &mut ViewContext<Self>,
2879+ cx: &mut WindowContext,
28802880 ) -> Option<View<SharedScreen>> {
28812881 let call = self.active_call()?;
28822882 let room = call.read(cx).room()?.read(cx);
@@ -2993,7 +2993,7 @@ impl Workspace { · 110 unmodified lines
29932993 }));
29942994 }
29952995
2996− fn serialize_workspace(&self, cx: &mut ViewContext<Self>) {
2996+ fn serialize_workspace(&self, cx: &mut WindowContext) {
29972997 fn serialize_pane_handle(pane_handle: &View<Pane>, cx: &WindowContext) -> SerializedPane {
29982998 let (items, active) = {
29992999 let pane = pane_handle.read(cx);
@@ -3039,10 +3039,7 @@ impl Workspace { · 39 unmodified lines
30393039 }
30403040 }
30413041
3042− fn build_serialized_docks(
3043− this: &Workspace,
3044− cx: &mut ViewContext<Workspace>,
3045− ) -> DockStructure {
3042+ fn build_serialized_docks(this: &Workspace, cx: &mut WindowContext) -> DockStructure {
30463043 let left_dock = this.left_dock.read(cx);
30473044 let left_visible = left_dock.is_open();
30483045 let left_active_panel = left_dock
@@ -3109,7 +3106,7 @@ impl Workspace { · 60 unmodified lines
31093106 docks,
31103107 };
31113108
3112− cx.spawn(|_, _| persistence::DB.save_workspace(serialized_workspace))
3109+ cx.spawn(|_| persistence::DB.save_workspace(serialized_workspace))
31133110 .detach();
31143111 }
31153112 }
@@ -3350,14 +3347,11 @@ impl Workspace { · 234 unmodified lines
33503347 self.modal_layer.read(cx).has_active_modal()
33513348 }
33523349
3353− pub fn active_modal<V: ManagedView + 'static>(
3354− &mut self,
3355− cx: &ViewContext<Self>,
3356− ) -> Option<View<V>> {
3350+ pub fn active_modal<V: ManagedView + 'static>(&mut self, cx: &AppContext) -> Option<View<V>> {
33573351 self.modal_layer.read(cx).active_modal()
33583352 }
33593353
3360− pub fn toggle_modal<V: ModalView, B>(&mut self, cx: &mut ViewContext<Self>, build: B)
3354+ pub fn toggle_modal<V: ModalView, B>(&mut self, cx: &mut WindowContext, build: B)
33613355 where
33623356 B: FnOnce(&mut ViewContext<V>) -> V,
33633357 {