Fix up warnings, bind 'Done' button to DismissEvent

This commit is contained in:
Piotr Osiewicz 2024-01-05 16:32:47 +01:00
parent 0ce94fc791
commit 0670a6f838
2 changed files with 15 additions and 13 deletions

View file

@ -376,9 +376,11 @@ fn initiate_sign_in(cx: &mut WindowContext) {
} }
_ => { _ => {
copilot.update(cx, |this, cx| this.sign_in(cx)).detach(); copilot.update(cx, |this, cx| this.sign_in(cx)).detach();
workspace.update(cx, |this, cx| { workspace
this.toggle_modal(cx, |cx| CopilotCodeVerification::new(&copilot, cx)); .update(cx, |this, cx| {
}); this.toggle_modal(cx, |cx| CopilotCodeVerification::new(&copilot, cx));
})
.ok();
} }
} }
} }

View file

@ -1,17 +1,14 @@
use copilot::{request::PromptUserDeviceFlow, Copilot, Status}; use copilot::{request::PromptUserDeviceFlow, Copilot, Status};
use gpui::{ use gpui::{
div, size, svg, AppContext, Bounds, ClipboardItem, DismissEvent, Element, EventEmitter, div, svg, AppContext, ClipboardItem, DismissEvent, Element, EventEmitter, FocusHandle,
FocusHandle, FocusableView, GlobalPixels, InteractiveElement, IntoElement, Model, FocusableView, InteractiveElement, IntoElement, Model, ParentElement, Render, Styled,
ParentElement, Point, Render, Styled, Subscription, ViewContext, VisualContext, WindowBounds, Subscription, ViewContext,
WindowHandle, WindowKind, WindowOptions,
}; };
use ui::{prelude::*, Button, Icon, Label}; use ui::{prelude::*, Button, Icon, Label};
use workspace::ModalView; use workspace::ModalView;
const COPILOT_SIGN_UP_URL: &'static str = "https://github.com/features/copilot"; const COPILOT_SIGN_UP_URL: &'static str = "https://github.com/features/copilot";
pub fn init(cx: &mut AppContext) {}
pub struct CopilotCodeVerification { pub struct CopilotCodeVerification {
status: Status, status: Status,
connect_clicked: bool, connect_clicked: bool,
@ -20,7 +17,7 @@ pub struct CopilotCodeVerification {
} }
impl FocusableView for CopilotCodeVerification { impl FocusableView for CopilotCodeVerification {
fn focus_handle(&self, cx: &AppContext) -> gpui::FocusHandle { fn focus_handle(&self, _: &AppContext) -> gpui::FocusHandle {
self.focus_handle.clone() self.focus_handle.clone()
} }
} }
@ -111,13 +108,16 @@ impl CopilotCodeVerification {
.style(ButtonStyle::Filled), .style(ButtonStyle::Filled),
) )
} }
fn render_enabled_modal() -> impl Element { fn render_enabled_modal(cx: &mut ViewContext<Self>) -> impl Element {
v_stack() v_stack()
.child(Label::new("Copilot Enabled!")) .child(Label::new("Copilot Enabled!"))
.child(Label::new( .child(Label::new(
"You can update your settings or sign out from the Copilot menu in the status bar.", "You can update your settings or sign out from the Copilot menu in the status bar.",
)) ))
.child(Button::new("copilot-enabled-done-button", "Done").on_click(|_, cx| {})) .child(
Button::new("copilot-enabled-done-button", "Done")
.on_click(cx.listener(|_, _, cx| cx.emit(DismissEvent))),
)
} }
fn render_unauthorized_modal() -> impl Element { fn render_unauthorized_modal() -> impl Element {
@ -148,7 +148,7 @@ impl Render for CopilotCodeVerification {
} }
Status::Authorized => { Status::Authorized => {
self.connect_clicked = false; self.connect_clicked = false;
Self::render_enabled_modal().into_any_element() Self::render_enabled_modal(cx).into_any_element()
} }
_ => div().into_any_element(), _ => div().into_any_element(),
}; };