Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

gpui: Implement `From<String>` for ElementId (#44447)

Jason Lee4e75f0f3ab86
diff --git a/crates/agent_ui/src/acp/thread_view.rs b/crates/agent_ui/src/acp/thread_view.rs
index 7b2954c2eda..36fb7e90974 100644
--- a/crates/agent_ui/src/acp/thread_view.rs
+++ b/crates/agent_ui/src/acp/thread_view.rs
@@ -3509,7 +3509,7 @@ impl AcpThreadView {
(method.id.0.clone(), method.name.clone())
};
- Button::new(SharedString::from(method_id.clone()), name)
+ Button::new(method_id.clone(), name)
.label_size(LabelSize::Small)
.map(|this| {
if ix == 0 {
diff --git a/crates/agent_ui/src/agent_configuration.rs b/crates/agent_ui/src/agent_configuration.rs
index 3e4654af6e7..aa4cbc8e5b2 100644
--- a/crates/agent_ui/src/agent_configuration.rs
+++ b/crates/agent_ui/src/agent_configuration.rs
@@ -838,7 +838,7 @@ impl AgentConfiguration {
.min_w_0()
.child(
h_flex()
- .id(SharedString::from(format!("tooltip-{}", item_id)))
+ .id(format!("tooltip-{}", item_id))
.h_full()
.w_3()
.mr_2()
diff --git a/crates/agent_ui/src/agent_configuration/configure_context_server_tools_modal.rs b/crates/agent_ui/src/agent_configuration/configure_context_server_tools_modal.rs
index 3573c8b67ee..5115e2f70c0 100644
--- a/crates/agent_ui/src/agent_configuration/configure_context_server_tools_modal.rs
+++ b/crates/agent_ui/src/agent_configuration/configure_context_server_tools_modal.rs
@@ -87,7 +87,7 @@ impl ConfigureContextServerToolsModal {
v_flex()
.child(
h_flex()
- .id(SharedString::from(format!("tool-header-{}", index)))
+ .id(format!("tool-header-{}", index))
.py_1()
.pl_1()
.pr_2()
diff --git a/crates/agent_ui/src/agent_configuration/manage_profiles_modal.rs b/crates/agent_ui/src/agent_configuration/manage_profiles_modal.rs
index 7e03dc46b70..2f17349c3d1 100644
--- a/crates/agent_ui/src/agent_configuration/manage_profiles_modal.rs
+++ b/crates/agent_ui/src/agent_configuration/manage_profiles_modal.rs
@@ -422,7 +422,7 @@ impl ManageProfilesModal {
let is_focused = profile.navigation.focus_handle.contains_focused(window, cx);
div()
- .id(SharedString::from(format!("profile-{}", profile.id)))
+ .id(format!("profile-{}", profile.id))
.track_focus(&profile.navigation.focus_handle)
.on_action({
let profile_id = profile.id.clone();
@@ -431,7 +431,7 @@ impl ManageProfilesModal {
})
})
.child(
- ListItem::new(SharedString::from(format!("profile-{}", profile.id)))
+ ListItem::new(format!("profile-{}", profile.id))
.toggle_state(is_focused)
.inset(true)
.spacing(ListItemSpacing::Sparse)
diff --git a/crates/agent_ui/src/profile_selector.rs b/crates/agent_ui/src/profile_selector.rs
index c1949d22e26..0182be0912d 100644
--- a/crates/agent_ui/src/profile_selector.rs
+++ b/crates/agent_ui/src/profile_selector.rs
@@ -542,7 +542,7 @@ impl PickerDelegate for ProfilePickerDelegate {
let is_active = active_id == candidate.id;
Some(
- ListItem::new(SharedString::from(candidate.id.0.clone()))
+ ListItem::new(candidate.id.0.clone())
.inset(true)
.spacing(ListItemSpacing::Sparse)
.toggle_state(selected)
diff --git a/crates/debugger_ui/src/attach_modal.rs b/crates/debugger_ui/src/attach_modal.rs
index 64146169f53..6e537ae0c6e 100644
--- a/crates/debugger_ui/src/attach_modal.rs
+++ b/crates/debugger_ui/src/attach_modal.rs
@@ -317,7 +317,7 @@ impl PickerDelegate for AttachModalDelegate {
let candidate = self.candidates.get(hit.candidate_id)?;
Some(
- ListItem::new(SharedString::from(format!("process-entry-{ix}")))
+ ListItem::new(format!("process-entry-{ix}"))
.inset(true)
.spacing(ListItemSpacing::Sparse)
.toggle_state(selected)
@@ -327,7 +327,7 @@ impl PickerDelegate for AttachModalDelegate {
.child(Label::new(format!("{} {}", candidate.name, candidate.pid)))
.child(
div()
- .id(SharedString::from(format!("process-entry-{ix}-command")))
+ .id(format!("process-entry-{ix}-command"))
.tooltip(Tooltip::text(
candidate
.command
diff --git a/crates/debugger_ui/src/new_process_modal.rs b/crates/debugger_ui/src/new_process_modal.rs
index 24f6cc8f341..8aaa61aad63 100644
--- a/crates/debugger_ui/src/new_process_modal.rs
+++ b/crates/debugger_ui/src/new_process_modal.rs
@@ -1519,7 +1519,7 @@ impl PickerDelegate for DebugDelegate {
});
Some(
- ListItem::new(SharedString::from(format!("debug-scenario-selection-{ix}")))
+ ListItem::new(format!("debug-scenario-selection-{ix}"))
.inset(true)
.start_slot::<IconWithIndicator>(icon)
.spacing(ListItemSpacing::Sparse)
diff --git a/crates/debugger_ui/src/session/running.rs b/crates/debugger_ui/src/session/running.rs
index bc99d6ac8e4..66e9dd7b434 100644
--- a/crates/debugger_ui/src/session/running.rs
+++ b/crates/debugger_ui/src/session/running.rs
@@ -286,10 +286,10 @@ impl Item for SubView {
impl Render for SubView {
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
v_flex()
- .id(SharedString::from(format!(
+ .id(format!(
"subview-container-{}",
self.kind.to_shared_string()
- )))
+ ))
.on_hover(cx.listener(|this, hovered, _, cx| {
this.hovered = *hovered;
cx.notify();
@@ -484,10 +484,7 @@ pub(crate) fn new_debugger_pane(
let deemphasized = !pane.has_focus(window, cx);
let item_ = item.boxed_clone();
div()
- .id(SharedString::from(format!(
- "debugger_tab_{}",
- item.item_id().as_u64()
- )))
+ .id(format!("debugger_tab_{}", item.item_id().as_u64()))
.p_1()
.rounded_md()
.cursor_pointer()
diff --git a/crates/git_ui/src/branch_picker.rs b/crates/git_ui/src/branch_picker.rs
index e198fa092e0..90b5c4bb284 100644
--- a/crates/git_ui/src/branch_picker.rs
+++ b/crates/git_ui/src/branch_picker.rs
@@ -911,7 +911,7 @@ impl PickerDelegate for BranchListDelegate {
});
Some(
- ListItem::new(SharedString::from(format!("vcs-menu-{ix}")))
+ ListItem::new(format!("vcs-menu-{ix}"))
.inset(true)
.spacing(ListItemSpacing::Sparse)
.toggle_state(selected)
diff --git a/crates/git_ui/src/picker_prompt.rs b/crates/git_ui/src/picker_prompt.rs
index 6161c62af57..14daedda61e 100644
--- a/crates/git_ui/src/picker_prompt.rs
+++ b/crates/git_ui/src/picker_prompt.rs
@@ -220,7 +220,7 @@ impl PickerDelegate for PickerPromptDelegate {
let shortened_option = util::truncate_and_trailoff(&hit.string, self.max_match_length);
Some(
- ListItem::new(SharedString::from(format!("picker-prompt-menu-{ix}")))
+ ListItem::new(format!("picker-prompt-menu-{ix}"))
.inset(true)
.spacing(ListItemSpacing::Sparse)
.toggle_state(selected)
diff --git a/crates/git_ui/src/stash_picker.rs b/crates/git_ui/src/stash_picker.rs
index fd81176a127..6d0a9d291e4 100644
--- a/crates/git_ui/src/stash_picker.rs
+++ b/crates/git_ui/src/stash_picker.rs
@@ -464,7 +464,7 @@ impl PickerDelegate for StashListDelegate {
);
Some(
- ListItem::new(SharedString::from(format!("stash-{ix}")))
+ ListItem::new(format!("stash-{ix}"))
.inset(true)
.spacing(ListItemSpacing::Sparse)
.toggle_state(selected)
diff --git a/crates/git_ui/src/worktree_picker.rs b/crates/git_ui/src/worktree_picker.rs
index d1231b51e3a..f6b3e47dec3 100644
--- a/crates/git_ui/src/worktree_picker.rs
+++ b/crates/git_ui/src/worktree_picker.rs
@@ -665,7 +665,7 @@ impl PickerDelegate for WorktreeListDelegate {
};
Some(
- ListItem::new(SharedString::from(format!("worktree-menu-{ix}")))
+ ListItem::new(format!("worktree-menu-{ix}"))
.inset(true)
.spacing(ListItemSpacing::Sparse)
.toggle_state(selected)
diff --git a/crates/gpui/examples/painting.rs b/crates/gpui/examples/painting.rs
index e7055cbdbbd..9f15d12f469 100644
--- a/crates/gpui/examples/painting.rs
+++ b/crates/gpui/examples/painting.rs
@@ -1,7 +1,7 @@
use gpui::{
Application, Background, Bounds, ColorSpace, Context, MouseDownEvent, Path, PathBuilder,
- PathStyle, Pixels, Point, Render, SharedString, StrokeOptions, Window, WindowOptions, canvas,
- div, linear_color_stop, linear_gradient, point, prelude::*, px, quad, rgb, size,
+ PathStyle, Pixels, Point, Render, StrokeOptions, Window, WindowOptions, canvas, div,
+ linear_color_stop, linear_gradient, point, prelude::*, px, quad, rgb, size,
};
struct PaintingViewer {
@@ -309,7 +309,7 @@ fn button(
on_click: impl Fn(&mut PaintingViewer, &mut Context<PaintingViewer>) + 'static,
) -> impl IntoElement {
div()
- .id(SharedString::from(text.to_string()))
+ .id(text.to_string())
.child(text.to_string())
.bg(gpui::black())
.text_color(gpui::white())
diff --git a/crates/gpui/examples/window.rs b/crates/gpui/examples/window.rs
index 4445f24e4ec..06003c4663e 100644
--- a/crates/gpui/examples/window.rs
+++ b/crates/gpui/examples/window.rs
@@ -1,6 +1,6 @@
use gpui::{
- App, Application, Bounds, Context, KeyBinding, PromptButton, PromptLevel, SharedString, Timer,
- Window, WindowBounds, WindowKind, WindowOptions, actions, div, prelude::*, px, rgb, size,
+ App, Application, Bounds, Context, KeyBinding, PromptButton, PromptLevel, Timer, Window,
+ WindowBounds, WindowKind, WindowOptions, actions, div, prelude::*, px, rgb, size,
};
struct SubWindow {
@@ -9,7 +9,7 @@ struct SubWindow {
fn button(text: &str, on_click: impl Fn(&mut Window, &mut App) + 'static) -> impl IntoElement {
div()
- .id(SharedString::from(text.to_string()))
+ .id(text.to_string())
.flex_none()
.px_2()
.bg(rgb(0xf7f7f7))
diff --git a/crates/gpui/src/window.rs b/crates/gpui/src/window.rs
index 2d525adb8f8..69bf583057f 100644
--- a/crates/gpui/src/window.rs
+++ b/crates/gpui/src/window.rs
@@ -5084,6 +5084,18 @@ impl From<SharedString> for ElementId {
}
}
+impl From<String> for ElementId {
+ fn from(name: String) -> Self {
+ ElementId::Name(name.into())
+ }
+}
+
+impl From<Arc<str>> for ElementId {
+ fn from(name: Arc<str>) -> Self {
+ ElementId::Name(name.into())
+ }
+}
+
impl From<Arc<std::path::Path>> for ElementId {
fn from(path: Arc<std::path::Path>) -> Self {
ElementId::Path(path)
diff --git a/crates/livekit_client/examples/test_app.rs b/crates/livekit_client/examples/test_app.rs
index 7b9b0183a08..a4d815aa9be 100644
--- a/crates/livekit_client/examples/test_app.rs
+++ b/crates/livekit_client/examples/test_app.rs
@@ -378,7 +378,7 @@ impl Render for LivekitWindow {
.when_some(state.audio_output_stream.as_ref(), |el, state| {
el.child(
button()
- .id(SharedString::from(identity.0.clone()))
+ .id(identity.0.clone())
.child(if state.0.is_enabled() {
"Deafen"
} else {
diff --git a/crates/tasks_ui/src/modal.rs b/crates/tasks_ui/src/modal.rs
index 0497512b762..644f82285b2 100644
--- a/crates/tasks_ui/src/modal.rs
+++ b/crates/tasks_ui/src/modal.rs
@@ -5,8 +5,8 @@ use editor::Editor;
use fuzzy::{StringMatch, StringMatchCandidate};
use gpui::{
Action, AnyElement, App, AppContext as _, Context, DismissEvent, Entity, EventEmitter,
- Focusable, InteractiveElement, ParentElement, Render, SharedString, Styled, Subscription, Task,
- WeakEntity, Window, rems,
+ Focusable, InteractiveElement, ParentElement, Render, Styled, Subscription, Task, WeakEntity,
+ Window, rems,
};
use itertools::Itertools;
use picker::{Picker, PickerDelegate, highlighted_match_with_paths::HighlightedMatch};
@@ -526,7 +526,7 @@ impl PickerDelegate for TasksModalDelegate {
};
Some(
- ListItem::new(SharedString::from(format!("tasks-modal-{ix}")))
+ ListItem::new(format!("tasks-modal-{ix}"))
.inset(true)
.start_slot::<IconWithIndicator>(icon)
.end_slot::<AnyElement>(
diff --git a/crates/title_bar/src/application_menu.rs b/crates/title_bar/src/application_menu.rs
index 01a12260ad0..817b73c45ec 100644
--- a/crates/title_bar/src/application_menu.rs
+++ b/crates/title_bar/src/application_menu.rs
@@ -151,10 +151,10 @@ impl ApplicationMenu {
// Application menu must have same ids as first menu item in standard menu
div()
- .id(SharedString::from(format!("{}-menu-item", menu_name)))
+ .id(format!("{}-menu-item", menu_name))
.occlude()
.child(
- PopoverMenu::new(SharedString::from(format!("{}-menu-popover", menu_name)))
+ PopoverMenu::new(format!("{}-menu-popover", menu_name))
.menu(move |window, cx| {
Self::build_menu_from_items(entry.clone(), window, cx).into()
})
@@ -184,10 +184,10 @@ impl ApplicationMenu {
.collect();
div()
- .id(SharedString::from(format!("{}-menu-item", menu_name)))
+ .id(format!("{}-menu-item", menu_name))
.occlude()
.child(
- PopoverMenu::new(SharedString::from(format!("{}-menu-popover", menu_name)))
+ PopoverMenu::new(format!("{}-menu-popover", menu_name))
.menu(move |window, cx| {
Self::build_menu_from_items(entry.clone(), window, cx).into()
})