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

Jason Lee created

Release Notes:

- N/A

## Before

```rs
div()
    .id(SharedString::from(format!("process-entry-{ix}-command")))
```

## After

```rs
div()
    .id(format!("process-entry-{ix}-command"))
```

Change summary

crates/agent_ui/src/acp/thread_view.rs                                          |  2 
crates/agent_ui/src/agent_configuration.rs                                      |  2 
crates/agent_ui/src/agent_configuration/configure_context_server_tools_modal.rs |  2 
crates/agent_ui/src/agent_configuration/manage_profiles_modal.rs                |  4 
crates/agent_ui/src/profile_selector.rs                                         |  2 
crates/debugger_ui/src/attach_modal.rs                                          |  4 
crates/debugger_ui/src/new_process_modal.rs                                     |  2 
crates/debugger_ui/src/session/running.rs                                       |  9 
crates/git_ui/src/branch_picker.rs                                              |  2 
crates/git_ui/src/picker_prompt.rs                                              |  2 
crates/git_ui/src/stash_picker.rs                                               |  2 
crates/git_ui/src/worktree_picker.rs                                            |  2 
crates/gpui/examples/painting.rs                                                |  6 
crates/gpui/examples/window.rs                                                  |  6 
crates/gpui/src/window.rs                                                       | 12 
crates/livekit_client/examples/test_app.rs                                      |  2 
crates/tasks_ui/src/modal.rs                                                    |  6 
crates/title_bar/src/application_menu.rs                                        |  8 
18 files changed, 42 insertions(+), 33 deletions(-)

Detailed changes

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 {

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()

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)

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)

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

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)

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()

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)

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)

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)

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)

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())

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))

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)

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 {

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>(

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()
                     })