assistant2: Allow dismissing the tool list with the keyboard (#27603)
This PR adds the ability to dismiss the tool list in the profile configuration modal using the keyboard. Release Notes: - N/A
This commit is contained in:
parent
5bb979820b
commit
a20a534ecf
1 changed files with 21 additions and 7 deletions
|
@ -3,7 +3,7 @@ use std::sync::Arc;
|
||||||
use assistant_settings::AssistantSettings;
|
use assistant_settings::AssistantSettings;
|
||||||
use assistant_tool::ToolWorkingSet;
|
use assistant_tool::ToolWorkingSet;
|
||||||
use fs::Fs;
|
use fs::Fs;
|
||||||
use gpui::{prelude::*, DismissEvent, Entity, EventEmitter, FocusHandle, Focusable};
|
use gpui::{prelude::*, DismissEvent, Entity, EventEmitter, FocusHandle, Focusable, Subscription};
|
||||||
use settings::Settings as _;
|
use settings::Settings as _;
|
||||||
use ui::{prelude::*, ListItem, ListItemSpacing, Navigable, NavigableEntry};
|
use ui::{prelude::*, ListItem, ListItemSpacing, Navigable, NavigableEntry};
|
||||||
use workspace::{ModalView, Workspace};
|
use workspace::{ModalView, Workspace};
|
||||||
|
@ -15,7 +15,10 @@ use crate::{AssistantPanel, ManageProfiles};
|
||||||
enum Mode {
|
enum Mode {
|
||||||
ChooseProfile(Entity<ProfilePicker>),
|
ChooseProfile(Entity<ProfilePicker>),
|
||||||
ViewProfile(ViewProfileMode),
|
ViewProfile(ViewProfileMode),
|
||||||
ConfigureTools(Entity<ToolPicker>),
|
ConfigureTools {
|
||||||
|
tool_picker: Entity<ToolPicker>,
|
||||||
|
_subscription: Subscription,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
@ -98,16 +101,27 @@ impl ManageProfilesModal {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
self.mode = Mode::ConfigureTools(cx.new(|cx| {
|
let tool_picker = cx.new(|cx| {
|
||||||
let delegate = ToolPickerDelegate::new(
|
let delegate = ToolPickerDelegate::new(
|
||||||
self.fs.clone(),
|
self.fs.clone(),
|
||||||
self.tools.clone(),
|
self.tools.clone(),
|
||||||
profile_id,
|
profile_id.clone(),
|
||||||
profile,
|
profile,
|
||||||
cx,
|
cx,
|
||||||
);
|
);
|
||||||
ToolPicker::new(delegate, window, cx)
|
ToolPicker::new(delegate, window, cx)
|
||||||
}));
|
});
|
||||||
|
let dismiss_subscription = cx.subscribe_in(&tool_picker, window, {
|
||||||
|
let profile_id = profile_id.clone();
|
||||||
|
move |this, _tool_picker, _: &DismissEvent, window, cx| {
|
||||||
|
this.view_profile(profile_id.clone(), window, cx);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
self.mode = Mode::ConfigureTools {
|
||||||
|
tool_picker,
|
||||||
|
_subscription: dismiss_subscription,
|
||||||
|
};
|
||||||
self.focus_handle(cx).focus(window);
|
self.focus_handle(cx).focus(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,7 +136,7 @@ impl Focusable for ManageProfilesModal {
|
||||||
fn focus_handle(&self, cx: &App) -> FocusHandle {
|
fn focus_handle(&self, cx: &App) -> FocusHandle {
|
||||||
match &self.mode {
|
match &self.mode {
|
||||||
Mode::ChooseProfile(profile_picker) => profile_picker.focus_handle(cx),
|
Mode::ChooseProfile(profile_picker) => profile_picker.focus_handle(cx),
|
||||||
Mode::ConfigureTools(tool_picker) => tool_picker.focus_handle(cx),
|
Mode::ConfigureTools { tool_picker, .. } => tool_picker.focus_handle(cx),
|
||||||
Mode::ViewProfile(_) => self.focus_handle.clone(),
|
Mode::ViewProfile(_) => self.focus_handle.clone(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -195,7 +209,7 @@ impl Render for ManageProfilesModal {
|
||||||
Mode::ViewProfile(mode) => self
|
Mode::ViewProfile(mode) => self
|
||||||
.render_view_profile(mode.clone(), window, cx)
|
.render_view_profile(mode.clone(), window, cx)
|
||||||
.into_any_element(),
|
.into_any_element(),
|
||||||
Mode::ConfigureTools(tool_picker) => tool_picker.clone().into_any_element(),
|
Mode::ConfigureTools { tool_picker, .. } => tool_picker.clone().into_any_element(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue