diff --git a/crates/python_ui/src/python_ui.rs b/crates/python_ui/src/python_ui.rs index 7ada5b8293..6520f30b3a 100644 --- a/crates/python_ui/src/python_ui.rs +++ b/crates/python_ui/src/python_ui.rs @@ -1,77 +1,11 @@ use db::kvp::Dismissable; use editor::Editor; -use gpui::{App, AppContext as _, Context, EventEmitter, Subscription}; +use gpui::{Context, EventEmitter, Subscription}; use ui::{ Banner, Button, Clickable, FluentBuilder as _, IconButton, IconName, InteractiveElement as _, - IntoElement, ParentElement as _, Render, Window, div, h_flex, + IntoElement, ParentElement as _, Render, Styled as _, Window, div, h_flex, }; -use workspace::{ - ToolbarItemEvent, ToolbarItemLocation, ToolbarItemView, Workspace, - notifications::{NotificationId, simple_message_notification::MessageNotification}, -}; - -impl Dismissable for BasedPyrightNote { - const KEY: &str = "basedpyright-note"; -} - -// pub fn init(cx: &mut App) { -// cx.observe_new(move |workspace: &mut Workspace, window, cx| { -// let Some(window) = window else { -// return; -// }; - -// cx.subscribe_in(workspace.project(), window, |_, _, event, window, cx| { -// if let project::Event::LanguageServerAdded(_, name, _) = event -// && name == "basedpyright" -// { -// if BasedPyrightNote::dismissed() { -// return; -// } - -// cx.on_next_frame(window, move |workspace, _, cx| { -// workspace.show_notification( -// NotificationId::unique::(), -// cx, -// |cx| { -// cx.new(move |cx| { -// MessageNotification::new( -// "basedpyright is now the default language server for Python", -// cx, -// ) -// .more_info_message("Learn More") -// .more_info_url("https://zed.dev/FIXME") -// // .primary_message("Yes, install extension") -// // .primary_icon(IconName::Check) -// // .primary_icon_color(Color::Success) -// // .primary_on_click({ -// // let extension_id = extension_id.clone(); -// // move |_window, cx| { -// // let extension_id = extension_id.clone(); -// // let extension_store = ExtensionStore::global(cx); -// // extension_store.update(cx, move |store, cx| { -// // store.install_latest_extension(extension_id, cx); -// // }); -// // } -// // }) -// // .secondary_message("No, don't install it") -// // .secondary_icon(IconName::Close) -// // .secondary_icon_color(Color::Error) -// // .secondary_on_click(move |_window, cx| { -// // let key = language_extension_key(&extension_id); -// // db::write_and_log(cx, move || { -// // KEY_VALUE_STORE.write_kvp(key, "dismissed".to_string()) -// // }); -// // }) -// }) -// }, -// ); -// }) -// } -// }) -// .detach(); -// }) -// .detach(); -// } +use workspace::{ToolbarItemEvent, ToolbarItemLocation, ToolbarItemView, Workspace}; pub struct BasedPyrightBanner { dismissed: bool, @@ -79,17 +13,22 @@ pub struct BasedPyrightBanner { _subscriptions: [Subscription; 1], } +impl Dismissable for BasedPyrightBanner { + const KEY: &str = "basedpyright-banner"; +} + impl BasedPyrightBanner { pub fn new(workspace: &Workspace, cx: &mut Context) -> Self { - let subscription = cx.subscribe(workspace.project(), |this, _, event, cx| { + let subscription = cx.subscribe(workspace.project(), |this, _, event, _| { if let project::Event::LanguageServerAdded(_, name, _) = event && name == "basedpyright" { this.have_basedpyright = true; } }); + let dismissed = Self::dismissed(); Self { - dismissed: false, + dismissed, have_basedpyright: false, _subscriptions: [subscription], } @@ -108,15 +47,21 @@ impl Render for BasedPyrightBanner { .severity(ui::Severity::Info) .child( h_flex() + .gap_2() .child("Basedpyright is now the default language server for Python") .child( Button::new("learn-more", "Learn More") - .icon(IconName::ArrowUpRight), + .icon(IconName::ArrowUpRight) + .on_click(|_, _, cx| { + // FIXME more specific link + cx.open_url("https://zed.dev/docs/languages/python") + }), ), ) .action_slot(IconButton::new("dismiss", IconName::Close).on_click( cx.listener(|this, _, _, cx| { this.dismissed = true; + Self::set_dismissed(true, cx); cx.notify(); }), )) @@ -130,17 +75,14 @@ impl ToolbarItemView for BasedPyrightBanner { fn set_active_pane_item( &mut self, active_pane_item: Option<&dyn workspace::ItemHandle>, - window: &mut ui::Window, + _window: &mut ui::Window, cx: &mut Context, ) -> ToolbarItemLocation { if let Some(item) = active_pane_item - && let Some(editor) = item.downcast::() - && let Some(buffer) = editor.read(cx).buffer().read(cx).as_singleton() - && let Some(file) = buffer.read(cx).file() - && file - .file_name(cx) - .as_encoded_bytes() - .ends_with(".py".as_bytes()) + && let Some(editor) = item.act_as::(cx) + && let Some(path) = editor.update(cx, |editor, cx| editor.target_file_abs_path(cx)) + && let Some(file_name) = path.file_name() + && file_name.as_encoded_bytes().ends_with(".py".as_bytes()) { return ToolbarItemLocation::Secondary; }