Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/shell/src/engine/quickjs/window_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ pub(super) fn install(ctx: &Ctx<'_>) -> JsResult<()> {
"__window_activate",
Func::from(|ctx: Ctx<'_>| -> JsResult<()> {
write(&ctx, "window.activate_window()", |window, _| {
window.activate_window()
window.activate()
})
}),
)?;
Expand Down
2 changes: 1 addition & 1 deletion crates/shell/src/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1372,7 +1372,7 @@ mod tests {
let (root, cx) = shell_root(cx);
// Timeouts only run while the window is active, so the test has to say
// that it is.
cx.update(|window, _| window.activate_window());
cx.update(|window, _| window.activate());
cx.run_until_parked();

root.update_in(cx, |root, window, cx| {
Expand Down
2 changes: 1 addition & 1 deletion crates/story/examples/dock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ impl StoryWorkspace {

window
.update(cx, |_, window, cx| {
window.activate_window();
window.activate();
window.set_window_title("GPUI App");
cx.on_release(|_, cx| {
// exit app
Expand Down
2 changes: 1 addition & 1 deletion crates/story/examples/tiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ impl StoryTiles {

window
.update(cx, |_, window, _| {
window.activate_window();
window.activate();
window.set_window_title("Story Tiles");
})
.expect("failed to update window");
Expand Down
2 changes: 1 addition & 1 deletion crates/story/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ pub fn create_new_window_with_size<F, E>(
.expect("failed to open window");

window.update(cx, |_, window, _| {
window.activate_window();
window.activate();
window.set_window_title(&title);
})?;

Expand Down
10 changes: 5 additions & 5 deletions crates/ui/src/native_menu/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use std::{cell::Cell, sync::Arc};

use gpui::{Action, App, AssetSource, Pixels, Point, SharedString, Window};
use gpui::{Action, App, AssetRegistry, Pixels, Point, SharedString, Window};
use objc2::rc::Retained;
use objc2::runtime::{AnyObject, NSObject};
use objc2::{AnyThread, DefinedClass, MainThreadMarker, define_class, msg_send, sel};
Expand Down Expand Up @@ -52,7 +52,7 @@ impl MenuTarget {
/// borrowed while the menu is open.
pub(super) fn show(
items: Vec<NativeMenuItem>,
asset_source: Arc<dyn AssetSource>,
asset_source: Arc<AssetRegistry>,
position: Point<Pixels>,
window: &mut Window,
cx: &mut App,
Expand Down Expand Up @@ -88,7 +88,7 @@ pub(super) fn show(
fn run_menu(
view_ptr: usize,
items: &[NativeMenuItem],
asset_source: &dyn AssetSource,
asset_source: &AssetRegistry,
position: Point<Pixels>,
) -> Option<Box<dyn Action>> {
let mtm = MainThreadMarker::new()?;
Expand Down Expand Up @@ -121,7 +121,7 @@ fn run_menu(
/// to its index in `actions`, so the selected tag maps back to its action.
fn build_menu<'a>(
items: &'a [NativeMenuItem],
asset_source: &dyn AssetSource,
asset_source: &AssetRegistry,
target: &MenuTarget,
mtm: MainThreadMarker,
actions: &mut Vec<&'a Box<dyn Action>>,
Expand Down Expand Up @@ -187,7 +187,7 @@ fn build_menu<'a>(

fn ns_image_for_icon(
path: &SharedString,
asset_source: &dyn AssetSource,
asset_source: &AssetRegistry,
) -> Option<Retained<NSImage>> {
let image = resolve_icon_image(path, asset_source)?;
if image.bytes.is_empty() {
Expand Down
40 changes: 16 additions & 24 deletions crates/ui/src/native_menu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use crate::ActiveTheme as _;
use crate::Icon;

#[cfg(any(target_os = "macos", target_os = "windows"))]
use gpui::AssetSource;
use gpui::AssetRegistry;
use gpui::{Action, App, Pixels, Point, SharedString, Window};
#[cfg(any(target_os = "macos", target_os = "windows"))]
use gpui::{Image, ImageFormat};
Expand Down Expand Up @@ -202,13 +202,13 @@ impl NativeMenu {

#[cfg(target_os = "macos")]
{
macos::show(self.items, cx.asset_source().clone(), position, window, cx);
macos::show(self.items, cx.assets().clone(), position, window, cx);
}
#[cfg(target_os = "windows")]
{
windows::show(
self.items,
cx.asset_source().clone(),
cx.assets().clone(),
position,
cx.theme().is_dark(),
window,
Expand All @@ -223,7 +223,7 @@ impl NativeMenu {
#[cfg(any(target_os = "macos", target_os = "windows"))]
pub(super) fn resolve_icon_image(
path: &SharedString,
asset_source: &dyn AssetSource,
asset_source: &AssetRegistry,
) -> Option<Arc<Image>> {
if path.is_empty() {
return None;
Expand All @@ -234,11 +234,7 @@ pub(super) fn resolve_icon_image(
let bytes = if icon_path.is_absolute() {
std::fs::read(icon_path).ok()?
} else {
asset_source
.load(path.as_ref())
.ok()
.flatten()?
.into_owned()
asset_source.load(path.as_ref())?.into_owned()
};
let format = image_format(path.as_ref(), &bytes)?;
Some(Arc::new(Image::from_bytes(format, bytes)))
Expand Down Expand Up @@ -411,16 +407,9 @@ mod tests {
const ASSET_SVG: &[u8] = br#"<svg xmlns="http://www.w3.org/2000/svg"/>"#;
const FILE_SVG: &[u8] = br#"<svg xmlns="http://www.w3.org/2000/svg"><path/></svg>"#;

struct TestAssetSource(Option<&'static [u8]>);

impl AssetSource for TestAssetSource {
fn load(&self, _path: &str) -> gpui::Result<Option<Cow<'static, [u8]>>> {
Ok(self.0.map(Cow::Borrowed))
}

fn list(&self, _path: &str) -> gpui::Result<Vec<SharedString>> {
Ok(Vec::new())
}
/// Assets holding only `path`, with the given contents.
fn assets_with(path: &SharedString, bytes: &'static [u8]) -> AssetRegistry {
[(path.clone(), Cow::Borrowed(bytes))].into_iter().collect()
}

/// A file written into the current directory for the duration of one test.
Expand Down Expand Up @@ -452,8 +441,11 @@ mod tests {
#[test]
fn test_native_menu_icon_asset_resolves_to_bytes() {
let icon = Icon::new(IconName::Github);
let image = resolve_icon_image(icon.path_ref(), &gpui_component_assets::Assets)
.expect("icon asset should resolve");
let image = resolve_icon_image(
icon.path_ref(),
&AssetRegistry::from(gpui_component_assets::Assets),
)
.expect("icon asset should resolve");

assert_eq!(image.format, ImageFormat::Svg);
assert!(!image.bytes.is_empty());
Expand All @@ -464,11 +456,11 @@ mod tests {
let path: SharedString = "native-menu-relative-shadow-test.svg".into();
let _file = TestIconFile::create(path.as_ref(), FILE_SVG);

let image = resolve_icon_image(&path, &TestAssetSource(Some(ASSET_SVG)))
let image = resolve_icon_image(&path, &assets_with(&path, ASSET_SVG))
.expect("relative icon should resolve from the asset source");
assert_eq!(image.bytes, ASSET_SVG);

assert!(resolve_icon_image(&path, &TestAssetSource(None)).is_none());
assert!(resolve_icon_image(&path, &AssetRegistry::default()).is_none());
}

#[test]
Expand All @@ -479,7 +471,7 @@ mod tests {
let _file = TestIconFile::create(&path, FILE_SVG);
let path: SharedString = path.to_string_lossy().into_owned().into();

let image = resolve_icon_image(&path, &TestAssetSource(Some(ASSET_SVG)))
let image = resolve_icon_image(&path, &assets_with(&path, ASSET_SVG))
.expect("absolute icon should resolve from the filesystem");
assert_eq!(image.bytes, FILE_SVG);
}
Expand Down
10 changes: 5 additions & 5 deletions crates/ui/src/native_menu/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{
sync::{Arc, OnceLock},
};

use gpui::{Action, App, AssetSource, ImageFormat, Pixels, Point, SharedString, Window};
use gpui::{Action, App, AssetRegistry, ImageFormat, Pixels, Point, SharedString, Window};
use raw_window_handle::{HasWindowHandle, RawWindowHandle};
use windows::Win32::Foundation::{BOOL, GlobalFree, HANDLE, HWND, POINT};
use windows::Win32::Graphics::Gdi::{
Expand Down Expand Up @@ -39,7 +39,7 @@ const MENU_IMAGE_SIZE: u32 = 16;
/// run from a foreground task to avoid re-entering GPUI while it is borrowed.
pub(super) fn show(
items: Vec<NativeMenuItem>,
asset_source: Arc<dyn AssetSource>,
asset_source: Arc<AssetRegistry>,
position: Point<Pixels>,
dark_mode: bool,
window: &mut Window,
Expand Down Expand Up @@ -85,7 +85,7 @@ pub(super) fn show(
fn run_menu(
hwnd: isize,
items: &[NativeMenuItem],
asset_source: &dyn AssetSource,
asset_source: &AssetRegistry,
client_x: i32,
client_y: i32,
image_px: u32,
Expand Down Expand Up @@ -187,7 +187,7 @@ unsafe fn apply_menu_theme(hwnd: HWND, dark_mode: bool) {
/// Win32 menu creation; the returned `HMENU` must be destroyed by the caller.
unsafe fn build_menu<'a>(
items: &'a [NativeMenuItem],
asset_source: &dyn AssetSource,
asset_source: &AssetRegistry,
actions: &mut Vec<&'a Box<dyn Action>>,
bitmaps: &mut Vec<HBITMAP>,
image_px: u32,
Expand Down Expand Up @@ -317,7 +317,7 @@ impl Drop for GdiplusSession {
/// Calls GDI+ /GDI flat APIs; the returned handle is owned by the caller.
unsafe fn load_hbitmap(
path: &SharedString,
asset_source: &dyn AssetSource,
asset_source: &AssetRegistry,
image_px: u32,
) -> Option<HBITMAP> {
let image = resolve_icon_image(path, asset_source)?;
Expand Down
12 changes: 6 additions & 6 deletions crates/ui/src/notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ impl SystemNotificationRegistry {
// Errs when the window is already closed: the entry is removed and the
// application is still brought to the foreground.
let _ = entry.window.update(cx, |_, window, cx| {
window.activate_window();
window.activate();
if let Some(list) = entry.list.upgrade() {
// No-op when the toast already closed or was never created
// (system-only delivery).
Expand Down Expand Up @@ -1121,7 +1121,7 @@ mod tests {
list: cx.new(|cx| NotificationList::new(window, cx)),
other_focus: cx.focus_handle(),
});
cx.update(|window, _| window.activate_window());
cx.update(|window, _| window.activate());
let list = root.read_with(cx, |root, _| root.list.clone());

// The left stack is pushed first, so it owns the lower group index.
Expand Down Expand Up @@ -1167,7 +1167,7 @@ mod tests {
list: cx.new(|cx| NotificationList::new(window, cx)),
other_focus: cx.focus_handle(),
});
cx.update(|window, _| window.activate_window());
cx.update(|window, _| window.activate());
let list = root.read_with(cx, |root, _| root.list.clone());

list.update_in(cx, |list, window, cx| {
Expand Down Expand Up @@ -1215,7 +1215,7 @@ mod tests {
list: cx.new(|cx| NotificationList::new(window, cx)),
other_focus: cx.focus_handle(),
});
cx.update(|window, _| window.activate_window());
cx.update(|window, _| window.activate());
let list = root.read_with(cx, |root, _| root.list.clone());

list.update_in(cx, |list, window, cx| {
Expand Down Expand Up @@ -1277,7 +1277,7 @@ mod tests {

let list_focus = list.read_with(cx, |list, _| list.focus_handle.clone());
cx.update(|window, cx| {
window.activate_window();
window.activate();
list_focus.focus(window, cx);
window.draw(cx).clear(cx);
});
Expand Down Expand Up @@ -1578,7 +1578,7 @@ mod tests {
list: cx.new(|cx| NotificationList::new(window, cx)),
other_focus: cx.focus_handle(),
});
cx.update(|window, _| window.activate_window());
cx.update(|window, _| window.activate());
let list = root.read_with(cx, |r, _| r.list.clone());

// Autohide expiry leaves the system notification in the center.
Expand Down
6 changes: 3 additions & 3 deletions crates/ui/src/text/format/html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -754,8 +754,8 @@ mod tests {
#[test]
fn test_value_to_length() {
assert_eq!(super::value_to_length("100px"), Some(px(100.).into()));
assert_eq!(super::value_to_length("100%"), Some(relative(1.)));
assert_eq!(super::value_to_length("56%"), Some(relative(0.56)));
assert_eq!(super::value_to_length("100%"), Some(relative(1.).into()));
assert_eq!(super::value_to_length("56%"), Some(relative(0.56).into()));
assert_eq!(super::value_to_length("240"), Some(px(240.).into()));
}

Expand Down Expand Up @@ -794,7 +794,7 @@ mod tests {
children: vec![InlineNode::image(ImageNode {
url: "https://example.com/image.png".to_string().into(),
alt: Some("Example".to_string().into()),
width: Some(relative(0.8)),
width: Some(relative(0.8).into()),
height: None,
title: Some("Example Image".to_string().into()),
..Default::default()
Expand Down
2 changes: 1 addition & 1 deletion examples/fps_monitor/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ fn main() {

cx.spawn(async move |cx| {
cx.open_window(WindowOptions::default(), |window, cx| {
window.activate_window();
window.activate();
window.set_window_title("FPS Monitor");
cx.new(|cx| Example::new(window, cx))
})
Expand Down
2 changes: 1 addition & 1 deletion examples/system_monitor/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ fn main() {

cx.spawn(async move |cx| {
cx.open_window(window_options, |window, cx| {
window.activate_window();
window.activate();
window.set_window_title("System Monitor");

Theme::change(ThemeMode::Dark, Some(window), cx);
Expand Down