Merge MutableAppContext into AppContext

There may have been a good reason for the difference at some point, or I was
still learning Rust. But now it's just &mut AppContext vs &AppContext.
This commit is contained in:
Nathan Sobo
2023-04-06 15:49:03 -06:00
parent dd00966cc6
commit de9bf6dfbd
112 changed files with 882 additions and 1041 deletions
+3 -3
View File
@@ -7,8 +7,8 @@ use gpui::{
actions,
elements::{ChildView, Container, Empty, MouseEventHandler, ParentElement, Side, Stack},
geometry::vector::Vector2F,
impl_internal_actions, Border, CursorStyle, Element, ElementBox, MouseButton,
MutableAppContext, RenderContext, SizeConstraint, ViewContext, ViewHandle,
impl_internal_actions, AppContext, Border, CursorStyle, Element, ElementBox, MouseButton,
RenderContext, SizeConstraint, ViewContext, ViewHandle,
};
use settings::{DockAnchor, Settings};
use theme::Theme;
@@ -36,7 +36,7 @@ actions!(
);
impl_internal_actions!(dock, [MoveDock, AddDefaultItemToDock]);
pub fn init(cx: &mut MutableAppContext) {
pub fn init(cx: &mut AppContext) {
cx.add_action(Dock::focus_dock);
cx.add_action(Dock::hide_dock);
cx.add_action(
+35 -40
View File
@@ -15,8 +15,8 @@ use std::{
use anyhow::Result;
use client::{proto, Client};
use gpui::{
AnyViewHandle, AppContext, ElementBox, ModelHandle, MutableAppContext, Task, View, ViewContext,
ViewHandle, WeakViewHandle,
AnyViewHandle, AppContext, ElementBox, ModelHandle, Task, View, ViewContext, ViewHandle,
WeakViewHandle,
};
use project::{Project, ProjectEntryId, ProjectPath};
use settings::{Autosave, Settings};
@@ -159,8 +159,8 @@ pub trait Item: View {
pub trait ItemHandle: 'static + fmt::Debug {
fn subscribe_to_item_events(
&self,
cx: &mut MutableAppContext,
handler: Box<dyn Fn(ItemEvent, &mut MutableAppContext)>,
cx: &mut AppContext,
handler: Box<dyn Fn(ItemEvent, &mut AppContext)>,
) -> gpui::Subscription;
fn tab_description<'a>(&self, detail: usize, cx: &'a AppContext) -> Option<Cow<'a, str>>;
fn tab_content(&self, detail: Option<usize>, style: &theme::Tab, cx: &AppContext)
@@ -174,7 +174,7 @@ pub trait ItemHandle: 'static + fmt::Debug {
fn clone_on_split(
&self,
workspace_id: WorkspaceId,
cx: &mut MutableAppContext,
cx: &mut AppContext,
) -> Option<Box<dyn ItemHandle>>;
fn added_to_pane(
&self,
@@ -182,35 +182,34 @@ pub trait ItemHandle: 'static + fmt::Debug {
pane: ViewHandle<Pane>,
cx: &mut ViewContext<Workspace>,
);
fn deactivated(&self, cx: &mut MutableAppContext);
fn workspace_deactivated(&self, cx: &mut MutableAppContext);
fn navigate(&self, data: Box<dyn Any>, cx: &mut MutableAppContext) -> bool;
fn deactivated(&self, cx: &mut AppContext);
fn workspace_deactivated(&self, cx: &mut AppContext);
fn navigate(&self, data: Box<dyn Any>, cx: &mut AppContext) -> bool;
fn id(&self) -> usize;
fn window_id(&self) -> usize;
fn as_any(&self) -> &AnyViewHandle;
fn is_dirty(&self, cx: &AppContext) -> bool;
fn has_conflict(&self, cx: &AppContext) -> bool;
fn can_save(&self, cx: &AppContext) -> bool;
fn save(&self, project: ModelHandle<Project>, cx: &mut MutableAppContext) -> Task<Result<()>>;
fn save(&self, project: ModelHandle<Project>, cx: &mut AppContext) -> Task<Result<()>>;
fn save_as(
&self,
project: ModelHandle<Project>,
abs_path: PathBuf,
cx: &mut MutableAppContext,
cx: &mut AppContext,
) -> Task<Result<()>>;
fn reload(&self, project: ModelHandle<Project>, cx: &mut MutableAppContext)
-> Task<Result<()>>;
fn reload(&self, project: ModelHandle<Project>, cx: &mut AppContext) -> Task<Result<()>>;
fn git_diff_recalc(
&self,
project: ModelHandle<Project>,
cx: &mut MutableAppContext,
cx: &mut AppContext,
) -> Task<Result<()>>;
fn act_as_type<'a>(&'a self, type_id: TypeId, cx: &'a AppContext) -> Option<&'a AnyViewHandle>;
fn to_followable_item_handle(&self, cx: &AppContext) -> Option<Box<dyn FollowableItemHandle>>;
fn on_release(
&self,
cx: &mut MutableAppContext,
callback: Box<dyn FnOnce(&mut MutableAppContext)>,
cx: &mut AppContext,
callback: Box<dyn FnOnce(&mut AppContext)>,
) -> gpui::Subscription;
fn to_searchable_item_handle(&self, cx: &AppContext) -> Option<Box<dyn SearchableItemHandle>>;
fn breadcrumb_location(&self, cx: &AppContext) -> ToolbarItemLocation;
@@ -239,8 +238,8 @@ impl dyn ItemHandle {
impl<T: Item> ItemHandle for ViewHandle<T> {
fn subscribe_to_item_events(
&self,
cx: &mut MutableAppContext,
handler: Box<dyn Fn(ItemEvent, &mut MutableAppContext)>,
cx: &mut AppContext,
handler: Box<dyn Fn(ItemEvent, &mut AppContext)>,
) -> gpui::Subscription {
cx.subscribe(self, move |_, event, cx| {
for item_event in T::to_item_events(event) {
@@ -306,7 +305,7 @@ impl<T: Item> ItemHandle for ViewHandle<T> {
fn clone_on_split(
&self,
workspace_id: WorkspaceId,
cx: &mut MutableAppContext,
cx: &mut AppContext,
) -> Option<Box<dyn ItemHandle>> {
self.update(cx, |item, cx| {
cx.add_option_view(|cx| item.clone_on_split(workspace_id, cx))
@@ -493,15 +492,15 @@ impl<T: Item> ItemHandle for ViewHandle<T> {
});
}
fn deactivated(&self, cx: &mut MutableAppContext) {
fn deactivated(&self, cx: &mut AppContext) {
self.update(cx, |this, cx| this.deactivated(cx));
}
fn workspace_deactivated(&self, cx: &mut MutableAppContext) {
fn workspace_deactivated(&self, cx: &mut AppContext) {
self.update(cx, |this, cx| this.workspace_deactivated(cx));
}
fn navigate(&self, data: Box<dyn Any>, cx: &mut MutableAppContext) -> bool {
fn navigate(&self, data: Box<dyn Any>, cx: &mut AppContext) -> bool {
self.update(cx, |this, cx| this.navigate(data, cx))
}
@@ -529,7 +528,7 @@ impl<T: Item> ItemHandle for ViewHandle<T> {
self.read(cx).can_save(cx)
}
fn save(&self, project: ModelHandle<Project>, cx: &mut MutableAppContext) -> Task<Result<()>> {
fn save(&self, project: ModelHandle<Project>, cx: &mut AppContext) -> Task<Result<()>> {
self.update(cx, |item, cx| item.save(project, cx))
}
@@ -537,23 +536,19 @@ impl<T: Item> ItemHandle for ViewHandle<T> {
&self,
project: ModelHandle<Project>,
abs_path: PathBuf,
cx: &mut MutableAppContext,
cx: &mut AppContext,
) -> Task<anyhow::Result<()>> {
self.update(cx, |item, cx| item.save_as(project, abs_path, cx))
}
fn reload(
&self,
project: ModelHandle<Project>,
cx: &mut MutableAppContext,
) -> Task<Result<()>> {
fn reload(&self, project: ModelHandle<Project>, cx: &mut AppContext) -> Task<Result<()>> {
self.update(cx, |item, cx| item.reload(project, cx))
}
fn git_diff_recalc(
&self,
project: ModelHandle<Project>,
cx: &mut MutableAppContext,
cx: &mut AppContext,
) -> Task<Result<()>> {
self.update(cx, |item, cx| item.git_diff_recalc(project, cx))
}
@@ -574,8 +569,8 @@ impl<T: Item> ItemHandle for ViewHandle<T> {
fn on_release(
&self,
cx: &mut MutableAppContext,
callback: Box<dyn FnOnce(&mut MutableAppContext)>,
cx: &mut AppContext,
callback: Box<dyn FnOnce(&mut AppContext)>,
) -> gpui::Subscription {
cx.observe_release(self, move |_, cx| callback(cx))
}
@@ -651,7 +646,7 @@ pub trait FollowableItem: Item {
project: ModelHandle<Project>,
id: ViewId,
state: &mut Option<proto::view::Variant>,
cx: &mut MutableAppContext,
cx: &mut AppContext,
) -> Option<Task<Result<ViewHandle<Self>>>>;
fn add_event_to_update_proto(
&self,
@@ -672,7 +667,7 @@ pub trait FollowableItem: Item {
pub trait FollowableItemHandle: ItemHandle {
fn remote_id(&self, client: &Arc<Client>, cx: &AppContext) -> Option<ViewId>;
fn set_leader_replica_id(&self, leader_replica_id: Option<u16>, cx: &mut MutableAppContext);
fn set_leader_replica_id(&self, leader_replica_id: Option<u16>, cx: &mut AppContext);
fn to_state_proto(&self, cx: &AppContext) -> Option<proto::view::Variant>;
fn add_event_to_update_proto(
&self,
@@ -684,7 +679,7 @@ pub trait FollowableItemHandle: ItemHandle {
&self,
project: &ModelHandle<Project>,
message: proto::update_view::Variant,
cx: &mut MutableAppContext,
cx: &mut AppContext,
) -> Task<Result<()>>;
fn should_unfollow_on_event(&self, event: &dyn Any, cx: &AppContext) -> bool;
}
@@ -699,7 +694,7 @@ impl<T: FollowableItem> FollowableItemHandle for ViewHandle<T> {
})
}
fn set_leader_replica_id(&self, leader_replica_id: Option<u16>, cx: &mut MutableAppContext) {
fn set_leader_replica_id(&self, leader_replica_id: Option<u16>, cx: &mut AppContext) {
self.update(cx, |this, cx| {
this.set_leader_replica_id(leader_replica_id, cx)
})
@@ -726,7 +721,7 @@ impl<T: FollowableItem> FollowableItemHandle for ViewHandle<T> {
&self,
project: &ModelHandle<Project>,
message: proto::update_view::Variant,
cx: &mut MutableAppContext,
cx: &mut AppContext,
) -> Task<Result<()>> {
self.update(cx, |this, cx| this.apply_update_proto(project, message, cx))
}
@@ -745,8 +740,8 @@ pub(crate) mod test {
use super::{Item, ItemEvent};
use crate::{sidebar::SidebarItem, ItemId, ItemNavHistory, Pane, Workspace, WorkspaceId};
use gpui::{
elements::Empty, AppContext, Element, ElementBox, Entity, ModelHandle, MutableAppContext,
RenderContext, Task, View, ViewContext, ViewHandle, WeakViewHandle,
elements::Empty, AppContext, Element, ElementBox, Entity, ModelHandle, RenderContext, Task,
View, ViewContext, ViewHandle, WeakViewHandle,
};
use project::{Project, ProjectEntryId, ProjectPath, WorktreeId};
use smallvec::SmallVec;
@@ -812,7 +807,7 @@ pub(crate) mod test {
}
impl TestProjectItem {
pub fn new(id: u64, path: &str, cx: &mut MutableAppContext) -> ModelHandle<Self> {
pub fn new(id: u64, path: &str, cx: &mut AppContext) -> ModelHandle<Self> {
let entry_id = Some(ProjectEntryId::from_proto(id));
let project_path = Some(ProjectPath {
worktree_id: WorktreeId::from_usize(0),
@@ -824,7 +819,7 @@ pub(crate) mod test {
})
}
pub fn new_untitled(cx: &mut MutableAppContext) -> ModelHandle<Self> {
pub fn new_untitled(cx: &mut AppContext) -> ModelHandle<Self> {
cx.add_model(|_| Self {
project_path: None,
entry_id: None,
+4 -4
View File
@@ -1,11 +1,11 @@
use std::{any::TypeId, ops::DerefMut};
use collections::HashSet;
use gpui::{AnyViewHandle, Entity, MutableAppContext, View, ViewContext, ViewHandle};
use gpui::{AnyViewHandle, Entity, AppContext, View, ViewContext, ViewHandle};
use crate::Workspace;
pub fn init(cx: &mut MutableAppContext) {
pub fn init(cx: &mut AppContext) {
cx.set_global(NotificationTracker::new());
simple_message_notification::init(cx);
}
@@ -138,7 +138,7 @@ pub mod simple_message_notification {
use gpui::{
actions,
elements::{Flex, MouseEventHandler, Padding, ParentElement, Svg, Text},
impl_actions, Action, CursorStyle, Element, Entity, MouseButton, MutableAppContext, View,
impl_actions, Action, CursorStyle, Element, Entity, MouseButton, AppContext, View,
ViewContext,
};
use menu::Cancel;
@@ -162,7 +162,7 @@ pub mod simple_message_notification {
impl_actions!(message_notifications, [OsOpen]);
pub fn init(cx: &mut MutableAppContext) {
pub fn init(cx: &mut AppContext) {
cx.add_action(MessageNotification::dismiss);
cx.add_action(
|_workspace: &mut Workspace, open_action: &OsOpen, cx: &mut ViewContext<Workspace>| {
+10 -10
View File
@@ -24,8 +24,8 @@ use gpui::{
keymap_matcher::KeymapContext,
platform::{CursorStyle, NavigationDirection},
Action, AnyViewHandle, AnyWeakViewHandle, AppContext, AsyncAppContext, Entity, EventContext,
ModelHandle, MouseButton, MouseRegion, MutableAppContext, PromptLevel, Quad, RenderContext,
Task, View, ViewContext, ViewHandle, WeakViewHandle,
ModelHandle, MouseButton, MouseRegion, PromptLevel, Quad, RenderContext, Task, View,
ViewContext, ViewHandle, WeakViewHandle,
};
use project::{Project, ProjectEntryId, ProjectPath};
use serde::Deserialize;
@@ -108,7 +108,7 @@ const MAX_NAVIGATION_HISTORY_LEN: usize = 1024;
pub type BackgroundActions = fn() -> &'static [(&'static str, &'static dyn Action)];
pub fn init(cx: &mut MutableAppContext) {
pub fn init(cx: &mut AppContext) {
cx.add_action(|pane: &mut Pane, action: &ActivateItem, cx| {
pane.activate_item(action.0, true, true, cx);
});
@@ -1094,7 +1094,7 @@ impl Pane {
pub fn autosave_item(
item: &dyn ItemHandle,
project: ModelHandle<Project>,
cx: &mut MutableAppContext,
cx: &mut AppContext,
) -> Task<Result<()>> {
if Self::can_autosave_item(item, cx) {
item.save(project, cx)
@@ -1740,15 +1740,15 @@ fn render_tab_bar_button<A: Action + Clone>(
}
impl ItemNavHistory {
pub fn push<D: 'static + Any>(&self, data: Option<D>, cx: &mut MutableAppContext) {
pub fn push<D: 'static + Any>(&self, data: Option<D>, cx: &mut AppContext) {
self.history.borrow_mut().push(data, self.item.clone(), cx);
}
pub fn pop_backward(&self, cx: &mut MutableAppContext) -> Option<NavigationEntry> {
pub fn pop_backward(&self, cx: &mut AppContext) -> Option<NavigationEntry> {
self.history.borrow_mut().pop(NavigationMode::GoingBack, cx)
}
pub fn pop_forward(&self, cx: &mut MutableAppContext) -> Option<NavigationEntry> {
pub fn pop_forward(&self, cx: &mut AppContext) -> Option<NavigationEntry> {
self.history
.borrow_mut()
.pop(NavigationMode::GoingForward, cx)
@@ -1768,7 +1768,7 @@ impl NavHistory {
self.mode = NavigationMode::Normal;
}
fn pop(&mut self, mode: NavigationMode, cx: &mut MutableAppContext) -> Option<NavigationEntry> {
fn pop(&mut self, mode: NavigationMode, cx: &mut AppContext) -> Option<NavigationEntry> {
let entry = match mode {
NavigationMode::Normal | NavigationMode::Disabled | NavigationMode::ClosingItem => {
return None
@@ -1788,7 +1788,7 @@ impl NavHistory {
&mut self,
data: Option<D>,
item: Rc<dyn WeakItemHandle>,
cx: &mut MutableAppContext,
cx: &mut AppContext,
) {
match self.mode {
NavigationMode::Disabled => {}
@@ -1833,7 +1833,7 @@ impl NavHistory {
self.did_update(cx);
}
fn did_update(&self, cx: &mut MutableAppContext) {
fn did_update(&self, cx: &mut AppContext) {
if let Some(pane) = self.pane.upgrade(cx) {
cx.defer(move |cx| pane.update(cx, |pane, cx| pane.history_updated(cx)));
}
+20 -25
View File
@@ -1,8 +1,8 @@
use std::any::Any;
use gpui::{
AnyViewHandle, AnyWeakViewHandle, AppContext, MutableAppContext, Subscription, Task,
ViewContext, ViewHandle, WeakViewHandle,
AnyViewHandle, AnyWeakViewHandle, AppContext, Subscription, Task, ViewContext, ViewHandle,
WeakViewHandle,
};
use project::search::SearchQuery;
@@ -90,34 +90,29 @@ pub trait SearchableItemHandle: ItemHandle {
fn supported_options(&self) -> SearchOptions;
fn subscribe_to_search_events(
&self,
cx: &mut MutableAppContext,
handler: Box<dyn Fn(SearchEvent, &mut MutableAppContext)>,
cx: &mut AppContext,
handler: Box<dyn Fn(SearchEvent, &mut AppContext)>,
) -> Subscription;
fn clear_matches(&self, cx: &mut MutableAppContext);
fn update_matches(&self, matches: &Vec<Box<dyn Any + Send>>, cx: &mut MutableAppContext);
fn query_suggestion(&self, cx: &mut MutableAppContext) -> String;
fn activate_match(
&self,
index: usize,
matches: &Vec<Box<dyn Any + Send>>,
cx: &mut MutableAppContext,
);
fn clear_matches(&self, cx: &mut AppContext);
fn update_matches(&self, matches: &Vec<Box<dyn Any + Send>>, cx: &mut AppContext);
fn query_suggestion(&self, cx: &mut AppContext) -> String;
fn activate_match(&self, index: usize, matches: &Vec<Box<dyn Any + Send>>, cx: &mut AppContext);
fn match_index_for_direction(
&self,
matches: &Vec<Box<dyn Any + Send>>,
current_index: usize,
direction: Direction,
cx: &mut MutableAppContext,
cx: &mut AppContext,
) -> usize;
fn find_matches(
&self,
query: SearchQuery,
cx: &mut MutableAppContext,
cx: &mut AppContext,
) -> Task<Vec<Box<dyn Any + Send>>>;
fn active_match_index(
&self,
matches: &Vec<Box<dyn Any + Send>>,
cx: &mut MutableAppContext,
cx: &mut AppContext,
) -> Option<usize>;
}
@@ -136,8 +131,8 @@ impl<T: SearchableItem> SearchableItemHandle for ViewHandle<T> {
fn subscribe_to_search_events(
&self,
cx: &mut MutableAppContext,
handler: Box<dyn Fn(SearchEvent, &mut MutableAppContext)>,
cx: &mut AppContext,
handler: Box<dyn Fn(SearchEvent, &mut AppContext)>,
) -> Subscription {
cx.subscribe(self, move |_, event, cx| {
if let Some(search_event) = T::to_search_event(event) {
@@ -146,21 +141,21 @@ impl<T: SearchableItem> SearchableItemHandle for ViewHandle<T> {
})
}
fn clear_matches(&self, cx: &mut MutableAppContext) {
fn clear_matches(&self, cx: &mut AppContext) {
self.update(cx, |this, cx| this.clear_matches(cx));
}
fn update_matches(&self, matches: &Vec<Box<dyn Any + Send>>, cx: &mut MutableAppContext) {
fn update_matches(&self, matches: &Vec<Box<dyn Any + Send>>, cx: &mut AppContext) {
let matches = downcast_matches(matches);
self.update(cx, |this, cx| this.update_matches(matches, cx));
}
fn query_suggestion(&self, cx: &mut MutableAppContext) -> String {
fn query_suggestion(&self, cx: &mut AppContext) -> String {
self.update(cx, |this, cx| this.query_suggestion(cx))
}
fn activate_match(
&self,
index: usize,
matches: &Vec<Box<dyn Any + Send>>,
cx: &mut MutableAppContext,
cx: &mut AppContext,
) {
let matches = downcast_matches(matches);
self.update(cx, |this, cx| this.activate_match(index, matches, cx));
@@ -170,7 +165,7 @@ impl<T: SearchableItem> SearchableItemHandle for ViewHandle<T> {
matches: &Vec<Box<dyn Any + Send>>,
current_index: usize,
direction: Direction,
cx: &mut MutableAppContext,
cx: &mut AppContext,
) -> usize {
let matches = downcast_matches(matches);
self.update(cx, |this, cx| {
@@ -180,7 +175,7 @@ impl<T: SearchableItem> SearchableItemHandle for ViewHandle<T> {
fn find_matches(
&self,
query: SearchQuery,
cx: &mut MutableAppContext,
cx: &mut AppContext,
) -> Task<Vec<Box<dyn Any + Send>>> {
let matches = self.update(cx, |this, cx| this.find_matches(query, cx));
cx.foreground().spawn(async {
@@ -194,7 +189,7 @@ impl<T: SearchableItem> SearchableItemHandle for ViewHandle<T> {
fn active_match_index(
&self,
matches: &Vec<Box<dyn Any + Send>>,
cx: &mut MutableAppContext,
cx: &mut AppContext,
) -> Option<usize> {
let matches = downcast_matches(matches);
self.update(cx, |this, cx| this.active_match_index(matches, cx))
+4 -13
View File
@@ -8,9 +8,8 @@ use gpui::{
vector::{vec2f, Vector2F},
},
json::{json, ToJson},
AnyViewHandle, DebugContext, ElementBox, Entity, LayoutContext, MeasurementContext,
MutableAppContext, PaintContext, RenderContext, SizeConstraint, Subscription, View,
ViewContext, ViewHandle,
AnyViewHandle, AppContext, DebugContext, ElementBox, Entity, LayoutContext, MeasurementContext,
PaintContext, RenderContext, SizeConstraint, Subscription, View, ViewContext, ViewHandle,
};
use settings::Settings;
@@ -24,11 +23,7 @@ pub trait StatusItemView: View {
trait StatusItemViewHandle {
fn as_any(&self) -> &AnyViewHandle;
fn set_active_pane_item(
&self,
active_pane_item: Option<&dyn ItemHandle>,
cx: &mut MutableAppContext,
);
fn set_active_pane_item(&self, active_pane_item: Option<&dyn ItemHandle>, cx: &mut AppContext);
}
pub struct StatusBar {
@@ -130,11 +125,7 @@ impl<T: StatusItemView> StatusItemViewHandle for ViewHandle<T> {
self
}
fn set_active_pane_item(
&self,
active_pane_item: Option<&dyn ItemHandle>,
cx: &mut MutableAppContext,
) {
fn set_active_pane_item(&self, active_pane_item: Option<&dyn ItemHandle>, cx: &mut AppContext) {
self.update(cx, |this, cx| {
this.set_active_pane_item(active_pane_item, cx)
});
+7 -7
View File
@@ -1,7 +1,7 @@
use crate::{ItemHandle, Pane};
use gpui::{
elements::*, platform::CursorStyle, Action, AnyViewHandle, AppContext, ElementBox, Entity,
MouseButton, MutableAppContext, RenderContext, View, ViewContext, ViewHandle, WeakViewHandle,
MouseButton, RenderContext, View, ViewContext, ViewHandle, WeakViewHandle,
};
use settings::Settings;
@@ -21,7 +21,7 @@ pub trait ToolbarItemView: View {
current_location
}
fn pane_focus_update(&mut self, _pane_focused: bool, _cx: &mut MutableAppContext) {}
fn pane_focus_update(&mut self, _pane_focused: bool, _cx: &mut AppContext) {}
}
trait ToolbarItemViewHandle {
@@ -30,9 +30,9 @@ trait ToolbarItemViewHandle {
fn set_active_pane_item(
&self,
active_pane_item: Option<&dyn ItemHandle>,
cx: &mut MutableAppContext,
cx: &mut AppContext,
) -> ToolbarItemLocation;
fn pane_focus_update(&mut self, pane_focused: bool, cx: &mut MutableAppContext);
fn pane_focus_update(&mut self, pane_focused: bool, cx: &mut AppContext);
}
#[derive(Copy, Clone, Debug, PartialEq)]
@@ -263,7 +263,7 @@ impl Toolbar {
}
}
pub fn pane_focus_update(&mut self, pane_focused: bool, cx: &mut MutableAppContext) {
pub fn pane_focus_update(&mut self, pane_focused: bool, cx: &mut AppContext) {
for (toolbar_item, _) in self.items.iter_mut() {
toolbar_item.pane_focus_update(pane_focused, cx);
}
@@ -292,14 +292,14 @@ impl<T: ToolbarItemView> ToolbarItemViewHandle for ViewHandle<T> {
fn set_active_pane_item(
&self,
active_pane_item: Option<&dyn ItemHandle>,
cx: &mut MutableAppContext,
cx: &mut AppContext,
) -> ToolbarItemLocation {
self.update(cx, |this, cx| {
this.set_active_pane_item(active_pane_item, cx)
})
}
fn pane_focus_update(&mut self, pane_focused: bool, cx: &mut MutableAppContext) {
fn pane_focus_update(&mut self, pane_focused: bool, cx: &mut AppContext) {
self.update(cx, |this, cx| this.pane_focus_update(pane_focused, cx));
}
}
+24 -24
View File
@@ -42,9 +42,9 @@ use gpui::{
keymap_matcher::KeymapContext,
platform::{CursorStyle, WindowOptions},
Action, AnyModelHandle, AnyViewHandle, AppContext, AsyncAppContext, Entity, ModelContext,
ModelHandle, MouseButton, MutableAppContext, PathPromptOptions, Platform, PromptLevel,
RenderContext, SizeConstraint, Subscription, Task, View, ViewContext, ViewHandle,
WeakViewHandle, WindowBounds,
ModelHandle, MouseButton, PathPromptOptions, Platform, PromptLevel, RenderContext,
SizeConstraint, Subscription, Task, View, ViewContext, ViewHandle, WeakViewHandle,
WindowBounds,
};
use item::{FollowableItem, FollowableItemHandle, Item, ItemHandle, ProjectItem};
use language::LanguageRegistry;
@@ -245,12 +245,12 @@ impl_internal_actions!(
);
impl_actions!(workspace, [ActivatePane]);
pub fn init(app_state: Arc<AppState>, cx: &mut MutableAppContext) {
pub fn init(app_state: Arc<AppState>, cx: &mut AppContext) {
pane::init(cx);
dock::init(cx);
notifications::init(cx);
cx.add_global_action(|_: &Open, cx: &mut MutableAppContext| {
cx.add_global_action(|_: &Open, cx: &mut AppContext| {
let mut paths = cx.prompt_for_paths(PathPromptOptions {
files: true,
directories: true,
@@ -283,7 +283,7 @@ pub fn init(app_state: Arc<AppState>, cx: &mut MutableAppContext) {
});
cx.add_global_action({
let app_state = Arc::downgrade(&app_state);
move |action: &OpenPaths, cx: &mut MutableAppContext| {
move |action: &OpenPaths, cx: &mut AppContext| {
if let Some(app_state) = app_state.upgrade() {
open_paths(&action.paths, &app_state, None, cx).detach();
}
@@ -315,7 +315,7 @@ pub fn init(app_state: Arc<AppState>, cx: &mut MutableAppContext) {
cx.add_global_action({
let app_state = Arc::downgrade(&app_state);
move |_: &NewWindow, cx: &mut MutableAppContext| {
move |_: &NewWindow, cx: &mut AppContext| {
if let Some(app_state) = app_state.upgrade() {
open_new(&app_state, cx, |_, cx| cx.dispatch_action(NewFile)).detach();
}
@@ -323,7 +323,7 @@ pub fn init(app_state: Arc<AppState>, cx: &mut MutableAppContext) {
});
cx.add_global_action({
let app_state = Arc::downgrade(&app_state);
move |_: &NewFile, cx: &mut MutableAppContext| {
move |_: &NewFile, cx: &mut AppContext| {
if let Some(app_state) = app_state.upgrade() {
open_new(&app_state, cx, |_, cx| cx.dispatch_action(NewFile)).detach();
}
@@ -444,7 +444,7 @@ type ProjectItemBuilders = HashMap<
TypeId,
fn(ModelHandle<Project>, AnyModelHandle, &mut ViewContext<Pane>) -> Box<dyn ItemHandle>,
>;
pub fn register_project_item<I: ProjectItem>(cx: &mut MutableAppContext) {
pub fn register_project_item<I: ProjectItem>(cx: &mut AppContext) {
cx.update_default_global(|builders: &mut ProjectItemBuilders, _| {
builders.insert(TypeId::of::<I::Item>(), |project, model, cx| {
let item = model.downcast::<I::Item>().unwrap();
@@ -458,7 +458,7 @@ type FollowableItemBuilder = fn(
ModelHandle<Project>,
ViewId,
&mut Option<proto::view::Variant>,
&mut MutableAppContext,
&mut AppContext,
) -> Option<Task<Result<Box<dyn FollowableItemHandle>>>>;
type FollowableItemBuilders = HashMap<
TypeId,
@@ -467,7 +467,7 @@ type FollowableItemBuilders = HashMap<
fn(&AnyViewHandle) -> Box<dyn FollowableItemHandle>,
),
>;
pub fn register_followable_item<I: FollowableItem>(cx: &mut MutableAppContext) {
pub fn register_followable_item<I: FollowableItem>(cx: &mut AppContext) {
cx.update_default_global(|builders: &mut FollowableItemBuilders, _| {
builders.insert(
TypeId::of::<I>(),
@@ -494,7 +494,7 @@ type ItemDeserializers = HashMap<
&mut ViewContext<Pane>,
) -> Task<Result<Box<dyn ItemHandle>>>,
>;
pub fn register_deserializable_item<I: Item>(cx: &mut MutableAppContext) {
pub fn register_deserializable_item<I: Item>(cx: &mut AppContext) {
cx.update_default_global(|deserializers: &mut ItemDeserializers, _cx| {
if let Some(serialized_item_kind) = I::serialized_item_kind() {
deserializers.insert(
@@ -524,7 +524,7 @@ pub struct AppState {
impl AppState {
#[cfg(any(test, feature = "test-support"))]
pub fn test(cx: &mut MutableAppContext) -> Arc<Self> {
pub fn test(cx: &mut AppContext) -> Arc<Self> {
let settings = Settings::test(cx);
cx.set_global(settings);
@@ -857,7 +857,7 @@ impl Workspace {
abs_paths: Vec<PathBuf>,
app_state: Arc<AppState>,
requesting_window_id: Option<usize>,
cx: &mut MutableAppContext,
cx: &mut AppContext,
) -> Task<(
ViewHandle<Workspace>,
Vec<Option<Result<Box<dyn ItemHandle>, anyhow::Error>>>,
@@ -1097,7 +1097,7 @@ impl Workspace {
}
}
pub fn close_global(_: &CloseWindow, cx: &mut MutableAppContext) {
pub fn close_global(_: &CloseWindow, cx: &mut AppContext) {
let id = cx.window_ids().find(|&id| cx.window_is_active(id));
if let Some(id) = id {
//This can only get called when the window's project connection has been lost
@@ -1132,7 +1132,7 @@ impl Workspace {
let window_id = cx.window_id();
let workspace_count = cx
.window_ids()
.flat_map(|window_id| cx.root_view::<Workspace>(window_id))
.filter_map(|window_id| cx.root_view(window_id)?.clone().downcast::<Workspace>())
.count();
cx.spawn(|this, mut cx| async move {
@@ -1313,7 +1313,7 @@ impl Workspace {
project: ModelHandle<Project>,
abs_path: &Path,
visible: bool,
cx: &mut MutableAppContext,
cx: &mut AppContext,
) -> Task<Result<(ModelHandle<Worktree>, ProjectPath)>> {
let entry = project.update(cx, |project, cx| {
project.find_or_create_local_worktree(abs_path, visible, cx)
@@ -1405,7 +1405,7 @@ impl Workspace {
let project = self.project.clone();
if let Some(item) = self.active_item(cx) {
if !force_name_change && item.can_save(cx) {
if item.has_conflict(cx.as_ref()) {
if item.has_conflict(cx) {
const CONFLICT_MESSAGE: &str = "This file has changed on disk since you started editing it. Do you want to overwrite it?";
let mut answer = cx.prompt(
@@ -2669,7 +2669,7 @@ impl Workspace {
fn load_from_serialized_workspace(
workspace: WeakViewHandle<Workspace>,
serialized_workspace: SerializedWorkspace,
cx: &mut MutableAppContext,
cx: &mut AppContext,
) {
cx.spawn(|mut cx| async move {
if let Some(workspace) = workspace.upgrade(&cx) {
@@ -2990,15 +2990,15 @@ impl std::fmt::Debug for OpenPaths {
pub struct WorkspaceCreated(WeakViewHandle<Workspace>);
pub fn activate_workspace_for_project(
cx: &mut MutableAppContext,
cx: &mut AppContext,
predicate: impl Fn(&mut Project, &mut ModelContext<Project>) -> bool,
) -> Option<ViewHandle<Workspace>> {
for window_id in cx.window_ids().collect::<Vec<_>>() {
if let Some(workspace_handle) = cx.root_view::<Workspace>(window_id) {
if let Some(workspace_handle) = cx.root_view(window_id)?.downcast_ref::<Workspace>() {
let project = workspace_handle.read(cx).project.clone();
if project.update(cx, &predicate) {
cx.activate_window(window_id);
return Some(workspace_handle);
return Some(workspace_handle.clone());
}
}
}
@@ -3014,7 +3014,7 @@ pub fn open_paths(
abs_paths: &[PathBuf],
app_state: &Arc<AppState>,
requesting_window_id: Option<usize>,
cx: &mut MutableAppContext,
cx: &mut AppContext,
) -> Task<(
ViewHandle<Workspace>,
Vec<Option<Result<Box<dyn ItemHandle>, anyhow::Error>>>,
@@ -3066,7 +3066,7 @@ pub fn open_paths(
pub fn open_new(
app_state: &Arc<AppState>,
cx: &mut MutableAppContext,
cx: &mut AppContext,
init: impl FnOnce(&mut Workspace, &mut ViewContext<Workspace>) + 'static,
) -> Task<()> {
let task = Workspace::new_local(Vec::new(), app_state.clone(), None, cx);