assistant2: Use ContextKind to match on ContextPicker entries (#22143)

This PR updates the `ContextPicker` entries to match on the
`ContextKind` instead of using strings.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2024-12-17 11:43:27 -05:00 committed by GitHub
parent ed3e647ed7
commit 68e3d79847
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -13,6 +13,7 @@ use ui::{prelude::*, ListItem, ListItemSpacing};
use util::ResultExt; use util::ResultExt;
use workspace::Workspace; use workspace::Workspace;
use crate::context::ContextKind;
use crate::context_picker::fetch_context_picker::FetchContextPicker; use crate::context_picker::fetch_context_picker::FetchContextPicker;
use crate::context_picker::file_context_picker::FileContextPicker; use crate::context_picker::file_context_picker::FileContextPicker;
use crate::context_picker::thread_context_picker::ThreadContextPicker; use crate::context_picker::thread_context_picker::ThreadContextPicker;
@ -40,16 +41,14 @@ impl ContextPicker {
cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
) -> Self { ) -> Self {
let mut entries = vec![ let mut entries = vec![
ContextPickerEntry {
name: "Directory".into(),
icon: IconName::Folder,
},
ContextPickerEntry { ContextPickerEntry {
name: "File".into(), name: "File".into(),
kind: ContextKind::File,
icon: IconName::File, icon: IconName::File,
}, },
ContextPickerEntry { ContextPickerEntry {
name: "Fetch".into(), name: "Fetch".into(),
kind: ContextKind::FetchedUrl,
icon: IconName::Globe, icon: IconName::Globe,
}, },
]; ];
@ -57,6 +56,7 @@ impl ContextPicker {
if thread_store.is_some() { if thread_store.is_some() {
entries.push(ContextPickerEntry { entries.push(ContextPickerEntry {
name: "Thread".into(), name: "Thread".into(),
kind: ContextKind::Thread,
icon: IconName::MessageCircle, icon: IconName::MessageCircle,
}); });
} }
@ -115,6 +115,7 @@ impl Render for ContextPicker {
#[derive(Clone)] #[derive(Clone)]
struct ContextPickerEntry { struct ContextPickerEntry {
name: SharedString, name: SharedString,
kind: ContextKind,
icon: IconName, icon: IconName,
} }
@ -155,8 +156,8 @@ impl PickerDelegate for ContextPickerDelegate {
if let Some(entry) = self.entries.get(self.selected_ix) { if let Some(entry) = self.entries.get(self.selected_ix) {
self.context_picker self.context_picker
.update(cx, |this, cx| { .update(cx, |this, cx| {
match entry.name.to_string().as_str() { match entry.kind {
"File" => { ContextKind::File => {
this.mode = ContextPickerMode::File(cx.new_view(|cx| { this.mode = ContextPickerMode::File(cx.new_view(|cx| {
FileContextPicker::new( FileContextPicker::new(
self.context_picker.clone(), self.context_picker.clone(),
@ -166,7 +167,7 @@ impl PickerDelegate for ContextPickerDelegate {
) )
})); }));
} }
"Fetch" => { ContextKind::FetchedUrl => {
this.mode = ContextPickerMode::Fetch(cx.new_view(|cx| { this.mode = ContextPickerMode::Fetch(cx.new_view(|cx| {
FetchContextPicker::new( FetchContextPicker::new(
self.context_picker.clone(), self.context_picker.clone(),
@ -176,7 +177,7 @@ impl PickerDelegate for ContextPickerDelegate {
) )
})); }));
} }
"Thread" => { ContextKind::Thread => {
if let Some(thread_store) = self.thread_store.as_ref() { if let Some(thread_store) = self.thread_store.as_ref() {
this.mode = ContextPickerMode::Thread(cx.new_view(|cx| { this.mode = ContextPickerMode::Thread(cx.new_view(|cx| {
ThreadContextPicker::new( ThreadContextPicker::new(
@ -188,7 +189,6 @@ impl PickerDelegate for ContextPickerDelegate {
})); }));
} }
} }
_ => {}
} }
cx.focus_self(); cx.focus_self();