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:
co-authored by
Antonio Scandurra
Cole Miller
Mikayla
Joseph
max
Michael Sloan
Mikayla Maki
Mikayla
joão
parent
21b4a0d50e
commit
6fca1d2b0b
@@ -1,6 +1,6 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use gpui::{AppContext, FontFeatures, FontWeight};
|
||||
use gpui::{App, FontFeatures, FontWeight};
|
||||
use settings::{EditableSettingControl, Settings};
|
||||
use theme::{FontFamilyCache, SystemAppearance, ThemeMode, ThemeRegistry, ThemeSettings};
|
||||
use ui::{
|
||||
@@ -18,7 +18,7 @@ impl AppearanceSettingsControls {
|
||||
}
|
||||
|
||||
impl RenderOnce for AppearanceSettingsControls {
|
||||
fn render(self, _cx: &mut WindowContext) -> impl IntoElement {
|
||||
fn render(self, _window: &mut Window, _cx: &mut App) -> impl IntoElement {
|
||||
SettingsContainer::new()
|
||||
.child(
|
||||
SettingsGroup::new("Theme").child(
|
||||
@@ -55,7 +55,7 @@ impl EditableSettingControl for ThemeControl {
|
||||
"Theme".into()
|
||||
}
|
||||
|
||||
fn read(cx: &AppContext) -> Self::Value {
|
||||
fn read(cx: &App) -> Self::Value {
|
||||
let settings = ThemeSettings::get_global(cx);
|
||||
let appearance = SystemAppearance::global(cx);
|
||||
settings
|
||||
@@ -68,7 +68,7 @@ impl EditableSettingControl for ThemeControl {
|
||||
fn apply(
|
||||
settings: &mut <Self::Settings as Settings>::FileContent,
|
||||
value: Self::Value,
|
||||
cx: &AppContext,
|
||||
cx: &App,
|
||||
) {
|
||||
let appearance = SystemAppearance::global(cx);
|
||||
settings.set_theme(value, appearance.0);
|
||||
@@ -76,24 +76,24 @@ impl EditableSettingControl for ThemeControl {
|
||||
}
|
||||
|
||||
impl RenderOnce for ThemeControl {
|
||||
fn render(self, cx: &mut WindowContext) -> impl IntoElement {
|
||||
fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
|
||||
let value = Self::read(cx);
|
||||
|
||||
DropdownMenu::new(
|
||||
"theme",
|
||||
value.clone(),
|
||||
ContextMenu::build(cx, |mut menu, cx| {
|
||||
ContextMenu::build(window, cx, |mut menu, _, cx| {
|
||||
let theme_registry = ThemeRegistry::global(cx);
|
||||
|
||||
for theme in theme_registry.list_names() {
|
||||
menu = menu.custom_entry(
|
||||
{
|
||||
let theme = theme.clone();
|
||||
move |_cx| Label::new(theme.clone()).into_any_element()
|
||||
move |_window, _cx| Label::new(theme.clone()).into_any_element()
|
||||
},
|
||||
{
|
||||
let theme = theme.clone();
|
||||
move |cx| {
|
||||
move |_window, cx| {
|
||||
Self::write(theme.to_string(), cx);
|
||||
}
|
||||
},
|
||||
@@ -118,7 +118,7 @@ impl EditableSettingControl for ThemeModeControl {
|
||||
"Theme Mode".into()
|
||||
}
|
||||
|
||||
fn read(cx: &AppContext) -> Self::Value {
|
||||
fn read(cx: &App) -> Self::Value {
|
||||
let settings = ThemeSettings::get_global(cx);
|
||||
settings
|
||||
.theme_selection
|
||||
@@ -130,14 +130,14 @@ impl EditableSettingControl for ThemeModeControl {
|
||||
fn apply(
|
||||
settings: &mut <Self::Settings as Settings>::FileContent,
|
||||
value: Self::Value,
|
||||
_cx: &AppContext,
|
||||
_cx: &App,
|
||||
) {
|
||||
settings.set_mode(value);
|
||||
}
|
||||
}
|
||||
|
||||
impl RenderOnce for ThemeModeControl {
|
||||
fn render(self, cx: &mut WindowContext) -> impl IntoElement {
|
||||
fn render(self, _window: &mut Window, cx: &mut App) -> impl IntoElement {
|
||||
let value = Self::read(cx);
|
||||
|
||||
h_flex()
|
||||
@@ -146,7 +146,7 @@ impl RenderOnce for ThemeModeControl {
|
||||
.style(ButtonStyle::Filled)
|
||||
.size(ButtonSize::Large)
|
||||
.toggle_state(value == ThemeMode::Light)
|
||||
.on_click(|_, cx| Self::write(ThemeMode::Light, cx))
|
||||
.on_click(|_, _, cx| Self::write(ThemeMode::Light, cx))
|
||||
.first(),
|
||||
)
|
||||
.child(
|
||||
@@ -154,7 +154,7 @@ impl RenderOnce for ThemeModeControl {
|
||||
.style(ButtonStyle::Filled)
|
||||
.size(ButtonSize::Large)
|
||||
.toggle_state(value == ThemeMode::System)
|
||||
.on_click(|_, cx| Self::write(ThemeMode::System, cx))
|
||||
.on_click(|_, _, cx| Self::write(ThemeMode::System, cx))
|
||||
.middle(),
|
||||
)
|
||||
.child(
|
||||
@@ -162,7 +162,7 @@ impl RenderOnce for ThemeModeControl {
|
||||
.style(ButtonStyle::Filled)
|
||||
.size(ButtonSize::Large)
|
||||
.toggle_state(value == ThemeMode::Dark)
|
||||
.on_click(|_, cx| Self::write(ThemeMode::Dark, cx))
|
||||
.on_click(|_, _, cx| Self::write(ThemeMode::Dark, cx))
|
||||
.last(),
|
||||
)
|
||||
}
|
||||
@@ -179,7 +179,7 @@ impl EditableSettingControl for UiFontFamilyControl {
|
||||
"UI Font Family".into()
|
||||
}
|
||||
|
||||
fn read(cx: &AppContext) -> Self::Value {
|
||||
fn read(cx: &App) -> Self::Value {
|
||||
let settings = ThemeSettings::get_global(cx);
|
||||
settings.ui_font.family.clone()
|
||||
}
|
||||
@@ -187,14 +187,14 @@ impl EditableSettingControl for UiFontFamilyControl {
|
||||
fn apply(
|
||||
settings: &mut <Self::Settings as Settings>::FileContent,
|
||||
value: Self::Value,
|
||||
_cx: &AppContext,
|
||||
_cx: &App,
|
||||
) {
|
||||
settings.ui_font_family = Some(value.to_string());
|
||||
}
|
||||
}
|
||||
|
||||
impl RenderOnce for UiFontFamilyControl {
|
||||
fn render(self, cx: &mut WindowContext) -> impl IntoElement {
|
||||
fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
|
||||
let value = Self::read(cx);
|
||||
|
||||
h_flex()
|
||||
@@ -203,18 +203,18 @@ impl RenderOnce for UiFontFamilyControl {
|
||||
.child(DropdownMenu::new(
|
||||
"ui-font-family",
|
||||
value.clone(),
|
||||
ContextMenu::build(cx, |mut menu, cx| {
|
||||
ContextMenu::build(window, cx, |mut menu, _, cx| {
|
||||
let font_family_cache = FontFamilyCache::global(cx);
|
||||
|
||||
for font_name in font_family_cache.list_font_families(cx) {
|
||||
menu = menu.custom_entry(
|
||||
{
|
||||
let font_name = font_name.clone();
|
||||
move |_cx| Label::new(font_name.clone()).into_any_element()
|
||||
move |_window, _cx| Label::new(font_name.clone()).into_any_element()
|
||||
},
|
||||
{
|
||||
let font_name = font_name.clone();
|
||||
move |cx| {
|
||||
move |_window, cx| {
|
||||
Self::write(font_name.clone(), cx);
|
||||
}
|
||||
},
|
||||
@@ -238,7 +238,7 @@ impl EditableSettingControl for UiFontSizeControl {
|
||||
"UI Font Size".into()
|
||||
}
|
||||
|
||||
fn read(cx: &AppContext) -> Self::Value {
|
||||
fn read(cx: &App) -> Self::Value {
|
||||
let settings = ThemeSettings::get_global(cx);
|
||||
settings.ui_font_size
|
||||
}
|
||||
@@ -246,14 +246,14 @@ impl EditableSettingControl for UiFontSizeControl {
|
||||
fn apply(
|
||||
settings: &mut <Self::Settings as Settings>::FileContent,
|
||||
value: Self::Value,
|
||||
_cx: &AppContext,
|
||||
_cx: &App,
|
||||
) {
|
||||
settings.ui_font_size = Some(value.into());
|
||||
}
|
||||
}
|
||||
|
||||
impl RenderOnce for UiFontSizeControl {
|
||||
fn render(self, cx: &mut WindowContext) -> impl IntoElement {
|
||||
fn render(self, _window: &mut Window, cx: &mut App) -> impl IntoElement {
|
||||
let value = Self::read(cx);
|
||||
|
||||
h_flex()
|
||||
@@ -262,10 +262,10 @@ impl RenderOnce for UiFontSizeControl {
|
||||
.child(NumericStepper::new(
|
||||
"ui-font-size",
|
||||
value.to_string(),
|
||||
move |_, cx| {
|
||||
move |_, _, cx| {
|
||||
Self::write(value - px(1.), cx);
|
||||
},
|
||||
move |_, cx| {
|
||||
move |_, _, cx| {
|
||||
Self::write(value + px(1.), cx);
|
||||
},
|
||||
))
|
||||
@@ -283,7 +283,7 @@ impl EditableSettingControl for UiFontWeightControl {
|
||||
"UI Font Weight".into()
|
||||
}
|
||||
|
||||
fn read(cx: &AppContext) -> Self::Value {
|
||||
fn read(cx: &App) -> Self::Value {
|
||||
let settings = ThemeSettings::get_global(cx);
|
||||
settings.ui_font.weight
|
||||
}
|
||||
@@ -291,14 +291,14 @@ impl EditableSettingControl for UiFontWeightControl {
|
||||
fn apply(
|
||||
settings: &mut <Self::Settings as Settings>::FileContent,
|
||||
value: Self::Value,
|
||||
_cx: &AppContext,
|
||||
_cx: &App,
|
||||
) {
|
||||
settings.ui_font_weight = Some(value.0);
|
||||
}
|
||||
}
|
||||
|
||||
impl RenderOnce for UiFontWeightControl {
|
||||
fn render(self, cx: &mut WindowContext) -> impl IntoElement {
|
||||
fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
|
||||
let value = Self::read(cx);
|
||||
|
||||
h_flex()
|
||||
@@ -307,12 +307,12 @@ impl RenderOnce for UiFontWeightControl {
|
||||
.child(DropdownMenu::new(
|
||||
"ui-font-weight",
|
||||
value.0.to_string(),
|
||||
ContextMenu::build(cx, |mut menu, _cx| {
|
||||
ContextMenu::build(window, cx, |mut menu, _window, _cx| {
|
||||
for weight in FontWeight::ALL {
|
||||
menu = menu.custom_entry(
|
||||
move |_cx| Label::new(weight.0.to_string()).into_any_element(),
|
||||
move |_window, _cx| Label::new(weight.0.to_string()).into_any_element(),
|
||||
{
|
||||
move |cx| {
|
||||
move |_window, cx| {
|
||||
Self::write(weight, cx);
|
||||
}
|
||||
},
|
||||
@@ -336,7 +336,7 @@ impl EditableSettingControl for UiFontLigaturesControl {
|
||||
"UI Font Ligatures".into()
|
||||
}
|
||||
|
||||
fn read(cx: &AppContext) -> Self::Value {
|
||||
fn read(cx: &App) -> Self::Value {
|
||||
let settings = ThemeSettings::get_global(cx);
|
||||
settings.ui_font.features.is_calt_enabled().unwrap_or(true)
|
||||
}
|
||||
@@ -344,7 +344,7 @@ impl EditableSettingControl for UiFontLigaturesControl {
|
||||
fn apply(
|
||||
settings: &mut <Self::Settings as Settings>::FileContent,
|
||||
value: Self::Value,
|
||||
_cx: &AppContext,
|
||||
_cx: &App,
|
||||
) {
|
||||
let value = if value { 1 } else { 0 };
|
||||
|
||||
@@ -365,14 +365,14 @@ impl EditableSettingControl for UiFontLigaturesControl {
|
||||
}
|
||||
|
||||
impl RenderOnce for UiFontLigaturesControl {
|
||||
fn render(self, cx: &mut WindowContext) -> impl IntoElement {
|
||||
fn render(self, _window: &mut Window, cx: &mut App) -> impl IntoElement {
|
||||
let value = Self::read(cx);
|
||||
|
||||
CheckboxWithLabel::new(
|
||||
"ui-font-ligatures",
|
||||
Label::new(self.name()),
|
||||
value.into(),
|
||||
|selection, cx| {
|
||||
|selection, _, cx| {
|
||||
Self::write(
|
||||
match selection {
|
||||
ToggleState::Selected => true,
|
||||
|
||||
@@ -5,7 +5,7 @@ use std::any::TypeId;
|
||||
use command_palette_hooks::CommandPaletteFilter;
|
||||
use editor::EditorSettingsControls;
|
||||
use feature_flags::{FeatureFlag, FeatureFlagViewExt};
|
||||
use gpui::{actions, AppContext, EventEmitter, FocusHandle, FocusableView, View};
|
||||
use gpui::{actions, App, Entity, EventEmitter, FocusHandle, Focusable};
|
||||
use ui::prelude::*;
|
||||
use workspace::item::{Item, ItemEvent};
|
||||
use workspace::Workspace;
|
||||
@@ -20,9 +20,13 @@ impl FeatureFlag for SettingsUiFeatureFlag {
|
||||
|
||||
actions!(zed, [OpenSettingsEditor]);
|
||||
|
||||
pub fn init(cx: &mut AppContext) {
|
||||
cx.observe_new_views(|workspace: &mut Workspace, cx| {
|
||||
workspace.register_action(|workspace, _: &OpenSettingsEditor, cx| {
|
||||
pub fn init(cx: &mut App) {
|
||||
cx.observe_new(|workspace: &mut Workspace, window, cx| {
|
||||
let Some(window) = window else {
|
||||
return;
|
||||
};
|
||||
|
||||
workspace.register_action(|workspace, _: &OpenSettingsEditor, window, cx| {
|
||||
let existing = workspace
|
||||
.active_pane()
|
||||
.read(cx)
|
||||
@@ -30,10 +34,10 @@ pub fn init(cx: &mut AppContext) {
|
||||
.find_map(|item| item.downcast::<SettingsPage>());
|
||||
|
||||
if let Some(existing) = existing {
|
||||
workspace.activate_item(&existing, true, true, cx);
|
||||
workspace.activate_item(&existing, true, true, window, cx);
|
||||
} else {
|
||||
let settings_page = SettingsPage::new(workspace, cx);
|
||||
workspace.add_item_to_active_pane(Box::new(settings_page), None, true, cx)
|
||||
workspace.add_item_to_active_pane(Box::new(settings_page), None, true, window, cx)
|
||||
}
|
||||
});
|
||||
|
||||
@@ -43,17 +47,20 @@ pub fn init(cx: &mut AppContext) {
|
||||
filter.hide_action_types(&settings_ui_actions);
|
||||
});
|
||||
|
||||
cx.observe_flag::<SettingsUiFeatureFlag, _>(move |is_enabled, _view, cx| {
|
||||
if is_enabled {
|
||||
CommandPaletteFilter::update_global(cx, |filter, _cx| {
|
||||
filter.show_action_types(settings_ui_actions.iter());
|
||||
});
|
||||
} else {
|
||||
CommandPaletteFilter::update_global(cx, |filter, _cx| {
|
||||
filter.hide_action_types(&settings_ui_actions);
|
||||
});
|
||||
}
|
||||
})
|
||||
cx.observe_flag::<SettingsUiFeatureFlag, _>(
|
||||
window,
|
||||
move |is_enabled, _workspace, _, cx| {
|
||||
if is_enabled {
|
||||
CommandPaletteFilter::update_global(cx, |filter, _cx| {
|
||||
filter.show_action_types(settings_ui_actions.iter());
|
||||
});
|
||||
} else {
|
||||
CommandPaletteFilter::update_global(cx, |filter, _cx| {
|
||||
filter.hide_action_types(&settings_ui_actions);
|
||||
});
|
||||
}
|
||||
},
|
||||
)
|
||||
.detach();
|
||||
})
|
||||
.detach();
|
||||
@@ -64,8 +71,8 @@ pub struct SettingsPage {
|
||||
}
|
||||
|
||||
impl SettingsPage {
|
||||
pub fn new(_workspace: &Workspace, cx: &mut ViewContext<Workspace>) -> View<Self> {
|
||||
cx.new_view(|cx| Self {
|
||||
pub fn new(_workspace: &Workspace, cx: &mut Context<Workspace>) -> Entity<Self> {
|
||||
cx.new(|cx| Self {
|
||||
focus_handle: cx.focus_handle(),
|
||||
})
|
||||
}
|
||||
@@ -73,8 +80,8 @@ impl SettingsPage {
|
||||
|
||||
impl EventEmitter<ItemEvent> for SettingsPage {}
|
||||
|
||||
impl FocusableView for SettingsPage {
|
||||
fn focus_handle(&self, _cx: &AppContext) -> FocusHandle {
|
||||
impl Focusable for SettingsPage {
|
||||
fn focus_handle(&self, _cx: &App) -> FocusHandle {
|
||||
self.focus_handle.clone()
|
||||
}
|
||||
}
|
||||
@@ -82,11 +89,11 @@ impl FocusableView for SettingsPage {
|
||||
impl Item for SettingsPage {
|
||||
type Event = ItemEvent;
|
||||
|
||||
fn tab_icon(&self, _cx: &WindowContext) -> Option<Icon> {
|
||||
fn tab_icon(&self, _window: &Window, _cx: &App) -> Option<Icon> {
|
||||
Some(Icon::new(IconName::Settings))
|
||||
}
|
||||
|
||||
fn tab_content_text(&self, _cx: &WindowContext) -> Option<SharedString> {
|
||||
fn tab_content_text(&self, _window: &Window, _cx: &App) -> Option<SharedString> {
|
||||
Some("Settings".into())
|
||||
}
|
||||
|
||||
@@ -100,7 +107,7 @@ impl Item for SettingsPage {
|
||||
}
|
||||
|
||||
impl Render for SettingsPage {
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
|
||||
fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
v_flex()
|
||||
.p_4()
|
||||
.size_full()
|
||||
|
||||
Reference in New Issue
Block a user