mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-10 20:41:59 +00:00
Rename app_state
to global
in gpui
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
parent
84bacc556f
commit
44d997c00c
24 changed files with 91 additions and 89 deletions
|
@ -64,13 +64,13 @@ impl ChatPanel {
|
|||
ix,
|
||||
item_type,
|
||||
is_hovered,
|
||||
&cx.app_state::<Settings>().theme.chat_panel.channel_select,
|
||||
&cx.global::<Settings>().theme.chat_panel.channel_select,
|
||||
cx,
|
||||
)
|
||||
}
|
||||
})
|
||||
.with_style(move |cx| {
|
||||
let theme = &cx.app_state::<Settings>().theme.chat_panel.channel_select;
|
||||
let theme = &cx.global::<Settings>().theme.chat_panel.channel_select;
|
||||
SelectStyle {
|
||||
header: theme.header.container.clone(),
|
||||
menu: theme.menu.clone(),
|
||||
|
@ -200,7 +200,7 @@ impl ChatPanel {
|
|||
}
|
||||
|
||||
fn render_channel(&self, cx: &mut RenderContext<Self>) -> ElementBox {
|
||||
let theme = &cx.app_state::<Settings>().theme;
|
||||
let theme = &cx.global::<Settings>().theme;
|
||||
Flex::column()
|
||||
.with_child(
|
||||
Container::new(ChildView::new(&self.channel_select).boxed())
|
||||
|
@ -224,7 +224,7 @@ impl ChatPanel {
|
|||
|
||||
fn render_message(&self, message: &ChannelMessage, cx: &AppContext) -> ElementBox {
|
||||
let now = OffsetDateTime::now_utc();
|
||||
let settings = cx.app_state::<Settings>();
|
||||
let settings = cx.global::<Settings>();
|
||||
let theme = if message.is_pending() {
|
||||
&settings.theme.chat_panel.pending_message
|
||||
} else {
|
||||
|
@ -267,7 +267,7 @@ impl ChatPanel {
|
|||
}
|
||||
|
||||
fn render_input_box(&self, cx: &AppContext) -> ElementBox {
|
||||
let theme = &cx.app_state::<Settings>().theme;
|
||||
let theme = &cx.global::<Settings>().theme;
|
||||
Container::new(ChildView::new(&self.input_editor).boxed())
|
||||
.with_style(theme.chat_panel.input_editor.container)
|
||||
.boxed()
|
||||
|
@ -304,7 +304,7 @@ impl ChatPanel {
|
|||
}
|
||||
|
||||
fn render_sign_in_prompt(&self, cx: &mut RenderContext<Self>) -> ElementBox {
|
||||
let theme = cx.app_state::<Settings>().theme.clone();
|
||||
let theme = cx.global::<Settings>().theme.clone();
|
||||
let rpc = self.rpc.clone();
|
||||
let this = cx.handle();
|
||||
|
||||
|
@ -385,7 +385,7 @@ impl View for ChatPanel {
|
|||
} else {
|
||||
self.render_sign_in_prompt(cx)
|
||||
};
|
||||
let theme = &cx.app_state::<Settings>().theme;
|
||||
let theme = &cx.global::<Settings>().theme;
|
||||
ConstrainedBox::new(
|
||||
Container::new(element)
|
||||
.with_style(theme.chat_panel.container)
|
||||
|
|
|
@ -55,7 +55,7 @@ impl ContactsPanel {
|
|||
app_state: Arc<AppState>,
|
||||
cx: &mut LayoutContext,
|
||||
) -> ElementBox {
|
||||
let theme = cx.app_state::<Settings>().theme.clone();
|
||||
let theme = cx.global::<Settings>().theme.clone();
|
||||
let theme = &theme.contacts_panel;
|
||||
let project_count = collaborator.projects.len();
|
||||
let font_cache = cx.font_cache();
|
||||
|
@ -236,7 +236,7 @@ impl View for ContactsPanel {
|
|||
}
|
||||
|
||||
fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
|
||||
let theme = &cx.app_state::<Settings>().theme.contacts_panel;
|
||||
let theme = &cx.global::<Settings>().theme.contacts_panel;
|
||||
Container::new(List::new(self.contacts.clone()).boxed())
|
||||
.with_style(theme.container)
|
||||
.boxed()
|
||||
|
|
|
@ -72,7 +72,7 @@ impl View for ProjectDiagnosticsEditor {
|
|||
|
||||
fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
|
||||
if self.path_states.is_empty() {
|
||||
let theme = &cx.app_state::<Settings>().theme.project_diagnostics;
|
||||
let theme = &cx.global::<Settings>().theme.project_diagnostics;
|
||||
Label::new(
|
||||
"No problems in workspace".to_string(),
|
||||
theme.empty_message.clone(),
|
||||
|
@ -441,7 +441,7 @@ impl workspace::Item for ProjectDiagnosticsEditor {
|
|||
render_summary(
|
||||
&self.summary,
|
||||
&style.label.text,
|
||||
&cx.app_state::<Settings>().theme.project_diagnostics,
|
||||
&cx.global::<Settings>().theme.project_diagnostics,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -535,7 +535,7 @@ impl workspace::Item for ProjectDiagnosticsEditor {
|
|||
fn diagnostic_header_renderer(diagnostic: Diagnostic) -> RenderBlock {
|
||||
let (message, highlights) = highlight_diagnostic_message(&diagnostic.message);
|
||||
Arc::new(move |cx| {
|
||||
let settings = cx.app_state::<Settings>();
|
||||
let settings = cx.global::<Settings>();
|
||||
let theme = &settings.theme.editor;
|
||||
let style = &theme.diagnostic_header;
|
||||
let font_size = (style.text_scale_factor * settings.buffer_font_size).round();
|
||||
|
|
|
@ -49,7 +49,7 @@ impl View for DiagnosticSummary {
|
|||
|
||||
let in_progress = self.in_progress;
|
||||
MouseEventHandler::new::<Tag, _, _>(0, cx, |_, cx| {
|
||||
let theme = &cx.app_state::<Settings>().theme.project_diagnostics;
|
||||
let theme = &cx.global::<Settings>().theme.project_diagnostics;
|
||||
if in_progress {
|
||||
Label::new(
|
||||
"Checking... ".to_string(),
|
||||
|
|
|
@ -883,7 +883,7 @@ impl Editor {
|
|||
cx: &mut ViewContext<Self>,
|
||||
) -> Self {
|
||||
let display_map = cx.add_model(|cx| {
|
||||
let settings = cx.app_state::<Settings>();
|
||||
let settings = cx.global::<Settings>();
|
||||
let style = build_style(&*settings, get_field_editor_theme, None, cx);
|
||||
DisplayMap::new(
|
||||
buffer.clone(),
|
||||
|
@ -1011,7 +1011,7 @@ impl Editor {
|
|||
|
||||
fn style(&self, cx: &AppContext) -> EditorStyle {
|
||||
build_style(
|
||||
cx.app_state::<Settings>(),
|
||||
cx.global::<Settings>(),
|
||||
self.get_field_editor_theme,
|
||||
self.override_text_style.as_deref(),
|
||||
cx,
|
||||
|
@ -2729,7 +2729,7 @@ impl Editor {
|
|||
}
|
||||
|
||||
self.start_transaction(cx);
|
||||
let tab_size = cx.app_state::<Settings>().tab_size;
|
||||
let tab_size = cx.global::<Settings>().tab_size;
|
||||
let mut selections = self.local_selections::<Point>(cx);
|
||||
let mut last_indent = None;
|
||||
self.buffer.update(cx, |buffer, cx| {
|
||||
|
@ -2806,7 +2806,7 @@ impl Editor {
|
|||
}
|
||||
|
||||
self.start_transaction(cx);
|
||||
let tab_size = cx.app_state::<Settings>().tab_size;
|
||||
let tab_size = cx.global::<Settings>().tab_size;
|
||||
let selections = self.local_selections::<Point>(cx);
|
||||
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
|
||||
let mut deletion_ranges = Vec::new();
|
||||
|
@ -5324,7 +5324,7 @@ impl Editor {
|
|||
|
||||
pub fn soft_wrap_mode(&self, cx: &AppContext) -> SoftWrap {
|
||||
let language = self.language(cx);
|
||||
let settings = cx.app_state::<Settings>();
|
||||
let settings = cx.global::<Settings>();
|
||||
let mode = self
|
||||
.soft_wrap_mode_override
|
||||
.unwrap_or_else(|| settings.soft_wrap(language));
|
||||
|
@ -5906,7 +5906,7 @@ pub fn diagnostic_block_renderer(diagnostic: Diagnostic, is_valid: bool) -> Rend
|
|||
}
|
||||
|
||||
Arc::new(move |cx: &BlockContext| {
|
||||
let settings = cx.app_state::<Settings>();
|
||||
let settings = cx.global::<Settings>();
|
||||
let theme = &settings.theme.editor;
|
||||
let style = diagnostic_style(diagnostic.severity, is_valid, theme);
|
||||
let font_size = (style.text_scale_factor * settings.buffer_font_size).round();
|
||||
|
@ -9108,7 +9108,7 @@ mod tests {
|
|||
|
||||
fn populate_settings(cx: &mut gpui::MutableAppContext) {
|
||||
let settings = Settings::test(cx);
|
||||
cx.add_app_state(settings);
|
||||
cx.set_global(settings);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1490,7 +1490,7 @@ mod tests {
|
|||
|
||||
#[gpui::test]
|
||||
fn test_layout_line_numbers(cx: &mut gpui::MutableAppContext) {
|
||||
cx.add_app_state(Settings::test(cx));
|
||||
cx.set_global(Settings::test(cx));
|
||||
let buffer = MultiBuffer::build_simple(&sample_text(6, 6, 'a'), cx);
|
||||
let (window_id, editor) = cx.add_window(Default::default(), |cx| {
|
||||
Editor::new(EditorMode::Full, buffer, None, None, cx)
|
||||
|
@ -1512,7 +1512,7 @@ mod tests {
|
|||
|
||||
#[gpui::test]
|
||||
fn test_layout_with_placeholder_text_and_blocks(cx: &mut gpui::MutableAppContext) {
|
||||
cx.add_app_state(Settings::test(cx));
|
||||
cx.set_global(Settings::test(cx));
|
||||
let buffer = MultiBuffer::build_simple("", cx);
|
||||
let (window_id, editor) = cx.add_window(Default::default(), |cx| {
|
||||
Editor::new(EditorMode::Full, buffer, None, None, cx)
|
||||
|
|
|
@ -179,7 +179,7 @@ impl View for CursorPosition {
|
|||
|
||||
fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
|
||||
if let Some(position) = self.position {
|
||||
let theme = &cx.app_state::<Settings>().theme.workspace.status_bar;
|
||||
let theme = &cx.global::<Settings>().theme.workspace.status_bar;
|
||||
let mut text = format!("{},{}", position.row + 1, position.column + 1);
|
||||
if self.selected_count > 0 {
|
||||
write!(text, " ({} selected)", self.selected_count).unwrap();
|
||||
|
@ -252,7 +252,7 @@ impl View for DiagnosticMessage {
|
|||
|
||||
fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
|
||||
if let Some(diagnostic) = &self.diagnostic {
|
||||
let theme = &cx.app_state::<Settings>().theme.workspace.status_bar;
|
||||
let theme = &cx.global::<Settings>().theme.workspace.status_bar;
|
||||
Label::new(
|
||||
diagnostic.message.split('\n').next().unwrap().to_string(),
|
||||
theme.diagnostic_message.clone(),
|
||||
|
|
|
@ -67,7 +67,7 @@ impl View for FileFinder {
|
|||
}
|
||||
|
||||
fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
|
||||
let settings = cx.app_state::<Settings>();
|
||||
let settings = cx.global::<Settings>();
|
||||
Align::new(
|
||||
ConstrainedBox::new(
|
||||
Container::new(
|
||||
|
@ -106,7 +106,7 @@ impl View for FileFinder {
|
|||
impl FileFinder {
|
||||
fn render_matches(&self, cx: &AppContext) -> ElementBox {
|
||||
if self.matches.is_empty() {
|
||||
let settings = cx.app_state::<Settings>();
|
||||
let settings = cx.global::<Settings>();
|
||||
return Container::new(
|
||||
Label::new(
|
||||
"No matches".into(),
|
||||
|
@ -142,7 +142,7 @@ impl FileFinder {
|
|||
|
||||
fn render_match(&self, path_match: &PathMatch, index: usize, cx: &AppContext) -> ElementBox {
|
||||
let selected_index = self.selected_index();
|
||||
let settings = cx.app_state::<Settings>();
|
||||
let settings = cx.global::<Settings>();
|
||||
let style = if index == selected_index {
|
||||
&settings.theme.selector.active_item
|
||||
} else {
|
||||
|
|
|
@ -59,7 +59,8 @@ impl GoToLine {
|
|||
}
|
||||
|
||||
fn toggle(workspace: &mut Workspace, _: &Toggle, cx: &mut ViewContext<Workspace>) {
|
||||
if let Some(editor) = workspace.active_item(cx)
|
||||
if let Some(editor) = workspace
|
||||
.active_item(cx)
|
||||
.and_then(|active_item| active_item.downcast::<Editor>())
|
||||
{
|
||||
workspace.toggle_modal(cx, |cx, _| {
|
||||
|
@ -148,7 +149,7 @@ impl View for GoToLine {
|
|||
}
|
||||
|
||||
fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
|
||||
let theme = &cx.app_state::<Settings>().theme.selector;
|
||||
let theme = &cx.global::<Settings>().theme.selector;
|
||||
|
||||
let label = format!(
|
||||
"{},{} of {} lines",
|
||||
|
|
|
@ -799,7 +799,7 @@ impl MutableAppContext {
|
|||
models: Default::default(),
|
||||
views: Default::default(),
|
||||
windows: Default::default(),
|
||||
app_states: Default::default(),
|
||||
globals: Default::default(),
|
||||
element_states: Default::default(),
|
||||
ref_counts: Arc::new(Mutex::new(ref_counts)),
|
||||
background,
|
||||
|
@ -1364,24 +1364,22 @@ impl MutableAppContext {
|
|||
Ok(pending)
|
||||
}
|
||||
|
||||
pub fn add_app_state<T: 'static>(&mut self, state: T) {
|
||||
self.cx
|
||||
.app_states
|
||||
.insert(TypeId::of::<T>(), Box::new(state));
|
||||
pub fn set_global<T: 'static>(&mut self, state: T) {
|
||||
self.cx.globals.insert(TypeId::of::<T>(), Box::new(state));
|
||||
}
|
||||
|
||||
pub fn update_app_state<T: 'static, F, U>(&mut self, update: F) -> U
|
||||
pub fn update_global<T: 'static, F, U>(&mut self, update: F) -> U
|
||||
where
|
||||
F: FnOnce(&mut T, &mut MutableAppContext) -> U,
|
||||
{
|
||||
let type_id = TypeId::of::<T>();
|
||||
let mut state = self
|
||||
.cx
|
||||
.app_states
|
||||
.globals
|
||||
.remove(&type_id)
|
||||
.expect("no app state has been added for this type");
|
||||
let result = update(state.downcast_mut().unwrap(), self);
|
||||
self.cx.app_states.insert(type_id, state);
|
||||
self.cx.globals.insert(type_id, state);
|
||||
result
|
||||
}
|
||||
|
||||
|
@ -2054,7 +2052,7 @@ pub struct AppContext {
|
|||
models: HashMap<usize, Box<dyn AnyModel>>,
|
||||
views: HashMap<(usize, usize), Box<dyn AnyView>>,
|
||||
windows: HashMap<usize, Window>,
|
||||
app_states: HashMap<TypeId, Box<dyn Any>>,
|
||||
globals: HashMap<TypeId, Box<dyn Any>>,
|
||||
element_states: HashMap<ElementStateId, Box<dyn Any>>,
|
||||
background: Arc<executor::Background>,
|
||||
ref_counts: Arc<Mutex<RefCounts>>,
|
||||
|
@ -2087,8 +2085,8 @@ impl AppContext {
|
|||
&self.platform
|
||||
}
|
||||
|
||||
pub fn app_state<T: 'static>(&self) -> &T {
|
||||
self.app_states
|
||||
pub fn global<T: 'static>(&self) -> &T {
|
||||
self.globals
|
||||
.get(&TypeId::of::<T>())
|
||||
.expect("no app state has been added for this type")
|
||||
.downcast_ref()
|
||||
|
|
|
@ -69,7 +69,7 @@ impl View for OutlineView {
|
|||
}
|
||||
|
||||
fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
|
||||
let settings = cx.app_state::<Settings>();
|
||||
let settings = cx.global::<Settings>();
|
||||
|
||||
Flex::new(Axis::Vertical)
|
||||
.with_child(
|
||||
|
@ -124,9 +124,12 @@ impl OutlineView {
|
|||
.active_item(cx)
|
||||
.and_then(|item| item.downcast::<Editor>())
|
||||
{
|
||||
let buffer = editor.read(cx).buffer().read(cx).read(cx).outline(Some(
|
||||
cx.app_state::<Settings>().theme.editor.syntax.as_ref(),
|
||||
));
|
||||
let buffer = editor
|
||||
.read(cx)
|
||||
.buffer()
|
||||
.read(cx)
|
||||
.read(cx)
|
||||
.outline(Some(cx.global::<Settings>().theme.editor.syntax.as_ref()));
|
||||
if let Some(outline) = buffer {
|
||||
workspace.toggle_modal(cx, |cx, _| {
|
||||
let view = cx.add_view(|cx| OutlineView::new(outline, editor, cx));
|
||||
|
@ -288,7 +291,7 @@ impl OutlineView {
|
|||
|
||||
fn render_matches(&self, cx: &AppContext) -> ElementBox {
|
||||
if self.matches.is_empty() {
|
||||
let settings = cx.app_state::<Settings>();
|
||||
let settings = cx.global::<Settings>();
|
||||
return Container::new(
|
||||
Label::new(
|
||||
"No matches".into(),
|
||||
|
@ -330,7 +333,7 @@ impl OutlineView {
|
|||
index: usize,
|
||||
cx: &AppContext,
|
||||
) -> ElementBox {
|
||||
let settings = cx.app_state::<Settings>();
|
||||
let settings = cx.global::<Settings>();
|
||||
let style = if index == self.selected_match_index {
|
||||
&settings.theme.selector.active_item
|
||||
} else {
|
||||
|
|
|
@ -517,7 +517,7 @@ impl View for ProjectPanel {
|
|||
}
|
||||
|
||||
fn render(&mut self, cx: &mut gpui::RenderContext<'_, Self>) -> gpui::ElementBox {
|
||||
let theme = &cx.app_state::<Settings>().theme.project_panel;
|
||||
let theme = &cx.global::<Settings>().theme.project_panel;
|
||||
let mut container_style = theme.container;
|
||||
let padding = std::mem::take(&mut container_style.padding);
|
||||
let handle = self.handle.clone();
|
||||
|
@ -528,7 +528,7 @@ impl View for ProjectPanel {
|
|||
.map(|(_, worktree_entries)| worktree_entries.len())
|
||||
.sum(),
|
||||
move |range, items, cx| {
|
||||
let theme = cx.app_state::<Settings>().theme.clone();
|
||||
let theme = cx.global::<Settings>().theme.clone();
|
||||
let this = handle.upgrade(cx).unwrap();
|
||||
this.update(cx.app, |this, cx| {
|
||||
this.for_each_visible_entry(range.clone(), cx, |entry, details, cx| {
|
||||
|
|
|
@ -69,7 +69,7 @@ impl View for ProjectSymbolsView {
|
|||
}
|
||||
|
||||
fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
|
||||
let settings = cx.app_state::<Settings>();
|
||||
let settings = cx.global::<Settings>();
|
||||
Flex::new(Axis::Vertical)
|
||||
.with_child(
|
||||
Container::new(ChildView::new(&self.query_editor).boxed())
|
||||
|
@ -233,7 +233,7 @@ impl ProjectSymbolsView {
|
|||
|
||||
fn render_matches(&self, cx: &AppContext) -> ElementBox {
|
||||
if self.matches.is_empty() {
|
||||
let settings = cx.app_state::<Settings>();
|
||||
let settings = cx.global::<Settings>();
|
||||
return Container::new(
|
||||
Label::new(
|
||||
"No matches".into(),
|
||||
|
@ -276,7 +276,7 @@ impl ProjectSymbolsView {
|
|||
show_worktree_root_name: bool,
|
||||
cx: &AppContext,
|
||||
) -> ElementBox {
|
||||
let settings = cx.app_state::<Settings>();
|
||||
let settings = cx.global::<Settings>();
|
||||
let style = if index == self.selected_match_index {
|
||||
&settings.theme.selector.active_item
|
||||
} else {
|
||||
|
|
|
@ -66,7 +66,7 @@ impl View for SearchBar {
|
|||
}
|
||||
|
||||
fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
|
||||
let theme = cx.app_state::<Settings>().theme.clone();
|
||||
let theme = cx.global::<Settings>().theme.clone();
|
||||
let editor_container = if self.query_contains_error {
|
||||
theme.search.invalid_editor
|
||||
} else {
|
||||
|
@ -197,7 +197,7 @@ impl SearchBar {
|
|||
) -> ElementBox {
|
||||
let is_active = self.is_search_option_enabled(search_option);
|
||||
MouseEventHandler::new::<Self, _, _>(search_option as usize, cx, |state, cx| {
|
||||
let theme = &cx.app_state::<Settings>().theme.search;
|
||||
let theme = &cx.global::<Settings>().theme.search;
|
||||
let style = match (is_active, state.hovered) {
|
||||
(false, false) => &theme.option_button,
|
||||
(false, true) => &theme.hovered_option_button,
|
||||
|
@ -222,7 +222,7 @@ impl SearchBar {
|
|||
) -> ElementBox {
|
||||
enum NavButton {}
|
||||
MouseEventHandler::new::<NavButton, _, _>(direction as usize, cx, |state, cx| {
|
||||
let theme = &cx.app_state::<Settings>().theme.search;
|
||||
let theme = &cx.global::<Settings>().theme.search;
|
||||
let style = if state.hovered {
|
||||
&theme.hovered_option_button
|
||||
} else {
|
||||
|
@ -475,7 +475,7 @@ impl SearchBar {
|
|||
}
|
||||
}
|
||||
|
||||
let theme = &cx.app_state::<Settings>().theme.search;
|
||||
let theme = &cx.global::<Settings>().theme.search;
|
||||
editor.highlight_background::<Self>(
|
||||
ranges,
|
||||
theme.match_background,
|
||||
|
@ -521,7 +521,7 @@ mod tests {
|
|||
let mut theme = gpui::fonts::with_font_cache(fonts.clone(), || theme::Theme::default());
|
||||
theme.search.match_background = Color::red();
|
||||
let settings = Settings::new("Courier", &fonts, Arc::new(theme)).unwrap();
|
||||
cx.update(|cx| cx.add_app_state(settings));
|
||||
cx.update(|cx| cx.set_global(settings));
|
||||
|
||||
let buffer = cx.update(|cx| {
|
||||
MultiBuffer::build_simple(
|
||||
|
|
|
@ -29,7 +29,7 @@ const MAX_TAB_TITLE_LEN: usize = 24;
|
|||
struct ActiveSearches(HashMap<WeakModelHandle<Project>, WeakViewHandle<ProjectSearchView>>);
|
||||
|
||||
pub fn init(cx: &mut MutableAppContext) {
|
||||
cx.add_app_state(ActiveSearches::default());
|
||||
cx.set_global(ActiveSearches::default());
|
||||
cx.add_bindings([
|
||||
Binding::new("cmd-shift-F", ToggleFocus, Some("ProjectSearchView")),
|
||||
Binding::new("cmd-f", ToggleFocus, Some("ProjectSearchView")),
|
||||
|
@ -155,7 +155,7 @@ impl View for ProjectSearchView {
|
|||
fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
|
||||
let model = &self.model.read(cx);
|
||||
let results = if model.match_ranges.is_empty() {
|
||||
let theme = &cx.app_state::<Settings>().theme;
|
||||
let theme = &cx.global::<Settings>().theme;
|
||||
let text = if self.query_editor.read(cx).text(cx).is_empty() {
|
||||
""
|
||||
} else if model.pending_search.is_some() {
|
||||
|
@ -183,7 +183,7 @@ impl View for ProjectSearchView {
|
|||
|
||||
fn on_focus(&mut self, cx: &mut ViewContext<Self>) {
|
||||
let handle = cx.weak_handle();
|
||||
cx.update_app_state(|state: &mut ActiveSearches, cx| {
|
||||
cx.update_global(|state: &mut ActiveSearches, cx| {
|
||||
state
|
||||
.0
|
||||
.insert(self.model.read(cx).project.downgrade(), handle)
|
||||
|
@ -219,7 +219,7 @@ impl Item for ProjectSearchView {
|
|||
}
|
||||
|
||||
fn tab_content(&self, tab_theme: &theme::Tab, cx: &gpui::AppContext) -> ElementBox {
|
||||
let settings = cx.app_state::<Settings>();
|
||||
let settings = cx.global::<Settings>();
|
||||
let search_theme = &settings.theme.search;
|
||||
Flex::row()
|
||||
.with_child(
|
||||
|
@ -370,12 +370,12 @@ impl ProjectSearchView {
|
|||
// If no search exists in the workspace, create a new one.
|
||||
fn deploy(workspace: &mut Workspace, _: &Deploy, cx: &mut ViewContext<Workspace>) {
|
||||
// Clean up entries for dropped projects
|
||||
cx.update_app_state(|state: &mut ActiveSearches, cx| {
|
||||
cx.update_global(|state: &mut ActiveSearches, cx| {
|
||||
state.0.retain(|project, _| project.is_upgradable(cx))
|
||||
});
|
||||
|
||||
let active_search = cx
|
||||
.app_state::<ActiveSearches>()
|
||||
.global::<ActiveSearches>()
|
||||
.0
|
||||
.get(&workspace.project().downgrade());
|
||||
|
||||
|
@ -534,7 +534,7 @@ impl ProjectSearchView {
|
|||
if reset_selections {
|
||||
editor.select_ranges(match_ranges.first().cloned(), Some(Autoscroll::Fit), cx);
|
||||
}
|
||||
let theme = &cx.app_state::<Settings>().theme.search;
|
||||
let theme = &cx.global::<Settings>().theme.search;
|
||||
editor.highlight_background::<Self>(match_ranges, theme.match_background, cx);
|
||||
});
|
||||
if self.query_editor.is_focused(cx) {
|
||||
|
@ -560,7 +560,7 @@ impl ProjectSearchView {
|
|||
}
|
||||
|
||||
fn render_query_editor(&self, cx: &mut RenderContext<Self>) -> ElementBox {
|
||||
let theme = cx.app_state::<Settings>().theme.clone();
|
||||
let theme = cx.global::<Settings>().theme.clone();
|
||||
let editor_container = if self.query_contains_error {
|
||||
theme.search.invalid_editor
|
||||
} else {
|
||||
|
@ -624,7 +624,7 @@ impl ProjectSearchView {
|
|||
) -> ElementBox {
|
||||
let is_active = self.is_option_enabled(option);
|
||||
MouseEventHandler::new::<Self, _, _>(option as usize, cx, |state, cx| {
|
||||
let theme = &cx.app_state::<Settings>().theme.search;
|
||||
let theme = &cx.global::<Settings>().theme.search;
|
||||
let style = match (is_active, state.hovered) {
|
||||
(false, false) => &theme.option_button,
|
||||
(false, true) => &theme.hovered_option_button,
|
||||
|
@ -657,7 +657,7 @@ impl ProjectSearchView {
|
|||
) -> ElementBox {
|
||||
enum NavButton {}
|
||||
MouseEventHandler::new::<NavButton, _, _>(direction as usize, cx, |state, cx| {
|
||||
let theme = &cx.app_state::<Settings>().theme.search;
|
||||
let theme = &cx.global::<Settings>().theme.search;
|
||||
let style = if state.hovered {
|
||||
&theme.hovered_option_button
|
||||
} else {
|
||||
|
@ -689,7 +689,7 @@ mod tests {
|
|||
let mut theme = gpui::fonts::with_font_cache(fonts.clone(), || theme::Theme::default());
|
||||
theme.search.match_background = Color::red();
|
||||
let settings = Settings::new("Courier", &fonts, Arc::new(theme)).unwrap();
|
||||
cx.update(|cx| cx.add_app_state(settings));
|
||||
cx.update(|cx| cx.set_global(settings));
|
||||
|
||||
let fs = FakeFs::new(cx.background());
|
||||
fs.insert_tree(
|
||||
|
|
|
@ -4414,7 +4414,7 @@ mod tests {
|
|||
async fn create_client(&mut self, cx: &mut TestAppContext, name: &str) -> TestClient {
|
||||
cx.update(|cx| {
|
||||
let settings = Settings::test(cx);
|
||||
cx.add_app_state(settings);
|
||||
cx.set_global(settings);
|
||||
});
|
||||
|
||||
let http = FakeHttpClient::with_404_response();
|
||||
|
|
|
@ -54,7 +54,7 @@ impl ThemeSelector {
|
|||
cx.subscribe(&query_editor, Self::on_query_editor_event)
|
||||
.detach();
|
||||
|
||||
let original_theme = cx.app_state::<Settings>().theme.clone();
|
||||
let original_theme = cx.global::<Settings>().theme.clone();
|
||||
|
||||
let mut this = Self {
|
||||
themes: registry,
|
||||
|
@ -82,7 +82,7 @@ impl ThemeSelector {
|
|||
}
|
||||
|
||||
fn reload(_: &mut Workspace, action: &Reload, cx: &mut ViewContext<Workspace>) {
|
||||
let current_theme_name = cx.app_state::<Settings>().theme.name.clone();
|
||||
let current_theme_name = cx.global::<Settings>().theme.name.clone();
|
||||
action.0.clear();
|
||||
match action.0.get(¤t_theme_name) {
|
||||
Ok(theme) => {
|
||||
|
@ -206,7 +206,7 @@ impl ThemeSelector {
|
|||
match event {
|
||||
editor::Event::Edited => {
|
||||
self.update_matches(cx);
|
||||
self.select_if_matching(&cx.app_state::<Settings>().theme.name);
|
||||
self.select_if_matching(&cx.global::<Settings>().theme.name);
|
||||
self.show_selected_theme(cx);
|
||||
}
|
||||
editor::Event::Blurred => cx.emit(Event::Dismissed),
|
||||
|
@ -216,7 +216,7 @@ impl ThemeSelector {
|
|||
|
||||
fn render_matches(&self, cx: &mut RenderContext<Self>) -> ElementBox {
|
||||
if self.matches.is_empty() {
|
||||
let settings = cx.app_state::<Settings>();
|
||||
let settings = cx.global::<Settings>();
|
||||
return Container::new(
|
||||
Label::new(
|
||||
"No matches".into(),
|
||||
|
@ -251,7 +251,7 @@ impl ThemeSelector {
|
|||
}
|
||||
|
||||
fn render_match(&self, theme_match: &StringMatch, index: usize, cx: &AppContext) -> ElementBox {
|
||||
let settings = cx.app_state::<Settings>();
|
||||
let settings = cx.global::<Settings>();
|
||||
let theme = &settings.theme;
|
||||
|
||||
let container = Container::new(
|
||||
|
@ -276,7 +276,7 @@ impl ThemeSelector {
|
|||
}
|
||||
|
||||
fn set_theme(theme: Arc<Theme>, cx: &mut MutableAppContext) {
|
||||
cx.update_app_state::<Settings, _, _>(|settings, cx| {
|
||||
cx.update_global::<Settings, _, _>(|settings, cx| {
|
||||
settings.theme = theme;
|
||||
cx.refresh_windows();
|
||||
});
|
||||
|
@ -299,7 +299,7 @@ impl View for ThemeSelector {
|
|||
}
|
||||
|
||||
fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
|
||||
let theme = cx.app_state::<Settings>().theme.clone();
|
||||
let theme = cx.global::<Settings>().theme.clone();
|
||||
Align::new(
|
||||
ConstrainedBox::new(
|
||||
Container::new(
|
||||
|
|
|
@ -116,7 +116,7 @@ impl View for LspStatus {
|
|||
}
|
||||
|
||||
fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
|
||||
let theme = &cx.app_state::<Settings>().theme;
|
||||
let theme = &cx.global::<Settings>().theme;
|
||||
|
||||
let mut pending_work = self.pending_language_server_work(cx);
|
||||
if let Some((lang_server_name, progress_token, progress)) = pending_work.next() {
|
||||
|
@ -166,7 +166,7 @@ impl View for LspStatus {
|
|||
} else if !self.failed.is_empty() {
|
||||
drop(pending_work);
|
||||
MouseEventHandler::new::<Self, _, _>(0, cx, |_, cx| {
|
||||
let theme = &cx.app_state::<Settings>().theme;
|
||||
let theme = &cx.global::<Settings>().theme;
|
||||
Label::new(
|
||||
format!(
|
||||
"Failed to download {} language server{}. Click to dismiss.",
|
||||
|
|
|
@ -513,7 +513,7 @@ impl Pane {
|
|||
}
|
||||
|
||||
fn render_tabs(&self, cx: &mut RenderContext<Self>) -> ElementBox {
|
||||
let theme = cx.app_state::<Settings>().theme.clone();
|
||||
let theme = cx.global::<Settings>().theme.clone();
|
||||
|
||||
enum Tabs {}
|
||||
let tabs = MouseEventHandler::new::<Tabs, _, _>(0, cx, |mouse_state, cx| {
|
||||
|
|
|
@ -38,7 +38,7 @@ impl View for StatusBar {
|
|||
}
|
||||
|
||||
fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
|
||||
let theme = &cx.app_state::<Settings>().theme.workspace.status_bar;
|
||||
let theme = &cx.global::<Settings>().theme.workspace.status_bar;
|
||||
Flex::row()
|
||||
.with_children(self.left_items.iter().map(|i| {
|
||||
ChildView::new(i.as_ref())
|
||||
|
|
|
@ -109,7 +109,7 @@ where
|
|||
V: Item,
|
||||
F: 'static + Fn(ModelHandle<Project>, ModelHandle<Buffer>, &mut ViewContext<V>) -> V,
|
||||
{
|
||||
cx.add_app_state::<BuildEditor>(Arc::new(move |window_id, project, model, cx| {
|
||||
cx.set_global::<BuildEditor>(Arc::new(move |window_id, project, model, cx| {
|
||||
Box::new(cx.add_view(window_id, |cx| build_editor(project, model, cx)))
|
||||
}));
|
||||
}
|
||||
|
@ -371,7 +371,7 @@ impl WorkspaceParams {
|
|||
#[cfg(any(test, feature = "test-support"))]
|
||||
pub fn test(cx: &mut MutableAppContext) -> Self {
|
||||
let settings = Settings::test(cx);
|
||||
cx.add_app_state(settings);
|
||||
cx.set_global(settings);
|
||||
|
||||
let fs = project::FakeFs::new(cx.background().clone());
|
||||
let languages = Arc::new(LanguageRegistry::test());
|
||||
|
@ -825,7 +825,7 @@ impl Workspace {
|
|||
.ok_or_else(|| anyhow!("buffer has no entry"))
|
||||
})?;
|
||||
let (window_id, build_editor) = this.update(&mut cx, |_, cx| {
|
||||
(cx.window_id(), cx.app_state::<BuildEditor>().clone())
|
||||
(cx.window_id(), cx.global::<BuildEditor>().clone())
|
||||
});
|
||||
let build_editor =
|
||||
move |cx: &mut MutableAppContext| build_editor(window_id, project, buffer, cx);
|
||||
|
@ -948,7 +948,7 @@ impl Workspace {
|
|||
}
|
||||
|
||||
fn render_connection_status(&self, cx: &mut RenderContext<Self>) -> Option<ElementBox> {
|
||||
let theme = &cx.app_state::<Settings>().theme;
|
||||
let theme = &cx.global::<Settings>().theme;
|
||||
match &*self.client.status().borrow() {
|
||||
client::Status::ConnectionError
|
||||
| client::Status::ConnectionLost
|
||||
|
@ -1134,7 +1134,7 @@ impl Workspace {
|
|||
|
||||
fn render_disconnected_overlay(&self, cx: &AppContext) -> Option<ElementBox> {
|
||||
if self.project.read(cx).is_read_only() {
|
||||
let theme = &cx.app_state::<Settings>().theme;
|
||||
let theme = &cx.global::<Settings>().theme;
|
||||
Some(
|
||||
EventHandler::new(
|
||||
Label::new(
|
||||
|
@ -1165,7 +1165,7 @@ impl View for Workspace {
|
|||
}
|
||||
|
||||
fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
|
||||
let theme = cx.app_state::<Settings>().theme.clone();
|
||||
let theme = cx.global::<Settings>().theme.clone();
|
||||
Stack::new()
|
||||
.with_child(
|
||||
Flex::column()
|
||||
|
|
|
@ -101,7 +101,7 @@ fn main() {
|
|||
cx.spawn(|mut cx| async move {
|
||||
while let Some(settings) = settings_rx.next().await {
|
||||
cx.update(|cx| {
|
||||
cx.update_app_state(|s, _| *s = settings);
|
||||
cx.update_global(|s, _| *s = settings);
|
||||
cx.refresh_windows();
|
||||
});
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ fn main() {
|
|||
|
||||
languages.set_language_server_download_dir(zed::ROOT_PATH.clone());
|
||||
languages.set_theme(&settings.theme.editor.syntax);
|
||||
cx.add_app_state(settings);
|
||||
cx.set_global(settings);
|
||||
|
||||
let app_state = Arc::new(AppState {
|
||||
languages: Arc::new(languages),
|
||||
|
|
|
@ -18,7 +18,7 @@ fn init_logger() {
|
|||
pub fn test_app_state(cx: &mut MutableAppContext) -> Arc<AppState> {
|
||||
let settings = Settings::test(cx);
|
||||
editor::init(cx);
|
||||
cx.add_app_state(settings);
|
||||
cx.set_global(settings);
|
||||
let themes = ThemeRegistry::new(Assets, cx.font_cache().clone());
|
||||
let http = FakeHttpClient::with_404_response();
|
||||
let client = Client::new(http.clone());
|
||||
|
|
|
@ -43,7 +43,7 @@ pub fn init(app_state: &Arc<AppState>, cx: &mut gpui::MutableAppContext) {
|
|||
cx.add_global_action(quit);
|
||||
cx.add_global_action({
|
||||
move |action: &AdjustBufferFontSize, cx| {
|
||||
cx.update_app_state::<Settings, _, _>(|settings, cx| {
|
||||
cx.update_global::<Settings, _, _>(|settings, cx| {
|
||||
settings.buffer_font_size =
|
||||
(settings.buffer_font_size + action.0).max(MIN_FONT_SIZE);
|
||||
cx.refresh_windows();
|
||||
|
|
Loading…
Reference in a new issue