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,8 +1,8 @@
|
|||
use fs::Fs;
|
||||
use fuzzy::{match_strings, StringMatch, StringMatchCandidate};
|
||||
use gpui::{
|
||||
actions, AppContext, DismissEvent, EventEmitter, FocusableView, Render, UpdateGlobal, View,
|
||||
ViewContext, VisualContext, WeakView,
|
||||
actions, App, Context, DismissEvent, Entity, EventEmitter, Focusable, Render, UpdateGlobal,
|
||||
WeakEntity, Window,
|
||||
};
|
||||
use picker::{Picker, PickerDelegate};
|
||||
use settings::{update_settings_file, SettingsStore};
|
||||
|
@ -15,51 +15,60 @@ use zed_actions::theme_selector::Toggle;
|
|||
|
||||
actions!(theme_selector, [Reload]);
|
||||
|
||||
pub fn init(cx: &mut AppContext) {
|
||||
cx.observe_new_views(
|
||||
|workspace: &mut Workspace, _cx: &mut ViewContext<Workspace>| {
|
||||
pub fn init(cx: &mut App) {
|
||||
cx.observe_new(
|
||||
|workspace: &mut Workspace, _window, _cx: &mut Context<Workspace>| {
|
||||
workspace.register_action(toggle);
|
||||
},
|
||||
)
|
||||
.detach();
|
||||
}
|
||||
|
||||
pub fn toggle(workspace: &mut Workspace, toggle: &Toggle, cx: &mut ViewContext<Workspace>) {
|
||||
pub fn toggle(
|
||||
workspace: &mut Workspace,
|
||||
toggle: &Toggle,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Workspace>,
|
||||
) {
|
||||
let fs = workspace.app_state().fs.clone();
|
||||
workspace.toggle_modal(cx, |cx| {
|
||||
workspace.toggle_modal(window, cx, |window, cx| {
|
||||
let delegate = ThemeSelectorDelegate::new(
|
||||
cx.view().downgrade(),
|
||||
cx.model().downgrade(),
|
||||
fs,
|
||||
toggle.themes_filter.as_ref(),
|
||||
cx,
|
||||
);
|
||||
ThemeSelector::new(delegate, cx)
|
||||
ThemeSelector::new(delegate, window, cx)
|
||||
});
|
||||
}
|
||||
|
||||
impl ModalView for ThemeSelector {}
|
||||
|
||||
pub struct ThemeSelector {
|
||||
picker: View<Picker<ThemeSelectorDelegate>>,
|
||||
picker: Entity<Picker<ThemeSelectorDelegate>>,
|
||||
}
|
||||
|
||||
impl EventEmitter<DismissEvent> for ThemeSelector {}
|
||||
|
||||
impl FocusableView for ThemeSelector {
|
||||
fn focus_handle(&self, cx: &AppContext) -> gpui::FocusHandle {
|
||||
impl Focusable for ThemeSelector {
|
||||
fn focus_handle(&self, cx: &App) -> gpui::FocusHandle {
|
||||
self.picker.focus_handle(cx)
|
||||
}
|
||||
}
|
||||
|
||||
impl Render for ThemeSelector {
|
||||
fn render(&mut self, _cx: &mut ViewContext<Self>) -> impl IntoElement {
|
||||
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
|
||||
v_flex().w(rems(34.)).child(self.picker.clone())
|
||||
}
|
||||
}
|
||||
|
||||
impl ThemeSelector {
|
||||
pub fn new(delegate: ThemeSelectorDelegate, cx: &mut ViewContext<Self>) -> Self {
|
||||
let picker = cx.new_view(|cx| Picker::uniform_list(delegate, cx));
|
||||
pub fn new(
|
||||
delegate: ThemeSelectorDelegate,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Self {
|
||||
let picker = cx.new(|cx| Picker::uniform_list(delegate, window, cx));
|
||||
Self { picker }
|
||||
}
|
||||
}
|
||||
|
@ -71,15 +80,15 @@ pub struct ThemeSelectorDelegate {
|
|||
original_theme: Arc<Theme>,
|
||||
selection_completed: bool,
|
||||
selected_index: usize,
|
||||
view: WeakView<ThemeSelector>,
|
||||
selector: WeakEntity<ThemeSelector>,
|
||||
}
|
||||
|
||||
impl ThemeSelectorDelegate {
|
||||
fn new(
|
||||
weak_view: WeakView<ThemeSelector>,
|
||||
selector: WeakEntity<ThemeSelector>,
|
||||
fs: Arc<dyn Fs>,
|
||||
themes_filter: Option<&Vec<String>>,
|
||||
cx: &mut ViewContext<ThemeSelector>,
|
||||
cx: &mut Context<ThemeSelector>,
|
||||
) -> Self {
|
||||
let original_theme = cx.theme().clone();
|
||||
|
||||
|
@ -118,14 +127,14 @@ impl ThemeSelectorDelegate {
|
|||
original_theme: original_theme.clone(),
|
||||
selected_index: 0,
|
||||
selection_completed: false,
|
||||
view: weak_view,
|
||||
selector,
|
||||
};
|
||||
|
||||
this.select_if_matching(&original_theme.name);
|
||||
this
|
||||
}
|
||||
|
||||
fn show_selected_theme(&mut self, cx: &mut ViewContext<Picker<ThemeSelectorDelegate>>) {
|
||||
fn show_selected_theme(&mut self, cx: &mut Context<Picker<ThemeSelectorDelegate>>) {
|
||||
if let Some(mat) = self.matches.get(self.selected_index) {
|
||||
let registry = ThemeRegistry::global(cx);
|
||||
match registry.get(&mat.string) {
|
||||
|
@ -147,13 +156,13 @@ impl ThemeSelectorDelegate {
|
|||
.unwrap_or(self.selected_index);
|
||||
}
|
||||
|
||||
fn set_theme(theme: Arc<Theme>, cx: &mut AppContext) {
|
||||
fn set_theme(theme: Arc<Theme>, cx: &mut App) {
|
||||
SettingsStore::update_global(cx, |store, cx| {
|
||||
let mut theme_settings = store.get::<ThemeSettings>(None).clone();
|
||||
theme_settings.active_theme = theme;
|
||||
theme_settings.apply_theme_overrides();
|
||||
store.override_global(theme_settings);
|
||||
cx.refresh();
|
||||
cx.refresh_windows();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -161,7 +170,7 @@ impl ThemeSelectorDelegate {
|
|||
impl PickerDelegate for ThemeSelectorDelegate {
|
||||
type ListItem = ui::ListItem;
|
||||
|
||||
fn placeholder_text(&self, _cx: &mut WindowContext) -> Arc<str> {
|
||||
fn placeholder_text(&self, _window: &mut Window, _cx: &mut App) -> Arc<str> {
|
||||
"Select Theme...".into()
|
||||
}
|
||||
|
||||
|
@ -169,33 +178,38 @@ impl PickerDelegate for ThemeSelectorDelegate {
|
|||
self.matches.len()
|
||||
}
|
||||
|
||||
fn confirm(&mut self, _: bool, cx: &mut ViewContext<Picker<ThemeSelectorDelegate>>) {
|
||||
fn confirm(
|
||||
&mut self,
|
||||
_: bool,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Picker<ThemeSelectorDelegate>>,
|
||||
) {
|
||||
self.selection_completed = true;
|
||||
|
||||
let theme_name = cx.theme().name.clone();
|
||||
|
||||
telemetry::event!("Settings Changed", setting = "theme", value = theme_name);
|
||||
|
||||
let appearance = Appearance::from(cx.appearance());
|
||||
let appearance = Appearance::from(window.appearance());
|
||||
|
||||
update_settings_file::<ThemeSettings>(self.fs.clone(), cx, move |settings, _| {
|
||||
settings.set_theme(theme_name.to_string(), appearance);
|
||||
});
|
||||
|
||||
self.view
|
||||
self.selector
|
||||
.update(cx, |_, cx| {
|
||||
cx.emit(DismissEvent);
|
||||
})
|
||||
.ok();
|
||||
}
|
||||
|
||||
fn dismissed(&mut self, cx: &mut ViewContext<Picker<ThemeSelectorDelegate>>) {
|
||||
fn dismissed(&mut self, _: &mut Window, cx: &mut Context<Picker<ThemeSelectorDelegate>>) {
|
||||
if !self.selection_completed {
|
||||
Self::set_theme(self.original_theme.clone(), cx);
|
||||
self.selection_completed = true;
|
||||
}
|
||||
|
||||
self.view
|
||||
self.selector
|
||||
.update(cx, |_, cx| cx.emit(DismissEvent))
|
||||
.log_err();
|
||||
}
|
||||
|
@ -207,7 +221,8 @@ impl PickerDelegate for ThemeSelectorDelegate {
|
|||
fn set_selected_index(
|
||||
&mut self,
|
||||
ix: usize,
|
||||
cx: &mut ViewContext<Picker<ThemeSelectorDelegate>>,
|
||||
_: &mut Window,
|
||||
cx: &mut Context<Picker<ThemeSelectorDelegate>>,
|
||||
) {
|
||||
self.selected_index = ix;
|
||||
self.show_selected_theme(cx);
|
||||
|
@ -216,7 +231,8 @@ impl PickerDelegate for ThemeSelectorDelegate {
|
|||
fn update_matches(
|
||||
&mut self,
|
||||
query: String,
|
||||
cx: &mut ViewContext<Picker<ThemeSelectorDelegate>>,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Picker<ThemeSelectorDelegate>>,
|
||||
) -> gpui::Task<()> {
|
||||
let background = cx.background_executor().clone();
|
||||
let candidates = self
|
||||
|
@ -226,7 +242,7 @@ impl PickerDelegate for ThemeSelectorDelegate {
|
|||
.map(|(id, meta)| StringMatchCandidate::new(id, &meta.name))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
cx.spawn(|this, mut cx| async move {
|
||||
cx.spawn_in(window, |this, mut cx| async move {
|
||||
let matches = if query.is_empty() {
|
||||
candidates
|
||||
.into_iter()
|
||||
|
@ -266,7 +282,8 @@ impl PickerDelegate for ThemeSelectorDelegate {
|
|||
&self,
|
||||
ix: usize,
|
||||
selected: bool,
|
||||
_cx: &mut ViewContext<Picker<Self>>,
|
||||
_window: &mut Window,
|
||||
_cx: &mut Context<Picker<Self>>,
|
||||
) -> Option<Self::ListItem> {
|
||||
let theme_match = &self.matches[ix];
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue