This commit is contained in:
Nathan Sobo 2023-04-11 18:48:00 -06:00
parent e115baa60c
commit e6cc132b19
14 changed files with 119 additions and 83 deletions

View file

@ -3,7 +3,8 @@ use gpui::{
elements::*,
geometry::rect::RectF,
platform::{WindowBounds, WindowKind, WindowOptions},
AppContext, ClipboardItem, Element, Entity, View, ViewContext, ViewHandle,
AnyViewHandle, AppContext, ClipboardItem, Element, ElementBox, Entity, View, ViewContext,
ViewHandle,
};
use settings::Settings;
use theme::ui::modal;
@ -28,9 +29,9 @@ pub fn init(cx: &mut AppContext) {
if let Some(code_verification_handle) = code_verification.as_mut() {
if cx.has_window(code_verification_handle.window_id()) {
code_verification_handle.update(cx, |code_verification_view, cx| {
code_verification_view.set_status(status, cx)
code_verification_view.set_status(status, cx);
cx.activate_window();
});
cx.activate_window(code_verification_handle.window_id());
} else {
create_copilot_auth_window(cx, &status, &mut code_verification);
}
@ -41,11 +42,11 @@ pub fn init(cx: &mut AppContext) {
Status::Authorized | Status::Unauthorized => {
if let Some(code_verification) = code_verification.as_ref() {
code_verification.update(cx, |code_verification, cx| {
code_verification.set_status(status, cx)
code_verification.set_status(status, cx);
cx.activate_window();
});
cx.platform().activate(true);
cx.activate_window(code_verification.window_id());
}
}
_ => {
@ -96,8 +97,8 @@ impl CopilotCodeVerification {
fn render_device_code(
data: &PromptUserDeviceFlow,
style: &theme::Copilot,
cx: &mut gpui::ViewContext<Self>,
) -> ElementBox {
cx: &mut ViewContext<Self>,
) -> ElementBox<Self> {
let copied = cx
.read_from_clipboard()
.map(|item| item.text() == &data.user_code)
@ -105,7 +106,7 @@ impl CopilotCodeVerification {
let device_code_style = &style.auth.prompting.device_code;
MouseEventHandler::<Self>::new(0, cx, |state, _cx| {
MouseEventHandler::<Self, _>::new(0, cx, |state, _cx| {
Flex::row()
.with_children([
Label::new(data.user_code.clone(), device_code_style.text.clone())
@ -132,7 +133,7 @@ impl CopilotCodeVerification {
})
.on_click(gpui::platform::MouseButton::Left, {
let user_code = data.user_code.clone();
move |_, cx| {
move |_, _, cx| {
cx.platform()
.write_to_clipboard(ClipboardItem::new(user_code.clone()));
cx.notify();
@ -145,8 +146,10 @@ impl CopilotCodeVerification {
fn render_prompting_modal(
data: &PromptUserDeviceFlow,
style: &theme::Copilot,
cx: &mut gpui::ViewContext<Self>,
) -> ElementBox {
cx: &mut ViewContext<Self>,
) -> ElementBox<Self> {
enum ConnectButton {}
Flex::column()
.with_children([
Flex::column()
@ -188,14 +191,14 @@ impl CopilotCodeVerification {
.contained()
.with_style(style.auth.prompting.hint.container.clone())
.boxed(),
theme::ui::cta_button_with_click(
theme::ui::cta_button_with_click::<ConnectButton, _, _, _>(
"Connect to GitHub",
style.auth.content_width,
&style.auth.cta_button,
cx,
{
let verification_uri = data.verification_uri.clone();
move |_, cx| cx.platform().open_url(&verification_uri)
move |_, _, cx| cx.platform().open_url(&verification_uri)
},
)
.boxed(),
@ -205,8 +208,10 @@ impl CopilotCodeVerification {
}
fn render_enabled_modal(
style: &theme::Copilot,
cx: &mut gpui::ViewContext<Self>,
) -> ElementBox {
cx: &mut ViewContext<Self>,
) -> ElementBox<Self> {
enum DoneButton {}
let enabled_style = &style.auth.authorized;
Flex::column()
.with_children([
@ -237,12 +242,12 @@ impl CopilotCodeVerification {
.contained()
.with_style(enabled_style.hint.container)
.boxed(),
theme::ui::cta_button_with_click(
theme::ui::cta_button_with_click::<DoneButton, _, _, _>(
"Done",
style.auth.content_width,
&style.auth.cta_button,
cx,
|_, cx| {
|_, _, cx| {
let window_id = cx.window_id();
cx.remove_window(window_id)
},
@ -254,8 +259,8 @@ impl CopilotCodeVerification {
}
fn render_unauthorized_modal(
style: &theme::Copilot,
cx: &mut gpui::ViewContext<Self>,
) -> ElementBox {
cx: &mut ViewContext<Self>,
) -> ElementBox<Self> {
let unauthorized_style = &style.auth.not_authorized;
Flex::column()
@ -298,12 +303,12 @@ impl CopilotCodeVerification {
.contained()
.with_style(unauthorized_style.warning.container)
.boxed(),
theme::ui::cta_button_with_click(
theme::ui::cta_button_with_click::<CopilotCodeVerification, _, _, _>(
"Subscribe on GitHub",
style.auth.content_width,
&style.auth.cta_button,
cx,
|_, cx| {
|_, _, cx| {
let window_id = cx.window_id();
cx.remove_window(window_id);
cx.platform().open_url(COPILOT_SIGN_UP_URL)
@ -325,18 +330,20 @@ impl View for CopilotCodeVerification {
"CopilotCodeVerification"
}
fn focus_in(&mut self, _: gpui::AnyViewHandle, cx: &mut gpui::ViewContext<Self>) {
fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
cx.notify()
}
fn focus_out(&mut self, _: gpui::AnyViewHandle, cx: &mut gpui::ViewContext<Self>) {
fn focus_out(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
cx.notify()
}
fn render(&mut self, cx: &mut gpui::ViewContext<'_, Self>) -> gpui::ElementBox {
fn render(&mut self, cx: &mut ViewContext<Self>) -> ElementBox<Self> {
enum ConnectModal {}
let style = cx.global::<Settings>().theme.clone();
modal("Connect Copilot to Zed", &style.copilot.modal, cx, |cx| {
modal::<ConnectModal, _, _, _>("Connect Copilot to Zed", &style.copilot.modal, cx, |cx| {
Flex::column()
.with_children([
theme::ui::icon(&style.copilot.auth.header).boxed(),