use galaxy_core::send_telemetry_from_ctx; use galaxyui::elements::{ChildView, Flex, ParentElement as _}; use galaxyui::{ AppContext, Element, Entity, FocusContext, TypedActionView, View, ViewContext, ViewHandle, }; use crate::coding_entrypoints::glowing_editor::{GlowingEditor, GlowingEditorEvent}; use crate::TelemetryEvent; pub struct CloneRepoView { editor: ViewHandle, is_ftux: bool, } pub enum CloneRepoEvent { SubmitPrompt(String), Cancel, } impl CloneRepoView { pub fn new(is_ftux: bool, ctx: &mut ViewContext) -> Self { let editor = ctx.add_typed_action_view(|ctx| { GlowingEditor::new( "Provide a repository URL e.g. \"git@github.com:username/project.git\"", ctx, ) }); ctx.subscribe_to_view(&editor, move |me, _, event, ctx| { me.handle_editor_event(event, ctx); }); Self { editor, is_ftux } } fn handle_editor_event(&mut self, event: &GlowingEditorEvent, ctx: &mut ViewContext) { match event { GlowingEditorEvent::Submit(prompt) => { send_telemetry_from_ctx!( TelemetryEvent::CloneRepoPromptSubmitted { is_ftux: self.is_ftux }, ctx ); ctx.emit(CloneRepoEvent::SubmitPrompt(prompt.clone())) } GlowingEditorEvent::Cancel => { self.editor.update(ctx, |editor, ctx| { editor.clear_buffer(ctx); }); ctx.emit(CloneRepoEvent::Cancel) } } } } impl Entity for CloneRepoView { type Event = CloneRepoEvent; } impl TypedActionView for CloneRepoView { type Action = (); } impl View for CloneRepoView { fn ui_name() -> &'static str { "CloneRepoView" } fn on_focus(&mut self, focus_ctx: &FocusContext, ctx: &mut ViewContext) { if focus_ctx.is_self_focused() { ctx.focus(&self.editor); } } fn render(&self, _app: &AppContext) -> Box { Flex::column() .with_child(ChildView::new(&self.editor).finish()) .finish() } }