finish drafting the banner
This commit is contained in:
parent
f697429456
commit
b290094f72
1 changed files with 22 additions and 80 deletions
|
@ -1,77 +1,11 @@
|
||||||
use db::kvp::Dismissable;
|
use db::kvp::Dismissable;
|
||||||
use editor::Editor;
|
use editor::Editor;
|
||||||
use gpui::{App, AppContext as _, Context, EventEmitter, Subscription};
|
use gpui::{Context, EventEmitter, Subscription};
|
||||||
use ui::{
|
use ui::{
|
||||||
Banner, Button, Clickable, FluentBuilder as _, IconButton, IconName, InteractiveElement as _,
|
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::{
|
use workspace::{ToolbarItemEvent, ToolbarItemLocation, ToolbarItemView, 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::<BasedPyrightNote>(),
|
|
||||||
// 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();
|
|
||||||
// }
|
|
||||||
|
|
||||||
pub struct BasedPyrightBanner {
|
pub struct BasedPyrightBanner {
|
||||||
dismissed: bool,
|
dismissed: bool,
|
||||||
|
@ -79,17 +13,22 @@ pub struct BasedPyrightBanner {
|
||||||
_subscriptions: [Subscription; 1],
|
_subscriptions: [Subscription; 1],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Dismissable for BasedPyrightBanner {
|
||||||
|
const KEY: &str = "basedpyright-banner";
|
||||||
|
}
|
||||||
|
|
||||||
impl BasedPyrightBanner {
|
impl BasedPyrightBanner {
|
||||||
pub fn new(workspace: &Workspace, cx: &mut Context<Self>) -> Self {
|
pub fn new(workspace: &Workspace, cx: &mut Context<Self>) -> 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
|
if let project::Event::LanguageServerAdded(_, name, _) = event
|
||||||
&& name == "basedpyright"
|
&& name == "basedpyright"
|
||||||
{
|
{
|
||||||
this.have_basedpyright = true;
|
this.have_basedpyright = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
let dismissed = Self::dismissed();
|
||||||
Self {
|
Self {
|
||||||
dismissed: false,
|
dismissed,
|
||||||
have_basedpyright: false,
|
have_basedpyright: false,
|
||||||
_subscriptions: [subscription],
|
_subscriptions: [subscription],
|
||||||
}
|
}
|
||||||
|
@ -108,15 +47,21 @@ impl Render for BasedPyrightBanner {
|
||||||
.severity(ui::Severity::Info)
|
.severity(ui::Severity::Info)
|
||||||
.child(
|
.child(
|
||||||
h_flex()
|
h_flex()
|
||||||
|
.gap_2()
|
||||||
.child("Basedpyright is now the default language server for Python")
|
.child("Basedpyright is now the default language server for Python")
|
||||||
.child(
|
.child(
|
||||||
Button::new("learn-more", "Learn More")
|
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(
|
.action_slot(IconButton::new("dismiss", IconName::Close).on_click(
|
||||||
cx.listener(|this, _, _, cx| {
|
cx.listener(|this, _, _, cx| {
|
||||||
this.dismissed = true;
|
this.dismissed = true;
|
||||||
|
Self::set_dismissed(true, cx);
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}),
|
}),
|
||||||
))
|
))
|
||||||
|
@ -130,17 +75,14 @@ impl ToolbarItemView for BasedPyrightBanner {
|
||||||
fn set_active_pane_item(
|
fn set_active_pane_item(
|
||||||
&mut self,
|
&mut self,
|
||||||
active_pane_item: Option<&dyn workspace::ItemHandle>,
|
active_pane_item: Option<&dyn workspace::ItemHandle>,
|
||||||
window: &mut ui::Window,
|
_window: &mut ui::Window,
|
||||||
cx: &mut Context<Self>,
|
cx: &mut Context<Self>,
|
||||||
) -> ToolbarItemLocation {
|
) -> ToolbarItemLocation {
|
||||||
if let Some(item) = active_pane_item
|
if let Some(item) = active_pane_item
|
||||||
&& let Some(editor) = item.downcast::<Editor>()
|
&& let Some(editor) = item.act_as::<Editor>(cx)
|
||||||
&& let Some(buffer) = editor.read(cx).buffer().read(cx).as_singleton()
|
&& let Some(path) = editor.update(cx, |editor, cx| editor.target_file_abs_path(cx))
|
||||||
&& let Some(file) = buffer.read(cx).file()
|
&& let Some(file_name) = path.file_name()
|
||||||
&& file
|
&& file_name.as_encoded_bytes().ends_with(".py".as_bytes())
|
||||||
.file_name(cx)
|
|
||||||
.as_encoded_bytes()
|
|
||||||
.ends_with(".py".as_bytes())
|
|
||||||
{
|
{
|
||||||
return ToolbarItemLocation::Secondary;
|
return ToolbarItemLocation::Secondary;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue