From 4c534708007ff5c0174f12cac019fdd8eb8d9b90 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Mon, 2 Aug 2021 16:57:10 -0600 Subject: [PATCH] Notify all views when a theme is selected --- gpui/src/app.rs | 14 ++++++++++++++ zed/src/theme_picker.rs | 15 +++++++++------ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/gpui/src/app.rs b/gpui/src/app.rs index 6d857952e2..579bf5c468 100644 --- a/gpui/src/app.rs +++ b/gpui/src/app.rs @@ -813,6 +813,16 @@ impl MutableAppContext { .push_back(Effect::ViewNotification { window_id, view_id }); } + pub(crate) fn notify_all_views(&mut self) { + let notifications = self + .views + .keys() + .copied() + .map(|(window_id, view_id)| Effect::ViewNotification { window_id, view_id }) + .collect::>(); + self.pending_effects.extend(notifications); + } + pub fn dispatch_action( &mut self, window_id: usize, @@ -2087,6 +2097,10 @@ impl<'a, T: View> ViewContext<'a, T> { self.app.notify_view(self.window_id, self.view_id); } + pub fn notify_all(&mut self) { + self.app.notify_all_views(); + } + pub fn propagate_action(&mut self) { self.halt_action_dispatch = false; } diff --git a/zed/src/theme_picker.rs b/zed/src/theme_picker.rs index 3aacf69ebf..419ad1ad26 100644 --- a/zed/src/theme_picker.rs +++ b/zed/src/theme_picker.rs @@ -95,16 +95,19 @@ impl ThemePicker { fn confirm(&mut self, _: &(), cx: &mut ViewContext) { if let Some(mat) = self.matches.get(self.selected_index) { - let settings_tx = self.settings_tx.clone(); if let Ok(theme) = self.registry.get(&mat.string) { - cx.foreground() - .spawn(async move { - settings_tx.lock().await.borrow_mut().theme = theme; + let settings_tx = self.settings_tx.clone(); + cx.spawn(|this, mut cx| async move { + let mut settings_tx = settings_tx.lock().await; + this.update(&mut cx, |_, cx| { + settings_tx.borrow_mut().theme = theme; + cx.notify_all(); + cx.emit(Event::Dismissed); }) - .detach(); + }) + .detach(); } } - cx.emit(Event::Dismissed); } fn select_prev(&mut self, _: &(), cx: &mut ViewContext) {