Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
settings_ui: Add confirmation prompt before deleting a skill (#61044)
Smit Barmase4e36451a8c01
diff --git a/crates/settings_ui/src/pages/skills_setup.rs b/crates/settings_ui/src/pages/skills_setup.rsindex bf450c76c2f..3700467a5d6 100644--- a/crates/settings_ui/src/pages/skills_setup.rs+++ b/crates/settings_ui/src/pages/skills_setup.rs@@ -1,9 +1,10 @@-use agent_skills::{Skill, SkillIndex, encode_skill_share_link};+use agent_skills::{Skill, SkillIndex, SkillSource, encode_skill_share_link};use fs::RemoveOptions;-use gpui::{App, ClipboardItem, ScrollHandle, SharedString, prelude::*};+use gpui::{App, ClipboardItem, PromptLevel, ScrollHandle, SharedString, prelude::*};use ui::{Divider, Tooltip, prelude::*};use util::ResultExt as _;+use util::paths::PathExt as _;use crate::pages::SkillCreatorOpenMode;use crate::{SettingsUiFile, SettingsWindow};@@ -115,6 +116,12 @@ fn render_skill_row() -> AnyElement {let skill_file_path = skill.skill_file_path.clone();let directory_path = skill.directory_path.clone();+ let skill_name = skill.name.clone();++ let (skill_scope, shared_scope) = match &skill.source {+ SkillSource::ProjectLocal { .. } => ("project", "used in this project"),+ _ => ("global", "on this machine"),+ };let share_copied = settings_window.last_copied_skill_directory_path.as_deref()== Some(skill.directory_path.as_path());@@ -214,19 +221,53 @@ fn render_skill_row(.icon_size(IconSize::Small).tooltip(Tooltip::text("Delete Skill")).on_click(cx.listener(- move |settings_window, _event, _window, cx| {+ move |settings_window, _event, window, cx| {let directory_path = directory_path.clone();- if !settings_window+ if settings_window.hidden_deleted_skill_directory_paths- .insert(directory_path.clone())+ .contains(&directory_path){return;}- cx.notify();++ let prompt_message =+ format!("Delete the {skill_scope} skill \"{skill_name}\"?");+ let prompt_detail = format!(+ "This will move {} to the trash. This skill is shared with other \+ agent tools {shared_scope}, so it will no longer be available to \+ them either.",+ directory_path.compact().display(),+ );+ let answer = window.prompt(+ PromptLevel::Info,+ &prompt_message,+ Some(&prompt_detail),+ &["Delete", "Cancel"],+ cx,+ );let app_state = workspace::AppState::global(cx);let fs = app_state.fs.clone();cx.spawn(async move |settings_window, cx| {+ if answer.await != Ok(0) {+ return;+ }++ let confirmed = settings_window+ .update(cx, |settings_window, cx| {+ let inserted = settings_window+ .hidden_deleted_skill_directory_paths+ .insert(directory_path.clone());+ if inserted {+ cx.notify();+ }+ inserted+ })+ .unwrap_or(false);+ if !confirmed {+ return;+ }+let trash_result = fs.trash(&directory_path,