1use std::any::Any;
  2
  3use ::settings::Settings;
  4use command_palette_hooks::CommandPaletteFilter;
  5use commit_modal::CommitModal;
  6use editor::{Editor, actions::DiffClipboardWithSelectionData};
  7use ui::{
  8    Headline, HeadlineSize, Icon, IconName, IconSize, IntoElement, ParentElement, Render, Styled,
  9    StyledExt, div, h_flex, rems, v_flex,
 10};
 11
 12mod blame_ui;
 13
 14use git::{
 15    repository::{Branch, Upstream, UpstreamTracking, UpstreamTrackingStatus},
 16    status::{FileStatus, StatusCode, UnmergedStatus, UnmergedStatusCode},
 17};
 18use git_panel_settings::GitPanelSettings;
 19use gpui::{
 20    Action, App, Context, DismissEvent, Entity, EventEmitter, FocusHandle, Focusable, SharedString,
 21    Window, actions,
 22};
 23use menu::{Cancel, Confirm};
 24use onboarding::GitOnboardingModal;
 25use project::git_store::Repository;
 26use project_diff::ProjectDiff;
 27use ui::prelude::*;
 28use workspace::{ModalView, Workspace, notifications::DetachAndPromptErr};
 29use zed_actions;
 30
 31use crate::{git_panel::GitPanel, text_diff_view::TextDiffView};
 32
 33mod askpass_modal;
 34pub mod branch_picker;
 35mod commit_modal;
 36pub mod commit_tooltip;
 37pub mod commit_view;
 38mod conflict_view;
 39pub mod file_diff_view;
 40pub mod git_panel;
 41mod git_panel_settings;
 42pub mod onboarding;
 43pub mod picker_prompt;
 44pub mod project_diff;
 45pub(crate) mod remote_output;
 46pub mod repository_selector;
 47pub mod stash_picker;
 48pub mod text_diff_view;
 49
 50actions!(
 51    git,
 52    [
 53        /// Resets the git onboarding state to show the tutorial again.
 54        ResetOnboarding
 55    ]
 56);
 57
 58pub fn init(cx: &mut App) {
 59    GitPanelSettings::register(cx);
 60
 61    editor::set_blame_renderer(blame_ui::GitBlameRenderer, cx);
 62    commit_view::init(cx);
 63
 64    cx.observe_new(|editor: &mut Editor, _, cx| {
 65        conflict_view::register_editor(editor, editor.buffer().clone(), cx);
 66    })
 67    .detach();
 68
 69    cx.observe_new(|workspace: &mut Workspace, _, cx| {
 70        ProjectDiff::register(workspace, cx);
 71        CommitModal::register(workspace);
 72        git_panel::register(workspace);
 73        repository_selector::register(workspace);
 74        branch_picker::register(workspace);
 75        stash_picker::register(workspace);
 76
 77        let project = workspace.project().read(cx);
 78        if project.is_read_only(cx) {
 79            return;
 80        }
 81        if !project.is_via_collab() {
 82            workspace.register_action(|workspace, _: &git::Fetch, window, cx| {
 83                let Some(panel) = workspace.panel::<git_panel::GitPanel>(cx) else {
 84                    return;
 85                };
 86                panel.update(cx, |panel, cx| {
 87                    panel.fetch(true, window, cx);
 88                });
 89            });
 90            workspace.register_action(|workspace, _: &git::FetchFrom, window, cx| {
 91                let Some(panel) = workspace.panel::<git_panel::GitPanel>(cx) else {
 92                    return;
 93                };
 94                panel.update(cx, |panel, cx| {
 95                    panel.fetch(false, window, cx);
 96                });
 97            });
 98            workspace.register_action(|workspace, _: &git::Push, window, cx| {
 99                let Some(panel) = workspace.panel::<git_panel::GitPanel>(cx) else {
100                    return;
101                };
102                panel.update(cx, |panel, cx| {
103                    panel.push(false, false, window, cx);
104                });
105            });
106            workspace.register_action(|workspace, _: &git::PushTo, window, cx| {
107                let Some(panel) = workspace.panel::<git_panel::GitPanel>(cx) else {
108                    return;
109                };
110                panel.update(cx, |panel, cx| {
111                    panel.push(false, true, window, cx);
112                });
113            });
114            workspace.register_action(|workspace, _: &git::ForcePush, window, cx| {
115                let Some(panel) = workspace.panel::<git_panel::GitPanel>(cx) else {
116                    return;
117                };
118                panel.update(cx, |panel, cx| {
119                    panel.push(true, false, window, cx);
120                });
121            });
122            workspace.register_action(|workspace, _: &git::Pull, window, cx| {
123                let Some(panel) = workspace.panel::<git_panel::GitPanel>(cx) else {
124                    return;
125                };
126                panel.update(cx, |panel, cx| {
127                    panel.pull(window, cx);
128                });
129            });
130        }
131        workspace.register_action(|workspace, action: &git::StashAll, window, cx| {
132            let Some(panel) = workspace.panel::<git_panel::GitPanel>(cx) else {
133                return;
134            };
135            panel.update(cx, |panel, cx| {
136                panel.stash_all(action, window, cx);
137            });
138        });
139        workspace.register_action(|workspace, action: &git::StashPop, window, cx| {
140            let Some(panel) = workspace.panel::<git_panel::GitPanel>(cx) else {
141                return;
142            };
143            panel.update(cx, |panel, cx| {
144                panel.stash_pop(action, window, cx);
145            });
146        });
147        workspace.register_action(|workspace, action: &git::StashApply, window, cx| {
148            let Some(panel) = workspace.panel::<git_panel::GitPanel>(cx) else {
149                return;
150            };
151            panel.update(cx, |panel, cx| {
152                panel.stash_apply(action, window, cx);
153            });
154        });
155        workspace.register_action(|workspace, action: &git::StageAll, window, cx| {
156            let Some(panel) = workspace.panel::<git_panel::GitPanel>(cx) else {
157                return;
158            };
159            panel.update(cx, |panel, cx| {
160                panel.stage_all(action, window, cx);
161            });
162        });
163        workspace.register_action(|workspace, action: &git::UnstageAll, window, cx| {
164            let Some(panel) = workspace.panel::<git_panel::GitPanel>(cx) else {
165                return;
166            };
167            panel.update(cx, |panel, cx| {
168                panel.unstage_all(action, window, cx);
169            });
170        });
171        workspace.register_action(|workspace, _: &git::Uncommit, window, cx| {
172            let Some(panel) = workspace.panel::<git_panel::GitPanel>(cx) else {
173                return;
174            };
175            panel.update(cx, |panel, cx| {
176                panel.uncommit(window, cx);
177            })
178        });
179        CommandPaletteFilter::update_global(cx, |filter, _cx| {
180            filter.hide_action_types(&[
181                zed_actions::OpenGitIntegrationOnboarding.type_id(),
182                // ResetOnboarding.type_id(),
183            ]);
184        });
185        workspace.register_action(
186            move |workspace, _: &zed_actions::OpenGitIntegrationOnboarding, window, cx| {
187                GitOnboardingModal::toggle(workspace, window, cx)
188            },
189        );
190        workspace.register_action(move |_, _: &ResetOnboarding, window, cx| {
191            window.dispatch_action(workspace::RestoreBanner.boxed_clone(), cx);
192            window.refresh();
193        });
194        workspace.register_action(|workspace, _action: &git::Init, window, cx| {
195            let Some(panel) = workspace.panel::<git_panel::GitPanel>(cx) else {
196                return;
197            };
198            panel.update(cx, |panel, cx| {
199                panel.git_init(window, cx);
200            });
201        });
202        workspace.register_action(|workspace, _action: &git::Clone, window, cx| {
203            let Some(panel) = workspace.panel::<git_panel::GitPanel>(cx) else {
204                return;
205            };
206
207            workspace.toggle_modal(window, cx, |window, cx| {
208                GitCloneModal::show(panel, window, cx)
209            });
210        });
211        workspace.register_action(|workspace, _: &git::OpenModifiedFiles, window, cx| {
212            open_modified_files(workspace, window, cx);
213        });
214        workspace.register_action(|workspace, _: &git::RenameBranch, window, cx| {
215            rename_current_branch(workspace, window, cx);
216        });
217        workspace.register_action(
218            |workspace, action: &DiffClipboardWithSelectionData, window, cx| {
219                if let Some(task) = TextDiffView::open(action, workspace, window, cx) {
220                    task.detach();
221                };
222            },
223        );
224    })
225    .detach();
226}
227
228fn open_modified_files(
229    workspace: &mut Workspace,
230    window: &mut Window,
231    cx: &mut Context<Workspace>,
232) {
233    let Some(panel) = workspace.panel::<git_panel::GitPanel>(cx) else {
234        return;
235    };
236    let modified_paths: Vec<_> = panel.update(cx, |panel, cx| {
237        let Some(repo) = panel.active_repository.as_ref() else {
238            return Vec::new();
239        };
240        let repo = repo.read(cx);
241        repo.cached_status()
242            .filter_map(|entry| {
243                if entry.status.is_modified() {
244                    repo.repo_path_to_project_path(&entry.repo_path, cx)
245                } else {
246                    None
247                }
248            })
249            .collect()
250    });
251    for path in modified_paths {
252        workspace.open_path(path, None, true, window, cx).detach();
253    }
254}
255
256pub fn git_status_icon(status: FileStatus) -> impl IntoElement {
257    GitStatusIcon::new(status)
258}
259
260struct RenameBranchModal {
261    current_branch: SharedString,
262    editor: Entity<Editor>,
263    repo: Entity<Repository>,
264}
265
266impl RenameBranchModal {
267    fn new(
268        current_branch: String,
269        repo: Entity<Repository>,
270        window: &mut Window,
271        cx: &mut Context<Self>,
272    ) -> Self {
273        let editor = cx.new(|cx| {
274            let mut editor = Editor::single_line(window, cx);
275            editor.set_text(current_branch.clone(), window, cx);
276            editor
277        });
278        Self {
279            current_branch: current_branch.into(),
280            editor,
281            repo,
282        }
283    }
284
285    fn cancel(&mut self, _: &Cancel, _window: &mut Window, cx: &mut Context<Self>) {
286        cx.emit(DismissEvent);
287    }
288
289    fn confirm(&mut self, _: &Confirm, window: &mut Window, cx: &mut Context<Self>) {
290        let new_name = self.editor.read(cx).text(cx);
291        if new_name.is_empty() || new_name == self.current_branch.as_ref() {
292            cx.emit(DismissEvent);
293            return;
294        }
295
296        let repo = self.repo.clone();
297        let current_branch = self.current_branch.to_string();
298        cx.spawn(async move |_, cx| {
299            match repo
300                .update(cx, |repo, _| {
301                    repo.rename_branch(current_branch, new_name.clone())
302                })?
303                .await
304            {
305                Ok(Ok(_)) => Ok(()),
306                Ok(Err(error)) => Err(error),
307                Err(_) => Err(anyhow::anyhow!("Operation was canceled")),
308            }
309        })
310        .detach_and_prompt_err("Failed to rename branch", window, cx, |_, _, _| None);
311        cx.emit(DismissEvent);
312    }
313}
314
315impl EventEmitter<DismissEvent> for RenameBranchModal {}
316impl ModalView for RenameBranchModal {}
317impl Focusable for RenameBranchModal {
318    fn focus_handle(&self, cx: &App) -> FocusHandle {
319        self.editor.focus_handle(cx)
320    }
321}
322
323impl Render for RenameBranchModal {
324    fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
325        v_flex()
326            .key_context("RenameBranchModal")
327            .on_action(cx.listener(Self::cancel))
328            .on_action(cx.listener(Self::confirm))
329            .elevation_2(cx)
330            .w(rems(34.))
331            .child(
332                h_flex()
333                    .px_3()
334                    .pt_2()
335                    .pb_1()
336                    .w_full()
337                    .gap_1p5()
338                    .child(Icon::new(IconName::GitBranch).size(IconSize::XSmall))
339                    .child(
340                        Headline::new(format!("Rename Branch ({})", self.current_branch))
341                            .size(HeadlineSize::XSmall),
342                    ),
343            )
344            .child(div().px_3().pb_3().w_full().child(self.editor.clone()))
345    }
346}
347
348fn rename_current_branch(
349    workspace: &mut Workspace,
350    window: &mut Window,
351    cx: &mut Context<Workspace>,
352) {
353    let Some(panel) = workspace.panel::<git_panel::GitPanel>(cx) else {
354        return;
355    };
356    let current_branch: Option<String> = panel.update(cx, |panel, cx| {
357        let repo = panel.active_repository.as_ref()?;
358        let repo = repo.read(cx);
359        repo.branch.as_ref().map(|branch| branch.name().to_string())
360    });
361
362    let Some(current_branch_name) = current_branch else {
363        return;
364    };
365
366    let repo = panel.read(cx).active_repository.clone();
367    let Some(repo) = repo else {
368        return;
369    };
370
371    workspace.toggle_modal(window, cx, |window, cx| {
372        RenameBranchModal::new(current_branch_name, repo, window, cx)
373    });
374}
375
376fn render_remote_button(
377    id: impl Into<SharedString>,
378    branch: &Branch,
379    keybinding_target: Option<FocusHandle>,
380    show_fetch_button: bool,
381) -> Option<impl IntoElement> {
382    let id = id.into();
383    let upstream = branch.upstream.as_ref();
384    match upstream {
385        Some(Upstream {
386            tracking: UpstreamTracking::Tracked(UpstreamTrackingStatus { ahead, behind }),
387            ..
388        }) => match (*ahead, *behind) {
389            (0, 0) if show_fetch_button => {
390                Some(remote_button::render_fetch_button(keybinding_target, id))
391            }
392            (0, 0) => None,
393            (ahead, 0) => Some(remote_button::render_push_button(
394                keybinding_target,
395                id,
396                ahead,
397            )),
398            (ahead, behind) => Some(remote_button::render_pull_button(
399                keybinding_target,
400                id,
401                ahead,
402                behind,
403            )),
404        },
405        Some(Upstream {
406            tracking: UpstreamTracking::Gone,
407            ..
408        }) => Some(remote_button::render_republish_button(
409            keybinding_target,
410            id,
411        )),
412        None => Some(remote_button::render_publish_button(keybinding_target, id)),
413    }
414}
415
416mod remote_button {
417    use gpui::{Action, AnyView, ClickEvent, Corner, FocusHandle};
418    use ui::{
419        App, ButtonCommon, Clickable, ContextMenu, ElementId, FluentBuilder, Icon, IconName,
420        IconSize, IntoElement, Label, LabelCommon, LabelSize, LineHeightStyle, ParentElement,
421        PopoverMenu, SharedString, SplitButton, Styled, Tooltip, Window, div, h_flex, rems,
422    };
423
424    pub fn render_fetch_button(
425        keybinding_target: Option<FocusHandle>,
426        id: SharedString,
427    ) -> SplitButton {
428        split_button(
429            id,
430            "Fetch",
431            0,
432            0,
433            Some(IconName::ArrowCircle),
434            keybinding_target.clone(),
435            move |_, window, cx| {
436                window.dispatch_action(Box::new(git::Fetch), cx);
437            },
438            move |_window, cx| {
439                git_action_tooltip(
440                    "Fetch updates from remote",
441                    &git::Fetch,
442                    "git fetch",
443                    keybinding_target.clone(),
444                    cx,
445                )
446            },
447        )
448    }
449
450    pub fn render_push_button(
451        keybinding_target: Option<FocusHandle>,
452        id: SharedString,
453        ahead: u32,
454    ) -> SplitButton {
455        split_button(
456            id,
457            "Push",
458            ahead as usize,
459            0,
460            None,
461            keybinding_target.clone(),
462            move |_, window, cx| {
463                window.dispatch_action(Box::new(git::Push), cx);
464            },
465            move |_window, cx| {
466                git_action_tooltip(
467                    "Push committed changes to remote",
468                    &git::Push,
469                    "git push",
470                    keybinding_target.clone(),
471                    cx,
472                )
473            },
474        )
475    }
476
477    pub fn render_pull_button(
478        keybinding_target: Option<FocusHandle>,
479        id: SharedString,
480        ahead: u32,
481        behind: u32,
482    ) -> SplitButton {
483        split_button(
484            id,
485            "Pull",
486            ahead as usize,
487            behind as usize,
488            None,
489            keybinding_target.clone(),
490            move |_, window, cx| {
491                window.dispatch_action(Box::new(git::Pull), cx);
492            },
493            move |_window, cx| {
494                git_action_tooltip(
495                    "Pull",
496                    &git::Pull,
497                    "git pull",
498                    keybinding_target.clone(),
499                    cx,
500                )
501            },
502        )
503    }
504
505    pub fn render_publish_button(
506        keybinding_target: Option<FocusHandle>,
507        id: SharedString,
508    ) -> SplitButton {
509        split_button(
510            id,
511            "Publish",
512            0,
513            0,
514            Some(IconName::ExpandUp),
515            keybinding_target.clone(),
516            move |_, window, cx| {
517                window.dispatch_action(Box::new(git::Push), cx);
518            },
519            move |_window, cx| {
520                git_action_tooltip(
521                    "Publish branch to remote",
522                    &git::Push,
523                    "git push --set-upstream",
524                    keybinding_target.clone(),
525                    cx,
526                )
527            },
528        )
529    }
530
531    pub fn render_republish_button(
532        keybinding_target: Option<FocusHandle>,
533        id: SharedString,
534    ) -> SplitButton {
535        split_button(
536            id,
537            "Republish",
538            0,
539            0,
540            Some(IconName::ExpandUp),
541            keybinding_target.clone(),
542            move |_, window, cx| {
543                window.dispatch_action(Box::new(git::Push), cx);
544            },
545            move |_window, cx| {
546                git_action_tooltip(
547                    "Re-publish branch to remote",
548                    &git::Push,
549                    "git push --set-upstream",
550                    keybinding_target.clone(),
551                    cx,
552                )
553            },
554        )
555    }
556
557    fn git_action_tooltip(
558        label: impl Into<SharedString>,
559        action: &dyn Action,
560        command: impl Into<SharedString>,
561        focus_handle: Option<FocusHandle>,
562        cx: &mut App,
563    ) -> AnyView {
564        let label = label.into();
565        let command = command.into();
566
567        if let Some(handle) = focus_handle {
568            Tooltip::with_meta_in(label, Some(action), command, &handle, cx)
569        } else {
570            Tooltip::with_meta(label, Some(action), command, cx)
571        }
572    }
573
574    fn render_git_action_menu(
575        id: impl Into<ElementId>,
576        keybinding_target: Option<FocusHandle>,
577    ) -> impl IntoElement {
578        PopoverMenu::new(id.into())
579            .trigger(
580                ui::ButtonLike::new_rounded_right("split-button-right")
581                    .layer(ui::ElevationIndex::ModalSurface)
582                    .size(ui::ButtonSize::None)
583                    .child(
584                        div()
585                            .px_1()
586                            .child(Icon::new(IconName::ChevronDown).size(IconSize::XSmall)),
587                    ),
588            )
589            .menu(move |window, cx| {
590                Some(ContextMenu::build(window, cx, |context_menu, _, _| {
591                    context_menu
592                        .when_some(keybinding_target.clone(), |el, keybinding_target| {
593                            el.context(keybinding_target)
594                        })
595                        .action("Fetch", git::Fetch.boxed_clone())
596                        .action("Fetch From", git::FetchFrom.boxed_clone())
597                        .action("Pull", git::Pull.boxed_clone())
598                        .separator()
599                        .action("Push", git::Push.boxed_clone())
600                        .action("Push To", git::PushTo.boxed_clone())
601                        .action("Force Push", git::ForcePush.boxed_clone())
602                }))
603            })
604            .anchor(Corner::TopRight)
605    }
606
607    #[allow(clippy::too_many_arguments)]
608    fn split_button(
609        id: SharedString,
610        left_label: impl Into<SharedString>,
611        ahead_count: usize,
612        behind_count: usize,
613        left_icon: Option<IconName>,
614        keybinding_target: Option<FocusHandle>,
615        left_on_click: impl Fn(&ClickEvent, &mut Window, &mut App) + 'static,
616        tooltip: impl Fn(&mut Window, &mut App) -> AnyView + 'static,
617    ) -> SplitButton {
618        fn count(count: usize) -> impl IntoElement {
619            h_flex()
620                .ml_neg_px()
621                .h(rems(0.875))
622                .items_center()
623                .overflow_hidden()
624                .px_0p5()
625                .child(
626                    Label::new(count.to_string())
627                        .size(LabelSize::XSmall)
628                        .line_height_style(LineHeightStyle::UiLabel),
629                )
630        }
631
632        let should_render_counts = left_icon.is_none() && (ahead_count > 0 || behind_count > 0);
633
634        let left = ui::ButtonLike::new_rounded_left(ElementId::Name(
635            format!("split-button-left-{}", id).into(),
636        ))
637        .layer(ui::ElevationIndex::ModalSurface)
638        .size(ui::ButtonSize::Compact)
639        .when(should_render_counts, |this| {
640            this.child(
641                h_flex()
642                    .ml_neg_0p5()
643                    .when(behind_count > 0, |this| {
644                        this.child(Icon::new(IconName::ArrowDown).size(IconSize::XSmall))
645                            .child(count(behind_count))
646                    })
647                    .when(ahead_count > 0, |this| {
648                        this.child(Icon::new(IconName::ArrowUp).size(IconSize::XSmall))
649                            .child(count(ahead_count))
650                    }),
651            )
652        })
653        .when_some(left_icon, |this, left_icon| {
654            this.child(
655                h_flex()
656                    .ml_neg_0p5()
657                    .child(Icon::new(left_icon).size(IconSize::XSmall)),
658            )
659        })
660        .child(
661            div()
662                .child(Label::new(left_label).size(LabelSize::Small))
663                .mr_0p5(),
664        )
665        .on_click(left_on_click)
666        .tooltip(tooltip);
667
668        let right = render_git_action_menu(
669            ElementId::Name(format!("split-button-right-{}", id).into()),
670            keybinding_target,
671        )
672        .into_any_element();
673
674        SplitButton::new(left, right)
675    }
676}
677
678/// A visual representation of a file's Git status.
679#[derive(IntoElement, RegisterComponent)]
680pub struct GitStatusIcon {
681    status: FileStatus,
682}
683
684impl GitStatusIcon {
685    pub fn new(status: FileStatus) -> Self {
686        Self { status }
687    }
688}
689
690impl RenderOnce for GitStatusIcon {
691    fn render(self, _window: &mut ui::Window, cx: &mut App) -> impl IntoElement {
692        let status = self.status;
693
694        let (icon_name, color) = if status.is_conflicted() {
695            (
696                IconName::Warning,
697                cx.theme().colors().version_control_conflict,
698            )
699        } else if status.is_deleted() {
700            (
701                IconName::SquareMinus,
702                cx.theme().colors().version_control_deleted,
703            )
704        } else if status.is_modified() {
705            (
706                IconName::SquareDot,
707                cx.theme().colors().version_control_modified,
708            )
709        } else {
710            (
711                IconName::SquarePlus,
712                cx.theme().colors().version_control_added,
713            )
714        };
715
716        Icon::new(icon_name).color(Color::Custom(color))
717    }
718}
719
720// View this component preview using `workspace: open component-preview`
721impl Component for GitStatusIcon {
722    fn scope() -> ComponentScope {
723        ComponentScope::VersionControl
724    }
725
726    fn preview(_window: &mut Window, _cx: &mut App) -> Option<AnyElement> {
727        fn tracked_file_status(code: StatusCode) -> FileStatus {
728            FileStatus::Tracked(git::status::TrackedStatus {
729                index_status: code,
730                worktree_status: code,
731            })
732        }
733
734        let modified = tracked_file_status(StatusCode::Modified);
735        let added = tracked_file_status(StatusCode::Added);
736        let deleted = tracked_file_status(StatusCode::Deleted);
737        let conflict = UnmergedStatus {
738            first_head: UnmergedStatusCode::Updated,
739            second_head: UnmergedStatusCode::Updated,
740        }
741        .into();
742
743        Some(
744            v_flex()
745                .gap_6()
746                .children(vec![example_group(vec![
747                    single_example("Modified", GitStatusIcon::new(modified).into_any_element()),
748                    single_example("Added", GitStatusIcon::new(added).into_any_element()),
749                    single_example("Deleted", GitStatusIcon::new(deleted).into_any_element()),
750                    single_example(
751                        "Conflicted",
752                        GitStatusIcon::new(conflict).into_any_element(),
753                    ),
754                ])])
755                .into_any_element(),
756        )
757    }
758}
759
760struct GitCloneModal {
761    panel: Entity<GitPanel>,
762    repo_input: Entity<Editor>,
763    focus_handle: FocusHandle,
764}
765
766impl GitCloneModal {
767    pub fn show(panel: Entity<GitPanel>, window: &mut Window, cx: &mut Context<Self>) -> Self {
768        let repo_input = cx.new(|cx| {
769            let mut editor = Editor::single_line(window, cx);
770            editor.set_placeholder_text("Enter repository URL…", window, cx);
771            editor
772        });
773        let focus_handle = repo_input.focus_handle(cx);
774
775        window.focus(&focus_handle);
776
777        Self {
778            panel,
779            repo_input,
780            focus_handle,
781        }
782    }
783}
784
785impl Focusable for GitCloneModal {
786    fn focus_handle(&self, _: &App) -> FocusHandle {
787        self.focus_handle.clone()
788    }
789}
790
791impl Render for GitCloneModal {
792    fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
793        div()
794            .elevation_3(cx)
795            .w(rems(34.))
796            .flex_1()
797            .overflow_hidden()
798            .child(
799                div()
800                    .w_full()
801                    .p_2()
802                    .border_b_1()
803                    .border_color(cx.theme().colors().border_variant)
804                    .child(self.repo_input.clone()),
805            )
806            .child(
807                h_flex()
808                    .w_full()
809                    .p_2()
810                    .gap_0p5()
811                    .rounded_b_sm()
812                    .bg(cx.theme().colors().editor_background)
813                    .child(
814                        Label::new("Clone a repository from GitHub or other sources.")
815                            .color(Color::Muted)
816                            .size(LabelSize::Small),
817                    )
818                    .child(
819                        Button::new("learn-more", "Learn More")
820                            .label_size(LabelSize::Small)
821                            .icon(IconName::ArrowUpRight)
822                            .icon_size(IconSize::XSmall)
823                            .on_click(|_, _, cx| {
824                                cx.open_url("https://github.com/git-guides/git-clone");
825                            }),
826                    ),
827            )
828            .on_action(cx.listener(|_, _: &menu::Cancel, _, cx| {
829                cx.emit(DismissEvent);
830            }))
831            .on_action(cx.listener(|this, _: &menu::Confirm, window, cx| {
832                let repo = this.repo_input.read(cx).text(cx);
833                this.panel.update(cx, |panel, cx| {
834                    panel.git_clone(repo, window, cx);
835                });
836                cx.emit(DismissEvent);
837            }))
838    }
839}
840
841impl EventEmitter<DismissEvent> for GitCloneModal {}
842
843impl ModalView for GitCloneModal {}