From 754560876bba0ec62afd2a4aab76e999bc5da809 Mon Sep 17 00:00:00 2001 From: Danilo Leal <67129314+danilo-leal@users.noreply.github.com> Date: Wed, 12 Feb 2025 00:13:38 -0300 Subject: [PATCH] edit predictions: Refine the settings migration banner (#24706) Just a slight design touch-up on the settings migration banner. Release Notes: - N/A --- crates/zed/src/zed/migrate.rs | 153 ++++++++++++++++++---------------- 1 file changed, 81 insertions(+), 72 deletions(-) diff --git a/crates/zed/src/zed/migrate.rs b/crates/zed/src/zed/migrate.rs index d4a0b54f5be2f72924bec5eacb57e395c68735dc..58cbc0aa7017aabd3cd1821c211172caef2bb28e 100644 --- a/crates/zed/src/zed/migrate.rs +++ b/crates/zed/src/zed/migrate.rs @@ -1,16 +1,13 @@ use anyhow::{Context as _, Result}; use editor::Editor; use fs::Fs; -use markdown_preview::markdown_elements::ParsedMarkdown; -use markdown_preview::markdown_renderer::render_parsed_markdown; use migrator::{migrate_keymap, migrate_settings}; use settings::{KeymapFile, SettingsStore}; -use util::markdown::MarkdownString; use util::ResultExt; use std::sync::Arc; -use gpui::{Entity, EventEmitter, Global, WeakEntity}; +use gpui::{Entity, EventEmitter, Global}; use ui::prelude::*; use workspace::item::ItemHandle; use workspace::{ToolbarItemEvent, ToolbarItemLocation, ToolbarItemView, Workspace}; @@ -23,8 +20,6 @@ pub enum MigrationType { pub struct MigratorBanner { migration_type: Option, - message: ParsedMarkdown, - workspace: WeakEntity, } pub enum MigratorEvent { @@ -54,7 +49,7 @@ struct GlobalMigratorNotification(Entity); impl Global for GlobalMigratorNotification {} impl MigratorBanner { - pub fn new(workspace: &Workspace, cx: &mut Context<'_, Self>) -> Self { + pub fn new(_: &Workspace, cx: &mut Context<'_, Self>) -> Self { if let Some(notifier) = MigratorNotification::try_global(cx) { cx.subscribe( ¬ifier, @@ -66,10 +61,25 @@ impl MigratorBanner { } Self { migration_type: None, - message: ParsedMarkdown { children: vec![] }, - workspace: workspace.weak_handle(), } } + + fn backup_file_name(&self) -> String { + match self.migration_type { + Some(MigrationType::Keymap) => paths::keymap_backup_file() + .file_name() + .unwrap_or_default() + .to_string_lossy() + .into_owned(), + Some(MigrationType::Settings) => paths::settings_backup_file() + .file_name() + .unwrap_or_default() + .to_string_lossy() + .into_owned(), + None => String::new(), + } + } + fn handle_notification(&mut self, event: &MigratorEvent, cx: &mut Context<'_, Self>) { match event { MigratorEvent::ContentChanged { @@ -141,84 +151,83 @@ impl ToolbarItemView for MigratorBanner { .detach(); } - if let Some(migration_type) = self.migration_type { - cx.spawn_in(window, |this, mut cx| async move { - let message = MarkdownString(format!( - "Your {} require migration to support this version of Zed. A backup will be saved to {}.", - match migration_type { - MigrationType::Keymap => "keymap", - MigrationType::Settings => "settings", - }, - match migration_type { - MigrationType::Keymap => paths::keymap_backup_file().to_string_lossy(), - MigrationType::Settings => paths::settings_backup_file().to_string_lossy(), - }, - )); - let parsed_markdown = cx - .background_executor() - .spawn(async move { - let file_location_directory = None; - let language_registry = None; - markdown_preview::markdown_parser::parse_markdown( - &message.0, - file_location_directory, - language_registry, - ) - .await - }) - .await; - this - .update(&mut cx, |this, _| { - this.message = parsed_markdown; - }) - .log_err(); - }) - .detach(); - } - return ToolbarItemLocation::Hidden; } } impl Render for MigratorBanner { - fn render(&mut self, window: &mut Window, cx: &mut Context) -> impl IntoElement { + fn render(&mut self, _: &mut Window, cx: &mut Context) -> impl IntoElement { let migration_type = self.migration_type; + let file_type = match migration_type { + Some(MigrationType::Keymap) => "keymap", + Some(MigrationType::Settings) => "settings", + None => "", + }; + let backup_file_name = self.backup_file_name(); + h_flex() .py_1() - .px_2() + .pl_2() + .pr_1() + .flex_wrap() .justify_between() - .bg(cx.theme().status().info_background) + .bg(cx.theme().status().info_background.opacity(0.6)) + .border_1() + .border_color(cx.theme().colors().border_variant) .rounded_md() - .gap_2() .overflow_hidden() .child( - render_parsed_markdown(&self.message, Some(self.workspace.clone()), window, cx) - .text_ellipsis(), - ) - .child( - Button::new( - SharedString::from("backup-and-migrate"), - "Backup and Migrate", - ) - .style(ButtonStyle::Filled) - .on_click(move |_, _, cx| { - let fs = ::global(cx); - match migration_type { - Some(MigrationType::Keymap) => { - cx.spawn( - move |_| async move { write_keymap_migration(&fs).await.ok() }, + h_flex() + .gap_2() + .child( + Icon::new(IconName::Warning) + .size(IconSize::XSmall) + .color(Color::Warning), + ) + .child( + h_flex() + .gap_0p5() + .child( + Label::new(format!( + "Your {} file requires migration to support this version of Zed. A backup will be saved to", + file_type + )) + .color(Color::Default) ) - .detach(); - } - Some(MigrationType::Settings) => { - cx.spawn( - move |_| async move { write_settings_migration(&fs).await.ok() }, + .child( + div() + .px_1() + .bg(cx.theme().colors().background) + .rounded_sm() + .child( + Label::new(backup_file_name) + .buffer_font(cx) + .size(LabelSize::Small) + ), ) - .detach(); + ) + ) + .child( + Button::new("backup-and-migrate", "Backup and Migrate").on_click( + move |_, _, cx| { + let fs = ::global(cx); + match migration_type { + Some(MigrationType::Keymap) => { + cx.spawn( + move |_| async move { write_keymap_migration(&fs).await.ok() }, + ) + .detach(); + } + Some(MigrationType::Settings) => { + cx.spawn(move |_| async move { + write_settings_migration(&fs).await.ok() + }) + .detach(); + } + None => unreachable!(), } - None => unreachable!(), - } - }), + }, + ), ) .into_any_element() }