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