assistant2: Only show thread context in picker when we have a ThreadStore
(#23501)
This PR fixes an issue with the context picker where it would show thread context as an option even if there was no `ThreadStore` available. Release Notes: - N/A
This commit is contained in:
parent
a1077c6fff
commit
01b57b10e7
2 changed files with 18 additions and 20 deletions
|
@ -43,15 +43,6 @@ pub enum ContextKind {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ContextKind {
|
impl ContextKind {
|
||||||
pub fn all() -> &'static [ContextKind] {
|
|
||||||
&[
|
|
||||||
ContextKind::File,
|
|
||||||
ContextKind::Directory,
|
|
||||||
ContextKind::FetchedUrl,
|
|
||||||
ContextKind::Thread,
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn label(&self) -> &'static str {
|
pub fn label(&self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
ContextKind::File => "File",
|
ContextKind::File => "File",
|
||||||
|
|
|
@ -77,16 +77,6 @@ impl ContextPicker {
|
||||||
let context_picker = cx.view().clone();
|
let context_picker = cx.view().clone();
|
||||||
|
|
||||||
let menu = ContextMenu::build(cx, move |menu, cx| {
|
let menu = ContextMenu::build(cx, move |menu, cx| {
|
||||||
let kind_entry = |kind: &'static ContextKind| {
|
|
||||||
let context_picker = context_picker.clone();
|
|
||||||
|
|
||||||
ContextMenuEntry::new(kind.label())
|
|
||||||
.icon(kind.icon())
|
|
||||||
.handler(move |cx| {
|
|
||||||
context_picker.update(cx, |this, cx| this.select_kind(*kind, cx))
|
|
||||||
})
|
|
||||||
};
|
|
||||||
|
|
||||||
let recent = self.recent_entries(cx);
|
let recent = self.recent_entries(cx);
|
||||||
let has_recent = !recent.is_empty();
|
let has_recent = !recent.is_empty();
|
||||||
let recent_entries = recent
|
let recent_entries = recent
|
||||||
|
@ -94,6 +84,15 @@ impl ContextPicker {
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(ix, entry)| self.recent_menu_item(context_picker.clone(), ix, entry));
|
.map(|(ix, entry)| self.recent_menu_item(context_picker.clone(), ix, entry));
|
||||||
|
|
||||||
|
let mut context_kinds = vec![
|
||||||
|
ContextKind::File,
|
||||||
|
ContextKind::Directory,
|
||||||
|
ContextKind::FetchedUrl,
|
||||||
|
];
|
||||||
|
if self.thread_store.is_some() {
|
||||||
|
context_kinds.push(ContextKind::Thread);
|
||||||
|
}
|
||||||
|
|
||||||
let menu = menu
|
let menu = menu
|
||||||
.when(has_recent, |menu| {
|
.when(has_recent, |menu| {
|
||||||
menu.custom_row(|_| {
|
menu.custom_row(|_| {
|
||||||
|
@ -109,7 +108,15 @@ impl ContextPicker {
|
||||||
})
|
})
|
||||||
.extend(recent_entries)
|
.extend(recent_entries)
|
||||||
.when(has_recent, |menu| menu.separator())
|
.when(has_recent, |menu| menu.separator())
|
||||||
.extend(ContextKind::all().into_iter().map(kind_entry));
|
.extend(context_kinds.into_iter().map(|kind| {
|
||||||
|
let context_picker = context_picker.clone();
|
||||||
|
|
||||||
|
ContextMenuEntry::new(kind.label())
|
||||||
|
.icon(kind.icon())
|
||||||
|
.handler(move |cx| {
|
||||||
|
context_picker.update(cx, |this, cx| this.select_kind(kind, cx))
|
||||||
|
})
|
||||||
|
}));
|
||||||
|
|
||||||
match self.confirm_behavior {
|
match self.confirm_behavior {
|
||||||
ConfirmBehavior::KeepOpen => menu.keep_open_on_confirm(),
|
ConfirmBehavior::KeepOpen => menu.keep_open_on_confirm(),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue