Skip to content

Commit

Permalink
chore: Upgrade for GPUI API changes. (#589)
Browse files Browse the repository at this point in the history
  • Loading branch information
huacnlee authored Jan 29, 2025
1 parent d2ff817 commit 6fa1888
Show file tree
Hide file tree
Showing 20 changed files with 79 additions and 79 deletions.
22 changes: 11 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions crates/story/src/modal_story.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ impl ModalStory {
.map(|s| Arc::new(s.to_string()))
.collect();

let story = cx.model().downgrade();
let story = cx.entity().downgrade();
let delegate = ListItemDeletegate {
story,
selected_index: None,
Expand Down Expand Up @@ -362,7 +362,7 @@ impl ModalStory {
let input1 = self.input1.clone();
let date_picker = self.date_picker.clone();
let dropdown = self.dropdown.clone();
let view = cx.model().clone();
let view = cx.entity().clone();
let keyboard = self.model_keyboard;

window.open_modal(cx, move |modal, _, _| {
Expand Down
6 changes: 3 additions & 3 deletions crates/story/src/scrollable_story.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ impl Render for ScrollableStory {
_: &mut gpui::Window,
cx: &mut gpui::Context<Self>,
) -> impl gpui::IntoElement {
let view = cx.model().clone();
let view = cx.entity().clone();

v_flex()
.size_full()
Expand All @@ -185,7 +185,7 @@ impl Render for ScrollableStory {
.size_full()
.child(
v_virtual_list(
cx.model().clone(),
cx.entity().clone(),
"items",
self.item_sizes.clone(),
move |story, visible_range, content_size, _, cx| {
Expand Down Expand Up @@ -270,7 +270,7 @@ impl Render for ScrollableStory {
.p_3()
.w(self.test_width)
.id("test-1")
.scrollable(cx.model().entity_id(), ScrollbarAxis::Vertical)
.scrollable(cx.entity().entity_id(), ScrollbarAxis::Vertical)
.gap_1()
.child("Scrollable Example")
.children(self.items.iter().take(500).map(|item| {
Expand Down
2 changes: 1 addition & 1 deletion crates/story/src/sidebar_story.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ impl Render for SidebarStory {
.border_color(cx.theme().border)
.h_full()
.child(
Sidebar::left(&cx.model())
Sidebar::left(&cx.entity())
.collapsed(self.is_collapsed)
.header(
SidebarHeader::new()
Expand Down
2 changes: 1 addition & 1 deletion crates/story/src/text_story.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ impl Render for TextStory {
Clipboard::new("clipboard1")
.content(|_, _| Label::new("Click icon to copy"))
.value_fn({
let view = cx.model().clone();
let view = cx.entity().clone();
move |_, cx| {
SharedString::from(format!(
"masked :{}",
Expand Down
2 changes: 1 addition & 1 deletion crates/ui/src/color_picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ impl Render for ColorPicker {
}
.into();

let view = cx.model().clone();
let view = cx.entity().clone();

div()
.id(self.id.clone())
Expand Down
8 changes: 4 additions & 4 deletions crates/ui/src/dock/dock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ impl Dock {
fn render_resize_handle(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let axis = self.placement.axis();
let neg_offset = -HANDLE_PADDING;
let view = cx.model().clone();
let view = cx.entity().clone();

div()
.id("resize-handle")
Expand Down Expand Up @@ -340,7 +340,7 @@ impl Dock {

// Get the size of the left dock if it's open and not the current dock
if let Some(left_dock) = &dock_area.left_dock {
if left_dock.entity_id() != cx.model().entity_id() {
if left_dock.entity_id() != cx.entity().entity_id() {
let left_dock_read = left_dock.read(cx);
if left_dock_read.is_open() {
left_dock_size = left_dock_read.size;
Expand All @@ -350,7 +350,7 @@ impl Dock {

// Get the size of the right dock if it's open and not the current dock
if let Some(right_dock) = &dock_area.right_dock {
if right_dock.entity_id() != cx.model().entity_id() {
if right_dock.entity_id() != cx.entity().entity_id() {
let right_dock_read = right_dock.read(cx);
if right_dock_read.is_open() {
right_dock_size = right_dock_read.size;
Expand Down Expand Up @@ -415,7 +415,7 @@ impl Render for Dock {
})
.child(self.render_resize_handle(window, cx))
.child(DockElement {
view: cx.model().clone(),
view: cx.entity().clone(),
})
}
}
Expand Down
14 changes: 7 additions & 7 deletions crates/ui/src/dock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ impl DockArea {
cx: &mut Context<Self>,
) {
self.subscribe_item(&panel, window, cx);
let weak_self = cx.model().downgrade();
let weak_self = cx.entity().downgrade();
self.left_dock = Some(cx.new(|cx| {
let mut dock = Dock::left(weak_self.clone(), window, cx);
if let Some(size) = size {
Expand All @@ -477,7 +477,7 @@ impl DockArea {
cx: &mut Context<Self>,
) {
self.subscribe_item(&panel, window, cx);
let weak_self = cx.model().downgrade();
let weak_self = cx.entity().downgrade();
self.bottom_dock = Some(cx.new(|cx| {
let mut dock = Dock::bottom(weak_self.clone(), window, cx);
if let Some(size) = size {
Expand All @@ -499,7 +499,7 @@ impl DockArea {
cx: &mut Context<Self>,
) {
self.subscribe_item(&panel, window, cx);
let weak_self = cx.model().downgrade();
let weak_self = cx.entity().downgrade();
self.right_dock = Some(cx.new(|cx| {
let mut dock = Dock::right(weak_self.clone(), window, cx);
if let Some(size) = size {
Expand Down Expand Up @@ -634,7 +634,7 @@ impl DockArea {
window: &mut Window,
cx: &mut Context<Self>,
) {
let weak_self = cx.model().downgrade();
let weak_self = cx.entity().downgrade();
match placement {
DockPlacement::Left => {
if let Some(dock) = self.left_dock.as_ref() {
Expand Down Expand Up @@ -677,7 +677,7 @@ impl DockArea {
}
DockPlacement::Center => {
self.items
.add_panel(panel, &cx.model().downgrade(), window, cx);
.add_panel(panel, &cx.entity().downgrade(), window, cx);
}
}
}
Expand All @@ -692,7 +692,7 @@ impl DockArea {
cx: &mut Context<Self>,
) -> Result<()> {
self.version = state.version;
let weak_self = cx.model().downgrade();
let weak_self = cx.entity().downgrade();

if let Some(left_dock_state) = state.left_dock {
self.left_dock = Some(left_dock_state.to_dock(weak_self.clone(), window, cx));
Expand Down Expand Up @@ -875,7 +875,7 @@ impl DockArea {
impl EventEmitter<DockEvent> for DockArea {}
impl Render for DockArea {
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let view = cx.model().clone();
let view = cx.entity().clone();

div()
.id("dock-area")
Expand Down
4 changes: 2 additions & 2 deletions crates/ui/src/dock/stack_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ impl StackPanel {
return;
}

let view = cx.model().clone();
let view = cx.entity().clone();
window.defer(cx, {
let panel = panel.clone();

Expand Down Expand Up @@ -300,7 +300,7 @@ impl StackPanel {
return;
}

let view = cx.model().clone();
let view = cx.entity().clone();
if let Some(parent) = self.parent.as_ref() {
_ = parent.update(cx, |parent, cx| {
parent.remove_panel(Arc::new(view.clone()), window, cx);
Expand Down
16 changes: 8 additions & 8 deletions crates/ui/src/dock/tab_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ impl TabPanel {
return;
}

let tab_view = cx.model().clone();
let tab_view = cx.entity().clone();
if let Some(stack_panel) = self.stack_panel.as_ref() {
_ = stack_panel.update(cx, |view, cx| {
view.remove_panel(Arc::new(tab_view), window, cx);
Expand Down Expand Up @@ -400,7 +400,7 @@ impl TabPanel {
cx: &mut Context<Self>,
) -> impl IntoElement {
let is_zoomed = self.is_zoomed;
let view = cx.model().clone();
let view = cx.entity().clone();
let zoomable_toolbar_visible = state.zoomable.map_or(false, |v| v.toolbar_visible());

// TODO: Do not show MenuButton if there is no menu items
Expand Down Expand Up @@ -480,7 +480,7 @@ impl TabPanel {
return None;
}

let view_entity_id = cx.model().entity_id();
let view_entity_id = cx.entity().entity_id();
let toggle_button_panels = dock_area.toggle_button_panels;

// Check if current TabPanel's entity_id matches the one stored in DockArea for this placement
Expand Down Expand Up @@ -553,7 +553,7 @@ impl TabPanel {
window: &mut Window,
cx: &mut Context<Self>,
) -> impl IntoElement {
let view = cx.model().clone();
let view = cx.entity().clone();

let Some(dock_area) = self.dock_area.upgrade() else {
return div().into_any_element();
Expand Down Expand Up @@ -838,7 +838,7 @@ impl TabPanel {
cx: &mut Context<Self>,
) {
let panel = drag.panel.clone();
let is_same_tab = drag.tab_panel == cx.model();
let is_same_tab = drag.tab_panel == cx.entity();

// If target is same tab, and it is only one panel, do nothing.
if is_same_tab && ix.is_none() {
Expand Down Expand Up @@ -904,7 +904,7 @@ impl TabPanel {

let ix = stack_panel
.read(cx)
.index_of_panel(Arc::new(cx.model().clone()))
.index_of_panel(Arc::new(cx.entity().clone()))
.unwrap_or_default();

if parent_axis.is_vertical() && placement.is_vertical() {
Expand Down Expand Up @@ -933,10 +933,10 @@ impl TabPanel {
});
} else {
// 1. Create new StackPanel with new axis
// 2. Move cx.model() from parent StackPanel to the new StackPanel
// 2. Move cx.entity() from parent StackPanel to the new StackPanel
// 3. Add the new TabPanel to the new StackPanel at the correct index
// 4. Add new StackPanel to the parent StackPanel at the correct index
let tab_panel = cx.model().clone();
let tab_panel = cx.entity().clone();

// Try to use the old stack panel, not just create a new one, to avoid too many nested stack panels
let new_stack_panel = if stack_panel.read(cx).panels_len() <= 1 {
Expand Down
2 changes: 1 addition & 1 deletion crates/ui/src/dock/tiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ impl EventEmitter<PanelEvent> for Tiles {}
impl EventEmitter<DismissEvent> for Tiles {}
impl Render for Tiles {
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let view = cx.model().clone();
let view = cx.entity().clone();
let view_id = view.entity_id();
let panels = self.sorted_panels();
let scroll_bounds =
Expand Down
4 changes: 2 additions & 2 deletions crates/ui/src/dropdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ where
let focus_handle = cx.focus_handle();
let delegate = DropdownListDelegate {
delegate,
dropdown: cx.model().downgrade(),
dropdown: cx.entity().downgrade(),
selected_index,
};

Expand Down Expand Up @@ -604,7 +604,7 @@ where
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let is_focused = self.focus_handle.is_focused(window);
let show_clean = self.cleanable && self.selected_index(cx).is_some();
let view = cx.model().clone();
let view = cx.entity().clone();
let bounds = self.bounds;
let allow_open = !(self.open || self.disabled);
let outline_visible = self.open || is_focused && !self.disabled;
Expand Down
Loading

0 comments on commit 6fa1888

Please sign in to comment.