Eliminate GPUI View, ViewContext, and WindowContext types (#22632)
There's still a bit more work to do on this, but this PR is compiling (with warnings) after eliminating the key types. When the tasks below are complete, this will be the new narrative for GPUI: - `Entity<T>` - This replaces `View<T>`/`Model<T>`. It represents a unit of state, and if `T` implements `Render`, then `Entity<T>` implements `Element`. - `&mut App` This replaces `AppContext` and represents the app. - `&mut Context<T>` This replaces `ModelContext` and derefs to `App`. It is provided by the framework when updating an entity. - `&mut Window` Broken out of `&mut WindowContext` which no longer exists. Every method that once took `&mut WindowContext` now takes `&mut Window, &mut App` and every method that took `&mut ViewContext<T>` now takes `&mut Window, &mut Context<T>` Not pictured here are the two other failed attempts. It's been quite a month! Tasks: - [x] Remove `View`, `ViewContext`, `WindowContext` and thread through `Window` - [x] [@cole-miller @mikayla-maki] Redraw window when entities change - [x] [@cole-miller @mikayla-maki] Get examples and Zed running - [x] [@cole-miller @mikayla-maki] Fix Zed rendering - [x] [@mikayla-maki] Fix todo! macros and comments - [x] Fix a bug where the editor would not be redrawn because of view caching - [x] remove publicness window.notify() and replace with `AppContext::notify` - [x] remove `observe_new_window_models`, replace with `observe_new_models` with an optional window - [x] Fix a bug where the project panel would not be redrawn because of the wrong refresh() call being used - [x] Fix the tests - [x] Fix warnings by eliminating `Window` params or using `_` - [x] Fix conflicts - [x] Simplify generic code where possible - [x] Rename types - [ ] Update docs ### issues post merge - [x] Issues switching between normal and insert mode - [x] Assistant re-rendering failure - [x] Vim test failures - [x] Mac build issue Release Notes: - N/A --------- Co-authored-by: Antonio Scandurra <me@as-cii.com> Co-authored-by: Cole Miller <cole@zed.dev> Co-authored-by: Mikayla <mikayla@zed.dev> Co-authored-by: Joseph <joseph@zed.dev> Co-authored-by: max <max@zed.dev> Co-authored-by: Michael Sloan <michael@zed.dev> Co-authored-by: Mikayla Maki <mikaylamaki@Mikaylas-MacBook-Pro.local> Co-authored-by: Mikayla <mikayla.c.maki@gmail.com> Co-authored-by: joão <joao@zed.dev>
This commit is contained in:
parent
21b4a0d50e
commit
6fca1d2b0b
648 changed files with 36248 additions and 28208 deletions
|
@ -1,7 +1,7 @@
|
|||
use std::sync::Arc;
|
||||
use std::time::Instant;
|
||||
|
||||
use gpui::{AppContext, Global, ReadGlobal, SharedString};
|
||||
use gpui::{App, Global, ReadGlobal, SharedString};
|
||||
use parking_lot::RwLock;
|
||||
|
||||
#[derive(Default)]
|
||||
|
@ -26,17 +26,17 @@ impl Global for GlobalFontFamilyCache {}
|
|||
|
||||
impl FontFamilyCache {
|
||||
/// Initializes the global font family cache.
|
||||
pub fn init_global(cx: &mut AppContext) {
|
||||
pub fn init_global(cx: &mut App) {
|
||||
cx.default_global::<GlobalFontFamilyCache>();
|
||||
}
|
||||
|
||||
/// Returns the global font family cache.
|
||||
pub fn global(cx: &AppContext) -> Arc<Self> {
|
||||
pub fn global(cx: &App) -> Arc<Self> {
|
||||
GlobalFontFamilyCache::global(cx).0.clone()
|
||||
}
|
||||
|
||||
/// Returns the list of font families.
|
||||
pub fn list_font_families(&self, cx: &AppContext) -> Vec<SharedString> {
|
||||
pub fn list_font_families(&self, cx: &App) -> Vec<SharedString> {
|
||||
if self.state.read().loaded_at.is_some() {
|
||||
return self.state.read().font_families.clone();
|
||||
}
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
use std::sync::Arc;
|
||||
use std::{fmt::Debug, path::Path};
|
||||
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
use anyhow::{anyhow, Context as _, Result};
|
||||
use collections::HashMap;
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use fs::Fs;
|
||||
use futures::StreamExt;
|
||||
use gpui::{AppContext, AssetSource, Global, SharedString};
|
||||
use gpui::{App, AssetSource, Global, SharedString};
|
||||
use parking_lot::RwLock;
|
||||
use util::ResultExt;
|
||||
|
||||
|
@ -49,19 +49,19 @@ pub struct ThemeRegistry {
|
|||
|
||||
impl ThemeRegistry {
|
||||
/// Returns the global [`ThemeRegistry`].
|
||||
pub fn global(cx: &AppContext) -> Arc<Self> {
|
||||
pub fn global(cx: &App) -> Arc<Self> {
|
||||
cx.global::<GlobalThemeRegistry>().0.clone()
|
||||
}
|
||||
|
||||
/// Returns the global [`ThemeRegistry`].
|
||||
///
|
||||
/// Inserts a default [`ThemeRegistry`] if one does not yet exist.
|
||||
pub fn default_global(cx: &mut AppContext) -> Arc<Self> {
|
||||
pub fn default_global(cx: &mut App) -> Arc<Self> {
|
||||
cx.default_global::<GlobalThemeRegistry>().0.clone()
|
||||
}
|
||||
|
||||
/// Sets the global [`ThemeRegistry`].
|
||||
pub(crate) fn set_global(assets: Box<dyn AssetSource>, cx: &mut AppContext) {
|
||||
pub(crate) fn set_global(assets: Box<dyn AssetSource>, cx: &mut App) {
|
||||
cx.set_global(GlobalThemeRegistry(Arc::new(ThemeRegistry::new(assets))));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#![allow(missing_docs)]
|
||||
use gpui::{AppContext, Hsla, SharedString};
|
||||
use gpui::{App, Hsla, SharedString};
|
||||
|
||||
use crate::{ActiveTheme, Appearance};
|
||||
|
||||
|
@ -282,14 +282,14 @@ impl ColorScaleSet {
|
|||
&self.dark_alpha
|
||||
}
|
||||
|
||||
pub fn step(&self, cx: &AppContext, step: ColorScaleStep) -> Hsla {
|
||||
pub fn step(&self, cx: &App, step: ColorScaleStep) -> Hsla {
|
||||
match cx.theme().appearance {
|
||||
Appearance::Light => self.light().step(step),
|
||||
Appearance::Dark => self.dark().step(step),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn step_alpha(&self, cx: &AppContext, step: ColorScaleStep) -> Hsla {
|
||||
pub fn step_alpha(&self, cx: &App, step: ColorScaleStep) -> Hsla {
|
||||
match cx.theme().appearance {
|
||||
Appearance::Light => self.light_alpha.step(step),
|
||||
Appearance::Dark => self.dark_alpha.step(step),
|
||||
|
|
|
@ -6,8 +6,7 @@ use crate::{
|
|||
use anyhow::Result;
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use gpui::{
|
||||
px, AppContext, Font, FontFallbacks, FontFeatures, FontStyle, FontWeight, Global, Pixels,
|
||||
WindowContext,
|
||||
px, App, Font, FontFallbacks, FontFeatures, FontStyle, FontWeight, Global, Pixels, Window,
|
||||
};
|
||||
use refineable::Refineable;
|
||||
use schemars::{
|
||||
|
@ -146,7 +145,7 @@ impl ThemeSettings {
|
|||
///
|
||||
/// Reads the [`ThemeSettings`] to know which theme should be loaded,
|
||||
/// taking into account the current [`SystemAppearance`].
|
||||
pub fn reload_current_theme(cx: &mut AppContext) {
|
||||
pub fn reload_current_theme(cx: &mut App) {
|
||||
let mut theme_settings = ThemeSettings::get_global(cx).clone();
|
||||
let system_appearance = SystemAppearance::global(cx);
|
||||
|
||||
|
@ -184,7 +183,7 @@ impl Global for GlobalSystemAppearance {}
|
|||
|
||||
impl SystemAppearance {
|
||||
/// Initializes the [`SystemAppearance`] for the application.
|
||||
pub fn init(cx: &mut AppContext) {
|
||||
pub fn init(cx: &mut App) {
|
||||
*cx.default_global::<GlobalSystemAppearance>() =
|
||||
GlobalSystemAppearance(SystemAppearance(cx.window_appearance().into()));
|
||||
}
|
||||
|
@ -192,17 +191,17 @@ impl SystemAppearance {
|
|||
/// Returns the global [`SystemAppearance`].
|
||||
///
|
||||
/// Inserts a default [`SystemAppearance`] if one does not yet exist.
|
||||
pub(crate) fn default_global(cx: &mut AppContext) -> Self {
|
||||
pub(crate) fn default_global(cx: &mut App) -> Self {
|
||||
cx.default_global::<GlobalSystemAppearance>().0
|
||||
}
|
||||
|
||||
/// Returns the global [`SystemAppearance`].
|
||||
pub fn global(cx: &AppContext) -> Self {
|
||||
pub fn global(cx: &App) -> Self {
|
||||
cx.global::<GlobalSystemAppearance>().0
|
||||
}
|
||||
|
||||
/// Returns a mutable reference to the global [`SystemAppearance`].
|
||||
pub fn global_mut(cx: &mut AppContext) -> &mut Self {
|
||||
pub fn global_mut(cx: &mut App) -> &mut Self {
|
||||
cx.global_mut::<GlobalSystemAppearance>()
|
||||
}
|
||||
}
|
||||
|
@ -449,7 +448,7 @@ impl ThemeSettings {
|
|||
///
|
||||
/// Returns a `Some` containing the new theme if it was successful.
|
||||
/// Returns `None` otherwise.
|
||||
pub fn switch_theme(&mut self, theme: &str, cx: &mut AppContext) -> Option<Arc<Theme>> {
|
||||
pub fn switch_theme(&mut self, theme: &str, cx: &mut App) -> Option<Arc<Theme>> {
|
||||
let themes = ThemeRegistry::default_global(cx);
|
||||
|
||||
let mut new_theme = None;
|
||||
|
@ -495,14 +494,14 @@ impl ThemeSettings {
|
|||
|
||||
// TODO: Make private, change usages to use `get_ui_font_size` instead.
|
||||
#[allow(missing_docs)]
|
||||
pub fn setup_ui_font(cx: &mut WindowContext) -> gpui::Font {
|
||||
pub fn setup_ui_font(window: &mut Window, cx: &mut App) -> gpui::Font {
|
||||
let (ui_font, ui_font_size) = {
|
||||
let theme_settings = ThemeSettings::get_global(cx);
|
||||
let font = theme_settings.ui_font.clone();
|
||||
(font, theme_settings.ui_font_size)
|
||||
};
|
||||
|
||||
cx.set_rem_size(ui_font_size);
|
||||
window.set_rem_size(ui_font_size);
|
||||
ui_font
|
||||
}
|
||||
|
||||
|
@ -515,7 +514,7 @@ impl settings::Settings for ThemeSettings {
|
|||
|
||||
type FileContent = ThemeSettingsContent;
|
||||
|
||||
fn load(sources: SettingsSources<Self::FileContent>, cx: &mut AppContext) -> Result<Self> {
|
||||
fn load(sources: SettingsSources<Self::FileContent>, cx: &mut App) -> Result<Self> {
|
||||
let themes = ThemeRegistry::default_global(cx);
|
||||
let system_appearance = SystemAppearance::default_global(cx);
|
||||
|
||||
|
@ -636,7 +635,7 @@ impl settings::Settings for ThemeSettings {
|
|||
fn json_schema(
|
||||
generator: &mut SchemaGenerator,
|
||||
params: &SettingsJsonSchemaParams,
|
||||
cx: &AppContext,
|
||||
cx: &App,
|
||||
) -> schemars::schema::RootSchema {
|
||||
let mut root_schema = generator.root_schema_for::<ThemeSettingsContent>();
|
||||
let theme_names = ThemeRegistry::global(cx)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#![allow(missing_docs)]
|
||||
|
||||
use gpui::{Hsla, SharedString, WindowBackgroundAppearance, WindowContext};
|
||||
use gpui::{App, Hsla, SharedString, WindowBackgroundAppearance};
|
||||
use refineable::Refineable;
|
||||
use std::sync::Arc;
|
||||
use strum::{AsRefStr, EnumIter, IntoEnumIterator};
|
||||
|
@ -512,7 +512,7 @@ impl ThemeColors {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn all_theme_colors(cx: &WindowContext) -> Vec<(Hsla, SharedString)> {
|
||||
pub fn all_theme_colors(cx: &mut App) -> Vec<(Hsla, SharedString)> {
|
||||
let theme = cx.theme();
|
||||
ThemeColorField::iter()
|
||||
.map(|field| {
|
||||
|
|
|
@ -26,8 +26,8 @@ use ::settings::Settings;
|
|||
use anyhow::Result;
|
||||
use fs::Fs;
|
||||
use gpui::{
|
||||
px, AppContext, AssetSource, HighlightStyle, Hsla, Pixels, Refineable, SharedString,
|
||||
WindowAppearance, WindowBackgroundAppearance,
|
||||
px, App, AssetSource, HighlightStyle, Hsla, Pixels, Refineable, SharedString, WindowAppearance,
|
||||
WindowBackgroundAppearance,
|
||||
};
|
||||
use serde::Deserialize;
|
||||
use uuid::Uuid;
|
||||
|
@ -87,7 +87,7 @@ pub enum LoadThemes {
|
|||
}
|
||||
|
||||
/// Initialize the theme system.
|
||||
pub fn init(themes_to_load: LoadThemes, cx: &mut AppContext) {
|
||||
pub fn init(themes_to_load: LoadThemes, cx: &mut App) {
|
||||
let (assets, load_user_themes) = match themes_to_load {
|
||||
LoadThemes::JustBase => (Box::new(()) as Box<dyn AssetSource>, false),
|
||||
LoadThemes::All(assets) => (assets, true),
|
||||
|
@ -108,7 +108,7 @@ pub trait ActiveTheme {
|
|||
fn theme(&self) -> &Arc<Theme>;
|
||||
}
|
||||
|
||||
impl ActiveTheme for AppContext {
|
||||
impl ActiveTheme for App {
|
||||
fn theme(&self) -> &Arc<Theme> {
|
||||
&ThemeSettings::get_global(self).active_theme
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue