assistant2: Do not allow a context entry to be added multiple times (#22712)
https://github.com/user-attachments/assets/81674c88-031b-4d55-b362-43819492b93d Release Notes: - N/A
This commit is contained in:
parent
c74e5f5de2
commit
3a061a91e7
9 changed files with 293 additions and 173 deletions
|
@ -14,6 +14,7 @@ use ui::{prelude::*, ListItem, ListItemSpacing};
|
|||
use util::ResultExt;
|
||||
use workspace::Workspace;
|
||||
|
||||
use crate::context::ContextKind;
|
||||
use crate::context_picker::directory_context_picker::DirectoryContextPicker;
|
||||
use crate::context_picker::fetch_context_picker::FetchContextPicker;
|
||||
use crate::context_picker::file_context_picker::FileContextPicker;
|
||||
|
@ -52,24 +53,24 @@ impl ContextPicker {
|
|||
let mut entries = Vec::new();
|
||||
entries.push(ContextPickerEntry {
|
||||
name: "File".into(),
|
||||
kind: ContextPickerEntryKind::File,
|
||||
kind: ContextKind::File,
|
||||
icon: IconName::File,
|
||||
});
|
||||
entries.push(ContextPickerEntry {
|
||||
name: "Folder".into(),
|
||||
kind: ContextPickerEntryKind::Directory,
|
||||
kind: ContextKind::Directory,
|
||||
icon: IconName::Folder,
|
||||
});
|
||||
entries.push(ContextPickerEntry {
|
||||
name: "Fetch".into(),
|
||||
kind: ContextPickerEntryKind::FetchedUrl,
|
||||
kind: ContextKind::FetchedUrl,
|
||||
icon: IconName::Globe,
|
||||
});
|
||||
|
||||
if thread_store.is_some() {
|
||||
entries.push(ContextPickerEntry {
|
||||
name: "Thread".into(),
|
||||
kind: ContextPickerEntryKind::Thread,
|
||||
kind: ContextKind::Thread,
|
||||
icon: IconName::MessageCircle,
|
||||
});
|
||||
}
|
||||
|
@ -133,18 +134,10 @@ impl Render for ContextPicker {
|
|||
#[derive(Clone)]
|
||||
struct ContextPickerEntry {
|
||||
name: SharedString,
|
||||
kind: ContextPickerEntryKind,
|
||||
kind: ContextKind,
|
||||
icon: IconName,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
enum ContextPickerEntryKind {
|
||||
File,
|
||||
Directory,
|
||||
FetchedUrl,
|
||||
Thread,
|
||||
}
|
||||
|
||||
pub(crate) struct ContextPickerDelegate {
|
||||
context_picker: WeakView<ContextPicker>,
|
||||
workspace: WeakView<Workspace>,
|
||||
|
@ -184,7 +177,7 @@ impl PickerDelegate for ContextPickerDelegate {
|
|||
self.context_picker
|
||||
.update(cx, |this, cx| {
|
||||
match entry.kind {
|
||||
ContextPickerEntryKind::File => {
|
||||
ContextKind::File => {
|
||||
this.mode = ContextPickerMode::File(cx.new_view(|cx| {
|
||||
FileContextPicker::new(
|
||||
self.context_picker.clone(),
|
||||
|
@ -195,7 +188,7 @@ impl PickerDelegate for ContextPickerDelegate {
|
|||
)
|
||||
}));
|
||||
}
|
||||
ContextPickerEntryKind::Directory => {
|
||||
ContextKind::Directory => {
|
||||
this.mode = ContextPickerMode::Directory(cx.new_view(|cx| {
|
||||
DirectoryContextPicker::new(
|
||||
self.context_picker.clone(),
|
||||
|
@ -206,7 +199,7 @@ impl PickerDelegate for ContextPickerDelegate {
|
|||
)
|
||||
}));
|
||||
}
|
||||
ContextPickerEntryKind::FetchedUrl => {
|
||||
ContextKind::FetchedUrl => {
|
||||
this.mode = ContextPickerMode::Fetch(cx.new_view(|cx| {
|
||||
FetchContextPicker::new(
|
||||
self.context_picker.clone(),
|
||||
|
@ -217,7 +210,7 @@ impl PickerDelegate for ContextPickerDelegate {
|
|||
)
|
||||
}));
|
||||
}
|
||||
ContextPickerEntryKind::Thread => {
|
||||
ContextKind::Thread => {
|
||||
if let Some(thread_store) = self.thread_store.as_ref() {
|
||||
this.mode = ContextPickerMode::Thread(cx.new_view(|cx| {
|
||||
ThreadContextPicker::new(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue