Notify all views when a theme is selected

Nathan Sobo created

Change summary

gpui/src/app.rs         | 14 ++++++++++++++
zed/src/theme_picker.rs | 15 +++++++++------
2 files changed, 23 insertions(+), 6 deletions(-)

Detailed changes

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::<Vec<_>>();
+        self.pending_effects.extend(notifications);
+    }
+
     pub fn dispatch_action<T: 'static + Any>(
         &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;
     }

zed/src/theme_picker.rs 🔗

@@ -95,16 +95,19 @@ impl ThemePicker {
 
     fn confirm(&mut self, _: &(), cx: &mut ViewContext<Self>) {
         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<Self>) {