directory_context_picker.rs

  1// TODO: Remove this once we've implemented the functionality.
  2#![allow(unused)]
  3
  4use std::sync::Arc;
  5
  6use fuzzy::PathMatch;
  7use gpui::{AppContext, DismissEvent, FocusHandle, FocusableView, Task, View, WeakModel, WeakView};
  8use picker::{Picker, PickerDelegate};
  9use project::{PathMatchCandidateSet, WorktreeId};
 10use ui::{prelude::*, ListItem};
 11use util::ResultExt as _;
 12use workspace::Workspace;
 13
 14use crate::context_picker::ContextPicker;
 15use crate::context_store::ContextStore;
 16
 17pub struct DirectoryContextPicker {
 18    picker: View<Picker<DirectoryContextPickerDelegate>>,
 19}
 20
 21impl DirectoryContextPicker {
 22    pub fn new(
 23        context_picker: WeakView<ContextPicker>,
 24        workspace: WeakView<Workspace>,
 25        context_store: WeakModel<ContextStore>,
 26        cx: &mut ViewContext<Self>,
 27    ) -> Self {
 28        let delegate =
 29            DirectoryContextPickerDelegate::new(context_picker, workspace, context_store);
 30        let picker = cx.new_view(|cx| Picker::uniform_list(delegate, cx));
 31
 32        Self { picker }
 33    }
 34}
 35
 36impl FocusableView for DirectoryContextPicker {
 37    fn focus_handle(&self, cx: &AppContext) -> FocusHandle {
 38        self.picker.focus_handle(cx)
 39    }
 40}
 41
 42impl Render for DirectoryContextPicker {
 43    fn render(&mut self, _cx: &mut ViewContext<Self>) -> impl IntoElement {
 44        self.picker.clone()
 45    }
 46}
 47
 48pub struct DirectoryContextPickerDelegate {
 49    context_picker: WeakView<ContextPicker>,
 50    workspace: WeakView<Workspace>,
 51    context_store: WeakModel<ContextStore>,
 52    matches: Vec<PathMatch>,
 53    selected_index: usize,
 54}
 55
 56impl DirectoryContextPickerDelegate {
 57    pub fn new(
 58        context_picker: WeakView<ContextPicker>,
 59        workspace: WeakView<Workspace>,
 60        context_store: WeakModel<ContextStore>,
 61    ) -> Self {
 62        Self {
 63            context_picker,
 64            workspace,
 65            context_store,
 66            matches: Vec::new(),
 67            selected_index: 0,
 68        }
 69    }
 70}
 71
 72impl PickerDelegate for DirectoryContextPickerDelegate {
 73    type ListItem = ListItem;
 74
 75    fn match_count(&self) -> usize {
 76        self.matches.len()
 77    }
 78
 79    fn selected_index(&self) -> usize {
 80        self.selected_index
 81    }
 82
 83    fn set_selected_index(&mut self, ix: usize, cx: &mut ViewContext<Picker<Self>>) {
 84        self.selected_index = ix;
 85    }
 86
 87    fn placeholder_text(&self, _cx: &mut WindowContext) -> Arc<str> {
 88        "Search folders…".into()
 89    }
 90
 91    fn update_matches(&mut self, _query: String, _cx: &mut ViewContext<Picker<Self>>) -> Task<()> {
 92        // TODO: Implement this once we fix the issues with the file context picker.
 93        Task::ready(())
 94    }
 95
 96    fn confirm(&mut self, _secondary: bool, _cx: &mut ViewContext<Picker<Self>>) {
 97        // TODO: Implement this once we fix the issues with the file context picker.
 98    }
 99
100    fn dismissed(&mut self, cx: &mut ViewContext<Picker<Self>>) {
101        self.context_picker
102            .update(cx, |this, cx| {
103                this.reset_mode();
104                cx.emit(DismissEvent);
105            })
106            .ok();
107    }
108
109    fn render_match(
110        &self,
111        _ix: usize,
112        _selected: bool,
113        _cx: &mut ViewContext<Picker<Self>>,
114    ) -> Option<Self::ListItem> {
115        None
116    }
117}