gpui: Add Global marker trait (#7095)

This should prevent a class of bugs where one queries the wrong type of
global, which results in oddities at runtime.

Release Notes:

- N/A

---------

Co-authored-by: Marshall <marshall@zed.dev>
Co-authored-by: Marshall Bowers <elliott.codes@gmail.com>
This commit is contained in:
Piotr Osiewicz
2024-01-30 14:08:20 -05:00
committed by GitHub
co-authored by Marshall Marshall Bowers
parent 7bfa584eb6
commit e6ebe7974d
59 changed files with 449 additions and 237 deletions
+2 -3
View File
@@ -104,7 +104,6 @@ use std::{
ops::{ControlFlow, Deref, DerefMut, Range, RangeInclusive},
path::Path,
sync::Arc,
sync::Weak,
time::{Duration, Instant},
};
pub use sum_tree::Bias;
@@ -241,7 +240,7 @@ pub fn init(cx: &mut AppContext) {
.detach();
cx.on_action(move |_: &workspace::NewFile, cx| {
let app_state = cx.global::<Weak<workspace::AppState>>();
let app_state = workspace::AppState::global(cx);
if let Some(app_state) = app_state.upgrade() {
workspace::open_new(&app_state, cx, |workspace, cx| {
Editor::new_file(workspace, &Default::default(), cx)
@@ -250,7 +249,7 @@ pub fn init(cx: &mut AppContext) {
}
});
cx.on_action(move |_: &workspace::NewWindow, cx| {
let app_state = cx.global::<Weak<workspace::AppState>>();
let app_state = workspace::AppState::global(cx);
if let Some(app_state) = app_state.upgrade() {
workspace::open_new(&app_state, cx, |workspace, cx| {
Editor::new_file(workspace, &Default::default(), cx)